<div dir="ltr"><div class="gmail_quote">Dear VTK users,<br><div dir="ltr"><br>I am trying to create a surface mesh from a point cloud using VTK, using a Marching Cubes or similar algorithm. However, I got really stuck - can&#39;t seem to figure out the right combination of Filters / Parameters. Can anybody please please help me out? All the details are below.<br>

<br>As a note, I do not want to render / visualize the result (so I don&#39;t need Actors, Mappers etc). I just need to retrieve the list of surface triangles from another program.<br><br>Thank you,<br>Matei<br><br>DETAILS:<br>

<br>- I have a point cloud. I use it to populate a vtkFloatArray, which in turn I use to create a vtkPoints. Then I create a vtkPolyData and call SetPoints ( my vtkPoints instance )<br><br>- there are some filters that also need the data as &quot;Cells&quot; (not sure what those are). Therefore, I create a vtkCellArray, populate it with a cell for each of my points and then I do vtkPolyData-&gt;setVerts ( my vtkCellArray )<br>

<br><div dir="ltr">- this is enough to run Delaunay filters (2D and 3D). However, these do not create the kind of mesh I want - I need a well behaved surface mesh like Marching Cubes generates<br><br>OPTION 1)<br><br>I create a vtkImplicitModeller and set as its input my vtkPolyData. Then I create a vtkContourFilter and set as its input the output from the vtkImplicitModeller. Then I take the output of the vtkContourFilter and use it as a vtkPolyData. <br>

<br>It computes for a while, so I guess my pipeline must be doing something, but the results is empty! It contains no triangles, no Cells, no nothing!<br><br>OPTION 2) <br><br>Exactly the same, but instead of vtkImplicitModeller I use a vtkSurfaceReconstructionFilter. In this case I do get a result that contains triangles, but it is just wrong - I don&#39;t know what those triangles are supposed to be. Definitely not my surface mesh. They look more like triangles on a grid with an arbitrary size, much much larger than the size of my initial point cloud.<br>

<br>In both cases, if I replace vtkContourFilter with vtkMarchingCubes, the result is identical.<br><br>Here is my exact code:<br><br>1) Create and populate vtkPolyData<br>
<br>&nbsp;&nbsp;&nbsp; // Create a float array which represents the points.<br>&nbsp;&nbsp;&nbsp; vtkFloatArray* pcoords = vtkFloatArray::New();<br>&nbsp;&nbsp;&nbsp; pcoords-&gt;SetNumberOfComponents(3);<br>&nbsp;&nbsp;&nbsp; pcoords-&gt;SetNumberOfTuples(mNumPoints);<br>&nbsp;&nbsp;&nbsp; for (int i=0; i&lt;mNumPoints; i++){<br>


&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pcoords-&gt;SetTuple3(i, mNativePoints[i].x, mNativePoints[i].y, mNativePoints[i].z);<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; // Create vtkPoints and assign pcoords as the internal data array.<br>&nbsp;&nbsp;&nbsp; vtkPoints* points = vtkPoints::New();<br>


&nbsp;&nbsp;&nbsp; points-&gt;SetData(pcoords);<br>&nbsp;&nbsp;&nbsp; // Create vtkPolyData and assign vtkPoints as internal data<br>&nbsp;&nbsp;&nbsp; mVtkData = vtkPolyData::New();<br>&nbsp;&nbsp;&nbsp; mVtkData-&gt;SetPoints(points);<br><br>&nbsp;&nbsp;&nbsp; //for some functions it seems we also need the points represented as &quot;cells&quot;...<br>


&nbsp;&nbsp;&nbsp; vtkCellArray *cells = vtkCellArray::New();<br>&nbsp;&nbsp;&nbsp; for (int i=0; i&lt;mNumPoints; i++) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cells-&gt;InsertNextCell(1);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cells-&gt;InsertCellPoint(i);<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; mVtkData-&gt;SetVerts(cells);<br>


<br>2) attempt surface mesh generation<br><br>&nbsp;&nbsp;&nbsp; vtkImplicitModeller *modeller = vtkImplicitModeller::New();<br>&nbsp;&nbsp;&nbsp; modeller-&gt;SetInput( mVtkData );<br>&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp; am incercat diversi parametri:<br>&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp; modeller-&gt;SetSampleDimensions(100, 100, 100);<br>


&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp; modeller-&gt;SetMaximumDistance(0.2);<br>&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp; modeller-&gt;SetModelBounds(-1,-1,-1,1,1,1);<br><br>&nbsp;&nbsp;&nbsp; vtkContourFilter *filter = vtkContourFilter::New();<br>&nbsp;&nbsp;&nbsp; filter-&gt;SetValue(0,0.0);<br>&nbsp;&nbsp;&nbsp; vtkPolyData *output = filter-&gt;GetOutput();<br>


&nbsp;&nbsp;&nbsp; filter-&gt;SetInputConnection( modeller-&gt;GetOutputPort() );<br>&nbsp;&nbsp;&nbsp; filter-&gt;Update();<br><br>------------------------ and I get a completely empty result<br><br><br>&nbsp; &nbsp; vtkSurfaceReconstructionFilter *surface = vtkSurfaceReconstructionFilter::New();<br>


&nbsp;&nbsp;&nbsp; surface-&gt;SetSampleSpacing(0.01);<br>&nbsp;&nbsp;&nbsp; surface-&gt;SetInput( mVtkData);<br><br>&nbsp;&nbsp;&nbsp; vtkContourFilter *filter = vtkContourFilter::New();<br>&nbsp;&nbsp;&nbsp; filter-&gt;SetValue(0,0.0);<br>&nbsp;&nbsp;&nbsp; vtkPolyData *output = filter-&gt;GetOutput();<br>


&nbsp;&nbsp;&nbsp; filter-&gt;SetInputConnection( surface-&gt;GetOutputPort() );<br>&nbsp;&nbsp;&nbsp; filter-&gt;Update();<br><br>--------------------------- and I get a strange result that is not the surface mesh I am looking for<br><br>Again - any kind of help much much appreciated!!!<br>

</div><br></div>
</div><br></div>