13 #ifndef ML_FLOATING_POINT_VECTOR_H
14 #define ML_FLOATING_POINT_VECTOR_H
40 template <
class DT,
size_t size>
61 template <
class T,
size_t size,
class DataContainer = FloatingPo
intVectorDataContainerBase<T, size> >
153 return (*
this - buffer).length();
159 return (*
this - buffer).lengthSquared();
164 #if ML_DEPRECATED_SINCE(3,5,0)
177 inline ML_DEPRECATED T Distance(
const FloatingPointVector<T, size, DataContainer>& buffer)
const
179 return distance(buffer);
183 inline ML_DEPRECATED T DistanceSquared(
const FloatingPointVector<T, size, DataContainer>& buffer)
const
185 return distanceSquared(buffer);
189 inline ML_DEPRECATED T Dot(
const FloatingPointVector<T, size, DataContainer>& b)
const
195 inline ML_DEPRECATED T length2()
const {
return lengthSquared(); }
198 inline ML_DEPRECATED T LengthSquared()
const {
return lengthSquared(); }
202 inline ML_DEPRECATED FloatingPointVector<T, 3, DataContainer> Cross(
const FloatingPointVector<T, 3, DataContainer>& b)
const
270 r[0] = this->_buffer[1]*b.
_buffer[2] - this->_buffer[2]*b.
_buffer[1];
271 r[1] = this->_buffer[2]*b.
_buffer[0] - this->_buffer[0]*b.
_buffer[2];
272 r[2] = this->_buffer[0]*b.
_buffer[1] - this->_buffer[1]*b.
_buffer[0];
298 template <
class T,
size_t size,
class DataContainer>
301 for (
size_t i=0; i<size; ++i){ op1[i] += buffer[i]; }
309 template <
class T,
size_t size,
class DataContainer>
312 for (
size_t i=0; i<size; ++i){ op1[i] -= buffer[i]; }
320 template <
class T,
size_t size,
class DataContainer>
323 for (
size_t i=0; i<size; ++i){ op1[i] *=
static_cast<T>(value); }
331 template <
class T,
size_t size,
class DataContainer>
334 for (
size_t i=0; i<size; ++i){ op1[i] *= op2[i]; }
343 template <
class T,
size_t size,
class DataContainer>
349 for (
size_t i=0; i<size; ++i){ op1[i] /=
static_cast<T>(value); }
358 template <
class T,
size_t size,
class DataContainer>
364 for (
size_t i=0; i<size; ++i){ op1[i] /= op2[i]; }
372 template <
class T,
size_t size,
class DataContainer>
376 for (
size_t c=1; c<size; c++){ v &= !a[c]; }
384 template <
class T,
size_t size,
class DataContainer>
395 template <
class T,
size_t size,
class DataContainer>
406 template <
class T,
size_t size,
class DataContainer>
417 template <
class T,
size_t size,
class DataContainer>
421 for (
size_t i=0; i<size; ++i){ buf[i] *= -1; }
429 template <
class T,
size_t size,
class DataContainer>
439 template <
class T,
size_t size,
class DataContainer>
442 return lhs *=
static_cast<T>(rhs);
449 template <
class T,
size_t size,
class DataContainer>
452 return rhs *=
static_cast<T>(lhs);
459 template <
class T,
size_t size,
class DataContainer>
462 return lhs /=
static_cast<T>(rhs);
469 template <
class T,
size_t size,
class DataContainer>
481 template <
class T,
size_t size,
class DataContainer>
493 template <
class T,
size_t size,
class DataContainer>
504 template <
class T,
size_t size,
class DataContainer>
516 template <
class T,
size_t size,
class DataContainer>
528 template <
class T,
size_t size,
class DataContainer>
541 template <
class T,
size_t size,
class DataContainer>
554 template <
class T,
size_t size,
class DataContainer>
569 template <
class T,
size_t size,
class DataContainer>
583 template <
class T,
size_t size,
class DataContainer>
600 template <
class T,
size_t size,
class DataContainer>
601 inline ostream&
operator<<(ostream& os,
const ML_LA_NAMESPACE::FloatingPointVector<T, size, DataContainer>& v)
603 return v.writeOut(os);
609 template <
class T,
size_t size,
class DataContainer>
610 inline istream&
operator>>(istream&
is, ML_LA_NAMESPACE::FloatingPointVector<T, size, DataContainer>& v)
617 ML_LA_START_NAMESPACE
632 template <
class T,
size_t size,
class DataContainer>
635 for (
size_t i=0; i<size; ++i){ this->_buffer[i] = value; }
641 template <
class T,
size_t size,
class DataContainer>
644 for (
size_t i=0; i<size; ++i){ this->_buffer[i] = value; }
655 template <
class T,
size_t size,
class DataContainer>
658 for (
size_t i=0; i<size; ++i){
670 template <
class T,
size_t size,
class DataContainer>
673 for (
size_t i=0; i<size; ++i){
691 template <
class T,
size_t size,
class DataContainer>
694 for (
size_t i=0; i<size; ++i) {
712 template <
class T,
size_t size,
class DataContainer>
715 return this->_buffer[i];
723 template <
class T,
size_t size,
class DataContainer>
726 return this->_buffer[i];
742 template <
class T,
size_t size,
class DataContainer>
752 template <
class T,
size_t size,
class DataContainer>
756 for (
size_t i=0; i<size; ++i){ norm += this->_buffer[i]*this->_buffer[i]; }
758 return static_cast<T>(sqrt(norm));
760 return static_cast<T>(::sqrt(norm));
768 template <
class T,
size_t size,
class DataContainer>
772 for (
size_t i=0; i<size; ++i){
773 norm += this->_buffer[i]*this->_buffer[i] * weight.
_buffer[i]*weight.
_buffer[i];
787 template <
class T,
size_t size,
class DataContainer>
791 for (
size_t i=0; i<size; ++i){ sum += this->_buffer[i]*buffer.
_buffer[i]; }
799 template <
class T,
size_t size,
class DataContainer>
805 T inv_norm =
static_cast<T>(1.0/norm);
806 for (
size_t i=0; i<size; ++i){ this->_buffer[i] *= inv_norm; }
815 template <
class T,
size_t size,
class DataContainer>
824 template <
class T,
size_t size,
class DataContainer>
833 template <
class T,
size_t size,
class DataContainer>
836 T retVal=this->_buffer[0];
837 for (
size_t i=1; i<size; ++i){ retVal += this->_buffer[i]; }
844 template <
class T,
size_t size,
class DataContainer>
847 T retVal=this->_buffer[0];
848 for (
size_t i=1; i<size; ++i){ retVal *= this->_buffer[i]; }
855 template <
class T,
size_t size,
class DataContainer>
859 T m =
static_cast<T>(
MLAbs(this->_buffer[i++]));
861 for (; i<size; ++i){ m = (n =
static_cast<T>(
MLAbs(this->_buffer[i])) ) > m ? n : m; }
868 template <
class T,
size_t size,
class DataContainer>
871 for (
size_t i=0; i<size; ++i){
872 this->_buffer[i] = this->_buffer[i] < buffer.
_buffer[i] ? this->_buffer[i] : buffer.
_buffer[i];
879 template <
class T,
size_t size,
class DataContainer>
882 for (
size_t i=0; i<size; ++i){
883 this->_buffer[i] = this->_buffer[i] < buffer.
_buffer[i] ? buffer.
_buffer[i] :this->_buffer[i];
890 template <
class T,
size_t size,
class DataContainer>
893 for (
size_t i=0; i<size; ++i){ this->_buffer[i] =
static_cast<T>(
MLAbs(this->_buffer[i])); }
900 template <
class T,
size_t size,
class DataContainer>
903 for (
size_t i=0; i<size; ++i){ this->_buffer[i] /= d.
_buffer[i]; }
909 template <
class T,
size_t size,
class DataContainer>
912 for (
size_t i=0; i<size; ++i){ this->_buffer[i] *= this->_buffer[i]; }
919 template <
class T,
size_t size,
class DataContainer>
922 for (
size_t i=0; i<size; ++i){
924 this->_buffer[i] =
static_cast<T>( sqrt(this->_buffer[i]));
926 this->_buffer[i] =
static_cast<T>(::sqrt(this->_buffer[i]));
935 template <
class T,
size_t size,
class DataContainer>
945 template <
class T,
size_t size,
class DataContainer>
958 template <
class T,
size_t size,
class DataContainer>
972 template <
class T,
size_t size,
class DataContainer>
975 for (
size_t i=0; i<size; ++i){ this->_buffer[i] = std::floor(this->_buffer[i] +
static_cast<T>(0.5)); }
981 template <
class T,
size_t size,
class DataContainer>
984 for (
size_t i=0; i<size; ++i){ this->_buffer[i] = std::floor(this->_buffer[i]); }
990 template <
class T,
size_t size,
class DataContainer>
993 for (
size_t i=0; i<size; ++i){ this->_buffer[i] = std::ceil(this->_buffer[i]); }
999 template <
class T,
size_t size,
class DataContainer>
1002 for (
size_t i=0; i<size; ++i){ this->_buffer[i] = f(this->_buffer[i]); }
1009 template <
class T,
size_t size,
class DataContainer>
1012 for (
size_t i=0; i<size; ++i){ os << this->_buffer[i] <<
" "; }
1019 template <
class T,
size_t size,
class DataContainer>
1022 for (
size_t i=0; i<size; ++i){
is >> this->_buffer[i]; }
1026 #if ML_DEPRECATED_SINCE(3,5,0)
1031 #define ScalarVectorTemplate FloatingPointVector
1033 #if defined(WIN32) && !defined(ML_NO_DEPRECATED_WARNINGS)
1034 #pragma deprecated("ScalarVectorTemplate")
Base class of the FloatingPointVector class which holds the data buffer.
Template class for vector arithmetic with floating point data types.
FloatingPointVector(T value=T(0))
Default and value constructor.
FloatingPointVector< T, 3, DataContainer > cross(const FloatingPointVector< T, 3, DataContainer > &b) const
Returns the cross product for elements, i.e., return vector vertical to *this and b.
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 > & operator/=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &op2)
Arithmetic assignment: Component wise division of *this by the values of a vector of the same size.
FloatingPointVector< T, size, DataContainer > operator*(FloatingPointVector< T, size, DataContainer > lhs, MLdouble rhs)
Component wise multiplication of lhs with rhs.
std::ostream & writeOut(std::ostream &os) const
Writes all components to ostream os starting from index 0 to size-1.
FloatingPointVector< T, size, DataContainer > compMax(FloatingPointVector< T, size, DataContainer > buffer1, const FloatingPointVector< T, size, DataContainer > &buffer2)
Component wise maximum of buffer1 and buffer2.
void clampMax(const FloatingPointVector< T, size, DataContainer > &upper)
Calculates and sets all components clamped to upper, i.e., if any component is greater than the corre...
void compMin(FloatingPointVector< T, size, DataContainer > buffer)
Sets the component wise minimum of *this and buffer in *this.
T & operator[](const size_t i)
Indexing operators.
FloatingPointVector< T, size, DataContainer > & operator*=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &op2)
Arithmetic assignment: Component wise multiplication *this with a vector of the same size.
T length() const
Returns the length of the vector, i.e. norm2().
void clamp(const FloatingPointVector< T, size, DataContainer > &lower, const FloatingPointVector< T, size, DataContainer > &upper)
Calculates and sets all components of *this so that they are between minimum min and maximum max.
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+(const FloatingPointVector< T, size, DataContainer > &buffer)
Unary plus, for completeness and for those who really want to use that...
bool operator==(const FloatingPointVector< T, size, DataContainer > &buffer) const
Returns whether *this and buffer are component wise equal.
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.
void compMax(FloatingPointVector< T, size, DataContainer > buffer)
Sets the component wise maximum of *this and buffer in *this.
FloatingPointVector< T, size, DataContainer > clamp(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &lower, const FloatingPointVector< T, size, DataContainer > &upper)
Returns a new vector with all components from vec clamped to range [lower, upper].
T normalize()
Normalizes the buffer and returns the Euclidean length of vector before normalization,...
void compAbs()
Kills negative signs from all components.
const T & operator[](const size_t i) const
Constant indexing operators.
T distance(const FloatingPointVector< T, size, DataContainer > &buffer) const
Returns the distance of this vector to a given one.
T compMaxAbs() const
Returns the maximum of absolute component values.
void compFloor()
Rounds all components of this vector using floor(component).
void compDiv(const FloatingPointVector< T, size, DataContainer > &d)
Divides each vector component by the corresponding one of d.
T compMul() const
Returns the product of all vector components.
bool operator!(const FloatingPointVector< T, size, DataContainer > &a)
Returns whether all components are 0.
FloatingPointVector< T, size, DataContainer > & operator=(T value)
Assignment of scalar value to all components.
T compMul(const FloatingPointVector< T, size, DataContainer > &vec)
Returns the product of all components.
FloatingPointVector< T, size, DataContainer > clampMax(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &m)
Returns a new vector with all components from vec clamped to maximum m.
FloatingPointVector< T, size, DataContainer > compSqrt(FloatingPointVector< T, size, DataContainer > vec)
Returns a vector with all components from vec square-rooted.
FloatingPointVector< T, size, DataContainer > compSqr(FloatingPointVector< T, size, DataContainer > vec)
Returns a vector with all components from vec squared.
T operator*(const FloatingPointVector< T, size, DataContainer > &a, const FloatingPointVector< T, size, DataContainer > &b)
Dot product, returns a.dot(b).
void compRound()
Rounds all components of this vector using floor(component + 0.5).
T norm2(const FloatingPointVector< T, size, DataContainer > &weight) const
Returns the weighted Euclidean norm, i.e., square root of sum of squares of all components multiplied...
T dot(const FloatingPointVector< T, size, DataContainer > &buffer) const
Returns the dot product, i.e., sum of all components multiplied with corresponding components of buff...
void compSqr()
Calculates and sets the square of all components.
bool operator!=(const FloatingPointVector< T, size, DataContainer > &buffer) const
Returns whether any components of *this and buffer are not equal.
T norm2() const
Returns the Euclidean norm (the vector length), i.e., square root of sum of squares of all components...
T compSum() const
Returns the sum of all components.
FloatingPointVector< T, size, DataContainer > operator+(FloatingPointVector< T, size, DataContainer > lhs, const FloatingPointVector< T, size, DataContainer > &rhs)
Return value is the component wise addition of lhs and rhs.
std::istream & readIn(std::istream &is)
Reads all components from istream is starting starting from index 0 to size-1.
FloatingPointVector< T, size, DataContainer > compMin(FloatingPointVector< T, size, DataContainer > buffer1, const FloatingPointVector< T, size, DataContainer > &buffer2)
Component wise minimum of buffer1 and buffer2.
void compCeil()
Rounds all components of this vector to integer using ceil(component).
size_t getSize() const
Returns the number of elements of value buffer.
void clampMin(const FloatingPointVector< T, size, DataContainer > &lower)
Calculates and sets all components clamped to lower, i.e., if any component is smaller than the corre...
void compSqrt()
Calculates and sets square root of all components.
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 > operator*(MLdouble lhs, FloatingPointVector< T, size, DataContainer > rhs)
Component wise multiplication of rhs with lhs.
FloatingPointVector< T, size, DataContainer > compAbs(FloatingPointVector< T, size, DataContainer > vec)
Returns a vector with all components from vec without negative sign.
T distanceSquared(const FloatingPointVector< T, size, DataContainer > &buffer) const
Returns the squared distance of this vector to a given one.
void apply(ML_LA_FROM_DOUBLE_TO_DOUBLE f)
Applies the function f to each component starting from index 0 to index size-1.
FloatingPointVector< T, size, DataContainer > & operator*=(FloatingPointVector< T, size, DataContainer > &op1, MLdouble value)
Arithmetic assignment: Component wise multiplication *this with specialized MLdouble scalar value.
FloatingPointVector< T, size, DataContainer > operator-(const FloatingPointVector< T, size, DataContainer > &buffer)
Unary minus, all components of the vector are multiplied with -1.
T ComponentType
A typedef to "export" the type of components.
FloatingPointVector< T, size, DataContainer > clampMin(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &m)
Returns a new vector with all components from vec clamped to minimum m.
T lengthSquared() const
Returns the squared length of the vector.
FloatingPointVector< T, size, DataContainer > compDiv(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &d)
Component wise division of vec / d.
bool MLValueIs0WOM(MLint8 a)
Returns true if value is 0, otherwise false.
DT MLAbs(const DT val)
Defines templated MLAbs version to circumvent fabs ambiguities on different platforms.
bool MLValuesDifferWOM(MLint8 a, MLint8 b)
Returns true if values differ, otherwise false.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator "<<" for stream output of Field objects.
double(* ML_LA_FROM_DOUBLE_TO_DOUBLE)(double)
Template base class for floating point vectors.
std::istream & operator>>(std::istream &in, ml::Variant &variant)
void apply(Fnc &&fnc, const std::tuple< Args... > &tuple)
FloatingPointVector< T, size, DataContainer > compMax(FloatingPointVector< T, size, DataContainer > buffer1, const FloatingPointVector< T, size, DataContainer > &buffer2)
Component wise maximum of buffer1 and buffer2.
FloatingPointVector< T, size, DataContainer > clamp(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &lower, const FloatingPointVector< T, size, DataContainer > &upper)
Returns a new vector with all components from vec clamped to range [lower, upper].
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.
FloatingPointVector< T, size, DataContainer > clampMax(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &m)
Returns a new vector with all components from vec clamped to maximum m.
FloatingPointVector< T, size, DataContainer > compSqrt(FloatingPointVector< T, size, DataContainer > vec)
Returns a vector with all components from vec square-rooted.
FloatingPointVector< T, size, DataContainer > compSqr(FloatingPointVector< T, size, DataContainer > vec)
Returns a vector with all components from vec squared.
bool operator!=(const Tmat2< DT > &a, const Tmat2< DT > &b)
a != b ? Return true if yes.
FloatingPointVector< T, size, DataContainer > compMin(FloatingPointVector< T, size, DataContainer > buffer1, const FloatingPointVector< T, size, DataContainer > &buffer2)
Component wise minimum of buffer1 and buffer2.
constexpr Is< T > is(T d)
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 > clampMin(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &m)
Returns a new vector with all components from vec clamped to minimum m.
FloatingPointVector< T, size, DataContainer > compDiv(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &d)
Component wise division of vec / d.