MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlIntegerVector.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_INTEGER_VECTOR_H
14#define ML_INTEGER_VECTOR_H
15
17
18// ML-includes
19#include "mlLinearAlgebra.h"
20#include <mlTypeTraits.h>
21#include <mlUtilsSystemC.h>
22
23
25
26//-------------------------------------------------------------------------
28//-------------------------------------------------------------------------
29typedef int VectorDimIdxType;
30
31//-------------------------------------------------------------------------
37//-------------------------------------------------------------------------
38template <typename CompIntType, VectorDimIdxType NumDim> class TVectorNDBase
39{
40public:
43
45 enum {
46 NumberOfDimensions = NumDim
47 };
48
51 ComponentType array[NumberOfDimensions];
52
53protected:
58};
59
60//-------------------------------------------------------------------------
64
108//-------------------------------------------------------------------------
109template <class TVectorBase> class TVector : public TVectorBase
110{
111public:
113 typedef typename TVectorBase::ComponentType ComponentType;
114
116 typedef TVectorBase ParentClass;
117
119 enum {
120 NumberOfDimensions = ParentClass::NumberOfDimensions
121 };
122
123
124 //------------------------------------------------------
127 //------------------------------------------------------
130 : ParentClass()
131 {
132 memset(this->array, 0, static_cast<size_t>(NumberOfDimensions) * sizeof(ComponentType));
133 }
134
136 explicit TVector(const ComponentType i)
137 : ParentClass()
138 {
139 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
140 this->array[d] = i;
141 }
142 }
143
144 // Even though the compiler should generate the copy constructor for us, gcc9+10 have a bug here, so implementation by
145 // hand again
147 : ParentClass()
148 {
149 *this = v2;
150 }
151
153 {
154 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
155 this->array[d] = v2.array[d];
156 }
157 return *this;
158 }
159
162 template <typename TVectorBase2> explicit TVector(const TVector<TVectorBase2>& v2)
163 : ParentClass()
164 {
165 VectorDimIdxType numDims = NumberOfDimensions;
166 if (v2.NumberOfDimensions < numDims) {
168 }
169 VectorDimIdxType d = 0;
170 for (; d < numDims; ++d) {
171 this->array[d] = static_cast<ComponentType>(v2.array[d]);
172 }
173 for (; d < NumberOfDimensions; ++d) {
174 this->array[d] = 0;
175 }
176 }
177
179 explicit TVector(const ComponentType xp, const TVector& p)
180 : ParentClass()
181 {
182 this->array[0] = xp;
183 for (VectorDimIdxType d = 1; d < NumberOfDimensions; ++d) {
184 this->array[d] = p.array[d];
185 }
186 }
187
191 explicit TVector(const MLint num, const ComponentType* const arr, const ComponentType deflt);
192
197 void copy(const MLint num, ComponentType* const arr) const;
198
200 void set(const ComponentType v = 0)
201 {
202 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
203 this->array[d] = v;
204 }
205 }
206
208 void set(const TVector& v)
209 {
210 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
211 this->array[d] = v.array[d];
212 }
213 }
215
216
217 //------------------------------------------------------
220 //------------------------------------------------------
221
224 {
225 return TVector<TVectorBase>(*this) += b;
226 }
229 {
230 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
231 this->array[d] += b.array[d];
232 }
233 return *this;
234 }
237 {
238 return TVector<TVectorBase>(*this) -= b;
239 }
242 {
243 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
244 this->array[d] -= b.array[d];
245 }
246 return *this;
247 }
250 {
251 return TVector<TVectorBase>(*this) *= b;
252 }
255 {
256 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
257 this->array[d] *= b.array[d];
258 }
259 return *this;
260 }
263 {
265 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
266 retVec.array[d] += b;
267 }
268 return retVec;
269 }
272 {
274 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
275 retVec.array[d] -= b;
276 }
277 return retVec;
278 }
281 {
283 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
284 retVec.array[d] *= b;
285 }
286 return retVec;
287 }
290 {
291 return TVector<TVectorBase>(*this) /= b;
292 }
295 {
296 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
297 ML_CHECK_THROW(b.array[d]);
298 this->array[d] /= b.array[d];
299 }
300 return *this;
301 }
304 bool operator==(const TVector<TVectorBase>& b) const
305 {
306 bool retFlag = true;
307 for (VectorDimIdxType d = 0; retFlag && (d < NumberOfDimensions); ++d) {
308 retFlag = retFlag && (this->array[d] == b.array[d]);
309 }
310 return retFlag;
311 }
314 bool operator!=(const TVector<TVectorBase>& b) const
315 {
316 return !(*this == b);
317 }
318
320 bool operator<(const TVector<TVectorBase>& b) const
321 {
322 bool retFlag = true;
323 for (VectorDimIdxType d = 0; retFlag && (d < NumberOfDimensions); ++d) {
324 retFlag = retFlag && (this->array[d] < b.array[d]);
325 }
326 return retFlag;
327 }
330 bool operator<=(const TVector<TVectorBase>& b) const
331 {
332 bool retFlag = true;
333 for (VectorDimIdxType d = 0; retFlag && (d < NumberOfDimensions); ++d) {
334 retFlag = retFlag && (this->array[d] <= b.array[d]);
335 }
336 return retFlag;
337 }
339 bool operator>(const TVector<TVectorBase>& b) const
340 {
341 bool retFlag = true;
342 for (VectorDimIdxType d = 0; retFlag && (d < NumberOfDimensions); ++d) {
343 retFlag = retFlag && (this->array[d] > b.array[d]);
344 }
345 return retFlag;
346 }
349 bool operator>=(const TVector<TVectorBase>& b) const
350 {
351 bool retFlag = true;
352 for (VectorDimIdxType d = 0; retFlag && (d < NumberOfDimensions); ++d) {
353 retFlag = retFlag && (this->array[d] >= b.array[d]);
354 }
355 return retFlag;
356 }
357
360 {
361 return TVector<TVectorBase>(*this) &= b;
362 }
365 {
366 return TVector<TVectorBase>(*this) |= b;
367 }
370 {
371 return TVector<TVectorBase>(*this) ^= b;
372 }
373
376 {
377 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
378 this->array[d] &= b.array[d];
379 }
380 return *this;
381 }
384 {
385 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
386 this->array[d] |= b.array[d];
387 }
388 return *this;
389 }
392 {
393 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
394 this->array[d] ^= b.array[d];
395 }
396 return *this;
397 }
398
401 {
402 return TVector<TVectorBase>(*this) &= b;
403 }
406 {
407 return TVector<TVectorBase>(*this) |= b;
408 }
411 {
412 return TVector<TVectorBase>(*this) ^= b;
413 }
414
417 {
418 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
419 this->array[d] &= b;
420 }
421 return *this;
422 }
425 {
426 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
427 this->array[d] |= b;
428 }
429 return *this;
430 }
433 {
434 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
435 this->array[d] ^= b;
436 }
437 return *this;
438 }
439
442 {
443 return TVector<TVectorBase>(*this) >>= b;
444 }
446 TVector<TVectorBase> operator<<(const int b) const
447 {
448 return TVector<TVectorBase>(*this) <<= b;
449 }
450
452 TVector<TVectorBase>& operator>>=(const int b)
453 {
454 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
455 this->array[d] >>= b;
456 }
457 return *this;
458 }
460 TVector<TVectorBase>& operator<<=(const int b)
461 {
462 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
463 this->array[d] <<= b;
464 }
465 return *this;
466 }
467
470 {
472 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
473 retVec.array[d] = -retVec.array[d];
474 }
475 return retVec;
476 }
477
481 // Note: No tracing! No try, No catch! Do nothing here that could degrade performance!
482 ComponentType operator[](const size_t i) const
483 {
484 return this->array[i];
485 }
486
490 // Note: No tracing! No try, No catch! Do nothing here that could degrade performance!
492 {
493 return this->array[i];
494 }
495
498 {
499 VectorDimIdxType idx = NumberOfDimensions - 1;
500 ComponentType val = this->array[idx];
501 for (VectorDimIdxType d = NumberOfDimensions - 2; d >= 0; d--) {
502 if (this->array[d] >= val) {
503 idx = d;
504 val = this->array[d];
505 }
506 }
507 return idx;
508 }
509
512 {
513 return this->array[getMaxIdx()];
514 }
515
518 {
519 VectorDimIdxType idx = NumberOfDimensions - 1;
520 ComponentType val = this->array[idx];
521 for (VectorDimIdxType d = NumberOfDimensions - 2; d >= 0; d--) {
522 if (this->array[d] <= val) {
523 idx = d;
524 val = this->array[d];
525 }
526 }
527 return idx;
528 }
529
532 {
533 return this->array[getMinIdx()];
534 }
535
542
550
554
556 bool hasNegativeComp() const
557 {
558 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
559 if (this->array[d] < 0) {
560 return true;
561 }
562 }
563 return false;
564 }
565
567 bool allBiggerZero() const
568 {
569 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
570 if (this->array[d] <= 0) {
571 return false;
572 }
573 }
574 return true;
575 }
576
579 {
580 double product = 1.0;
581 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
582 product *= static_cast<double>(this->array[d]);
583 }
585 }
587
588
589 //------------------------------------------------------
592 //------------------------------------------------------
593 // Methods:
597 {
598 return TVector<TVectorBase>::divCeil(*this, b);
599 }
602 {
603 return TVector<TVectorBase>::compMin(*this, b);
604 }
607 {
608 return TVector<TVectorBase>::compMax(*this, b);
609 }
613 {
614 return TVector<TVectorBase>::compMod(*this, b);
615 }
618 {
619 return TVector<TVectorBase>::compAbs(*this);
620 }
621
624 {
625 return TVector<TVectorBase>::compMul(*this);
626 }
629 {
630 return TVector<TVectorBase>::compSum(*this);
631 }
632
635 {
636 return TVector<TVectorBase>::dot(*this, b);
637 }
638
651
654 {
655 ComponentType retVal = a.array[0];
656 for (VectorDimIdxType d = 1; d < NumberOfDimensions; ++d) {
657 retVal *= a.array[d];
658 }
659 return retVal;
660 }
663 {
664 ComponentType retVal = a.array[0];
665 for (VectorDimIdxType d = 1; d < NumberOfDimensions; ++d) {
666 retVal += a.array[d];
667 }
668 return retVal;
669 }
670
671
674 {
675 ComponentType retVal = a.array[0] * b.array[0];
676 for (VectorDimIdxType d = 1; d < NumberOfDimensions; ++d) {
677 retVal += a.array[d] * b.array[d];
678 }
679 return retVal;
680 }
681
684 {
685 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
686 if (this->array[d] < threshold) {
687 this->array[d] = fillVal;
688 }
689 }
690 }
691
694 {
695 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
696 if (this->array[d] > threshold) {
697 this->array[d] = fillVal;
698 }
699 }
700 }
701
704 {
705 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
706 if (this->array[d] == threshold) {
707 this->array[d] = fillVal;
708 }
709 }
710 }
712
717 std::string print(const std::string& openStr = "", const std::string& sepStr = " ", const std::string& termStr = "",
718 const int numDigits = -1) const;
719};
720
722
723
724//-----------------------------------------------------------------------------------
725// Stream output for std::ostream
726//-----------------------------------------------------------------------------------
727namespace std
728{
729
732 template <class TVectorBase> ostream& operator<<(ostream& s, const ML_NAMESPACE::TVector<TVectorBase>& v)
733 {
734 s << "(";
735 for (ML_NAMESPACE::VectorDimIdxType d = 0; d < ML_NAMESPACE::TVector<TVectorBase>::NumberOfDimensions - 1; ++d) {
736 s << v.array[d] << ",";
737 }
738 s << v.array[ML_NAMESPACE::TVector<TVectorBase>::NumberOfDimensions - 1];
739 s << ")";
740 return s;
741 }
742
743} // namespace std
744
745
747
748
749//------------------------------------------------------
750// TVector<TVectorBase>
751//------------------------------------------------------
752// Constructor that initializes the vector components by copying them from
753// arr[0] ,..., arr[num-1]. All other elements are initialized to
754// the value \p deflt.
755template <class TVectorBase>
757 : ParentClass()
758{
760 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
761 this->array[d] = (num > d ? arr[d] : deflt);
762 }
763}
764
765// Copies the first \p num elements from internal array into \p arr,
766// starting with array[0] to arr[0] to array[num-1] to arr[num-1], respectively.
767// All other components are left unchanged.
768// \p arr must have at least \p num entries and at most NumberOfDimensions elements are copied.
769template <class TVectorBase> void TVector<TVectorBase>::copy(const MLint num, ComponentType* const arr) const
770{
772 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
773 if (num > d) {
774 arr[d] = this->array[d];
775 }
776 }
777}
778
779// Interprets vector as an image extent and returns a stride vector.
780// The smallest stride (the x stride) is set to offset, i.e., an
781// image voxel is assumed to have size = offset.
782// This way, stride.x = offset, stride.y = offset*x, stride.z = offset*x*y, ...,
783// stride.u=offset*x*y*z*c*t.
784template <class TVectorBase> TVector<TVectorBase> TVector<TVectorBase>::getStrides(const ComponentType offset) const
785{
787 stride.array[0] = offset;
788 for (VectorDimIdxType d = 1; d < NumberOfDimensions; ++d) {
789 stride.array[d] = stride.array[d - 1] * this->array[d - 1];
790 }
791 return stride;
792}
793
794// Interprets the vector as a stride vector of an image and returns the offset
795// position \p offsetPos from the image origin to the coordinate specified by
796// the vector. For offsetPos, an image with extents given by *this and the return
797// value rv then holds:
798// \code offsetPos = rv.x*x + rv.y*y + ... + rv.u*u \endcode )
800{
802 for (VectorDimIdxType d = NumberOfDimensions - 1; d >= 1; d--) {
803 ML_CHECK_THROW(this->array[d]);
804 vectorPos.array[d] = offsetPos / this->array[d];
805 offsetPos = offsetPos % this->array[d];
806 }
807 ML_CHECK_THROW(this->array[0]);
808 vectorPos.array[0] = offsetPos / this->array[0];
809
810 return vectorPos;
811}
812
813// Returns the highest vector component that is not 1. Useful to get the actual dimension of an image.
814template <class TVectorBase> MLint TVector<TVectorBase>::getExtDimension() const
815{
817 for (VectorDimIdxType d = NumberOfDimensions - 1; d >= 1; d--) {
818 if (1 != this->array[d]) {
819 dimen = d + 1;
820 break;
821 }
822 }
823 return dimen;
824}
825
826// Returns the component-wise division of the vector this by vector \p b with rounding up.
827// Division by zero caused by zero components of \p b must be avoided by caller.
828template <class TVectorBase>
830{
832 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
833 ML_CHECK_THROW(b.array[d]);
834 c.array[d] = static_cast<ComponentType>(ceil(static_cast<MLdouble>(a.array[d]) / b.array[d]));
835 }
836 return c;
837}
838
839
840// Returns the component-wise minimum of TVector<TVectorBase>s this and \p b.
841template <class TVectorBase>
843{
845 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
846 if (a.array[d] < c.array[d]) {
847 c.array[d] = a.array[d];
848 }
849 }
850 return c;
851}
852
853// Returns the component-wise maximum of vectors this and \p b.
854template <class TVectorBase>
856{
858 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
859 if (a.array[d] > c.array[d]) {
860 c.array[d] = a.array[d];
861 }
862 }
863 return c;
864}
865
866// Returns the rest dividing vector this a by \p b component-wise.
867// Division by zero caused by zero components of \p b must be avoided by caller and will
868// be handled as fatal error exception otherwise.
869template <class TVectorBase>
871{
873 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
874 ML_CHECK_THROW(b.array[d]);
875 c.array[d] = a.array[d] % b.array[d];
876 }
877 return c;
878}
879
880// Returns a vector with all components of a replaced by their absolute values.
882{
884 for (VectorDimIdxType d = 0; d < NumberOfDimensions; ++d) {
885 if (c.array[d] < 0) {
886 c.array[d] = -c.array[d];
887 }
888 }
889 return c;
890}
891
892// Returns the string openStr + v.x + sepStr + ... + v.t + sepStr + v.u + termStr.
893// \p numDigits is the number of digits to be used as print parameter.
894// If numDigits is <=0, then no space specification is used.
895template <class TVectorBase>
896std::string TVector<TVectorBase>::print(const std::string& openStr, const std::string& sepStr,
897 const std::string& termStr, const int numDigits) const
898{
899 std::string result = openStr;
900 // 512 chars are sufficient, because MLint64 or even in future MLint
901 // as 128 bit version does not use more than 2^128 digits, which are
902 // about 10^43.
903 char buf[512] = "";
904 for (VectorDimIdxType d = 0; d < NumberOfDimensions - 1; ++d) {
905 snprintf(buf, 511, "%*lld", numDigits, this->array[d]);
906 result += buf + sepStr;
907 }
908 snprintf(buf, 511, "%*lld", numDigits, this->array[NumberOfDimensions - 1]);
909 result += buf + termStr;
910 return result;
911}
912
914
915#endif // of __mlIntegerVector_H
Declaration of integer vector type traits.
TVectorNDBase()
Do not allow a direct creation of this class as object, as this container does not initialize itself.
CompIntType ComponentType
Integer type used by this vector.
ML integer image vector class to be specialized for different purposes.
bool operator>=(const TVector< TVectorBase > &b) const
'Greater or Equal' comparison operator, returns whether the 'greater or equal' relation is valid for ...
ComponentType getMax() const
Returns the maximum component value.
std::string print(const std::string &openStr="", const std::string &sepStr=" ", const std::string &termStr="", const int numDigits=-1) const
Returns the string openStr + v.array[0] + sepStr + ... + v.array[NumberOfDimensions-2] + sepStr + v....
TVector< TVectorBase > & operator+=(const TVector< TVectorBase > &b)
Adds the corresponding component from b to each component.
bool operator<(const TVector< TVectorBase > &b) const
'Less than' comparison operator, returns whether the 'less than' relation is valid for all components...
TVector< TVectorBase > & operator|=(const ComponentType b)
Performs a binary 'Or' of all components with an integer.
TVector< TVectorBase > & operator&=(const ComponentType b)
Performs a binary 'And' of all components with an integer.
TVector< TVectorBase > & operator*=(const TVector< TVectorBase > &b)
Multiplies each component with its corresponding components from b.
void set(const ComponentType v=0)
Sets all components to v or - if v is not specified - to 0.
static TVector< TVectorBase > compAbs(const TVector< TVectorBase > &a)
Static version: Returns a vector with all components of a replaced by their absolute values.
static ComponentType compMul(const TVector< TVectorBase > &a)
Static version: Returns the product of all components without checking for integer overflow.
bool operator>(const TVector< TVectorBase > &b) const
'Greater' comparison operator, returns whether the 'greater' relation is valid for all components.
TVector< TVectorBase > compMin(const TVector< TVectorBase > &b) const
Returns the component-wise minimum of components of this and b.
static TVector< TVectorBase > divCeil(const TVector< TVectorBase > &a, const TVector< TVectorBase > &b)
Static version: Returns the component-wise division of the vector a by vector b with rounding up.
TVector< TVectorBase > operator*(const ComponentType b) const
Multiplies all components with scalar b.
bool allBiggerZero() const
Returns whether all components > 0.
TVector< TVectorBase > operator+(const ComponentType b) const
Calculates and returns the addition of each component of *this with scalar b.
TVector< TVectorBase > operator|(const TVector< TVectorBase > &b) const
Performs a binary 'Or' of all components with the corresponding components of another vector.
MLint getMaxIdx() const
Searches the maximum component and returns the index of its first occurrence.
TVector< TVectorBase > operator-(const ComponentType b) const
Subtracts the scalar b from all components.
TVector< TVectorBase > operator*(const TVector< TVectorBase > &b) const
Calculates and returns the multiplication of each component of this with its corresponding component ...
void fillGreaterComps(const ComponentType threshold=0, const ComponentType fillVal=0)
Sets the components that are greater than threshold to fillVal.
TVector< TVectorBase > operator-() const
Performs an unary '-' on each vector component.
static TVector< TVectorBase > compMax(const TVector< TVectorBase > &a, const TVector< TVectorBase > &b)
Static version: Returns the component-wise maximum of vectors a and b.
TVector< TVectorBase > compMax(const TVector< TVectorBase > &b) const
Returns the component-wise maximum of components of this and b.
TVector< TVectorBase > operator^(const TVector< TVectorBase > &b) const
Performs a binary 'Xor' of all components with the corresponding components of another vector.
void set(const TVector &v)
Like assignment operator.
TVector< TVectorBase > & operator^=(const TVector< TVectorBase > &b)
Performs a binary 'Xor' of all components with the corresponding components of another vector.
bool hasNegativeComp() const
Returns whether any component is negative.
void fillEqualComps(const ComponentType threshold=0, const ComponentType fillVal=0)
Sets the components that are equal to threshold to fillVal.
TVector< TVectorBase > operator&(const TVector< TVectorBase > &b) const
Performs a binary 'And' of all components with the corresponding components of another vector.
TVector< TVectorBase > & operator-=(const TVector< TVectorBase > &b)
Subtracts the corresponding component from b from each component.
void fillSmallerComps(const ComponentType threshold=0, const ComponentType fillVal=0)
Sets the components that are smaller than threshold to fillVal.
TVector< TVectorBase > & operator=(const TVector< TVectorBase > &v2)
TVector< TVectorBase > getStrides(const ComponentType offset=1) const
Interprets the vector as image extension and returns a stride vector.
bool operator==(const TVector< TVectorBase > &b) const
Equality operator: Returns whether each component of this is equal to its corresponding component of ...
ComponentType dot(const TVector< TVectorBase > &b) const
Returns the scalar product of vectors this and b. There is no check for integer overflow.
TVector(const MLint num, const ComponentType *const arr, const ComponentType deflt)
Constructor that initializes the vector components by copying them from arr[0] ,.....
static ComponentType dot(const TVector< TVectorBase > &a, const TVector< TVectorBase > &b)
Static version: Returns the scalar product of vectors a and b without checking for integer overflow.
TVector< TVectorBase > compAbs() const
Returns a vector with all components of this replaced by their absolute values.
MLint getExtDimension() const
Returns the index to the highest vector component that is not 1.
TVectorBase ParentClass
Parent class of this class.
bool sanityCheckNumberOfVoxels() const
Returns whether the product of all components is in range of integer type.
TVector(const TVector< TVectorBase > &v2)
TVector(const ComponentType i)
Constructor that initializes all components to i.
TVector< TVectorBase > & operator|=(const TVector< TVectorBase > &b)
Performs a binary 'Or' of all components with the corresponding components of another vector.
TVector< TVectorBase > & operator&=(const TVector< TVectorBase > &b)
Performs a binary 'And' of all components with the corresponding components of another vector.
void copy(const MLint num, ComponentType *const arr) const
Copies the first num elements from internal array into arr, starting with array[0] to arr[0] to array...
MLint getMinIdx() const
Searches the minimum component and returns the index of its first occurrence.
TVector< TVectorBase > operator/(const TVector< TVectorBase > &b) const
Calculates and returns the division of each component of *this by its corresponding component from b.
TVector(const ComponentType xp, const TVector &p)
Constructor that assigns X to x and copies other elements from p.
TVector< TVectorBase > operator-(const TVector< TVectorBase > &b) const
Calculates and returns *this - b.
static TVector< TVectorBase > compMod(const TVector< TVectorBase > &a, const TVector< TVectorBase > &b)
Static version: Returns the rest dividing vector a by b component-wise.
ComponentType operator[](const size_t i) const
Constant indexing operator permits read access to array[0], ..., array[NumberOfDimensions-1] via inde...
TVector(const TVector< TVectorBase2 > &v2)
Copy constructor from another TVector of same or other integer type, values are cast.
TVectorBase::ComponentType ComponentType
Integer type used by this vector.
ComponentType compSum() const
Returns the sum of all components. There is no check for integer overflow.
TVector< TVectorBase > operator+(const TVector &b) const
Adds the corresponding component from b to each component.
TVector< TVectorBase > & operator^=(const ComponentType b)
Performs a binary 'Xor' of all components with an integer.
ComponentType getMin() const
Returns the minimum component value.
static ComponentType compSum(const TVector< TVectorBase > &a)
Static version: Returns the sum of all components without checking for integer overflow.
TVector< TVectorBase > operator&(const ComponentType b) const
Performs a binary 'And' of all components with an integer.
static TVector< TVectorBase > compMin(const TVector< TVectorBase > &a, const TVector< TVectorBase > &b)
Static version: Returns the component-wise minimum of vectors a and b.
TVector< TVectorBase > divCeil(const TVector< TVectorBase > &b) const
Returns the component-wise division of the vector this by vector b with rounding up.
TVector< TVectorBase > operator|(const ComponentType b) const
Performs a binary 'Or' of all components with an integer.
bool operator<=(const TVector< TVectorBase > &b) const
'Less than or equal' comparison operator, returns whether the 'Less than or equal' relation is valid ...
TVector< TVectorBase > compMod(const TVector< TVectorBase > &b) const
Returns the rest of the division of this by b component-wise.
TVector< TVectorBase > & operator/=(const TVector< TVectorBase > &b)
Divides each component by its corresponding component from b.
TVector< TVectorBase > operator^(const ComponentType b) const
Performs a binary 'Xor' of all components with an integer.
ComponentType compMul() const
Returns the product of all components. There is no check for integer overflow.
ComponentType & operator[](const size_t i)
Indexing operator permits read and write access to array[0], ..., array[NumberOfDimensions-1] via ind...
TVector()
Constructor. All components are initialized to 0.
bool operator!=(const TVector< TVectorBase > &b) const
Inequality operator: Returns whether any component differs from its corresponding component of b.
TVector< TVectorBase > getVectorPosition(ComponentType offsetPos) const
Interprets the vector as a stride vector of an image and returns the offset position offsetPos from t...
#define ML_CHECK_THROW(x)
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
double MLdouble
Definition mlTypeDefs.h:217
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
double ceil(T value)
std::ostream & operator<<(std::ostream &out, const ml::Variant &variant)
Definition mlVariant.h:231
std::istream & operator>>(std::istream &in, ml::Variant &variant)
Definition mlVariant.h:236
int VectorDimIdxType
Signed integer type used as count and index type to traverse the array of the TVector.
STL namespace.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator '<<' for stream output of Field objects.
Defines a template to get the minimum and maximum values for each basic integer type.