Exemplo n.º 1
0
    Color32[] AddColorsToMesh(int count, HeatPoint pt)
    {
        Color32[] colors = new Color32[count];

        Color color;

        if (m_MaskOption == k_RadiusMasking && IsOutsideRadius(pt))
        {
            color = s_GhostColor;
        }
        else
        {
            float pct = pt.density / m_MaxDensity;
            if (float.IsInfinity(pct))
            {
                pct = 0f;
            }
            color = GradientUtils.PickGradientColor(m_Gradient, pct);
        }
        for (int b = 0; b < count; b++)
        {
            colors[b] = new Color(color.r, color.g, color.b, color.a);
        }
        return(colors);
    }
Exemplo n.º 2
0
        private void Generate1DHeatMap()
        {
            // Get source list
            object[] source = this._sourceList.GetVisible().ToArray();

            // Generate heatmap values
            HeatPoint[] tsrc = new HeatPoint[source.Length];

            for (int n = 0; n < source.Length; n++)
            {
                var       vis  = source[n];
                HeatPoint heat = new HeatPoint();
                heat.XSource = vis;
                heat.XIndex  = n;
                heat.ZValue  = this.GetRow(vis);
                tsrc[n]      = heat;
            }

            // Sort if specified
            if (this._sort)
            {
                tsrc = tsrc.OrderBy(z => z.ZValue).ToArray();
            }

            this._heatMap = new HeatPoint[tsrc.Length, 1];

            for (int n = 0; n < tsrc.Length; n++)
            {
                this._heatMap[n, 0] = tsrc[n];
            }
        }
