glc_geometry.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 *****************************************************************************/
00022 
00024 
00025 #ifndef GLC_GEOMETRY_H_
00026 #define GLC_GEOMETRY_H_
00027 #include "../shading/glc_material.h"
00028 #include "../shading/glc_renderproperties.h"
00029 #include "glc_wiredata.h"
00030 #include "../glc_boundingbox.h"
00031 
00032 #include "../glc_config.h"
00033 
00034 typedef QHash<GLC_uint, GLC_Material*> MaterialHash;
00035 typedef QHash<GLC_uint, GLC_uint> MaterialHashMap;
00036 
00039 
00061 
00062 
00063 class GLC_LIB_EXPORT GLC_Geometry
00064 {
00066 
00068 
00069 public:
00071         GLC_Geometry(const QString &name, const bool type);
00072 
00074         GLC_Geometry(const GLC_Geometry& sourceGeom);
00075 
00077         GLC_Geometry& operator=(const GLC_Geometry& sourceGeom);
00078 
00080         virtual ~GLC_Geometry();
00082 
00084 
00086 
00087 public:
00089         inline GLC_uint id() const
00090         {return m_Id;}
00091 
00093         inline QString name() const
00094         {return m_Name;}
00095 
00097         inline bool isValid(void) const
00098         {return m_GeometryIsValid;}
00099 
00101         inline bool hasMaterial() const
00102         {return !m_MaterialHash.isEmpty();}
00103 
00105         inline GLC_Material* firstMaterial(void) const
00106         {
00107                 if (!m_MaterialHash.isEmpty())
00108                 {
00109                         return m_MaterialHash.begin().value();
00110                 }
00111                 else return NULL;
00112         }
00113 
00115         inline int materialCount() const
00116         {return m_MaterialHash.size();}
00117 
00119         inline GLC_Material* material(const GLC_uint key) const
00120         {return m_MaterialHash[key];}
00121 
00123         inline QSet<GLC_Material*> materialSet() const
00124         {return m_MaterialHash.values().toSet();}
00125 
00127         inline QList<GLC_uint> materialIds() const
00128         {return m_MaterialHash.keys();}
00129 
00131         inline bool containsMaterial(const GLC_uint key) const
00132         {return m_MaterialHash.contains(key);}
00133 
00135         virtual const GLC_BoundingBox& boundingBox(void) = 0;
00136 
00138         inline bool boundingBoxIsValid() const
00139         {return NULL != m_pBoundingBox;}
00140 
00142         virtual GLC_Geometry* clone() const = 0;
00143 
00145         inline bool isTransparent() const
00146         {return (m_TransparentMaterialNumber >= m_MaterialHash.size()) && hasTransparentMaterials();}
00147 
00149         inline bool hasTransparentMaterials() const
00150         {return m_TransparentMaterialNumber > 0;}
00151 
00153         inline bool usedColorPerVertex() const
00154         {return m_UseColorPerVertex;}
00155 
00157         inline bool typeIsWire() const
00158         {return m_IsWire;}
00159 
00161         virtual unsigned int faceCount(int lod=0) const;
00162 
00164         virtual unsigned int VertexCount() const;
00165 
00167         GLfloat lineWidth() const
00168         {return m_LineWidth;}
00169 
00171         inline QColor wireColor() const
00172         {return m_WireColor;}
00173 
00175         inline bool wireDataIsEmpty() const
00176         {return m_WireData.isEmpty();}
00177 
00179         inline GLfloatVector wirePositionVector() const
00180         {return m_WireData.positionVector();}
00181 
00183         inline int wirePolylineCount() const
00184         {return m_WireData.verticeGroupCount();}
00185 
00187         inline GLuint wirePolylineOffset(int index) const
00188         {return m_WireData.verticeGroupOffset(index);}
00189 
00191         inline GLsizei wirePolylineSize(int index) const
00192         {return m_WireData.verticeGroupSize(index);}
00193 
00195         virtual double volume();
00196 
00198         inline bool vboIsUsed() const
00199         {return m_UseVbo;}
00200 
00202 
00204 
00206 
00207 public:
00208 
00210         virtual void clear();
00211 
00213         virtual void replaceMasterMaterial(GLC_Material*);
00214 
00216         void addMaterial(GLC_Material *);
00217 
00219         inline void colorPerVertex(const bool colorPerVertex)
00220         {
00221                 if (m_UseColorPerVertex != colorPerVertex)
00222                 {
00223                         m_UseColorPerVertex= colorPerVertex;
00224                         m_GeometryIsValid= false;
00225                 }
00226         }
00227 
00229         void updateTransparentMaterialNumber();
00230 
00232         virtual void reverseNormals() {}
00233 
00235 
00236         virtual void setCurrentLod(const int) {}
00237 
00239         inline void setId(const GLC_uint id)
00240         {m_Id= id;}
00241 
00243         inline void setName(const QString name)
00244         {m_Name= name;}
00245 
00247         inline GLC_uint addVerticeGroup(const GLfloatVector& vector)
00248         {return m_WireData.addVerticeGroup(vector);}
00249 
00251         inline void setLineWidth(GLfloat lineWidth)
00252         {m_LineWidth= lineWidth;}
00253 
00255         void setWireColor(const QColor& color);
00256 
00258         virtual void copyVboToClientSide();
00259 
00261         virtual void releaseVboClientSide(bool update= false);
00262 
00264         virtual void setVboUsage(bool usage);
00265 
00267 
00268 
00270 
00271 public:
00273         virtual void glLoadTexture(void);
00274 
00276         virtual void render(const GLC_RenderProperties&);
00277 
00278 
00279 protected:
00281 
00282         virtual void glDraw(const GLC_RenderProperties&) = 0;
00283 
00285         virtual void glPropGeom(const GLC_RenderProperties&);
00286 
00288 
00289 
00291 
00292 protected:
00294         void removeMaterial(GLC_uint);
00295 
00297         inline void clearWireAndBoundingBox()
00298         {
00299                 delete m_pBoundingBox;
00300                 m_pBoundingBox= NULL;
00301                 m_WireData.clear();
00302                 m_GeometryIsValid= false;
00303         }
00304 
00306 
00308 
00310 
00311 private:
00313         void clearGeometry();
00314 
00316 
00318 // Protected members
00320 protected:
00321 
00323         bool m_GeometryIsValid;
00324 
00326         GLC_BoundingBox* m_pBoundingBox;
00327 
00329         MaterialHash m_MaterialHash;
00330 
00332         bool m_UseColorPerVertex;
00333 
00335         bool m_IsSelected;
00336 
00338         GLC_WireData m_WireData;
00339 
00341         QColor m_WireColor;
00342 
00344         GLfloat m_LineWidth;
00345 
00346 
00348 // Private members
00350 private:
00351 
00353         bool m_IsWire;
00354 
00356         int m_TransparentMaterialNumber;
00357 
00359 
00360         GLC_uint m_Id;
00361 
00363         QString m_Name;
00364 
00366         bool m_UseVbo;
00367 };
00368 
00369 #endif /*GLC_GEOMETRY_H_*/

SourceForge.net Logo

©2005-2011 Laurent Ribon