[vtkusers] cell picking problem
Greg Book
gbook at gbook.org
Fri Jul 31 12:08:31 EDT 2009
I'm creating a 3D tracing application to get polygonal models from 3D Dicom
images. I'm able to click points and create contour lines between those
points. I'm now trying to connect points between the contour lines to create
a 3D mesh. I have a single vtkPolyData object that contains all the
points/cells/lines. My problem is that the pick event returns a cell id of 0
most of the time, and always crashes eventually when doing the Pick().
Here is the code from the picker (I created it as an observer on a
vtkImagePlaneWidget):
vtkRenderer *m_ren1,
wxVTKRenderWindowInteractor *m_vtkWindow,
void ObserverMousePicker::Execute(vtkObject *caller, unsigned long event,
void*)
{
double *p;
vtkIdType pid;
frame->cellPicker->Pick(m_vtkWindow->GetEventPosition()[0],
m_vtkWindow->GetEventPosition()[1], 0.0, m_ren1);
vtkIdType cid = frame->cellPicker->GetCellId();
/* get the current cursor position and create a new point */
p = m_planeWidgetZ->GetCurrentCursorPosition();
pid = m_points->InsertNextPoint(p);
/* check if were creating a new contour */
if (frame->newContour) {
log->WriteLog("This should be a new contour");
frame->newContour = false;
}
else { /* otherwise connect the current and previous points */
if (m_points->GetNumberOfPoints() > 1) {
frame->lines->InsertNextCell(2);
frame->lines->InsertCellPoint(pid-1);
log->WriteLog(wxString::Format("Inserted cell %d",pid-1));
frame->lines->InsertCellPoint(pid);
log->WriteLog(wxString::Format("Inserted cell %d",pid));
}
}
/* insert the next cell in the poly and draw it */
m_conn->InsertNextCell(1, &pid);
m_poly->Modified();
m_vtkWindow->Render();
log->WriteLog(wxString::Format("%f\t%f\t%f", p[0], p[1], p[2]));
}
Again, it almost always picks a cell ID of zero, even when I click in the
same general spot repeatedly (maybe a tolerance thing?). More problematic is
that it always crashes at the Pick() function if I click enough times.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090731/878b81fe/attachment.htm>
More information about the vtkusers
mailing list