ML Reference
|
00001 // **InsertLicense** code 00002 //------------------------------------------------------------------------- 00010 //------------------------------------------------------------------------- 00011 #ifndef __mlModule_H 00012 #define __mlModule_H 00013 00014 // ML-includes 00015 #ifndef __mlInitSystemML_H 00016 #include "mlInitSystemML.h" 00017 #endif 00018 #ifndef __mlRuntimeSubClass_H 00019 #include "mlRuntimeSubClass.h" 00020 #endif 00021 #ifndef __mlBasics_H 00022 #include "mlBasics.h" 00023 #endif 00024 #ifndef __mlBase_H 00025 #include "mlBase.h" 00026 #endif 00027 #ifndef __mlInputSubImageProperties_H 00028 #include "mlInputSubImageProperties.h" 00029 #endif 00030 #ifndef __mlFields_H 00031 #include "mlFields.h" 00032 #endif 00033 #ifndef __mlFieldContainer_H 00034 #include "mlFieldContainer.h" 00035 #endif 00036 00037 #include "mlModuleInterfaces.h" 00038 #include "mlProcessAllPagesHandler.h" 00039 #include "mlPagedImage.h" 00040 00041 #include <mlMetaProfilePtr.h> 00042 00043 00046 #define ML_ADD_FIELD(NAME_P, TYPE_P, VALUE_P) \ 00047 ((TYPE_P##Field*) this->getFieldContainer()->addField(NAME_P, #TYPE_P, VALUE_P)); 00048 00049 00050 class MLMemoryBlockHandle; 00051 00052 // Namespace ML. It is recommended that all ML classes and modules are in this 00053 // name space to avoid collisions with types of other libraries. 00054 ML_START_NAMESPACE 00055 00056 // ML-classes 00057 class SubImage; 00058 class PagedImage; 00059 class ProcessAllPagesHandler; 00060 #ifdef ML_DEPRECATED 00061 class BaseOp; 00062 class DummyOp; 00063 #endif 00064 00065 //------------------------------------------------------------------------- 00068 00165 //------------------------------------------------------------------------- 00166 class MLEXPORT Module : public FieldContainer 00167 { 00168 00169 //--------------------------------------------------------------------------- 00171 //--------------------------------------------------------------------------- 00172 friend class Host; 00173 friend class PagedImage; 00174 friend class PageRequest; 00175 friend class TileRequest; 00176 friend class ModuleCalculateOutputImageHandler; 00177 friend class State; 00178 friend class ClassicHost; 00179 00180 ML_DISALLOW_COPY_AND_ASSIGN(Module) 00181 00182 //--------------------------------------------------------------------------- 00184 00185 //--------------------------------------------------------------------------- 00186 00187 00188 00189 00190 00191 00192 00193 00194 00195 public: Module(int numInputImages, int numOutputImages); 00196 00202 public: virtual ~Module(); 00204 00205 00206 00207 //--------------------------------------------------------------------------- 00209 00210 //--------------------------------------------------------------------------- 00211 00218 protected: void setOutputImageInplace(MLint outputIndex=0, MLint inputIndex=0); 00219 00223 protected: void unsetOutputImageInplace(MLint outputIndex=0); 00224 00229 public: MLint getOutputImageInplace(MLint outputIndex=0) const; 00230 00231 00232 00238 protected: void setBypass(MLint outputIndex=0, MLint inputIndex=0); 00239 00243 public: MLint getBypass(MLint outputIndex=0) const; 00244 00247 enum THREAD_SUPPORT { 00248 NO_THREAD_SUPPORT = PagedImage::NO_THREAD_SUPPORT, 00249 MULTITHREADED = PagedImage::MULTITHREADED, 00250 IO_THREAD = PagedImage::IO_THREAD, 00251 00252 ML_CALCULATEOUTPUTSUBIMAGE_ON_STD_TYPES = PagedImage::MULTITHREADED, 00253 ML_CALCULATEOUTPUTSUBIMAGE_ON_ALL_TYPES = PagedImage::MULTITHREADED, 00254 #ifdef ML_DEPRECATED 00255 CALC_OUTSUBIMAGE_ON_STD_TYPES = PagedImage::MULTITHREADED, 00256 CALC_OUTSUBIMAGE_ON_ALL_TYPES = PagedImage::MULTITHREADED 00257 #endif // ML_DEPRECATED 00258 }; 00259 00262 protected: void setThreadSupport(THREAD_SUPPORT supportMode); 00263 00266 public: THREAD_SUPPORT getThreadSupport() const; 00267 00268 00272 protected: void permitRecursiveHandleNotifications(bool enable); 00273 00276 public: bool areRecursiveHandleNotificationsPermitted() const; 00277 00283 public: MLint getHandleNotificationEntryCounter() const; 00284 00286 00287 00288 //--------------------------------------------------------------------------- 00290 00291 //--------------------------------------------------------------------------- 00293 public: enum PERMITTED_TYPES { 00294 ONLY_SCALAR_TYPES, 00295 ONLY_DEFAULT_TYPES, 00296 ALL_REGISTERED_TYPES, 00297 ONLY_STANDARD_TYPES = ONLY_SCALAR_TYPES, 00298 FULLY_OPERATIONAL = ONLY_DEFAULT_TYPES, 00299 MINIMUM_OPERATIONAL = ALL_REGISTERED_TYPES 00300 }; 00301 00317 protected: void setVoxelDataTypeSupport(PERMITTED_TYPES permTypes); 00318 00322 public: PERMITTED_TYPES getVoxelDataTypeSupport() const; 00323 00326 public: bool isSupportedVoxelDataType(MLDataType dt) const; 00328 00329 00330 //--------------------------------------------------------------------------- 00332 00333 //--------------------------------------------------------------------------- 00334 00339 public: std::string whoAmI(bool withInstanceName=true) const; 00341 00342 00343 00344 00345 //--------------------------------------------------------------------------- 00347 00348 //--------------------------------------------------------------------------- 00349 00351 public: enum INPUT_STATE { 00352 DISCONNECTED = 0, //<! defines that the input is disconnected. In the case of handleInput, this means that the input image can not be updated to a valid image. 00353 CONNECTED_BUT_INVALID = 1, //<! defines that the input is connected but has no valid data. 00354 CONNECTED_AND_VALID = 2, //<! defines that the input is connected and valid. 00355 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. 00356 #ifdef ML_DEPRECATED 00357 OPEN = DISCONNECTED, //<! \deprecated, use DISCONNECTED 00358 UNDEFINED_CLOSED = CONNECTED_BUT_INVALID //<! \deprecated, use CONNECTED_BUT_INVALID 00359 #endif 00360 }; 00361 00363 public: enum INPUT_HANDLE { 00364 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(). 00365 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. 00366 #ifdef ML_DEPRECATED 00367 REDIRECT_TO_DUMMY_OP = 1, //<! Deprecated flag to indicate that an invalid input should be redirected to the DummyOp module. 00368 #endif 00369 }; 00370 00398 public: virtual INPUT_HANDLE handleInput(int /*inputIndex*/, INPUT_STATE /*state*/) const { return INVALIDATE; } 00399 00407 public: INPUT_STATE getInputState(MLint index); 00408 00413 public: INPUT_STATE getUpdatedInputState(MLint index); 00415 00416 00417 00418 //--------------------------------------------------------------------------- 00420 00421 //--------------------------------------------------------------------------- 00422 00423 public: 00425 InputConnectorField* getInputImageField(MLint i) const; 00427 OutputConnectorField* getOutputImageField(MLint i=0) const; 00428 00430 MLint getNumInputImages() const; 00431 00433 MLint getNumOutputImages() const; 00434 00436 PagedImage* getOutputImage(MLint outputIndex=0) const; 00437 00441 InputConnectorField* addInputImage(const char* name = NULL); 00442 00447 OutputConnectorField* addOutputImage(const char* name = NULL); 00448 00449 //--------------------------------------------------------------------------- 00464 //--------------------------------------------------------------------------- 00465 public: PagedImage* getInputImage(MLint inputIndex, bool getReal=false) const; 00466 00467 //--------------------------------------------------------------------------- 00478 //--------------------------------------------------------------------------- 00479 public: PagedImage *getUpdatedInputImage(MLint inputIndex, bool getReal=false); 00480 00482 00483 00484 00485 //--------------------------------------------------------------------------- 00487 00488 // These functions are identical to those from 00489 // Host::getDefaultHost() and are 00490 // wrapped here for convenience and to avoid direct accesses 00491 // to the host and to avoid includes of mlHost.h. 00492 // See mlHost.h for documentation. 00493 //--------------------------------------------------------------------------- 00494 public: 00495 00498 static MLErrorCode getTile(PagedImage* image, 00499 SubImageBox loc, 00500 MLDataType datatype, 00501 void** data, 00502 const ScaleShiftData &scaleShiftData=ScaleShiftData()) ML_RETURN_VALUE_SHOULD_BE_USED; 00503 00507 static MLErrorCode getTile(PagedImage* image, 00508 SubImage &subimg, 00509 const ScaleShiftData &scaleShiftData=ScaleShiftData()) ML_RETURN_VALUE_SHOULD_BE_USED; 00510 00513 static MLErrorCode updateImageProperties(PagedImage* image) ML_RETURN_VALUE_SHOULD_BE_USED; 00514 00516 static void freeTile(void* data); 00517 00519 static void updateProgress(const char* info1, const char* info2); 00520 00522 static bool shouldTerminate(); 00523 00525 static Field* getPressedNotifyField(); 00526 00537 static void adaptPageExtent (ImageVector& pageExtent, 00538 MLDataType imageType, 00539 const ImageVector& newImgExtent, 00540 const ImageVector& oldImgExtent, 00541 const ImageVector& pageUnit = ImageVector(0), 00542 const ImageVector& minPageExtent = ImageVector(0), 00543 const ImageVector& maxPageExtent = ImageVector(0)); 00544 00546 00547 //--------------------------------------------------------------------------- 00549 00550 //--------------------------------------------------------------------------- 00551 00558 static std::string getVoxelValueAsString(PagedImage* image, 00559 const ImageVector& position, 00560 MLErrorCode* errorCode=NULL, 00561 const std::string& errorResult=""); 00563 00564 00565 00566 //--------------------------------------------------------------------------- 00568 00569 //--------------------------------------------------------------------------- 00570 00599 protected: virtual CalculateOutputImageHandler* createCalculateOutputImageHandler(PagedImage* outputImage); 00600 00616 protected: virtual void calculateOutputImageProperties(int outputIndex, PagedImage* /*outputImage*/) { calculateOutputImageProperties(outputIndex); }; 00617 00620 protected: virtual void calculateOutputImageProperties(int /*outputIndex*/) {}; 00621 00628 protected: virtual SubImageBox calculateInputSubImageBox(int /*inputIndex*/, 00629 const SubImageBox& outputSubImageBox, 00630 int /*outputIndex*/) 00631 { 00632 return outputSubImageBox; 00633 }; 00634 00649 protected: virtual void calculateOutputSubImage(SubImage *outputSubImage, int outputIndex, SubImage *inputSubImages); 00650 00652 00653 //--------------------------------------------------------------------------- 00655 00656 //--------------------------------------------------------------------------- 00657 00665 protected: virtual void provideCustomPage(int /*outputIndex*/, const SubImageBox& /*pageBox*/, MLMemoryBlockHandle& /*resultPage*/) {}; 00666 00668 00669 //--------------------------------------------------------------------------- 00671 00672 //--------------------------------------------------------------------------- 00709 public: MLErrorCode processAllPages(int outputIndex = -1, 00710 SubImageBox region = SubImageBox()) ML_RETURN_VALUE_SHOULD_BE_USED; 00711 00716 public: MLErrorCode processAllPages(ProcessAllPagesHandler& handler, 00717 SubImageBox region = SubImageBox()) ML_RETURN_VALUE_SHOULD_BE_USED; 00718 00722 public: MLErrorCode processMissingPages(int outputIndex = 0, 00723 SubImageBox region = SubImageBox()) ML_RETURN_VALUE_SHOULD_BE_USED; 00725 00726 00727 00728 //--------------------------------------------------------------------------- 00730 00731 //--------------------------------------------------------------------------- 00732 00734 public: void clearOutputImage(MLint i=0); 00736 00738 public: MLMetaProfilePtr& getMetaProfile() const; 00739 00740 00741 //--------------------------------------------------------------------------- 00743 00744 //--------------------------------------------------------------------------- 00747 protected: void handleNotificationOff(); 00748 00751 protected: void handleNotificationOn(); 00752 00754 protected: bool isHandleNotificationOn(); 00756 00757 00758 //--------------------------------------------------------------------------- 00760 00761 //--------------------------------------------------------------------------- 00762 00764 public: bool isInputImageField(Field* field) const; 00765 00767 public: void touchOutputImageFields() const; 00768 00772 public: inline FieldContainer* getFieldContainer() { return this; } 00773 00777 public: inline const FieldContainer* getFieldContainer() const { return this; } 00778 00793 protected: virtual void handleNotification(Field* /*field*/) {} 00794 00798 public: virtual void beginSaveFields() {} 00799 00803 public: virtual void endSaveFields() {} 00805 00808 protected: virtual void handleNotificationInternal(Field* field, FieldSensor::Strength strength); 00809 00810 00811 //--------------------------------------------------------------------------- 00813 00814 //--------------------------------------------------------------------------- 00816 public: static size_t getNumModules(); 00817 00819 public: static Module* getModule(size_t index); 00820 00822 public: static MLint findModuleIndex(Module& module); 00823 00826 public: static void destroyModule(); 00828 00830 00831 00832 public: void setMarker(int val); 00833 00835 public: int getMarker(); 00837 00838 private: 00839 //-----------Private methods: 00843 bool _addBaseOp(Module& module); 00844 00848 MLint _removeBaseOp(Module& module); 00849 00850 00851 //-----------Private members: 00853 std::vector <OutputConnectorField*> _outputConnectorFields; 00854 00856 std::vector <InputConnectorField*> _inputConnectorFields; 00857 00859 THREAD_SUPPORT _threadSupport; 00860 00867 MLint _handleNotificationEntryCounter; 00868 00872 bool _permitRecursiveHandleNotifications; 00873 00877 MLint _marker; 00878 00880 PERMITTED_TYPES _permittedTypes; 00881 00886 MLint _handleNotificationBlockCounter; 00887 00889 mutable MLMetaProfilePtr _metaProfilePtr; 00890 00892 static std::vector<Module*> _instantiatedModules; 00893 00899 ML_ABSTRACT_CLASS_HEADER(Module) 00900 00901 public: 00904 00905 00906 00907 virtual InputConnectorField* addInputConnector(const char* name, Module* module, MLint i); 00908 00911 virtual OutputConnectorField* addOutputConnector(const char* name, Module* module, MLint i); 00912 00914 00915 #ifdef ML_DEPRECATED 00916 00918 00919 00920 public: 00921 00924 protected: void setMemoryOutputControl(MLint outputIndex, bool manually); 00925 00928 public: bool getMemoryOutputControl(MLint outputIndex) const; 00929 00930 00933 static inline ML_DEPRECATED std::string getVoxelValueAsString(Module &op, 00934 MLint outIdx, 00935 const ImageVector &pos, 00936 MLErrorCode *errCode=NULL, 00937 const std::string &errResult="") 00938 { 00939 return getVoxelValueAsString(op.getOutputImage(outIdx), pos, errCode, errResult); 00940 } 00943 static ML_DEPRECATED MLErrorCode getTile(Module* op, 00944 MLint outIndex, 00945 SubImageBox loc, 00946 MLDataType datatype, 00947 void** data, 00948 const ScaleShiftData &scaleShiftData=ScaleShiftData()) ML_RETURN_VALUE_SHOULD_BE_USED; 00951 static ML_DEPRECATED MLErrorCode getTile(Module* op, 00952 MLint outIndex, 00953 SubImage &subimg, 00954 const ScaleShiftData &scaleShiftData=ScaleShiftData()) ML_RETURN_VALUE_SHOULD_BE_USED; 00957 static ML_DEPRECATED MLErrorCode updateImageProps(Module* op, MLint outIndex) ML_RETURN_VALUE_SHOULD_BE_USED; 00960 static ML_DEPRECATED MLErrorCode updateImageProperties(Module* op, MLint outIndex) ML_RETURN_VALUE_SHOULD_BE_USED; 00963 ML_DEPRECATED BaseOp* getInOp(MLint i, bool getReal=false) const; 00966 ML_DEPRECATED MLint getInOpIndex(MLint i, bool getReal=false) const; 00969 inline ML_DEPRECATED MLint getOutImgInplace(MLint outIndex=0) const { return getOutputImageInplace(outIndex); } 00970 00973 ML_DEPRECATED static void getInInfos(const BaseOp &op, 00974 MLint i, 00975 bool getReal, 00976 bool *isValidInputRet, 00977 BaseOp **inOpRet, 00978 PagedImage **inImgRet, 00979 MLint *inOpIndexRet); 00980 00983 inline ML_DEPRECATED MLint getInputNum() const { return getNumInputImages(); } 00986 inline ML_DEPRECATED MLint getOutputNum() const { return getNumOutputImages(); } 00989 inline ML_DEPRECATED PagedImage* getOutImg(MLint i=0) const { return getOutputImage(i); } 00992 inline ML_DEPRECATED PagedImage* getInImg(MLint i, bool getReal=false) const { return getInputImage(i, getReal); } 00995 inline ML_DEPRECATED PagedImage* getUpdatedInImg(MLint i, bool getReal=false) { return getUpdatedInputImage(i, getReal); } 00996 01006 ML_DEPRECATED PagedImage* getNonDummyUpdatedInImg(int inIndex); 01007 01010 inline ML_DEPRECATED static void adaptPageExt (ImageVector &pageExt, 01011 MLDataType imgType, 01012 const ImageVector &newImgExt, 01013 const ImageVector &oldImgExt, 01014 const ImageVector &pageUnit = ImageVector(0), 01015 const ImageVector &minPageExt = ImageVector(0), 01016 const ImageVector &maxPageExt = ImageVector(0)) 01017 { 01018 adaptPageExtent(pageExt, imgType, newImgExt, oldImgExt, pageUnit, minPageExt, maxPageExt); 01019 } 01022 inline ML_DEPRECATED void clearOutImg(MLint i=0) { clearOutputImage(i); } 01025 inline ML_DEPRECATED InputConnectorField* getInField(MLint i) const { return getInputImageField(i); } 01028 inline ML_DEPRECATED OutputConnectorField* getOutField(MLint i=0) const { return getOutputImageField(i); } 01031 inline const FieldContainer* getConstFieldContainer() const { return getFieldContainer(); } 01034 inline ML_DEPRECATED static size_t getNumBaseOps() { return getNumModules(); } 01037 ML_DEPRECATED static BaseOp* getBaseOp(size_t idx); 01040 inline ML_DEPRECATED static MLint findBaseOpIndex(Module &op) { return findModuleIndex(op); } 01043 inline ML_DEPRECATED static void destroyBaseOp() { destroyModule(); } 01044 01045 01046 protected: 01047 01050 inline ML_DEPRECATED void setOutImgInplace(MLint outIndex=0, MLint inIndex=0) { setOutputImageInplace(outIndex, inIndex); } 01053 inline ML_DEPRECATED void unsetOutImgInplace(MLint outIndex=0) { unsetOutputImageInplace(outIndex); } 01054 01056 01057 #endif // ML_DEPRECATED 01058 01059 }; 01060 01061 #ifdef ML_DEPRECATED 01062 01063 01064 01065 01066 #define calcOutImageProps calculateOutputImageProperties 01067 01068 01069 #define calcInSubImageBox calculateInputSubImageBox 01070 01071 01072 #define calcOutSubImage calculateOutputSubImage 01073 01074 01075 #define typedCalcOutSubImage typedCalculateOutputSubImage 01076 01077 #if defined(WIN32) && defined(ML_WARN_DEPRECATED) 01078 #pragma deprecated("calcOutImageProps", "calcInSubImageBox", "calcOutSubImage", "typedCalcOutSubImage") 01079 #endif 01080 01081 #ifndef DOXYGEN_SHOULD_SKIP_THIS 01082 01088 template<typename CauseAnErrorIfNotSpecified> 01089 class calcInSubImageProps_has_been_removed_from_the_ML { 01090 }; 01091 01093 #define calcInSubImageProps(a,b,c) calcInSubImageProps() { calcInSubImageProps_has_been_removed_from_the_ML; }; 01094 01095 #endif 01096 01097 // disable deprecation warnings 01098 #ifdef _MSC_VER 01099 #pragma warning(push) 01100 #pragma warning(disable : 4996 ) 01101 #endif 01102 01105 class MLEXPORT ML_DEPRECATED BaseOp : public Module 01106 { 01107 public: 01108 BaseOp(int numInputImages, int numOutputImages):Module(numInputImages, numOutputImages) 01109 {}; 01110 01111 ML_ABSTRACT_CLASS_HEADER(BaseOp) 01112 }; 01113 01114 // re-enable deprecation warnings 01115 #ifdef _MSC_VER 01116 #pragma warning(pop) 01117 #endif 01118 01120 01121 #endif // ML_DEPRECATED 01122 01123 01124 ML_END_NAMESPACE 01125 01126 #endif //of __mlModule_H 01127 01128