Exemplo n.º 3
0
        private void pictureBox1_Render(object sender, RenderEventArgs e)
        {
            int       w   = this._heatMap.GetLength(0);
            int       h   = this._heatMap.GetLength(1);
            Bitmap    bmp = e.Bitmap;
            Rectangle all = new Rectangle(0, 0, bmp.Width, bmp.Height);

            BitmapData bdata = bmp.LockBits(all, ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
            int        size  = bdata.Height * bdata.Stride;

            byte[] data = new byte[size];

            for (int y = 0; y < bmp.Height; y++)
            {
                for (int x = 0; x < bmp.Width; x++)
                {
                    int i = (x * 3) + (y * bdata.Stride);

                    HeatPoint hm = this.ScreenToHeatMap(new Point(x, y));

                    Color c = !hm.IsEmpty ? hm.ZColour : this._oorColour;

                    data[i + 0] = c.B;
                    data[i + 1] = c.G;
                    data[i + 2] = c.R;
                }
            }

            // Marshal to avoid unsafe code...
            Marshal.Copy(data, 0, bdata.Scan0, data.Length);

            bmp.UnlockBits(bdata);
        }
        private void DrawHeatPoint(Graphics Canvas, HeatPoint HeatPoint, int Radius)
        {
            // Create points generic list of points to hold circumference points
            List <Point> CircumferencePointsList = new List <Point>();
            // Create an empty point to predefine the point struct used in the circumference loop
            Point CircumferencePoint;

            // Create an empty array that will be populated with points from the generic list
            Point[] CircumferencePointsArray;
            // Calculate ratio to scale byte intensity range from 0-255 to 0-1
            float fRatio = 1F / Byte.MaxValue;
            // Precalulate half of byte max value
            byte bHalf = Byte.MaxValue / 2;
            // Flip intensity on it's center value from low-high to high-low
            int iIntensity = (byte)(HeatPoint.Intensity - ((HeatPoint.Intensity - bHalf) * 2));
            // Store scaled and flipped intensity value for use with gradient center location
            float fIntensity = iIntensity * fRatio;

            // Loop through all angles of a circle
            // Define loop variable as a double to prevent casting in each iteration
            // Iterate through loop on 10 degree deltas, this can change to improve performance
            for (double i = 0; i <= 360; i += 10)
            {
                // Replace last iteration point with new empty point struct
                CircumferencePoint = new Point();
                // Plot new point on the circumference of a circle of the defined radius
                // Using the point coordinates, radius, and angle
                // Calculate the position of this iterations point on the circle
                CircumferencePoint.X = Convert.ToInt32(HeatPoint.X + Radius * Math.Cos(ConvertDegreesToRadians(i)));
                CircumferencePoint.Y = Convert.ToInt32(HeatPoint.Y + Radius * Math.Sin(ConvertDegreesToRadians(i)));
                // Add newly plotted circumference point to generic point list
                CircumferencePointsList.Add(CircumferencePoint);
            }
            // Populate empty points system array from generic points array list
            // Do this to satisfy the datatype of the PathGradientBrush and FillPolygon methods
            CircumferencePointsArray = CircumferencePointsList.ToArray();
            // Create new PathGradientBrush to create a radial gradient using the circumference points
            PathGradientBrush GradientShaper = new PathGradientBrush(CircumferencePointsArray);
            // Create new color blend to tell the PathGradientBrush what colors to use and where to put them
            ColorBlend GradientSpecifications = new ColorBlend(3);

            // Define positions of gradient colors, use intesity to adjust the middle color to
            // show more mask or less mask
            GradientSpecifications.Positions = new float[3] {
                0, fIntensity, 1
            };
            // Define gradient colors and their alpha values, adjust alpha of gradient colors to match intensity
            GradientSpecifications.Colors = new Color[3]
            {
                Color.FromArgb(0, Color.White),
                Color.FromArgb(HeatPoint.Intensity, Color.Black),
                Color.FromArgb(HeatPoint.Intensity, Color.Black)
            };
            // Pass off color blend to PathGradientBrush to instruct it how to generate the gradient
            GradientShaper.InterpolationColors = GradientSpecifications;
            // Draw polygon (circle) using our point array and gradient brush
            Canvas.FillPolygon(GradientShaper, CircumferencePointsArray);
        }
Exemplo n.º 5
0
 bool FilterPoint(HeatPoint pt)
 {
     if (pt.time < m_StartTime || pt.time > m_EndTime)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 6
0
 void createHeatLine(double startX, double startY, int len, double slope, int type)
 {
     for (int i = 0; i < len; i++)
     {
         HeatPoint hp = new HeatPoint();
         hp.Xloc    = startX + 0.001 * i;
         hp.Yloc    = startY + 0.001 * i * slope;
         hp.instant = DateTime.Now;
         hp.Type    = type;
         myDb.HeatPoints.Add(hp);
     }
 }
Exemplo n.º 7
0
        // GET api/<controller>
        public string Get(Double x, Double y, int Type)
        {
            HeatPoint    hp   = new HeatPoint();
            EmataContext myDb = new EmataContext();

            hp.Xloc    = x;
            hp.Yloc    = y;
            hp.Type    = Type;
            hp.instant = DateTime.Now;
            myDb.HeatPoints.Add(hp);
            myDb.SaveChanges();
            return("Thanks !");
        }
Exemplo n.º 8
0
//    float m_CollapseDensity = 0f;

    HeatPoint Aggregate(HeatPoint pt, Dictionary <Vector3, HeatPoint> collapsePoints)
    {
        HeatPoint retv = pt;

        if (collapsePoints.ContainsKey(pt.position))
        {
            retv          = collapsePoints[pt.position];
            retv.density += pt.density;
        }
//        m_CollapseDensity = Mathf.Max(retv.density, m_MaxDensity);
        collapsePoints[pt.position] = retv;
        return(retv);
    }
        public async void WebView_ScriptNotify(object sender, Windows.UI.Xaml.Controls.NotifyEventArgs e)
        {
            if (e.Value.Contains("tap") && !IsOnStart && recordSettings.Touches)
            {
                if (currentRecordScreen == null)
                {
                    currentRecordScreen = new RecordScreenModel(previousUrl, await DoCaptureWebView());
                }

                float    x;
                float    y;
                string[] arr = e.Value.Split(new char[] { ':' });
                if (!float.TryParse(arr[1], out x))
                {
                    System.Diagnostics.Debug.WriteLine("ErrorX");
                }
                if (!float.TryParse(arr[2], out y))
                {
                    System.Diagnostics.Debug.WriteLine("ErrorY");
                }
                int       iX = (int)Math.Round(x);
                int       iY = (int)Math.Round(y);
                HeatPoint hp = new HeatPoint(iX, iY);
                currentRecordScreen.ListPoints.Add(hp);

                if (!_webview.Source.AbsoluteUri.Equals(currentRecordScreen.UriPage))
                {
                    int indexFind = _screens.FindIndex(s => s.UriPage.Equals(currentRecordScreen.UriPage));
                    if (indexFind != -1)
                    {
                        _screens[indexFind].ListPoints = currentRecordScreen.ListPoints;
                    }
                    else
                    {
                        _screens.Add(currentRecordScreen);
                    }

                    indexFind = _screens.FindIndex(s => s.UriPage.Equals(_webview.Source.AbsoluteUri));
                    if (indexFind != -1)
                    {
                        currentRecordScreen = _screens[indexFind];
                    }
                    else
                    {
                        currentRecordScreen = null;
                        previousUrl         = _webview.Source.AbsoluteUri;
                    }
                }
            }
        }
Exemplo n.º 10
0
    string BuildText(HeatPoint pt)
    {
        string text = "Position x: " + pt.position.x;

        text += " y: " + pt.position.y;
        text += " z: " + pt.position.z + "\n";
        text += "Rotation x: " + pt.position.x;
        text += " y: " + pt.position.y;
        text += " z: " + pt.position.z + "\n";
        text += "Destination x: " + pt.destination.x;
        text += " y: " + pt.destination.y;
        text += " z: " + pt.destination.z + "\n";
        text += "Time: " + pt.time + "\n";
        text += "Density: " + pt.density;
        return(text);
    }
        /// <summary>
        /// Inspects the given matrix and sets the series to this matrix M.
        /// </summary>
        /// <param name="M">The matrix to investigate.</param>
        public override void AddPoints(MatrixValue M)
        {
            var p   = data;
            var min = double.MaxValue;
            var max = double.MinValue;

            for (var i = 1; i <= M.DimensionX; i++)
            {
                for (var j = 1; j <= M.DimensionY; j++)
                {
                    var value = M[j, i].Abs();

                    p.Add(new HeatPoint
                    {
                        Row       = j,
                        Column    = i,
                        Magnitude = value
                    });

                    if (value > max)
                    {
                        max = value;
                    }
                    else if (value < min)
                    {
                        min = value;
                    }
                }
            }

            var gap = max - min;

            for (var i = 0; i != p.Count; i++)
            {
                p[i] = new HeatPoint {
                    Column = p[i].Column, Row = p[i].Row, Magnitude = (p[i].Magnitude - min) / gap
                }
            }
            ;

            Minimum = min;
            Maximum = max;
            MinX    = 1;
            MaxX    = M.DimensionX;
            MinY    = 1;
            MaxY    = M.DimensionY;
        }
Exemplo n.º 12
0
    Color32[] AddColorsToMesh(int count, HeatPoint pt)
    {
        Color32[] colors = new Color32[count];
        float     pct    = (pt.density / m_MaxDensity);

        if (float.IsInfinity(pct))
        {
            pct = 0f;
        }
        Color color = PickGradientColor(pct);

        for (int b = 0; b < count; b++)
        {
            colors[b] = new Color(color.r, color.g, color.b, color.a);
        }
        return(colors);
    }
Exemplo n.º 13
0
    bool FilterPoint(HeatPoint pt)
    {
        if (pt.time < m_StartTime || pt.time > m_EndTime)
        {
            return(false);
        }

        if (m_MaskOption == k_RadiusMasking)
        {
            return(true);
        }

        return
            (pt.position.x >= m_LowX && pt.position.x <= m_HighX &&
             pt.position.y >= m_LowY && pt.position.y <= m_HighY &&
             pt.position.z >= m_LowZ && pt.position.z <= m_HighZ);
    }
Exemplo n.º 14
0
    string BuildText(HeatPoint pt)
    {
        string text = "Position x: " + pt.position.x;

        text += " y: " + pt.position.y;
        text += " z: " + pt.position.z + "\n";
        text += "Rotation x: " + pt.position.x;
        text += " y: " + pt.position.y;
        text += " z: " + pt.position.z + "\n";
        text += "Destination x: " + pt.destination.x;
        text += " y: " + pt.destination.y;
        text += " z: " + pt.destination.z + "\n";
        text += "Time: " + pt.time + "\n";
        string label = (String.IsNullOrEmpty(pt.densityLabel)) ? "Density" : pt.densityLabel;

        text += label + ": " + pt.density;
        return(text);
    }
Exemplo n.º 15
0
        public static List <HeatPoint> Read(string filePath)
        {
            var result = new List <HeatPoint>();

            using (var sr = new StreamReader(filePath))
            {
                while (!sr.EndOfStream)
                {
                    var vals  = sr.ReadLine().Split(',');
                    var point = new HeatPoint();
                    point.X = float.Parse(vals[0]);
                    point.Y = float.Parse(vals[1]);
                    point.W = float.Parse(vals[2]);

                    result.Add(point);
                }
            }

            return(result);
        }
Exemplo n.º 16
0
    void OnSceneGUI()
    {
        if (m_Target.GetComponent <MeshCollider>() == null || m_Target.m_PointData == null)
        {
            return;
        }

        if (m_DisplayTime > 0)
        {
            m_DisplayTime--;
            Handles.BeginGUI();

            string     text    = BuildText(m_Point);
            GUIContent content = new GUIContent(text);

            Vector2 size = m_TextStyle.CalcSize(content) * 1.05f;


            float xPos = m_LabelPosition.x > Screen.width * .5f ? m_LabelPosition.x - size.x - 10f : m_LabelPosition.x + 10f;
            float yPos = m_LabelPosition.y > Screen.height * .5f ? m_LabelPosition.y - size.y - 10f : m_LabelPosition.y + 10f;


            GUILayout.BeginArea(new Rect(xPos, yPos, size.x, size.y), m_BgStyle);
            GUILayout.Label(content, m_TextStyle);
            GUILayout.EndArea();
            Handles.EndGUI();
        }
        if (Event.current != null && Event.current.type == EventType.mouseMove)
        {
            RaycastHit hit;
            Ray        ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            if (m_Target.GetComponent <MeshCollider>().Raycast(ray, out hit, float.MaxValue))
            {
                int idx = hit.triangleIndex / m_Target.m_TrianglesPerShape;
                m_Point         = m_Target.m_PointData[idx];
                m_LabelPosition = Event.current.mousePosition;
                m_DisplayTime   = m_MaxDisplayTime;
            }
        }
    }
Exemplo n.º 17
0
        private List <HeatPoint> RandomPoints(int width, int height, int count)
        {
            List <HeatPoint> result = new List <HeatPoint>();

            var r = new Random();

            for (int i = 0; i < count; i++)
            {
                var x = r.Next(width);
                var y = r.Next(height);
                //var w = (float)r.NextDouble()/2;

                HeatPoint point = new HeatPoint
                {
                    X = x,
                    Y = y,
                    W = 1
                };
                result.Add(point);
            }
            return(result);
        }
Exemplo n.º 18
0
        private void Generate2DHeatMap()
        {
            int n = this._source2D.ValueMatrix.NumRows;

            this._heatMap = new HeatPoint[n, n];

            for (int y = 0; y < n; y++)
            {
                for (int x = 0; x < n; x++)
                {
                    HeatPoint hp = new HeatPoint(  );
                    hp.XIndex  = x;
                    hp.XSource = this._source2D.ValueMatrix.Vectors[x].Peak;
                    hp.YIndex  = y;
                    hp.YSource = this._source2D.ValueMatrix.Vectors[y].Peak;

                    hp.ZValue = this._source2D.Values[x, y];

                    this._heatMap[x, y] = hp;
                }
            }
        }
Exemplo n.º 19
0
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            HeatPoint h = this.ScreenToHeatMap(e.Location);

            if (h.IsEmpty)
            {
                this._lblSelection.Visible         = false;
                this.toolStripStatusLabel3.Visible = false;
                return;
            }

            if (h.YSource == null || h.YSource == h.XSource)
            {
                this._sourceList.ActivateItem(h.XSource);
            }
            else
            {
                this.alphaToolStripMenuItem.Text = h.XSource.ToString();
                this.alphaToolStripMenuItem.Tag  = h.XSource;
                this.betaToolStripMenuItem.Text  = h.YSource.ToString();
                this.betaToolStripMenuItem.Tag   = h.YSource;
                this.contextMenuStrip1.Show(this.pictureBox1, e.Location);
            }
        }
Exemplo n.º 20
0
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            HeatPoint h = this.ScreenToHeatMap(e.Location);

            if (h.IsEmpty)
            {
                this._lblSelection.Visible         = false;
                this.toolStripStatusLabel3.Visible = false;
                return;
            }

            if (h.YSource == null)
            {
                this._lblSelection.Text = h.XSource.ToString() + " = (" + h.XIndex + ", " + h.ZValue + ")";
            }
            else
            {
                this._lblSelection.Text = "{" + h.XSource.ToString() + ", " + h.YSource.ToString() + "} ( {" + h.XIndex + ", " + h.YIndex + " }, " + h.ZValue + ")";
            }

            this.toolStripStatusLabel3.BackColor = h.ZColour;
            this._lblSelection.Visible           = true;
            this.toolStripStatusLabel3.Visible   = true;
        }
