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 #ifndef Q_MOC_RUN
33 #include <boost/shared_ptr.hpp>
34 #endif
35 
36 #include "../common/WBoundingBox.h"
37 #include "WDataSet.h"
38 
39 /**
40  * Dataset to store a bunch of points without order or topology.
41  */
42 class WDataSetPoints : public WDataSet // NOLINT
43 {
44 public:
45  // some type alias for the used arrays.
46  /**
47  * Pointer to dataset.
48  */
49  typedef boost::shared_ptr< WDataSetPoints > SPtr;
50 
51  /**
52  * Pointer to const dataset.
53  */
54  typedef boost::shared_ptr< const WDataSetPoints > ConstSPtr;
55 
56  /**
57  * List of vertex coordinates in term of components of vertices.
58  */
59  typedef boost::shared_ptr< std::vector< float > > VertexArray;
60 
61  /**
62  * Colors for each vertex in VertexArray.
63  */
64  typedef boost::shared_ptr< std::vector< float > > ColorArray;
65 
66  /**
67  * Constructs a new set of points. If no color is specified, white is used for all points.
68  *
69  * \note the number of floats in vertices must be a multiple of 3
70  * \note the number of floats in colors (if not NULL) must be vertices->size() / 3 times one of 1,3, or 4
71  *
72  * \param vertices the vertices of the points, stored in x1,y1,z1,x2,y2,z2, ..., xn,yn,zn scheme
73  * \param colors the colors of each vertex. Can be NULL.. Stored as R1,G1,B1,A1, ... Rn,Gn,Bn,An
74  * \param boundingBox The bounding box of the points (first minimum, second maximum).
75  */
76  WDataSetPoints( VertexArray vertices, ColorArray colors,
77  WBoundingBox boundingBox );
78 
79  /**
80  * Constructs a new set of points. The bounding box is calculated during construction. If no color is specified, white is used for all
81  * points.
82  *
83  * \note the number of floats in vertices must be a multiple of 3
84  * \note the number of floats in colors (if not NULL) must be vertices->size() / 3 times one of 1,3, or 4
85  *
86  * \param vertices the vertices of the points, stored in x1,y1,z1,x2,y2,z2, ..., xn,yn,zn scheme
87  * \param colors the colors of each vertex. Can be NULL.. Stored as R1,[G1,B1,[A1,]] ... Rn,[Gn,Bn,[An]]
88  */
89  WDataSetPoints( VertexArray vertices, ColorArray colors );
90 
91  /**
92  * Constructs a new set of points. The constructed instance is empty..
93  */
95 
96  /**
97  * Destructor.
98  */
99  virtual ~WDataSetPoints();
100 
101  /**
102  * Get number of points in this data set.
103  *
104  * \return number of points
105  */
106  size_t size() const;
107 
108  /**
109  * Determines whether this dataset can be used as a texture.
110  *
111  * \return true if usable as texture.
112  */
113  virtual bool isTexture() const;
114 
115  /**
116  * Gets the name of this prototype.
117  *
118  * \return the name.
119  */
120  virtual const std::string getName() const;
121 
122  /**
123  * Gets the description for this prototype.
124  *
125  * \return the description
126  */
127  virtual const std::string getDescription() const;
128 
129  /**
130  * Returns a prototype instantiated with the true type of the deriving class.
131  *
132  * \return the prototype.
133  */
134  static boost::shared_ptr< WPrototyped > getPrototype();
135 
136  /**
137  * Getter for the point vertices
138  * \return The vertices
139  */
140  VertexArray getVertices() const;
141 
142  /**
143  * Getter for the point colors
144  * \return The colors
145  */
146  ColorArray getColors() const;
147 
148  /**
149  * Get the bounding box.
150  * \return The bounding box of all points.
151  */
153 
154  /**
155  * Query coordinates of a given point.
156  *
157  * \throw WOutOfBounds if invalid index is used.
158  * \param pointIdx the point index.
159  *
160  * \return the coordinates
161  */
162  WPosition operator[]( const size_t pointIdx ) const;
163 
164  /**
165  * Query coordinates of a given point.
166  *
167  * \throw WOutOfBounds if invalid index is used.
168  * \param pointIdx the point index.
169  *
170  * \return the coordinates
171  */
172  WPosition getPosition( const size_t pointIdx ) const;
173 
174  /**
175  * The color of a given point.
176  *
177  * \throw WOutOfBounds if invalid index is used.
178  * \param pointIdx the point index.
179  *
180  * \return the color
181  */
182  WColor getColor( const size_t pointIdx ) const;
183 
184  /**
185  * Is this a valid point index?
186  *
187  * \param pointIdx the index to check
188  *
189  * \return true if yes.
190  */
191  bool isValidPointIdx( const size_t pointIdx ) const;
192 
193  /**
194  * The type of colors we have for each point.
195  */
197  {
198  GRAY = 1,
199  RGB = 3,
200  RGBA =4
201  };
202 
203  /**
204  * Check the type of color.
205  *
206  * \return the type
207  */
208  ColorType getColorType() const;
209 protected:
210  /**
211  * The prototype as singleton.
212  */
213  static boost::shared_ptr< WPrototyped > m_prototype;
214 
215 private:
216  /**
217  * Point vector for all points
218  */
219  VertexArray m_vertices;
220 
221  /**
222  * An array of the colors per vertex.
223  */
224  ColorArray m_colors;
225 
226  /**
227  * Which colortype do we use in m_colors.
228  */
230 
231  /**
232  * Axis aligned bounding box for all point-vertices of this dataset.
233  */
235 
236  /**
237  * Initialize arrays and bbox if needed. Used during construction.
238  *
239  * \param calcBB if true, the bounding box is calculated
240  */
241  void init( bool calcBB = false );
242 };
243 
244 #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:55
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.