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
00020
00021
00022
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
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
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.;
00101 m_trajectoryColorArray[j+1] = 0.;
00102 m_trajectoryColorArray[j+2] = 1.;
00103 m_trajectoryColorArray[j+3] = 1.;
00104 }
00105 }
00106
00107 }
00108