ML Reference
|
Base class for an image processing module of the ML. More...
#include <mlModule.h>
Public Member Functions | |
MLMetaProfilePtr & | getMetaProfile () const |
Returns the meta profile for the base operator. | |
const char * | getTypeNameFast () const |
Macro to declare methods for the ML runtime type system (see mlRuntimeSubClass.h). | |
Construction/Destruction/Initialization | |
Module (int numInputImages, int numOutputImages) | |
Constructor: Initializes numInputImages input images and numOutputImages output images of the module. | |
~Module () override | |
Destructor: Destroys this module. | |
Input/Output connections and connected modules | |
InputConnectorField * | getInputImageField (MLint i) const |
Returns the field representing input image i . i must be a valid index. | |
OutputConnectorField * | getOutputImageField (MLint i=0) const |
Returns field representing output image i . i must be a valid index. | |
MLint | getNumInputImages () const |
Returns number of input images of this module. | |
MLint | getNumOutputImages () const |
Returns number of output images of this module. | |
PagedImage * | getOutputImage (MLint outputIndex=0) const |
Returns output image outputIndex . The index needs to be in the range [0, getNumOutputImages()-1]. | |
InputConnectorField * | addInputImage (const char *name=nullptr) |
Adds a new input image with name to the module. | |
OutputConnectorField * | addOutputImage (const char *name=nullptr) |
Adds a new output image with name to the module. | |
PagedImage * | getInputImage (MLint inputIndex, bool getReal=false) const |
Returns the output image of the module connected to input inputIndex . | |
PagedImage * | getUpdatedInputImage (MLint inputIndex, bool getReal=false) const |
Convenience method for safe access to the input image at index inputIndex . | |
Sequential image processing. | |
MLErrorCode | processAllPages (int outputIndex=-1, SubImageBox region=SubImageBox(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr) |
Processes all pages of a module for easy implementation of page-based image processing of complete images. | |
MLErrorCode | processAllPages (ProcessAllPagesHandler &handler, SubImageBox region=SubImageBox(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr) |
Process input images with a ProcessAllPagesHandler handler on a temporary output image (which allocates no data) For details, see processAllPages(-1) above. | |
MLErrorCode | processMissingPages (int outputIndex=0, SubImageBox region=SubImageBox(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr) |
Processes all missing pages on the given output image. | |
Memory management | |
void | clearOutputImage (MLint i=0) |
Clear cached output image pages of output image i . | |
Public Member Functions inherited from ml::FieldContainer | |
FieldContainer () | |
Constructor. | |
~FieldContainer () override | |
Destructor: Deletes all added fields. | |
std::string | whoAmI (bool withInstanceName=true) const |
Returns type and instance name of format "ClassTypeName(instanceName)" if the instance name is not empty and withInstanceName is true. | |
Field * | addField (const char *name, const char *type, const char *value) |
Adds a new field with name name , type type and value value (coded as string) to the container. | |
Field * | addField (Field *field) |
Adds a field , the ownership of the field is passed to the FieldContainer. | |
BoolField * | addBool (const char *name) |
Creates a BoolField with name and adds it to the container. Default value is false. | |
BoolField * | addBool (const char *name, bool value) |
Creates a BoolField with name and adds it to the container. | |
IntField * | addInt (const char *name) |
Creates an IntField with name and adds it to the container. Default value is 0. | |
IntField * | addInt (const char *name, MLint value) |
Creates an IntField with name and adds it to the container. | |
EnumField * | addEnum (const char *name, const char *const *enumerationItemNames, MLint numEnumerationItems) |
Creates an EnumField field with name and adds it to the container. | |
EnumField * | addEnum (const char *name, const std::vector< std::string > &enumerationItemNames) |
Creates an EnumField field with name and adds it to the container. | |
template<typename EnumType > | |
TypedEnumField< EnumType > * | addEnum (const char *name, const EnumValues< EnumType > &values, EnumType initialValue) |
Creates a TypedEnumField field with name and adds it to the container. | |
FloatField * | addFloat (const char *name) |
Creates a FloatField with name and adds it to the container. Default value is 0.f. | |
FloatField * | addFloat (const char *name, float value) |
Creates a FloatField with name and adds it to the container. | |
ProgressField * | addProgress (const char *name) |
Creates a float ProgressField with name and adds it to the container. Default value is 0.f. | |
ProgressField * | addProgress (const char *name, float value) |
Creates a float ProgressField with name and adds it to the container. | |
DoubleField * | addDouble (const char *name) |
Creates a DoubleField with name and adds it to the container. Default value is 0. | |
DoubleField * | addDouble (const char *name, double value) |
Creates a DoubleField with name and adds it to the container. | |
StringField * | addString (const char *name) |
Creates a StringField with name and adds it to the container. Default value is empty string. | |
StringField * | addString (const char *name, const std::string &value) |
Creates a StringField with name and adds it to the container. | |
NotifyField * | addNotify (const char *name) |
Creates a NotifyField field with name and adds it to the container. | |
TriggerField * | addTrigger (const char *name) |
Creates a TriggerField field with name and adds it to the container. | |
BaseField * | addBase (const char *name) |
Creates a Base field with name and adds it to the container. Default value is NULL. | |
BaseField * | addBase (const char *name, Base *value) |
Creates a Base field with name and adds it to the container. | |
BaseField * | addBase (const char *name, const RefCountedBasePtr &value) |
Creates a Base field with name and adds it to the container. Sets the value from intrusive pointer. | |
template<typename T > | |
BaseField * | addBaseWithAllowedType (const char *name, T *value=nullptr) |
As above, but also sets the allowed type of the field. | |
template<typename T > | |
BaseField * | addBaseWithAllowedType (const char *name, const ::boost::intrusive_ptr< T > &value) |
As above, but also sets the allowed type of the field. | |
template<typename T > | |
TypedBaseField< T > * | addTypedBase (const char *name) |
Creates a TypedBaseField with name and adds it to the container. Default value is NULL. | |
template<typename T > | |
TypedBaseField< T > * | addTypedBase (const char *name, T *value) |
Creates a TypedBaseField with name and adds it to the container. | |
template<typename T > | |
TypedBaseField< T > * | addTypedBase (const char *name, const ::boost::intrusive_ptr< T > &value) |
Creates a TypedBaseField with name and adds it to the container. Sets the value from intrusive pointer. | |
SoNodeField * | addSoNode (const char *name) |
Creates a SoNodeField with name and adds it to the container. Default value is NULL. | |
SoNodeField * | addSoNode (const char *name, SoNode *value) |
Creates a SoNodeField with name and adds it to the container. | |
PointerField * | addPointer (const char *name) |
Creates a PointerField with name and adds it to the container. | |
Vector2Field * | addVector2 (const char *name) |
Creates a Vector2Field with name and adds it to the container. | |
Vector2Field * | addVector2 (const char *name, const Vector2 &value) |
Creates a Vector2Field with name and adds it to the container. | |
Vector2Field * | addVector2 (const char *name, double x, double y) |
Creates a Vector2Field with name and adds it to the container. | |
Vector3Field * | addVector3 (const char *name) |
Creates a Vector3Field with name and adds it to the container. | |
Vector3Field * | addVector3 (const char *name, const Vector3 &value) |
Creates a Vector3Field with name and adds it to the container. | |
Vector3Field * | addVector3 (const char *name, double x, double y, double z) |
Creates a Vector3Field with name and adds it to the container. | |
Vector4Field * | addVector4 (const char *name) |
Creates a Vector4Field with name and adds it to the container. | |
Vector4Field * | addVector4 (const char *name, const Vector4 &value) |
Creates a Vector4Field with name and adds it to the container. | |
Vector4Field * | addVector4 (const char *name, double x, double y, double z, double w) |
Creates a Vector4Field with name and adds it to the container. | |
Vector5Field * | addVector5 (const char *name) |
Creates a Vector5Field with name and adds it to the container. | |
Vector5Field * | addVector5 (const char *name, const Vector5 &value) |
Creates a Vector5Field with name and adds it to the container. | |
Vector6Field * | addVector6 (const char *name) |
Creates a Vector6Field with name and adds it to the container. | |
Vector6Field * | addVector6 (const char *name, const Vector6 &value) |
Creates a Vector6Field with name and adds it to the container. | |
Vector10Field * | addVector10 (const char *name) |
Creates a Vector10Field with name and adds it to the container. | |
Vector10Field * | addVector10 (const char *name, const Vector10 &value) |
Creates a Vector10Field with name and adds it to the container. | |
ImageVectorField * | addImageVector (const char *name) |
Creates a ImageVectorField with name and adds it to the container. | |
ImageVectorField * | addImageVector (const char *name, const ImageVector &value) |
Creates a ImageVectorField with name and adds it to the container. | |
ImageVectorField * | addImageVector (const char *name, MLint x, MLint y, MLint z, MLint c, MLint t, MLint u) |
Creates a ImageVectorField with name and adds it to the container. | |
SubImageBoxField * | addSubImageBox (const char *name) |
Creates a SubImageBoxField with name and adds it to the container. | |
SubImageBoxField * | addSubImageBox (const char *name, const SubImageBox &value) |
Creates a SubImageBoxField with name and adds it to the container. | |
SubImageBoxdField * | addSubImageBoxd (const char *name) |
Creates a SubImageBoxd field with name and adds it to the container. | |
SubImageBoxdField * | addSubImageBoxd (const char *name, const SubImageBoxd &value) |
Creates a SubImageBoxd field with name and adds it to the container. | |
ColorField * | addColor (const char *name) |
Creates a ColorField with name and adds it to the container. | |
ColorField * | addColor (const char *name, float r, float g, float b) |
Creates a ColorField with name and adds it to the container. | |
ColorField * | addColor (const char *name, const Vector3 &value) |
Creates a ColorField with name and adds it to the container. | |
PlaneField * | addPlane (const char *name) |
Creates a PlaneField with name and adds it to the container. | |
PlaneField * | addPlane (const char *name, double f0, double f1, double f2, double f3) |
Creates a PlaneField with name and adds it to the container. | |
PlaneField * | addPlane (const char *name, const Plane &value) |
Creates a PlaneField with name and adds it to the container. | |
RotationField * | addRotation (const char *name) |
Creates a RotationField with name and adds it to the container. | |
RotationField * | addRotation (const char *name, const Rotation &value) |
Creates a RotationField with name and adds it to the container. | |
Matrix2Field * | addMatrix2 (const char *name) |
Creates a Matrix2Field with name and adds it to the container. | |
Matrix2Field * | addMatrix2 (const char *name, const Matrix2 &value) |
Creates a Matrix2Field with name and adds it to the container. | |
Matrix3Field * | addMatrix3 (const char *name) |
Creates a Matrix3Field with name and adds it to the container. | |
Matrix3Field * | addMatrix3 (const char *name, const Matrix3 &value) |
Creates a Matrix3Field with name and adds it to the container. | |
Matrix4Field * | addMatrix4 (const char *name) |
Creates a Matrix4Field with name and adds it to the container. | |
Matrix4Field * | addMatrix4 (const char *name, const Matrix4 &value) |
Creates a Matrix4Field with name and adds it to the container. | |
Matrix5Field * | addMatrix5 (const char *name) |
Creates a Matrix5Field with name and adds it to the container. | |
Matrix5Field * | addMatrix5 (const char *name, const Matrix5 &value) |
Creates a Matrix5Field with name and adds it to the container. | |
Matrix6Field * | addMatrix6 (const char *name) |
Creates a Matrix6Field with name and adds it to the container. | |
Matrix6Field * | addMatrix6 (const char *name, const Matrix6 &value) |
Creates a Matrix6Field with name and adds it to the container. | |
MatrixField * | addMatrix (const char *name) |
Creates a MatrixField with name and adds it to the container. | |
MatrixField * | addMatrix (const char *name, const Matrix4 &value) |
Creates a MatrixField with name and adds it to the container. | |
MLDataTypeField * | addMLDataType (const char *name) |
Creates a MTDataTypeField with name and adds it to the container. | |
MLDataTypeField * | addMLDataType (const char *name, MLDataType value) |
Creates a MTDataTypeField with name and adds it to the container. | |
UniversalTypeField * | addUniversalType (const char *name) |
Creates an UniversalTypeField field with name and adds it to the container. | |
IntListField * | addIntList (const char *name) |
Creates an IntListField field with name and empty list value and adds it to the container. | |
IntListField * | addIntList (const char *name, const std::vector< MLint > &value) |
Creates an IntListField field with name and given list value and adds it to the container. | |
DoubleListField * | addDoubleList (const char *name) |
Creates an DoubleListField field with name and empty list value and adds it to the container. | |
DoubleListField * | addDoubleList (const char *name, const std::vector< double > &value) |
Creates an DoubleListField field with name and given list value and adds it to the container. | |
Vector2ListField * | addVector2List (const char *name) |
Creates an Vector2ListField field with name and empty list value and adds it to the container. | |
Vector2ListField * | addVector2List (const char *name, const std::vector< Vector2 > &value) |
Creates an Vector2ListField field with name and given list value and adds it to the container. | |
Vector3ListField * | addVector3List (const char *name) |
Creates an Vector3ListField field with name and empty list value and adds it to the container. | |
Vector3ListField * | addVector3List (const char *name, const std::vector< Vector3 > &value) |
Creates an Vector3ListField field with name and given list value and adds it to the container. | |
Vector4ListField * | addVector4List (const char *name) |
Creates an Vector4ListField field with name and empty list value and adds it to the container. | |
Vector4ListField * | addVector4List (const char *name, const std::vector< Vector4 > &value) |
Creates an Vector4ListField field with name and given list value and adds it to the container. | |
size_t | getNumFields () const |
Returns the number of added fields. | |
bool | hasField (const std::string &name) const |
Returns true if the field with name name exists; otherwise false is returned. | |
Field * | getField (const std::string &name) const |
Returns the pointer to the field with name name . | |
Field * | getField (MLint index) const |
Returns pointer of field at index if it exists. If not, -1 is returned. | |
MLint | getFieldIndex (Field *field) const |
Returns index of field if it exists. If not, -1 is returned. | |
void | setFieldStringValue (const std::string &name, const std::string &value) |
Sets the value of the field with name if it exists. | |
std::string | getFieldStringValue (const std::string &name) const |
Returns the string value of the field with name if it is found. | |
virtual void | activateAttachments () |
Reactivates notification handling, i.e., all fields of this module will send notifications again to attached sensors and fields if their value is set or changed. | |
virtual void | deactivateAttachments () |
Disables notification handling, i.e., all fields of this module will not send notifications to attached sensors and fields any more if their values are set or changed. | |
Public Member Functions inherited from ml::Base | |
Base () | |
Constructor. | |
virtual | ~Base () |
Destructor. | |
virtual Base * | deepCopy () const |
Set addStateToTree version number that can be accessed via getAddStateVersion() | |
bool | isOfAllowedType (const std::vector< const RuntimeType * > &types) const |
Check if this object's type is equal to or derived from one of the types given in the argument. | |
virtual bool | isRefCountedBase () const |
Returns if the instance is derived from RefCountedBase. | |
virtual std::string | detailString () const |
Return a string describing this object. | |
virtual bool | implementsPersistence (PersistenceInterface) const |
Override this method to declare which persistence interfaces are implemented by your derived class. | |
virtual std::string | persistentState () const |
Returns a string describing the object's internal state. | |
virtual void | setPersistentState (const std::string &state) |
Restores the object's internal state from a string that had been previously generated using persistentState() . | |
virtual void | addStateToTree (TreeNode *) const |
Attaches the object state as children of the given parent node. | |
virtual void | readStateFromTree (TreeNode *) |
Reads the object state from the children of the given parent node. | |
virtual void | writeTo (AbstractPersistenceOutputStream *) const |
Write the objects state to the data stream object. | |
virtual void | readFrom (AbstractPersistenceInputStream *, int) |
Read the objects state from the data stream object. | |
Static Public Member Functions | |
Convenience functions and methods. | |
static MLErrorCode | getTile (PagedImage *image, SubImageBox loc, MLDataType datatype, void **data, const ScaleShiftData &scaleShiftData=ScaleShiftData(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr) |
For documentation see Host::getTile() function with same signature. | |
static MLErrorCode | getTile (PagedImage *image, SubImage &subimg, const ScaleShiftData &scaleShiftData=ScaleShiftData(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr) |
For documentation see Host::getTile() function with same signature and Module passed as reference. | |
static MLErrorCode | updateImageProperties (PagedImage *image) |
For documentation see Host::updateImageProperties() function with same signature. | |
static void | freeTile (void *data) |
For documentation see Host::freeTile(). | |
static void | updateProgress (const char *info1, const char *info2) |
For documentation see Host::updateProgress(). | |
static bool | shouldTerminate () |
For documentation see Host::shouldTerminate(). | |
static Field * | getPressedNotifyField () |
For documentation see Host::getPressedNotifyField(). | |
static void | adaptPageExtent (ImageVector &pageExtent, MLDataType imageType, const ImageVector &newImgExtent, const ImageVector &oldImgExtent, const ImageVector &pageUnit=ImageVector(0), const ImageVector &minPageExtent=ImageVector(0), const ImageVector &maxPageExtent=ImageVector(0)) |
Adapt page size. | |
Convenience functions not wrapped from Host. | |
static std::string | getVoxelValueAsString (PagedImage *image, const ImageVector &position, MLErrorCode *errorCode=nullptr, const std::string &errorResult="") |
Returns the voxel value at position position of the image image . | |
Data base of currently instantiated modules. | |
static size_t | getNumModules () |
Returns number of instantiated modules. | |
static Module * | getModule (size_t index) |
Returns pointer to instantiated module index . | |
static MLint | findModuleIndex (Module &module) |
Returns index of Module module . If not found -1 is returned. | |
static void | destroyModule () |
Destroys static allocated tables to avoid memory leaks. | |
Protected Member Functions | |
void | handleNotificationInternal (Field *field, FieldSensor::Strength strength) override |
Called from FieldContainer whenever a field changes. | |
Custom page allocation. | |
virtual void | provideCustomPage (int, const SubImageBox &, MLMemoryBlockHandle &) |
This method allows a Module to provide its own pages to the Host for the outputIndex output image. | |
Control of handleNotification calls. | |
void | handleNotificationOff () |
Decreases lock counter for handleNotification calls. | |
void | handleNotificationOn () |
Increases lock counter for handleNotification calls. | |
bool | isHandleNotificationOn () |
Returns true if handleNotification calls are permitted, otherwise false. | |
Friends | |
class | Host |
Permit other classes access to protected methods. | |
class | PagedImage |
class | PageRequest |
class | TileRequest |
class | ModuleCalculateOutputImageHandler |
class | State |
class | ClassicHost |
Image processing and general properties of the module. | |
enum | THREAD_SUPPORT { NO_THREAD_SUPPORT = PagedImage::NO_THREAD_SUPPORT , MULTITHREADED = PagedImage::MULTITHREADED , IO_THREAD = PagedImage::IO_THREAD } |
Enumerator deciding whether and which type of multithreading is supported by this module. More... | |
MLint | getOutputImageInplace (MLint outputIndex=0) const |
Return optimization flag: Return index of input image whose input tile is used also as output page for output outputIndex in calculateOutputSubImage() (instead of allocating its own memory). | |
MLint | getBypass (MLint outputIndex=0) const |
Returns the currently bypass index or -1 if bypassing is disabled (default). | |
THREAD_SUPPORT | getThreadSupport () const |
Returns the multithreading mode supported by this module, default is NO_THREAD_SUPPORT. | |
bool | areRecursiveHandleNotificationsPermitted () const |
Returns if recursive entries in handleNotification are permitted. | |
MLint | getHandleNotificationEntryCounter () const |
A counter returning the current number of (recursive re)entries in handleNotification. | |
void | setOutputImageInplace (MLint outputIndex=0, MLint inputIndex=0) |
Set optimization flag: If calculating a page in calculateOutputSubImage(), the output image page of output outputIndex shall use the same memory as the input page of input inputIndex . | |
void | unsetOutputImageInplace (MLint outputIndex=0) |
Clear optimization flag: output page of output at outputIndex and input tile shall use different memory buffers in calculateOutputSubImage(). | |
void | setBypass (MLint outputIndex=0, MLint inputIndex=0) |
Sets the input image whose pages can also be used instead of output pages for the output image at outputIndex to avoid recalculations. | |
void | setClampPagesToImageExtent (bool flag=true) |
Enables/disables page clamping on all output images. | |
void | setThreadSupport (THREAD_SUPPORT supportMode) |
Pass any THREAD_SUPPORT supportMode to decide whether and what type of multithreading is supported by this module. | |
void | permitRecursiveHandleNotifications (bool enable) |
If this flag is set to enable =true, recursive entries in handleNotification are permitted. | |
Data type support of this module. | |
enum | PERMITTED_TYPES { ONLY_SCALAR_TYPES , ONLY_DEFAULT_TYPES , ALL_REGISTERED_TYPES } |
See documentation of setVoxelDataTypeSupport. More... | |
PERMITTED_TYPES | getVoxelDataTypeSupport () const |
Returns the current state of supported voxel data types. | |
bool | isSupportedVoxelDataType (MLDataType dt) const |
Check if a given data type is supported on the module as configured with setVoxelDataTypeSupport. | |
void | setVoxelDataTypeSupport (PERMITTED_TYPES permTypes) |
Specifies which types this module supports. | |
Input handling | |
enum | INPUT_STATE { DISCONNECTED = 0 , CONNECTED_BUT_INVALID = 1 , CONNECTED_AND_VALID = 2 , CONNECTED_BUT_NEEDS_UPDATE = 3 } |
See documentation of handleInput. More... | |
enum | INPUT_HANDLE { INVALIDATE = 0 , ALLOW_INVALID_INPUT = 2 } |
See documentation of handleInput. More... | |
virtual INPUT_HANDLE | handleInput (int, INPUT_STATE) const |
This method may be reimplemented to enable support for invalid input images on the module. | |
INPUT_STATE | getInputState (MLint index) |
Returns the current state of the input connection. | |
INPUT_STATE | getUpdatedInputState (MLint index) |
Returns the updated state of the input image by calling updateImageProperties(index) and returning getInputState(index) afterwards. | |
Management of fields | |
bool | isInputImageField (Field *field) const |
Returns if the given field is an input image field. This can be used in handleNotification(), to check if one of the input images has changed. | |
void | touchOutputImageFields () const |
Touch all output image fields to indicate that the images have changed. | |
virtual void | beginSaveFields () |
Called before all fields data contents of this modules are saved. | |
virtual void | endSaveFields () |
Called after saving all field contents of this module. | |
virtual void | handleNotification (Field *) |
Called when any field data in the field container of this module is modified. | |
Virtual methods to implement the image processing algorithm. | |
virtual CalculateOutputImageHandler * | createCalculateOutputImageHandler (PagedImage *outputImage) |
Creates the CalculateOutputImageHandler for the given output image outputImage . | |
virtual void | calculateOutputImageProperties (int outputIndex, PagedImage *outputImage) |
Set properties of output image outputImage with output index outputIndex . | |
virtual SubImageBox | calculateInputSubImageBox (int, const SubImageBox &outputSubImageBox, int) |
Called by the Host to determine which input image region (tile) of input inputIndex is required to calculate a certain output image region (page) of output outputIndex . | |
virtual void | calculateOutputSubImage (SubImage *outputSubImage, int outputIndex, SubImage *inputSubImages) |
Calculate page outputSubImage of output image with index outputIndex given the input image tiles in array inputSubImages . | |
Additional Inherited Members | |
Public Types inherited from ml::Base | |
enum | PersistenceInterface { PersistenceByString , PersistenceByTreeNode , PersistenceByStream } |
This enum describes the different persistence interfaces available. More... | |
Base class for an image processing module of the ML.
Thread-safety: This class is not thread-safe and should only be used from the main thread.
This class is the base class for all image processing modules of the ML. Such modules have the following properties:
Connected modules derived from Module define an image processing graph.
IMPORTANT NOTE: An ML module derived from Module is mostly a reacting class, not an acting one. The module is almost every time activated by a call from the ML core (the so called Host) which controls image and image property calculation in the module graph. The Host controls image/page (de)allocation, image/page calculation etc.
IMPORTANT NOTE: An ML modules usually works with input and output images. These images are calculated by calculating the so called pages by the ML. An image is usually composed of many pages of identical size. To calculate a page, an image processing module derived from Module requests one or more arbitrary regions of an input image, the so called tiles. Pages and tiles are derived from the so called SubImage.
Each creation/deletion of this class sends automatically a notification to the global MLNotify instance. See mlNotify.h for more information.
If you want to derive your own image processing module from a Module then you should consider to overload the following methods:
Constructor - Creates the module, sets some image processing properties (multithreading, inplace calculation, etc.) and creates module fields. Superclass constructor specifies number of inputs/outputs.
Destructor - Destroys the module.
activateAttachments - Enables notification handling for the Module class again; it should be used to reset field values after module (re)load or clone, because handleNotification is not called during module state reload or clone.
handleNotification - Called on field changes so that the image processing algorithms can adapt itself to the new settings.
calculateOutputImageProperties - Called by the host to determine the properties of an (output) image.
calculateInputSubImageBox - Called by the host to determine which input image region (tile) is required to calculate a certain output image region (page).
calculateOutputSubImage - Implements the actual image processing algorithm. It reads one (or more) input image region (tile) and calculates the output image region (page) out of it. Two versions are available - a normal one and an extended one which passes additional data with thread information for multithreading support.
For a more detailed description of these methods have a look at their header documentation.
Definition at line 150 of file mlModule.h.
See documentation of handleInput.
Enumerator | |
---|---|
INVALIDATE | |
ALLOW_INVALID_INPUT |
Definition at line 323 of file mlModule.h.
See documentation of handleInput.
Enumerator | |
---|---|
DISCONNECTED | |
CONNECTED_BUT_INVALID | |
CONNECTED_AND_VALID | |
CONNECTED_BUT_NEEDS_UPDATE |
Definition at line 315 of file mlModule.h.
See documentation of setVoxelDataTypeSupport.
Enumerator | |
---|---|
ONLY_SCALAR_TYPES | |
ONLY_DEFAULT_TYPES | |
ALL_REGISTERED_TYPES |
Definition at line 276 of file mlModule.h.
|
protected |
Enumerator deciding whether and which type of multithreading is supported by this module.
Definition at line 237 of file mlModule.h.
ml::Module::Module | ( | int | numInputImages, |
int | numOutputImages ) |
Constructor: Initializes numInputImages
input images and numOutputImages
output images of the module.
(Usually this is called by the implementation of the derived constructor). Moreover, a FieldContainer is initialized, which will contain all image processing parameters (see Field). The touching of these fields will call handleSensorNotification() and handleNotification() when changed. Notifies MLNotify. See mlMLNotify.h for more infos.
|
override |
Destructor: Destroys this module.
Should be called only by the application managing the module graph. It automatically cleans up indirectly created stuff like Field objects, field connections, PagedImgs and data managed by PagedImgs. Notifies MLNotify. See mlMLNotify.h for more infos.
|
static |
Adapt page size.
Call this method when the operator modifies the image size to avoid large memory overhead. Arguments are:
InputConnectorField * ml::Module::addInputImage | ( | const char * | name = nullptr | ) |
Adds a new input image with name
to the module.
The new InputConnectorField gets appended to the fields list and to the input images list. It gets getNumInputImages() as its index. If no name
is given, the image is named "input" + its index. The returned field is owned by the Module.
OutputConnectorField * ml::Module::addOutputImage | ( | const char * | name = nullptr | ) |
Adds a new output image with name
to the module.
The new OutputConnectorField gets appended to the fields list and to the input images list. A new PagedImage is created and owned by the OutputConnectorField. It gets getNumOutputImages() as its index. If no name
is given, the image is named "output" + its index. The returned field is owned by the Module.
bool ml::Module::areRecursiveHandleNotificationsPermitted | ( | ) | const |
Returns if recursive entries in handleNotification are permitted.
By default this setting is false.
|
inlinevirtual |
Called before all fields data contents of this modules are saved.
Useful for initializing time consuming field states only for saving module state.
Definition at line 762 of file mlModule.h.
|
inlineprotectedvirtual |
Called by the Host to determine which input image region (tile) of input inputIndex
is required to calculate a certain output image region (page) of output outputIndex
.
Default is that a region with position and location of outputSubImageBox
is requested from input image inputIndex
.
Definition at line 585 of file mlModule.h.
|
inlineprotectedvirtual |
Set properties of output image outputImage
with output index outputIndex
.
With getInputImage(inputIndex) the input images can be accessed to calculate output image properties. By default, the properties of input image are copied to output image and all input sub images are requested with the datatype of the outputImage
. If you want to request input sub images of a different type as your output image, you can use the PagedImage::setInSubImageDataType() to specify those types. See PagedImage for details on the properties you can set for input sub images. In case of a processAllPages(-1) call, the outputIndex
will be -1 and outImage will be a temporary output image whose properties can be set. To invalidate the output image, do:
Definition at line 572 of file mlModule.h.
|
protectedvirtual |
Calculate page outputSubImage
of output image with index outputIndex
given the input image tiles in array inputSubImages
.
inputSubImages
contains as many images as inputs of the module exists (see getNumInputImages()). If not overloaded, the content of the inputSubImage i is copied to outputSubImage i if possible. If more outputs than input images exist, the last input image is copied to the additional output images. If output images are bigger than the input images, non overlapping regions remain filled with undefined values. If no input exists, the outputs are remain filled with undefined values. If handleInput() is reimplemented and returns ALLOW_INVALID_INPUT for an invalid input image (either not connected or connected and invalid), the input sub image at that index will be empty and contain no data.
void ml::Module::clearOutputImage | ( | MLint | i = 0 | ) |
Clear cached output image pages of output image i
.
|
protectedvirtual |
Creates the CalculateOutputImageHandler for the given output image outputImage
.
The default implementation returns a CalculateOutputImageHandler that maps the interface back to the Module, callings its calculateOutputSubImage() and calculateInputSubImageBox(). Although this default implementation might feel simpler than implementing your own handler, please note that it is worth the effort and that it makes several issues much simpler:
A derived module may reimplement this virtual function to provide a CalculateOutputImageHandler which is used for the calculation of the pages of the given outputImage
. Since this is called for each output image individually, it is possible to create different handlers for different output images. This method is be called by the ML Host after calculateOutputImageProperties() was called for one of the output images and the output image is valid after that call. Because of this, it is also possible to return a different handler for the same output image, depending on the module state, e.g. one handler that implements one kind of filter and another one which implements another filter, instead of using a switch statement in a single handler. If you are about thread-safety, please make sure that you copy all needed state in the constructor of your handler and do NOT store any back-references to the module, the output image, field pointers etc.
|
static |
Destroys static allocated tables to avoid memory leaks.
Only to be called on ML destruction.
|
inlinevirtual |
Called after saving all field contents of this module.
Useful to clean up field states only generated for saving module state. See beginSaveFields().
Definition at line 767 of file mlModule.h.
Returns index of Module module
. If not found -1 is returned.
|
static |
For documentation see Host::freeTile().
Returns the currently bypass index or -1 if bypassing is disabled (default).
Bypassing requires that image (data) content, image extent, page extent and voxel data type remain unchanged or errors will occur.
MLint ml::Module::getHandleNotificationEntryCounter | ( | ) | const |
A counter returning the current number of (recursive re)entries in handleNotification.
It typically has the value 1 in handleNotification() and 0 outside. It can only return higher values if permitRecursiveHandleNotification() permits recursions in handleNotification().
PagedImage * ml::Module::getInputImage | ( | MLint | inputIndex, |
bool | getReal = false ) const |
Returns the output image of the module connected to input inputIndex
.
The index inputIndex
needs to be in the range [0, getNumInputImages()-1]. If getReal==true
is passed, handleInput() will not be called and a connected input image will be returned regardless of its state (see getInputState()) for possible input image states) or NULL if there is no connection.
If getReal==false
is passed, the return value depends on the reimplementation of handleInput(). It will return either the real input image (not regarding its state) or NULL.
NOTE: getInputImage() should typically NOT be used outside of the calculate*() methods of Module, please use getUpdatedInputImage() instead to make sure that the input image is correctly updated if its properties have changed.
InputConnectorField * ml::Module::getInputImageField | ( | MLint | i | ) | const |
Returns the field representing input image i
. i
must be a valid index.
INPUT_STATE ml::Module::getInputState | ( | MLint | index | ) |
Returns the current state of the input connection.
NOTE: This does not update the input image, so it will return Module::CONNECTED_BUT_NEEDS_UPDATE if the input image state is unknown and could be updated via updateImageProperties(). When this method is called from within calculateOutputImageProperties(), you can be sure that Module::CONNECTED_BUT_NEEDS_UPDATE is never returned, because the ML host calls updateImageProperties() on each input image prior to calling calculateOutputImageProperties().
MLMetaProfilePtr & ml::Module::getMetaProfile | ( | ) | const |
Returns the meta profile for the base operator.
|
static |
Returns pointer to instantiated module index
.
MLint ml::Module::getNumInputImages | ( | ) | const |
Returns number of input images of this module.
|
static |
Returns number of instantiated modules.
MLint ml::Module::getNumOutputImages | ( | ) | const |
Returns number of output images of this module.
PagedImage * ml::Module::getOutputImage | ( | MLint | outputIndex = 0 | ) | const |
Returns output image outputIndex
. The index needs to be in the range [0, getNumOutputImages()-1].
OutputConnectorField * ml::Module::getOutputImageField | ( | MLint | i = 0 | ) | const |
Returns field representing output image i
. i
must be a valid index.
Return optimization flag: Return index of input image whose input tile is used also as output page for output outputIndex
in calculateOutputSubImage() (instead of allocating its own memory).
If inplace calculation is off, -1 is returned.
|
static |
For documentation see Host::getPressedNotifyField().
THREAD_SUPPORT ml::Module::getThreadSupport | ( | ) | const |
Returns the multithreading mode supported by this module, default is NO_THREAD_SUPPORT.
See THREAD_SUPPORT for possible return values.
|
static |
For documentation see Host::getTile() function with same signature and Module passed as reference.
On NULL op parameter ML_BAD_OPERATOR_POINTER is returned.
|
static |
For documentation see Host::getTile() function with same signature.
On NULL op parameter ML_BAD_OPERATOR_POINTER is returned.
|
inline |
Macro to declare methods for the ML runtime type system (see mlRuntimeSubClass.h).
It registers the Module class and its string name. In the implementation (.cpp) file there must be a similar macro, too, which registers the parent class name and string. This macro also implements the init function of this module which needs to be called before first module usage in e.g., the dll initialization. Get registered type name of this module, returns "<unregistered_module>" if not registered. Unlike getTypeIdName() this will not print an error message if the type is not registered.
Definition at line 869 of file mlModule.h.
PagedImage * ml::Module::getUpdatedInputImage | ( | MLint | inputIndex, |
bool | getReal = false ) const |
Convenience method for safe access to the input image at index inputIndex
.
It is forbidden to call this in calculateOutputSubImage, calculateInputSubImageBox or calculateOutputImageProperties, please use getInputImage(i) instead. This method will call updateImageProperties() if needed and will return a pointer to the image if it is valid (isValid()==true).
INPUT_STATE ml::Module::getUpdatedInputState | ( | MLint | index | ) |
Returns the updated state of the input image by calling updateImageProperties(index) and returning getInputState(index) afterwards.
It will never return Module::CONNECTED_BUT_NEEDS_UPDATE.
PERMITTED_TYPES ml::Module::getVoxelDataTypeSupport | ( | ) | const |
Returns the current state of supported voxel data types.
See also Module::PERMITTED_TYPES and setVoxelDataTypeSupport. Default is Module::ONLY_SCALAR_TYPES.
|
static |
Returns the voxel value at position position
of the image image
.
On any error errorResult
is returned instead of the pixel value as string. errCode
can be passed as NULL (the default). Otherwise errors are reported in *errorCode
or ML_RESULT_OK is set. If the voxel position is out of image range "" is returned and *result
is set to ML_RESULT_OK.
|
inlinevirtual |
This method may be reimplemented to enable support for invalid input images on the module.
If all inputs are connected and valid, this method is not called at all.
The handleInput method is called for each disconnected or invalid input image that is encountered. It allows to consider two cases separately:
The two cases are indicated by the passed state
. If you do not care about the difference between a disconnected and an invalid connected image, just return the same handling and ignore the state flag. The default implementation returns Module::INVALIDATE to indicate that all input images need to be connected and valid.
The reimplemented version may return one of the following flags for each of the two cases:
It is strongly advised to not use REDIRECT_TO_DUMMY_OP in new code, please use Module::ALLOW_INVALID_INPUT instead.
If Module::ALLOW_INVALID_INPUT is returned, getInputImage() will return NULL for the invalid input image, so you need to handle this in your code, e.g., when calling getInputImage() in calculateOutputImageProperties() you need to handle a possible NULL return value. The same applies to calculateOutputSubImage(), where the input sub images for invalid inputs will be empty (isEmpty()==true) and and will contain no data (getData()==NULL).
IMPORTANT: For one input configuration handleInput must return a unique value. Input handling cannot change during life time of the Module instance. If it changes image processing may become instable.
Definition at line 354 of file mlModule.h.
|
inlineprotectedvirtual |
Called when any field data in the field container of this module is modified.
The pointer to the changed field is passed in field
. Notes:
Definition at line 757 of file mlModule.h.
|
overrideprotectedvirtual |
Called from FieldContainer whenever a field changes.
This method will call the virtual handleNotification() method if handleNotification is enabled.
Reimplemented from ml::FieldContainer.
|
protected |
Decreases lock counter for handleNotification calls.
Calls can be nested. If < 0 then handleNotification calls are prohibited.
|
protected |
Increases lock counter for handleNotification calls.
Calls can be nested. If >= 0 then handleNotification calls are permitted.
|
protected |
Returns true if handleNotification calls are permitted, otherwise false.
bool ml::Module::isInputImageField | ( | Field * | field | ) | const |
Returns if the given field is an input image field. This can be used in handleNotification(), to check if one of the input images has changed.
bool ml::Module::isSupportedVoxelDataType | ( | MLDataType | dt | ) | const |
Check if a given data type is supported on the module as configured with setVoxelDataTypeSupport.
|
protected |
If this flag is set to enable
=true, recursive entries in handleNotification are permitted.
By default this setting is false and should only be enabled with care.
MLErrorCode ml::Module::processAllPages | ( | int | outputIndex = -1, |
SubImageBox | region = SubImageBox(), | ||
MLRequestProgressCB * | progressCallback = nullptr, | ||
void * | progressCallbackUserData = nullptr ) |
Processes all pages of a module for easy implementation of page-based image processing of complete images.
Internally all pages of the output image with index outputIndex
are requested from the this module.
The normal page-based image processing takes place with the following changes:
region
.outputIndex
is -1, a temporary output image with index -1 is created. The properties for the temporary output image are copied from the input image 0. If outputIndex
is positive, it must specify a legal module output index.outputIndex
is -1, in calculateOutputSubImage the output subimages must NOT be written since not data is collected for them to improve performance for pure input scan algorithms.outputIndex
is -1, the calculateOutputImageProperties method is called with outputIndex
set to -1 and outImg
set to the temporary image. This allows to specify different properties for the temporary output image than the properties of image 0. Note: Module::getOutputImage(-1) will not work, but you can use calculateOutputImageProperties(MLint outputIndex, PagedImage* outputImage) to change the temporary output images properties, e.g., the page extent.outputIndex
is passed to calculateOutputSubImage (even if it is negative). By negative value you can see that the output must not be written.region
can be passed by the caller to specify a region which covers all pages to be processed instead of all pages of the image. By default it is empty which means that all pages of the images are to be processed. The return value will ML_RESULT_OK on successful operation, otherwise a code describing the error. For details on progressCallback
, see Host::getTile(). MLErrorCode ml::Module::processAllPages | ( | ProcessAllPagesHandler & | handler, |
SubImageBox | region = SubImageBox(), | ||
MLRequestProgressCB * | progressCallback = nullptr, | ||
void * | progressCallbackUserData = nullptr ) |
Process input images with a ProcessAllPagesHandler handler
on a temporary output image (which allocates no data) For details, see processAllPages(-1) above.
progressCallback
, see Host::getTile(). MLErrorCode ml::Module::processMissingPages | ( | int | outputIndex = 0, |
SubImageBox | region = SubImageBox(), | ||
MLRequestProgressCB * | progressCallback = nullptr, | ||
void * | progressCallbackUserData = nullptr ) |
Processes all missing pages on the given output image.
If the pages are already available, they are not recomputed. Apart from this, it behaves like processAllPages(outputIndex), except that the outputIndex may not be -1. For details on progressCallback
, see Host::getTile().
|
inlineprotectedvirtual |
This method allows a Module to provide its own pages to the Host for the outputIndex
output image.
The pageBox
specifies the location of the requested page. To return an own page, the page needs to be allocated with the MLMemoryManager and needs to be assigned to the resultPage
parameter.
Definition at line 622 of file mlModule.h.
Sets the input image whose pages can also be used instead of output pages for the output image at outputIndex
to avoid recalculations.
Setting an inputIndex
of -1 disables bypassing (which is the default). Bypassing requires that image (data) content, image extent, page extent and voxel data type remain unchanged or errors will occur.
|
protected |
Enables/disables page clamping on all output images.
(default when not called is false, for backward compatibility) For details, see PagedImage::setClampPagesToImageExtent().
Set optimization flag: If calculating a page in calculateOutputSubImage(), the output image page of output outputIndex
shall use the same memory as the input page of input inputIndex
.
This way less allocations occur because the read and written buffer are identical. Usually only useful for pixel operations or algorithms which do not modify the image data. Setting inIndex = -1 disables inplace optimization for the given outputIndex.
|
protected |
Pass any THREAD_SUPPORT supportMode
to decide whether and what type of multithreading is supported by this module.
See THREAD_SUPPORT for possible modes.
|
protected |
Specifies which types this module supports.
If Module::ALL_REGISTERED_TYPES is set then the module might work on all registered data types.
If Module::ONLY_DEFAULT_TYPES is set then the module only supports operations on the default scalar and extended types. See the macro ML_INSTANTIATE_DEFAULT_EXTENDED_TYPES for the list of the default extended types.
Default is Module::ONLY_SCALAR_TYPES, i.e., the module can work only with the standard built-in data types. (MLuint8, MLint8,..., MLint64, MLfloat, MLdouble).
The set of allowed types can still be further restricted in calculateOutputSubImageProperties by setting the output image to invalid for not supported combinations of types and modes/parameters.
|
static |
For documentation see Host::shouldTerminate().
void ml::Module::touchOutputImageFields | ( | ) | const |
Touch all output image fields to indicate that the images have changed.
|
protected |
Clear optimization flag: output page of output at outputIndex
and input tile shall use different memory buffers in calculateOutputSubImage().
This is an equivalent to setOutImgInplace(outIndex, -1).
|
static |
For documentation see Host::updateImageProperties() function with same signature.
On NULL PagedImage parameter ML_BAD_OPERATOR_POINTER is returned.
|
static |
For documentation see Host::updateProgress().
|
friend |
Definition at line 162 of file mlModule.h.
|
friend |
Permit other classes access to protected methods.
Definition at line 156 of file mlModule.h.
|
friend |
Definition at line 160 of file mlModule.h.
|
friend |
Definition at line 157 of file mlModule.h.
|
friend |
Definition at line 158 of file mlModule.h.
|
friend |
Definition at line 161 of file mlModule.h.
|
friend |
Definition at line 159 of file mlModule.h.