13#ifndef ML_PAGED_IMAGE_H
14#define ML_PAGED_IMAGE_H
46#include <unordered_map>
52class PagedImageCurrentlyUsedMemoryTracker;
74 struct ExtendedPageEntry;
143 inline bool isValid()
const {
return _isValid; }
147 inline void setValid(
bool flag =
true) { _isValid=flag; }
513 void* progressCallbackUserData =
nullptr);
522 void* progressCallbackUserData =
nullptr);
560 MLEXPORT bool arePropertiesLocked()
const {
return _propertiesLocked; }
563 MLEXPORT bool setPropertiesLocked(
bool locked);
566 inline bool _checkPropertyWriteAccess(
const char* methodName) {
567 if (_propertiesLocked) {
568 _showInvalidPropertyWriteAccessError(methodName);
570 return !_propertiesLocked;
574 void _showInvalidPropertyWriteAccessError(
const char* methodName);
576 PagedImage(
const PagedImage&) =
delete;
577 PagedImage&
operator=(
const PagedImage&) =
delete;
592 void _allocatePageList();
596 void static deleteMemoryBlockCallback(
void* data,
size_t size,
void* userData);
601 static bool registerDeletionCallback(
const ExtendedPageEntry* entry);
606 static bool deregisterDeletionCallback(
const ExtendedPageEntry* entry);
608 static ExtendedPageEntry* deletePageEntryFromMapUnsafe(std::unordered_map<MLint, ExtendedPageEntry *> &pageEntryMap,
620 CalculateOutputImageHandler* _calculateOutputImageHandler;
625 void* _calculateOutputImagePropertiesUserData;
628 bool _isExternalCalculateOutputImageHandler;
647 std::vector<PageEntry> _pageList;
650 std::unordered_map<MLint, ExtendedPageEntry*> _pageEntryMap;
653 mutable Mutex _pageAccessMutex;
656 bool _pageHandlesAreStoredInList;
669 bool _updateOfImagePropertiesNeeded;
677 bool _propertiesLocked;
681 bool _clampPagesToImageExtent;
685 MemoryImage _memoryImg;
688 std::string _stateInfoString;
697 std::vector<InputSubImageProperties> _inSubImageProps;
700 ThreadSupport _threadSupport;
704 mutable PagedImageCurrentlyUsedMemoryTracker* _currentlyUsedPageMemoryTracker;
707 mutable MLMetaProfilePtr _metaProfilePtr;
714 static MLuint32 _pageCountLimitToUsePageEntryMap;
718 static const char*
const _pageAllocationMemoryProfileKey;
719 static const char*
const _pageCacheHitsCountProfileKey;
720 static const char*
const _pageCacheMissesCountProfileKey;
MLEXPORT void setImageExtent(const ImageVector &extent)
Sets the extent of the (sub)image.
MedicalImageProperties & operator=(const MedicalImageProperties &medicalImageProperties)
MLint getInPlaceIndex() const
MLEXPORT void setInputSubImageDataType(int inputIndex, MLDataType dataType)
MLEXPORT PagedImage(Module *module=nullptr, MLint outputIndex=-1)
MLEXPORT void setMaxVoxelValue(MLdouble maxval)
Sets the assumed maximum value to maxval. Overridden to perform access check.
MLEXPORT void clearPendingPageRequest(MLint pageID)
Clears a pending page request for the given page ID.
virtual MLEXPORT void setStateInfo(const std::string &info, MLErrorCode errorCode)
Module * getModule() const
Returns the associated Module instance if passed to the constructor, NULL otherwise.
MLEXPORT MLErrorCode getTile(SubImageBox location, MLDataType dataType, void **data, const ScaleShiftData &scaleShiftData=ScaleShiftData(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
MLEXPORT void clearPageList()
MLEXPORT MLdouble getInterpolatedValue(const Vector3 &pos, MLint c=0, MLint t=0, MLint u=0, MLdouble outsideFillValue=0)
MLEXPORT SubImageBox getPageBox(MLint pageID) const
ImageVector getPageExtent() const
Returns the extent of a page.
MLEXPORT const InputSubImageProperties & getInputSubImageProperties(int inputIndex) const
MLEXPORT MLMemoryBlockHandle getPage(MLint pageID) const
MLEXPORT const PagedImage * getInputImage(int inputIndex) const
Returns the input image at inputIndex of the associated Module.
MLEXPORT void setPageExtent(const ImageVector &pageExtent)
Sets the extents of the pages to pageExtent.
MLEXPORT void setMinVoxelValue(MLdouble minval)
Sets the assumed minimum value to minval. Overridden to perform access check.
MLEXPORT MLDataType getInputSubImageDataType(int inputIndex) const
Returns the input subimage data type for the input image at inputIndex.
MLEXPORT ThreadSupport getThreadSupport() const
virtual MLEXPORT void setStateInfoErrorCode(MLErrorCode errorCode)
MLEXPORT void setCalculateOutputImagePropertiesCB(CalculateOutputImagePropertiesCB *callback, void *userData)
Sets the callback and userdata for the calculation of the properties of this PagedImage if they need ...
void setValid(bool flag=true)
MLEXPORT void setUpdateOfImagePropertiesNeeded(bool flag)
MLEXPORT void setExternalCalculateOutputImageHandler(CalculateOutputImageHandler *handler)
ImageVector getPageStride() const
Returns the stride to get from one page to another.
MLEXPORT void removePage(MLint pageID)
static MLEXPORT void setPageCountLimitToUsePageEntryMap(MLuint32 limit)
Sets the limit of number of pages for using the page entry map instead of the page list.
MLuint32 getID()
Returns the current image ID that changes whenever the image changes and that is unique accross all i...
MLEXPORT void copyPages(const std::vector< MLint > &pageIDs, SubImage *subImage, const ScaleShiftData &scaleShiftData=ScaleShiftData()) const
MLint getOutputIndex() const
Returns associated output index of Module instance if passed to constructor, -1 otherwise.
const MemoryImage & getMemoryImage() const
MLint getPageID(const ImageVector &voxelPosition) const
Returns the ID of that page that contains the image voxel position voxelPosition.
MLEXPORT void setInputSubImageIsReadOnly(int inputIndex, bool readOnly)
MLEXPORT void setInputSubImageUseMemoryImage(int inputIndex, bool useMemoryImage)
MLEXPORT void setInputSubImageScaleShift(int inputIndex, const ScaleShiftData &scaleShift)
MLEXPORT void setThreadSupport(ThreadSupport support)
bool getClampPagesToImageExtent() const
See setClampPagesToImageExtent().
ML_FRIEND_TEST(PagedImageDeprecationTest, NewAPI)
MLEXPORT void setPage(MLint pageID, const MLMemoryBlockHandle &page)
Sets the given page handle as pagedata at pageID.
MLEXPORT bool updateOfImagePropertiesNeeded() const
void setBypassIndex(MLint index)
CalculateOutputImageHandler * getCalculateOutputImageHandler() const
Returns the pointer to the output image calculation interface.
virtual MLEXPORT void setImageProperties(const PagedImage &imageProperties)
MLint getBypassIndex() const
MLEXPORT ~PagedImage() override
friend class Host
The host may access some methods that are otherwise unavailable.
ImageVector getPageSetExtent() const
Returns the extents of the page set covering the entire image extents.
void setImageExtent(MLint x, MLint y, MLint z=1, MLint c=1, MLint t=1, MLint u=1)
virtual MLEXPORT const std::string & getStateInfoString() const
static MLEXPORT void getPageIDs(std::vector< MLint > &pageIDs, const SubImageBox &subImageBox, const ImageVector &imageExtent, const ImageVector &pageExtent)
void updateID()
Sets that the image has changed.
MLEXPORT bool getInputSubImageIsReadOnly(int inputIndex) const
Returns whether the input subimage at inputIndex is set to 'read-only'.
MLEXPORT void deletePageEntryFromDeletionCallback(ExtendedPageEntry *entry)
MLEXPORT MLMetaProfilePtr & getMetaProfile() const
Returns the MLMetaProfile for this paged image. Creates it if necessary.
MLEXPORT PagedImage & getBypassSourceImage()
Returns the reference to the source image of a bypass chain.
bool hasExternalCalculateOutputImageHandler() const
Returns whether the CalculateOutputImageHandler is an external handler and should not be overwritten.
MLEXPORT void setCalculateOutputImageHandler(CalculateOutputImageHandler *handler)
Sets the pointer to the output image calculation interface handler; the ownership is passed to the Pa...
ThreadSupport
Defines the multithreading support of the paged image.
@ 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.
@ USE_MODULE_THREAD_SUPPORT
< Use the overall thread support flag of the module.
@ NO_THREAD_SUPPORT
< The image can only be calculated from the main thread.
MLEXPORT MLErrorCode getTile(SubImage &subImage, const ScaleShiftData &scaleShiftData=ScaleShiftData(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
static MLEXPORT MLuint32 getPageCountLimitToUsePageEntryMap()
Returns the limit of number of pages for using the page entry map instead of the page list.
ML_FRIEND_TEST(PagedImageDeprecationTest, DeprecatedAPI)
MLEXPORT void getPageIDs(std::vector< MLint > &pageIDs, const SubImageBox &subImageBox) const
MLEXPORT MLMemoryBlockHandle getPageOrCreatePageRequestOrAddToPendingRequest(MLint &pageID, TileRequest *tileRequest, PageRequest **newPageRequest)
void setClampPagesToImageExtent(bool flag=true)
MLEXPORT MLint getNumPages() const
void setPageExtent(MLint x, MLint y, MLint z=1, MLint c=1, MLint t=1, MLint u=1)
MLEXPORT void calculateImageProperties()
Updates the image properties via the Module::calculateOutputImageProperties or via CalculateOutputIma...
ML_FRIEND_TEST(TypedHandlersTest, SetupAndVerifyProperties)
virtual MLEXPORT MLErrorCode getStateInfoErrorCode() const
MLEXPORT MLErrorCode updateImageProperties()
Updates the image properties of the PagedImage using the Host::updateImageProperties method.
void setInPlaceIndex(MLint inputIndex)
MLEXPORT void initializeInputSubImageProperties(MLint numInputs)
Initializes the InSubImageProps for a given number of inputs; should only be called by the Host!
MLEXPORT void setDataType(MLDataType dataType) override
Sets the type of data to dataType. Overridden to perform access check.
MLEXPORT void clearPageListAndMemoryImage()
MLEXPORT void freeTile(void *data)
Same as corresponding Host::freeTile(void *data).
MLEXPORT std::size_t getCachedPagesSizeInBytes() const
Returns the currently used cache size for pages in bytes.
MLEXPORT void validateInputSubImagePropertiesAfterCalculateOutputImageProperties()
Validates the properties and sets the data type where it was not set; should only be called by the Ho...
MemoryImage & getMemoryImage()
void setImageExtent(const SubImageBox &box)
virtual MLEXPORT void setImageExtent(const ImageVector &extent)
Sets the extents of the image to extent. The list of valid pages and its content are cleared.
MLEXPORT void setInputSubImagesAreReadOnly(bool readOnly=true)
VectorType getExtent() const
MLint32 MLErrorCode
Type of an ML Error code.
#define MLEXPORT
Code it as import symbol if compiled elsewhere.
void MLRequestProgressCB(void *usrData, double progress)
void CalculateOutputImagePropertiesCB(void *userData, PagedImage *outImage)
Callback for the calculation of the output image properties for outputImage.
Tvec3< MLdouble > Vector3
A vector with three components of type double.
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.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator '<<' for stream output of Field objects.