ImFusion SDK 4.3
ExampleAlgorithm.cpp
#include "ExampleAlgorithm.h"
using namespace ImFusion;
ExampleAlgorithm::ExampleAlgorithm(SharedImageSet* image)
: m_image(image)
, m_output(nullptr)
{
configureDefaults(); // Initializes the algorithm with default values in configuration
}
ExampleAlgorithm::~ExampleAlgorithm() = default;
bool ExampleAlgorithm::createCompatible(const DataList& data, Algorithm** a)
{
// Algorithm only supports 1 input
if (data.size() == 1)
{
// Check if the data is a 2D image
if (data[0]->kind() == Data::IMAGE)
{
// All 2D images are SharedImageSet objects
SharedImageSet* img = dynamic_cast<SharedImageSet*>(data[0]);
if (img) // Only allow valid 2D images
{
// If pointer is provided, create a new instance
if (a)
*a = new ExampleAlgorithm(img);
return true;
}
}
}
return false;
}
void ExampleAlgorithm::compute()
{
//... Add actual image data to m_output
}
OwningDataList ExampleAlgorithm::takeOutput()
{
// Transfer the algorithm output to the caller
result.add(std::move(m_output));
return result;
}
void ExampleAlgorithm::configure(const Properties* p)
{
if (!p)
return;
// Make sure Configuration::configure is called so all members of type Parameter are
// automatically deserialized.
// Parameters can have any name and can be accessed in any order
p->param("paramVec", m_paramVec);
p->param("firstParameter", m_paramDouble);
// Only update the parameters but try to keep additional computation to a minimum
}
void ExampleAlgorithm::configuration(Properties* p) const
{
if (!p)
return;
// Make sure Configuration::configuration is called so all members of type Parameter are
// automatically serialized.
// Use the same names in both configure and configuration
p->setParam("firstParameter", m_paramDouble);
// Parameters can have default values
p->setParam("paramVec", m_paramVec, vec2(1, 0));
// Don't save Data, e.g. m_image, in the configuration
}
Interface for describing algorithms that can be made available in the ImFusion Suite through Algorith...
Definition Algorithm.h:41
virtual void configure(const Properties *p)
Configure this object instance by de-serializing the given Properties.
virtual void configuration(Properties *p) const
Serialize the current object configuration into the given Properties object.
@ IMAGE
2D image
Definition Data.h:34
Container for any number of Data instances such as image or meshes.
Definition DataList.h:30
Wrapper class to store a list of owned Data instances.
Definition OwningDataList.h:24
virtual void add(std::unique_ptr< Data > data)
Add data to the list.
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:424
bool param(const std::string &name, T &value) const
Return the value of a parameter of arbitrary types.
Definition Properties.h:436
Set of images independent of their storage location.
Definition SharedImageSet.h:42
T make_unique(T... args)
Namespace of the ImFusion SDK.
Definition Assert.h:7
Search Tab / S to search, Esc to close