13 #ifndef ML_SUB_IMAGE_H
14 #define ML_SUB_IMAGE_H
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()),
116 _dataType (datatype),
126 _sourceImageExtent(si._sourceImageExtent),
128 _memoryBlock (si._memoryBlock),
129 _stride (si._stride),
130 _dataType (si._dataType),
131 _dataTypeSize (si._dataTypeSize)
133 _box.translate(offset);
151 _dataTypeSize = si._dataTypeSize;
182 _box.translate(offset);
193 _box.v2 = newOrigin + offset;
207 _box.v2 = _box.v1 + newExtent -1;
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) );
551 bool* dataTypesMatch,
552 bool* thisBoxIsPartOfRegion2,
553 bool* region2IsPartOfThisBox,
554 bool* overlapHasSameValues,
621 fillBordersWithScalarValue(getValidRegion(), value);
627 fillBordersWithTypeData(getValidRegion(), value);
634 fillBordersWithBorderValues(getValidRegion());
681 MLint &fullLineLenXB,
682 MLint &leftLineStartX,
684 MLint &leftLineLenXB,
685 MLint &rightLineStartX,
686 MLint &rightLineLenX,
687 MLint &rightLineLenXB);
718 size_t _dataTypeSize;
720 #if ML_DEPRECATED_SINCE(3,5,0)
729 inline ML_DEPRECATED
SubImageBox getBoxFromImgExt()
const {
return getBoxFromExtent(); }
732 inline ML_DEPRECATED
ImageVector getImgExt()
const {
return getImageExtent(); }
735 inline ML_DEPRECATED
void setImgExt(
const ImageVector& newExtent) { setImageExtent(newExtent); }
738 inline ML_DEPRECATED
MLint getSize()
const {
return getNumVoxels(); }
741 inline ML_DEPRECATED
MLint getByteSize()
const {
return getSizeInBytes(); }
744 inline ML_DEPRECATED
void* getVoidSubImgPos(
const ImageVector &p)
const {
return getSubImagePointer(p); }
747 inline ML_DEPRECATED
void* getVoidSubImgPos(
MLint x,
MLint y,
MLint z)
const {
return getSubImagePointer(x, y, z); }
750 inline ML_DEPRECATED
void* getVoidImgPos(
const ImageVector &p)
const {
return getImagePointer(p); }
753 inline ML_DEPRECATED
void* getVoidImgPos(
MLint x,
MLint y,
MLint z)
const {
return getImagePointer(x, y, z); }
756 inline ML_DEPRECATED
MLint isValidSubImgPos(
const ImageVector& p)
const {
return isValidSubImagePosition(p); }
759 inline ML_DEPRECATED
MLint isValidSubImgPos(
MLint x,
MLint y,
MLint z)
const {
return isValidSubImagePosition(x, y, z); }
762 inline ML_DEPRECATED
MLint isValidImgPos(
const ImageVector& p)
const {
return isValidImagePosition(p); }
765 inline ML_DEPRECATED
MLint isValidImgPos(
MLint x,
MLint y,
MLint z)
const {
return isValidImagePosition(x, y, z); }
769 const SubImageBox*
const validBox=
nullptr)
const {
MLdouble tmpMin, tmpMax;
MLint result = calculateMinMax(tmpMin, tmpMax, validBox); minValue = tmpMin; maxValue = tmpMax;
return result; }
773 const SubImageBox*
const validBox=
nullptr)
const {
return calculateMinMax(minVal, maxVal, validBox); }
777 const SubImageBox *
const validBox=
nullptr)
const {
MLdouble tmpMin, tmpMax;
MLint result = calculateMinMax(tmpMin, tmpMax, validBox); minValue = tmpMin; maxValue = tmpMax;
return result; }
780 inline ML_DEPRECATED
void fillSubImg(
MLldouble val) { fill(
static_cast<MLdouble>(val)); }
783 inline ML_DEPRECATED
void fillSubImgWithTypeData(
const MLTypeData *val) { fillWithTypeData(val); }
786 inline ML_DEPRECATED
void fillBordersWithClampedInputValues(
const SubImageBox& box) { fillBordersWithBorderValues(box); }
789 inline ML_DEPRECATED
void fillBordersWithLDoubleValue(
const SubImageBox &box,
MLldouble fillValue) { fillBordersWithScalarValue(box,
static_cast<MLdouble>(fillValue)); }
792 inline ML_DEPRECATED
void fillInvalidRegionWithLDoubleValue(
MLldouble value) { fillBordersWithScalarValue(getValidRegion(),
static_cast<MLdouble>(value)); }
801 #if ML_DEPRECATED_SINCE(3,5,0)
806 ML_DEPRECATED
typedef SubImage SubImg;
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.
void * getData() const
Returns the memory address of the memory managed by the subimage.
void fillInvalidRegionWithScalarValue(MLdouble value)
Fills the invalid region (everything outside of getValidRegion()) with the given value.
ImageVector _stride
Stride vector to address the memory efficiently.
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 fillInvalidRegionWithTypeData(const MLTypeData *value)
Fills the invalid region (everything outside of getValidRegion()) with the given value.
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.
void * getSubImagePointer(const ImageVector &voxelPosition) const
Returns pointer to voxel data of image voxel at 6d voxelPosition relative to the begin of the subimag...
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
const MLTypeInfos * _getDataTypeInfos(MLDataType dt) const
Get MLTypeInfos for used data types, indicates error if type is not registered.
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.
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.
SubImage & operator=(const SubImage &si)
Assignment operator to get identical copy.
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,...
const SubImageBox & getBox() const
Returns the box describing the origin/extent of the subimage.
MLint getOffset(const ImageVector &voxelPosition) const
Returns the array index offset from the origin (0,0,0,0,0,0) to the voxelPosition.
const MLTypeInfos * getDataTypeInfos() const
Get MLTypeInfos for image data type.
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,...
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 ...
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.
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.
const MLMemoryBlockHandle & getMemoryBlockHandle() const
Returns the memory block handle that manages the data of this SubImage if it has been set via setData...
MLEXPORT void fillBordersWithTypeData(const SubImageBox &box, const MLTypeData *fillValue)
Fills all regions with the fill value fillValue which are not covered by box.
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 ImageVector & getOrigin() const
Returns the origin of the subimage (which is identical to getBox().v1).
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()
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...
MLDataType _dataType
Datatype of the image.
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 set(const ComponentType v=0)
Sets all components to v or - if v is not specified - to 0.
VectorType getExtent() const
Returns the extents of the subimage region.
ComponentType c
Color component of the vector.
ComponentType t
Time component of the vector.
ComponentType u
Unit/Modality/User component of the vector.
ComponentType z
Z component of the vector.
ComponentType x
X component of the vector.
ComponentType y
Y component of the vector.
TVector< TVectorBase > getStrides(const ComponentType offset=1) const
Interprets the vector as image extension and returns a stride vector.
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.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator "<<" for stream output of Field objects.
#define MLEXPORT
To export symbols from a dll/shared object, we need to mark them with the MLEXPORT symbol.
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 ...
TSubImageBox< MLint > SubImageBox
Define 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 which is used by the ML for indexing and coordinates.
Structure containing all data type features and pointers to all functions needed to implement operati...