Exemplo n.º 1
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.º 2
0
        List<HeatPoint> randomPoints(int width, int height, int count)
        {
            var 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;

                var point = new HeatPoint
                {
                    X = x,
                    Y = y,
                    W = 1
                };

                result.Add(point);
            }

            return result;
        }
        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);
        }
        protected override void DrawCore(IEnumerable <Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection <SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection <SimpleCandidate> labelsInAllLayers)
        {
            Bitmap       intensityBitmap = null;
            Bitmap       colorBitmap     = null;
            GeoImage     geoImage        = null;
            MemoryStream pngStream       = null;

            try
            {
                // Load the default color palette if it does not exisit
                // or does not have the right amount of colors
                if (colorPalette.Count != 256)
                {
                    colorPalette = GetDefaultColorPalette();
                }

                intensityBitmap = new Bitmap(Convert.ToInt32(canvas.Width), Convert.ToInt32(canvas.Height));
                Graphics Surface = Graphics.FromImage(intensityBitmap);
                Surface.Clear(Color.Transparent);
                Surface.Dispose();

                List <HeatPoint> heatPoints = new List <HeatPoint>();

                foreach (Feature feature in features)
                {
                    if (feature.GetWellKnownType() == WellKnownType.Point)
                    {
                        PointShape   pointShape  = (PointShape)feature.GetShape();
                        ScreenPointF screenPoint = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, pointShape, canvas.Width, canvas.Height);

                        double realValue;
                        if (intensityRangeStart != 0 && intensityRangeEnd != 0 && intensityRangeStart != intensityRangeEnd && intensityColumnName != string.Empty)
                        {
                            if (intensityRangeStart < intensityRangeEnd)
                            {
                                realValue = (255 / (intensityRangeEnd - intensityRangeStart)) * (GetDoubleValue(feature.ColumnValues[intensityColumnName], intensityRangeStart, intensityRangeEnd) - intensityRangeStart);
                            }
                            else
                            {
                                realValue = (255 / (intensityRangeEnd - intensityRangeStart)) * (intensityRangeEnd - GetDoubleValue(feature.ColumnValues[intensityColumnName], intensityRangeStart, intensityRangeEnd));
                            }
                        }
                        else
                        {
                            realValue = intensity;
                        }

                        HeatPoint heatPoint = new HeatPoint(Convert.ToInt32(screenPoint.X), Convert.ToInt32(screenPoint.Y), Convert.ToByte(realValue));
                        heatPoints.Add(heatPoint);
                    }
                }


                //Calls the function to get the pixel size of the point based on the world point size and the current extent of the map.
                float size = GetPointSize(canvas);


                // Create the intensity bitmap
                intensityBitmap = CreateIntensityMask(intensityBitmap, heatPoints, Convert.ToInt32(size));

                // Color the intensity bitmap
                colorBitmap = Colorize(intensityBitmap, (byte)alpha, colorPalette);

                // Create a geoimage from the color bitmap
                pngStream = new MemoryStream();
                colorBitmap.Save(pngStream, System.Drawing.Imaging.ImageFormat.Png);
                geoImage = new GeoImage(pngStream);

                // Write the geoimage to the canvas
                canvas.DrawWorldImageWithoutScaling(geoImage, canvas.CurrentWorldExtent.GetCenterPoint().X, canvas.CurrentWorldExtent.GetCenterPoint().Y, DrawingLevel.LevelOne);
            }
            finally
            {
                // Make sure we clean up all the memeory that we use durring the process
                if (intensityBitmap != null)
                {
                    intensityBitmap.Dispose();
                }
                if (colorBitmap != null)
                {
                    colorBitmap.Dispose();
                }
                if (geoImage != null)
                {
                    geoImage.Dispose();
                }
                if (pngStream != null)
                {
                    pngStream.Dispose();
                }
            }
        }