ImFusion C++ SDK 4.4.0
SqrtAlgorithm.cpp
#include "SqrtAlgorithm.h"
#include <ImFusion/Base/MemImage.h>
using namespace ImFusion;
SqrtAlgorithm::SqrtAlgorithm(SharedImageSet* image)
: m_image(image)
{
configureDefaults(); // initializes the algorithm with default values in configuration
}
SqrtAlgorithm::~SqrtAlgorithm() {}
bool SqrtAlgorithm::createCompatible(const DataList& data, Algorithm** a)
{
// algorithm only supports 1 input
if (data.size() == 1)
{
// either one 2D image ..
SharedImageSet* img = data.getImage(Data::IMAGE);
if (!img)
// .. or one 3D volume
img = data.getImage(Data::VOLUME);
if (img)
{
if (a)
*a = new SqrtAlgorithm(img);
return true;
}
}
return false;
}
void SqrtAlgorithm::compute()
{
if (!m_image)
return;
// Get the currently focused MemImage from the input image
MemImage* mem = m_image->mem();
for (int z = 0; z < mem->slices(); ++z)
{
for (int y = 0; y < mem->height(); ++y)
{
for (int x = 0; x < mem->width(); ++x)
{
double val = mem->valueDouble(x, y, z);
val = std::sqrt(val) * m_multiplier;
mem->setValueDouble(val, x, y, z);
}
}
}
m_image->get()->setDirtyMem();
}
void SqrtAlgorithm::configure(const Properties* p)
{
if (!p)
return;
p->param("multiplier", m_multiplier);
}
void SqrtAlgorithm::configuration(Properties* p) const
{
if (!p)
return;
p->setParam("multiplier", m_multiplier, 2.0);
}
Interface for describing algorithms that can be made available in the ImFusion Suite through Algorith...
Definition Algorithm.h:41
@ VOLUME
3D volume
Definition Data.h:35
@ IMAGE
2D image
Definition Data.h:34
Container for any number of Data instances such as image or meshes.
Definition DataList.h:30
int width() const
Returns the width of the image.
Definition Image.h:109
int slices() const
Returns the number of 3D slices of the image.
Definition Image.h:115
int height() const
Returns the height of the image.
Definition Image.h:112
Abstract base class for an image residing in main memory.
Definition MemImage.h:20
virtual void setValueDouble(double value, size_t index) const =0
Set the pixel intensity at the given index to value casted to the underlying type without any clampin...
virtual double valueDouble(size_t index) const =0
Return the pixel intensity at the given index without interpolation casted to double.
Storage container for serialization of arbitrary types, internally backed by strings.
Definition Properties.h:50
void setParam(const std::string &name, const T &value, const T &defaultValue)
Set a parameter with arbitrary type and a default value.
Definition Properties.h:425
bool param(const std::string &name, T &value) const
Return the value of a parameter of arbitrary types.
Definition Properties.h:437
Set of images independent of their storage location.
Definition SharedImageSet.h:42
Namespace of the ImFusion SDK.
Definition Changelog.dox:1
T sqrt(T... args)
Search Tab / S to search, Esc to close