OpenWalnut  1.5.0dev
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 <any>
29 #include <memory>
30 #include <string>
31 #include <utility>
32 #include <vector>
33 
34 
35 #include "../common/WBoundingBox.h"
36 #include "WDataSet.h"
37 
38 /**
39  * Dataset to store a bunch of points without order or topology.
40  */
41 class WDataSetPoints : public WDataSet // NOLINT
42 {
43 public:
44  // some type alias for the used arrays.
45  /**
46  * Pointer to dataset.
47  */
48  typedef std::shared_ptr< WDataSetPoints > SPtr;
49 
50  /**
51  * Pointer to const dataset.
52  */
53  typedef std::shared_ptr< const WDataSetPoints > ConstSPtr;
54 
55  /**
56  * List of vertex coordinates in term of components of vertices.
57  */
58  typedef std::shared_ptr< std::vector< float > > VertexArray;
59 
60  /**
61  * Colors for each vertex in VertexArray.
62  */
63  typedef std::shared_ptr< std::vector< float > > ColorArray;
64 
65  /**
66  * Constructs a new set of points. If no color is specified, white is used for all points.
67  *
68  * \note the number of floats in vertices must be a multiple of 3
69  * \note the number of floats in colors (if not NULL) must be vertices->size() / 3 times one of 1,3, or 4
70  *
71  * \param vertices the vertices of the points, stored in x1,y1,z1,x2,y2,z2, ..., xn,yn,zn scheme
72  * \param colors the colors of each vertex. Can be NULL. Stored as R1,G1,B1,A1, ... Rn,Gn,Bn,An
73  * \param boundingBox The bounding box of the points (first minimum, second maximum).
74  */
75  WDataSetPoints( VertexArray vertices, ColorArray colors,
76  WBoundingBox boundingBox );
77 
78  /**
79  * Constructs a new set of points. The bounding box is calculated during construction. If no color is specified, white is used for all
80  * points.
81  *
82  * \note the number of floats in vertices must be a multiple of 3
83  * \note the number of floats in colors (if not NULL) must be vertices->size() / 3 times one of 1,3, or 4
84  *
85  * \param vertices the vertices of the points, stored in x1,y1,z1,x2,y2,z2, ..., xn,yn,zn scheme
86  * \param colors optional colors of each vertex. Stored as R1,[G1,B1,[A1,]] ... Rn,[Gn,Bn,[An]]
87  * \param data optional extra data.
88  */
89  WDataSetPoints( VertexArray vertices, ColorArray colors = NULL, std::any data = NULL );
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 std::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  * Getter for the data set
150  * \return The data set
151  */
152  std::any getData() const;
153 
154  /**
155  * Get the bounding box.
156  * \return The bounding box of all points.
157  */
159 
160  /**
161  * Query coordinates of a given point.
162  *
163  * \throw WOutOfBounds if invalid index is used.
164  * \param pointIdx the point index.
165  *
166  * \return the coordinates
167  */
168  WPosition operator[]( const size_t pointIdx ) const;
169 
170  /**
171  * Query coordinates of a given point.
172  *
173  * \throw WOutOfBounds if invalid index is used.
174  * \param pointIdx the point index.
175  *
176  * \return the coordinates
177  */
178  WPosition getPosition( const size_t pointIdx ) const;
179 
180  /**
181  * The color of a given point.
182  *
183  * \throw WOutOfBounds if invalid index is used.
184  * \param pointIdx the point index.
185  *
186  * \return the color
187  */
188  WColor getColor( const size_t pointIdx ) const;
189 
190  /**
191  * Is this a valid point index?
192  *
193  * \param pointIdx the index to check
194  *
195  * \return true if yes.
196  */
197  bool isValidPointIdx( const size_t pointIdx ) const;
198 
199  /**
200  * The type of colors we have for each point.
201  */
203  {
204  GRAY = 1,
205  RGB = 3,
206  RGBA =4
207  };
208 
209  /**
210  * Check the type of color.
211  *
212  * \return the type
213  */
214  ColorType getColorType() const;
215 protected:
216  /**
217  * The prototype as singleton.
218  */
219  static std::shared_ptr< WPrototyped > m_prototype;
220 
221 private:
222  /**
223  * Point vector for all points
224  */
226 
227  /**
228  * An array of the colors per vertex.
229  */
231 
232  /**
233  * An optional vector for data per vertex.
234  */
235  std::any m_data;
236 
237  /**
238  * Which colortype do we use in m_colors.
239  */
241 
242  /**
243  * Axis aligned bounding box for all point-vertices of this dataset.
244  */
246 
247  /**
248  * Initialize arrays and bbox if needed. Used during construction.
249  *
250  * \param calcBB if true, the bounding box is calculated
251  */
252  void init( bool calcBB = false );
253 };
254 
255 #endif // WDATASETPOINTS_H
Dataset to store a bunch of points without order or topology.
virtual const std::string getName() const
Gets the name of this prototype.
std::shared_ptr< WDataSetPoints > SPtr
Pointer to dataset.
VertexArray getVertices() const
Getter for the point vertices.
bool isValidPointIdx(const size_t pointIdx) const
Is this a valid point index?
WColor getColor(const size_t pointIdx) const
The color of a given point.
ColorArray getColors() const
Getter for the point colors.
WBoundingBox m_bb
Axis aligned bounding box for all point-vertices of this dataset.
ColorArray m_colors
An array of the colors per vertex.
std::any m_data
An optional vector for data per vertex.
size_t size() const
Get number of points in this data set.
static std::shared_ptr< WPrototyped > m_prototype
The prototype as singleton.
VertexArray m_vertices
Point vector for all points.
ColorType m_colorType
Which colortype do we use in m_colors.
virtual const std::string getDescription() const
Gets the description for this prototype.
ColorType
The type of colors we have for each point.
virtual bool isTexture() const
Determines whether this dataset can be used as a texture.
void init(bool calcBB=false)
Initialize arrays and bbox if needed.
std::shared_ptr< std::vector< float > > ColorArray
Colors for each vertex in VertexArray.
WPosition getPosition(const size_t pointIdx) const
Query coordinates of a given point.
ColorType getColorType() const
Check the type of color.
std::shared_ptr< std::vector< float > > VertexArray
List of vertex coordinates in term of components of vertices.
std::shared_ptr< const WDataSetPoints > ConstSPtr
Pointer to const dataset.
WPosition operator[](const size_t pointIdx) const
Query coordinates of a given point.
static std::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
std::any getData() const
Getter for the data set.
virtual ~WDataSetPoints()
Destructor.
WBoundingBox getBoundingBox() const
Get the bounding box.
WDataSetPoints()
Constructs a new set of points.
Base class for all data set types.
Definition: WDataSet.h:50
This only is a 3d double vector.