13#ifndef ML_TSUB_IMAGE_H
14#define ML_TSUB_IMAGE_H
30#pragma warning(disable: 4244)
39template <
typename DATATYPE>
class TSubImageCursor;
41template <
typename DATATYPE>
class ConstTSubImageCursor;
44#define _ML_TSUBIMG_SUBDOT6(pos, offset, stride) \
45 (((pos).x - (offset).x) * (stride).x + \
46 ((pos).y - (offset).y) * (stride).y + \
47 ((pos).z - (offset).z) * (stride).z + \
48 ((pos).c - (offset).c) * (stride).c + \
49 ((pos).t - (offset).t) * (stride).t + \
50 ((pos).u - (offset).u) * (stride).u)
53#define _ML_TSUBIMG_SUBDOT3(x, y, z, offset, stride) \
54 (((x) - (offset).x) * (stride).x + \
55 ((y) - (offset).y) * (stride).y + \
56 ((z) - (offset).z) * (stride).z)
59#define _ML_TSUBIMG_SUBDOT2(x, y, offset, stride) \
60 (((x) - (offset).x) * (stride).x + \
61 ((y) - (offset).y) * (stride).y)
108template <
typename DATATYPE>
143 "Mismatch of data type between argument and template typename.");
158 "Data type has no registered TypeTraits.");
175 setDataType(
subImage.getDataType());
181 setSourceImageExtent(
subImage.getSourceImageExtent());
188 "Mismatch of data type between argument and template typename.");
284 const MLint offset = pointer -
static_cast<DATATYPE*
>(_data);
291 *x = (offset/stride.x) %
imgExt.x;
297 *y = (offset/stride.y) %
imgExt.y;
303 *z = (offset/stride.z) %
imgExt.z;
312 {
return convertPointerToSubImagePosition(pointer) + _box.v1; }
322 convertPointerToSubImagePosition(pointer, x, y, z);
323 if (x){ *x += _box.v1.x; }
324 if (y){ *y += _box.v1.y; }
325 if (z){ *z += _box.v1.z; }
451 for (
MLint u=box.
v1.u; u <= box.
v2.u; ++u){
452 for (
MLint t=box.
v1.t; t <= box.
v2.t; ++t){
453 for (
MLint c=box.
v1.c; c <= box.
v2.c; ++c){
454 for (
MLint z=box.
v1.z; z <= box.
v2.z; ++z){
455 for (
MLint y=box.
v1.y; y <= box.
v2.y; ++y){
457 p.
set(box.
v1.x, y, z, c, t, u);
482#define _ML_CHECK_SUBIMAGE_DATA_POINTERS(FROM_PTR, TO_PTR) \
485 if (!FROM_PTR || !TO_PTR){ \
486 ML_PRINT_ERROR("TSubImage::copySubImageTyped( )", \
487 ML_BAD_POINTER_OR_0, \
488 "Valid data pointers in source and target subimage required for" \
489 "subimage copying, thus call is ignored."); \
497 template <
typename FROM_DATATYPE>
590 template <
typename FROM_DATATYPE>
594 if (getBox().isEmpty() ||
typedFromImg.getBox().isEmpty()){
598 if (
scaleShiftData.getReorderMode() == ScaleShiftData::ReorderColorPlanesToInterleaved) {
629 const MLint size = getNumVoxels();
681 toPt = getImagePointer(pos);
739 toPt = getImagePointer(pos);
805 fillBordersWithValue(getValidRegion(), value);
814 fillBordersWithBorderValues(getValidRegion());
823template <
typename DATATYPE>
830 _subImageOffset =
subImage.getBox().v1;
860 inline void moveX() { _cursor += _stride.x; }
862 inline void moveY() { _cursor += _stride.y; }
864 inline void moveZ() { _cursor += _stride.z; }
866 inline void moveC() { _cursor += _stride.c; }
868 inline void moveT() { _cursor += _stride.t; }
870 inline void moveU() { _cursor += _stride.u; }
920template <
typename DATATYPE>
946template <
typename DATATYPE>
989template <
typename DATATYPE>
1135template <
typename T>
1142 "Mismatch of data type between argument and template typename.");
1147template <
typename T>
1154 "Mismatch of data type between argument and template typename.");
1159template <
typename T>
1166 "Mismatch of data type between argument and template typename.");
1171template <
typename T>
1178 "Mismatch of data type between argument and template typename.");
1196 template <
typename DATATYPE>
1197 inline ostream &
operator<<(ostream &
ostr,
const ML_NAMESPACE::TSubImage<DATATYPE> &v)
1200 const ML_NAMESPACE::SubImageBox& box = v.getBox();
1201 ML_NAMESPACE::ImageVector p;
1202 for (p.u=box.v1.u; p.u<=box.v2.u; ++p.u){
1203 for (p.t=box.v1.t; p.t<=box.v2.t; ++p.t){
1204 for (p.c=box.v1.c; p.c<=box.v2.c; ++p.c){
1205 for (p.z=box.v1.z; p.z<=box.v2.z; ++p.z){
1206 for (p.y=box.v1.y; p.y<=box.v2.y; ++p.y){
1210 for (; p.x<=box.v2.x; p.x++){
1211 ostr << v.getImageValue(p) <<
" ";
Predeclaration for const cursor.
ConstTSubImageCursor(const TSubImage< DATATYPE > &subImage)
const DATATYPE * getPointerWithOffset(const ImageVector &offset) const
Returns cursor position of voxel given from current cursor shifted by offset.
const DATATYPE * getPointerWithOffset(MLint dx, MLint dy, MLint dz) const
Returns cursor position of voxel given from current cursor shifted by (dx, dy, dz).
const DATATYPE * getPointer() const
This class manages/represents a rectangular 6d image region which is organized linearly in memory.
void set(const ComponentType v=0)
Sets all components to v or - if v is not specified - to 0.
VectorType v1
Corner v1 of the subimage region (included in region).
VectorType v2
Corner v2 of the subimage region (also included in region!).
intT getNumVoxels() const
Returns number of voxels in the subimage region, i.e., the product of all extents if this is not empt...
bool isEmpty() const
Returns true if subimage region is empty, i.e., if any of the components of v1 is greater than the co...
Base class for all TSubImage Cursors.
void reverseMoveC()
Moves cursor backward in c direction.
void moveT()
Moves cursor forward in t direction.
void reverseMoveX()
Moves cursor backward in x direction.
void moveZ()
Moves cursor forward in z direction.
void setPosition(const DATATYPE *pointer)
Sets cursor to the given pointer where the pointer is the memory address of the voxel.
void reverseMoveY()
Moves cursor backward in y direction.
DATATYPE getValue() const
Returns voxel value at cursor position.
void reverseMoveT()
Moves cursor backward in t direction.
ImageVector _stride
Stride for the sub image.
void moveU()
Moves cursor forward in u direction.
void setSubImagePosition(MLint x, MLint y, MLint z)
Sets cursor to the given 3d position (x, y, z) relative to the origin of the subimage region.
DATATYPE getValueWithOffset(MLint dx, MLint dy, MLint dz) const
Return voxel value at (cursor position + (dx, dy, dz))
void moveX()
Moves cursor forward in x direction.
DATATYPE getValueWithOffset(const ImageVector &offset) const
Returns voxel value at (cursor position + offset).
ImageVector _subImageOffset
SubImage offset in original image.
DATATYPE * _data
SubImage data.
void reverseMoveZ()
Moves cursor backward in z direction.
void setImagePosition(const ImageVector &position)
Sets cursor to the given 6d position relative to the origin of the complete image region.
void moveByOffset(const ImageVector &offset)
Moves cursor to cursor position + offset.
DATATYPE * _cursor
Cursor address for image data access.
void reverseMoveU()
Moves cursor backward in u direction.
TSubImageCursorBase(const TSubImage< DATATYPE > &subImage)
void moveY()
Moves cursor forward in y direction.
void setSubImagePosition(const ImageVector &position)
Sets cursor to the given position relative to the origin of the subimage region.
void moveByOffset(MLint x, MLint y, MLint z)
Moves cursor to cursor position + (x, y, z).
void setImagePosition(MLint x, MLint y, MLint z)
Sets cursor to the given 3d position (x, y, z) relative to the origin of the complete image region.
void moveC()
Moves cursor forward in c direction.
Predeclaration for cursor.
DATATYPE * getPointerWithOffset(const ImageVector &offset) const
Returns cursor position of voxel given from current cursor shifted by offset.
DATATYPE * getPointer() const
void setValueWithOffset(MLint dx, MLint dy, MLint dz, DATATYPE value) const
Sets voxel value at (cursor position + (dx, dy, dz)) to value.
TSubImageCursor(TSubImage< DATATYPE > &subImage)
void setValueWithOffset(const ImageVector &offset, DATATYPE value) const
Sets voxel value at (cursor position + offset) to value.
void setValue(DATATYPE value) const
Sets voxel value at cursor position to value.
DATATYPE * getPointerWithOffset(MLint dx, MLint dy, MLint dz) const
Returns cursor position of voxel given from current cursor shifted by (dx, dy, dz).
A class that offers a TSubImage with a TSubImageCursor.
void setCursorValue(DATATYPE value)
Sets the voxel value at cursor position to value.
void reverseMoveCursorC()
Moves cursor backward in c direction.
void moveCursorT()
Moves cursor forward in t direction.
void moveCursorByOffset(const ImageVector &offset)
Moves cursor to cursor position + offset.
void setCursorImagePosition(MLint x, MLint y, MLint z)
Sets cursor to the given 3d position (x, y, z) relative to the origin of the complete image region.
DATATYPE getCursorValue() const
Returns the voxel value at the cursor position.
void reverseMoveCursorU()
Moves cursor backward in u direction.
void reverseMoveCursorY()
Moves cursor backward in y direction.
DATATYPE getCursorValueWithOffset(MLint dx, MLint dy, MLint dz) const
Returns voxel value at (cursor position + (dx, dy, dz))
void reverseMoveCursorX()
Moves cursor backward in x direction.
void moveCursorByOffset(MLint x, MLint y, MLint z)
Moves cursor to cursor position + (x, y, z).
TSubImageWithCursor(const TSubImage< DATATYPE > &subImage)
Constructor with TSubImage.
void moveCursorZ()
Moves cursor forward in z direction.
void reverseMoveCursorZ()
Moves cursor backward in z direction.
void moveCursorC()
Moves cursor forward in c direction.
DATATYPE * getCursorPointerWithOffset(const ImageVector &offset) const
Returns cursor pointer of voxel given from current cursor shifted by offset.
void reverseMoveCursorT()
Moves cursor backward in t direction.
void setCursorValueWithOffset(const ImageVector &offset, DATATYPE value)
Sets the voxel value at (cursor position + offset) to value.
void setCursorImagePosition(const ImageVector &position)
Sets cursor to the given 6d position relative to the origin of the complete image region.
DATATYPE * getCursorPointerWithOffset(MLint dx, MLint dy, MLint dz) const
Returns cursor pointer of voxel given from current cursor shifted by (dx, dy, dz).
void setCursorPosition(const DATATYPE *pointer)
Sets cursor to the given pointer where pointer is the memory address of the voxel.
void moveCursorY()
Moves cursor forward in y direction.
void moveCursorX()
Moves cursor forward in x direction.
TSubImageWithCursor(const TSubImageWithCursor &subImage)
Constructor with TSubImageWithCursor.
TSubImageWithCursor(const SubImage &subImage)
Constructor with SubImage.
void moveCursorU()
Moves cursor forward in u direction.
DATATYPE getCursorValueWithOffset(const ImageVector &offset) const
Returns the voxel value at (cursor position + offset)
void setCursorSubImagePosition(MLint x, MLint y, MLint z)
Sets cursor to the given 3d position (x, y, z) relative to the origin of the subimage region.
void setCursorSubImagePosition(const ImageVector &position)
Sets cursor to the given position relative to the origin of the subimage region.
DATATYPE * getCursorPointer() const
TSubImageWithCursor()
Default constructor.
TSubImageWithCursor & operator=(const TSubImageWithCursor< DATATYPE > &tSubImg)
Assignment operator to get an identical copy.
void setCursorValueWithOffset(MLint dx, MLint dy, MLint dz, DATATYPE value)
Sets voxel value at (cursor position + (dx, dy,dz)) to value.
This template class manages/represents a rectangular 6d image region in memory which is organized lin...
TSubImage(const SubImage &subImage)
Constructor to build a typed subimage from an untyped subImage.
const DATATYPE * getImagePointer(const ImageVector &position) const
Returns a pointer to voxel data of image voxel at 6d position position relative to the begin of the c...
DATATYPE getSubImageValue(MLint x, MLint y, MLint z) const
Returns the voxel value at the given position (x, y, z) where the position is relative to the origin ...
void copySubImageTyped(const TSubImage< FROM_DATATYPE > &typedFromImg, const ScaleShiftData &scaleShiftData)
Copies image data from the subimage fromImg into the overlapping region of this subimage.
DATATYPE * getImagePointer(const ImageVector &position)
TSubImage(const TSubImage< DATATYPE > &typedSubImage)
Copy constructor to get an identical copy.
void copySubImageReorderColorPlanesToInterleaved(const TSubImage< FROM_DATATYPE > &typedFromImage, const ScaleShiftData &scaleShiftData)
Implements special case for void copySubImageTyped(const TSubImage<FROM_DATATYPE> &typedFromImg,...
void setSubImageValue(MLint x, MLint y, DATATYPE value)
Sets the voxel value at the given position(x, y) to the given value where the position is relative to...
DATATYPE getImageValue(MLint x, MLint y) const
Returns the 2d voxel value from the given position (x, y).
TSubImage(const SubImageBox &box, MLDataType dataType, void *data)
Constructor for an image region with location/extent box, with data type dataType (must fit to DATATY...
const DATATYPE * 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 begin of th...
void setImageValue(const ImageVector &position, DATATYPE value)
Sets the 6d voxel at the given position to the given value.
DATATYPE getSubImageValue(MLint x, MLint y) const
Returns the voxel value at position (x, y) where the position is relative to the origin of the subima...
ConstTSubImageCursor< DATATYPE > ConstCursor
A read-only cursor.
~TSubImage() override=default
Virtual destructor to shut up compiler warnings.
void fill(DATATYPE value)
Sets all voxel values in subimage to value.
ImageVector convertPointerToImagePosition(DATATYPE *pointer) const
Returns 6d voxel coordinates corresponding to the memory address pointer.
DATATYPE & operator[](const ImageVector &position)
Reference access to voxel value at the given position.
DATATYPE getImageValue(MLint x, MLint y, MLint z) const
Returns the 3d voxel value from given position (x, y, z).
TSubImageCursor< DATATYPE > Cursor
A read/write cursor.
ImageVector convertPointerToSubImagePosition(DATATYPE *pointer) const
Returns 6d voxel coordinates corresponding to the memory address pointer.
const DATATYPE * getSubImagePointer(const ImageVector &position) const
Returns a pointer to voxel data of image voxel at the 6d position relative to the begin of the subima...
TSubImage()
Default constructor to build a typed subimage (with an empty box) from scratch.
DATATYPE getImageValue(const ImageVector &position) const
Returns the 6d voxel value from the given position.
const DATATYPE * 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 begin of th...
void fillInvalidRegionWithValue(DATATYPE value)
Fills the invalid region (everything outside of getValidRegion()) with the given value.
DATATYPE * getSubImagePointer(const ImageVector &position)
const DATATYPE & operator[](const ImageVector &position) const
Constant reference access to voxel value at the given position.
DATATYPE * getImagePointer(MLint x, MLint y, MLint z)
DATATYPE ComponentType
A typedef to "export" the type of voxels components.
void setImageValue(MLint x, MLint y, MLint z, DATATYPE value)
Sets the 3d voxel at the given position (x, y, z) to the given value.
void fillBordersWithValue(const SubImageBox &box, DATATYPE fillValue)
Fills all regions with fillValue which are not covered by box.
DATATYPE getSubImageValue(const ImageVector &position) const
Returns voxel value at the given position where position is relative to the origin of the subimage re...
void setSubImageValue(const ImageVector &position, DATATYPE value)
Sets the voxel value at the given position to the given value where position is relative to the origi...
MLint calculateMinMax(DATATYPE &minValue, DATATYPE &maxValue, const SubImageBox *const validBox=nullptr) const
Scans subimage and determines minimum and maximum values of the region which is part of subimage box ...
void convertPointerToSubImagePosition(DATATYPE *pointer, MLint *x, MLint *y, MLint *z) const
Returns 3d voxel coordinates corresponding to the memory address pointer.
TSubImage & operator=(const TSubImage< DATATYPE > &typedSubImage)
Assignment operator to get an identical copy.
void setImageValue(MLint x, MLint y, DATATYPE value)
Sets the 2d voxel at the given position (x, y) to the the given value.
const DATATYPE * getData() const
Returns memory address of image region (Overloads method from SubImage)
void setSubImageValue(MLint x, MLint y, MLint z, DATATYPE value)
Sets the voxel value at the given position (x, y, z) to the given value where the positionis relative...
void convertPointerToImagePosition(DATATYPE *pointer, MLint *x, MLint *y, MLint *z) const
Returns 3d voxel coordinates corresponding to the memory address pointer.
DATATYPE * getSubImagePointer(MLint x, MLint y, MLint z)
void fillInvalidRegionWithBorderValues()
Fills the invalid region (everything outside of getValidRegion()) with the values on the borders of t...
TVector< TVectorBase > getStrides(const ComponentType offset=1) const
Interprets the vector as image extension and returns a stride vector.
TVector< TVectorBase > getVectorPosition(ComponentType offsetPos) const
Interprets the vector as a stride vector of an image and returns the offset position offsetPos from t...
MLEXPORT size_t MLSizeOf(MLDataType dataType)
Returns the size of the data type dataType in bytes.
#define ML_INVALID_DATA_TYPE
Defines an invalid MLDataType.
bool MLValuesAreEqual(MLint8 a, MLint8 b, MLint8)
Returns true if values are equal (numerically safely compared), otherwise false.
MLint32 MLDataType
MLDataType.
#define ML_BAD_DATA_TYPE
A wrong or unexpected data type has been passed to an algorithm which often is a programming error; t...
#define ML_PRINT_FATAL_ERROR(FUNC_NAME, REASON, HANDLING)
Like ML_PRINT_FATAL_ERROR_DUMP(FUNC_NAME, REASON, HANDLING, RT_OBJ) without a runtime object to be du...
#define ML_CHECK_THROW(x)
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#define _ML_TSUBIMG_SUBDOT6(pos, offset, stride)
Private helper macro for calculation of memory offset, calculates (pos-offset) * stride.
#define _ML_TSUBIMG_SUBDOT2(x, y, offset, stride)
Private helper macro for calculation of memory offset, calculates ((xy)-offset) * stride.
#define _ML_TSUBIMG_SUBDOT3(x, y, z, offset, stride)
Private helper macro for calculation of memory offset, calculates ((xyz)-offset) * stride.
#define _ML_CHECK_SUBIMAGE_DATA_POINTERS(FROM_PTR, TO_PTR)
Internal helper macro to check validity of data pointers of subimages.
MLint32 MLIsScalarTypePtr(const T *)
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 ...
TSubImage< T > & tsubimage_cast(SubImage &subImg)
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator "<<" for stream output of Field objects.
TypeTraits for scalar ML Datatypes.