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/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
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
00088
00089
00090
00091
00092
00093
00094
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 }