![]() |
ImFusion SDK 4.3
|
#include <ImFusion/ML/AdvancedParameter.h>
The AdvancedParameter class extends the Parameter class by providing some additional functionalities used in ML::Operation and ML::ImageROISampler classes, like specifying whether a parameter is required for the object to work, and automatically logging an error message in case the user doesn't provide it. More...
The AdvancedParameter class extends the Parameter class by providing some additional functionalities used in ML::Operation and ML::ImageROISampler classes, like specifying whether a parameter is required for the object to work, and automatically logging an error message in case the user doesn't provide it.
You can also add a deprecated param name, and the class will check and cast a deprecation warning. In case of a configure error, a ParamException is raised.
Public Attributes | |
is stored as | string |
Create an Enum Parameter that is directly registered to the Parent, which can be serialized as string for better UX. | |
![]() | |
Signal | signalValueChanged |
Signal gets emitted when the underlying value of the Parameter/SubProperty has changed (either through setValue() or configure()). | |
Additional Inherited Members | |
![]() | |
template<typename U> | |
Parameter (const std::string &name, U &&value) | |
Creates a Parameter that will be configured under the given name and with the given initial value. | |
template<typename U> | |
Parameter (const std::string &name, U &&value, Configurable *parent) | |
Create a Parameter that is directly registered with the parent Configurable instance. | |
template<typename U> | |
Parameter (const std::string &name, U &&value, Configurable &parent) | |
Parameter (const Parameter< T > &other) | |
Parameter (Parameter< T > &&other) | |
Parameter< T > & | operator= (const Parameter< T > &other) |
Assigns value, default value, type, and attributes from another Parameter instance of the same type and emits signalValueChanged. | |
Parameter< T > & | operator= (Parameter< T > &other) |
Assigns value, default value, type, and attributes from another Parameter instance of the same type and emits signalValueChanged. | |
Parameter< T > & | operator= (Parameter< T > &&other) |
Assigns value, default value, type, and attributes from another Parameter instance of the same type and emits signalValueChanged. | |
template<typename U> | |
Parameter< T > & | operator= (U &&value) |
Updates the Parameter's stored value, emits the signalValueChanged if needed. | |
template<typename U> | |
void | setValue (U &&value) |
Updates the Parameter's stored value, emits the signalValueChanged if needed. | |
const T & | value () const |
Returns the currently stored value. | |
operator const T & () const | |
Returns the currently stored value. | |
void | setDefault (const T &defaultValue) |
Sets the default value for this parameter. | |
void | removeDefault () |
Removes the default value for this parameter. | |
std::optional< T > | defaultValue () const |
Returns the default value of this parameter if specified. | |
void | setType (Properties::ParamType type) |
Sets an optional custom ParamType. | |
template<typename Q = T> | |
std::enable_if_t< std::is_arithmetic_v< Q > > | setRange (T min, T max) |
Set the min /max parameter attributes of arithmetic parameters. | |
template<typename Q = T> | |
std::enable_if_t< std::is_same_v< Q, std::optional< typename Q::value_type > > &&std::is_arithmetic_v< typename Q::value_type > > | setRange (typename Q::value_type min, typename Q::value_type max) |
Set the min /max parameter attributes of optional arithmetic parameters. | |
void | configure (const Properties *p) override |
Configure this parameter/sub property by de-serializing the given Properties. | |
void | configuration (Properties *p) const override |
Serialize the current parameter/sub property state into the given Properties object. | |
![]() | |
ParameterBase (const std::string &name) | |
const Configurable * | parent () const |
Return the parent Configurable instance that this parameter is registered with. | |
virtual const std::string & | name () const |
Returns parameter name, can only be set during construction. | |
void | setAttribute (const std::string &key, const std::string &value) |
Add the given attribute key-value pair to the set of parameter attributes. | |
void | removeAttribute (const std::string &key) |
Remove the attribute with the given key. | |
const std::map< std::string, std::string > & | attributes () const |
Get the attribute map. | |
void | setLabel (const std::string &label) |
Sets an optional label for the Parameter if displayed in the UI. | |
void | addDeprecatedName (const std::string &deprecatedName) |
Adds an optional alternative parameter name that should be used for param lookup for during configure() in case de-serialization from m_name was not successful. | |
const std::vector< std::string > & | deprecatedNames () const |
Returns the list of deprecated parameter names that should be used for param lookup (see addDeprecatedName()). | |
![]() | |
void | setParentFromCopy (const ParameterBase &other) |
Helper function to be called from a copy/move ctor in order to correctly set the parent relation ship to the new parent Configurable. | |
![]() | |
T | m_value |
std::optional< T > | m_defaultValue |
Properties::ParamType | m_type = Properties::ParamType::Unknown |
![]() | |
Configurable * | m_parent = nullptr |
const std::string | m_name |
std::vector< std::string > | m_deprecatedNames |
std::map< std::string, std::string > | m_attributes |
is stored as string |
Create an Enum Parameter that is directly registered to the Parent, which can be serialized as string for better UX.
enumNames
shall match the number of enum fields and their definition order template <typename U, REQUIRE_ENUM(U)> AdvancedParameter(const std::string& name, U&& value, Parent* parent, ParamRequired required, std::string deprecatedName = "", std::function<std::string(T)> convertEnumToString = nullptr, std::function<T(const std::string&)> convertStringToEnum = nullptr, const std::vector<std::string>& enumNames = {}) : Parameter<T>(name, std::forward<U>(value)) , m_parent(parent) , m_required(required) , m_convertEnumToString(convertEnumToString) , m_convertStringToEnum(convertStringToEnum) , m_enumNames(enumNames) { if (m_parent) m_parent->registerParameter(this);if (!deprecatedName.empty()) Parameter<T>::addDeprecatedName(deprecatedName);
Add lambdas for commonly used enum if constexpr (std::is_same_v<T, PaddingMode>) { m_convertEnumToString = paddingModeToString; m_convertStringToEnum = stringToPaddingMode; m_enumNames = {"zero", "mirror", "clamp"}; } else if constexpr (std::is_same_v<T, ParamUnit>) { m_convertEnumToString = paramUnitToString; m_convertStringToEnum = stringToParamUnit; m_enumNames = {"MM", "Fraction", "Voxel"}; }
if (!m_enumNames.empty()) { Parameter<T>::setType(Properties::ParamType::EnumString); Parameter<T>::setAttribute("values", String::join(m_enumNames, ",")); } }
/ Create a Parameter that is directly registered to the Parent template <typename U, PROHIBIT_ENUM(U)> AdvancedParameter(const std::string& name, U&& value, Parent* parent, ParamRequired required, std::string deprecatedName = "") : Parameter<T>(name, std::forward<U>(value)) , m_parent(parent) , m_required(required) { if (m_parent) m_parent->registerParameter(this);
if (!deprecatedName.empty()) Parameter<T>::addDeprecatedName(deprecatedName); }
template <typename U> AdvancedParameter<T, Parent>& operator=(U&& value) { Parameter<T>::setValue(std::forward<U>(value)); return *this; }
using Parameter<T>::value; T& value() { return Parameter<T>::m_value; }
cast operator for implicit casting to underlying type operator const T&() const { return Parameter<T>::m_value; } operator T&() { return Parameter<T>::m_value; }
bool readParam(const std::string& pname, const Properties* properties, T& outParam) { if constexpr (std::is_same_v<T, vec3>) { return ML::detail::readVec3OrVec2OrScalar(*properties, pname, outParam, Parameter<T>::m_defaultValue.value_or(T::Zero())); } else if constexpr (std::is_same_v<T, vec3i>) { return ML::detail::readVec3iOrVec2iOrScalar(*properties, pname, outParam, Parameter<T>::m_defaultValue.value_or(T::Zero())); } else if constexpr (std::is_enum_v<T>) { We first try parsing the enum from an int, this is the default behavior if (std::optional<int> mode = properties->param<int>(pname)) { outParam = static_cast<T>(*mode); return true; } // otherwise we try with the string representation else if (auto modeStr = properties->param<std::string>(pname)) { if (m_convertStringToEnum != nullptr) { outParam = m_convertStringToEnum(*modeStr); return true; } else { LOG_ERROR( "Enum Parameter `" + Parameter<T>::m_name +