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);
94 ~Error() override;
96 const std::string& getMessage() const;
97
98 private:
100 std::string _message;
101 };
102
108 public:
109 InputObjectError(const std::string& message);
111 };
112
118 public:
119 InputParameterError(const std::string& message);
121 };
122
129 public:
130 InternalError(const std::string& message);
131 ~InternalError() override;
132 };
133
137 virtual void validateInput() = 0;
138
142 virtual void update() = 0;
143
145 virtual void clear() = 0;
146
153
154 private:
155 enum EOnInputChangeBehavior {
156 OICB_Update = 0,
157 OICB_Clear
158 };
159
160 void _addUpdateControlFields();
161 void _addStatusFields();
162 void _addStatusCodeField();
163 bool _isFieldUpdate(Field* field) const;
164 bool _isFieldOnInputChangeBehavior(Field* field) const;
165 bool _shouldUpdateOnInputChange() const;
166 bool _isFieldClear(Field* field) const;
167 bool _isInputField(const Field* field) const;
168 bool _hasNamePrefixIn(const std::string& name) const;
169 bool _hasNamePrefixInput(const std::string& name) const;
170 void _handleInputFieldNotification();
171 void _initiateUpdate();
172 void _validateInputAndUpdate();
173 void _handleErrorDuringUpdate(const AlgorithmModule::Error& error);
174 bool _shouldClearOnFailedUpdate();
175 void _setStatusCodeAndMessageFieldValues(const EStatusCode code, const std::string& message);
176 void _clearOutput();
177 void _initiateClear();
178 void _tryToSetOutputImageProperties(int outputIndex, PagedImage* outputImage);
179 void _validateOutputImageValidity(const PagedImage* const outputImage) const;
180 void _handleErrorDuringSetOutputImageProperties(PagedImage* outputImage, const AlgorithmModule::Error& error);
181 void _setImageInvalid(PagedImage* const image);
182
183 bool _hasValidatedInputAndInitiatedUpdate;
184 bool _wasOutputCleared;
185 bool _didSetOutputImagePropertiesFail;
186
188 TypedEnumField<EOnInputChangeBehavior>* onInputChangeBehaviorField;
189
191 NotifyField* updateField;
192
194 NotifyField* clearField;
195
201 NotifyField* updateDoneField;
202
204 TypedEnumField<EStatusCode>* statusCodeField;
205
207 StringField* statusMessageField;
208
210 BoolField* hasValidOutputField;
211
215 BoolField* doNotClearOnFailedUpdateField;
216
219};
220
#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
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:58
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:659
Class which represents an image, which manages properties of an image and image data which is located...
Field to encapsulate a string value.
Definition mlFields.h:610
TypedEnumField is used to encapsulate a C++ enum value and work with a real enum value instead of int...
Definition mlFields.h:384
#define ML_ABSTRACT_MODULE_CLASS_HEADER(className)
Like ML_ABSTRACT_CLASS_HEADER for the usage of derived classes from Module.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.