gpuhelper.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_GPUHELPER_H
11 #define EIGEN_GPUHELPER_H
12 
13 #include <Eigen/Geometry>
14 #include <GL/gl.h>
15 #include <vector>
16 
17 using namespace Eigen;
18 
19 typedef Vector4f Color;
20 
21 class GpuHelper
22 {
23  public:
24 
25  GpuHelper();
26 
27  ~GpuHelper();
28 
29  enum ProjectionMode2D { PM_Normalized = 1, PM_Viewport = 2 };
30  void pushProjectionMode2D(ProjectionMode2D pm);
31  void popProjectionMode2D();
32 
40  template<typename Scalar, int _Flags>
41  void multMatrix(const Matrix<Scalar,4,4, _Flags, 4,4>& mat, GLenum matrixTarget);
42 
50  template<typename Scalar, int _Flags>
51  void loadMatrix(const Eigen::Matrix<Scalar,4,4, _Flags, 4,4>& mat, GLenum matrixTarget);
52 
53  template<typename Scalar, typename Derived>
54  void loadMatrix(
56  GLenum matrixTarget);
57 
63  inline void forceMatrixTarget(GLenum matrixTarget) {glMatrixMode(mCurrentMatrixTarget=matrixTarget);}
64 
65  inline void setMatrixTarget(GLenum matrixTarget);
66 
69  template<typename Scalar, int _Flags>
70  inline void pushMatrix(const Matrix<Scalar,4,4, _Flags, 4,4>& mat, GLenum matrixTarget);
71 
72  template<typename Scalar, typename Derived>
73  void pushMatrix(
75  GLenum matrixTarget);
76 
79  inline void pushMatrix(GLenum matrixTarget);
80 
83  inline void popMatrix(GLenum matrixTarget);
84 
85  void drawVector(const Vector3f& position, const Vector3f& vec, const Color& color, float aspect = 50.);
86  void drawVectorBox(const Vector3f& position, const Vector3f& vec, const Color& color, float aspect = 50.);
87  void drawUnitCube(void);
88  void drawUnitSphere(int level=0);
89 
91  inline void draw(GLenum mode, uint nofElement);
92 
94  inline void draw(GLenum mode, uint start, uint end);
95 
97  inline void draw(GLenum mode, const std::vector<uint>* pIndexes);
98 
99 protected:
100 
101  void update(void);
102 
104  int mVpWidth, mVpHeight;
107 };
108 
111 extern GpuHelper gpu;
112 
113 
116 template<bool RowMajor, int _Flags> struct GlMatrixHelper;
117 
118 template<int _Flags> struct GlMatrixHelper<false,_Flags>
119 {
120  static void loadMatrix(const Matrix<float, 4,4, _Flags, 4,4>& mat) { glLoadMatrixf(mat.data()); }
121  static void loadMatrix(const Matrix<double,4,4, _Flags, 4,4>& mat) { glLoadMatrixd(mat.data()); }
122  static void multMatrix(const Matrix<float, 4,4, _Flags, 4,4>& mat) { glMultMatrixf(mat.data()); }
123  static void multMatrix(const Matrix<double,4,4, _Flags, 4,4>& mat) { glMultMatrixd(mat.data()); }
124 };
125 
126 template<int _Flags> struct GlMatrixHelper<true,_Flags>
127 {
128  static void loadMatrix(const Matrix<float, 4,4, _Flags, 4,4>& mat) { glLoadMatrixf(mat.transpose().eval().data()); }
129  static void loadMatrix(const Matrix<double,4,4, _Flags, 4,4>& mat) { glLoadMatrixd(mat.transpose().eval().data()); }
130  static void multMatrix(const Matrix<float, 4,4, _Flags, 4,4>& mat) { glMultMatrixf(mat.transpose().eval().data()); }
131  static void multMatrix(const Matrix<double,4,4, _Flags, 4,4>& mat) { glMultMatrixd(mat.transpose().eval().data()); }
132 };
133 
134 inline void GpuHelper::setMatrixTarget(GLenum matrixTarget)
135 {
136  if (matrixTarget != mCurrentMatrixTarget)
137  glMatrixMode(mCurrentMatrixTarget=matrixTarget);
138 }
139 
140 template<typename Scalar, int _Flags>
142 {
143  setMatrixTarget(matrixTarget);
145 }
146 
147 template<typename Scalar, typename Derived>
150  GLenum matrixTarget)
151 {
152  setMatrixTarget(matrixTarget);
153  glLoadIdentity();
154 }
155 
156 template<typename Scalar, int _Flags>
158 {
159  setMatrixTarget(matrixTarget);
160  GlMatrixHelper<(_Flags&Eigen::RowMajorBit)!=0, _Flags>::loadMatrix(mat);
161 }
162 
163 inline void GpuHelper::pushMatrix(GLenum matrixTarget)
164 {
165  setMatrixTarget(matrixTarget);
166  glPushMatrix();
167 }
168 
169 template<typename Scalar, int _Flags>
170 inline void GpuHelper::pushMatrix(const Matrix<Scalar,4,4, _Flags, 4,4>& mat, GLenum matrixTarget)
171 {
172  pushMatrix(matrixTarget);
174 }
175 
176 template<typename Scalar, typename Derived>
179  GLenum matrixTarget)
180 {
181  pushMatrix(matrixTarget);
182  glLoadIdentity();
183 }
184 
185 inline void GpuHelper::popMatrix(GLenum matrixTarget)
186 {
187  setMatrixTarget(matrixTarget);
188  glPopMatrix();
189 }
190 
191 inline void GpuHelper::draw(GLenum mode, uint nofElement)
192 {
193  glDrawArrays(mode, 0, nofElement);
194 }
195 
196 
197 inline void GpuHelper::draw(GLenum mode, const std::vector<uint>* pIndexes)
198 {
199  glDrawElements(mode, pIndexes->size(), GL_UNSIGNED_INT, &(pIndexes->front()));
200 }
201 
202 inline void GpuHelper::draw(GLenum mode, uint start, uint end)
203 {
204  glDrawArrays(mode, start, end-start);
205 }
206 
207 #endif // EIGEN_GPUHELPER_H
GpuHelper::forceMatrixTarget
void forceMatrixTarget(GLenum matrixTarget)
Definition: gpuhelper.h:63
GlMatrixHelper< true, _Flags >::loadMatrix
static void loadMatrix(const Matrix< float, 4, 4, _Flags, 4, 4 > &mat)
Definition: gpuhelper.h:128
relicense.update
def update(text)
Definition: relicense.py:46
Eigen::internal::scalar_identity_op
Definition: NullaryFunctors.h:31
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
GlMatrixHelper< true, _Flags >::multMatrix
static void multMatrix(const Matrix< float, 4, 4, _Flags, 4, 4 > &mat)
Definition: gpuhelper.h:130
GpuHelper::mInitialized
bool mInitialized
Definition: gpuhelper.h:106
GlMatrixHelper< false, _Flags >::loadMatrix
static void loadMatrix(const Matrix< float, 4, 4, _Flags, 4, 4 > &mat)
Definition: gpuhelper.h:120
GlMatrixHelper< true, _Flags >::loadMatrix
static void loadMatrix(const Matrix< double, 4, 4, _Flags, 4, 4 > &mat)
Definition: gpuhelper.h:129
Eigen::RowMajorBit
const unsigned int RowMajorBit
Definition: Constants.h:66
GpuHelper::mColorBufferId
GLuint mColorBufferId
Definition: gpuhelper.h:103
GpuHelper::ProjectionMode2D
ProjectionMode2D
Definition: gpuhelper.h:29
mat
MatrixXf mat
Definition: Tutorial_AdvancedInitialization_CommaTemporary.cpp:1
GlMatrixHelper< false, _Flags >::loadMatrix
static void loadMatrix(const Matrix< double, 4, 4, _Flags, 4, 4 > &mat)
Definition: gpuhelper.h:121
GlMatrixHelper< true, _Flags >::multMatrix
static void multMatrix(const Matrix< double, 4, 4, _Flags, 4, 4 > &mat)
Definition: gpuhelper.h:131
Eigen::CwiseNullaryOp
Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:60
gpu
GpuHelper gpu
Definition: gpuhelper.cpp:18
mode
static const DiscreteKey mode(modeKey, 2)
GpuHelper::draw
void draw(GLenum mode, uint nofElement)
draw the nofElement first elements
Definition: gpuhelper.h:191
gtsam.examples.SFMExample_bal.level
level
Definition: SFMExample_bal.py:24
GlMatrixHelper< false, _Flags >::multMatrix
static void multMatrix(const Matrix< double, 4, 4, _Flags, 4, 4 > &mat)
Definition: gpuhelper.h:123
GpuHelper::popMatrix
void popMatrix(GLenum matrixTarget)
Definition: gpuhelper.h:185
GlMatrixHelper< false, _Flags >::multMatrix
static void multMatrix(const Matrix< float, 4, 4, _Flags, 4, 4 > &mat)
Definition: gpuhelper.h:122
Color
Vector4f Color
Definition: gpuhelper.h:19
pm
Matrix4d pm
Definition: HessenbergDecomposition_packedMatrix.cpp:4
GpuHelper::mVpWidth
int mVpWidth
Definition: gpuhelper.h:104
gtsam::internal::position
Point3 position(const NavState &X, OptionalJacobian< 3, 9 > H)
Definition: navigation/expressions.h:25
GpuHelper::setMatrixTarget
void setMatrixTarget(GLenum matrixTarget)
Definition: gpuhelper.h:134
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
GlMatrixHelper
Definition: gpuhelper.h:116
Eigen::placeholders::end
static const EIGEN_DEPRECATED end_t end
Definition: IndexedViewHelper.h:181
GpuHelper::pushMatrix
void pushMatrix(const Matrix< Scalar, 4, 4, _Flags, 4, 4 > &mat, GLenum matrixTarget)
Definition: gpuhelper.h:170
GpuHelper::mCurrentMatrixTarget
GLenum mCurrentMatrixTarget
Definition: gpuhelper.h:105
GpuHelper::multMatrix
void multMatrix(const Matrix< Scalar, 4, 4, _Flags, 4, 4 > &mat, GLenum matrixTarget)
Definition: gpuhelper.h:141
GpuHelper
Definition: gpuhelper.h:21
GpuHelper::loadMatrix
void loadMatrix(const Eigen::Matrix< Scalar, 4, 4, _Flags, 4, 4 > &mat, GLenum matrixTarget)
Definition: gpuhelper.h:157


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:23