Exemplo n.º 21
0
        public static HeatPoint[,] Generate(int fromX, int fromY, bool draw, int breakOnX, int breakOnY)
        {
            var _mazeWidth = MazeData.MazeSize;
            var _mazeHeight = MazeData.MazeSize;

            //distMatrix = new int[_mazeWidth, _mazeHeight];
            //precMatrix = new MazePoint[_mazeWidth, _mazeHeight];

            var heatMatrix = new HeatPoint[_mazeWidth,_mazeHeight];

            for (int i = 0; i < _mazeWidth; i++)
                for (int j = 0; j < _mazeHeight; j++)
                    heatMatrix[i, j] = new HeatPoint();

            var point = new MazePoint(fromX, fromY);
            var row = new LinkedList<MazePoint>();
            row.AddFirst(point);

            var endPointFound = false;
            var count = 1;
            var newCount = -1;
            var index = -1;
            for (var curr = row.First; curr != null; curr = curr.Next)
            {
                index++;
                if (AppData.AppState == AppData.AppStates.Idle)
                    break;

                if (index == count)
                    newCount = row.Count;

                if (index == newCount)
                {
                    for (var i = 0; i < count; i++)
                        row.RemoveFirst();
                    index -= count;
                    count = newCount - count;
                    newCount = row.Count;
                }

                var adjPoints = MazeData.GetAdjPoints(curr.Value);
                foreach (var adjPoint in adjPoints)
                {
                    MazePoint goToPoint;
                    /*if (MazeData.MazeMatrix[adjPoint.X, adjPoint.Y] == CellState.HorWeave ||
                        MazeData.MazeMatrix[adjPoint.X, adjPoint.Y] == CellState.VertWeave)
                    {
                        goToPoint = new MazePoint(adjPoint.X + (adjPoint.X - curr.Value.X),
                            adjPoint.Y + (adjPoint.Y - curr.Value.Y));
                    }
                    else*/
                        goToPoint = adjPoint;

                    if (row.Contains(goToPoint))
                        continue;
                    row.AddLast(goToPoint);
                    heatMatrix[goToPoint.X, goToPoint.Y].Preceding = curr.Value;
                    heatMatrix[goToPoint.X, goToPoint.Y].Distance = heatMatrix[curr.Value.X, curr.Value.Y].Distance + 1;

                    if (breakOnX > 0 && breakOnY > 0 && goToPoint.X == breakOnX && goToPoint.Y == breakOnY)
                    {
                        endPointFound = true;
                        break;
                    }
                }
                //if (AnimateCheckBox.Checked && Convert.ToInt32(DelayTextBox.Text) > 0)
                //    Thread.Sleep(Convert.ToInt32(DelayTextBox.Text));
                if (endPointFound)
                    break;
            }

            /*for (var i = 0; i < _mazeWidth; i++)
            {
                for (var j = 0; j < _mazeHeight; j++)
                {
                    switch (_mazeMatrix[i, j])
                    {
                        case CellState.VertWeave:
                            distMatrix[i, j] = (distMatrix[i + 1, j] + distMatrix[i - 1, j]) / 2;
                            break;
                        case CellState.HorWeave:
                            distMatrix[i, j] = (distMatrix[i, j + 1] + distMatrix[i, j - 1]) / 2;
                            break;
                    }
                }
            }*/

            if (!draw)
                return heatMatrix;

            var maxDist = 1;
            for (var i = 0; i < _mazeWidth; i++)
                for (var j = 0; j < _mazeHeight; j++)
                    if (heatMatrix[i, j].Distance > maxDist)
                        maxDist = heatMatrix[i, j].Distance;

            for (var i = 0; i < _mazeWidth; i++)
            {
                for (var j = 0; j < _mazeHeight; j++)
                {
                    if (MazeData.MazeMatrix[i, j] == null || MazeData.MazeMatrix[i, j].State == CellState.Wall)
                        continue;

                    var red = heatMatrix[i, j].Distance * 255 / maxDist;
                    Color c;
                    if (heatMatrix[i, j].Distance < 1)
                        c = MazeData.MazeColors[CellState.Entrance];
                    else if (heatMatrix[i, j].Distance > maxDist - 1)
                        c = MazeData.MazeColors[CellState.Furthest];
                    else c = Color.FromRgba(50 * 256 * 256 + 50 * 256 + red);
                    MazeData.MazeMatrix[i, j].Display = c;
                }
            }

            return heatMatrix;
        }
