/// <summary> /// Default constructor /// </summary> public MainForm() { InitializeComponent(); package = new Package(); patternImageView = new ImageCanvas(this); columnProfileView = new ProfileCanvas(); rowProfileView = new ProfileCanvas(); panelImage.Controls.Add(patternImageView); panelColumnProfile.Controls.Add(columnProfileView); panelRowProfile.Controls.Add(rowProfileView); MaximumSize = MinimumSize = Size; profilesPoint = new Location(); RefreshAll(); }
/// <summary> /// Gets average intensity value for square with 2*radius+1 edge and center in point /// </summary> /// <param name="point">Center point of square</param> /// <param name="radius">Distance from center to edge</param> public byte PointAverageIntensity(Location point, int radius) { int sum = 0, count = 0; for (int x = point.x - radius; x <= point.x + radius; x++) { if (x < 0 || x >= width) continue; for (int y = point.y - radius; y <= point.y + radius; y++) { if (y < 0 || y >= height) continue; sum += useSmoothed ? smoothed[x, y] : matrix[x, y]; count++; } } return (byte)(sum / count); }
/// <summary> /// Moves profiles point to the mouse position /// </summary> /// <param name="newPoint">Location from the upper-left window corner</param> private void MoveProfilesPoint(Location newPoint) { parent.profilesPoint = newPoint - new Location(this.Location); parent.RefreshProfiles(); Invalidate(); }
/// <summary> /// Refresh profiles view /// </summary> private void RefreshProfiles() { // enable or disable profiles if (Empty) groupBoxProfiles.Enabled = false; else groupBoxProfiles.Enabled = true; if (Empty && ProfilesSelected) { checkBoxProfiles.Checked = false; } else if (ProfilesSelected) { Pattern current = package.CurrentPattern; patternImageView.Select(); // draw profile views if (!profilesPoint.exists) profilesPoint = new Location(current.Width / 2, current.Height / 2); byte[] columnProfile = current.ColumnProfile(profilesPoint.x); byte[] rowProfile = current.RowProfile(profilesPoint.y); columnProfileView.DrawProfile(columnProfile, false); panelColumnProfile.Invalidate(); rowProfileView.DrawProfile(rowProfile, true); // show numeric values labelColumnProfile.Text = string.Format("X : {0}", profilesPoint.x); labelRowProfile.Text = string.Format("Y : {0}", profilesPoint.y); labelIntensity1x1.Text = string.Format("1 x 1 : {0}", current.PointAverageIntensity(profilesPoint, 0)); labelIntensity3x3.Text = string.Format("3 x 3 : {0}", current.PointAverageIntensity(profilesPoint, 1)); labelIntensity5x5.Text = string.Format("5 x 5 : {0}", current.PointAverageIntensity(profilesPoint, 2)); } else { // hide profile views columnProfileView.Clear(); rowProfileView.Clear(); patternImageView.Invalidate(); // hide numeric values labelColumnProfile.Text = "X :"; labelRowProfile.Text = "Y :"; labelIntensity1x1.Text = "1 x 1 :"; labelIntensity3x3.Text = "3 x 3 :"; labelIntensity5x5.Text = "5 x 5 :"; } }
/// <summary> /// Location constructor /// </summary> /// <param name="location">Location to construct from</param> public Location(Location location) { x = location.x; y = location.y; exists = location.exists; }