<div class="gmail_quote">2011/7/26 Miguel Sotaquirá <span dir="ltr"><<a href="mailto:msotaquira@gmail.com">msotaquira@gmail.com</a>></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's the hardcoded version. Just to clarify: I just want to know if the current 3-D vertex ("c" in the code) is contained in the convex hull of its 3-D neighbors ("pts" in the code). I've used vtkDelaunay3D and vtkDelaunay2D currently without any success.</div>
<div>Miguel</div><div><br></div><div><div>#include <vtkSmartPointer.h></div><div>#include <vtkPolyData.h></div><div>#include <vtkPoints.h></div><div>#include <vtkUnstructuredGrid.h></div><div>#include <vtkDelaunay3D.h></div>
<div>#include <vtkPlane.h></div><div>#include <vtkDelaunay2D.h></div><div>#include <vtkXMLPolyDataWriter.h></div><div>#include <vtkXMLUnstructuredGridWriter.h></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<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New();</div><div><span style="white-space:pre-wrap">        </span>pts->InsertNextPoint( p0 );</div>
<div><span style="white-space:pre-wrap">        </span>pts->InsertNextPoint( p1 );</div><div><span style="white-space:pre-wrap">        </span>pts->InsertNextPoint( p2 );</div><div><span style="white-space:pre-wrap">        </span>pts->InsertNextPoint( p3 );</div>
<div><span style="white-space:pre-wrap">        </span>pts->InsertNextPoint( p4 );</div><div><span style="white-space:pre-wrap">        </span>pts->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<vtkUnstructuredGrid> points = vtkSmartPointer<vtkUnstructuredGrid>::New();</div>
<div><span style="white-space:pre-wrap">        </span>points->SetPoints( pts );</div><div><span style="white-space:pre-wrap">        </span>points->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<vtkDelaunay3D> delaunay3D = vtkSmartPointer<vtkDelaunay3D>::New();</div>
</div><div><span style="white-space:pre-wrap">        </span>delaunay3D->SetInput( points );</div><div><span style="white-space:pre-wrap">        </span>delaunay3D->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<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New();</div>
<div><span style="white-space:pre-wrap">        </span>plane->SetOrigin(0.0, 0.0, 0.0);</div><div><span style="white-space:pre-wrap">        </span>plane->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<vtkPoints> ptsProj = vtkSmartPointer<vtkPoints>::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 < pts->GetNumberOfPoints(); i++ ) {</div>
<div><span style="white-space:pre-wrap">                </span>pts->GetPoint(i,p);</div><div><span style="white-space:pre-wrap">                </span>plane->ProjectPoint( p, origin, normal, projected );</div>
<div><span style="white-space:pre-wrap">                </span>ptsProj->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<vtkPolyData> ptsForTriang = vtkSmartPointer<vtkPolyData>::New();</div>
<div><span style="white-space:pre-wrap">        </span>ptsForTriang->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<vtkDelaunay2D> delaunay2D = vtkSmartPointer<vtkDelaunay2D>::New();</div>
<div><span style="white-space:pre-wrap">        </span>delaunay2D->SetInput(ptsForTriang);</div><div><span style="white-space:pre-wrap">        </span>delaunay2D->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<vtkUnstructuredGrid> points2D = vtkSmartPointer<vtkUnstructuredGrid>::New();</div>
<div><span style="white-space:pre-wrap">        </span>vtkSmartPointer<vtkUnstructuredGrid> points3D = vtkSmartPointer<vtkUnstructuredGrid>::New();</div><div><span style="white-space:pre-wrap">        </span>points2D->SetPoints(ptsProj);</div>
<div><span style="white-space:pre-wrap">        </span>points3D->SetPoints(pts);</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>vtkSmartPointer<vtkXMLUnstructuredGridWriter> writerpts2D = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();</div>
<div><span style="white-space:pre-wrap">        </span>writerpts2D->SetFileName("points2D.vtu");</div><div><span style="white-space:pre-wrap">        </span>writerpts2D->SetInput(points2D);</div>
<div><span style="white-space:pre-wrap">        </span>writerpts2D->Write();</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>vtkSmartPointer<vtkXMLUnstructuredGridWriter> writerpts3D = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();</div>
<div><span style="white-space:pre-wrap">        </span>writerpts3D->SetFileName("points3D.vtu");</div><div><span style="white-space:pre-wrap">        </span>writerpts3D->SetInput(points3D);</div>
<div><span style="white-space:pre-wrap">        </span>writerpts3D->Write();</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();</div>
<div><span style="white-space:pre-wrap">        </span>writer->SetFileName("delaunay2D.vtp");</div><div><span style="white-space:pre-wrap">        </span>writer->SetInput(delaunay2D->GetOutput());</div>
<div><span style="white-space:pre-wrap">        </span>writer->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>"<span class="Apple-style-span" style="font-family: 'Lucida Grande', 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)"</span></div>
<div><span class="Apple-style-span" style="font-family: 'Lucida Grande', 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: 'Lucida Grande', Verdana, Geneva, Arial, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255); ">I'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>