Exemplo n.º 22
0
        /// <summary>
        /// Gets the view of a given point
        /// </summary>
        /// <param name="point"></param>
        /// <param name="label"></param>
        /// <returns></returns>
        public override IChartPointView GetPointView(ChartPoint point, string label)
        {
            var pbv = (HeatPoint)point.View;

            if (pbv == null)
            {
                pbv = new HeatPoint
                {
                    IsNew     = true,
                    Rectangle = new Rectangle()
                };

                Model.Chart.View.AddToDrawMargin(pbv.Rectangle);
            }
            else
            {
                pbv.IsNew = false;
                point.SeriesView.Model.Chart.View
                .EnsureElementBelongsToCurrentDrawMargin(pbv.Rectangle);
                point.SeriesView.Model.Chart.View
                .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape);
                point.SeriesView.Model.Chart.View
                .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel);
            }

            pbv.Rectangle.Stroke          = Stroke;
            pbv.Rectangle.StrokeThickness = StrokeThickness;
            pbv.Rectangle.Visibility      = Visibility;
            pbv.Rectangle.StrokeDashArray = StrokeDashArray;
            Panel.SetZIndex(pbv.Rectangle, Panel.GetZIndex(pbv.Rectangle));

            if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null)
            {
                pbv.HoverShape = new Rectangle
                {
                    Fill            = Brushes.Transparent,
                    StrokeThickness = 0
                };

                Panel.SetZIndex(pbv.HoverShape, int.MaxValue);

                var wpfChart = (Chart)Model.Chart.View;
                wpfChart.AttachHoverableEventTo(pbv.HoverShape);

                Model.Chart.View.AddToDrawMargin(pbv.HoverShape);
            }

            if (pbv.HoverShape != null)
            {
                pbv.HoverShape.Visibility = Visibility;
            }

            if (DataLabels)
            {
                pbv.DataLabel = UpdateLabelContent(new DataLabelViewModel
                {
                    FormattedText = label,
                    Point         = point
                }, pbv.DataLabel);
            }

            if (!DataLabels && pbv.DataLabel != null)
            {
                Model.Chart.View.RemoveFromDrawMargin(pbv.DataLabel);
                pbv.DataLabel = null;
            }

            return(pbv);
        }
