[vtkusers] problem with vtkPicker(vtkCellPicker, vtkPointPicker)

Shady Shidfar shady_shidfar at yahoo.com
Wed Sep 24 10:28:50 EDT 2008


Hi Everyone,
I'm using vtkPicker to pick cells on an image and draw on the image. I've copied a short version of my program. I'm using vtkDotNet and managedItk. I want to draw lines through the picked points on a 2d tif image. Key 'p' is used to pick a point. The lines need to remain in the same place they've been drawn no matter zooming or rotating. The problem is :
1- When I zoom the image and get the picked cell dimension, Z would be a value rather than 0 which I don't understand why.
2- When I rotate the image and pick the points and draw lines. It seems they are in the right place but when I rotate the image the lines would be somewhere outside the image. 
 
I'm using picker.GetPickPosition() to get the dimension of the picked point. I'd probably need to change this. Does anyone know how I can fix the problem? Any suggestions would be a great help
 
Thanks
Shaadi

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Collections;usingvtk;usingitk;namespace
{InteractiveHierarchicalSegmentationDotNet.TestpublicpartialclasstestPicking: Form{
{
InitializeComponent();
vtkFormsWindowControl1.GetRenderWindow().AddRenderer(renderer);
viewImage();
picker = 
picker.PickFromListOn(); vtkCellPickerpicker;vtkRendererrenderer = newvtkRenderer();publictestPicking()newvtkCellPicker();// to make sure picker won't pick props instead of cellspicker.AddObserver((
vtkFormsWindowControl1.GetInteractor().SetPicker(picker);
}
{
{
pointsDataGridView.Rows.Add();
pointsDataGridView.Rows[pointsDataGridView.RowCount - 1].Cells[0].Value = xp;
pointsDataGridView.Rows[pointsDataGridView.RowCount - 1].Cells[1].Value = yp;
pointsDataGridView.Rows[pointsDataGridView.RowCount - 1].Cells[2].Value = zp;uint)vtk.EventIds.EndPickEvent, newvtk.vtkDotNetCallback(annotatePick));privatevoidannotatePick(vtk.vtkObjectcaller, uinteventId,objectclientData, IntPtrcallData)vtkActor2DtextActor = newvtkActor2D();double[] selPt = picker.GetSelectionPoint();doublex = selPt[0];doubley = selPt[1];double[] pickPos = picker.GetPickPosition();doublexp = pickPos[0];doubleyp = pickPos[1];doublezp = pickPos[2];double[] newPoint = newdouble[] { xp, yp, zp };double[] previousPoint = newdouble[3];{if(pointsDataGridView.Rows.Count == 1)previousPoint = newPoint;
}else{// retrieve the previous rowpreviousPoint[0] = pxp;
previousPoint[1] = pyp;
previousPoint[2] = pzp;
}
createLine(previousPoint, newPoint);
vtkFormsWindowControl1.Refresh();
}
}
{
VTKpoints.SetNumberOfPoints(2);doublepxp = Convert.ToDouble(pointsDataGridView.Rows[pointsDataGridView.Rows.Count - 2].Cells[0].Value);doublepyp = Convert.ToDouble(pointsDataGridView.Rows[pointsDataGridView.Rows.Count - 2].Cells[1].Value);doublepzp = Convert.ToDouble(pointsDataGridView.Rows[pointsDataGridView.Rows.Count - 2].Cells[2].Value);intr = 1, g = 0, b = 0;privatevoidcreateLine(double[] startPoint, double[] endPoint)vtkPointsVTKpoints = newvtkPoints();VTKpoints.InsertPoint(0, startPoint[0], startPoint[1], startPoint[2]);
VTKpoints.InsertPoint(1, endPoint[0], endPoint[1], endPoint[2]);
 
line.GetPointIds().SetId(0, 0);
line.GetPointIds().SetId(1, 1);
grid.Allocate(1, 1);
grid.InsertNextCell(line.GetCellType(), line.GetPointIds());
grid.SetPoints(VTKpoints);
aLineMapper.SetInput(grid);
aLineActor.SetMapper(aLineMapper);
aLineActor.AddPosition(0, 0, 0);
aLineActor.GetProperty().SetDiffuseColor(1, 0, 0);
renderer.AddActor(aLineActor);
vtkFormsWindowControl1.GetRenderWindow().AddRenderer(renderer);
}
{vtkLineline = newvtkLine();vtkUnstructuredGridgrid = newvtkUnstructuredGrid();vtkDataSetMapperaLineMapper = newvtkDataSetMapper();vtkActoraLineActor = newvtkActor();privatevoidviewImage()try{
input.Read(itkImage_UC3input = itkImage_UC3.New();"C:/brain.tif");// Import ITK image to VTKitk2vtk.SetInput(input);
itk2vtk.Update();
imageFlip.SetFilteredAxis(1);
imageFlip.SetInput(data);
vtk.
imageActor.SetInput(imageFlip.GetOutput());
renderer.AddActor(imageActor);
vtkFormsWindowControl1.Update();
}
{
}
}
}
}itkImageToVTKImageFilter_IUC3itk2vtk =itkImageToVTKImageFilter_IUC3.New();vtkImageDatadata = itk2vtk.GetOutput();vtkImageFlipimageFlip = newvtkImageFlip();vtkImageActorimageActor = newvtkImageActor();catch(Exceptionex)Console.WriteLine(ex);


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080924/f1bbe05e/attachment.htm>


More information about the vtkusers mailing list