/*============================================================================= Project: SharpImage Module: siFormSelectSeeds.cs Language: C# Author: Dan Mueller Date: $Date: 2007-07-06 10:57:00 +1000 (Fri, 06 Jul 2007) $ Revision: $Revision: 2 $ Copyright (c) Queensland University of Technology (QUT) 2007. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =============================================================================*/ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using SharpImage.Rendering; namespace SharpImage.Forms { public partial class siFormSelectSeeds : siFormTool { private siPointsSelection m_PointsSelection; public siFormSelectSeeds(siRenderer renderer) : base(renderer) { InitializeComponent(); // Add Form handlers this.FormClosed += new FormClosedEventHandler(FormSelectSeeds_FormClosed); // Add Actor this.m_PointsSelection = new siPointsSelection(); this.PointsSelection.EnterAdditionMode(); this.PointsSelection.PointAdded += new siPointsSelection.siPointsHandler(PointsSelection_PointAdded); this.PointsSelection.PointSelected += new siPointsSelection.siPointsHandler(PointsSelection_PointSelected); this.PointsSelection.ExitedAdditionMode += new siActor.siActorHandler(PointsSelection_ExitedAdditionMode); this.Renderer.AddActorToFront(this.PointsSelection); } /// /// Gets the siSeedSelector Actor associated with this form. /// public siPointsSelection PointsSelection { get { return this.m_PointsSelection; } } /// /// Gets the list of points. /// public List Points { get { return this.m_PointsSelection.Points; } } void FormSelectSeeds_FormClosed(object sender, FormClosedEventArgs e) { // Remove renderer handlers this.Renderer.RemoveActor(this.m_PointsSelection); this.PointsSelection.PointAdded -= new siPointsSelection.siPointsHandler(PointsSelection_PointAdded); this.PointsSelection.PointSelected -= new siPointsSelection.siPointsHandler(PointsSelection_PointSelected); } void PointsSelection_PointSelected(siPointsSelection sender, itk.itkPoint point) { foreach (ListViewItem item in this.listPoints.Items) { if (item.Tag as itk.itkPoint == point) item.Selected = true; else item.Selected = false; } } void PointsSelection_PointAdded(siPointsSelection sender, itk.itkPoint point) { itk.itkImageBase input = this.Renderer.Inputs[0] as itk.itkImageBase; itk.itkIndex index; input.TransformPhysicalPointToIndex(point, out index); ListViewItem item = new ListViewItem(index.ToString()); item.Tag = point; item.SubItems.Add(input.GetPixel(index).ToString()); this.listPoints.Items.Add(item); item.Selected = true; } void PointsSelection_ExitedAdditionMode(siActor sender) { this.PointsSelection.EnterAdditionMode(); } private void cmdClear_Click(object sender, EventArgs e) { this.PointsSelection.ClearPoints(); this.listPoints.Items.Clear(); } protected override void OnContinue(object sender, ContinueEventArgs e) { if (this.Points.Count >= 1) base.OnContinue(sender, e); else { string caption = "No points were selected"; string text = "No points were selected. At least one point must be chosen."; this.ParentApplication.ShowMessageBox(text, caption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); e.SuppressContinue = true; return; } } private void menuItemRemove_Click(object sender, EventArgs e) { this.RemoveSelectedPoint(); } private void listSeeds_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete || e.KeyCode == Keys.Back || e.KeyCode == Keys.D) this.RemoveSelectedPoint(); } private void RemoveSelectedPoint() { if (this.listPoints.Items.Count > 0 && this.listPoints.SelectedItems.Count > 0) { itk.itkPoint point = this.listPoints.SelectedItems[0].Tag as itk.itkPoint; this.PointsSelection.RemovePoint(point); this.listPoints.Items.Remove(this.listPoints.SelectedItems[0]); this.listPoints.SelectedIndices.Clear(); } if (this.listPoints.SelectedItems.Count == 0) this.PointsSelection.SelectPoint(null); } private void listSeeds_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { if (e.IsSelected) this.PointsSelection.SelectPoint((itk.itkPoint)e.Item.Tag); else this.PointsSelection.SelectPoint(null); } } }