ML Reference
mlFloatingPointVector.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_FLOATING_POINT_VECTOR_H
14#define ML_FLOATING_POINT_VECTOR_H
15
17
18//------------------------------------------------------------------------
19// Includes
20//----------------------------------------------------------------------
22
23#include <mlTypeDefs.h>
24#include <mlTypeDefTraits.h>
25#include <iostream>
26
27//------------------------------------------------------------------------
29//------------------------------------------------------------------------
30typedef double (*ML_LA_FROM_DOUBLE_TO_DOUBLE)(double);
31
32//------------------------------------------------------------------------
33// Put all code in a specific ML_LA_NAMESPACE namespace to avoid
34// collisions with other libraries.
35//------------------------------------------------------------------------
36ML_LA_START_NAMESPACE
37
40template <class DT, size_t size>
42{
43protected:
44 DT _buffer[size];
45};
46
47
48//------------------------------------------------------------------------
60//------------------------------------------------------------------------
61template <class T, size_t size, class DataContainer = FloatingPointVectorDataContainerBase<T, size> >
62class FloatingPointVector : public DataContainer
63{
64
65public:
66
68 typedef T ComponentType;
69
72 enum { Size = size };
73
74 //----------------------------------------------------------------------
77 //----------------------------------------------------------------------
80 explicit FloatingPointVector(T value=T(0));
81
85
86
87 //----------------------------------------------------------------------
90 //----------------------------------------------------------------------
93
96
104 bool operator <(const FloatingPointVector<T, size, DataContainer>& buffer) const;
106
107
108 //----------------------------------------------------------------------
111 //----------------------------------------------------------------------
115 const T& operator[](const size_t i) const;
116
120 T& operator[](const size_t i);
122
123
124 //----------------------------------------------------------------------
127 //----------------------------------------------------------------------
129 size_t getSize() const;
130
133 T norm2() const;
134
138
142
146
148 T length() const;
149
152 {
153 return (*this - buffer).length();
154 }
155
158 {
159 return (*this - buffer).lengthSquared();
160 }
161
163 T lengthSquared() const;
164
166 T compSum() const;
167
169 T compMul() const;
170
172 T compMaxAbs() const;
173
176
179
181 void compAbs();
182
186
188 void compSqr();
189
192 void compSqrt();
193
197
201
209
211 void compRound();
212
214 void compFloor();
215
217 void compCeil();
218
221 {
223 r[0] = this->_buffer[1]*b._buffer[2] - this->_buffer[2]*b._buffer[1];
224 r[1] = this->_buffer[2]*b._buffer[0] - this->_buffer[0]*b._buffer[2];
225 r[2] = this->_buffer[0]*b._buffer[1] - this->_buffer[1]*b._buffer[0];
226 return r;
227 }
228
231
234 std::ostream& writeOut(std::ostream& os) const;
235
237 std::istream& readIn(std::istream& is);
239
240}; // end of class *FloatingPointVector*
241
242
243//-----------------------------------------------------------------------------------
246//-----------------------------------------------------------------------------------
247//-----------------------------------------------------------------------------------
250//-----------------------------------------------------------------------------------
251template <class T, size_t size, class DataContainer>
253{
254 for (size_t i=0; i<size; ++i){ op1[i] += buffer[i]; }
255 return op1;
256}
257
258//-----------------------------------------------------------------------------------
261//-----------------------------------------------------------------------------------
262template <class T, size_t size, class DataContainer>
264{
265 for (size_t i=0; i<size; ++i){ op1[i] -= buffer[i]; }
266 return op1;
267}
268
269//-----------------------------------------------------------------------------------
272//-----------------------------------------------------------------------------------
273template <class T, size_t size, class DataContainer>
275{
276 for (size_t i=0; i<size; ++i){ op1[i] *= static_cast<T>(value); }
277 return op1;
278}
279
280//-----------------------------------------------------------------------------------
283//-----------------------------------------------------------------------------------
284template <class T, size_t size, class DataContainer>
286{
287 for (size_t i=0; i<size; ++i){ op1[i] *= op2[i]; }
288 return op1;
289}
290
291//-----------------------------------------------------------------------------------
295//-----------------------------------------------------------------------------------
296template <class T, size_t size, class DataContainer>
298{
299 // The desired optimization by multiplying by 1.0/value we cannot do since some
300 // people simply use this class also for integer types although that's not really ok.
301 // We do not want to force bad errors for those people; so we spend the time here...
302 for (size_t i=0; i<size; ++i){ op1[i] /= static_cast<T>(value); }
303 return op1;
304}
305
306//-----------------------------------------------------------------------------------
310//-----------------------------------------------------------------------------------
311template <class T, size_t size, class DataContainer>
313{
314 // The desired optimization by multiplying by 1.0/value we cannot do since some
315 // people simply use this class also for integer types although that's not really ok.
316 // We do not want to force bad errors for those people; so we spend the time here...
317 for (size_t i=0; i<size; ++i){ op1[i] /= op2[i]; }
318 return op1;
319}
320
321//--------------------------------------------------------------------
324//--------------------------------------------------------------------
325template <class T, size_t size, class DataContainer>
327{
328 bool v = !a[0];
329 for (size_t c=1; c<size; c++){ v &= !a[c]; }
330 return v;
331}
332
333//-----------------------------------------------------------------------------------
336//-----------------------------------------------------------------------------------
337template <class T, size_t size, class DataContainer>
343
344//-----------------------------------------------------------------------------------
347//-----------------------------------------------------------------------------------
348template <class T, size_t size, class DataContainer>
354
355//-----------------------------------------------------------------------------------
358//-----------------------------------------------------------------------------------
359template <class T, size_t size, class DataContainer>
364
365
366//-----------------------------------------------------------------------------------
369//-----------------------------------------------------------------------------------
370template <class T, size_t size, class DataContainer>
372{
374 for (size_t i=0; i<size; ++i){ buf[i] *= -1; }
375 return buf;
376}
377
378//-----------------------------------------------------------------------------------
381//-----------------------------------------------------------------------------------
382template <class T, size_t size, class DataContainer>
387
388//-----------------------------------------------------------------------------------
391//-----------------------------------------------------------------------------------
392template <class T, size_t size, class DataContainer>
397
398//-----------------------------------------------------------------------------------
401//-----------------------------------------------------------------------------------
402template <class T, size_t size, class DataContainer>
407
408//-----------------------------------------------------------------------------------
411//-----------------------------------------------------------------------------------
412template <class T, size_t size, class DataContainer>
417
418//-----------------------------------------------------------------------------------
421//-----------------------------------------------------------------------------------
422template <class T, size_t size, class DataContainer>
429
430//-----------------------------------------------------------------------------------
433//-----------------------------------------------------------------------------------
434template <class T, size_t size, class DataContainer>
441
442//-----------------------------------------------------------------------------------
445//-----------------------------------------------------------------------------------
446template <class T, size_t size, class DataContainer>
452
453//-----------------------------------------------------------------------------------
456//-----------------------------------------------------------------------------------
457template <class T, size_t size, class DataContainer>
463
464
465//-----------------------------------------------------------------------------------
468//-----------------------------------------------------------------------------------
469template <class T, size_t size, class DataContainer>
475
476//-----------------------------------------------------------------------------------
480//-----------------------------------------------------------------------------------
481template <class T, size_t size, class DataContainer>
488
489//-----------------------------------------------------------------------------------
493//-----------------------------------------------------------------------------------
494template <class T, size_t size, class DataContainer>
501
502//-----------------------------------------------------------------------------------
506//-----------------------------------------------------------------------------------
507template <class T, size_t size, class DataContainer>
514
515//-----------------------------------------------------------------------------------
521//-----------------------------------------------------------------------------------
522template <class T, size_t size, class DataContainer>
531
532//-----------------------------------------------------------------------------------
535//-----------------------------------------------------------------------------------
536template <class T, size_t size, class DataContainer>
538{
539 return vec.compMul();
540}
542
543ML_LA_END_NAMESPACE
544
545//-----------------------------------------------------------------------------------
546// Some I/O stream operators are implemented in this namespace by this library.
547//-----------------------------------------------------------------------------------
548namespace std {
549
550 //-----------------------------------------------------------------------------------
552 //-----------------------------------------------------------------------------------
553 template <class T, size_t size, class DataContainer>
554 inline ostream& operator<<(ostream& os, const ML_LA_NAMESPACE::FloatingPointVector<T, size, DataContainer>& v)
555 {
556 return v.writeOut(os);
557 }
558
559 //-----------------------------------------------------------------------------------
561 //-----------------------------------------------------------------------------------
562 template <class T, size_t size, class DataContainer>
563 inline istream& operator>>(istream& is, ML_LA_NAMESPACE::FloatingPointVector<T, size, DataContainer>& v)
564 {
565 return v.readIn(is);
566 }
567
568}
569
570ML_LA_START_NAMESPACE
571
572//-----------------------------------------------------------------------------------
573//
574// IMPLEMENTATION.
575//
576//-----------------------------------------------------------------------------------
577
578//-----------------------------------------------------------------------------------
579// Constructors and assignment operators.
580//-----------------------------------------------------------------------------------
581//-----------------------------------------------------------------------------------
582// Default and value constructor. Default is the initialization of all
583// components with a \p value whose default is 0.
584//-----------------------------------------------------------------------------------
585template <class T, size_t size, class DataContainer>
587{
588 for (size_t i=0; i<size; ++i){ this->_buffer[i] = value; }
589}
590
591//-----------------------------------------------------------------------------------
592// Assignment of scalar value to all components.
593//-----------------------------------------------------------------------------------
594template <class T, size_t size, class DataContainer>
596{
597 for (size_t i=0; i<size; ++i){ this->_buffer[i] = value; }
598 return *this;
599}
600
601
602//----------------------------------------------------------------------
603// Comparison.
604//----------------------------------------------------------------------
605//-----------------------------------------------------------------------------------
606// Returns whether *this and buffer are component-wise equal.
607//-----------------------------------------------------------------------------------
608template <class T, size_t size, class DataContainer>
610{
611 for (size_t i=0; i<size; ++i){
612 // Use the numerically better method (although slower to compare) floats to ensure that
613 // insignificant differences after least significant mantissa bit are not considered as
614 // difference.
615 if (MLValuesDifferWOM(this->_buffer[i], buffer._buffer[i])){ return false; }
616 }
617 return true;
618}
619
620//-----------------------------------------------------------------------------------
621// Returns whether any components of *this and \p buffer are not equal.
622//-----------------------------------------------------------------------------------
623template <class T, size_t size, class DataContainer>
625{
626 for (size_t i=0; i<size; ++i){
627 // Use the numerically better method (although slower to compare) floats to ensure that
628 // insignificant differences after least significant mantissa bit are not considered as
629 // difference.
630 if (MLValuesDifferWOM(this->_buffer[i], buffer._buffer[i])){ return true; }
631 }
632 return false;
633}
634
635//-----------------------------------------------------------------------------------
636// Defines an artificial order for use in sort algorithms (lexicographical
637// order). Starting from the first component (i.e., index 0), all components
638// from *this are compared with the corresponding one in buffer:
639// If the components of *this are smaller than the corresponding on in
640// buffer, then \c true is returned. If the comparison is greater, then
641// \c false is returned. On equality, the components for the next index are
642// compared. If all components are equal, then \c false is returned.
643//-----------------------------------------------------------------------------------
644template <class T, size_t size, class DataContainer>
646{
647 for (size_t i=0; i<size; ++i) {
648 if (MLValuesDifferWOM(this->_buffer[i], buffer._buffer[i])){ return (this->_buffer[i]<buffer._buffer[i]); }
649 }
650 return false;
651}
652
653
654
655
656
657//-----------------------------------------------------------------------------------
658// Value access and indexing operators.
659//-----------------------------------------------------------------------------------
660//-----------------------------------------------------------------------------------
661// Constant indexing operators. The caller must guarantee that is in [0, size-1].
662// It is legal to consider all elements as a subsequent array in memory for
663// pointer addressing of all elements.
664//-----------------------------------------------------------------------------------
665template <class T, size_t size, class DataContainer>
667{
668 return this->_buffer[i];
669}
670
671//-----------------------------------------------------------------------------------
672// Indexing operator. The caller must guarantee that is in [0, size-1].
673// It is legal to consider all elements as a subsequent array in memory for
674// pointer addressing of all elements.
675//-----------------------------------------------------------------------------------
676template <class T, size_t size, class DataContainer>
678{
679 return this->_buffer[i];
680}
681
682
683
684
685
686
687
688
689//----------------------------------------------------------------------
690// Other operations.
691//----------------------------------------------------------------------
692//-----------------------------------------------------------------------------------
693// Returns the number of elements of value buffer.
694//-----------------------------------------------------------------------------------
695template <class T, size_t size, class DataContainer>
697{
698 return size;
699}
700
701//-----------------------------------------------------------------------------------
702// Returns the Euclidean norm (the vector length), i.e., square root of sum
703// of squares of all components.
704//-----------------------------------------------------------------------------------
705template <class T, size_t size, class DataContainer>
707{
708 T norm = 0;
709 for (size_t i=0; i<size; ++i){ norm += this->_buffer[i]*this->_buffer[i]; }
710#ifdef WIN32
711 return static_cast<T>(sqrt(norm));
712#else
713 return static_cast<T>(::sqrt(norm));
714#endif
715}
716
717//-----------------------------------------------------------------------------------
718// Returns the weighted Euclidean norm, i.e., square root of sum of squares of all
719// components multiplied with corresponding squared component of weight.
720//-----------------------------------------------------------------------------------
721template <class T, size_t size, class DataContainer>
723{
724 T norm = 0;
725 for (size_t i=0; i<size; ++i){
726 norm += this->_buffer[i]*this->_buffer[i] * weight._buffer[i]*weight._buffer[i];
727 }
728#ifdef WIN32
729 return sqrt(norm);
730#else
731 return ::sqrt(norm);
732#endif
733}
734
735
736//-----------------------------------------------------------------------------------
737// Returns the dot product, i.e., sum of all components multiplied with corresponding
738// components of buffer.
739//-----------------------------------------------------------------------------------
740template <class T, size_t size, class DataContainer>
742{
743 T sum = 0;
744 for (size_t i=0; i<size; ++i){ sum += this->_buffer[i]*buffer._buffer[i]; }
745 return sum;
746}
747
748//-----------------------------------------------------------------------------------
749// Normalizes buffer and returns the Euclidean length of vector before normalization,
750// i.e., norm2. On zero vector length, the vector is left unchanged.
751//-----------------------------------------------------------------------------------
752template <class T, size_t size, class DataContainer>
754{
755 T norm = norm2();
756
757 if (!MLValueIs0WOM(norm)) {
758 T inv_norm = static_cast<T>(1.0/norm);
759 for (size_t i=0; i<size; ++i){ this->_buffer[i] *= inv_norm; }
760 }
761
762 return norm;
763}
764
765//-----------------------------------------------------------------------------------
766// Returns the length of the vector, i.e., norm2().
767//-----------------------------------------------------------------------------------
768template <class T, size_t size, class DataContainer>
770{
771 return norm2();
772}
773
774//-----------------------------------------------------------------------------------
775// Returns the squared length of vector.
776//-----------------------------------------------------------------------------------
777template <class T, size_t size, class DataContainer>
779{
780 return dot(*this);
781}
782
783//-----------------------------------------------------------------------------------
784// Returns the sum of all components.
785//-----------------------------------------------------------------------------------
786template <class T, size_t size, class DataContainer>
788{
789 T retVal=this->_buffer[0];
790 for (size_t i=1; i<size; ++i){ retVal += this->_buffer[i]; }
791 return retVal;
792}
793
794//-----------------------------------------------------------------------------------
795// Returns the product of all vector components.
796//-----------------------------------------------------------------------------------
797template <class T, size_t size, class DataContainer>
799{
800 T retVal=this->_buffer[0];
801 for (size_t i=1; i<size; ++i){ retVal *= this->_buffer[i]; }
802 return retVal;
803}
804
805//-----------------------------------------------------------------------------------
806// Returns the maximum of absolute component values.
807//-----------------------------------------------------------------------------------
808template <class T, size_t size, class DataContainer>
810{
811 size_t i = 0;
812 T m = static_cast<T>( MLAbs(this->_buffer[i++]));
813 T n = 0;
814 for (; i<size; ++i){ m = (n = static_cast<T>( MLAbs(this->_buffer[i])) ) > m ? n : m; }
815 return m;
816}
817
818//-----------------------------------------------------------------------------------
819// Sets the component-wise minimum of *this and \p buffer in *this.
820//-----------------------------------------------------------------------------------
821template <class T, size_t size, class DataContainer>
823{
824 for (size_t i=0; i<size; ++i){
825 this->_buffer[i] = this->_buffer[i] < buffer._buffer[i] ? this->_buffer[i] : buffer._buffer[i];
826 }
827}
828
829//-----------------------------------------------------------------------------------
830// Sets the component-wise maximum of *this and \p buffer in *this.
831//-----------------------------------------------------------------------------------
832template <class T, size_t size, class DataContainer>
834{
835 for (size_t i=0; i<size; ++i){
836 this->_buffer[i] = this->_buffer[i] < buffer._buffer[i] ? buffer._buffer[i] :this->_buffer[i];
837 }
838}
839
840//-----------------------------------------------------------------------------------
841// Removes negative signs from all components.
842//-----------------------------------------------------------------------------------
843template <class T, size_t size, class DataContainer>
845{
846 for (size_t i=0; i<size; ++i){ this->_buffer[i] = static_cast<T>( MLAbs(this->_buffer[i])); }
847}
848
849//-----------------------------------------------------------------------------------
850// Divides each vector component by the corresponding one of \p d.
851// Divisions by zero are not handled; the caller must avoid them.
852//-----------------------------------------------------------------------------------
853template <class T, size_t size, class DataContainer>
855{
856 for (size_t i=0; i<size; ++i){ this->_buffer[i] /= d._buffer[i]; }
857}
858
859//-----------------------------------------------------------------------------------
860// Calculates and sets the square of all components.
861//-----------------------------------------------------------------------------------
862template <class T, size_t size, class DataContainer>
864{
865 for (size_t i=0; i<size; ++i){ this->_buffer[i] *= this->_buffer[i]; }
866}
867
868//-----------------------------------------------------------------------------------
869// Calculates and sets the square root of all components.
870// Negative values have to be avoided by caller.
871//-----------------------------------------------------------------------------------
872template <class T, size_t size, class DataContainer>
874{
875 for (size_t i=0; i<size; ++i){
876#ifdef WIN32
877 this->_buffer[i] = static_cast<T>( sqrt(this->_buffer[i]));
878#else
879 this->_buffer[i] = static_cast<T>(::sqrt(this->_buffer[i]));
880#endif
881 }
882}
883
884//-----------------------------------------------------------------------------------
885// Calculates and sets all components clamped to \p lower, i.e., if any component is
886// smaller than the corresponding one in \p lower, then it is set to the one from \p lower.
887//-----------------------------------------------------------------------------------
888template <class T, size_t size, class DataContainer>
893
894//-----------------------------------------------------------------------------------
895// Calculates and sets all components clamped to \p upper, i.e., if any component is
896// greater than the corresponding one in \p upper, then it is set to the one from \p upper.
897//-----------------------------------------------------------------------------------
898template <class T, size_t size, class DataContainer>
903
904//-----------------------------------------------------------------------------------
905// Calculates and sets all components of *this so that they are between minimum
906// \p lower and maximum \p upper. This is done by applying clampMin(lower) first
907// and then clampMax(upper). Note that components can become smaller than
908// \p lower if a component in \p upper is smaller than their corresponding one in
909// in \p lower.
910//-----------------------------------------------------------------------------------
911template <class T, size_t size, class DataContainer>
914{
915 // Make copy to avoid self modification if lower or upper is equal to *this.
917 buf.clampMin(lower);
918 buf.clampMax(upper);
919 *this = buf;
920}
921
922//-----------------------------------------------------------------------------------
923// Rounds all components of this vector using floor(component + 0.5).
924//-----------------------------------------------------------------------------------
925template <class T, size_t size, class DataContainer>
927{
928 for (size_t i=0; i<size; ++i){ this->_buffer[i] = std::floor(this->_buffer[i] + static_cast<T>(0.5)); }
929}
930
931//-----------------------------------------------------------------------------------
932// Rounds all components of this vector using floor(component).
933//-----------------------------------------------------------------------------------
934template <class T, size_t size, class DataContainer>
936{
937 for (size_t i=0; i<size; ++i){ this->_buffer[i] = std::floor(this->_buffer[i]); }
938}
939
940//-----------------------------------------------------------------------------------
941// Rounds all components of this vector to integer using ceil(component).
942//-----------------------------------------------------------------------------------
943template <class T, size_t size, class DataContainer>
945{
946 for (size_t i=0; i<size; ++i){ this->_buffer[i] = std::ceil(this->_buffer[i]); }
947}
948
949//-----------------------------------------------------------------------------------
950// Applies function \p f to each component starting from index 0 to index size-1.
951//-----------------------------------------------------------------------------------
952template <class T, size_t size, class DataContainer>
954{
955 for (size_t i=0; i<size; ++i){ this->_buffer[i] = f(this->_buffer[i]); }
956}
957
958//-----------------------------------------------------------------------------------
959// Writes all components to ostream \p os starting from index 0 to size-1.
960// Each buffer elements is followed separated by a space symbols " ".
961//-----------------------------------------------------------------------------------
962template <class T, size_t size, class DataContainer>
963inline std::ostream& FloatingPointVector<T, size, DataContainer>::writeOut(std::ostream& os) const
964{
965 for (size_t i=0; i<size; ++i){ os << this->_buffer[i] << " "; }
966 return os;
967}
968
969//-----------------------------------------------------------------------------------
970// Reads all components from istream \p is starting starting from index 0 to size-1.
971//-----------------------------------------------------------------------------------
972template <class T, size_t size, class DataContainer>
973inline std::istream& FloatingPointVector<T, size, DataContainer>::readIn(std::istream& is)
974{
975 for (size_t i=0; i<size; ++i){ is >> this->_buffer[i]; }
976 return is;
977}
978
979ML_LA_END_NAMESPACE
980
981
982#endif
983
984
985
Base class of the FloatingPointVector class that holds the data buffer.
Template class for vector arithmetic with floating point datatypes.
FloatingPointVector(T value=T(0))
Default and value constructor.
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 lower and maximum upper.
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].
FloatingPointVector< T, 3, DataContainer > cross(const FloatingPointVector< T, 3, DataContainer > &b) const
Returns the cross product for elements, i.e., the returned vector is orthogonal to *this and b.
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, it returns false.
DT MLAbs(const DT val)
Defines a templated MLAbs version to circumvent fabs ambiguities on different platforms.
bool MLValuesDifferWOM(MLint8 a, MLint8 b)
Returns true if values differ; otherwise, it returns false.
double(* ML_LA_FROM_DOUBLE_TO_DOUBLE)(double)
Template base class for floating point vectors.
double MLdouble
Definition mlTypeDefs.h:217
FloatingPointVector< T, size, DataContainer > compMax(FloatingPointVector< T, size, DataContainer > buffer1, const FloatingPointVector< T, size, DataContainer > &buffer2)
Component-wise maximum of buffer1 and buffer2.
constexpr Is< T > is(T d)
FloatingPointVector< T, size, DataContainer > compMin(FloatingPointVector< T, size, DataContainer > buffer1, const FloatingPointVector< T, size, DataContainer > &buffer2)
Component-wise minimum of buffer1 and buffer2.
STL namespace.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator '<<' for stream output of Field objects.
istream & operator>>(istream &is, ml::FloatingPointVector< T, size, DataContainer > &v)
Reads a vector from std::istream.