Debian Codegraph @

octovis/src/TrajectoryDrawer.cpp

raw symbols SCIP
1 /*
2 * This file is part of OctoMap - An Efficient Probabilistic 3D Mapping
3 * Framework Based on Octrees
4 * http://octomap.github.io
5 *
6 * Copyright (c) 2009-2014, K.M. Wurm and A. Hornung, University of Freiburg
7 * All rights reserved. License for the viewer octovis: GNU GPL v2
8 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
9 *
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see http://www.gnu.org/licenses/.
23 */
24
25 #include <octovis/TrajectoryDrawer.h>
26
27 namespace octomap {
28
29 TrajectoryDrawer::TrajectoryDrawer()
30 : ScanGraphDrawer(), m_trajectoryVertexArray(NULL), m_trajectoryColorArray(NULL), m_trajectorySize(0)
31 {
32
33 }
34
35 TrajectoryDrawer::TrajectoryDrawer(const octomap::ScanGraph& graph)
36 : ScanGraphDrawer(), m_trajectoryVertexArray(NULL), m_trajectoryColorArray(NULL), m_trajectorySize(0)
37 {
38 this->setScanGraph(graph);
39 }
40
41 TrajectoryDrawer::~TrajectoryDrawer() {
42 clear();
43
44 }
45
46 void TrajectoryDrawer::draw() const{
47 if (m_trajectorySize == 0)
48 return;
49
50 // draw lines:
51 glEnableClientState(GL_VERTEX_ARRAY);
52 glEnableClientState(GL_COLOR_ARRAY);
53 glLineWidth(3.0f);
54 glVertexPointer(3, GL_FLOAT, 0, m_trajectoryVertexArray);
55 glColorPointer(4, GL_FLOAT, 0, m_trajectoryColorArray);
56 glDrawArrays(GL_LINE_STRIP, 0, m_trajectorySize);
57 glDisableClientState(GL_COLOR_ARRAY);
58 glDisableClientState(GL_VERTEX_ARRAY);
59
60 // draw nodes:
61 GLUquadricObj* quadric=gluNewQuadric();
62 gluQuadricNormals(quadric, GLU_SMOOTH);
63 for (uint i = 0; i < m_trajectorySize; ++i){
64 glPushMatrix();
65 glTranslatef(m_trajectoryVertexArray[3*i], m_trajectoryVertexArray[3*i +1], m_trajectoryVertexArray[3*i +2]);
66 glColor4f(m_trajectoryColorArray[4*i],m_trajectoryColorArray[4*i+1],m_trajectoryColorArray[4*i+2],m_trajectoryColorArray[4*i+3]);
67 gluSphere(quadric, 0.05, 32, 32);
68 glPopMatrix();
69 }
70
71 gluDeleteQuadric(quadric);
72 }
73
74 void TrajectoryDrawer::clear(){
75
76 if (m_trajectorySize != 0) {
77 delete[] m_trajectoryVertexArray;
78 delete[] m_trajectoryColorArray;
79 m_trajectorySize = 0;
80 }
81 }
82
83 void TrajectoryDrawer::setScanGraph(const octomap::ScanGraph& graph){
84
85 clear();
86
87 m_trajectorySize = graph.size();
88 m_trajectoryVertexArray = new GLfloat[m_trajectorySize * 3];
89 m_trajectoryColorArray = new GLfloat[m_trajectorySize * 4];
90
91 uint i = 0;
92 for (octomap::ScanGraph::const_iterator it = graph.begin(); it != graph.end(); it++) {
93 m_trajectoryVertexArray[i] = (*it)->pose.trans().x();
94 m_trajectoryVertexArray[i+1] = (*it)->pose.trans().y();
95 m_trajectoryVertexArray[i+2] = (*it)->pose.trans().z();
96 i+=3;
97 }
98
99 for (unsigned int j=0; j < m_trajectorySize*4; j+=4) {
100 m_trajectoryColorArray[j] = 0.; // r
101 m_trajectoryColorArray[j+1] = 0.; // g
102 m_trajectoryColorArray[j+2] = 1.; // b
103 m_trajectoryColorArray[j+3] = 1.; // alpha
104 }
105 }
106
107 }
108