MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlTVirtualVolume.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_TVIRTUAL_VOLUME_H
14#define ML_TVIRTUAL_VOLUME_H
15
16
19
26
27// Include dll-specific settings.
28#include "MLToolsSystem.h"
29
30// Include most ml specific things.
31#include "mlVirtualVolume.h"
32
33// Include BitImage.
34#include "mlBitImage.h"
35
37
38//---------------------------------------------------------------------------------------------------------
211//---------------------------------------------------------------------------------------------------------
212template <typename DATATYPE> class TVirtualVolume
213{
214
215protected:
218 {}
219
224
225public:
228
232 {
233 _convenienceInstance = nullptr;
234 _init(vVol);
235 }
236
244 TVirtualVolume(PagedImage* image, MLint maxNumKB = -1, bool areExceptionsOn = false)
245 {
246 _convenienceInstance =
247 new VirtualVolume(image, MLGetDataTypeFromPtr(static_cast<DATATYPE*>(nullptr)), maxNumKB, areExceptionsOn);
248 _init(*_convenienceInstance);
249 }
250
258 TVirtualVolume(const ImageVector& ext, MLdouble fillVal = 0, MLint maxNumKB = -1, bool areExceptionsOn = false)
259 {
260 _convenienceInstance = new VirtualVolume(ext, fillVal, MLGetDataTypeFromPtr(static_cast<DATATYPE*>(nullptr)),
261 maxNumKB, areExceptionsOn);
262 _init(*_convenienceInstance);
263 }
264
269 {
270 _cleanUp();
271 delete _convenienceInstance;
272 _convenienceInstance = nullptr;
273 }
274
277 {
278 return *_virtVol;
279 }
280
286 inline void getValues(const ImageVector* pos, DATATYPE* results, MLuint num);
287
290 inline DATATYPE getValue(const ImageVector& pos)
291 {
292 return _getVoxelFunc(this, pos);
293 }
294
297 inline void setValue(const ImageVector& pos, DATATYPE data)
298 {
299 _setVoxelFunc(this, pos, data);
300 }
301
303 inline void setCursorPosition(const ImageVector& pos)
304 {
305 _setCursorPosFunc(this, pos);
306 }
307
309 inline const ImageVector& getCursorPosition() const
310 {
311 return _cPos;
312 }
313
315 inline void setCursorValue(DATATYPE val);
316
318 inline DATATYPE getCursorValue();
319
321 inline bool isMapped(const ImageVector& pos) const
322 {
323 return _isMappedFunc(this, pos);
324 }
325
328 inline void moveCursorX()
329 {
330 _moveFXFunc(this);
331 }
332 inline void moveCursorY()
333 {
334 _moveFYFunc(this);
335 }
336 inline void moveCursorZ()
337 {
338 _moveFZFunc(this);
339 }
340 inline void moveCursorC()
341 {
342 _moveFCFunc(this);
343 }
344 inline void moveCursorT()
345 {
346 _moveFTFunc(this);
347 }
348 inline void moveCursorU()
349 {
350 _moveFUFunc(this);
351 }
352
353 inline void reverseMoveCursorX()
354 {
355 _moveBXFunc(this);
356 }
357 inline void reverseMoveCursorY()
358 {
359 _moveBYFunc(this);
360 }
361 inline void reverseMoveCursorZ()
362 {
363 _moveBZFunc(this);
364 }
365 inline void reverseMoveCursorC()
366 {
367 _moveBCFunc(this);
368 }
369 inline void reverseMoveCursorT()
370 {
371 _moveBTFunc(this);
372 }
373 inline void reverseMoveCursorU()
374 {
375 _moveBUFunc(this);
376 }
378
381 {
382 _moveCursorOffsetFunc(this, off);
383 }
384
388 void resetCursor();
389
399 bool moveCursorXWrapAround();
401
405 void fill(const SubImageBox& box, DATATYPE value);
406
411 void copyToSubImage(TSubImage<DATATYPE>& outSubImg);
412
417 void copyFromSubImage(const TSubImage<DATATYPE>& inImg, const SubImageBox& box, const ImageVector& pos);
418
438 //
439 // It would be desirable to have this function in the implementation part, but I
440 // don't know how to do that syntactically with the second template argument.
441 // (Maybe the VC++6 compiler does not support that?)
442 //
443 template <typename OUTDTYPE> void copyMaskToSubImage(TSubImage<OUTDTYPE>& outSubImg, BitImage& maskBits,
444 bool maskValue = true, bool writeBK = false,
446 {
447 // Save cursor positions of *this, maskBits and outSubImg.
448 const ImageVector vvCursorPos(getCursorPosition());
449 const ImageVector bitImgCursorPos(maskBits.getCursorPosition());
450
451 // Determine valid overlapping region of virtual volume and output page.
452 SubImageBox box = SubImageBox::intersect(_virtVol->getBox(), outSubImg.getBox());
453
454 // Clamp box against bitImage box.
455 box = box.intersect(SubImageBox(maskBits.getExtent()));
456
457 // Scan all voxels in both input subimages which have identical
458 // extents (as specified in calculateInputSubImageBox).
459 ImageVector p = box.v1;
460 for (p.u = box.v1.u; p.u <= box.v2.u; p.u++) {
461 for (p.t = box.v1.t; p.t <= box.v2.t; p.t++) {
462 for (p.c = box.v1.c; p.c <= box.v2.c; p.c++) {
463 for (p.z = box.v1.z; p.z <= box.v2.z; p.z++) {
464 for (p.y = box.v1.y; p.y <= box.v2.y; p.y++) {
465
466 // Calculate first voxel position in x row.
467 p.x = box.v1.x;
468
469 // Get pointer to first voxels in x-rows of output subimage.
470 OUTDTYPE* oP = outSubImg.getImagePointer(p);
471
472 // Set cursor position in virtual volume.
473 setCursorPosition(p);
474
475 // Set cursor in bitImage of _drawImage.
476 maskBits.setCursorPosition(p);
477
478 // Iterate over all voxels in voxel rows.
479 for (; p.x <= box.v2.x; p.x++) {
480
481 // Copy value from virtual volume if corresponding bit
482 // image flag denotes a modified value.
483 if (maskBits.getCursorValue() == maskValue) {
484 *oP = static_cast<OUTDTYPE>(getCursorValue());
485 }
486 else {
487 // No copy desired. Set bkVal if writeBK permits it.
488 if (writeBK) {
489 *oP = bkVal;
490 }
491 }
492
493 // Move all image cursors forward, but do not move them
494 // outside image areas in last column to avoid exceptions.
495 if (p.x < box.v2.x) {
496 // Move forward the output data pointer.
497 ++oP;
498
499 // Move forward the virtual volume cursor.
500 moveCursorX();
501
502 // Move forward the bit image cursor.
503 maskBits.moveCursorX();
504 }
505 }
506 }
507 }
508 }
509 }
510 }
511
512 // Restore cursor positions.
513 setCursorPosition(vvCursorPos);
514 maskBits.setCursorPosition(bitImgCursorPos);
515 }
516
517
525 {
526 return static_cast<DATATYPE*>(_virtVol->getWrittenPageData(wp));
527 }
528
529
538 static MLint getIntValueWrapped(void* vv, const ImageVector& pos)
539 {
540 return static_cast<MLint>((static_cast<TVirtualVolume<DATATYPE>*>(vv))->getValue(pos));
541 }
542 static MLint64 getInt64ValueWrapped(void* vv, const ImageVector& pos)
543 {
544 return static_cast<MLint64>((static_cast<TVirtualVolume<DATATYPE>*>(vv))->getValue(pos));
545 }
547 {
548 return static_cast<MLdouble>((static_cast<TVirtualVolume<DATATYPE>*>(vv))->getValue(pos));
549 }
551 {
552 return static_cast<MLldouble>((static_cast<TVirtualVolume<DATATYPE>*>(vv))->getValue(pos));
553 }
555 {
556 return static_cast<MLint>((static_cast<TVirtualVolume<DATATYPE>*>(vv))->getCursorValue());
557 }
559 {
560 return static_cast<MLint64>((static_cast<TVirtualVolume<DATATYPE>*>(vv))->getCursorValue());
561 }
563 {
564 return static_cast<MLdouble>((static_cast<TVirtualVolume<DATATYPE>*>(vv))->getCursorValue());
565 }
567 {
568 return static_cast<MLldouble>((static_cast<TVirtualVolume<DATATYPE>*>(vv))->getCursorValue());
569 }
571 {
572 return (static_cast<TVirtualVolume<DATATYPE>*>(vv))->getCursorPosition();
573 }
574 static bool isMappedWrapped(void* vv, const ImageVector& pos)
575 {
576 return (static_cast<TVirtualVolume<DATATYPE>*>(vv))->isMapped(pos);
577 }
578 static void setCursorPositionWrapped(void* vv, const ImageVector& pos)
579 {
580 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->setCursorPosition(pos);
581 }
582 static void setIntValueWrapped(void* vv, const ImageVector& pos, MLint v)
583 {
584 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->setValue(pos, static_cast<DATATYPE>(v));
585 }
586 static void setInt64ValueWrapped(void* vv, const ImageVector& pos, MLint64 v)
587 {
588 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->setValue(pos, static_cast<DATATYPE>(v));
589 }
590 static void setDoubleValueWrapped(void* vv, const ImageVector& pos, MLdouble v)
591 {
592 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->setValue(pos, static_cast<DATATYPE>(v));
593 }
594 static void setLDoubleValueWrapped(void* vv, const ImageVector& pos, MLldouble v)
595 {
596 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->setValue(pos, static_cast<DATATYPE>(v));
597 }
598 static void setIntCursorValueWrapped(void* vv, MLint v)
599 {
600 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->setCursorValue(static_cast<DATATYPE>(v));
601 }
603 {
604 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->setCursorValue(static_cast<DATATYPE>(v));
605 }
607 {
608 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->setCursorValue(static_cast<DATATYPE>(v));
609 }
611 {
612 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->setCursorValue(static_cast<DATATYPE>(v));
613 }
614 static void fillIntWrapped(void* vv, const ImageVector& v1, const ImageVector& v2, MLint v)
615 {
616 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->fill(SubImageBox(v1, v2), static_cast<DATATYPE>(v));
617 }
618 static void fillInt64Wrapped(void* vv, const ImageVector& v1, const ImageVector& v2, MLint64 v)
619 {
620 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->fill(SubImageBox(v1, v2), static_cast<DATATYPE>(v));
621 }
622 static void fillDoubleWrapped(void* vv, const ImageVector& v1, const ImageVector& v2, MLdouble v)
623 {
624 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->fill(SubImageBox(v1, v2), static_cast<DATATYPE>(v));
625 }
626 static void fillLDoubleWrapped(void* vv, const ImageVector& v1, const ImageVector& v2, MLldouble v)
627 {
628 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->fill(SubImageBox(v1, v2), static_cast<DATATYPE>(v));
629 }
630 static void moveCursorXWrapped(void* vv)
631 {
632 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->moveCursorX();
633 }
634 static void moveCursorYWrapped(void* vv)
635 {
636 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->moveCursorY();
637 }
638 static void moveCursorZWrapped(void* vv)
639 {
640 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->moveCursorZ();
641 }
642 static void moveCursorCWrapped(void* vv)
643 {
644 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->moveCursorC();
645 }
646 static void moveCursorTWrapped(void* vv)
647 {
648 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->moveCursorT();
649 }
650 static void moveCursorUWrapped(void* vv)
651 {
652 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->moveCursorU();
653 }
654 static void reverseMoveCursorXWrapped(void* vv)
655 {
656 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->reverseMoveCursorX();
657 }
658 static void reverseMoveCursorYWrapped(void* vv)
659 {
660 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->reverseMoveCursorY();
661 }
662 static void reverseMoveCursorZWrapped(void* vv)
663 {
664 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->reverseMoveCursorZ();
665 }
666 static void reverseMoveCursorCWrapped(void* vv)
667 {
668 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->reverseMoveCursorC();
669 }
670 static void reverseMoveCursorTWrapped(void* vv)
671 {
672 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->reverseMoveCursorT();
673 }
674 static void reverseMoveCursorUWrapped(void* vv)
675 {
676 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->reverseMoveCursorU();
677 }
678 static void moveCursorByOffsetWrapped(void* vv, const ImageVector& off)
679 {
680 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->moveCursorByOffset(off);
681 }
682 static void resetCursorWrapped(void* vv)
683 {
684 (static_cast<TVirtualVolume<DATATYPE>*>(vv))->resetCursor();
685 }
687 {
688 return (static_cast<TVirtualVolume<DATATYPE>*>(vv))->moveCursorXWrapAround();
689 }
691
692protected:
693 //------------------------------------------------------------------------------------------------------
694 //------------------------------------------------------------------------------------------------------
695 //------------------------------------------------------------------------------------------------------
696 //
697 //
698 // NOTHING BELOW FOR NORMAL VIRTUAL VOLUME USAGE.
699 //
700 //
701 //------------------------------------------------------------------------------------------------------
702 //------------------------------------------------------------------------------------------------------
703 //------------------------------------------------------------------------------------------------------
704
705
706 //------------------------------------------------------------------------------------------------------
708 //------------------------------------------------------------------------------------------------------
709 void _init(VirtualVolume& vVol);
710
711 //------------------------------------------------------------------------------------------------------
713 //------------------------------------------------------------------------------------------------------
714 void _cleanUp();
715
716 //------------------------------------------------------------------------------------------------------
717 //------------------------------------------------------------------------------------------------------
718 // GetVoxel, SetVoxel and IsMapped implementations.
719 //------------------------------------------------------------------------------------------------------
720 //------------------------------------------------------------------------------------------------------
721
722 //------------------------------------------------------------------------------------------------------
729 //------------------------------------------------------------------------------------------------------
731 inline DATATYPE _getVoxel1D(const ImageVector& pos);
732 inline DATATYPE _getVoxel2D(const ImageVector& pos);
733 inline DATATYPE _getVoxel3D(const ImageVector& pos);
734 inline DATATYPE _getVoxel4D(const ImageVector& pos);
735 inline DATATYPE _getVoxel5D(const ImageVector& pos);
736 inline DATATYPE _getVoxel6D(const ImageVector& pos);
737
738 inline DATATYPE _getVoxel1DE(const ImageVector& pos);
739 inline DATATYPE _getVoxel2DE(const ImageVector& pos);
740 inline DATATYPE _getVoxel3DE(const ImageVector& pos);
741 inline DATATYPE _getVoxel4DE(const ImageVector& pos);
742 inline DATATYPE _getVoxel5DE(const ImageVector& pos);
743 inline DATATYPE _getVoxel6DE(const ImageVector& pos);
745
746 //----------------------------------------------------------------------------------
753 //----------------------------------------------------------------------------------
755 inline void _setVoxel1D(const ImageVector& pos, DATATYPE voxVal);
756 inline void _setVoxel2D(const ImageVector& pos, DATATYPE voxVal);
757 inline void _setVoxel3D(const ImageVector& pos, DATATYPE voxVal);
758 inline void _setVoxel4D(const ImageVector& pos, DATATYPE voxVal);
759 inline void _setVoxel5D(const ImageVector& pos, DATATYPE voxVal);
760 inline void _setVoxel6D(const ImageVector& pos, DATATYPE voxVal);
761
762 inline void _setVoxel1DE(const ImageVector& pos, DATATYPE voxVal);
763 inline void _setVoxel2DE(const ImageVector& pos, DATATYPE voxVal);
764 inline void _setVoxel3DE(const ImageVector& pos, DATATYPE voxVal);
765 inline void _setVoxel4DE(const ImageVector& pos, DATATYPE voxVal);
766 inline void _setVoxel5DE(const ImageVector& pos, DATATYPE voxVal);
767 inline void _setVoxel6DE(const ImageVector& pos, DATATYPE voxVal);
769
770 //----------------------------------------------------------------------------------
776 //----------------------------------------------------------------------------------
778 inline bool _isMapped1D(const ImageVector& pos) const;
779 inline bool _isMapped2D(const ImageVector& pos) const;
780 inline bool _isMapped3D(const ImageVector& pos) const;
781 inline bool _isMapped4D(const ImageVector& pos) const;
782 inline bool _isMapped5D(const ImageVector& pos) const;
783 inline bool _isMapped6D(const ImageVector& pos) const;
784
785 inline bool _isMapped1DE(const ImageVector& pos) const;
786 inline bool _isMapped2DE(const ImageVector& pos) const;
787 inline bool _isMapped3DE(const ImageVector& pos) const;
788 inline bool _isMapped4DE(const ImageVector& pos) const;
789 inline bool _isMapped5DE(const ImageVector& pos) const;
790 inline bool _isMapped6DE(const ImageVector& pos) const;
792
793
794 //--------------------------------------------------------------------------------------------------------------------------
800 //--------------------------------------------------------------------------------------------------------------------------
803 {
804 return obj->_getVoxel1D(pos);
805 };
807 {
808 return obj->_getVoxel2D(pos);
809 };
811 {
812 return obj->_getVoxel3D(pos);
813 };
815 {
816 return obj->_getVoxel4D(pos);
817 };
819 {
820 return obj->_getVoxel5D(pos);
821 };
823 {
824 return obj->_getVoxel6D(pos);
825 };
826
828 {
829 return obj->_getVoxel1DE(pos);
830 };
832 {
833 return obj->_getVoxel2DE(pos);
834 };
836 {
837 return obj->_getVoxel3DE(pos);
838 };
840 {
841 return obj->_getVoxel4DE(pos);
842 };
844 {
845 return obj->_getVoxel5DE(pos);
846 };
848 {
849 return obj->_getVoxel6DE(pos);
850 };
851
852 inline static void _setVoxel1DCB(TVirtualVolume* obj, const ImageVector& pos, DATATYPE voxVal)
853 {
854 obj->_setVoxel1D(pos, voxVal);
855 };
856 inline static void _setVoxel2DCB(TVirtualVolume* obj, const ImageVector& pos, DATATYPE voxVal)
857 {
858 obj->_setVoxel2D(pos, voxVal);
859 };
860 inline static void _setVoxel3DCB(TVirtualVolume* obj, const ImageVector& pos, DATATYPE voxVal)
861 {
862 obj->_setVoxel3D(pos, voxVal);
863 };
864 inline static void _setVoxel4DCB(TVirtualVolume* obj, const ImageVector& pos, DATATYPE voxVal)
865 {
866 obj->_setVoxel4D(pos, voxVal);
867 };
868 inline static void _setVoxel5DCB(TVirtualVolume* obj, const ImageVector& pos, DATATYPE voxVal)
869 {
870 obj->_setVoxel5D(pos, voxVal);
871 };
872 inline static void _setVoxel6DCB(TVirtualVolume* obj, const ImageVector& pos, DATATYPE voxVal)
873 {
874 obj->_setVoxel6D(pos, voxVal);
875 };
876
877 inline static void _setVoxel1DCBE(TVirtualVolume* obj, const ImageVector& pos, DATATYPE voxVal)
878 {
879 obj->_setVoxel1DE(pos, voxVal);
880 };
881 inline static void _setVoxel2DCBE(TVirtualVolume* obj, const ImageVector& pos, DATATYPE voxVal)
882 {
883 obj->_setVoxel2DE(pos, voxVal);
884 };
885 inline static void _setVoxel3DCBE(TVirtualVolume* obj, const ImageVector& pos, DATATYPE voxVal)
886 {
887 obj->_setVoxel3DE(pos, voxVal);
888 };
889 inline static void _setVoxel4DCBE(TVirtualVolume* obj, const ImageVector& pos, DATATYPE voxVal)
890 {
891 obj->_setVoxel4DE(pos, voxVal);
892 };
893 inline static void _setVoxel5DCBE(TVirtualVolume* obj, const ImageVector& pos, DATATYPE voxVal)
894 {
895 obj->_setVoxel5DE(pos, voxVal);
896 };
897 inline static void _setVoxel6DCBE(TVirtualVolume* obj, const ImageVector& pos, DATATYPE voxVal)
898 {
899 obj->_setVoxel6DE(pos, voxVal);
900 };
901
902 inline static bool _isMapped1DCB(const TVirtualVolume* obj, const ImageVector& pos)
903 {
904 return obj->_isMapped1D(pos);
905 }
906 inline static bool _isMapped2DCB(const TVirtualVolume* obj, const ImageVector& pos)
907 {
908 return obj->_isMapped2D(pos);
909 };
910 inline static bool _isMapped3DCB(const TVirtualVolume* obj, const ImageVector& pos)
911 {
912 return obj->_isMapped3D(pos);
913 };
914 inline static bool _isMapped4DCB(const TVirtualVolume* obj, const ImageVector& pos)
915 {
916 return obj->_isMapped4D(pos);
917 };
918 inline static bool _isMapped5DCB(const TVirtualVolume* obj, const ImageVector& pos)
919 {
920 return obj->_isMapped5D(pos);
921 };
922 inline static bool _isMapped6DCB(const TVirtualVolume* obj, const ImageVector& pos)
923 {
924 return obj->_isMapped6D(pos);
925 };
926
927 inline static bool _isMapped1DCBE(const TVirtualVolume* obj, const ImageVector& pos)
928 {
929 return obj->_isMapped1DE(pos);
930 };
931 inline static bool _isMapped2DCBE(const TVirtualVolume* obj, const ImageVector& pos)
932 {
933 return obj->_isMapped2DE(pos);
934 };
935 inline static bool _isMapped3DCBE(const TVirtualVolume* obj, const ImageVector& pos)
936 {
937 return obj->_isMapped3DE(pos);
938 };
939 inline static bool _isMapped4DCBE(const TVirtualVolume* obj, const ImageVector& pos)
940 {
941 return obj->_isMapped4DE(pos);
942 };
943 inline static bool _isMapped5DCBE(const TVirtualVolume* obj, const ImageVector& pos)
944 {
945 return obj->_isMapped5DE(pos);
946 };
947 inline static bool _isMapped6DCBE(const TVirtualVolume* obj, const ImageVector& pos)
948 {
949 return obj->_isMapped6DE(pos);
950 };
952
953
954 //----------------------------------------------------------------------------------
955 //----------------------------------------------------------------------------------
957 //----------------------------------------------------------------------------------
958 //----------------------------------------------------------------------------------
959
960 //----------------------------------------------------------------------------------
962 //----------------------------------------------------------------------------------
964 inline void _setCursorPos1D(const ImageVector& p);
965 inline void _setCursorPos2D(const ImageVector& p);
966 inline void _setCursorPos3D(const ImageVector& p);
967 inline void _setCursorPos4D(const ImageVector& p);
968 inline void _setCursorPos5D(const ImageVector& p);
969 inline void _setCursorPos6D(const ImageVector& p);
970
971 inline void _setCursorPos1DE(const ImageVector& p);
972 inline void _setCursorPos2DE(const ImageVector& p);
973 inline void _setCursorPos3DE(const ImageVector& p);
974 inline void _setCursorPos4DE(const ImageVector& p);
975 inline void _setCursorPos5DE(const ImageVector& p);
976 inline void _setCursorPos6DE(const ImageVector& p);
978
979 //--------------------------------------------------------------------------------------------------------------------------
982 //--------------------------------------------------------------------------------------------------------------------------
984 inline static void _setCursorPos1DCB(TVirtualVolume* obj, const ImageVector& p)
985 {
986 obj->_setCursorPos1D(p);
987 };
988 inline static void _setCursorPos2DCB(TVirtualVolume* obj, const ImageVector& p)
989 {
990 obj->_setCursorPos2D(p);
991 };
992 inline static void _setCursorPos3DCB(TVirtualVolume* obj, const ImageVector& p)
993 {
994 obj->_setCursorPos3D(p);
995 };
996 inline static void _setCursorPos4DCB(TVirtualVolume* obj, const ImageVector& p)
997 {
998 obj->_setCursorPos4D(p);
999 };
1000 inline static void _setCursorPos5DCB(TVirtualVolume* obj, const ImageVector& p)
1001 {
1002 obj->_setCursorPos5D(p);
1003 };
1004 inline static void _setCursorPos6DCB(TVirtualVolume* obj, const ImageVector& p)
1005 {
1006 obj->_setCursorPos6D(p);
1007 };
1008
1009 inline static void _setCursorPos1DCBE(TVirtualVolume* obj, const ImageVector& p)
1010 {
1011 obj->_setCursorPos1DE(p);
1012 };
1013 inline static void _setCursorPos2DCBE(TVirtualVolume* obj, const ImageVector& p)
1014 {
1015 obj->_setCursorPos2DE(p);
1016 };
1017 inline static void _setCursorPos3DCBE(TVirtualVolume* obj, const ImageVector& p)
1018 {
1019 obj->_setCursorPos3DE(p);
1020 };
1021 inline static void _setCursorPos4DCBE(TVirtualVolume* obj, const ImageVector& p)
1022 {
1023 obj->_setCursorPos4DE(p);
1024 };
1025 inline static void _setCursorPos5DCBE(TVirtualVolume* obj, const ImageVector& p)
1026 {
1027 obj->_setCursorPos5DE(p);
1028 };
1029 inline static void _setCursorPos6DCBE(TVirtualVolume* obj, const ImageVector& p)
1030 {
1031 obj->_setCursorPos6DE(p);
1032 };
1034
1035
1036 //----------------------------------------------------------------------------------
1037 //----------------------------------------------------------------------------------
1039 //----------------------------------------------------------------------------------
1040 //----------------------------------------------------------------------------------
1041
1042 //----------------------------------------------------------------------------------
1044 //----------------------------------------------------------------------------------
1046 inline void _moveCursorOffset1D(const ImageVector& p);
1047 inline void _moveCursorOffset2D(const ImageVector& p);
1048 inline void _moveCursorOffset3D(const ImageVector& p);
1049 inline void _moveCursorOffset4D(const ImageVector& p);
1050 inline void _moveCursorOffset5D(const ImageVector& p);
1051 inline void _moveCursorOffset6D(const ImageVector& p);
1052
1053 inline void _moveCursorOffset1DE(const ImageVector& p);
1054 inline void _moveCursorOffset2DE(const ImageVector& p);
1055 inline void _moveCursorOffset3DE(const ImageVector& p);
1056 inline void _moveCursorOffset4DE(const ImageVector& p);
1057 inline void _moveCursorOffset5DE(const ImageVector& p);
1058 inline void _moveCursorOffset6DE(const ImageVector& p);
1060
1061 //--------------------------------------------------------------------------------------------------------------------------
1064 //--------------------------------------------------------------------------------------------------------------------------
1067 {
1068 obj->_moveCursorOffset1D(p);
1069 };
1071 {
1072 obj->_moveCursorOffset2D(p);
1073 };
1075 {
1076 obj->_moveCursorOffset3D(p);
1077 };
1079 {
1080 obj->_moveCursorOffset4D(p);
1081 };
1083 {
1084 obj->_moveCursorOffset5D(p);
1085 };
1087 {
1088 obj->_moveCursorOffset6D(p);
1089 };
1090
1092 {
1093 obj->_moveCursorOffset1DE(p);
1094 };
1096 {
1097 obj->_moveCursorOffset2DE(p);
1098 };
1100 {
1101 obj->_moveCursorOffset3DE(p);
1102 };
1104 {
1105 obj->_moveCursorOffset4DE(p);
1106 };
1108 {
1109 obj->_moveCursorOffset5DE(p);
1110 };
1112 {
1113 obj->_moveCursorOffset6DE(p);
1114 };
1116
1117
1118 //----------------------------------------------------------------------------------
1119 //----------------------------------------------------------------------------------
1121 //----------------------------------------------------------------------------------
1122 //----------------------------------------------------------------------------------
1123
1124 // In the following sections multiple expressions such as
1125 // _cIdx -= static_cast<MLuint>(_pStrides.x);
1126 // are performed with casts to unsigned MLuint64 values, because according to C-standard
1127 // the signed values are cast to unsigned int 64 before subtracting anyway; and this
1128 // which is warned by compilers.
1129 // Therefore the cast is done explicitly, which is okay, when considering that negative
1130 // signed values are cast, converted to usually large unsigned values which are added
1131 // with overflows resulting to the same value.
1132
1133
1134 //--------------------------------------------------------------------------------------------------------------------------
1136 //--------------------------------------------------------------------------------------------------------------------------
1138 // See notes about casts at line 1000.
1139 inline void _moveFX()
1140 {
1141 _cPos.x++;
1142 _cIdx += static_cast<MLuint>(_pStrides.x);
1143 if ((_cPos.x & _idxMask.x) == 0) {
1144 _cPageIdx += static_cast<MLuint>(_strides.x);
1145 }
1146 }
1147 inline void _moveFY()
1148 {
1149 _cPos.y++;
1150 _cIdx += static_cast<MLuint>(_pStrides.y);
1151 if ((_cPos.y & _idxMask.y) == 0) {
1152 _cPageIdx += static_cast<MLuint>(_strides.y);
1153 }
1154 }
1155 inline void _moveFZ()
1156 {
1157 _cPos.z++;
1158 _cIdx += static_cast<MLuint>(_pStrides.z);
1159 if ((_cPos.z & _idxMask.z) == 0) {
1160 _cPageIdx += static_cast<MLuint>(_strides.z);
1161 }
1162 }
1163 inline void _moveFC()
1164 {
1165 _cPos.c++;
1166 _cIdx += static_cast<MLuint>(_pStrides.c);
1167 if ((_cPos.c & _idxMask.c) == 0) {
1168 _cPageIdx += static_cast<MLuint>(_strides.c);
1169 }
1170 }
1171 inline void _moveFT()
1172 {
1173 _cPos.t++;
1174 _cIdx += static_cast<MLuint>(_pStrides.t);
1175 if ((_cPos.t & _idxMask.t) == 0) {
1176 _cPageIdx += static_cast<MLuint>(_strides.t);
1177 }
1178 }
1179 inline void _moveFU()
1180 {
1181 _cPos.u++;
1182 _cIdx += static_cast<MLuint>(_pStrides.u);
1183 if ((_cPos.u & _idxMask.u) == 0) {
1184 _cPageIdx += static_cast<MLuint>(_strides.u);
1185 }
1186 }
1187
1188 inline void _moveFXE()
1189 {
1190 if (_cPos.x < _extD.x) {
1191 _moveFX();
1192 }
1193 else {
1194 throw(ML_OUT_OF_RANGE);
1195 }
1196 }
1197 inline void _moveFYE()
1198 {
1199 if (_cPos.y < _extD.y) {
1200 _moveFY();
1201 }
1202 else {
1203 throw(ML_OUT_OF_RANGE);
1204 }
1205 }
1206 inline void _moveFZE()
1207 {
1208 if (_cPos.z < _extD.z) {
1209 _moveFZ();
1210 }
1211 else {
1212 throw(ML_OUT_OF_RANGE);
1213 }
1214 }
1215 inline void _moveFCE()
1216 {
1217 if (_cPos.c < _extD.c) {
1218 _moveFC();
1219 }
1220 else {
1221 throw(ML_OUT_OF_RANGE);
1222 }
1223 }
1224 inline void _moveFTE()
1225 {
1226 if (_cPos.t < _extD.t) {
1227 _moveFT();
1228 }
1229 else {
1230 throw(ML_OUT_OF_RANGE);
1231 }
1232 }
1233 inline void _moveFUE()
1234 {
1235 if (_cPos.u < _extD.u) {
1236 _moveFU();
1237 }
1238 else {
1239 throw(ML_OUT_OF_RANGE);
1240 }
1241 }
1243
1244 //--------------------------------------------------------------------------------------------------------------------------
1247 //--------------------------------------------------------------------------------------------------------------------------
1249 inline static void _moveFXCB(TVirtualVolume* obj)
1250 {
1251 obj->_moveFX();
1252 }
1253 inline static void _moveFYCB(TVirtualVolume* obj)
1254 {
1255 obj->_moveFY();
1256 }
1257 inline static void _moveFZCB(TVirtualVolume* obj)
1258 {
1259 obj->_moveFZ();
1260 }
1261 inline static void _moveFCCB(TVirtualVolume* obj)
1262 {
1263 obj->_moveFC();
1264 }
1265 inline static void _moveFTCB(TVirtualVolume* obj)
1266 {
1267 obj->_moveFT();
1268 }
1269 inline static void _moveFUCB(TVirtualVolume* obj)
1270 {
1271 obj->_moveFU();
1272 }
1273
1274 inline static void _moveFXCBE(TVirtualVolume* obj)
1275 {
1276 obj->_moveFXE();
1277 }
1278 inline static void _moveFYCBE(TVirtualVolume* obj)
1279 {
1280 obj->_moveFYE();
1281 }
1282 inline static void _moveFZCBE(TVirtualVolume* obj)
1283 {
1284 obj->_moveFZE();
1285 }
1286 inline static void _moveFCCBE(TVirtualVolume* obj)
1287 {
1288 obj->_moveFCE();
1289 }
1290 inline static void _moveFTCBE(TVirtualVolume* obj)
1291 {
1292 obj->_moveFTE();
1293 }
1294 inline static void _moveFUCBE(TVirtualVolume* obj)
1295 {
1296 obj->_moveFUE();
1297 }
1299
1300 //--------------------------------------------------------------------------------------------------------------------------
1302 //--------------------------------------------------------------------------------------------------------------------------
1304 // See notes about casts at line 1000.
1305 inline void _moveBX()
1306 {
1307 _cPos.x--;
1308 _cIdx -= static_cast<MLuint>(_pStrides.x);
1309 if ((_cPos.x & _idxMask.x) == _idxMask.x) {
1310 _cPageIdx -= static_cast<MLuint>(_strides.x);
1311 }
1312 }
1313 inline void _moveBY()
1314 {
1315 _cPos.y--;
1316 _cIdx -= static_cast<MLuint>(_pStrides.y);
1317 if ((_cPos.y & _idxMask.y) == _idxMask.y) {
1318 _cPageIdx -= static_cast<MLuint>(_strides.y);
1319 }
1320 }
1321 inline void _moveBZ()
1322 {
1323 _cPos.z--;
1324 _cIdx -= static_cast<MLuint>(_pStrides.z);
1325 if ((_cPos.z & _idxMask.z) == _idxMask.z) {
1326 _cPageIdx -= static_cast<MLuint>(_strides.z);
1327 }
1328 }
1329 inline void _moveBC()
1330 {
1331 _cPos.c--;
1332 _cIdx -= static_cast<MLuint>(_pStrides.c);
1333 if ((_cPos.c & _idxMask.c) == _idxMask.c) {
1334 _cPageIdx -= static_cast<MLuint>(_strides.c);
1335 }
1336 }
1337 inline void _moveBT()
1338 {
1339 _cPos.t--;
1340 _cIdx -= static_cast<MLuint>(_pStrides.t);
1341 if ((_cPos.t & _idxMask.t) == _idxMask.t) {
1342 _cPageIdx -= static_cast<MLuint>(_strides.t);
1343 }
1344 }
1345 inline void _moveBU()
1346 {
1347 _cPos.u--;
1348 _cIdx -= static_cast<MLuint>(_pStrides.u);
1349 if ((_cPos.u & _idxMask.u) == _idxMask.u) {
1350 _cPageIdx -= static_cast<MLuint>(_strides.u);
1351 }
1352 }
1353
1356#define _VV_MOVEBE_TEST(Q) \
1357 if (_cPos.Q >= 0) { \
1358 _cPageIdx -= static_cast<MLuint>(_strides.Q); \
1359 } \
1360 else { \
1361 _cPos.Q++; \
1362 _cIdx += static_cast<MLuint>(_pStrides.Q); \
1363 throw(ML_OUT_OF_RANGE); \
1364 }
1365
1366 // See notes about casts at line 1000.
1367 inline void _moveBXE()
1368 {
1369 _cPos.x--;
1370 _cIdx -= static_cast<MLuint>(_pStrides.x);
1371 if ((_cPos.x & _idxMask.x) == _idxMask.x) {
1372 _VV_MOVEBE_TEST(x);
1373 }
1374 }
1375 inline void _moveBYE()
1376 {
1377 _cPos.y--;
1378 _cIdx -= static_cast<MLuint>(_pStrides.y);
1379 if ((_cPos.y & _idxMask.y) == _idxMask.y) {
1380 _VV_MOVEBE_TEST(y);
1381 }
1382 }
1383 inline void _moveBZE()
1384 {
1385 _cPos.z--;
1386 _cIdx -= static_cast<MLuint>(_pStrides.z);
1387 if ((_cPos.z & _idxMask.z) == _idxMask.z) {
1388 _VV_MOVEBE_TEST(z);
1389 }
1390 }
1391 inline void _moveBCE()
1392 {
1393 _cPos.c--;
1394 _cIdx -= static_cast<MLuint>(_pStrides.c);
1395 if ((_cPos.c & _idxMask.c) == _idxMask.c) {
1396 _VV_MOVEBE_TEST(c);
1397 }
1398 }
1399 inline void _moveBTE()
1400 {
1401 _cPos.t--;
1402 _cIdx -= static_cast<MLuint>(_pStrides.t);
1403 if ((_cPos.t & _idxMask.t) == _idxMask.t) {
1404 _VV_MOVEBE_TEST(t);
1405 }
1406 }
1407 inline void _moveBUE()
1408 {
1409 _cPos.u--;
1410 _cIdx -= static_cast<MLuint>(_pStrides.u);
1411 if ((_cPos.u & _idxMask.u) == _idxMask.u) {
1412 _VV_MOVEBE_TEST(u);
1413 }
1414 }
1415#undef _VV_MOVEBE_TEST
1417
1418
1419 //--------------------------------------------------------------------------------------------------------------------------
1422 //--------------------------------------------------------------------------------------------------------------------------
1424 inline static void _moveBXCB(TVirtualVolume* obj)
1425 {
1426 obj->_moveBX();
1427 }
1428 inline static void _moveBYCB(TVirtualVolume* obj)
1429 {
1430 obj->_moveBY();
1431 }
1432 inline static void _moveBZCB(TVirtualVolume* obj)
1433 {
1434 obj->_moveBZ();
1435 }
1436 inline static void _moveBCCB(TVirtualVolume* obj)
1437 {
1438 obj->_moveBC();
1439 }
1440 inline static void _moveBTCB(TVirtualVolume* obj)
1441 {
1442 obj->_moveBT();
1443 }
1444 inline static void _moveBUCB(TVirtualVolume* obj)
1445 {
1446 obj->_moveBU();
1447 }
1448
1449 inline static void _moveBXCBE(TVirtualVolume* obj)
1450 {
1451 obj->_moveBXE();
1452 }
1453 inline static void _moveBYCBE(TVirtualVolume* obj)
1454 {
1455 obj->_moveBYE();
1456 }
1457 inline static void _moveBZCBE(TVirtualVolume* obj)
1458 {
1459 obj->_moveBZE();
1460 }
1461 inline static void _moveBCCBE(TVirtualVolume* obj)
1462 {
1463 obj->_moveBCE();
1464 }
1465 inline static void _moveBTCBE(TVirtualVolume* obj)
1466 {
1467 obj->_moveBTE();
1468 }
1469 inline static void _moveBUCBE(TVirtualVolume* obj)
1470 {
1471 obj->_moveBUE();
1472 }
1474
1475
1476private:
1478 typedef DATATYPE (*GetVoxelFunc)(TVirtualVolume* obj, const ImageVector& p);
1479
1481 typedef void (*SetVoxelFunc)(TVirtualVolume* obj, const ImageVector& p, DATATYPE voxVal);
1482
1484 typedef bool (*IsMappedFunc)(const TVirtualVolume* obj, const ImageVector& p);
1485
1487 typedef void (*SetCursorPosFunc)(TVirtualVolume* obj, const ImageVector& p);
1488
1490 typedef void (*MoveCursorOffsetFunc)(TVirtualVolume* obj, const ImageVector& p);
1491
1493 typedef void (*MoveCursorPosFunc)(TVirtualVolume* obj);
1494
1498 VirtualVolume* _convenienceInstance;
1499
1501 VirtualVolume* _virtVol;
1502
1504 ImageVector _ext;
1505
1507 ImageVector _extD;
1508
1510 PageBuffer* _pageArray;
1511
1514 ImageVector _rShift;
1515
1517 ImageVector _strides;
1518
1520 ImageVector _pStrides;
1521
1523 ImageVector _idxMask;
1524
1526 GetVoxelFunc _getVoxelFunc;
1527
1529 SetVoxelFunc _setVoxelFunc;
1530
1532 IsMappedFunc _isMappedFunc;
1533
1535 SetCursorPosFunc _setCursorPosFunc;
1536
1538 MoveCursorOffsetFunc _moveCursorOffsetFunc;
1539
1542 MoveCursorPosFunc _moveFXFunc;
1543 MoveCursorPosFunc _moveFYFunc;
1544 MoveCursorPosFunc _moveFZFunc;
1545 MoveCursorPosFunc _moveFCFunc;
1546 MoveCursorPosFunc _moveFTFunc;
1547 MoveCursorPosFunc _moveFUFunc;
1548
1549 MoveCursorPosFunc _moveBXFunc;
1550 MoveCursorPosFunc _moveBYFunc;
1551 MoveCursorPosFunc _moveBZFunc;
1552 MoveCursorPosFunc _moveBCFunc;
1553 MoveCursorPosFunc _moveBTFunc;
1554 MoveCursorPosFunc _moveBUFunc;
1556
1558 ImageVector _cPos;
1559
1561 MLuint _cPageIdx;
1562
1564 MLuint _cIdx;
1565
1567 bool _useExc;
1568};
1569
1570//--------------------------------------------------------------------------------------------------------
1571// END OF USER INTERFACE
1572//--------------------------------------------------------------------------------------------------------
1573
1574
1575//--------------------------------------------------------------------------------------------------------
1576//--------------------------------------------------------------------------------------------------------
1577// Implementation part of Virtual Volume.
1578//--------------------------------------------------------------------------------------------------------
1579//--------------------------------------------------------------------------------------------------------
1580
1581template <typename DATATYPE>
1583{
1584 for (MLuint c = 0; c < num; c++) {
1585 *results = _getVoxelFunc(this, *pos);
1586 results++;
1587 pos++;
1588 }
1589}
1590
1591template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::setCursorValue(DATATYPE val)
1592{
1593 PageBuffer* page = _pageArray + _cPageIdx;
1594 (static_cast<DATATYPE*>(page->_getPageFkt(page)))[_cIdx] = val;
1595 page->_locked = true;
1596}
1597
1599template <typename DATATYPE> inline DATATYPE TVirtualVolume<DATATYPE>::getCursorValue()
1600{
1601 PageBuffer* page = _pageArray + _cPageIdx;
1602 return (static_cast<DATATYPE*>(page->_getPageFkt(page)))[_cIdx];
1603}
1604
1606template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::resetCursor()
1607{
1608 static const ImageVector zeroPos(0);
1609 _setCursorPosFunc(this, zeroPos);
1610}
1611
1621template <typename DATATYPE> inline bool TVirtualVolume<DATATYPE>::moveCursorXWrapAround()
1622{
1623 if (_cPos.x < _extD.x) {
1624 _moveFXFunc(this);
1625 return true;
1626 }
1627 else {
1628 if (_cPos.y < _extD.y) {
1629 _moveFYFunc(this);
1630 }
1631 else {
1632 if (_cPos.z < _extD.z) {
1633 _moveFZFunc(this);
1634 }
1635 else {
1636 if (_cPos.c < _extD.c) {
1637 _moveFCFunc(this);
1638 }
1639 else {
1640 if (_cPos.t < _extD.t) {
1641 _moveFTFunc(this);
1642 }
1643 else {
1644 if (_cPos.u < _extD.u) {
1645 _moveFUFunc(this);
1646 }
1647 else {
1648 // Just return false but do not move cursor any
1649 // further. This makes loops much easier.
1650 return false;
1651 }
1652 _cPos.t = 0;
1653 }
1654 _cPos.c = 0;
1655 }
1656 _cPos.z = 0;
1657 }
1658 _cPos.y = 0;
1659 }
1660 _cPos.x = 0;
1661
1662 // Cursor position has been reset in any component. Update settings.
1663 _setCursorPosFunc(this, _cPos);
1664 return true;
1665 }
1666}
1667
1669template <typename DATATYPE> void TVirtualVolume<DATATYPE>::fill(const SubImageBox& box, DATATYPE value)
1670{
1671 // Restrict size of filled area to valid image regions.
1672 SubImageBox subImgBox = SubImageBox::intersect(box, _virtVol->getBox());
1673
1674 // Note: Future versions could optimise inner loop significantly
1675 // by filling complete rows in pages with memcpy statements
1676 // from a prefilled row (or even by using subimage copies
1677 // from a prefilled page if many pages are filled).
1678 ImageVector p;
1679 for (p.u = subImgBox.v1.u; p.u <= subImgBox.v2.u; p.u++) {
1680 for (p.t = subImgBox.v1.t; p.t <= subImgBox.v2.t; p.t++) {
1681 for (p.c = subImgBox.v1.c; p.c <= subImgBox.v2.c; p.c++) {
1682 for (p.z = subImgBox.v1.z; p.z <= subImgBox.v2.z; p.z++) {
1683 for (p.y = subImgBox.v1.y; p.y <= subImgBox.v2.y; p.y++) {
1684 for (p.x = subImgBox.v1.x; p.x <= subImgBox.v2.x; p.x++) {
1685 setValue(p, value);
1686 } // x
1687 }
1688 }
1689 }
1690 }
1691 } // u
1692}
1693
1694//-----------------------------------------------------------------------------------------------
1696//-----------------------------------------------------------------------------------------------
1697template <typename DATATYPE> void TVirtualVolume<DATATYPE>::copyToSubImage(TSubImage<DATATYPE>& outSubImg)
1698{
1699 _virtVol->copyToSubImage(outSubImg);
1700}
1701
1702//-----------------------------------------------------------------------------------------------
1704//-----------------------------------------------------------------------------------------------
1706 const SubImageBox& box,
1707 const ImageVector& pos)
1708{
1709 // Get extents of subImg as box.
1710 SubImageBox inBox = inImg.getBoxFromImageExtent();
1711
1712 // Determine valid area in inImg which can be copied (overlap of inBox and box).
1713 // (Source area)
1714 SubImageBox srcBox = SubImageBox::intersect(inBox, box);
1715
1716 // Get extents of virtualVolume as box.
1717 SubImageBox vvBox = _virtVol->getBox();
1718
1719 // Determine the area where srcBox is copied to.
1721 tvvBox.v1 = srcBox.v1 + pos;
1722 tvvBox.v2 = srcBox.v2 + pos;
1723
1724 // Restrict tvvBox to valid virtualVolume extents. (Destination area)
1725 SubImageBox dstBox = SubImageBox::intersect(vvBox, tvvBox);
1726
1727 // Iterate over all voxels of the destination area in the virtual volume.
1729 for (dPos.u = dstBox.v1.u, sPos.u = srcBox.v1.u; dPos.u <= dstBox.v2.u; dPos.u++, sPos.u++) {
1730 for (dPos.t = dstBox.v1.t, sPos.t = srcBox.v1.t; dPos.t <= dstBox.v2.t; dPos.t++, sPos.t++) {
1731 for (dPos.c = dstBox.v1.c, sPos.c = srcBox.v1.c; dPos.c <= dstBox.v2.c; dPos.c++, sPos.c++) {
1732 for (dPos.z = dstBox.v1.z, sPos.z = srcBox.v1.z; dPos.z <= dstBox.v2.z; dPos.z++, sPos.z++) {
1733 for (dPos.y = dstBox.v1.y, sPos.y = srcBox.v1.y; dPos.y <= dstBox.v2.y; dPos.y++, sPos.y++) {
1734 for (dPos.x = dstBox.v1.x, sPos.x = srcBox.v1.x; dPos.x <= dstBox.v2.x; dPos.x++, sPos.x++) {
1735 setValue(dPos, inImg.getSubImageValue(sPos));
1736 } // x
1737 }
1738 }
1739 }
1740 }
1741 } // u
1742}
1743
1747template <typename DATATYPE> void TVirtualVolume<DATATYPE>::_init(VirtualVolume& vVol)
1748{
1749 // To avoid a typical programming error force a fatal error if the template data type
1750 // does not match the virtual volume data type.
1751 if (vVol.getDataType() != MLGetDataTypeFromPtr(static_cast<DATATYPE*>(nullptr))) {
1752 ML_PRINT_FATAL_ERROR("TVirtualVolume<DATATYPE>::_init()", ML_BAD_DATA_TYPE,
1753 "Mismatch of data type of virtual volume and template typename");
1754 }
1755
1756 // Get some parameters from virtual volume instance.
1757 // _convenienceInstance = ...; // Must be initialized in all constructors before.
1758 _virtVol = &vVol;
1759 _ext = vVol._origVolumeExt;
1760 _extD = vVol._origVolumeExt - ImageVector(1);
1761 _pageArray = vVol._pageArray;
1762 _rShift = vVol._rShift;
1763 _strides = vVol._strides;
1764 _pStrides = vVol._pStrides;
1765 _idxMask = vVol._idxMask;
1766 _useExc = vVol._areExceptionsOn;
1767
1768 // Set cursor position, cursor index and cursor page.
1769 _cPos = ImageVector(0);
1770 _cIdx = 0;
1771 _cPageIdx = 0;
1772
1773 // Dependent on the dimension of the image we can select different read/write
1774 // functions. We do this to avoid unnecessary calculations of 6d coordinates
1775 // if the volume has only e.g. 2 dimensions.
1776 if (_useExc) {
1777
1779 _moveFXFunc = _moveFXCBE;
1780 _moveFYFunc = _moveFYCBE;
1781 _moveFZFunc = _moveFZCBE;
1782 _moveFCFunc = _moveFCCBE;
1783 _moveFTFunc = _moveFTCBE;
1784 _moveFUFunc = _moveFUCBE;
1785
1786 _moveBXFunc = _moveBXCBE;
1787 _moveBYFunc = _moveBYCBE;
1788 _moveBZFunc = _moveBZCBE;
1789 _moveBCFunc = _moveBCCBE;
1790 _moveBTFunc = _moveBTCBE;
1791 _moveBUFunc = _moveBUCBE;
1792
1793 // Set the correct setValue/getValue and setCursorPosition functions.
1794 switch (vVol.getDim()) {
1795 case 1:
1796 _getVoxelFunc = _getVoxel1DCBE;
1797 _setVoxelFunc = _setVoxel1DCBE;
1798 _setCursorPosFunc = _setCursorPos1DCBE;
1799 _moveCursorOffsetFunc = _moveCursorOffset1DCBE;
1800 _isMappedFunc = _isMapped1DCBE;
1801 break;
1802 case 2:
1803 _getVoxelFunc = _getVoxel2DCBE;
1804 _setVoxelFunc = _setVoxel2DCBE;
1805 _setCursorPosFunc = _setCursorPos2DCBE;
1806 _moveCursorOffsetFunc = _moveCursorOffset2DCBE;
1807 _isMappedFunc = _isMapped2DCBE;
1808 break;
1809 case 3:
1810 _getVoxelFunc = _getVoxel3DCBE;
1811 _setVoxelFunc = _setVoxel3DCBE;
1812 _setCursorPosFunc = _setCursorPos3DCBE;
1813 _moveCursorOffsetFunc = _moveCursorOffset3DCBE;
1814 _isMappedFunc = _isMapped3DCBE;
1815 break;
1816 case 4:
1817 _getVoxelFunc = _getVoxel4DCBE;
1818 _setVoxelFunc = _setVoxel4DCBE;
1819 _setCursorPosFunc = _setCursorPos4DCBE;
1820 _moveCursorOffsetFunc = _moveCursorOffset4DCBE;
1821 _isMappedFunc = _isMapped4DCBE;
1822 break;
1823 case 5:
1824 _getVoxelFunc = _getVoxel5DCBE;
1825 _setVoxelFunc = _setVoxel5DCBE;
1826 _setCursorPosFunc = _setCursorPos5DCBE;
1827 _moveCursorOffsetFunc = _moveCursorOffset5DCBE;
1828 _isMappedFunc = _isMapped5DCBE;
1829 break;
1830 case 6:
1831 _getVoxelFunc = _getVoxel6DCBE;
1832 _setVoxelFunc = _setVoxel6DCBE;
1833 _setCursorPosFunc = _setCursorPos6DCBE;
1834 _moveCursorOffsetFunc = _moveCursorOffset6DCBE;
1835 _isMappedFunc = _isMapped6DCBE;
1836 break;
1837 default:
1838 _getVoxelFunc = _getVoxel6DCBE;
1839 _setVoxelFunc = _setVoxel6DCBE;
1840 _moveCursorOffsetFunc = _moveCursorOffset6DCBE;
1841 _setCursorPosFunc = _setCursorPos6DCBE;
1842 _isMappedFunc = _isMapped6DCBE;
1843 _virtVol->invalidate();
1844 throw(ML_BAD_DIMENSION);
1845 break;
1846 }
1847 }
1848 else {
1849
1851 _moveFXFunc = _moveFXCB;
1852 _moveFYFunc = _moveFYCB;
1853 _moveFZFunc = _moveFZCB;
1854 _moveFCFunc = _moveFCCB;
1855 _moveFTFunc = _moveFTCB;
1856 _moveFUFunc = _moveFUCB;
1857
1858 _moveBXFunc = _moveBXCB;
1859 _moveBYFunc = _moveBYCB;
1860 _moveBZFunc = _moveBZCB;
1861 _moveBCFunc = _moveBCCB;
1862 _moveBTFunc = _moveBTCB;
1863 _moveBUFunc = _moveBUCB;
1864
1865 // Set the correct setValue/getValue and setCursorPosition functions.
1866 switch (vVol.getDim()) {
1867 case 1:
1868 _getVoxelFunc = _getVoxel1DCB;
1869 _setVoxelFunc = _setVoxel1DCB;
1870 _setCursorPosFunc = _setCursorPos1DCB;
1871 _moveCursorOffsetFunc = _moveCursorOffset1DCB;
1872 _isMappedFunc = _isMapped1DCB;
1873 break;
1874 case 2:
1875 _getVoxelFunc = _getVoxel2DCB;
1876 _setVoxelFunc = _setVoxel2DCB;
1877 _setCursorPosFunc = _setCursorPos2DCB;
1878 _moveCursorOffsetFunc = _moveCursorOffset2DCB;
1879 _isMappedFunc = _isMapped2DCB;
1880 break;
1881 case 3:
1882 _getVoxelFunc = _getVoxel3DCB;
1883 _setVoxelFunc = _setVoxel3DCB;
1884 _setCursorPosFunc = _setCursorPos3DCB;
1885 _moveCursorOffsetFunc = _moveCursorOffset3DCB;
1886 _isMappedFunc = _isMapped3DCB;
1887 break;
1888 case 4:
1889 _getVoxelFunc = _getVoxel4DCB;
1890 _setVoxelFunc = _setVoxel4DCB;
1891 _setCursorPosFunc = _setCursorPos4DCB;
1892 _moveCursorOffsetFunc = _moveCursorOffset4DCB;
1893 _isMappedFunc = _isMapped4DCB;
1894 break;
1895 case 5:
1896 _getVoxelFunc = _getVoxel5DCB;
1897 _setVoxelFunc = _setVoxel5DCB;
1898 _setCursorPosFunc = _setCursorPos5DCB;
1899 _moveCursorOffsetFunc = _moveCursorOffset5DCB;
1900 _isMappedFunc = _isMapped5DCB;
1901 break;
1902 case 6:
1903 _getVoxelFunc = _getVoxel6DCB;
1904 _setVoxelFunc = _setVoxel6DCB;
1905 _setCursorPosFunc = _setCursorPos6DCB;
1906 _moveCursorOffsetFunc = _moveCursorOffset6DCB;
1907 _isMappedFunc = _isMapped6DCB;
1908 break;
1909 default:
1910 _getVoxelFunc = _getVoxel6DCB;
1911 _setVoxelFunc = _setVoxel6DCB;
1912 _setCursorPosFunc = _setCursorPos6DCB;
1913 _moveCursorOffsetFunc = _moveCursorOffset6DCB;
1914 _isMappedFunc = _isMapped6DCBE;
1915 _virtVol->invalidate();
1916 ML_PRINT_ERROR("TVirtualVolume::_init()", ML_BAD_DIMENSION, "Invalid image dimension. Using dimension 6. \n");
1917 break;
1918 }
1919 }
1920}
1921
1923template <typename DATATYPE> void TVirtualVolume<DATATYPE>::_cleanUp()
1924{
1925 // _convenienceInstance = ...; // Must be handled in destructor explicitly.
1926 _virtVol = nullptr;
1927 _ext = ImageVector(0);
1928 _extD = ImageVector(0);
1929 _pageArray = nullptr;
1930 _rShift = ImageVector(0);
1931 _strides = ImageVector(0);
1932 _pStrides = ImageVector(0);
1933 _getVoxelFunc = nullptr;
1934 _setVoxelFunc = nullptr;
1935 _setCursorPosFunc = nullptr;
1936 _moveCursorOffsetFunc = nullptr;
1937 _isMappedFunc = nullptr;
1938 _moveFXFunc = nullptr;
1939 _moveFYFunc = nullptr;
1940 _moveFZFunc = nullptr;
1941 _moveFCFunc = nullptr;
1942 _moveFTFunc = nullptr;
1943 _moveFUFunc = nullptr;
1944 _moveBXFunc = nullptr;
1945 _moveBYFunc = nullptr;
1946 _moveBZFunc = nullptr;
1947 _moveBCFunc = nullptr;
1948 _moveBTFunc = nullptr;
1949 _moveBUFunc = nullptr;
1950 _idxMask = ImageVector(0);
1951 _cPos = ImageVector(0);
1952 _cIdx = 0;
1953 _cPageIdx = 0;
1954 _useExc = false;
1955}
1956
1957
1958//----------------------------------------------------------------------------------------------------------
1959// GetVoxel
1960//----------------------------------------------------------------------------------------------------------
1961
1963template <typename DATATYPE> inline DATATYPE TVirtualVolume<DATATYPE>::_getVoxel1D(const ImageVector& pos)
1964{
1965 PageBuffer* const page = _pageArray + (pos.x >> _rShift.x);
1966 return (static_cast<DATATYPE*>(page->_getPageFkt(page)))[pos.x];
1967};
1968
1970template <typename DATATYPE> inline DATATYPE TVirtualVolume<DATATYPE>::_getVoxel1DE(const ImageVector& pos)
1971{
1972 const MLint px = pos.x;
1973 if ((px < 0) || (px >= _ext.x)) {
1974 throw(ML_OUT_OF_RANGE);
1975 }
1976 PageBuffer* const page = _pageArray + (px >> _rShift.x);
1977 return (static_cast<DATATYPE*>(page->_getPageFkt(page)))[px];
1978};
1979
1980
1982template <typename DATATYPE> inline DATATYPE TVirtualVolume<DATATYPE>::_getVoxel2D(const ImageVector& pos)
1983{
1984 PageBuffer* const page = _pageArray + ((pos.x >> _rShift.x) + (pos.y >> _rShift.y) * _strides.y);
1985 return (static_cast<DATATYPE*>(page->_getPageFkt(page)))[pos.x + pos.y * _pStrides.y];
1986};
1987
1989template <typename DATATYPE> inline DATATYPE TVirtualVolume<DATATYPE>::_getVoxel2DE(const ImageVector& pos)
1990{
1991 const MLint px = pos.x;
1992 const MLint py = pos.y;
1993 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y)) {
1994 throw(ML_OUT_OF_RANGE);
1995 }
1996 PageBuffer* const page = _pageArray + ((px >> _rShift.x) + (py >> _rShift.y) * _strides.y);
1997 return (static_cast<DATATYPE*>(page->_getPageFkt(page)))[px + py * _pStrides.y];
1998};
1999
2000
2002template <typename DATATYPE> inline DATATYPE TVirtualVolume<DATATYPE>::_getVoxel3D(const ImageVector& pos)
2003{
2004 PageBuffer* const page =
2005 _pageArray + ((pos.x >> _rShift.x) + (pos.y >> _rShift.y) * _strides.y + (pos.z >> _rShift.z) * _strides.z);
2006 return (static_cast<DATATYPE*>(page->_getPageFkt(page)))[pos.x + pos.y * _pStrides.y + pos.z * _pStrides.z];
2007};
2008
2010template <typename DATATYPE> inline DATATYPE TVirtualVolume<DATATYPE>::_getVoxel3DE(const ImageVector& pos)
2011{
2012 const MLint px = pos.x;
2013 const MLint py = pos.y;
2014 const MLint pz = pos.z;
2015 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z)) {
2016 throw(ML_OUT_OF_RANGE);
2017 }
2018 PageBuffer* const page =
2019 _pageArray + ((px >> _rShift.x) + (py >> _rShift.y) * _strides.y + (pz >> _rShift.z) * _strides.z);
2020 return (static_cast<DATATYPE*>(page->_getPageFkt(page)))[px + py * _pStrides.y + pz * _pStrides.z];
2021};
2022
2023
2025template <typename DATATYPE> inline DATATYPE TVirtualVolume<DATATYPE>::_getVoxel4D(const ImageVector& pos)
2026{
2027 PageBuffer* const page = _pageArray + ((pos.x >> _rShift.x) + (pos.y >> _rShift.y) * _strides.y +
2028 (pos.z >> _rShift.z) * _strides.z + (pos.c >> _rShift.c) * _strides.c);
2029 return (static_cast<DATATYPE*>(
2030 page->_getPageFkt(page)))[pos.x + pos.y * _pStrides.y + pos.z * _pStrides.z + pos.c * _pStrides.c];
2031};
2032
2034template <typename DATATYPE> inline DATATYPE TVirtualVolume<DATATYPE>::_getVoxel4DE(const ImageVector& pos)
2035{
2036 const MLint px = pos.x;
2037 const MLint py = pos.y;
2038 const MLint pz = pos.z;
2039 const MLint pc = pos.c;
2040 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z) || (pc < 0) ||
2041 (pc >= _ext.c))
2042 {
2043 throw(ML_OUT_OF_RANGE);
2044 }
2045 PageBuffer* const page = _pageArray + ((px >> _rShift.x) + (py >> _rShift.y) * _strides.y +
2046 (pz >> _rShift.z) * _strides.z + (pc >> _rShift.c) * _strides.c);
2047 return (static_cast<DATATYPE*>(page->_getPageFkt(page)))[px + py * _pStrides.y + pz * _pStrides.z + pc * _pStrides.c];
2048};
2049
2051template <typename DATATYPE> inline DATATYPE TVirtualVolume<DATATYPE>::_getVoxel5D(const ImageVector& pos)
2052{
2053 PageBuffer* const page =
2054 _pageArray + ((pos.x >> _rShift.x) + (pos.y >> _rShift.y) * _strides.y + (pos.z >> _rShift.z) * _strides.z +
2055 (pos.c >> _rShift.c) * _strides.c + (pos.t >> _rShift.t) * _strides.t);
2056 return (static_cast<DATATYPE*>(page->_getPageFkt(
2057 page)))[pos.x + pos.y * _pStrides.y + pos.z * _pStrides.z + pos.c * _pStrides.c + pos.t * _pStrides.t];
2058};
2059
2061template <typename DATATYPE> inline DATATYPE TVirtualVolume<DATATYPE>::_getVoxel5DE(const ImageVector& pos)
2062{
2063 const MLint px = pos.x;
2064 const MLint py = pos.y;
2065 const MLint pz = pos.z;
2066 const MLint pc = pos.c;
2067 const MLint pt = pos.t;
2068 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z) || (pc < 0) ||
2069 (pc >= _ext.c) || (pt < 0) || (pt >= _ext.t))
2070 {
2071 throw(ML_OUT_OF_RANGE);
2072 }
2073 PageBuffer* const page =
2074 _pageArray + ((px >> _rShift.x) + (py >> _rShift.y) * _strides.y + (pz >> _rShift.z) * _strides.z +
2075 (pc >> _rShift.c) * _strides.c + (pt >> _rShift.t) * _strides.t);
2076 return (static_cast<DATATYPE*>(
2077 page->_getPageFkt(page)))[px + py * _pStrides.y + pz * _pStrides.z + pc * _pStrides.c + pt * _pStrides.t];
2078};
2079
2081template <typename DATATYPE> inline DATATYPE TVirtualVolume<DATATYPE>::_getVoxel6D(const ImageVector& pos)
2082{
2083 PageBuffer* const page = _pageArray + ((pos.x >> _rShift.x) + (pos.y >> _rShift.y) * _strides.y +
2084 (pos.z >> _rShift.z) * _strides.z + (pos.c >> _rShift.c) * _strides.c +
2085 (pos.t >> _rShift.t) * _strides.t + (pos.u >> _rShift.u) * _strides.u);
2086 return (
2087 static_cast<DATATYPE*>(page->_getPageFkt(page)))[pos.x + pos.y * _pStrides.y + pos.z * _pStrides.z +
2088 pos.c * _pStrides.c + pos.t * _pStrides.t + pos.u * _pStrides.u];
2089};
2090
2092template <typename DATATYPE> inline DATATYPE TVirtualVolume<DATATYPE>::_getVoxel6DE(const ImageVector& pos)
2093{
2094 const MLint px = pos.x;
2095 const MLint py = pos.y;
2096 const MLint pz = pos.z;
2097 const MLint pc = pos.c;
2098 const MLint pt = pos.t;
2099 const MLint pu = pos.u;
2100 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z) || (pc < 0) ||
2101 (pc >= _ext.c) || (pt < 0) || (pt >= _ext.t) || (pu < 0) || (pu >= _ext.u))
2102 {
2103 throw(ML_OUT_OF_RANGE);
2104 }
2105 PageBuffer* const page =
2106 _pageArray + ((px >> _rShift.x) + (py >> _rShift.y) * _strides.y + (pz >> _rShift.z) * _strides.z +
2107 (pc >> _rShift.c) * _strides.c + (pt >> _rShift.t) * _strides.t + (pu >> _rShift.u) * _strides.u);
2108 return (static_cast<DATATYPE*>(page->_getPageFkt(
2109 page)))[px + py * _pStrides.y + pz * _pStrides.z + pc * _pStrides.c + pt * _pStrides.t + pu * _pStrides.u];
2110};
2111
2112
2113//----------------------------------------------------------------------------------------------------------
2114// SetVoxel
2115//----------------------------------------------------------------------------------------------------------
2116
2117
2119template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setVoxel1D(const ImageVector& pos, DATATYPE voxVal)
2120{
2121 PageBuffer* const page = _pageArray + (pos.x >> _rShift.x);
2122 page->_locked = true;
2123 (static_cast<DATATYPE*>(page->_getPageFkt(page)))[pos.x] = voxVal;
2124};
2125
2127template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setVoxel1DE(const ImageVector& pos, DATATYPE voxVal)
2128{
2129 const MLint px = pos.x;
2130 if ((px < 0) || (px >= _ext.x)) {
2131 throw(ML_OUT_OF_RANGE);
2132 }
2133 PageBuffer* const page = _pageArray + (px >> _rShift.x);
2134 page->_locked = true;
2135 (static_cast<DATATYPE*>(page->_getPageFkt(page)))[px] = voxVal;
2136};
2137
2138
2140template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setVoxel2D(const ImageVector& pos, DATATYPE voxVal)
2141{
2142 PageBuffer* const page = _pageArray + ((pos.x >> _rShift.x) + (pos.y >> _rShift.y) * _strides.y);
2143 page->_locked = true;
2144 (static_cast<DATATYPE*>(page->_getPageFkt(page)))[pos.x + pos.y * _pStrides.y] = voxVal;
2145};
2146
2148template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setVoxel2DE(const ImageVector& pos, DATATYPE voxVal)
2149{
2150 const MLint px = pos.x;
2151 const MLint py = pos.y;
2152 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y)) {
2153 throw(ML_OUT_OF_RANGE);
2154 }
2155 PageBuffer* const page = _pageArray + ((px >> _rShift.x) + (py >> _rShift.y) * _strides.y);
2156 page->_locked = true;
2157 (static_cast<DATATYPE*>(page->_getPageFkt(page)))[px + py * _pStrides.y] = voxVal;
2158};
2159
2160
2162template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setVoxel3D(const ImageVector& pos, DATATYPE voxVal)
2163{
2164 PageBuffer* const page =
2165 _pageArray + ((pos.x >> _rShift.x) + (pos.y >> _rShift.y) * _strides.y + (pos.z >> _rShift.z) * _strides.z);
2166 page->_locked = true;
2167 (static_cast<DATATYPE*>(page->_getPageFkt(page)))[pos.x + pos.y * _pStrides.y + pos.z * _pStrides.z] = voxVal;
2168};
2169
2171template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setVoxel3DE(const ImageVector& pos, DATATYPE voxVal)
2172{
2173 const MLint px = pos.x;
2174 const MLint py = pos.y;
2175 const MLint pz = pos.z;
2176 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z)) {
2177 throw(ML_OUT_OF_RANGE);
2178 }
2179 PageBuffer* const page =
2180 _pageArray + ((px >> _rShift.x) + (py >> _rShift.y) * _strides.y + (pz >> _rShift.z) * _strides.z);
2181 page->_locked = true;
2182 (static_cast<DATATYPE*>(page->_getPageFkt(page)))[px + py * _pStrides.y + pz * _pStrides.z] = voxVal;
2183};
2184
2185
2187template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setVoxel4D(const ImageVector& pos, DATATYPE voxVal)
2188{
2189 PageBuffer* const page = _pageArray + ((pos.x >> _rShift.x) + (pos.y >> _rShift.y) * _strides.y +
2190 (pos.z >> _rShift.z) * _strides.z + (pos.c >> _rShift.c) * _strides.c);
2191 page->_locked = true;
2192 (static_cast<DATATYPE*>(
2193 page->_getPageFkt(page)))[pos.x + pos.y * _pStrides.y + pos.z * _pStrides.z + pos.c * _pStrides.c] = voxVal;
2194};
2195
2197template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setVoxel4DE(const ImageVector& pos, DATATYPE voxVal)
2198{
2199 const MLint px = pos.x;
2200 const MLint py = pos.y;
2201 const MLint pz = pos.z;
2202 const MLint pc = pos.c;
2203 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z) || (pc < 0) ||
2204 (pc >= _ext.c))
2205 {
2206 throw(ML_OUT_OF_RANGE);
2207 }
2208 PageBuffer* const page = _pageArray + ((px >> _rShift.x) + (py >> _rShift.y) * _strides.y +
2209 (pz >> _rShift.z) * _strides.z + (pc >> _rShift.c) * _strides.c);
2210 page->_locked = true;
2211 (static_cast<DATATYPE*>(page->_getPageFkt(page)))[px + py * _pStrides.y + pz * _pStrides.z + pc * _pStrides.c] =
2212 voxVal;
2213};
2214
2215
2217template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setVoxel5D(const ImageVector& pos, DATATYPE voxVal)
2218{
2219 PageBuffer* const page =
2220 _pageArray + ((pos.x >> _rShift.x) + (pos.y >> _rShift.y) * _strides.y + (pos.z >> _rShift.z) * _strides.z +
2221 (pos.c >> _rShift.c) * _strides.c + (pos.t >> _rShift.t) * _strides.t);
2222 page->_locked = true;
2223 (static_cast<DATATYPE*>(page->_getPageFkt(
2224 page)))[pos.x + pos.y * _pStrides.y + pos.z * _pStrides.z + pos.c * _pStrides.c + pos.t * _pStrides.t] = voxVal;
2225};
2226
2228template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setVoxel5DE(const ImageVector& pos, DATATYPE voxVal)
2229{
2230 const MLint px = pos.x;
2231 const MLint py = pos.y;
2232 const MLint pz = pos.z;
2233 const MLint pc = pos.c;
2234 const MLint pt = pos.t;
2235 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z) || (pc < 0) ||
2236 (pc >= _ext.c) || (pt < 0) || (pt >= _ext.t))
2237 {
2238 throw(ML_OUT_OF_RANGE);
2239 }
2240 PageBuffer* const page =
2241 _pageArray + ((px >> _rShift.x) + (py >> _rShift.y) * _strides.y + (pz >> _rShift.z) * _strides.z +
2242 (pc >> _rShift.c) * _strides.c + (pt >> _rShift.t) * _strides.t);
2243 page->_locked = true;
2244 (static_cast<DATATYPE*>(page->_getPageFkt(
2245 page)))[px + py * _pStrides.y + pz * _pStrides.z + pc * _pStrides.c + pt * _pStrides.t] = voxVal;
2246};
2247
2248
2250template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setVoxel6D(const ImageVector& pos, DATATYPE voxVal)
2251{
2252 PageBuffer* const page = _pageArray + ((pos.x >> _rShift.x) + (pos.y >> _rShift.y) * _strides.y +
2253 (pos.z >> _rShift.z) * _strides.z + (pos.c >> _rShift.c) * _strides.c +
2254 (pos.t >> _rShift.t) * _strides.t + (pos.u >> _rShift.u) * _strides.u);
2255 page->_locked = true;
2256 (static_cast<DATATYPE*>(page->_getPageFkt(page)))[pos.x + pos.y * _pStrides.y + pos.z * _pStrides.z +
2257 pos.c * _pStrides.c + pos.t * _pStrides.t + pos.u * _pStrides.u] =
2258 voxVal;
2259};
2260
2262template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setVoxel6DE(const ImageVector& pos, DATATYPE voxVal)
2263{
2264 const MLint px = pos.x;
2265 const MLint py = pos.y;
2266 const MLint pz = pos.z;
2267 const MLint pc = pos.c;
2268 const MLint pt = pos.t;
2269 const MLint pu = pos.u;
2270 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z) || (pc < 0) ||
2271 (pc >= _ext.c) || (pt < 0) || (pt >= _ext.t) || (pu < 0) || (pu >= _ext.u))
2272 {
2273 throw(ML_OUT_OF_RANGE);
2274 }
2275 PageBuffer* const page =
2276 _pageArray + ((px >> _rShift.x) + (py >> _rShift.y) * _strides.y + (pz >> _rShift.z) * _strides.z +
2277 (pc >> _rShift.c) * _strides.c + (pt >> _rShift.t) * _strides.t + (pu >> _rShift.u) * _strides.u);
2278 page->_locked = true;
2279 (static_cast<DATATYPE*>(page->_getPageFkt(
2280 page)))[px + py * _pStrides.y + pz * _pStrides.z + pc * _pStrides.c + pt * _pStrides.t + pu * _pStrides.u] =
2281 voxVal;
2282};
2283
2284
2285//----------------------------------------------------------------------------------------------------------
2286// SetCursorPos.
2287//----------------------------------------------------------------------------------------------------------
2288
2289
2291template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setCursorPos1D(const ImageVector& p)
2292{
2293 _cPos.x = p.x;
2294 _cIdx = static_cast<MLuint>(p.x);
2295 _cPageIdx = static_cast<MLuint>(p.x >> _rShift.x);
2296}
2297
2299template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setCursorPos1DE(const ImageVector& pos)
2300{
2301 const MLint px = pos.x;
2302 if ((px < 0) || (px >= _ext.x)) {
2303 throw(ML_OUT_OF_RANGE);
2304 }
2305 _cPos.x = px;
2306 _cIdx = static_cast<MLuint>(px);
2307 _cPageIdx = static_cast<MLuint>(px >> _rShift.x);
2308}
2309
2310
2312template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setCursorPos2D(const ImageVector& p)
2313{
2314 _cPos.x = p.x;
2315 _cPos.y = p.y;
2316 _cIdx = static_cast<MLuint>(p.x + p.y * _pStrides.y);
2317 _cPageIdx = static_cast<MLuint>((p.x >> _rShift.x) + (p.y >> _rShift.y) * _strides.y);
2318}
2319
2321template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setCursorPos2DE(const ImageVector& pos)
2322{
2323 const MLint px = pos.x;
2324 const MLint py = pos.y;
2325 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y)) {
2326 throw(ML_OUT_OF_RANGE);
2327 }
2328 _cPos.x = px;
2329 _cPos.y = py;
2330 _cIdx = static_cast<MLuint>(px + py * _pStrides.y);
2331 _cPageIdx = static_cast<MLuint>((px >> _rShift.x) + (py >> _rShift.y) * _strides.y);
2332}
2333
2334
2336template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setCursorPos3D(const ImageVector& p)
2337{
2338 _cPos.x = p.x;
2339 _cPos.y = p.y;
2340 _cPos.z = p.z;
2341 _cIdx = static_cast<MLuint>(p.x + p.y * _pStrides.y + p.z * _pStrides.z);
2342 _cPageIdx =
2343 static_cast<MLuint>((p.x >> _rShift.x) + (p.y >> _rShift.y) * _strides.y + (p.z >> _rShift.z) * _strides.z);
2344}
2345
2347template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setCursorPos3DE(const ImageVector& pos)
2348{
2349 const MLint px = pos.x;
2350 const MLint py = pos.y;
2351 const MLint pz = pos.z;
2352 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z)) {
2353 throw(ML_OUT_OF_RANGE);
2354 }
2355 _cPos.x = px;
2356 _cPos.y = py;
2357 _cPos.z = pz;
2358 _cIdx = static_cast<MLuint>(px + py * _pStrides.y + pz * _pStrides.z);
2359 _cPageIdx = static_cast<MLuint>((px >> _rShift.x) + (py >> _rShift.y) * _strides.y + (pz >> _rShift.z) * _strides.z);
2360}
2361
2362
2364template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setCursorPos4D(const ImageVector& p)
2365{
2366 _cPos.x = p.x;
2367 _cPos.y = p.y;
2368 _cPos.z = p.z;
2369 _cPos.c = p.c;
2370 _cIdx = static_cast<MLuint>(p.x + p.y * _pStrides.y + p.z * _pStrides.z + p.c * _pStrides.c);
2371 _cPageIdx = static_cast<MLuint>((p.x >> _rShift.x) + (p.y >> _rShift.y) * _strides.y +
2372 (p.z >> _rShift.z) * _strides.z + (p.c >> _rShift.c) * _strides.c);
2373}
2374
2376template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setCursorPos4DE(const ImageVector& pos)
2377{
2378 const MLint px = pos.x;
2379 const MLint py = pos.y;
2380 const MLint pz = pos.z;
2381 const MLint pc = pos.c;
2382 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z) || (pc < 0) ||
2383 (pc >= _ext.c))
2384 {
2385 throw(ML_OUT_OF_RANGE);
2386 }
2387 _cPos.x = px;
2388 _cPos.y = py;
2389 _cPos.z = pz;
2390 _cPos.c = pc;
2391 _cIdx = static_cast<MLuint>(px + py * _pStrides.y + pz * _pStrides.z + pc * _pStrides.c);
2392 _cPageIdx = static_cast<MLuint>((px >> _rShift.x) + (py >> _rShift.y) * _strides.y + (pz >> _rShift.z) * _strides.z +
2393 (pc >> _rShift.c) * _strides.c);
2394}
2395
2396
2398template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setCursorPos5D(const ImageVector& p)
2399{
2400 // Save cursor position.
2401 _cPos = p;
2402
2403 // Determine the index to the voxel within the page.
2404 _cIdx = static_cast<MLuint>(p.x + p.y * _pStrides.y + p.z * _pStrides.z + p.c * _pStrides.c + p.t * _pStrides.t);
2405
2406 // Determine index of the page under the cursor position.
2407 _cPageIdx =
2408 static_cast<MLuint>((p.x >> _rShift.x) + (p.y >> _rShift.y) * _strides.y + (p.z >> _rShift.z) * _strides.z +
2409 (p.c >> _rShift.c) * _strides.c + (p.t >> _rShift.t) * _strides.t);
2410}
2411
2413template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setCursorPos5DE(const ImageVector& pos)
2414{
2415 const MLint px = pos.x;
2416 const MLint py = pos.y;
2417 const MLint pz = pos.z;
2418 const MLint pc = pos.c;
2419 const MLint pt = pos.t;
2420 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z) || (pc < 0) ||
2421 (pc >= _ext.c) || (pt < 0) || (pt >= _ext.t))
2422 {
2423 throw(ML_OUT_OF_RANGE);
2424 }
2425
2426 // Save cursor position.
2427 _cPos = pos;
2428
2429 // Determine the index to the voxel within the page.
2430 _cIdx = static_cast<MLuint>(px + py * _pStrides.y + pz * _pStrides.z + pc * _pStrides.c + pt * _pStrides.t);
2431
2432 // Determine index of the page under the cursor position.
2433 _cPageIdx = static_cast<MLuint>((px >> _rShift.x) + (py >> _rShift.y) * _strides.y + (pz >> _rShift.z) * _strides.z +
2434 (pc >> _rShift.c) * _strides.c + (pt >> _rShift.t) * _strides.t);
2435}
2436
2437
2439template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setCursorPos6D(const ImageVector& p)
2440{
2441 // Save cursor position.
2442 _cPos = p;
2443
2444 // Determine the index to the voxel within the page.
2445 _cIdx = static_cast<MLuint>(p.x + p.y * _pStrides.y + p.z * _pStrides.z + p.c * _pStrides.c + p.t * _pStrides.t +
2446 p.u * _pStrides.u);
2447
2448 // Determine index of the page under the cursor position.
2449 _cPageIdx = static_cast<MLuint>((p.x >> _rShift.x) + (p.y >> _rShift.y) * _strides.y +
2450 (p.z >> _rShift.z) * _strides.z + (p.c >> _rShift.c) * _strides.c +
2451 (p.t >> _rShift.t) * _strides.t + (p.u >> _rShift.u) * _strides.u);
2452}
2453
2455template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_setCursorPos6DE(const ImageVector& pos)
2456{
2457 const MLint px = pos.x;
2458 const MLint py = pos.y;
2459 const MLint pz = pos.z;
2460 const MLint pc = pos.c;
2461 const MLint pt = pos.t;
2462 const MLint pu = pos.u;
2463 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z) || (pc < 0) ||
2464 (pc >= _ext.c) || (pt < 0) || (pt >= _ext.t) || (pu < 0) || (pu >= _ext.u))
2465 {
2466 throw(ML_OUT_OF_RANGE);
2467 }
2468
2469 // Save cursor position.
2470 _cPos = pos;
2471
2472 // Determine the index to the voxel within the page.
2473 _cIdx = static_cast<MLuint>(px + py * _pStrides.y + pz * _pStrides.z + pc * _pStrides.c + pt * _pStrides.t +
2474 pu * _pStrides.u);
2475
2476 // Determine index of the page under the cursor position.
2477 _cPageIdx = static_cast<MLuint>((px >> _rShift.x) + (py >> _rShift.y) * _strides.y + (pz >> _rShift.z) * _strides.z +
2478 (pc >> _rShift.c) * _strides.c + (pt >> _rShift.t) * _strides.t +
2479 (pu >> _rShift.u) * _strides.u);
2480}
2481
2482
2483//----------------------------------------------------------------------------------------------------------
2484// MoveCursorOffset
2485//----------------------------------------------------------------------------------------------------------
2486
2487
2489template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_moveCursorOffset1D(const ImageVector& off)
2490{
2491 _cPos.x += off.x;
2492 _cIdx = static_cast<MLuint>(_cPos.x);
2493 _cPageIdx = static_cast<MLuint>(_cPos.x >> _rShift.x);
2494}
2495
2497template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_moveCursorOffset1DE(const ImageVector& off)
2498{
2499 const MLint px = _cPos.x + off.x;
2500 if ((px < 0) || (px >= _ext.x)) {
2501 throw(ML_OUT_OF_RANGE);
2502 }
2503 _cPos.x = px;
2504 _cIdx = static_cast<MLuint>(px);
2505 _cPageIdx = static_cast<MLuint>(px >> _rShift.x);
2506}
2507
2508
2510template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_moveCursorOffset2D(const ImageVector& off)
2511{
2512 _cPos.x += off.x;
2513 _cPos.y += off.y;
2514 _cIdx = static_cast<MLuint>(_cPos.x + _cPos.y * _pStrides.y);
2515 _cPageIdx = static_cast<MLuint>((_cPos.x >> _rShift.x) + (_cPos.y >> _rShift.y) * _strides.y);
2516}
2517
2519template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_moveCursorOffset2DE(const ImageVector& off)
2520{
2521 const MLint px = _cPos.x + off.x;
2522 const MLint py = _cPos.y + off.y;
2523 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y)) {
2524 throw(ML_OUT_OF_RANGE);
2525 }
2526 _cPos.x = px;
2527 _cPos.y = py;
2528 _cIdx = static_cast<MLuint>(px + py * _pStrides.y);
2529 _cPageIdx = static_cast<MLuint>((px >> _rShift.x) + (py >> _rShift.y) * _strides.y);
2530}
2531
2532
2534template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_moveCursorOffset3D(const ImageVector& off)
2535{
2536 _cPos.x += off.x;
2537 _cPos.y += off.y;
2538 _cPos.z += off.z;
2539 _cIdx = static_cast<MLuint>(_cPos.x + _cPos.y * _pStrides.y + _cPos.z * _pStrides.z);
2540 _cPageIdx = static_cast<MLuint>((_cPos.x >> _rShift.x) + (_cPos.y >> _rShift.y) * _strides.y +
2541 (_cPos.z >> _rShift.z) * _strides.z);
2542}
2543
2545template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_moveCursorOffset3DE(const ImageVector& off)
2546{
2547 const MLint px = _cPos.x + off.x;
2548 const MLint py = _cPos.y + off.y;
2549 const MLint pz = _cPos.z + off.z;
2550 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z)) {
2551 throw(ML_OUT_OF_RANGE);
2552 }
2553 _cPos.x = px;
2554 _cPos.y = py;
2555 _cPos.z = pz;
2556 _cIdx = static_cast<MLuint>(px + py * _pStrides.y + pz * _pStrides.z);
2557 _cPageIdx = static_cast<MLuint>((px >> _rShift.x) + (py >> _rShift.y) * _strides.y + (pz >> _rShift.z) * _strides.z);
2558}
2559
2560
2562template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_moveCursorOffset4D(const ImageVector& off)
2563{
2564 _cPos.x += off.x;
2565 _cPos.y += off.y;
2566 _cPos.z += off.z;
2567 _cPos.c += off.c;
2568 _cIdx = static_cast<MLuint>(_cPos.x + _cPos.y * _pStrides.y + _cPos.z * _pStrides.z + _cPos.c * _pStrides.c);
2569 _cPageIdx = static_cast<MLuint>((_cPos.x >> _rShift.x) + (_cPos.y >> _rShift.y) * _strides.y +
2570 (_cPos.z >> _rShift.z) * _strides.z + (_cPos.c >> _rShift.c) * _strides.c);
2571}
2572
2574template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_moveCursorOffset4DE(const ImageVector& off)
2575{
2576 const MLint px = _cPos.x + off.x;
2577 const MLint py = _cPos.y + off.y;
2578 const MLint pz = _cPos.z + off.z;
2579 const MLint pc = _cPos.c + off.c;
2580 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z) || (pc < 0) ||
2581 (pc >= _ext.c))
2582 {
2583 throw(ML_OUT_OF_RANGE);
2584 }
2585 _cPos.x = px;
2586 _cPos.y = py;
2587 _cPos.z = pz;
2588 _cPos.c = pc;
2589 _cIdx = static_cast<MLuint>(px + py * _pStrides.y + pz * _pStrides.z + pc * _pStrides.c);
2590 _cPageIdx = static_cast<MLuint>((px >> _rShift.x) + (py >> _rShift.y) * _strides.y + (pz >> _rShift.z) * _strides.z +
2591 (pc >> _rShift.c) * _strides.c);
2592}
2593
2594
2596template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_moveCursorOffset5D(const ImageVector& off)
2597{
2598 // Calculate new cursor position.
2599 _cPos += off;
2600
2601 // Determine the index to the voxel within the page.
2602 _cIdx = static_cast<MLuint>(_cPos.x + _cPos.y * _pStrides.y + _cPos.z * _pStrides.z + _cPos.c * _pStrides.c +
2603 _cPos.t * _pStrides.t);
2604
2605 // Determine index of the page under the cursor position.
2606 _cPageIdx = static_cast<MLuint>((_cPos.x >> _rShift.x) + (_cPos.y >> _rShift.y) * _strides.y +
2607 (_cPos.z >> _rShift.z) * _strides.z + (_cPos.c >> _rShift.c) * _strides.c +
2608 (_cPos.t >> _rShift.t) * _strides.t);
2609}
2610
2612template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_moveCursorOffset5DE(const ImageVector& off)
2613{
2614 const MLint px = _cPos.x + off.x;
2615 const MLint py = _cPos.y + off.y;
2616 const MLint pz = _cPos.z + off.z;
2617 const MLint pc = _cPos.c + off.c;
2618 const MLint pt = _cPos.t + off.t;
2619 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z) || (pc < 0) ||
2620 (pc >= _ext.c) || (pt < 0) || (pt >= _ext.t))
2621 {
2622 throw(ML_OUT_OF_RANGE);
2623 }
2624
2625 // Save cursor position.
2626 _cPos.set(px, py, pz, pc, pt, 0);
2627
2628 // Determine the index to the voxel within the page.
2629 _cIdx = static_cast<MLuint>(px + py * _pStrides.y + pz * _pStrides.z + pc * _pStrides.c + pt * _pStrides.t);
2630
2631 // Determine index of the page under the cursor position.
2632 _cPageIdx = static_cast<MLuint>((px >> _rShift.x) + (py >> _rShift.y) * _strides.y + (pz >> _rShift.z) * _strides.z +
2633 (pc >> _rShift.c) * _strides.c + (pt >> _rShift.t) * _strides.t);
2634}
2635
2636
2638template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_moveCursorOffset6D(const ImageVector& off)
2639{
2640 // Save cursor position.
2641 _cPos += off;
2642
2643 // Determine the index to the voxel within the page.
2644 _cIdx = static_cast<MLuint>(_cPos.x + _cPos.y * _pStrides.y + _cPos.z * _pStrides.z + _cPos.c * _pStrides.c +
2645 _cPos.t * _pStrides.t + _cPos.u * _pStrides.u);
2646
2647 // Determine index of the page under the cursor position.
2648 _cPageIdx = static_cast<MLuint>((_cPos.x >> _rShift.x) + (_cPos.y >> _rShift.y) * _strides.y +
2649 (_cPos.z >> _rShift.z) * _strides.z + (_cPos.c >> _rShift.c) * _strides.c +
2650 (_cPos.t >> _rShift.t) * _strides.t + (_cPos.u >> _rShift.u) * _strides.u);
2651}
2652
2654template <typename DATATYPE> inline void TVirtualVolume<DATATYPE>::_moveCursorOffset6DE(const ImageVector& off)
2655{
2656 const MLint px = _cPos.x + off.x;
2657 const MLint py = _cPos.y + off.y;
2658 const MLint pz = _cPos.z + off.z;
2659 const MLint pc = _cPos.c + off.c;
2660 const MLint pt = _cPos.t + off.t;
2661 const MLint pu = _cPos.u + off.u;
2662 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z) || (pc < 0) ||
2663 (pc >= _ext.c) || (pt < 0) || (pt >= _ext.t) || (pu < 0) || (pu >= _ext.u))
2664 {
2665 throw(ML_OUT_OF_RANGE);
2666 }
2667
2668 // Save cursor position.
2669 _cPos.set(px, py, pz, pc, pt, pu);
2670
2671 // Determine the index to the voxel within the page.
2672 _cIdx = static_cast<MLuint>(px + py * _pStrides.y + pz * _pStrides.z + pc * _pStrides.c + pt * _pStrides.t +
2673 pu * _pStrides.u);
2674
2675 // Determine index of the page under the cursor position.
2676 _cPageIdx = static_cast<MLuint>((px >> _rShift.x) + (py >> _rShift.y) * _strides.y + (pz >> _rShift.z) * _strides.z +
2677 (pc >> _rShift.c) * _strides.c + (pt >> _rShift.t) * _strides.t +
2678 (pu >> _rShift.u) * _strides.u);
2679}
2680
2681
2682//----------------------------------------------------------------------------------------------------------
2683// IsMapped.
2684//----------------------------------------------------------------------------------------------------------
2685
2686
2688template <typename DATATYPE> inline bool TVirtualVolume<DATATYPE>::_isMapped1D(const ImageVector& pos) const
2689{
2690 const PageBuffer* const page = _pageArray + (pos.x >> _rShift.x);
2691 return page->_getPageFkt != VirtualVolume::_loadPageCB;
2692};
2693
2696template <typename DATATYPE> inline bool TVirtualVolume<DATATYPE>::_isMapped1DE(const ImageVector& pos) const
2697{
2698 const MLint px = pos.x;
2699 if ((px < 0) || (px >= _ext.x)) {
2700 throw(ML_OUT_OF_RANGE);
2701 }
2702 const PageBuffer* const page = _pageArray + (px >> _rShift.x);
2703 return page->_getPageFkt != VirtualVolume::_loadPageCB;
2704};
2705
2706
2708template <typename DATATYPE> inline bool TVirtualVolume<DATATYPE>::_isMapped2D(const ImageVector& pos) const
2709{
2710 const PageBuffer* const page = _pageArray + ((pos.x >> _rShift.x) + (pos.y >> _rShift.y) * _strides.y);
2711 return page->_getPageFkt != VirtualVolume::_loadPageCB;
2712};
2713
2716template <typename DATATYPE> inline bool TVirtualVolume<DATATYPE>::_isMapped2DE(const ImageVector& pos) const
2717{
2718 const MLint px = pos.x;
2719 const MLint py = pos.y;
2720 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y)) {
2721 throw(ML_OUT_OF_RANGE);
2722 }
2723 const PageBuffer* const page = _pageArray + ((px >> _rShift.x) + (py >> _rShift.y) * _strides.y);
2724 return page->_getPageFkt != VirtualVolume::_loadPageCB;
2725};
2726
2727
2729template <typename DATATYPE> inline bool TVirtualVolume<DATATYPE>::_isMapped3D(const ImageVector& pos) const
2730{
2731 const PageBuffer* const page =
2732 _pageArray + ((pos.x >> _rShift.x) + (pos.y >> _rShift.y) * _strides.y + (pos.z >> _rShift.z) * _strides.z);
2733 return page->_getPageFkt != VirtualVolume::_loadPageCB;
2734};
2735
2738template <typename DATATYPE> inline bool TVirtualVolume<DATATYPE>::_isMapped3DE(const ImageVector& pos) const
2739{
2740 const MLint px = pos.x;
2741 const MLint py = pos.y;
2742 const MLint pz = pos.z;
2743 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z)) {
2744 throw(ML_OUT_OF_RANGE);
2745 }
2746 const PageBuffer* const page =
2747 _pageArray + ((px >> _rShift.x) + (py >> _rShift.y) * _strides.y + (pz >> _rShift.z) * _strides.z);
2748 return page->_getPageFkt != VirtualVolume::_loadPageCB;
2749};
2750
2751
2753template <typename DATATYPE> inline bool TVirtualVolume<DATATYPE>::_isMapped4D(const ImageVector& pos) const
2754{
2755 const PageBuffer* const page = _pageArray + ((pos.x >> _rShift.x) + (pos.y >> _rShift.y) * _strides.y +
2756 (pos.z >> _rShift.z) * _strides.z + (pos.c >> _rShift.c) * _strides.c);
2757 return page->_getPageFkt != VirtualVolume::_loadPageCB;
2758};
2759
2762template <typename DATATYPE> inline bool TVirtualVolume<DATATYPE>::_isMapped4DE(const ImageVector& pos) const
2763{
2764 const MLint px = pos.x;
2765 const MLint py = pos.y;
2766 const MLint pz = pos.z;
2767 const MLint pc = pos.c;
2768 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z) || (pc < 0) ||
2769 (pc >= _ext.c))
2770 {
2771 throw(ML_OUT_OF_RANGE);
2772 }
2773 const PageBuffer* const page = _pageArray + ((px >> _rShift.x) + (py >> _rShift.y) * _strides.y +
2774 (pz >> _rShift.z) * _strides.z + (pc >> _rShift.c) * _strides.c);
2775 return page->_getPageFkt != VirtualVolume::_loadPageCB;
2776};
2777
2778
2780template <typename DATATYPE> inline bool TVirtualVolume<DATATYPE>::_isMapped5D(const ImageVector& pos) const
2781{
2782 const PageBuffer* const page =
2783 _pageArray + ((pos.x >> _rShift.x) + (pos.y >> _rShift.y) * _strides.y + (pos.z >> _rShift.z) * _strides.z +
2784 (pos.c >> _rShift.c) * _strides.c + (pos.t >> _rShift.t) * _strides.t);
2785 return page->_getPageFkt != VirtualVolume::_loadPageCB;
2786};
2787
2790template <typename DATATYPE> inline bool TVirtualVolume<DATATYPE>::_isMapped5DE(const ImageVector& pos) const
2791{
2792 const MLint px = pos.x;
2793 const MLint py = pos.y;
2794 const MLint pz = pos.z;
2795 const MLint pc = pos.c;
2796 const MLint pt = pos.t;
2797 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z) || (pc < 0) ||
2798 (pc >= _ext.c) || (pt < 0) || (pt >= _ext.t))
2799 {
2800 throw(ML_OUT_OF_RANGE);
2801 }
2802 const PageBuffer* const page =
2803 _pageArray + ((px >> _rShift.x) + (py >> _rShift.y) * _strides.y + (pz >> _rShift.z) * _strides.z +
2804 (pc >> _rShift.c) * _strides.c + (pt >> _rShift.t) * _strides.t);
2805 return page->_getPageFkt != VirtualVolume::_loadPageCB;
2806};
2807
2808
2810template <typename DATATYPE> inline bool TVirtualVolume<DATATYPE>::_isMapped6D(const ImageVector& pos) const
2811{
2812 const PageBuffer* const page = _pageArray + ((pos.x >> _rShift.x) + (pos.y >> _rShift.y) * _strides.y +
2813 (pos.z >> _rShift.z) * _strides.z + (pos.c >> _rShift.c) * _strides.c +
2814 (pos.t >> _rShift.t) * _strides.t + (pos.u >> _rShift.u) * _strides.u);
2815 return page->_getPageFkt != VirtualVolume::_loadPageCB;
2816};
2817
2820template <typename DATATYPE> inline bool TVirtualVolume<DATATYPE>::_isMapped6DE(const ImageVector& pos) const
2821{
2822 const MLint px = pos.x;
2823 const MLint py = pos.y;
2824 const MLint pz = pos.z;
2825 const MLint pc = pos.c;
2826 const MLint pt = pos.t;
2827 const MLint pu = pos.u;
2828 if ((px < 0) || (px >= _ext.x) || (py < 0) || (py >= _ext.y) || (pz < 0) || (pz >= _ext.z) || (pc < 0) ||
2829 (pc >= _ext.c) || (pt < 0) || (pt >= _ext.t) || (pu < 0) || (pu >= _ext.u))
2830 {
2831 throw(ML_OUT_OF_RANGE);
2832 }
2833 const PageBuffer* const page =
2834 _pageArray + ((px >> _rShift.x) + (py >> _rShift.y) * _strides.y + (pz >> _rShift.z) * _strides.z +
2835 (pc >> _rShift.c) * _strides.c + (pt >> _rShift.t) * _strides.t + (pu >> _rShift.u) * _strides.u);
2836 return page->_getPageFkt != VirtualVolume::_loadPageCB;
2837};
2838
2839
2841
2842#endif // __mlTVirtualVolume_H
Class to manage a binary image.
Definition mlBitImage.h:68
The class PagedImage, representing a fragmented image that manages properties and data of an image lo...
const SubImageBox & getBox() const
Returns the box describing the origin/extent of the subimage.
Definition mlSubImage.h:249
VectorType v1
Corner v1 of the subimage region (included in region).
static TSubImageBox< intT > intersect(const TSubImageBox< intT > &box1, const TSubImageBox< intT > &box2)
Returns the overlapping region of subimage regions box1 and box2.
VectorType v2
Corner v2 of the subimage region (also included in region!).
This template class manages/represents a rectangular 6D image region in memory that is organized line...
Definition mlTSubImage.h:99
const DATATYPE * getImagePointer(const ImageVector &position) const
Returns a pointer to voxel data of image voxel at 6D position position relative to the origin of the ...
The TVirtualVolume class implements random access to a paged input image or a pure virtual image with...
static void _moveFZCB(TVirtualVolume *obj)
static void _setVoxel4DCBE(TVirtualVolume *obj, const ImageVector &pos, DATATYPE voxVal)
static void setInt64ValueWrapped(void *vv, const ImageVector &pos, MLint64 v)
static void _moveBUCBE(TVirtualVolume *obj)
static MLdouble getDoubleCursorValueWrapped(void *vv)
static void _moveCursorOffset3DCB(TVirtualVolume *obj, const ImageVector &p)
static void _moveFYCBE(TVirtualVolume *obj)
static bool _isMapped5DCB(const TVirtualVolume *obj, const ImageVector &pos)
virtual ~TVirtualVolume()
Destructor.
static void _setVoxel6DCB(TVirtualVolume *obj, const ImageVector &pos, DATATYPE voxVal)
static bool _isMapped4DCBE(const TVirtualVolume *obj, const ImageVector &pos)
void setCursorPosition(const ImageVector &pos)
Set the cursor to a certain position.
static void _moveCursorOffset2DCBE(TVirtualVolume *obj, const ImageVector &p)
static MLint64 getInt64ValueWrapped(void *vv, const ImageVector &pos)
static void reverseMoveCursorUWrapped(void *vv)
static void _setCursorPos4DCB(TVirtualVolume *obj, const ImageVector &p)
static void setIntValueWrapped(void *vv, const ImageVector &pos, MLint v)
static void setDoubleValueWrapped(void *vv, const ImageVector &pos, MLdouble v)
static void _moveBXCB(TVirtualVolume *obj)
static void _setCursorPos3DCB(TVirtualVolume *obj, const ImageVector &p)
static void fillDoubleWrapped(void *vv, const ImageVector &v1, const ImageVector &v2, MLdouble v)
static void _setCursorPos6DCB(TVirtualVolume *obj, const ImageVector &p)
static MLdouble getDoubleValueWrapped(void *vv, const ImageVector &pos)
static void setDoubleCursorValueWrapped(void *vv, MLdouble v)
static void reverseMoveCursorCWrapped(void *vv)
static bool _isMapped2DCBE(const TVirtualVolume *obj, const ImageVector &pos)
static MLint64 getInt64CursorValueWrapped(void *vv)
static void setLDoubleCursorValueWrapped(void *vv, MLldouble v)
static void fillLDoubleWrapped(void *vv, const ImageVector &v1, const ImageVector &v2, MLldouble v)
static DATATYPE _getVoxel3DCBE(TVirtualVolume *obj, const ImageVector &pos)
static void _moveBTCB(TVirtualVolume *obj)
static void _setVoxel3DCBE(TVirtualVolume *obj, const ImageVector &pos, DATATYPE voxVal)
static bool _isMapped1DCB(const TVirtualVolume *obj, const ImageVector &pos)
DATATYPE ComponentType
A typedef to "export" the type of voxels components.
DATATYPE * getWrittenPageData(MLuint32 wp) const
Returns typed pointer to data of written page with page id wp.
static void reverseMoveCursorZWrapped(void *vv)
TVirtualVolume()
Hide the default constructor to avoid incorrect usage due to missing initializations.
static DATATYPE _getVoxel1DCBE(TVirtualVolume *obj, const ImageVector &pos)
static void setIntCursorValueWrapped(void *vv, MLint v)
static void setCursorPositionWrapped(void *vv, const ImageVector &pos)
static void _moveCursorOffset3DCBE(TVirtualVolume *obj, const ImageVector &p)
static MLint getIntCursorValueWrapped(void *vv)
static void _moveFTCB(TVirtualVolume *obj)
static void _setCursorPos5DCBE(TVirtualVolume *obj, const ImageVector &p)
static MLint getIntValueWrapped(void *vv, const ImageVector &pos)
Wrapper functions for non template application interfaces.
static const ImageVector & getCursorPositionWrapped(void *vv)
static void moveCursorByOffsetWrapped(void *vv, const ImageVector &off)
static void _moveCursorOffset1DCB(TVirtualVolume *obj, const ImageVector &p)
static DATATYPE _getVoxel4DCBE(TVirtualVolume *obj, const ImageVector &pos)
static void _moveFYCB(TVirtualVolume *obj)
static void moveCursorUWrapped(void *vv)
static void moveCursorYWrapped(void *vv)
static bool isMappedWrapped(void *vv, const ImageVector &pos)
static void moveCursorTWrapped(void *vv)
static bool _isMapped6DCB(const TVirtualVolume *obj, const ImageVector &pos)
static void _setVoxel5DCBE(TVirtualVolume *obj, const ImageVector &pos, DATATYPE voxVal)
static void _setCursorPos3DCBE(TVirtualVolume *obj, const ImageVector &p)
static void _setCursorPos2DCBE(TVirtualVolume *obj, const ImageVector &p)
static void _setVoxel6DCBE(TVirtualVolume *obj, const ImageVector &pos, DATATYPE voxVal)
static void _moveCursorOffset5DCBE(TVirtualVolume *obj, const ImageVector &p)
static void _moveBXCBE(TVirtualVolume *obj)
static void _moveBCCBE(TVirtualVolume *obj)
static void _moveFXCBE(TVirtualVolume *obj)
static void _moveFUCBE(TVirtualVolume *obj)
void copyMaskToSubImage(TSubImage< OUTDTYPE > &outSubImg, BitImage &maskBits, bool maskValue=true, bool writeBK=false, OUTDTYPE bkVal=ml_cast_from_scalar< OUTDTYPE >(0))
Takes overlapping region from *this, outSubImg and maskBits and copies all voxels from *this to outSu...
static DATATYPE _getVoxel4DCB(TVirtualVolume *obj, const ImageVector &pos)
VirtualVolume & getVirtualVolume()
Returns the pointer to the wrapped untyped virtual volume.
static bool _isMapped3DCBE(const TVirtualVolume *obj, const ImageVector &pos)
static void moveCursorXWrapped(void *vv)
static void _moveCursorOffset5DCB(TVirtualVolume *obj, const ImageVector &p)
TVirtualVolume(const ImageVector &ext, MLdouble fillVal=0, MLint maxNumKB=-1, bool areExceptionsOn=false)
Convenience constructor (3) creating an untyped virtual volume inside the typed one to avoid addition...
static bool _isMapped1DCBE(const TVirtualVolume *obj, const ImageVector &pos)
static void _setVoxel1DCBE(TVirtualVolume *obj, const ImageVector &pos, DATATYPE voxVal)
static void _moveBTCBE(TVirtualVolume *obj)
static bool _isMapped6DCBE(const TVirtualVolume *obj, const ImageVector &pos)
static void _setVoxel2DCB(TVirtualVolume *obj, const ImageVector &pos, DATATYPE voxVal)
static void reverseMoveCursorTWrapped(void *vv)
static bool _isMapped2DCB(const TVirtualVolume *obj, const ImageVector &pos)
static void resetCursorWrapped(void *vv)
static void _moveFZCBE(TVirtualVolume *obj)
DATATYPE getValue(const ImageVector &pos)
Get a voxel value from the virtual volume.
static void fillIntWrapped(void *vv, const ImageVector &v1, const ImageVector &v2, MLint v)
static void _setCursorPos6DCBE(TVirtualVolume *obj, const ImageVector &p)
static void _moveFCCB(TVirtualVolume *obj)
static void _setCursorPos2DCB(TVirtualVolume *obj, const ImageVector &p)
static void _setCursorPos1DCB(TVirtualVolume *obj, const ImageVector &p)
static void _setVoxel4DCB(TVirtualVolume *obj, const ImageVector &pos, DATATYPE voxVal)
static void moveCursorCWrapped(void *vv)
static bool _isMapped5DCBE(const TVirtualVolume *obj, const ImageVector &pos)
static DATATYPE _getVoxel1DCB(TVirtualVolume *obj, const ImageVector &pos)
static void _setCursorPos4DCBE(TVirtualVolume *obj, const ImageVector &p)
static void _moveBYCB(TVirtualVolume *obj)
static DATATYPE _getVoxel6DCBE(TVirtualVolume *obj, const ImageVector &pos)
static DATATYPE _getVoxel2DCB(TVirtualVolume *obj, const ImageVector &pos)
static bool moveCursorXWrapAroundWrapped(void *vv)
static void moveCursorZWrapped(void *vv)
static void setInt64CursorValueWrapped(void *vv, MLint64 v)
static void _moveBUCB(TVirtualVolume *obj)
static bool _isMapped4DCB(const TVirtualVolume *obj, const ImageVector &pos)
const ImageVector & getCursorPosition() const
Return the current cursor coordinates.
TVirtualVolume(PagedImage *image, MLint maxNumKB=-1, bool areExceptionsOn=false)
Convenience constructor (2) creating an untyped virtual volume inside the typed one to avoid addition...
static void _setCursorPos1DCBE(TVirtualVolume *obj, const ImageVector &p)
static DATATYPE _getVoxel2DCBE(TVirtualVolume *obj, const ImageVector &pos)
static DATATYPE _getVoxel5DCBE(TVirtualVolume *obj, const ImageVector &pos)
static void _moveFXCB(TVirtualVolume *obj)
static void _moveBZCBE(TVirtualVolume *obj)
TVirtualVolume(VirtualVolume &vVol)
Constructor 1.
static void fillInt64Wrapped(void *vv, const ImageVector &v1, const ImageVector &v2, MLint64 v)
static DATATYPE _getVoxel6DCB(TVirtualVolume *obj, const ImageVector &pos)
static void _moveCursorOffset1DCBE(TVirtualVolume *obj, const ImageVector &p)
static void _moveBCCB(TVirtualVolume *obj)
static void _setVoxel5DCB(TVirtualVolume *obj, const ImageVector &pos, DATATYPE voxVal)
static void _moveCursorOffset2DCB(TVirtualVolume *obj, const ImageVector &p)
static MLldouble getLDoubleValueWrapped(void *vv, const ImageVector &pos)
static void _moveCursorOffset6DCB(TVirtualVolume *obj, const ImageVector &p)
static void _moveFCCBE(TVirtualVolume *obj)
static void _moveFTCBE(TVirtualVolume *obj)
static void _moveBZCB(TVirtualVolume *obj)
static bool _isMapped3DCB(const TVirtualVolume *obj, const ImageVector &pos)
static void reverseMoveCursorXWrapped(void *vv)
TVirtualVolume & operator=(const TVirtualVolume &)
Hide the default assignment operator to avoid incorrect usage due to missing initializations.
void setValue(const ImageVector &pos, DATATYPE data)
Write a voxel into the virtual volume.
static void _moveCursorOffset6DCBE(TVirtualVolume *obj, const ImageVector &p)
static void _moveFUCB(TVirtualVolume *obj)
static void _moveCursorOffset4DCB(TVirtualVolume *obj, const ImageVector &p)
bool isMapped(const ImageVector &pos) const
Returns true if voxel is mapped into memory, otherwise it returns false.
static void _setVoxel1DCB(TVirtualVolume *obj, const ImageVector &pos, DATATYPE voxVal)
void moveCursorByOffset(const ImageVector &off)
Shift cursor to current position + offset.
static void _moveBYCBE(TVirtualVolume *obj)
void copyToSubImage(TSubImage< DATATYPE > &outSubImg)
Copy area from the virtual volume into the subimage given by outSubImg.
static DATATYPE _getVoxel3DCB(TVirtualVolume *obj, const ImageVector &pos)
static void reverseMoveCursorYWrapped(void *vv)
static void _moveCursorOffset4DCBE(TVirtualVolume *obj, const ImageVector &p)
static void _setVoxel3DCB(TVirtualVolume *obj, const ImageVector &pos, DATATYPE voxVal)
static void _setVoxel2DCBE(TVirtualVolume *obj, const ImageVector &pos, DATATYPE voxVal)
static MLldouble getLDoubleCursorValueWrapped(void *vv)
static DATATYPE _getVoxel5DCB(TVirtualVolume *obj, const ImageVector &pos)
static void _setCursorPos5DCB(TVirtualVolume *obj, const ImageVector &p)
static void setLDoubleValueWrapped(void *vv, const ImageVector &pos, MLldouble v)
This class manages a virtual volume organizing efficient voxel access to the output image of an input...
#define ML_BAD_DATA_TYPE
A wrong or unexpected data type has been passed to an algorithm, which often is a programming error.
Definition mlTypeDefs.h:838
#define ML_BAD_DIMENSION
The image or data structure has wrong extent or dimensions.
Definition mlTypeDefs.h:891
#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
#define ML_PRINT_FATAL_ERROR(FUNC_NAME, REASON, HANDLING)
Like ML_PRINT_FATAL_ERROR_DUMP(FUNC_NAME, REASON, HANDLING, RT_OBJ) without a runtime object to be du...
#define ML_PRINT_ERROR(FUNC_NAME, REASON, HANDLING)
Like ML_PRINT_ERROR_DUMP(FUNC_NAME, REASON, HANDLING, RT_OBJ) without a runtime object to be dumped.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#define _VV_MOVEBE_TEST(Q)
Macro to save cursor movement with exception handling if outside image.
MLDataType MLGetDataTypeFromPtr(const T *)
long double MLldouble
Definition mlTypeDefs.h:232
unsigned int MLuint32
Definition mlTypeDefs.h:185
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
double MLdouble
Definition mlTypeDefs.h:217
INT64 MLint64
Include 64-bit integer support for Windows or Unix.
Definition mlTypeDefs.h:411
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
PageBuffer is a helper structure to manage one page of input data of the VirtualVolume class and it a...
ReturnPageFunc _getPageFkt
Pointer to function to return the page managed by the PageBuffer.
bool _locked
If true this page contains written data and must not be removed.