PointcloudDrawer.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/PointcloudDrawer.h>
00026 
00027 namespace octomap {
00028 
00029   PointcloudDrawer::PointcloudDrawer()
00030     : ScanGraphDrawer(), m_pointsArray(NULL), m_numberPoints(0)
00031   {
00032   }
00033 
00034   PointcloudDrawer::PointcloudDrawer(const ScanGraph& graph)
00035     : ScanGraphDrawer(), m_pointsArray(NULL), m_numberPoints(0)
00036   {
00037     this->setScanGraph(graph);
00038 
00039   }
00040 
00041   PointcloudDrawer::~PointcloudDrawer() {
00042     clear();
00043 
00044   }
00045 
00046   void PointcloudDrawer::setScanGraph(const ScanGraph& graph){
00047     clear();
00048 
00049     // count points first:
00050     for (octomap::ScanGraph::const_iterator it = graph.begin(); it != graph.end(); it++) {
00051       m_numberPoints += (*it)->scan->size();
00052     }
00053 
00054     m_pointsArray = new GLfloat[3*m_numberPoints];
00055 
00056     unsigned i = 0;
00057     for (octomap::ScanGraph::const_iterator graph_it = graph.begin(); graph_it != graph.end(); graph_it++) {
00058       octomap::Pointcloud* scan = new Pointcloud((*graph_it)->scan);
00059       scan->transformAbsolute((*graph_it)->pose);
00060 
00061       for (Pointcloud::iterator pc_it = scan->begin(); pc_it != scan->end(); ++pc_it){
00062         m_pointsArray[3*i] = pc_it->x();
00063         m_pointsArray[3*i +1] = pc_it->y();
00064         m_pointsArray[3*i +2] = pc_it->z();
00065 
00066         i++;
00067       }
00068       delete scan;
00069     }
00070   }
00071 
00072   void PointcloudDrawer::clear(){
00073 
00074     if (m_numberPoints != 0) {
00075       delete[] m_pointsArray;
00076       m_numberPoints = 0;
00077     }
00078   }
00079 
00080   void PointcloudDrawer::draw() const{
00081     if (m_numberPoints == 0)
00082       return;
00083 
00084     glEnable(GL_POINT_SMOOTH);
00085     glEnableClientState(GL_VERTEX_ARRAY);
00086 
00087    // TODO: find a solution for printout-mode (=> separate drawer?)
00088 //    if (m_printoutMode){
00089 //      if (!m_drawFree) {
00090 //        glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
00091 //      }
00092 //      glColor4f(0.0, 0.0, 0.0, 1.);
00093 //    } else{
00094 //      glColor4f(1.0, 0.0, 0.0, 1.);
00095 //    }
00096 
00097     glPointSize(1.0);
00098     glColor4f(1.0, 0.0, 0.0, 1.);
00099 
00100     glVertexPointer(3, GL_FLOAT, 0, m_pointsArray);
00101     glDrawArrays(GL_POINTS, 0, m_numberPoints);
00102     glDisableClientState(GL_VERTEX_ARRAY);
00103   }
00104 
00105 }


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