iMSTK
Interactive Medical Simulation Toolkit
imstkExtractEdges.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 "imstkExtractEdges.h"
8 #include "imstkGeometryUtilities.h"
9 #include "imstkLineMesh.h"
10 #include "imstkLogger.h"
11 #include "imstkSurfaceMesh.h"
12 
13 #include <vtkExtractEdges.h>
14 #include <vtkTriangleFilter.h>
15 
16 namespace imstk
17 {
18 ExtractEdges::ExtractEdges()
19 {
21  setRequiredInputType<SurfaceMesh>(0);
22 
24  setOutput(std::make_shared<LineMesh>());
25 }
26 
27 void
28 ExtractEdges::setInputMesh(std::shared_ptr<SurfaceMesh> inputMesh)
29 {
30  setInput(inputMesh, 0);
31 }
32 
33 std::shared_ptr<LineMesh>
34 ExtractEdges::getOutputMesh() const
35 {
36  return std::static_pointer_cast<LineMesh>(getOutput(0));
37 }
38 
39 void
41 {
42  std::shared_ptr<SurfaceMesh> inputMesh = std::dynamic_pointer_cast<SurfaceMesh>(getInput(0));
43  if (inputMesh == nullptr)
44  {
45  LOG(WARNING) << "No inputMesh to extract edges from";
46  return;
47  }
48 
49  vtkNew<vtkExtractEdges> extractEdges;
50  extractEdges->SetInputData(GeometryUtils::copyToVtkPolyData(inputMesh));
51  extractEdges->Update();
52 
53  vtkNew<vtkTriangleFilter> triangleFilter;
54  triangleFilter->SetInputData(extractEdges->GetOutput());
55  triangleFilter->Update();
56 
57  setOutput(GeometryUtils::copyToLineMesh(triangleFilter->GetOutput()));
58 }
59 } // namespace imstk
std::shared_ptr< LineMesh > copyToLineMesh(vtkSmartPointer< vtkPolyData > vtkMesh)
Converts vtk polydata into a imstk surface mesh.
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.
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...
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.