ML Reference
|
00001 // **InsertLicense** code 00002 //------------------------------------------------------------------------------ 00025 //------------------------------------------------------------------------------ 00026 #ifndef __mlPagedImage_H 00027 #define __mlPagedImage_H 00028 00029 //ML-includes 00030 #ifndef __mlInitSystemML_H 00031 #include "mlInitSystemML.h" 00032 #endif 00033 #ifndef __mlMedicalImageProperties_H 00034 #include "mlMedicalImageProperties.h" 00035 #endif 00036 #ifndef __mlMemoryImage_H 00037 #include "mlMemoryImage.h" 00038 #endif 00039 00040 #include "mlInputSubImageProperties.h" 00041 #include "mlModuleInterfaces.h" 00042 #include "mlRangeCasts.h" 00043 00044 #include <mlMemoryBlockHandle.h> 00045 #include <mlMetaProfilePtr.h> 00046 00047 00048 ML_START_NAMESPACE 00049 00051 class PagedImageCurrentlyUsedMemoryTracker; 00052 class Module; 00053 class SubImage; 00054 class PageRequest; 00055 struct PagedImagePageEntry; 00056 struct PagedImageExtendedPageEntry; 00057 #ifdef ML_DEPRECATED 00058 class BaseOp; 00059 #endif 00060 00061 00062 00063 //------------------------------------------------------------------------------ 00067 //------------------------------------------------------------------------------ 00068 class ML_UNIX_ONLY_EXPORT(MLEXPORT) PagedImage: public MedicalImageProperties 00069 { 00070 00071 public: 00072 00074 friend class Host; 00075 // needed for testing protected API: 00076 ML_FRIEND_TEST(PagedImageDeprecationTest, NewAPI); 00077 ML_FRIEND_TEST(PagedImageDeprecationTest, DeprecatedAPI); 00078 00079 //------------------------------------------------------ 00081 00082 //------------------------------------------------------ 00083 00091 MLEXPORT PagedImage(Module* module=NULL, MLint outputIndex=-1); 00092 00095 MLEXPORT virtual ~PagedImage(); 00097 00099 inline CalculateOutputImageHandler* getCalculateOutputImageHandler() const { return _calculateOutputImageHandler; } 00100 00103 MLEXPORT void setExternalCalculateOutputImageHandler(CalculateOutputImageHandler* handler); 00104 00106 inline bool hasExternalCalculateOutputImageHandler() const { return _isExternalCalculateOutputImageHandler; } 00107 00109 MLEXPORT void setCalculateOutputImageHandler(CalculateOutputImageHandler* handler); 00110 00112 MLEXPORT void setCalculateOutputImagePropertiesCB(CalculateOutputImagePropertiesCB* callback, void* userData); 00113 00115 inline MLuint32 getID() { return _id; } 00116 00118 inline void updateID() { _id = getUniqueId(); } 00119 00120 //------------------------------------------------------------------- 00122 00123 //------------------------------------------------------------------- 00129 inline bool isValid() const { return _isValid; } 00130 00133 inline void setValid(bool flag = true) { _isValid=flag; } 00134 00137 inline void setInvalid() { _isValid=false; } 00138 00141 MLEXPORT void setUpdateOfImagePropertiesNeeded(bool flag); 00142 00145 MLEXPORT bool updateOfImagePropertiesNeeded() const { return _updateOfImagePropertiesNeeded; } 00146 00148 MLEXPORT MLErrorCode updateImageProperties() ML_RETURN_VALUE_SHOULD_BE_USED; 00149 00151 00152 //------------------------------------------------------ 00154 00155 //------------------------------------------------------ 00156 00158 MLEXPORT virtual void setImageExtent(const ImageVector& extent); 00159 00163 inline void setImageExtent(MLint x, MLint y, MLint z = 1, MLint c = 1, MLint t = 1, MLint u = 1) { 00164 setImageExtent(ImageVector(x,y,z,c,t,u)); 00165 } 00166 00170 inline void setImageExtent(const SubImageBox &box) { setImageExtent(box.getExtent()); } 00171 00176 MLEXPORT virtual void setImageProperties(const PagedImage& imageProperties); 00177 00179 MLEXPORT void setPageExtent(const ImageVector& pageExtent); 00180 00183 inline void setPageExtent(MLint x, MLint y, MLint z = 1, MLint c = 1, MLint t = 1, MLint u = 1) { 00184 setPageExtent(ImageVector(x,y,z,c,t,u)); 00185 } 00186 00188 MLEXPORT void setPage(MLint pageID, const MLMemoryBlockHandle& page); 00189 00192 MLEXPORT void removePage(MLint pageID); 00193 00197 MLEXPORT void deletePageEntryFromDeletionCallback(PagedImageExtendedPageEntry* entry); 00198 00202 MLEXPORT void clearPageList(); 00203 00208 MLEXPORT void clearPageListAndMemoryImage(); 00210 00211 00212 00213 //------------------------------------------------------ 00215 00216 //------------------------------------------------------ 00223 MLEXPORT virtual void setStateInfo(const std::string& info, MLErrorCode errorCode); 00224 00231 MLEXPORT virtual void setStateInfoErrorCode(MLErrorCode errorCode); 00232 00235 MLEXPORT virtual const std::string& getStateInfoString() const; 00236 00239 MLEXPORT virtual MLErrorCode getStateInfoErrorCode() const; 00241 00242 //--------------------------------------------------------------------------- 00244 00245 //--------------------------------------------------------------------------- 00246 00252 inline void setBypassIndex(MLint index) { _bypassIndex = index; } 00253 00256 inline MLint getBypassIndex() const { return _bypassIndex; } 00258 00259 00260 //------------------------------------------------------ 00262 00263 //------------------------------------------------------ 00264 00266 inline Module* getModule() const { return _module; } 00267 00269 MLEXPORT const PagedImage* getInputImage(int inputIndex) const; 00270 00272 inline MLint getOutputIndex() const { return _outIndex; } 00273 00275 inline ImageVector getPageSetExtent() const { return _pageSetExt; } 00276 00278 inline ImageVector getPageStride() const { return _pageStride; } 00279 00281 inline ImageVector getPageExtent() const { return _pageExt; } 00282 00284 inline MLint getPageID(const ImageVector& voxelPosition) const { return (voxelPosition/_pageExt).dot(_pageStride); } 00285 00290 00291 inline MemoryImage& getMemoryImage() { return _memoryImg; } 00292 inline const MemoryImage& getMemoryImage() const { return _memoryImg; } 00294 00297 MLEXPORT MLMemoryBlockHandle getPage(MLint pageID) const; 00298 00301 MLEXPORT MLMemoryBlockHandle getPageOrPendingRequest(MLint pageID, PageRequest** pendingRequest) const; 00302 00304 MLEXPORT void setPageRequest(MLint pageID, PageRequest* request); 00305 00307 MLEXPORT PagedImage& getBypassSourceImage(); 00308 00311 MLEXPORT SubImageBox getPageBox(MLint pageID) const; 00312 00315 MLEXPORT void getPageIDs(std::vector <MLint>& pageIDs, const SubImageBox& subImageBox) const; 00316 00320 MLEXPORT static void getPageIDs(std::vector<MLint>& pageIDs, 00321 const SubImageBox& subImageBox, 00322 const ImageVector& imageExtent, 00323 const ImageVector& pageExtent); 00324 00326 MLEXPORT size_t getCachedPagesSizeInBytes() const; 00328 00329 00330 //--------------------------------------------------------------------------- 00332 00333 //--------------------------------------------------------------------------- 00334 00343 inline void setInPlaceIndex(MLint inputIndex) { _inPlaceIndex = inputIndex; } 00344 00352 inline MLint getInPlaceIndex() const { return _inPlaceIndex; } 00354 00355 00356 //------------------------------------------------------ 00358 00359 00360 00361 00362 00363 00364 //------------------------------------------------------ 00365 00371 MLEXPORT void setInputSubImageDataType(int inputIndex, MLDataType dataType); 00372 00380 MLEXPORT void setInputSubImageIsReadOnly(int inputIndex, bool readOnly); 00381 00397 MLEXPORT void setInputSubImageUseMemoryImage(int inputIndex, bool useMemoryImage); 00398 00402 MLEXPORT void setInputSubImageScaleShift(int inputIndex, const ScaleShiftData& scaleShift); 00403 00406 inline const InputSubImageProperties& getInputSubImageProperties(int inputIndex) const { return _inSubImageProps[mlrange_cast<size_t>(inputIndex)]; } 00407 00409 MLEXPORT MLDataType getInputSubImageDataType(int inputIndex) const; 00410 00412 MLEXPORT bool getInputSubImageIsReadOnly(int inputIndex) const; 00413 00415 00416 //------------------------------------------------------ 00418 00419 //------------------------------------------------------ 00420 00421 //--------------------------------------------------------------------------------- 00432 //--------------------------------------------------------------------------------- 00433 MLEXPORT void copyPages(const std::vector<MLint>& pageIDs, 00434 SubImage* subImage, 00435 const ScaleShiftData& scaleShiftData=ScaleShiftData()) const; 00437 00438 00439 //------------------------------------------------------------------- 00441 00442 //------------------------------------------------------------------- 00447 MLEXPORT MLErrorCode getTile(SubImageBox location, 00448 MLDataType dataType, 00449 void** data, 00450 const ScaleShiftData& scaleShiftData=ScaleShiftData()) ML_RETURN_VALUE_SHOULD_BE_USED; 00451 00456 MLEXPORT MLErrorCode getTile(SubImage& subImage, const ScaleShiftData& scaleShiftData=ScaleShiftData()) ML_RETURN_VALUE_SHOULD_BE_USED; 00457 00459 MLEXPORT void freeTile(void* data); 00461 00462 00463 //------------------------------------------------------ 00465 00466 //------------------------------------------------------ 00467 00470 MLEXPORT void printPageData(MLint pageID, std::ostream& ostr) const; 00471 00475 MLEXPORT void printPages(std::ostream& ostr) const; 00477 00479 MLEXPORT MLMetaProfilePtr& getMetaProfile() const; 00480 00482 MLEXPORT static void setPageCountLimitToUsePageEntryMap(MLuint32 limit) { _pageCountLimitToUsePageEntryMap = limit; } 00483 00485 MLEXPORT static MLuint32 getPageCountLimitToUsePageEntryMap() { return _pageCountLimitToUsePageEntryMap; } 00486 00487 protected: 00489 MLEXPORT void calculateImageProperties(); 00490 00492 MLEXPORT void initializeInputSubImageProperties(MLint numInputs); 00493 00495 MLEXPORT void validateInputSubImagePropertiesAfterCalculateOutputImageProperties(); 00496 00497 private: 00499 static MLuint32 getUniqueId(); 00500 00501 //------------------------------------------------------ 00503 00504 //------------------------------------------------------ 00511 PagedImage(const PagedImage&); 00512 00515 PagedImage& operator=(const PagedImage&); 00517 00518 00519 //------------------------------------------------------ 00521 00522 //------------------------------------------------------ 00527 void _updateAll(); 00528 00530 void _deletePageList(); 00531 00534 void _reallocPages(MLint pageSetSize); 00536 00537 00538 //------------------------------------------------------ 00540 00541 //------------------------------------------------------ 00542 00544 Module* _module; 00545 00547 CalculateOutputImageHandler* _calculateOutputImageHandler; 00548 00550 CalculateOutputImagePropertiesCB* _calculateOutputImageProperties; 00552 void* _calculateOutputImagePropertiesUserData; 00553 00555 bool _isExternalCalculateOutputImageHandler; 00556 00559 MLint _outIndex; 00560 00562 ImageVector _pageExt; 00563 00566 ImageVector _pageStride; 00567 00569 ImageVector _pageSetExt; 00570 00572 MLint _pageSetSize; 00573 00575 PagedImagePageEntry* _pageList; 00576 00578 std::map<MLint, PagedImageExtendedPageEntry*> _pageEntryMap; 00579 00581 mutable Mutex _pageEntryMapMutex; 00582 00584 bool _pageHandlesAreStoredInList; 00585 00591 MLint _inPlaceIndex; 00592 00594 MLint _bypassIndex; 00595 00597 bool _updateOfImagePropertiesNeeded; 00598 00600 bool _isValid; 00601 00604 MemoryImage _memoryImg; 00605 00607 std::string _stateInfoString; 00608 00610 MLErrorCode _stateInfoErrorCode; 00611 00613 MLuint32 _id; 00614 00616 std::vector<InputSubImageProperties> _inSubImageProps; 00617 00620 mutable PagedImageCurrentlyUsedMemoryTracker* _currentlyUsedPageMemoryTracker; 00621 00623 mutable MLMetaProfilePtr _metaProfilePtr; 00625 00627 static MLuint32 _staticUniqueId; 00628 00630 static MLuint32 _pageCountLimitToUsePageEntryMap; 00631 00632 #ifdef ML_DEPRECATED 00633 00635 00636 00637 public: 00639 static const char* const pageAllocationMemoryProfileKey; 00640 static const char* const pageCacheHitsCountProfileKey; 00641 static const char* const pageCacheMissesCountProfileKey; 00642 00643 00644 // \deprecated 00645 // Use getOutputIndex() instead. 00646 inline ML_DEPRECATED MLint getOutIndex() const { return getOutputIndex(); } 00647 00648 // \deprecated 00649 // Use isValid() instead. 00650 inline ML_DEPRECATED bool isUpToDate() const { return isValid(); } 00651 00652 // \deprecated 00653 // Use setValid() instead. 00654 inline ML_DEPRECATED void setUpToDate() { setValid(); } 00655 00656 // \deprecated 00657 // Use setInvalid() instead. 00658 inline ML_DEPRECATED void setOutOfDate() { setInvalid(); } 00659 00663 MLEXPORT bool isGlobalDummyImage(); 00664 00667 inline ML_DEPRECATED void setImgExt(const ImageVector &ext) { setImageExtent(ext); } 00670 inline ML_DEPRECATED void setImgExt(const SubImageBox &box) { setImageExtent(box); } 00673 inline ML_DEPRECATED void clearPageListAndMemoryImg() { clearPageListAndMemoryImage(); } 00676 MLEXPORT ML_DEPRECATED BaseOp* getBaseOp() const; 00679 inline ML_DEPRECATED void setImgProps(const PagedImage &imgProps) { setImageProperties(imgProps); } 00682 inline ML_DEPRECATED void setPageExt(const ImageVector &pageExt) { setPageExtent(pageExt); } 00685 inline ML_DEPRECATED const PagedImage* getInImg(int index) const { return getInputImage(index); } 00688 inline ML_DEPRECATED ImageVector getPageSetExt() const { return getPageSetExtent(); } 00691 inline ML_DEPRECATED ImageVector getPageExt() const { return getPageExtent(); } 00694 inline ML_DEPRECATED MemoryImage& getMemoryImg() { return getMemoryImage(); } 00697 inline ML_DEPRECATED const MemoryImage& getMemoryImg() const { return getMemoryImage(); } 00700 inline ML_DEPRECATED size_t getPageMemorySize() const { return getCachedPagesSizeInBytes(); } 00703 inline ML_DEPRECATED void setInSubImageDataType(int inputIndex, MLDataType datatype) { setInputSubImageDataType(inputIndex,datatype); } 00706 inline ML_DEPRECATED void setInSubImageIsReadOnly(int inputIndex, bool readOnly) { setInputSubImageIsReadOnly(inputIndex, readOnly); } 00709 inline ML_DEPRECATED void setInSubImageUseMemoryImage(int inputIndex, bool useMemImg) { setInputSubImageUseMemoryImage(inputIndex, useMemImg); } 00712 inline ML_DEPRECATED void setInSubImageScaleShift(int inputIndex, const ScaleShiftData& scaleShift) { setInputSubImageScaleShift(inputIndex, scaleShift); } 00715 inline ML_DEPRECATED const InputSubImageProperties& getInSubImageProps(int inputIndex) const { return getInputSubImageProperties(inputIndex); } 00718 inline ML_DEPRECATED MLDataType getInSubImageDataType(int inputIndex) const { return getInputSubImageDataType(inputIndex); } 00721 inline ML_DEPRECATED bool getInSubImageIsReadOnly(int inputIndex) const { return getInputSubImageIsReadOnly(inputIndex); } 00722 00724 00725 #endif // ML_DEPRECATED 00726 00727 }; 00728 00729 #ifdef ML_DEPRECATED 00730 00731 00732 00733 00734 ML_DEPRECATED typedef PagedImage PagedImg; 00736 #endif // ML_DEPRECATED 00737 00738 00739 ML_END_NAMESPACE 00740 00741 // Stream output for std::ostream 00742 namespace std { 00743 00745 MLEXPORT std::ostream& operator<<(std::ostream& s, const ML_NAMESPACE::PagedImage &pi); 00746 00747 } 00748 00749 #endif //of __mlPagedImage_H 00750 00751