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
186 inline bool isEmpty()
const {
return _ext.compMul() == 0; }
189 inline void clear(
bool val) {
if (
nullptr != _image){
memset(_image, val ? 0xff : 0, _numBytes); } }
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);
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. Never throws control...
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 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 false. Never throws controlled diagnostic exceptio...
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 which 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 which is outside of an image or it is ...
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
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.