Exemplo n.º 23
0
    void CreatePoints()
    {
        if (hasData())
        {
//            m_CollapseDensity = 0f;

            totalPoints   = m_Data.Length;
            currentPoints = 0;

            var submaps          = new List <List <HeatPoint> >();
            int currentSubmap    = 0;
            int verticesPerShape = RenderShapeMeshUtils.GetVecticesForShape(m_RenderStyle, m_Projection);

            // Filter & Aggregate
            Dictionary <Vector3, HeatPoint> collapsePoints = new Dictionary <Vector3, HeatPoint>();
            List <HeatPoint> otherPoints = new List <HeatPoint>();

            for (int a = 0; a < m_Data.Length; a++)
            {
                // FILTER FOR TIME & POSITION
                var pt = m_Data[a];
                if (FilterPoint(pt))
                {
                    if (m_MaskOption == k_RadiusMasking && m_Projection == RenderProjection.FirstPerson && IsOutsideRadius(pt))
                    {
                        Aggregate(pt, collapsePoints);
                    }
                    else
                    {
                        otherPoints.Add(pt);
                    }
                }
            }
            HeatPoint[] dictData     = collapsePoints.Values.ToArray();
            HeatPoint[] filteredData = new HeatPoint[dictData.Length + otherPoints.Count];

            dictData.CopyTo(filteredData, 0);
            otherPoints.CopyTo(filteredData, dictData.Length);


            // Arrange into submaps
            for (int a = 0; a < filteredData.Length; a++)
            {
                var pt = filteredData[a];
                currentPoints++;
                if (submaps.Count <= currentSubmap)
                {
                    submaps.Add(new List <HeatPoint>());
                }
                submaps[currentSubmap].Add(pt);
                currentSubmap = (currentPoints * verticesPerShape) / k_VerticesPerMesh;
            }

            int neededSubmaps  = submaps.Count;
            int currentSubmaps = m_GameObjects.Count;
            int addCount       = neededSubmaps - currentSubmaps;

            if (addCount > 0)
            {
                // Add submaps if we need more
                for (int a = 0; a < addCount; a++)
                {
                    int submapID = currentSubmaps + a;
                    var go       = new GameObject("Submap" + submapID);
                    go.AddComponent <HeatmapSubmap>();
                    go.GetComponent <MeshFilter>().sharedMesh = new Mesh();

                    go.transform.parent = gameObject.transform;
                    m_GameObjects.Add(go);
                }
            }
            else if (addCount < 0)
            {
                // Dispose of excess submaps
                for (var a = neededSubmaps; a < currentSubmaps; a++)
                {
                    Transform trans = gameObject.transform.Find("Submap" + a);
                    if (trans != null)
                    {
                        trans.parent = null;
                        m_GameObjects.Remove(trans.gameObject);
                        GameObject.DestroyImmediate(trans.gameObject);
                    }
                }
            }
            //Render submaps
            for (var a = 0; a < m_GameObjects.Count; a++)
            {
                Mesh renderMesh = m_GameObjects[a].GetComponent <MeshFilter>().sharedMesh;
                renderMesh.Clear();
                renderMesh.subMeshCount = submaps[a].Count;
                RenderSubmap(m_GameObjects[a], submaps[a]);
            }
            m_RenderState = k_NotRendering;
        }
    }
