[vtkusers] how to reduce the density of the mesh surface.

Martin Baumann mailsgetlost at web.de
Sat Mar 15 09:42:51 EDT 2008


Hi,

the following code snippet should do a reduction using
vtkQuadricdecimation and vtkDecimationPro

  // Parameters
  double target_reduction  = 0.98;                             // for vtkQuadricDecimation
  int    smoothing_steps_1 = 10;                               // after vtkQuadricDecimation
  int    smoothing_steps_2 = 10;                               // after vtkDecimatePro


  // read STL file
  vtkSTLReader* stl_reader = vtkSTLReader::New();
  stl_reader->SetFileName(in_file);
        

  // reduce triangles using vtkQuadricDecimation
  vtkQuadricDecimation* reduction1 = vtkQuadricDecimation::New();
  reduction1->SetInputConnection(stl_reader->GetOutputPort());
  reduction1->SetTargetReduction(target_reduction);

  vtkSmoothPolyDataFilter* smoother1 = vtkSmoothPolyDataFilter::New();
  smoother1->SetInputConnection(reduction1->GetOutputPort());
  smoother1->SetNumberOfIterations(smoothing_steps_1);


  // reduce triangles using vtkDecimatePro
  vtkDecimatePro* reduction2 = vtkDecimatePro::New();
  reduction2->SetInputConnection(smoother1->GetOutputPort());
  reduction2->SetPreserveTopology(1);

  vtkSmoothPolyDataFilter* smoother2 = vtkSmoothPolyDataFilter::New();
  smoother2->SetInputConnection(reduction2->GetOutputPort());
  smoother2->SetNumberOfIterations(smoothing_steps_2);


Best regards,
M.B.


Dongqing Chen schrieb:
> Dear all:
>  
>   I am working on generating a mesh surface of segmented liver CT
> images. Right now, I could generate the mesh surface and save it to
> stl file. But the numbers of polygon and vertices are very huge:
> 781052 and about 2.3M, respectively. The code patches are shown as
> follows.  Is there any way to make the surface mesh much coarser?
>  
> ***********************************************************************
>   vtkTriangleFilter* triangles=vtkTriangleFilter::New();
>   triangles->SetInput(smooth->GetOutput());
>         
>   vtkSTLWriter* stlWriter=vtkSTLWriter::New();
>   stlWriter->SetInput(triangles->GetOutput());
>   stlWriter->SetFileName("40g.stl");
>   stlWriter->Write();
> ************************************************************************
>  
> Best Wishes,
> -----------------------------------------------------------------
> Dongqing Chen
> Ph.D Candidate
> Rm. 07, Paul C. Lutz Hall
> Computer Vision & Image Processing (CVIP) Lab
> Department of Electrical & Computer Engineering
> Speed School of Engineering
> University of Louisville
> Louisville, KY. 40292
> U.S.A
> Email: dqchen at cvip.louisville.edu <mailto:dqchen at cvip.louisville.edu>
> Phone:+1-502-852-2789 (Lab)
>             +1-502-852-6130 (Office)
> -----------------------------------------------------------------
> ------------------------------------------------------------------------
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>   



More information about the vtkusers mailing list