Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
PropertyAutoWrap.h File Reference
#include <mitkBaseProperty.h>
#include <mitkColorProperty.h>
#include <mitkIPropertyOwner.h>
#include <mitkProperties.h>
#include <mitkStringProperty.h>
#include <pybind11/pybind11.h>

Go to the source code of this file.

Functions

mitk::BaseProperty::Pointer pythonValueToProperty (py::object value)
 Converts a Python object to a BaseProperty, auto-wrapping common scalar types. More...
 
mitk::BaseProperty::Pointer pythonValueToPropertyWithType (py::object value, const std::string &targetType)
 Converts a Python object to a BaseProperty, coercing to a specific target class when given. More...
 
mitk::BaseProperty::Pointer coerceToExistingType (const mitk::BaseProperty *existing, py::object value)
 Coerces a Python value to the class of an existing property. More...
 
mitk::BaseProperty::Pointer resolvePropertyValue (mitk::IPropertyOwner &owner, const std::string &key, py::object value)
 Resolves a Python value to a BaseProperty, respecting any existing property's type. More...
 

Function Documentation

◆ coerceToExistingType()

mitk::BaseProperty::Pointer coerceToExistingType ( const mitk::BaseProperty *  existing,
py::object  value 
)
inline

Coerces a Python value to the class of an existing property.

Definition at line 141 of file PropertyAutoWrap.h.

References pythonValueToPropertyWithType().

Referenced by resolvePropertyValue().

◆ pythonValueToProperty()

mitk::BaseProperty::Pointer pythonValueToProperty ( py::object  value)
inline

Converts a Python object to a BaseProperty, auto-wrapping common scalar types.

Supported auto-wrap conversions:

  • bool -> BoolProperty
  • int -> IntProperty
  • float -> DoubleProperty (Python float is double-precision)
  • str -> StringProperty
  • mitk.Color -> ColorProperty
  • tuple(r, g, b) -> ColorProperty (3-element tuple shorthand; lists are not accepted in this untyped path to avoid accidental mismatches)
  • BaseProperty subclasses -> used directly

For property types without a scalar equivalent (Vector3D, Point*, ...), callers must pass an explicit mitk.<Name>Property instance.

Exceptions
py::type_errorif the Python type cannot be auto-wrapped.

Definition at line 43 of file PropertyAutoWrap.h.

References mitk::ColorProperty::New(), and mitk::StringProperty::New().

Referenced by pythonValueToPropertyWithType(), and resolvePropertyValue().

◆ pythonValueToPropertyWithType()

mitk::BaseProperty::Pointer pythonValueToPropertyWithType ( py::object  value,
const std::string &  targetType 
)
inline

Converts a Python object to a BaseProperty, coercing to a specific target class when given.

If targetType is empty, falls back to pythonValueToProperty() (type inference). Otherwise, coerces the Python value to the named property class.

Definition at line 93 of file PropertyAutoWrap.h.

References mitk::ColorProperty::New(), mitk::StringProperty::New(), and pythonValueToProperty().

Referenced by coerceToExistingType().

◆ resolvePropertyValue()

mitk::BaseProperty::Pointer resolvePropertyValue ( mitk::IPropertyOwner &  owner,
const std::string &  key,
py::object  value 
)
inline

Resolves a Python value to a BaseProperty, respecting any existing property's type.

Resolution order:

  1. If the value is already a BaseProperty, use it directly.
  2. If key already has a property on owner, coerce to that type.
  3. Otherwise auto-wrap by Python type.

Definition at line 157 of file PropertyAutoWrap.h.

References coerceToExistingType(), mitk::IPropertyProvider::GetConstProperty(), and pythonValueToProperty().

Referenced by bind_property_owner().