Exemplo n.º 24
0
 bool IsOutsideRadius(HeatPoint pt)
 {
     return(Vector3.Distance(m_MaskSource, pt.position) > m_MaskRadius);
 }
Exemplo n.º 25
0
        public override IChartPointView GetPointView(IChartPointView view, ChartPoint point, string label)
        {
            var pbv = (view as HeatPoint);

            if (pbv == null)
            {
                pbv = new HeatPoint
                {
                    IsNew     = true,
                    Rectangle = new Rectangle()
                };

                BindingOperations.SetBinding(pbv.Rectangle, Shape.StrokeProperty,
                                             new Binding {
                    Path = new PropertyPath(StrokeProperty), Source = this
                });
                BindingOperations.SetBinding(pbv.Rectangle, Shape.StrokeThicknessProperty,
                                             new Binding {
                    Path = new PropertyPath(StrokeThicknessProperty), Source = this
                });
                BindingOperations.SetBinding(pbv.Rectangle, VisibilityProperty,
                                             new Binding {
                    Path = new PropertyPath(VisibilityProperty), Source = this
                });
                BindingOperations.SetBinding(pbv.Rectangle, Panel.ZIndexProperty,
                                             new Binding {
                    Path = new PropertyPath(Panel.ZIndexProperty), Source = this
                });
                BindingOperations.SetBinding(pbv.Rectangle, Shape.StrokeDashArrayProperty,
                                             new Binding {
                    Path = new PropertyPath(StrokeDashArrayProperty), Source = this
                });

                Model.Chart.View.AddToDrawMargin(pbv.Rectangle);
            }
            else
            {
                pbv.IsNew = false;
                point.SeriesView.Model.Chart.View
                .EnsureElementBelongsToCurrentDrawMargin(pbv.Rectangle);
                point.SeriesView.Model.Chart.View
                .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape);
                point.SeriesView.Model.Chart.View
                .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel);
            }

            if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null)
            {
                pbv.HoverShape = new Rectangle
                {
                    Fill            = Brushes.Transparent,
                    StrokeThickness = 0
                };

                Panel.SetZIndex(pbv.HoverShape, int.MaxValue);
                BindingOperations.SetBinding(pbv.HoverShape, VisibilityProperty,
                                             new Binding {
                    Path = new PropertyPath(VisibilityProperty), Source = this
                });

                var wpfChart = (Chart)Model.Chart.View;
                wpfChart.AttachHoverableEventTo(pbv.HoverShape);

                Model.Chart.View.AddToDrawMargin(pbv.HoverShape);
            }

            if (DataLabels && pbv.DataLabel == null)
            {
                pbv.DataLabel = BindATextBlock(0);
                Panel.SetZIndex(pbv.DataLabel, int.MaxValue - 1);

                Model.Chart.View.AddToDrawMargin(pbv.DataLabel);
            }

            if (pbv.DataLabel != null)
            {
                pbv.DataLabel.Text = label;
            }

            return(pbv);
        }
Exemplo n.º 26
0
 public static void AddHeatpoint(HeatPoint point)
 {
     heatPoints.Add(point);
 }
