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 
00075         GLC_Geometry(const QString &, const bool);
00077 
00080         GLC_Geometry(const GLC_Geometry&);
00081 
00083         GLC_Geometry& operator=(const GLC_Geometry&);
00084 
00086         virtual ~GLC_Geometry();
00088 
00090 
00092 
00093 public:
00095         inline GLC_uint id() const
00096         {return m_Id;}
00097 
00099         inline QString name() const
00100         {return m_Name;}
00101 
00103         inline bool isValid(void) const
00104         {return m_GeometryIsValid;}
00105 
00107         inline bool hasMaterial() const
00108         {return !m_MaterialHash.isEmpty();}
00109 
00111         inline GLC_Material* firstMaterial(void) const
00112         {
00113                 if (!m_MaterialHash.isEmpty())
00114                 {
00115                         return m_MaterialHash.begin().value();
00116                 }
00117                 else return NULL;
00118         }
00119 
00121         inline int materialCount() const
00122         {return m_MaterialHash.size();}
00123 
00125         inline GLC_Material* material(const GLC_uint key) const
00126         {return m_MaterialHash[key];}
00127 
00129         inline QSet<GLC_Material*> materialSet() const
00130         {return m_MaterialHash.values().toSet();}
00131 
00133         inline QList<GLC_uint> materialIds() const
00134         {return m_MaterialHash.keys();}
00135 
00137         inline bool containsMaterial(const GLC_uint key) const
00138         {return m_MaterialHash.contains(key);}
00139 
00141         virtual const GLC_BoundingBox& boundingBox(void) = 0;
00142 
00144         inline bool boundingBoxIsValid() const
00145         {return NULL != m_pBoundingBox;}
00146 
00148         virtual GLC_Geometry* clone() const = 0;
00149 
00151         inline bool isTransparent() const
00152         {return (m_TransparentMaterialNumber >= m_MaterialHash.size()) && hasTransparentMaterials();}
00153 
00155         inline bool hasTransparentMaterials() const
00156         {return m_TransparentMaterialNumber > 0;}
00157 
00159         inline bool usedColorPerVertex() const
00160         {return m_UseColorPerVertex;}
00161 
00163         inline bool typeIsWire() const
00164         {return m_IsWire;}
00165 
00167         virtual unsigned int faceCount(int lod=0) const;
00168 
00170         virtual unsigned int VertexCount() const;
00171 
00173         GLfloat lineWidth() const
00174         {return m_LineWidth;}
00175 
00177         inline QColor wireColor() const
00178         {return m_WireColor;}
00179 
00181         inline bool wireDataIsEmpty() const
00182         {return m_WireData.isEmpty();}
00183 
00185         inline GLfloatVector wirePositionVector() const
00186         {return m_WireData.positionVector();}
00187 
00189         inline int wirePolylineCount() const
00190         {return m_WireData.verticeGroupCount();}
00191 
00193         inline GLuint wirePolylineOffset(int index) const
00194         {return m_WireData.verticeGroupOffset(index);}
00195 
00197         inline GLsizei wirePolylineSize(int index) const
00198         {return m_WireData.verticeGroupSize(index);}
00199 
00201 
00203 
00205 
00206 public:
00207 
00209         virtual void clear();
00210 
00212         virtual void replaceMasterMaterial(GLC_Material*);
00213 
00215         void addMaterial(GLC_Material *);
00216 
00218         inline void colorPerVertex(const bool colorPerVertex)
00219         {
00220                 if (m_UseColorPerVertex != colorPerVertex)
00221                 {
00222                         m_UseColorPerVertex= colorPerVertex;
00223                         m_GeometryIsValid= false;
00224                 }
00225         }
00226 
00228         void updateTransparentMaterialNumber();
00229 
00231         virtual void reverseNormals() {}
00232 
00234 
00235         virtual void setCurrentLod(const int) {}
00236 
00238         inline void setId(const GLC_uint id)
00239         {m_Id= id;}
00240 
00242         inline void setName(const QString name)
00243         {m_Name= name;}
00244 
00246         inline GLC_uint addVerticeGroup(const GLfloatVector& vector)
00247         {return m_WireData.addVerticeGroup(vector);}
00248 
00250         inline void setLineWidth(GLfloat lineWidth)
00251         {m_LineWidth= lineWidth;}
00252 
00254         void setWireColor(const QColor& color);
00255 
00257         virtual void copyVboToClientSide();
00258 
00260         virtual void releaseVboClientSide(bool update= false);
00261 
00263 
00264 
00266 
00267 public:
00269         virtual void glLoadTexture(void);
00270 
00272         virtual void render(const GLC_RenderProperties&);
00273 
00274 
00275 protected:
00277 
00278         virtual void glDraw(const GLC_RenderProperties&) = 0;
00279 
00281         virtual void glPropGeom(const GLC_RenderProperties&);
00282 
00284 
00285 
00287 
00288 protected:
00290         void removeMaterial(GLC_uint);
00291 
00293         inline void clearWireAndBoundingBox()
00294         {
00295                 delete m_pBoundingBox;
00296                 m_pBoundingBox= NULL;
00297                 m_WireData.clear();
00298                 m_GeometryIsValid= false;
00299         }
00300 
00302 
00304 
00306 
00307 private:
00309         void clearGeometry();
00310 
00312 
00314 // Protected members
00316 protected:
00317 
00319         bool m_GeometryIsValid;
00320 
00322         GLC_BoundingBox* m_pBoundingBox;
00323 
00325         MaterialHash m_MaterialHash;
00326 
00328         bool m_UseColorPerVertex;
00329 
00331         bool m_IsSelected;
00332 
00334         GLC_WireData m_WireData;
00335 
00337         QColor m_WireColor;
00338 
00340         GLfloat m_LineWidth;
00341 
00342 
00344 // Private members
00346 private:
00347 
00349         bool m_IsWire;
00350 
00352         int m_TransparentMaterialNumber;
00353 
00355 
00356         GLC_uint m_Id;
00357 
00359         QString m_Name;
00360 };
00361 
00362 #endif /*GLC_GEOMETRY_H_*/

SourceForge.net Logo

©2005-2011 Laurent Ribon