iMSTK
Interactive Medical Simulation Toolkit
imstkSurfaceMeshSubdivide.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 "imstkSurfaceMeshSubdivide.h"
8 #include "imstkGeometryUtilities.h"
9 #include "imstkSurfaceMesh.h"
10 #include "imstkLogger.h"
11 
12 #include <vtkButterflySubdivisionFilter.h>
13 #include <vtkLinearSubdivisionFilter.h>
14 #include <vtkLoopSubdivisionFilter.h>
15 
16 namespace imstk
17 {
18 SurfaceMeshSubdivide::SurfaceMeshSubdivide()
19 {
21  setRequiredInputType<SurfaceMesh>(0);
22 
24  setOutput(std::make_shared<SurfaceMesh>());
25 }
26 
27 std::shared_ptr<SurfaceMesh>
28 SurfaceMeshSubdivide::getOutputMesh()
29 {
30  return std::dynamic_pointer_cast<SurfaceMesh>(getOutput(0));
31 }
32 
33 void
34 SurfaceMeshSubdivide::setInputMesh(std::shared_ptr<SurfaceMesh> inputMesh)
35 {
36  setInput(inputMesh, 0);
37 }
38 
39 void
41 {
42  std::shared_ptr<SurfaceMesh> inputMesh = std::dynamic_pointer_cast<SurfaceMesh>(getInput(0));
43 
44  if (inputMesh == nullptr)
45  {
46  LOG(WARNING) << "Missing required SurfaceMesh input";
47  return;
48  }
49 
50  vtkSmartPointer<vtkSubdivisionFilter> filter = nullptr;
51  if (m_SubdivisionType == Type::BUTTERFLY)
52  {
53  filter = vtkSmartPointer<vtkButterflySubdivisionFilter>::New();
54  }
55  else if (m_SubdivisionType == Type::LOOP)
56  {
57  filter = vtkSmartPointer<vtkLoopSubdivisionFilter>::New();
58  }
59  else
60  {
61  filter = vtkSmartPointer<vtkLinearSubdivisionFilter>::New();
62  }
63 
64  filter->SetInputData(GeometryUtils::copyToVtkPolyData(inputMesh));
65  filter->SetNumberOfSubdivisions(m_NumberOfSubdivisions);
66  filter->Update();
67 
68  setOutput(GeometryUtils::copyToSurfaceMesh(filter->GetOutput()));
69 }
70 } // namespace imstk
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 requestUpdate() override
Users can implement this for the logic to be run.
std::shared_ptr< Geometry > getOutput(size_t port=0) const
Returns output geometry given port, returns nullptr if doesn&#39;t exist.
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.