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);
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
void draw(GLenum mode, uint nofElement)
draw the nofElement first elements
Definition: gpuhelper.h:191
Generic expression of a matrix where all coefficients are defined by a functor.
GLenum mCurrentMatrixTarget
Definition: gpuhelper.h:105
bool mInitialized
Definition: gpuhelper.h:106
void forceMatrixTarget(GLenum matrixTarget)
Definition: gpuhelper.h:63
static void multMatrix(const Matrix< double, 4, 4, _Flags, 4, 4 > &mat)
Definition: gpuhelper.h:123
def update(text)
Definition: relicense.py:46
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
static void multMatrix(const Matrix< double, 4, 4, _Flags, 4, 4 > &mat)
Definition: gpuhelper.h:131
static void loadMatrix(const Matrix< float, 4, 4, _Flags, 4, 4 > &mat)
Definition: gpuhelper.h:128
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Vector4f Color
Definition: gpuhelper.h:19
void popMatrix(GLenum matrixTarget)
Definition: gpuhelper.h:185
void pushMatrix(const Matrix< Scalar, 4, 4, _Flags, 4, 4 > &mat, GLenum matrixTarget)
Definition: gpuhelper.h:170
static void loadMatrix(const Matrix< float, 4, 4, _Flags, 4, 4 > &mat)
Definition: gpuhelper.h:120
static void multMatrix(const Matrix< float, 4, 4, _Flags, 4, 4 > &mat)
Definition: gpuhelper.h:122
void loadMatrix(const Eigen::Matrix< Scalar, 4, 4, _Flags, 4, 4 > &mat, GLenum matrixTarget)
Definition: gpuhelper.h:157
GLuint mColorBufferId
Definition: gpuhelper.h:103
static void multMatrix(const Matrix< float, 4, 4, _Flags, 4, 4 > &mat)
Definition: gpuhelper.h:130
static void loadMatrix(const Matrix< double, 4, 4, _Flags, 4, 4 > &mat)
Definition: gpuhelper.h:121
static void loadMatrix(const Matrix< double, 4, 4, _Flags, 4, 4 > &mat)
Definition: gpuhelper.h:129
ProjectionMode2D
Definition: gpuhelper.h:29
static EIGEN_DEPRECATED const end_t end
int mVpWidth
Definition: gpuhelper.h:104
static const DiscreteKey mode(modeKey, 2)
void setMatrixTarget(GLenum matrixTarget)
Definition: gpuhelper.h:134
The matrix class, also used for vectors and row-vectors.
GpuHelper gpu
Definition: gpuhelper.cpp:18
void multMatrix(const Matrix< Scalar, 4, 4, _Flags, 4, 4 > &mat, GLenum matrixTarget)
Definition: gpuhelper.h:141
Point3 position(const NavState &X, OptionalJacobian< 3, 9 > H)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:19