ML Reference
mlModule.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_MODULE_H
14#define ML_MODULE_H
15
18
19// ML-includes
20#include "mlInitSystemML.h"
21#include "mlRuntimeSubClass.h"
22#include "mlBase.h"
23#include "mlFields.h"
24#include "mlFieldContainer.h"
25
26#include "mlModuleInterfaces.h"
28#include "mlPagedImage.h"
29
30#include <mlMetaProfilePtr.h>
31
32
35#define ML_ADD_FIELD(NAME_P, TYPE_P, VALUE_P) \
36(static_cast<TYPE_P##Field*> (this->addField(NAME_P, #TYPE_P, VALUE_P)));
37
39
40// Namespace ML. It is recommended that all ML classes and modules reside in this
41// namespace to avoid collisions with types of other libraries.
42ML_START_NAMESPACE
43
44// ML-classes
45class SubImage;
46class PagedImage;
47class ProcessAllPagesHandler;
48
49//-------------------------------------------------------------------------
52
149//-------------------------------------------------------------------------
151{
152
153 //---------------------------------------------------------------------------
155 //---------------------------------------------------------------------------
156 friend class Host;
157 friend class PagedImage;
158 friend class PageRequest;
159 friend class TileRequest;
161 friend class State;
162 friend class ClassicHost;
163
165
166public:
167 //---------------------------------------------------------------------------
170 //---------------------------------------------------------------------------
171
179public: Module(int numInputImages, int numOutputImages);
180
186public: ~Module() override;
188
189
190
191 //---------------------------------------------------------------------------
194 //---------------------------------------------------------------------------
195
202protected: void setOutputImageInplace(MLint outputIndex=0, MLint inputIndex=0);
203
207protected: void unsetOutputImageInplace(MLint outputIndex=0);
208
213public: MLint getOutputImageInplace(MLint outputIndex=0) const;
214
215
216
222protected: void setBypass(MLint outputIndex=0, MLint inputIndex=0);
223
227public: MLint getBypass(MLint outputIndex=0) const;
228
232protected: void setClampPagesToImageExtent(bool flag = true);
233
241
244protected: void setThreadSupport(THREAD_SUPPORT supportMode);
245
249
250
254protected: void permitRecursiveHandleNotifications(bool enable);
255
259
266
268
269
270 //---------------------------------------------------------------------------
273 //---------------------------------------------------------------------------
280
296protected: void setVoxelDataTypeSupport(PERMITTED_TYPES permTypes);
297
302
307
308 //---------------------------------------------------------------------------
311 //---------------------------------------------------------------------------
312
314public: enum INPUT_STATE {
315 DISCONNECTED = 0, //<! Defines that the input is disconnected. In the case of handleInput, this means that the input image cannot be updated to a valid image.
316 CONNECTED_BUT_INVALID = 1, //<! Defines that the input is connected but has no valid data.
317 CONNECTED_AND_VALID = 2, //<! Defines that the input is connected and valid.
318 CONNECTED_BUT_NEEDS_UPDATE = 3, //<! Defines that the input is connected and needs to be updated via updateImageProperties(). After the update, it may either become CONNECTED_AND_VALID or CONNECTED_BUT_INVALID.
319};
320
322public: enum INPUT_HANDLE {
323 INVALIDATE = 0, //<! Used as return value of handleInput() to indicate that the given input is not allowed to be invalid and the output images of the module should be invalidated without calling calculateOutputImageProperties().
324 ALLOW_INVALID_INPUT = 2, //<! Used as return value of handleInput() to indicate that the given input is allowed to be invalid. calculateOutputImageProperties() will be called and getInputImage() for that input index will return NULL.
325};
326
353public: virtual INPUT_HANDLE handleInput(int /*inputIndex*/, INPUT_STATE /*state*/) const { return INVALIDATE; }
354
363
370
371
372
373 //---------------------------------------------------------------------------
376 //---------------------------------------------------------------------------
377
378public:
383
386
389
391 PagedImage* getOutputImage(MLint outputIndex=0) const;
392
396 InputConnectorField* addInputImage(const char* name = nullptr);
397
402 OutputConnectorField* addOutputImage(const char* name = nullptr);
403
404 //---------------------------------------------------------------------------
417 //---------------------------------------------------------------------------
418public: PagedImage* getInputImage(MLint inputIndex, bool getReal=false) const;
419
420 //---------------------------------------------------------------------------
427 //---------------------------------------------------------------------------
428public: PagedImage *getUpdatedInputImage(MLint inputIndex, bool getReal=false) const;
429
431
432
433
434 //---------------------------------------------------------------------------
437 // These functions are identical to those from
438 // Host::getDefaultHost() and are
439 // wrapped here for convenience.
440 // See mlHost.h for documentation.
441 //---------------------------------------------------------------------------
442public:
443
446 [[nodiscard]]
448 SubImageBox loc,
449 MLDataType datatype,
450 void** data,
451 const ScaleShiftData &scaleShiftData=ScaleShiftData(),
452 MLRequestProgressCB* progressCallback = nullptr,
453 void* progressCallbackUserData = nullptr);
454
458 [[nodiscard]]
460 SubImage &subimg,
461 const ScaleShiftData &scaleShiftData = ScaleShiftData(),
462 MLRequestProgressCB* progressCallback = nullptr,
463 void* progressCallbackUserData = nullptr);
464
468
470 static void freeTile(void* data);
471
473 static void updateProgress(const char* info1, const char* info2);
474
476 static bool shouldTerminate();
477
480
491 static void adaptPageExtent (ImageVector& pageExtent,
492 MLDataType imageType,
493 const ImageVector& newImgExtent,
494 const ImageVector& oldImgExtent,
495 const ImageVector& pageUnit = ImageVector(0),
496 const ImageVector& minPageExtent = ImageVector(0),
497 const ImageVector& maxPageExtent = ImageVector(0));
498
500
501 //---------------------------------------------------------------------------
504 //---------------------------------------------------------------------------
505
512 static std::string getVoxelValueAsString(PagedImage* image,
513 const ImageVector& position,
514 MLErrorCode* errorCode=nullptr,
515 const std::string& errorResult="");
517
518
519
520 //---------------------------------------------------------------------------
523 //---------------------------------------------------------------------------
524
554
570protected:
571 virtual void calculateOutputImageProperties([[maybe_unused]] int outputIndex, [[maybe_unused]] PagedImage* outputImage) {}
572
573protected:
580 virtual SubImageBox calculateInputSubImageBox(int /*inputIndex*/,
581 const SubImageBox& outputSubImageBox,
582 int /*outputIndex*/)
583 {
584 return outputSubImageBox;
585 };
586
601protected: virtual void calculateOutputSubImage(SubImage *outputSubImage, int outputIndex, SubImage *inputSubImages);
602
604
605 //---------------------------------------------------------------------------
608 //---------------------------------------------------------------------------
609
617protected: virtual void provideCustomPage(int /*outputIndex*/, const SubImageBox& /*pageBox*/, MLMemoryBlockHandle& /*resultPage*/) {};
618
620
621 //---------------------------------------------------------------------------
624 //---------------------------------------------------------------------------
662public:
663 [[nodiscard]]
664 MLErrorCode processAllPages(int outputIndex = -1,
665 SubImageBox region = SubImageBox(),
666 MLRequestProgressCB* progressCallback = nullptr,
667 void* progressCallbackUserData = nullptr);
668
674public:
675 [[nodiscard]]
677 SubImageBox region = SubImageBox(),
678 MLRequestProgressCB* progressCallback = nullptr,
679 void* progressCallbackUserData = nullptr);
680
685public:
686 [[nodiscard]]
687 MLErrorCode processMissingPages(int outputIndex = 0,
688 SubImageBox region = SubImageBox(),
689 MLRequestProgressCB* progressCallback = nullptr,
690 void* progressCallbackUserData = nullptr);
692
693
694
695 //---------------------------------------------------------------------------
698 //---------------------------------------------------------------------------
699
701public: void clearOutputImage(MLint i=0);
703
705public: MLMetaProfilePtr& getMetaProfile() const;
706
707
708
709public:
710 //---------------------------------------------------------------------------
713 //---------------------------------------------------------------------------
716protected: void handleNotificationOff();
717
720protected: void handleNotificationOn();
721
723protected: bool isHandleNotificationOn();
725
726
727 //---------------------------------------------------------------------------
730 //---------------------------------------------------------------------------
731
734public: bool isInputImageField(Field* field) const;
735
737public: void touchOutputImageFields() const;
738
753protected: virtual void handleNotification(Field* /*field*/) {}
754
758public: virtual void beginSaveFields() {}
759
763public: virtual void endSaveFields() {}
765
768protected: void handleNotificationInternal(Field* field, FieldSensor::Strength strength) override;
769
770
771 //---------------------------------------------------------------------------
774 //---------------------------------------------------------------------------
776public: static size_t getNumModules();
777
779public: static Module* getModule(size_t index);
780
782public: static MLint findModuleIndex(Module& module);
783
786public: static void destroyModule();
788
791
793private: void setWasVisited(bool flag) { _visitedFlag = flag; }
794
796private: bool wasVisited() { return _visitedFlag; }
797
799
800private:
801 //-----------Private methods:
805 bool _addBaseOp(Module& module);
806
810 MLint _removeBaseOp(Module& module);
811
812
813 //-----------Private members:
815 std::vector <OutputConnectorField*> _outputConnectorFields;
816
818 std::vector <InputConnectorField*> _inputConnectorFields;
819
821 THREAD_SUPPORT _threadSupport;
822
829 MLint _handleNotificationEntryCounter;
830
834 bool _permitRecursiveHandleNotifications;
835
837 bool _visitedFlag;
838
840 PERMITTED_TYPES _permittedTypes;
841
846 MLint _handleNotificationBlockCounter;
847
849 mutable MLMetaProfilePtr _metaProfilePtr;
850
852 static std::vector<Module*> _instantiatedModules;
853
860
861public:
862
865 const char* getTypeNameFast() const { return getTypeId() ? getTypeId()->getName() : "<unregistered_module>"; }
866
868};
869
871{
872public:
873 ModuleDiagnosisStackScope(Module* module) : _module(module) { if (pushModuleForDiagnosis) { pushModuleForDiagnosis(_module); } }
874 ~ModuleDiagnosisStackScope() { if (popModuleForDiagnosis) { popModuleForDiagnosis(_module); } }
875
876 typedef void (*DiagnosisModuleStackCallback)(void*);
877
879 {
880 pushModuleForDiagnosis = pushCallback;
881 popModuleForDiagnosis = popCallback;
882 }
883
884private:
885 static DiagnosisModuleStackCallback pushModuleForDiagnosis;
886 static DiagnosisModuleStackCallback popModuleForDiagnosis;
887
888 Module* _module;
889};
890
891ML_END_NAMESPACE
892
893#endif
894
895
FieldContainer()
Constructor.
Strength
Enumeration type describing the strength of notifications.
ModuleDiagnosisStackScope(Module *module)
Definition mlModule.h:873
void(* DiagnosisModuleStackCallback)(void *)
Definition mlModule.h:876
static void setCallbacksForDiagnosisModuleStack(DiagnosisModuleStackCallback pushCallback, DiagnosisModuleStackCallback popCallback)
Definition mlModule.h:878
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))
PagedImage * getOutputImage(MLint outputIndex=0) const
Returns the output image outputIndex. The index needs to be in the range [0, getNumOutputImages()-1].
static void updateProgress(const char *info1, const char *info2)
For documentation see Host::updateProgress().
const char * getTypeNameFast() const
Definition mlModule.h:865
InputConnectorField * getInputImageField(MLint i) const
Returns the field representing input image i. i must be a valid index.
friend class PageRequest
Definition mlModule.h:158
void handleNotificationOff()
bool isHandleNotificationOn()
Returns true if handleNotification calls are permitted; otherwise, it returns false.
bool isSupportedVoxelDataType(MLDataType dt) const
MLint getOutputImageInplace(MLint outputIndex=0) const
OutputConnectorField * addOutputImage(const char *name=nullptr)
virtual void calculateOutputImageProperties(int outputIndex, PagedImage *outputImage)
Definition mlModule.h:571
MLErrorCode processAllPages(ProcessAllPagesHandler &handler, SubImageBox region=SubImageBox(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
void setOutputImageInplace(MLint outputIndex=0, MLint inputIndex=0)
InputConnectorField * addInputImage(const char *name=nullptr)
void touchOutputImageFields() const
Touches all output image fields to indicate that the images have changed.
~Module() override
INPUT_HANDLE
See documentation of handleInput.
Definition mlModule.h:322
@ ALLOW_INVALID_INPUT
Definition mlModule.h:324
Module(int numInputImages, int numOutputImages)
MLErrorCode processMissingPages(int outputIndex=0, SubImageBox region=SubImageBox(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
virtual void beginSaveFields()
Definition mlModule.h:758
static std::string getVoxelValueAsString(PagedImage *image, const ImageVector &position, MLErrorCode *errorCode=nullptr, const std::string &errorResult="")
void setClampPagesToImageExtent(bool flag=true)
void permitRecursiveHandleNotifications(bool enable)
INPUT_STATE
See documentation of handleInput.
Definition mlModule.h:314
@ CONNECTED_BUT_INVALID
Definition mlModule.h:316
@ CONNECTED_BUT_NEEDS_UPDATE
Definition mlModule.h:318
@ CONNECTED_AND_VALID
Definition mlModule.h:317
INPUT_STATE getInputState(MLint index)
void setBypass(MLint outputIndex=0, MLint inputIndex=0)
void setThreadSupport(THREAD_SUPPORT supportMode)
bool isInputImageField(Field *field) const
static bool shouldTerminate()
For documentation see Host::shouldTerminate().
void handleNotificationOn()
MLint getHandleNotificationEntryCounter() const
bool areRecursiveHandleNotificationsPermitted() const
void setVoxelDataTypeSupport(PERMITTED_TYPES permTypes)
friend class ClassicHost
Definition mlModule.h:162
virtual CalculateOutputImageHandler * createCalculateOutputImageHandler(PagedImage *outputImage)
friend class State
Definition mlModule.h:161
PERMITTED_TYPES
See documentation of setVoxelDataTypeSupport.
Definition mlModule.h:275
@ ALL_REGISTERED_TYPES
Definition mlModule.h:278
@ ONLY_SCALAR_TYPES
Definition mlModule.h:276
@ ONLY_DEFAULT_TYPES
Definition mlModule.h:277
MLint getNumInputImages() const
Returns the number of input images of this module.
friend class ModuleCalculateOutputImageHandler
Definition mlModule.h:160
friend class Host
Permit other classes access to protected methods.
Definition mlModule.h:156
MLint getNumOutputImages() const
Returns the number of output images of this module.
static Module * getModule(size_t index)
Returns a pointer to instantiated module index.
@ IO_THREAD
The calculation of the image data can be called from a designated I/O thread.
Definition mlModule.h:239
@ NO_THREAD_SUPPORT
The module is not thread-safe at all.
Definition mlModule.h:237
@ MULTITHREADED
The calculation of the image data can be called from multiple threads.
Definition mlModule.h:238
static Field * getPressedNotifyField()
For documentation see Host::getPressedNotifyField().
static MLErrorCode getTile(PagedImage *image, SubImageBox loc, MLDataType datatype, void **data, const ScaleShiftData &scaleShiftData=ScaleShiftData(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
PagedImage * getUpdatedInputImage(MLint inputIndex, bool getReal=false) const
virtual void endSaveFields()
Definition mlModule.h:763
MLint getBypass(MLint outputIndex=0) const
virtual void calculateOutputSubImage(SubImage *outputSubImage, int outputIndex, SubImage *inputSubImages)
static void freeTile(void *data)
For documentation see Host::freeTile().
void unsetOutputImageInplace(MLint outputIndex=0)
friend class TileRequest
Definition mlModule.h:159
static void destroyModule()
THREAD_SUPPORT getThreadSupport() const
static MLErrorCode getTile(PagedImage *image, SubImage &subimg, const ScaleShiftData &scaleShiftData=ScaleShiftData(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
static MLint findModuleIndex(Module &module)
Returns the index of Module module. If not found, -1 is returned.
void clearOutputImage(MLint i=0)
Clears cached output image pages of output image i.
static MLErrorCode updateImageProperties(PagedImage *image)
void handleNotificationInternal(Field *field, FieldSensor::Strength strength) override
friend class PagedImage
Definition mlModule.h:157
OutputConnectorField * getOutputImageField(MLint i=0) const
Returns the field representing output image i. i must be a valid index.
virtual SubImageBox calculateInputSubImageBox(int, const SubImageBox &outputSubImageBox, int)
Definition mlModule.h:580
MLErrorCode processAllPages(int outputIndex=-1, SubImageBox region=SubImageBox(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
static size_t getNumModules()
Returns the number of instantiated modules.
virtual void provideCustomPage(int, const SubImageBox &, MLMemoryBlockHandle &)
Definition mlModule.h:617
PagedImage * getInputImage(MLint inputIndex, bool getReal=false) const
virtual void handleNotification(Field *)
Definition mlModule.h:753
PERMITTED_TYPES getVoxelDataTypeSupport() const
MLMetaProfilePtr & getMetaProfile() const
Returns the metaprofile for the base operator.
INPUT_STATE getUpdatedInputState(MLint index)
virtual INPUT_HANDLE handleInput(int, INPUT_STATE) const
Definition mlModule.h:353
@ MULTITHREADED
< The calculation of the image data can be called from multiple threads.
@ IO_THREAD
< The calculation of the image data can be called from a designated I/O thread.
@ NO_THREAD_SUPPORT
< The image can only be calculated from the main thread.
#define ML_DISALLOW_COPY_AND_ASSIGN(className)
Defines basic macros.
Definition mlMacros.h:21
#define ML_ABSTRACT_CLASS_HEADER(className)
MLint32 MLDataType
Definition mlTypeDefs.h:595
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:715
#define MLEXPORT
Code it as import symbol if compiled elsewhere.
void MLRequestProgressCB(void *usrData, double progress)
MLint64 MLint
Definition mlTypeDefs.h:489
TScaleShiftData< MLdouble > ScaleShiftData
Double version of TScaleShiftData for maximum reasonable precision.
TSubImageBox< MLint > SubImageBox
Defines the standard SubImageBox type used in the ML. Its size varies with the size of the MLint type...
TImageVector< MLint > ImageVector
Defines the standard ImageVector type that is used by the ML for indexing and coordinates.