iMSTK
Interactive Medical Simulation Toolkit
imstkQuadricDecimate.cpp
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #include "imstkQuadricDecimate.h"
8 #include "imstkSurfaceMesh.h"
9 #include "imstkLogger.h"
10 #include "imstkGeometryUtilities.h"
11 
12 #include <vtkQuadricDecimation.h>
13 
14 namespace imstk
15 {
16 QuadricDecimate::QuadricDecimate() :
17  m_VolumePreserving(true), m_TargetReduction(0.6)
18 {
19  setRequiredInputType<SurfaceMesh>(0);
20 
23  setOutput(std::make_shared<SurfaceMesh>());
24 }
25 
26 void
27 QuadricDecimate::setInputMesh(std::shared_ptr<SurfaceMesh> inputMesh)
28 {
29  setInput(inputMesh, 0);
30 }
31 
32 void
34 {
35  std::shared_ptr<SurfaceMesh> inputMesh = std::dynamic_pointer_cast<SurfaceMesh>(getInput(0));
36  if (inputMesh == nullptr)
37  {
38  LOG(WARNING) << "No inputMesh to clean";
39  return;
40  }
41  vtkSmartPointer<vtkPolyData> inputMeshVtk = GeometryUtils::copyToVtkPolyData(std::dynamic_pointer_cast<SurfaceMesh>(inputMesh));
42 
43  vtkNew<vtkQuadricDecimation> filter;
44  filter->SetInputData(inputMeshVtk);
45  filter->SetVolumePreservation(m_VolumePreserving);
46  filter->SetTargetReduction(m_TargetReduction);
47  filter->Update();
48 
49  setOutput(GeometryUtils::copyToSurfaceMesh(filter->GetOutput()));
50 }
51 } // namespace imstk
void setInputMesh(std::shared_ptr< SurfaceMesh > inputMesh)
Required input, port 0.
vtkSmartPointer< vtkPolyData > copyToVtkPolyData(std::shared_ptr< LineMesh > imstkMesh)
Converts imstk line mesh into a vtk polydata.
std::shared_ptr< Geometry > getInput(size_t port=0) const
Returns input geometry given port, returns nullptr if doesn&#39;t exist.
Compound Geometry.
void requestUpdate() override
Users can implement this for the logic to be run.
void setNumOutputPorts(const size_t numPorts)
Get/Set the amount of output ports.
void setInput(std::shared_ptr< Geometry > inputGeometry, size_t port=0)
Set the input at the port.
Represents a set of triangles & vertices via an array of Vec3d double vertices & Vec3i integer indice...
std::shared_ptr< SurfaceMesh > copyToSurfaceMesh(vtkSmartPointer< vtkPolyData > vtkMesh)
Converts vtk polydata into a imstk surface mesh.
void setOutput(std::shared_ptr< Geometry > inputGeometry, const size_t port=0)
Set the output at the port.
void setNumInputPorts(const size_t numPorts)
Get/Set the amount of input ports.