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
142 bool result = _setExt(ext);
186 inline bool isEmpty()
const {
return _ext.compMul() == 0; }
189 inline void clear(
bool val) {
if (
nullptr != _image){ memset(_image, val ? 0xff : 0, _numBytes); } }
347 const unsigned char addBorderPixels=0);
416 const double intMax);
483 inline ML_BIT_IMG_BIT_IDX_TYPE _bitIdx6D(
const ImageVector &pos)
const {
return static_cast<ML_BIT_IMG_BIT_IDX_TYPE>(_strides.x*pos.x + _strides.y*pos.y + _strides.z*pos.z + _strides.c*pos.c + _strides.t*pos.t + _strides.u*pos.u); }
492 inline bool _isInRangeVector1D(
const ImageVector &p)
const {
return (p.x<_ext.x) && (p.x>=0); }
493 inline bool _isInRangeVector2D(
const ImageVector &p)
const {
return (p.x<_ext.x) && (p.y<_ext.y) && (p.x>=0) && (p.y>=0); }
494 inline bool _isInRangeVector3D(
const ImageVector &p)
const {
return (p.x<_ext.x) && (p.y<_ext.y) && (p.z<_ext.z) && (p.x>=0) && (p.y>=0) && (p.z>=0); }
495 inline bool _isInRangeVector4D(
const ImageVector &p)
const {
return (p.x<_ext.x) && (p.y<_ext.y) && (p.z<_ext.z) && (p.c<_ext.c) && (p.x>=0) && (p.y>=0) && (p.z>=0) && (p.c>=0); }
496 inline bool _isInRangeVector5D(
const ImageVector &p)
const {
return (p.x<_ext.x) && (p.y<_ext.y) && (p.z<_ext.z) && (p.c<_ext.c) && (p.t<_ext.t) && (p.x>=0) && (p.y>=0) && (p.z>=0) && (p.c>=0) && (p.t>=0); }
497 inline bool _isInRangeVector6D(
const ImageVector &p)
const {
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) && (p.x>=0) && (p.y>=0) && (p.z>=0) && (p.c>=0) && (p.t>=0) && (p.u>=0); }
508 inline bool _isInRangeVec61D(
const Vector6 &p)
const {
return (p[
ML_VX]<
static_cast<double>(_ext.x)) && (p[
ML_VX]>=0.); }
509 inline bool _isInRangeVec62D(
const Vector6 &p)
const {
return (p[
ML_VX]<
static_cast<double>(_ext.x)) && (p[
ML_VY]<
static_cast<double>(_ext.y)) && (p[
ML_VX]>=0.) && (p[
ML_VY]>=0.); }
510 inline bool _isInRangeVec63D(
const Vector6 &p)
const {
return (p[
ML_VX]<
static_cast<double>(_ext.x)) && (p[
ML_VY]<
static_cast<double>(_ext.y)) && (p[
ML_VZ]<
static_cast<double>(_ext.z)) && (p[
ML_VX]>=0.) && (p[
ML_VY]>=0.) && (p[
ML_VZ]>=0.); }
511 inline bool _isInRangeVec64D(
const Vector6 &p)
const {
return (p[
ML_VX]<
static_cast<double>(_ext.x)) && (p[
ML_VY]<
static_cast<double>(_ext.y)) && (p[
ML_VZ]<
static_cast<double>(_ext.z)) && (p[
ML_VC]<
static_cast<double>(_ext.c)) && (p[
ML_VX]>=0.) && (p[
ML_VY]>=0.) && (p[
ML_VZ]>=0.) && (p[
ML_VC]>=0.); }
512 inline bool _isInRangeVec65D(
const Vector6 &p)
const {
return (p[
ML_VX]<
static_cast<double>(_ext.x)) && (p[
ML_VY]<
static_cast<double>(_ext.y)) && (p[
ML_VZ]<
static_cast<double>(_ext.z)) && (p[
ML_VC]<
static_cast<double>(_ext.c)) && (p[
ML_VT]<
static_cast<double>(_ext.t)) && (p[
ML_VX]>=0.) && (p[
ML_VY]>=0.) && (p[
ML_VZ]>=0.) && (p[
ML_VC]>=0.) && (p[
ML_VT]>=0.); }
513 inline bool _isInRangeVec66D(
const Vector6 &p)
const {
return (p[
ML_VX]<
static_cast<double>(_ext.x)) && (p[
ML_VY]<
static_cast<double>(_ext.y)) && (p[
ML_VZ]<
static_cast<double>(_ext.z)) && (p[
ML_VC]<
static_cast<double>(_ext.c)) && (p[
ML_VT]<
static_cast<double>(_ext.t)) && (p[
ML_VU]<
static_cast<double>(_ext.u)) && (p[
ML_VX]>=0.) && (p[
ML_VY]>=0.) && (p[
ML_VZ]>=0.) && (p[
ML_VC]>=0.) && (p[
ML_VT]>=0.) && (p[
ML_VU]>=0.); }
524 inline bool _isCursorAtEnd1D()
const {
return (_cursorPos.x == _extM1.x); }
525 inline bool _isCursorAtEnd2D()
const {
return (_cursorPos.x == _extM1.x) && (_cursorPos.y == _extM1.y); }
526 inline bool _isCursorAtEnd3D()
const {
return (_cursorPos.x == _extM1.x) && (_cursorPos.y == _extM1.y) && (_cursorPos.z == _extM1.z); }
527 inline bool _isCursorAtEnd4D()
const {
return (_cursorPos.x == _extM1.x) && (_cursorPos.y == _extM1.y) && (_cursorPos.z == _extM1.z) && (_cursorPos.c == _extM1.c); }
528 inline bool _isCursorAtEnd5D()
const {
return (_cursorPos.x == _extM1.x) && (_cursorPos.y == _extM1.y) && (_cursorPos.z == _extM1.z) && (_cursorPos.c == _extM1.c) && (_cursorPos.t == _extM1.t); }
529 inline bool _isCursorAtEnd6D()
const {
return (_cursorPos.x == _extM1.x) && (_cursorPos.y == _extM1.y) && (_cursorPos.z == _extM1.z) && (_cursorPos.c == _extM1.c) && (_cursorPos.t == _extM1.t) && (_cursorPos.u == _extM1.u); }
551 inline void _moveCursorF1N() { ++_cursorPos.x; _cursorBitIdx++; }
552 inline void _moveCursorF2N() { ++_cursorPos.y; _cursorBitIdx +=
static_cast<MLuint64>(_strides.y); }
553 inline void _moveCursorF3N() { ++_cursorPos.z; _cursorBitIdx +=
static_cast<MLuint64>(_strides.z); }
554 inline void _moveCursorF4N() { ++_cursorPos.c; _cursorBitIdx +=
static_cast<MLuint64>(_strides.c); }
555 inline void _moveCursorF5N() { ++_cursorPos.t; _cursorBitIdx +=
static_cast<MLuint64>(_strides.t); }
556 inline void _moveCursorF6N() { ++_cursorPos.u; _cursorBitIdx +=
static_cast<MLuint64>(_strides.u); }
561 inline void _moveCursorF1E() {
if (_cursorPos.x >= _extM1.x){
throw(
ML_OUT_OF_RANGE); } _moveCursorF1N(); }
562 inline void _moveCursorF2E() {
if (_cursorPos.y >= _extM1.y){
throw(
ML_OUT_OF_RANGE); } _moveCursorF2N(); }
563 inline void _moveCursorF3E() {
if (_cursorPos.z >= _extM1.z){
throw(
ML_OUT_OF_RANGE); } _moveCursorF3N(); }
564 inline void _moveCursorF4E() {
if (_cursorPos.c >= _extM1.c){
throw(
ML_OUT_OF_RANGE); } _moveCursorF4N(); }
565 inline void _moveCursorF5E() {
if (_cursorPos.t >= _extM1.t){
throw(
ML_OUT_OF_RANGE); } _moveCursorF5N(); }
566 inline void _moveCursorF6E() {
if (_cursorPos.u >= _extM1.u){
throw(
ML_OUT_OF_RANGE); } _moveCursorF6N(); }
577 inline void _moveCursorB1N() { --_cursorPos.x; _cursorBitIdx--; }
578 inline void _moveCursorB2N() { --_cursorPos.y; _cursorBitIdx -=
static_cast<MLuint64>(_strides.y); }
579 inline void _moveCursorB3N() { --_cursorPos.z; _cursorBitIdx -=
static_cast<MLuint64>(_strides.z); }
580 inline void _moveCursorB4N() { --_cursorPos.c; _cursorBitIdx -=
static_cast<MLuint64>(_strides.c); }
581 inline void _moveCursorB5N() { --_cursorPos.t; _cursorBitIdx -=
static_cast<MLuint64>(_strides.t); }
582 inline void _moveCursorB6N() { --_cursorPos.u; _cursorBitIdx -=
static_cast<MLuint64>(_strides.u); }
587 inline void _moveCursorB1E() {
if (!_cursorPos.x){
throw(
ML_OUT_OF_RANGE); } _moveCursorB1N(); }
588 inline void _moveCursorB2E() {
if (!_cursorPos.y){
throw(
ML_OUT_OF_RANGE); } _moveCursorB2N(); }
589 inline void _moveCursorB3E() {
if (!_cursorPos.z){
throw(
ML_OUT_OF_RANGE); } _moveCursorB3N(); }
590 inline void _moveCursorB4E() {
if (!_cursorPos.c){
throw(
ML_OUT_OF_RANGE); } _moveCursorB4N(); }
591 inline void _moveCursorB5E() {
if (!_cursorPos.t){
throw(
ML_OUT_OF_RANGE); } _moveCursorB5N(); }
592 inline void _moveCursorB6E() {
if (!_cursorPos.u){
throw(
ML_OUT_OF_RANGE); } _moveCursorB6N(); }
598 inline void _setCursorPos(
const ImageVector &pos)
600 _cursorBitIdx = _bitIdx(
this, pos);
608 MLTOOLS_EXPORT bool _init(
const ImageVector &ext,
bool useExceptions);
618 MLTOOLS_EXPORT void _updateFunctionPointers(
const ImageVector &ext,
bool useExceptions);
const ImageVector & getExtent() const
Return image size. Never throws controlled diagnostic exceptions.
ML_BIT_IMG_DATA_TYPE * getImageMemory()
bool useExceptionHandling() const
bool operator[](const ImageVector &pos) const
void reverseMoveCursorC()
MLTOOLS_EXPORT bool readFromFile(const std::string &path)
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)
MLTOOLS_EXPORT void copyToBitImage(BitImage &dstBitImg, OperationModes mode=SET_MODE, const SubImageBox &box=SubImageBox(), const ImageVector &offset=ImageVector(0))
const ImageVector & getCursorPosition() const
Return current cursor position. Never throws controlled diagnostic exceptions.
BitImage(const ImageVector &ext, bool useExceptions=false)
MLTOOLS_EXPORT BitImage * getSubBitImageByMask(bool val, SubImageBox *maskedBox=nullptr)
MLTOOLS_EXPORT void useExceptionHandling(bool useExceptions)
MLTOOLS_EXPORT bool is64BitVersion() const
ML_BIT_IMG_DATA_TYPE getCursorWord() const
MLint getCursorBitIndex() const
Return strides for words. Never throws controlled diagnostic exceptions.
MLTOOLS_EXPORT bool writeToFile(const std::string &path, bool overwrite=true)
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)
void setCursorValue(const bool val)
Sets the bit under the cursor to 1 if true is passed as val, otherwise 0 is set. Never throws control...
void reverseMoveCursorT()
MLTOOLS_EXPORT SubImageBox calculateBoundingBox(bool val=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)
bool isEmpty() const
Returns true if image is empty. Never throws controlled diagnostic exceptions.
static MLTOOLS_EXPORT MLuint32 selfTest()
MLTOOLS_EXPORT MLErrorCode load(const std::string &path)
MLTOOLS_EXPORT void copyFromSubImage(SubImage &inImg, const SubImageBox &box, const ImageVector &pos, const double intMin, const double intMax)
@ 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.
@ NUM_MODES
number of OperationMode enums.
@ SET_MODE
values are written/replaced into target values.
bool isSet(const ImageVector &pos) const
void toggleCursorValue()
Toggles the bit under the cursor. Never throws controlled diagnostic exceptions.
bool isInRange(const Vector6 &p) const
void setSourceBox(const SubImageBox &box)
MLTOOLS_EXPORT BitImage(const BitImage &bitImg)
void set(const ImageVector &pos)
MLTOOLS_EXPORT bool moveCursorXWrapAround()
MLTOOLS_EXPORT void copyToSubImage(SubImage &outSubImg, const double bkVal, const double fgVal, const OperationModes mode=SET_MODE) const
void reverseMoveCursorY()
void reverseMoveCursorU()
bool isInRange(const ImageVector &p) const
bool getCursorValue() const
Return true if bit under cursor is true; otherwise, it returns false. Never throws controlled diagnos...
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)
void clear(const ImageVector &pos)
void setValue(const ImageVector &pos, const bool v)
MLTOOLS_EXPORT ~BitImage() override
Destructor. Never throws controlled diagnostic exceptions.
const SubImageBox & getSourceBox() const
MLTOOLS_EXPORT MLErrorCode save(const std::string &path, bool overwrite=true)
void setCursorPosition(const ImageVector &pos)
MLTOOLS_EXPORT void resetCursor()
void toggle(const ImageVector &pos)
MLTOOLS_EXPORT BitImage * getDownScaledBitImage(const ImageVector &scales) const
bool setExtent(const ImageVector &ext)
void clear(bool val)
Clears/sets all bits in the image. Never throws controlled diagnostic exceptions.
ComponentType x
X component of the vector.
ComponentType y
Y component of the vector.
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
#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.
#define ML_CLASS_HEADER_EXPORTED(className, EXP_SYM)
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).
#define IMPLEMENT_EXC_DISPATCHER_P0(FUNC_NAME, CLASS_NAME, RET_TYPE, RET_COMMAND)
#define ML_EMPTY_SPACE
A simple macro containing nothing to be passed as macro parameter which has no content.
#define IMPLEMENT_DIM_DISPATCHER_P0(FUNC_NAME, CLASS_NAME, RET_TYPE, RET_COMMAND)
#define IMPLEMENT_DIM_DISPATCHER_P1(FUNC_NAME, CLASS_NAME, RET_TYPE, RET_COMMAND, P_TYPE)
Tvec6< MLdouble > Vector6
A vector with six components of type double.
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.