TrajectoryDrawer.cpp
Go to the documentation of this file.
00001 /*
00002  * This file is part of OctoMap - An Efficient Probabilistic 3D Mapping
00003  * Framework Based on Octrees
00004  * http://octomap.github.io
00005  *
00006  * Copyright (c) 2009-2014, K.M. Wurm and A. Hornung, University of Freiburg
00007  * All rights reserved. License for the viewer octovis: GNU GPL v2
00008  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
00009  *
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful, but
00017  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00018  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
00019  * for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program. If not, see http://www.gnu.org/licenses/.
00023  */
00024 
00025 #include <octovis/TrajectoryDrawer.h>
00026 
00027 namespace octomap {
00028 
00029   TrajectoryDrawer::TrajectoryDrawer()
00030   : ScanGraphDrawer(), m_trajectoryVertexArray(NULL), m_trajectoryColorArray(NULL), m_trajectorySize(0)
00031   {
00032 
00033   }
00034 
00035   TrajectoryDrawer::TrajectoryDrawer(const octomap::ScanGraph& graph)
00036   : ScanGraphDrawer(), m_trajectoryVertexArray(NULL), m_trajectoryColorArray(NULL), m_trajectorySize(0)
00037   {
00038     this->setScanGraph(graph);
00039   }
00040 
00041   TrajectoryDrawer::~TrajectoryDrawer() {
00042     clear();
00043 
00044   }
00045 
00046   void TrajectoryDrawer::draw() const{
00047     if (m_trajectorySize == 0)
00048       return;
00049 
00050     // draw lines:
00051     glEnableClientState(GL_VERTEX_ARRAY);
00052     glEnableClientState(GL_COLOR_ARRAY);
00053     glLineWidth(3.0f);
00054     glVertexPointer(3, GL_FLOAT, 0, m_trajectoryVertexArray);
00055     glColorPointer(4, GL_FLOAT, 0, m_trajectoryColorArray);
00056     glDrawArrays(GL_LINE_STRIP, 0, m_trajectorySize);
00057     glDisableClientState(GL_COLOR_ARRAY);
00058     glDisableClientState(GL_VERTEX_ARRAY);
00059 
00060     // draw nodes:
00061     GLUquadricObj* quadric=gluNewQuadric();
00062     gluQuadricNormals(quadric, GLU_SMOOTH);
00063     for (uint i = 0; i < m_trajectorySize; ++i){
00064       glPushMatrix();
00065       glTranslatef(m_trajectoryVertexArray[3*i], m_trajectoryVertexArray[3*i +1], m_trajectoryVertexArray[3*i +2]);
00066       glColor4f(m_trajectoryColorArray[4*i],m_trajectoryColorArray[4*i+1],m_trajectoryColorArray[4*i+2],m_trajectoryColorArray[4*i+3]);
00067       gluSphere(quadric, 0.05, 32, 32);
00068       glPopMatrix();
00069     }
00070 
00071     gluDeleteQuadric(quadric);
00072   }
00073 
00074   void TrajectoryDrawer::clear(){
00075 
00076     if (m_trajectorySize != 0) {
00077       delete[] m_trajectoryVertexArray;
00078       delete[] m_trajectoryColorArray;
00079       m_trajectorySize = 0;
00080     }
00081   }
00082 
00083   void TrajectoryDrawer::setScanGraph(const octomap::ScanGraph& graph){
00084 
00085     clear();
00086 
00087     m_trajectorySize = graph.size();
00088     m_trajectoryVertexArray = new GLfloat[m_trajectorySize * 3];
00089     m_trajectoryColorArray = new GLfloat[m_trajectorySize * 4];
00090 
00091     uint i = 0;
00092     for (octomap::ScanGraph::const_iterator it = graph.begin(); it != graph.end(); it++) {
00093       m_trajectoryVertexArray[i] = (*it)->pose.trans().x();
00094       m_trajectoryVertexArray[i+1] = (*it)->pose.trans().y();
00095       m_trajectoryVertexArray[i+2] = (*it)->pose.trans().z();
00096       i+=3;
00097     }
00098 
00099     for (unsigned int j=0; j < m_trajectorySize*4; j+=4) {
00100       m_trajectoryColorArray[j]   = 0.; // r
00101       m_trajectoryColorArray[j+1] = 0.; // g
00102       m_trajectoryColorArray[j+2] = 1.; // b
00103       m_trajectoryColorArray[j+3] = 1.; // alpha
00104     }
00105   }
00106 
00107 }
00108 


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Thu Feb 11 2016 23:51:20