[vtkusers] vtkSurfaceReconstructionFilter

George Kamucha kamucha at hfm.e-technik.uni-kassel.de
Thu Nov 28 06:54:19 EST 2002


Hi all,
I am trying to use vtkSurfaceReconstructionFilter to generate a surface
of the two upper planes of a wedge model (see the program below) from
vtkPoints. If I display the vtkPoints as a cloud of points (by entering
1), the surface looks perfect. But when I use the
vtkSurfaceReconstructionFilter (by entering 2), the surface looks
disjointed and there also appears an extra plane! What am I doing wrong?
>From the archives, I didn't get any useful hint of going about it apart
from using vtkPowerCrustSurfaceReconstruction which requires vtk4 (I am
still using 3.2). Any other options available?

Regards
George

#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkWedge.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkPoints.h"
#include "vtkUnstructuredGrid.h"
#include "vtkDataSetMapper.h"
#include "vtkDataSetWriter.h"
#include "vtkTriangleFilter.h"
#include "vtkGaussianSplatter.h"
#include "vtkContourFilter.h"
#include "vtkSurfaceReconstructionFilter.h"
#include "vtkReverseSense.h"
#include "vtkDelaunay3D.h"


#include "SaveImage.h"

void main( int argc, char *argv[] )
{
  // create a rendering window and renderer
  vtkRenderer *ren = vtkRenderer::New();
  vtkRenderWindow *renWindow = vtkRenderWindow::New();
    renWindow->AddRenderer(ren);
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWindow);
  renWindow->SetSize( 300, 300 );


// Create points
  vtkPoints *wedgePoints = vtkPoints::New();
   wedgePoints->SetNumberOfPoints(3321);

vtkScalars *scalars = vtkScalars::New(VTK_INT);
vtkCellArray *verts = vtkCellArray::New();
int x, z, i, n;
i=0;

for (x=0; x<41; x++)
 {
    for (z=0; z<41; z++)

      {
        if (z !=40)
  {
           wedgePoints->InsertPoint(i,x,0.5*z,z);
           scalars->InsertScalar(i, i);
           //int Id = i;
           verts->InsertNextCell(1, &i);
           i +=1;

    wedgePoints->InsertPoint(i,x,(40-0.5*z),z);
           scalars->InsertScalar(i, i);

           verts->InsertNextCell(1, &i);

           i +=1;

          }
         else
          {
           wedgePoints->InsertPoint(i,x,0.5*z,z);
           scalars->InsertScalar(i, i);
           //int Id = i;
           verts->InsertNextCell(1, &i);

           i +=1;

           }
      }
  }

  cout<<"Total number of Points:"<<i<<"\n";


  vtkPolyData *wedgeData = vtkPolyData::New();
      wedgeData->SetPoints(wedgePoints);
      wedgeData->GetPointData()->SetScalars(scalars);
      wedgeData->SetVerts(verts);



vtkSurfaceReconstructionFilter *surf =
vtkSurfaceReconstructionFilter::New();
    surf->SetInput(wedgeData);

vtkContourFilter *cf = vtkContourFilter::New();
    cf->SetInput(surf->GetOutput());
    cf->SetValue(0, 0.0);

vtkPolyDataMapper *wedgeMapper = vtkPolyDataMapper::New();

cout<<"Enter 1 to display data as a cloud of points or 2 as a surface
using vtkSurfaceReconstructionFilter:\n";

cin>>n;

if (n==1) {

// Display the data as a cloud of points

      wedgeMapper->SetInput(wedgeData);
      wedgeMapper->ScalarVisibilityOff();
          }

else if (n==2) {

//Use vtkSurfaceReconstructionFilter

      wedgeMapper->SetInput(cf->GetOutput());
      wedgeMapper->ScalarVisibilityOff();
                 }

vtkActor *wedgeActor = vtkActor::New();
       wedgeActor->SetMapper(wedgeMapper);
       wedgeActor->GetProperty()->SetColor(1, 0.8, 0.8);



  vtkDataSetWriter *dsw = vtkDataSetWriter::New();
    dsw->SetInput(cf->GetOutput());
    dsw->SetFileName("../../../vtkdata/Wedge.vtk");
    //dsw->Write();
    //dsw->Update();

  // assign our actor to the renderer
  ren->AddActor(wedgeActor);
  ren->SetBackground(1, 1, 1); // Set background white

  // draw the resulting scene
  renWindow->Render();

  SAVEIMAGE( renWindow );

  //  Begin mouse interaction
  iren->Start();

  // Clean up
  wedgePoints->Delete();
  scalars->Delete();
  verts->Delete();
  ren->Delete();
  renWindow->Delete();
  iren->Delete();
  wedgeData->Delete();
  surf->Delete();
  cf->Delete();
  //reverse->Delete();
  wedgeMapper->Delete();
  wedgeActor->Delete();
  //del->Delete();
}





More information about the vtkusers mailing list