CMultiPoint.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2016, CHAI3D.
5  (www.chai3d.org)
6 
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following
18  disclaimer in the documentation and/or other materials provided
19  with the distribution.
20 
21  * Neither the name of CHAI3D nor the names of its contributors may
22  be used to endorse or promote products derived from this software
23  without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  POSSIBILITY OF SUCH DAMAGE.
37 
38  \author <http://www.chai3d.org>
39  \author Francois Conti
40  \version 3.2.0 $Rev: 2161 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 #ifndef CMultiPointH
46 #define CMultiPointH
47 //------------------------------------------------------------------------------
48 #include "world/CGenericObject.h"
49 #include "materials/CMaterial.h"
50 #include "materials/CTexture2d.h"
51 #include "graphics/CColor.h"
52 //------------------------------------------------------------------------------
53 #include <vector>
54 #include <list>
55 //------------------------------------------------------------------------------
56 
57 //------------------------------------------------------------------------------
58 namespace chai3d {
59 //------------------------------------------------------------------------------
60 
61 //------------------------------------------------------------------------------
62 class cWorld;
63 //------------------------------------------------------------------------------
64 
65 //==============================================================================
72 //==============================================================================
73 
74 //------------------------------------------------------------------------------
76 class cVertexArray;
77 typedef std::shared_ptr<cVertexArray> cVertexArrayPtr;
78 
80 class cPointArray;
81 typedef std::shared_ptr<cPointArray> cPointArrayPtr;
82 //------------------------------------------------------------------------------
83 
84 //==============================================================================
95 //==============================================================================
97 {
98  //--------------------------------------------------------------------------
99  // CONSTRUCTOR & DESTRUCTOR:
100  //--------------------------------------------------------------------------
101 
102 public:
103 
105  cMultiPoint();
106 
108  virtual ~cMultiPoint();
109 
110 
111  //--------------------------------------------------------------------------
112  // PUBLIC METHODS - GENERAL
113  //--------------------------------------------------------------------------
114 
115 public:
116 
118  virtual cMultiPoint* copy(const bool a_duplicateMaterialData = false,
119  const bool a_duplicateTextureData = false,
120  const bool a_duplicateMeshData = false,
121  const bool a_buildCollisionDetector = false);
122 
123 
124  //--------------------------------------------------------------------------
125  // PUBLIC METHODS - VERTICES
126  //--------------------------------------------------------------------------
127 
128 public:
129 
131  unsigned int newVertex(const double a_x = 0.0,
132  const double a_y = 0.0,
133  const double a_z = 0.0);
134 
136  unsigned int newVertex(const cVector3d& a_pos,
137  const cColorf& a_color = cColorf(0,0,0,1));
138 
140  inline unsigned int getNumVertices() const { return (unsigned int)(m_vertices->getNumElements()); }
141 
142 
143  //--------------------------------------------------------------------------
144  // PUBLIC METHODS - POINTS
145  //--------------------------------------------------------------------------
146 
147 public:
148 
150  unsigned int newPoint(const unsigned int a_indexVertex0);
151 
153  unsigned int newPoint(const cVector3d& a_vertex0 = cVector3d(0,0,0),
154  const cColorf& a_colorVertex0 = cColorf(0,0,0,1));
155 
157  bool removePoint(const unsigned int a_index);
158 
160  unsigned int getNumPoints();
161 
163  void clear();
164 
165 
166  //-----------------------------------------------------------------------
167  // PUBLIC METHODS - GRAPHIC PROPERTIES:
168  //-----------------------------------------------------------------------
169 
170 public:
171 
173  virtual void setTransparencyLevel(const float a_level,
174  const bool a_applyToVertices = false,
175  const bool a_applyToTextures = false,
176  const bool a_affectChildren = false);
177 
178 
179  //-----------------------------------------------------------------------
180  // PUBLIC METHODS - DISPLAY LISTS:
181  //-----------------------------------------------------------------------
182 
183 public:
184 
186  virtual void markForUpdate(const bool a_affectChildren = false);
187 
188 
189  //--------------------------------------------------------------------------
190  // PUBLIC METHODS - POINTS GRAPHIC PROPERTIES
191  //--------------------------------------------------------------------------
192 
193 public:
194 
196  void setPointColor(const cColorf& a_color);
197 
199  inline void setPointSize(const double a_pointSize) { m_pointSize = fabs(a_pointSize); }
200 
202  inline double getPointSize() const { return (m_pointSize); }
203 
204 
205  //--------------------------------------------------------------------------
206  // PUBLIC METHODS - COLLISION DETECTION:
207  //--------------------------------------------------------------------------
208 
209 public:
210 
212  virtual void createBruteForceCollisionDetector();
213 
215  virtual void createAABBCollisionDetector(const double a_radius);
216 
217 
218  //--------------------------------------------------------------------------
219  // PUBLIC VIRTUAL METHODS - FILES:
220  //--------------------------------------------------------------------------
221 
222 public:
223 
225  virtual bool loadFromFile(std::string a_filename);
226 
228  virtual bool saveToFile(std::string a_filename);
229 
230 
231  //--------------------------------------------------------------------------
232  // PUBLIC METHODS - GEOMETRY:
233  //--------------------------------------------------------------------------
234 
235 public:
236 
238  void scaleXYZ(const double a_scaleX, const double a_scaleY, const double a_scaleZ);
239 
241  virtual void offsetVertices(const cVector3d& a_offset,
242  const bool a_updateCollisionDetector = true);
243 
245  virtual cVector3d getCenterOfMass();
246 
247 
248  //--------------------------------------------------------------------------
249  // PROTECTED METHODS - INTERNAL
250  //--------------------------------------------------------------------------
251 
252 protected:
253 
255  virtual void render(cRenderOptions& a_options);
256 
258  virtual void renderPoints(cRenderOptions& a_options);
259 
261  virtual void updateGlobalPositions(const bool a_frameOnly);
262 
264  virtual void updateBoundaryBox();
265 
268  const bool a_duplicateMaterialData = false,
269  const bool a_duplicateTextureData = false,
270  const bool a_duplicateMeshData = false,
271  const bool a_buildCollisionDetector = false);
272 
274  virtual void scaleObject(const double& a_scaleFactor) { scaleXYZ(a_scaleFactor, a_scaleFactor, a_scaleFactor); }
275 
276 
277  //--------------------------------------------------------------------------
278  // PROTECTED MEMBERS - DISPLAY PROPERTIES:
279  //--------------------------------------------------------------------------
280 
281 protected:
282 
285 
287  double m_pointSize;
288 
289 
290  //--------------------------------------------------------------------------
291  // PUBLIC MEMBERS - POINT AND VERTEX DATA:
292  //--------------------------------------------------------------------------
293 
294 public:
295 
297  cVertexArrayPtr m_vertices;
298 
300  cPointArrayPtr m_points;
301 };
302 
303 //------------------------------------------------------------------------------
304 } // namespace chai3d
305 //------------------------------------------------------------------------------
306 
307 //------------------------------------------------------------------------------
308 #endif
309 //------------------------------------------------------------------------------
This class implements a 3D vector.
Definition: CVector3d.h:88
This structures provide a containers for storing rendering options that are passed through the sceneg...
Definition: CRenderOptions.h:82
std::shared_ptr< cPointArray > cPointArrayPtr
Definition: CPointArray.h:71
This class implements 3D point cloud object.
Definition: CMultiPoint.h:96
virtual void render(cRenderOptions &a_options)
This method renders this object graphically using OpenGL.
Definition: CMultiPoint.cpp:737
virtual void createBruteForceCollisionDetector()
This method builds a brute force collision detector for this mesh.
Definition: CMultiPoint.cpp:588
double m_pointSize
Display size of point.
Definition: CMultiPoint.h:287
virtual bool saveToFile(std::string a_filename)
This method saves a 3D point cloud to a file.
Definition: CMultiPoint.cpp:694
unsigned int newVertex(const double a_x=0.0, const double a_y=0.0, const double a_z=0.0)
This method creates a new vertex and adds it to the vertex list.
Definition: CMultiPoint.cpp:255
void clear()
This method clears all points and vertices.
Definition: CMultiPoint.cpp:369
void scaleXYZ(const double a_scaleX, const double a_scaleY, const double a_scaleZ)
This method scales this point cloud by using different scale factors along X, Y and Z axes...
Definition: CMultiPoint.cpp:389
virtual bool loadFromFile(std::string a_filename)
This method loads a 3D point cloud from a file.
Definition: CMultiPoint.cpp:637
virtual void markForUpdate(const bool a_affectChildren=false)
This method invalidates any existing display lists and marks the mesh for update. ...
Definition: CMultiPoint.cpp:432
virtual void renderPoints(cRenderOptions &a_options)
This method renders all points.
Definition: CMultiPoint.cpp:770
double getPointSize() const
This method returns the point size.
Definition: CMultiPoint.h:202
virtual ~cMultiPoint()
Destructor of cMultiPoint.
Definition: CMultiPoint.cpp:101
This class implements a base class for all 2D or 3D objects in CHAI3D.
Definition: CGenericObject.h:112
unsigned int newPoint(const unsigned int a_indexVertex0)
This method creates a new point by passing a vertex index.
Definition: CMultiPoint.cpp:302
virtual void updateBoundaryBox()
This method updates the boundary box dimensions based on the vertices.
Definition: CMultiPoint.cpp:531
unsigned int getNumPoints()
This method returns the number of stored points.
Definition: CMultiPoint.cpp:238
Implements a base class for all objects.
virtual void offsetVertices(const cVector3d &a_offset, const bool a_updateCollisionDetector=true)
This method shifts all vertex positions by the specified amount.
Definition: CMultiPoint.cpp:502
void copyMultiPointProperties(cMultiPoint *a_obj, const bool a_duplicateMaterialData=false, const bool a_duplicateTextureData=false, const bool a_duplicateMeshData=false, const bool a_buildCollisionDetector=false)
This method copies all properties of this point cloud to another.
Definition: CMultiPoint.cpp:151
virtual void createAABBCollisionDetector(const double a_radius)
This method builds an AABB collision detector for this mesh.
Definition: CMultiPoint.cpp:609
virtual cVector3d getCenterOfMass()
This method computes the center of mass of this point cloud, based on vertex positions.
Definition: CMultiPoint.cpp:212
virtual cMultiPoint * copy(const bool a_duplicateMaterialData=false, const bool a_duplicateTextureData=false, const bool a_duplicateMeshData=false, const bool a_buildCollisionDetector=false)
This method creates a copy of itself.
Definition: CMultiPoint.cpp:120
std::shared_ptr< cVertexArray > cVertexArrayPtr
Definition: CVertexArray.h:107
This class defines a color using a GLfloat representation for each component.
Definition: CColor.h:138
Implements color properties.
virtual void setTransparencyLevel(const float a_level, const bool a_applyToVertices=false, const bool a_applyToTextures=false, const bool a_affectChildren=false)
This method sets the alpha value at each vertex and in all of my material colors. ...
Definition: CMultiPoint.cpp:453
cPointArrayPtr m_points
Array of points.
Definition: CMultiPoint.h:300
void setPointSize(const double a_pointSize)
This method sets the point size that is used to graphically render the points.
Definition: CMultiPoint.h:199
Implements material properties.
cVertexArrayPtr m_vertices
Array of vertices.
Definition: CMultiPoint.h:297
Definition: CAudioBuffer.cpp:56
Implements 2D textures.
virtual void scaleObject(const double &a_scaleFactor)
This method scales this object by a scale factor.
Definition: CMultiPoint.h:274
bool m_showPoints
If true, then segments are displayed.
Definition: CMultiPoint.h:284
unsigned int getNumVertices() const
This method returns the number of stored vertices.
Definition: CMultiPoint.h:140
void setPointColor(const cColorf &a_color)
This method sets a color for all points.
Definition: CMultiPoint.cpp:482
cMultiPoint()
Constructor of cMultiPoint.
Definition: CMultiPoint.cpp:71
bool removePoint(const unsigned int a_index)
This method removed a selected point.
Definition: CMultiPoint.cpp:352
virtual void updateGlobalPositions(const bool a_frameOnly)
This method updates the global position of each vertex.
Definition: CMultiPoint.cpp:410