gpuhelper.cpp
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 #include "gpuhelper.h"
11 #include "icosphere.h"
12 #include <GL/glu.h>
13 // PLEASE don't look at this old code... ;)
14 
15 #include <fstream>
16 #include <algorithm>
17 
19 
21 {
22  mVpWidth = mVpHeight = 0;
24  mInitialized = false;
25 }
26 
28 {
29 }
30 
32 {
33  // switch to 2D projection
34  pushMatrix(Matrix4f::Identity(),GL_PROJECTION);
35 
36  if(pm==PM_Normalized)
37  {
38  //glOrtho(-1., 1., -1., 1., 0., 1.);
39  }
40  else if(pm==PM_Viewport)
41  {
42  GLint vp[4];
43  glGetIntegerv(GL_VIEWPORT, vp);
44  glOrtho(0., vp[2], 0., vp[3], -1., 1.);
45  }
46 
47  pushMatrix(Matrix4f::Identity(),GL_MODELVIEW);
48 }
49 
51 {
52  popMatrix(GL_PROJECTION);
53  popMatrix(GL_MODELVIEW);
54 }
55 
56 void GpuHelper::drawVector(const Vector3f& position, const Vector3f& vec, const Color& color, float aspect /* = 50.*/)
57 {
58  static GLUquadricObj *cylindre = gluNewQuadric();
59  glColor4fv(color.data());
60  float length = vec.norm();
61  pushMatrix(GL_MODELVIEW);
62  glTranslatef(position.x(), position.y(), position.z());
63  Vector3f ax = Matrix3f::Identity().col(2).cross(vec);
64  ax.normalize();
65  Vector3f tmp = vec;
66  tmp.normalize();
67  float angle = 180.f/M_PI * acos(tmp.z());
68  if (angle>1e-3)
69  glRotatef(angle, ax.x(), ax.y(), ax.z());
70  gluCylinder(cylindre, length/aspect, length/aspect, 0.8*length, 10, 10);
71  glTranslatef(0.0,0.0,0.8*length);
72  gluCylinder(cylindre, 2.0*length/aspect, 0.0, 0.2*length, 10, 10);
73 
74  popMatrix(GL_MODELVIEW);
75 }
76 
77 void GpuHelper::drawVectorBox(const Vector3f& position, const Vector3f& vec, const Color& color, float aspect)
78 {
79  static GLUquadricObj *cylindre = gluNewQuadric();
80  glColor4fv(color.data());
81  float length = vec.norm();
82  pushMatrix(GL_MODELVIEW);
83  glTranslatef(position.x(), position.y(), position.z());
84  Vector3f ax = Matrix3f::Identity().col(2).cross(vec);
85  ax.normalize();
86  Vector3f tmp = vec;
87  tmp.normalize();
88  float angle = 180.f/M_PI * acos(tmp.z());
89  if (angle>1e-3)
90  glRotatef(angle, ax.x(), ax.y(), ax.z());
91  gluCylinder(cylindre, length/aspect, length/aspect, 0.8*length, 10, 10);
92  glTranslatef(0.0,0.0,0.8*length);
93  glScalef(4.0*length/aspect,4.0*length/aspect,4.0*length/aspect);
94  drawUnitCube();
95  popMatrix(GL_MODELVIEW);
96 }
97 
99 {
100  static float vertices[][3] = {
101  {-0.5,-0.5,-0.5},
102  { 0.5,-0.5,-0.5},
103  {-0.5, 0.5,-0.5},
104  { 0.5, 0.5,-0.5},
105  {-0.5,-0.5, 0.5},
106  { 0.5,-0.5, 0.5},
107  {-0.5, 0.5, 0.5},
108  { 0.5, 0.5, 0.5}};
109 
110  glBegin(GL_QUADS);
111  glNormal3f(0,0,-1); glVertex3fv(vertices[0]); glVertex3fv(vertices[2]); glVertex3fv(vertices[3]); glVertex3fv(vertices[1]);
112  glNormal3f(0,0, 1); glVertex3fv(vertices[4]); glVertex3fv(vertices[5]); glVertex3fv(vertices[7]); glVertex3fv(vertices[6]);
113  glNormal3f(0,-1,0); glVertex3fv(vertices[0]); glVertex3fv(vertices[1]); glVertex3fv(vertices[5]); glVertex3fv(vertices[4]);
114  glNormal3f(0, 1,0); glVertex3fv(vertices[2]); glVertex3fv(vertices[6]); glVertex3fv(vertices[7]); glVertex3fv(vertices[3]);
115  glNormal3f(-1,0,0); glVertex3fv(vertices[0]); glVertex3fv(vertices[4]); glVertex3fv(vertices[6]); glVertex3fv(vertices[2]);
116  glNormal3f( 1,0,0); glVertex3fv(vertices[1]); glVertex3fv(vertices[3]); glVertex3fv(vertices[7]); glVertex3fv(vertices[5]);
117  glEnd();
118 }
119 
121 {
122  static IcoSphere sphere;
123  sphere.draw(level);
124 }
125 
126 
IcoSphere
Definition: icosphere.h:16
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
GpuHelper::drawVectorBox
void drawVectorBox(const Vector3f &position, const Vector3f &vec, const Color &color, float aspect=50.)
Definition: gpuhelper.cpp:77
GpuHelper::GpuHelper
GpuHelper()
Definition: gpuhelper.cpp:20
GpuHelper::mInitialized
bool mInitialized
Definition: gpuhelper.h:106
GpuHelper::mVpHeight
int mVpHeight
Definition: gpuhelper.h:104
GpuHelper::ProjectionMode2D
ProjectionMode2D
Definition: gpuhelper.h:29
ceres::acos
Jet< T, N > acos(const Jet< T, N > &f)
Definition: jet.h:432
GpuHelper::PM_Viewport
@ PM_Viewport
Definition: gpuhelper.h:29
icosphere.h
GpuHelper::drawVector
void drawVector(const Vector3f &position, const Vector3f &vec, const Color &color, float aspect=50.)
Definition: gpuhelper.cpp:56
GpuHelper::PM_Normalized
@ PM_Normalized
Definition: gpuhelper.h:29
GpuHelper::drawUnitSphere
void drawUnitSphere(int level=0)
Definition: gpuhelper.cpp:120
gtsam.examples.SFMExample_bal.level
level
Definition: SFMExample_bal.py:24
GpuHelper::pushProjectionMode2D
void pushProjectionMode2D(ProjectionMode2D pm)
Definition: gpuhelper.cpp:31
GpuHelper::~GpuHelper
~GpuHelper()
Definition: gpuhelper.cpp:27
GpuHelper::popMatrix
void popMatrix(GLenum matrixTarget)
Definition: gpuhelper.h:185
Color
Vector4f Color
Definition: gpuhelper.h:19
pm
Matrix4d pm
Definition: HessenbergDecomposition_packedMatrix.cpp:4
GpuHelper::drawUnitCube
void drawUnitCube(void)
Definition: gpuhelper.cpp:98
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::popProjectionMode2D
void popProjectionMode2D()
Definition: gpuhelper.cpp:50
gpuhelper.h
M_PI
#define M_PI
Definition: mconf.h:117
gpu
GpuHelper gpu
Definition: gpuhelper.cpp:18
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
Definition: gpuhelper.h:21
IcoSphere::draw
void draw(int level)
Definition: icosphere.cpp:100


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