[vtkusers] Creating a surface mesh from a point cloud

I. Matei Ciocarlie ciocarlie at willowgarage.com
Thu Jul 24 18:15:34 EDT 2008


Dear VTK users,

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.

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.

Thank you,
Matei

DETAILS:

- 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 )

- 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 )

- 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

OPTION 1)

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.

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!

OPTION 2)

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.

In both cases, if I replace vtkContourFilter with vtkMarchingCubes, the
result is identical.

Here is my exact code:

1) Create and populate vtkPolyData

    // Create a float array which represents the points.
    vtkFloatArray* pcoords = vtkFloatArray::New();
    pcoords->SetNumberOfComponents(3);
    pcoords->SetNumberOfTuples(mNumPoints);
    for (int i=0; i<mNumPoints; i++){
        pcoords->SetTuple3(i, mNativePoints[i].x, mNativePoints[i].y,
mNativePoints[i].z);
    }
    // Create vtkPoints and assign pcoords as the internal data array.
    vtkPoints* points = vtkPoints::New();
    points->SetData(pcoords);
    // Create vtkPolyData and assign vtkPoints as internal data
    mVtkData = vtkPolyData::New();
    mVtkData->SetPoints(points);

    //for some functions it seems we also need the points represented as
"cells"...
    vtkCellArray *cells = vtkCellArray::New();
    for (int i=0; i<mNumPoints; i++) {
        cells->InsertNextCell(1);
        cells->InsertCellPoint(i);
    }
    mVtkData->SetVerts(cells);

2) attempt surface mesh generation

    vtkImplicitModeller *modeller = vtkImplicitModeller::New();
    modeller->SetInput( mVtkData );
    //    am incercat diversi parametri:
    //    modeller->SetSampleDimensions(100, 100, 100);
    //    modeller->SetMaximumDistance(0.2);
    //    modeller->SetModelBounds(-1,-1,-1,1,1,1);

    vtkContourFilter *filter = vtkContourFilter::New();
    filter->SetValue(0,0.0);
    vtkPolyData *output = filter->GetOutput();
    filter->SetInputConnection( modeller->GetOutputPort() );
    filter->Update();

------------------------ and I get a completely empty result


    vtkSurfaceReconstructionFilter *surface =
vtkSurfaceReconstructionFilter::New();
    surface->SetSampleSpacing(0.01);
    surface->SetInput( mVtkData);

    vtkContourFilter *filter = vtkContourFilter::New();
    filter->SetValue(0,0.0);
    vtkPolyData *output = filter->GetOutput();
    filter->SetInputConnection( surface->GetOutputPort() );
    filter->Update();

--------------------------- and I get a strange result that is not the
surface mesh I am looking for

Again - any kind of help much much appreciated!!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080724/1b8a39ff/attachment.htm>


More information about the vtkusers mailing list