iMSTK
Interactive Medical Simulation Toolkit
imstkSurfaceMeshSmoothen.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 "imstkSurfaceMeshSmoothen.h"
8 #include "imstkGeometryUtilities.h"
9 #include "imstkLogger.h"
10 #include "imstkSurfaceMesh.h"
11 
12 #include <vtkSmoothPolyDataFilter.h>
13 
14 namespace imstk
15 {
16 SurfaceMeshSmoothen::SurfaceMeshSmoothen()
17 {
19  setRequiredInputType<SurfaceMesh>(0);
20 
22  setOutput(std::make_shared<SurfaceMesh>());
23 }
24 
25 void
26 SurfaceMeshSmoothen::setInputMesh(std::shared_ptr<SurfaceMesh> inputMesh)
27 {
28  setInput(inputMesh, 0);
29 }
30 
31 void
33 {
34  std::shared_ptr<SurfaceMesh> inputMesh = std::dynamic_pointer_cast<SurfaceMesh>(getInput(0));
35  if (inputMesh == nullptr)
36  {
37  LOG(WARNING) << "No inputMesh to smoothen";
38  return;
39  }
40 
41  vtkNew<vtkSmoothPolyDataFilter> filter;
42  filter->SetInputData(GeometryUtils::copyToVtkPolyData(inputMesh));
43  filter->SetNumberOfIterations(m_NumberOfIterations);
44  filter->SetRelaxationFactor(m_RelaxationFactor);
45  filter->SetConvergence(m_Convergence);
46  filter->SetFeatureAngle(m_FeatureAngle);
47  filter->SetEdgeAngle(m_EdgeAngle);
48  filter->SetFeatureEdgeSmoothing(m_FeatureEdgeSmoothing);
49  filter->SetBoundarySmoothing(m_BoundarySmoothing);
50  filter->Update();
51 
52  setOutput(GeometryUtils::copyToSurfaceMesh(filter->GetOutput()));
53 }
54 } // namespace imstk
void requestUpdate() override
Users can implement this for the logic to be run.
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 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 setInputMesh(std::shared_ptr< SurfaceMesh > inputMesh)
Required input, port 0.
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.