SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Vector4d.hpp
Go to the documentation of this file.
1 /*
2  * Copyright(c):
3  * Signal Image and Communications (SIC) Department
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * - University of Poitiers, France http://www.univ-poitiers.fr
6  * - XLIM Institute UMR CNRS 7252 http://www.xlim.fr/
7  *
8  * and
9  *
10  * D2 Fluid, Thermic and Combustion
11  * - University of Poitiers, France http://www.univ-poitiers.fr
12  * - PPRIME Institute - UPR CNRS 3346 http://www.pprime.fr
13  * - ISAE-ENSMA http://www.ensma.fr
14  *
15  * Contributor(s):
16  * The SLIP team,
17  * Benoit Tremblais <tremblais_AT_sic.univ-poitiers.fr>,
18  * Laurent David <laurent.david_AT_lea.univ-poitiers.fr>,
19  * Ludovic Chatellier <ludovic.chatellier_AT_univ-poitiers.fr>,
20  * Lionel Thomas <lionel.thomas_AT_univ-poitiers.fr>,
21  * Denis Arrivault <arrivault_AT_sic.univ-poitiers.fr>,
22  * Julien Dombre <julien.dombre_AT_univ-poitiers.fr>.
23  *
24  * Description:
25  * The Simple Library of Image Processing (SLIP) is a new image processing
26  * library. It is written in the C++ language following as much as possible
27  * the ISO/ANSI C++ standard. It is consequently compatible with any system
28  * satisfying the ANSI C++ complience. It works on different Unix , Linux ,
29  * Mircrosoft Windows and Mac OS X plateforms. SLIP is a research library that
30  * was created by the Signal, Image and Communications (SIC) departement of
31  * the XLIM, UMR 7252 CNRS Institute in collaboration with the Fluids, Thermic
32  * and Combustion departement of the P', UPR 3346 CNRS Institute of the
33  * University of Poitiers.
34  *
35  * The SLIP Library source code has been registered to the APP (French Agency
36  * for the Protection of Programs) by the University of Poitiers and CNRS,
37  * under registration number IDDN.FR.001.300034.000.S.P.2010.000.21000.
38 
39  * http://www.sic.sp2mi.univ-poitiers.fr/slip/
40  *
41  * This software is governed by the CeCILL-C license under French law and
42  * abiding by the rules of distribution of free software. You can use,
43  * modify and/ or redistribute the software under the terms of the CeCILL-C
44  * license as circulated by CEA, CNRS and INRIA at the following URL
45  * http://www.cecill.info.
46  * As a counterpart to the access to the source code and rights to copy,
47  * modify and redistribute granted by the license, users are provided only
48  * with a limited warranty and the software's author, the holder of the
49  * economic rights, and the successive licensors have only limited
50  * liability.
51  *
52  * In this respect, the user's attention is drawn to the risks associated
53  * with loading, using, modifying and/or developing or reproducing the
54  * software by the user in light of its specific status of free software,
55  * that may mean that it is complicated to manipulate, and that also
56  * therefore means that it is reserved for developers and experienced
57  * professionals having in-depth computer knowledge. Users are therefore
58  * encouraged to load and test the software's suitability as regards their
59  * requirements in conditions enabling the security of their systems and/or
60  * data to be ensured and, more generally, to use and operate it in the
61  * same conditions as regards security.
62  *
63  * The fact that you are presently reading this means that you have had
64  * knowledge of the CeCILL-C license and that you accept its terms.
65  */
66 
74 #ifndef SLIP_VECTOR4D_HPP
75 #define SLIP_VECTOR4D_HPP
76 
77 #include <iostream>
78 #include <iterator>
79 #include <cassert>
80 #include <cstddef>
81 #include <algorithm>
82 #include <numeric>
83 #include <string>
84 #include "KVector.hpp"
85 #include "norms.hpp"
86 
87 #include <boost/serialization/access.hpp>
88 #include <boost/serialization/split_member.hpp>
89 #include <boost/serialization/version.hpp>
90 
91 
92 namespace slip
93 {
94 
95 template <typename T>
96 struct Vector4d;
97 
98 template <typename T>
99 bool operator<(const Vector4d<T>& x, const Vector4d<T>& y);
100 
101 template <typename T>
102 bool operator>(const Vector4d<T>& x, const Vector4d<T>& y);
103 
104 template <typename T>
105 bool operator<=(const Vector4d<T>& x, const Vector4d<T>& y);
106 
107 template <typename T>
108 bool operator>=(const Vector4d<T>& x, const Vector4d<T>& y);
109 
123 template <typename T>
124 struct Vector4d : public slip::kvector<T,4>
125 {
126 
127  typedef Vector4d<T> self;
128  typedef T value_type;
129  typedef value_type* pointer;
130  typedef const value_type* const_pointer;
132  typedef const value_type& const_reference;
133 
134  typedef ptrdiff_t difference_type;
135  typedef std::size_t size_type;
136 
137  typedef pointer iterator;
139 
140 
145 
150  Vector4d();
151 
157  Vector4d(const T& val);
158 
167  Vector4d(const T& x1,
168  const T& x2,
169  const T& x3,
170  const T& x4);
171 
177  Vector4d(const T* val);
178 
179 
185  Vector4d(const Vector4d<T>& rhs);
186 
187 
188 
195  self operator-() const;
196 
201 
202 
210  friend bool operator< <>(const Vector4d<T>& x, const Vector4d<T>& y);
211 
219  friend bool operator> <>(const Vector4d<T>& x, const Vector4d<T>& y);
220 
228  friend bool operator<= <>(const Vector4d<T>& x, const Vector4d<T>& y);
229 
237  friend bool operator> <>(const Vector4d<T>& x, const Vector4d<T>& y);
238 
239 
250  const T& get_x1() const;
255  const T& get_x() const;
260  const T& u() const;
261 
266  const T& get_x2() const;
271  const T& get_y() const;
276  const T& v() const;
277 
278 
283  const T& get_x3() const;
288  const T& get_z() const;
293  const T& w() const;
294 
299  const T& get_x4() const;
304  const T& get_t() const;
309  const T& t() const;
310 
315  void set_x1(const T& x1);
320  void set_x(const T& r);
325  void u(const T& u_);
326 
327 
332  void set_x2(const T& x2);
337  void set_y(const T& g);
342  void v(const T& v_);
343 
348  void set_x3(const T& x3);
353  void set_z(const T& r);
358  void w(const T& w_);
359 
364  void set_x4(const T& x4);
369  void set_t(const T& s);
374  void t(const T& x_);
375 
376 
384  void set(const T& x1,
385  const T& x2,
386  const T& x3,
387  const T& x4);
388 
389 
390 
397  std::string name() const;
398 
399  private:
401  template<class Archive>
402  void save(Archive & ar, const unsigned int version) const
403  {
404  ar & boost::serialization::base_object<slip::kvector<T,4> >(*this);
405  }
406  template<class Archive>
407  void load(Archive & ar, const unsigned int version)
408  {
409  ar & boost::serialization::base_object<slip::kvector<T,4> >(*this);
410  }
411  BOOST_SERIALIZATION_SPLIT_MEMBER()
412 
413 };
414 
435 
436 }//slip::
437 
438 namespace slip
439 {
440 
441 template<typename T>
442 inline
444 {
445  this->fill(T(0));
446 }
447 
448 template<typename T>
449 inline
451 {
452  this->fill(val);
453 }
454 
455 template<typename T>
456 inline
458  const T& x2,
459  const T& x3,
460  const T& x4)
461  {
462  (*this)[0] = x1;
463  (*this)[1] = x2;
464  (*this)[2] = x3;
465  (*this)[3] = x4;
466  }
467 
468 template<typename T>
469 inline
471 {
472  assert(val != 0);
473  this->fill(val);
474 }
475 
476 
477 template<typename T>
478 inline
480 {
481  *this = rhs;
482 }
483 
484 template<typename T>
485 inline
487 {
488  self tmp;
489  tmp[0] = -(*this)[0];
490  tmp[1] = -(*this)[1];
491  tmp[2] = -(*this)[2];
492  tmp[3] = -(*this)[3];
493  return tmp;
494 }
496 /* @{ */
497  template<typename T>
498 inline
499 bool operator<(const Vector4d<T>& x,
500  const Vector4d<T>& y)
501  {
502  return (slip::Euclidean_norm<T>(x.begin(),x.end())
503  < slip::Euclidean_norm<T>(y.begin(),y.end())
504  );
505  }
506 
507 
508 
509  template<typename T>
510  inline
511  bool operator>(const Vector4d<T>& x,
512  const Vector4d<T>& y)
513  {
514  return y < x;
515  }
516 
517  template<typename T>
518  inline
519  bool operator<=(const Vector4d<T>& x,
520  const Vector4d<T>& y)
521  {
522  return !(y < x);
523  }
524 
525  template<typename T>
526  inline
527  bool operator>=(const Vector4d<T>& x,
528  const Vector4d<T>& y)
529  {
530  return !(x < y);
531  }
532  /* @} */
533 
534  template<typename T>
535  inline
536  const T& Vector4d<T>::get_x1() const {return (*this)[0];}
537 
538  template<typename T>
539  inline
540  const T& Vector4d<T>::get_x() const {return (*this)[0];}
541 
542  template<typename T>
543  inline
544  const T& Vector4d<T>::u() const {return (*this)[0];}
545 
546 
547  template<typename T>
548  inline
549  const T& Vector4d<T>::get_x2() const {return (*this)[1];}
550 
551  template<typename T>
552  inline
553  const T& Vector4d<T>::get_y() const {return (*this)[1];}
554 
555  template<typename T>
556  inline
557  const T& Vector4d<T>::v() const {return (*this)[1];}
558 
559 
560  template<typename T>
561  inline
562  const T& Vector4d<T>::get_x3() const {return (*this)[2];}
563 
564  template<typename T>
565  inline
566  const T& Vector4d<T>::get_z() const {return (*this)[2];}
567 
568  template<typename T>
569  inline
570  const T& Vector4d<T>::w() const {return (*this)[2];}
571 
572  template<typename T>
573  inline
574  const T& Vector4d<T>::get_x4() const {return (*this)[3];}
575 
576  template<typename T>
577  inline
578  const T& Vector4d<T>::get_t() const {return (*this)[3];}
579 
580  template<typename T>
581  inline
582  const T& Vector4d<T>::t() const {return (*this)[3];}
583 
584 
585  template<typename T>
586  inline
587  void Vector4d<T>::set_x1(const T& x1){(*this)[0] = x1;}
588 
589  template<typename T>
590  inline
591  void Vector4d<T>::set_x(const T& x){(*this)[0] = x;}
592 
593  template<typename T>
594  inline
595  void Vector4d<T>::u(const T& x){(*this)[0] = x;}
596 
597 
598  template<typename T>
599  inline
600  void Vector4d<T>::set_x2(const T& x2){(*this)[1] = x2;}
601 
602  template<typename T>
603  inline
604  void Vector4d<T>::set_y(const T& y){(*this)[1] = y;}
605 
606  template<typename T>
607  inline
608  void Vector4d<T>::v(const T& y){(*this)[1] = y;}
609 
610 
611  template<typename T>
612  inline
613  void Vector4d<T>::set_x3(const T& x3){(*this)[2] = x3;}
614 
615  template<typename T>
616  inline
617  void Vector4d<T>::set_z(const T& z){(*this)[2] = z;}
618 
619  template<typename T>
620  inline
621  void Vector4d<T>::w(const T& w_){(*this)[2] = w_;}
622 
623  template<typename T>
624  inline
625  void Vector4d<T>::set_x4(const T& x4){(*this)[3] = x4;}
626 
627  template<typename T>
628  inline
629  void Vector4d<T>::set_t(const T& s){(*this)[3] = s;}
630 
631  template<typename T>
632  inline
633  void Vector4d<T>::t(const T& x_){(*this)[3] = x_;}
634 
635  template<typename T>
636  inline
637  void Vector4d<T>::set(const T& x1,
638  const T& x2,
639  const T& x3,
640  const T& x4)
641  {
642  (*this)[0] = x1;
643  (*this)[1] = x2;
644  (*this)[2] = x3;
645  (*this)[3] = x4;
646  }
647 
648 }//slip::
649 
650 
651 namespace slip
652 {
653 template<typename T>
654 inline
656  const Vector4d<T>& V2)
657 {
658  Vector4d<T> tmp;
659  tmp[0] = V1[0] + V2[0];
660  tmp[1] = V1[1] + V2[1];
661  tmp[2] = V1[2] + V2[2];
662  tmp[3] = V1[3] + V2[3];
663  return tmp;
664 }
665 
666 template<typename T>
667 inline
669  const T& val)
670 {
671  Vector4d<T> tmp = V1;
672  tmp+=val;
673  return tmp;
674 }
675 
676 template<typename T>
677 inline
678 Vector4d<T> operator+(const T& val,
679  const Vector4d<T>& V1)
680 {
681  return V1 + val;
682 }
683 
684 template<typename T>
685 inline
687  const Vector4d<T>& V2)
688 {
689  Vector4d<T> tmp;
690  tmp[0] = V1[0] - V2[0];
691  tmp[1] = V1[1] - V2[1];
692  tmp[2] = V1[2] - V2[2];
693  tmp[3] = V1[3] - V2[3];
694  return tmp;
695 }
696 
697 template<typename T>
698 inline
700  const T& val)
701 {
702  Vector4d<T> tmp = V1;
703  tmp-=val;
704  return tmp;
705 }
706 
707 template<typename T>
708 inline
709 Vector4d<T> operator-(const T& val,
710  const Vector4d<T>& V1)
711 {
712  Vector4d<T> tmp;
713  tmp[0] = val - V1[0];
714  tmp[1] = val - V1[1];
715  tmp[2] = val - V1[2];
716  tmp[3] = val - V1[3];
717  return tmp;
718 }
719 
720 
721 template<typename T>
722 inline
724  const Vector4d<T>& V2)
725 {
726  Vector4d<T> tmp;
727  tmp[0] = V1[0] * V2[0];
728  tmp[1] = V1[1] * V2[1];
729  tmp[2] = V1[2] * V2[2];
730  tmp[2] = V1[3] * V2[3];
731  return tmp;
732 }
733 
734 template<typename T>
735 inline
737  const T& val)
738 {
739  Vector4d<T> tmp = V1;
740  tmp*=val;
741  return tmp;
742 }
743 
744 template<typename T>
745 inline
746 Vector4d<T> operator*(const T& val,
747  const Vector4d<T>& V1)
748 {
749  return V1 * val;
750 }
751 
752 template<typename T>
753 inline
755  const Vector4d<T>& V2)
756 {
757  Vector4d<T> tmp;
758  tmp[0] = V1[0] / V2[0];
759  tmp[1] = V1[1] / V2[1];
760  tmp[2] = V1[2] / V2[2];
761  tmp[3] = V1[3] / V2[3];
762  return tmp;
763 }
764 
765 template<typename T>
766 inline
768  const T& val)
769 {
770  Vector4d<T> tmp = V1;
771  tmp/=val;
772  return tmp;
773 }
774 
775 template<typename T>
776 inline
777 std::string
778 Vector4d<T>::name() const {return "Vector4d";}
779 
780 
781 }//slip::
782 
783 #endif //SLIP_VECTOR4D_HPP
const T & get_x4() const
Accessor to the fourth dimension value of the Vector4d.
Definition: Vector4d.hpp:574
void set_x(const T &r)
Mutator of the first dimension value of the Vector4d.
Definition: Vector4d.hpp:591
const T & get_x3() const
Accessor to the third dimension value of the Vector4d.
Definition: Vector4d.hpp:562
void set_x2(const T &x2)
Mutator of the second dimension value of the Vector4d.
Definition: Vector4d.hpp:600
const_pointer const_iterator
Definition: Vector4d.hpp:138
This is a linear (one-dimensional) static vector. This container statisfies the RandomAccessContainer...
Definition: KVector.hpp:100
slip::Vector4d< float > Vector4d_f
float alias
Definition: Vector4d.hpp:418
void set_z(const T &r)
Mutator of the third dimension value of the Vector4d.
Definition: Vector4d.hpp:617
std::string name() const
Returns the name of the class.
Definition: Vector4d.hpp:778
slip::Vector4d< unsigned long > Vector4d_ul
unsigned long alias
Definition: Vector4d.hpp:422
const T & v() const
Accessor to the second dimension value of the Vector4d.
Definition: Vector4d.hpp:557
Color< T > operator+(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:602
slip::Vector4d< char > Vector4d_c
char alias
Definition: Vector4d.hpp:432
void set_x1(const T &x1)
Mutator of the first dimension value of the Vector4d.
Definition: Vector4d.hpp:587
const T & get_x1() const
Accessor to the first dimension value of the Vector4d.
Definition: Vector4d.hpp:536
ptrdiff_t difference_type
Definition: Vector4d.hpp:134
slip::Vector4d< unsigned short > Vector4d_us
unsigned long alias
Definition: Vector4d.hpp:426
value_type * pointer
Definition: Vector4d.hpp:129
std::size_t size_type
Definition: Vector4d.hpp:135
slip::Vector4d< unsigned char > Vector4d_uc
unsigned char alias
Definition: Vector4d.hpp:434
bool operator>(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1469
const T & u() const
Accessor to the first dimension value of the Vector4d.
Definition: Vector4d.hpp:544
const value_type & const_reference
Definition: Vector4d.hpp:132
void set_x3(const T &x3)
Mutator of the third dimension value of the Vector4d.
Definition: Vector4d.hpp:613
Provides a class to manipulate static and generic vectors.
value_type & reference
Definition: Vector4d.hpp:131
const T & w() const
Accessor to the third dimension value of the Vector4d.
Definition: Vector4d.hpp:570
const value_type * const_pointer
Definition: Vector4d.hpp:130
const T & get_x2() const
Accessor to the second dimension value of the Vector4d.
Definition: Vector4d.hpp:549
Vector4d()
Default constructor init all the components to 0.
Definition: Vector4d.hpp:443
slip::Vector4d< short > Vector4d_s
short alias
Definition: Vector4d.hpp:424
void set_y(const T &g)
Mutator of the second dimension value of the Vector4d.
Definition: Vector4d.hpp:604
slip::Vector4d< double > Vector4d_d
double alias
Definition: Vector4d.hpp:416
void set(const T &x1, const T &x2, const T &x3, const T &x4)
Mutator of the three dimension values of the Vector4d.
Definition: Vector4d.hpp:637
This is a Vector4d struct. It is a specialization of kvector. It implements some specific 4d operatio...
Definition: Vector4d.hpp:96
friend class boost::serialization::access
Definition: Vector4d.hpp:400
self operator-() const
Definition: Vector4d.hpp:486
const T & get_y() const
Accessor to the second dimension value of the Vector4d.
Definition: Vector4d.hpp:553
void set_x4(const T &x4)
Mutator of the fourth dimension value of the Vector4d.
Definition: Vector4d.hpp:625
void set_t(const T &s)
Mutator of the fourth dimension value of the Vector4d.
Definition: Vector4d.hpp:629
pointer iterator
Definition: Vector4d.hpp:137
slip::Vector4d< long > Vector4d_l
long alias
Definition: Vector4d.hpp:420
slip::Vector4d< int > Vector4d_i
int alias
Definition: Vector4d.hpp:428
const T & t() const
Accessor to the fourth dimension value of the Vector4d.
Definition: Vector4d.hpp:582
const T & get_x() const
Accessor to the first dimension value of the Vector4d.
Definition: Vector4d.hpp:540
const T & get_z() const
Accessor to the third dimension value of the Vector4d.
Definition: Vector4d.hpp:566
Color< T > operator*(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:658
Color< T > operator/(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:686
bool operator>=(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1485
slip::Vector4d< unsigned int > Vector4d_ui
unsigned int alias
Definition: Vector4d.hpp:430
Color< T > operator-(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:630
const T & get_t() const
Accessor to the fourth dimension value of the Vector4d.
Definition: Vector4d.hpp:578
Provides some algorithms to compute norms.