MeVisLab Toolbox Reference
mlAlgorithmModule.h
Go to the documentation of this file.
1// Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
2// **InsertLicense** code
3//------------------------------------------------------------------------------
4
5#pragma once
6
8#include <mlModuleIncludes.h>
9#include <FMEException/Exception.h>
10#include <FMEThirdPartyWarningsDisable.h>
11#include <string>
12#include <FMEThirdPartyWarningsRestore.h>
13
15
31 public:
38 ~AlgorithmModule() override;
39
52
59 void activateAttachments() override;
60
71
72 protected:
84
91 class ML_ALGORITHM_MODULE_EXPORT Error : public fme::Exception {
92 public:
93 Error(const AlgorithmModule::EStatusCode statusCode, const std::string& message);
95 const std::string& getMessage() const;
96
97 private:
99 std::string _message;
100 };
101
107 public:
108 InputObjectError(const std::string& message);
110 };
111
117 public:
118 InputParameterError(const std::string& message);
120 };
121
128 public:
129 InternalError(const std::string& message);
130 ~InternalError() override;
131 };
132
136 virtual void validateInput() = 0;
137
141 virtual void update() = 0;
142
144 virtual void clear() = 0;
145
152
157 bool _isInputField(const Field* field) const;
158
159 private:
160 enum EOnInputChangeBehavior {
161 OICB_Update = 0,
162 OICB_Clear
163 };
164
165 void _addUpdateControlFields();
166 void _addStatusFields();
167 void _addStatusCodeField();
168 bool _isFieldUpdate(Field* field) const;
169 bool _isFieldOnInputChangeBehavior(Field* field) const;
170 bool _shouldUpdateOnInputChange() const;
171 bool _isFieldClear(Field* field) const;
172 bool _hasNamePrefixIn(const std::string& name) const;
173 bool _hasNamePrefixInput(const std::string& name) const;
174 void _handleInputFieldNotification();
175 void _initiateUpdate();
176 void _validateInputAndUpdate();
177 void _handleErrorDuringUpdate(const AlgorithmModule::Error& error);
178 bool _shouldClearOnFailedUpdate();
179 void _setStatusCodeAndMessageFieldValues(const EStatusCode code, const std::string& message);
180 void _clearOutput();
181 void _initiateClear();
182 void _tryToSetOutputImageProperties(int outputIndex, PagedImage* outputImage);
183 void _validateOutputImageValidity(const PagedImage* const outputImage) const;
184 void _handleErrorDuringSetOutputImageProperties(PagedImage* outputImage, const AlgorithmModule::Error& error);
185 void _setImageInvalid(PagedImage* const image);
186
187 bool _hasValidatedInputAndInitiatedUpdate;
188 bool _wasOutputCleared;
189 bool _didSetOutputImagePropertiesFail;
190
192 TypedEnumField<EOnInputChangeBehavior>* onInputChangeBehaviorField;
193
195 NotifyField* updateField;
196
198 NotifyField* clearField;
199
205 NotifyField* updateDoneField;
206
208 TypedEnumField<EStatusCode>* statusCodeField;
209
211 StringField* statusMessageField;
212
214 BoolField* hasValidOutputField;
215
219 BoolField* doNotClearOnFailedUpdateField;
220
223};
224
#define ML_ALGORITHM_MODULE_EXPORT
Data structure to indicate an error within an AlgorithmModule derivative's implementation of interfac...
AlgorithmModule::EStatusCode getStatusCode() const
const std::string & getMessage() const
Error(const AlgorithmModule::EStatusCode statusCode, const std::string &message)
Data structure indicating an error because of an invalid input object.
InputObjectError(const std::string &message)
Data structure indicating an error because of an invalid input parameter.
InputParameterError(const std::string &message)
Data structure indicating an internally caused error.
InternalError(const std::string &message)
ML-Module base class to simplify development of modules encapsulating an algorithm with dedicated inp...
AlgorithmModule(int numInputImages, int numOutputImages)
Forwards given parameters to base class constructor.
void activateAttachments() override
Never overwrite this method in derivative!
void handleNotification(Field *field) override
Never overwrite this method in derivative!
virtual void setOutputImageProperties(int outputIndex, PagedImage *outputImage)
Sets properties of the output image at output outputIndex.
~AlgorithmModule() override
bool _isInputField(const Field *field) const
Returns true if the field is treated as an input field that changes the module parameterization and r...
virtual void clear()=0
Clears the values of module's output fields (object and parameter fields).
virtual void update()=0
Executes the algorithm and updates the values of module's output fields with results.
EStatusCode
Contains possible values of field statusCode.
@ SC_ERROR_INTERNAL
An internal error caused abort of update.
@ SC_ERROR_INPUT_PARAMETER
An invalid input parameter caused abort of update.
@ SC_ERROR_INPUT_OBJECT
An invalid input object caused abort of update.
void calculateOutputImageProperties(int outputIndex, PagedImage *outputImage) override
Never overwrite this method in derivative!
virtual void validateInput()=0
Validates the values of module's input fields (object and parameter fields).
Field to encapsulate a boolean value.
Definition mlFields.h:56
Base class for all fields used in the ML.
Definition mlField.h:73
Base class for an image processing module of the ML.
Definition mlModule.h:151
Field without value for notifications.
Definition mlFields.h:598
The class PagedImage, representing a fragmented image that manages properties and data of an image lo...
Field to encapsulate a string value.
Definition mlFields.h:553
TypedEnumField is used to encapsulate a C++ enum value and work with a real enum value instead of int...
Definition mlFields.h:358
#define ML_ABSTRACT_MODULE_CLASS_HEADER(className)
Similar to ML_ABSTRACT_CLASS_HEADER for the usage of derived classes from Module.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.