private Point CalculateHotSpot(ImageAnalyzer.Region r) { Point geoAverage = new Point(); // Geometric Average Point hotSpot; Point left, right, top, bottom; int turn = 0; // Check geometric average geoAverage.X = r.GeometricSum.X / r.Pixels.Count; geoAverage.Y = r.GeometricSum.Y / r.Pixels.Count; if (ImageAnalyzerObject.Pixels[geoAverage.X, geoAverage.Y].Region.ColorID == r.ColorID) { return(geoAverage); } int s = 0; foreach (ImageAnalyzer.CPoint p in r.Pixels) { s += p.X; } // Check left, top, right and bottom point of geoAverage bool notFound = true; left = top = right = bottom = hotSpot = geoAverage; while (notFound) { switch (turn) { case 0: // Left if (left.X > r.Boundaries.X) { left.X -= 1; if (ImageAnalyzerObject.Pixels[left.X, left.Y].Region.ColorID == r.ColorID) { hotSpot = left; notFound = false; // HotSpot found } } break; case 1: // Top if (top.Y > r.Boundaries.Y) { top.Y -= 1; if (ImageAnalyzerObject.Pixels[top.X, top.Y].Region.ColorID == r.ColorID) { hotSpot = top; notFound = false; // HotSpot found } } break; case 2: // Right if (right.X < r.Boundaries.Right - 1) { right.X += 1; if (ImageAnalyzerObject.Pixels[right.X, right.Y].Region.ColorID == r.ColorID) { hotSpot = right; notFound = false; // HotSpot found } } break; case 3: // Bottom if (bottom.Y < r.Boundaries.Bottom - 1) { bottom.Y += 1; if (ImageAnalyzerObject.Pixels[bottom.X, bottom.Y].Region.ColorID == r.ColorID) { hotSpot = bottom; notFound = false; // HotSpot found } } break; } // Change direction turn++; if (turn == 4) { turn = 0; } } return(hotSpot); }
private void picOutput_MouseMove(object sender, MouseEventArgs e) { Point p; p = ImageAnalyzerObject.GetOriginalPixelLocation( (int)(e.X / _zoomScale), (int)(e.Y / _zoomScale)); // If mouse does not leave the current cell, we should do nothing. if (p.X == _mouseInfo.OriginalPixelLocation.X && p.Y == _mouseInfo.OriginalPixelLocation.Y) { return; } else { _mouseInfo.OriginalPixelLocation = p; } if (p.X == -1) { // Mouse is in border area of output image lblStatusLeft.Text = ""; } else { if (ImageAnalyzerObject.HighlightRegions) { ImageAnalyzer.Region previouslyHighlightedRegion = ImageAnalyzerObject.HighlightedRegion; ImageAnalyzer.Region r = ImageAnalyzerObject.Pixels[p.X, p.Y].Region; ImageAnalyzerObject.HighlightedRegion = r; // Invalidate picOutput picOutput.Invalidate(ImageAnalyzerObject.GetRegionBoundariesOnOutputImage(r.Boundaries, _zoomScale)); if (previouslyHighlightedRegion != null) { picOutput.Invalidate(ImageAnalyzerObject.GetRegionBoundariesOnOutputImage(previouslyHighlightedRegion.Boundaries, _zoomScale)); } } #region Update Left Status Bar _tmpStrBuilder.Remove(0, _tmpStrBuilder.Length);//_tmpStrBuilder.Clear(); _tmpStrBuilder.Append("XY={"); _tmpStrBuilder.Append(p.X + 1); _tmpStrBuilder.Append(", "); _tmpStrBuilder.Append(ImageAnalyzerObject.Input.Height - p.Y); _tmpStrBuilder.Append("} RGBA={"); _tmpStrBuilder.Append(ImageAnalyzerObject.Pixels[p.X, p.Y].Color.R); _tmpStrBuilder.Append(", "); _tmpStrBuilder.Append(ImageAnalyzerObject.Pixels[p.X, p.Y].Color.G); _tmpStrBuilder.Append(", "); _tmpStrBuilder.Append(ImageAnalyzerObject.Pixels[p.X, p.Y].Color.B); _tmpStrBuilder.Append(", "); _tmpStrBuilder.Append(ImageAnalyzerObject.Pixels[p.X, p.Y].Color.A); _tmpStrBuilder.Append("} ColorID={"); _mouseInfo.ColorID = ImageAnalyzerObject.UsedColors[ImageAnalyzerObject.Pixels[p.X, p.Y].Color.ToArgb()]; _tmpStrBuilder.Append(_mouseInfo.ColorID); _tmpStrBuilder.Append("}"); lblStatusLeft.Text = _tmpStrBuilder.ToString(); #endregion } #region Pan Image if ((e.Button == System.Windows.Forms.MouseButtons.Left) && (_selectedTool == Tool.Pan)) { int deltaX = _mouseInfo.PanStartLocation.X - e.X; int deltaY = _mouseInfo.PanStartLocation.Y - e.Y; tabOutputImage.AutoScrollPosition = new Point( deltaX - tabOutputImage.AutoScrollPosition.X, deltaY - tabOutputImage.AutoScrollPosition.Y); } #endregion }