13#ifndef ML_INTEGER_VECTOR_H
14#define ML_INTEGER_VECTOR_H
38template <
typename CompIntType, VectorDimIdxType NumDim>
class TVectorNDBase
46 NumberOfDimensions =
NumDim
109template <
class TVectorBase>
class TVector :
public TVectorBase
120 NumberOfDimensions = ParentClass::NumberOfDimensions
155 this->array[d] = v2.array[d];
173 for (; d < NumberOfDimensions; ++d) {
184 this->array[d] = p.array[d];
211 this->array[d] = v.array[d];
231 this->array[d] += b.array[d];
244 this->array[d] -= b.array[d];
257 this->array[d] *= b.array[d];
298 this->array[d] /= b.array[d];
316 return !(*
this == b);
378 this->array[d] &= b.array[d];
386 this->array[d] |= b.array[d];
394 this->array[d] ^= b.array[d];
455 this->array[d] >>= b;
463 this->array[d] <<= b;
484 return this->array[
i];
493 return this->array[
i];
502 if (this->array[d] >= val) {
504 val = this->array[d];
513 return this->array[getMaxIdx()];
522 if (this->array[d] <= val) {
524 val = this->array[d];
533 return this->array[getMinIdx()];
559 if (this->array[d] < 0) {
570 if (this->array[d] <= 0) {
582 product *=
static_cast<double>(this->array[d]);
677 retVal += a.array[d] * b.array[d];
732 template <
class TVectorBase> ostream&
operator<<(ostream& s,
const ML_NAMESPACE::TVector<TVectorBase>& v)
736 s << v.array[d] <<
",";
738 s << v.array[ML_NAMESPACE::TVector<TVectorBase>::NumberOfDimensions - 1];
755template <
class TVectorBase>
761 this->array[d] = (num > d ?
arr[d] :
deflt);
774 arr[d] = this->array[d];
787 stride.array[0] = offset;
789 stride.array[d] = stride.array[d - 1] * this->array[d - 1];
818 if (1 != this->array[d]) {
828template <
class TVectorBase>
841template <
class TVectorBase>
846 if (a.array[d] < c.array[d]) {
847 c.array[d] = a.array[d];
854template <
class TVectorBase>
859 if (a.array[d] > c.array[d]) {
860 c.array[d] = a.array[d];
869template <
class TVectorBase>
875 c.array[d] = a.array[d] % b.array[d];
885 if (c.array[d] < 0) {
886 c.array[d] = -c.array[d];
895template <
class TVectorBase>
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.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
std::ostream & operator<<(std::ostream &out, const ml::Variant &variant)
std::istream & operator>>(std::istream &in, ml::Variant &variant)
int VectorDimIdxType
Signed integer type used as count and index type to traverse the array of the TVector.
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.