[vtkusers] question ? [hole filling inside the mesh]

agatte agatakrason at gmail.com
Mon Sep 28 10:49:14 EDT 2015


Hi,

I have a surface with lots of small holes. 
I would like to  fill these holes.
I used hole filling filter. I followed example from wiki :
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Meshes/FillHoles
But I don't know why it didn't work in mycase.  I received empty file
without any surface. 

Could anybody help me please ? 

here surface with holes :
<http://vtk.1045678.n5.nabble.com/file/n5734157/surface.png> 

Here my code :

  vtkSmartPointer<vtkMetaImageReader> reader =
vtkSmartPointer<vtkMetaImageReader>::New();
  reader->SetFileName(inputFilename.c_str());
  reader->Update();

  vtkSmartPointer<vtkMarchingCubes> surface = 
vtkSmartPointer<vtkMarchingCubes>::New();
  surface->SetInputConnection(reader->GetOutputPort());
  surface->ComputeNormalsOn();
  surface->ComputeGradientsOn();
  surface->ComputeScalarsOn();
  surface->SetValue(0,5.0);
  surface->Update();

  vtkSmartPointer<vtkPolyData> polyData = surface->GetOutput();
  
  // To remain largest region
  vtkSmartPointer<vtkPolyDataConnectivityFilter> conFilter =
vtkSmartPointer<vtkPolyDataConnectivityFilter>::New();
  conFilter->SetInputConnection(surface->GetOutputPort());
  conFilter->SetExtractionModeToLargestRegion();
  conFilter->Update();

  // Decimation
  vtkSmartPointer<vtkDecimatePro> decimateFilter =
vtkSmartPointer<vtkDecimatePro>::New();
  decimateFilter->SetInputData(conFilter->GetOutput());
  decimateFilter->SetTargetReduction(.5); //10% reduction (if there was 100
triangles, now there will be 90)
  decimateFilter->Update();

  vtkSmartPointer<vtkSmoothPolyDataFilter> smoothFilter =
vtkSmartPointer<vtkSmoothPolyDataFilter>::New();
  smoothFilter->SetInputConnection(decimateFilter->GetOutputPort());
  smoothFilter->SetNumberOfIterations(6000);
  smoothFilter->Update();

  vtkSmartPointer<vtkPolyData> smoothPolyData = smoothFilter->GetOutput();
  
  vtkSmartPointer<vtkFeatureEdges> featureEdges =
vtkSmartPointer<vtkFeatureEdges>::New();
  featureEdges->SetInputConnection(smoothFilter->GetOutputPort());
  featureEdges->BoundaryEdgesOn();
  featureEdges->FeatureEdgesOn();
  featureEdges->ManifoldEdgesOn();
  featureEdges->NonManifoldEdgesOn();
  featureEdges->Update();

  int numberOfOpenEdges = featureEdges->GetOutput()->GetNumberOfCells();

  std::cout << "Number of open edges : " <<numberOfOpenEdges<<
std::endl;
  vtkSmartPointer<vtkFillHolesFilter> fillHolesFilter =
vtkSmartPointer<vtkFillHolesFilter>::New();
  fillHolesFilter->SetInputData(smoothPolyData);
  fillHolesFilter->SetHoleSize(1000.0);
  fillHolesFilter->Update();

  vtkSmartPointer<vtkPolyDataNormals> normals =
vtkSmartPointer<vtkPolyDataNormals>::New();
  normals->SetInputData(fillHolesFilter->GetOutput());
  normals->ConsistencyOff();
  normals->SplittingOn();
  normals->Update();


normals->GetOutput()->GetPointData()->SetNormals(polyData->GetPointData()->GetNormals());

  vtkSmartPointer<vtkPolyDataWriter> polyWriter =
vtkSmartPointer<vtkPolyDataWriter>::New();
  polyWriter->SetInputConnection( normals->GetOutputPort());
  polyWriter->SetFileName("deformedSurface.vtk");
  polyWriter->Write();


I would appreciate for any advice. 


agatte



--
View this message in context: http://vtk.1045678.n5.nabble.com/question-hole-filling-inside-the-mesh-tp5734157.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list