iMSTK
Interactive Medical Simulation Toolkit
imstkImageResample.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 "imstkImageResample.h"
8 #include "imstkDataArray.h"
9 #include "imstkGeometryUtilities.h"
10 #include "imstkImageData.h"
11 #include "imstkLogger.h"
12 #include "imstkParallelFor.h"
13 #include <vtkImageData.h>
14 #include <vtkImageResample.h>
15 #include <vtkSmartPointer.h>
16 
17 namespace imstk
18 {
19 ImageResample::ImageResample()
20 {
22  setRequiredInputType<ImageData>(0);
23 
25  setOutput(std::make_shared<ImageData>());
26 }
27 
28 std::shared_ptr<ImageData>
29 ImageResample::getOutputImage() const
30 {
31  return std::dynamic_pointer_cast<ImageData>(getOutput(0));
32 }
33 
34 void
35 ImageResample::setInputImage(std::shared_ptr<ImageData> inputData)
36 {
37  setInput(inputData, 0);
38 }
39 
40 void
42 {
43  std::shared_ptr<ImageData> inputImage = std::dynamic_pointer_cast<ImageData>(getInput(0));
44  if (inputImage == nullptr)
45  {
46  LOG(WARNING) << "No inputImage to resample";
47  return;
48  }
49 
50  vtkNew<vtkImageResample> resample;
51  resample->SetInputData(GeometryUtils::copyToVtkImageData(inputImage));
52  resample->SetInterpolationModeToLinear();
53  resample->SetOutputExtent(0, m_Dimensions[0] - 1, 0, m_Dimensions[1] - 1, 0, m_Dimensions[2] - 1);
54  resample->Update();
55 
56  setOutput(GeometryUtils::copyToImageData(resample->GetOutput()));
57 }
58 } // namespace imstk
void requestUpdate() override
Users can implement this for the logic to be run.
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.
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.
Class to represent 1, 2, or 3D image data (i.e. structured points)