[vtkusers] getting point colour (was: intersecting 3D mesh with a line)
David Doria
daviddoria+vtk at gmail.com
Thu Feb 25 09:13:57 EST 2010
On Thu, Feb 25, 2010 at 7:20 AM, Andrea Bottino <andrea.bottino at polito.it>wrote:
> Hi everybody,
>
> I solved the previous problem using vtkCellLocator. for who's interested,
> given a vtkPolyData source the code is:
>
>
> // the cell locator
> vtkCellLocator* locator = vtkCellLocator::New();
> locator->SetDataSet(source);
> locator->CacheCellBoundsOn();
> locator->AutomaticOn();
> locator->BuildLocator();
>
> // init the interesection parameters
> double tolerance = 0.001, lineParameter, intersect[3], paraCoord[3];
> double startPnt[3] = {// add coordinates of start point here},
> endPnt[3] = {// add coordinates of end point here};
> int sub_id;
>
>
> if(locator->IntersectWithLine(startPnt, endPnt, tolerance,
> lineParameter, intersect, paraCoord, sub_id))
> {
> printf("Point intersection: (%.2f, %.2f, %.2f)\n", intersect[0],
> intersect[1], intersect[2]);
> // do something with the intersection point
> }
>
>
> locator->Delete();
>
>
> now I have a new problem (as you can see I'm not a big expert of vtk...)
> The vtkPolyData comes from a textured model. Is there a way to get easily
> the colour of the intersection point (considering that probably it is not a
> vertex of the mesh)?
>
> regards,
> a.
>
>
Are you cells colored? If so, there is an overloaded function:
http://www.vtk.org/doc/nightly/html/classvtkOBBTree.html#a2b2d9174fa6fac5268b44f57f1ffb005
That will give you the cellId of the intersection. You would then just have
to get the color of that cell. If the cell is not colored (if only the
vertices are colored), you could use
vtkIdList* vtkCell::GetPointIds
to get the points that comprise the cell, then do some averaging of the
color of those points or something like that. Maybe someone knows a better
way to automatically interpolate the color of a cell at a point?
Thanks,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100225/a0c4d989/attachment.htm>
More information about the vtkusers
mailing list