glc_geometry.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00026
00027 #ifndef GLC_GEOMETRY_H_
00028 #define GLC_GEOMETRY_H_
00029 #include "../shading/glc_material.h"
00030 #include "../shading/glc_renderproperties.h"
00031 #include "glc_wiredata.h"
00032 #include "../glc_boundingbox.h"
00033
00034 #include "glc_config.h"
00035
00036 typedef QHash<GLC_uint, GLC_Material*> MaterialHash;
00037 typedef QHash<GLC_uint, GLC_uint> MaterialHashMap;
00038
00041
00063
00064
00065 class GLC_LIB_EXPORT GLC_Geometry
00066 {
00068
00070
00071 public:
00073
00077 GLC_Geometry(const QString &, const bool);
00079
00082 GLC_Geometry(const GLC_Geometry&);
00083
00085 GLC_Geometry& operator=(const GLC_Geometry&);
00086
00088 virtual ~GLC_Geometry();
00090
00092
00094
00095 public:
00097 inline GLC_uint id() const
00098 {return m_Id;}
00099
00101 inline QString name() const
00102 {return m_Name;}
00103
00105 inline bool isValid(void) const
00106 {return m_GeometryIsValid;}
00107
00109 inline bool hasMaterial() const
00110 {return !m_MaterialHash.isEmpty();}
00111
00113 inline GLC_Material* firstMaterial(void) const
00114 {
00115 if (!m_MaterialHash.isEmpty())
00116 {
00117 return m_MaterialHash.begin().value();
00118 }
00119 else return NULL;
00120 }
00121
00123 inline int materialCount() const
00124 {return m_MaterialHash.size();}
00125
00127 inline GLC_Material* material(const GLC_uint key) const
00128 {return m_MaterialHash[key];}
00129
00131 inline QSet<GLC_Material*> materialSet() const
00132 {return m_MaterialHash.values().toSet();}
00133
00135 inline QList<GLC_uint> materialIds() const
00136 {return m_MaterialHash.keys();}
00137
00139 inline bool containsMaterial(const GLC_uint key) const
00140 {return m_MaterialHash.contains(key);}
00141
00143 virtual const GLC_BoundingBox& boundingBox(void) = 0;
00144
00146 inline bool boundingBoxIsValid() const
00147 {return NULL != m_pBoundingBox;}
00148
00150 virtual GLC_Geometry* clone() const = 0;
00151
00153 inline bool isTransparent() const
00154 {return (m_TransparentMaterialNumber >= m_MaterialHash.size()) && hasTransparentMaterials();}
00155
00157 inline bool hasTransparentMaterials() const
00158 {return m_TransparentMaterialNumber > 0;}
00159
00161 inline bool usedColorPerVertex() const
00162 {return m_UseColorPerVertex;}
00163
00165 inline bool typeIsWire() const
00166 {return m_IsWire;}
00167
00169 virtual unsigned int faceCount(int lod=0) const;
00170
00172 virtual unsigned int VertexCount() const;
00173
00175 GLfloat lineWidth() const
00176 {return m_LineWidth;}
00177
00179 inline QColor wireColor() const
00180 {return m_WireColor;}
00181
00183 inline bool wireDataIsEmpty() const
00184 {return m_WireData.isEmpty();}
00185
00187 inline GLfloatVector wirePositionVector() const
00188 {return m_WireData.positionVector();}
00189
00191 inline int wirePolylineCount() const
00192 {return m_WireData.polylineCount();}
00193
00195 inline GLuint wirePolylineOffset(int index) const
00196 {return m_WireData.polylineOffset(index);}
00197
00199 inline GLsizei wirePolylineSize(int index) const
00200 {return m_WireData.polylineSize(index);}
00201
00203
00205
00207
00208 public:
00209
00211 virtual void clear();
00212
00214 virtual void replaceMasterMaterial(GLC_Material*);
00215
00217 void addMaterial(GLC_Material *);
00218
00220 inline void colorPerVertex(const bool colorPerVertex)
00221 {
00222 if (m_UseColorPerVertex != colorPerVertex)
00223 {
00224 m_UseColorPerVertex= colorPerVertex;
00225 m_GeometryIsValid= false;
00226 }
00227 }
00228
00230 void updateTransparentMaterialNumber();
00231
00233 virtual void reverseNormals() {}
00234
00236
00237 virtual void setCurrentLod(const int) {}
00238
00240 inline void setId(const GLC_uint id)
00241 {m_Id= id;}
00242
00244 inline void setName(const QString name)
00245 {m_Name= name;}
00246
00248 inline GLC_uint addPolyline(const GLfloatVector& vector)
00249 {return m_WireData.addPolyline(vector);}
00250
00252 inline void setLineWidth(GLfloat lineWidth)
00253 {m_LineWidth= lineWidth;}
00254
00256 void setWireColor(const QColor& color);
00257
00259 virtual void copyVboToClientSide();
00260
00262 virtual void releaseVboClientSide(bool update= false);
00263
00265
00266
00268
00269 public:
00271 virtual void glLoadTexture(void);
00272
00274 virtual void render(const GLC_RenderProperties&);
00275
00276
00277 protected:
00279
00280 virtual void glDraw(const GLC_RenderProperties&) = 0;
00281
00283 virtual void glPropGeom(const GLC_RenderProperties&);
00284
00286
00287
00289
00290 protected:
00292 void removeMaterial(GLC_uint);
00293
00295 inline void clearWireAndBoundingBox()
00296 {
00297 delete m_pBoundingBox;
00298 m_pBoundingBox= NULL;
00299 m_WireData.clear();
00300 m_GeometryIsValid= false;
00301 }
00302
00304
00306
00308
00309 private:
00311 void clearGeometry();
00312
00314
00316
00318 protected:
00319
00321 bool m_GeometryIsValid;
00322
00324 GLC_BoundingBox* m_pBoundingBox;
00325
00327 MaterialHash m_MaterialHash;
00328
00330 bool m_UseColorPerVertex;
00331
00333 bool m_IsSelected;
00334
00336 GLC_WireData m_WireData;
00337
00339 QColor m_WireColor;
00340
00342 GLfloat m_LineWidth;
00343
00344
00346
00348 private:
00349
00351 bool m_IsWire;
00352
00354 int m_TransparentMaterialNumber;
00355
00357
00358 GLC_uint m_Id;
00359
00361 QString m_Name;
00362 };
00363
00364 #endif