glc_pointcloud.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021  *****************************************************************************/
00023 
00024 #include "glc_pointcloud.h"
00025 
00026 GLC_PointCloud::GLC_PointCloud()
00027 : GLC_Geometry("Point Cloud", true)
00028 {
00029 
00030 }
00031 
00032 GLC_PointCloud::GLC_PointCloud(const GLC_PointCloud& pointCloud)
00033 : GLC_Geometry(pointCloud)
00034 {
00035 
00036 
00037 }
00038 
00039 GLC_PointCloud::~GLC_PointCloud()
00040 {
00041 
00042 }
00043 
00045 // Get Functions
00047 const GLC_BoundingBox& GLC_PointCloud::boundingBox()
00048 {
00049         if (NULL == GLC_Geometry::m_pBoundingBox)
00050         {
00051                 GLC_Geometry::m_pBoundingBox= new GLC_BoundingBox();
00052                 if (! m_WireData.isEmpty())
00053                 {
00054                         GLC_Geometry::m_pBoundingBox->combine(m_WireData.boundingBox());
00055                 }
00056         }
00057         return *GLC_Geometry::m_pBoundingBox;
00058 }
00059 
00060 GLC_Geometry* GLC_PointCloud::clone() const
00061 {
00062         return new GLC_PointCloud(*this);
00063 }
00064 
00066 // Set Functions
00068 
00069 GLC_uint GLC_PointCloud::addPoint(const QList<GLC_Point3d>& pointsList)
00070 {
00071         const int pointCount= pointsList.size();
00072         const int size= pointCount * 3;
00073         GLfloatVector data(size);
00074         for (int i= 0; i < pointCount; ++i)
00075         {
00076                 const GLC_Point3d currentPoint(pointsList.at(i));
00077                 data[i * 3]= static_cast<float>(currentPoint.x());
00078                 data[i * 3 + 1]= static_cast<float>(currentPoint.y());
00079                 data[i * 3 + 2]= static_cast<float>(currentPoint.z());
00080         }
00081         return GLC_Geometry::m_WireData.addVerticeGroup(data);
00082 }
00083 
00084 GLC_uint GLC_PointCloud::addPoint(const QList<GLC_Point3df>& pointsList)
00085 {
00086         const int pointCount= pointsList.size();
00087         const int size= pointCount * 3;
00088         GLfloatVector data(size);
00089         for (int i= 0; i < pointCount; ++i)
00090         {
00091                 const GLC_Point3df currentPoint(pointsList.at(i));
00092                 data[i * 3]= currentPoint.x();
00093                 data[i * 3 + 1]= currentPoint.y();
00094                 data[i * 3 + 2]= currentPoint.z();
00095         }
00096         return GLC_Geometry::m_WireData.addVerticeGroup(data);
00097 }
00098 
00099 void GLC_PointCloud::addColors(const QList<QColor>& colors)
00100 {
00101         const int colorCount= colors.count();
00102         const int size= colorCount * 4;
00103         GLfloatVector data(size);
00104         for (int i= 0; i < colorCount; ++i)
00105         {
00106                 QColor color= colors.at(i);
00107                 data[i * 4]= static_cast<GLfloat>(color.redF());
00108                 data[i * 4 + 1]= static_cast<GLfloat>(color.greenF());
00109                 data[i * 4 + 2]= static_cast<GLfloat>(color.blueF());
00110                 data[i * 4 + 3]= static_cast<GLfloat>(color.alphaF());
00111         }
00112 
00113         GLC_Geometry::m_WireData.addColors(data);
00114 }
00115 
00116 GLC_PointCloud& GLC_PointCloud::operator=(const GLC_PointCloud& pointCloud)
00117 {
00118         if (this != &pointCloud)
00119         {
00120                 GLC_Geometry::operator=(pointCloud);
00121         }
00122         return *this;
00123 }
00124 
00126 // OpenGL Functions
00128 void GLC_PointCloud::glDraw(const GLC_RenderProperties& renderProperties)
00129 {
00130         if (!GLC_Geometry::m_WireData.isEmpty())
00131         {
00132                 GLC_Geometry::m_WireData.glDraw(renderProperties, GL_POINTS);
00133         }
00134 }
00135 

SourceForge.net Logo

©2005-2011 Laurent Ribon