transformation.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2010-2011 Taneli Kalvas. All rights reserved.
6  *
7  * You can redistribute this software and/or modify it under the terms
8  * of the GNU General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this library (file "COPYING" included in the package);
19  * if not, write to the Free Software Foundation, Inc., 51 Franklin
20  * Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * If you have questions about your rights to use or distribute this
23  * software, please contact Berkeley Lab's Technology Transfer
24  * Department at TTD@lbl.gov. Other questions, comments and bug
25  * reports should be sent directly to the author via email at
26  * taneli.kalvas@jyu.fi.
27  *
28  * NOTICE. This software was developed under partial funding from the
29  * U.S. Department of Energy. As such, the U.S. Government has been
30  * granted for itself and others acting on its behalf a paid-up,
31  * nonexclusive, irrevocable, worldwide license in the Software to
32  * reproduce, prepare derivative works, and perform publicly and
33  * display publicly. Beginning five (5) years after the date
34  * permission to assert copyright is obtained from the U.S. Department
35  * of Energy, and subject to any subsequent five (5) year renewals,
36  * the U.S. Government is granted for itself and others acting on its
37  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
38  * the Software to reproduce, prepare derivative works, distribute
39  * copies to the public, perform publicly and display publicly, and to
40  * permit others to do so.
41  */
42 
43 #ifndef TRANSFORMATION_HPP
44 #define TRANSFORMATION_HPP 1
45 
46 
47 #include <string.h>
48 #include "vec3d.hpp"
49 #include "vec4d.hpp"
50 
51 
60 {
61 
62  double x[16]; /* Matrix data in row first order:
63  * 0 1 2 3
64  * 4 5 6 7
65  * 8 9 10 11
66  * 12 13 14 15
67  */
68 
69 public:
70 
74 
77  Transformation( double x11, double x12, double x13, double x14,
78  double x21, double x22, double x23, double x24,
79  double x31, double x32, double x33, double x34,
80  double x41, double x42, double x43, double x44 );
81 
84  Transformation( const Transformation &m );
85 
88  Transformation( std::istream &is );
89 
93 
94 
95 
96 
97 
100  double &operator[]( int i ) {
101  return( x[i] );
102  }
103 
106  const double &operator[]( int i ) const {
107  return( x[i] );
108  }
109 
112  double determinant( void ) const;
113 
116  Transformation inverse( void ) const;
117 
120  const Transformation &operator*=( double s );
121 
130  Transformation operator*( const Transformation &m ) const;
131 
136  Vec4D operator*( const Vec4D &v ) const;
137 
143  Vec4D operator%( const Vec4D &v ) const;
144 
145 
146 
147 
148 
151  Vec4D transform( const Vec4D &xin ) const;
152 
153 
154 
155 
161  Vec3D transform_point( const Vec3D &xin ) const;
162 
172  Vec3D inv_transform_point( const Vec3D &xin ) const;
173 
174 
175 
176 
182  Vec3D transform_vector( const Vec3D &xin ) const;
183 
193  Vec3D inv_transform_vector( const Vec3D &xin ) const;
194 
195 
196 
197 
202  void reset( void );
203 
209  void translate( const Vec3D &d );
210 
216  void scale( const Vec3D &s );
217 
225  void rotate_x( double a );
226 
234  void rotate_y( double a );
235 
243  void rotate_z( double a );
244 
247  static Transformation unity( void );
248 
251  static Transformation translation( const Vec3D &d );
252 
255  static Transformation scaling( const Vec3D &s );
256 
259  static Transformation rotation_x( double a );
260 
263  static Transformation rotation_y( double a );
264 
267  static Transformation rotation_z( double a );
268 
271  friend std::ostream &operator<<( std::ostream &os, const Transformation &t );
272 
275  void save( const std::string &filename ) const;
276 
279  void save( std::ostream &os ) const;
280 
283  void debug_print( std::ostream &os ) const;
284 };
285 
286 
287 
288 
289 #endif
290 
291