13 #ifndef ML_INTEGER_VECTOR_H
14 #define ML_INTEGER_VECTOR_H
37 template <
typename CompIntType, VectorDimIdxType NumDim>
46 enum { NumberOfDimensions = NumDim };
109 template<
class TVectorBase>
121 enum { NumberOfDimensions = ParentClass::NumberOfDimensions };
131 memset(this->array, 0,
static_cast<size_t>(NumberOfDimensions)*
sizeof(
ComponentType));
153 this->array[d] = v2.array[d];
160 template <
typename TVectorBase2>
169 for (; d < numDims; ++d)
173 for (; d < NumberOfDimensions; ++d)
183 for (
VectorDimIdxType d=1; d < NumberOfDimensions; ++d){ this->array[d] = p.array[d]; }
200 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ this->array[d]=v; }
206 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ this->array[d] = v.array[d]; }
224 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ this->array[d] += b.array[d]; }
235 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ this->array[d] -= b.array[d]; }
246 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ this->array[d] *= b.array[d]; }
253 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ retVec.array[d] += b; }
260 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ retVec.array[d] -= b; }
267 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ retVec.array[d] *= b; }
280 this->array[d] /= b.array[d];
289 for (
VectorDimIdxType d=0; retFlag && (d < NumberOfDimensions); ++d){ retFlag = retFlag && (this->array[d] == b.array[d]); }
296 return !(*
this == b);
303 for (
VectorDimIdxType d=0; retFlag && (d < NumberOfDimensions); ++d){ retFlag = retFlag && (this->array[d] < b.array[d]); }
310 for (
VectorDimIdxType d=0; retFlag && (d < NumberOfDimensions); ++d){ retFlag = retFlag && (this->array[d] <= b.array[d]); }
317 for (
VectorDimIdxType d=0; retFlag && (d < NumberOfDimensions); ++d){ retFlag = retFlag && (this->array[d] > b.array[d]); }
324 for (
VectorDimIdxType d=0; retFlag && (d < NumberOfDimensions); ++d){ retFlag = retFlag && (this->array[d] >= b.array[d]); }
347 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ this->array[d] &= b.array[d]; }
353 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ this->array[d] |= b.array[d]; }
359 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ this->array[d] ^= b.array[d]; }
382 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ this->array[d] &= b; }
388 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ this->array[d] |= b; }
394 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ this->array[d] ^= b; }
412 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ this->array[d] >>= b; }
418 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ this->array[d] <<= b; }
426 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ retVec.array[d] = -retVec.array[d]; }
448 if (this->array[d] >= val){ idx=d; val=this->array[d]; }
456 return this->array[getMaxIdx()];
465 if (this->array[d] <= val){ idx=d; val=this->array[d]; }
473 return this->array[getMinIdx()];
497 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){
if (this->array[d]<0){
return true; } }
504 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){
if (this->array[d]<=0){
return false; } }
555 retVal *= a.array[d];
565 retVal += a.array[d];
577 retVal += a.array[d]*b.array[d];
587 if (this->array[d] < threshold)
589 this->array[d] = fillVal;
597 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){
if (this->array[d] > threshold){ this->array[d] = fillVal; } }
603 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){
if (this->array[d] == threshold){ this->array[d] = fillVal; } }
610 std::string
print(
const std::string &openStr=
"",
611 const std::string &sepStr=
" ",
612 const std::string &termStr=
"",
613 const MLint16 numDigits=-1)
const;
627 template <
class TVectorBase>
628 ostream&
operator<<(ostream& s,
const ML_NAMESPACE::TVector<TVectorBase> &v){
631 s << v.array[ML_NAMESPACE::TVector<TVectorBase>::NumberOfDimensions-1];
649 template <
class TVectorBase>
660 template <
class TVectorBase>
664 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){
if (num>d){ arr[d] = this->array[d]; } }
672 template <
class TVectorBase>
676 stride.array[0] = offset;
677 for (
VectorDimIdxType d=1; d < NumberOfDimensions; ++d){ stride.array[d] = stride.array[d-1] * this->array[d-1]; }
686 template <
class TVectorBase>
692 vectorPos.array[d] = offsetPos / this->array[d];
693 offsetPos = offsetPos % this->array[d];
696 vectorPos.array[0] = offsetPos / this->array[0];
702 template <
class TVectorBase>
707 if (1 != this->array[d]){
717 template <
class TVectorBase>
730 template <
class TVectorBase>
735 if (a.array[d] < c.array[d]){ c.array[d] = a.array[d]; }
741 template <
class TVectorBase>
746 if (a.array[d] > c.array[d]){ c.array[d] = a.array[d]; }
754 template <
class TVectorBase>
760 c.array[d] = a.array[d] % b.array[d];
766 template <
class TVectorBase>
771 if (c.array[d]<0){ c.array[d] = -c.array[d]; }
779 template <
class TVectorBase>
781 const std::string &sepStr,
782 const std::string &termStr,
785 std::string result = openStr;
795 snprintf(frmt, 99,
"%%%dlld", numDigits);
798 snprintf(frmt, 99,
"%%lld");
805 snprintf(buf, 511, frmt, this->array[d]);
806 result += buf + sepStr;
808 snprintf(buf, 511, frmt, this->array[NumberOfDimensions-1]);
809 result += buf + termStr;
CompIntType ComponentType
Integer type used by this vector.
Declaration of integer vector type traits:
TVectorNDBase()
Do not allow a direct creation of this class as object, because this container does not initialize it...
CompIntType ComponentType
Integer type used by this vector.
ML integer image vector class to be specialized for different purposes.
ComponentType getMax() const
Returns the maximum component value.
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 check for integer overflow.
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.
bool allBiggerZero() const
Returns whether all components > 0.
MLint getMaxIdx() const
Searches the maximum component and returns the index of its first occurrence.
void fillGreaterComps(const ComponentType threshold=0, const ComponentType fillVal=0)
Sets the components which are greater than threshold to fillVal.
static TVector< TVectorBase > compMax(const TVector< TVectorBase > &a, const TVector< TVectorBase > &b)
Static version: Returns the component wise maximum of vectors a and b.
void set(const TVector &v)
Like assignment operator.
bool hasNegativeComp() const
Returns whether any component is negative.
TVector< TVectorBase > compMax(const TVector< TVectorBase > &b) const
Returns the component wise maximum of components of this and b.
void fillEqualComps(const ComponentType threshold=0, const ComponentType fillVal=0)
Sets the components which are equal to threshold to fillVal.
void fillSmallerComps(const ComponentType threshold=0, const ComponentType fillVal=0)
Sets the components which are smaller than threshold to fillVal.
TVector< TVectorBase > getStrides(const ComponentType offset=1) const
Interprets the vector as image extension and returns a stride vector.
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 > compMin(const TVector< TVectorBase > &b) const
Returns the component wise minimum of components of this and b.
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 which 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 check for integer overflow.
TVector< TVectorBase > & operator=(const TVector< TVectorBase > &v2)
MLint getExtDimension() const
Returns the index to the highest vector component which is not 1 which is useful to get the real dime...
TVectorBase ParentClass
Parent class of this class.
TVector(const TVector< TVectorBase > &v2)
std::string print(const std::string &openStr="", const std::string &sepStr=" ", const std::string &termStr="", const MLint16 numDigits=-1) const
Returns the string openStr + v.array[0] + sepStr + ...
TVector(const ComponentType i)
Constructor which initializes all components to i.
void copy(const MLint num, ComponentType *const arr) const
Copy the first num elements from internal array into arr starting with array[0] to arr[0] to array[nu...
MLint getMinIdx() const
Searches the minimum component and returns the index of its first occurrence.
TVector(const ComponentType xp, const TVector &p)
Constructor which assigns X to x and copies other elements from p.
ComponentType & operator[](const size_t i)
Indexing operator permits read and write access to array[0], ..., array[NumberOfDimensions-1] via ind...
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 > compAbs() const
Returns a vector with all components of this replaced by their absolute values.
ComponentType getMin() const
Returns the minimum component value.
static ComponentType compSum(const TVector< TVectorBase > &a)
Static version: Returns the sum of all components without check for integer overflow.
static TVector< TVectorBase > compMin(const TVector< TVectorBase > &a, const TVector< TVectorBase > &b)
Static version: Returns the component wise minimum of vectors a and b.
ComponentType compMul() const
Returns the product of all components. There is no check for integer overflow.
TVector< TVectorBase > compMod(const TVector< TVectorBase > &b) const
Returns the rest of the division of this by b component wise.
TVector()
Constructor. All components are initialized to 0.
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)
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator "<<" for stream output of Field objects.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
std::istream & operator>>(std::istream &in, ml::Variant &variant)
ScopeGuard< Functor > operator+(ScopeGuardOnExit, Functor &&fn)
FloatingPointVector< T, size, DataContainer > operator/(FloatingPointVector< T, size, DataContainer > lhs, MLdouble rhs)
Component wise division of lhs by specialized rhs of type MLdouble.
FloatingPointVector< T, size, DataContainer > compMax(FloatingPointVector< T, size, DataContainer > buffer1, const FloatingPointVector< T, size, DataContainer > &buffer2)
Component wise maximum of buffer1 and buffer2.
WEMBoundingBox MLWEM_EXPORT operator&(WEMBoundingBox x, const WEMBoundingBox &y)
Returns the united bounding box of x and y.
FloatingPointVector< T, size, DataContainer > & operator/=(FloatingPointVector< T, size, DataContainer > &op1, MLdouble value)
Arithmetic assignment: Component wise division of *this by scalar value.
FloatingPointVector< T, size, DataContainer > & operator-=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &buffer)
Arithmetic assignment: Component wise subtraction of buffer from *this.
int VectorDimIdxType
Signed integer type used as count and index type to traverse the array of the TVector.
bool operator==(const Tmat2< DT > &a, const Tmat2< DT > &b)
a == b ? Return true if yes.
T compMul(const FloatingPointVector< T, size, DataContainer > &vec)
Returns the product of all components.
T operator*(const FloatingPointVector< T, size, DataContainer > &a, const FloatingPointVector< T, size, DataContainer > &b)
Dot product, returns a.dot(b).
bool operator!=(const Tmat2< DT > &a, const Tmat2< DT > &b)
a != b ? Return true if yes.
Tvec3< DT > operator^(const Tvec3< DT > &a, const Tvec3< DT2 > &b)
Returns a vector orthogonal to a and b.
FloatingPointVector< T, size, DataContainer > compMin(FloatingPointVector< T, size, DataContainer > buffer1, const FloatingPointVector< T, size, DataContainer > &buffer2)
Component wise minimum of buffer1 and buffer2.
FloatingPointVector< T, size, DataContainer > & operator+=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &buffer)
Arithmetic assignment: Component wise addition.
FloatingPointVector< T, size, DataContainer > operator-(FloatingPointVector< T, size, DataContainer > lhs, const FloatingPointVector< T, size, DataContainer > &rhs)
Return value is the component wise subtraction of rhs from lhs.
FloatingPointVector< T, size, DataContainer > compAbs(FloatingPointVector< T, size, DataContainer > vec)
Returns a vector with all components from vec without negative sign.
FloatingPointVector< T, size, DataContainer > & operator*=(FloatingPointVector< T, size, DataContainer > &op1, MLdouble value)
Arithmetic assignment: Component wise multiplication *this with specialized MLdouble scalar value.