<div dir="ltr">Thanks for your reply Bryn!<br><br>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].<br>
<br>I want to calculate the dose-volume histograms from these meshes.<br><br>I will make a new post with a more appropriate subject.<br><br>Thanks again<br><br>Jothy<br><br><div class="gmail_quote">On Mon, Jul 25, 2011 at 7:03 AM, Bryn Lloyd <span dir="ltr">&lt;<a href="mailto:lloyd@itis.ethz.ch">lloyd@itis.ethz.ch</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div link="blue" vlink="purple" lang="EN-US"><div><p class="MsoNormal">Hi Jothy<u></u><u></u></p><p class="MsoNormal">
<u></u> <u></u></p><p class="MsoNormal">Since you are using vtkDiscreteMarchingCubes, I assume your mesh is a 3d surface mesh.<u></u><u></u></p><p class="MsoNormal">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.<u></u><u></u></p>
<p class="MsoNormal"><a href="http://www.vtk.org/doc/nightly/html/classvtkPolyDataSilhouette.html" target="_blank">http://www.vtk.org/doc/nightly/html/classvtkPolyDataSilhouette.html</a><u></u><u></u></p><p class="MsoNormal">
<u></u> <u></u></p><p class="MsoNormal">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 &lt;double*&gt;.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">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.<u></u><u></u></p>
<p class="MsoNormal">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”.<u></u><u></u></p>
<p class="MsoNormal"><a href="http://www.vtk.org/doc/nightly/html/classvtkSelectEnclosedPoints.html" target="_blank">http://www.vtk.org/doc/nightly/html/classvtkSelectEnclosedPoints.html</a><u></u><u></u></p><p class="MsoNormal">
<u></u> <u></u></p><p class="MsoNormal">Cheers<u></u><u></u></p><p class="MsoNormal">Bryn<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"><u></u> <u></u></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><b><span style="font-size:10.0pt">From:</span></b><span style="font-size:10.0pt"> <a href="mailto:vtkusers-bounces@vtk.org" target="_blank">vtkusers-bounces@vtk.org</a> [mailto:<a href="mailto:vtkusers-bounces@vtk.org" target="_blank">vtkusers-bounces@vtk.org</a>] <b>On Behalf Of </b>Jothy<br>
<b>Sent:</b> Friday, July 22, 2011 4:39 PM<br><b>To:</b> VTK Mailing List<br><b>Subject:</b> [vtkusers] PointInPolygon returns 1 for all points within bounds<u></u><u></u></span></p></div><div><div></div><div class="h5"><p class="MsoNormal">
<u></u> <u></u></p><div><p class="MsoNormal">Hi all,<br><br>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 &quot;1! for the all the points whichever falls with the bounds.<br>
<br>Here is the piece of code that I am using<br><br>(smoother is vtkWindowedSincPolyDataFilter)<br><br> int npts=smoother-&gt;GetOutput()-&gt; GetPoints()-&gt;GetNumberOfPoints();// test point <br> //double n[3]={0.707, 0.707, 0};<br>
 double n[3];<br><br>  vtkSmartPointer&lt;vtkPolygon&gt; polygon =<br>           vtkSmartPointer&lt;vtkPolygon&gt;::New();<br>  <b><span style="color:#CC0000">polygon-&gt;ComputeNormal(mapper-&gt;GetInput()-&gt;GetPoints()-&gt;GetNumberOfPoints(),<br>
                              static_cast&lt;double*&gt;(mapper-&gt;GetInput()-&gt;GetPoints()-&gt;GetData()-&gt;GetVoidPointer(0)), n);      </span></b>         <br><br>   double bds[6];<br>   smoother-&gt;GetOutput()-&gt;GetBounds(bds);                  <br>
    qDebug()&lt;&lt; polygon-&gt;PointInPolygon(testIn,npts,<b><span style="color:red">static_cast&lt;double*&gt;(mapper-&gt;GetInput()-&gt;GetPolys()-&gt;GetData()-&gt;GetVoidPointer(0)</span></b>),bds,n)&lt;&lt;&quot;Result&quot;;<br>
<br>Are these two highlighted lines correct?<br><br>Many thanks<br><br>Jothy<br>                   <u></u><u></u></p></div></div></div></div></div></blockquote></div><br></div>