OpenWalnut  1.4.0
WDataSetPoints.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WDATASETPOINTS_H
26 #define WDATASETPOINTS_H
27 
28 #include <string>
29 #include <utility>
30 #include <vector>
31 
32 #include <boost/shared_ptr.hpp>
33 
34 #include "../common/WBoundingBox.h"
35 #include "WDataSet.h"
36 
37 /**
38  * Dataset to store a bunch of points without order or topology.
39  */
40 class WDataSetPoints : public WDataSet // NOLINT
41 {
42 public:
43  // some type alias for the used arrays.
44  /**
45  * Pointer to dataset.
46  */
47  typedef boost::shared_ptr< WDataSetPoints > SPtr;
48 
49  /**
50  * Pointer to const dataset.
51  */
52  typedef boost::shared_ptr< const WDataSetPoints > ConstSPtr;
53 
54  /**
55  * List of vertex coordinates in term of components of vertices.
56  */
57  typedef boost::shared_ptr< std::vector< float > > VertexArray;
58 
59  /**
60  * Colors for each vertex in VertexArray.
61  */
62  typedef boost::shared_ptr< std::vector< float > > ColorArray;
63 
64  /**
65  * Constructs a new set of points. If no color is specified, white is used for all points.
66  *
67  * \note the number of floats in vertices must be a multiple of 3
68  * \note the number of floats in colors (if not NULL) must be vertices->size() / 3 times one of 1,3, or 4
69  *
70  * \param vertices the vertices of the points, stored in x1,y1,z1,x2,y2,z2, ..., xn,yn,zn scheme
71  * \param colors the colors of each vertex. Can be NULL.. Stored as R1,G1,B1,A1, ... Rn,Gn,Bn,An
72  * \param boundingBox The bounding box of the points (first minimum, second maximum).
73  */
74  WDataSetPoints( VertexArray vertices, ColorArray colors,
75  WBoundingBox boundingBox );
76 
77  /**
78  * Constructs a new set of points. The bounding box is calculated during construction. If no color is specified, white is used for all
79  * points.
80  *
81  * \note the number of floats in vertices must be a multiple of 3
82  * \note the number of floats in colors (if not NULL) must be vertices->size() / 3 times one of 1,3, or 4
83  *
84  * \param vertices the vertices of the points, stored in x1,y1,z1,x2,y2,z2, ..., xn,yn,zn scheme
85  * \param colors the colors of each vertex. Can be NULL.. Stored as R1,[G1,B1,[A1,]] ... Rn,[Gn,Bn,[An]]
86  */
87  WDataSetPoints( VertexArray vertices, ColorArray colors );
88 
89  /**
90  * Constructs a new set of points. The constructed instance is empty..
91  */
93 
94  /**
95  * Destructor.
96  */
97  virtual ~WDataSetPoints();
98 
99  /**
100  * Get number of points in this data set.
101  *
102  * \return number of points
103  */
104  size_t size() const;
105 
106  /**
107  * Determines whether this dataset can be used as a texture.
108  *
109  * \return true if usable as texture.
110  */
111  virtual bool isTexture() const;
112 
113  /**
114  * Gets the name of this prototype.
115  *
116  * \return the name.
117  */
118  virtual const std::string getName() const;
119 
120  /**
121  * Gets the description for this prototype.
122  *
123  * \return the description
124  */
125  virtual const std::string getDescription() const;
126 
127  /**
128  * Returns a prototype instantiated with the true type of the deriving class.
129  *
130  * \return the prototype.
131  */
132  static boost::shared_ptr< WPrototyped > getPrototype();
133 
134  /**
135  * Getter for the point vertices
136  * \return The vertices
137  */
138  VertexArray getVertices() const;
139 
140  /**
141  * Getter for the point colors
142  * \return The colors
143  */
144  ColorArray getColors() const;
145 
146  /**
147  * Get the bounding box.
148  * \return The bounding box of all points.
149  */
151 
152  /**
153  * Query coordinates of a given point.
154  *
155  * \throw WOutOfBounds if invalid index is used.
156  * \param pointIdx the point index.
157  *
158  * \return the coordinates
159  */
160  WPosition operator[]( const size_t pointIdx ) const;
161 
162  /**
163  * Query coordinates of a given point.
164  *
165  * \throw WOutOfBounds if invalid index is used.
166  * \param pointIdx the point index.
167  *
168  * \return the coordinates
169  */
170  WPosition getPosition( const size_t pointIdx ) const;
171 
172  /**
173  * The color of a given point.
174  *
175  * \throw WOutOfBounds if invalid index is used.
176  * \param pointIdx the point index.
177  *
178  * \return the color
179  */
180  WColor getColor( const size_t pointIdx ) const;
181 
182  /**
183  * Is this a valid point index?
184  *
185  * \param pointIdx the index to check
186  *
187  * \return true if yes.
188  */
189  bool isValidPointIdx( const size_t pointIdx ) const;
190 
191  /**
192  * The type of colors we have for each point.
193  */
195  {
196  GRAY = 1,
197  RGB = 3,
198  RGBA =4
199  };
200 
201  /**
202  * Check the type of color.
203  *
204  * \return the type
205  */
206  ColorType getColorType() const;
207 protected:
208  /**
209  * The prototype as singleton.
210  */
211  static boost::shared_ptr< WPrototyped > m_prototype;
212 
213 private:
214  /**
215  * Point vector for all points
216  */
217  VertexArray m_vertices;
218 
219  /**
220  * An array of the colors per vertex.
221  */
222  ColorArray m_colors;
223 
224  /**
225  * Which colortype do we use in m_colors.
226  */
228 
229  /**
230  * Axis aligned bounding box for all point-vertices of this dataset.
231  */
233 
234  /**
235  * Initialize arrays and bbox if needed. Used during construction.
236  *
237  * \param calcBB if true, the bounding box is calculated
238  */
239  void init( bool calcBB = false );
240 };
241 
242 #endif // WDATASETPOINTS_H
ColorArray getColors() const
Getter for the point colors.
WPosition getPosition(const size_t pointIdx) const
Query coordinates of a given point.
WPosition operator[](const size_t pointIdx) const
Query coordinates of a given point.
Dataset to store a bunch of points without order or topology.
Base class for all data set types.
Definition: WDataSet.h:51
WBoundingBox getBoundingBox() const
Get the bounding box.
virtual const std::string getDescription() const
Gets the description for this prototype.
boost::shared_ptr< WDataSetPoints > SPtr
Pointer to dataset.
WColor getColor(const size_t pointIdx) const
The color of a given point.
This only is a 3d double vector.
VertexArray m_vertices
Point vector for all points.
static boost::shared_ptr< WPrototyped > m_prototype
The prototype as singleton.
ColorArray m_colors
An array of the colors per vertex.
bool isValidPointIdx(const size_t pointIdx) const
Is this a valid point index?
boost::shared_ptr< const WDataSetPoints > ConstSPtr
Pointer to const dataset.
WDataSetPoints()
Constructs a new set of points.
VertexArray getVertices() const
Getter for the point vertices.
void init(bool calcBB=false)
Initialize arrays and bbox if needed.
virtual bool isTexture() const
Determines whether this dataset can be used as a texture.
virtual ~WDataSetPoints()
Destructor.
ColorType getColorType() const
Check the type of color.
virtual const std::string getName() const
Gets the name of this prototype.
WBoundingBox m_bb
Axis aligned bounding box for all point-vertices of this dataset.
ColorType m_colorType
Which colortype do we use in m_colors.
boost::shared_ptr< std::vector< float > > ColorArray
Colors for each vertex in VertexArray.
size_t size() const
Get number of points in this data set.
static boost::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
ColorType
The type of colors we have for each point.
boost::shared_ptr< std::vector< float > > VertexArray
List of vertex coordinates in term of components of vertices.