<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'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'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 "Cells" (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->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'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> // Create a float array which represents the points.<br> vtkFloatArray* pcoords = vtkFloatArray::New();<br> pcoords->SetNumberOfComponents(3);<br> pcoords->SetNumberOfTuples(mNumPoints);<br> for (int i=0; i<mNumPoints; i++){<br>
pcoords->SetTuple3(i, mNativePoints[i].x, mNativePoints[i].y, mNativePoints[i].z);<br> }<br> // Create vtkPoints and assign pcoords as the internal data array.<br> vtkPoints* points = vtkPoints::New();<br>
points->SetData(pcoords);<br> // Create vtkPolyData and assign vtkPoints as internal data<br> mVtkData = vtkPolyData::New();<br> mVtkData->SetPoints(points);<br><br> //for some functions it seems we also need the points represented as "cells"...<br>
vtkCellArray *cells = vtkCellArray::New();<br> for (int i=0; i<mNumPoints; i++) {<br> cells->InsertNextCell(1);<br> cells->InsertCellPoint(i);<br> }<br> mVtkData->SetVerts(cells);<br>
<br>2) attempt surface mesh generation<br><br> vtkImplicitModeller *modeller = vtkImplicitModeller::New();<br> modeller->SetInput( mVtkData );<br> // am incercat diversi parametri:<br> // modeller->SetSampleDimensions(100, 100, 100);<br>
// modeller->SetMaximumDistance(0.2);<br> // modeller->SetModelBounds(-1,-1,-1,1,1,1);<br><br> vtkContourFilter *filter = vtkContourFilter::New();<br> filter->SetValue(0,0.0);<br> vtkPolyData *output = filter->GetOutput();<br>
filter->SetInputConnection( modeller->GetOutputPort() );<br> filter->Update();<br><br>------------------------ and I get a completely empty result<br><br><br> vtkSurfaceReconstructionFilter *surface = vtkSurfaceReconstructionFilter::New();<br>
surface->SetSampleSpacing(0.01);<br> surface->SetInput( mVtkData);<br><br> vtkContourFilter *filter = vtkContourFilter::New();<br> filter->SetValue(0,0.0);<br> vtkPolyData *output = filter->GetOutput();<br>
filter->SetInputConnection( surface->GetOutputPort() );<br> filter->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>