iMSTK
Interactive Medical Simulation Toolkit
imstkAppendMesh.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 "imstkAppendMesh.h"
8 #include "imstkGeometryUtilities.h"
9 #include "imstkLogger.h"
10 #include "imstkSurfaceMesh.h"
11 
12 #include <vtkAppendPolyData.h>
13 
14 namespace imstk
15 {
16 AppendMesh::AppendMesh()
17 {
20  setOutput(std::make_shared<SurfaceMesh>());
21 }
22 
23 void
24 AppendMesh::addInputMesh(std::shared_ptr<SurfaceMesh> inputMesh)
25 {
26  setNumInputPorts(getNumInputPorts() + 1);
27  setInput(inputMesh, getNumInputPorts() - 1);
28 }
29 
30 std::shared_ptr<SurfaceMesh>
31 AppendMesh::getOutputMesh() const
32 {
33  return std::static_pointer_cast<SurfaceMesh>(getOutput(0));
34 }
35 
36 void
38 {
39  vtkNew<vtkAppendPolyData> filter;
40  for (size_t i = 0; i < getNumInputPorts(); i++)
41  {
42  std::shared_ptr<SurfaceMesh> inputMesh = std::dynamic_pointer_cast<SurfaceMesh>(getInput(i));
43  if (inputMesh == nullptr)
44  {
45  LOG(WARNING) << "Input " << i << " invalid";
46  return;
47  }
48  filter->AddInputData(GeometryUtils::copyToVtkPolyData(inputMesh));
49  }
50  filter->Update();
51 
52  setOutput(GeometryUtils::copyToSurfaceMesh(filter->GetOutput()));
53 }
54 } // 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.
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.
void requestUpdate() override
Users can implement this for the logic to be run.