g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
apps
g2o_viewer
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
23
#include "
g2o/core/hyper_graph_action.h
"
24
#include "
g2o/core/sparse_optimizer.h
"
25
#include "
g2o/stuff/opengl_primitives.h
"
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>
52
using namespace
std
;
53
54
namespace
g2o
{
55
56
namespace
{
57
61
class
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
:
83
bool
_standard;
84
};
85
86
}
// end anonymous namespace
87
88
G2oQGLViewer::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
);
95
_drawActionParameters
=
new
DrawAction::Parameters
();
96
}
97
98
G2oQGLViewer::~G2oQGLViewer
() {
99
delete
_drawActionParameters
;
100
glDeleteLists(
_drawList
, 1);
101
}
102
103
void
G2oQGLViewer::draw
() {
104
if
(!
graph
)
return
;
105
106
if
(
_drawActions
== 0) {
107
_drawActions
=
HyperGraphActionLibrary::instance
()->
actionByName
(
"draw"
);
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);
116
applyAction
(
graph
,
_drawActions
,
_drawActionParameters
);
117
glEndList();
118
}
else
{
119
glCallList(
_drawList
);
120
}
121
}
122
123
void
G2oQGLViewer::init
() {
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
172
void
G2oQGLViewer::setUpdateDisplay
(
bool
updateDisplay
) {
173
_updateDisplay
=
updateDisplay
;
174
}
175
176
}
// namespace g2o
g2o::DrawAction::Parameters
Definition
hyper_graph_action.h:204
g2o::G2oQGLViewer::graph
SparseOptimizer * graph
Definition
g2o_qglviewer.h:53
g2o::G2oQGLViewer::init
void init()
Definition
g2o_qglviewer.cpp:123
g2o::G2oQGLViewer::~G2oQGLViewer
~G2oQGLViewer()
Definition
g2o_qglviewer.cpp:98
g2o::G2oQGLViewer::setUpdateDisplay
void setUpdateDisplay(bool updateDisplay)
Definition
g2o_qglviewer.cpp:172
g2o::G2oQGLViewer::_drawActions
HyperGraphElementAction * _drawActions
Definition
g2o_qglviewer.h:56
g2o::G2oQGLViewer::updateDisplay
bool updateDisplay() const
Definition
g2o_qglviewer.h:47
g2o::G2oQGLViewer::draw
void draw()
Definition
g2o_qglviewer.cpp:103
g2o::G2oQGLViewer::_drawActionParameters
DrawAction::Parameters * _drawActionParameters
Definition
g2o_qglviewer.h:59
g2o::G2oQGLViewer::_updateDisplay
bool _updateDisplay
Definition
g2o_qglviewer.h:58
g2o::G2oQGLViewer::_drawList
GLuint _drawList
Definition
g2o_qglviewer.h:57
g2o::G2oQGLViewer::G2oQGLViewer
G2oQGLViewer(QWidget *parent=NULL, const QGLWidget *shareWidget=0)
Definition
g2o_qglviewer.cpp:88
g2o::HyperGraphActionLibrary::instance
static HyperGraphActionLibrary * instance()
return the single instance of the HyperGraphActionLibrary
Definition
hyper_graph_action.cpp:127
g2o::HyperGraphActionLibrary::actionByName
HyperGraphElementAction * actionByName(const std::string &name)
Definition
hyper_graph_action.cpp:140
qglv_real
#define qglv_real
Definition
g2o_qglviewer.cpp:34
g2o_qglviewer.h
hyper_graph_action.h
g2o
Definition
dl_wrapper.cpp:55
g2o::applyAction
void applyAction(HyperGraph *graph, HyperGraphElementAction *action, HyperGraphElementAction::Parameters *params, const std::string &typeName)
Definition
hyper_graph_action.cpp:261
std
Definition
jet.h:876
opengl_primitives.h
sparse_optimizer.h
Generated on
for g2o by
1.17.0