MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlTSubImage.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_TSUB_IMAGE_H
14#define ML_TSUB_IMAGE_H
15
19
20// ML-includes
21#include "mlInitSystemML.h"
22#include "mlSubImage.h"
23#include "mlTypeTraits.h"
24
25#include "mlTemplateSupport.h"
26
27#ifdef _MSC_VER
28#pragma warning(push)
29// warning C4244: 'Argument': Konvertierung von 'typ1' in 'typ2', m�glicher Datenverlust
30#pragma warning(disable : 4244)
31#endif
32
34
35
37template <typename DATATYPE> class TSubImageCursor;
39template <typename DATATYPE> class ConstTSubImageCursor;
40
42#define _ML_TSUBIMG_SUBDOT6(pos, offset, stride) \
43 (((pos).x - (offset).x) * (stride).x + ((pos).y - (offset).y) * (stride).y + ((pos).z - (offset).z) * (stride).z + \
44 ((pos).c - (offset).c) * (stride).c + ((pos).t - (offset).t) * (stride).t + ((pos).u - (offset).u) * (stride).u)
45
47#define _ML_TSUBIMG_SUBDOT3(x, y, z, offset, stride) \
48 (((x) - (offset).x) * (stride).x + ((y) - (offset).y) * (stride).y + ((z) - (offset).z) * (stride).z)
49
51#define _ML_TSUBIMG_SUBDOT2(x, y, offset, stride) (((x) - (offset).x) * (stride).x + ((y) - (offset).y) * (stride).y)
52
53
54//-------------------------------------------------------------------------
97//-------------------------------------------------------------------------
98template <typename DATATYPE> class TSubImage : public SubImage
99{
100
101public:
104
109
110 //---------------------------------------------------------------------------
113 //---------------------------------------------------------------------------
125 TSubImage(const SubImageBox& box, MLDataType dataType, void* data)
126 : SubImage(box, dataType, data)
127 {
128 // Check whether template type and real data type match if there is valid data.
129 if (data && !TypeTraits<DATATYPE>::matches(dataType)) {
130 ML_PRINT_FATAL_ERROR("TSubImage::TSubImage()", ML_BAD_DATA_TYPE,
131 "Mismatch of data type between argument and template typename.");
132 }
133 }
134
141 {
142 // Set correct data type enum from template data type.
145 ML_PRINT_FATAL_ERROR("TSubImage::TSubImage()", ML_BAD_DATA_TYPE, "Data type has no registered TypeTraits.");
146 }
147 }
148
149
157 {
158 // Sets box the data is correlated with.
159 setBox(subImage.getBox());
160
161 // Sets correct data type enum.
162 setDataType(subImage.getDataType());
163
164 // Stores data pointer (but \e not the memory block handle).
165 setData(subImage.getData());
166
167 // Sets the source image extent.
168 setSourceImageExtent(subImage.getSourceImageExtent());
169
170 // Checks whether template type and real data type match if there is valid data.
171 // This check only works if TypeTraits has been specified for the argument type.
172 if (subImage.getData() && !TypeTraits<DATATYPE>::matches(subImage.getDataType())) {
173 ML_PRINT_FATAL_ERROR("TSubImage::TSubImage()", ML_BAD_DATA_TYPE,
174 "Mismatch of data type between argument and template typename.");
175 }
176 }
177
183
185 inline ~TSubImage() override = default;
186
190 {
191 SubImage::operator=(typedSubImage);
192 return *this;
193 }
195
196 //---------------------------------------------------------------------------
199 //---------------------------------------------------------------------------
200
202 inline const DATATYPE* getData() const
203 {
204 return static_cast<DATATYPE*>(_data);
205 }
207 {
208 return static_cast<DATATYPE*>(_data);
209 }
210
212
213 //---------------------------------------------------------------------------
216 //---------------------------------------------------------------------------
220 // 64-bit arithmetic is not needed here, because the pointer offset goes from the valid
221 // address space to another position inside the valid address space. We do not
222 // fall outside 32-bit ranges.
224 inline const DATATYPE* getSubImagePointer(const ImageVector& position) const
225 {
226 return static_cast<DATATYPE*>(_data) + ImageVector::dot(position, _stride);
227 }
228 inline DATATYPE* getSubImagePointer(const ImageVector& position)
229 {
230 return static_cast<DATATYPE*>(_data) + ImageVector::dot(position, _stride);
231 }
233
238 // 64-bit arithmetic is not needed here, because the pointer offset goes from the valid
239 // address space to another position inside the valid address space. We do not
240 // fall outside 32-bit ranges.
242 inline const DATATYPE* getSubImagePointer(MLint x, MLint y, MLint z) const
243 {
244 return static_cast<DATATYPE*>(_data) + (x * _stride.x + y * _stride.y + _stride.z * z);
245 }
247 {
248 return static_cast<DATATYPE*>(_data) + (x * _stride.x + y * _stride.y + _stride.z * z);
249 }
251
256 inline const DATATYPE* getImagePointer(const ImageVector& position) const
257 {
258 return static_cast<DATATYPE*>(_data) + _ML_TSUBIMG_SUBDOT6(position, _box.v1, _stride);
259 }
260 inline DATATYPE* getImagePointer(const ImageVector& position)
261 {
262 return static_cast<DATATYPE*>(_data) + _ML_TSUBIMG_SUBDOT6(position, _box.v1, _stride);
263 }
265
270 inline const DATATYPE* getImagePointer(MLint x, MLint y, MLint z) const
271 {
272 return static_cast<DATATYPE*>(_data) + _ML_TSUBIMG_SUBDOT3(x, y, z, _box.v1, _stride);
273 }
275 {
276 return static_cast<DATATYPE*>(_data) + _ML_TSUBIMG_SUBDOT3(x, y, z, _box.v1, _stride);
277 }
280
281
282 //-------------------------------------------------------------------------------------
285 //-------------------------------------------------------------------------------------
290 {
291 return getStride().getVectorPosition(pointer - static_cast<DATATYPE*>(_data));
292 }
293
299 inline void convertPointerToSubImagePosition(DATATYPE* pointer, MLint* x, MLint* y, MLint* z) const
300 {
301 const MLint offset = pointer - static_cast<DATATYPE*>(_data);
302 const ImageVector stride = getStride();
303 const ImageVector imgExt = getExtent();
304
305 if (x) {
306 ML_CHECK_THROW(stride.x);
308 *x = (offset / stride.x) % imgExt.x;
309 }
310
311 if (y) {
313 ML_CHECK_THROW(stride.y);
314 *y = (offset / stride.y) % imgExt.y;
315 }
316
317 if (z) {
319 ML_CHECK_THROW(stride.z);
320 *z = (offset / stride.z) % imgExt.z;
321 }
322 }
323
324
329 {
330 return convertPointerToSubImagePosition(pointer) + _box.v1;
331 }
332
333
339 inline void convertPointerToImagePosition(DATATYPE* pointer, MLint* x, MLint* y, MLint* z) const
340 {
341 convertPointerToSubImagePosition(pointer, x, y, z);
342 if (x) {
343 *x += _box.v1.x;
344 }
345 if (y) {
346 *y += _box.v1.y;
347 }
348 if (z) {
349 *z += _box.v1.z;
350 }
351 }
353
354
355 //---------------------------------------------------------------------------
358 //---------------------------------------------------------------------------
359
364 inline const DATATYPE& operator[](const ImageVector& position) const
365 {
366 return getImagePointer(position)[0];
367 }
368
373 inline DATATYPE& operator[](const ImageVector& position)
374 {
375 return getImagePointer(position)[0];
376 }
377
381 inline void setSubImageValue(const ImageVector& position, DATATYPE value)
382 {
383 static_cast<DATATYPE*>(_data)[ImageVector::dot(position, _stride)] = value;
384 }
385
389 inline DATATYPE getSubImageValue(const ImageVector& position) const
390 {
391 return static_cast<DATATYPE*>(_data)[ImageVector::dot(position, _stride)];
392 }
393
397 inline void setSubImageValue(MLint x, MLint y, DATATYPE value)
398 {
399 static_cast<DATATYPE*>(_data)[x * _stride.x + y * _stride.y] = value;
400 }
405 {
406 return static_cast<DATATYPE*>(_data)[x * _stride.x + y * _stride.y];
407 }
408
412 inline void setSubImageValue(MLint x, MLint y, MLint z, DATATYPE value)
413 {
414 static_cast<DATATYPE*>(_data)[x * _stride.x + y * _stride.y + _stride.z * z] = value;
415 }
420 {
421 return static_cast<DATATYPE*>(_data)[x * _stride.x + y * _stride.y + _stride.z * z];
422 }
423
427 inline void setImageValue(const ImageVector& position, DATATYPE value)
428 {
429 getImagePointer(position)[0] = value;
430 }
434 inline DATATYPE getImageValue(const ImageVector& position) const
435 {
436 return getImagePointer(position)[0];
437 }
438
442 inline void setImageValue(MLint x, MLint y, DATATYPE value)
443 {
444 static_cast<DATATYPE*>(_data)[_ML_TSUBIMG_SUBDOT2(x, y, _box.v1, _stride)] = value;
445 }
450 {
451 return static_cast<DATATYPE*>(_data)[_ML_TSUBIMG_SUBDOT2(x, y, _box.v1, _stride)];
452 }
453
457 inline void setImageValue(MLint x, MLint y, MLint z, DATATYPE value)
458 {
459 getImagePointer(x, y, z)[0] = value;
460 }
464 inline DATATYPE getImageValue(MLint x, MLint y, MLint z) const
465 {
466 return getImagePointer(x, y, z)[0];
467 }
468
470
471
472 //---------------------------------------------------------------------------
475 //---------------------------------------------------------------------------
487 {
488 // If passed box pointer is valid, then compute intersection with
489 // this subimage box, otherwise use non intersected subimage box of this.
490 const SubImageBox& thisBox = getBox();
491 const SubImageBox box = validBox ? SubImageBox::intersect(thisBox, *validBox) : thisBox;
492
493 // Return number of voxels in subimage. Return 0/0 if subimage is empty.
494 const MLint numVoxels = box.getNumVoxels();
495 if (numVoxels == 0) {
496 minValue = 0;
497 maxValue = 0;
498 return 0;
499 }
500
501 // Set min/max to first voxel value.
502 minValue = maxValue = getImageValue(box.v1);
503
504 // Simply scan all voxels. If box is subimage box, it is faster.
505 if (box == thisBox) {
506 // Not empty. Get pointer to voxel directly after last voxel.
507
508 ML_CHECK_THROW(_data);
509 const DATATYPE* dataEnd = static_cast<DATATYPE*>(_data) + numVoxels;
510
511 // Scan all voxels starting with the second one.
512 for (DATATYPE* i = static_cast<DATATYPE*>(_data) + 1; i < dataEnd; ++i) {
513 if (*i < minValue) {
514 minValue = *i;
515 }
516 if (*i > maxValue) {
517 maxValue = *i;
518 }
519 }
520 }
521 else {
522 // Loop over all rows of the valid subimage region.
523 ImageVector p;
524 for (MLint u = box.v1.u; u <= box.v2.u; ++u) {
525 for (MLint t = box.v1.t; t <= box.v2.t; ++t) {
526 for (MLint c = box.v1.c; c <= box.v2.c; ++c) {
527 for (MLint z = box.v1.z; z <= box.v2.z; ++z) {
528 for (MLint y = box.v1.y; y <= box.v2.y; ++y) {
529 // For inner loop, move pointer.
530 p.set(box.v1.x, y, z, c, t, u);
531 const DATATYPE* dPtr = getImagePointer(p);
532 const MLint pEnd = box.v2.x;
533 for (MLint x = box.v1.x; x <= pEnd; ++x, ++dPtr) {
534 if (*dPtr < minValue) {
535 minValue = *dPtr;
536 }
537 if (*dPtr > maxValue) {
538 maxValue = *dPtr;
539 }
540 }
541 }
542 }
543 }
544 }
545 }
546 }
547
548 // Return how many voxel have been scanned.
549 return numVoxels;
550 };
552
553 //---------------------------------------------------------------------------
556 //---------------------------------------------------------------------------
557
559#define _ML_CHECK_SUBIMAGE_DATA_POINTERS(FROM_PTR, TO_PTR) \
560 /* Check for valid data pointers to avoid memory access errors. */ \
561 { \
562 if (!FROM_PTR || !TO_PTR) { \
563 ML_PRINT_ERROR("TSubImage::copySubImageTyped( )", ML_BAD_POINTER_OR_0, \
564 "Valid data pointers in source and target subimage required for" \
565 "subimage copying, thus call is ignored."); \
566 return; \
567 } \
568 }
569
573 template <typename FROM_DATATYPE>
576 {
577 // Copy in local variables to reduce calculations in getBox().
578 const SubImageBox& box = getBox();
579 const SubImageBox& tBox = typedFromImage.getBox();
580
581 if (box.isEmpty() || tBox.isEmpty()) {
582 return;
583 }
584
585 // Calculate overlap of both subimages and copy only if overlap is not empty.
586 const SubImageBox intersection = SubImageBox::intersect(typedFromImage.getBox(), getBox());
587 if (!intersection.isEmpty()) {
588
589 // Check data pointers and print errors if necessary.
591
592 ImageVector p;
593 const FROM_DATATYPE* fromPt = nullptr;
594 DATATYPE* toPt = nullptr;
595
596 const ImageVector toExtent = getExtent();
597 const ImageVector toStrides =
599 const ImageVector offsetReordered(_box.v1.c, _box.v1.x, _box.v1.y, _box.v1.z, _box.v1.t, _box.v1.u);
600
601 const MLdouble scaleDbl = static_cast<MLdouble>(scaleShiftData.getScale());
602 const MLdouble shiftDbl = static_cast<MLdouble>(scaleShiftData.getShift());
603
604 // Check for identical scaling.
605 const bool identicalScaling = MLValuesAreEqual(scaleDbl, static_cast<MLdouble>(1), static_cast<MLdouble>(1)) &&
606 MLValuesAreEqual(shiftDbl, static_cast<MLdouble>(0), static_cast<MLdouble>(1));
607
608 // Traverse all voxels.
609 if (identicalScaling) {
610 for (p.u = intersection.v1.u; p.u <= intersection.v2.u; ++p.u) {
611 for (p.t = intersection.v1.t; p.t <= intersection.v2.t; ++p.t) {
612 for (p.c = intersection.v1.c; p.c <= intersection.v2.c; ++p.c) {
613 for (p.z = intersection.v1.z; p.z <= intersection.v2.z; ++p.z) {
614 for (p.y = intersection.v1.y; p.y <= intersection.v2.y; ++p.y) {
615
616 const ImageVector pos(intersection.v1.x, p.y, p.z, p.c, p.t, p.u);
617 const ImageVector posReordered(p.c, intersection.v1.x, p.y, p.z, p.t, p.u);
618 fromPt = typedFromImage.getImagePointer(pos);
620
621 for (p.x = intersection.v1.x; p.x <= intersection.v2.x; ++p.x, ++fromPt) {
622 *toPt = static_cast<DATATYPE>(*fromPt);
623 toPt += toStrides.y;
624 }
625 }
626 }
627 }
628 }
629 }
630 }
631 else {
632 for (p.u = intersection.v1.u; p.u <= intersection.v2.u; ++p.u) {
633 for (p.t = intersection.v1.t; p.t <= intersection.v2.t; ++p.t) {
634 for (p.c = intersection.v1.c; p.c <= intersection.v2.c; ++p.c) {
635 for (p.z = intersection.v1.z; p.z <= intersection.v2.z; ++p.z) {
636 for (p.y = intersection.v1.y; p.y <= intersection.v2.y; ++p.y) {
637
638 const ImageVector pos(intersection.v1.x, p.y, p.z, p.c, p.t, p.u);
639 const ImageVector posReordered(p.c, intersection.v1.x, p.y, p.z, p.t, p.u);
640 fromPt = typedFromImage.getImagePointer(pos);
642
643 for (p.x = intersection.v1.x; p.x <= intersection.v2.x; ++p.x, ++fromPt) {
644 *toPt = static_cast<DATATYPE>(static_cast<MLdouble>(*fromPt) * scaleDbl + shiftDbl);
645 toPt += toStrides.y;
646 }
647 }
648 }
649 }
650 }
651 }
652 }
653 } // if (!intersection.isEmpty())
654 }
655
667 //
668 // Note: The following function definition must be implemented in the class definition
669 // See BUG: LNK2001 on Member Function When Use Nested Class Template, Article ID: Q128789
670 template <typename FROM_DATATYPE>
672 {
673 // Any box empty? Then no copy is necessary.
674 if (getBox().isEmpty() || typedFromImg.getBox().isEmpty()) {
675 return;
676 }
677
678 if (scaleShiftData.getReorderMode() == ScaleShiftData::ReorderColorPlanesToInterleaved) {
679 copySubImageReorderColorPlanesToInterleaved(typedFromImg, scaleShiftData);
680 return;
681 }
682
683 // Get double and long double versions of scale and shift values.
684 const MLdouble scaleDbl = scaleShiftData.getScale();
685 const MLdouble shiftDbl = scaleShiftData.getShift();
686
687 // Check for identical scaling and use default copying then.
688 if (MLValuesAreEqual(scaleDbl, 1.0, 1.0) && MLValuesAreEqual(shiftDbl, 0.0, 1.0)) {
689 copySubImage(typedFromImg);
690 return;
691 }
692
693 // Get data type properties. If we calculate with normal datatypes then we calculate in double values;
694 // on long double built-in types we use long double, and if we use extended types we remain in extended types.
695 const MLint isDTScalarType = MLIsScalarTypePtr(static_cast<DATATYPE*>(nullptr));
696 const MLint isFDTScalarType = MLIsScalarTypePtr(static_cast<FROM_DATATYPE*>(nullptr));
697
698 if (getDataType() == typedFromImg.getDataType()) {
699 if (getBox() == typedFromImg.getBox()) {
700 // Images have same data type and same position/extent:
701 //-----------------------------------------------------
702 const FROM_DATATYPE* fromPt = typedFromImg.getData();
703 DATATYPE* toPt = getData();
704
705 // Check data pointers and print errors if necessary.
707
708 // Get number and the size in bytes of all voxels of this subimage.
709 const MLint size = getNumVoxels();
710 const MLint bytesize = size * MLSizeOf(getDataType());
711
712 // Copy the memory to the target buffer, it must fit since types are identical.
714
715 // When we work with extended types we must avoid to change to double during calculations since
716 // that causes information loss. In normal case we remain in double.
717 if (!isDTScalarType) {
718 // NOTE/TODO:
719 // Currently extended types must support adding and multiplying with doubles
720 // for this to work.
721 for (DATATYPE* toPtEnd = toPt + size; toPt < toPtEnd; ++toPt) {
722 *toPt = static_cast<DATATYPE>(static_cast<DATATYPE>(*toPt) * scaleDbl + shiftDbl);
723 }
724 }
725 else {
726 for (DATATYPE* toPtEnd = toPt + size; toPt < toPtEnd; ++toPt) {
727 *toPt = static_cast<DATATYPE>(static_cast<MLdouble>(*toPt) * scaleDbl + shiftDbl);
728 }
729 }
730 }
731 else {
732 // Images have same data type:
733 //----------------------------
734 // Calculate intersection of both subimages. Copy only if intersection is not empty.
735 const SubImageBox intersection = SubImageBox::intersect(typedFromImg.getBox(), getBox());
736 if (!intersection.isEmpty()) {
737
738 // Check data pointers and print errors if necessary.
740
741 ImageVector p;
742 const FROM_DATATYPE* fromPt = nullptr;
743 DATATYPE *toPt = nullptr, *toPt_ = nullptr, *toPtEnd = nullptr;
744 const ImageVector fromStr = typedFromImg.getStride();
745 const ImageVector toStr = getStride();
746 const MLint dist = intersection.v2.x - intersection.v1.x;
747 const MLint size_x = dist + 1;
748 const MLint bytesize_x = size_x * MLSizeOf(getDataType());
749
750 // Traverse all 6 dimensions.
751 for (p.u = intersection.v1.u; p.u <= intersection.v2.u; ++p.u) {
752 for (p.t = intersection.v1.t; p.t <= intersection.v2.t; ++p.t) {
753 for (p.c = intersection.v1.c; p.c <= intersection.v2.c; ++p.c) {
754 for (p.z = intersection.v1.z; p.z <= intersection.v2.z; ++p.z) {
755
756 // Get start position to each slice of data.
757 const ImageVector pos(intersection.v1.x, intersection.v1.y, p.z, p.c, p.t, p.u);
758 fromPt = typedFromImg.getImagePointer(pos);
759 toPt = getImagePointer(pos);
762
763 for (p.y = intersection.v1.y; p.y <= intersection.v2.y; ++p.y, fromPt += fromStr.y, toPt += toStr.y) {
764
765 // Copy buffer to target buffer. Below we work only on one buffer for rescaling.
767 toPt_ = toPt;
768
769 if (!isDTScalarType) {
770 // See description in upper case "if (getDataType()==typedFromImg.getDataType())".
771 for (toPtEnd = toPt_ + size_x; toPt_ < toPtEnd; ++toPt_) {
772 *toPt_ = static_cast<DATATYPE>(static_cast<DATATYPE>(*toPt_) * scaleDbl + shiftDbl);
773 }
774 }
775 else {
776 for (toPtEnd = toPt_ + size_x; toPt_ < toPtEnd; ++toPt_) {
777 *toPt_ = static_cast<DATATYPE>(static_cast<MLdouble>(*toPt_) * scaleDbl + shiftDbl);
778 }
779 }
780 }
781 }
782 }
783 }
784 }
785 } // if (!intersection.isEmpty())
786 } // else
787 } // if (getDataType()==typedFromImg.getDataType())
788
789 // Images have different data type:
790 //---------------------------------
791 else {
792 // Copy overlap of both subimages and copy only if it is not empty.
793 const SubImageBox intersection = SubImageBox::intersect(typedFromImg.getBox(), getBox());
794 if (!intersection.isEmpty()) {
795
796 // Check data pointers and print errors if necessary.
798
799 ImageVector p;
800 const FROM_DATATYPE* fromPt = nullptr;
801 DATATYPE* toPt = nullptr;
802
803 // Traverse all 6 dimensions.
804 for (p.u = intersection.v1.u; p.u <= intersection.v2.u; ++p.u) {
805 for (p.t = intersection.v1.t; p.t <= intersection.v2.t; ++p.t) {
806 for (p.c = intersection.v1.c; p.c <= intersection.v2.c; ++p.c) {
807 for (p.z = intersection.v1.z; p.z <= intersection.v2.z; ++p.z) {
808 for (p.y = intersection.v1.y; p.y <= intersection.v2.y; ++p.y) {
809
810 // Get start position to each slice of data.
811 const ImageVector pos(intersection.v1.x, p.y, p.z, p.c, p.t, p.u);
812 fromPt = typedFromImg.getImagePointer(pos);
813 toPt = getImagePointer(pos);
814 const MLint startX = intersection.v1.x;
815 const MLint endX = intersection.v2.x;
816
817 if (!isFDTScalarType) {
818 // When we work with extended types we must avoid to change to double during calculations since
819 // that causes information loss. In normal case we remain in double.
820 for (p.x = startX; p.x <= endX; ++p.x, ++fromPt, ++toPt) {
821 *toPt = static_cast<DATATYPE>(static_cast<FROM_DATATYPE>(*fromPt) * scaleDbl + shiftDbl);
822 }
823 }
824 else {
825 for (p.x = startX; p.x <= endX; ++p.x, ++fromPt, ++toPt) {
826 *toPt = static_cast<DATATYPE>(static_cast<MLdouble>(*fromPt) * scaleDbl + shiftDbl);
827 }
828 }
829 }
830 }
831 }
832 }
833 } // for (p.u)
834
835 } // if (!intersection.isEmpty())
836
837 } // else of if (getDataType()==typedFromImg.getDataType())
838 }
839
840
842
843
844 //-------------------------------------------------------------------------------------------
847 //-------------------------------------------------------------------------------------------
848
849 //---------------------------------------------------------------------------
851 //---------------------------------------------------------------------------
852 inline void fill(DATATYPE value)
853 {
854 ML_CHECK_THROW(_data);
855
856 const DATATYPE* dataEnd = static_cast<DATATYPE*>(_data) + getNumVoxels();
857
858 for (DATATYPE* i = static_cast<DATATYPE*>(_data); i < dataEnd; ++i) {
859 *i = value;
860 }
861 };
862
863
864 //-------------------------------------------------------------------------------------------
870 //-------------------------------------------------------------------------------------------
872 {
873 SubImage::fillBordersWithTypeData(box, reinterpret_cast<const MLTypeData*>(&fillValue));
874 }
875
876 //-------------------------------------------------------------------------------------------
879 //-------------------------------------------------------------------------------------------
881 {
882 fillBordersWithValue(getValidRegion(), value);
883 }
884
885 //-------------------------------------------------------------------------------------------
889 //-------------------------------------------------------------------------------------------
891 {
892 fillBordersWithBorderValues(getValidRegion());
893 }
894
896};
897
898//---------------------------------------------------------------------------
900//---------------------------------------------------------------------------
901template <typename DATATYPE> class TSubImageCursorBase
902{
903
904protected:
906 {
907 _data = const_cast<DATATYPE*>(subImage.getData());
908 _subImageOffset = subImage.getBox().v1;
909 _stride = subImage.getStride();
910 _cursor = _data;
911 }
912
913public:
914 //---------------------------------------------------------------------------
917 //---------------------------------------------------------------------------
920 inline void setSubImagePosition(const ImageVector& position)
921 {
922 _cursor = _data + ImageVector::dot(position, _stride);
923 }
927 {
928 _cursor = _data + _stride.x * x + _stride.y * y + _stride.z * z;
929 }
932 inline void setImagePosition(const ImageVector& position)
933 {
934 _cursor = _data + _ML_TSUBIMG_SUBDOT6(position, _subImageOffset, _stride);
935 }
938 inline void setImagePosition(MLint x, MLint y, MLint z)
939 {
940 _cursor = _data + +_ML_TSUBIMG_SUBDOT3(x, y, z, _subImageOffset, _stride);
941 }
943 inline void setPosition(const DATATYPE* pointer)
944 {
945 _cursor = const_cast<DATATYPE*>(pointer);
946 }
948 inline void moveByOffset(const ImageVector& offset)
949 {
950 _cursor += ImageVector::dot(offset, _stride);
951 }
953 inline void moveByOffset(MLint x, MLint y, MLint z)
954 {
955 _cursor += _stride.x * x + _stride.y * y + _stride.z * z;
956 }
958 inline void moveX()
959 {
960 _cursor += _stride.x;
961 }
963 inline void moveY()
964 {
965 _cursor += _stride.y;
966 }
968 inline void moveZ()
969 {
970 _cursor += _stride.z;
971 }
973 inline void moveC()
974 {
975 _cursor += _stride.c;
976 }
978 inline void moveT()
979 {
980 _cursor += _stride.t;
981 }
983 inline void moveU()
984 {
985 _cursor += _stride.u;
986 }
988 inline void reverseMoveX()
989 {
990 _cursor -= _stride.x;
991 }
993 inline void reverseMoveY()
994 {
995 _cursor -= _stride.y;
996 }
998 inline void reverseMoveZ()
999 {
1000 _cursor -= _stride.z;
1001 }
1003 inline void reverseMoveC()
1004 {
1005 _cursor -= _stride.c;
1006 }
1008 inline void reverseMoveT()
1009 {
1010 _cursor -= _stride.t;
1011 }
1013 inline void reverseMoveU()
1014 {
1015 _cursor -= _stride.u;
1016 }
1017
1019
1020 //---------------------------------------------------------------------------
1023 // Note: All these functions do not need explicit 64-bit arithmetic, as
1024 // pointer arithmetic always moves from valid address area to another
1025 // valid address area even on 32-bit systems, and calculations do not fall
1026 // outside valid ranges.
1027 //---------------------------------------------------------------------------
1029 inline DATATYPE getValue() const
1030 {
1031 return *(_cursor);
1032 }
1033
1035 inline DATATYPE getValueWithOffset(const ImageVector& offset) const
1036 {
1037 return *(_cursor + ImageVector::dot(offset, _stride));
1038 }
1039
1042 {
1043 return *(_cursor + _stride.x * dx + _stride.y * dy + _stride.z * dz);
1044 }
1045
1047
1048protected:
1057};
1058
1059//---------------------------------------------------------------------------
1062//---------------------------------------------------------------------------
1063template <typename DATATYPE> class ConstTSubImageCursor : public TSubImageCursorBase<DATATYPE>
1064{
1065
1067
1068public:
1072
1073 //---------------------------------------------------------------------------
1078 inline const DATATYPE* getPointer() const
1079 {
1080 return T::_cursor;
1081 }
1083 inline const DATATYPE* getPointerWithOffset(const ImageVector& offset) const
1084 {
1085 return T::_cursor + ImageVector::dot(offset, T::_stride);
1086 }
1089 {
1090 return (T::_cursor + T::_stride.x * dx + T::_stride.y * dy + T::_stride.z * dz);
1091 }
1093};
1094
1095//---------------------------------------------------------------------------
1098//---------------------------------------------------------------------------
1099template <typename DATATYPE> class TSubImageCursor : public TSubImageCursorBase<DATATYPE>
1100{
1101
1103
1104public:
1108
1109 //---------------------------------------------------------------------------
1114 inline DATATYPE* getPointer() const
1115 {
1116 return T::_cursor;
1117 }
1119 inline DATATYPE* getPointerWithOffset(const ImageVector& offset) const
1120 {
1121 return T::_cursor + ImageVector::dot(offset, T::_stride);
1122 }
1125 {
1126 return (T::_cursor + T::_stride.x * dx + T::_stride.y * dy + T::_stride.z * dz);
1127 }
1129
1130 //---------------------------------------------------------------------------
1133 // Note: All these functions do not need explicit 64-bit arithmetic, because
1134 // pointer arithmetic always moves from valid address area to another
1135 // valid address area even on 32-bit systems, and calculations do not fall
1136 // outside valid ranges.
1137 //---------------------------------------------------------------------------
1139 inline void setValue(DATATYPE value) const
1140 {
1141 *(T::_cursor) = value;
1142 }
1144 inline void setValueWithOffset(const ImageVector& offset, DATATYPE value) const
1145 {
1146 *(T::_cursor + ImageVector::dot(offset, T::_stride)) = value;
1147 }
1149 inline void setValueWithOffset(MLint dx, MLint dy, MLint dz, DATATYPE value) const
1150 {
1151 *(T::_cursor + T::_stride.x * dx + T::_stride.y * dy + T::_stride.z * dz) = value;
1152 }
1154};
1155
1156//-------------------------------------------------------------------------
1159//-------------------------------------------------------------------------
1160template <typename DATATYPE> class TSubImageWithCursor : public TSubImage<DATATYPE>
1161{
1162 typedef TSubImage<DATATYPE> T;
1163
1164public:
1167 : TSubImage<DATATYPE>()
1168 , _cursor(nullptr)
1169 {}
1175
1179 , _cursor(nullptr)
1180 {}
1181
1185 , _cursor(subImage._cursor)
1186 {}
1187
1191 {
1193 _cursor = tSubImg._cursor;
1194 return *this;
1195 }
1196
1197 //---------------------------------------------------------------------------
1200 //---------------------------------------------------------------------------
1203 inline void setCursorSubImagePosition(const ImageVector& position)
1204 {
1205 _cursor = static_cast<DATATYPE*>(T::_data) + ImageVector::dot(position, T::_stride);
1206 }
1210 {
1211 _cursor = static_cast<DATATYPE*>(T::_data) + T::_stride.x * x + T::_stride.y * y + T::_stride.z * z;
1212 }
1215 inline void setCursorImagePosition(const ImageVector& position)
1216 {
1217 _cursor = static_cast<DATATYPE*>(T::_data) + _ML_TSUBIMG_SUBDOT6(position, T::_box.v1, T::_stride);
1218 }
1222 {
1223 _cursor = static_cast<DATATYPE*>(T::_data) + _ML_TSUBIMG_SUBDOT3(x, y, z, T::_box.v1, T::_stride);
1224 }
1226 inline void setCursorPosition(const DATATYPE* pointer)
1227 {
1228 _cursor = const_cast<DATATYPE*>(pointer);
1229 }
1231 inline void moveCursorByOffset(const ImageVector& offset)
1232 {
1233 _cursor += ImageVector::dot(offset, T::_stride);
1234 }
1237 {
1238 _cursor += T::_stride.x * x + T::_stride.y * y + T::_stride.z * z;
1239 }
1241 inline void moveCursorX()
1242 {
1243 _cursor += T::_stride.x;
1244 }
1246 inline void moveCursorY()
1247 {
1248 _cursor += T::_stride.y;
1249 }
1251 inline void moveCursorZ()
1252 {
1253 _cursor += T::_stride.z;
1254 }
1256 inline void moveCursorC()
1257 {
1258 _cursor += T::_stride.c;
1259 }
1261 inline void moveCursorT()
1262 {
1263 _cursor += T::_stride.t;
1264 }
1266 inline void moveCursorU()
1267 {
1268 _cursor += T::_stride.u;
1269 }
1272 {
1273 _cursor -= T::_stride.x;
1274 }
1277 {
1278 _cursor -= T::_stride.y;
1279 }
1282 {
1283 _cursor -= T::_stride.z;
1284 }
1287 {
1288 _cursor -= T::_stride.c;
1289 }
1292 {
1293 _cursor -= T::_stride.t;
1294 }
1297 {
1298 _cursor -= T::_stride.u;
1299 }
1300
1302
1303 //---------------------------------------------------------------------------
1306 // Note: All these functions do not need explicit 64-bit arithmetic, because
1307 // pointer arithmetic always goes from valid address area to another
1308 // valid address area even on 32-bit systems, and calculations do not fall
1309 // outside valid ranges.
1310 //---------------------------------------------------------------------------
1313 {
1314 return *(_cursor);
1315 }
1318 {
1319 return *(_cursor + ImageVector::dot(offset, T::_stride));
1320 }
1323 {
1324 return *(_cursor + T::_stride.x * dx + T::_stride.y * dy + T::_stride.z * dz);
1325 }
1326
1328
1329 //---------------------------------------------------------------------------
1335 {
1336 return _cursor;
1337 }
1340 {
1341 return _cursor + ImageVector::dot(offset, T::_stride);
1342 }
1345 {
1346 return (_cursor + T::_stride.x * dx + T::_stride.y * dy + T::_stride.z * dz);
1347 }
1349
1350 //---------------------------------------------------------------------------
1353 // Note: All these functions do not need explicit 64-bit arithmetic, because
1354 // pointer arithmetic always goes from valid address area to another
1355 // valid address area even on 32-bit systems, and calculations do not fall
1356 // outside valid ranges.
1357 //---------------------------------------------------------------------------
1359 inline void setCursorValue(DATATYPE value)
1360 {
1361 *(_cursor) = value;
1362 }
1364 inline void setCursorValueWithOffset(const ImageVector& offset, DATATYPE value)
1365 {
1366 *(_cursor + ImageVector::dot(offset, T::_stride)) = value;
1367 }
1370 {
1371 *(_cursor + T::_stride.x * dx + T::_stride.y * dy + T::_stride.z * dz) = value;
1372 }
1373
1375
1376private:
1378 DATATYPE* _cursor;
1379};
1380
1381//---------------------------------------------------------------------------
1392//---------------------------------------------------------------------------
1394{
1395 // Check whether template type and real data type match if there is valid data.
1396 if (subImg.getData() && !TypeTraits<T>::matches(subImg.getDataType())) {
1397 ML_PRINT_FATAL_ERROR("tsubimage_cast", ML_BAD_DATA_TYPE,
1398 "Mismatch of data type between argument and template typename.");
1399 }
1400 return *(static_cast<TSubImage<T>*>(&subImg));
1401}
1402
1403template <typename T> const TSubImage<T>& tsubimage_cast(const SubImage& subImg)
1404{
1405 // Check whether template type and real data type match if there is valid data.
1406 if (subImg.getData() && !TypeTraits<T>::matches(subImg.getDataType())) {
1407 ML_PRINT_FATAL_ERROR("tsubimage_cast", ML_BAD_DATA_TYPE,
1408 "Mismatch of data type between argument and template typename.");
1409 }
1410 return *(static_cast<const TSubImage<T>*>(&subImg));
1411}
1412
1414{
1415 // Check whether template type and real data type match if there is valid data.
1416 if (subImg->getData() && !TypeTraits<T>::matches(subImg->getDataType())) {
1417 ML_PRINT_FATAL_ERROR("tsubimage_cast", ML_BAD_DATA_TYPE,
1418 "Mismatch of data type between argument and template typename.");
1419 }
1420 return static_cast<TSubImage<T>*>(subImg);
1421}
1422
1423template <typename T> const TSubImage<T>* tsubimage_cast(const SubImage* subImg)
1424{
1425 // Check whether template type and real data type match if there is valid data.
1426 if (subImg->getData() && !TypeTraits<T>::matches(subImg->getDataType())) {
1427 ML_PRINT_FATAL_ERROR("tsubimage_cast", ML_BAD_DATA_TYPE,
1428 "Mismatch of data type between argument and template typename.");
1429 }
1430 return static_cast<const TSubImage<T>*>(subImg);
1431}
1432
1434
1435
1437
1438namespace std
1439{
1440
1441 //---------------------------------------------------------------------------
1442 // Debug printing for TSubImage.
1443 //---------------------------------------------------------------------------
1444
1447 template <typename DATATYPE> inline ostream& operator<<(ostream& ostr, const ML_NAMESPACE::TSubImage<DATATYPE>& v)
1448 {
1449 // Get box of subimage and traverse all of its voxels.
1450 const ML_NAMESPACE::SubImageBox& box = v.getBox();
1451 ML_NAMESPACE::ImageVector p;
1452 for (p.u = box.v1.u; p.u <= box.v2.u; ++p.u) {
1453 for (p.t = box.v1.t; p.t <= box.v2.t; ++p.t) {
1454 for (p.c = box.v1.c; p.c <= box.v2.c; ++p.c) {
1455 for (p.z = box.v1.z; p.z <= box.v2.z; ++p.z) {
1456 for (p.y = box.v1.y; p.y <= box.v2.y; ++p.y) {
1457 // Print row of voxels after a single row start position.
1458 p.x = box.v1.x;
1459 ostr << p << ": ";
1460 for (; p.x <= box.v2.x; p.x++) {
1461 ostr << v.getImageValue(p) << " ";
1462 }
1463 ostr << std::endl;
1464 }
1465 }
1466 }
1467 }
1468 }
1469 return ostr;
1470 }
1471
1472} // namespace std
1473
1474#ifdef _MSC_VER
1475#pragma warning(pop)
1476#endif
1477
1478
1479#endif // of __mlTSubImage_H
@ T
Predeclaration for const cursor.
ConstTSubImageCursor(const TSubImage< DATATYPE > &subImage)
const DATATYPE * getPointerWithOffset(const ImageVector &offset) const
Returns the cursor position of the voxel computed from the current cursor shifted by offset.
const DATATYPE * getPointerWithOffset(MLint dx, MLint dy, MLint dz) const
Returns the cursor position of the voxel computed from the current cursor shifted by (dx,...
const DATATYPE * getPointer() const
This class manages/represents a rectangular 6D image region that is organized linearly in memory.
Definition mlSubImage.h:75
void set(const ComponentType v=0)
Sets all components to v or - if v is not specified - to 0.
VectorType v1
Corner v1 of the subimage region (included in region).
VectorType v2
Corner v2 of the subimage region (also included in region!).
intT getNumVoxels() const
Returns number of voxels in the subimage region, i.e., the product of all extents if this is not empt...
bool isEmpty() const
Returns true if subimage region is empty, i.e., if any of the components of v1 is greater than the co...
Base class for all TSubImage Cursors.
void reverseMoveC()
Moves the cursor backward in c direction.
void moveT()
Moves the cursor forward in t direction.
void reverseMoveX()
Moves the cursor backward in x direction.
void moveZ()
Moves the cursor forward in z direction.
void setPosition(const DATATYPE *pointer)
Sets the cursor to the given pointer where the pointer is the memory address of the voxel.
void reverseMoveY()
Moves the cursor backward in y direction.
DATATYPE getValue() const
Returns the voxel value at cursor position.
void reverseMoveT()
Moves the cursor backward in t direction.
ImageVector _stride
Stride for the subimage.
void moveU()
Moves the cursor forward in u direction.
void setSubImagePosition(MLint x, MLint y, MLint z)
Sets the cursor to the given 3D position (x, y, z) relative to the origin of the subimage region.
DATATYPE getValueWithOffset(MLint dx, MLint dy, MLint dz) const
Return the voxel value at (cursor position + (dx, dy, dz))
void moveX()
Moves the cursor forward in x direction.
DATATYPE getValueWithOffset(const ImageVector &offset) const
Returns the voxel value at (cursor position + offset).
ImageVector _subImageOffset
SubImage offset in original image.
DATATYPE * _data
SubImage data.
void reverseMoveZ()
Moves the cursor backward in z direction.
void setImagePosition(const ImageVector &position)
Sets the cursor to the given 6D position relative to the origin of the complete image region.
void moveByOffset(const ImageVector &offset)
Moves the cursor to cursor position + offset.
DATATYPE * _cursor
Cursor address for image data access.
void reverseMoveU()
Moves the cursor backward in u direction.
TSubImageCursorBase(const TSubImage< DATATYPE > &subImage)
void moveY()
Moves the cursor forward in y direction.
void setSubImagePosition(const ImageVector &position)
Sets the cursor to the given position relative to the origin of the subimage region.
void moveByOffset(MLint x, MLint y, MLint z)
Moves the cursor to cursor position + (x, y, z).
void setImagePosition(MLint x, MLint y, MLint z)
Sets the cursor to the given 3D position (x, y, z) relative to the origin of the complete image regio...
void moveC()
Moves the cursor forward in c direction.
Predeclaration for cursor.
DATATYPE * getPointerWithOffset(const ImageVector &offset) const
Returns the cursor position of the voxel computed from the current cursor shifted by offset.
DATATYPE * getPointer() const
void setValueWithOffset(MLint dx, MLint dy, MLint dz, DATATYPE value) const
Sets the voxel value at (cursor position + (dx, dy, dz)) to value.
TSubImageCursor(TSubImage< DATATYPE > &subImage)
void setValueWithOffset(const ImageVector &offset, DATATYPE value) const
Sets the voxel value at (cursor position + offset) to value.
void setValue(DATATYPE value) const
Sets the voxel value at the cursor position to value.
DATATYPE * getPointerWithOffset(MLint dx, MLint dy, MLint dz) const
Returns the cursor position of the voxel computed from the current cursor shifted by (dx,...
A class that offers a TSubImage with a TSubImageCursor.
void setCursorValue(DATATYPE value)
Sets the voxel value at the cursor position to value.
void reverseMoveCursorC()
Moves the cursor backward in c direction.
void moveCursorT()
Moves the cursor forward in t direction.
void moveCursorByOffset(const ImageVector &offset)
Moves the cursor to cursor position + offset.
void setCursorImagePosition(MLint x, MLint y, MLint z)
Sets the cursor to the given 3D position (x, y, z) relative to the origin of the complete image regio...
DATATYPE getCursorValue() const
Returns the voxel value at the cursor position.
void reverseMoveCursorU()
Moves the cursor backward in u direction.
void reverseMoveCursorY()
Moves the cursor backward in y direction.
DATATYPE getCursorValueWithOffset(MLint dx, MLint dy, MLint dz) const
Returns the voxel value at (cursor position + (dx, dy, dz))
void reverseMoveCursorX()
Moves the cursor backward in x direction.
void moveCursorByOffset(MLint x, MLint y, MLint z)
Moves the cursor to cursor position + (x, y, z).
TSubImageWithCursor(const TSubImage< DATATYPE > &subImage)
Constructor with TSubImage.
void moveCursorZ()
Moves the cursor forward in z direction.
void reverseMoveCursorZ()
Moves the cursor backward in z direction.
void moveCursorC()
Moves the cursor forward in c direction.
DATATYPE * getCursorPointerWithOffset(const ImageVector &offset) const
Returns the cursor pointer of the voxel computed from the current cursor shifted by offset.
void reverseMoveCursorT()
Moves the cursor backward in t direction.
void setCursorValueWithOffset(const ImageVector &offset, DATATYPE value)
Sets the voxel value at (cursor position + offset) to value.
void setCursorImagePosition(const ImageVector &position)
Sets the cursor to the given 6D position relative to the origin of the complete image region.
DATATYPE * getCursorPointerWithOffset(MLint dx, MLint dy, MLint dz) const
Returns the cursor pointer of the voxel computed from the current cursor shifted by (dx,...
void setCursorPosition(const DATATYPE *pointer)
Sets the cursor to the given pointer where pointer is the memory address of the voxel.
void moveCursorY()
Moves the cursor forward in y direction.
void moveCursorX()
Moves the cursor forward in x direction.
TSubImageWithCursor(const TSubImageWithCursor &subImage)
Constructor with TSubImageWithCursor.
TSubImageWithCursor(const SubImage &subImage)
Constructor with SubImage.
void moveCursorU()
Moves the cursor forward in u direction.
DATATYPE getCursorValueWithOffset(const ImageVector &offset) const
Returns the voxel value at (cursor position + offset)
void setCursorSubImagePosition(MLint x, MLint y, MLint z)
Sets the cursor to the given 3D position (x, y, z) relative to the origin of the subimage region.
void setCursorSubImagePosition(const ImageVector &position)
Sets the cursor to the given position relative to the origin of the subimage region.
DATATYPE * getCursorPointer() const
TSubImageWithCursor()
Default constructor.
TSubImageWithCursor & operator=(const TSubImageWithCursor< DATATYPE > &tSubImg)
Assignment operator to get an identical copy.
void setCursorValueWithOffset(MLint dx, MLint dy, MLint dz, DATATYPE value)
Sets voxel value at (cursor position + (dx, dy,dz)) to value.
This template class manages/represents a rectangular 6D image region in memory that is organized line...
Definition mlTSubImage.h:99
TSubImage(const SubImage &subImage)
Constructor to build a typed subimage from an untyped subImage.
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 ...
DATATYPE getSubImageValue(MLint x, MLint y, MLint z) const
Returns the voxel value at the given position (x, y, z) where the position is relative to the origin ...
void copySubImageTyped(const TSubImage< FROM_DATATYPE > &typedFromImg, const ScaleShiftData &scaleShiftData)
Copies image data from the subimage fromImg into the overlapping region of this subimage.
DATATYPE * getImagePointer(const ImageVector &position)
TSubImage(const TSubImage< DATATYPE > &typedSubImage)
Copy constructor to get an identical copy.
void copySubImageReorderColorPlanesToInterleaved(const TSubImage< FROM_DATATYPE > &typedFromImage, const ScaleShiftData &scaleShiftData)
Implements special case for void copySubImageTyped(const TSubImage<FROM_DATATYPE> &typedFromImg,...
void setSubImageValue(MLint x, MLint y, DATATYPE value)
Sets the voxel value at the given position(x, y) to the given value where the position is relative to...
DATATYPE getImageValue(MLint x, MLint y) const
Returns the 2D voxel value from the given position (x, y).
TSubImage(const SubImageBox &box, MLDataType dataType, void *data)
Constructor for an image region with location/extent box with data type dataType (must fit to DATATYP...
const DATATYPE * getSubImagePointer(MLint x, MLint y, MLint z) const
Returns a pointer to voxel data of image voxel at 3D position p=(x, y, z) relative to the origin of t...
void setImageValue(const ImageVector &position, DATATYPE value)
Sets the 6D voxel at the given position to the given value.
DATATYPE getSubImageValue(MLint x, MLint y) const
Returns the voxel value at position (x, y) where the position is relative to the origin of the subima...
ConstTSubImageCursor< DATATYPE > ConstCursor
A read-only cursor.
~TSubImage() override=default
Virtual destructor to suppress compiler warnings.
void fill(DATATYPE value)
Sets all voxel values in subimage to value.
ImageVector convertPointerToImagePosition(DATATYPE *pointer) const
Returns the 6D voxel coordinates corresponding to the memory address pointer.
DATATYPE & operator[](const ImageVector &position)
Reference access to voxel value at the given position.
DATATYPE getImageValue(MLint x, MLint y, MLint z) const
Returns the 3D voxel value from given position (x, y, z).
TSubImageCursor< DATATYPE > Cursor
A read/write cursor.
ImageVector convertPointerToSubImagePosition(DATATYPE *pointer) const
Returns the 6D voxel coordinates corresponding to the memory address pointer.
const DATATYPE * getSubImagePointer(const ImageVector &position) const
Returns a pointer to voxel data of image voxel at the 6D position relative to the origin of the subim...
TSubImage()
Default constructor to build a typed subimage (with an empty box) from scratch.
DATATYPE * getData()
DATATYPE getImageValue(const ImageVector &position) const
Returns the 6D voxel value from the given position.
const DATATYPE * getImagePointer(MLint x, MLint y, MLint z) const
Returns a pointer to voxel data of image voxel at 3D position p=(x, y, z) relative to the origin of t...
void fillInvalidRegionWithValue(DATATYPE value)
Fills the invalid region (everything outside of getValidRegion()) with the given value.
DATATYPE * getSubImagePointer(const ImageVector &position)
const DATATYPE & operator[](const ImageVector &position) const
Constant reference access to voxel value at the given position.
DATATYPE * getImagePointer(MLint x, MLint y, MLint z)
DATATYPE ComponentType
A typedef to 'export' the type of voxels components.
void setImageValue(MLint x, MLint y, MLint z, DATATYPE value)
Sets the 3D voxel at the given position (x, y, z) to the given value.
void fillBordersWithValue(const SubImageBox &box, DATATYPE fillValue)
Fills all regions with fillValue that are not covered by box.
DATATYPE getSubImageValue(const ImageVector &position) const
Returns voxel value at the given position where position is relative to the origin of the subimage re...
void setSubImageValue(const ImageVector &position, DATATYPE value)
Sets the voxel value at the given position to the given value where position is relative to the origi...
MLint calculateMinMax(DATATYPE &minValue, DATATYPE &maxValue, const SubImageBox *const validBox=nullptr) const
Scans subimage and determines the minimum and maximum values of the region that is part of subimage b...
void convertPointerToSubImagePosition(DATATYPE *pointer, MLint *x, MLint *y, MLint *z) const
Returns the 3D voxel coordinates corresponding to the memory address pointer.
TSubImage & operator=(const TSubImage< DATATYPE > &typedSubImage)
Assignment operator to get an identical copy.
void setImageValue(MLint x, MLint y, DATATYPE value)
Sets the 2D voxel at the given position (x, y) to the the given value.
const DATATYPE * getData() const
Returns the memory address of the image region. Overloads methods from SubImage.
void setSubImageValue(MLint x, MLint y, MLint z, DATATYPE value)
Sets the voxel value at the given position (x, y, z) to the given value where the position is relativ...
void convertPointerToImagePosition(DATATYPE *pointer, MLint *x, MLint *y, MLint *z) const
Returns the 3D voxel coordinates corresponding to the memory address pointer.
DATATYPE * getSubImagePointer(MLint x, MLint y, MLint z)
void fillInvalidRegionWithBorderValues()
Fills the invalid region (i.e., everything outside of getValidRegion() ) with the values on the borde...
TVector< TVectorBase > getStrides(const ComponentType offset=1) const
Interprets the vector as image extension and returns a stride vector.
TVector< TVectorBase > getVectorPosition(ComponentType offsetPos) const
Interprets the vector as a stride vector of an image and returns the offset position offsetPos from t...
MLEXPORT size_t MLSizeOf(MLDataType dataType)
Returns the size of the data type dataType in bytes.
#define ML_INVALID_DATA_TYPE
Defines an invalid MLDataType.
Definition mlTypeDefs.h:609
bool MLValuesAreEqual(MLint8 a, MLint8 b, MLint8)
Returns true if values are equal (numerically safely compared); otherwise, it returns false.
MLint32 MLDataType
MLDataType.
Definition mlTypeDefs.h:592
#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_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_CHECK_THROW(x)
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#define _ML_TSUBIMG_SUBDOT6(pos, offset, stride)
Private helper macro for calculation of memory offset, calculates (pos-offset) * stride.
Definition mlTSubImage.h:42
#define _ML_TSUBIMG_SUBDOT2(x, y, offset, stride)
Private helper macro for calculation of memory offset, calculates ((xy)-offset) * stride.
Definition mlTSubImage.h:51
#define _ML_TSUBIMG_SUBDOT3(x, y, z, offset, stride)
Private helper macro for calculation of memory offset, calculates ((xyz)-offset) * stride.
Definition mlTSubImage.h:47
#define _ML_CHECK_SUBIMAGE_DATA_POINTERS(FROM_PTR, TO_PTR)
Internal helper macro to check validity of data pointers of subimages.
MLint32 MLIsScalarTypePtr(const T *)
double MLdouble
Definition mlTypeDefs.h:217
unsigned char MLTypeData
This is the pointer type used to point to the data of MLType data instances.
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
TSubImage< T > & tsubimage_cast(SubImage &subImg)
STL namespace.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator '<<' for stream output of Field objects.
TypeTraits for scalar ML datatypes.