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;
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;
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 that 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
Compares two subimages with respect to their regions and their contents.
bool isValidSubImagePosition(const ImageVector &voxelPosition) const
Returns true if the 6D voxelPosition is a valid position within the subimage region,...
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)
Override the 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 a pointer to voxel data of image voxel at 6D voxelPosition relative to the origin of the subi...
MLEXPORT void allocateAsMemoryBlockHandle(MLMemoryErrorHandling handleFailure=ML_RETURN_NULL)
Allocates data using the ML memory manager. For failure handing, see SubImage::allocate().
MLDataType getDataType() const
Returns the type of image data.
MLEXPORT bool isOneValued() const
Returns true if all page voxels have the same value or if the page contains only one voxel.
SubImageBox getBoxFromImageExtent() const
const MLTypeInfos * _getDataTypeInfos(MLDataType dt) const
Returns MLTypeInfos for used datatypes, indicates error if the type dt 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 to newExtent. This also changes the strides.
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 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)
Allocates 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 a 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)
Fills all regions with the fill value fillValue that 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.
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
Returns MLTypeInfos for image data type.
bool isValidImagePosition(MLint x, MLint y, MLint z) const
Returns true if the 3D position p=(x, y, z) is a valid position within the subimage region,...
void * getImagePointer(MLint x, MLint y, MLint z) const
Returns a pointer to voxel data of image voxel at 3D position p=(x, y, z) relative to the origin of t...
SubImage()
Constructor: Creates a subimage with no data.
bool isValidSubImagePosition(MLint x, MLint y, MLint z) const
Returns true if the 3D position p=(x, y, z) is a valid position within the subimage region,...
MLEXPORT bool isValid() const
Returns 1 (=true) if image region and data is valid.
SubImageBox getBoxFromExtent() const
Returns the 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 the 6D voxelPosition is a valid position within the subimage region,...
void setImageExtent(const ImageVector &newExtent)
MLEXPORT void setFromImageProperties(const ImageProperties &imageProperties)
Sets the image box and data type from the imageProperties extent and data type.
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 data type 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 that is cast to the data type of the subimage.
MLEXPORT void setDataFromMemoryBlockHandle(const MLMemoryBlockHandle &data)
Sets the managed data from a given MLMemoryBlockHandle, the subimage 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 that is not inside box is filled with the voxel value of the nearest voxel that is inside ...
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 a pointer to voxel data of image voxel at 3D position p=(x,y,z) relative to the origin of the...
MLDataType _dataType
Data type of the image.
void * getImagePointer(const ImageVector &voxelPosition) const
Returns a pointer to voxel data of image voxel at 6D position voxelPosition relative to the origin of...
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 ...
MLWEM_EXPORT void intersect(WEMTrianglePatch *inPatch1, WEMTrianglePatch *inPatch2, WEMTrianglePatch *outPatch, unsigned int outputMode, TriangulationModes triangulationMode, WEMVector< WEMCut > *cuts=nullptr)
Returns the intersection of the given patches.
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.
Structure containing all data type features and pointers to all functions needed to implement operati...