iMSTK
Interactive Medical Simulation Toolkit
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
imstkSurfaceMeshFlyingEdges.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 "imstkSurfaceMeshFlyingEdges.h"
8 #include "imstkGeometryUtilities.h"
9 #include "imstkImageData.h"
10 #include "imstkLogger.h"
11 #include "imstkSurfaceMesh.h"
12 
13 #include <vtkFlyingEdges3D.h>
14 #include <vtkImageData.h>
15 
16 namespace imstk
17 {
18 SurfaceMeshFlyingEdges::SurfaceMeshFlyingEdges()
19 {
21  setRequiredInputType<ImageData>(0);
22 
24  setOutput(std::make_shared<SurfaceMesh>());
25 }
26 
27 void
28 SurfaceMeshFlyingEdges::setInputImage(std::shared_ptr<ImageData> inputImage)
29 {
30  setInput(inputImage, 0);
31 }
32 
33 std::shared_ptr<SurfaceMesh>
34 SurfaceMeshFlyingEdges::getOutputMesh() const
35 {
36  return std::dynamic_pointer_cast<SurfaceMesh>(getOutput(0));
37 }
38 
39 void
41 {
42  std::shared_ptr<ImageData> inputImage = std::dynamic_pointer_cast<ImageData>(getInput(0));
43  if (inputImage == nullptr)
44  {
45  LOG(WARNING) << "No inputImage to extract isosurface from";
46  return;
47  }
48 
49  vtkNew<vtkFlyingEdges3D> filter;
50  filter->SetInputData(GeometryUtils::coupleVtkImageData(inputImage));
51  filter->SetValue(0, m_IsoValue);
52  filter->ComputeNormalsOff();
53  filter->ComputeScalarsOff();
54  filter->ComputeGradientsOff();
55  filter->Update();
56 
57  std::shared_ptr<SurfaceMesh> outputSurfMesh = GeometryUtils::copyToSurfaceMesh(filter->GetOutput());
58  *std::dynamic_pointer_cast<SurfaceMesh>(getOutput(0)) = *outputSurfMesh->clone();
59 }
60 } // namespace imstk
std::shared_ptr< Geometry > getInput(size_t port=0) const
Returns input geometry given port, returns nullptr if doesn&#39;t exist.
Compound Geometry.
std::unique_ptr< SurfaceMesh > clone()
Polymorphic clone, hides the declaration in superclass return own type.
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.
void setInputImage(std::shared_ptr< ImageData > inputImage)
Required input, port 0.
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.
Class to represent 1, 2, or 3D image data (i.e. structured points)