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 
38 ML_START_NAMESPACE
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  //----------------------------------------------------------------------------------
67  class ML_UNIX_ONLY_EXPORT(MLTOOLS_EXPORT) BitImage : public Base {
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 
118  MLTOOLS_EXPORT void useExceptionHandling(bool useExceptions);
119 
124  MLTOOLS_EXPORT const BitImage &operator=(const BitImage &bitImg);
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 
316  MLTOOLS_EXPORT void getStatistics(MLuint64 *numBits, MLuint64 *numSetBits, MLuint64 *numClearedBits);
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 #if ML_DEPRECATED_SINCE(3,5,0)
471 
474 
475  public:
478  inline ML_DEPRECATED bool setExt(const ImageVector &ext) { return setExtent(ext); }
479 
482  inline ML_DEPRECATED const ImageVector &getExt() const { return getExtent(); }
483 
486  inline ML_DEPRECATED SubImageBox getBoxFromImgExt() const { return getBoxFromImageExtent(); }
487 
490  inline ML_DEPRECATED MLint getCursorBitIdx() const { return getCursorBitIndex(); }
491 
494  inline ML_DEPRECATED void copyToSubImg(SubImage &outSubImg,
495  const double bkVal,
496  const double fgVal,
497  const OperationModes mode=SET_MODE) const { copyToSubImage(outSubImg, bkVal, fgVal, mode); }
498 
501  inline ML_DEPRECATED void copyFromSubImg(SubImage &inImg,
502  const SubImageBox &box,
503  const ImageVector &pos,
504  const double intMin,
505  const double intMax) { copyFromSubImage(inImg, box, pos, intMin, intMax); }
506 
509  inline ML_DEPRECATED SubImageBox calcBoundingBox(bool val=true) { return calculateBoundingBox(val); }
510 
513  inline ML_DEPRECATED void setCursorPos(const ImageVector &pos) { setCursorPosition(pos); }
514 
517  inline ML_DEPRECATED const ImageVector& getCursorPos() const { return getCursorPosition(); }
518 
521  inline ML_DEPRECATED void moveFX() { moveCursorX(); }
522 
525  inline ML_DEPRECATED void moveFY() { moveCursorY(); }
526 
529  inline ML_DEPRECATED void moveFZ() { moveCursorZ(); }
530 
533  inline ML_DEPRECATED void moveFC() { moveCursorC(); }
534 
537  inline ML_DEPRECATED void moveFT() { moveCursorT(); }
538 
541  inline ML_DEPRECATED void moveFU() { moveCursorU(); }
542 
545  inline ML_DEPRECATED void moveBX() { reverseMoveCursorX(); }
546 
549  inline ML_DEPRECATED void moveBY() { reverseMoveCursorY(); }
550 
553  inline ML_DEPRECATED void moveBZ() { reverseMoveCursorZ(); }
554 
557  inline ML_DEPRECATED void moveBC() { reverseMoveCursorC(); }
558 
561  inline ML_DEPRECATED void moveBT() { reverseMoveCursorT(); }
562 
565  inline ML_DEPRECATED void moveBU() { reverseMoveCursorU(); }
566 
569  inline ML_DEPRECATED bool moveCursorFXLF() { return moveCursorXWrapAround(); }
571 
572 #endif // ML_DEPRECATED
573 
574  private:
575 
578  IMPLEMENT_DIM_DISPATCHER_P1(_bitIdx, const BitImage, ML_BIT_IMG_BIT_IDX_TYPE, return, const ImageVector &);
579 
582  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); }
583  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); }
584  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); }
585  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); }
586  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); }
587  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); }
589 
592  IMPLEMENT_DIM_DISPATCHER_P1(_isInRangeVector, const BitImage, bool, return, const ImageVector &);
593 
596  inline bool _isInRangeVector1D(const ImageVector &p) const { return (p.x<_ext.x) && (p.x>=0); }
597  inline bool _isInRangeVector2D(const ImageVector &p) const { return (p.x<_ext.x) && (p.y<_ext.y) && (p.x>=0) && (p.y>=0); }
598  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); }
599  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); }
600  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); }
601  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); }
603 
604 
605 
608  IMPLEMENT_DIM_DISPATCHER_P1(_isInRangeVec6, const BitImage, bool, return, const Vector6 &);
609 
612  inline bool _isInRangeVec61D(const Vector6 &p) const { return (p[ML_VX]< static_cast<double>(_ext.x)) && (p[ML_VX]>=0.); }
613  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.); }
614  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.); }
615  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.); }
616  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.); }
617  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.); }
619 
620 
621 
624  IMPLEMENT_DIM_DISPATCHER_P0(_isCursorAtEnd, const BitImage, bool, return);
625 
628  inline bool _isCursorAtEnd1D() const { return (_cursorPos.x == _extM1.x); }
629  inline bool _isCursorAtEnd2D() const { return (_cursorPos.x == _extM1.x) && (_cursorPos.y == _extM1.y); }
630  inline bool _isCursorAtEnd3D() const { return (_cursorPos.x == _extM1.x) && (_cursorPos.y == _extM1.y) && (_cursorPos.z == _extM1.z); }
631  inline bool _isCursorAtEnd4D() const { return (_cursorPos.x == _extM1.x) && (_cursorPos.y == _extM1.y) && (_cursorPos.z == _extM1.z) && (_cursorPos.c == _extM1.c); }
632  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); }
633  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); }
635 
636 
637 
640  IMPLEMENT_EXC_DISPATCHER_P0(_moveCursorF, BitImage, void, ML_EMPTY_SPACE);
641 
642  // In the following 40 lines expressions such as
643  // _cursorBitIdx += static_cast<MLuint64>(_strides.y);
644  // or
645  // _cursorBitIdx += static_cast<MLuint64>(_strides.y);
646  // are performed with casts to unsigned MLuint64 values, because according to C-standard
647  // the signed values are cast to unsigned int 64 before subtracting anyway; and this
648  // which is warned by compilers.
649  // Therefore the cast is done explicitly, which is okay, when considering that negative
650  // signed values are cast, converted to usually large unsigned values which are added
651  // with overflows resulting to the same value.
652 
655  inline void _moveCursorF1N() { ++_cursorPos.x; _cursorBitIdx++; }
656  inline void _moveCursorF2N() { ++_cursorPos.y; _cursorBitIdx += static_cast<MLuint64>(_strides.y); } // See cast notes above.
657  inline void _moveCursorF3N() { ++_cursorPos.z; _cursorBitIdx += static_cast<MLuint64>(_strides.z); }
658  inline void _moveCursorF4N() { ++_cursorPos.c; _cursorBitIdx += static_cast<MLuint64>(_strides.c); }
659  inline void _moveCursorF5N() { ++_cursorPos.t; _cursorBitIdx += static_cast<MLuint64>(_strides.t); }
660  inline void _moveCursorF6N() { ++_cursorPos.u; _cursorBitIdx += static_cast<MLuint64>(_strides.u); }
662 
665  inline void _moveCursorF1E() { if (_cursorPos.x >= _extM1.x){ throw(ML_OUT_OF_RANGE); } _moveCursorF1N(); }
666  inline void _moveCursorF2E() { if (_cursorPos.y >= _extM1.y){ throw(ML_OUT_OF_RANGE); } _moveCursorF2N(); }
667  inline void _moveCursorF3E() { if (_cursorPos.z >= _extM1.z){ throw(ML_OUT_OF_RANGE); } _moveCursorF3N(); }
668  inline void _moveCursorF4E() { if (_cursorPos.c >= _extM1.c){ throw(ML_OUT_OF_RANGE); } _moveCursorF4N(); }
669  inline void _moveCursorF5E() { if (_cursorPos.t >= _extM1.t){ throw(ML_OUT_OF_RANGE); } _moveCursorF5N(); }
670  inline void _moveCursorF6E() { if (_cursorPos.u >= _extM1.u){ throw(ML_OUT_OF_RANGE); } _moveCursorF6N(); }
672 
673 
674 
677  IMPLEMENT_EXC_DISPATCHER_P0(_moveCursorB, BitImage, void, ML_EMPTY_SPACE);
678 
681  inline void _moveCursorB1N() { --_cursorPos.x; _cursorBitIdx--; }
682  inline void _moveCursorB2N() { --_cursorPos.y; _cursorBitIdx -= static_cast<MLuint64>(_strides.y); } // See cast notes above.
683  inline void _moveCursorB3N() { --_cursorPos.z; _cursorBitIdx -= static_cast<MLuint64>(_strides.z); }
684  inline void _moveCursorB4N() { --_cursorPos.c; _cursorBitIdx -= static_cast<MLuint64>(_strides.c); }
685  inline void _moveCursorB5N() { --_cursorPos.t; _cursorBitIdx -= static_cast<MLuint64>(_strides.t); }
686  inline void _moveCursorB6N() { --_cursorPos.u; _cursorBitIdx -= static_cast<MLuint64>(_strides.u); }
688 
691  inline void _moveCursorB1E() { if (!_cursorPos.x){ throw(ML_OUT_OF_RANGE); } _moveCursorB1N(); }
692  inline void _moveCursorB2E() { if (!_cursorPos.y){ throw(ML_OUT_OF_RANGE); } _moveCursorB2N(); }
693  inline void _moveCursorB3E() { if (!_cursorPos.z){ throw(ML_OUT_OF_RANGE); } _moveCursorB3N(); }
694  inline void _moveCursorB4E() { if (!_cursorPos.c){ throw(ML_OUT_OF_RANGE); } _moveCursorB4N(); }
695  inline void _moveCursorB5E() { if (!_cursorPos.t){ throw(ML_OUT_OF_RANGE); } _moveCursorB5N(); }
696  inline void _moveCursorB6E() { if (!_cursorPos.u){ throw(ML_OUT_OF_RANGE); } _moveCursorB6N(); }
698 
702  inline void _setCursorPos(const ImageVector &pos)
703  { if (_useExceptions && !isInRange(pos)){ throw(ML_OUT_OF_RANGE); }
704  _cursorBitIdx = _bitIdx(this, pos);
705  _cursorPos = pos;
706  }
707 
712  MLTOOLS_EXPORT bool _init(const ImageVector &ext, bool useExceptions);
713 
715  MLTOOLS_EXPORT void _reset();
716 
722  MLTOOLS_EXPORT void _updateFunctionPointers(const ImageVector &ext, bool useExceptions);
723 
732  MLTOOLS_EXPORT bool _setExt(const ImageVector &ext);
733 
734  //------------------------------------------------------
735  // Members
736  //------------------------------------------------------
737 
739  ML_BIT_IMG_DATA_TYPE *_image;
740 
742  bool _useExceptions;
743 
745  ImageVector _ext;
746 
748  ImageVector _extM1;
749 
756  SubImageBox _sourceBox;
757 
759  ImageVector _strides;
760 
762  size_t _numWords;
763 
765  size_t _numBytes;
766 
768  ML_BIT_IMG_BIT_IDX_TYPE _cursorBitIdx;
769 
771  ImageVector _cursorPos;
772 
775 
776  }; // class mlBitImage
777 
778 ML_END_NAMESPACE
779 
780 #endif // __mlBitImage_H
#define ML_DEPRECATED
Definition: CSOGroup.h:371
#define MLTOOLS_EXPORT
Resolves system dependencies for this project.
Definition: MLToolsSystem.h:26
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition: mlBase.h:62
Class to manage a binary image.
Definition: mlBitImage.h:67
MLTOOLS_EXPORT const BitImage & operator=(const BitImage &bitImg)
Assignment operator.
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.
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...
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
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....
BitImage(const ImageVector &ext, bool useExceptions=false)
Convenience constructor.
Definition: mlBitImage.h:96
void moveCursorY()
Definition: mlBitImage.h:275
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.
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
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
const ImageVector & getStrides() const
Definition: mlBitImage.h:180
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 ImageVector & getCursorPosition() const
Return current cursor position. Never throws controlled diagnostic exceptions.
Definition: mlBitImage.h:244
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
MLTOOLS_EXPORT BitImage * getDownScaledBitImage(const ImageVector &scales) const
Create a down scaled mlBitImage from this.
void moveCursorZ()
Definition: mlBitImage.h:276
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
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
const ImageVector & getExtent() const
Return image size. Never throws controlled diagnostic exceptions.
Definition: mlBitImage.h:150
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:684
#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:974
MLint32 MLErrorCode
Type of an ML Error code.
Definition: mlTypeDefs.h:818
#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
#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:513
unsigned int MLuint32
Definition: mlTypeDefs.h:191
@ ML_VT
Array index for t (time) components (entry 4)
Definition: mlTypeDefs.h:1268
@ ML_VC
Array index for c (color) components (entry 3)
Definition: mlTypeDefs.h:1267
@ ML_VY
Array index for y components (entry 1)
Definition: mlTypeDefs.h:1264
@ ML_VU
Array index for u (unit/user dimension) components (entry 5)
Definition: mlTypeDefs.h:1269
@ ML_VZ
Array index for z components (entry 2)
Definition: mlTypeDefs.h:1265
@ ML_VX
Array index for x components (entry 0)
Definition: mlTypeDefs.h:1263
MLuint64 MLuint
An unsigned ML integer type with at least 64 bits used for index calculations on very large images ev...
Definition: mlTypeDefs.h:594
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:578
#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.
Tvec6< MLdouble > Vector6
A vector with 6 components of type double.
Definition: mlVector6.h:194
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.