<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
h1
        {mso-style-priority:9;
        mso-style-link:"Heading 1 Char";
        margin-top:24.0pt;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:0in;
        margin-bottom:.0001pt;
        page-break-after:avoid;
        font-size:14.0pt;
        font-family:"Cambria","serif";
        color:#365F91;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.Heading1Char
        {mso-style-name:"Heading 1 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 1";
        font-family:"Cambria","serif";
        color:#365F91;
        font-weight:bold;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Hi Jothy<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Since you are using vtkDiscreteMarchingCubes, I assume your mesh is a 3d surface mesh.<o:p></o:p></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.<o:p></o:p></p><p class=MsoNormal><a href="http://www.vtk.org/doc/nightly/html/classvtkPolyDataSilhouette.html">http://www.vtk.org/doc/nightly/html/classvtkPolyDataSilhouette.html</a><o:p></o:p></p><p class=MsoNormal><o:p> </o:p></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 <double*>.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></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.<o:p></o:p></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”.<o:p></o:p></p><p class=MsoNormal><a href="http://www.vtk.org/doc/nightly/html/classvtkSelectEnclosedPoints.html">http://www.vtk.org/doc/nightly/html/classvtkSelectEnclosedPoints.html</a><o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Cheers<o:p></o:p></p><p class=MsoNormal>Bryn<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></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;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> vtkusers-bounces@vtk.org [mailto:vtkusers-bounces@vtk.org] <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<o:p></o:p></span></p></div><p class=MsoNormal><o:p> </o:p></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 "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->GetOutput()-> GetPoints()->GetNumberOfPoints();// test point <br> //double n[3]={0.707, 0.707, 0};<br> double n[3];<br><br> vtkSmartPointer<vtkPolygon> polygon =<br> vtkSmartPointer<vtkPolygon>::New();<br> <b><span style='color:#CC0000'>polygon->ComputeNormal(mapper->GetInput()->GetPoints()->GetNumberOfPoints(),<br> static_cast<double*>(mapper->GetInput()->GetPoints()->GetData()->GetVoidPointer(0)), n); </span></b> <br><br> double bds[6];<br> smoother->GetOutput()->GetBounds(bds); <br> qDebug()<< polygon->PointInPolygon(testIn,npts,<b><span style='color:red'>static_cast<double*>(mapper->GetInput()->GetPolys()->GetData()->GetVoidPointer(0)</span></b>),bds,n)<<"Result";<br><br>Are these two highlighted lines correct?<br><br>Many thanks<br><br>Jothy<br> <o:p></o:p></p></div></div></body></html>