MeVisLab Toolbox Reference
ml::ManagedSubImage Class Reference

ManagedSubImage is derived from SubImage and frees its allocated memory automatically when it is destructed. More...

#include <mlManagedSubImage.h>

Inheritance diagram for ml::ManagedSubImage:
ml::SubImage

Public Member Functions

 ManagedSubImage ()
 Constructor. More...
 
ManagedSubImageoperator= (const SubImage &si)
 Copy operator from SubImage. More...
 
 ~ManagedSubImage () override
 Destruct the object, freeing the memory. More...
 
void * takeData ()
 Returns the data pointer and set the internal data to NULL (so it passes the ownership of the data to the caller) NOTE: This should only be used on images that where allocated via MLAlloc or with user provided memory. More...
 
- Public Member Functions inherited from ml::SubImage
const SubImageBoxgetBox () const
 Returns the box describing the origin/extent of the subimage. More...
 
void setSourceImageExtent (const ImageVector &extent)
 Sets the image extent of the source image that was used to create this SubImage to extent. More...
 
ImageVector getSourceImageExtent () const
 Returns the image extent of the source image that was used to create this SubImage. More...
 
SubImageBox getValidRegion () const
 Returns the valid region of the SubImage, which is defined by the intersection of the SubImage::getBox() and the SubImageBox(ImageVector(0), SubImage::getSourceImageExtent()-1). More...
 
MLint getNumVoxels () const
 Returns number of voxels in (sub)image. More...
 
MLint getSizeInBytes () const
 Returns number of potential bytes in (sub)image. More...
 
ImageVector getStride () const
 Returns a stride vector to address the memory efficiently. More...
 
MLint getOffset (const ImageVector &voxelPosition) const
 Returns the array index offset from the origin (0,0,0,0,0,0) to the voxelPosition. More...
 
void setDataType (MLDataType dataType)
 Overwrite inherited setDataType method to set type of data to dataType. More...
 
MLDataType getDataType () const
 Return type of image data. More...
 
const MLTypeInfosgetDataTypeInfos () const
 Get MLTypeInfos for image data type. More...
 
MLEXPORT ImageProperties toImageProperties () const
 Converts the Subimage's datatype and extend to an ImageProperties object. More...
 
MLEXPORT void setFromImageProperties (const ImageProperties &imageProperties)
 Sets the image box and datatype from the imageProperties extent and datatype. More...
 
void toStream (std::ostream &ostr) const
 
 SubImage ()
 Constructor: Creates a subimage with no data. More...
 
 SubImage (const SubImage &si)
 Copy constructor to get identical copy. More...
 
 SubImage (const SubImageBox &box, MLDataType datatype, void *data=nullptr)
 Constructor for a rectangular 6d image region with position and extent given by box, with data type datatype and memory given by the pointer data. More...
 
 SubImage (const SubImage &si, const ImageVector &offset)
 Copy constructor to get identical copy. More...
 
virtual ~SubImage ()=default
 Virtual destructor to suppress compiler warnings. More...
 
SubImageoperator= (const SubImage &si)
 Assignment operator to get identical copy. More...
 
void setBox (const SubImageBox &subImageBox)
 Sets a rectangular 6d region of the subimage to subImageBox. More...
 
void setBox (const ImageVector &imageExtent)
 Sets a rectangular 6d region of the subimage to imageExtent. More...
 
void translate (const ImageVector &offset)
 Translates the box of the subimage by adding the vector offset. More...
 
const ImageVectorgetOrigin () const
 Returns the origin of the subimage (which is identical to getBox().v1). More...
 
void setOrigin (const ImageVector &newOrigin)
 Sets the origin of the subimage (which moves the box of the subimage to newOrigin). More...
 
ImageVector getExtent () const
 Returns the extent of the subimage (which is identical to getBox().getExtent()). More...
 
void setExtent (MLint x, MLint y, MLint z=1, MLint c=1, MLint t=1, MLint u=1)
 Sets the extent of the subimage (which also changes the strides) to newExtent. More...
 
void setExtent (const ImageVector &newExtent)
 Sets the extent of the subimage (which also changes the strides) to newExtent. More...
 
SubImageBox getBoxFromExtent () const
 Returns size of image as box with origin 0. More...
 
SubImageBox getBoxFromImageExtent () const
 
ImageVector getImageExtent () const
 
void setImageExtent (const ImageVector &newExtent)
 
