ML Reference
MeVis/Foundation/Sources/ML/include/mlModule.h
Go to the documentation of this file.
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 
00040 #include <mlMetaProfilePtr.h>
00041 
00042 
00045 #define ML_ADD_FIELD(NAME_P, TYPE_P, VALUE_P) \
00046 ((TYPE_P##Field*) this->getFieldContainer()->addField(NAME_P, #TYPE_P, VALUE_P));
00047 
00048 
00049 class MLMemoryBlockHandle;
00050 
00051 // Namespace ML. It is recommended that all ML classes and modules are in this
00052 // name space to avoid collisions with types of other libraries.
00053 ML_START_NAMESPACE
00054 
00055 // ML-classes
00056 class SubImage;
00057 class PagedImage;
00058 class ProcessAllPagesHandler;
00059 #ifdef ML_DEPRECATED
00060 class BaseOp;
00061 class DummyOp;
00062 #endif
00063 
00064 //-------------------------------------------------------------------------
00067 
00164 //-------------------------------------------------------------------------
00165 class MLEXPORT Module : public FieldContainer
00166 {
00167 
00168   //---------------------------------------------------------------------------
00170   //---------------------------------------------------------------------------
00171   friend class Host;
00172   friend class PagedImage;
00173   friend class PageRequest;
00174   friend class TileRequest;
00175   friend class ModuleCalculateOutputImageHandler;
00176   friend class State;
00177 
00178   ML_DISALLOW_COPY_AND_ASSIGN(Module)
00179 
00180   //---------------------------------------------------------------------------
00182 
00183   //---------------------------------------------------------------------------
00184 
00185   
00186 
00187 
00188 
00189 
00190 
00191 
00192 
00193 public: Module(int numInputImages, int numOutputImages);
00194 
00200 public: virtual ~Module();
00202 
00203 
00204 
00205   //---------------------------------------------------------------------------
00207 
00208   //---------------------------------------------------------------------------
00209 
00216 protected: void setOutputImageInplace(MLint outputIndex=0, MLint inputIndex=0);
00217 
00221 protected: void unsetOutputImageInplace(MLint outputIndex=0);
00222 
00227 public:    MLint getOutputImageInplace(MLint outputIndex=0) const;
00228 
00229 
00230 
00236 protected: void setBypass(MLint outputIndex=0, MLint inputIndex=0);
00237 
00241 public:    MLint getBypass(MLint outputIndex=0) const;
00242 
00245   enum THREAD_SUPPORT {
00246     NO_THREAD_SUPPORT                           = 0, 
00247     ML_CALCULATEOUTPUTSUBIMAGE_ON_STD_TYPES     = 1, 
00248     ML_CALCULATEOUTPUTSUBIMAGE_ON_ALL_TYPES     = 3  
00249 #ifdef ML_DEPRECATED
00250     ,
00251     CALC_OUTSUBIMAGE_ON_STD_TYPES     = ML_CALCULATEOUTPUTSUBIMAGE_ON_STD_TYPES,
00252     CALC_OUTSUBIMAGE_ON_ALL_TYPES     = ML_CALCULATEOUTPUTSUBIMAGE_ON_ALL_TYPES
00253 #endif // ML_DEPRECATED
00254   };
00255 
00258 protected: void setThreadSupport(THREAD_SUPPORT supportMode);
00259 
00262 public:    THREAD_SUPPORT getThreadSupport() const;
00263 
00264 
00268 protected: void permitRecursiveHandleNotifications(bool enable);
00269 
00272 public:    bool areRecursiveHandleNotificationsPermitted() const;
00273 
00279 public:    MLint getHandleNotificationEntryCounter() const;
00280 
00282 
00283 
00284   //---------------------------------------------------------------------------
00286 
00287   //---------------------------------------------------------------------------
00289 public: enum PERMITTED_TYPES {
00290   ONLY_SCALAR_TYPES,
00291   ONLY_DEFAULT_TYPES,
00292   ALL_REGISTERED_TYPES,
00293   ONLY_STANDARD_TYPES   = ONLY_SCALAR_TYPES,    
00294   FULLY_OPERATIONAL     = ONLY_DEFAULT_TYPES,   
00295   MINIMUM_OPERATIONAL   = ALL_REGISTERED_TYPES  
00296   // PARTIALLY_OPERATIONAL = 2 // nobody ever used that
00297 };
00298 
00314 protected: void setVoxelDataTypeSupport(PERMITTED_TYPES permTypes);
00315 
00319 public:    PERMITTED_TYPES getVoxelDataTypeSupport() const;
00320 
00323 public:    bool isSupportedVoxelDataType(MLDataType dt) const;
00325 
00326 
00327   //---------------------------------------------------------------------------
00329 
00330   //---------------------------------------------------------------------------
00331 
00336 public:    std::string whoAmI(bool withInstanceName=true) const;
00338 
00339 
00340 
00341 
00342   //---------------------------------------------------------------------------
00344 
00345   //---------------------------------------------------------------------------
00346 
00348 public:    enum INPUT_STATE  {
00349   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.
00350   CONNECTED_BUT_INVALID      = 1,  //<! defines that the input is connected but has no valid data.
00351   CONNECTED_AND_VALID        = 2,  //<! defines that the input is connected and valid.
00352   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.
00353 #ifdef ML_DEPRECATED
00354   OPEN             = DISCONNECTED,         //<! \deprecated, use DISCONNECTED
00355   UNDEFINED_CLOSED = CONNECTED_BUT_INVALID //<! \deprecated, use CONNECTED_BUT_INVALID
00356 #endif
00357 };
00358 
00360 public:    enum INPUT_HANDLE {
00361   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().
00362   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.
00363 #ifdef ML_DEPRECATED
00364   REDIRECT_TO_DUMMY_OP = 1, //<! Deprecated flag to indicate that an invalid input should be redirected to the DummyOp module.
00365 #endif
00366 };
00367 
00395 public:    virtual INPUT_HANDLE handleInput(int /*inputIndex*/, INPUT_STATE /*state*/) const { return INVALIDATE; }
00396 
00404 public:    INPUT_STATE getInputState(MLint index);
00405 
00410 public:    INPUT_STATE getUpdatedInputState(MLint index);
00412 
00413 
00414 
00415   //---------------------------------------------------------------------------
00417 
00418   //---------------------------------------------------------------------------
00419 
00420 public:
00422   InputConnectorField*  getInputImageField(MLint i) const;
00424   OutputConnectorField* getOutputImageField(MLint i=0) const;
00425 
00427   MLint getNumInputImages() const;
00428 
00430   MLint getNumOutputImages() const;
00431 
00433   PagedImage* getOutputImage(MLint outputIndex=0) const;
00434 
00438   InputConnectorField* addInputImage(const char* name = NULL);
00439 
00444   OutputConnectorField* addOutputImage(const char* name = NULL);
00445 
00446   //---------------------------------------------------------------------------
00461   //---------------------------------------------------------------------------
00462 public:    PagedImage* getInputImage(MLint inputIndex, bool getReal=false) const;
00463 
00464   //---------------------------------------------------------------------------
00475   //---------------------------------------------------------------------------
00476 public:    PagedImage *getUpdatedInputImage(MLint inputIndex, bool getReal=false);
00477 
00479 
00480 
00481 
00482   //---------------------------------------------------------------------------
00484 
00485   //         These functions are identical to those from
00486   //         Host::getDefaultHost() and are
00487   //         wrapped here for convenience and to avoid direct accesses
00488   //         to the host and to avoid includes of mlHost.h.
00489   //         See mlHost.h for documentation.
00490   //---------------------------------------------------------------------------
00491 public:
00492 
00495   static MLErrorCode getTile(PagedImage*  image,
00496                              SubImageBox  loc,
00497                              MLDataType datatype,
00498                              void**     data,
00499                              const ScaleShiftData &scaleShiftData=ScaleShiftData()) ML_RETURN_VALUE_SHOULD_BE_USED;
00500 
00504   static MLErrorCode getTile(PagedImage* image,
00505                              SubImage &subimg,
00506                              const ScaleShiftData &scaleShiftData=ScaleShiftData()) ML_RETURN_VALUE_SHOULD_BE_USED;
00507 
00510   static MLErrorCode updateImageProperties(PagedImage* image) ML_RETURN_VALUE_SHOULD_BE_USED;
00511 
00513   static void        freeTile(void* data);
00514 
00516   static void        updateProgress(const char* info1, const char* info2);
00517 
00519   static bool        shouldTerminate();
00520 
00522   static Field*      getPressedNotifyField();
00523 
00534   static void adaptPageExtent (ImageVector&       pageExtent,
00535                                MLDataType         imageType,
00536                                const ImageVector& newImgExtent,
00537                                const ImageVector& oldImgExtent,
00538                                const ImageVector& pageUnit      = ImageVector(0),
00539                                const ImageVector& minPageExtent = ImageVector(0),
00540                                const ImageVector& maxPageExtent = ImageVector(0));
00541 
00543 
00544   //---------------------------------------------------------------------------
00546 
00547   //---------------------------------------------------------------------------
00548 
00555   static std::string getVoxelValueAsString(PagedImage*          image,
00556                                            const ImageVector& position,
00557                                            MLErrorCode*       errorCode=NULL,
00558                                            const std::string& errorResult="");
00560 
00561 
00562 
00563   //---------------------------------------------------------------------------
00565 
00566   //---------------------------------------------------------------------------
00567 
00596 protected: virtual CalculateOutputImageHandler* createCalculateOutputImageHandler(PagedImage* outputImage);
00597 
00613 protected: virtual void calculateOutputImageProperties(int outputIndex, PagedImage* /*outputImage*/) { calculateOutputImageProperties(outputIndex); };
00614 
00617 protected: virtual void calculateOutputImageProperties(int /*outputIndex*/) {};
00618 
00625 protected: virtual SubImageBox calculateInputSubImageBox(int /*inputIndex*/,
00626                                                        const SubImageBox& outputSubImageBox,
00627                                                        int /*outputIndex*/)
00628   {
00629     return outputSubImageBox;
00630   };
00631 
00646 protected: virtual void calculateOutputSubImage(SubImage *outputSubImage, int outputIndex, SubImage *inputSubImages);
00647 
00649 
00650   //---------------------------------------------------------------------------
00652 
00653   //---------------------------------------------------------------------------
00654 
00662 protected: virtual void provideCustomPage(int /*outputIndex*/, const SubImageBox& /*pageBox*/, MLMemoryBlockHandle& /*resultPage*/) {};
00663 
00665 
00666   //---------------------------------------------------------------------------
00668 
00669   //---------------------------------------------------------------------------
00699 public: MLErrorCode processAllPages(int       outputIndex = -1,
00700                                     SubImageBox region      = SubImageBox()) ML_RETURN_VALUE_SHOULD_BE_USED;
00701 
00706 public: MLErrorCode processAllPages(ProcessAllPagesHandler& handler,
00707                                     SubImageBox region  = SubImageBox()) ML_RETURN_VALUE_SHOULD_BE_USED;
00709 
00710 
00711 
00712   //---------------------------------------------------------------------------
00714 
00715   //---------------------------------------------------------------------------
00716 
00718 public:    void clearOutputImage(MLint i=0);
00720 
00722 public: MLMetaProfilePtr& getMetaProfile() const;
00723 
00724 
00725   //---------------------------------------------------------------------------
00727 
00728   //---------------------------------------------------------------------------
00731 protected: void handleNotificationOff();
00732 
00735 protected: void handleNotificationOn();
00736 
00738 protected: bool isHandleNotificationOn();
00740 
00741 
00742   //---------------------------------------------------------------------------
00744 
00745   //---------------------------------------------------------------------------
00746 
00748 public:    bool isInputImageField(Field* field) const;
00749 
00751 public:    void touchOutputImageFields() const;
00752 
00756 public:    inline FieldContainer* getFieldContainer()                  { return this; }
00757 
00761 public:    inline const FieldContainer* getFieldContainer() const { return this; }
00762 
00777 protected: virtual void handleNotification(Field* /*field*/) {}
00778 
00782 public:    virtual void beginSaveFields() {}
00783 
00787 public:    virtual void endSaveFields() {}
00789   
00792 protected: virtual void handleNotificationInternal(Field* field, FieldSensor::Strength strength);
00793 
00794 
00795   //---------------------------------------------------------------------------
00797 
00798   //---------------------------------------------------------------------------
00800 public:    static size_t getNumModules();
00801 
00803 public:    static Module* getModule(size_t index);
00804 
00806 public:    static MLint findModuleIndex(Module& module);
00807 
00810 public:    static void destroyModule();
00812 
00814 
00815 
00816 public:    void  setMarker(int val);
00817 
00819 public:    int getMarker();
00821 
00822 private:
00823   //-----------Private methods:
00827   bool _addBaseOp(Module& module);
00828 
00832   MLint _removeBaseOp(Module& module);
00833 
00834 
00835   //-----------Private members:
00837   std::vector <OutputConnectorField*> _outputConnectorFields;
00838 
00840   std::vector <InputConnectorField*>  _inputConnectorFields;
00841 
00843   THREAD_SUPPORT         _threadSupport;
00844 
00851   MLint                  _handleNotificationEntryCounter;
00852 
00856   bool                   _permitRecursiveHandleNotifications;
00857 
00861   MLint                  _marker;
00862 
00864   PERMITTED_TYPES        _permittedTypes;
00865 
00870   MLint                  _handleNotificationBlockCounter;
00871 
00873   mutable MLMetaProfilePtr _metaProfilePtr;
00874 
00876   static std::vector<Module*> _instantiatedModules;
00877 
00883   ML_ABSTRACT_CLASS_HEADER(Module)
00884 
00885 public:
00888 
00889 
00890 
00891   virtual InputConnectorField* addInputConnector(const char* name, Module* module, MLint i);
00892 
00895   virtual OutputConnectorField* addOutputConnector(const char* name, Module* module, MLint i);
00896 
00898 
00899 #ifdef ML_DEPRECATED
00900 
00902 
00903 
00904 public:
00905 
00908 protected: void setMemoryOutputControl(MLint outputIndex, bool manually);
00909 
00912 public:    bool getMemoryOutputControl(MLint outputIndex) const;
00913 
00914 
00917   static inline ML_DEPRECATED std::string getVoxelValueAsString(Module &op,
00918                                                                 MLint outIdx,
00919                                                                 const ImageVector &pos,
00920                                                                 MLErrorCode *errCode=NULL,
00921                                                                 const std::string &errResult="")
00922   {
00923     return getVoxelValueAsString(op.getOutputImage(outIdx), pos, errCode, errResult);
00924   }
00927   static ML_DEPRECATED MLErrorCode getTile(Module* op,
00928                                            MLint outIndex,
00929                                            SubImageBox loc,
00930                                            MLDataType datatype,
00931                                            void** data,
00932                                            const ScaleShiftData &scaleShiftData=ScaleShiftData()) ML_RETURN_VALUE_SHOULD_BE_USED;
00935   static ML_DEPRECATED MLErrorCode getTile(Module* op,
00936                                            MLint outIndex,
00937                                            SubImage &subimg,
00938                                            const ScaleShiftData &scaleShiftData=ScaleShiftData()) ML_RETURN_VALUE_SHOULD_BE_USED;
00941   static ML_DEPRECATED MLErrorCode updateImageProps(Module* op, MLint outIndex) ML_RETURN_VALUE_SHOULD_BE_USED;
00944   static ML_DEPRECATED MLErrorCode updateImageProperties(Module* op, MLint outIndex) ML_RETURN_VALUE_SHOULD_BE_USED;
00947   ML_DEPRECATED BaseOp* getInOp(MLint i, bool getReal=false) const;
00950   ML_DEPRECATED MLint getInOpIndex(MLint i, bool getReal=false) const;
00953   inline ML_DEPRECATED MLint getOutImgInplace(MLint outIndex=0) const { return getOutputImageInplace(outIndex); }
00954 
00957   ML_DEPRECATED static void getInInfos(const BaseOp  &op,
00958                                               MLint          i,
00959                                               bool           getReal,
00960                                               bool          *isValidInputRet,
00961                                               BaseOp       **inOpRet,
00962                                               PagedImage     **inImgRet,
00963                                               MLint         *inOpIndexRet);
00964 
00967   inline ML_DEPRECATED MLint getInputNum() const { return getNumInputImages(); }
00970   inline ML_DEPRECATED MLint getOutputNum() const { return getNumOutputImages(); }
00973   inline ML_DEPRECATED PagedImage* getOutImg(MLint i=0) const { return getOutputImage(i); }
00976   inline ML_DEPRECATED PagedImage* getInImg(MLint i, bool getReal=false) const { return getInputImage(i, getReal); }
00979   inline ML_DEPRECATED PagedImage* getUpdatedInImg(MLint i, bool getReal=false) { return getUpdatedInputImage(i, getReal); }
00980 
00990   ML_DEPRECATED PagedImage* getNonDummyUpdatedInImg(int inIndex);
00991 
00994   inline ML_DEPRECATED static void adaptPageExt (ImageVector &pageExt,
00995                                                  MLDataType imgType,
00996                                                  const ImageVector &newImgExt,
00997                                                  const ImageVector &oldImgExt,
00998                                                  const ImageVector &pageUnit   = ImageVector(0),
00999                                                  const ImageVector &minPageExt = ImageVector(0),
01000                                                  const ImageVector &maxPageExt = ImageVector(0))
01001   {
01002     adaptPageExtent(pageExt, imgType, newImgExt, oldImgExt, pageUnit, minPageExt, maxPageExt);
01003   }
01006   inline ML_DEPRECATED void clearOutImg(MLint i=0) { clearOutputImage(i); }
01009   inline ML_DEPRECATED InputConnectorField* getInField(MLint i) const       { return getInputImageField(i); }
01012   inline ML_DEPRECATED OutputConnectorField* getOutField(MLint i=0) const   { return getOutputImageField(i); }
01015   inline const FieldContainer* getConstFieldContainer() const { return getFieldContainer(); }
01018   inline ML_DEPRECATED static size_t getNumBaseOps() { return getNumModules(); }
01021   ML_DEPRECATED static BaseOp* getBaseOp(size_t idx);
01024   inline ML_DEPRECATED static MLint findBaseOpIndex(Module &op) { return findModuleIndex(op); }
01027   inline ML_DEPRECATED static void destroyBaseOp() { destroyModule(); }
01028 
01029 
01030 protected:
01031 
01034   inline ML_DEPRECATED void setOutImgInplace(MLint outIndex=0, MLint inIndex=0) { setOutputImageInplace(outIndex, inIndex); }
01037   inline ML_DEPRECATED void unsetOutImgInplace(MLint outIndex=0) { unsetOutputImageInplace(outIndex); }
01038 
01040 
01041 #endif // ML_DEPRECATED
01042 
01043 };
01044 
01045 #ifdef ML_DEPRECATED
01046 
01047 
01048 
01049 
01050 #define calcOutImageProps calculateOutputImageProperties
01051 
01052 
01053 #define calcInSubImageBox calculateInputSubImageBox
01054 
01055 
01056 #define calcOutSubImage   calculateOutputSubImage
01057 
01058 
01059 #define typedCalcOutSubImage   typedCalculateOutputSubImage
01060 
01061 #if defined(WIN32) && defined(ML_WARN_DEPRECATED)
01062 #pragma deprecated("calcOutImageProps", "calcInSubImageBox", "calcOutSubImage", "typedCalcOutSubImage")
01063 #endif
01064 
01065 #ifndef DOXYGEN_SHOULD_SKIP_THIS
01066 
01072 template<typename CauseAnErrorIfNotSpecified>
01073 class calcInSubImageProps_has_been_removed_from_the_ML {
01074 };
01075 
01077 #define calcInSubImageProps(a,b,c) calcInSubImageProps() { calcInSubImageProps_has_been_removed_from_the_ML; };
01078 
01079 #endif
01080 
01081 // disable deprecation warnings
01082 #ifdef _MSC_VER
01083 #pragma warning(push)
01084 #pragma warning(disable : 4996 )
01085 #endif
01086 
01089 class MLEXPORT ML_DEPRECATED BaseOp : public Module
01090 {
01091 public:
01092   BaseOp(int numInputImages, int numOutputImages):Module(numInputImages, numOutputImages)
01093   {};
01094 
01095   ML_ABSTRACT_CLASS_HEADER(BaseOp)
01096 };
01097 
01098 // re-enable deprecation warnings
01099 #ifdef _MSC_VER
01100 #pragma warning(pop)
01101 #endif
01102 
01104 
01105 #endif // ML_DEPRECATED
01106 
01107 
01108 ML_END_NAMESPACE
01109 
01110 #endif //of __mlModule_H
01111 
01112