[vtkusers] Surfaces from cloud of points

de Boer Ingo I.deBoer at polytec.de
Mon Jan 26 05:59:57 EST 2004


Hi,

> I looking for tools in vtk to generate surfaces from cloud of points.
> I'm using vtkDelaunay but I want to know about other functions if it
> is possible
> Could somebody help me?
Try this...

greets
  Ingo

---
Dr.-Ing. Ingo H. de Boer

Polytec GmbH
Polytec-Platz 1-7, 76337 Waldbronn, Germany
phone: ++49 7243 604 106
fax  : ++49 7243 604 255

#########################################################################

int main( int argc, char *argv[] )
{
    // Read some 3d points.
    FILE *datei = fopen(argv[1],"rt");

    vtkPolyData *data = vtkPolyData::New();
    vtkPoints *points = vtkPoints::New();
    
    int iCounter = 0;
    while (!feof(datei))
    {
        fprintf(stdout,"reading points: %i\r", iCounter);
        float x, y, z;
        fscanf(datei,"%f %f %f\n", &x, &y, &z);
        points->InsertPoint(iCounter++, x, y, z);
    }
    data->SetPoints(points);
    fclose(datei);
    fprintf(stdout,"\n\n");

    // Construct the surface and create isosurface
    vtkSurfaceReconstructionFilter *surf = vtkSurfaceReconstructionFilter::New();
    surf->SetInput(data);
    vtkContourFilter *cf = vtkContourFilter::New();
    cf->SetInput((vtkDataSet*)surf->GetOutput());
    cf->SetValue(0, 0.0);

//#define _SMOOTHING_
#ifdef _SMOOTHING_
/*  vtkDecimatePro *decimate = vtkDecimatePro::New();
    decimate->SetInput(cf->GetOutput());
    decimate->SetTargetReduction(0.9);
    decimate->PreserveTopologyOn();
*/
    vtkSmoothPolyDataFilter *smoother = vtkSmoothPolyDataFilter::New();
    smoother->SetInput(cf->GetOutput());
    smoother->SetNumberOfIterations(50);

    vtkPolyDataNormals *normals = vtkPolyDataNormals::New();
    normals->SetInput(smoother->GetOutput());
    normals->FlipNormalsOn();

    vtkPolyDataMapper *map = vtkPolyDataMapper::New();
    map->SetInput(normals->GetOutput());
#else
    vtkReverseSense *reverse = vtkReverseSense::New();
    reverse->SetInput(cf->GetOutput());
    reverse->ReverseCellsOn();
    reverse->ReverseNormalsOn();

    vtkPolyDataMapper *map = vtkPolyDataMapper::New();
    map->SetInput(reverse->GetOutput());
#endif

    map->ScalarVisibilityOff();

    vtkActor *surfaceActor = vtkActor::New();
    surfaceActor->SetMapper(map);
    surfaceActor->GetProperty()->SetDiffuseColor(1.0000, 0.3882, 0.2784);
    surfaceActor->GetProperty()->SetSpecularColor(1, 1, 1);
    surfaceActor->GetProperty()->SetSpecular(.4);
    surfaceActor->GetProperty()->SetSpecularPower(50);

    // The usual rendering stuff.
    vtkCamera *camera = vtkCamera::New();
    camera->SetPosition(1,1,1);
    camera->SetFocalPoint(0,0,0);

    vtkRenderer *renderer = vtkRenderer::New();
    vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(renderer);

    vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);

    renderer->AddActor(surfaceActor);
    renderer->SetActiveCamera(camera);
    renderer->GetActiveCamera()->SetFocalPoint(0, 0, 0);
    renderer->GetActiveCamera()->SetPosition(1, 0, 0);
    renderer->GetActiveCamera()->SetViewUp(0, 0, 1);
    renderer->ResetCamera();
    renderer->GetActiveCamera()->Azimuth(20);
    renderer->GetActiveCamera()->Elevation(30);
    renderer->GetActiveCamera()->Dolly(1.2);
    renderer->ResetCameraClippingRange();
    renderer->SetBackground(1,1,1);

    renWin->SetSize(300,300);

    // interact with data
    renWin->Render();
    iren->Start();

    // Clean up
    points->Delete();
    data->Delete();
    surf->Delete();
    cf->Delete();
#ifdef _SMOOTHING_
//  decimate->Delete();
    smoother->Delete();
    normals->Delete();
#else
    reverse->Delete();
#endif
    map->Delete();
    surfaceActor->Delete();
    camera->Delete();
    renderer->Delete();
    renWin->Delete();
    iren->Delete();

    return 0;
}





More information about the vtkusers mailing list