MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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
70public:
74 SET_MODE = 0,
79
80 NUM_MODES
81 };
82
83
90 inline BitImage(bool useExceptions = false)
91 {
92 _init(ImageVector(0), useExceptions);
93 }
94
100 inline BitImage(const ImageVector& ext, bool useExceptions = false)
101 {
102 _init(ext, useExceptions);
103 }
104
111
114 {
115 _reset();
116 }
117
120 inline void reset()
121 {
122 _reset();
123 }
124
127 inline bool useExceptionHandling() const
128 {
129 return _useExceptions;
130 }
131
135
142
143
156 inline bool setExtent(const ImageVector& ext)
157 {
158 bool result = _setExt(ext);
159
160 clear(false); // initialize content to zero
161
162 return result;
163 }
164
166 inline const ImageVector& getExtent() const
167 {
168 return _ext;
169 }
170
173 {
174 return SubImageBox(_ext);
175 }
176
184 inline const SubImageBox& getSourceBox() const
185 {
186 return _sourceBox;
187 }
188
196 inline void setSourceBox(const SubImageBox& box)
197 {
198 _sourceBox = box;
199 }
201
202
207 inline const ImageVector& getStrides() const
208 {
209 return _strides;
210 }
211
214 {
215 return static_cast<MLint>(_cursorBitIdx);
216 }
217
219 inline bool isEmpty() const
220 {
221 return _ext.compMul() == 0;
222 }
223
225 inline void clear(bool val)
226 {
227 if (nullptr != _image) {
228 memset(_image, val ? 0xff : 0, _numBytes);
229 }
230 }
232
233
236
240 inline bool operator[](const ImageVector& pos) const
241 {
242 return isSet(pos);
243 }
244
248 inline void setValue(const ImageVector& pos, const bool v)
249 {
250 if (v) {
251 set(pos);
252 }
253 else {
254 clear(pos);
255 }
256 }
257
261 inline void set(const ImageVector& pos)
262 {
263 const MLuint b = _bitIdx(this, pos);
264 _image[b >> ML_BIT_IMG_SHIFT] |=
266 }
267
271 inline void clear(const ImageVector& pos)
272 {
273 const MLuint b = _bitIdx(this, pos);
274 _image[b >> ML_BIT_IMG_SHIFT] &=
276 }
277
281 inline void toggle(const ImageVector& pos)
282 {
283 const MLuint b = _bitIdx(this, pos);
284 _image[b >> ML_BIT_IMG_SHIFT] ^=
286 }
287
291 inline bool isSet(const ImageVector& pos) const
292 {
293 const MLuint b = _bitIdx(this, pos);
294 return (_image[b >> ML_BIT_IMG_SHIFT] & (ML_BIT_IMG_LOW_BIT << (b & ML_BIT_IMG_INDEX_BITS))) != 0;
295 }
296
299 inline bool isInRange(const ImageVector& p) const
300 {
301 return _isInRangeVector(this, p);
302 }
303
306 inline bool isInRange(const Vector6& p) const
307 {
308 return _isInRangeVec6(this, p);
309 }
311
312
318 inline void setCursorPosition(const ImageVector& pos)
319 {
320 _setCursorPos(pos);
321 }
322
324 inline const ImageVector& getCursorPosition() const
325 {
326 return _cursorPos;
327 }
328
331 inline bool getCursorValue() const
332 {
333 return (_image[static_cast<size_t>(_cursorBitIdx >> ML_BIT_IMG_SHIFT)] &
334 (ML_BIT_IMG_LOW_BIT << (_cursorBitIdx & ML_BIT_IMG_INDEX_BITS))) != 0;
335 }
336
339 inline void setCursorValue(const bool val)
340 {
341 if (val) {
342 setCursorValue();
343 }
344 else {
345 clearCursorValue();
346 }
347 }
348
350 inline void setCursorValue()
351 {
352 _image[static_cast<size_t>(_cursorBitIdx >> ML_BIT_IMG_SHIFT)] |=
353 static_cast<ML_BIT_IMG_DATA_TYPE>((ML_BIT_IMG_LOW_BIT << (_cursorBitIdx & ML_BIT_IMG_INDEX_BITS)));
354 }
355
357 inline void toggleCursorValue()
358 {
359 _image[static_cast<size_t>(_cursorBitIdx >> ML_BIT_IMG_SHIFT)] ^=
360 static_cast<ML_BIT_IMG_DATA_TYPE>((ML_BIT_IMG_LOW_BIT << (_cursorBitIdx & ML_BIT_IMG_INDEX_BITS)));
361 }
362
364 inline void clearCursorValue()
365 {
366 _image[static_cast<size_t>(_cursorBitIdx >> ML_BIT_IMG_SHIFT)] &= static_cast<ML_BIT_IMG_DATA_TYPE>(
368 }
369
371 inline size_t getCursorWordIndex() const
372 {
373 return static_cast<size_t>(_cursorBitIdx >> ML_BIT_IMG_SHIFT);
374 }
375
379 {
380 return _image[static_cast<size_t>(_cursorBitIdx >> ML_BIT_IMG_SHIFT)];
381 }
382
385 {
386 return (static_cast<ML_BIT_IMG_DATA_TYPE>(ML_BIT_IMG_LOW_BIT << (_cursorBitIdx & ML_BIT_IMG_INDEX_BITS)));
387 }
389
393 inline void moveCursorX()
394 {
395 _moveCursorF1(this);
396 }
397 inline void moveCursorY()
398 {
399 _moveCursorF2(this);
400 }
401 inline void moveCursorZ()
402 {
403 _moveCursorF3(this);
404 }
405 inline void moveCursorC()
406 {
407 _moveCursorF4(this);
408 }
409 inline void moveCursorT()
410 {
411 _moveCursorF5(this);
412 }
413 inline void moveCursorU()
414 {
415 _moveCursorF6(this);
416 }
418
422 inline void reverseMoveCursorX()
423 {
424 _moveCursorB1(this);
425 }
426 inline void reverseMoveCursorY()
427 {
428 _moveCursorB2(this);
429 }
430 inline void reverseMoveCursorZ()
431 {
432 _moveCursorB3(this);
433 }
434 inline void reverseMoveCursorC()
435 {
436 _moveCursorB4(this);
437 }
438 inline void reverseMoveCursorT()
439 {
440 _moveCursorB5(this);
441 }
442 inline void reverseMoveCursorU()
443 {
444 _moveCursorB6(this);
445 }
447
454
467
473
483
499 const double minVal, const double maxVal,
500 const unsigned char addBorderPixels = 0);
501
505
515 const SubImageBox& box = SubImageBox(),
516 const ImageVector& offset = ImageVector(0));
517
525
526
529
533 MLTOOLS_EXPORT void fill(const SubImageBox& box, const bool value);
534
539
551 MLTOOLS_EXPORT void copyToSubImage(SubImage& outSubImg, const double bkVal, const double fgVal,
552 const OperationModes mode = SET_MODE) const;
553
554
562 const double intMin, const double intMax);
564
565
568
572
579 MLTOOLS_EXPORT bool writeToFile(const std::string& path, bool overwrite = true);
580
586 MLTOOLS_EXPORT MLErrorCode save(const std::string& path, bool overwrite = true);
587
588
592 MLTOOLS_EXPORT bool readFromFile(const std::string& path);
593
597 MLTOOLS_EXPORT MLErrorCode load(const std::string& path);
599
601
606 {
607 return _image;
608 }
609
612 {
613 return _numWords;
614 }
616
620
621private:
625
628 inline ML_BIT_IMG_BIT_IDX_TYPE _bitIdx1D(const ImageVector& pos) const
629 {
630 return static_cast<ML_BIT_IMG_BIT_IDX_TYPE>(_strides.x * pos.x);
631 }
632 inline ML_BIT_IMG_BIT_IDX_TYPE _bitIdx2D(const ImageVector& pos) const
633 {
634 return static_cast<ML_BIT_IMG_BIT_IDX_TYPE>(_strides.x * pos.x + _strides.y * pos.y);
635 }
636 inline ML_BIT_IMG_BIT_IDX_TYPE _bitIdx3D(const ImageVector& pos) const
637 {
638 return static_cast<ML_BIT_IMG_BIT_IDX_TYPE>(_strides.x * pos.x + _strides.y * pos.y + _strides.z * pos.z);
639 }
640 inline ML_BIT_IMG_BIT_IDX_TYPE _bitIdx4D(const ImageVector& pos) const
641 {
642 return static_cast<ML_BIT_IMG_BIT_IDX_TYPE>(_strides.x * pos.x + _strides.y * pos.y + _strides.z * pos.z +
643 _strides.c * pos.c);
644 }
645 inline ML_BIT_IMG_BIT_IDX_TYPE _bitIdx5D(const ImageVector& pos) const
646 {
647 return static_cast<ML_BIT_IMG_BIT_IDX_TYPE>(_strides.x * pos.x + _strides.y * pos.y + _strides.z * pos.z +
648 _strides.c * pos.c + _strides.t * pos.t);
649 }
650 inline ML_BIT_IMG_BIT_IDX_TYPE _bitIdx6D(const ImageVector& pos) const
651 {
652 return static_cast<ML_BIT_IMG_BIT_IDX_TYPE>(_strides.x * pos.x + _strides.y * pos.y + _strides.z * pos.z +
653 _strides.c * pos.c + _strides.t * pos.t + _strides.u * pos.u);
654 }
656
659 IMPLEMENT_DIM_DISPATCHER_P1(_isInRangeVector, const BitImage, bool, return, const ImageVector&);
660
663 inline bool _isInRangeVector1D(const ImageVector& p) const
664 {
665 return (p.x < _ext.x) && (p.x >= 0);
666 }
667 inline bool _isInRangeVector2D(const ImageVector& p) const
668 {
669 return (p.x < _ext.x) && (p.y < _ext.y) && (p.x >= 0) && (p.y >= 0);
670 }
671 inline bool _isInRangeVector3D(const ImageVector& p) const
672 {
673 return (p.x < _ext.x) && (p.y < _ext.y) && (p.z < _ext.z) && (p.x >= 0) && (p.y >= 0) && (p.z >= 0);
674 }
675 inline bool _isInRangeVector4D(const ImageVector& p) const
676 {
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);
679 }
680 inline bool _isInRangeVector5D(const ImageVector& p) const
681 {
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);
684 }
685 inline bool _isInRangeVector6D(const ImageVector& p) const
686 {
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);
689 }
691
692
695 IMPLEMENT_DIM_DISPATCHER_P1(_isInRangeVec6, const BitImage, bool, return, const Vector6&);
696
699 inline bool _isInRangeVec61D(const Vector6& p) const
700 {
701 return (p[ML_VX] < static_cast<double>(_ext.x)) && (p[ML_VX] >= 0.);
702 }
703 inline bool _isInRangeVec62D(const Vector6& p) const
704 {
705 return (p[ML_VX] < static_cast<double>(_ext.x)) && (p[ML_VY] < static_cast<double>(_ext.y)) && (p[ML_VX] >= 0.) &&
706 (p[ML_VY] >= 0.);
707 }
708 inline bool _isInRangeVec63D(const Vector6& p) const
709 {
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.);
712 }
713 inline bool _isInRangeVec64D(const Vector6& p) const
714 {
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.) &&
717 (p[ML_VY] >= 0.) && (p[ML_VZ] >= 0.) && (p[ML_VC] >= 0.);
718 }
719 inline bool _isInRangeVec65D(const Vector6& p) const
720 {
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.) &&
724 (p[ML_VC] >= 0.) && (p[ML_VT] >= 0.);
725 }
726 inline bool _isInRangeVec66D(const Vector6& p) const
727 {
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.) &&
731 (p[ML_VY] >= 0.) && (p[ML_VZ] >= 0.) && (p[ML_VC] >= 0.) && (p[ML_VT] >= 0.) && (p[ML_VU] >= 0.);
732 }
734
735
738 IMPLEMENT_DIM_DISPATCHER_P0(_isCursorAtEnd, const BitImage, bool, return);
739
743 inline bool _isCursorAtEnd1D() const
744 {
745 return (_cursorPos.x == _extM1.x);
746 }
747 inline bool _isCursorAtEnd2D() const
748 {
749 return (_cursorPos.x == _extM1.x) && (_cursorPos.y == _extM1.y);
750 }
751 inline bool _isCursorAtEnd3D() const
752 {
753 return (_cursorPos.x == _extM1.x) && (_cursorPos.y == _extM1.y) && (_cursorPos.z == _extM1.z);
754 }
755 inline bool _isCursorAtEnd4D() const
756 {
757 return (_cursorPos.x == _extM1.x) && (_cursorPos.y == _extM1.y) && (_cursorPos.z == _extM1.z) &&
758 (_cursorPos.c == _extM1.c);
759 }
760 inline bool _isCursorAtEnd5D() const
761 {
762 return (_cursorPos.x == _extM1.x) && (_cursorPos.y == _extM1.y) && (_cursorPos.z == _extM1.z) &&
763 (_cursorPos.c == _extM1.c) && (_cursorPos.t == _extM1.t);
764 }
765 inline bool _isCursorAtEnd6D() const
766 {
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);
769 }
771
772
776
777 // In the following 40 lines expressions such as
778 // _cursorBitIdx += static_cast<MLuint64>(_strides.y);
779 // or
780 // _cursorBitIdx += static_cast<MLuint64>(_strides.y);
781 // are performed with casts to unsigned MLuint64 values, because according to C-standard
782 // the signed values are cast to unsigned int 64 before subtracting anyway; and this
783 // which is warned by compilers.
784 // Therefore the cast is done explicitly, which is okay, when considering that negative
785 // signed values are cast, converted to usually large unsigned values which are added
786 // with overflows resulting to the same value.
787
790 inline void _moveCursorF1N()
791 {
792 ++_cursorPos.x;
793 _cursorBitIdx++;
794 }
795 inline void _moveCursorF2N()
796 {
797 ++_cursorPos.y;
798 _cursorBitIdx += static_cast<MLuint64>(_strides.y);
799 } // See cast notes above.
800 inline void _moveCursorF3N()
801 {
802 ++_cursorPos.z;
803 _cursorBitIdx += static_cast<MLuint64>(_strides.z);
804 }
805 inline void _moveCursorF4N()
806 {
807 ++_cursorPos.c;
808 _cursorBitIdx += static_cast<MLuint64>(_strides.c);
809 }
810 inline void _moveCursorF5N()
811 {
812 ++_cursorPos.t;
813 _cursorBitIdx += static_cast<MLuint64>(_strides.t);
814 }
815 inline void _moveCursorF6N()
816 {
817 ++_cursorPos.u;
818 _cursorBitIdx += static_cast<MLuint64>(_strides.u);
819 }
821
825 inline void _moveCursorF1E()
826 {
827 if (_cursorPos.x >= _extM1.x) {
828 throw(ML_OUT_OF_RANGE);
829 }
830 _moveCursorF1N();
831 }
832 inline void _moveCursorF2E()
833 {
834 if (_cursorPos.y >= _extM1.y) {
835 throw(ML_OUT_OF_RANGE);
836 }
837 _moveCursorF2N();
838 }
839 inline void _moveCursorF3E()
840 {
841 if (_cursorPos.z >= _extM1.z) {
842 throw(ML_OUT_OF_RANGE);
843 }
844 _moveCursorF3N();
845 }
846 inline void _moveCursorF4E()
847 {
848 if (_cursorPos.c >= _extM1.c) {
849 throw(ML_OUT_OF_RANGE);
850 }
851 _moveCursorF4N();
852 }
853 inline void _moveCursorF5E()
854 {
855 if (_cursorPos.t >= _extM1.t) {
856 throw(ML_OUT_OF_RANGE);
857 }
858 _moveCursorF5N();
859 }
860 inline void _moveCursorF6E()
861 {
862 if (_cursorPos.u >= _extM1.u) {
863 throw(ML_OUT_OF_RANGE);
864 }
865 _moveCursorF6N();
866 }
868
869
873
876 inline void _moveCursorB1N()
877 {
878 --_cursorPos.x;
879 _cursorBitIdx--;
880 }
881 inline void _moveCursorB2N()
882 {
883 --_cursorPos.y;
884 _cursorBitIdx -= static_cast<MLuint64>(_strides.y);
885 } // See cast notes above.
886 inline void _moveCursorB3N()
887 {
888 --_cursorPos.z;
889 _cursorBitIdx -= static_cast<MLuint64>(_strides.z);
890 }
891 inline void _moveCursorB4N()
892 {
893 --_cursorPos.c;
894 _cursorBitIdx -= static_cast<MLuint64>(_strides.c);
895 }
896 inline void _moveCursorB5N()
897 {
898 --_cursorPos.t;
899 _cursorBitIdx -= static_cast<MLuint64>(_strides.t);
900 }
901 inline void _moveCursorB6N()
902 {
903 --_cursorPos.u;
904 _cursorBitIdx -= static_cast<MLuint64>(_strides.u);
905 }
907
911 inline void _moveCursorB1E()
912 {
913 if (!_cursorPos.x) {
914 throw(ML_OUT_OF_RANGE);
915 }
916 _moveCursorB1N();
917 }
918 inline void _moveCursorB2E()
919 {
920 if (!_cursorPos.y) {
921 throw(ML_OUT_OF_RANGE);
922 }
923 _moveCursorB2N();
924 }
925 inline void _moveCursorB3E()
926 {
927 if (!_cursorPos.z) {
928 throw(ML_OUT_OF_RANGE);
929 }
930 _moveCursorB3N();
931 }
932 inline void _moveCursorB4E()
933 {
934 if (!_cursorPos.c) {
935 throw(ML_OUT_OF_RANGE);
936 }
937 _moveCursorB4N();
938 }
939 inline void _moveCursorB5E()
940 {
941 if (!_cursorPos.t) {
942 throw(ML_OUT_OF_RANGE);
943 }
944 _moveCursorB5N();
945 }
946 inline void _moveCursorB6E()
947 {
948 if (!_cursorPos.u) {
949 throw(ML_OUT_OF_RANGE);
950 }
951 _moveCursorB6N();
952 }
954
958 inline void _setCursorPos(const ImageVector& pos)
959 {
960 if (_useExceptions && !isInRange(pos)) {
961 throw(ML_OUT_OF_RANGE);
962 }
963 _cursorBitIdx = _bitIdx(this, pos);
964 _cursorPos = pos;
965 }
966
971 MLTOOLS_EXPORT bool _init(const ImageVector& ext, bool useExceptions);
972
974 MLTOOLS_EXPORT void _reset();
975
981 MLTOOLS_EXPORT void _updateFunctionPointers(const ImageVector& ext, bool useExceptions);
982
991 MLTOOLS_EXPORT bool _setExt(const ImageVector& ext);
992
993 //------------------------------------------------------
994 // Members
995 //------------------------------------------------------
996
998 ML_BIT_IMG_DATA_TYPE* _image;
999
1001 bool _useExceptions;
1002
1004 ImageVector _ext;
1005
1007 ImageVector _extM1;
1008
1015 SubImageBox _sourceBox;
1016
1018 ImageVector _strides;
1019
1021 size_t _numWords;
1022
1024 size_t _numBytes;
1025
1027 ML_BIT_IMG_BIT_IDX_TYPE _cursorBitIdx;
1028
1030 ImageVector _cursorPos;
1031
1034
1035}; // class mlBitImage
1036
1038
1039#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:63
Class to manage a binary image.
Definition mlBitImage.h:68
const ImageVector & getExtent() const
Return image size. Never throws controlled diagnostic exceptions.
Definition mlBitImage.h:166
ML_BIT_IMG_DATA_TYPE * getImageMemory()
Provide access to the BitImage memory.
Definition mlBitImage.h:605
void moveCursorC()
Definition mlBitImage.h:405
bool useExceptionHandling() const
Return true if exception handling is on, otherwise return false.
Definition mlBitImage.h:127
bool operator[](const ImageVector &pos) const
Constant vector index read access to voxel value at position pos.
Definition mlBitImage.h:240
void reverseMoveCursorC()
Definition mlBitImage.h:434
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:350
void moveCursorU()
Definition mlBitImage.h:413
void reverseMoveCursorZ()
Definition mlBitImage.h:430
const ImageVector & getStrides() const
Definition mlBitImage.h:207
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:324
BitImage(const ImageVector &ext, bool useExceptions=false)
Convenience constructor.
Definition mlBitImage.h:100
void moveCursorY()
Definition mlBitImage.h:397
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:378
MLint getCursorBitIndex() const
Return strides for words. Never throws controlled diagnostic exceptions.
Definition mlBitImage.h:213
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.
Definition mlBitImage.h:339
void reverseMoveCursorT()
Definition mlBitImage.h:438
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:364
void reverseMoveCursorX()
Definition mlBitImage.h:422
size_t getCursorWordIndex() const
Return index to word in image to which the cursor points. Never throws controlled diagnostic exceptio...
Definition mlBitImage.h:371
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:384
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:219
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:76
@ OR_MODE
values are ored to target values.
Definition mlBitImage.h:75
@ CLEAR_MODE
set bits in values are cleared in target values.
Definition mlBitImage.h:78
@ XOR_MODE
values are xored to/with target values.
Definition mlBitImage.h:77
bool isSet(const ImageVector &pos) const
Return true if bit at position pos is set; otherwise, it returns false.
Definition mlBitImage.h:291
void toggleCursorValue()
Toggles the bit under the cursor. Never throws controlled diagnostic exceptions.
Definition mlBitImage.h:357
bool isInRange(const Vector6 &p) const
Test for Vector6 coordinates in valid range.
Definition mlBitImage.h:306
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:196
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:261
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:426
void reverseMoveCursorU()
Definition mlBitImage.h:442
void moveCursorT()
Definition mlBitImage.h:409
void reset()
Make image empty and restore default construction state with disabled exceptions.
Definition mlBitImage.h:120
bool isInRange(const ImageVector &p) const
Test for ImageVector coordinates in valid range.
Definition mlBitImage.h:299
bool getCursorValue() const
Return true if bit under cursor is true; otherwise, it returns false.
Definition mlBitImage.h:331
const SubImageBox getBoxFromImageExtent() const
Return a SubImageBox representing the image extent of the BitImage.
Definition mlBitImage.h:172
size_t getNumberOfAllocatedImageMemoryWords() const
Returns the number of currently allocated ML_BIT_IMG_DATA_TYPE words.
Definition mlBitImage.h:611
void moveCursorX()
Definition mlBitImage.h:393
BitImage(bool useExceptions=false)
Definition mlBitImage.h:90
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:271
void setValue(const ImageVector &pos, const bool v)
Set bit at position pos to value v.
Definition mlBitImage.h:248
MLTOOLS_EXPORT ~BitImage() override
Destructor. Never throws controlled diagnostic exceptions.
Definition mlBitImage.h:113
void moveCursorZ()
Definition mlBitImage.h:401
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:184
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:318
MLTOOLS_EXPORT void resetCursor()
void toggle(const ImageVector &pos)
Toggle bit at position pos.
Definition mlBitImage.h:281
MLTOOLS_EXPORT BitImage * getDownScaledBitImage(const ImageVector &scales) const
Create a down scaled mlBitImage from this.
bool setExtent(const ImageVector &ext)
Definition mlBitImage.h:156
void clear(bool val)
Clears/sets all bits in the image. Never throws controlled diagnostic exceptions.
Definition mlBitImage.h:225
This class manages/represents a rectangular 6D image region that is organized linearly in memory.
Definition mlSubImage.h:75
MLint32 MLDataType
MLDataType.
Definition mlTypeDefs.h:592
#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...
Definition mlTypeDefs.h:928
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:772
#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:424
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:505
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition mlTypeDefs.h:489
#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.