A.I.M.S


trieder.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 /*
35  * 3 axis trieder class
36  */
37 #ifndef AIMS_MATH_TRIEDER_H
38 #define AIMS_MATH_TRIEDER_H
39 
41 #include <aims/vector/vector.h>
42 #include <fstream>
43 #include <math.h>
44 
45 class Trieder;
46 
47 AIMSDATA_API int operator == (const Trieder& thing1, const Trieder& thing2);
48 AIMSDATA_API std::ostream& operator << (std::ostream& os,
49  const Trieder& thing);
51 
52 
54 {
55  public:
56  Trieder() { }
57  Trieder( const Point3df& dirX, const Point3df& dirY, const Point3df& dirZ )
58  {
59  _dir[ 0 ] = dirX;
60  _dir[ 1 ] = dirY;
61  _dir[ 2 ] = dirZ;
62  }
63  Trieder( const Point3df& angle );
64  ~Trieder() { }
65 
66  const Point3df& dirX() const { return _dir[ 0 ]; }
67  const Point3df& dirY() const { return _dir[ 1 ]; }
68  const Point3df& dirZ() const { return _dir[ 2 ]; }
69  const Point3df& operator []( int i ) const { return _dir[ i ]; }
70 
71  Point3df& dirX() { return _dir[ 0 ]; }
72  Point3df& dirY() { return _dir[ 1 ]; }
73  Point3df& dirZ() { return _dir[ 2 ]; }
74  Point3df& operator []( int i ) { return _dir[ i ]; }
75 
76  float dot(const Trieder& other) const;
77 
78  friend
79  int operator == (const Trieder& thing1, const Trieder& thing2);
80 
81  friend
82  std::ostream& operator << (std::ostream& os, const Trieder& thing);
83 
84  protected:
85  Point3df _dir[ 3 ];
86 };
87 
88 
89 //
90 // -> -> ->
91 // [ e1 ; e2 ; e3 ] = Rz * Ry * Rx
92 //
93 // [ 1 0 0 ]
94 // Rx = [ 0 cos(thetax) -sin(thetax) ]
95 // [ 0 sin(thetax) cos(thetax) ]
96 //
97 // [ cos(thetay) 0 -sin(thetay) ]
98 // Ry = [ 0 1 0 ]
99 // [ sin(thetay) 0 cos(thetay) ]
100 //
101 // [ cos(thetaz) -sin(thetaz) 0 ]
102 // Rz = [ sin(thetaz) cos(thetaz) 0 ]
103 // [ 0 0 1 ]
104 //
105 
106 inline
107 Trieder::Trieder( const Point3df& angle )
108 {
109  _dir[ 0 ].item(0) = cos( angle.item(1) ) * cos( angle.item(2) );
110  _dir[ 0 ].item(1) = cos( angle.item(1) ) * sin( angle.item(2) );
111  _dir[ 0 ].item(2) = sin( angle.item(1) );
112 
113  _dir[ 1 ].item(0) = - sin( angle.item(0) ) * sin( angle.item(1) )
114  * cos( angle.item(2) )
115  - cos( angle.item(0) ) * sin( angle.item(2) );
116  _dir[ 1 ].item(1) = - sin( angle.item(0) ) * sin( angle.item(1) )
117  * sin( angle.item(2) )
118  + cos( angle.item(0) ) * cos( angle.item(2) );
119  _dir[ 1 ].item(2) = sin( angle.item(0) ) * cos( angle.item(1) );
120 
121  _dir[ 2 ].item(0) = - cos( angle.item(0) ) * sin( angle.item(1) )
122  * cos( angle.item(2) )
123  + sin( angle.item(0) ) * sin( angle.item(2) );
124  _dir[ 2 ].item(1) = - cos( angle.item(0) ) * sin( angle.item(1) )
125  * sin( angle.item(2) )
126  - sin( angle.item(0) ) * cos( angle.item(2) );
127  _dir[ 2 ].item(2) = cos( angle.item(0) ) * cos( angle.item(1) );
128 }
129 
130 
131 inline
132 float Trieder::dot(const Trieder& other) const
133 {
134  return _dir[ 0 ].dot( other.dirX() ) +
135  _dir[ 1 ].dot( other.dirY() ) +
136  _dir[ 2 ].dot( other.dirZ() ) ;
137 }
138 
139 
140 inline
141 int operator == (const Trieder& thing1, const Trieder& thing2)
142 {
143  return thing1.dirX() == thing2.dirX() &&
144  thing1.dirY() == thing2.dirY() &&
145  thing1.dirZ() == thing2.dirZ();
146 }
147 
148 
149 inline
150 std::ostream& operator << (std::ostream& os, const Trieder& thing)
151 {
152  os << "{dirX=" << thing.dirX()
153  << ",dirY=" << thing.dirY()
154  << ",dirZ=" << thing.dirZ()
155  << "}";
156  return os;
157 }
158 
159 
160 
161 #endif
AIMSDATA_API Point3df AimsRotationAngle(const Trieder &trieder)
#define AIMSDATA_API
AIMSDATA_API int operator==(const Trieder &thing1, const Trieder &thing2)
Definition: trieder.h:141
Trieder()
Definition: trieder.h:56
AIMSDATA_API std::ostream & operator<<(std::ostream &os, const Trieder &thing)
Definition: trieder.h:150
~Trieder()
Definition: trieder.h:64
const Point3df & dirX() const
Definition: trieder.h:66
Point3df & dirY()
Definition: trieder.h:72
Point3df & dirX()
Definition: trieder.h:71
float dot(const Trieder &other) const
Definition: trieder.h:132
Point3df _dir[3]
Definition: trieder.h:85
Point3df & dirZ()
Definition: trieder.h:73
const Point3df & dirZ() const
Definition: trieder.h:68
const T & item(int d) const
Get a const reference to the dth item.
Definition: vector.h:605
const Point3df & dirY() const
Definition: trieder.h:67
Trieder(const Point3df &dirX, const Point3df &dirY, const Point3df &dirZ)
Definition: trieder.h:57
T dot(const AimsVector< T, D > &other) const
Get the dot product between 2 vectors.
Definition: vector.h:698