MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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//------------------------------------------------------------------------
31
32//------------------------------------------------------------------------
33// Put all code in a specific ML_LA_NAMESPACE namespace to avoid
34// collisions with other libraries.
35//------------------------------------------------------------------------
37
40template <class DT, size_t size> class FloatingPointVectorDataContainerBase
41{
42protected:
43 DT _buffer[size];
44};
45
46
47//------------------------------------------------------------------------
59//------------------------------------------------------------------------
60template <class T, size_t size, class DataContainer = FloatingPointVectorDataContainerBase<T, size>>
62{
63
64public:
67
70 enum {
71 Size = size
72 };
73
74 //----------------------------------------------------------------------
77 //----------------------------------------------------------------------
80 explicit FloatingPointVector(T value = T(0));
81
85
86
87 //----------------------------------------------------------------------
90 //----------------------------------------------------------------------
93
96
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
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> inline FloatingPointVector<T, size, DataContainer>&
253{
254 for (size_t i = 0; i < size; ++i) {
255 op1[i] += buffer[i];
256 }
257 return op1;
258}
259
260//-----------------------------------------------------------------------------------
263//-----------------------------------------------------------------------------------
264template <class T, size_t size, class DataContainer> inline FloatingPointVector<T, size, DataContainer>&
266{
267 for (size_t i = 0; i < size; ++i) {
268 op1[i] -= buffer[i];
269 }
270 return op1;
271}
272
273//-----------------------------------------------------------------------------------
276//-----------------------------------------------------------------------------------
277template <class T, size_t size, class DataContainer>
279 MLdouble value)
280{
281 for (size_t i = 0; i < size; ++i) {
282 op1[i] *= static_cast<T>(value);
283 }
284 return op1;
285}
286
287//-----------------------------------------------------------------------------------
290//-----------------------------------------------------------------------------------
291template <class T, size_t size, class DataContainer>
300
301//-----------------------------------------------------------------------------------
305//-----------------------------------------------------------------------------------
306template <class T, size_t size, class DataContainer>
308 MLdouble value)
309{
310 // The desired optimization by multiplying by 1.0/value we cannot do since some
311 // people simply use this class also for integer types although that's not really ok.
312 // We do not want to force bad errors for those people; so we spend the time here...
313 for (size_t i = 0; i < size; ++i) {
314 op1[i] /= static_cast<T>(value);
315 }
316 return op1;
317}
318
319//-----------------------------------------------------------------------------------
323//-----------------------------------------------------------------------------------
324template <class T, size_t size, class DataContainer>
327{
328 // The desired optimization by multiplying by 1.0/value we cannot do since some
329 // people simply use this class also for integer types although that's not really ok.
330 // We do not want to force bad errors for those people; so we spend the time here...
331 for (size_t i = 0; i < size; ++i) {
332 op1[i] /= op2[i];
333 }
334 return op1;
335}
336
337//--------------------------------------------------------------------
340//--------------------------------------------------------------------
341template <class T, size_t size, class DataContainer>
343{
344 bool v = !a[0];
345 for (size_t c = 1; c < size; c++) {
346 v &= !a[c];
347 }
348 return v;
349}
350
351//-----------------------------------------------------------------------------------
354//-----------------------------------------------------------------------------------
355template <class T, size_t size, class DataContainer>
361
362//-----------------------------------------------------------------------------------
365//-----------------------------------------------------------------------------------
366template <class T, size_t size, class DataContainer>
372
373//-----------------------------------------------------------------------------------
376//-----------------------------------------------------------------------------------
377template <class T, size_t size, class DataContainer>
382
383
384//-----------------------------------------------------------------------------------
387//-----------------------------------------------------------------------------------
388template <class T, size_t size, class DataContainer>
397
398//-----------------------------------------------------------------------------------
401//-----------------------------------------------------------------------------------
402template <class T, size_t size, class DataContainer>
408
409//-----------------------------------------------------------------------------------
412//-----------------------------------------------------------------------------------
413template <class T, size_t size, class DataContainer>
419
420//-----------------------------------------------------------------------------------
423//-----------------------------------------------------------------------------------
424template <class T, size_t size, class DataContainer>
430
431//-----------------------------------------------------------------------------------
434//-----------------------------------------------------------------------------------
435template <class T, size_t size, class DataContainer>
441
442//-----------------------------------------------------------------------------------
445//-----------------------------------------------------------------------------------
446template <class T, size_t size, class DataContainer>
453
454//-----------------------------------------------------------------------------------
457//-----------------------------------------------------------------------------------
458template <class T, size_t size, class DataContainer>
465
466//-----------------------------------------------------------------------------------
469//-----------------------------------------------------------------------------------
470template <class T, size_t size, class DataContainer>
476
477//-----------------------------------------------------------------------------------
480//-----------------------------------------------------------------------------------
481template <class T, size_t size, class DataContainer>
487
488
489//-----------------------------------------------------------------------------------
492//-----------------------------------------------------------------------------------
493template <class T, size_t size, class DataContainer>
499
500//-----------------------------------------------------------------------------------
504//-----------------------------------------------------------------------------------
505template <class T, size_t size, class DataContainer>
512
513//-----------------------------------------------------------------------------------
517//-----------------------------------------------------------------------------------
518template <class T, size_t size, class DataContainer>
525
526//-----------------------------------------------------------------------------------
530//-----------------------------------------------------------------------------------
531template <class T, size_t size, class DataContainer>
538
539//-----------------------------------------------------------------------------------
545//-----------------------------------------------------------------------------------
546template <class T, size_t size, class DataContainer>
555
556//-----------------------------------------------------------------------------------
559//-----------------------------------------------------------------------------------
560template <class T, size_t size, class DataContainer>
562{
563 return vec.compMul();
564}
566
568
569//-----------------------------------------------------------------------------------
570// Some I/O stream operators are implemented in this namespace by this library.
571//-----------------------------------------------------------------------------------
572namespace std
573{
574
575 //-----------------------------------------------------------------------------------
577 //-----------------------------------------------------------------------------------
578 template <class T, size_t size, class DataContainer>
579 inline ostream& operator<<(ostream& os, const ML_LA_NAMESPACE::FloatingPointVector<T, size, DataContainer>& v)
580 {
581 return v.writeOut(os);
582 }
583
584 //-----------------------------------------------------------------------------------
586 //-----------------------------------------------------------------------------------
587 template <class T, size_t size, class DataContainer>
588 inline istream& operator>>(istream& is, ML_LA_NAMESPACE::FloatingPointVector<T, size, DataContainer>& v)
589 {
590 return v.readIn(is);
591 }
592
593} // namespace std
594
596
597//-----------------------------------------------------------------------------------
598//
599// IMPLEMENTATION.
600//
601//-----------------------------------------------------------------------------------
602
603//-----------------------------------------------------------------------------------
604// Constructors and assignment operators.
605//-----------------------------------------------------------------------------------
606//-----------------------------------------------------------------------------------
607// Default and value constructor. Default is the initialization of all
608// components with a \p value whose default is 0.
609//-----------------------------------------------------------------------------------
610template <class T, size_t size, class DataContainer>
612{
613 for (size_t i = 0; i < size; ++i) {
614 this->_buffer[i] = value;
615 }
616}
617
618//-----------------------------------------------------------------------------------
619// Assignment of scalar value to all components.
620//-----------------------------------------------------------------------------------
621template <class T, size_t size, class DataContainer>
623{
624 for (size_t i = 0; i < size; ++i) {
625 this->_buffer[i] = value;
626 }
627 return *this;
628}
629
630
631//----------------------------------------------------------------------
632// Comparison.
633//----------------------------------------------------------------------
634//-----------------------------------------------------------------------------------
635// Returns whether *this and buffer are component-wise equal.
636//-----------------------------------------------------------------------------------
637template <class T, size_t size, class DataContainer> inline bool
639{
640 for (size_t i = 0; i < size; ++i) {
641 // Use the numerically better method (although slower to compare) floats to ensure that
642 // insignificant differences after least significant mantissa bit are not considered as
643 // difference.
644 if (MLValuesDifferWOM(this->_buffer[i], buffer._buffer[i])) {
645 return false;
646 }
647 }
648 return true;
649}
650
651//-----------------------------------------------------------------------------------
652// Returns whether any components of *this and \p buffer are not equal.
653//-----------------------------------------------------------------------------------
654template <class T, size_t size, class DataContainer> inline bool
656{
657 for (size_t i = 0; i < size; ++i) {
658 // Use the numerically better method (although slower to compare) floats to ensure that
659 // insignificant differences after least significant mantissa bit are not considered as
660 // difference.
661 if (MLValuesDifferWOM(this->_buffer[i], buffer._buffer[i])) {
662 return true;
663 }
664 }
665 return false;
666}
667
668//-----------------------------------------------------------------------------------
669// Defines an artificial order for use in sort algorithms (lexicographical
670// order). Starting from the first component (i.e., index 0), all components
671// from *this are compared with the corresponding one in buffer:
672// If the components of *this are smaller than the corresponding on in
673// buffer, then \c true is returned. If the comparison is greater, then
674// \c false is returned. On equality, the components for the next index are
675// compared. If all components are equal, then \c false is returned.
676//-----------------------------------------------------------------------------------
677template <class T, size_t size, class DataContainer> inline bool
679{
680 for (size_t i = 0; i < size; ++i) {
681 if (MLValuesDifferWOM(this->_buffer[i], buffer._buffer[i])) {
682 return (this->_buffer[i] < buffer._buffer[i]);
683 }
684 }
685 return false;
686}
687
688
689//-----------------------------------------------------------------------------------
690// Value access and indexing operators.
691//-----------------------------------------------------------------------------------
692//-----------------------------------------------------------------------------------
693// Constant indexing operators. The caller must guarantee that is in [0, size-1].
694// It is legal to consider all elements as a subsequent array in memory for
695// pointer addressing of all elements.
696//-----------------------------------------------------------------------------------
697template <class T, size_t size, class DataContainer>
699{
700 return this->_buffer[i];
701}
702
703//-----------------------------------------------------------------------------------
704// Indexing operator. The caller must guarantee that is in [0, size-1].
705// It is legal to consider all elements as a subsequent array in memory for
706// pointer addressing of all elements.
707//-----------------------------------------------------------------------------------
708template <class T, size_t size, class DataContainer>
710{
711 return this->_buffer[i];
712}
713
714
715//----------------------------------------------------------------------
716// Other operations.
717//----------------------------------------------------------------------
718//-----------------------------------------------------------------------------------
719// Returns the number of elements of value buffer.
720//-----------------------------------------------------------------------------------
721template <class T, size_t size, class DataContainer>
723{
724 return size;
725}
726
727//-----------------------------------------------------------------------------------
728// Returns the Euclidean norm (the vector length), i.e., square root of sum
729// of squares of all components.
730//-----------------------------------------------------------------------------------
731template <class T, size_t size, class DataContainer> inline T FloatingPointVector<T, size, DataContainer>::norm2() const
732{
733 T norm = 0;
734 for (size_t i = 0; i < size; ++i) {
735 norm += this->_buffer[i] * this->_buffer[i];
736 }
737#ifdef WIN32
738 return static_cast<T>(sqrt(norm));
739#else
740 return static_cast<T>(::sqrt(norm));
741#endif
742}
743
744//-----------------------------------------------------------------------------------
745// Returns the weighted Euclidean norm, i.e., square root of sum of squares of all
746// components multiplied with corresponding squared component of weight.
747//-----------------------------------------------------------------------------------
748template <class T, size_t size, class DataContainer> inline T
750{
751 T norm = 0;
752 for (size_t i = 0; i < size; ++i) {
753 norm += this->_buffer[i] * this->_buffer[i] * weight._buffer[i] * weight._buffer[i];
754 }
755#ifdef WIN32
756 return sqrt(norm);
757#else
758 return ::sqrt(norm);
759#endif
760}
761
762
763//-----------------------------------------------------------------------------------
764// Returns the dot product, i.e., sum of all components multiplied with corresponding
765// components of buffer.
766//-----------------------------------------------------------------------------------
767template <class T, size_t size, class DataContainer> inline T
769{
770 T sum = 0;
771 for (size_t i = 0; i < size; ++i) {
772 sum += this->_buffer[i] * buffer._buffer[i];
773 }
774 return sum;
775}
776
777//-----------------------------------------------------------------------------------
778// Normalizes buffer and returns the Euclidean length of vector before normalization,
779// i.e., norm2. On zero vector length, the vector is left unchanged.
780//-----------------------------------------------------------------------------------
781template <class T, size_t size, class DataContainer> inline T FloatingPointVector<T, size, DataContainer>::normalize()
782{
783 T norm = norm2();
784
785 if (!MLValueIs0WOM(norm)) {
786 T inv_norm = static_cast<T>(1.0 / norm);
787 for (size_t i = 0; i < size; ++i) {
788 this->_buffer[i] *= inv_norm;
789 }
790 }
791
792 return norm;
793}
794
795//-----------------------------------------------------------------------------------
796// Returns the length of the vector, i.e., norm2().
797//-----------------------------------------------------------------------------------
798template <class T, size_t size, class DataContainer>
800{
801 return norm2();
802}
803
804//-----------------------------------------------------------------------------------
805// Returns the squared length of vector.
806//-----------------------------------------------------------------------------------
807template <class T, size_t size, class DataContainer>
809{
810 return dot(*this);
811}
812
813//-----------------------------------------------------------------------------------
814// Returns the sum of all components.
815//-----------------------------------------------------------------------------------
816template <class T, size_t size, class DataContainer>
818{
819 T retVal = this->_buffer[0];
820 for (size_t i = 1; i < size; ++i) {
821 retVal += this->_buffer[i];
822 }
823 return retVal;
824}
825
826//-----------------------------------------------------------------------------------
827// Returns the product of all vector components.
828//-----------------------------------------------------------------------------------
829template <class T, size_t size, class DataContainer>
831{
832 T retVal = this->_buffer[0];
833 for (size_t i = 1; i < size; ++i) {
834 retVal *= this->_buffer[i];
835 }
836 return retVal;
837}
838
839//-----------------------------------------------------------------------------------
840// Returns the maximum of absolute component values.
841//-----------------------------------------------------------------------------------
842template <class T, size_t size, class DataContainer>
844{
845 size_t i = 0;
846 T m = static_cast<T>(MLAbs(this->_buffer[i++]));
847 T n = 0;
848 for (; i < size; ++i) {
849 m = (n = static_cast<T>(MLAbs(this->_buffer[i]))) > m ? n : m;
850 }
851 return m;
852}
853
854//-----------------------------------------------------------------------------------
855// Sets the component-wise minimum of *this and \p buffer in *this.
856//-----------------------------------------------------------------------------------
857template <class T, size_t size, class DataContainer>
859{
860 for (size_t i = 0; i < size; ++i) {
861 this->_buffer[i] = this->_buffer[i] < buffer._buffer[i] ? this->_buffer[i] : buffer._buffer[i];
862 }
863}
864
865//-----------------------------------------------------------------------------------
866// Sets the component-wise maximum of *this and \p buffer in *this.
867//-----------------------------------------------------------------------------------
868template <class T, size_t size, class DataContainer>
870{
871 for (size_t i = 0; i < size; ++i) {
872 this->_buffer[i] = this->_buffer[i] < buffer._buffer[i] ? buffer._buffer[i] : this->_buffer[i];
873 }
874}
875
876//-----------------------------------------------------------------------------------
877// Removes negative signs from all components.
878//-----------------------------------------------------------------------------------
879template <class T, size_t size, class DataContainer> inline void FloatingPointVector<T, size, DataContainer>::compAbs()
880{
881 for (size_t i = 0; i < size; ++i) {
882 this->_buffer[i] = static_cast<T>(MLAbs(this->_buffer[i]));
883 }
884}
885
886//-----------------------------------------------------------------------------------
887// Divides each vector component by the corresponding one of \p d.
888// Divisions by zero are not handled; the caller must avoid them.
889//-----------------------------------------------------------------------------------
890template <class T, size_t size, class DataContainer>
892{
893 for (size_t i = 0; i < size; ++i) {
894 this->_buffer[i] /= d._buffer[i];
895 }
896}
897
898//-----------------------------------------------------------------------------------
899// Calculates and sets the square of all components.
900//-----------------------------------------------------------------------------------
901template <class T, size_t size, class DataContainer> inline void FloatingPointVector<T, size, DataContainer>::compSqr()
902{
903 for (size_t i = 0; i < size; ++i) {
904 this->_buffer[i] *= this->_buffer[i];
905 }
906}
907
908//-----------------------------------------------------------------------------------
909// Calculates and sets the square root of all components.
910// Negative values have to be avoided by caller.
911//-----------------------------------------------------------------------------------
912template <class T, size_t size, class DataContainer> inline void FloatingPointVector<T, size, DataContainer>::compSqrt()
913{
914 for (size_t i = 0; i < size; ++i) {
915#ifdef WIN32
916 this->_buffer[i] = static_cast<T>(sqrt(this->_buffer[i]));
917#else
918 this->_buffer[i] = static_cast<T>(::sqrt(this->_buffer[i]));
919#endif
920 }
921}
922
923//-----------------------------------------------------------------------------------
924// Calculates and sets all components clamped to \p lower, i.e., if any component is
925// smaller than the corresponding one in \p lower, then it is set to the one from \p lower.
926//-----------------------------------------------------------------------------------
927template <class T, size_t size, class DataContainer> inline void
932
933//-----------------------------------------------------------------------------------
934// Calculates and sets all components clamped to \p upper, i.e., if any component is
935// greater than the corresponding one in \p upper, then it is set to the one from \p upper.
936//-----------------------------------------------------------------------------------
937template <class T, size_t size, class DataContainer> inline void
942
943//-----------------------------------------------------------------------------------
944// Calculates and sets all components of *this so that they are between minimum
945// \p lower and maximum \p upper. This is done by applying clampMin(lower) first
946// and then clampMax(upper). Note that components can become smaller than
947// \p lower if a component in \p upper is smaller than their corresponding one in
948// in \p lower.
949//-----------------------------------------------------------------------------------
950template <class T, size_t size, class DataContainer>
953{
954 // Make copy to avoid self modification if lower or upper is equal to *this.
956 buf.clampMin(lower);
957 buf.clampMax(upper);
958 *this = buf;
959}
960
961//-----------------------------------------------------------------------------------
962// Rounds all components of this vector using floor(component + 0.5).
963//-----------------------------------------------------------------------------------
964template <class T, size_t size, class DataContainer>
966{
967 for (size_t i = 0; i < size; ++i) {
968 this->_buffer[i] = std::floor(this->_buffer[i] + static_cast<T>(0.5));
969 }
970}
971
972//-----------------------------------------------------------------------------------
973// Rounds all components of this vector using floor(component).
974//-----------------------------------------------------------------------------------
975template <class T, size_t size, class DataContainer>
977{
978 for (size_t i = 0; i < size; ++i) {
979 this->_buffer[i] = std::floor(this->_buffer[i]);
980 }
981}
982
983//-----------------------------------------------------------------------------------
984// Rounds all components of this vector to integer using ceil(component).
985//-----------------------------------------------------------------------------------
986template <class T, size_t size, class DataContainer> inline void FloatingPointVector<T, size, DataContainer>::compCeil()
987{
988 for (size_t i = 0; i < size; ++i) {
989 this->_buffer[i] = std::ceil(this->_buffer[i]);
990 }
991}
992
993//-----------------------------------------------------------------------------------
994// Applies function \p f to each component starting from index 0 to index size-1.
995//-----------------------------------------------------------------------------------
996template <class T, size_t size, class DataContainer>
998{
999 for (size_t i = 0; i < size; ++i) {
1000 this->_buffer[i] = f(this->_buffer[i]);
1001 }
1002}
1003
1004//-----------------------------------------------------------------------------------
1005// Writes all components to ostream \p os starting from index 0 to size-1.
1006// Each buffer elements is followed separated by a space symbols " ".
1007//-----------------------------------------------------------------------------------
1008template <class T, size_t size, class DataContainer>
1009inline std::ostream& FloatingPointVector<T, size, DataContainer>::writeOut(std::ostream& os) const
1010{
1011 for (size_t i = 0; i < size; ++i) {
1012 os << this->_buffer[i] << " ";
1013 }
1014 return os;
1015}
1016
1017//-----------------------------------------------------------------------------------
1018// Reads all components from istream \p is starting starting from index 0 to size-1.
1019//-----------------------------------------------------------------------------------
1020template <class T, size_t size, class DataContainer>
1021inline std::istream& FloatingPointVector<T, size, DataContainer>::readIn(std::istream& is)
1022{
1023 for (size_t i = 0; i < size; ++i) {
1024 is >> this->_buffer[i];
1025 }
1026 return is;
1027}
1028
1030
1031
1032#endif
@ T
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).
bool operator<(const FloatingPointVector< T, size, DataContainer > &buffer) const
Defines an artificial order for use in sort algorithms (lexicographical order).
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.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
double MLdouble
Definition mlTypeDefs.h:217
double sqrt(T value)
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.