GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_geometry.h
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21 *****************************************************************************/
22 
24 
25 #ifndef GLC_GEOMETRY_H_
26 #define GLC_GEOMETRY_H_
27 #include "../shading/glc_material.h"
28 #include "../shading/glc_renderproperties.h"
29 #include "glc_wiredata.h"
30 #include "../glc_boundingbox.h"
31 
32 #include "../glc_config.h"
33 
34 typedef QHash<GLC_uint, GLC_Material*> MaterialHash;
35 typedef QHash<GLC_uint, GLC_uint> MaterialHashMap;
36 
39 
61 
62 
64 {
66 
68 
69 public:
71  GLC_Geometry(const QString &name, const bool type);
72 
74  GLC_Geometry(const GLC_Geometry& sourceGeom);
75 
77  GLC_Geometry& operator=(const GLC_Geometry& sourceGeom);
78 
80  virtual ~GLC_Geometry();
82 
84 
86 
87 public:
89  inline GLC_uint id() const
90  {return m_Id;}
91 
93  inline QString name() const
94  {return m_Name;}
95 
97  inline bool isValid(void) const
98  {return m_GeometryIsValid;}
99 
101  inline bool hasMaterial() const
102  {return !m_MaterialHash.isEmpty();}
103 
105  inline GLC_Material* firstMaterial(void) const
106  {
107  if (!m_MaterialHash.isEmpty())
108  {
109  return m_MaterialHash.begin().value();
110  }
111  else return NULL;
112  }
113 
115  inline int materialCount() const
116  {return m_MaterialHash.size();}
117 
119  inline GLC_Material* material(const GLC_uint key) const
120  {return m_MaterialHash[key];}
121 
123  inline QSet<GLC_Material*> materialSet() const
124  {return m_MaterialHash.values().toSet();}
125 
127  inline QList<GLC_uint> materialIds() const
128  {return m_MaterialHash.keys();}
129 
131  inline bool containsMaterial(const GLC_uint key) const
132  {return m_MaterialHash.contains(key);}
133 
135  virtual const GLC_BoundingBox& boundingBox(void) = 0;
136 
138  inline bool boundingBoxIsValid() const
139  {return NULL != m_pBoundingBox;}
140 
142  virtual GLC_Geometry* clone() const = 0;
143 
145  inline bool isTransparent() const
146  {return (m_TransparentMaterialNumber >= m_MaterialHash.size()) && hasTransparentMaterials();}
147 
149  inline bool hasTransparentMaterials() const
150  {return m_TransparentMaterialNumber > 0;}
151 
153  inline bool usedColorPerVertex() const
154  {return m_UseColorPerVertex;}
155 
157  inline bool typeIsWire() const
158  {return m_IsWire;}
159 
161  virtual unsigned int faceCount(int lod=0) const;
162 
164  virtual unsigned int VertexCount() const;
165 
167  GLfloat lineWidth() const
168  {return m_LineWidth;}
169 
171  inline QColor wireColor() const
172  {return m_WireColor;}
173 
175  inline bool wireDataIsEmpty() const
176  {return m_WireData.isEmpty();}
177 
179  inline GLfloatVector wirePositionVector() const
180  {return m_WireData.positionVector();}
181 
183  inline int wirePolylineCount() const
184  {return m_WireData.verticeGroupCount();}
185 
187  inline GLuint wirePolylineOffset(int index) const
188  {return m_WireData.verticeGroupOffset(index);}
189 
191  inline GLsizei wirePolylineSize(int index) const
192  {return m_WireData.verticeGroupSize(index);}
193 
195  virtual double volume();
196 
198  inline bool vboIsUsed() const
199  {return m_UseVbo;}
200 
202 
204 
206 
207 public:
208 
210  virtual void clear();
211 
213  virtual void replaceMasterMaterial(GLC_Material*);
214 
216  void addMaterial(GLC_Material *);
217 
219  inline void colorPerVertex(const bool colorPerVertex)
220  {
221  if (m_UseColorPerVertex != colorPerVertex)
222  {
223  m_UseColorPerVertex= colorPerVertex;
224  m_GeometryIsValid= false;
225  }
226  }
227 
229  void updateTransparentMaterialNumber();
230 
232  virtual void reverseNormals() {}
233 
235 
236  virtual void setCurrentLod(const int) {}
237 
239  inline void setId(const GLC_uint id)
240  {m_Id= id;}
241 
243  inline void setName(const QString name)
244  {m_Name= name;}
245 
247  inline GLC_uint addVerticeGroup(const GLfloatVector& vector)
248  {return m_WireData.addVerticeGroup(vector);}
249 
251  inline void setLineWidth(GLfloat lineWidth)
252  {m_LineWidth= lineWidth;}
253 
255  void setWireColor(const QColor& color);
256 
258  virtual void copyVboToClientSide();
259 
261  virtual void releaseVboClientSide(bool update= false);
262 
264  virtual void setVboUsage(bool usage);
265 
267 
268 
270 
271 public:
273  virtual void glLoadTexture(void);
274 
276  virtual void render(const GLC_RenderProperties&);
277 
278 
279 protected:
281 
282  virtual void glDraw(const GLC_RenderProperties&) = 0;
283 
285  virtual void glPropGeom(const GLC_RenderProperties&);
286 
288 
289 
291 
292 protected:
294  void removeMaterial(GLC_uint);
295 
297  inline void clearWireAndBoundingBox()
298  {
299  delete m_pBoundingBox;
300  m_pBoundingBox= NULL;
301  m_WireData.clear();
302  m_GeometryIsValid= false;
303  }
304 
306 
308 
310 
311 private:
313  void clearGeometry();
314 
316 
318 // Protected members
320 protected:
321 
324 
327 
330 
333 
336 
339 
341  QColor m_WireColor;
342 
344  GLfloat m_LineWidth;
345 
346 
348 // Private members
350 private:
351 
353  bool m_IsWire;
354 
357 
359 
361 
363  QString m_Name;
364 
366  bool m_UseVbo;
367 };
368 
369 #endif /*GLC_GEOMETRY_H_*/

©2005-2013 Laurent Ribon