[vtkusers] Correct implementation of vtkImageData -> FindCell (...)

Jake Nickel jake.nickel at gmail.com
Tue Jan 22 23:16:10 EST 2008


Hi All,

I have an application that uses ITK, VTK, and KWWidgets to display a 3D
surface created from a dataset and its 3 corresponding orthogonal views.  I
have a subclass of vtkInteractorStyle that listens for events on the
orthogonal slices.  When I left click on one of them, I would like to find
the nearest cell associated with the picked location.  I am using the
following code:

/********************begin code**********************/
...
  //double p[3] is initialized
...
  vtkEmptyCell * femptycell = vtkEmptyCell::New();
  vtkCell * fcell = femptycell->NewInstance();
  vtkIdType fcellID;
  double ftol2;
  int fsubId;
  double fpcoords[3];
  double * fweights;

  vtkIdType fFindCell = [instance of vtkImageData *]->FindCell(p, fcell,
fcellID, ftol2, fsubId, fpcoords, fweights);

  std::cout << "cellID returned from FindCell() = " << fFindCell <<
std::endl;
/********************end code**********************/

When I click on one of the orthogonal slices, my application successfully
prints out the cellId, for instance:

"cellID returned from FindCell() = 42196578"

However, it then crashes with a Segmentation Fault.  I have narrowed the
problem down to this chunk of code because when I replace it with similar
code to compute the cell ID (pasted below), it runs fine without any seg
fault.

/********************begin code**********************/
...
  //int ijk[3] is initialized
...
  vtkIdType compCellId;
  compCellId = [instance of vtkImageData *]->ComputeCellId( ijk );
  std::cout << "Computed Cell Id = " << compCellId << std::endl;
/********************end code**********************/

Does anyone see a problem with my first code segment that tries to find the
cell associated with an X, Y, Z location?  Thanks in advance for any
assistance!

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


More information about the vtkusers mailing list