g2o_qglviewer.cpp
Go to the documentation of this file.
00001 // g2o - General Graph Optimization
00002 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
00003 //
00004 // This file is part of g2o.
00005 // 
00006 // g2o is free software: you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation, either version 3 of the License, or
00009 // (at your option) any later version.
00010 // 
00011 // g2o is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 // 
00016 // You should have received a copy of the GNU General Public License
00017 // along with g2o.  If not, see <http://www.gnu.org/licenses/>.
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 } // end anonymous namespace
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  //glDisable(GL_LIGHT0);
00099  //glDisable(GL_LIGHTING);
00100 
00101   setBackgroundColor(QColor::fromRgb(51, 51, 51));
00102 
00103   // some default settings i like
00104   glEnable(GL_LINE_SMOOTH);
00105   glEnable(GL_BLEND); 
00106   glEnable(GL_DEPTH_TEST);
00107   glEnable(GL_NORMALIZE);
00108   //glEnable(GL_CULL_FACE);
00109   glShadeModel(GL_FLAT);
00110   //glShadeModel(GL_SMOOTH);
00111   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00112 
00113   setAxisIsDrawn();
00114 
00115   // don't save state
00116   setStateFileName(QString::null);
00117 
00118   // mouse bindings
00119   setMouseBinding(Qt::RightButton, CAMERA, ZOOM);
00120   setMouseBinding(Qt::MidButton, CAMERA, TRANSLATE);
00121 
00122   // keyboard shortcuts
00123   setShortcut(CAMERA_MODE, 0);
00124   setShortcut(EXIT_VIEWER, 0);
00125   //setShortcut(SAVE_SCREENSHOT, 0);
00126 
00127   // replace camera
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   // getting a display list
00137   _drawList = glGenLists(1);
00138 }
00139 
00140 void G2oQGLViewer::setUpdateDisplay(bool updateDisplay)
00141 {
00142   _updateDisplay = updateDisplay;
00143 }
00144 
00145 } // end namespace


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:13