MeVisLab Toolbox Reference
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 
33 ML_START_NAMESPACE
34 
35 
36 
37 
39 template <typename DATATYPE> class TSubImageCursor;
41 template <typename DATATYPE> class ConstTSubImageCursor;
42 
44 #define _ML_TSUBIMG_SUBDOT6(pos, offset, stride) \
45  (((pos).x - (offset).x) * (stride).x + \
46  ((pos).y - (offset).y) * (stride).y + \
47  ((pos).z - (offset).z) * (stride).z + \
48  ((pos).c - (offset).c) * (stride).c + \
49  ((pos).t - (offset).t) * (stride).t + \
50  ((pos).u - (offset).u) * (stride).u)
51 
53 #define _ML_TSUBIMG_SUBDOT3(x, y, z, offset, stride) \
54  (((x) - (offset).x) * (stride).x + \
55  ((y) - (offset).y) * (stride).y + \
56  ((z) - (offset).z) * (stride).z)
57 
59 #define _ML_TSUBIMG_SUBDOT2(x, y, offset, stride) \
60  (((x) - (offset).x) * (stride).x + \
61  ((y) - (offset).y) * (stride).y)
62 
63 
64 //-------------------------------------------------------------------------
107 //-------------------------------------------------------------------------
108 template <typename DATATYPE>
109 class TSubImage : public SubImage
110 {
111 
112 public:
113 
115  typedef DATATYPE ComponentType;
116 
121 
122  //---------------------------------------------------------------------------
125  //---------------------------------------------------------------------------
137  TSubImage(const SubImageBox& box, MLDataType dataType, void* data):SubImage(box, dataType, data)
138  {
139  // Check whether template type and real data type match if there is valid data.
140  if (data && !TypeTraits<DATATYPE>::matches(dataType) )
141  {
142  ML_PRINT_FATAL_ERROR("TSubImage::TSubImage()", ML_BAD_DATA_TYPE,
143  "Mismatch of data type between argument and template typename.");
144  }
145  }
146 
153  {
154  // Set correct data type enum from template datatype.
155  setDataType(TypeTraits<DATATYPE>::dataType);
157  ML_PRINT_FATAL_ERROR("TSubImage::TSubImage()", ML_BAD_DATA_TYPE,
158  "Data type has no registered TypeTraits.");
159  }
160  }
161 
162 
169  TSubImage(const SubImage &subImage)
170  {
171  // Set box the data is correlated with.
172  setBox(subImage.getBox());
173 
174  // Set correct data type enum.
175  setDataType(subImage.getDataType());
176 
177  // Store data pointer (but NOT the memory block handle)
178  setData(subImage.getData());
179 
180  // Set the source image extent
181  setSourceImageExtent(subImage.getSourceImageExtent());
182 
183  // Check whether template type and real data type match if there is valid data.
184  // This check only works if TypeTraits has been specified for the argument type.
185  if (subImage.getData() && !TypeTraits<DATATYPE>::matches(subImage.getDataType()) )
186  {
187  ML_PRINT_FATAL_ERROR("TSubImage::TSubImage()", ML_BAD_DATA_TYPE,
188  "Mismatch of data type between argument and template typename.");
189  }
190  }
191 
194  inline TSubImage(const TSubImage<DATATYPE>& typedSubImage) :
195  SubImage (typedSubImage)
196  {
197  }
198 
200  inline ~TSubImage() override = default;
201 
204  inline TSubImage &operator=(const TSubImage<DATATYPE>& typedSubImage)
205  {
206  SubImage::operator=(typedSubImage);
207  return *this;
208  }
210 
211  //---------------------------------------------------------------------------
214  //---------------------------------------------------------------------------
215 
217  inline const DATATYPE* getData() const { return static_cast<DATATYPE*>(_data); }
218  inline DATATYPE* getData() { return static_cast<DATATYPE*>(_data); }
219 
221 
222  //---------------------------------------------------------------------------
225  //---------------------------------------------------------------------------
229  // 64 bit arithmetic is not needed here, because the pointer offset goes from the valid
230  // address space to another position inside the valid address space. We do not
231  // fall outside 32 bit ranges.
233  inline const DATATYPE* getSubImagePointer(const ImageVector& position) const { return static_cast<DATATYPE*>(_data) + ImageVector::dot(position,_stride); }
234  inline DATATYPE* getSubImagePointer(const ImageVector& position) { return static_cast<DATATYPE*>(_data) + ImageVector::dot(position,_stride); }
236 
241  // 64 bit arithmetic is not needed here, because the pointer offset goes from the valid
242  // address space to another position inside the valid address space. We do not
243  // fall outside 32 bit ranges.
245  inline const DATATYPE* getSubImagePointer(MLint x, MLint y, MLint z) const { return static_cast<DATATYPE*>(_data) + (x*_stride.x + y*_stride.y + _stride.z*z); }
246  inline DATATYPE* getSubImagePointer(MLint x, MLint y, MLint z) { return static_cast<DATATYPE*>(_data) + (x*_stride.x + y*_stride.y + _stride.z*z); }
248 
253  inline const DATATYPE* getImagePointer(const ImageVector& position) const { return static_cast<DATATYPE*>(_data) + _ML_TSUBIMG_SUBDOT6(position, _box.v1, _stride); }
254  inline DATATYPE* getImagePointer(const ImageVector& position) { return static_cast<DATATYPE*>(_data) + _ML_TSUBIMG_SUBDOT6(position, _box.v1, _stride); }
256 
261  inline const DATATYPE* getImagePointer(MLint x, MLint y, MLint z) const { return static_cast<DATATYPE*>(_data) + _ML_TSUBIMG_SUBDOT3(x,y,z, _box.v1, _stride); }
262  inline DATATYPE* getImagePointer(MLint x, MLint y, MLint z) { return static_cast<DATATYPE*>(_data) + _ML_TSUBIMG_SUBDOT3(x,y,z, _box.v1, _stride); }
265 
266 
267  //-------------------------------------------------------------------------------------
270  //-------------------------------------------------------------------------------------
274  inline ImageVector convertPointerToSubImagePosition(DATATYPE* pointer) const
275  { return getStride().getVectorPosition(pointer - static_cast<DATATYPE*>(_data)); }
276 
282  inline void convertPointerToSubImagePosition(DATATYPE* pointer, MLint* x, MLint* y, MLint* z) const
283  {
284  const MLint offset = pointer - static_cast<DATATYPE*>(_data);
285  const ImageVector stride=getStride();
286  const ImageVector imgExt=getImageExtent();
287 
288  if (x){
289  ML_CHECK_THROW(stride.x);
290  ML_CHECK_THROW(imgExt.x);
291  *x = (offset/stride.x) % imgExt.x;
292  }
293 
294  if (y){
295  ML_CHECK_THROW(imgExt.y);
296  ML_CHECK_THROW(stride.y);
297  *y = (offset/stride.y) % imgExt.y;
298  }
299 
300  if (z){
301  ML_CHECK_THROW(imgExt.z);
302  ML_CHECK_THROW(stride.z);
303  *z = (offset/stride.z) % imgExt.z;
304  }
305  }
306 
307 
311  inline ImageVector convertPointerToImagePosition(DATATYPE* pointer) const
312  { return convertPointerToSubImagePosition(pointer) + _box.v1; }
313 
314 
320  inline void convertPointerToImagePosition(DATATYPE* pointer, MLint* x, MLint* y, MLint* z) const
321  {
322  convertPointerToSubImagePosition(pointer, x, y, z);
323  if (x){ *x += _box.v1.x; }
324  if (y){ *y += _box.v1.y; }
325  if (z){ *z += _box.v1.z; }
326  }
328 
329 
330 
331  //---------------------------------------------------------------------------
334  //---------------------------------------------------------------------------
335 
340  inline const DATATYPE& operator[](const ImageVector& position) const { return getImagePointer(position)[0]; }
341 
346  inline DATATYPE& operator[](const ImageVector& position) { return getImagePointer(position)[0]; }
347 
351  inline void setSubImageValue(const ImageVector& position, DATATYPE value) { static_cast<DATATYPE*>(_data)[ ImageVector::dot(position,_stride) ]=value; }
352 
356  inline DATATYPE getSubImageValue(const ImageVector& position) const { return static_cast<DATATYPE*>(_data)[ ImageVector::dot(position,_stride) ]; }
357 
361  inline void setSubImageValue(MLint x, MLint y, DATATYPE value) { static_cast<DATATYPE*>(_data)[ x*_stride.x + y*_stride.y ]=value; }
365  inline DATATYPE getSubImageValue(MLint x, MLint y) const { return static_cast<DATATYPE*>(_data)[ x*_stride.x + y*_stride.y ]; }
366 
370  inline void setSubImageValue(MLint x, MLint y, MLint z, DATATYPE value){ static_cast<DATATYPE*>(_data)[ x*_stride.x + y*_stride.y+_stride.z*z ]=value; }
374  inline DATATYPE getSubImageValue(MLint x, MLint y, MLint z) const { return static_cast<DATATYPE*>(_data)[ x*_stride.x + y*_stride.y+_stride.z*z ]; }
375 
379  inline void setImageValue(const ImageVector& position, DATATYPE value) { getImagePointer(position)[0] = value; }
383  inline DATATYPE getImageValue(const ImageVector& position) const { return getImagePointer(position)[0]; }
384 
388  inline void setImageValue(MLint x, MLint y, DATATYPE value) { static_cast<DATATYPE*>(_data)[_ML_TSUBIMG_SUBDOT2(x,y,_box.v1, _stride)]=value; }
392  inline DATATYPE getImageValue(MLint x, MLint y) const { return static_cast<DATATYPE*>(_data)[_ML_TSUBIMG_SUBDOT2(x,y,_box.v1, _stride)]; }
393 
397  inline void setImageValue(MLint x, MLint y, MLint z, DATATYPE value){ getImagePointer(x,y,z)[0] = value; }
401  inline DATATYPE getImageValue(MLint x, MLint y, MLint z) const { return getImagePointer(x,y,z)[0]; }
402 
404 
405 
406  //---------------------------------------------------------------------------
409  //---------------------------------------------------------------------------
420  MLint calculateMinMax(DATATYPE& minValue, DATATYPE& maxValue, const SubImageBox * const validBox=nullptr) const
421  {
422  // If passed box pointer is valid then compute intersection with
423  // this subimage box, otherwise use non intersected subimage box of this.
424  const SubImageBox& thisBox = getBox();
425  const SubImageBox box = validBox ? SubImageBox::intersect(thisBox, *validBox) : thisBox;
426 
427  // Get number of voxels in subimage. Return 0/0 if subimage is empty.
428  const MLint numVoxels = box.getNumVoxels();
429  if (numVoxels==0){ minValue=0; maxValue=0; return 0; }
430 
431  // Set min/max to first voxel value.
432  minValue = maxValue = getImageValue(box.v1);
433 
434  // Simply scan all voxels if box is subimage box, it is faster.
435  if (box == thisBox){
436  // Not empty. Get pointer to voxel directly after last voxel.
437 
438  ML_CHECK_THROW(_data);
439  const DATATYPE* dataEnd = static_cast<DATATYPE*>(_data) + numVoxels;
440 
441  // Scan all voxels starting with the second one.
442  for (DATATYPE* i=static_cast<DATATYPE*>(_data)+1; i<dataEnd; ++i)
443  {
444  if (*i < minValue){ minValue = *i; }
445  if (*i > maxValue){ maxValue = *i; }
446  }
447  }
448  else{
449  // Loop over all rows of the valid subimage region.
450  ImageVector p;
451  for (MLint u=box.v1.u; u <= box.v2.u; ++u){
452  for (MLint t=box.v1.t; t <= box.v2.t; ++t){
453  for (MLint c=box.v1.c; c <= box.v2.c; ++c){
454  for (MLint z=box.v1.z; z <= box.v2.z; ++z){
455  for (MLint y=box.v1.y; y <= box.v2.y; ++y){
456  // For inner loop move pointer.
457  p.set(box.v1.x, y, z, c, t, u);
458  const DATATYPE *dPtr = getImagePointer(p);
459  const MLint pEnd = box.v2.x;
460  for (MLint x=box.v1.x; x <= pEnd; ++x, ++dPtr){
461  if (*dPtr < minValue){ minValue = *dPtr; }
462  if (*dPtr > maxValue){ maxValue = *dPtr; }
463  }
464  }
465  }
466  }
467  }
468  }
469  }
470 
471  // Return how many voxel have been scanned.
472  return numVoxels;
473  };
475 
476  //---------------------------------------------------------------------------
479  //---------------------------------------------------------------------------
480 
482 #define _ML_CHECK_SUBIMAGE_DATA_POINTERS(FROM_PTR, TO_PTR) \
483  /* Check for valid data pointers to avoid memory access errors. */ \
484  { \
485  if (!FROM_PTR || !TO_PTR){ \
486  ML_PRINT_ERROR("TSubImage::copySubImageTyped( )", \
487  ML_BAD_POINTER_OR_0, \
488  "Valid data pointers in source and target subimage required for" \
489  "subimage copying, thus call is ignored."); \
490  return; \
491  } \
492  }
493 
497  template <typename FROM_DATATYPE>
499  {
500  // Copy in local variables to reduce calculations in getBox().
501  const SubImageBox& box =getBox();
502  const SubImageBox& tBox=typedFromImage.getBox();
503 
504  if (box.isEmpty() || tBox.isEmpty()){ return; }
505 
506  // Calculate overlap of both subimages and copy only if overlap is not empty.
507  const SubImageBox intersection = SubImageBox::intersect(typedFromImage.getBox(),getBox());
508  if (!intersection.isEmpty()){
509 
510  // Check data pointers and print errors if necessary.
511  _ML_CHECK_SUBIMAGE_DATA_POINTERS(typedFromImage.getData(), getData());
512 
513  ImageVector p;
514  const FROM_DATATYPE* fromPt = nullptr;
515  DATATYPE* toPt = nullptr;
516 
517  const ImageVector toExtent = getExtent();
518  const ImageVector toStrides = ImageVector(toExtent.c, toExtent.x, toExtent.y, toExtent.z, toExtent.t, toExtent.u).getStrides();
519  const ImageVector offsetReordered(_box.v1.c, _box.v1.x, _box.v1.y, _box.v1.z, _box.v1.t, _box.v1.u);
520 
521  const MLdouble scaleDbl = static_cast<MLdouble>(scaleShiftData.getScale());
522  const MLdouble shiftDbl = static_cast<MLdouble>(scaleShiftData.getShift());
523 
524  // Check for identical scaling.
525  const bool identicalScaling = MLValuesAreEqual(scaleDbl, static_cast<MLdouble>(1), static_cast<MLdouble>(1)) &&
526  MLValuesAreEqual(shiftDbl, static_cast<MLdouble>(0), static_cast<MLdouble>(1));
527 
528  // Traverse all voxels.
529  if (identicalScaling) {
530  for (p.u=intersection.v1.u; p.u<=intersection.v2.u; ++p.u) {
531  for (p.t=intersection.v1.t; p.t<=intersection.v2.t; ++p.t) {
532  for (p.c=intersection.v1.c; p.c<=intersection.v2.c; ++p.c) {
533  for (p.z=intersection.v1.z; p.z<=intersection.v2.z; ++p.z) {
534  for (p.y=intersection.v1.y; p.y<=intersection.v2.y; ++p.y) {
535 
536  const ImageVector pos(intersection.v1.x,p.y,p.z,p.c,p.t,p.u);
537  const ImageVector posReordered(p.c, intersection.v1.x,p.y,p.z,p.t,p.u);
538  fromPt= typedFromImage.getImagePointer(pos);
539  toPt = static_cast<DATATYPE*>(_data) + _ML_TSUBIMG_SUBDOT6(posReordered, offsetReordered, toStrides);
540 
541  for (p.x = intersection.v1.x; p.x <= intersection.v2.x; ++p.x, ++fromPt) {
542  *toPt = static_cast<DATATYPE>(*fromPt);
543  toPt += toStrides.y;
544  }
545  }
546  }
547  }
548  }
549  }
550  } else {
551  for (p.u=intersection.v1.u; p.u<=intersection.v2.u; ++p.u) {
552  for (p.t=intersection.v1.t; p.t<=intersection.v2.t; ++p.t) {
553  for (p.c=intersection.v1.c; p.c<=intersection.v2.c; ++p.c) {
554  for (p.z=intersection.v1.z; p.z<=intersection.v2.z; ++p.z) {
555  for (p.y=intersection.v1.y; p.y<=intersection.v2.y; ++p.y) {
556 
557  const ImageVector pos(intersection.v1.x,p.y,p.z,p.c,p.t,p.u);
558  const ImageVector posReordered(p.c, intersection.v1.x,p.y,p.z,p.t,p.u);
559  fromPt= typedFromImage.getImagePointer(pos);
560  toPt = static_cast<DATATYPE*>(_data) + _ML_TSUBIMG_SUBDOT6(posReordered, offsetReordered, toStrides);
561 
562  for (p.x = intersection.v1.x; p.x <= intersection.v2.x; ++p.x, ++fromPt) {
563  *toPt = static_cast<DATATYPE>(static_cast<MLdouble>(*fromPt)*scaleDbl + shiftDbl);
564  toPt += toStrides.y;
565  }
566  }
567  }
568  }
569  }
570  }
571  }
572  } // if (!intersection.isEmpty())
573  }
574 
587  //
588  //Note: The following function definition must be implemented in the class definition
589  // See BUG: LNK2001 on Member Function When Use Nested Class Template, Article ID: Q128789
590  template <typename FROM_DATATYPE>
591  void copySubImageTyped(const TSubImage<FROM_DATATYPE> &typedFromImg, const ScaleShiftData& scaleShiftData)
592  {
593  // Any box empty? Then no copy is necessary.
594  if (getBox().isEmpty() || typedFromImg.getBox().isEmpty()){
595  return;
596  }
597 
598  if (scaleShiftData.getReorderMode() == ScaleShiftData::ReorderColorPlanesToInterleaved) {
599  copySubImageReorderColorPlanesToInterleaved(typedFromImg, scaleShiftData);
600  return;
601  }
602 
603  // Get double and long double versions of scale and shift values.
604  const MLdouble scaleDbl = scaleShiftData.getScale();
605  const MLdouble shiftDbl = scaleShiftData.getShift();
606 
607  // Check for identical scaling and use default copying then.
608  if (MLValuesAreEqual(scaleDbl, 1.0, 1.0) && MLValuesAreEqual(shiftDbl, 0.0, 1.0)){
609  copySubImage(typedFromImg);
610  return;
611  }
612 
613  // Get data type properties. If we calculate with normal data types then we calculate in double values;
614  // on long double built-in types we use long double, and if we use extended types we remain in extended types.
615  const MLint isDTScalarType = MLIsScalarTypePtr(static_cast<DATATYPE*>(nullptr));
616  const MLint isFDTScalarType = MLIsScalarTypePtr(static_cast<FROM_DATATYPE*>(nullptr));
617 
618  if (getDataType()==typedFromImg.getDataType()){
619  if (getBox()==typedFromImg.getBox()){
620  // Images have same data type and same position/extent:
621  //-----------------------------------------------------
622  const FROM_DATATYPE *fromPt = typedFromImg.getData();
623  DATATYPE *toPt = getData();
624 
625  // Check data pointers and print errors if necessary.
626  _ML_CHECK_SUBIMAGE_DATA_POINTERS(fromPt, toPt);
627 
628  // Get number and the size in bytes of all voxels of this subimage.
629  const MLint size = getNumVoxels();
630  const MLint bytesize = size * MLSizeOf(getDataType());
631 
632  // Copy the memory to the target buffer, it must fit since types are identical.
633  memcpy( toPt, fromPt, bytesize );
634 
635  // When we work with extended types we must avoid to change to double during calculations since
636  // that causes information loss. In normal case we remain in double.
637  if (!isDTScalarType){
638  // NOTE/TODO:
639  // Currently extended types must support adding and multiplying with doubles
640  // for this to work.
641  for (DATATYPE* toPtEnd=toPt+size; toPt<toPtEnd; ++toPt){
642  *toPt=static_cast<DATATYPE>(static_cast<DATATYPE>(*toPt)*scaleDbl + shiftDbl);
643  }
644  }
645  else{
646  for (DATATYPE* toPtEnd=toPt+size; toPt<toPtEnd; ++toPt){
647  *toPt=static_cast<DATATYPE>( static_cast<MLdouble>(*toPt)*scaleDbl + shiftDbl);
648  }
649  }
650  }
651  else{
652  // Images have same data type:
653  //----------------------------
654  // Calculate intersection of both subimages. Copy only if intersection is not empty.
655  const SubImageBox intersection = SubImageBox::intersect(typedFromImg.getBox(),getBox());
656  if (!intersection.isEmpty()){
657 
658  // Check data pointers and print errors if necessary.
659  _ML_CHECK_SUBIMAGE_DATA_POINTERS(typedFromImg.getData(), getData());
660 
661  ImageVector p;
662  const FROM_DATATYPE *fromPt = nullptr;
663  DATATYPE *toPt = nullptr,
664  *toPt_ = nullptr,
665  *toPtEnd = nullptr;
666  const ImageVector fromStr = typedFromImg.getStride();
667  const ImageVector toStr = getStride();
668  const MLint dist = intersection.v2.x - intersection.v1.x;
669  const MLint size_x = dist+1;
670  const MLint bytesize_x = size_x * MLSizeOf(getDataType());
671 
672  // Traverse all 6 dimensions.
673  for (p.u=intersection.v1.u; p.u<=intersection.v2.u; ++p.u){
674  for (p.t=intersection.v1.t; p.t<=intersection.v2.t; ++p.t){
675  for (p.c=intersection.v1.c; p.c<=intersection.v2.c; ++p.c){
676  for (p.z=intersection.v1.z; p.z<=intersection.v2.z; ++p.z){
677 
678  // Get start position to each slice of data.
679  const ImageVector pos(intersection.v1.x, intersection.v1.y, p.z, p.c, p.t, p.u);
680  fromPt = typedFromImg.getImagePointer(pos);
681  toPt = getImagePointer(pos);
682  ML_CHECK_THROW(fromPt);
683  ML_CHECK_THROW(toPt);
684 
685  for (p.y=intersection.v1.y; p.y<=intersection.v2.y; ++p.y,fromPt+=fromStr.y,toPt+=toStr.y){
686 
687  // Copy buffer to target buffer. Below we work only on one buffer for rescaling.
688  memcpy(toPt, fromPt, bytesize_x);
689  toPt_ = toPt;
690 
691  if (!isDTScalarType){
692  // See description in upper case "if (getDataType()==typedFromImg.getDataType())".
693  for (toPtEnd = toPt_+size_x;
694  toPt_<toPtEnd;
695  ++toPt_){
696  *toPt_=static_cast<DATATYPE>(static_cast<DATATYPE>(*toPt_)*scaleDbl + shiftDbl);
697  }
698  }
699  else{
700  for (toPtEnd = toPt_+size_x;
701  toPt_<toPtEnd;
702  ++toPt_){
703  *toPt_=static_cast<DATATYPE>(static_cast<MLdouble>(*toPt_)*scaleDbl + shiftDbl);
704  }
705  }
706  }
707  }
708  }
709  }
710  }
711  } // if (!intersection.isEmpty())
712  } // else
713  } // if (getDataType()==typedFromImg.getDataType())
714 
715  // Images have different data type:
716  //---------------------------------
717  else{
718  // Copy overlap of both subimages and copy only if it is not empty.
719  const SubImageBox intersection = SubImageBox::intersect(typedFromImg.getBox(),getBox());
720  if (!intersection.isEmpty()){
721 
722  // Check data pointers and print errors if necessary.
723  _ML_CHECK_SUBIMAGE_DATA_POINTERS(typedFromImg.getData(), getData());
724 
725  ImageVector p;
726  const FROM_DATATYPE *fromPt = nullptr;
727  DATATYPE *toPt = nullptr;
728 
729  // Traverse all 6 dimensions.
730  for (p.u=intersection.v1.u; p.u<=intersection.v2.u; ++p.u){
731  for (p.t=intersection.v1.t; p.t<=intersection.v2.t; ++p.t){
732  for (p.c=intersection.v1.c; p.c<=intersection.v2.c; ++p.c){
733  for (p.z=intersection.v1.z; p.z<=intersection.v2.z; ++p.z){
734  for (p.y=intersection.v1.y; p.y<=intersection.v2.y; ++p.y){
735 
736  // Get start position to each slice of data.
737  const ImageVector pos(intersection.v1.x,p.y,p.z,p.c,p.t,p.u);
738  fromPt = typedFromImg.getImagePointer(pos);
739  toPt = getImagePointer(pos);
740  const MLint startX = intersection.v1.x;
741  const MLint endX = intersection.v2.x;
742 
743  if (!isFDTScalarType){
744  // When we work with extended types we must avoid to change to double during calculations since
745  // that causes information loss. In normal case we remain in double.
746  for (p.x = startX; p.x <= endX; ++p.x, ++fromPt, ++toPt){
747  *toPt=static_cast<DATATYPE>(static_cast<FROM_DATATYPE>(*fromPt)*scaleDbl + shiftDbl);
748  }
749  }
750  else{
751  for (p.x = startX; p.x <= endX; ++p.x, ++fromPt, ++toPt){
752  *toPt=static_cast<DATATYPE>(static_cast<MLdouble>(*fromPt)*scaleDbl + shiftDbl);
753  }
754  }
755  }
756  }
757  }
758  }
759  } // for (p.u)
760 
761  } // if (!intersection.isEmpty())
762 
763  } // else of if (getDataType()==typedFromImg.getDataType())
764  }
765 
766 
768 
769 
770  //-------------------------------------------------------------------------------------------
773  //-------------------------------------------------------------------------------------------
774 
775  //---------------------------------------------------------------------------
777  //---------------------------------------------------------------------------
778  inline void fill(DATATYPE value)
779  {
780  ML_CHECK_THROW(_data);
781 
782  const DATATYPE* dataEnd = static_cast<DATATYPE*>(_data) + getNumVoxels();
783 
784  for (DATATYPE* i = static_cast<DATATYPE*>(_data); i<dataEnd; ++i){ *i=value; }
785  };
786 
787 
788  //-------------------------------------------------------------------------------------------
794  //-------------------------------------------------------------------------------------------
795  inline void fillBordersWithValue(const SubImageBox& box, DATATYPE fillValue)
796  {
797  SubImage::fillBordersWithTypeData(box, reinterpret_cast<const MLTypeData*>(&fillValue));
798  }
799 
800  //-------------------------------------------------------------------------------------------
803  //-------------------------------------------------------------------------------------------
804  inline void fillInvalidRegionWithValue(DATATYPE value) {
805  fillBordersWithValue(getValidRegion(), value);
806  }
807 
808  //-------------------------------------------------------------------------------------------
812  //-------------------------------------------------------------------------------------------
814  fillBordersWithBorderValues(getValidRegion());
815  }
816 
818 
819 #if ML_DEPRECATED_SINCE(3,5,0)
820 
823 
824 public:
825 
828  inline ML_DEPRECATED const DATATYPE* getSubImgPos(const ImageVector &p) const { return getSubImagePointer(p); }
831  inline ML_DEPRECATED DATATYPE* getSubImgPos(const ImageVector &p) { return getSubImagePointer(p); }
834  inline ML_DEPRECATED const DATATYPE* getSubImgPos(MLint x, MLint y, MLint z) const { return getSubImagePointer(x, y, z); }
837  inline ML_DEPRECATED DATATYPE* getSubImgPos(MLint x, MLint y, MLint z) { return getSubImagePointer(x, y, z); }
840  inline ML_DEPRECATED const DATATYPE* getImgPos(const ImageVector &p) const { return getImagePointer(p); }
843  inline ML_DEPRECATED DATATYPE* getImgPos(const ImageVector &p) { return getImagePointer(p); }
846  inline ML_DEPRECATED const DATATYPE* getImgPos(MLint x, MLint y, MLint z) const { return getImagePointer(x, y, z); }
849  inline ML_DEPRECATED DATATYPE* getImgPos(MLint x, MLint y, MLint z) { return getImagePointer(x, y, z); }
852  inline ML_DEPRECATED ImageVector getSubImgCoords(DATATYPE *pos) const { return convertPointerToSubImagePosition(pos); }
855  inline ML_DEPRECATED void getSubImgCoords(DATATYPE *pos, MLint *x, MLint *y, MLint *z) const { convertPointerToSubImagePosition(pos, x, y, z); }
858  inline ML_DEPRECATED ImageVector getImgCoords(DATATYPE *pos) const { return convertPointerToImagePosition(pos); }
861  inline ML_DEPRECATED void getImgCoords(DATATYPE *pos, MLint *x, MLint *y, MLint *z) const { convertPointerToImagePosition(pos, x, y, z); }
864  inline ML_DEPRECATED void setSubImgVal(const ImageVector& p, DATATYPE val) { setSubImageValue(p, val); }
867  inline ML_DEPRECATED DATATYPE getSubImgVal(const ImageVector& p) const { return getSubImageValue(p); }
870  inline ML_DEPRECATED void setSubImgVal(MLint x, MLint y, DATATYPE val) { setSubImageValue(x, y, val); }
873  inline ML_DEPRECATED DATATYPE getSubImgVal(MLint x, MLint y) const { return getSubImageValue(x, y); }
876  inline ML_DEPRECATED void setSubImgVal(MLint x, MLint y, MLint z, DATATYPE val){ setSubImageValue(x, y, z, val); }
879  inline ML_DEPRECATED DATATYPE getSubImgVal(MLint x, MLint y, MLint z) const { return getSubImageValue(x, y, z); }
882  inline ML_DEPRECATED void setImgVal(const ImageVector& p, DATATYPE val) { setImageValue(p, val); }
885  inline ML_DEPRECATED DATATYPE getImgVal(const ImageVector& p) const { return getImageValue(p); }
888  inline ML_DEPRECATED void setImgVal(MLint x, MLint y, DATATYPE val) { setImageValue(x, y, val); }
891  inline ML_DEPRECATED DATATYPE getImgVal(MLint x, MLint y) const { return getImageValue(x, y); }
894  inline ML_DEPRECATED void setImgVal(MLint x, MLint y, MLint z, DATATYPE val){ setImageValue(x, y, z, val); }
897  inline ML_DEPRECATED DATATYPE getImgVal(MLint x, MLint y, MLint z) const { return getImageValue(x, y, z); }
900  inline ML_DEPRECATED MLint calcMinMax(DATATYPE &minVal, DATATYPE &maxVal, const SubImageBox * const validBox=nullptr) const { return calculateMinMax(minVal, maxVal, validBox); }
903  template <typename FROM_DATATYPE>
904  ML_DEPRECATED void copySubImg(const TSubImage<FROM_DATATYPE> &typedFromImg) { copySubImage(typedFromImg); }
907  template <typename FROM_DATATYPE>
908  ML_DEPRECATED void copySubImg(const TSubImage<FROM_DATATYPE> &typedFromImg, const ScaleShiftData& scaleShiftData) { copySubImage(typedFromImg, scaleShiftData); }
911  inline ML_DEPRECATED void fillSubImg(DATATYPE value) { fill(value);}
912 
915  inline ML_DEPRECATED void fillBordersWithClampedInputValues(const SubImageBox& box) { fillBordersWithBorderValues(box); }
916 
919  inline ML_DEPRECATED void fillBordersWithFillValue(const SubImageBox& box, DATATYPE value) { fillBordersWithValue(box, value); }
920 
922 
923 #endif
924 
925 };
926 
927 #if ML_DEPRECATED_SINCE(3,5,0)
932 #define TSubImg TSubImage
933 
934 #if defined(WIN32) && !defined(ML_NO_DEPRECATED_WARNINGS)
935 #pragma deprecated("TSubImg")
936 #endif
937 
939 #endif
940 
941 
942 //---------------------------------------------------------------------------
944 //---------------------------------------------------------------------------
945 template <typename DATATYPE>
947 
948 protected:
949 
951  _data = const_cast<DATATYPE*>(subImage.getData());
952  _subImageOffset = subImage.getBox().v1;
953  _stride = subImage.getStride();
954  _cursor = _data;
955  }
956 
957 public:
958 
959  //---------------------------------------------------------------------------
962  //---------------------------------------------------------------------------
965  inline void setSubImagePosition(const ImageVector& position) { _cursor = _data+ImageVector::dot(position,_stride); }
968  inline void setSubImagePosition(MLint x, MLint y, MLint z) { _cursor = _data+_stride.x*x+_stride.y*y+_stride.z*z; }
971  inline void setImagePosition(const ImageVector& position) { _cursor = _data + _ML_TSUBIMG_SUBDOT6(position,_subImageOffset,_stride); }
974  inline void setImagePosition(MLint x, MLint y, MLint z) { _cursor = _data+ + _ML_TSUBIMG_SUBDOT3(x,y,z,_subImageOffset,_stride); }
976  inline void setPosition(const DATATYPE *pointer) { _cursor = const_cast<DATATYPE*>(pointer); }
978  inline void moveByOffset(const ImageVector& offset) { _cursor += ImageVector::dot(offset,_stride); }
980  inline void moveByOffset(MLint x, MLint y, MLint z) { _cursor += _stride.x*x+_stride.y*y+_stride.z*z; }
982  inline void moveX() { _cursor += _stride.x; }
984  inline void moveY() { _cursor += _stride.y; }
986  inline void moveZ() { _cursor += _stride.z; }
988  inline void moveC() { _cursor += _stride.c; }
990  inline void moveT() { _cursor += _stride.t; }
992  inline void moveU() { _cursor += _stride.u; }
994  inline void reverseMoveX() { _cursor -= _stride.x; }
996  inline void reverseMoveY() { _cursor -= _stride.y; }
998  inline void reverseMoveZ() { _cursor -= _stride.z; }
1000  inline void reverseMoveC() { _cursor -= _stride.c; }
1002  inline void reverseMoveT() { _cursor -= _stride.t; }
1004  inline void reverseMoveU() { _cursor -= _stride.u; }
1005 
1007 
1008  //---------------------------------------------------------------------------
1011  // Note: All these functions do not need explicit 64 bit arithmetic, because
1012  // pointer arithmetic always goes from valid address area to another
1013  // valid address area even on 32 systems and calculations do not fall
1014  // outside valid ranges.
1015  //---------------------------------------------------------------------------
1017  inline DATATYPE getValue() const { return *(_cursor); }
1018 
1020  inline DATATYPE getValueWithOffset(const ImageVector& offset) const { return *(_cursor+ImageVector::dot(offset,_stride)); }
1021 
1023  inline DATATYPE getValueWithOffset(MLint dx, MLint dy, MLint dz) const { return *(_cursor+_stride.x*dx+_stride.y*dy+_stride.z*dz); }
1024 
1026 
1027 protected:
1029  DATATYPE* _data;
1035  DATATYPE* _cursor;
1036 
1037 
1038 #if ML_DEPRECATED_SINCE(3,5,0)
1039 
1042 
1043 public:
1044 
1047  inline ML_DEPRECATED void setCursorSubImgPos(const ImageVector& p) { setSubImagePosition(p); }
1050  inline ML_DEPRECATED void setCursorSubImgPos(MLint x, MLint y, MLint z) { setSubImagePosition(x, y, z); }
1053  inline ML_DEPRECATED void setCursorImgPos(const ImageVector& p) { setImagePosition(p); }
1056  inline ML_DEPRECATED void setCursorImgPos(MLint x, MLint y, MLint z) { setImagePosition(x, y, z); }
1059  inline ML_DEPRECATED void setCursorPos(const DATATYPE *position) { setPosition(position); }
1062  inline ML_DEPRECATED void moveCursor(const ImageVector& dp) { moveByOffset(dp); }
1065  inline ML_DEPRECATED void moveCursor(MLint x, MLint y, MLint z) { moveByOffset(x, y, z); }
1068  inline ML_DEPRECATED void moveCursorX() { moveX(); }
1071  inline ML_DEPRECATED void moveCursorY() { moveY(); }
1074  inline ML_DEPRECATED void moveCursorZ() { moveZ(); }
1077  inline ML_DEPRECATED void moveCursorC() { moveC(); }
1080  inline ML_DEPRECATED void moveCursorT() { moveT(); }
1083  inline ML_DEPRECATED void moveCursorU() { moveU(); }
1086  inline ML_DEPRECATED void moveCursorBX() { reverseMoveX(); }
1089  inline ML_DEPRECATED void moveCursorBY() { reverseMoveY(); }
1092  inline ML_DEPRECATED void moveCursorBZ() { reverseMoveZ(); }
1095  inline ML_DEPRECATED void moveCursorBC() { reverseMoveC(); }
1098  inline ML_DEPRECATED void moveCursorBT() { reverseMoveT(); }
1101  inline ML_DEPRECATED void moveCursorBU() { reverseMoveU(); }
1104  inline DATATYPE getCursorVal() const { return getValue(); }
1107  inline DATATYPE getCursorVal(const ImageVector& dp) const { return getValueWithOffset(dp); }
1110  inline DATATYPE getCursorVal(MLint dx, MLint dy, MLint dz) const { return getValueWithOffset(dx, dy, dz); }
1111 
1113 
1114 #endif
1115 
1116 };
1117 
1118 //---------------------------------------------------------------------------
1121 //---------------------------------------------------------------------------
1122 template <typename DATATYPE>
1123 class ConstTSubImageCursor : public TSubImageCursorBase<DATATYPE> {
1124 
1126 
1127 public:
1128  ConstTSubImageCursor(const TSubImage<DATATYPE>& subImage) : TSubImageCursorBase<DATATYPE>(subImage) {
1129  }
1130 
1131  //---------------------------------------------------------------------------
1136  inline const DATATYPE* getPointer() const { return T::_cursor; }
1138  inline const DATATYPE* getPointerWithOffset(const ImageVector& offset) const { return T::_cursor+ImageVector::dot(offset,T::_stride); }
1140  inline const DATATYPE* getPointerWithOffset(MLint dx, MLint dy, MLint dz) const { return (T::_cursor+T::_stride.x*dx+T::_stride.y*dy+T::_stride.z*dz); }
1142 
1143 
1144 #if ML_DEPRECATED_SINCE(3,5,0)
1145 
1148 
1149 public:
1150 
1153  inline ML_DEPRECATED const DATATYPE* getCursorPos() const { return getPointer(); }
1156  inline ML_DEPRECATED const DATATYPE* getCursorPos(const ImageVector& dp) const { return getPointerWithOffset(dp); }
1159  inline ML_DEPRECATED const DATATYPE* getCursorPos(MLint dx, MLint dy, MLint dz) const { return getPointerWithOffset(dx, dy, dz); }
1160 
1162 
1163 #endif
1164 
1165 };
1166 
1167 #if ML_DEPRECATED_SINCE(3,5,0)
1172 #define ConstTSubImgCursor ConstTSubImageCursor
1173 
1174 #if defined(WIN32) && !defined(ML_NO_DEPRECATED_WARNINGS)
1175 #pragma deprecated("ConstTSubImgCursor")
1176 #endif
1177 
1179 #endif
1180 
1181 
1182 //---------------------------------------------------------------------------
1185 //---------------------------------------------------------------------------
1186 template <typename DATATYPE>
1187 class TSubImageCursor : public TSubImageCursorBase<DATATYPE> {
1188 
1190 
1191 public:
1192 
1193  TSubImageCursor(TSubImage<DATATYPE>& subImage) : TSubImageCursorBase<DATATYPE>(subImage) {
1194  }
1195 
1196  //---------------------------------------------------------------------------
1201  inline DATATYPE* getPointer() const { return T::_cursor; }
1203  inline DATATYPE* getPointerWithOffset(const ImageVector& offset) const { return T::_cursor+ImageVector::dot(offset,T::_stride); }
1205  inline DATATYPE* getPointerWithOffset(MLint dx, MLint dy, MLint dz) const { return (T::_cursor+T::_stride.x*dx+T::_stride.y*dy+T::_stride.z*dz); }
1207 
1208  //---------------------------------------------------------------------------
1211  // Note: All these functions do not need explicit 64 bit arithmetic, because
1212  // pointer arithmetic always goes from valid address area to another
1213  // valid address area even on 32 systems and calculations do not fall
1214  // outside valid ranges.
1215  //---------------------------------------------------------------------------
1217  inline void setValue(DATATYPE value) const { *(T::_cursor) = value; }
1219  inline void setValueWithOffset(const ImageVector& offset, DATATYPE value) const { *(T::_cursor+ImageVector::dot(offset,T::_stride))=value; }
1221  inline void setValueWithOffset(MLint dx, MLint dy, MLint dz, DATATYPE value) const { *(T::_cursor+T::_stride.x*dx+T::_stride.y*dy+T::_stride.z*dz)=value; }
1223 
1224 #if ML_DEPRECATED_SINCE(3,5,0)
1225 
1228 
1229 public:
1230 
1233  inline ML_DEPRECATED DATATYPE* getCursorPos() const { return getPointer(); }
1236  inline ML_DEPRECATED DATATYPE* getCursorPos(const ImageVector& dp) const { return getPointerWithOffset(dp); }
1239  inline ML_DEPRECATED DATATYPE* getCursorPos(MLint dx, MLint dy, MLint dz) const { return getPointerWithOffset(dx, dy, dz); }
1242  inline ML_DEPRECATED void setCursorVal(DATATYPE val) const { setValue(val); }
1245  inline ML_DEPRECATED void setCursorVal(const ImageVector& dp, DATATYPE val) const { setValueWithOffset(dp, val); }
1248  inline ML_DEPRECATED void setCursorVal(MLint dx, MLint dy, MLint dz, DATATYPE val) const { setValueWithOffset(dx, dy, dz, val); }
1249 
1251 
1252 #endif
1253 
1254 };
1255 
1256 #if ML_DEPRECATED_SINCE(3,5,0)
1261 #define TSubImgCursor TSubImageCursor
1262 
1263 #if defined(WIN32) && !defined(ML_NO_DEPRECATED_WARNINGS)
1264 #pragma deprecated("TSubImgCursor")
1265 #endif
1266 
1268 #endif
1269 
1270 
1271 //-------------------------------------------------------------------------
1274 //-------------------------------------------------------------------------
1275 template <typename DATATYPE>
1276 class TSubImageWithCursor : public TSubImage<DATATYPE>
1277 {
1278  typedef TSubImage<DATATYPE> T;
1279 
1280 public:
1282  TSubImageWithCursor():TSubImage<DATATYPE>(), _cursor(nullptr)
1283  {
1284  }
1286  TSubImageWithCursor(const TSubImage<DATATYPE>& subImage):TSubImage<DATATYPE>(subImage), _cursor(nullptr)
1287  {
1288  }
1289 
1291  TSubImageWithCursor(const SubImage& subImage):TSubImage<DATATYPE>(subImage), _cursor(nullptr)
1292  {
1293  }
1294 
1296  TSubImageWithCursor(const TSubImageWithCursor& subImage):TSubImage<DATATYPE>(subImage),_cursor(subImage._cursor)
1297  {
1298  }
1299 
1303  {
1305  _cursor = tSubImg._cursor;
1306  return *this;
1307  }
1308 
1309  //---------------------------------------------------------------------------
1312  //---------------------------------------------------------------------------
1315  inline void setCursorSubImagePosition(const ImageVector& position) { _cursor = static_cast<DATATYPE*>(T::_data)+ImageVector::dot(position,T::_stride); }
1318  inline void setCursorSubImagePosition(MLint x, MLint y, MLint z) { _cursor = static_cast<DATATYPE*>(T::_data)+T::_stride.x*x+T::_stride.y*y+T::_stride.z*z; }
1321  inline void setCursorImagePosition(const ImageVector& position) { _cursor = static_cast<DATATYPE*>(T::_data)+ _ML_TSUBIMG_SUBDOT6(position, T::_box.v1 ,T::_stride); }
1324  inline void setCursorImagePosition(MLint x, MLint y, MLint z) { _cursor = static_cast<DATATYPE*>(T::_data)+ _ML_TSUBIMG_SUBDOT3(x,y,z, T::_box.v1 ,T::_stride); }
1326  inline void setCursorPosition(const DATATYPE* pointer) { _cursor = const_cast<DATATYPE*>(pointer); }
1328  inline void moveCursorByOffset(const ImageVector& offset) { _cursor += ImageVector::dot(offset,T::_stride); }
1330  inline void moveCursorByOffset(MLint x, MLint y, MLint z) { _cursor += T::_stride.x*x+T::_stride.y*y+T::_stride.z*z; }
1332  inline void moveCursorX() { _cursor += T::_stride.x; }
1334  inline void moveCursorY() { _cursor += T::_stride.y; }
1336  inline void moveCursorZ() { _cursor += T::_stride.z; }
1338  inline void moveCursorC() { _cursor += T::_stride.c; }
1340  inline void moveCursorT() { _cursor += T::_stride.t; }
1342  inline void moveCursorU() { _cursor += T::_stride.u; }
1344  inline void reverseMoveCursorX() { _cursor -= T::_stride.x; }
1346  inline void reverseMoveCursorY() { _cursor -= T::_stride.y; }
1348  inline void reverseMoveCursorZ() { _cursor -= T::_stride.z; }
1350  inline void reverseMoveCursorC() { _cursor -= T::_stride.c; }
1352  inline void reverseMoveCursorT() { _cursor -= T::_stride.t; }
1354  inline void reverseMoveCursorU() { _cursor -= T::_stride.u; }
1355 
1357 
1358  //---------------------------------------------------------------------------
1361  // Note: All these functions do not need explicit 64 bit arithmetic, because
1362  // pointer arithmetic always goes from valid address area to another
1363  // valid address area even on 32 systems and calculations do not fall
1364  // outside valid ranges.
1365  //---------------------------------------------------------------------------
1367  inline DATATYPE getCursorValue() const { return *(_cursor); }
1369  inline DATATYPE getCursorValueWithOffset(const ImageVector& offset) const { return *(_cursor+ImageVector::dot(offset,T::_stride)); }
1371  inline DATATYPE getCursorValueWithOffset(MLint dx, MLint dy, MLint dz) const { return *(_cursor+T::_stride.x*dx+T::_stride.y*dy+T::_stride.z*dz); }
1372 
1374 
1375  //---------------------------------------------------------------------------
1380  inline DATATYPE* getCursorPointer() const { return _cursor; }
1382  inline DATATYPE* getCursorPointerWithOffset(const ImageVector& offset) const { return _cursor+ImageVector::dot(offset,T::_stride); }
1384  inline DATATYPE* getCursorPointerWithOffset(MLint dx, MLint dy, MLint dz) const { return (_cursor+T::_stride.x*dx+T::_stride.y*dy+T::_stride.z*dz); }
1386 
1387  //---------------------------------------------------------------------------
1390  // Note: All these functions do not need explicit 64 bit arithmetic, because
1391  // pointer arithmetic always goes from valid address area to another
1392  // valid address area even on 32 systems and calculations do not fall
1393  // outside valid ranges.
1394  //---------------------------------------------------------------------------
1396  inline void setCursorValue(DATATYPE value) { *(_cursor) = value; }
1398  inline void setCursorValueWithOffset(const ImageVector& offset, DATATYPE value) { *(_cursor+ImageVector::dot(offset,T::_stride))=value; }
1400  inline void setCursorValueWithOffset(MLint dx, MLint dy, MLint dz, DATATYPE value) { *(_cursor+T::_stride.x*dx+T::_stride.y*dy+T::_stride.z*dz)=value; }
1401 
1403 
1404 private:
1406  DATATYPE* _cursor;
1407 
1408 
1409 #ifdef ML_DEPRECATED
1410 
1413 
1414 public:
1415 
1418  inline ML_DEPRECATED void setCursorSubImgPos(const ImageVector& p) { setCursorSubImagePosition(p); }
1421  inline ML_DEPRECATED void setCursorSubImgPos(MLint x, MLint y, MLint z) { setCursorSubImagePosition(x, y, z); }
1424  inline ML_DEPRECATED void setCursorImgPos(const ImageVector& p) { setCursorImagePosition(p); }
1427  inline ML_DEPRECATED void setCursorImgPos(MLint x, MLint y, MLint z) { setCursorImagePosition(x, y, z); }
1430  inline ML_DEPRECATED void setCursorPos(const DATATYPE* position) { setCursorPosition(position); }
1433  inline ML_DEPRECATED void moveCursor(const ImageVector& dp) { moveCursorByOffset(dp); }
1436  inline ML_DEPRECATED void moveCursor(MLint x, MLint y, MLint z) { moveCursorByOffset(x, y, z); }
1439  inline ML_DEPRECATED void moveCursorBX() { reverseMoveCursorX(); }
1442  inline ML_DEPRECATED void moveCursorBY() { reverseMoveCursorY(); }
1445  inline ML_DEPRECATED void moveCursorBZ() { reverseMoveCursorZ(); }
1448  inline ML_DEPRECATED void moveCursorBC() { reverseMoveCursorC(); }
1451  inline ML_DEPRECATED void moveCursorBT() { reverseMoveCursorT(); }
1454  inline ML_DEPRECATED void moveCursorBU() { reverseMoveCursorU(); }
1457  inline ML_DEPRECATED DATATYPE getCursorVal() const { return getCursorValue(); }
1460  inline ML_DEPRECATED DATATYPE getCursorVal(const ImageVector& dp) const { return getCursorValueWithOffset(dp); }
1463  inline ML_DEPRECATED DATATYPE getCursorVal(MLint dx, MLint dy, MLint dz) const { return getCursorValueWithOffset(dx, dy, dz); }
1466  inline ML_DEPRECATED DATATYPE* getCursorPos() const { return getCursorPointer(); }
1469  inline ML_DEPRECATED DATATYPE* getCursorPos(const ImageVector& dp) const { return getCursorPointerWithOffset(dp); }
1472  inline ML_DEPRECATED DATATYPE* getCursorPos(MLint dx, MLint dy, MLint dz) const { return getCursorPointerWithOffset(dx, dy, dz); }
1475  inline void setCursorVal(DATATYPE val) { setCursorValue(val); }
1478  inline void setCursorVal(const ImageVector& dp, DATATYPE val) { setCursorValueWithOffset(dp, val); }
1481  inline void setCursorVal(MLint dx, MLint dy, MLint dz, DATATYPE val) { setCursorValueWithOffset(dx, dy, dz, val); }
1482 
1484 
1485 #endif
1486 
1487 };
1488 
1489 #if ML_DEPRECATED_SINCE(3,5,0)
1494 #define TSubImgWithCursor TSubImageWithCursor
1495 
1496 #if defined(WIN32) && !defined(ML_NO_DEPRECATED_WARNINGS)
1497 #pragma deprecated("TSubImgWithCursor")
1498 #endif
1499 
1501 #endif
1502 
1503 //---------------------------------------------------------------------------
1514 //---------------------------------------------------------------------------
1515 template <typename T>
1517 {
1518  // Check whether template type and real data type match if there is valid data.
1519  if (subImg.getData() && !TypeTraits<T>::matches(subImg.getDataType()) )
1520  {
1521  ML_PRINT_FATAL_ERROR("tsubimage_cast", ML_BAD_DATA_TYPE,
1522  "Mismatch of data type between argument and template typename.");
1523  }
1524  return *(static_cast<TSubImage<T>* >(&subImg));
1525 }
1526 
1527 template <typename T>
1528 const TSubImage<T>& tsubimage_cast(const SubImage& subImg)
1529 {
1530  // Check whether template type and real data type match if there is valid data.
1531  if (subImg.getData() && !TypeTraits<T>::matches(subImg.getDataType()) )
1532  {
1533  ML_PRINT_FATAL_ERROR("tsubimage_cast", ML_BAD_DATA_TYPE,
1534  "Mismatch of data type between argument and template typename.");
1535  }
1536  return *(static_cast<const TSubImage<T>* >(&subImg));
1537 }
1538 
1539 template <typename T>
1541 {
1542  // Check whether template type and real data type match if there is valid data.
1543  if (subImg->getData() && !TypeTraits<T>::matches(subImg->getDataType()) )
1544  {
1545  ML_PRINT_FATAL_ERROR("tsubimage_cast", ML_BAD_DATA_TYPE,
1546  "Mismatch of data type between argument and template typename.");
1547  }
1548  return static_cast<TSubImage<T>* >(subImg);
1549 }
1550 
1551 template <typename T>
1552 const TSubImage<T>* tsubimage_cast(const SubImage* subImg)
1553 {
1554  // Check whether template type and real data type match if there is valid data.
1555  if (subImg->getData() && !TypeTraits<T>::matches(subImg->getDataType()) )
1556  {
1557  ML_PRINT_FATAL_ERROR("tsubimage_cast", ML_BAD_DATA_TYPE,
1558  "Mismatch of data type between argument and template typename.");
1559  }
1560  return static_cast<const TSubImage<T>* >(subImg);
1561 }
1562 
1564 
1565 #ifdef ML_DEPRECATED
1566 
1569 template <typename T>
1570 TSubImage<T>* tsubimg_cast(SubImage* subImg) { return tsubimage_cast<T>(subImg); }
1571 
1574 template <typename T>
1575 const TSubImage<T>* tsubimg_cast(const SubImage* subImg) { return tsubimage_cast<T>(subImg); }
1576 
1579 template <typename T>
1580 TSubImage<T>& tsubimg_cast(SubImage& subImg) { return tsubimage_cast<T>(subImg); }
1581 
1584 template <typename T>
1585 const TSubImage<T>& tsubimg_cast(const SubImage& subImg) { return tsubimage_cast<T>(subImg); }
1586 
1587 
1588 #endif
1589 
1590 
1591 ML_END_NAMESPACE
1592 
1593 namespace std {
1594 
1595  //---------------------------------------------------------------------------
1596  // Debug printing for TSubImage.
1597  //---------------------------------------------------------------------------
1598 
1601  template <typename DATATYPE>
1602  inline ostream &operator<<(ostream &ostr, const ML_NAMESPACE::TSubImage<DATATYPE> &v)
1603  {
1604  // Get box of subimage and traverse all of its voxels.
1605  const ML_NAMESPACE::SubImageBox& box = v.getBox();
1607  for (p.u=box.v1.u; p.u<=box.v2.u; ++p.u){
1608  for (p.t=box.v1.t; p.t<=box.v2.t; ++p.t){
1609  for (p.c=box.v1.c; p.c<=box.v2.c; ++p.c){
1610  for (p.z=box.v1.z; p.z<=box.v2.z; ++p.z){
1611  for (p.y=box.v1.y; p.y<=box.v2.y; ++p.y){
1612  // Print row of voxels after a single row start position.
1613  p.x = box.v1.x;
1614  ostr << p << ": ";
1615  for (; p.x<=box.v2.x; p.x++){
1616  ostr << v.getImageValue(p) << " ";
1617  }
1618  ostr << std::endl;
1619  }
1620  }
1621  }
1622  }
1623  }
1624  return ostr;
1625  }
1626 
1627 }
1628 
1629 #ifdef _MSC_VER
1630 #pragma warning(pop)
1631 #endif
1632 
1633 
1634 #endif //of __mlTSubImage_H
1635 
1636 
1637 
#define ML_DEPRECATED
Definition: CSOGroup.h:371
@ T
Definition: SoKeyGrabber.h:71
Predeclaration for const cursor.
Definition: mlTSubImage.h:1123
ConstTSubImageCursor(const TSubImage< DATATYPE > &subImage)
Definition: mlTSubImage.h:1128
const DATATYPE * getPointer() const
Definition: mlTSubImage.h:1136
const DATATYPE * getPointerWithOffset(const ImageVector &offset) const
Returns cursor position of voxel given from current cursor shifted by offset.
Definition: mlTSubImage.h:1138
const DATATYPE * getPointerWithOffset(MLint dx, MLint dy, MLint dz) const
Returns cursor position of voxel given from current cursor shifted by (dx, dy, dz).
Definition: mlTSubImage.h:1140
This class manages/represents a rectangular 6d image region which is organized linearly in memory.
Definition: mlSubImage.h:75
void * getData() const
Returns the memory address of the memory managed by the subimage.
Definition: mlSubImage.h:372
MLDataType getDataType() const
Return type of image data.
Definition: mlSubImage.h:288
ImageVector getStride() const
Returns a stride vector to address the memory efficiently.
Definition: mlSubImage.h:264
const SubImageBox & getBox() const
Returns the box describing the origin/extent of the subimage.
Definition: mlSubImage.h:230
ImageVector getSourceImageExtent() const
Returns the image extent of the source image that was used to create this SubImage.
Definition: mlSubImage.h:241
void set(const ComponentType v=0)
Sets all components to v or - if v is not specified - to 0.
DT getScale() const
Returns scale constant from transformation y=scale*x+offset.
ReorderMode getReorderMode() const
Get the reorder mode.
DT getShift() const
Returns addition constant shift from transformation y=scale*x+shift.
VectorType v1
Corner v1 of the subimage region (included in region).
Definition: mlSubImageBox.h:63
VectorType v2
Corner v2 of the subimage region (also included in region!).
Definition: mlSubImageBox.h:69
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.
Definition: mlTSubImage.h:946
void reverseMoveC()
Moves cursor backward in c direction.
Definition: mlTSubImage.h:1000
void moveT()
Moves cursor forward in t direction.
Definition: mlTSubImage.h:990
void reverseMoveX()
Moves cursor backward in x direction.
Definition: mlTSubImage.h:994
void moveZ()
Moves cursor forward in z direction.
Definition: mlTSubImage.h:986
void setPosition(const DATATYPE *pointer)
Sets cursor to the given pointer where the pointer is the memory address of the voxel.
Definition: mlTSubImage.h:976
void reverseMoveY()
Moves cursor backward in y direction.
Definition: mlTSubImage.h:996
DATATYPE getValue() const
Returns voxel value at cursor position.
Definition: mlTSubImage.h:1017
void reverseMoveT()
Moves cursor backward in t direction.
Definition: mlTSubImage.h:1002
ImageVector _stride
Stride for the sub image.
Definition: mlTSubImage.h:1033
void moveU()
Moves cursor forward in u direction.
Definition: mlTSubImage.h:992
void setSubImagePosition(MLint x, MLint y, MLint z)
Sets cursor to the given 3d position (x, y, z) relative to the origin of the subimage region.
Definition: mlTSubImage.h:968
DATATYPE getValueWithOffset(MLint dx, MLint dy, MLint dz) const
Return voxel value at (cursor position + (dx, dy, dz))
Definition: mlTSubImage.h:1023
void moveX()
Moves cursor forward in x direction.
Definition: mlTSubImage.h:982
DATATYPE getValueWithOffset(const ImageVector &offset) const
Returns voxel value at (cursor position + offset).
Definition: mlTSubImage.h:1020
ImageVector _subImageOffset
SubImage offset in original image.
Definition: mlTSubImage.h:1031
DATATYPE * _data
SubImage data.
Definition: mlTSubImage.h:1029
void reverseMoveZ()
Moves cursor backward in z direction.
Definition: mlTSubImage.h:998
void setImagePosition(const ImageVector &position)
Sets cursor to the given 6d position relative to the origin of the complete image region.
Definition: mlTSubImage.h:971
void moveByOffset(const ImageVector &offset)
Moves cursor to cursor position + offset.
Definition: mlTSubImage.h:978
DATATYPE * _cursor
Cursor address for image data access.
Definition: mlTSubImage.h:1035
void reverseMoveU()
Moves cursor backward in u direction.
Definition: mlTSubImage.h:1004
TSubImageCursorBase(const TSubImage< DATATYPE > &subImage)
Definition: mlTSubImage.h:950
void moveY()
Moves cursor forward in y direction.
Definition: mlTSubImage.h:984
void setSubImagePosition(const ImageVector &position)
Sets cursor to the given position relative to the origin of the subimage region.
Definition: mlTSubImage.h:965
void moveByOffset(MLint x, MLint y, MLint z)
Moves cursor to cursor position + (x, y, z).
Definition: mlTSubImage.h:980
void setImagePosition(MLint x, MLint y, MLint z)
Sets cursor to the given 3d position (x, y, z) relative to the origin of the complete image region.
Definition: mlTSubImage.h:974
void moveC()
Moves cursor forward in c direction.
Definition: mlTSubImage.h:988
Predeclaration for cursor.
Definition: mlTSubImage.h:1187
void setValueWithOffset(MLint dx, MLint dy, MLint dz, DATATYPE value) const
Sets voxel value at (cursor position + (dx, dy, dz)) to value.
Definition: mlTSubImage.h:1221
TSubImageCursor(TSubImage< DATATYPE > &subImage)
Definition: mlTSubImage.h:1193
void setValueWithOffset(const ImageVector &offset, DATATYPE value) const
Sets voxel value at (cursor position + offset) to value.
Definition: mlTSubImage.h:1219
void setValue(DATATYPE value) const
Sets voxel value at cursor position to value.
Definition: mlTSubImage.h:1217
DATATYPE * getPointerWithOffset(MLint dx, MLint dy, MLint dz) const
Returns cursor position of voxel given from current cursor shifted by (dx, dy, dz).
Definition: mlTSubImage.h:1205
DATATYPE * getPointerWithOffset(const ImageVector &offset) const
Returns cursor position of voxel given from current cursor shifted by offset.
Definition: mlTSubImage.h:1203
DATATYPE * getPointer() const
Definition: mlTSubImage.h:1201
A class that offers a TSubImage with a TSubImageCursor.
Definition: mlTSubImage.h:1277
void setCursorValue(DATATYPE value)
Sets the voxel value at cursor position to value.
Definition: mlTSubImage.h:1396
DATATYPE * getCursorPos(const ImageVector &dp) const
Definition: mlTSubImage.h:1469
void reverseMoveCursorC()
Moves cursor backward in c direction.
Definition: mlTSubImage.h:1350
void moveCursorT()
Moves cursor forward in t direction.
Definition: mlTSubImage.h:1340
DATATYPE getCursorVal() const
Definition: mlTSubImage.h:1457
DATATYPE * getCursorPointer() const
Definition: mlTSubImage.h:1380
void setCursorSubImgPos(MLint x, MLint y, MLint z)
Definition: mlTSubImage.h:1421
void moveCursorByOffset(const ImageVector &offset)
Moves cursor to cursor position + offset.
Definition: mlTSubImage.h:1328
void setCursorImagePosition(MLint x, MLint y, MLint z)
Sets cursor to the given 3d position (x, y, z) relative to the origin of the complete image region.
Definition: mlTSubImage.h:1324
DATATYPE * getCursorPos() const
Definition: mlTSubImage.h:1466
DATATYPE getCursorValue() const
Returns the voxel value at the cursor position.
Definition: mlTSubImage.h:1367
void reverseMoveCursorU()
Moves cursor backward in u direction.
Definition: mlTSubImage.h:1354
void reverseMoveCursorY()
Moves cursor backward in y direction.
Definition: mlTSubImage.h:1346
DATATYPE * getCursorPointerWithOffset(MLint dx, MLint dy, MLint dz) const
Returns cursor pointer of voxel given from current cursor shifted by (dx, dy, dz).
Definition: mlTSubImage.h:1384
DATATYPE getCursorValueWithOffset(MLint dx, MLint dy, MLint dz) const
Returns voxel value at (cursor position + (dx, dy, dz))
Definition: mlTSubImage.h:1371
void reverseMoveCursorX()
Moves cursor backward in x direction.
Definition: mlTSubImage.h:1344
void moveCursorByOffset(MLint x, MLint y, MLint z)
Moves cursor to cursor position + (x, y, z).
Definition: mlTSubImage.h:1330
TSubImageWithCursor(const TSubImage< DATATYPE > &subImage)
Constructor with TSubImage.
Definition: mlTSubImage.h:1286
void moveCursorZ()
Moves cursor forward in z direction.
Definition: mlTSubImage.h:1336
void reverseMoveCursorZ()
Moves cursor backward in z direction.
Definition: mlTSubImage.h:1348
void moveCursorC()
Moves cursor forward in c direction.
Definition: mlTSubImage.h:1338
void setCursorVal(const ImageVector &dp, DATATYPE val)
Definition: mlTSubImage.h:1478
void setCursorPos(const DATATYPE *position)
Definition: mlTSubImage.h:1430
void moveCursor(const ImageVector &dp)
Definition: mlTSubImage.h:1433
void reverseMoveCursorT()
Moves cursor backward in t direction.
Definition: mlTSubImage.h:1352
void setCursorValueWithOffset(const ImageVector &offset, DATATYPE value)
Sets the voxel value at (cursor position + offset) to value.
Definition: mlTSubImage.h:1398
void setCursorImagePosition(const ImageVector &position)
Sets cursor to the given 6d position relative to the origin of the complete image region.
Definition: mlTSubImage.h:1321
void setCursorVal(DATATYPE val)
Definition: mlTSubImage.h:1475
void setCursorPosition(const DATATYPE *pointer)
Sets cursor to the given pointer where pointer is the memory address of the voxel.
Definition: mlTSubImage.h:1326
DATATYPE * getCursorPointerWithOffset(const ImageVector &offset) const
Returns cursor pointer of voxel given from current cursor shifted by offset.
Definition: mlTSubImage.h:1382
TSubImageWithCursor & operator=(const TSubImageWithCursor< DATATYPE > &tSubImg)
Assignment operator to get an identical copy.
Definition: mlTSubImage.h:1302
void moveCursorY()
Moves cursor forward in y direction.
Definition: mlTSubImage.h:1334
DATATYPE * getCursorPos(MLint dx, MLint dy, MLint dz) const
Definition: mlTSubImage.h:1472
void moveCursorX()
Moves cursor forward in x direction.
Definition: mlTSubImage.h:1332
DATATYPE getCursorVal(const ImageVector &dp) const
Definition: mlTSubImage.h:1460
TSubImageWithCursor(const TSubImageWithCursor &subImage)
Constructor with TSubImageWithCursor.
Definition: mlTSubImage.h:1296
void moveCursor(MLint x, MLint y, MLint z)
Definition: mlTSubImage.h:1436
TSubImageWithCursor(const SubImage &subImage)
Constructor with SubImage.
Definition: mlTSubImage.h:1291
void moveCursorU()
Moves cursor forward in u direction.
Definition: mlTSubImage.h:1342
DATATYPE getCursorValueWithOffset(const ImageVector &offset) const
Returns the voxel value at (cursor position + offset)
Definition: mlTSubImage.h:1369
void setCursorSubImgPos(const ImageVector &p)
Definition: mlTSubImage.h:1418
void setCursorSubImagePosition(MLint x, MLint y, MLint z)
Sets cursor to the given 3d position (x, y, z) relative to the origin of the subimage region.
Definition: mlTSubImage.h:1318
void setCursorSubImagePosition(const ImageVector &position)
Sets cursor to the given position relative to the origin of the subimage region.
Definition: mlTSubImage.h:1315
void setCursorVal(MLint dx, MLint dy, MLint dz, DATATYPE val)
Definition: mlTSubImage.h:1481
TSubImageWithCursor()
Default constructor.
Definition: mlTSubImage.h:1282
void setCursorImgPos(MLint x, MLint y, MLint z)
Definition: mlTSubImage.h:1427
DATATYPE getCursorVal(MLint dx, MLint dy, MLint dz) const
Definition: mlTSubImage.h:1463
void setCursorImgPos(const ImageVector &p)
Definition: mlTSubImage.h:1424
void setCursorValueWithOffset(MLint dx, MLint dy, MLint dz, DATATYPE value)
Sets voxel value at (cursor position + (dx, dy,dz)) to value.
Definition: mlTSubImage.h:1400
This template class manages/represents a rectangular 6d image region in memory which is organized lin...
Definition: mlTSubImage.h:110
TSubImage(const SubImage &subImage)
Constructor to build a typed subimage from an untyped subImage.
Definition: mlTSubImage.h:169
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 ...
Definition: mlTSubImage.h:374
void copySubImageTyped(const TSubImage< FROM_DATATYPE > &typedFromImg, const ScaleShiftData &scaleShiftData)
Copies image data from the subimage fromImg into the overlapping region of this subimage.
Definition: mlTSubImage.h:591
TSubImage(const TSubImage< DATATYPE > &typedSubImage)
Copy constructor to get an identical copy.
Definition: mlTSubImage.h:194
void copySubImageReorderColorPlanesToInterleaved(const TSubImage< FROM_DATATYPE > &typedFromImage, const ScaleShiftData &scaleShiftData)
Implements special case for void copySubImageTyped(const TSubImage<FROM_DATATYPE> &typedFromImg,...
Definition: mlTSubImage.h:498
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...
Definition: mlTSubImage.h:361
DATATYPE getImageValue(MLint x, MLint y) const
Returns the 2d voxel value from the given position (x, y).
Definition: mlTSubImage.h:392
TSubImage(const SubImageBox &box, MLDataType dataType, void *data)
Constructor for an image region with location/extent box, with data type dataType (must fit to DATATY...
Definition: mlTSubImage.h:137
const DATATYPE * getImagePointer(const ImageVector &position) const
Returns a pointer to voxel data of image voxel at 6d position position relative to the begin of the c...
Definition: mlTSubImage.h:253
void setImageValue(const ImageVector &position, DATATYPE value)
Sets the 6d voxel at the given position to the given value.
Definition: mlTSubImage.h:379
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...
Definition: mlTSubImage.h:365
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 begin of th...
Definition: mlTSubImage.h:261
ConstTSubImageCursor< DATATYPE > ConstCursor
A read-only cursor.
Definition: mlTSubImage.h:120
~TSubImage() override=default
Virtual destructor to shut up compiler warnings.
void fill(DATATYPE value)
Sets all voxel values in subimage to value.
Definition: mlTSubImage.h:778
TSubImage & operator=(const TSubImage< DATATYPE > &typedSubImage)
Assignment operator to get an identical copy.
Definition: mlTSubImage.h:204
ImageVector convertPointerToImagePosition(DATATYPE *pointer) const
Returns 6d voxel coordinates corresponding to the memory address pointer.
Definition: mlTSubImage.h:311
DATATYPE getImageValue(MLint x, MLint y, MLint z) const
Returns the 3d voxel value from given position (x, y, z).
Definition: mlTSubImage.h:401
TSubImageCursor< DATATYPE > Cursor
A read/write cursor.
Definition: mlTSubImage.h:118
ImageVector convertPointerToSubImagePosition(DATATYPE *pointer) const
Returns 6d voxel coordinates corresponding to the memory address pointer.
Definition: mlTSubImage.h:274
TSubImage()
Default constructor to build a typed subimage (with an empty box) from scratch.
Definition: mlTSubImage.h:152
DATATYPE getImageValue(const ImageVector &position) const
Returns the 6d voxel value from the given position.
Definition: mlTSubImage.h:383
DATATYPE * getSubImagePointer(const ImageVector &position)
Definition: mlTSubImage.h:234
void fillInvalidRegionWithValue(DATATYPE value)
Fills the invalid region (everything outside of getValidRegion()) with the given value.
Definition: mlTSubImage.h:804
DATATYPE * getImagePointer(MLint x, MLint y, MLint z)
Definition: mlTSubImage.h:262
DATATYPE ComponentType
A typedef to "export" the type of voxels components.
Definition: mlTSubImage.h:115
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.
Definition: mlTSubImage.h:397
void fillBordersWithValue(const SubImageBox &box, DATATYPE fillValue)
Fills all regions with fillValue which are not covered by box.
Definition: mlTSubImage.h:795
DATATYPE getSubImageValue(const ImageVector &position) const
Returns voxel value at the given position where position is relative to the origin of the subimage re...
Definition: mlTSubImage.h:356
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...
Definition: mlTSubImage.h:351
MLint calculateMinMax(DATATYPE &minValue, DATATYPE &maxValue, const SubImageBox *const validBox=nullptr) const
Scans subimage and determines minimum and maximum values of the region which is part of subimage box ...
Definition: mlTSubImage.h:420
void convertPointerToSubImagePosition(DATATYPE *pointer, MLint *x, MLint *y, MLint *z) const
Returns 3d voxel coordinates corresponding to the memory address pointer.
Definition: mlTSubImage.h:282
DATATYPE & operator[](const ImageVector &position)
Reference access to voxel value at the given position.
Definition: mlTSubImage.h:346
DATATYPE * getSubImagePointer(MLint x, MLint y, MLint z)
Definition: mlTSubImage.h:246
DATATYPE * getData()
Definition: mlTSubImage.h:218
const DATATYPE * getData() const
Returns memory address of image region (Overloads method from SubImage)
Definition: mlTSubImage.h:217
const DATATYPE * getSubImagePointer(const ImageVector &position) const
Returns a pointer to voxel data of image voxel at the 6d position relative to the begin of the subima...
Definition: mlTSubImage.h:233
void setImageValue(MLint x, MLint y, DATATYPE value)
Sets the 2d voxel at the given position (x, y) to the the given value.
Definition: mlTSubImage.h:388
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 positionis relative...
Definition: mlTSubImage.h:370
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 begin of th...
Definition: mlTSubImage.h:245
const DATATYPE & operator[](const ImageVector &position) const
Constant reference access to voxel value at the given position.
Definition: mlTSubImage.h:340
void convertPointerToImagePosition(DATATYPE *pointer, MLint *x, MLint *y, MLint *z) const
Returns 3d voxel coordinates corresponding to the memory address pointer.
Definition: mlTSubImage.h:320
DATATYPE * getImagePointer(const ImageVector &position)
Definition: mlTSubImage.h:254
void fillInvalidRegionWithBorderValues()
Fills the invalid region (everything outside of getValidRegion()) with the values on the borders of t...
Definition: mlTSubImage.h:813
ComponentType c
Color component of the vector.
Definition: mlImageVector.h:65
ComponentType t
Time component of the vector.
Definition: mlImageVector.h:67
ComponentType u
Unit/Modality/User component of the vector.
Definition: mlImageVector.h:69
ComponentType z
Z component of the vector.
Definition: mlImageVector.h:63
ComponentType x
X component of the vector.
Definition: mlImageVector.h:59
ComponentType y
Y component of the vector.
Definition: mlImageVector.h:61
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:715
bool MLValuesAreEqual(MLint8 a, MLint8 b, MLint8)
Returns true if values are equal (numerically safely compared), otherwise false.
MLint32 MLDataType
MLDataType.
Definition: mlTypeDefs.h:684
#define ML_BAD_DATA_TYPE
A wrong or unexpected data type has been passed to an algorithm which often is a programming error; t...
Definition: mlTypeDefs.h:884
#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)
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator "<<" for stream output of Field objects.
#define _ML_TSUBIMG_SUBDOT6(pos, offset, stride)
Private helper macro for calculation of memory offset, calculates (pos-offset) * stride.
Definition: mlTSubImage.h:44
#define _ML_TSUBIMG_SUBDOT2(x, y, offset, stride)
Private helper macro for calculation of memory offset, calculates ((xy)-offset) * stride.
Definition: mlTSubImage.h:59
#define _ML_TSUBIMG_SUBDOT3(x, y, z, offset, stride)
Private helper macro for calculation of memory offset, calculates ((xyz)-offset) * stride.
Definition: mlTSubImage.h:53
#define _ML_CHECK_SUBIMAGE_DATA_POINTERS(FROM_PTR, TO_PTR)
Internal helper macro to check validity of data pointers of subimages.
Definition: mlTSubImage.h:482
MLint32 MLIsScalarTypePtr(const T *)
double MLdouble
Definition: mlTypeDefs.h:223
unsigned char MLTypeData
This is the pointer type used to point to the data of MLType data instances.
Definition: mlTypeDefs.h:1436
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:578
MLWEM_EXPORT void intersect(WEMTrianglePatch *inPatch1, WEMTrianglePatch *inPatch2, WEMTrianglePatch *outPatch, unsigned int outputMode, TriangulationModes triangulationMode, WEMVector< WEMCut > *cuts=nullptr)
Returns the intersection of the given patches.
TScaleShiftData< MLdouble > ScaleShiftData
Double version of TScaleShiftData for maximum reasonable precision.
TSubImageBox< MLint > SubImageBox
Define the standard SubImageBox type used in the ML. Its size varies with the size of the MLint type.
const TSubImage< T > & tsubimg_cast(const SubImage &subImg)
Definition: mlTSubImage.h:1585
TImageVector< MLint > ImageVector
Defines the standard ImageVector type which is used by the ML for indexing and coordinates.
const TSubImage< T > * tsubimage_cast(const SubImage *subImg)
Definition: mlTSubImage.h:1552
TypeTraits for scalar ML Datatypes.
Definition: mlTypeTraits.h:51