7 #include "imstkImplicitGeometryToImageData.h" 8 #include "imstkImageData.h" 9 #include "imstkLogger.h" 10 #include "imstkGeometryUtilities.h" 11 #include "imstkImplicitGeometry.h" 12 #include "imstkDataArray.h" 16 ImplicitGeometryToImageData::ImplicitGeometryToImageData()
19 setRequiredInputType<ImplicitGeometry>(0);
25 std::shared_ptr<ImageData>
26 ImplicitGeometryToImageData::getOutputImage()
const 28 return std::dynamic_pointer_cast<ImageData>(
getOutput(0));
41 if (inputGeometry ==
nullptr)
43 LOG(WARNING) <<
"No inputGeometry to rasterize";
47 if (m_Dimensions[0] == 0 || m_Dimensions[1] == 0 || m_Dimensions[2] == 0)
49 LOG(WARNING) <<
"Dimensions must be non-zero";
53 const Vec3d size = Vec3d(m_Bounds[1] - m_Bounds[0], m_Bounds[3] - m_Bounds[2], m_Bounds[5] - m_Bounds[4]);
54 const Vec3d spacing = size.cwiseQuotient(m_Dimensions.cast<
double>());
55 const Vec3d origin = Vec3d(m_Bounds[0], m_Bounds[2], m_Bounds[4]);
56 const Vec3d shift = origin + spacing * 0.5;
58 std::shared_ptr<ImageData> outputImage = std::make_shared<ImageData>();
59 outputImage->allocate(IMSTK_DOUBLE, 1, m_Dimensions, spacing, origin);
61 double* imgPtr = scalars.getPointer();
64 for (
int z = 0; z < m_Dimensions[2]; z++)
66 for (
int y = 0; y < m_Dimensions[1]; y++)
68 for (
int x = 0; x < m_Dimensions[0]; x++, i++)
70 const Vec3d pos = Vec3d(x, y, z).cwiseProduct(spacing) + shift;
71 imgPtr[i] = inputGeometry->getFunctionValue(pos);
std::shared_ptr< Geometry > getInput(size_t port=0) const
Returns input geometry given port, returns nullptr if doesn't exist.
void setInputGeometry(std::shared_ptr< ImplicitGeometry > inputGeometry)
Required input, port 0.
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'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 requestUpdate() override
Users can implement this for the logic to be run.
void setNumInputPorts(const size_t numPorts)
Get/Set the amount of input ports.
Class that can represent the geometry of multiple implicit geometries as boolean functions One may su...