Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Vector4.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #ifndef _Vector4_hh_
27 #define _Vector4_hh_
28 #include "bias_config.h"
29 
30 #include <iostream>
31 #include <iomanip>
32 #include <sstream>
33 
34 #ifdef BIAS_HAVE_CPP11
35  #include <initializer_list>
36 #endif
37 
38 #include <Base/Debug/Error.hh>
39 //#include <Base/Debug/Debug.hh>
40 
41 #include <Base/Math/Vector.hh>
42 #include <Base/Math/Matrix.hh>
43 #include <Base/Math/Matrix4x4.hh>
44 #include <Base/Math/Operators.hh>
45 #include <Base/Math/Utils.hh>
46 
47 #define VECTOR4SIZE 4
48 namespace BIAS {
49  /** @class Vector4
50  @ingroup g_math
51  @brief class Vector4 contains a Vector of dim. 4 and fixed dimension
52 
53  It's elment type is templated.
54  manual loop unrolling is used if possible.
55  The Vector is in row-major order (4 rows, 1 column)
56  the indizes begin with zero (to size-1)
57  @author Jan Woetzel
58  @status tested in part (02/28/2002) **/
59 
60  // forward declaration to avoid mutual inclusion
61  template <class T> class BIASMathBase_EXPORT Matrix3x4;
62  template <class T> class BIASMathBase_EXPORT Matrix4x4;
63 
64  template<class T>
65  class BIASMathBase_EXPORT Vector4 {
66  public:
67  typedef T value_type;
68 
69  inline Vector4() {};
70 
71  /** copy constructor
72  @author Daniel Grest (06/2003)
73  */
74  inline Vector4(const Vector4<T>& vec) { *this = vec; };
75 
76  /** assignment with a constant value for all elements
77  @author Jan Woetzel
78  @status alpha (03/01/2002) **/
79  explicit inline Vector4(const T & scalar);
80 
81  /** assignment with an array of values
82  which is copied into this ones class members
83  @author Jan Woetzel
84  @status untested (02/28/2002) **/
85  explicit inline Vector4(const T * pv);
86 
87  /** constructor with element assignment
88  @author Jan Woetzel
89  @status alpha (03/01/2002) **/
90  explicit inline Vector4(char *s);
91 
92  /** constructor with element assigment using explicit values
93  @author Ingo Thomsen
94  @status tested (03/04/2002) **/
95  inline Vector4(const T v0, const T v1, const T v2, const T v3);
96 
97  /** cast constructor
98  @author Jan Woetzel
99  @status untested (03/22/2002)**/
100  Vector4(const Vector <T> &v);
101 
102 #ifdef BIAS_HAVE_CPP11
103  /** initializer list constructor (C++11)
104  @author Stefan Reinhold
105  @status untested (08/13/2014) **/
106  Vector4(const std::initializer_list< T> &i) {
107  BIASASSERT(i.size() >= 4);
108  auto iter = i.begin();
109  data_[0] = *iter;
110  data_[1] = *(++iter);
111  data_[2] = *(++iter);
112  data_[3] = *(++iter);
113  }
114 #endif
115 
116  inline ~Vector4() {};
117 
118  /** copy the array of vectorsize beginning at *T to this->data_
119  @author Jan Woetzel
120  @status untested (02/28/2002) **/
121  inline void Copy(const T * pv);
122 
123  /** set all elements to a scalat value
124  @author Jan Woetzel
125  @status untested (02/28/2002) **/
126  inline void Set(const T & scalar);
127 
128  /** set elementwise with given scalr values
129  @author Jan Woetzel, Ingo Thomsen
130  @status tested (02/28/2002) **/
131  inline void Set(const T & x, const T & y, const T & z, const T & w);
132 
133  /** set all values to 0
134  @author Jan Woetzel **/
135  inline void SetZero();
136  // stl conform interface
137  inline void clear();
138 
139  /** @return the size of this vector
140  @author Jan Woetzel (02/28/2002) **/
141  inline const unsigned int Size() const;
142  // stl conform interface
143  inline const unsigned int size() const;
144  // compatibility interface
145  inline const unsigned int GetNumElements() const { return size(); };
146 
147  /** @name Iterator Functions
148  @{
149  */
150  /** Iterator to first component of vector
151  * @author Stefan Reinhold **/
152  inline T const *begin() const {
153  return &data_[0];
154  }
155  inline T *begin() {
156  return &data_[0];
157  }
158 
159  /** Iterator pointing to one element after the last vector element
160  * @author Stefan Reinhold **/
161  inline T const *end() const {
162  return &data_[VECTOR4SIZE];
163  }
164  inline T *end() {
165  return &data_[VECTOR4SIZE];
166  }
167  /** @}
168  */
169 
170 
171 
172  /** get the data pointer
173  the member function itself is const (before {..}) because it
174  doesn't change the this object.
175  @return the const pointer to the data array for reading
176  @author Jan Woetzel
177  @status untested (02/28/2002) **/
178  inline const T *GetData() const
179  { return data_; };
180 
181  /* non const, used for assignment like this: v.GetData()[1]=42 JW */
182  inline T *GetData()
183  { return data_; };
184 
185  /** assignment operator
186  set the vector elementwise to scalar value
187  @author Jan Woetzel
188  @status alpha (02/28/2002)**/
189  inline Vector4<T>& operator=(const T& scalar);
190 
191 
192  /** assignment operator
193  @author grest 06 2003
194  */
195  inline Vector4<T>& operator=(const Vector4<T>& vec) {
196  memcpy((void *)data_, (void *)vec.GetData(), VECTOR4SIZE*sizeof(T));
197  return *this;
198  };
199 
200  /** access an element of the vector with 0-based indizes.
201  read only (no write)
202  member funciton const because it doesn't change this object
203  @author Jan Woetzel
204  @status alpha (03/01/2002) **/
205  inline const T& operator[] (const int i) const;
206 
207  /** access an element of the vector with 0-based indizes.
208  write allowed
209  @author Jan Woetzel
210  @status alpha (03/01/2002) **/
211  inline T & operator[] (const int i);
212 
213  /** scalar product (=inner product) of two vectors, storing
214  the result in result
215  @author Jan Woetzel
216  @status untested**/
217  inline void ScalarProduct(const Vector4 < T > &argvec, T & result) const;
218  inline T ScalarProduct(const Vector4 < T > &argvec) const;
219 
220 
221  /** outer product, constructs a matrix.
222  Often written as v * v^T for col vectors
223  @author frick
224  */
225  Matrix4x4<T> OuterProduct(const Vector4<T> &v) const;
226 
227  /** multiply two vectors elementwise, storing the result in destvec
228  @author Jan Woetzel
229  @status untested (03/06/2002)**/
230  inline void ElementwiseProduct(const Vector4 < T > &argvec,
231  Vector4 < T > &destvec) const;
232 
233  /** Return the L1 norm: |a| + |b| + |c|+ |d|
234  @author Ingo Thomsen
235  @date 04/11/2002
236  @status untested **/
237  inline T NormL1() const;
238 
239  /** Return the L2 norm: sqrt(a^2 + b^2 + c^2 + d^2)
240  @author Ingo Thomsen
241  @date 04/11/2002
242  @status untested **/
243  inline double NormL2() const;
244 
245  /** Return the euclidean distance of 2 vectors.
246  @author Birger Streckel
247  @date 08/2002
248  **/
249  inline double Dist(const Vector4<T> &vec) const;
250 
251  /** return a new Matrix with 1 row and 4 columns representing a
252  transposed vector **/
253  inline Matrix<T> transposed() const;
254 
255  /** Comparison operator 'equal'
256  @author Ingo Thomsen
257  @status tested **/
258  inline bool operator==(const Vector4<T>& arg) const;
259 
260  /** Comparison operator 'not equal'
261  @author Ingo Thomsen **/
262  inline bool operator!=(const Vector4<T>& arg) const;
263 
264 
265 
266  /** Addition operator with scalar argument
267  @author Ingo Thomsen
268  @status tested **/
269  inline Vector4<T>& operator+=(const T& scalar);
270 
271  /** Addition (in place) of an scalar
272  @author Ingo Thomsen **/
273  inline void AddIP (const T& scalar);
274 
275  /** Addition with a scalar, storing results in destionation vector
276  @author Ingo Thomsen **/
277  inline void Add(const T& scalar, Vector4<T>& dest) const;
278 
279 
280 
281  /** Substraction operator with scalar argument
282  @author Ingo Thomsen
283  @status tested **/
284  inline Vector4<T>& operator-=(const T& scalar);
285 
286  /** Substraction (in place) of an scalar
287  @author Ingo Thomsen **/
288  inline void SubIP(const T& scalar);
289 
290  /** Substraction with a scalar, storing results in destionation vector
291  @author Ingo Thomsen **/
292  inline void Sub(const T& scalar, Vector4<T>& dest) const;
293 
294 
295 
296  /** Multiplication operator with scalar argument
297  @author Ingo Thomsen
298  @status tested **/
299  inline Vector4<T>& operator*=(const T& scalar);
300 
301  /** Multiplication (in place) of an scalar
302  @author Ingo Thomsen **/
303  inline void MultiplyIP(const T& scalar);
304 
305  /** Multiplication with a scalar, storing results in destionation vector
306  @author Ingo Thomsen **/
307  inline void Multiply(const T& scalar, Vector4<T>& dest) const;
308 
309 
310 
311  /** Division operator with scalar argument
312  @author Ingo Thomsen
313  @status tested **/
314  inline Vector4<T>& operator/=(const T& scalar);
315 
316  /** Division (in place) of an scalar
317  @author Ingo Thomsen **/
318  inline void DivideIP(const T& scalar);
319 
320  /** Division with a scalar, storing results in destionation vector
321  @author Ingo Thomsen **/
322  inline void Divide(const T& scalar, Vector4<T>& dest) const;
323 
324 
325 
326  /** add operator for two Vectors
327  @author Ingo Thomsen
328  @status tested **/
329  inline Vector4<T>& operator+=(const Vector4<T> &argvec);
330 
331  /** in place adding
332  @author Ingo Thomsen
333  @status tested **/
334  inline void AddIP(const Vector4<T> &argvec);
335 
336  /** adding of two vectors, storing the result in destvec
337  @author Ingo Thomsen
338  @status tested **/
339  inline void Add(const Vector4<T> &argvec, Vector4<T> &destvec) const;
340 
341 
342 
343  /** sub operator for two Vectors
344  @author Ingo Thomsen
345  @status tested **/
346  inline Vector4<T> &operator-=(const Vector4<T> &argvec);
347 
348  /** in place substraction
349  @author Ingo Thomsen
350  @status tested **/
351  inline void SubIP(const Vector4<T> &argvec);
352 
353  /** subtracting of two Vectors, storing the result in destvec
354  @author Ingo Thomsen
355  @status tested **/
356  inline void Sub(const Vector4<T> &argvec, Vector4<T> &destvec) const;
357 
358 
359  /** method to load directly from a given filename.
360  internally using stream operator
361  @author Jan Woetzel 09/2005
362  @return false in case of error, true in case of success */
363  bool Load(const std::string & filename);
364 
365  /** method to save directly to a given filename.
366  internally using stream operator
367  @author Jan Woetzel 09/2009
368  @return false in case of error, true in case of success */
369  bool Save(const std::string & filename) const;
370 
371 
372  protected:
373  // the 4 elements of the vector without additional pointers etc...
374  // it is the *same* as 4 individual members, so there is *NO* additional pointer
375  // in particular an array of Vector4 is the same as one big array of T (JW)
376  T data_[VECTOR4SIZE]; //
377 
378  }; // end of class ==================================================
379 
380 
381 
382 
383  template <class T>
384  inline Vector4<T>::Vector4(const T & scalar)
385  {
386  Set(scalar);
387  }
388 
389  template <class T>
390  inline Vector4<T>::Vector4(char *s)
391  {
392  std::istringstream inst(s);
393  inst >> data_[0];
394  inst >> data_[1];
395  inst >> data_[2];
396  inst >> data_[3];
397  }
398 
399  template <class T>
400  inline Vector4<T>::Vector4(const T v0, const T v1, const T v2, const T v3)
401  {
402  Set(v0, v1, v2, v3);
403  }
404 
405  template <class T>
406  inline Vector4<T>::Vector4(const T * pv)
407  {
408  Copy(pv);
409  }
410 
411  template <class T>
412  inline void Vector4<T>::Copy(const T * pv)
413  {
414  data_[0] = pv[0];
415  data_[1] = pv[1];
416  data_[2] = pv[2];
417  data_[3] = pv[3];
418  }
419 
420  template <class T>
421  inline void Vector4<T>::Set(const T & scalar)
422  {
423  Set(scalar, scalar, scalar, scalar);
424  }
425 
426  template <class T>
427  inline void Vector4<T>::Set(const T & x, const T & y, const T & z, const T & w)
428  {
429  data_[0] = x;
430  data_[1] = y;
431  data_[2] = z;
432  data_[3] = w;
433  }
434 
435  template <class T>
436  inline const unsigned int Vector4<T>::size() const
437  {
438  return VECTOR4SIZE;
439  }
440 
441  template <class T>
442  inline const unsigned int Vector4<T>::Size() const
443  {
444  return size();
445  }
446 
447 
448  template <class T>
449  inline Vector4<T>& Vector4<T>::operator=(const T& scalar)
450  {
451  Set(scalar);
452  return *this;
453  }
454 
455  template <class T>
456  inline const T& Vector4<T>::operator[](const int i) const
457  {
458  BIASASSERT(0 <= i);
459  BIASASSERT(i < VECTOR4SIZE);
460  return data_[i];
461  }
462 
463  template <class T>
464  inline T& Vector4<T>::operator[](const int i)
465  {
466  BIASASSERT(0 <= i);
467  BIASASSERT(i < VECTOR4SIZE);
468  return data_[i];
469  }
470 
471 
472 
473  template <class T>
474  inline void
475  Vector4<T>::ScalarProduct(const Vector4<T> &argvec, T & result) const
476  {
477  result = ScalarProduct(argvec);
478  }
479 
480  template <class T>
481  inline T
483  {
484  return data_[0] * argvec[0] +
485  data_[1] * argvec[1] +
486  data_[2] * argvec[2] +
487  data_[3] * argvec[3];
488  }
489 
490  template <class T>
491  inline void Vector4<T>::ElementwiseProduct(const Vector4<T> &argvec,
492  Vector4<T> &destvec) const
493  {
494  destvec[0] = data_[0] * argvec[0];
495  destvec[1] = data_[1] * argvec[1];
496  destvec[2] = data_[2] * argvec[2];
497  destvec[3] = data_[3] * argvec[3];
498  }
499 
500  template <class T>
501  inline T Vector4<T>::NormL1() const
502  {
503  return (data_[0] > 0 ? data_[0] : data_[0] * -1)
504  + (data_[1] > 0 ? data_[1] : data_[1] * -1)
505  + (data_[2] > 0 ? data_[2] : data_[2] * -1)
506  + (data_[3] > 0 ? data_[3] : data_[3] * -1);
507  }
508 
509  template <class T>
510  inline double Vector4<T>::NormL2() const
511  {
512  return sqrt((double) ( data_[0]*data_[0] +
513  data_[1]*data_[1] +
514  data_[2]*data_[2] +
515  data_[3]*data_[3] ));
516  }
517 
518  template <class T>
519  inline double Vector4<T>::Dist(const Vector4<T> &vec) const
520  {
521  return sqrt((double) ( (data_[0]-vec[0])*(data_[0]-vec[0]) +
522  (data_[1]-vec[1])*(data_[1]-vec[1]) +
523  (data_[2]-vec[2])*(data_[2]-vec[2]) +
524  (data_[3]-vec[3])*(data_[3]-vec[3]) ));
525  }
526 
527  template <class T>
529  {
530  Matrix<T> destmat(1, 4);
531  destmat.GetData()[0] = data_[0];
532  destmat.GetData()[0] = data_[1];
533  destmat.GetData()[0] = data_[2];
534  destmat.GetData()[0] = data_[3];
535  return destmat;
536  }
537 
538  template <class T>
539  inline bool Vector4<T>::operator==(const Vector4<T>& arg) const
540  {
541  return ( (data_[0] == arg.data_[0]) && (data_[1] == arg.data_[1]) &&
542  (data_[2] == arg.data_[2]) && (data_[3] == arg.data_[3]) );
543  }
544 
545  template <class T>
546  inline bool Vector4<T>::operator!=(const Vector4<T>& arg) const
547  {
548  return !operator==(arg);
549  }
550 
551 
552 
553  template <class T>
554  inline Vector4<T>& Vector4<T>::operator+=(const T& scalar)
555  {
556  AddIP(scalar);
557  return *this;
558  }
559 
560  template <class T>
561  inline void Vector4<T>::AddIP(const T& scalar)
562  {
563  Add(scalar, *this);
564  }
565 
566  template <class T>
567  inline void Vector4<T>::Add(const T& scalar, Vector4<T>& dest) const
568  {
569  dest.data_[0] = data_[0] + scalar;
570  dest.data_[1] = data_[1] + scalar;
571  dest.data_[2] = data_[2] + scalar;
572  dest.data_[3] = data_[3] + scalar;
573  }
574 
575 
576 
577  template <class T>
578  inline Vector4<T>& Vector4<T>::operator-=(const T& scalar)
579  {
580  SubIP(scalar);
581  return *this;
582  }
583 
584  template <class T>
585  inline void Vector4<T>::SubIP(const T& scalar)
586  {
587  Sub(scalar, *this);
588  }
589 
590  template <class T>
591  inline void Vector4<T>::Sub (const T& scalar, Vector4<T>& dest) const
592  {
593  dest.data_[0] = data_[0] - scalar;
594  dest.data_[1] = data_[1] - scalar;
595  dest.data_[2] = data_[2] - scalar;
596  dest.data_[3] = data_[3] - scalar;
597  }
598 
599 
600 
601  template <class T>
602  inline Vector4<T>& Vector4<T>::operator*=(const T& scalar)
603  {
604  MultiplyIP(scalar);
605  return *this;
606  }
607 
608  template <class T>
609  inline void Vector4<T>::MultiplyIP(const T& scalar)
610  {
611  Multiply(scalar, *this);
612  }
613 
614  template <class T>
615  inline void Vector4<T>::Multiply(const T& scalar, Vector4<T>& dest) const
616  {
617  dest.data_[0] = data_[0] * scalar;
618  dest.data_[1] = data_[1] * scalar;
619  dest.data_[2] = data_[2] * scalar;
620  dest.data_[3] = data_[3] * scalar;
621  }
622 
623 
624 
625  template <class T>
626  inline Vector4<T>& Vector4<T>::operator/=(const T& scalar)
627  {
628  DivideIP(scalar);
629  return *this;
630  }
631 
632  template <class T>
633  inline void Vector4<T>::DivideIP(const T& scalar)
634  { Divide(scalar, *this);}
635 
636  template <class T>
637  inline void Vector4<T>::Divide(const T& scalar, Vector4<T>& dest) const
638  {
639 #ifdef BIAS_DEBUG
640  if (scalar == 0 ){
641  BIASERR("Division by Zero!");
642  BIASABORT;
643  }
644 #endif
645  dest.data_[0] = data_[0] / scalar;
646  dest.data_[1] = data_[1] / scalar;
647  dest.data_[2] = data_[2] / scalar;
648  dest.data_[3] = data_[3] / scalar;
649  }
650 
651 
652 
653  template <class T>
655  {
656  Add(argvec, *this);
657  return *this;
658  }
659 
660  template <class T>
661  inline void Vector4<T>::AddIP(const Vector4<T> &argvec)
662  {
663  Add(argvec, *this);
664  }
665 
666  template <class T> inline void
667  Vector4<T>::Add(const Vector4<T> &argvec, Vector4<T> &destvec) const
668  {
669  destvec[0] = data_[0] + argvec[0];
670  destvec[1] = data_[1] + argvec[1];
671  destvec[2] = data_[2] + argvec[2];
672  destvec[3] = data_[3] + argvec[3];
673  }
674 
675 
676 
677  template <class T>
679  {
680  SubIP(argvec);
681  return *this;
682  }
683 
684  template <class T>
685  inline void Vector4<T>::SubIP(const Vector4<T> &argvec)
686  {
687  Sub(argvec, *this);
688  }
689 
690  template <class T> inline void
691  Vector4<T>::Sub(const Vector4<T> &argvec, Vector4<T> &destvec) const
692  {
693  destvec[0] = data_[0] - argvec[0];
694  destvec[1] = data_[1] - argvec[1];
695  destvec[2] = data_[2] - argvec[2];
696  destvec[3] = data_[3] - argvec[3];
697  }
698 
699 
700  // JW
701  template <class T>
702  inline void Vector4<T>::SetZero()
703  {
704  Set( (T)0);
705  }
706 
707 
708  // JW
709  template <class T>
710  inline void Vector4<T>::clear()
711  {
712  SetZero();
713  }
714 
715 
716 
717  //////////////////////////////////////////////////////////
718  // operators
719  ///////////////////////////////////////////////////////////
720 
721 
722  /**
723  @relates Vector4
724  @brief Input with streams
725  specialization for numerical display of unsigned char instead of alphebetically.
726  fout format should be consistent with template implementation and Vector<>
727  @author Jan Woetzel */
728  inline
729  std::ostream& operator<<(std::ostream & os, const Vector4<unsigned char> &vec)
730  {
731  if (!IsConsoleStream(os))
732  { // not cout and not cerr, display trailing dim for consistency with Vector<>
733  os << VECTOR4SIZE << NL;
734  for (int row = 0; row < VECTOR4SIZE; row++) {
735  // print out one element per line
736  os<<std::setw(3)<<(int)vec.GetData()[row]<<" "<<NL;
737  }
738  } else {// cout or cerr
739  os << "[ ";
740  for (int row = 0; row < VECTOR4SIZE; row++)
741  os<<std::setw(3)<<(int)vec.GetData()[row]<<" ";
742  os<<" ]";
743  }
744  return os;
745  }
746 
747 
748  inline
749  std::ostream& operator<<(std::ostream & os, const Vector4<char> &vec)
750  {
751  if (!IsConsoleStream(os))
752  { // not cout and not cerr, display trailing dim for consistency with Vector<>
753  os << VECTOR4SIZE << NL;
754  for (int row = 0; row < VECTOR4SIZE; row++) {
755  // print out one element per line
756  os<<std::setw(3)<<(int)vec.GetData()[row]<<" "<<NL;
757  }
758  } else {// cout or cerr
759  os << "[ ";
760  for (int row = 0; row < VECTOR4SIZE; row++)
761  os<<std::setw(3)<<(unsigned int)vec.GetData()[row]<<" ";
762  os<<" ]";
763  }
764  return os;
765  }
766 
767 
768  /**
769  @relates Vector4
770  @brief Input with streams
771  fout format should be consistent with template implementation and Vector<>
772  @author Jan Woetzel */
773  template<class T>
774  inline
775  std::ostream& operator<<(std::ostream & os, const Vector4<T> &vec)
776  {
777  if (!IsConsoleStream(os))
778  { // not cout and not cerr, display trailing dim for consistency with Vector<>
779  os << VECTOR4SIZE << NL;
780  for (int row = 0; row < VECTOR4SIZE; row++) {
781  //os<<std::setw(14); // set width for output format
782  os<<std::setprecision( DecimalsToStore<T>() );
783  // print out one element per line
784  os<<vec.GetData()[row]<<" "<<NL;
785  }
786  } else {// cout or cerr
787  os<<"[ ";
788  for (int row = 0; row < VECTOR4SIZE; row++){
789  os<<std::setprecision(CONSOLE_PRECISION_DIGITS);
790  os<<vec.GetData()[row]<<" ";
791  }
792  os<<" ]";
793  }
794  return os;
795  }
796 
797 
798  /**
799  @relates Vector4
800  @brief Input with streams
801  specialization for numerical display of unsigned char instead of alphebetically.
802  fout format should be consistent with template implementation and Vector<>
803  @author Jan Woetzel */
804  inline std::istream &
805  operator>>(std::istream & is, Vector4<unsigned char> & vec)
806  {
807  int N;
808  is >> N;
809  if (N != (int)vec.Size()){
810  BIASERR("can't assign to a Vector4<unsigned char> from a vector with dim " << N );
811  } else {
812  // correct size, sequential read elementwise
813  int tmp(0); //< used for casting between unsigned char are written int
814  for (unsigned int row = 0; row < vec.Size(); row++)
815  {
816  is >> tmp;
817  BIASASSERT(tmp>=std::numeric_limits<unsigned char>::min() );
818  BIASASSERT(tmp<=std::numeric_limits<unsigned char>::max() );
819  vec.GetData()[row] = (unsigned char)tmp;
820  };
821  };
822  return is;
823  }
824 
825  inline std::istream &
826  operator>>(std::istream & is, Vector4<char> & vec)
827  {
828  int N;
829  is >> N;
830  if (N != (int)vec.Size()){
831  BIASERR("can't assign to a Vector4<unsigned> from a vector with dim " << N );
832  } else {
833  // correct size, sequential read elementwise
834  int tmp(0); //< used for casting between unsigned char are written int
835  for (unsigned int row = 0; row < vec.Size(); row++)
836  {
837  is >> tmp;
838  BIASASSERT(tmp>=std::numeric_limits< char>::min() );
839  BIASASSERT(tmp<=std::numeric_limits< char>::max() );
840  vec.GetData()[row] = (char)tmp;
841  };
842  };
843  return is;
844  }
845 
846  /** @relates Vector4
847  @brief Input with streams
848  fout format should be consistent with template implementation and Vector<>
849  @author Jan Woetzel */
850  template <class T>
851  std::istream& operator>>(std::istream & is, Vector4<T> &vec)
852  {
853  int N;
854  is >> N;
855  if (!(N == (int)vec.Size())) {
856  BIASERR("can't assign a Vector4<T> with a dim " << N << " vector");
857  BIASBREAK;
858  } else {
859  for (unsigned int row = 0; row < vec.Size(); row++) {
860  is>>vec.GetData()[row];
861  };
862  };
863  return is;
864  }
865 
866 
867 } // namespace BIAS
868 #endif
869 
void Sub(const T &scalar, Vector4< T > &dest) const
Substraction with a scalar, storing results in destionation vector.
Definition: Vector4.hh:591
void Multiply(const T &scalar, Vector4< T > &dest) const
Multiplication with a scalar, storing results in destionation vector.
Definition: Vector4.hh:615
void Add(const T &scalar, Vector4< T > &dest) const
Addition with a scalar, storing results in destionation vector.
Definition: Vector4.hh:567
void AddIP(const T &scalar)
Addition (in place) of an scalar.
Definition: Vector4.hh:561
T const * begin() const
Iterator to first component of vector.
Definition: Vector4.hh:152
class for column vectors with arbitrary size
void SetZero()
set all values to 0
Definition: Vector4.hh:702
T * begin()
Definition: Vector4.hh:155
bool IsConsoleStream(const std::ostream &os)
Helper returning true on console ostreams like cerr, cout Useful to distinguish between console (cout...
Definition: Utils.hh:54
T const * end() const
Iterator pointing to one element after the last vector element.
Definition: Vector4.hh:161
Matrix< T > transposed() const
return a new Matrix with 1 row and 4 columns representing a transposed vector
Definition: Vector4.hh:528
BIASMathBase_EXPORT Vector2< T > & operator/=(Vector2< T > &vec, const Vector2< T > &argvec)
elementwise division
Definition: Vector2.hh:846
void ElementwiseProduct(const Vector4< T > &argvec, Vector4< T > &destvec) const
multiply two vectors elementwise, storing the result in destvec
Definition: Vector4.hh:491
void Set(const T &scalar)
set all elements to a scalat value
Definition: Vector4.hh:421
std::istream & operator>>(std::istream &is, Vector4< unsigned char > &vec)
Input with streams specialization for numerical display of unsigned char instead of alphebetically...
Definition: Vector4.hh:805
const T & operator[](const int i) const
access an element of the vector with 0-based indizes.
Definition: Vector4.hh:456
void SubIP(const T &scalar)
Substraction (in place) of an scalar.
Definition: Vector4.hh:585
Vector2< T > & operator-=(Vector2< T > &vec, const Vector2< T > &argvec)
sub operator for two Vectors
Definition: Vector2.hh:839
double NormL2() const
Return the L2 norm: sqrt(a^2 + b^2 + c^2 + d^2)
Definition: Vector4.hh:510
Vector4< T > & operator+=(const T &scalar)
Addition operator with scalar argument.
Definition: Vector4.hh:554
std::istream & operator>>(std::istream &is, Vector4< T > &vec)
Input with streams fout format should be consistent with template implementation and Vector&lt;&gt; ...
Definition: Vector4.hh:851
bool operator==(const Vector4< T > &arg) const
Comparison operator &#39;equal&#39;.
Definition: Vector4.hh:539
class Vector4 contains a Vector of dim.
Definition: Vector4.hh:65
T data_[VECTOR4SIZE]
Definition: Vector4.hh:375
void Copy(const T *pv)
copy the array of vectorsize beginning at *T to this-&gt;data_
Definition: Vector4.hh:412
const unsigned int GetNumElements() const
Definition: Vector4.hh:145
BIASMathBase_EXPORT Vector2< T > & operator+=(Vector2< T > &vec, const Vector2< T > &argvec)
add operator for two Vectors
Definition: Vector2.hh:830
Vector2< T > & operator*=(Vector2< T > &vec, const T &scalar)
Multiplication operator with scalar argument.
Definition: Vector2.hh:873
Vector4< T > & operator*=(const T &scalar)
Multiplication operator with scalar argument.
Definition: Vector4.hh:602
const unsigned int Size() const
Definition: Vector4.hh:442
void Divide(const T &scalar, Vector4< T > &dest) const
Division with a scalar, storing results in destionation vector.
Definition: Vector4.hh:637
double Dist(const Vector4< T > &vec) const
Return the euclidean distance of 2 vectors.
Definition: Vector4.hh:519
const unsigned int size() const
Definition: Vector4.hh:436
T * GetData()
get the pointer to the data array of the matrix (for faster direct memeory access) ...
Definition: Matrix.hh:185
class BIASMathBase_EXPORT Matrix4x4
Definition: Operators.hh:45
Vector4< T > & operator/=(const T &scalar)
Division operator with scalar argument.
Definition: Vector4.hh:626
void ScalarProduct(const Vector4< T > &argvec, T &result) const
scalar product (=inner product) of two vectors, storing the result in result
Definition: Vector4.hh:475
bool operator!=(const Vector4< T > &arg) const
Comparison operator &#39;not equal&#39;.
Definition: Vector4.hh:546
Vector4< T > & operator=(const T &scalar)
assignment operator set the vector elementwise to scalar value
Definition: Vector4.hh:449
matrix class with arbitrary size, indexing is row major.
const T * GetData() const
get the data pointer the member function itself is const (before {..}) because it doesn&#39;t change the...
Definition: Vector4.hh:177
void MultiplyIP(const T &scalar)
Multiplication (in place) of an scalar.
Definition: Vector4.hh:609
void clear()
Definition: Vector4.hh:710
class BIASMathBase_EXPORT Vector4
Definition: Operators.hh:46
Vector4< T > & operator-=(const T &scalar)
Substraction operator with scalar argument.
Definition: Vector4.hh:578
class BIASMathBase_EXPORT Matrix3x4
Definition: Operators.hh:47
void DivideIP(const T &scalar)
Division (in place) of an scalar.
Definition: Vector4.hh:633
is a &#39;fixed size&#39; quadratic matrix of dim.
Definition: Matrix4x4.hh:54
T NormL1() const
Return the L1 norm: |a| + |b| + |c|+ |d|.
Definition: Vector4.hh:501
Vector4(const Vector4< T > &vec)
copy constructor
Definition: Vector4.hh:74
BIASCommon_EXPORT std::istream & operator>>(std::istream &is, BIAS::TimeStamp &ts)
Standard input operator for TimeStamps.
Definition: TimeStamp.cpp:157