[vtkusers] Intersect a ray with a model

T.R.Shashwath trshash at gmail.com
Sun Feb 8 15:47:21 EST 2009


Hi David,

On Sunday 08 Feb 2009 12:52:46 am David Doria wrote:
> The only thing I could find online is this:
>
> vtkCellLocator::IntersectWithLine
>
> But I have some questions:
>
> 1) It says it intersects with a vtkPolyData surface. I have a vtp file
> of triangles that I wrote using ->SetPolys(...).  Is that a
> "vtkPolyData surface"?

Read the vtp file into a vtkPolyData object using the appropriate reader. That 
will give you the right object to do this with.

> 2) What is this vtkCellLocator business? ie. how do I actually call
> this function IntersectWithLine?

vtkCellLocator and vtkOBBTree will help you with this... Both do the same job, 
but OBBTree is a whole lot faster, except that it works only with polydata.

Use it like this:

1) Create a cell locator (or OBB tree) object
2) Set your model as the input using SetDataSet(...)
3) Call BuildLocator() to initialize the object.
4) Use IntersectWithLine. 

In OBBTree, the syntax is int IntersectWithLine (const double a0[3], const 
double a1[3], vtkPoints *points, vtkIdList *cellIds);

The values a0 and a1 are the endpoints of the line, and points and cellIds are 
the outputs containing the points and cells that the line intersects with. You 
should create them (using vtkPoints::New() and vtkIdList::New()) before 
sending them in. The locator will fill them for you. The return value 
indicates whether the line intersected or not (0), and whether the point is 
inside or outside the surface (-1, 1).

I haven't used vtkCellLocator much in this context, so I don't know how to do 
that. OBBTree serves my purpose, anyway.

HTH
Shash



More information about the vtkusers mailing list