Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
glfMatrix.hh
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS 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 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS 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 BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #ifndef __glfMatrix_hh__
26 #define __glfMatrix_hh__
27 
28 #include "glfCommon.hh"
29 #include <Base/Math/Matrix3x3.hh>
30 #include <Base/Math/Matrix4x4.hh>
31 #include <Geometry/ProjectionParametersPerspective.hh>
32 #include <Base/Math/Utils.hh>
33 
34 namespace BIAS {
35 
36  /**
37  * \brief A 4x4 matrix in native OpenGL format.
38  * \ingroup g_openglframework
39  * \author jkollmann
40  */
41  class BIASOpenGLFramework_EXPORT glfMatrix {
42  public:
43 
44  /**
45  * The constructor leaves the matrix undefined!
46  */
47  glfMatrix();
48 
49  /**
50  * Constructor that initializes the entries of the matrix.
51  */
52  glfMatrix(GLfloat m0, GLfloat m1, GLfloat m2, GLfloat m3,
53  GLfloat m4, GLfloat m5, GLfloat m6, GLfloat m7,
54  GLfloat m8, GLfloat m9, GLfloat m10, GLfloat m11,
55  GLfloat m12, GLfloat m13, GLfloat m14, GLfloat m15);
56 
57  virtual ~glfMatrix() {}
58 
59  /**
60  * \name Initialization methods similar to glIdentity, glRotate etc.
61  */
62  //@{
63  void MakeIdentity();
64  void MakeRotation(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
65  void MakeTranslation(GLfloat x, GLfloat y, GLfloat z);
66  void MakeScalation(GLfloat x, GLfloat y, GLfloat z);
67  void MakeFrustum(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal);
68  void MakeOrtho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal);
69  void MakePerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar);
70  void MakeLookAt(GLfloat eyeX, GLfloat eyeY, GLfloat eyeZ,
71  GLfloat centerX, GLfloat centerY, GLfloat centerZ,
72  GLfloat upX, GLfloat upY, GLfloat upZ);
73  //@}
74 
75  static unsigned int Matrix2DIndexToRep(unsigned int row, unsigned int column);
76 
77  /**
78  * Initializes the glf matrix from a BIAS matrix.
79  */
80  //@{
81  void Make(const Matrix4x4<float>& a);
82  void Make(const Matrix4x4<double>& a);
83  //@}
84 
85  /**
86  * Initializes the render matrix as an affine mapping.
87  */
88  //@{
89  void MakeAffine(const Matrix3x3<float>& r, const Vector3<float>& t);
90  void MakeAffine(const Matrix3x3<double>& r, const Vector3<double>& t);
91  //@}
92 
93  /**
94  * Computes the inverse of the matrix, assuming it is an affine transformation
95  * with an orthonormal linear part.
96  */
97  void MakeAffineInverse(const glfMatrix& a);
98 
99  /**
100  * Conversion from <code>ProjectionParametersPerspective</code>.
101  */
102  //@{
103  /** \param flip has to be used if a gl rendered texture is used but
104  * BIAS ProjectionParameters, since up and down interpretation is
105  * the other way around (got it?). flip does not have to be true
106  * if an BIAS image is uploaded without a previous call to
107  * BIAS::ImageBase::Flip(). (However it afterall depends on what you want to
108  * achieve!)
109  */
110  void MakeTextureMatrix(const ProjectionParametersPerspective& params,
111  bool flip = false);
112  void MakeViewMatrix(const ProjectionParametersBase& params);
113  void MakeViewMatrixNew(const ProjectionParametersBase& params);
114  void MakeProjectionMatrix(const ProjectionParametersPerspective& params,
115  GLfloat nearZZ, GLfloat farZ, bool useIdealK = false);
116  void MakeProjectionMatrix(ProjectionParametersPerspective params,
117  GLfloat nearZ, GLfloat farZ,
118  unsigned int x0, unsigned int y0,
119  unsigned int width, unsigned int height,
120  bool useIdealK = false);
121  void MakeProjectionMatrixNew(const ProjectionParametersPerspective& params,
122  GLfloat nearZ, GLfloat farZ,
123  unsigned int x0, unsigned int y0,
124  unsigned int width, unsigned int height,
125  bool useIdealK = false, bool flip = false);
126  void MakeProjectionMatrixNew(const ProjectionParametersPerspective& params,
127  GLfloat nearZ, GLfloat farZ, bool flip = false);
128  void MakeTextureMatrixNew(const ProjectionParametersPerspective& params, bool flip);
129  //@}
130 
131  /**
132  * Transforms a point by the matrix.
133  */
134  //@{
135  void TransformPoint(const Vector3<float>& in, Vector3<float>& out) const;
136  void TransformPoint(const Vector3<double>& in, Vector3<double>& out) const;
137  //@}
138 
139  /**
140  * \name Matrix multiplications.
141  */
142  //@{
143  void Multiply(const glfMatrix& a);
144  void operator*=(const glfMatrix& a);
145  glfMatrix operator*(const glfMatrix& a);
146  void Multiply(Vector4<float> vIn, Vector4<float>& vOut);
147  void Multiply(Vector4<double> vIn, Vector4<double>& vOut);
148  //@}
149 
150  /**
151  * Loads the matrix in OpenGL.
152  */
153  virtual void Load() const;
154 
155  /**
156  * The identity matrix.
157  */
158  static const glfMatrix IDENTITY;
159 
160  inline friend std::ostream& operator<<(std::ostream& s, const glfMatrix& m)
161  {
162  for (int i = 0; i < 4; i++) {
163  for (int j = 0; j < 4; j++) {
164  s << m.m[i+j*4] << " ";
165  }
166  s << std::endl;
167  }
168  return s;
169  }
170 
171  const GLfloat* GetArray() const { return m; }
172 
173  private:
174  GLfloat m[16];
175  };
176 
177 } // namespace BIAS
178 
179 #endif // __glfMatrix_hh__
static const glfMatrix IDENTITY
The identity matrix.
Definition: glfMatrix.hh:158
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
friend std::ostream & operator<<(std::ostream &s, const glfMatrix &m)
Definition: glfMatrix.hh:160
Vector2< T > & operator*=(Vector2< T > &vec, const T &scalar)
Multiplication operator with scalar argument.
Definition: Vector2.hh:873
is a &#39;fixed size&#39; quadratic matrix of dim.
Definition: Matrix.hh:54
DualQuaternion< T > operator*(const DualQuaternion< T > &l, const T &scalar)
A 4x4 matrix in native OpenGL format.
Definition: glfMatrix.hh:41
virtual ~glfMatrix()
Definition: glfMatrix.hh:57
is a &#39;fixed size&#39; quadratic matrix of dim.
Definition: Matrix4x4.hh:54
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
const GLfloat * GetArray() const
Definition: glfMatrix.hh:171