[vtkusers] PointInPolygon returns 1 for all points within bounds

Jothy jothybasu at gmail.com
Mon Jul 25 10:26:23 EDT 2011


I ahve done this before by using vtkCutterat every 1mm to get the outline
points and passed it to a point-in-polygon method. But it was done in python
which comes with lot of math libs.

I will try this again .

Thanks

Jothy

On Mon, Jul 25, 2011 at 3:14 PM, Bryn Lloyd <lloyd at itis.ethz.ch> wrote:

> You are right: vtkPolygon:: PointInPolygon is also for 3D polygons. ****
>
> ** **
>
> But a surface mesh (obtained via marching cubes) does not correspond to a
> polygon! Also the projection on the plane defined by the normal n (which you
> provide to PointInPolygon) in general is not a (single) polygon. ****
>
> To test inside/outside you will need to ****
>
> **-          **project the surface mesh onto a plane, ****
>
> **-          **obtain the outer edges/points defining the silhouette
> boundary, ****
>
> **-          **put these points into the vtkPolygon as a list of ordered
> points (oriented polygon ring).****
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> *From:* Jothy [mailto:jothybasu at gmail.com]
> *Sent:* Monday, July 25, 2011 11:07 AM
> *To:* Bryn Lloyd
> *Cc:* VTK Mailing List
> *Subject:* Re: [vtkusers] PointInPolygon returns 1 for all points within
> bounds****
>
> ** **
>
> Thanks for your reply Bryn!
>
> vtkPolygon is meant to be used for 2D polygons, but the pointInPolygon uses
> a ray-tracing to find the points inside the polygon so why it will work only
> for 2D polygons. The arguments are [x,y,z].
>
> I want to calculate the dose-volume histograms from these meshes.
>
> I will make a new post with a more appropriate subject.
>
> Thanks again
>
> Jothy****
>
> On Mon, Jul 25, 2011 at 7:03 AM, Bryn Lloyd <lloyd at itis.ethz.ch> wrote:***
> *
>
> 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()->GetVoidPointer(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/90a2efe3/attachment.htm>


More information about the vtkusers mailing list