public override void OnFileNameChanged(string filePath) { if (filePath.ToLower().EndsWith(".bmp") || filePath.ToLower().EndsWith(".jpg") || filePath.ToLower().EndsWith(".png") || filePath.ToLower().EndsWith(".tif") || filePath.ToLower().EndsWith(".gif")) { if (pbxPreview.Image != null) pbxPreview.Image.Dispose(); try { FileInfo fi = new FileInfo(filePath); pbxPreview.Image = Bitmap.FromFile(filePath); lblSizeValue.Text = (fi.Length / 1024).ToString() + "KB"; lblColorsValue.Text = GetColorsCountFromImage(pbxPreview.Image); lblFormatValue.Text = GetFormatFromImage(pbxPreview.Image); } catch(Exception){} } else if (filePath.ToLower().EndsWith(".ppm")) { if (pbxPreview.Image != null) pbxPreview.Image.Dispose(); try { FileInfo fi = new FileInfo(filePath); PixelMap.PixelMap pm = new PixelMap.PixelMap(filePath); pbxPreview.Image = pm.BitMap; lblSizeValue.Text = (fi.Length / 1024).ToString() + "KB"; lblColorsValue.Text = GetColorsCountFromImage(pbxPreview.Image); lblFormatValue.Text = GetFormatFromImage(pbxPreview.Image); } catch (Exception) { } } else { if (pbxPreview.Image != null) pbxPreview.Image.Dispose(); pbxPreview.Image = null; } }
private void mapViewOpenFileDialog_FileOk(object sender, CancelEventArgs e) { try { workingPath = System.IO.Path.GetDirectoryName(this.mapViewOpenFileDialog.FileName); infoMgr.LoadFile(this.mapViewOpenFileDialog.FileName); this.mapFilepath = System.IO.Path.Combine(workingPath, infoMgr.mapFilename); this.pixelMap = new PixelMap.PixelMap(this.mapFilepath); //this.mapViewPictureBox.BackgroundImage = this.pixelMap.GreyMap; this.mapViewPictureBox.BackgroundImage = this.pixelMap.GetTransparentMap(50); this.mapViewPictureBox.Size = new Size(this.pixelMap.Header.Width, this.pixelMap.Header.Height); this.mapViewPanel.Size = this.mapViewPictureBox.Size; this.mapViewPanel.AutoScroll = true; this.toolbarForm.Visible = true; this.mapToolStripMenuItem.Checked = true; this.saveToolStripMenuItem.Enabled = true; this.widthNum = (int)this.pixelMap.Header.Width / (paramMgr.hexagonalSize); this.heightNum = (int)(this.pixelMap.Header.Height / (Math.Sqrt(2) * paramMgr.hexagonalSize / 2)); this.map = new HexagonalMap(this.widthNum, this.heightNum, paramMgr.hexagonalSize, HexOrientation.Pointy); this.mapDrawer = new HexagonalMapDrawer(this.map); Random rnd = new Random(); for (int i = 0; i < this.widthNum; i++) { for (int j = 0; j < this.heightNum; j++) { //this.map.MapState.hexVals[i, j] = rnd.NextDouble(); this.map.MapState.hexVals[i, j] = this.infoMgr.GetDiffusionValue(i, j); } } this.map.MapState.NormalizeHexVal(); //this.map.MapState.DumpHexValToFile("test.csv"); for (int i = 0; i < this.widthNum; i++) { for (int j = 0; j < this.heightNum; j++) { this.map.GetMapStateMgr().SetEntropy(i, j, this.map.MapState.hexVals[i, j]); } } /* * for (int i = 0; i < this.pixelMap.BitMap.Width; i++) * { * for (int j = 0; j < this.pixelMap.BitMap.Height; j++) * { * Color c = this.pixelMap.BitMap.GetPixel(i, j); * Console.WriteLine("[" + i.ToString() + "," + j.ToString() + "]:" + c.R.ToString() + " " + c.G.ToString() + " " + c.B.ToString()); * * } * } */ for (int i = 0; i < this.map.mapWidth; i++) { for (int j = 0; j < this.map.mapHeight; j++) { List <System.Drawing.PointF> points = this.map.GetHex(i, j).inPointSet; int obsCnt = 0; List <System.Drawing.PointF> .Enumerator eP = points.GetEnumerator(); while (eP.MoveNext()) { int tX = (int)System.Math.Floor(eP.Current.X); int tY = (int)System.Math.Floor(eP.Current.Y); int bW = this.pixelMap.BitMap.Width; int bH = this.pixelMap.BitMap.Height; if (tX > (bW - 1)) { tX = bW - 1; } if (tY > (bH - 1)) { tY = bH - 1; } Color tColor = this.pixelMap.BitMap.GetPixel(tX, tY); if ((int)tColor.R < 200 || (int)tColor.G < 200 || (int)tColor.B < 200) { obsCnt++; } } //if (obsCnt * 2 > points.Count) if (obsCnt > 0) { this.map.mapState.AddObstalce(this.map.GetHex(i, j)); } } } robot = new Robot(map); this.pathMgr = new PathManager(map, infoMgr.mapFilename); } catch (Exception ex) { ShowException(ex); } }
private void openDataFileDialog_FileOk(object sender, CancelEventArgs e) { this.dataFilepath = this.openDataFileDialog.FileName; this.dataPixelMap = new PixelMap.PixelMap(this.dataFilepath); this.mapViewPictureBox.BackgroundImage = dataPixelMap.GreyMap; int dataPixelMapWidth = this.dataPixelMap.BitMap.Width; int dataPixelMapHeight = this.dataPixelMap.BitMap.Height; Bitmap greyMap = this.dataPixelMap.GreyMap; for (int i = 0; i < this.widthNum; i++) { for (int j = 0; j < this.heightNum; j++) { Hex h = this.map.GetHex(i, j); float val = 0; for (int k = 0; k < h.inPointSet.Count; k++) { int h_p_x = (int)h.inPointSet[k].X; int h_p_y = (int)h.inPointSet[k].Y; if (h_p_x < 0) { h_p_x = 0; } if (h_p_x >= dataPixelMapWidth) { h_p_x = dataPixelMapWidth - 1; } if (h_p_y < 0) { h_p_y = 0; } if (h_p_y >= dataPixelMapHeight) { h_p_y = dataPixelMapHeight - 1; } Color h_p_color = greyMap.GetPixel(h_p_x, h_p_y); //val += (float)((h_p_color.R * .3) + (h_p_color.G * .59) + (h_p_color.B * .11)); val += (float)h_p_color.R; } /* * int h_p_x = (int)h.centroid.X; * int h_p_y = (int)h.centroid.Y; * * if (h_p_x < 0) * { * h_p_x = 0; * } * if (h_p_x >= dataPixelMapWidth) * { * h_p_x = dataPixelMapWidth - 1; * } * if (h_p_y < 0) * { * h_p_y = 0; * } * if (h_p_y >= dataPixelMapHeight) * { * h_p_y = dataPixelMapHeight - 1; * } * Color h_p_color = greyMap.GetPixel(h_p_x, h_p_y); * * Console.WriteLine("x:" + h_p_x.ToString() + " y:" + h_p_y.ToString() + " " + h_p_color.R.ToString()); * val = (float)h_p_color.R; */ this.map.MapState.hexVals[i, j] = val; } } this.map.MapState.NormalizeHexVal(); for (int i = 0; i < this.widthNum; i++) { for (int j = 0; j < this.heightNum; j++) { this.map.GetMapStateMgr().SetEntropy(i, j, this.map.MapState.hexVals[i, j]); } } this.Refresh(); }