MeVisLab Toolbox Reference
mlBitImage.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_BIT_IMAGE_H
14#define ML_BIT_IMAGE_H
15
16
28
32
33// ML-includes
34#include "MLToolsSystem.h"
35#include "mlModuleIncludes.h"
36#include "mlWrapperMacros.h"
37
39
41#define ML_BIT_IMG_SHIFT 5l
42
44#define ML_BIT_IMG_ALL_BITS 0xffffffffl
45
47#define ML_BIT_IMG_INDEX_BITS 0x1fl
48
50#define ML_BIT_IMG_LOW_BIT 0x00000001l
51
53#define ML_BIT_IMG_HIGH_BIT 0x80000000l
54
56#define ML_BIT_IMG_DATA_TYPE MLuint32
57
62#define ML_BIT_IMG_BIT_IDX_TYPE MLuint64
63
64 //----------------------------------------------------------------------------------
66 //----------------------------------------------------------------------------------
68
69 public:
70
73 enum OperationModes { SET_MODE = 0,
78
79 NUM_MODES
80 };
81
82
89 inline BitImage(bool useExceptions=false) { _init(ImageVector(0), useExceptions); }
90
96 inline BitImage(const ImageVector &ext, bool useExceptions=false) { _init(ext, useExceptions); }
97
104
106 MLTOOLS_EXPORT ~BitImage() override { _reset(); }
107
110 inline void reset() { _reset(); }
111
114 inline bool useExceptionHandling() const { return _useExceptions; }
115
119
126
127
140 inline bool setExtent(const ImageVector &ext)
141 {
142 bool result = _setExt(ext);
143
144 clear(false); //initialize content to zero
145
146 return result;
147 }
148
150 inline const ImageVector &getExtent() const { return _ext; }
151
153 inline const SubImageBox getBoxFromImageExtent() const { return SubImageBox(_ext); }
154
162 inline const SubImageBox &getSourceBox() const { return _sourceBox; }
163
171 inline void setSourceBox(const SubImageBox &box) { _sourceBox = box; }
173
174
175
180 inline const ImageVector &getStrides() const { return _strides; }
181
183 inline MLint getCursorBitIndex() const { return static_cast<MLint>(_cursorBitIdx); }
184
186 inline bool isEmpty() const { return _ext.compMul() == 0; }
187
189 inline void clear(bool val) { if (nullptr != _image){ memset(_image, val ? 0xff : 0, _numBytes); } }
191
192
195
199 inline bool operator[](const ImageVector &pos) const { return isSet(pos); }
200
204 inline void setValue(const ImageVector &pos, const bool v) { if (v){ set(pos); } else { clear(pos); } }
205
209 inline void set(const ImageVector &pos) { const MLuint b=_bitIdx(this, pos); _image[b >> ML_BIT_IMG_SHIFT] |= static_cast<ML_BIT_IMG_DATA_TYPE>(ML_BIT_IMG_LOW_BIT << (b & ML_BIT_IMG_INDEX_BITS)); }
210
214 inline void clear(const ImageVector &pos) { const MLuint b = _bitIdx(this, pos); _image[b >> ML_BIT_IMG_SHIFT] &= static_cast<ML_BIT_IMG_DATA_TYPE>(ML_BIT_IMG_ALL_BITS ^ (ML_BIT_IMG_LOW_BIT << (b & ML_BIT_IMG_INDEX_BITS))); }
215
219 inline void toggle(const ImageVector &pos) { const MLuint b=_bitIdx(this, pos); _image[b >> ML_BIT_IMG_SHIFT] ^= static_cast<ML_BIT_IMG_DATA_TYPE>(ML_BIT_IMG_LOW_BIT << (b & ML_BIT_IMG_INDEX_BITS)); }
220
224 inline bool isSet(const ImageVector &pos) const { const MLuint b=_bitIdx(this, pos); return (_image[b >> ML_BIT_IMG_SHIFT] & (ML_BIT_IMG_LOW_BIT << (b & ML_BIT_IMG_INDEX_BITS)))!=0; }
225
228 inline bool isInRange(const ImageVector &p) const { return _isInRangeVector(this, p); }
229
232 inline bool isInRange(const Vector6 &p) const { return _isInRangeVec6(this, p); }
234
235
241 inline void setCursorPosition(const ImageVector &pos) { _setCursorPos(pos); }
242
244 inline const ImageVector &getCursorPosition() const { return _cursorPos; }
245
247 inline bool getCursorValue() const { return (_image[static_cast<size_t>(_cursorBitIdx >> ML_BIT_IMG_SHIFT)] & (ML_BIT_IMG_LOW_BIT << (_cursorBitIdx & ML_BIT_IMG_INDEX_BITS))) != 0; }
248
250 inline void setCursorValue(const bool val) { if (val){ setCursorValue(); } else{ clearCursorValue(); } }
251
253 inline void setCursorValue() { _image[static_cast<size_t>(_cursorBitIdx >> ML_BIT_IMG_SHIFT)] |= static_cast<ML_BIT_IMG_DATA_TYPE>((ML_BIT_IMG_LOW_BIT << (_cursorBitIdx & ML_BIT_IMG_INDEX_BITS))); }
254
256 inline void toggleCursorValue() { _image[static_cast<size_t>(_cursorBitIdx >> ML_BIT_IMG_SHIFT)] ^= static_cast<ML_BIT_IMG_DATA_TYPE>((ML_BIT_IMG_LOW_BIT << (_cursorBitIdx & ML_BIT_IMG_INDEX_BITS))); }
257
259 inline void clearCursorValue() { _image[static_cast<size_t>(_cursorBitIdx >> ML_BIT_IMG_SHIFT)] &= static_cast<ML_BIT_IMG_DATA_TYPE>((ML_BIT_IMG_ALL_BITS ^ (ML_BIT_IMG_LOW_BIT << (_cursorBitIdx & ML_BIT_IMG_INDEX_BITS)))); }
260
262 inline size_t getCursorWordIndex() const { return static_cast<size_t>(_cursorBitIdx >> ML_BIT_IMG_SHIFT); }
263
266 inline ML_BIT_IMG_DATA_TYPE getCursorWord() const { return _image[static_cast<size_t>(_cursorBitIdx >> ML_BIT_IMG_SHIFT)]; }
267
269 inline ML_BIT_IMG_DATA_TYPE getCursorBitMask() const { return (static_cast<ML_BIT_IMG_DATA_TYPE>(ML_BIT_IMG_LOW_BIT << (_cursorBitIdx & ML_BIT_IMG_INDEX_BITS))); }
271
274 inline void moveCursorX() { _moveCursorF1(this); }
275 inline void moveCursorY() { _moveCursorF2(this); }
276 inline void moveCursorZ() { _moveCursorF3(this); }
277 inline void moveCursorC() { _moveCursorF4(this); }
278 inline void moveCursorT() { _moveCursorF5(this); }
279 inline void moveCursorU() { _moveCursorF6(this); }
281
284 inline void reverseMoveCursorX() { _moveCursorB1(this); }
285 inline void reverseMoveCursorY() { _moveCursorB2(this); }
286 inline void reverseMoveCursorZ() { _moveCursorB3(this); }
287 inline void reverseMoveCursorC() { _moveCursorB4(this); }
288 inline void reverseMoveCursorT() { _moveCursorB5(this); }
289 inline void reverseMoveCursorU() { _moveCursorB6(this); }
291
298
311
317
327
343 const MLDataType dType,
344 const SubImageBox &origBox,
345 const double minVal,
346 const double maxVal,
347 const unsigned char addBorderPixels=0);
348
352
362 OperationModes mode = SET_MODE,
363 const SubImageBox& box = SubImageBox(),
364 const ImageVector& offset = ImageVector(0));
365
372 SubImageBox *maskedBox=nullptr);
374
375
378
382 MLTOOLS_EXPORT void fill(const SubImageBox &box, const bool value);
383
388
401 const double bkVal,
402 const double fgVal,
403 const OperationModes mode=SET_MODE) const;
404
405
413 const SubImageBox &box,
414 const ImageVector &pos,
415 const double intMin,
416 const double intMax);
418
419
420
423
427
434 MLTOOLS_EXPORT bool writeToFile(const std::string &path, bool overwrite=true);
435
441 MLTOOLS_EXPORT MLErrorCode save(const std::string &path, bool overwrite=true);
442
443
447 MLTOOLS_EXPORT bool readFromFile(const std::string &path);
448
452 MLTOOLS_EXPORT MLErrorCode load(const std::string &path);
454
456
460 inline ML_BIT_IMG_DATA_TYPE *getImageMemory() { return _image; }
461
463 inline size_t getNumberOfAllocatedImageMemoryWords() const { return _numWords; }
465
469
470 private:
471
475
478 inline ML_BIT_IMG_BIT_IDX_TYPE _bitIdx1D(const ImageVector &pos) const { return static_cast<ML_BIT_IMG_BIT_IDX_TYPE>(_strides.x*pos.x); }
479 inline ML_BIT_IMG_BIT_IDX_TYPE _bitIdx2D(const ImageVector &pos) const { return static_cast<ML_BIT_IMG_BIT_IDX_TYPE>(_strides.x*pos.x + _strides.y*pos.y); }
480 inline ML_BIT_IMG_BIT_IDX_TYPE _bitIdx3D(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); }
481 inline ML_BIT_IMG_BIT_IDX_TYPE _bitIdx4D(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); }
482 inline ML_BIT_IMG_BIT_IDX_TYPE _bitIdx5D(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); }
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); }
485
488 IMPLEMENT_DIM_DISPATCHER_P1(_isInRangeVector, const BitImage, bool, return, const ImageVector &);
489
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); }
499
500
501
504 IMPLEMENT_DIM_DISPATCHER_P1(_isInRangeVec6, const BitImage, bool, return, const Vector6 &);
505
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.); }
515
516
517
520 IMPLEMENT_DIM_DISPATCHER_P0(_isCursorAtEnd, const BitImage, bool, return);
521
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); }
531
532
533
537
538 // In the following 40 lines expressions such as
539 // _cursorBitIdx += static_cast<MLuint64>(_strides.y);
540 // or
541 // _cursorBitIdx += static_cast<MLuint64>(_strides.y);
542 // are performed with casts to unsigned MLuint64 values, because according to C-standard
543 // the signed values are cast to unsigned int 64 before subtracting anyway; and this
544 // which is warned by compilers.
545 // Therefore the cast is done explicitly, which is okay, when considering that negative
546 // signed values are cast, converted to usually large unsigned values which are added
547 // with overflows resulting to the same value.
548
551 inline void _moveCursorF1N() { ++_cursorPos.x; _cursorBitIdx++; }
552 inline void _moveCursorF2N() { ++_cursorPos.y; _cursorBitIdx += static_cast<MLuint64>(_strides.y); } // See cast notes above.
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); }
558
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(); }
568
569
570
574
577 inline void _moveCursorB1N() { --_cursorPos.x; _cursorBitIdx--; }
578 inline void _moveCursorB2N() { --_cursorPos.y; _cursorBitIdx -= static_cast<MLuint64>(_strides.y); } // See cast notes above.
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); }
584
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(); }
594
598 inline void _setCursorPos(const ImageVector &pos)
599 { if (_useExceptions && !isInRange(pos)){ throw(ML_OUT_OF_RANGE); }
600 _cursorBitIdx = _bitIdx(this, pos);
601 _cursorPos = pos;
602 }
603
608 MLTOOLS_EXPORT bool _init(const ImageVector &ext, bool useExceptions);
609
611 MLTOOLS_EXPORT void _reset();
612
618 MLTOOLS_EXPORT void _updateFunctionPointers(const ImageVector &ext, bool useExceptions);
619
628 MLTOOLS_EXPORT bool _setExt(const ImageVector &ext);
629
630 //------------------------------------------------------
631 // Members
632 //------------------------------------------------------
633
635 ML_BIT_IMG_DATA_TYPE *_image;
636
638 bool _useExceptions;
639
641 ImageVector _ext;
642
644 ImageVector _extM1;
645
652 SubImageBox _sourceBox;
653
655 ImageVector _strides;
656
658 size_t _numWords;
659
661 size_t _numBytes;
662
664 ML_BIT_IMG_BIT_IDX_TYPE _cursorBitIdx;
665
667 ImageVector _cursorPos;
668
671
672 }; // class mlBitImage
673
675
676#endif // __mlBitImage_H
#define MLTOOLS_EXPORT
Resolves system dependencies for this project.
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition mlBase.h:59
Class to manage a binary image.
Definition mlBitImage.h:67
const ImageVector & getExtent() const
Return image size. Never throws controlled diagnostic exceptions.
Definition mlBitImage.h:150
ML_BIT_IMG_DATA_TYPE * getImageMemory()
Provide access to the BitImage memory.
Definition mlBitImage.h:460
void moveCursorC()
Definition mlBitImage.h:277
bool useExceptionHandling() const
Return true if exception handling is on, otherwise return false.
Definition mlBitImage.h:114
bool operator[](const ImageVector &pos) const
Constant vector index read access to voxel value at position pos.
Definition mlBitImage.h:199
void reverseMoveCursorC()
Definition mlBitImage.h:287
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.
Definition mlBitImage.h:253
void moveCursorU()
Definition mlBitImage.h:279
void reverseMoveCursorZ()
Definition mlBitImage.h:286
const ImageVector & getStrides() const
Definition mlBitImage.h:180
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.
Definition mlBitImage.h:244
BitImage(const ImageVector &ext, bool useExceptions=false)
Convenience constructor.
Definition mlBitImage.h:96
void moveCursorY()
Definition mlBitImage.h:275
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.
Definition mlBitImage.h:266
MLint getCursorBitIndex() const
Return strides for words. Never throws controlled diagnostic exceptions.
Definition mlBitImage.h:183
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...
Definition mlBitImage.h:250
void reverseMoveCursorT()
Definition mlBitImage.h:288
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.
Definition mlBitImage.h:259
void reverseMoveCursorX()
Definition mlBitImage.h:284
size_t getCursorWordIndex() const
Return index to word in image to which the cursor points. Never throws controlled diagnostic exceptio...
Definition mlBitImage.h:262
ML_BIT_IMG_DATA_TYPE getCursorBitMask() const
Return the bit mask specifying the bit in the cursor word. Never throws controlled diagnostic excepti...
Definition mlBitImage.h:269
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.
Definition mlBitImage.h:186
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.
Definition mlBitImage.h:75
@ OR_MODE
values are ored to target values.
Definition mlBitImage.h:74
@ CLEAR_MODE
set bits in values are cleared in target values.
Definition mlBitImage.h:77
@ XOR_MODE
values are xored to/with target values.
Definition mlBitImage.h:76
bool isSet(const ImageVector &pos) const
Return true if bit at position pos is set, otherwise false.
Definition mlBitImage.h:224
void toggleCursorValue()
Toggles the bit under the cursor. Never throws controlled diagnostic exceptions.
Definition mlBitImage.h:256
bool isInRange(const Vector6 &p) const
Test for Vector6 coordinates in valid range.
Definition mlBitImage.h:232
void setSourceBox(const SubImageBox &box)
Sets the original placement of the bit image corresponding to a potential image the bit image is crea...
Definition mlBitImage.h:171
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.
Definition mlBitImage.h:209
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()
Definition mlBitImage.h:285
void reverseMoveCursorU()
Definition mlBitImage.h:289
void moveCursorT()
Definition mlBitImage.h:278
void reset()
Make image empty and restore default construction state with disabled exceptions.
Definition mlBitImage.h:110
bool isInRange(const ImageVector &p) const
Test for ImageVector coordinates in valid range.
Definition mlBitImage.h:228
bool getCursorValue() const
Return true if bit under cursor is true, otherwise false. Never throws controlled diagnostic exceptio...
Definition mlBitImage.h:247
const SubImageBox getBoxFromImageExtent() const
Return a SubImageBox representing the image extent of the BitImage.
Definition mlBitImage.h:153
size_t getNumberOfAllocatedImageMemoryWords() const
Returns the number of currently allocated ML_BIT_IMG_DATA_TYPE words.
Definition mlBitImage.h:463
void moveCursorX()
Definition mlBitImage.h:274
BitImage(bool useExceptions=false)
Definition mlBitImage.h:89
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.
Definition mlBitImage.h:214
void setValue(const ImageVector &pos, const bool v)
Set bit at position pos to value v.
Definition mlBitImage.h:204
MLTOOLS_EXPORT ~BitImage() override
Destructor. Never throws controlled diagnostic exceptions.
Definition mlBitImage.h:106
void moveCursorZ()
Definition mlBitImage.h:276
const SubImageBox & getSourceBox() const
Returns the original placement of the bit image corresponding to a potential image the bit image is c...
Definition mlBitImage.h:162
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)
Definition mlBitImage.h:241
MLTOOLS_EXPORT void resetCursor()
void toggle(const ImageVector &pos)
Toggle bit at position pos.
Definition mlBitImage.h:219
MLTOOLS_EXPORT BitImage * getDownScaledBitImage(const ImageVector &scales) const
Create a down scaled mlBitImage from this.
bool setExtent(const ImageVector &ext)
Definition mlBitImage.h:140
void clear(bool val)
Clears/sets all bits in the image. Never throws controlled diagnostic exceptions.
Definition mlBitImage.h:189
This class manages/represents a rectangular 6d image region which is organized linearly in memory.
Definition mlSubImage.h:75
MLint32 MLDataType
MLDataType.
Definition mlTypeDefs.h:596
#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 ...
Definition mlTypeDefs.h:872
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:716
#define ML_BIT_IMG_DATA_TYPE
Data type used for words in bit image (even on 64 bit versions).
Definition mlBitImage.h:56
#define ML_BIT_IMG_ALL_BITS
Bit mask specifying all bits in bit image word e.g. 32 set bits for 32 bit words.
Definition mlBitImage.h:44
#define ML_BIT_IMG_SHIFT
Power of 2 to get bit size of word of bit image, e.g. 5 for 32 bit words.
Definition mlBitImage.h:41
#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...
Definition mlBitImage.h:62
#define ML_BIT_IMG_LOW_BIT
Bit image word with lowest bit set.
Definition mlBitImage.h:50
#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.
Definition mlBitImage.h:47
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.
Definition mlTypeDefs.h:425
unsigned int MLuint32
Definition mlTypeDefs.h:185
@ 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...
Definition mlTypeDefs.h:506
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition mlTypeDefs.h:490
#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.