SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Vector3d.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 
67 
68 
75 #ifndef SLIP_VECTOR3D_HPP
76 #define SLIP_VECTOR3D_HPP
77 
78 #include <iostream>
79 #include <iterator>
80 #include <cassert>
81 #include <cstddef>
82 #include <algorithm>
83 #include <numeric>
84 #include <string>
85 #include "KVector.hpp"
86 #include "norms.hpp"
87 
88 #include <boost/serialization/access.hpp>
89 #include <boost/serialization/split_member.hpp>
90 #include <boost/serialization/version.hpp>
91 
92 namespace slip
93 {
94 
95 template <typename T>
96 struct Vector3d;
97 
98 template <typename T>
99 bool operator<(const Vector3d<T>& x, const Vector3d<T>& y);
100 
101 template <typename T>
102 bool operator>(const Vector3d<T>& x, const Vector3d<T>& y);
103 
104 template <typename T>
105 bool operator<=(const Vector3d<T>& x, const Vector3d<T>& y);
106 
107 template <typename T>
108 bool operator>=(const Vector3d<T>& x, const Vector3d<T>& y);
109 
121 template <typename T>
122 struct Vector3d : public kvector<T,3>
123 {
124 
125  typedef Vector3d<T> self;
126  typedef T value_type;
127  typedef value_type* pointer;
128  typedef const value_type* const_pointer;
130  typedef const value_type& const_reference;
131 
132  typedef ptrdiff_t difference_type;
133  typedef std::size_t size_type;
134 
135  typedef pointer iterator;
137 
138 
143 
148  Vector3d();
149 
155  Vector3d(const T& val);
156 
164  Vector3d(const T& x1,
165  const T& x2,
166  const T& x3);
167 
173  Vector3d(const T* val);
174 
175 
181  Vector3d(const Vector3d<T>& rhs);
182 
183 
184 
191  self operator-() const;
192 
197 
198 
206  friend bool operator< <>(const Vector3d<T>& x, const Vector3d<T>& y);
207 
215  friend bool operator> <>(const Vector3d<T>& x, const Vector3d<T>& y);
216 
224  friend bool operator<= <>(const Vector3d<T>& x, const Vector3d<T>& y);
225 
233  friend bool operator> <>(const Vector3d<T>& x, const Vector3d<T>& y);
234 
235 
246  const T& get_x1() const;
251  const T& get_x() const;
256  const T& u() const;
257 
262  const T& get_x2() const;
267  const T& get_y() const;
272  const T& v() const;
273 
274 
279  const T& get_x3() const;
284  const T& get_z() const;
289  const T& w() const;
290 
291 
292 
293 
294 
299  void set_x1(const T& x1);
304  void set_x(const T& r);
309  void u(const T& u_);
310 
311 
316  void set_x2(const T& x2);
321  void set_y(const T& g);
326  void v(const T& v_);
327 
328 
333  void set_x3(const T& x3);
338  void set_z(const T& r);
343  void w(const T& w_);
344 
345 
353  void set(const T& x1,
354  const T& x2,
355  const T& x3);
356 
357 
358 
371  self product(const self& other) const ;
379  std::string name() const;
380 
381 
382  private:
384  template<class Archive>
385  void save(Archive & ar, const unsigned int version) const
386  {
387  ar & boost::serialization::base_object<slip::kvector<T,3> >(*this);
388  }
389  template<class Archive>
390  void load(Archive & ar, const unsigned int version)
391  {
392  ar & boost::serialization::base_object<slip::kvector<T,3> >(*this);
393  }
394  BOOST_SERIALIZATION_SPLIT_MEMBER()
395 };
396 
417 
418 }//slip::
419 
420 namespace slip
421 {
422 
423  template<typename T>
424  inline
426  {
427  this->fill(T(0));
428  }
429 
430  template<typename T>
431  inline
432  Vector3d<T>::Vector3d(const T& val)
433  {
434  this->fill(val);
435  }
436 
437  template<typename T>
438  inline
440  const T& x2,
441  const T& x3)
442  {
443  (*this)[0] = x1;
444  (*this)[1] = x2;
445  (*this)[2] = x3;
446 
447  }
448 
449  template<typename T>
450  inline
451  Vector3d<T>::Vector3d(const T* val)
452  {
453  assert(val != 0);
454  this->fill(val);
455  }
456 
457 
458  template<typename T>
459  inline
461  {
462  *this = rhs;
463  }
464 
465  template<typename T>
466  inline
468  {
469  self tmp;
470  tmp[0] = -(*this)[0];
471  tmp[1] = -(*this)[1];
472  tmp[2] = -(*this)[2];
473 
474  return tmp;
475  }
477  /* @{ */
478  template<typename T>
479  inline
480  bool operator<(const Vector3d<T>& x,
481  const Vector3d<T>& y)
482  {
483  return (slip::Euclidean_norm<T>(x.begin(),x.end())
484  <
485  slip::Euclidean_norm<T>(y.begin(),y.end())
486  );
487  }
488 
489 
490 
491  template<typename T>
492  inline
493  bool operator>(const Vector3d<T>& x,
494  const Vector3d<T>& y)
495  {
496  return y < x;
497  }
498 
499  template<typename T>
500  inline
501  bool operator<=(const Vector3d<T>& x,
502  const Vector3d<T>& y)
503  {
504  return !(y < x);
505  }
506 
507  template<typename T>
508  inline
509  bool operator>=(const Vector3d<T>& x,
510  const Vector3d<T>& y)
511  {
512  return !(x < y);
513  }
514  /* @} */
515 
516  template<typename T>
517  inline
518  const T& Vector3d<T>::get_x1() const {return (*this)[0];}
519 
520  template<typename T>
521  inline
522  const T& Vector3d<T>::get_x() const {return (*this)[0];}
523 
524  template<typename T>
525  inline
526  const T& Vector3d<T>::u() const {return (*this)[0];}
527 
528 
529  template<typename T>
530  inline
531  const T& Vector3d<T>::get_x2() const {return (*this)[1];}
532 
533  template<typename T>
534  inline
535  const T& Vector3d<T>::get_y() const {return (*this)[1];}
536 
537  template<typename T>
538  inline
539  const T& Vector3d<T>::v() const {return (*this)[1];}
540 
541 
542  template<typename T>
543  inline
544  const T& Vector3d<T>::get_x3() const {return (*this)[2];}
545 
546  template<typename T>
547  inline
548  const T& Vector3d<T>::get_z() const {return (*this)[2];}
549 
550  template<typename T>
551  inline
552  const T& Vector3d<T>::w() const {return (*this)[2];}
553 
554 
555  template<typename T>
556  inline
557  void Vector3d<T>::set_x1(const T& x1){(*this)[0] = x1;}
558 
559  template<typename T>
560  inline
561  void Vector3d<T>::set_x(const T& x){(*this)[0] = x;}
562 
563  template<typename T>
564  inline
565  void Vector3d<T>::u(const T& x){(*this)[0] = x;}
566 
567 
568  template<typename T>
569  inline
570  void Vector3d<T>::set_x2(const T& x2){(*this)[1] = x2;}
571 
572  template<typename T>
573  inline
574  void Vector3d<T>::set_y(const T& y){(*this)[1] = y;}
575 
576  template<typename T>
577  inline
578  void Vector3d<T>::v(const T& y){(*this)[1] = y;}
579 
580 
581  template<typename T>
582  inline
583  void Vector3d<T>::set_x3(const T& x3){(*this)[2] = x3;}
584 
585  template<typename T>
586  inline
587  void Vector3d<T>::set_z(const T& z){(*this)[2] = z;}
588 
589  template<typename T>
590  inline
591  void Vector3d<T>::w(const T& w_){(*this)[2] = w_;}
592 
593 
594  template<typename T>
595  inline
596  void Vector3d<T>::set(const T& x1,
597  const T& x2,
598  const T& x3)
599  {
600  (*this)[0] = x1;
601  (*this)[1] = x2;
602  (*this)[2] = x3;
603 
604  }
605 
606  template<typename T>
607  inline
609  {
610  Vector3d<T> tmp(this->size());
611  tmp[0] = ( ((*this)[1] * other[2]) - ((*this)[2] * other[1]) );
612  tmp[1] = ( ((*this)[2] * other[0]) - ((*this)[0] * other[2]) );
613  tmp[2] = ( ((*this)[0] * other[1]) - ((*this)[1] * other[0]) );
614  return tmp;
615  }
616 
617 
618 }//slip::
619 
620 
621 namespace slip
622 {
623 template<typename T>
624 inline
626  const Vector3d<T>& V2)
627 {
628  Vector3d<T> tmp;
629  tmp[0] = V1[0] + V2[0];
630  tmp[1] = V1[1] + V2[1];
631  tmp[2] = V1[2] + V2[2];
632  return tmp;
633 }
634 
635 template<typename T>
636 inline
638  const T& val)
639 {
640  Vector3d<T> tmp = V1;
641  tmp+=val;
642  return tmp;
643 }
644 
645 template<typename T>
646 inline
647 Vector3d<T> operator+(const T& val,
648  const Vector3d<T>& V1)
649 {
650  return V1 + val;
651 }
652 
653 template<typename T>
654 inline
656  const Vector3d<T>& V2)
657 {
658  Vector3d<T> tmp;
659  tmp[0] = V1[0] - V2[0];
660  tmp[1] = V1[1] - V2[1];
661  tmp[2] = V1[2] - V2[2];
662  return tmp;
663 }
664 
665 template<typename T>
666 inline
668  const T& val)
669 {
670  Vector3d<T> tmp = V1;
671  tmp-=val;
672  return tmp;
673 }
674 
675 template<typename T>
676 inline
677 Vector3d<T> operator-(const T& val,
678  const Vector3d<T>& V1)
679 {
680  Vector3d<T> tmp;
681  tmp[0] = val - V1[0];
682  tmp[1] = val - V1[1];
683  tmp[2] = val - V1[2];
684  return tmp;
685 }
686 
687 
688 template<typename T>
689 inline
691  const Vector3d<T>& V2)
692 {
693  Vector3d<T> tmp;
694  tmp[0] = V1[0] * V2[0];
695  tmp[1] = V1[1] * V2[1];
696  tmp[2] = V1[2] * V2[2];
697 
698  return tmp;
699 }
700 
701 template<typename T>
702 inline
704  const T& val)
705 {
706  Vector3d<T> tmp = V1;
707  tmp*=val;
708  return tmp;
709 }
710 
711 template<typename T>
712 inline
713 Vector3d<T> operator*(const T& val,
714  const Vector3d<T>& V1)
715 {
716  return V1 * val;
717 }
718 
719 template<typename T>
720 inline
722  const Vector3d<T>& V2)
723 {
724  Vector3d<T> tmp;
725  tmp[0] = V1[0] / V2[0];
726  tmp[1] = V1[1] / V2[1];
727  tmp[2] = V1[2] / V2[2];
728  return tmp;
729 }
730 
731 template<typename T>
732 inline
734  const T& val)
735 {
736  Vector3d<T> tmp = V1;
737  tmp/=val;
738  return tmp;
739 }
740 
741 template<typename T>
742 inline
743 std::string
744 Vector3d<T>::name() const {return "Vector3d";}
745 
746 
747 }//slip::
748 
749 #endif //SLIP_VECTOR3D_HPP
slip::Vector3d< unsigned char > Vector3d_uc
unsigned char alias
Definition: Vector3d.hpp:416
slip::Vector3d< unsigned short > Vector3d_us
unsigned long alias
Definition: Vector3d.hpp:408
const T & get_z() const
Accessor to the third dimension value of the Vector3d.
Definition: Vector3d.hpp:548
const_pointer const_iterator
Definition: Vector3d.hpp:136
const T & get_y() const
Accessor to the second dimension value of the Vector3d.
Definition: Vector3d.hpp:535
This is a linear (one-dimensional) static vector. This container statisfies the RandomAccessContainer...
Definition: KVector.hpp:100
This is a Vector3d struct. It is a specialization of kvector. It implements some specific 3d operatio...
Definition: Vector3d.hpp:96
void set_x2(const T &x2)
Mutator of the second dimension value of the Vector3d.
Definition: Vector3d.hpp:570
Color< T > operator+(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:602
slip::Vector3d< float > Vector3d_f
float alias
Definition: Vector3d.hpp:400
const T & get_x() const
Accessor to the first dimension value of the Vector3d.
Definition: Vector3d.hpp:522
value_type & reference
Definition: Vector3d.hpp:129
self operator-() const
Definition: Vector3d.hpp:467
const T & get_x1() const
Accessor to the first dimension value of the Vector3d.
Definition: Vector3d.hpp:518
void set_x3(const T &x3)
Mutator of the third dimension value of the Vector3d.
Definition: Vector3d.hpp:583
bool operator>(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1469
const value_type * const_pointer
Definition: Vector3d.hpp:128
void set_y(const T &g)
Mutator of the second dimension value of the Vector3d.
Definition: Vector3d.hpp:574
slip::Vector3d< long > Vector3d_l
long alias
Definition: Vector3d.hpp:402
slip::Vector3d< char > Vector3d_c
char alias
Definition: Vector3d.hpp:414
slip::Vector3d< double > Vector3d_d
double alias
Definition: Vector3d.hpp:398
const T & get_x2() const
Accessor to the second dimension value of the Vector3d.
Definition: Vector3d.hpp:531
Vector3d()
Default constructor init all the components to 0.
Definition: Vector3d.hpp:425
void set_x(const T &r)
Mutator of the first dimension value of the Vector3d.
Definition: Vector3d.hpp:561
const T & v() const
Accessor to the second dimension value of the Vector3d.
Definition: Vector3d.hpp:539
const value_type & const_reference
Definition: Vector3d.hpp:130
pointer iterator
Definition: Vector3d.hpp:135
slip::Vector3d< unsigned int > Vector3d_ui
unsigned int alias
Definition: Vector3d.hpp:412
ptrdiff_t difference_type
Definition: Vector3d.hpp:132
Provides a class to manipulate static and generic vectors.
std::string name() const
Returns the name of the class.
Definition: Vector3d.hpp:744
slip::Vector3d< int > Vector3d_i
int alias
Definition: Vector3d.hpp:410
void set_z(const T &r)
Mutator of the third dimension value of the Vector3d.
Definition: Vector3d.hpp:587
const T & u() const
Accessor to the first dimension value of the Vector3d.
Definition: Vector3d.hpp:526
self product(const self &other) const
Computes the vector cross product betwin the current Vector3d and the Vector3d other.
Definition: Vector3d.hpp:608
slip::Vector3d< short > Vector3d_s
short alias
Definition: Vector3d.hpp:406
value_type * pointer
Definition: Vector3d.hpp:127
const T & get_x3() const
Accessor to the third dimension value of the Vector3d.
Definition: Vector3d.hpp:544
const T & w() const
Accessor to the third dimension value of the Vector3d.
Definition: Vector3d.hpp:552
std::size_t size_type
Definition: Vector3d.hpp:133
slip::Vector3d< unsigned long > Vector3d_ul
unsigned long alias
Definition: Vector3d.hpp:404
void set_x1(const T &x1)
Mutator of the first dimension value of the Vector3d.
Definition: Vector3d.hpp:557
Color< T > operator*(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:658
void set(const T &x1, const T &x2, const T &x3)
Mutator of the three dimension values of the Vector3d.
Definition: Vector3d.hpp:596
Color< T > operator/(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:686
friend class boost::serialization::access
Definition: Vector3d.hpp:383
bool operator>=(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1485
Color< T > operator-(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:630
Provides some algorithms to compute norms.