Exemplo n.º 27
0
        public static HeatPoint[,] Generate(int fromX, int fromY, bool draw, int breakOnX, int breakOnY)
        {
            var _mazeWidth  = MazeData.MazeSize;
            var _mazeHeight = MazeData.MazeSize;

            //distMatrix = new int[_mazeWidth, _mazeHeight];
            //precMatrix = new MazePoint[_mazeWidth, _mazeHeight];

            var heatMatrix = new HeatPoint[_mazeWidth, _mazeHeight];

            for (int i = 0; i < _mazeWidth; i++)
            {
                for (int j = 0; j < _mazeHeight; j++)
                {
                    heatMatrix[i, j] = new HeatPoint();
                }
            }

            var point = new MazePoint(fromX, fromY);
            var row   = new LinkedList <MazePoint>();

            row.AddFirst(point);

            var endPointFound = false;
            var count         = 1;
            var newCount      = -1;
            var index         = -1;

            for (var curr = row.First; curr != null; curr = curr.Next)
            {
                index++;
                if (AppData.AppState == AppData.AppStates.Idle)
                {
                    break;
                }

                if (index == count)
                {
                    newCount = row.Count;
                }

                if (index == newCount)
                {
                    for (var i = 0; i < count; i++)
                    {
                        row.RemoveFirst();
                    }
                    index   -= count;
                    count    = newCount - count;
                    newCount = row.Count;
                }

                var adjPoints = MazeData.GetAdjPoints(curr.Value);
                foreach (var adjPoint in adjPoints)
                {
                    MazePoint goToPoint;

                    /*if (MazeData.MazeMatrix[adjPoint.X, adjPoint.Y] == CellState.HorWeave ||
                     *  MazeData.MazeMatrix[adjPoint.X, adjPoint.Y] == CellState.VertWeave)
                     * {
                     *  goToPoint = new MazePoint(adjPoint.X + (adjPoint.X - curr.Value.X),
                     *      adjPoint.Y + (adjPoint.Y - curr.Value.Y));
                     * }
                     * else*/
                    goToPoint = adjPoint;

                    if (row.Contains(goToPoint))
                    {
                        continue;
                    }
                    row.AddLast(goToPoint);
                    heatMatrix[goToPoint.X, goToPoint.Y].Preceding = curr.Value;
                    heatMatrix[goToPoint.X, goToPoint.Y].Distance  = heatMatrix[curr.Value.X, curr.Value.Y].Distance + 1;

                    if (breakOnX > 0 && breakOnY > 0 && goToPoint.X == breakOnX && goToPoint.Y == breakOnY)
                    {
                        endPointFound = true;
                        break;
                    }
                }
                //if (AnimateCheckBox.Checked && Convert.ToInt32(DelayTextBox.Text) > 0)
                //    Thread.Sleep(Convert.ToInt32(DelayTextBox.Text));
                if (endPointFound)
                {
                    break;
                }
            }

            /*for (var i = 0; i < _mazeWidth; i++)
             * {
             *  for (var j = 0; j < _mazeHeight; j++)
             *  {
             *      switch (_mazeMatrix[i, j])
             *      {
             *          case CellState.VertWeave:
             *              distMatrix[i, j] = (distMatrix[i + 1, j] + distMatrix[i - 1, j]) / 2;
             *              break;
             *          case CellState.HorWeave:
             *              distMatrix[i, j] = (distMatrix[i, j + 1] + distMatrix[i, j - 1]) / 2;
             *              break;
             *      }
             *  }
             * }*/

            if (!draw)
            {
                return(heatMatrix);
            }

            var maxDist = 1;

            for (var i = 0; i < _mazeWidth; i++)
            {
                for (var j = 0; j < _mazeHeight; j++)
                {
                    if (heatMatrix[i, j].Distance > maxDist)
                    {
                        maxDist = heatMatrix[i, j].Distance;
                    }
                }
            }

            for (var i = 0; i < _mazeWidth; i++)
            {
                for (var j = 0; j < _mazeHeight; j++)
                {
                    if (MazeData.MazeMatrix[i, j] == null || MazeData.MazeMatrix[i, j].State == CellState.Wall)
                    {
                        continue;
                    }

                    var   red = heatMatrix[i, j].Distance * 255 / maxDist;
                    Color c;
                    if (heatMatrix[i, j].Distance < 1)
                    {
                        c = MazeData.MazeColors[CellState.Entrance];
                    }
                    else if (heatMatrix[i, j].Distance > maxDist - 1)
                    {
                        c = MazeData.MazeColors[CellState.Furthest];
                    }
                    else
                    {
                        c = Color.FromRgba(50 * 256 * 256 + 50 * 256 + red);
                    }
                    MazeData.MazeMatrix[i, j].Display = c;
                }
            }

            return(heatMatrix);
        }
Exemplo n.º 28
0
        private static void DrawHeatPoint(Graphics Canvas, HeatPoint HeatPoint, int Radius)
        {
            // Create points generic list of points to hold circumference points
            List<Point> CircumferencePointsList = new List<Point>();

            // Create an empty point to predefine the point struct used in the circumference loop
            Point CircumferencePoint;

            // Create an empty array that will be populated with points from the generic list
            Point[] CircumferencePointsArray;

            // Calculate ratio to scale byte intensity range from 0-255 to 0-1
            float fRatio = 1F / Byte.MaxValue;
            // Precalulate half of byte max value
            byte bHalf = Byte.MaxValue / 2;
            // Flip intensity on it's center value from low-high to high-low
            int iIntensity = (byte)(HeatPoint.Intensity - ((HeatPoint.Intensity - bHalf) * 2));
            // Store scaled and flipped intensity value for use with gradient center location
            float fIntensity = iIntensity * fRatio;

            // Loop through all angles of a circle
            // Define loop variable as a double to prevent casting in each iteration
            // Iterate through loop on 10 degree deltas, this can change to improve performance
            for (double i = 0; i <= 360; i += 10)
            {
                // Replace last iteration point with new empty point struct
                CircumferencePoint = new Point();

                // Plot new point on the circumference of a circle of the defined radius
                // Using the point coordinates, radius, and angle
                // Calculate the position of this iterations point on the circle
                CircumferencePoint.X = Convert.ToInt32(HeatPoint.X + Radius * Math.Cos(ConvertDegreesToRadians(i)));
                CircumferencePoint.Y = Convert.ToInt32(HeatPoint.Y + Radius * Math.Sin(ConvertDegreesToRadians(i)));

                // Add newly plotted circumference point to generic point list
                CircumferencePointsList.Add(CircumferencePoint);
            }

            // Populate empty points system array from generic points array list
            // Do this to satisfy the datatype of the PathGradientBrush and FillPolygon methods
            CircumferencePointsArray = CircumferencePointsList.ToArray();

            // Create new PathGradientBrush to create a radial gradient using the circumference points
            PathGradientBrush GradientShaper = new PathGradientBrush(CircumferencePointsArray);
            // Create new color blend to tell the PathGradientBrush what colors to use and where to put them
            ColorBlend GradientSpecifications = new ColorBlend(3);

            // Define positions of gradient colors, use intesity to adjust the middle color to
            // show more mask or less mask
            GradientSpecifications.Positions = new float[3] { 0, fIntensity, 1 };
            // Define gradient colors and their alpha values, adjust alpha of gradient colors to match intensity
            GradientSpecifications.Colors = new Color[3]
            {
                Color.FromArgb(0, Color.White),
                Color.FromArgb(HeatPoint.Intensity, Color.Black),
                Color.FromArgb(HeatPoint.Intensity, Color.Black)
            };

            // Pass off color blend to PathGradientBrush to instruct it how to generate the gradient
            GradientShaper.InterpolationColors = GradientSpecifications;
            // Draw polygon (circle) using our point array and gradient brush
            Canvas.FillPolygon(GradientShaper, CircumferencePointsArray);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Gets the view of a given point
        /// </summary>
        /// <param name="point"></param>
        /// <param name="label"></param>
        /// <returns></returns>
        public override IChartPointView GetPointView(ChartPoint point, string label)
        {
            var pbv = (HeatPoint)point.View;

            if (pbv == null)
            {
                pbv = new HeatPoint
                {
                    IsNew     = true,
                    Rectangle = new Rectangle()
                };

                Model.Chart.View.AddToDrawMargin(pbv.Rectangle);
            }
            else
            {
                pbv.IsNew = false;
                point.SeriesView.Model.Chart.View
                .EnsureElementBelongsToCurrentDrawMargin(pbv.Rectangle);
                point.SeriesView.Model.Chart.View
                .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape);
                point.SeriesView.Model.Chart.View
                .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel);
            }

            pbv.Rectangle.Stroke          = Stroke;
            pbv.Rectangle.StrokeThickness = StrokeThickness;
            pbv.Rectangle.Visibility      = Visibility;
            pbv.Rectangle.StrokeDashArray = StrokeDashArray;

            Canvas.SetZIndex(pbv.Rectangle, Canvas.GetZIndex(pbv.Rectangle));

            if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null)
            {
                pbv.HoverShape = new Rectangle
                {
                    Fill            = new SolidColorBrush(Colors.Transparent),
                    StrokeThickness = 0
                };

                Canvas.SetZIndex(pbv.HoverShape, short.MaxValue);

                var uwpfChart = (Chart)Model.Chart.View;
                uwpfChart.AttachHoverableEventTo(pbv.HoverShape);

                Model.Chart.View.AddToDrawMargin(pbv.HoverShape);
            }

            if (pbv.HoverShape != null)
            {
                pbv.HoverShape.Visibility = Visibility;
            }

            if (DataLabels && pbv.DataLabel == null)
            {
                pbv.DataLabel = UpdateLabelContent(new DataLabelViewModel
                {
                    FormattedText = label,
                    Instance      = point.Instance
                });
                Canvas.SetZIndex(pbv.DataLabel, short.MaxValue - 1);

                Model.Chart.View.AddToDrawMargin(pbv.DataLabel);
            }

            return(pbv);
        }
