g2o
Loading...
Searching...
No Matches
g2o_qglviewer.cpp
Go to the documentation of this file.
1// g2o - General Graph Optimization
2// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3//
4// This file is part of g2o.
5//
6// g2o is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// g2o is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with g2o. If not, see <http://www.gnu.org/licenses/>.
18
19#include "g2o_qglviewer.h"
20
21#include <cassert>
22
26
27// some macro helpers for identifying the version number of QGLViewer
28// QGLViewer changed some parts of its API in version 2.6.
29// The following preprocessor hack accounts for this. THIS SUCKS!!!
30#if (((QGLVIEWER_VERSION & 0xff0000) >> 16) >= 2 && \
31 ((QGLVIEWER_VERSION & 0x00ff00) >> 8) >= 6)
32#define qglv_real qreal
33#else
34#define qglv_real float
35#endif
36
37// Again, some API changes in QGLViewer which produce annoying text in the
38// console if the old API is used.
39#if (((QGLVIEWER_VERSION & 0xff0000) >> 16) >= 2 && \
40 ((QGLVIEWER_VERSION & 0x00ff00) >> 8) >= 5)
41#define QGLVIEWER_DEPRECATED_MOUSEBINDING
42#endif
43
44#ifdef __APPLE__
45#include <OpenGL/gl.h>
46#else
47#include <GL/gl.h>
48#include <GL/glu.h>
49#endif
50
51#include <iostream>
52using namespace std;
53
54namespace g2o {
55
56namespace {
57
61class StandardCamera : public qglviewer::Camera {
62 public:
63 StandardCamera() : _standard(true){};
64
65 qglv_real zNear() const {
66 if (_standard)
67 return qglv_real(0.001);
68 else
69 return Camera::zNear();
70 }
71
72 qglv_real zFar() const {
73 if (_standard)
74 return qglv_real(10000.0);
75 else
76 return Camera::zFar();
77 }
78
79 bool standard() const { return _standard; }
80 void setStandard(bool s) { _standard = s; }
81
82 private:
84};
85
86} // end anonymous namespace
87
88G2oQGLViewer::G2oQGLViewer(QWidget* parent, const QGLWidget* shareWidget)
89 : QGLViewer(parent, shareWidget),
90 graph(0),
91 _drawActions(0),
92 _drawList(0),
93 _updateDisplay(true) {
94 setAxisIsDrawn(false);
96}
97
100 glDeleteLists(_drawList, 1);
101}
102
104 if (!graph) return;
105
106 if (_drawActions == 0) {
108 assert(_drawActions);
109 }
110
111 if (!_drawActions) // avoid segmentation fault in release build
112 return;
113 if (_updateDisplay) {
114 _updateDisplay = false;
115 glNewList(_drawList, GL_COMPILE_AND_EXECUTE);
117 glEndList();
118 } else {
119 glCallList(_drawList);
120 }
121}
122
124 QGLViewer::init();
125 // glDisable(GL_LIGHT0);
126 // glDisable(GL_LIGHTING);
127
128 setBackgroundColor(QColor::fromRgb(51, 51, 51));
129
130 // some default settings i like
131 glEnable(GL_LINE_SMOOTH);
132 glEnable(GL_BLEND);
133 glEnable(GL_DEPTH_TEST);
134 glEnable(GL_NORMALIZE);
135 // glEnable(GL_CULL_FACE);
136 glShadeModel(GL_FLAT);
137 // glShadeModel(GL_SMOOTH);
138 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
139
140 setAxisIsDrawn();
141
142 // don't save state
143 setStateFileName(QString());
144
145 // mouse bindings
146#ifdef QGLVIEWER_DEPRECATED_MOUSEBINDING
147 setMouseBinding(Qt::NoModifier, Qt::RightButton, CAMERA, TRANSLATE);
148 setMouseBinding(Qt::NoModifier, Qt::MiddleButton, CAMERA, TRANSLATE);
149#else
150 setMouseBinding(Qt::RightButton, CAMERA, TRANSLATE);
151 setMouseBinding(Qt::MidButton, CAMERA, TRANSLATE);
152#endif
153
154 // keyboard shortcuts
155 setShortcut(CAMERA_MODE, 0);
156 setShortcut(EXIT_VIEWER, 0);
157 // setShortcut(SAVE_SCREENSHOT, 0);
158
159 // replace camera
160 qglviewer::Camera* oldcam = camera();
161 qglviewer::Camera* cam = new StandardCamera();
162 setCamera(cam);
163 cam->setPosition(qglviewer::Vec(0., 0., 75.));
164 cam->setUpVector(qglviewer::Vec(0., 1., 0.));
165 cam->lookAt(qglviewer::Vec(0., 0., 0.));
166 delete oldcam;
167
168 // getting a display list
169 _drawList = glGenLists(1);
170}
171
175
176} // namespace g2o
SparseOptimizer * graph
void setUpdateDisplay(bool updateDisplay)
HyperGraphElementAction * _drawActions
bool updateDisplay() const
DrawAction::Parameters * _drawActionParameters
G2oQGLViewer(QWidget *parent=NULL, const QGLWidget *shareWidget=0)
static HyperGraphActionLibrary * instance()
return the single instance of the HyperGraphActionLibrary
HyperGraphElementAction * actionByName(const std::string &name)
void updateDisplay(ostream &os, const SparseOptimizer &optimizer)
bool _standard
#define qglv_real
void applyAction(HyperGraph *graph, HyperGraphElementAction *action, HyperGraphElementAction::Parameters *params, const std::string &typeName)
Definition jet.h:876