static void Main(string[] args) { List <Point> testData = new List <Point>(); //Generate random data for the heat mapper. Random random = new Random((int)System.DateTime.Now.ToFileTime()); for (int i = 0; i < 10000; i++) { testData.Add(new Point(random.Next(0, 1920), random.Next(0, 1080))); } //Set up the factory and run the GetHeatMap function. HeatmapFactory map = new HeatmapFactory(); map.OpenOnComplete = true; map.InputMax = new Point(1920, 1080); map.OutputResolution = new Point(1920, 1080); map.SaveLocation = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\HeatMap.png"; //map.ColorFunction = HeatmapFactory.GrayScale; map.ColorFunction = HeatmapFactory.BasicColorMapping; map.GetHeatMap(testData); Console.ReadKey(); }
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(); } }