Exemplo n.º 30
0
    void PopulateMatrices(List <HeatPoint> map)
    {
        if (map == null)
        {
            return;
        }

        m_Properties = new List <MaterialPropertyBlock>();
        m_Matrices   = new List <Matrix4x4[]>();
        Vector3          scale  = Vector3.one;
        List <Vector4[]> colors = new List <Vector4[]>();

        int index = 0;

        for (int a = 0; a < map.Count; a++)
        {
            int mod = a % k_ShapesPerDraw;
            if (mod == 0)
            {
                m_Properties.Add(new MaterialPropertyBlock());
                m_Matrices.Add(new Matrix4x4[k_ShapesPerDraw]);
                colors.Add(new Vector4[k_ShapesPerDraw]);
            }

            Matrix4x4  matrix     = Matrix4x4.identity;
            HeatPoint  pt         = map[a];
            Quaternion quaternion = Quaternion.Euler(pt.rotation);
            matrix.SetTRS(pt.position, quaternion, scale);
            m_Matrices[index][mod] = matrix;

            float pct = (pt.density / m_MaxDensity);
            colors[index][mod] = GradientUtils.PickGradientColor(m_Gradient, pct);

            if (a + 1 % k_ShapesPerDraw == 0)
            {
                index++;
            }
        }

        for (int a = 0; a < m_Properties.Count; a++)
        {
            if (colors[a] != null && colors[a].Length > 0)
            {
                m_Properties[a].SetVectorArray(m_ColorID, colors[a]);
            }
            index++;
        }

//        gameObject.GetComponent<Renderer>().materials = materials;
//        gameObject.GetComponent<HeatmapSubmap>().m_PointData = map;
//        gameObject.GetComponent<HeatmapSubmap>().m_TrianglesPerShape = RenderShapeUtils.GetTrianglesForShape(m_RenderStyle);
//
//        if (m_Tips)
//        {
//            if (gameObject.GetComponent<MeshCollider>() == null)
//            {
//                gameObject.AddComponent<MeshCollider>();
//            }
//
//            go.GetComponent<MeshCollider>().sharedMesh = mesh;
//        }
    }
Exemplo n.º 31
0
        /// <summary>
        /// Inspects the given matrix and sets the series to this matrix M.
        /// </summary>
        /// <param name="M">The matrix to investigate.</param>
        public override void AddPoints(MatrixValue M)
        {
            var p = data;
            var min = double.MaxValue;
            var max = double.MinValue;

            for (var i = 1; i <= M.DimensionX; i++)
            {
                for (var j = 1; j <= M.DimensionY; j++)
                {
                    var value = M[j, i].Abs();

                    p.Add(new HeatPoint
                    {
                        Row = j,
                        Column = i,
                        Magnitude = value
                    });

                    if (value > max)
                        max = value;
                    else if (value < min)
                        min = value;
                }
            }

            var gap = max - min;

            for (var i = 0; i != p.Count; i++)
                p[i] = new HeatPoint { Column = p[i].Column, Row = p[i].Row, Magnitude = (p[i].Magnitude - min) / gap };

            Minimum = min;
            Maximum = max;
            MinX = 1;
            MaxX = M.DimensionX;
            MinY = 1;
            MaxY = M.DimensionY;
        }