41#define ML_BIT_IMG_SHIFT 5l
44#define ML_BIT_IMG_ALL_BITS 0xffffffffl
47#define ML_BIT_IMG_INDEX_BITS 0x1fl
50#define ML_BIT_IMG_LOW_BIT 0x00000001l
53#define ML_BIT_IMG_HIGH_BIT 0x80000000l
56#define ML_BIT_IMG_DATA_TYPE MLuint32
62#define ML_BIT_IMG_BIT_IDX_TYPE MLuint64
129 return _useExceptions;
215 return static_cast<MLint>(_cursorBitIdx);
221 return _ext.compMul() == 0;
227 if (
nullptr != _image) {
228 memset(_image, val ? 0xff : 0, _numBytes);
499 const double minVal,
const double maxVal,
648 _strides.c * pos.c + _strides.t * pos.t);
653 _strides.c * pos.c + _strides.t * pos.t + _strides.u * pos.u);
663 inline bool _isInRangeVector1D(
const ImageVector& p)
const
665 return (p.x < _ext.x) && (p.x >= 0);
667 inline bool _isInRangeVector2D(
const ImageVector& p)
const
669 return (p.x < _ext.x) && (p.y < _ext.y) && (p.x >= 0) && (p.y >= 0);
671 inline bool _isInRangeVector3D(
const ImageVector& p)
const
673 return (p.x < _ext.x) && (p.y < _ext.y) && (p.z < _ext.z) && (p.x >= 0) && (p.y >= 0) && (p.z >= 0);
675 inline bool _isInRangeVector4D(
const ImageVector& p)
const
677 return (p.x < _ext.x) && (p.y < _ext.y) && (p.z < _ext.z) && (p.c < _ext.c) && (p.x >= 0) && (p.y >= 0) &&
678 (p.z >= 0) && (p.c >= 0);
680 inline bool _isInRangeVector5D(
const ImageVector& p)
const
682 return (p.x < _ext.x) && (p.y < _ext.y) && (p.z < _ext.z) && (p.c < _ext.c) && (p.t < _ext.t) && (p.x >= 0) &&
683 (p.y >= 0) && (p.z >= 0) && (p.c >= 0) && (p.t >= 0);
685 inline bool _isInRangeVector6D(
const ImageVector& p)
const
687 return (p.x < _ext.x) && (p.y < _ext.y) && (p.z < _ext.z) && (p.c < _ext.c) && (p.t < _ext.t) && (p.u < _ext.u) &&
688 (p.x >= 0) && (p.y >= 0) && (p.z >= 0) && (p.c >= 0) && (p.t >= 0) && (p.u >= 0);
699 inline bool _isInRangeVec61D(
const Vector6& p)
const
701 return (p[
ML_VX] <
static_cast<double>(_ext.x)) && (p[
ML_VX] >= 0.);
703 inline bool _isInRangeVec62D(
const Vector6& p)
const
705 return (p[
ML_VX] <
static_cast<double>(_ext.x)) && (p[
ML_VY] <
static_cast<double>(_ext.y)) && (p[
ML_VX] >= 0.) &&
708 inline bool _isInRangeVec63D(
const Vector6& p)
const
710 return (p[
ML_VX] <
static_cast<double>(_ext.x)) && (p[
ML_VY] <
static_cast<double>(_ext.y)) &&
711 (p[
ML_VZ] <
static_cast<double>(_ext.z)) && (p[
ML_VX] >= 0.) && (p[
ML_VY] >= 0.) && (p[
ML_VZ] >= 0.);
713 inline bool _isInRangeVec64D(
const Vector6& p)
const
715 return (p[
ML_VX] <
static_cast<double>(_ext.x)) && (p[
ML_VY] <
static_cast<double>(_ext.y)) &&
716 (p[
ML_VZ] <
static_cast<double>(_ext.z)) && (p[
ML_VC] <
static_cast<double>(_ext.c)) && (p[
ML_VX] >= 0.) &&
719 inline bool _isInRangeVec65D(
const Vector6& p)
const
721 return (p[
ML_VX] <
static_cast<double>(_ext.x)) && (p[
ML_VY] <
static_cast<double>(_ext.y)) &&
722 (p[
ML_VZ] <
static_cast<double>(_ext.z)) && (p[
ML_VC] <
static_cast<double>(_ext.c)) &&
723 (p[
ML_VT] <
static_cast<double>(_ext.t)) && (p[
ML_VX] >= 0.) && (p[
ML_VY] >= 0.) && (p[
ML_VZ] >= 0.) &&
726 inline bool _isInRangeVec66D(
const Vector6& p)
const
728 return (p[
ML_VX] <
static_cast<double>(_ext.x)) && (p[
ML_VY] <
static_cast<double>(_ext.y)) &&
729 (p[
ML_VZ] <
static_cast<double>(_ext.z)) && (p[
ML_VC] <
static_cast<double>(_ext.c)) &&
730 (p[
ML_VT] <
static_cast<double>(_ext.t)) && (p[
ML_VU] <
static_cast<double>(_ext.u)) && (p[
ML_VX] >= 0.) &&
743 inline bool _isCursorAtEnd1D()
const
745 return (_cursorPos.x == _extM1.x);
747 inline bool _isCursorAtEnd2D()
const
749 return (_cursorPos.x == _extM1.x) && (_cursorPos.y == _extM1.y);
751 inline bool _isCursorAtEnd3D()
const
753 return (_cursorPos.x == _extM1.x) && (_cursorPos.y == _extM1.y) && (_cursorPos.z == _extM1.z);
755 inline bool _isCursorAtEnd4D()
const
757 return (_cursorPos.x == _extM1.x) && (_cursorPos.y == _extM1.y) && (_cursorPos.z == _extM1.z) &&
758 (_cursorPos.c == _extM1.c);
760 inline bool _isCursorAtEnd5D()
const
762 return (_cursorPos.x == _extM1.x) && (_cursorPos.y == _extM1.y) && (_cursorPos.z == _extM1.z) &&
763 (_cursorPos.c == _extM1.c) && (_cursorPos.t == _extM1.t);
765 inline bool _isCursorAtEnd6D()
const
767 return (_cursorPos.x == _extM1.x) && (_cursorPos.y == _extM1.y) && (_cursorPos.z == _extM1.z) &&
768 (_cursorPos.c == _extM1.c) && (_cursorPos.t == _extM1.t) && (_cursorPos.u == _extM1.u);
790 inline void _moveCursorF1N()
795 inline void _moveCursorF2N()
798 _cursorBitIdx +=
static_cast<MLuint64>(_strides.y);
800 inline void _moveCursorF3N()
803 _cursorBitIdx +=
static_cast<MLuint64>(_strides.z);
805 inline void _moveCursorF4N()
808 _cursorBitIdx +=
static_cast<MLuint64>(_strides.c);
810 inline void _moveCursorF5N()
813 _cursorBitIdx +=
static_cast<MLuint64>(_strides.t);
815 inline void _moveCursorF6N()
818 _cursorBitIdx +=
static_cast<MLuint64>(_strides.u);
825 inline void _moveCursorF1E()
827 if (_cursorPos.x >= _extM1.x) {
832 inline void _moveCursorF2E()
834 if (_cursorPos.y >= _extM1.y) {
839 inline void _moveCursorF3E()
841 if (_cursorPos.z >= _extM1.z) {
846 inline void _moveCursorF4E()
848 if (_cursorPos.c >= _extM1.c) {
853 inline void _moveCursorF5E()
855 if (_cursorPos.t >= _extM1.t) {
860 inline void _moveCursorF6E()
862 if (_cursorPos.u >= _extM1.u) {
876 inline void _moveCursorB1N()
881 inline void _moveCursorB2N()
884 _cursorBitIdx -=
static_cast<MLuint64>(_strides.y);
886 inline void _moveCursorB3N()
889 _cursorBitIdx -=
static_cast<MLuint64>(_strides.z);
891 inline void _moveCursorB4N()
894 _cursorBitIdx -=
static_cast<MLuint64>(_strides.c);
896 inline void _moveCursorB5N()
899 _cursorBitIdx -=
static_cast<MLuint64>(_strides.t);
901 inline void _moveCursorB6N()
904 _cursorBitIdx -=
static_cast<MLuint64>(_strides.u);
911 inline void _moveCursorB1E()
918 inline void _moveCursorB2E()
925 inline void _moveCursorB3E()
932 inline void _moveCursorB4E()
939 inline void _moveCursorB5E()
946 inline void _moveCursorB6E()
958 inline void _setCursorPos(
const ImageVector& pos)
960 if (_useExceptions && !isInRange(pos)) {
963 _cursorBitIdx =
_bitIdx(
this, pos);
1001 bool _useExceptions;
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Class to manage a binary image.
const ImageVector & getExtent() const
Return image size. Never throws controlled diagnostic exceptions.
ML_BIT_IMG_DATA_TYPE * getImageMemory()
Provide access to the BitImage memory.
bool useExceptionHandling() const
Return true if exception handling is on, otherwise return false.
bool operator[](const ImageVector &pos) const
Constant vector index read access to voxel value at position pos.
void reverseMoveCursorC()
MLTOOLS_EXPORT bool readFromFile(const std::string &path)
Reads a bit image from file specified by path and returns true on success, false on error.
void setCursorValue()
Sets the bit under the cursor to 1. Never throws controlled diagnostic exceptions.
void reverseMoveCursorZ()
const ImageVector & getStrides() const
MLTOOLS_EXPORT const BitImage & operator=(const BitImage &bitImg)
Assignment operator.
MLTOOLS_EXPORT void copyToBitImage(BitImage &dstBitImg, OperationModes mode=SET_MODE, const SubImageBox &box=SubImageBox(), const ImageVector &offset=ImageVector(0))
Copy all bits from the overlapping regions from box and *this to the position box....
const ImageVector & getCursorPosition() const
Return current cursor position. Never throws controlled diagnostic exceptions.
BitImage(const ImageVector &ext, bool useExceptions=false)
Convenience constructor.
MLTOOLS_EXPORT BitImage * getSubBitImageByMask(bool val, SubImageBox *maskedBox=nullptr)
Calculates the bounding box of all bits of value val and returns a new BitImage containing exactly th...
MLTOOLS_EXPORT void useExceptionHandling(bool useExceptions)
Pass true to enable exception handling, false to disable it.
MLTOOLS_EXPORT bool is64BitVersion() const
Returns true if any member or allocated buffer requires 64 handling, otherwise false is returned.
ML_BIT_IMG_DATA_TYPE getCursorWord() const
Return content of word in image to which the cursor points.
MLint getCursorBitIndex() const
Return strides for words. Never throws controlled diagnostic exceptions.
MLTOOLS_EXPORT bool writeToFile(const std::string &path, bool overwrite=true)
Writes bit image content into file specified by path path and return true on success and false on fai...
MLTOOLS_EXPORT void getStatistics(MLuint64 *numBits, MLuint64 *numSetBits, MLuint64 *numClearedBits)
MLTOOLS_EXPORT long updateBitImageFromVolume(const void *data, const MLDataType dType, const SubImageBox &origBox, const double minVal, const double maxVal, const unsigned char addBorderPixels=0)
Scan volume given by data and origBox and filter all values through the interval given by [minVal,...
void setCursorValue(const bool val)
Sets the bit under the cursor to 1 if true is passed as val, otherwise 0 is set.
void reverseMoveCursorT()
MLTOOLS_EXPORT SubImageBox calculateBoundingBox(bool val=true)
Calculates the bounding box of all bits of value val (default is true).
void clearCursorValue()
Clears the bit under the cursor to 0. Never throws controlled diagnostic exceptions.
void reverseMoveCursorX()
size_t getCursorWordIndex() const
Return index to word in image to which the cursor points. Never throws controlled diagnostic exceptio...
ML_BIT_IMG_DATA_TYPE getCursorBitMask() const
Return the bit mask specifying the bit in the cursor word. Never throws controlled diagnostic excepti...
MLTOOLS_EXPORT void invert(const SubImageBox &box)
Toggle the area given by box in the bit image.
bool isEmpty() const
Returns true if image is empty. Never throws controlled diagnostic exceptions.
static MLTOOLS_EXPORT MLuint32 selfTest()
Starts a self test of the mlBitImage class.
MLTOOLS_EXPORT MLErrorCode load(const std::string &path)
Read bit image from file specified by path and returns ML_RESULT_OK success or another error code in ...
MLTOOLS_EXPORT void copyFromSubImage(SubImage &inImg, const SubImageBox &box, const ImageVector &pos, const double intMin, const double intMax)
Copy the area given by box from inImg to the position p of the bitImage.
@ AND_MODE
values are anded to/with target values.
@ OR_MODE
values are ored to target values.
@ CLEAR_MODE
set bits in values are cleared in target values.
@ XOR_MODE
values are xored to/with target values.
bool isSet(const ImageVector &pos) const
Return true if bit at position pos is set; otherwise, it returns false.
void toggleCursorValue()
Toggles the bit under the cursor. Never throws controlled diagnostic exceptions.
bool isInRange(const Vector6 &p) const
Test for Vector6 coordinates in valid range.
void setSourceBox(const SubImageBox &box)
Sets the original placement of the bit image corresponding to a potential image the bit image is crea...
MLTOOLS_EXPORT BitImage(const BitImage &bitImg)
Copy constructor, copies bitImg to this instance.
void set(const ImageVector &pos)
Set bit at position pos optimized for all extents of a bit image.
MLTOOLS_EXPORT bool moveCursorXWrapAround()
Special cursor move: Increment x coordinate of cursor.
MLTOOLS_EXPORT void copyToSubImage(SubImage &outSubImg, const double bkVal, const double fgVal, const OperationModes mode=SET_MODE) const
Copy area from the bit image into the subimage given by outSubImg.
void reverseMoveCursorY()
void reverseMoveCursorU()
void reset()
Make image empty and restore default construction state with disabled exceptions.
bool isInRange(const ImageVector &p) const
Test for ImageVector coordinates in valid range.
bool getCursorValue() const
Return true if bit under cursor is true; otherwise, it returns false.
const SubImageBox getBoxFromImageExtent() const
Return a SubImageBox representing the image extent of the BitImage.
size_t getNumberOfAllocatedImageMemoryWords() const
Returns the number of currently allocated ML_BIT_IMG_DATA_TYPE words.
BitImage(bool useExceptions=false)
MLTOOLS_EXPORT void fill(const SubImageBox &box, const bool value)
Fill the area given by box in the bit image with value value.
void clear(const ImageVector &pos)
Clear bit at position pos optimized for all extents of a bit image.
void setValue(const ImageVector &pos, const bool v)
Set bit at position pos to value v.
MLTOOLS_EXPORT ~BitImage() override
Destructor. Never throws controlled diagnostic exceptions.
const SubImageBox & getSourceBox() const
Returns the original placement of the bit image corresponding to a potential image the bit image is c...
MLTOOLS_EXPORT MLErrorCode save(const std::string &path, bool overwrite=true)
Writes bit image content into file specified by path.
void setCursorPosition(const ImageVector &pos)
MLTOOLS_EXPORT void resetCursor()
void toggle(const ImageVector &pos)
Toggle bit at position pos.
MLTOOLS_EXPORT BitImage * getDownScaledBitImage(const ImageVector &scales) const
Create a down scaled mlBitImage from this.
bool setExtent(const ImageVector &ext)
void clear(bool val)
Clears/sets all bits in the image. Never throws controlled diagnostic exceptions.
This class manages/represents a rectangular 6D image region that is organized linearly in memory.
MLint32 MLDataType
MLDataType.
#define ML_OUT_OF_RANGE
Any coordinate or value is out of range, often a voxel address that is outside of an image or it is e...
MLint32 MLErrorCode
Type of an ML Error code.
#define ML_BIT_IMG_DATA_TYPE
Data type used for words in bit image (even on 64 bit versions).
#define ML_BIT_IMG_ALL_BITS
Bit mask specifying all bits in bit image word e.g. 32 set bits for 32 bit words.
#define ML_BIT_IMG_SHIFT
Power of 2 to get bit size of word of bit image, e.g. 5 for 32 bit words.
#define ML_BIT_IMG_BIT_IDX_TYPE
Data type used for an index to the current bit inside of the image; note that this may exceed the add...
#define ML_BIT_IMG_LOW_BIT
Bit image word with lowest bit set.
#define ML_BIT_IMG_INDEX_BITS
Bits to mask lower ML_BIT_IMG_SHIFT bits, e.g. 0x1f = 31 for 2^5 = 32 bits in word.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#define ML_CLASS_HEADER_EXPORTED(className, EXP_SYM)
This macro has to be put into the header of a non-abstract class to declare some additional methods d...
UINT64 MLuint64
Introduce platform-independent 64-bit unsigned integer type.
@ ML_VT
Array index for t (time) components (entry 4)
@ ML_VC
Array index for c (color) components (entry 3)
@ ML_VY
Array index for y components (entry 1)
@ ML_VU
Array index for u (unit/user dimension) components (entry 5)
@ ML_VZ
Array index for z components (entry 2)
@ ML_VX
Array index for x components (entry 0)
MLuint64 MLuint
An unsigned ML integer type with at least 64 bits used for index calculations on very large images ev...
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
#define IMPLEMENT_EXC_DISPATCHER_P0(FUNC_NAME, CLASS_NAME, RET_TYPE, RET_COMMAND)
This macro defines a function type and 12 static functions of this type.
#define ML_EMPTY_SPACE
In this header some macros are defined which implement some c-wrapper stuff to address member functio...
#define IMPLEMENT_DIM_DISPATCHER_P0(FUNC_NAME, CLASS_NAME, RET_TYPE, RET_COMMAND)
This macro defines a function type and six static functions of this type.
#define IMPLEMENT_DIM_DISPATCHER_P1(FUNC_NAME, CLASS_NAME, RET_TYPE, RET_COMMAND, P_TYPE)
For documentation see IMPLEMENT_DIM_DISPATCHER_P0.
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.