MLAlgorithmModule
Loading...
Searching...
No Matches
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
14ML_START_NAMESPACE
15
31 public:
37 AlgorithmModule(int numInputImages, int numOutputImages);
38 ~AlgorithmModule() override;
39
51 void handleNotification(Field* field) override;
52
59 void activateAttachments() override;
60
70 void calculateOutputImageProperties(int outputIndex, PagedImage* outputImage) override;
71
72 protected:
76 SC_OK = 0,
83 };
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;
95 AlgorithmModule::EStatusCode getStatusCode() const;
96 const std::string& getMessage() const;
97
98 private:
100 std::string _message;
101 };
102
108 public:
109 InputObjectError(const std::string& message);
110 ~InputObjectError() override;
111 };
112
118 public:
119 InputParameterError(const std::string& message);
120 ~InputParameterError() override;
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
152 virtual void setOutputImageProperties(int outputIndex, PagedImage* outputImage);
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
218 ML_ABSTRACT_MODULE_CLASS_HEADER(AlgorithmModule)
219};
220
221ML_END_NAMESPACE
#define ML_ALGORITHM_MODULE_EXPORT
Definition MLAlgorithmModuleSystem.h:12
Data structure to indicate an error within an AlgorithmModule derivative's implementation of interfac...
Definition mlAlgorithmModule.h:91
Data structure indicating an error because of an invalid input object.
Definition mlAlgorithmModule.h:107
Data structure indicating an error because of an invalid input parameter.
Definition mlAlgorithmModule.h:117
Data structure indicating an internally caused error.
Definition mlAlgorithmModule.h:128
ML-Module base class to simplify development of modules encapsulating an algorithm with dedicated inp...
Definition mlAlgorithmModule.h:30
virtual void validateInput()=0
Validates the values of module's input fields (object and parameter fields).
virtual void update()=0
Executes the algorithm and updates the values of module's output fields with results.
virtual void clear()=0
Clears the values of module's output fields (object and parameter fields).
EStatusCode
Contains possible values of field statusCode.
Definition mlAlgorithmModule.h:74
@ SC_ERROR_INPUT_PARAMETER
An invalid input parameter caused abort of update.
Definition mlAlgorithmModule.h:80
@ SC_ERROR_INTERNAL
An internal error caused abort of update.
Definition mlAlgorithmModule.h:82
@ SC_ERROR_INPUT_OBJECT
An invalid input object caused abort of update.
Definition mlAlgorithmModule.h:78