void * getSubImagePointer (const ImageVector &voxelPosition) const
 Returns pointer to voxel data of image voxel at 6d voxelPosition relative to the begin of the subimage region. More...
 
void * getSubImagePointer (MLint x, MLint y, MLint z) const
 Returns pointer to voxel data of image voxel at 3d position p=(x,y,z) relative to the begin of the subimage region. More...
 
void * getImagePointer (const ImageVector &voxelPosition) const
 Returns pointer to voxel data of image voxel at 6d position voxelPosition relative to the begin of the complete image region. More...
 
void * getImagePointer (MLint x, MLint y, MLint z) const
 Returns pointer to voxel data of image voxel at 3d position p=(x, y, z) relative to the begin of the complete image region. More...
 
MLEXPORT void copySubImage (const SubImage &fromImage, const ScaleShiftData &scaleShiftData)
 Copies image data from the subimage fromImage into the overlapping region of this subimage. More...
 
MLEXPORT void copySubImage (const SubImage &fromImage)
 Implements special case for void copySubImage(const TSubImage<FROM_DATATYPE> &typedFromImg, const ScaleShiftData& scaleShiftData) where scaleShiftData is default. More...
 
bool isValidSubImagePosition (const ImageVector &voxelPosition) const
 Returns true if 6d voxelPosition is a valid position within subimage region, i.e., if voxelPosition is within (0,0,0,0,0,0) and subimage extents. More...
 
bool isValidSubImagePosition (MLint x, MLint y, MLint z) const
 Returns true if 3d position p=(x, y, z) is a valid position within subimage region, i.e., if the position is within (0,0,0) and subimage extents. More...
 
bool isValidImagePosition (const ImageVector &voxelPosition) const
 Returns true if 6d voxelPosition is a valid position within subimage region, i.e., if voxelPosition is within subImgBox.v1 and subImgBox.v2. More...
 
bool isValidImagePosition (MLint x, MLint y, MLint z) const
 Returns true if 3d position p=(x, y, z) is a valid position within subimage region, i.e., if the position is within subImgBox.v1 and subImgBox.v2. More...
 
MLEXPORT void allocate (MLMemoryErrorHandling handleFailure)
 Allocate data with MLAlloc(). More...
 
MLEXPORT void allocateAsMemoryBlockHandle (MLMemoryErrorHandling handleFailure=ML_RETURN_NULL)
 Allocate data using the ML memory manager. For failure handing, see SubImage::allocate(). More...
 
MLEXPORT void free ()
 Frees data pointed to by getData() with MLFree(). More...
 
MLEXPORT bool isOneValued () const
 Returns true if all page voxels have the same value or if the page contains only 1 voxel. More...
 
MLEXPORT MLint calculateMinMax (MLdouble &minValue, MLdouble &maxValue, const SubImageBox *const validBox=nullptr) const
 Scans subimage and determines minimum and maximum values on region which is part of subimage box and of validBox. More...
 
MLEXPORT void compare (const SubImage &subImage2, bool *regionsMatch, bool *dataTypesMatch, bool *thisBoxIsPartOfRegion2, bool *region2IsPartOfThisBox, bool *overlapHasSameValues, ImageVector *firstMismatchPos) const
 Compare two subimages with respect to their regions and their contents. More...
 
MLEXPORT void fill (MLdouble value)
 Fills the subimage with a value cast to the data type of the subimage. More...
 
MLEXPORT void fillWithTypeData (const MLTypeData *value)
 Fills the subimage with a value given as MLTypeData. More...
 
MLEXPORT void fillBordersWithScalarValue (const SubImageBox &box, MLdouble fillValue)
 Fill all regions with the fill value fillValue which are not covered by box. More...
 
MLEXPORT void fillBordersWithTypeData (const SubImageBox &box, const MLTypeData *fillValue)
 Fills all regions with the fill value fillValue which are not covered by box. More...
 
MLEXPORT void fillBordersWithInputValues (const SubImageBox &box, const SubImage &inputSubImage)
 Fills all regions with values from inputSubImage which are not covered by box, however, only valid regions of inputSubImage are read. More...
 
MLEXPORT void fillBordersWithBorderValues (const SubImageBox &box)
 Each voxel of which is not inside box is filled with the nearest voxel which is inside box. More...
 
void fillInvalidRegionWithScalarValue (MLdouble value)
 Fills the invalid region (everything outside of getValidRegion()) with the given value. More...
 
void fillInvalidRegionWithTypeData (const MLTypeData *value)
 Fills the invalid region (everything outside of getValidRegion()) with the given value. More...
 
