/// <summary> /// A heat mask where the heat intensity falls off as 1 / distance from the center point. /// </summary> /// <param name="xRadius"></param> /// <param name="yRadius"></param> /// <returns></returns> public static HeatMask LinearFalloff(int xRadius, int yRadius) { HeatMask heatMask; float[][] heatMaskArray = new float[(xRadius * 2) + 1][]; for (int i = 0; i < (xRadius * 2) + 1; i++) { heatMaskArray[i] = new float[(yRadius * 2) + 1]; } for (int i = -xRadius; i <= xRadius; i++) { for (int j = -yRadius; j <= yRadius; j++) { float distance; if (i == 0 && j == 0) { distance = 1; } else { distance = (float)Math.Sqrt(Math.Pow(i, 2) + Math.Pow(j, 2)); } heatMaskArray[i + xRadius][j + xRadius] = (1 / distance); } } heatMask = new HeatMask(xRadius, yRadius, heatMaskArray); /* * for (int i = -xRadius; i < xRadius; i++) * { * for (int j = -yRadius; j < yRadius; j++) * { * Console.Write(heatMask.value(i, j)); * } * Console.WriteLine(); * Console.WriteLine(); * } */ return(heatMask); }
public void GetHeatMap(List <Point> points) { if (SaveLocation == null) { Console.WriteLine("You must specifiy a save location for the Heatmap output. fn:GetHeatMap aborted."); return; } if (InputMax == null) { InputMax = new Point(1920, 1080); Console.WriteLine("No max input value specified. Defaulting to 1920:1080."); } //TODO Scale down the input to output resolution if it is larger. if (OutputResolution == null) { OutputResolution = new Point(1920, 1080); Console.WriteLine("No resolutin specified. Defaulting to 1920:1080."); } if (HeatFunction == null) { Console.WriteLine("No HeatFunction mapper specified. Defaulting to Identity."); HeatFunction = (f => f); } if (ColorFunction == null) { Console.WriteLine("No ColorFunction mapper specified. Defaulting to Gray Scale."); ColorFunction = HeatmapFactory.GrayScale; } if (HeatMask == null) { Console.WriteLine("No HeatMask specified. Defaulting to linear falloff with xRadius = 20 and yRadius = 20."); HeatMask = HeatmapFactory.LinearFalloff(40, 40); } //Heatbin is used as a value store for heat resutling from point inputs. int[][] Heatbin = new int[OutputResolution.X][]; for (int i = 0; i < OutputResolution.X; i++) { Heatbin[i] = new int[OutputResolution.Y]; } //Initialize Heatbin for (int i = 0; i < OutputResolution.X; i++) { for (int j = 0; j < OutputResolution.Y; j++) { Heatbin[i][j] = 0; } } //Test the input to make sure its in the right format. CheckInput(points); AssignHeat(Heatbin, points); float[][] normalized = NormalizedHeatbin(Heatbin); Bitmap output = GetBitmap(normalized); //TODO This is filty. Don't be filty. using (FileStream f = File.Open(SaveLocation, FileMode.Create)) { output.Save(f, ImageFormat.Png); } Console.WriteLine("Bitmap created and saved to " + SaveLocation); if (OpenOnComplete) { Process myProc = new Process(); myProc.StartInfo.FileName = SaveLocation; myProc.Start(); } }