Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "g2o_qglviewer.h"
00020
00021 #include "primitives.h"
00022 #include "g2o/core/graph_optimizer_sparse.h"
00023 #include "g2o/core/hyper_graph_action.h"
00024
00025 #include <iostream>
00026 using namespace std;
00027
00028 namespace g2o {
00029
00030 namespace {
00031
00035 class StandardCamera : public qglviewer::Camera
00036 {
00037 public:
00038 StandardCamera() : _standard(true) {};
00039
00040 float zNear() const {
00041 if (_standard)
00042 return 0.001;
00043 else
00044 return Camera::zNear();
00045 }
00046
00047 float zFar() const
00048 {
00049 if (_standard)
00050 return 10000.0;
00051 else
00052 return Camera::zFar();
00053 }
00054
00055 const bool& standard() const {return _standard;}
00056 bool& standard() {return _standard;}
00057
00058 private:
00059 bool _standard;
00060 };
00061
00062 }
00063
00064 G2oQGLViewer::G2oQGLViewer(QWidget* parent, const QGLWidget* shareWidget, Qt::WFlags flags) :
00065 QGLViewer(parent, shareWidget, flags),
00066 graph(0), _drawActions(0), _drawList(0)
00067 {
00068 }
00069
00070 G2oQGLViewer::~G2oQGLViewer()
00071 {
00072 }
00073
00074 void G2oQGLViewer::draw()
00075 {
00076 if (! graph)
00077 return;
00078
00079 if (_drawActions == 0) {
00080 _drawActions = HyperGraphActionLibrary::instance()->actionByName("draw");
00081 assert(_drawActions);
00082 }
00083
00084 if (_updateDisplay) {
00085 _updateDisplay = false;
00086 glNewList(_drawList, GL_COMPILE_AND_EXECUTE);
00087 applyAction(graph, _drawActions);
00088 glEndList();
00089 } else {
00090 glCallList(_drawList);
00091 }
00092 }
00093
00094 void G2oQGLViewer::init()
00095 {
00096 QGLViewer::init();
00097
00098
00099
00100
00101 setBackgroundColor(QColor::fromRgb(51, 51, 51));
00102
00103
00104 glEnable(GL_LINE_SMOOTH);
00105 glEnable(GL_BLEND);
00106 glEnable(GL_DEPTH_TEST);
00107 glEnable(GL_NORMALIZE);
00108
00109 glShadeModel(GL_FLAT);
00110
00111 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00112
00113 setAxisIsDrawn();
00114
00115
00116 setStateFileName(QString::null);
00117
00118
00119 setMouseBinding(Qt::RightButton, CAMERA, ZOOM);
00120 setMouseBinding(Qt::MidButton, CAMERA, TRANSLATE);
00121
00122
00123 setShortcut(CAMERA_MODE, 0);
00124 setShortcut(EXIT_VIEWER, 0);
00125
00126
00127
00128 qglviewer::Camera* oldcam = camera();
00129 qglviewer::Camera* cam = new StandardCamera();
00130 setCamera(cam);
00131 cam->setPosition(qglviewer::Vec(0., 0., 75.));
00132 cam->setUpVector(qglviewer::Vec(0., 1., 0.));
00133 cam->lookAt(qglviewer::Vec(0., 0., 0.));
00134 delete oldcam;
00135
00136
00137 _drawList = glGenLists(1);
00138 }
00139
00140 void G2oQGLViewer::setUpdateDisplay(bool updateDisplay)
00141 {
00142 _updateDisplay = updateDisplay;
00143 }
00144
00145 }