13#ifndef ML_INTEGER_VECTOR_H
14#define ML_INTEGER_VECTOR_H
38 template <
typename CompIntType, VectorDimIdxType NumDim>
110 template<
class TVectorBase>
154 this->
array[d] = v2.array[d];
161 template <
typename TVectorBase2>
167 numDims = v2.NumberOfDimensions;
170 for (; d < numDims; ++d)
281 this->
array[d] /= b.array[d];
297 return !(*
this == b);
419 for (
VectorDimIdxType d=0; d < NumberOfDimensions; ++d){ this->array[d] <<= b; }
449 if (this->
array[d] >= val){ idx=d; val=this->
array[d]; }
466 if (this->
array[d] <= val){ idx=d; val=this->
array[d]; }
512 double product = 1.0;
515 product *=
static_cast<double>(this->
array[d]);
567 retVal *= a.array[d];
577 retVal += a.array[d];
589 retVal += a.array[d]*b.array[d];
599 if (this->
array[d] < threshold)
601 this->
array[d] = fillVal;
622 std::string
print(
const std::string &openStr=
"",
623 const std::string &sepStr=
" ",
624 const std::string &termStr=
"",
625 const MLint16 numDigits=-1)
const;
639 template <
class TVectorBase>
640 ostream&
operator<<(ostream& s,
const ML_NAMESPACE::TVector<TVectorBase> &v){
642 for (ML_NAMESPACE::VectorDimIdxType d=0; d < ML_NAMESPACE::TVector<TVectorBase>::NumberOfDimensions-1; ++d){ s << v.array[d] <<
","; }
643 s << v.array[ML_NAMESPACE::TVector<TVectorBase>::NumberOfDimensions-1];
661 template <
class TVectorBase>
672 template <
class TVectorBase>
684 template <
class TVectorBase>
688 stride.array[0] = offset;
698 template <
class TVectorBase>
704 vectorPos.array[d] = offsetPos / this->array[d];
705 offsetPos = offsetPos % this->array[d];
708 vectorPos.array[0] = offsetPos / this->array[0];
714 template <
class TVectorBase>
719 if (1 != this->array[d]){
729 template <
class TVectorBase>
742 template <
class TVectorBase>
747 if (a.array[d] < c.array[d]){ c.array[d] = a.array[d]; }
753 template <
class TVectorBase>
758 if (a.array[d] > c.array[d]){ c.array[d] = a.array[d]; }
766 template <
class TVectorBase>
772 c.array[d] = a.array[d] % b.array[d];
778 template <
class TVectorBase>
783 if (c.array[d]<0){ c.array[d] = -c.array[d]; }
791 template <
class TVectorBase>
793 const std::string &sepStr,
794 const std::string &termStr,
797 std::string result = openStr;
807 snprintf(frmt, 99,
"%%%dlld", numDigits);
810 snprintf(frmt, 99,
"%%lld");
814 snprintf(buf, 511, frmt, this->array[d]);
815 result += buf + sepStr;
818 result += buf + termStr;
ComponentType array[NumberOfDimensions]
ComponentType array[NumberOfDimensions]
CompIntType ComponentType
Integer type used by this vector.
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 checking for integer overflow.
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)
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 that 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.
TVector< TVectorBase > compMax(const TVector< TVectorBase > &b) const
Returns the component-wise maximum of components of this and b.
void set(const TVector &v)
Like assignment operator.
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.
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
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)
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
TVector6DBase< CompIntType > ParentClass
bool sanityCheckNumberOfVoxels() const
Returns whether the product of all components is in range of integer type.
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
TVector(const ComponentType i)
Constructor that initializes all components to i.
void copy(const MLint num, ComponentType *const arr) const
MLint getMinIdx() const
Searches the minimum component and returns the index of its first occurrence.
TVector(const ComponentType xp, const TVector &p)
Constructor that assigns X to x and copies other elements from p.
static TVector< TVectorBase > compMod(const TVector< TVectorBase > &a, const TVector< TVectorBase > &b)
ComponentType operator[](const size_t i) const
TVector(const TVector< TVectorBase2 > &v2)
TVector6DBase< CompIntType >::ComponentType ComponentType
ComponentType compSum() const
Returns the sum of all components. There is no check for integer overflow.
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.
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
TVector< TVectorBase > compMod(const TVector< TVectorBase > &b) const
ComponentType compMul() const
Returns the product of all components. There is no check for integer overflow.
ComponentType & operator[](const size_t i)
TVector()
Constructor. All components are initialized to 0.
TVector< TVectorBase > getVectorPosition(ComponentType offsetPos) const
#define ML_CHECK_THROW(x)
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.