86 _sourceImageExtent(0),
99 _sourceImageExtent(
si._sourceImageExtent),
101 _memoryBlock (
si._memoryBlock),
102 _stride (
si._stride),
103 _dataType (
si._dataType),
104 _dataTypeSize (
si._dataTypeSize)
113 _sourceImageExtent(0),
115 _stride (box.getExtent().getStrides()),
126 _sourceImageExtent(
si._sourceImageExtent),
128 _memoryBlock (
si._memoryBlock),
129 _stride (
si._stride),
130 _dataType (
si._dataType),
131 _dataTypeSize (
si._dataTypeSize)
133 _box.translate(offset);
146 _sourceImageExtent =
si._sourceImageExtent;
148 _memoryBlock =
si._memoryBlock;
149 _stride =
si._stride;
150 _dataType =
si._dataType;
151 _dataTypeSize =
si._dataTypeSize;
182 _box.translate(offset);
250 return SubImageBox::intersect(_box,
sourceBox);
272 return ImageVector::dot(voxelPosition,_stride);
283 _dataType = dataType;
306 return static_cast<void*
>(
static_cast<char*
>(_data) +
static_cast<size_t>(ImageVector::dot(voxelPosition, _stride) *
static_cast<MLint>(_dataTypeSize)));
317 return static_cast<void*
>(
static_cast<char*
>(_data) +
static_cast<size_t>((x*_stride.x + y*_stride.y + _stride.z*z) *
static_cast<MLint>(_dataTypeSize)));
325 return getSubImagePointer(voxelPosition-_box.v1);
333 return getSubImagePointer(x-_box.v1.x, y-_box.v1.y, z-_box.v1.z);
372 inline void*
getData()
const {
return _data; }
425 return ((voxelPosition.x>=0) && (voxelPosition.y>=0) && (voxelPosition.z>=0) &&
426 (voxelPosition.c>=0) && (voxelPosition.t>=0) && (voxelPosition.u>=0) &&
427 voxelPosition.x < extent.x && voxelPosition.y < extent.y && voxelPosition.z < extent.z &&
428 voxelPosition.c < extent.c && voxelPosition.t < extent.t && voxelPosition.u < extent.u );
438 return ((x>=0) && (y>=0) && (z>=0) &&
439 (x < extent.x) && (y < extent.y) && (z < extent.z));
448 return ((voxelPosition.x>=_box.v1.x) && (voxelPosition.y>=_box.v1.y) && (voxelPosition.z>=_box.v1.z) &&
449 (voxelPosition.c>=_box.v1.c) && (voxelPosition.t>=_box.v1.t) && (voxelPosition.u>=_box.v1.u) &&
450 (voxelPosition.x<=_box.v2.x) && (voxelPosition.y<=_box.v2.y) && (voxelPosition.z<=_box.v2.z) &&
451 (voxelPosition.c<=_box.v2.c) && (voxelPosition.t<=_box.v2.t) && (voxelPosition.u<=_box.v2.u) );
460 return ((x>=_box.v1.x) && (y>=_box.v1.y) && (z>=_box.v1.z) &&
461 (x<=_box.v2.x) && (y<=_box.v2.y) && (z<=_box.v2.z) );
621 fillBordersWithScalarValue(getValidRegion(), value);
627 fillBordersWithTypeData(getValidRegion(), value);
634 fillBordersWithBorderValues(getValidRegion());
718 size_t _dataTypeSize;
The strong handle of a MLMemoryBlock.
void * data() const
Returns the data of the memory block. If this handle is null, then NULL is returned.
This class represents basic image properties:
This class manages/represents a rectangular 6d image region which is organized linearly in memory.
const MLTypeInfos * _getDataTypeInfos(MLDataType dt) const
Get MLTypeInfos for used data types, indicates error if type is not registered.
void fillInvalidRegionWithScalarValue(MLdouble value)
Fills the invalid region (everything outside of getValidRegion()) with the given value.
SubImage & operator=(const SubImage &si)
Assignment operator to get identical copy.
ImageVector _stride
Stride vector to address the memory efficiently.
void * getSubImagePointer(const ImageVector &voxelPosition) const
Returns pointer to voxel data of image voxel at 6d voxelPosition relative to the begin of the subimag...
void setBox(const SubImageBox &subImageBox)
Sets a rectangular 6d region of the subimage to subImageBox.
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.
bool isValidSubImagePosition(const ImageVector &voxelPosition) const
Returns true if 6d voxelPosition is a valid position within subimage region, i.e.,...
void * getImagePointer(const ImageVector &voxelPosition) const
Returns pointer to voxel data of image voxel at 6d position voxelPosition relative to the begin of th...
void fillInvalidRegionWithTypeData(const MLTypeData *value)
Fills the invalid region (everything outside of getValidRegion()) with the given value.
const SubImageBox & getBox() const
Returns the box describing the origin/extent of the subimage.
virtual ~SubImage()=default
Virtual destructor to suppress compiler warnings.
void setDataType(MLDataType dataType)
Overwrite inherited setDataType method to set type of data to dataType.
void translate(const ImageVector &offset)
Translates the box of the subimage by adding the vector offset.
MLEXPORT void allocateAsMemoryBlockHandle(MLMemoryErrorHandling handleFailure=ML_RETURN_NULL)
Allocate data using the ML memory manager. For failure handing, see SubImage::allocate().
MLDataType getDataType() const
Return type of image data.
MLEXPORT bool isOneValued() const
Returns true if all page voxels have the same value or if the page contains only 1 voxel.
SubImageBox getBoxFromImageExtent() const
SubImage(const SubImage &si, const ImageVector &offset)
Copy constructor to get identical copy.
MLMemoryBlockHandle _memoryBlock
Memory block used by this subimage.
SubImageBox _box
The box of the 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.
void setExtent(const ImageVector &newExtent)
Sets the extent of the subimage (which also changes the strides) to newExtent.
SubImage(const SubImage &si)
Copy constructor to get identical copy.
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 ...
ImageVector getExtent() const
Returns the extent of the subimage (which is identical to getBox().getExtent()).
ImageVector getStride() const
Returns a stride vector to address the memory efficiently.
const ImageVector & getOrigin() const
Returns the origin of the subimage (which is identical to getBox().v1).
SubImageBox getValidRegion() const
Returns the valid region of the SubImage, which is defined by the intersection of the SubImage::getBo...
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.
void _copySubImageGeneric(const SubImage &fromImage, const ScaleShiftData &scaleShiftData)
Generic, non-optimized version of copySubImage.
void toStream(std::ostream &ostr) const
MLEXPORT void free()
Frees data pointed to by getData() with MLFree().
MLEXPORT void allocate(MLMemoryErrorHandling handleFailure)
Allocate data with MLAlloc().
void setSourceImageExtent(const ImageVector &extent)
Sets the image extent of the source image that was used to create this SubImage to extent.
void * _data
Memory chunk managed by this subimage.
static MLEXPORT MLint coordToIndex(const ImageVector &voxelPosition, const ImageVector &size)
Converts the coordinate voxelPosition into the image with extents size to an index.
MLEXPORT void copySubImage(const SubImage &fromImage)
Implements special case for void copySubImage(const TSubImage<FROM_DATATYPE> &typedFromImg,...
MLEXPORT void fillBordersWithInputValues(const SubImageBox &box, const SubImage &inputSubImage)
Fills all regions with values from inputSubImage which are not covered by box, however,...
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.
MLEXPORT void fillBordersWithScalarValue(const SubImageBox &box, MLdouble fillValue)
Fill all regions with the fill value fillValue which are not covered by box.
void setOrigin(const ImageVector &newOrigin)
Sets the origin of the subimage (which moves the box of the subimage to newOrigin).
void fillInvalidRegionWithBorderValues()
Fills the invalid region (everything outside of getValidRegion()) with the values on the borders of t...
SubImage(const SubImageBox &box, MLDataType datatype, void *data=nullptr)
Constructor for a rectangular 6d image region with position and extent given by box,...
MLint getOffset(const ImageVector &voxelPosition) const
Returns the array index offset from the origin (0,0,0,0,0,0) to the voxelPosition.
void * getData() const
Returns the memory address of the memory managed by the subimage.
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,...
SubImage()
Constructor: Creates a subimage with no data.
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,...
MLEXPORT bool isValid() const
Returns 1(=true) if image region and data is valid.
SubImageBox getBoxFromExtent() const
Returns size of image as box with origin 0.
MLint getSizeInBytes() const
Returns number of potential bytes in (sub)image.
ImageVector getSourceImageExtent() const
Returns the image extent of the source image that was used to create this SubImage.
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 ...
bool isValidImagePosition(const ImageVector &voxelPosition) const
Returns true if 6d voxelPosition is a valid position within subimage region, i.e.,...
void setImageExtent(const ImageVector &newExtent)
MLEXPORT void setFromImageProperties(const ImageProperties &imageProperties)
Sets the image box and datatype from the imageProperties extent and datatype.
MLEXPORT void fillBordersWithTypeData(const SubImageBox &box, const MLTypeData *fillValue)
Fills all regions with the fill value fillValue which are not covered by box.
const MLMemoryBlockHandle & getMemoryBlockHandle() const
Returns the memory block handle that manages the data of this SubImage if it has been set via setData...
MLEXPORT ImageProperties toImageProperties() const
Converts the Subimage's datatype and extend to an ImageProperties object.
MLint getNumVoxels() const
Returns number of voxels in (sub)image.
MLEXPORT void fillWithTypeData(const MLTypeData *value)
Fills the subimage with a value given as MLTypeData.
MLEXPORT void fill(MLdouble value)
Fills the subimage with a value cast to the data type of the subimage.
MLEXPORT void setDataFromMemoryBlockHandle(const MLMemoryBlockHandle &data)
Sets the managed data from a given MLMemoryBlockHandle, the sub image will store this handle and thus...
ImageVector getImageExtent() const
static MLEXPORT ImageVector indexToCoord(MLint index, const ImageVector &extent)
Converts an index into an array with extents extent to a coordinate.
const MLTypeInfos * getDataTypeInfos() const
Get MLTypeInfos for image data type.
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 su...
MLEXPORT void fillBordersWithBorderValues(const SubImageBox &box)
Each voxel of which is not inside box is filled with the nearest voxel which is inside box.
MLEXPORT void copySubImage(const SubImage &fromImage, const ScaleShiftData &scaleShiftData)
Copies image data from the subimage fromImage into the overlapping region of this subimage.
MLEXPORT void setData(void *data)
Sets data as a new memory block for the subimage.
void setBox(const ImageVector &imageExtent)
Sets a rectangular 6d region of the subimage to imageExtent.
ImageVector _sourceImageExtent
The extent of the source image, which is used for getValidRegion()
MLDataType _dataType
Datatype of the image.
MLEXPORT size_t MLSizeOf(MLDataType dataType)
Returns the size of the data type dataType in bytes.
MLint32 MLDataType
MLDataType.
@ MLuint8Type
Enumerator for the unsigned 8 bit ML integer type.
MLEXPORT MLTypeInfos * MLGetTypeInfosForDataType(MLDataType dataType)
Returns the MLTypeInfos for the data type dataType, or NULL on non registered or invalid type.
#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.
MLMemoryErrorHandling
Enumerator to specify memory error handling.
@ ML_RETURN_NULL
On allocation failure NULL is returned without error handling.
unsigned char MLTypeData
This is the pointer type used to point to the data of MLType data instances.
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)
Structure containing all data type features and pointers to all functions needed to implement operati...