Hi David!<div><br></div><div>Here&#39;s the hardcoded version. Just to clarify: I just want to know if the current 3-D vertex (&quot;c&quot; in the code) is contained in the convex hull of its 3-D neighbors (&quot;pts&quot; in the code). I&#39;ve used vtkDelaunay3D and vtkDelaunay2D currently without any success.</div>
<div>Miguel</div><div><br></div><div><div>#include &lt;vtkSmartPointer.h&gt;</div><div>#include &lt;vtkPolyData.h&gt;</div><div>#include &lt;vtkPoints.h&gt;</div><div>#include &lt;vtkUnstructuredGrid.h&gt;</div><div>#include &lt;vtkDelaunay3D.h&gt;</div>
<div>#include &lt;vtkPlane.h&gt;</div><div>#include &lt;vtkDelaunay2D.h&gt;</div><div>#include &lt;vtkXMLPolyDataWriter.h&gt;</div><div>#include &lt;vtkXMLUnstructuredGridWriter.h&gt;</div><div><br></div><div>int main (int argc, char* argv[])</div>
<div>{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// Current vertex coordinates (this data is not used. serves only as a reference)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>double c[3] = {-0.59842, 2.12762, 5.17183};</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// Current vertex normal</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>double N[3] = {-0.604189, 0.796814, -0.00654253};</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// Original 3-D neighbors coordinates</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>double p0[3] = {-0.53592, 2.21902, 5.10933};</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>double p1[3] = {-0.59842, 2.17465, 5.10933};</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>double p2[3] = {-0.53592, 2.17465, 5.17183};</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>double p3[3] = {-0.66092, 2.07811, 5.17183};</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>double p4[3] = {-0.59842, 2.17465, 5.23433};</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>double p5[3] = {-0.66092, 2.12762, 5.23433};</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// Insert 3-D neighbors in a polydata</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer&lt;vtkPoints&gt; pts = vtkSmartPointer&lt;vtkPoints&gt;::New();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>pts-&gt;InsertNextPoint( p0 );</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>pts-&gt;InsertNextPoint( p1 );</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>pts-&gt;InsertNextPoint( p2 );</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>pts-&gt;InsertNextPoint( p3 );</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>pts-&gt;InsertNextPoint( p4 );</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>pts-&gt;InsertNextPoint( p5 );</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div>/*</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// 3-D convex hull: NOT WORKING</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// point cloud of neighbors</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer&lt;vtkUnstructuredGrid&gt; points = vtkSmartPointer&lt;vtkUnstructuredGrid&gt;::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>points-&gt;SetPoints( pts );</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>points-&gt;Update();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>// convex hull</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer&lt;vtkDelaunay3D&gt; delaunay3D = vtkSmartPointer&lt;vtkDelaunay3D&gt;::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>delaunay3D-&gt;SetInput( points );</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>delaunay3D-&gt;Update();</div><div>*/</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>//</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// A 2D triangulation (using vtkDelaunay2D) will be obtained by projecting</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>// 3-D points onto a plane</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>// create a plane, seting its origin in (0,0,0) and its normal N</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer&lt;vtkPlane&gt; plane = vtkSmartPointer&lt;vtkPlane&gt;::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>plane-&gt;SetOrigin(0.0, 0.0, 0.0);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>plane-&gt;SetNormal(N[0], N[1], N[2]);</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// project each point in the point cloud onto the plane</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer&lt;vtkPoints&gt; ptsProj = vtkSmartPointer&lt;vtkPoints&gt;::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>double origin[3] = {0.0, 0.0, 0.0};</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>double normal[3] = {N[0], N[1], N[2]};</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>double projected[3];</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>double p[3];</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>for ( int i = 0; i &lt; pts-&gt;GetNumberOfPoints(); i++ ) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>pts-&gt;GetPoint(i,p);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>plane-&gt;ProjectPoint( p, origin, normal, projected );</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>ptsProj-&gt;InsertNextPoint(projected);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>// apply delaunay2D on the projected points</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer&lt;vtkPolyData&gt; ptsForTriang = vtkSmartPointer&lt;vtkPolyData&gt;::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>ptsForTriang-&gt;SetPoints(ptsProj);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer&lt;vtkDelaunay2D&gt; delaunay2D = vtkSmartPointer&lt;vtkDelaunay2D&gt;::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>delaunay2D-&gt;SetInput(ptsForTriang);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>delaunay2D-&gt;Update();</div><div><br></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>// export points (original and projected) and triangulation for viewing in Paraview</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer&lt;vtkUnstructuredGrid&gt; points2D = vtkSmartPointer&lt;vtkUnstructuredGrid&gt;::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer&lt;vtkUnstructuredGrid&gt; points3D = vtkSmartPointer&lt;vtkUnstructuredGrid&gt;::New();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>points2D-&gt;SetPoints(ptsProj);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>points3D-&gt;SetPoints(pts);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer&lt;vtkXMLUnstructuredGridWriter&gt; writerpts2D = vtkSmartPointer&lt;vtkXMLUnstructuredGridWriter&gt;::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>writerpts2D-&gt;SetFileName(&quot;points2D.vtu&quot;);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>writerpts2D-&gt;SetInput(points2D);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>writerpts2D-&gt;Write();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer&lt;vtkXMLUnstructuredGridWriter&gt; writerpts3D = vtkSmartPointer&lt;vtkXMLUnstructuredGridWriter&gt;::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>writerpts3D-&gt;SetFileName(&quot;points3D.vtu&quot;);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>writerpts3D-&gt;SetInput(points3D);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>writerpts3D-&gt;Write();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer&lt;vtkXMLPolyDataWriter&gt; writer = vtkSmartPointer&lt;vtkXMLPolyDataWriter&gt;::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>writer-&gt;SetFileName(&quot;delaunay2D.vtp&quot;);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>writer-&gt;SetInput(delaunay2D-&gt;GetOutput());</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>writer-&gt;Update();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>return 0;</div>
<div>}</div><br><div class="gmail_quote">2011/7/26 David Doria <span dir="ltr">&lt;<a href="mailto:daviddoria@gmail.com">daviddoria@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
2011/7/26 Miguel Sotaquirá &lt;<a href="mailto:msotaquira@gmail.com">msotaquira@gmail.com</a>&gt;:<br>
&gt; Hi David,<br>
<div><div></div><div class="h5">&gt; You&#39;re right, vtkDelaunay3D is not the correct approach in this case. Now<br>
&gt; I&#39;m trying to obtain a 2D convex hull (vtkDelaunay2D) by projecting the 3-D<br>
&gt; points onto a plane. Here&#39;s the code:<br>
&gt; // create a plane, seting its origin in (0,0,0) and its normal N (N is the<br>
&gt; normal to  the current vertex, the center of the neighborhood)<br>
&gt; vtkSmartPointer&lt;vtkPlane&gt; plane = vtkSmartPointer&lt;vtkPlane&gt;::New();<br>
&gt; plane-&gt;SetOrigin(0.0, 0.0, 0.0);<br>
&gt; plane-&gt;SetNormal(N[0], N[1], N[2]);<br>
&gt;  // project each point in the neighborhood onto the plane<br>
&gt; vtkSmartPointer&lt;vtkPoints&gt; ptsProj = vtkSmartPointer&lt;vtkPoints&gt;::New();<br>
&gt; double origin[3] = {0.0, 0.0, 0.0};<br>
&gt; double normal[3] = {N[0], N[1], N[2]};<br>
&gt; double projected[3];<br>
&gt; for ( int i = 0; i &lt; pts-&gt;GetNumberOfPoints(); i++ ) {<br>
&gt;   pts-&gt;GetPoint(i,p);<br>
&gt;   plane-&gt;ProjectPoint( p, origin, normal, projected );<br>
&gt;   ptsProj-&gt;InsertNextPoint(projected);}<br>
&gt; // store projected points in a polydata<br>
&gt; vtkSmartPointer&lt;vtkPolyData&gt; ptsForTriang =<br>
&gt; vtkSmartPointer&lt;vtkPolyData&gt;::New();<br>
&gt; ptsForTriang-&gt;SetPoints(ptsProj);<br>
&gt; // apply delaunay2D<br>
&gt; vtkSmartPointer&lt;vtkDelaunay2D&gt; delaunay2D =<br>
&gt; vtkSmartPointer&lt;vtkDelaunay2D&gt;::New();<br>
&gt; delaunay2D-&gt;SetInput(ptsForTriang);<br>
&gt; delaunay2D-&gt;Update();<br>
&gt; When using this approach to my initial problem I get this:<br>
&gt; <a href="http://tinypic.com/r/2mre8ma/7" target="_blank">http://tinypic.com/r/2mre8ma/7</a><br>
&gt; again, some vertices were not included in the convex hull . When I check the<br>
&gt; 2D convex hull info it says that has 6 points (which is correct) but only 2<br>
&gt; cells (the ones that can be seen in the image)...<br>
&gt; Is this the correct approach for computing the 2D convex hull (using<br>
&gt; projections)? Am I missing something?<br>
&gt; Thanks again,<br>
&gt; Miguel<br>
<br>
</div></div>Can you hardcode those points into a compilable demo of this?<br>
<font color="#888888"><br>
David<br>
</font></blockquote></div><br></div>