<div dir="ltr">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. <br><br>I will try this again .<br>
<br>Thanks<br><br>Jothy<br><br><div class="gmail_quote">On Mon, Jul 25, 2011 at 3:14 PM, 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"><span style="font-size:11.0pt;color:#1F497D">You are right: vtkPolygon:: PointInPolygon is also for 3D polygons. <u></u><u></u></span></p><p class="MsoNormal">
<span style="font-size:11.0pt;color:#1F497D"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">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. <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">To test inside/outside you will need to <u></u><u></u></span></p><p><u></u><span style="font-size:11.0pt;color:#1F497D"><span>-<span style="font:7.0pt &quot;Times New Roman&quot;">          </span></span></span><u></u><span style="font-size:11.0pt;color:#1F497D">project the surface mesh onto a plane, <u></u><u></u></span></p>
<p><u></u><span style="font-size:11.0pt;color:#1F497D"><span>-<span style="font:7.0pt &quot;Times New Roman&quot;">          </span></span></span><u></u><span style="font-size:11.0pt;color:#1F497D">obtain the outer edges/points defining the silhouette boundary, <u></u><u></u></span></p>
<p><u></u><span style="font-size:11.0pt;color:#1F497D"><span>-<span style="font:7.0pt &quot;Times New Roman&quot;">          </span></span></span><u></u><span style="font-size:11.0pt;color:#1F497D">put these points into the vtkPolygon as a list of ordered points (oriented polygon ring).<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"><u></u> <u></u></span></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"> Jothy [mailto:<a href="mailto:jothybasu@gmail.com" target="_blank">jothybasu@gmail.com</a>] <br>
<b>Sent:</b> Monday, July 25, 2011 11:07 AM<br><b>To:</b> Bryn Lloyd<br><b>Cc:</b> VTK Mailing List<br><b>Subject:</b> Re: [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" style="margin-bottom:12.0pt">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<u></u><u></u></p><div><p class="MsoNormal">On Mon, Jul 25, 2011 at 7:03 AM, Bryn Lloyd &lt;<a href="mailto:lloyd@itis.ethz.ch" target="_blank">lloyd@itis.ethz.ch</a>&gt; wrote:<u></u><u></u></p>
<div><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"> </span><u></u><u></u></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</span><u></u><u></u></p></div><div><div><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></div><p class="MsoNormal"><u></u> <u></u></p></div></div></div></div></div>
</blockquote></div><br></div>