13#ifndef ML_PAGED_IMAGE_H
14#define ML_PAGED_IMAGE_H
46#include <unordered_map>
79 NO_THREAD_SUPPORT = 0,
82 USE_MODULE_THREAD_SUPPORT = -1
143 inline bool isValid()
const {
return _isValid; }
562 MLEXPORT bool arePropertiesLocked()
const {
return _propertiesLocked; }
568 inline bool _checkPropertyWriteAccess(
const char*
methodName) {
569 if (_propertiesLocked) {
570 _showInvalidPropertyWriteAccessError(
methodName);
572 return !_propertiesLocked;
576 void _showInvalidPropertyWriteAccessError(
const char*
methodName);
578 PagedImage(
const PagedImage&) =
delete;
579 PagedImage&
operator=(
const PagedImage&) =
delete;
594 void _allocatePageList();
598 void static deleteMemoryBlockCallback(
void* data,
size_t size,
void* userData);
622 CalculateOutputImageHandler* _calculateOutputImageHandler;
627 void* _calculateOutputImagePropertiesUserData;
630 bool _isExternalCalculateOutputImageHandler;
650 std::vector<PageEntry> _pageList;
653 std::unordered_map<MLint, ExtendedPageEntry*> _pageEntryMap;
656 mutable Mutex _pageAccessMutex;
659 bool _pageHandlesAreStoredInList;
672 bool _updateOfImagePropertiesNeeded;
680 bool _propertiesLocked;
684 bool _clampPagesToImageExtent;
688 MemoryImage _memoryImg;
691 std::string _stateInfoString;
700 std::vector<InputSubImageProperties> _inSubImageProps;
703 ThreadSupport _threadSupport;
717 static MLuint32 _pageCountLimitToUsePageEntryMap;
721 static const char*
const _pageAllocationMemoryProfileKey;
722 static const char*
const _pageCacheHitsCountProfileKey;
723 static const char*
const _pageCacheMissesCountProfileKey;
The strong handle of a MLMemoryBlock.
The weak handle of a MLMemoryBlock.
Base class for the calculation of pages of an output image (PagedImage) of a Module.
The Host is the central image processing class in the ML.
MLEXPORT void setImageExtent(const ImageVector &extent)
Sets the extent of the (sub)image.
This class encapsulates basic medical image properties:
MedicalImageProperties & operator=(const MedicalImageProperties &medicalImageProperties)
Assignment operator from an existing edicalImageProperties object to get a copy.
A memory cache for the complete output image of an output connector.
Base class for an image processing module of the ML.
Class which represents an image, which manages properties of an image and image data which is located...
MLint getInPlaceIndex() const
Return optimization flag: Return index of input image whose input tile is used also as output page in...
MLEXPORT void setInputSubImageDataType(int inputIndex, MLDataType dataType)
Sets the dataType for the given inputIndex.
MLEXPORT PagedImage(Module *module=nullptr, MLint outputIndex=-1)
Constructor.
MLEXPORT void setMaxVoxelValue(MLdouble maxval)
Sets assumed maximum value to maxval. Overriden 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)
Sets the state information for this PagedImage to the string info and the 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)
See Host::getTile( module, outputIndex, location, dataType, data, scaleShiftData).
MLEXPORT void clearPageList()
Remove all pages of the page image and from the ML cache, and all page data chunks are freed,...
bool isValid() const
Returns whether image properties are valid and up-to-date.
MLEXPORT MLdouble getInterpolatedValue(const Vector3 &pos, MLint c=0, MLint t=0, MLint u=0, MLdouble outsideFillValue=0)
Get trilinear interpolated image value at given voxel position (center of a voxel is 0....
MLEXPORT SubImageBox getPageBox(MLint pageID) const
Returns the rectangular region in the entire image covered by the page with the id pageID.
ImageVector getPageExtent() const
Returns the extent of a page.
MLEXPORT const InputSubImageProperties & getInputSubImageProperties(int inputIndex) const
Returns a const reference to the InputSubImageProperties of the given input image at inputIndex.
MLEXPORT MLMemoryBlockHandle getPage(MLint pageID) const
Returns the pointer to the CachedBuffer containing the data of the page with the id pageID.
void setInvalid()
Sets image properties invalid, i.e., isValid() returns false afterwards.
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 assumed minimum value to minval. Overriden to perform access check.
MLEXPORT MLDataType getInputSubImageDataType(int inputIndex) const
Returns the input sub image data type for the input image at inputIndex.
MLEXPORT ThreadSupport getThreadSupport() const
Returns the current thread support of the paged image.
virtual MLEXPORT void setStateInfoErrorCode(MLErrorCode errorCode)
Sets the state information as MLErrorCode errorCode for this instance.
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)
Sets image properties to valid/up-to-date, i.e., isValid() returns true afterwards.
MLEXPORT void setUpdateOfImagePropertiesNeeded(bool flag)
Sets if the update of the image properties is needed, because the ML graph has changed since the last...
MLEXPORT void setExternalCalculateOutputImageHandler(CalculateOutputImageHandler *handler)
Sets the pointer to the output image calculation interface handler, the ownership is NOT passed to th...
ImageVector getPageStride() const
Returns the stride to get from one page to another.
MLEXPORT void removePage(MLint pageID)
This method removes a page with id pageID from this instance.
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 (which changes whenever the image changes and which is unique accross al...
MLEXPORT void copyPages(const std::vector< MLint > &pageIDs, SubImage *subImage, const ScaleShiftData &scaleShiftData=ScaleShiftData()) const
Fills the subImage with contents of the Pages with the IDs pagesIDs The grey values become according ...
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 which contains the image voxel position voxelPosition.
MLEXPORT void setInputSubImageIsReadOnly(int inputIndex, bool readOnly)
Sets that the input sub image for the input image at inputIndex to readOnly.
MLEXPORT void setInputSubImageUseMemoryImage(int inputIndex, bool useMemoryImage)
Sets that the input sub image for the input image at inputIndex should use a memory image (this impli...
MLEXPORT void setInputSubImageScaleShift(int inputIndex, const ScaleShiftData &scaleShift)
Sets that the input sub image for the input image at inputIndex should be rescaled with the given sca...
MLEXPORT void setThreadSupport(ThreadSupport support)
Sets the thread support of the paged image to the given value.
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
Gets if the update of the image properties is needed, because the ML graph has changed since the last...
void setBypassIndex(MLint index)
Sets the index of the input image whose pages should be used instead of the pages of this image.
CalculateOutputImageHandler * getCalculateOutputImageHandler() const
Returns the pointer to the output image calculation interface.
virtual MLEXPORT void setImageProperties(const PagedImage &imageProperties)
Function to copy all associated characteristics from imageProperties.
MLint getBypassIndex() const
Returns the index of the input image whose pages should be used instead of the pages of this image or...
MLEXPORT ~PagedImage() override
Destructor.
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)
Sets the extents of the image to the extent (x,y,z,c,t,u) and clears the list of valid pages and its ...
virtual MLEXPORT const std::string & getStateInfoString() const
Returns the current state information string which might explain something about the state of this in...
static MLEXPORT void getPageIDs(std::vector< MLint > &pageIDs, const SubImageBox &subImageBox, const ImageVector &imageExtent, const ImageVector &pageExtent)
Clears pageIDs and inserts the ids of all pages which need to be calculated to cover subImageBox comp...
void updateID()
Sets that the image has changed.
MLEXPORT bool getInputSubImageIsReadOnly(int inputIndex) const
Returns if input sub image at inputIndex is set to 'read-only'.
MLEXPORT void deletePageEntryFromDeletionCallback(ExtendedPageEntry *entry)
This method removes a page referenced by the page 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 if 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 multi-threading support of the paged image.
MLEXPORT MLErrorCode getTile(SubImage &subImage, const ScaleShiftData &scaleShiftData=ScaleShiftData(), MLRequestProgressCB *progressCallback=nullptr, void *progressCallbackUserData=nullptr)
See Host::getTile( module, outputIndex, subImg, scaleShiftData).
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
Clears pageIDs and inserts the ids of all pages which need to be calculated to cover subImageBox comp...
MLEXPORT MLMemoryBlockHandle getPageOrCreatePageRequestOrAddToPendingRequest(MLint &pageID, TileRequest *tileRequest, PageRequest **newPageRequest)
Returns the valid page handle if it exists.
void setClampPagesToImageExtent(bool flag=true)
If enabled, the pages are clamped to the image extent, so that pages on the border of the image will ...
MLEXPORT MLint getNumPages() const
Returns the total number of pages in this output image (regardless if they are allocated or not).
void setPageExtent(MLint x, MLint y, MLint z=1, MLint c=1, MLint t=1, MLint u=1)
Sets the extents of the pages to the extent (x,y,z,c,t,u).
MLEXPORT void calculateImageProperties()
Updates the image properties via the Module::calculateOutputImageProperties or via CalculateOutputIma...
ML_FRIEND_TEST(TypedHandlersTest, SetupAndVerifyProperties)
virtual MLEXPORT MLErrorCode getStateInfoErrorCode() const
Returns the current state information as MLError code which might explain something about the state o...
MLEXPORT MLErrorCode updateImageProperties()
Updates the image properties of the PagedImage using the Host::updateImageProperties method.
void setInPlaceIndex(MLint inputIndex)
Set optimization flag: If calculating a page in calculateOutputSubImage() the output image page shall...
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 type of data to dataType. Overriden to perform access check.
MLEXPORT void clearPageListAndMemoryImage()
Remove all pages of the page image and from the ML cache, and all page data chunks are freed.
MLEXPORT void freeTile(void *data)
Same as corresponding Host::freeTile(void *data).
MLEXPORT std::size_t getCachedPagesSizeInBytes() const
Returns currently used cache size for pages in bytes.
MLEXPORT void validateInputSubImagePropertiesAfterCalculateOutputImageProperties()
Validates the properties and set datatype where it was not set, should only be called by the Host!
MemoryImage & getMemoryImage()
Permits the access to a memory cached output of the paged image.
void setImageExtent(const SubImageBox &box)
Sets the extents of the image to box.getExtent() and updates all PagedImage settings.
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)
Sets the read-only flag for all input images (see setInputSubImageIsReadOnly() for details)
This class manages/represents a rectangular 6d image region which is organized linearly in memory.
VectorType getExtent() const
Returns the extents of the subimage region.
A TileRequest either represents the input sub image that is needed by a PageRequest or if it is a roo...
MLint32 MLDataType
MLDataType.
MLint32 MLErrorCode
Type of an ML Error code.
boost::mutex Mutex
Defines a non-recursive mutex.
#define MLEXPORT
To export symbols from a dll/shared object, we need to mark them with the MLEXPORT symbol.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
void MLRequestProgressCB(void *usrData, double progress)
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
std::ostream & operator<<(std::ostream &out, const ml::Variant &variant)
void CalculateOutputImagePropertiesCB(void *userData, PagedImage *outImage)
Callback for the calculation of the output image properties for outputImage.
TScaleShiftData< MLdouble > ScaleShiftData
Double version of TScaleShiftData for maximum reasonable precision.
TImageVector< MLint > ImageVector
Defines the standard ImageVector type which is used by the ML for indexing and coordinates.