OpenWalnut  1.4.0
WDataSetPoints.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WDATASETPOINTS_H
00026 #define WDATASETPOINTS_H
00027 
00028 #include <string>
00029 #include <utility>
00030 #include <vector>
00031 
00032 #include <boost/shared_ptr.hpp>
00033 
00034 #include "../common/WBoundingBox.h"
00035 #include "WDataSet.h"
00036 
00037 /**
00038  * Dataset to store a bunch of points without order or topology.
00039  */
00040 class WDataSetPoints : public WDataSet // NOLINT
00041 {
00042 public:
00043     // some type alias for the used arrays.
00044     /**
00045      * Pointer to dataset.
00046      */
00047     typedef boost::shared_ptr< WDataSetPoints > SPtr;
00048 
00049     /**
00050      * Pointer to const dataset.
00051      */
00052     typedef boost::shared_ptr< const WDataSetPoints > ConstSPtr;
00053 
00054     /**
00055      * List of vertex coordinates in term of components of vertices.
00056      */
00057     typedef boost::shared_ptr< std::vector< float > > VertexArray;
00058 
00059     /**
00060      * Colors for each vertex in VertexArray.
00061      */
00062     typedef boost::shared_ptr< std::vector< float > > ColorArray;
00063 
00064     /**
00065      * Constructs a new set of points. If no color is specified, white is used for all points.
00066      *
00067      * \note the number of floats in vertices must be a multiple of 3
00068      * \note the number of floats in colors (if not NULL) must be vertices->size() / 3  times one of 1,3, or 4
00069      *
00070      * \param vertices the vertices of the points, stored in x1,y1,z1,x2,y2,z2, ..., xn,yn,zn scheme
00071      * \param colors the colors of each vertex. Can be NULL.. Stored as R1,G1,B1,A1, ... Rn,Gn,Bn,An
00072      * \param boundingBox The bounding box of the points (first minimum, second maximum).
00073      */
00074     WDataSetPoints( VertexArray vertices, ColorArray colors,
00075                     WBoundingBox boundingBox );
00076 
00077     /**
00078      * Constructs a new set of points. The bounding box is calculated during construction. If no color is specified, white is used for all
00079      * points.
00080      *
00081      * \note the number of floats in vertices must be a multiple of 3
00082      * \note the number of floats in colors (if not NULL) must be vertices->size() / 3  times one of 1,3, or 4
00083      *
00084      * \param vertices the vertices of the points, stored in x1,y1,z1,x2,y2,z2, ..., xn,yn,zn scheme
00085      * \param colors the colors of each vertex. Can be NULL.. Stored as R1,[G1,B1,[A1,]] ... Rn,[Gn,Bn,[An]]
00086      */
00087     WDataSetPoints( VertexArray vertices, ColorArray colors );
00088 
00089     /**
00090      * Constructs a new set of points. The constructed instance is empty..
00091      */
00092     WDataSetPoints();
00093 
00094     /**
00095      * Destructor.
00096      */
00097     virtual ~WDataSetPoints();
00098 
00099     /**
00100      * Get number of points in this data set.
00101      *
00102      * \return number of points
00103      */
00104     size_t size() const;
00105 
00106     /**
00107      * Determines whether this dataset can be used as a texture.
00108      *
00109      * \return true if usable as texture.
00110      */
00111     virtual bool isTexture() const;
00112 
00113     /**
00114      * Gets the name of this prototype.
00115      *
00116      * \return the name.
00117      */
00118     virtual const std::string getName() const;
00119 
00120     /**
00121      * Gets the description for this prototype.
00122      *
00123      * \return the description
00124      */
00125     virtual const std::string getDescription() const;
00126 
00127     /**
00128      * Returns a prototype instantiated with the true type of the deriving class.
00129      *
00130      * \return the prototype.
00131      */
00132     static boost::shared_ptr< WPrototyped > getPrototype();
00133 
00134     /**
00135      * Getter for the point vertices
00136      * \return The vertices
00137      */
00138     VertexArray getVertices() const;
00139 
00140     /**
00141      * Getter for the point colors
00142      * \return The colors
00143      */
00144     ColorArray getColors() const;
00145 
00146     /**
00147      * Get the bounding box.
00148      * \return The bounding box of all points.
00149      */
00150     WBoundingBox getBoundingBox() const;
00151 
00152     /**
00153      * Query coordinates of a given point.
00154      *
00155      * \throw WOutOfBounds if invalid index is used.
00156      * \param pointIdx the point index.
00157      *
00158      * \return the coordinates
00159      */
00160     WPosition operator[]( const size_t pointIdx ) const;
00161 
00162     /**
00163      * Query coordinates of a given point.
00164      *
00165      * \throw WOutOfBounds if invalid index is used.
00166      * \param pointIdx the point index.
00167      *
00168      * \return the coordinates
00169      */
00170     WPosition getPosition( const size_t pointIdx ) const;
00171 
00172     /**
00173      * The color of a given point.
00174      *
00175      * \throw WOutOfBounds if invalid index is used.
00176      * \param pointIdx the point index.
00177      *
00178      * \return the color
00179      */
00180     WColor getColor( const size_t pointIdx ) const;
00181 
00182     /**
00183      * Is this a valid point index?
00184      *
00185      * \param pointIdx the index to check
00186      *
00187      * \return true if yes.
00188      */
00189     bool isValidPointIdx( const size_t pointIdx ) const;
00190 
00191     /**
00192      * The type of colors we have for each point.
00193      */
00194     enum ColorType
00195     {
00196         GRAY = 1,
00197         RGB = 3,
00198         RGBA =4
00199     };
00200 
00201     /**
00202      * Check the type of color.
00203      *
00204      * \return the type
00205      */
00206     ColorType getColorType() const;
00207 protected:
00208     /**
00209      * The prototype as singleton.
00210      */
00211     static boost::shared_ptr< WPrototyped > m_prototype;
00212 
00213 private:
00214     /**
00215      * Point vector for all points
00216      */
00217     VertexArray m_vertices;
00218 
00219     /**
00220      * An array of the colors per vertex.
00221      */
00222     ColorArray m_colors;
00223 
00224     /**
00225      * Which colortype do we use in m_colors.
00226      */
00227     ColorType m_colorType;
00228 
00229     /**
00230      * Axis aligned bounding box for all point-vertices of this dataset.
00231      */
00232     WBoundingBox m_bb;
00233 
00234     /**
00235      * Initialize arrays and bbox if needed. Used during construction.
00236      *
00237      * \param calcBB if true, the bounding box is calculated
00238      */
00239     void init( bool calcBB = false );
00240 };
00241 
00242 #endif  // WDATASETPOINTS_H