Gizmo3D

gzGeometryOptimizer.h

Go to the documentation of this file.
00001 //*****************************************************************************
00002 // File         : gzGeometryOptimizer.h
00003 // Module       : 
00004 // Description  : Class definition of the gzGeometryOptimizer class
00005 // Author       : Anders Modén      
00006 // Product      : Gizmo3D 2.1.1
00007 //      
00008 // Copyright © 2003- Saab Training Systems AB, Sweden   
00009 //          
00010 // NOTE:    Gizmo3D is a high performance 3D Scene Graph and effect visualisation 
00011 //          C++ toolkit for Linux, Mac OS X, Windows (Win32) and IRIX® for  
00012 //          usage in Game or VisSim development.
00013 //
00014 //
00015 // Revision History...                          
00016 //                                  
00017 // Who  Date    Description                     
00018 //                                  
00019 // AMO  981122  Created file    
00020 //
00021 //******************************************************************************
00022 #ifndef __GZ_GEOMETRY_OPTIMIZER_H__
00023 #define __GZ_GEOMETRY_OPTIMIZER_H__
00024 
00030 #include "gzGeometry.h"
00031 #include "gzMutex.h"
00032 
00033 GZ_DECLARE_MEMBASE_EXPORT(gzVertex,GZ_GRAPH_EXPORT);
00034 GZ_DECLARE_MEMBASE_EXPORT(gzTriangle,GZ_GRAPH_EXPORT);
00035 GZ_DECLARE_MEMBASE_EXPORT(gzPolygon,GZ_GRAPH_EXPORT);
00036 
00037 GZ_DECLARE_RECYCLE_DATA_EXPORT(gzGeometryOptimizer, GZ_GRAPH_EXPORT);
00038 
00039 //******************************************************************************
00040 // Class    : gzVertex
00041 //                                  
00042 // Purpose  : Utility class to hold vertex data
00043 //                                  
00044 // Notes    : - 
00045 //                                  
00046 // Revision History...                          
00047 //                                  
00048 // Who  Date    Description                     
00049 //                                  
00050 // AMO  990106  Created 
00051 //                                  
00052 //******************************************************************************
00053 class gzVertex : public gzReference , public GZ_MEMBASE(gzVertex)
00054 {
00055 public:
00056 
00057     GZ_MEMBASE_IMP(gzVertex);
00058 
00059     GZ_GRAPH_EXPORT gzVertex();
00060 
00061     GZ_GRAPH_EXPORT virtual ~gzVertex();
00062 
00063     GZ_GRAPH_EXPORT virtual gzBool  useDeepCopy() { return FALSE; }
00064 
00065     // -------------- data ---------------
00066 
00067     gzVec3          coordinate;
00068     gzVec2          projcoordinate;
00069     gzVec3          normal;
00070     gzVec4          color;
00071     gzArray<gzVec2> texcoord;
00072     gzWeight        weight;
00073     gzBool          edge;
00074 };
00075 
00076 //******************************************************************************
00077 // Class    : gzVertexList
00078 //                                  
00079 // Purpose  : Utility class to very fast recycle storage for vertex lists
00080 //                                  
00081 // Notes    : - 
00082 //                                  
00083 // Revision History...                          
00084 //                                  
00085 // Who  Date    Description                     
00086 //                                  
00087 // AMO  080124  Created 
00088 //                                  
00089 //******************************************************************************
00090 class gzVertexList : public gzRecycleDataExport(gzGeometryOptimizer)<gzRefList<gzVertex> >
00091 {
00092 public:
00093     virtual gzVoid onNewItem(gzRefList<gzVertex> & data) const;
00094     virtual gzVoid onInitItem(gzRefList<gzVertex> & data) const;
00095 };
00096 
00097 //******************************************************************************
00098 // Class    : gzTriStrip
00099 //                                  
00100 // Purpose  : Utility class to hold tristrip data
00101 //                                  
00102 // Notes    : - 
00103 //                                  
00104 // Revision History...                          
00105 //                                  
00106 // Who  Date    Description                     
00107 //                                  
00108 // AMO  990106  Created 
00109 //                                  
00110 //******************************************************************************
00111 class gzTriStrip : public gzReference
00112 {
00113 public:
00114     GZ_GRAPH_EXPORT gzTriStrip();
00115 
00116     GZ_GRAPH_EXPORT virtual ~gzTriStrip();
00117 
00118     GZ_GRAPH_EXPORT virtual gzBool  useDeepCopy() { return FALSE; }
00119 
00120     // ----------- data --------------
00121 
00122     gzVertexList    vertexList;
00123 };
00124 
00125 //******************************************************************************
00126 // Class    : gzPolygon
00127 //                                  
00128 // Purpose  : Utility class to hold polygon data
00129 //                                  
00130 // Notes    : - 
00131 //                                  
00132 // Revision History...                          
00133 //                                  
00134 // Who  Date    Description                     
00135 //                                  
00136 // AMO  990106  Created 
00137 //                                  
00138 //******************************************************************************
00139 class gzPolygon : public gzReference , public GZ_MEMBASE(gzPolygon)
00140 {
00141 public:
00142 
00143     GZ_MEMBASE_IMP(gzPolygon);
00144 
00145     GZ_GRAPH_EXPORT gzPolygon();
00146 
00147     GZ_GRAPH_EXPORT virtual ~gzPolygon();
00148 
00149     // ------------ utils --------------
00150 
00151     GZ_GRAPH_EXPORT gzVoid  calcNormal(gzBool project);
00152     GZ_GRAPH_EXPORT gzVoid  clean(const gzGeoOptimizeLevel &level);
00153     GZ_GRAPH_EXPORT gzBool  intersect(const gzVec3 &p1 , const gzVec3 &p3);
00154     GZ_GRAPH_EXPORT gzBool  contains(const gzVec3 &p1 , gzFloat maxdist);
00155     GZ_GRAPH_EXPORT gzBool  contains(gzPolygon *poly , gzFloat maxdist);
00156     GZ_GRAPH_EXPORT gzBool  addSubPoly(gzPolygon *poly , gzFloat maxdist);
00157     GZ_GRAPH_EXPORT gzVoid  subtractPolyList(gzRefList<gzPolygon> &subs);
00158     GZ_GRAPH_EXPORT gzDouble minVertexDistanceMag(gzPolygon *poly,gzULong *coordIndex=NULL,gzULong *closestCoordIndex=NULL);
00159     GZ_GRAPH_EXPORT gzBool  insertPoly(gzPolygon *poly,gzULong startIndex,gzULong polyStartIndex,gzBool subtract);
00160     GZ_GRAPH_EXPORT gzVoid  reverse();
00161 
00162     GZ_GRAPH_EXPORT virtual gzBool  useDeepCopy() { return FALSE; }
00163     
00164     // ----------- data ----------------
00165 
00166     gzVertexList            vertexList;
00167     gzVec3                  normalVec;
00168     gzMatrix4               projector;
00169     gzPolygonWinding        winding;
00170     gzRefList<gzPolygon>    subPolys;
00171 };
00172 
00173 //******************************************************************************
00174 // Class    : gzTriangle
00175 //                                  
00176 // Purpose  : Utility class to hold triangle data
00177 //                                  
00178 // Notes    : - 
00179 //                                  
00180 // Revision History...                          
00181 //                                  
00182 // Who  Date    Description                     
00183 //                                  
00184 // AMO  990106  Created 
00185 //                                  
00186 //******************************************************************************
00187 class gzTriangle : public gzReference , public GZ_MEMBASE(gzTriangle)
00188 {
00189 public:
00190 
00191     GZ_MEMBASE_IMP(gzTriangle);
00192 
00193     GZ_GRAPH_EXPORT gzTriangle();
00194     GZ_GRAPH_EXPORT virtual ~gzTriangle();
00195 
00196     GZ_GRAPH_EXPORT virtual gzBool  useDeepCopy() { return FALSE; }
00197 
00198 
00199     // ------------ data --------------
00200 
00201     gzVertex    a,b,c;
00202 
00203     gzTriangle *a_b , *b_c , *c_a;
00204 
00205     gzUByte     connections;
00206 
00207     gzUByte     isValid;
00208 };
00209 
00210 //******************************************************************************
00211 // Class    : gzPolygonOptimizer
00212 //                                  
00213 // Purpose  : Utility class to optimize polygon geometry 
00214 //                                  
00215 // Notes    : - 
00216 //                                  
00217 // Revision History...                          
00218 //                                  
00219 // Who  Date    Description                     
00220 //                                  
00221 // AMO  990106  Created 
00222 //                                  
00223 //******************************************************************************
00224 class gzPolygonOptimizer
00225 {
00226 public:
00227 
00228     GZ_GRAPH_EXPORT gzPolygonOptimizer();
00229     GZ_GRAPH_EXPORT virtual ~gzPolygonOptimizer();
00230 
00231     GZ_GRAPH_EXPORT gzBool optimize(gzGeometry *geometry , gzGeoOptimizeLevel level);
00232 
00233     GZ_GRAPH_EXPORT gzPolygonWinding polygonWinding(gzGeometry *geometry,const gzVec3 &up);
00234     GZ_GRAPH_EXPORT gzVoid stitchGeometry(gzGeometry *geometry,const gzVec3 &upVec=GZ_Z_VEC3,gzStitchSettings setting=GZ_STITCH_SETTING_DEFAULT,gzFloat maxdist=GZ_FLOAT_ONE);
00235 
00236 private:
00237 
00238     gzVoid  createPolygonList(gzBool convertToConvex);
00239     gzVoid  optimizeForTriFan(gzPolygon *poly);
00240     gzVoid  updateGeometry(gzBool force,gzBool isTrifan);
00241     gzVoid  calculatePolygonWinding(const gzVec3 &up);
00242     gzVoid  calculatePolygonContainment(const gzVec3 &up,gzFloat maxdist);
00243     gzVoid  splitIntersectedPolygons();
00244 
00245     gzVoid  createEvenOddPolygons();
00246 
00247     gzGeometry              *m_geometry;
00248 
00249     gzRefList<gzPolygon>    m_polygonList;
00250     gzRefList<gzPolygon>    m_polygonTopList;
00251 
00252     gzGeoOptimizeLevel      m_optimizeLevel;
00253 
00254     gzBool      m_useNormals;
00255     gzBool      m_useTexCoord;
00256     gzBool      m_useEdges;
00257     gzBool      m_useColors;
00258 };
00259 
00260 class gzTriOptimData
00261 {
00262 public:
00263 
00264     gzRefList<gzTriangle>           m_triList;
00265     gzRefList<gzTriStrip>           m_stripList;
00266     gzRefDict<gzVec3,gzTriangle>    m_hashTriList;
00267 };
00268 
00269 class gzRecycledTriOptimData : public gzRecycleDataExport(gzGeometryOptimizer)<gzTriOptimData>
00270 {
00271 public:
00272 
00273     virtual gzVoid onNewItem(gzTriOptimData & data) const 
00274     {
00275         data.m_hashTriList.setSize(100);
00276         data.m_hashTriList.useAutoResize(TRUE);
00277         data.m_hashTriList.reuseLinks(TRUE);
00278         data.m_stripList.reuseLinks(TRUE);
00279         data.m_triList.reuseLinks(TRUE);
00280     }                                   
00281         
00282     virtual gzVoid onInitItem(gzTriOptimData & data) const 
00283     {
00284         data.m_hashTriList.clear();
00285         data.m_stripList.clear();
00286         data.m_triList.clear();
00287     }
00288 
00289 };
00290 
00291 
00292 //******************************************************************************
00293 // Class    : gzTriOptimizer
00294 //                                  
00295 // Purpose  : Utility class to optimize triangle geometry 
00296 //                                  
00297 // Notes    : - 
00298 //                                  
00299 // Revision History...                          
00300 //                                  
00301 // Who  Date    Description                     
00302 //                                  
00303 // AMO  990106  Created 
00304 //                                  
00305 //******************************************************************************
00306 class gzTriOptimizer
00307 {
00308 public:
00309 
00310     GZ_GRAPH_EXPORT gzTriOptimizer():m_leastTriangle(NULL){};
00311 
00312     GZ_GRAPH_EXPORT virtual ~gzTriOptimizer(){};
00313 
00314     GZ_GRAPH_EXPORT gzBool optimize(gzGeometry *geometry , gzGeoOptimizeLevel level);
00315 
00316 private:
00317 
00318     gzVoid createTriangleList();
00319     gzVoid optimizeForTriList();
00320     gzBool updateGeometry();
00321 
00322     gzTriangle *findTriangle(gzVertex &a , gzVertex &b , gzTriangle *exclude);
00323 
00324     gzTriangle *findLeastTriangle();
00325 
00326     gzGeometry                  *m_geometry;
00327 
00328     gzRecycledTriOptimData      m_optimData;
00329 
00330     gzGeoOptimizeLevel          m_optimizeLevel;
00331 
00332     gzTriangle                  *m_leastTriangle;
00333 
00334     gzUByte                     m_leastConnections;
00335 
00336 
00337     gzBool      m_useNormals;
00338     gzBool      m_useTexCoord;
00339     gzBool      m_useEdges;
00340     gzBool      m_useColors;
00341     gzBool      m_useWeights;
00342 };
00343 
00344 //******************************************************************************
00345 // Class    : gzTrifanOptimizer
00346 //                                  
00347 // Purpose  : Utility class to optimize trifan geometry
00348 //                                  
00349 // Notes    : - 
00350 //                                  
00351 // Revision History...                          
00352 //                                  
00353 // Who  Date    Description                     
00354 //                                  
00355 // AMO  990106  Created 
00356 //                                  
00357 //******************************************************************************
00358 class gzTrifanOptimizer
00359 {
00360 public:
00361 
00362     GZ_GRAPH_EXPORT gzTrifanOptimizer(){};
00363 
00364     GZ_GRAPH_EXPORT virtual ~gzTrifanOptimizer(){};
00365 
00366     GZ_GRAPH_EXPORT gzBool optimize(gzGeometry *geometry , gzGeoOptimizeLevel level);
00367 
00368 private:
00369 
00370     gzGeometry  *m_geometry;
00371 
00372     gzBool      m_useNormals;
00373     gzBool      m_useTexCoord;
00374     gzBool      m_useEdges;
00375     gzBool      m_useColors;
00376 
00377     gzVoid createTriData();
00378 
00379 };
00380 
00381 class gzTristripOptimizer
00382 {
00383 public:
00384 
00385     GZ_GRAPH_EXPORT gzTristripOptimizer(){};
00386 
00387     GZ_GRAPH_EXPORT virtual ~gzTristripOptimizer(){};
00388 
00389     GZ_GRAPH_EXPORT gzBool optimize(gzGeometry *geometry , gzGeoOptimizeLevel level);
00390 
00391 private:
00392 
00393     gzGeometry  *m_geometry;
00394 
00395     gzBool      m_useNormals;
00396     gzBool      m_useTexCoord;
00397     gzBool      m_useEdges;
00398     gzBool      m_useColors;
00399 
00400     gzVoid createTriData();
00401 
00402 };
00403 
00404 //******************************************************************************
00405 // Class    : gzGeometryOptimizer
00406 //                                  
00407 // Purpose  : Utility class to convert geometry to optimized fans or polys
00408 //                                  
00409 // Notes    : - 
00410 //                                  
00411 // Revision History...                          
00412 //                                  
00413 // Who  Date    Description                     
00414 //                                  
00415 // AMO  990106  Created 
00416 //                                  
00417 //******************************************************************************
00418 class gzGeometryOptimizer
00419 {
00420 public:
00421     GZ_GRAPH_EXPORT static gzVoid optimize(gzGeometry *geometry , gzGeoOptimizeLevel level=GZ_GEO_OPTIMIZE_LEAVE_LINES);
00422     GZ_GRAPH_EXPORT static gzPolygonWinding polygonWinding(gzGeometry *geometry,const gzVec3 &upVec=GZ_Z_VEC3);
00423     GZ_GRAPH_EXPORT static gzVoid stitchGeometry(gzGeometry *geometry,const gzVec3 &upVec=GZ_Z_VEC3,gzStitchSettings setting=GZ_STITCH_SETTING_DEFAULT,gzFloat maxdist=GZ_FLOAT_ONE);
00424 };
00425 
00426 
00427 #endif
00428 

Documentation for Gizmo3D generated at Wed Feb 20 11:54:05 2008 by   Saab Training Systems AB, ¸ (c) 2003-and beyond