[vtkusers] PointInPolygon returns 1 for all points within bounds

Bryn Lloyd lloyd at itis.ethz.ch
Mon Jul 25 02:03:24 EDT 2011


Hi Jothy

 

Since you are using vtkDiscreteMarchingCubes, I assume your mesh is a 3d
surface mesh.

vtkPolygon is meant to used for 2D polygons (e.g. a triangle in the
xy-plane). Unless you project your 3D mesh to a 2d plane, and obtain the
silhouette, this will not work.

http://www.vtk.org/doc/nightly/html/classvtkPolyDataSilhouette.html

 

Also, it seems dangerous or even wrong to cast the points and polygons to a
double pointer like this. First, the points could also be floats. Second, I
doubt the polys in your mesh can be cast to <double*>.

 

 

Instead, you should probably use one of the cell locators, e.g. vtkOBBTree
or vtkCellLocator to test if your point is inside the mesh in 3D.

You could have a look at the code in "vtkSelectEnclosedPoints" to see how to
do this in a robust way. You can even use this filter directly, via the
function "vtkSelectEnclosedPoints::IsInsideSurface".

http://www.vtk.org/doc/nightly/html/classvtkSelectEnclosedPoints.html

 

Cheers

Bryn

 

 

 

From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On Behalf
Of Jothy
Sent: Friday, July 22, 2011 4:39 PM
To: VTK Mailing List
Subject: [vtkusers] PointInPolygon returns 1 for all points within bounds

 

Hi all,

I have a mesh generated from vtkDiscreteMarchingCubes and processed through
vtkDecimatePro and vtkWindowedSincPolyDataFilter. Now, I want to find the
points/voxels inside this mesh. I am using vtkPolygon::PointInPolygon. But,
the result is "1! for the all the points whichever falls with the bounds.

Here is the piece of code that I am using

(smoother is vtkWindowedSincPolyDataFilter)

 int npts=smoother->GetOutput()-> GetPoints()->GetNumberOfPoints();// test
point 
 //double n[3]={0.707, 0.707, 0};
 double n[3];

  vtkSmartPointer<vtkPolygon> polygon =
           vtkSmartPointer<vtkPolygon>::New();
 
polygon->ComputeNormal(mapper->GetInput()->GetPoints()->GetNumberOfPoints(),
 
static_cast<double*>(mapper->GetInput()->GetPoints()->GetData()->GetVoidPoin
ter(0)), n);               

   double bds[6];
   smoother->GetOutput()->GetBounds(bds);                  
    qDebug()<<
polygon->PointInPolygon(testIn,npts,static_cast<double*>(mapper->GetInput()-
>GetPolys()->GetData()->GetVoidPointer(0)),bds,n)<<"Result";

Are these two highlighted lines correct?

Many thanks

Jothy
                   

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


More information about the vtkusers mailing list