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 #include "mlSystemWarningsDisable.h" 00048 #include <boost/unordered_map.hpp> 00049 #include "mlSystemWarningsRestore.h" 00050 00051 ML_START_NAMESPACE 00052 00054 class PagedImageCurrentlyUsedMemoryTracker; 00055 class Module; 00056 class SubImage; 00057 class PageRequest; 00058 class TileRequest; 00059 struct PagedImagePageEntry; 00060 struct PagedImageExtendedPageEntry; 00061 #ifdef ML_DEPRECATED 00062 class BaseOp; 00063 #endif 00064 00065 00066 00067 //------------------------------------------------------------------------------ 00071 //------------------------------------------------------------------------------ 00072 class ML_UNIX_ONLY_EXPORT(MLEXPORT) PagedImage: public MedicalImageProperties 00073 { 00074 00075 public: 00077 enum ThreadSupport { 00078 NO_THREAD_SUPPORT = 0, 00079 MULTITHREADED = 1, 00080 IO_THREAD = 4, 00081 USE_MODULE_THREAD_SUPPORT = -1 00082 }; 00083 00085 friend class Host; 00086 // needed for testing protected API: 00087 ML_FRIEND_TEST(PagedImageDeprecationTest, NewAPI); 00088 ML_FRIEND_TEST(PagedImageDeprecationTest, DeprecatedAPI); 00089 00090 //------------------------------------------------------ 00092 00093 //------------------------------------------------------ 00094 00102 MLEXPORT PagedImage(Module* module=NULL, MLint outputIndex=-1); 00103 00106 MLEXPORT virtual ~PagedImage(); 00108 00110 inline CalculateOutputImageHandler* getCalculateOutputImageHandler() const { return _calculateOutputImageHandler; } 00111 00114 MLEXPORT void setExternalCalculateOutputImageHandler(CalculateOutputImageHandler* handler); 00115 00117 inline bool hasExternalCalculateOutputImageHandler() const { return _isExternalCalculateOutputImageHandler; } 00118 00120 MLEXPORT void setCalculateOutputImageHandler(CalculateOutputImageHandler* handler); 00121 00123 MLEXPORT void setCalculateOutputImagePropertiesCB(CalculateOutputImagePropertiesCB* callback, void* userData); 00124 00126 inline MLuint32 getID() { return _id; } 00127 00129 inline void updateID() { _id = getUniqueId(); } 00130 00131 //------------------------------------------------------------------- 00133 00134 //------------------------------------------------------------------- 00140 inline bool isValid() const { return _isValid; } 00141 00144 inline void setValid(bool flag = true) { _isValid=flag; } 00145 00148 inline void setInvalid() { _isValid=false; } 00149 00152 MLEXPORT void setUpdateOfImagePropertiesNeeded(bool flag); 00153 00156 MLEXPORT bool updateOfImagePropertiesNeeded() const { return _updateOfImagePropertiesNeeded; } 00157 00159 MLEXPORT MLErrorCode updateImageProperties() ML_RETURN_VALUE_SHOULD_BE_USED; 00160 00162 00163 //------------------------------------------------------ 00165 00166 //------------------------------------------------------ 00167 00169 MLEXPORT virtual void setImageExtent(const ImageVector& extent); 00170 00174 inline void setImageExtent(MLint x, MLint y, MLint z = 1, MLint c = 1, MLint t = 1, MLint u = 1) { 00175 setImageExtent(ImageVector(x,y,z,c,t,u)); 00176 } 00177 00181 inline void setImageExtent(const SubImageBox &box) { setImageExtent(box.getExtent()); } 00182 00187 MLEXPORT virtual void setImageProperties(const PagedImage& imageProperties); 00188 00190 MLEXPORT void setPageExtent(const ImageVector& pageExtent); 00191 00194 inline void setPageExtent(MLint x, MLint y, MLint z = 1, MLint c = 1, MLint t = 1, MLint u = 1) { 00195 setPageExtent(ImageVector(x,y,z,c,t,u)); 00196 } 00197 00199 MLEXPORT void setPage(MLint pageID, const MLMemoryBlockHandle& page); 00200 00203 MLEXPORT void removePage(MLint pageID); 00204 00208 MLEXPORT void deletePageEntryFromDeletionCallback(PagedImageExtendedPageEntry* entry); 00209 00213 MLEXPORT void clearPageList(); 00214 00219 MLEXPORT void clearPageListAndMemoryImage(); 00221 00222 00223 00224 //------------------------------------------------------ 00226 00227 //------------------------------------------------------ 00234 MLEXPORT virtual void setStateInfo(const std::string& info, MLErrorCode errorCode); 00235 00242 MLEXPORT virtual void setStateInfoErrorCode(MLErrorCode errorCode); 00243 00246 MLEXPORT virtual const std::string& getStateInfoString() const; 00247 00250 MLEXPORT virtual MLErrorCode getStateInfoErrorCode() const; 00252 00253 //--------------------------------------------------------------------------- 00255 00256 //--------------------------------------------------------------------------- 00257 00263 inline void setBypassIndex(MLint index) { _bypassIndex = index; } 00264 00267 inline MLint getBypassIndex() const { return _bypassIndex; } 00269 00270 00271 //------------------------------------------------------ 00273 00274 //------------------------------------------------------ 00275 00277 inline Module* getModule() const { return _module; } 00278 00280 MLEXPORT const PagedImage* getInputImage(int inputIndex) const; 00281 00283 inline MLint getOutputIndex() const { return _outIndex; } 00284 00286 inline ImageVector getPageSetExtent() const { return _pageSetExt; } 00287 00289 inline ImageVector getPageStride() const { return _pageStride; } 00290 00292 inline ImageVector getPageExtent() const { return _pageExt; } 00293 00295 inline MLint getPageID(const ImageVector& voxelPosition) const { return (voxelPosition/_pageExt).dot(_pageStride); } 00296 00301 00302 inline MemoryImage& getMemoryImage() { return _memoryImg; } 00303 inline const MemoryImage& getMemoryImage() const { return _memoryImg; } 00305 00310 MLEXPORT void setThreadSupport(ThreadSupport support) { _threadSupport = support; } 00311 00315 MLEXPORT ThreadSupport getThreadSupport() const; 00316 00319 MLEXPORT MLMemoryBlockHandle getPage(MLint pageID) const; 00320 00325 MLEXPORT MLMemoryBlockHandle getPageOrCreatePageRequestOrAddToPendingRequest(MLint pageID, TileRequest* tileRequest, PageRequest** newPageRequest); 00326 00328 MLEXPORT void clearPendingPageRequest(MLint pageID); 00329 00331 MLEXPORT PagedImage& getBypassSourceImage(); 00332 00335 MLEXPORT SubImageBox getPageBox(MLint pageID) const; 00336 00339 MLEXPORT void getPageIDs(std::vector <MLint>& pageIDs, const SubImageBox& subImageBox) const; 00340 00344 MLEXPORT static void getPageIDs(std::vector<MLint>& pageIDs, 00345 const SubImageBox& subImageBox, 00346 const ImageVector& imageExtent, 00347 const ImageVector& pageExtent); 00348 00350 MLEXPORT size_t getCachedPagesSizeInBytes() const; 00351 00354 MLEXPORT MLint getNumPages() const { return _pageSetSize; } 00355 00357 00358 00359 //--------------------------------------------------------------------------- 00361 00362 //--------------------------------------------------------------------------- 00363 00372 inline void setInPlaceIndex(MLint inputIndex) { _inPlaceIndex = inputIndex; } 00373 00381 inline MLint getInPlaceIndex() const { return _inPlaceIndex; } 00383 00384 00385 //------------------------------------------------------ 00387 00388 00389 00390 00391 00392 00393 //------------------------------------------------------ 00394 00400 MLEXPORT void setInputSubImageDataType(int inputIndex, MLDataType dataType); 00401 00409 MLEXPORT void setInputSubImageIsReadOnly(int inputIndex, bool readOnly); 00410 00413 MLEXPORT void setInputSubImagesAreReadOnly(bool readOnly = true); 00414 00430 MLEXPORT void setInputSubImageUseMemoryImage(int inputIndex, bool useMemoryImage); 00431 00435 MLEXPORT void setInputSubImageScaleShift(int inputIndex, const ScaleShiftData& scaleShift); 00436 00439 inline const InputSubImageProperties& getInputSubImageProperties(int inputIndex) const { return _inSubImageProps[mlrange_cast<size_t>(inputIndex)]; } 00440 00442 MLEXPORT MLDataType getInputSubImageDataType(int inputIndex) const; 00443 00445 MLEXPORT bool getInputSubImageIsReadOnly(int inputIndex) const; 00446 00448 00449 //------------------------------------------------------ 00451 00452 //------------------------------------------------------ 00453 00454 //--------------------------------------------------------------------------------- 00465 //--------------------------------------------------------------------------------- 00466 MLEXPORT void copyPages(const std::vector<MLint>& pageIDs, 00467 SubImage* subImage, 00468 const ScaleShiftData& scaleShiftData=ScaleShiftData()) const; 00470 00471 00472 //------------------------------------------------------------------- 00474 00475 //------------------------------------------------------------------- 00480 MLEXPORT MLErrorCode getTile(SubImageBox location, 00481 MLDataType dataType, 00482 void** data, 00483 const ScaleShiftData& scaleShiftData=ScaleShiftData()) ML_RETURN_VALUE_SHOULD_BE_USED; 00484 00489 MLEXPORT MLErrorCode getTile(SubImage& subImage, const ScaleShiftData& scaleShiftData=ScaleShiftData()) ML_RETURN_VALUE_SHOULD_BE_USED; 00490 00492 MLEXPORT void freeTile(void* data); 00494 00496 MLEXPORT MLMetaProfilePtr& getMetaProfile() const; 00497 00499 MLEXPORT static void setPageCountLimitToUsePageEntryMap(MLuint32 limit) { _pageCountLimitToUsePageEntryMap = limit; } 00500 00502 MLEXPORT static MLuint32 getPageCountLimitToUsePageEntryMap() { return _pageCountLimitToUsePageEntryMap; } 00503 00504 protected: 00506 MLEXPORT void calculateImageProperties(); 00507 00509 MLEXPORT void initializeInputSubImageProperties(MLint numInputs); 00510 00512 MLEXPORT void validateInputSubImagePropertiesAfterCalculateOutputImageProperties(); 00513 00514 private: 00516 static MLuint32 getUniqueId(); 00517 00518 //------------------------------------------------------ 00520 00521 //------------------------------------------------------ 00528 PagedImage(const PagedImage&); 00529 00532 PagedImage& operator=(const PagedImage&); 00534 00535 00536 //------------------------------------------------------ 00538 00539 //------------------------------------------------------ 00544 void _updateAll(); 00545 00547 void _deletePageList(); 00548 00550 void _allocatePageList(); 00552 00553 00554 //------------------------------------------------------ 00556 00557 //------------------------------------------------------ 00558 00560 Module* _module; 00561 00563 CalculateOutputImageHandler* _calculateOutputImageHandler; 00564 00566 CalculateOutputImagePropertiesCB* _calculateOutputImageProperties; 00568 void* _calculateOutputImagePropertiesUserData; 00569 00571 bool _isExternalCalculateOutputImageHandler; 00572 00575 MLint _outIndex; 00576 00578 ImageVector _pageExt; 00579 00582 ImageVector _pageStride; 00583 00585 ImageVector _pageSetExt; 00586 00588 MLint _pageSetSize; 00589 00591 PagedImagePageEntry* _pageList; 00592 00594 boost::unordered_map<MLint, PagedImageExtendedPageEntry*> _pageEntryMap; 00595 00597 mutable Mutex _pageAccessMutex; 00598 00600 bool _pageHandlesAreStoredInList; 00601 00607 MLint _inPlaceIndex; 00608 00610 MLint _bypassIndex; 00611 00613 bool _updateOfImagePropertiesNeeded; 00614 00616 bool _isValid; 00617 00620 MemoryImage _memoryImg; 00621 00623 std::string _stateInfoString; 00624 00626 MLErrorCode _stateInfoErrorCode; 00627 00629 MLuint32 _id; 00630 00632 std::vector<InputSubImageProperties> _inSubImageProps; 00633 00635 ThreadSupport _threadSupport; 00636 00639 mutable PagedImageCurrentlyUsedMemoryTracker* _currentlyUsedPageMemoryTracker; 00640 00642 mutable MLMetaProfilePtr _metaProfilePtr; 00644 00646 static MLuint32 _staticUniqueId; 00647 00649 static MLuint32 _pageCountLimitToUsePageEntryMap; 00650 00651 #ifdef ML_DEPRECATED 00652 00654 00655 00656 public: 00658 static const char* const pageAllocationMemoryProfileKey; 00659 static const char* const pageCacheHitsCountProfileKey; 00660 static const char* const pageCacheMissesCountProfileKey; 00661 00662 00663 // \deprecated 00664 // Use getOutputIndex() instead. 00665 inline ML_DEPRECATED MLint getOutIndex() const { return getOutputIndex(); } 00666 00667 // \deprecated 00668 // Use isValid() instead. 00669 inline ML_DEPRECATED bool isUpToDate() const { return isValid(); } 00670 00671 // \deprecated 00672 // Use setValid() instead. 00673 inline ML_DEPRECATED void setUpToDate() { setValid(); } 00674 00675 // \deprecated 00676 // Use setInvalid() instead. 00677 inline ML_DEPRECATED void setOutOfDate() { setInvalid(); } 00678 00682 MLEXPORT bool isGlobalDummyImage(); 00683 00686 inline ML_DEPRECATED void setImgExt(const ImageVector &ext) { setImageExtent(ext); } 00689 inline ML_DEPRECATED void setImgExt(const SubImageBox &box) { setImageExtent(box); } 00692 inline ML_DEPRECATED void clearPageListAndMemoryImg() { clearPageListAndMemoryImage(); } 00695 MLEXPORT ML_DEPRECATED BaseOp* getBaseOp() const; 00698 inline ML_DEPRECATED void setImgProps(const PagedImage &imgProps) { setImageProperties(imgProps); } 00701 inline ML_DEPRECATED void setPageExt(const ImageVector &pageExt) { setPageExtent(pageExt); } 00704 inline ML_DEPRECATED const PagedImage* getInImg(int index) const { return getInputImage(index); } 00707 inline ML_DEPRECATED ImageVector getPageSetExt() const { return getPageSetExtent(); } 00710 inline ML_DEPRECATED ImageVector getPageExt() const { return getPageExtent(); } 00713 inline ML_DEPRECATED MemoryImage& getMemoryImg() { return getMemoryImage(); } 00716 inline ML_DEPRECATED const MemoryImage& getMemoryImg() const { return getMemoryImage(); } 00719 inline ML_DEPRECATED size_t getPageMemorySize() const { return getCachedPagesSizeInBytes(); } 00722 inline ML_DEPRECATED void setInSubImageDataType(int inputIndex, MLDataType datatype) { setInputSubImageDataType(inputIndex,datatype); } 00725 inline ML_DEPRECATED void setInSubImageIsReadOnly(int inputIndex, bool readOnly) { setInputSubImageIsReadOnly(inputIndex, readOnly); } 00728 inline ML_DEPRECATED void setInSubImageUseMemoryImage(int inputIndex, bool useMemImg) { setInputSubImageUseMemoryImage(inputIndex, useMemImg); } 00731 inline ML_DEPRECATED void setInSubImageScaleShift(int inputIndex, const ScaleShiftData& scaleShift) { setInputSubImageScaleShift(inputIndex, scaleShift); } 00734 inline ML_DEPRECATED const InputSubImageProperties& getInSubImageProps(int inputIndex) const { return getInputSubImageProperties(inputIndex); } 00737 inline ML_DEPRECATED MLDataType getInSubImageDataType(int inputIndex) const { return getInputSubImageDataType(inputIndex); } 00740 inline ML_DEPRECATED bool getInSubImageIsReadOnly(int inputIndex) const { return getInputSubImageIsReadOnly(inputIndex); } 00742 00743 #endif // ML_DEPRECATED 00744 00745 }; 00746 00747 #ifdef ML_DEPRECATED 00748 00749 00750 00751 00752 ML_DEPRECATED typedef PagedImage PagedImg; 00754 #endif // ML_DEPRECATED 00755 00756 00757 ML_END_NAMESPACE 00758 00759 // Stream output for std::ostream 00760 namespace std { 00761 00763 MLEXPORT std::ostream& operator<<(std::ostream& s, const ML_NAMESPACE::PagedImage &pi); 00764 00765 } 00766 00767 #endif //of __mlPagedImage_H 00768 00769