void fillInvalidRegionWithBorderValues ()
 Fills the invalid region (everything outside of getValidRegion()) with the values on the borders of the valid region. More...
 
MLEXPORT bool isValid () const
 Returns 1(=true) if image region and data is valid. More...
 
void * getData () const
 Returns the memory address of the memory managed by the subimage. More...
 
MLEXPORT void setData (void *data)
 Sets data as a new memory block for the subimage. More...
 
MLEXPORT void setDataFromMemoryBlockHandle (const MLMemoryBlockHandle &data)
 Sets the managed data from a given MLMemoryBlockHandle, the sub image will store this handle and thus reference count the memory managed by the handle as long as the SubImage stays alive. More...
 
const MLMemoryBlockHandlegetMemoryBlockHandle () const
 Returns the memory block handle that manages the data of this SubImage if it has been set via setDataFromMemoryBlockHandle(). More...
 

Additional Inherited Members

- Static Public Member Functions inherited from ml::SubImage
static MLEXPORT MLint coordToIndex (MLint x, MLint y, MLint z, MLint c, MLint t, MLint u, const ImageVector &size)
 Converts the coordinate (x, y, z, c, t,u) to an index into an image with 6D extents given by size. More...
 
static MLEXPORT MLint coordToIndex (const ImageVector &voxelPosition, const ImageVector &size)
 Converts the coordinate voxelPosition into the image with extents size to an index. More...
 
static MLEXPORT ImageVector indexToCoord (MLint index, const ImageVector &extent)
 Converts an index into an array with extents extent to a coordinate. More...
 
- Protected Member Functions inherited from ml::SubImage
void _calcFillAreaParams (const SubImageBox &box, const SubImageBox &maxValidInputRegion, ImageVector &boxV1, ImageVector &boxV2, ImageVector &outputTSubImageV1, ImageVector &outputTSubImageV2, MLint &fullLineLenX, MLint &fullLineLenXB, MLint &leftLineStartX, MLint &leftLineLenX, MLint &leftLineLenXB, MLint &rightLineStartX, MLint &rightLineLenX, MLint &rightLineLenXB)
 Helper method to calculate important parameters for page based border filling. More...
 
void _copySubImageGeneric (const SubImage &fromImage, const ScaleShiftData &scaleShiftData)
 Generic, non-optimized version of copySubImage. More...
 
const MLTypeInfos_getDataTypeInfos (MLDataType dt) const
 Get MLTypeInfos for used data types, indicates error if type is not registered. More...
 
- Protected Attributes inherited from ml::SubImage
SubImageBox _box
 The box of the subimage. More...
 
ImageVector _sourceImageExtent
 The extent of the source image, which is used for getValidRegion() More...
 
void * _data
 Memory chunk managed by this subimage. More...
 
MLMemoryBlockHandle _memoryBlock
 Memory block used by this subimage. More...
 
ImageVector _stride
 Stride vector to address the memory efficiently. More...
 
MLDataType _dataType
 Datatype of the image. More...
 

Detailed Description

ManagedSubImage is derived from SubImage and frees its allocated memory automatically when it is destructed.

If you make use of TileRequest::AllocationPolicy == TileRequest::ExternalBuffer, make sure that you call takeData(), otherwise this class will delete your external buffer in its destructor!

The class is not exported to make inlining possible.

Definition at line 30 of file mlManagedSubImage.h.

Constructor & Destructor Documentation

◆ ManagedSubImage()

ml::ManagedSubImage::ManagedSubImage ( )
inline

Constructor.

Definition at line 35 of file mlManagedSubImage.h.

◆ ~ManagedSubImage()

ml::ManagedSubImage::~ManagedSubImage ( )
inlineoverride

Destruct the object, freeing the memory.

Definition at line 44 of file mlManagedSubImage.h.

Member Function Documentation

◆ operator=()

ManagedSubImage& ml::ManagedSubImage::operator= ( const SubImage si)
inline

Copy operator from SubImage.

Definition at line 38 of file mlManagedSubImage.h.

◆ takeData()

void* ml::ManagedSubImage::takeData ( )
inline

Returns the data pointer and set the internal data to NULL (so it passes the ownership of the data to the caller) NOTE: This should only be used on images that where allocated via MLAlloc or with user provided memory.

It will not work correctly on MemoryManager allocated memory, since one has to use getMemoryBlockHandle() instead to get the data.

Definition at line 52 of file mlManagedSubImage.h.


The documentation for this class was generated from the following file: