<div class="gmail_quote">2011/7/26 Miguel Sotaquirá <span dir="ltr">&lt;<a href="mailto:msotaquira@gmail.com">msotaquira@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
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 style="white-space:pre-wrap">        </span>// Current vertex coordinates (this data is not used. serves only as a reference)</div><div><span style="white-space:pre-wrap">        </span>double c[3] = {-0.59842, 2.12762, 5.17183};</div>

<div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>// Current vertex normal</div><div><span style="white-space:pre-wrap">        </span>double N[3] = {-0.604189, 0.796814, -0.00654253};</div>

<div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>// Original 3-D neighbors coordinates</div><div><span style="white-space:pre-wrap">        </span>double p0[3] = {-0.53592, 2.21902, 5.10933};</div>

<div><span style="white-space:pre-wrap">        </span>double p1[3] = {-0.59842, 2.17465, 5.10933};</div><div><span style="white-space:pre-wrap">        </span>double p2[3] = {-0.53592, 2.17465, 5.17183};</div>
<div><span style="white-space:pre-wrap">        </span>double p3[3] = {-0.66092, 2.07811, 5.17183};</div><div><span style="white-space:pre-wrap">        </span>double p4[3] = {-0.59842, 2.17465, 5.23433};</div>
<div><span style="white-space:pre-wrap">        </span>double p5[3] = {-0.66092, 2.12762, 5.23433};</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>// Insert 3-D neighbors in a polydata</div>

<div><span style="white-space:pre-wrap">        </span>vtkSmartPointer&lt;vtkPoints&gt; pts = vtkSmartPointer&lt;vtkPoints&gt;::New();</div><div><span style="white-space:pre-wrap">        </span>pts-&gt;InsertNextPoint( p0 );</div>
<div><span style="white-space:pre-wrap">        </span>pts-&gt;InsertNextPoint( p1 );</div><div><span style="white-space:pre-wrap">        </span>pts-&gt;InsertNextPoint( p2 );</div><div><span style="white-space:pre-wrap">        </span>pts-&gt;InsertNextPoint( p3 );</div>

<div><span style="white-space:pre-wrap">        </span>pts-&gt;InsertNextPoint( p4 );</div><div><span style="white-space:pre-wrap">        </span>pts-&gt;InsertNextPoint( p5 );</div><div><span style="white-space:pre-wrap">        </span></div>

<div>/*</div><div><span style="white-space:pre-wrap">        </span>// 3-D convex hull: NOT WORKING</div><div><span style="white-space:pre-wrap">        </span>// point cloud of neighbors</div><div><span style="white-space:pre-wrap">        </span>vtkSmartPointer&lt;vtkUnstructuredGrid&gt; points = vtkSmartPointer&lt;vtkUnstructuredGrid&gt;::New();</div>

<div><span style="white-space:pre-wrap">        </span>points-&gt;SetPoints( pts );</div><div><span style="white-space:pre-wrap">        </span>points-&gt;Update();</div><div><span style="white-space:pre-wrap">        </span></div>
<div><span style="white-space:pre-wrap">        </span>// convex hull</div><div class="im"><div><span style="white-space:pre-wrap">        </span>vtkSmartPointer&lt;vtkDelaunay3D&gt; delaunay3D = vtkSmartPointer&lt;vtkDelaunay3D&gt;::New();</div>

</div><div><span style="white-space:pre-wrap">        </span>delaunay3D-&gt;SetInput( points );</div><div><span style="white-space:pre-wrap">        </span>delaunay3D-&gt;Update();</div><div>*/</div><div><span style="white-space:pre-wrap">        </span></div>

<div><span style="white-space:pre-wrap">        </span>//</div><div><span style="white-space:pre-wrap">        </span>// A 2D triangulation (using vtkDelaunay2D) will be obtained by projecting</div><div>
<span style="white-space:pre-wrap">        </span>// 3-D points onto a plane</div><div><span style="white-space:pre-wrap">        </span>//</div><div class="im"><div><span style="white-space:pre-wrap">        </span></div>
<div><span style="white-space:pre-wrap">        </span>// create a plane, seting its origin in (0,0,0) and its normal N</div></div><div class="im"><div><span style="white-space:pre-wrap">        </span>vtkSmartPointer&lt;vtkPlane&gt; plane = vtkSmartPointer&lt;vtkPlane&gt;::New();</div>

<div><span style="white-space:pre-wrap">        </span>plane-&gt;SetOrigin(0.0, 0.0, 0.0);</div><div><span style="white-space:pre-wrap">        </span>plane-&gt;SetNormal(N[0], N[1], N[2]);</div><div>
<span style="white-space:pre-wrap">        </span></div></div><div><span style="white-space:pre-wrap">        </span>// project each point in the point cloud onto the plane</div><div class="im"><div><span style="white-space:pre-wrap">        </span>vtkSmartPointer&lt;vtkPoints&gt; ptsProj = vtkSmartPointer&lt;vtkPoints&gt;::New();</div>

<div><span style="white-space:pre-wrap">        </span>double origin[3] = {0.0, 0.0, 0.0};</div><div><span style="white-space:pre-wrap">        </span>double normal[3] = {N[0], N[1], N[2]};</div><div>
<span style="white-space:pre-wrap">        </span>double projected[3];</div></div><div><span style="white-space:pre-wrap">        </span>double p[3];</div><div class="im"><div><span style="white-space:pre-wrap">        </span>for ( int i = 0; i &lt; pts-&gt;GetNumberOfPoints(); i++ ) {</div>

<div><span style="white-space:pre-wrap">                </span>pts-&gt;GetPoint(i,p);</div><div><span style="white-space:pre-wrap">                </span>plane-&gt;ProjectPoint( p, origin, normal, projected );</div>
<div><span style="white-space:pre-wrap">                </span>ptsProj-&gt;InsertNextPoint(projected);</div><div><span style="white-space:pre-wrap">        </span>}</div><div><span style="white-space:pre-wrap">        </span></div>
</div><div><span style="white-space:pre-wrap">        </span>// apply delaunay2D on the projected points</div><div class="im"><div><span style="white-space:pre-wrap">        </span>vtkSmartPointer&lt;vtkPolyData&gt; ptsForTriang = vtkSmartPointer&lt;vtkPolyData&gt;::New();</div>

<div><span style="white-space:pre-wrap">        </span>ptsForTriang-&gt;SetPoints(ptsProj);</div><div><span style="white-space:pre-wrap">        </span></div></div><div class="im"><div><span style="white-space:pre-wrap">        </span>vtkSmartPointer&lt;vtkDelaunay2D&gt; delaunay2D = vtkSmartPointer&lt;vtkDelaunay2D&gt;::New();</div>

<div><span style="white-space:pre-wrap">        </span>delaunay2D-&gt;SetInput(ptsForTriang);</div><div><span style="white-space:pre-wrap">        </span>delaunay2D-&gt;Update();</div><div><br></div>
</div><div><span style="white-space:pre-wrap">        </span>// export points (original and projected) and triangulation for viewing in Paraview</div><div><span style="white-space:pre-wrap">        </span>vtkSmartPointer&lt;vtkUnstructuredGrid&gt; points2D = vtkSmartPointer&lt;vtkUnstructuredGrid&gt;::New();</div>

<div><span style="white-space:pre-wrap">        </span>vtkSmartPointer&lt;vtkUnstructuredGrid&gt; points3D = vtkSmartPointer&lt;vtkUnstructuredGrid&gt;::New();</div><div><span style="white-space:pre-wrap">        </span>points2D-&gt;SetPoints(ptsProj);</div>

<div><span style="white-space:pre-wrap">        </span>points3D-&gt;SetPoints(pts);</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>vtkSmartPointer&lt;vtkXMLUnstructuredGridWriter&gt; writerpts2D = vtkSmartPointer&lt;vtkXMLUnstructuredGridWriter&gt;::New();</div>

<div><span style="white-space:pre-wrap">        </span>writerpts2D-&gt;SetFileName(&quot;points2D.vtu&quot;);</div><div><span style="white-space:pre-wrap">        </span>writerpts2D-&gt;SetInput(points2D);</div>
<div><span style="white-space:pre-wrap">        </span>writerpts2D-&gt;Write();</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>vtkSmartPointer&lt;vtkXMLUnstructuredGridWriter&gt; writerpts3D = vtkSmartPointer&lt;vtkXMLUnstructuredGridWriter&gt;::New();</div>

<div><span style="white-space:pre-wrap">        </span>writerpts3D-&gt;SetFileName(&quot;points3D.vtu&quot;);</div><div><span style="white-space:pre-wrap">        </span>writerpts3D-&gt;SetInput(points3D);</div>
<div><span style="white-space:pre-wrap">        </span>writerpts3D-&gt;Write();</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>vtkSmartPointer&lt;vtkXMLPolyDataWriter&gt; writer = vtkSmartPointer&lt;vtkXMLPolyDataWriter&gt;::New();</div>

<div><span style="white-space:pre-wrap">        </span>writer-&gt;SetFileName(&quot;delaunay2D.vtp&quot;);</div><div><span style="white-space:pre-wrap">        </span>writer-&gt;SetInput(delaunay2D-&gt;GetOutput());</div>
<div><span style="white-space:pre-wrap">        </span>writer-&gt;Update();</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>return 0;</div><div><div></div><div class="h5">

<div>}</div></div></div></div></blockquote><div><br></div><div>You are projecting the points onto an arbitrary plane, but Delaunay2D expected them to be on the XY plane:</div><div><br></div><div>&quot;<span class="Apple-style-span" style="font-family: &#39;Lucida Grande&#39;, Verdana, Geneva, Arial, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255); ">The input to this filter is a list of points specified in 3D, even though the triangulation is 2D. Thus the triangulation is constructed in the x-y plane, and the z coordinate is ignored (although carried through to the output)&quot;</span></div>
<div><span class="Apple-style-span" style="font-family: &#39;Lucida Grande&#39;, Verdana, Geneva, Arial, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255); "><br></span></div><div><span class="Apple-style-span" style="font-family: &#39;Lucida Grande&#39;, Verdana, Geneva, Arial, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255); ">I&#39;ve done this by finding a local coordinate system on the plane and mapping the points into that coordinate system:</span></div>
<a href="https://github.com/daviddoria/vtkPlanarPatch/blob/master/vtkPlanarPatch.cxx">https://github.com/daviddoria/vtkPlanarPatch/blob/master/vtkPlanarPatch.cxx</a><br clear="all"><br></div><div class="gmail_quote">You can also do this by passing a transform to Delaunay2D with SetTransform().<br>
<br></div><div class="gmail_quote">The idea is to apply the topology that results from the triangulation to your original points.</div><div class="gmail_quote"><br></div><div class="gmail_quote">David</div>