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 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<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>pts->InsertNextPoint( p0 );</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>pts->InsertNextPoint( p1 );</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>pts->InsertNextPoint( p2 );</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>pts->InsertNextPoint( p3 );</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>pts->InsertNextPoint( p4 );</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>pts->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<vtkUnstructuredGrid> points = vtkSmartPointer<vtkUnstructuredGrid>::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>points->SetPoints( pts );</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>points->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<vtkDelaunay3D> delaunay3D = vtkSmartPointer<vtkDelaunay3D>::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>delaunay3D->SetInput( points );</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>delaunay3D->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<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>plane->SetOrigin(0.0, 0.0, 0.0);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>plane->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<vtkPoints> ptsProj = vtkSmartPointer<vtkPoints>::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 < pts->GetNumberOfPoints(); i++ ) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>pts->GetPoint(i,p);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>plane->ProjectPoint( p, origin, normal, projected );</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>ptsProj->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<vtkPolyData> ptsForTriang = vtkSmartPointer<vtkPolyData>::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>ptsForTriang->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<vtkDelaunay2D> delaunay2D = vtkSmartPointer<vtkDelaunay2D>::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>delaunay2D->SetInput(ptsForTriang);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>delaunay2D->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<vtkUnstructuredGrid> points2D = vtkSmartPointer<vtkUnstructuredGrid>::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkUnstructuredGrid> points3D = vtkSmartPointer<vtkUnstructuredGrid>::New();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>points2D->SetPoints(ptsProj);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>points3D->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<vtkXMLUnstructuredGridWriter> writerpts2D = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>writerpts2D->SetFileName("points2D.vtu");</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>writerpts2D->SetInput(points2D);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>writerpts2D->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<vtkXMLUnstructuredGridWriter> writerpts3D = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>writerpts3D->SetFileName("points3D.vtu");</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>writerpts3D->SetInput(points3D);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>writerpts3D->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<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>writer->SetFileName("delaunay2D.vtp");</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>writer->SetInput(delaunay2D->GetOutput());</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>writer->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"><<a href="mailto:daviddoria@gmail.com">daviddoria@gmail.com</a>></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á <<a href="mailto:msotaquira@gmail.com">msotaquira@gmail.com</a>>:<br>
> Hi David,<br>
<div><div></div><div class="h5">> You're right, vtkDelaunay3D is not the correct approach in this case. Now<br>
> I'm trying to obtain a 2D convex hull (vtkDelaunay2D) by projecting the 3-D<br>
> points onto a plane. Here's the code:<br>
> // create a plane, seting its origin in (0,0,0) and its normal N (N is the<br>
> normal to the current vertex, the center of the neighborhood)<br>
> vtkSmartPointer<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New();<br>
> plane->SetOrigin(0.0, 0.0, 0.0);<br>
> plane->SetNormal(N[0], N[1], N[2]);<br>
> // project each point in the neighborhood onto the plane<br>
> vtkSmartPointer<vtkPoints> ptsProj = vtkSmartPointer<vtkPoints>::New();<br>
> double origin[3] = {0.0, 0.0, 0.0};<br>
> double normal[3] = {N[0], N[1], N[2]};<br>
> double projected[3];<br>
> for ( int i = 0; i < pts->GetNumberOfPoints(); i++ ) {<br>
> pts->GetPoint(i,p);<br>
> plane->ProjectPoint( p, origin, normal, projected );<br>
> ptsProj->InsertNextPoint(projected);}<br>
> // store projected points in a polydata<br>
> vtkSmartPointer<vtkPolyData> ptsForTriang =<br>
> vtkSmartPointer<vtkPolyData>::New();<br>
> ptsForTriang->SetPoints(ptsProj);<br>
> // apply delaunay2D<br>
> vtkSmartPointer<vtkDelaunay2D> delaunay2D =<br>
> vtkSmartPointer<vtkDelaunay2D>::New();<br>
> delaunay2D->SetInput(ptsForTriang);<br>
> delaunay2D->Update();<br>
> When using this approach to my initial problem I get this:<br>
> <a href="http://tinypic.com/r/2mre8ma/7" target="_blank">http://tinypic.com/r/2mre8ma/7</a><br>
> again, some vertices were not included in the convex hull . When I check the<br>
> 2D convex hull info it says that has 6 points (which is correct) but only 2<br>
> cells (the ones that can be seen in the image)...<br>
> Is this the correct approach for computing the 2D convex hull (using<br>
> projections)? Am I missing something?<br>
> Thanks again,<br>
> 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>