[vtkusers] Extracting a volume from a set of points

Vetria Byrd byrdv at cis.uab.edu
Fri Apr 22 13:50:39 EDT 2005


I am trying to extract a small volume from a set of 48 points.

 

I have downloaded reconstructSurface.py from the vtk website and converted
it to C++ (code included below).

I added a line to print out the number of triangles read.  The program
reports 144 triangles.  It is treating each line of 3 points as one
triangle, but my input data is in the format described below:

 

T0V1X  T0V1Y T0V1Z

T0V2X  T0V2Y T0V2Z

T0V3X  T0V3Y T0V3Z

:

:

T48V1X  T48V1Y  T48V1Z

T48V2X  T48V2Y  T48V2Z

T48V3X  T48V3Y  T48V3Z

 

Where T# is the triangle, V# is the vertex and x,y and z are the coordinate
axis.

 

I need a way to read and render the data points.

Any suggestions on how I can further modify reconstructSurface.py to
recognize my data points?

 

Thank you.

 

Source code for reconstructSurface.py converted to C++

:

#include "vtkPolyData.h"

#include "vtkPoints.h"

#include "vtkSurfaceReconstructionFilter.h"

#include "vtkContourFilter.h"

#include "vtkReverseSense.h"

#include "vtkPolyDataMapper.h"

#include "vtkProperty.h"

#include "vtkActor.h"

#include "vtkCamera.h"

#include "vtkRenderer.h"

#include "vtkRenderWindow.h"

#include "vtkRenderWindowInteractor.h"

#include "vtkDecimatePro.h"

#include "vtkSmoothPolyDataFilter.h"

#include "vtkPolyDataNormals.h"

 

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\n", iCounter);

            float x, y, z;

            fscanf(datei,"%f %f %f\n", &x, &y, &z);

            points->InsertPoint(iCounter++, x, y, z);

            fprintf(stdout,"%f %f %f\n",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);

 

#ifdef _SMOOTHING_

      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_

      smoother->Delete();

      normals->Delete();

#else

      reverse->Delete();

#endif

      map->Delete();

      surfaceActor->Delete();

      camera->Delete();

      renderer->Delete();

      renWin->Delete();

      iren->Delete();

 

      return 0;

}

 

 

_______________

Vetria L. Byrd

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050422/4fe6c7dd/attachment.htm>


More information about the vtkusers mailing list