OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WGridTransformOrtho.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut 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 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut 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 OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WGRIDTRANSFORMORTHO_H
26 #define WGRIDTRANSFORMORTHO_H
27 
28 #include "../common/math/WMatrix.h"
29 #include "../common/math/linearAlgebra/WLinearAlgebra.h"
30 
31 #include "WExportDataHandler.h"
32 
33 /**
34  * Implements an orthogonal grid transformation.
35  *
36  * \class WGridTransformOrtho
37  */
39 {
40 public:
41  /**
42  * Constructs an identity transform.
43  */
45 
46  /**
47  * Construct a transformation that scales the grid space.
48  * \param scaleX The scale in the x-direction.
49  * \param scaleY The scale in the y-direction.
50  * \param scaleZ The scale in the z-direction.
51  */
52  WGridTransformOrtho( double scaleX, double scaleY, double scaleZ );
53 
54  /**
55  * Construct a transformation from a transformation matrix. The provided matrix
56  * represents the transformation from grid to world space.
57  * \param mat The matrix.
58  */
59  WGridTransformOrtho( WMatrix< double > const& mat ); // NOLINT
60 
61  /**
62  * Destructor.
63  */
65 
66  /**
67  * Transforms a position from grid space to world space.
68  * \param position The position in grid space.
69  * \return The same position in world space.
70  */
71  WVector3d positionToWorldSpace( WVector3d const& position ) const;
72 
73  /**
74  * Transforms a position from world space to grid space.
75  * \param position The position in world space.
76  * \return The same position in grid space.
77  */
78  WVector3d positionToGridSpace( WVector3d const& position ) const;
79 
80  /**
81  * Transforms a direction from grid space to world space.
82  * \param direction The direction in grid space.
83  * \return The same direction in world space.
84  */
85  WVector3d directionToWorldSpace( WVector3d const& direction ) const;
86 
87  /**
88  * Transforms a direction from world space to grid space.
89  * \param direction The position in world space.
90  * \return The same position in grid space.
91  */
92  WVector3d directionToGridSpace( WVector3d const& direction ) const;
93 
94  /**
95  * Returns the distance between samples in x direction.
96  * \return The distance between samples in x direction.
97  */
98  double getOffsetX() const;
99 
100  /**
101  * Returns the distance between samples in y direction.
102  * \return The distance between samples in y direction.
103  */
104  double getOffsetY() const;
105 
106  /**
107  * Returns the distance between samples in z direction.
108  * \return The distance between samples in z direction.
109  */
110  double getOffsetZ() const;
111 
112  /**
113  * Returns the vector determining the direction of samples in x direction.
114  * Adding this vector to a grid position in world coordinates yields the position of the next sample
115  * along the grids (world coordinate) x-axis.
116  * \return The vector determining the direction of samples in x direction.
117  */
118  WVector3d getDirectionX() const;
119 
120  /**
121  * Returns the vector determining the direction of samples in y direction.
122  * Adding this vector to a grid position in world coordinates yields the position of the next sample
123  * along the grids (world coordinate) y-axis.
124  * \return The vector determining the direction of samples in y direction.
125  */
126  WVector3d getDirectionY() const;
127 
128  /**
129  * Returns the vector determining the direction of samples in z direction.
130  * Adding this vector to a grid position in world coordinates yields the position of the next sample
131  * along the grids (world coordinate) z-axis.
132  * \return The vector determining the direction of samples in z direction.
133  */
134  WVector3d getDirectionZ() const;
135 
136  /**
137  * Returns the vector determining the unit (normalized) direction of samples in x direction.
138  * \return The vector determining the unit (normalized) direction of samples in x direction.
139  */
140  WVector3d getUnitDirectionX() const;
141 
142  /**
143  * Returns the vector determining the unit (normalized) direction of samples in y direction.
144  * \return The vector determining the unit (normalized) direction of samples in y direction.
145  */
146  WVector3d getUnitDirectionY() const;
147 
148  /**
149  * Returns the vector determining the unit (normalized) direction of samples in z direction.
150  * \return The vector determining the unit (normalized) direction of samples in z direction.
151  */
152  WVector3d getUnitDirectionZ() const;
153 
154  /**
155  * Returns the position of the origin of the grid.
156  * \return The position of the origin of the grid.
157  */
158  WPosition getOrigin() const;
159 
160  /**
161  * Returns a 4x4 matrix that represents the grid's transformaion.
162  * \return The grid's transformation.
163  */
164  // NOTE: this is temporary and should be removed as soon as all modules are
165  // adapted to the grid transform object
166  WMatrix< double > getTransformationMatrix() const;
167 
168  /**
169  * Cast the transformation to the corresponding 4x4 matrix.
170  *
171  * \return the matrix representing the transform
172  */
173  operator WMatrix4d() const;
174 
175  /**
176  * Check if this transform does not include a rotation.
177  *
178  * \return True, if this transform only scales and translates.
179  */
180  bool isNotRotated() const;
181 
182  /**
183  * Translate by a vector.
184  *
185  * \param vec The vector.
186  */
187  template< typename VecType >
188  void translate( VecType const& vec );
189 
190  /**
191  * Scale the transform.
192  *
193  * \param scale A vector of scaling coeffs for the 3 directions.
194  */
195  template< typename VecType >
196  void scale( VecType const& scale );
197 
198 private:
199  //! normalized direction of the grid's x-axis in world coordinates
201 
202  //! normalized direction of the grid's y-axis in world coordinates
204 
205  //! normalized direction of the grid's z-axis in world coordinates
207 
208  //! the scaling factors for the 3 axes, i.e. the distance between samples
210 
211  //! the origin of the grid in world coordinates
213 };
214 
215 template< typename VecType >
216 void WGridTransformOrtho::translate( VecType const& vec )
217 {
218  m_origin[ 0 ] += vec[ 0 ];
219  m_origin[ 1 ] += vec[ 1 ];
220  m_origin[ 2 ] += vec[ 2 ];
221 }
222 
223 template< typename VecType >
224 void WGridTransformOrtho::scale( VecType const& scale )
225 {
226  m_scaling[ 0 ] *= scale[ 0 ];
227  m_scaling[ 1 ] *= scale[ 1 ];
228  m_scaling[ 2 ] *= scale[ 2 ];
229 }
230 
231 #endif // WGRIDTRANSFORMORTHO_H