Changeset 1526


Ignore:
Timestamp:
09/28/06 17:49:37 (18 years ago)
Author:
gumbau
Message:

Updated modules to the new interface and the new simplification algorithm improvements.

Location:
GTP/trunk/Lib/Geom/shared
Files:
17 added
40 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Geom/shared/GTGeometry/GTGeometry.vcproj

    r1090 r1526  
    2020                                Name="VCCLCompilerTool" 
    2121                                Optimization="0" 
    22                                 AdditionalIncludeDirectories=".\src\libs;.\include;.\src\libs\vmi\include" 
     22                                AdditionalIncludeDirectories=".\src\libs;.\include;.\src\libs\vmi\include;.\src\libs\ntl" 
    2323                                PreprocessorDefinitions="WIN32;_DEBUG;_LIB;GLEW_STATIC" 
    2424                                MinimalRebuild="TRUE" 
     
    6363                                Name="VCCLCompilerTool" 
    6464                                Optimization="2" 
    65                                 AdditionalIncludeDirectories=".\src\libs;.\include;.\src\libs\vmi\include" 
     65                                AdditionalIncludeDirectories=".\src\libs;.\include;.\src\libs\vmi\include;.\src\libs\ntl" 
    6666                                PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GLEW_STATIC" 
    6767                                MinimalRebuild="TRUE" 
     
    324324                                <File 
    325325                                        RelativePath=".\src\libs\vmi\src\simplify.cpp"> 
     326                                </File> 
     327                        </Filter> 
     328                        <Filter 
     329                                Name="ntl" 
     330                                Filter=""> 
     331                                <File 
     332                                        RelativePath=".\src\libs\ntl\Cont.cpp"> 
    326333                                </File> 
    327334                        </Filter> 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoBase.h

    r1070 r1526  
    1515{ 
    1616        //      Basic types. 
    17         typedef float                                   Real; 
    18         typedef unsigned int            Index; 
    19         typedef int                                                     int32; 
    20         typedef unsigned int            uint32; 
     17        typedef float                   Real; 
     18        typedef unsigned int    Index; 
     19        typedef int                             int32; 
     20        typedef unsigned int    uint32; 
    2121        typedef unsigned short  uint16; 
    22         typedef std::string                     String; 
     22        typedef std::string             String; 
    2323 
    2424        //      Vertex Info. 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodManager.h

    r1310 r1526  
    1515#include "GeoVector3.h" 
    1616#include "GeoLodObject.h" 
    17 #include <map> 
    18 #include <vector> 
    1917 
    2018namespace Geometry 
    2119{ 
    22         class lodobj_dist_node_t 
    23         { 
    24         public: 
    25                 lodobj_dist_node_t(float dist, LodObject *o):dist2cam(dist),lodobj(o){ must_recalculate_distance=false; } 
    26                 float dist2cam; 
    27                 LodObject *lodobj; 
    28                 bool must_recalculate_distance; 
    29                 bool operator < (const lodobj_dist_node_t &o) const { return (dist2cam < o.dist2cam); } 
    30         }; 
     20        class NodeContainer;     
     21        class lodobj_node_t; 
    3122 
    3223        class LodManager 
    3324        {        
    3425        public: 
    35                 LodManager(float near, float far, const Geometry::Vector3 &campos); 
    36                 void AddLodObj(LodObject*, const Geometry::Vector3 &); 
    37                 void UpdateLOD(void); 
     26                LodManager(Real near, Real far, const Geometry::Vector3 &campos, int numslots=10); 
     27                ~LodManager(void); 
     28                void AddLodObj(const std::string &name, LodObject*, const Geometry::Vector3 &); 
     29                void UpdateLOD(uint32 currFPS, uint32 targetFPS=30); 
    3830                void UpdateCamera(const Geometry::Vector3 &); 
    3931                void UpdateLODObjectPos(LodObject*,const Geometry::Vector3 &); 
     32 
     33                bool always_calculate_lod; // if true, there is no instant LOD changing 
     34                bool force_highest_lod; // if set to true, all objects will be set to their highest level of detail 
     35 
    4036        private: 
    41                 std::vector<lodobj_dist_node_t> lodobj_dists; // key: dist2cam for efficient distance finding 
    42                 std::map<uint32,Geometry::Vector3> lodobj_pos; // map key: LodObject UniqueID for efficient ID-based finding 
    43                 unsigned int targetFPS; 
    44                 Vector3 camera_pos; 
    45                 bool camera_changed; 
     37                NodeContainer *lodobj_container; 
     38                uint32 lasttime; 
     39                bool camera_changed, node_added; 
    4640                float near_range, far_range; 
    47                 float CalculateDistToCamera(const Geometry::Vector3 &) const; 
    4841                float SelectRandomDistance(void) const; 
    49                 void RecalculateDist(lodobj_dist_node_t & node); 
     42                void ChangeLOD(lodobj_node_t*,Real); 
     43                void ReallyGoToLOD(lodobj_node_t*,Real); 
     44 
     45                lodobj_node_t * FindMostSimilarRealLOD(const std::string &, Real desired_lod); 
     46 
     47                void MakeDiscipleOf(lodobj_node_t *master, lodobj_node_t *disciple); 
     48                void MakeIndependent(lodobj_node_t*); 
     49                void RemoveDiscipleFrom(LodObject *master, LodObject *disciple); 
     50                void UpdateDisciples(lodobj_node_t *master); 
     51                void DeleteMeFromMyMastersDiscipleList(lodobj_node_t *); 
     52                void ChangeMaster(lodobj_node_t *orig, lodobj_node_t *newmaster); 
    5053        }; 
    51 }; 
     54} 
    5255 
    5356#endif 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodObject.h

    r1058 r1526  
    44namespace Geometry 
    55{ 
     6        class IndexData; 
     7 
    68        class LodObject 
    79        { 
     
    1315                uint32 GetUniqueID(void) const { return  uniqueID; } 
    1416                virtual void GoToLod(Real)=0; 
     17                virtual Real GetCurrentLodFactor(void) const =0; 
     18                virtual Geometry::IndexData * GetIndexDataInterface(void)=0; 
    1519 
    1620        private: 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodStripsConstructor.h

    r1078 r1526  
    124124                        //      Sort submesh bones. 
    125125                        void    sortBones(); 
    126                          
     126 
     127                        //      Add new vertices to mesh. 
     128                        void AddNewVertices(); 
     129         
    127130                public: 
    128131 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodStripsLibrary.h

    r1090 r1526  
    3434        typedef struct 
    3535        { 
    36                 unsigned        long    strip; 
    37                 char                                            position; 
    38                 char                                            vertexRepetition; 
    39                 char                                            edgeRepetition; 
     36                unsigned        long    strip; // change this to uint32 
     37                char            position; 
     38                char            vertexRepetition; 
     39                char            edgeRepetition; 
     40                char            obligatory; 
    4041        }       LODRegisterType; 
    4142 
    4243        typedef struct 
    4344        { 
    44                 float                   Vertex[3]; 
     45                float           Vertex[3]; 
    4546                SmallInt        Next; 
    4647        } VertexType; 
     
    130131 
    131132                        //      Copa STL vectors to C arrays. 
    132                         void    CopyVectors2Arrays(); 
     133                        void    CopyVectors2Arrays(void); 
    133134 
    134135                        //      Loads Mesh. 
    135136                        void    LoadStripMesh(const LodStripsLibraryData *, Mesh *geomesh); 
    136137 
    137                         Geometry::CREATEINDEXDATAFUNC create_index_data_func; 
     138//                      Geometry::CREATEINDEXDATAFUNC create_index_data_func; 
    138139 
    139140                        //      Strips vector. 
     
    146147                        //Number of strips in each submesh 
    147148                        int* mStripsSubmesh; 
     149                        bool delete_indexdata; 
     150                        int *submesh_x_strip; 
     151                        Real lodFactor; 
     152                        IndexData *dataRetrievalInterface; 
     153                        uint32 current_triangle_count; 
    148154 
    149155                public: 
    150156 
    151                         IndexData *dataRetrievalInterface; 
     157                        IndexData *GetIndexDataInterface(void){ return dataRetrievalInterface; } 
    152158                         
    153159                        /**     Constructor, receives as a parameter the name of the file 
    154160                         *      including the multiresolution object. 
    155161                        */ 
    156                         LodStripsLibrary(const LodStripsLibraryData *, Mesh *geomesh, CREATEINDEXDATAFUNC idfun=NULL); 
     162                        LodStripsLibrary(const LodStripsLibraryData *, Mesh *geomesh, IndexData * userindexdata = NULL); 
    157163 
    158164                        /// Destructor. 
     
    182188                        uint32 GetTotalStripCount(void) const { return mTotalStrips; } 
    183189                        uint32 GetSubMeshtripCount(int submeshid) const { return mStripsSubmesh[submeshid]; } 
     190                        uint32 GetCurrentTriangleCount(void) const { return current_triangle_count; } 
     191 
     192                        virtual Real GetCurrentLodFactor(void) const { return lodFactor; } 
    184193        }; 
    185194} 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodTreeLibrary.h

    r1090 r1526  
    2020        { 
    2121        public: 
    22 /*              LodTreeLibrary( const LodTreeLibrary &); 
    23                 LodTreeLibrary(LodTreeLibrary*);*/ 
    2422                LodTreeLibrary( const LodStripsLibraryData *, 
    2523                                                const TreeSimplificationSequence *, 
    26                                                 Geometry::Mesh *treeGeoMesh/*, 
    27                                                 uint32 leafSubMeshID 
    28                                                 /*std::string foliage_verts, 
    29                                                 std::string foliage_leafs, 
    30                                                 std::string foliage_simpl/*, 
    31                                                 uint32 leafSubMeshID, 
    32                                                 CREATEVERTEXDATAFUNC vdfun=NULL,  
    33                                                 CREATEINDEXDATAFUNC idfun=NULL, 
    34                                                 CREATEMULTIINDEXDATAFUNC midfun=NULL*/); // throws a FileNotFound exception 
     24                                                Geometry::Mesh *treeGeoMesh, 
     25                                                Geometry::IndexData *user_indexdata); 
    3526                ~LodTreeLibrary(void); 
    3627 
     
    4839                // changes the lod of the entire object (trunk and leaves) 
    4940                virtual void GoToLod(Real); 
     41                virtual Real GetCurrentLodFactor(void) const { return (currentFoliageLodFactor+trunk->GetCurrentLodFactor())*0.5f; } 
     42                virtual Geometry::IndexData * GetIndexDataInterface(void){ return dataRetrievalInterface; } 
    5043 
    5144                // new proposed functions 
     
    7164                Geometry::LodStripsLibrary *trunk; 
    7265                uint32 mLeavesSubMesh; 
     66                IndexData *dataRetrievalInterface; 
     67                bool delete_indexdata; 
     68                float currentFoliageLodFactor; 
    7369        }; 
    7470} 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoMeshSimpSequence.h

    r1007 r1526  
    2828        \n 
    2929        */ 
     30 
     31        //      Vertex info. 
     32        struct  GeoVertex 
     33        { 
     34                Index   id; 
     35                Index   bonefrom; 
     36                Vector3 position; 
     37                Vector2 texcoord; 
     38                Vector3 normal; 
     39        }; 
    3040 
    3141        class MeshSimplificationSequence: public Serializable 
     
    6070                                //      Indicates the the step is obligatory to execute 
    6171                                //      joined width the following step. 
    62                                 unsigned int obligatorio; 
     72                                unsigned int obligatory; 
    6373                        }; 
     74 
     75                        //      Vertices added in simplification. 
     76                        std::vector<GeoVertex>  mNewVertices; 
    6477 
    6578                        // Name of mesh. 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/VertexData.h

    r1325 r1526  
    44namespace Geometry 
    55{ 
    6         class VertexData 
    7         { 
    8         private: 
    9                 unsigned int numverts; 
    10         public: 
    11                 VertexData(unsigned int numv):numverts(numv){} 
    12                 virtual ~VertexData(void){} 
    13  
    14                 virtual void Begin(void)=0; 
    15                 virtual void SetVertexCoord(unsigned int i, float x, float y, float z)=0; 
    16                 virtual void SetVertexNormal(unsigned int i, float x, float y, float z)=0; 
    17                 virtual void SetVertexTexCoord(unsigned int i, float x, float y)=0; 
    18                 virtual void End(void)=0;        
    19  
    20                 virtual void GetVertexCoord(unsigned int i, float &x, float &y, float &z) const = 0; 
    21                 virtual void GetVertexNormal(unsigned int i, float &x, float &y, float &z) const = 0; 
    22                 virtual void GetVertexTexCoord(unsigned int i, float &x, float &y) const =0; 
    23  
    24                 unsigned int GetNumVertices(void) const { return numverts; } 
    25         }; 
    26  
    276        class IndexData 
    287        { 
    298        private: 
    30                 unsigned int numinds, numvalidinds; 
    31                 unsigned int current_submesh; 
    329        public: 
    33                 IndexData(unsigned int numi):numinds(numi),numvalidinds(numi){ current_submesh=0; } 
     10                IndexData(void){} 
    3411                virtual ~IndexData(void){} 
    3512 
    36                 virtual void Begin(void)=0; 
     13                virtual void Begin(unsigned int submesh, unsigned int numinds)=0; 
    3714                virtual void SetIndex(unsigned int i, unsigned int index)=0; 
    3815                virtual void End(void)=0; 
    3916 
    40                 virtual unsigned int GetIndex(unsigned int) const =0; 
    41                 unsigned int GetNumMaxIndices(void) const { return numinds; } 
    42                 unsigned int GetNumValidIndices(void) const { return numvalidinds; } 
    43                 void SetNumValidIndices(unsigned int valid){ numvalidinds=valid; } // this should not be called from client applications 
    44                 void SetCurrentSubmesh(unsigned int c){ current_submesh=c; }  // this should not be called from client applications 
    45                 unsigned int GetCurrentSubmesh(void) const { return current_submesh; } 
     17                virtual void BorrowIndexData(const IndexData *)=0; // tells the application to use this IndexData. If the app must use its own IndexData the param will be NULL 
    4618        }; 
    4719 
    48 /*      class MultiIndexData 
    49         { 
    50         private: 
    51                 unsigned int num_prims, num_total_inds, *num_max_inds, *num_valid_inds; 
    52         public: 
    53                 MultiIndexData(unsigned int numprims, unsigned int *maxinds){ 
    54                         num_prims=numprims; 
    55                         num_total_inds=0; 
    56                         num_max_inds=new unsigned int[numprims]; 
    57                         num_valid_inds=new unsigned int[numprims]; 
    58                         for (unsigned int i=0; i<numprims; i++) 
    59                         { 
    60                                 num_max_inds[i]=num_valid_inds[i]=maxinds[i]; 
    61                                 num_total_inds += maxinds[i]; 
    62                         } 
    63                 } 
    6420 
    65                 ~MultiIndexData(void){ 
    66                         delete[] num_max_inds; 
    67                         delete[] num_valid_inds; 
    68                 } 
    69  
    70                 virtual void Begin(void)=0; 
    71                 virtual void SetIndex(unsigned int iprim, unsigned int i, unsigned int index)=0; 
    72                 virtual void End(void)=0; 
    73  
    74                 virtual unsigned int GetIndex(unsigned int iprim, unsigned int index) const =0; 
    75                 unsigned int GetNumMaxIndices(unsigned int iprim) const { return num_max_inds[iprim]; } 
    76                 unsigned int GetNumValidIndices(unsigned int iprim) const { return num_valid_inds[iprim]; } 
    77                 void SetNumValidIndices(unsigned int iprim, unsigned int valid){ num_valid_inds[iprim]=valid; } 
    78                 unsigned int GetNumPrims(void) const { return num_prims; } 
    79         };*/ 
    80  
    81         typedef VertexData* CreateVertexDataFunc(unsigned int numv); 
    82         typedef CreateVertexDataFunc* CREATEVERTEXDATAFUNC; 
    83         typedef IndexData* CreateIndexDataFunc(unsigned int numi); 
     21/*      typedef IndexData* CreateIndexDataFunc(unsigned int numi); 
    8422        typedef CreateIndexDataFunc* CREATEINDEXDATAFUNC; 
    85 /*      typedef MultiIndexData* CreateMultiIndexDataFunc(unsigned int numprims, unsigned int *numi); 
    86         typedef CreateMultiIndexDataFunc* CREATEMULTIINDEXDATAFUNC;*/ 
    87  
    88         class DefaultVertexData : public VertexData 
    89         { 
    90         private: 
    91                 float *v, *n, *t; 
    92         public: 
    93                 DefaultVertexData(unsigned int numv); 
    94                 ~DefaultVertexData(void); 
    95  
    96                 virtual void Begin(void){} 
    97                 virtual void SetVertexCoord(unsigned int i, float x, float y, float z){  
    98                         v[i*3+0]=x; v[i*3+1]=y; v[i*3+2]=z; } 
    99                 virtual void SetVertexNormal(unsigned int i, float x, float y, float z){ 
    100                         n[i*3+0]=x; n[i*3+1]=y; n[i*3+2]=z; } 
    101                 virtual void SetVertexTexCoord(unsigned int i, float x, float y){  
    102                         t[i*2+0]=x; t[i*2+1]=y; } 
    103  
    104                 virtual void End(void){} 
    105  
    106                 virtual void GetVertexCoord(unsigned int i, float &x, float &y, float &z) const {  
    107                         x=v[i*3+0];  
    108                         y=v[i*3+1];  
    109                         z=v[i*3+2]; 
    110                 } 
    111                 virtual void GetVertexNormal(unsigned int i, float &x, float &y, float &z) const {x=n[i*3+0]; y=n[i*3+1]; z=n[i*3+2]; } 
    112                 virtual void GetVertexTexCoord(unsigned int i, float &x, float &y) const {x=t[i*2+0]; y=t[i*2+1]; } 
    113  
    114                 const float * GetVertexFloatBuffer(void) const { return v; } 
    115  
    116         }; 
    117         VertexData *DefaultVertexDataCreator(unsigned int numv); 
    118  
    11923 
    12024        class DefaultIndexData : public IndexData 
     
    12327                unsigned int *indices; 
    12428        public: 
    125                 DefaultIndexData(unsigned int numi); 
     29                DefaultIndexData(void){ indices=0; } 
    12630                ~DefaultIndexData(void); 
    12731 
    128                 virtual void Begin(void){} 
     32                virtual void Init(unsigned int); 
     33                virtual void Begin(unsigned int submesh, unsigned int numinds){} 
    12934                virtual void SetIndex(unsigned int i, unsigned int index){  
    13035                        indices[i] = index;  
     
    13540                        return indices[i]; 
    13641                } 
    137  
     42                virtual void BorrowIndexData(const IndexData *){} 
    13843        }; 
    139         IndexData *DefaultIndexDataCreator(unsigned int numi); 
    140  
    141 /*      class DefaultMultiIndexData : public MultiIndexData 
    142         { 
    143         private: 
    144                 unsigned int **indices; 
    145         public: 
    146                 DefaultMultiIndexData(unsigned int numprims, unsigned int *numi); 
    147                 ~DefaultMultiIndexData(void); 
    148  
    149                 virtual void Begin(void){} 
    150                 virtual void SetIndex(unsigned int iprim, unsigned int i, unsigned int index){  
    151                         indices[iprim][i] = index;  
    152                 } 
    153                 virtual void End(void){} 
    154  
    155                 virtual unsigned int GetIndex(unsigned int iprim, unsigned int i) const { 
    156                         return indices[iprim][i]; 
    157                 } 
    158  
    159         }; 
    160         MultiIndexData *DefaultMultiIndexDataCreator(unsigned int numprims, unsigned int *numi); 
    161 */ 
     44        IndexData *DefaultIndexDataCreator(unsigned int numi);*/ 
    16245} 
    16346 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/auxiliar.h

    r993 r1526  
    2424{ 
    2525        uint32  strip; 
    26         char            nP,nL1,nL2,obligatory; 
     26        char    nP,nL1,nL2,obligatory; 
    2727} LODData; 
    2828#pragma pack() 
     
    3737        float Normal[3]; 
    3838        float TexCoords[2]; 
    39         unsigned int obligatorio; 
     39        unsigned int obligatory; 
    4040        int numMesh; 
    4141        uint32 Next; 
     
    5555        uint32                          vLSNext; 
    5656        uint32                          vLS; 
    57         unsigned int    obligatorio; 
     57        unsigned int    obligatory; 
    5858        float                                   x; 
    5959        char                                    *cambio; 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/leaf.h

    r1019 r1526  
    55{ 
    66        public : 
    7         int  vertsLeaf[4];// Array of pointers to vertices 
     7        int  vertsLeaf[4]; // the four indices of the leaf 
    88                float  normal[3]; 
    99                float  parentLeafCount; 
     
    3030                Leaf (void); // default constructor 
    3131                Leaf (const Leaf&); // Copy constructor 
    32                 virtual ~Leaf (void); // Destructor 
     32//              virtual ~Leaf (void); // Destructor 
    3333 
    3434                float Distance (Leaf&); 
     
    3636}; 
    3737 
     38// this class is used by the lodtreelibrary to represent a leaf 
     39class RuntimeLeaf 
     40{ 
     41public: 
     42        RuntimeLeaf(void); 
     43        RuntimeLeaf (const RuntimeLeaf&); // Copy constructor 
     44 
     45        int vertsLeaf[4]; // the four indices of the leaf 
     46        int childLeft; 
     47        int childRight; 
     48        int parent; 
     49        int root; 
     50}; 
     51 
    3852#endif 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodManager.cpp

    r1309 r1526  
    1212#include "GeoLodManager.h" 
    1313#include "GeoLodObject.h" 
    14 #include <algorithm> 
    15 /* 
     14#include "VertexData.h" 
     15#include <ntls.h> 
     16#include <map> 
     17 
     18using namespace Geometry; 
     19 
     20//#define MINIMUM_VALID_LOD_SIMILARITY 0.1f 
     21 
     22 
    1623namespace Geometry 
    1724{ 
    18  
    19  
    20         class lodobj_idpos_node_t 
     25        class lodobj_node_t : public Moveable<lodobj_node_t> 
    2126        { 
    2227        public: 
    23                 lodobj_idpos_node_t(LodObject *o):lodobj(o),must_recalculate_distance(true),dist2cam(0.0f){} 
     28                lodobj_node_t(const std::string &nam, float dist, LodObject *o):dist2cam(dist),lodobj(o),name(nam){ must_recalculate_distance=false; to_update=0; master=NULL; lodfactor=o->GetCurrentLodFactor(); precalpos=-1; } 
     29                lodobj_node_t(const lodobj_node_t &n){ operator=(n); } 
     30                float dist2cam; 
    2431                LodObject *lodobj; 
    25                 float dist2cam; // used to index the lodobj in the other map 
    26                 bool operator < (const lodobj_idpos_node_t &o) const { return (lodobj->GetUniqueID()<o.lodobj->GetUniqueID()); } 
     32                bool must_recalculate_distance; 
     33                uint32 to_update; 
     34                bool operator < (const lodobj_node_t &o) const { return (dist2cam < o.dist2cam); } 
     35                void operator = (const lodobj_node_t &n){ dist2cam=n.dist2cam; lodobj=n.lodobj; must_recalculate_distance=n.must_recalculate_distance; master=n.master; lodfactor=n.lodfactor; precalpos=-1; name=n.name; } 
     36 
     37                lodobj_node_t * master; 
     38                VectorMap<uint32,lodobj_node_t*> disciples; 
     39                float lodfactor; // virtual lod factor (the lodfactor it seems, not its real internal lodfactor) 
     40                int precalpos; 
     41                std::string name; 
    2742        }; 
    28 }*/ 
    29  
    30 using namespace Geometry; 
    31  
    32 LodManager::LodManager(float near, float far, const Geometry::Vector3 &campos) 
    33 :targetFPS(30),camera_changed(true),camera_pos(campos), 
    34  near_range(near),far_range(far) 
    35 { 
    36         // make the lodobj_dists vector into a heap 
    37         make_heap(lodobj_dists.begin(),lodobj_dists.end()); 
    38 } 
    39  
    40 void Geometry::LodManager::AddLodObj(LodObject * o, const Geometry::Vector3 &p) 
    41 { 
    42         float dist = CalculateDistToCamera(p); 
    43         lodobj_dists.push_back(lodobj_dist_node_t(dist,o)); 
    44         push_heap(lodobj_dists.begin(),lodobj_dists.end()); 
    45 //      lodobj_dists[dist] = lodobj_dist_node_t(o); 
     43 
     44        class NodeContainer 
     45        { 
     46        public: 
     47                Vector<lodobj_node_t> lodobj_dists; 
     48                std::map<uint32,Geometry::Vector3> lodobj_pos; // map key: LodObject UniqueID for efficient ID-based finding 
     49                Vector3 camera_pos; 
     50 
     51                int num_lod_sim; 
     52 
     53                NodeContainer(const Geometry::Vector3 &campos) 
     54                        :camera_pos(campos){ 
     55                } 
     56 
     57                ~NodeContainer(void){ 
     58                        for (VectorMap<std::string,lodobj_node_t**>::Iterator it = precalculated_lods.Begin();  
     59                                                                                                                                  it != precalculated_lods.End(); it ++) 
     60                        { 
     61                                lodobj_node_t **nodes = *it; 
     62                                delete[] nodes; 
     63                        } 
     64                } 
     65 
     66                void RecalculateDist(lodobj_node_t & node){ 
     67                        std::map<uint32,Vector3>::iterator posit = lodobj_pos.find(node.lodobj->GetUniqueID()); 
     68                        assert(posit!=lodobj_pos.end()); 
     69                        const Vector3 & pos = posit->second; 
     70 
     71                        node.dist2cam = CalculateDistToCamera(pos); 
     72                } 
     73 
     74                float CalculateDistToCamera(const Geometry::Vector3 &p) const 
     75                { 
     76                        Geometry::Vector3 v = camera_pos - p; 
     77                        float distquad = v.length(); 
     78                        return distquad; 
     79                } 
     80 
     81                lodobj_node_t * & GetPrecalculatedLOD(const std::string &name, int ipos){ 
     82                        int foundpos = precalculated_lods.Find(name); 
     83                        if (foundpos==-1) 
     84                        { 
     85                                lodobj_node_t **new_precalculated_lods=new lodobj_node_t*[num_lod_sim+1]; // +1 is done to include the highest lod (1.0) 
     86                                for (int i=0; i<num_lod_sim+1; i++) 
     87                                        new_precalculated_lods[i]=NULL; 
     88                                precalculated_lods.Add(name) = new_precalculated_lods; 
     89                                return new_precalculated_lods[ipos]; 
     90                        } 
     91                        else 
     92                        { 
     93                                return precalculated_lods[foundpos][ipos]; 
     94                        } 
     95                } 
     96 
     97                uint32 lod2precalpos(Real lodfactor){  
     98                        return (uint32)(num_lod_sim*lodfactor);  
     99                } 
     100 
     101        private: 
     102                // the following is an array of precalculated lods 
     103                // for 10 precalculated lods each element is in order [0.1, 0.2, 0.3, 0.4, 0.5, ...] 
     104                // for 100 precalculated lods each element is in order [0.01, 0.02, 0.03, 0.04, 0.05, ...] 
     105                // the funcion lod2precalpos translates a LOD factor to a position in the array 
     106                VectorMap<std::string,lodobj_node_t**> precalculated_lods; 
     107 
     108        }; 
     109} 
     110 
     111LodManager::LodManager(Real near, Real far, const Geometry::Vector3 &campos, int numslots) 
     112:lasttime(0),camera_changed(true),node_added(false), 
     113 near_range(near),far_range(far), 
     114 always_calculate_lod(false),force_highest_lod(false) 
     115{ 
     116        lodobj_container=new NodeContainer(campos); 
     117        lodobj_container->num_lod_sim = numslots; 
     118} 
     119 
     120LodManager::~LodManager(void) 
     121{ 
     122        delete lodobj_container; 
     123//      delete[] precalculated_lods; 
     124} 
     125 
     126void Geometry::LodManager::AddLodObj(const std::string &name, LodObject * o, const Geometry::Vector3 &p) 
     127{ 
     128        float dist = lodobj_container->CalculateDistToCamera(p); 
     129        lodobj_node_t auxnode(name,dist,o); 
     130         
     131        lodobj_container->lodobj_dists.Add(auxnode); 
     132        Sort(lodobj_container->lodobj_dists); 
     133 
    46134        UpdateLODObjectPos(o,p); 
    47 } 
    48  
    49  
    50 void Geometry::LodManager::UpdateLOD(void) 
    51 { 
    52         if (!lodobj_dists.empty()) 
     135        node_added=true; 
     136} 
     137 
     138 
     139void Geometry::LodManager::UpdateLOD(uint32 currFPS, uint32 targetFPS) 
     140{ 
     141        if (!lodobj_container->lodobj_dists.IsEmpty()) 
    53142        { 
    54143                // update distances to the camera 
    55                 bool must_resort = false; 
    56                 for (std::vector<lodobj_dist_node_t>::iterator it=lodobj_dists.begin(); it!=lodobj_dists.end(); it++) 
    57                 {                        
    58                         lodobj_dist_node_t & node = *it; 
    59                         if (camera_changed || node.must_recalculate_distance) 
    60                         { 
    61                                 RecalculateDist(node); 
    62                                 must_resort=true; 
    63                         } 
    64                 } 
    65                 if (must_resort) 
    66                         sort_heap(lodobj_dists.begin(),lodobj_dists.end()); 
    67  
    68                 // select a tree to change its LOD 
    69         //      float random_dist = SelectRandomDistance(); 
    70         //      std::map<float,Geometry::lodobj_dist_node_t>::iterator nearest = lodobj_dists.upper_bound(random_dist); 
    71  
    72                 // the begining of the list is the greater element (greater dist)                
    73                 lodobj_dist_node_t & node = lodobj_dists.front(); 
     144                if (camera_changed || node_added) 
     145                { 
     146                        bool must_resort = false; 
     147                        for (Vector<lodobj_node_t>::Iterator it=lodobj_container->lodobj_dists.Begin();  
     148                                                                                                 it!=lodobj_container->lodobj_dists.End();  
     149                                                                                                 it++) 
     150                        {                        
     151                                lodobj_node_t & node = *it; 
     152                                if (node.must_recalculate_distance || camera_changed || node_added) 
     153                                { 
     154                                        lodobj_container->RecalculateDist(node); 
     155                                        must_resort=true; 
     156                                } 
     157                        } 
     158/*                      if (must_resort) 
     159                                Sort(lodobj_container->lodobj_dists);*/ 
     160                } 
     161 
     162                // the end of the list is the greater element (greater dist)     
     163/*              if (currFPS < targetFPS - 5) 
     164                { 
     165                        Vector<lodobj_node_t>::Iterator selnode; 
     166                        for (selnode=lodobj_container->lodobj_dists.End()-1; selnode!=lodobj_container->lodobj_dists.Begin()-1; selnode--) 
     167                        {                        
     168                        // NO HAY QUE USAR CURRENT LOD FACTOR SINO lodobj_container->lodobj_lodfactor 
     169                                if (selnode->lodobj->GetCurrentLodFactor()>0.00001f) 
     170                                { 
     171                                        if (selnode->to_update==0) 
     172                                                break; 
     173                                        else 
     174                                                selnode->to_update--; 
     175                                } 
     176                        } 
     177 
     178                        if (selnode!=lodobj_container->lodobj_dists.Begin()-1) 
     179                        { 
     180                                // EL DECREMENTO O EL NUMERO DE DECREMENTOS TIENE QUE VENIR EN FUNCION DE LA DIFERENCIA DE FPS 
     181                                // NO HAY QUE USAR CURRENT LOD FACTOR SINO lodobj_container->lodobj_lodfactor 
     182                                selnode->lodobj->GoToLod(selnode->lodobj->GetCurrentLodFactor()-0.02f);  
     183                                selnode->to_update=10; // ESTO DEBE ASIGNARSE BASADO EN LA DISTANCIA A LA CAMARA! 
     184                        } 
     185                } 
     186                if (currFPS > targetFPS + 5) 
     187                { 
     188                        Vector<lodobj_node_t>::Iterator selnode; 
     189                        for (selnode=lodobj_container->lodobj_dists.Begin(); selnode!=lodobj_container->lodobj_dists.End(); selnode++) 
     190                        {                        
     191                        // NO HAY QUE USAR CURRENT LOD FACTOR SINO lodobj_container->lodobj_lodfactor 
     192                                if (selnode->lodobj->GetCurrentLodFactor()<0.99999f) 
     193                                { 
     194                                        if (selnode->to_update==0) 
     195                                                break; 
     196                                        else 
     197                                                selnode->to_update--; 
     198                                } 
     199                        } 
     200 
     201                        if (selnode!=lodobj_container->lodobj_dists.End()) 
     202                        { 
     203                        // NO HAY QUE USAR CURRENT LOD FACTOR SINO lodobj_container->lodobj_lodfactor 
     204                                selnode->lodobj->GoToLod(selnode->lodobj->GetCurrentLodFactor()+0.02f); 
     205                                selnode->to_update=10; // ESTO DEBE ASIGNARSE BASADO EN LA DISTANCIA A LA CAMARA! 
     206                        } 
     207                }*/ 
     208 
     209                if (camera_changed) 
     210                { 
     211                        // por ahora solo sacar el lod basado en la camara 
     212                        for (Vector<lodobj_node_t>::Iterator it = lodobj_container->lodobj_dists.Begin();  
     213                                                                                                 it != lodobj_container->lodobj_dists.End();  it ++) 
     214                        { 
     215                                float lodfactor = - ((it->dist2cam - near_range) / (far_range - near_range)); 
     216                                if (lodfactor < 0.0f) 
     217                                        lodfactor = 0.0f; 
     218                                if (lodfactor > 1.0f) 
     219                                        lodfactor = 1.0f; 
     220 
     221                                if (force_highest_lod) 
     222                                        lodfactor = 1.0f; 
     223 
     224                                ChangeLOD(it,lodfactor); 
     225                        } 
     226                }                                                           
    74227        } 
    75228        camera_changed=false; 
    76 } 
    77  
    78 void Geometry::LodManager::RecalculateDist(lodobj_dist_node_t & node) 
    79 { 
    80         std::map<uint32,Vector3>::iterator posit = lodobj_pos.find(node.lodobj->GetUniqueID()); 
    81         assert(posit!=lodobj_pos.end()); 
    82         const Vector3 & pos = posit->second; 
    83  
    84         node.dist2cam = CalculateDistToCamera(pos); 
    85 } 
    86  
     229        node_added=false; 
     230} 
     231 
     232void Geometry::LodManager::ChangeLOD(lodobj_node_t *lodobjnode, Real lodfactor) 
     233{ 
     234        LodObject *lodobj = lodobjnode->lodobj; 
     235 
     236        if (always_calculate_lod) 
     237        { 
     238                lodobj->GoToLod(lodfactor); 
     239                return; 
     240        } 
     241         
     242        // if the lodfactor is exactly 1.0 its level of detail must be always regenerated (for closeups) 
     243        if (lodfactor<1.0f) 
     244        { 
     245                // if the desired lod is very similar to the previous one, 
     246                // then there is no need to change the level of detail at all 
     247//              float sim = fabsf(lodfactor - lodobjnode->lodfactor); 
     248//              if (sim <= MINIMUM_VALID_LOD_SIMILARITY) 
     249//                      return; // do not change anything if the lod is very similar! 
     250                int desiredpos = lodobj_container->lod2precalpos(lodfactor); 
     251                int mypos = lodobj_container->lod2precalpos(lodobjnode->lodfactor); 
     252                if (mypos==desiredpos) 
     253                        return; 
     254        } 
     255 
     256        lodobj_node_t *found_node = FindMostSimilarRealLOD(lodobjnode->name,lodfactor); 
     257 
     258        if (found_node && found_node->lodobj->GetUniqueID()!=lodobj->GetUniqueID()) 
     259        { 
     260                // DEBUG 
     261                assert(found_node->master==NULL); 
     262 
     263//              float sim = fabsf(lodfactor - found_node->lodfactor); 
     264//              if (sim <= MINIMUM_VALID_LOD_SIMILARITY) 
     265                int desiredpos = lodobj_container->lod2precalpos(lodfactor); 
     266                int foundpos = lodobj_container->lod2precalpos(found_node->lodfactor); 
     267                if (foundpos==desiredpos) 
     268                { 
     269                        lodobj->GetIndexDataInterface()->BorrowIndexData(found_node->lodobj->GetIndexDataInterface()); 
     270                        MakeDiscipleOf(found_node,lodobjnode); 
     271                } 
     272                else 
     273                        ReallyGoToLOD(lodobjnode,lodfactor); 
     274        } 
     275        else 
     276                ReallyGoToLOD(lodobjnode,lodfactor); 
     277 
     278        lodobjnode->lodfactor = lodfactor; 
     279} 
     280 
     281void Geometry::LodManager::DeleteMeFromMyMastersDiscipleList(lodobj_node_t *lodobjnode) 
     282{ 
     283        // if I have a master... 
     284        if (lodobjnode->master) 
     285                lodobjnode->master->disciples.RemoveKey(lodobjnode->lodobj->GetUniqueID());      
     286} 
     287 
     288 
     289void Geometry::LodManager::MakeIndependent(lodobj_node_t *lodobjnode) 
     290{ 
     291        DeleteMeFromMyMastersDiscipleList(lodobjnode); 
     292 
     293        // next, delete my master 
     294        lodobjnode->master=NULL; 
     295} 
     296 
     297void Geometry::LodManager::MakeDiscipleOf(lodobj_node_t *master_node, lodobj_node_t *disciple_node) 
     298{ 
     299        ChangeMaster(disciple_node, master_node); 
     300 
     301        // delete my disciples 
     302        disciple_node->disciples.Clear(); 
     303 
     304        // first remove me from my master's disciple list 
     305        DeleteMeFromMyMastersDiscipleList(disciple_node); 
     306 
     307        master_node->disciples.GetAdd(disciple_node->lodobj->GetUniqueID()) = disciple_node; 
     308 
     309        // set master 
     310        disciple_node->master = master_node; 
     311 
     312        // no one must take me as a master! 
     313        if (disciple_node->precalpos!=-1) 
     314        {                
     315//              lodobj_container->precalculated_lods[disciple_node->precalpos] = NULL; 
     316                lodobj_container->GetPrecalculatedLOD(master_node->name,disciple_node->precalpos) = NULL; 
     317                disciple_node->precalpos = -1; 
     318        } 
     319} 
     320 
     321void Geometry::LodManager::ChangeMaster(lodobj_node_t *lodobj, lodobj_node_t *newmaster) 
     322{ 
     323        // delete me from my disciples' master list 
     324        for (VectorMap<uint32,lodobj_node_t*>::Iterator it = lodobj->disciples.Begin(); it != lodobj->disciples.End(); it++) 
     325        { 
     326                lodobj_node_t * auxnode = *it; 
     327                assert(auxnode->master->lodobj->GetUniqueID() == lodobj->lodobj->GetUniqueID()); 
     328//              auxnode->master = NULL; 
     329                // chanbge the master to the new one 
     330                auxnode->master = newmaster; 
     331 
     332                // add the new disciple to the new master 
     333                if (newmaster) 
     334                        newmaster->disciples.GetAdd(auxnode->lodobj->GetUniqueID()) = auxnode; 
     335        }        
     336} 
     337 
     338 
     339void Geometry::LodManager::UpdateDisciples(lodobj_node_t *master_node) 
     340{ 
     341        for (VectorMap<uint32,lodobj_node_t*>::Iterator it= master_node->disciples.Begin(); it!= master_node->disciples.End(); it++) 
     342        { 
     343                lodobj_node_t *disciple_node = *it; 
     344                disciple_node->lodobj->GetIndexDataInterface()->BorrowIndexData(master_node->lodobj->GetIndexDataInterface()); 
     345                disciple_node->lodfactor = master_node->lodobj->GetCurrentLodFactor(); // we can use currentlodfactor here because the master is supposed to be at its REAL level of detail 
     346        } 
     347} 
     348 
     349void Geometry::LodManager::ReallyGoToLOD(lodobj_node_t *lodobjnode, Real lodfactor) 
     350{ 
     351        lodobjnode->lodobj->GoToLod(lodfactor); 
     352 
     353        MakeIndependent(lodobjnode); 
     354        UpdateDisciples(lodobjnode); 
     355 
     356        // store the precalculated lod in the table 
     357        int i = lodobj_container->lod2precalpos(lodfactor); 
     358 
     359        assert(i>=0 && i<=lodobj_container->num_lod_sim); // <= por lo del +1 
     360 
     361        if (lodobjnode->precalpos != -1) 
     362                //lodobj_container->precalculated_lods[lodobjnode->precalpos] = NULL; 
     363                lodobj_container->GetPrecalculatedLOD(lodobjnode->name,lodobjnode->precalpos) = NULL; 
     364 
     365//      lodobj_container->precalculated_lods[i] = lodobjnode; 
     366        lodobj_container->GetPrecalculatedLOD(lodobjnode->name,i) = lodobjnode; 
     367 
     368        lodobjnode->precalpos = i; 
     369} 
     370 
     371 
     372lodobj_node_t * Geometry::LodManager::FindMostSimilarRealLOD(const std::string &name, Real desired_lod) 
     373{ 
     374        uint32 i = lodobj_container->lod2precalpos(desired_lod); 
     375        assert(i>=0 && i<=lodobj_container->num_lod_sim); // <= por lo del +1 
     376//      lodobj_node_t *obj = lodobj_container->precalculated_lods[i]; 
     377        lodobj_node_t *obj = lodobj_container->GetPrecalculatedLOD(name,i); 
     378 
     379        return obj; 
     380} 
    87381 
    88382void Geometry::LodManager::UpdateCamera(const Geometry::Vector3 &p) 
    89383{ 
    90         camera_pos = p; 
     384        lodobj_container->camera_pos = p; 
    91385        camera_changed = true; 
    92386} 
     
    94388void Geometry::LodManager::UpdateLODObjectPos(LodObject *o, const Geometry::Vector3 &p) 
    95389{ 
    96         lodobj_pos[o->GetUniqueID()] = p; 
    97 } 
    98  
    99  
    100 float Geometry::LodManager::CalculateDistToCamera(const Geometry::Vector3 &p) const 
    101 { 
    102         return camera_pos.dotProduct(p); 
    103 } 
     390        lodobj_container->lodobj_pos[o->GetUniqueID()] = p; 
     391} 
     392 
    104393 
    105394float Geometry::LodManager::SelectRandomDistance(void) const 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsConstructor.cpp

    r1136 r1526  
    2727void LodStripsConstructor::CalcularCambiosLODsVNuevaED(TIPOFUNC upb) 
    2828{ 
    29 //      LODPosition                                             pos; 
    30 //      vector  <LODPosition>   listaPos; 
    31         long            int                                                     k; 
    32         long            int                                                     i; 
    33         unsigned long           int             t; 
    34         long            int                                                     r; 
    35         unsigned long           int             v; 
    36         long            int                                                     p0; 
    37         long            int                                                     lod     =       0; 
    38         long            int                                                     sigue; 
    39         long            int                                                     ac[3]   =       {0,0,0}; 
    40         long            int                                                     totalRegs       =       0; 
    41         long            int                                                     RegsCambios; 
    42         std::vector<std::vector<int> >                  TiraOriginal; 
    43         LODData                                                                 regLOD; 
    44         //LODChanges                                                    listaCambios; 
    45         std::vector<LODData>                                            listaCambios; 
    46         float                                                                           percent; 
    47         float                                                                           increment; 
    48         long            int                                                     update; 
     29        long            int                                     k; 
     30        long            int                                     i; 
     31        unsigned long           int                     t; 
     32        long            int                                     r; 
     33        unsigned long           int                     v; 
     34        long            int                                     p0; 
     35        long            int                                     lod     =       0; 
     36        long            int                                     sigue; 
     37        long            int                                     ac[3]   =       {0,0,0}; 
     38        long            int                                     totalRegs       =       0; 
     39        long            int                                     RegsCambios; 
     40        std::vector<std::vector<int> >  TiraOriginal; 
     41        LODData                                                 regLOD; 
     42        std::vector<LODData>                    listaCambios; 
     43        float                                                   percent; 
     44        float                                                   increment; 
     45        long            int                                     update; 
    4946 
    5047        //      Saves original copy. 
     
    6865         
    6966        this->LodsDisp  =       this->TOTALCAMBIOS      =       lod; 
    70         pCambios                                =       new uint32[this->TOTALCAMBIOS]; 
    71         pCambios[0]                     =       0; 
     67        pCambios                =       new uint32[this->TOTALCAMBIOS]; 
     68        pCambios[0]             =       0; 
    7269         
    7370        for     (lod = 0; ((this->cVerts[lod].Next) != -1); lod++) 
    7471        { 
    75 /*              if (update      != (int)(increment * lod)) 
    76                 { 
    77                         update  =       (int)(increment * lod); 
    78                         upb(percent); 
    79                 }*/ 
    80  
    8172                tipoVertice & cVertsLOD = this->cVerts[lod]; 
    8273                 
    8374                RegsCambios                             =       0; 
    84                 regLOD.obligatory       =       this->Ordenacion[lod].obligatorio; 
     75                regLOD.obligatory       =       this->Ordenacion[lod].obligatory; 
    8576                 
    8677                for(t = 0; t < this->cStrips.size(); t++) 
    8778                { 
    88  
    8979                        std::vector<int> & cStripsT = this->cStrips[t]; 
    9080 
     
    10191                                        //      Strips. 
    10292                                        if (regLOD.strip == this->MARCAVACIO) 
    103                                         { 
    104                                                 regLOD.strip    =       t; 
    105                                         } 
     93                                                regLOD.strip = t; 
    10694                                         
    10795                                        ++totalRegs; 
     
    118106                        //      Changes for simplification of level 1 to greater than 2. 
    119107                        totalRegs       =       0; 
    120                         i                                       =       0; 
    121                         r                                       =       0; 
    122                         sigue                   =       0; 
    123                         k                                       =       long(cStripsT.size()-3); 
     108                        i                       =       0; 
     109                        r                       =       0; 
     110                        sigue           =       0; 
     111                        k                       =       long(cStripsT.size()-3); 
    124112                         
    125113                        while (i < k) 
     
    305293        long int vSig; 
    306294        long int k; 
    307         VECTORVERTEX                            Vertices; 
     295        VECTORVERTEX                    Vertices; 
    308296        std::vector<tipoVertice>                NuevosVerts; 
    309         //vector        <VECTORINT>     NuevasTiras; 
    310         std::vector<std::vector<int> > NuevasTiras; 
    311 //      VECTORINT                                               tira; 
    312         std::vector<int> tira; 
    313         vector  <Index>                 mV1Aux; 
    314         tipoOrden                                               Orden; 
    315         tipoOrden                                               *Ord; 
    316         bool                                                            bEncontrado; 
    317         long    int                                             c1; 
    318         long    int                                             c2; 
     297        std::vector<std::vector<int> >  NuevasTiras; 
     298        std::vector<int>                tira; 
     299        tipoOrden                               Orden; 
     300        tipoOrden                               *Ord; 
     301        bool                                    bEncontrado; 
     302 
     303 
    319304        //      Progress bar 
    320305        float                   percent; 
     
    326311        size_t  mStepsSize = mGeoMeshSQ->mSteps.size(); 
    327312 
    328         c1                                      =       0; 
    329         c2                                      =       0; 
    330          
    331313        update                  =       -1; 
    332314        percent                 =       1.0; 
     
    341323                } 
    342324                 
    343                 const Geometry::MeshSimplificationSequence::Step & theStep = this->mGeoMeshSQ->mSteps[i]; 
    344  
    345                 mV1Aux.push_back(theStep.mV1); 
     325                const MeshSimplificationSequence::Step & theStep = this->mGeoMeshSQ->mSteps[i]; 
    346326 
    347327                Orden.vQslimNext        =       theStep.mV0; 
    348                 Orden.vQslim                    =       theStep.mV1; 
    349                 Orden.obligatorio       =       theStep.obligatorio; 
    350                 Orden.vLS                                       =       i; 
    351  
    352                 Orden.x                                         =       theStep.x; 
    353                 Orden.vLSNext                   =       -1; 
    354                 Orden.cambio                    =       "n"; 
     328                Orden.vQslim            =       theStep.mV1; 
     329                Orden.obligatory        =       theStep.obligatory; 
     330                Orden.vLS                       =       i; 
     331 
     332                Orden.x                         =       theStep.x; 
     333                Orden.vLSNext           =       -1; 
     334                Orden.cambio            =       "n"; 
    355335 
    356336                Ordenacion.push_back(Orden); 
    357337        } 
    358338         
    359         this->NumVertsRepetidos = c2; 
    360339 
    361340        update          =       -1; 
     
    363342        percent         =       1.0; 
    364343 
    365         //      Change all vertices that have x != 0. 
    366         for(i   =       0;      i < Ordenacion.size();  i++) 
    367         { 
    368                 if (update      != (int)(i * increment)) 
    369                 { 
    370                         update  = (int)(i * increment); 
    371                         upb(percent); 
    372                 } 
    373                  
    374                 Ord     =       &(Ordenacion[i]); 
    375  
    376                 if (Ord->x!=0) 
    377                 { 
    378                         //      Change the simplification order. 
    379                         v                                                               =       Ord->vQslim; 
    380                         Ord->vQslim                     =       Ord->vQslimNext; 
    381                         Ord->vQslimNext =       v; 
    382  
    383                         for (j = i+1; j < Ordenacion.size(); j++) 
    384                         { 
    385                                 tipoOrden & ordJ = Ordenacion[j]; 
    386                                 if (ordJ.vQslim == Ord->vQslim) 
    387                                 { 
    388                                         ordJ.vQslim     =       Ord->vQslimNext; 
    389                                         ordJ.cambio     =       "y"; 
    390                                 } 
    391                                 else if (ordJ.vQslimNext == Ord->vQslim) 
    392                                 { 
    393                                         ordJ.vQslimNext =       Ord->vQslimNext;         
    394                                         ordJ.cambio                     =       "y"; 
    395                                 } 
    396                         } 
    397                 } 
    398         } 
    399  
    400344        update          =       -1; 
    401345        increment       =       (float)(10.0) / (float)(Ordenacion.size()); 
     
    412356                } 
    413357 
    414                 c1++; 
    415                 NuevosVerts.push_back(this->cVerts[Ordenacion[i].vQslim]); 
    416  
    417                 cVerts[Ordenacion[i].vQslim].Next       =       -1; 
     358                int OrdvQslim = Ordenacion[i].vQslim; 
     359                int OrdvQslimNext = Ordenacion[i].vQslimNext; 
     360 
     361                NuevosVerts.push_back(this->cVerts[OrdvQslim]); 
     362 
     363                cVerts[OrdvQslim].Next  =       -1; 
    418364 
    419365        } 
     
    421367        //      Añadir aquellos vertices que no estaban en NuevosVerts  
    422368        //      y no se simplificaban. 
    423         int cont                                =       0; 
     369        int cont                =       0; 
    424370        int contestaban =       0; 
    425371 
     
    431377                        cont++; 
    432378                        NuevosVerts.push_back(this->cVerts[i]); 
    433                         Orden.vLS                                       =       int(Ordenacion.size()); 
    434                         Orden.obligatorio       = 0; 
    435                         Orden.vLSNext                   =       -1; 
    436                         Orden.vQslim                    =       i; 
     379                        Orden.vLS                       =       int(Ordenacion.size()); 
     380                        Orden.obligatory        = 0; 
     381                        Orden.vLSNext           =       -1; 
     382                        Orden.vQslim            =       i; 
    437383                        Orden.vQslimNext        =       -1; 
    438384 
     
    466412                for (t = 0; t < Ordenacion.size() && !vSig;t++) 
    467413                { 
    468                         if (Ordenacion[t].vQslim==v) 
    469                         { 
    470                                 vSig=Ordenacion[t].vLS; 
    471                         } 
    472                 } 
    473  
    474                 if (vSig!=0) 
     414                        if (Ordenacion[t].vQslim == v) 
     415                        { 
     416                                vSig    =       Ordenacion[t].vLS; 
     417                        } 
     418                } 
     419 
     420                if (vSig != 0) 
    475421                { 
    476422                        Ordenacion[i].vLSNext   =       vSig; 
     
    485431 
    486432                size_t  cStripsSizeT = this->cStrips[t].size(); 
     433 
    487434                for(i = 0; i < cStripsSizeT; i++) 
     435                { 
    488436                        tira.push_back(0); 
     437                } 
    489438 
    490439                NuevasTiras.push_back(tira); 
     
    499448        //      2 min. 
    500449        //Cambiar los vertices de las tiras 
    501         size_t  NuevosVertsSize = NuevosVerts.size();    
     450        size_t  NuevosVertsSize = NuevosVerts.size(); 
     451 
    502452        for(v = 0; v < NuevosVertsSize; v++) 
    503453        { 
     
    515465                        std::vector<int> & NuevasTirasT = NuevasTiras[t]; 
    516466                        size_t  cStripsSizeT = thisStrip.size(); 
     467 
    517468                        for(i = 0; i < cStripsSizeT; i++) 
    518469                        { 
     
    531482        //NuevosVerts y Ordenacion = tamaño. 
    532483        NuevosVertsSize = NuevosVerts.size(); 
     484 
    533485        for(i = 0; i < NuevosVertsSize; i++) 
    534486        { 
     
    563515         
    564516        this->mGeoMeshSQ        =       const_cast<MeshSimplificationSequence*>(ms); 
     517 
     518        //      Add new vertices to mesh. 
     519        AddNewVertices(); 
    565520 
    566521        //      Set the leaves submesh. 
     
    612567void LodStripsConstructor::Save(std::string filename) 
    613568{ 
    614         //size_t        i, j; 
    615         int                     k       =       0; 
    616         char            simp[256]; 
    617  
    618569        int vertexCount         =       (int)this->cVerts.size(); 
    619570        int changesCount        =       (int)this->cCambios.size(); 
    620         int dataCount                   =       (int)this->cDatos.size(); 
     571        int dataCount           =       (int)this->cDatos.size(); 
    621572        int cambiosCount        =       this->TOTALCAMBIOS; 
    622         int size                                        =       changesCount*sizeof(LODData) +  
     573        int size                        =       changesCount*sizeof(LODData) +  
    623574                                (vertexCount + dataCount + cambiosCount + 4)*sizeof(int) + 
    624575                                CHUNK_OVERHEAD_SIZE; 
     
    630581        fwrite(&size,sizeof(unsigned long),1,f); 
    631582 
     583        // VERTICES 
    632584        fwrite(&vertexCount, sizeof(int), 1, f); 
    633585        for(size_t      i = 0; i < this->cVerts.size(); i++) 
     
    636588                fwrite(&auxv, sizeof(int), 1, f); 
    637589        } 
    638  
    639         //      VERTICES. 
    640 /*      for(i = 0; i < this->cVerts.size(); i++) 
    641         { 
    642                 sprintf(simp,"v %d\n",cVerts[i].Next); 
    643                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    644         } 
    645 */ 
    646590         
    647591        //      CSTRIPS. 
     
    649593         
    650594        for(size_t      i = 0; i < this->cStrips.size(); i++) 
    651         { 
    652595                this->TOTALINDICES += int(this->cStrips[i].size()); 
    653         } 
    654596 
    655597        //      lines starting with a d. 
     
    662604        } 
    663605 
    664  
    665 /*      for(i = 0; i < this->cCambios.size(); i++) 
    666         { 
    667                 sprintf(simp,"c\n"); 
    668                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    669                  
    670                 sprintf(simp, 
    671                                                 "d %u %u %u %u %u\n", 
    672                                                 cCambios[i].strip, 
    673                                                 cCambios[i].nP, 
    674                                                 cCambios[i].nL1, 
    675                                                 cCambios[i].nL2, 
    676                                                 cCambios[i].obligatory); 
    677                  
    678                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    679         } 
    680 */      //      Lines starting with a b. 
    681606        //      Data. 
    682  
    683607        fwrite(&dataCount, sizeof(int), 1, f); 
    684  
    685608        for(size_t      i = 0; i < this->cDatos.size(); i++) 
    686609        { 
     
    688611                fwrite(&data, sizeof(int), 1, f); 
    689612        } 
    690  
    691         sprintf(simp,"a\n"); 
    692 /*      oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    693          
    694         for(i = 0; i < this->cDatos.size(); i++) 
    695         { 
    696                 sprintf(simp,"b %d\n",cDatos[i]); 
    697  
    698                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    699         } 
    700 */ 
    701613 
    702614        //      lines starting with a p. 
     
    711623 
    712624        fclose(f); 
    713  
    714 /* 
    715         //      VERTICES. 
    716         for(i = 0; i < this->cVerts.size(); i++) 
    717         { 
    718                 sprintf(simp,"v %d\n",cVerts[i].Next); 
    719                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    720         } 
    721  
    722         //      CSTRIPS. 
    723         this->TOTALINDICES      =       0; 
    724          
    725         for(i = 0; i < this->cStrips.size(); i++) 
    726         { 
    727                 this->TOTALINDICES += int(this->cStrips[i].size()); 
    728         } 
    729  
    730         //      lines starting with a d. 
    731         //      Changes 
    732         for(i = 0; i < this->cCambios.size(); i++) 
    733         { 
    734                 sprintf(simp,"c\n"); 
    735                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    736                  
    737                 sprintf(simp, 
    738                                                 "d %u %u %u %u %u\n", 
    739                                                 cCambios[i].strip, 
    740                                                 cCambios[i].nP, 
    741                                                 cCambios[i].nL1, 
    742                                                 cCambios[i].nL2, 
    743                                                 cCambios[i].obligatory); 
    744                  
    745                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    746         } 
    747         //      Lines starting with a b. 
    748         //      Data. 
    749         sprintf(simp,"a\n"); 
    750         oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    751          
    752         for(i = 0; i < this->cDatos.size(); i++) 
    753         { 
    754                 sprintf(simp,"b %d\n",cDatos[i]); 
    755  
    756                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    757         } 
    758  
    759         //      lines starting with a p. 
    760         //      Chages made in a LOD. 
    761         for(i = 0; i < this->TOTALCAMBIOS; i++) 
    762         { 
    763                 sprintf(simp,"p %d\n",this->pCambios[i]); 
    764  
    765                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    766         } 
    767  
    768         oSerializer.WriteData("\n",sizeof(char),1);     */ 
    769625} 
    770626 
     
    815671        for(i = 0; i < this->TOTALTIRAS; i++) 
    816672        { 
    817                 t       =       long(this->cStrips[i].size()); 
     673                t = long(this->cStrips[i].size()); 
    818674                 
    819675                if (t > max) 
    820                 { 
    821                         max     =       t; 
    822                 } 
     676                        max     = t; 
    823677        } 
    824678 
     
    970824                                } 
    971825 
    972                                 vAux.Next                       =       -10; 
    973                                 vAux.numMesh    =       0; 
    974                          
    975                                 vAux.obligatorio        =       0; 
     826                                vAux.Next               =       -10; 
     827                                vAux.numMesh    =       0;                       
     828                                vAux.obligatory =       0; 
    976829                                 
    977830                                this->cVerts.push_back(vAux); 
     
    11701023                { 
    11711024                        assign.boneIndex        =       0; 
    1172                         assign.weight                   =       1; 
    1173  
    1174                         for (   size_t  m = copy_vb->mVertexCount; 
     1025                        assign.weight           =       1; 
     1026 
     1027                        for (size_t     m = copy_vb->mVertexCount; 
    11751028                                                m < mesh_vb->mVertexCount; 
    11761029                                                m++) 
    11771030                        { 
    11781031                                assign.vertexIndex      =       (unsigned int)m; 
    1179                                  
    11801032                                mesh_bones->push_back(assign); 
    11811033                        } 
     
    11851037                        { 
    11861038                                n       =       (*mesh_bones)[m].vertexIndex; 
    1187  
    11881039                                o       =       0; 
    11891040                                 
    1190                                 while (!(       (mesh_vb->mPosition[n].x == copy_vb->mPosition[o].x) 
    1191                                                                         && 
    1192                                                                         (mesh_vb->mPosition[n].y == copy_vb->mPosition[o].y) 
    1193                                                                         && 
    1194                                                                         (mesh_vb->mPosition[n].z == copy_vb->mPosition[o].z))) 
     1041                                while (!(       (mesh_vb->mPosition[n].x == copy_vb->mPosition[o].x)    && 
     1042                                                        (mesh_vb->mPosition[n].y == copy_vb->mPosition[o].y)    && 
     1043                                                        (mesh_vb->mPosition[n].z == copy_vb->mPosition[o].z))) 
    11951044                                { 
    11961045                                        o++; 
     
    12001049                                 
    12011050                                while ((*copy_bones)[p].vertexIndex != o) 
    1202                                 { 
    12031051                                        p++; 
    1204                                 } 
    12051052 
    12061053                                //      Same bone for 'm' and 'p'. 
     
    12441091} 
    12451092 
    1246 void Geometry::LodStripsConstructor::UpdateMesh(void) 
     1093void LodStripsConstructor::UpdateMesh(void) 
    12471094{ 
    12481095        int num_no      =       0; 
     
    13031150 
    13041151                        indice++; 
    1305  
    13061152                } 
    13071153 
     
    14361282        } 
    14371283} 
     1284 
     1285//--------------------------------------------------------------------------- 
     1286//      Add new vertices to mesh. 
     1287//--------------------------------------------------------------------------- 
     1288void LodStripsConstructor::AddNewVertices() 
     1289{ 
     1290        int                             num_vertices; 
     1291        SubMesh                 *geosubmesh; 
     1292        VertexBuffer    *vertex_buffer; 
     1293        VertexBuffer    *new_vertex_buffer; 
     1294 
     1295        //      Gets old vertex buffer. 
     1296        vertex_buffer   =       mGeoMesh->mVertexBuffer; 
     1297         
     1298        num_vertices    =       vertex_buffer->mVertexCount 
     1299                                                                        + 
     1300                                                mGeoMeshSQ->mNewVertices.size(); 
     1301 
     1302        //      Initialize auxiliar vertex buffer. 
     1303        new_vertex_buffer       =       new     VertexBuffer(); 
     1304 
     1305        new_vertex_buffer->mVertexCount =       num_vertices; 
     1306         
     1307        new_vertex_buffer->mPosition            =       new     Vector3[num_vertices]; 
     1308        new_vertex_buffer->mNormal                      =       new     Vector3[num_vertices]; 
     1309        new_vertex_buffer->mTexCoords           =       new     Vector2[num_vertices]; 
     1310 
     1311        new_vertex_buffer->mVertexInfo  =       vertex_buffer->mVertexInfo; 
     1312 
     1313        //      Num old vertices. 
     1314        num_vertices    =       vertex_buffer->mVertexCount; 
     1315 
     1316        //      Copy the old vertex buffer. 
     1317        for     (unsigned       int     i       =       0;      i < num_vertices;       i++) 
     1318        { 
     1319                new_vertex_buffer->mPosition[i] =       vertex_buffer->mPosition[i]; 
     1320                new_vertex_buffer->mNormal[i]   =       vertex_buffer->mNormal[i]; 
     1321                new_vertex_buffer->mTexCoords[i]=       vertex_buffer->mTexCoords[i]; 
     1322        } 
     1323 
     1324 
     1325        //      Copy new vertices. 
     1326        for (unsigned   int     i       =       0;      i < mGeoMeshSQ->mNewVertices.size();    i++) 
     1327        { 
     1328                new_vertex_buffer->mPosition[num_vertices + i] = mGeoMeshSQ->mNewVertices[i].position; 
     1329                new_vertex_buffer->mTexCoords[num_vertices + i] = mGeoMeshSQ->mNewVertices[i].texcoord; 
     1330                new_vertex_buffer->mNormal[num_vertices + i] = mGeoMeshSQ->mNewVertices[i].normal; 
     1331 
     1332                // check if my twin-vertex-bone has a bone assignment 
     1333                // we check only the GeoMesh bones because the lodstrips only works for sharedvertex bones 
     1334                for (std::vector<VertexBoneAssignment>::iterator it = mGeoMesh->mBones.begin(); it != mGeoMesh->mBones.end(); it ++) 
     1335                { 
     1336                        if (it->vertexIndex == mGeoMeshSQ->mNewVertices[i].bonefrom) 
     1337                        { 
     1338                                VertexBoneAssignment vba; 
     1339                                vba.boneIndex = it->boneIndex; 
     1340                                vba.vertexIndex = mGeoMeshSQ->mNewVertices[i].id; 
     1341                                vba.weight = it->weight; 
     1342                                mGeoMesh->mBones.push_back(vba); 
     1343                        } 
     1344                } 
     1345        } 
     1346 
     1347        //      For each submesh. 
     1348        for (unsigned int submesh       =       0; submesh < mGeoMesh->mSubMeshCount; submesh++) 
     1349        { 
     1350                geosubmesh      =       &mGeoMesh->mSubMesh[submesh]; 
     1351 
     1352                geosubmesh->mVertexBuffer       =       new_vertex_buffer; 
     1353        } 
     1354 
     1355        delete  vertex_buffer; 
     1356         
     1357        mGeoMesh->mVertexBuffer =       new_vertex_buffer; 
     1358} 
     1359 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsLibrary.cpp

    r1325 r1526  
    1515 
    1616//----------------------------------------------------------------------------- 
    17 //      Constructors. 
    18 //----------------------------------------------------------------------------- 
    19 LodStripsLibrary::LodStripsLibrary(const LodStripsLibraryData *lodstripsdata, Mesh *geomesh, CREATEINDEXDATAFUNC idfun) 
    20 :create_index_data_func(idfun?idfun:DefaultIndexDataCreator) 
     17//      Constructor. 
     18//----------------------------------------------------------------------------- 
     19LodStripsLibrary::LodStripsLibrary(const LodStripsLibraryData *lodstripsdata, Mesh *geomesh, IndexData *userindexdata) 
     20//:dataRetrievalInterface(idfun?idfun:DefaultIndexDataCreator) 
    2121{ 
    2222//      const   char    *name_of_file; 
     
    3131        mGeoMesh = geomesh; 
    3232 
    33         dataRetrievalInterface=NULL; 
     33        delete_indexdata=false; 
     34        dataRetrievalInterface=userindexdata; 
     35         
    3436        indices_x_submesh = NULL; 
    3537        offsets_x_submesh = NULL; 
    3638        mStripsSubmesh = NULL; 
     39        submesh_x_strip = NULL; 
     40        lodFactor=1.0f; 
     41        current_triangle_count=0; 
    3742         
    3843        //      Loads the Level Of Detail file. 
     
    5156 
    5257//----------------------------------------------------------------------------- 
    53 //      Destroyer. 
     58//      Destructor 
    5459//----------------------------------------------------------------------------- 
    5560LodStripsLibrary::~LodStripsLibrary() 
    5661{ 
    5762        delete  [] mStrips; 
    58         if (dataRetrievalInterface) 
     63        if (delete_indexdata) 
    5964                delete dataRetrievalInterface; 
    6065        if (indices_x_submesh) 
     
    6469        if (mStripsSubmesh) 
    6570                delete[] mStripsSubmesh; 
     71        if (submesh_x_strip) 
     72                delete[] submesh_x_strip; 
    6673} 
    6774 
     
    7582void LodStripsLibrary::GoToLod(float lodfactor) 
    7683{ 
    77         register        int                                                     j; 
    78         register        int                                                     offset; 
    79         long                    int                                                     i; 
    80         long                    int                                                     k; 
    81         long                    int                                                     b_change_ok     =       1; 
    82         unsigned long   int                                     lod; 
    83         long                    int                                                     t; 
    84         long                    int                                                     r; 
    85         long                    int                                                     next; 
    86         long                    int                                                     el1; 
    87         long                    int                                                     el2; 
    88         long                    int                                                     total_changes; 
    89         long                    int                                                     totalR; 
    90         SmallIntVector                                          *strip; 
     84        register        int                             j; 
     85        register        int                             offset; 
     86        long                    int                     i; 
     87        long                    int                     k; 
     88        long                    int                     b_change_ok     =       1; 
     89        unsigned long   int                     lod; 
     90        long                    int                     t; 
     91        long                    int                     r; 
     92        long                    int                     next; 
     93        long                    int                     el1; 
     94        long                    int                     el2; 
     95        long                    int                     total_changes; 
     96        long                    int                     totalR; 
     97        SmallIntVector                          *strip; 
    9198        SmallIntVector::iterator        start; 
    92         uint32                                                                          return_value; 
     99 
     100        if (lodfactor<0.0f) lodfactor=0.0f; 
     101        if (lodfactor>1.0f) lodfactor=1.0f; 
    93102 
    94103        uint32 newLOD = (uint32)((1.0f - lodfactor) * mLods); 
     104 
     105        lodFactor=lodfactor; 
     106        LODRegisterType * lastLOD = mCurrentRegLOD; 
    95107     
    96         //      Initialize the return value to the current LOD. 
    97         return_value    =       mCurrentLod; 
    98  
    99108        if (newLOD != mCurrentLod) 
    100109        { 
     
    103112                        //      Forwards. 
    104113                        //      Increments LOD. 
    105                         for (lod = mCurrentLod; lod < newLOD; lod++) 
    106                         { 
    107                                 next                                            =       mVertex[lod]; 
     114                        for (lod = mCurrentLod; lod < newLOD || lastLOD->obligatory==1; lod++) 
     115                        { 
     116                                next                    =       mVertex[lod]; 
    108117                                total_changes   =       mPChanges[lod]; 
    109118 
     
    111120                                { 
    112121                                        //      Strip change. 
    113                                         t                       =       mCurrentRegLOD->strip;  
     122                                        t               =       mCurrentRegLOD->strip;  
    114123                                        strip   =       &(mStrips[t]); 
    115124                                        start   =       strip->begin();                          
     125                                        int stripsize_ini = strip->size(); 
    116126                                 
    117127                                        //      Position. 
     
    120130                                        for (j = totalR - 1; j >= 0; j--) 
    121131                                        { 
    122                                                 start[*mCurrentData]    =       next; 
    123                                                  
     132                                                start[*mCurrentData]    =       next;                                            
    124133                                                ++mCurrentData; 
    125134                                        } 
     
    160169                                        } 
    161170 
     171                                        lastLOD = mCurrentRegLOD; 
    162172                                        mCurrentRegLOD++; 
    163173                                         
    164174                                        mStripsChanges[t]       =       1; 
     175 
     176                                        int stripsize_end = strip->size(); 
     177                                        indices_x_submesh[submesh_x_strip[t]] -= (stripsize_ini - stripsize_end); 
    165178                                 
    166179                                } 
     
    177190                         
    178191                        //      Decrements LOD. 
    179                         for (lod = mCurrentLod; lod > newLOD; lod--) 
     192                        for (lod = mCurrentLod; lod > newLOD || lastLOD->obligatory==1; lod--) 
    180193                        { 
    181194                                total_changes   =       mPChanges[lod - 1]; 
     
    186199                                        strip   =       &(mStrips[t]); 
    187200                                        start   =       mStrips[t].begin(); 
     201                                        int stripsize_ini = strip->size(); 
    188202 
    189203                                        //      L2. 
     
    232246                                        } 
    233247                                         
     248                                        lastLOD = mCurrentRegLOD; 
    234249                                        mCurrentRegLOD--; 
    235250                                        mStripsChanges[t]       =       1; 
     251 
     252                                        int stripsize_end = strip->size(); 
     253                                        indices_x_submesh[submesh_x_strip[t]] += (stripsize_end - stripsize_ini); 
     254 
    236255                                }                        
    237256                                 
    238                                 //      Update LOD. 
     257                                //      Update LOD.                              
    239258                                mCurrentLod     =       lod - 1; 
    240259                        } 
     
    359378//      Copy a STL vector to a C array. 
    360379//----------------------------------------------------------------------------- 
    361 void LodStripsLibrary::CopyVectors2Arrays() 
     380void LodStripsLibrary::CopyVectors2Arrays(void) 
    362381{ 
    363382        SmallInt                                        max; 
     
    400419        //      Copy strips. 
    401420//      unsigned int numDegenerated = 2*mTotalStrips - 2; 
    402         dataRetrievalInterface=create_index_data_func(total_strip_size/*+numDegenerated*/); // temporal! 
    403         dataRetrievalInterface->Begin(); 
     421//      dataRetrievalInterface=create_index_data_func(total_strip_size,indexdata_user_data); // temporal! 
     422 
     423//      dataRetrievalInterface->Init(total_strip_size); 
     424/*      dataRetrievalInterface->numinds=total_strip_size; 
     425        dataRetrievalInterface->numvalidinds=total_strip_size;*/ 
     426//      dataRetrievalInterface->Begin(); 
    404427 
    405428        unsigned        int     ii = 0; 
     
    410433                { 
    411434                        mStrips[i].push_back(mFileStrips[i][j]); 
    412                         dataRetrievalInterface->SetIndex(ii,mFileStrips[i][j]); 
     435//                      dataRetrievalInterface->SetIndex(ii,mFileStrips[i][j]); 
    413436                } 
    414437                 
     
    416439                mStripsChanges[i]       =       0; 
    417440        } 
    418         dataRetrievalInterface->End(); 
     441//      dataRetrievalInterface->End(); 
    419442 
    420443        for (unsigned   int     i = 0; i < mData.size(); i++) 
     
    459482        indices_x_submesh = new int[geomesh->mSubMeshCount]; 
    460483        offsets_x_submesh = new int[geomesh->mSubMeshCount]; 
     484 
     485        int totaltiras = 0; 
     486        for (unsigned int submesh = 0; submesh < geomesh->mSubMeshCount; submesh++) 
     487                for (unsigned int strip = 0; strip < geomesh->mSubMesh[submesh].mStripCount; strip++) 
     488                        totaltiras++; 
     489 
     490        submesh_x_strip = new int[totaltiras]; 
     491 
     492        int istrip = 0; 
    461493        for (unsigned int submesh       =       0; submesh < geomesh->mSubMeshCount; submesh++) 
    462494        { 
    463495                geoSubMesh      =       &geomesh->mSubMesh[submesh]; 
     496                indices_x_submesh[submesh] = 0; 
    464497 
    465498                //      For each one of the strips. 
    466                 for (unsigned int strip = 0; strip < geoSubMesh->mStripCount; strip++) 
     499                for (unsigned int strip = 0; strip < geoSubMesh->mStripCount; strip++, istrip++) 
    467500                { 
    468501                        // Insert an empty strip. 
     502                        submesh_x_strip[istrip] = submesh; 
    469503                        t++; 
    470504                        strip_aux.clear(); 
     
    499533                        int i; 
    500534                        i       = 0; 
    501                         indices_x_submesh[submesh] = 0; 
     535                         
    502536                        if (submesh==0) 
    503537                                offsets_x_submesh[submesh] = 0; 
     
    592626         
    593627        for (unsigned int i = 0; i < mLods; i++) 
    594         { 
    595628                mPChanges[i] = p_changes[i]; 
    596         } 
    597629 
    598630        mTotalVertices          =       int(mFileVertices.size()); 
     
    603635        //Copy the data to the structure we will use 
    604636        CopyVectors2Arrays(); 
    605 //      } 
    606637} 
    607638 
     
    610641        unsigned        int     ii      =       0; 
    611642         
    612         dataRetrievalInterface->Begin(); 
    613  
    614643        int     counter = 0; 
    615644        int     target_submesh  = 0; 
    616645        size_t  strip_count     = 0; 
    617  
    618         dataRetrievalInterface->SetCurrentSubmesh(target_submesh); 
     646        unsigned int ii_submesh = 0; 
     647 
     648        dataRetrievalInterface->Begin(target_submesh, indices_x_submesh[target_submesh]); 
     649 
     650//      dataRetrievalInterface->SetCurrentSubmesh(target_submesh); 
    619651 
    620652        for (unsigned   int     i       =       0;      i < mTotalStrips;       i++,    strip_count++) 
     
    622654                if (strip_count >= mGeoMesh->mSubMesh[target_submesh].mStripCount) 
    623655                { 
    624                         indices_x_submesh[target_submesh] = counter; 
     656//                      indices_x_submesh[target_submesh] = counter; 
    625657 
    626658                        if (target_submesh==0) 
     
    634666 
    635667                        target_submesh++; 
    636                         dataRetrievalInterface->SetCurrentSubmesh(target_submesh); 
     668                        ii_submesh = 0; 
     669//                      dataRetrievalInterface->SetCurrentSubmesh(target_submesh); 
     670                        dataRetrievalInterface->End(); 
     671                        dataRetrievalInterface->Begin(target_submesh, indices_x_submesh[target_submesh]); 
    637672                } 
    638673                 
    639674                int lastindex = -1; 
    640                 for (SmallIntVector::iterator it=mStrips[i].begin(); it!=mStrips[i].end(); it++, ii++) 
     675                for (SmallIntVector::iterator it=mStrips[i].begin(); it!=mStrips[i].end(); it++, ii++, ii_submesh++) 
    641676                { 
    642677/*                      // repeat the first index of the strip: degenerate 
     
    649684                        }*/ 
    650685                        lastindex=*it; 
    651                         dataRetrievalInterface->SetIndex(ii,*it); 
     686                        dataRetrievalInterface->SetIndex(ii_submesh,*it); 
    652687                        counter++; 
    653688                } 
     
    658693                ii++;*/ 
    659694 
    660                 dataRetrievalInterface->SetNumValidIndices(ii); 
     695//              dataRetrievalInterface->SetNumValidIndices(ii); 
    661696        } 
    662697 
    663698        if (strip_count >= mGeoMesh->mSubMesh[target_submesh].mStripCount) 
    664699        { 
    665                 indices_x_submesh[target_submesh] = counter; 
     700//              indices_x_submesh[target_submesh] = counter; 
    666701                if (target_submesh==0) 
    667702                        offsets_x_submesh[target_submesh] = 0; 
     
    673708                strip_count = 0; 
    674709                target_submesh++; 
    675                 dataRetrievalInterface->SetCurrentSubmesh(target_submesh); 
     710//              dataRetrievalInterface->SetCurrentSubmesh(target_submesh); 
    676711        } 
    677712 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodTreeLibrary.cpp

    r1136 r1526  
    77Geometry::LodTreeLibrary::LodTreeLibrary(const LodStripsLibraryData *lodstripsdata, 
    88                                                                                 const TreeSimplificationSequence *simpseq, 
    9                                                                                  Geometry::Mesh *treeGeoMesh/*, 
    10                                                                                  uint32 leafSubMeshID, 
    11                                                            CREATEVERTEXDATAFUNC vdfun, 
    12                                                            CREATEINDEXDATAFUNC idfun, 
    13                                                            CREATEMULTIINDEXDATAFUNC midfun*/) 
     9                                                                                 Geometry::Mesh *treeGeoMesh, 
     10                                                                                 Geometry::IndexData *userindexdata) 
    1411{ 
    1512        // Cargar el tronco 
    16         trunk = new LodStripsLibrary(lodstripsdata,treeGeoMesh); 
     13        trunk = new LodStripsLibrary(lodstripsdata,treeGeoMesh,userindexdata); 
    1714 
    1815        // select the first triangle-list submesh as leaves submesh 
     
    2825        } 
    2926 
     27        delete_indexdata=false; 
     28        dataRetrievalInterface=userindexdata; 
     29 
    3030        // Cargar la copa del árbol 
    3131        Geometry::SubMesh * leafsSubMesh = &(treeGeoMesh->mSubMesh[mLeavesSubMesh]); 
    32         foliage = new Foliage(leafsSubMesh,simpseq); 
     32        foliage = new Foliage(mLeavesSubMesh,leafsSubMesh,simpseq); 
    3333        GoToFoliageLod(1.0f); 
    3434} 
     
    5656        if (trunk) delete trunk; 
    5757        if (foliage) delete foliage; 
    58 /*      if (trunk_all_indices) delete trunk_all_indices; 
    59         if (indices_offsets) delete[] indices_offsets; 
    60 //      if (current_foliage_indices) delete[] current_foliage_indices;*/ 
     58        if (delete_indexdata) delete dataRetrievalInterface; 
    6159} 
    6260/* 
     
    10199void LodTreeLibrary::GoToFoliageLod(float newlod) 
    102100{ 
    103         uint32 targetLeaves = (uint32) 
    104                                                                                                 ( 
    105                                                                                                         (1.0f - newlod) 
    106                                                                                                         * 
    107                                                                                                         foliage->minLeaves 
     101        uint32 targetLeaves = (uint32)  (       (1.0f - newlod) * foliage->minLeaves 
    108102                                                                                                        + 
    109                                                                                                         newlod 
    110                                                                                                         * 
    111                                                                                                         foliage->leafCount 
    112                                                                                                 ); 
     103                                                                                newlod * foliage->leafCount     ); 
    113104 
    114105        foliage->CalculateLOD(targetLeaves); 
    115106 
    116         foliage->indexdata->Begin(); 
    117         foliage->vertexdata->Begin(); 
    118107        int i = foliage->begin; 
    119108        int auxnumleaves = 0; 
     
    124113        } 
    125114 
    126         assert(auxnumleaves*6<=int(foliage->indexdata->GetNumMaxIndices())); 
    127         foliage->indexdata->SetNumValidIndices(auxnumleaves*6); 
     115//      foliage->indexdata->Begin(GetLeavesSubMesh(),auxnumleaves*6); 
     116        dataRetrievalInterface->Begin(GetLeavesSubMesh(),auxnumleaves*6); 
     117//      foliage->vertexdata->Begin(); 
     118 
    128119        i = foliage->begin; 
    129120        int index=0; 
     
    136127                v3 = foliage->Leaves[i].vertsLeaf[3]; 
    137128 
    138                 foliage->indexdata->SetIndex(index+0,v0); 
    139                 foliage->indexdata->SetIndex(index+1,v1); 
    140                 foliage->indexdata->SetIndex(index+2,v2); 
    141                 foliage->indexdata->SetIndex(index+3,v2); 
    142                 foliage->indexdata->SetIndex(index+4,v1); 
    143                 foliage->indexdata->SetIndex(index+5,v3); 
    144  
    145                 foliage->vertexdata->SetVertexTexCoord(v0,0,0); 
     129                dataRetrievalInterface->SetIndex(index+0,v0); 
     130                dataRetrievalInterface->SetIndex(index+1,v1); 
     131                dataRetrievalInterface->SetIndex(index+2,v2); 
     132                dataRetrievalInterface->SetIndex(index+3,v2); 
     133                dataRetrievalInterface->SetIndex(index+4,v1); 
     134                dataRetrievalInterface->SetIndex(index+5,v3); 
     135 
     136/*              foliage->vertexdata->SetVertexTexCoord(v0,0,0); 
    146137                foliage->vertexdata->SetVertexTexCoord(v1,0,1); 
    147138                foliage->vertexdata->SetVertexTexCoord(v2,1,0); 
    148                 foliage->vertexdata->SetVertexTexCoord(v3,1,1);  
     139                foliage->vertexdata->SetVertexTexCoord(v3,1,1); */ 
    149140 
    150141                index+=6; 
    151142                i=foliage->Acth[i].next; 
    152143        } 
    153         foliage->indexdata->End(); 
    154         foliage->vertexdata->End(); 
     144        dataRetrievalInterface->End(); 
     145//      foliage->vertexdata->End(); 
     146        currentFoliageLodFactor = newlod; 
    155147} 
    156148/* 
     
    170162const IndexData* LodTreeLibrary::CurrentLOD_Trunk_Indices(void) const  
    171163{  
    172         return trunk->dataRetrievalInterface; 
    173 } 
    174  
    175  
     164        return trunk->GetIndexDataInterface(); 
     165} 
     166 
     167/* 
    176168const VertexData* LodTreeLibrary::Get_Foliage_VertexData(void) const 
    177169{ 
     
    181173const IndexData* LodTreeLibrary::CurrentLOD_Foliage_Indices(void) const 
    182174{ 
    183         return foliage->indexdata; 
    184 } 
    185  
    186  
    187 /*void ThrowFileNotFoundError(const char *text) 
     175        return currentLOD_foliageIndexCount; 
     176} 
     177 
     178 
     179void ThrowFileNotFoundError(const char *text) 
    188180{ 
    189181        throw Geometry::FileNotFound(text); 
     
    193185{ 
    194186//      return current_foliage_indexcount; 
    195         return foliage->indexdata->GetNumValidIndices(); 
     187//      return foliage->indexdata->GetNumValidIndices(); 
     188        return foliage->active_leaf_count*6; 
    196189} 
    197190/* 
     
    213206uint32 LodTreeLibrary::Get_Foliage_MaxIndexCount(void) const 
    214207{ 
    215         return foliage->indexdata->GetNumMaxIndices(); 
     208        return foliage->leafTotal*6; 
    216209} 
    217210 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshLoader.cpp

    r1136 r1526  
    681681                        { 
    682682                                case 0xabcd: 
     683                                         
     684                                        //      Debug. 
    683685                                        cout << "LODSTRIPS_Chunk" << endl; 
     686                                         
    684687                                        lodstripsdata = new Geometry::LodStripsLibraryData; 
    685688 
    686                                         int                             aux,v,c; 
     689                                        int                                                     aux,v,c; 
    687690                                        LODRegisterType lod_register; 
    688                                         LODData                 dataaux; 
    689                                         int                             tam; 
     691                                        LODData                                 dataaux; 
     692                                        int                                                     tam; 
    690693 
    691694                                        fread(&tam, sizeof(int), 1, f); 
     695                                         
    692696                                        lodstripsdata->mFileVertices.clear(); 
    693                                         for (v=0; v<tam; v++) 
     697                                         
     698                                        for (v  =       0; v < tam; v++) 
    694699                                        { 
    695700                                                fread(&aux, sizeof(int), 1, f); 
     
    698703 
    699704                                        lodstripsdata->mFileChangesLOD.clear(); 
     705                                         
    700706                                        fread(&tam, sizeof(int), 1, f); 
    701                                         for (c=0; c<tam; c++) 
     707                                         
     708                                        for (c  =       0; c < tam; c++) 
    702709                                        { 
    703710                                                fread(&dataaux, sizeof(LODData), 1, f); 
     
    706713                                                lod_register.vertexRepetition= dataaux.nL1; 
    707714                                                lod_register.edgeRepetition= dataaux.nL2; 
    708                                                 //lod_register.obligatory=false; 
    709                                                 //lod_register.obligatory= dataaux.obligatory; 
     715                                                lod_register.obligatory=dataaux.obligatory; 
    710716 
    711717                                                lodstripsdata->mFileChangesLOD.push_back(lod_register); 
     
    713719                                         
    714720                                        lodstripsdata->mData.clear(); 
     721                                         
    715722                                        fread(&tam, sizeof(int), 1, f); 
    716                                         for (int b=0; b<tam; b++) 
     723                                         
     724                                        for (int        b       =       0; b < tam; b++) 
    717725                                        { 
    718726                                                fread(&aux, sizeof(int), 1, f); 
     
    721729 
    722730                                        lodstripsdata->p_changes.clear(); 
     731                                         
    723732                                        fread(&tam, sizeof(int), 1, f); 
    724                                         for (int p=0; p<tam; p++) 
     733                                         
     734                                        for (int        p       =       0; p < tam; p++) 
    725735                                        { 
    726736                                                fread(&aux, sizeof(int), 1, f); 
    727737                                                lodstripsdata->p_changes.push_back(aux); 
    728                                         }                                        
     738                                        } 
    729739 
    730740                                        break; 
     
    11461156                                cout    <<      version <<      endl; 
    11471157 
    1148                                 if (strcmp(version,"[MeshSerializer_v1.30]\n")) 
     1158                                /*if (strcmp(version,"[MeshSerializer_v1.30]\n")) 
    11491159                                { 
    11501160                                        //      Debug. 
     
    11561166                                        //      Error. 
    11571167                                        mError  =       true; 
    1158                                 } 
     1168                                }*/ 
    11591169 
    11601170                                while(!feof(pFile)) 
     
    14231433//      Read bones of the submesh. 
    14241434//--------------------------------------------------------------------------- 
    1425 void GeoMeshLoader::readSubMeshBoneAssignment(FILE* f, 
    1426                                                                                                                                                                                         SubMesh* geoSubMesh, 
    1427                                                                                                                                                                                         int option) 
     1435void GeoMeshLoader::readSubMeshBoneAssignment(FILE              *f, 
     1436                                                                                                                                                                                        SubMesh *geoSubMesh, 
     1437                                                                                                                                                                                        int                     option) 
    14281438{ 
    14291439        if (option == GEOMESH_BUILD) 
     
    14451455//      Read bones of the main mesh. 
    14461456//--------------------------------------------------------------------------- 
    1447 void GeoMeshLoader::readMeshBoneAssignment(FILE* f, Mesh* geoMesh,int option) 
     1457void GeoMeshLoader::readMeshBoneAssignment(FILE *f, Mesh        *geoMesh,       int option) 
    14481458{ 
    14491459        if (option == GEOMESH_BUILD) 
     
    14651475//      Read skeleton link. 
    14661476//--------------------------------------------------------------------------- 
    1467 void GeoMeshLoader::readSkeletonLink(FILE* f, Mesh* geoMesh,int option) 
     1477void GeoMeshLoader::readSkeletonLink(FILE       *f, Mesh        *geoMesh,       int option) 
    14681478{ 
    14691479        if (option == GEOMESH_BUILD) 
     
    18291839                const std::vector<face_t> & vecfaces = faces[i]; 
    18301840                std::vector<Geometry::Index> aux_indices; 
     1841                 
    18311842                submesh->mSharedVertexBuffer = true; 
    18321843                submesh->mIndexCount = vecfaces.size()*3; 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSaver.cpp

    r1136 r1526  
    878878        } 
    879879} 
     880 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimpSequence.cpp

    r1009 r1526  
    44using namespace std; 
    55 
    6 MeshSimplificationSequence::MeshSimplificationSequence()  
     6//--------------------------------------------------------------------------- 
     7//      Constructor. 
     8//--------------------------------------------------------------------------- 
     9MeshSimplificationSequence::MeshSimplificationSequence() 
    710{ 
    8         meshName=""; 
     11        meshName        =       ""; 
    912} 
    1013 
    11 MeshSimplificationSequence::~MeshSimplificationSequence()  
     14MeshSimplificationSequence::~MeshSimplificationSequence() 
    1215{ 
    1316} 
    1417 
    15 void MeshSimplificationSequence::Load(Serializer &s)  
     18//--------------------------------------------------------------------------- 
     19//      Loads mesh simplification sequence. 
     20//--------------------------------------------------------------------------- 
     21void MeshSimplificationSequence::Load(Serializer &s) 
    1622{ 
    17         //Loads a simplification sequence from a file 
    18         char buffer[256]; 
    19         unsigned int modVertex; 
    20         char name[256]; 
     23        //      Loads a simplification sequence from a file. 
     24        char                                    buffer[256]; 
     25        unsigned int    modVertex; 
     26        char                                    name[256]; 
    2127 
     28        //      Read mesh name. 
    2229        if (s.ReadData(buffer,256) != NULL) 
    2330        { 
    2431                sscanf(buffer,"%s",&name); 
    25                 meshName=new char[strlen(name)]; 
     32 
     33                meshName        =       new char[strlen(name)]; 
     34 
    2635                strcpy(meshName,name); 
    2736        } 
    2837 
     38        //      Read steps data. 
    2939        while (s.ReadData(buffer,256) != NULL) 
    3040        { 
    3141                Geometry::MeshSimplificationSequence::Step simplifstep; 
    32                 //new step 
    33                 sscanf(buffer,"%u %u %u %u %u %f %f %f &",&simplifstep.mV1,&simplifstep.mV0, &simplifstep.mT0,&simplifstep.mT1, &simplifstep.obligatorio,&simplifstep.x, &simplifstep.y, &simplifstep.z); 
    34                 //sscanf(buffer,"%u %u %u %u %u &",&simplifstep.mV1,&simplifstep.mV0, &simplifstep.mT0,&simplifstep.mT1, &simplifstep.obligatorio); 
    35                 //sscanf(buffer + 3,"%u %u %f %f %f %u %u &",&simplifstep.mV0,&simplifstep.mV1,&simplifstep.x, &simplifstep.y, &simplifstep.z, &simplifstep.mT0,&simplifstep.mT1); 
    36                 //sscanf(buffer,"%u %u %u %u %u &",&simplifstep.mV0,&simplifstep.mV1,&simplifstep.mT0,&simplifstep.mT1, &simplifstep.obligatorio); 
    3742 
    38                 buffer[strlen(buffer)-1]='\0'; 
     43                //      New step. 
     44                sscanf( buffer, 
     45                                                "%u %u %u %u %u %f %f %f &", 
     46                                                &simplifstep.mV1, 
     47                                                &simplifstep.mV0, 
     48                                                &simplifstep.mT0, 
     49                                                &simplifstep.mT1, 
     50                                                &simplifstep.obligatory, 
     51                                                &simplifstep.x, 
     52                                                &simplifstep.y, 
     53                                                &simplifstep.z); 
    3954 
    40                 //if(!simplifstep.obligatorio) 
    41                 //{ 
     55                buffer[strlen(buffer)-1]        =       '\0'; 
     56 
    4257                char *ptr1; 
    43                 ptr1=strtok(buffer,"&"); 
    44                 ptr1=strtok(NULL,"&"); 
    4558 
    46                 if (ptr1!=NULL) 
     59                ptr1    =       strtok(buffer,"&"); 
     60                ptr1    =       strtok(NULL,"&"); 
     61 
     62                if (ptr1 != NULL) 
    4763                { 
    4864                        char *ptr; 
    49                         ptr=strtok(ptr1," "); 
     65 
     66                        ptr     =       strtok(ptr1," "); 
    5067                         
    51                         while(ptr != NULL ) 
     68                        while (ptr != NULL ) 
    5269                        { 
    53                                 modVertex = (unsigned int)atoi(ptr); 
     70                                modVertex       =       (unsigned int)atoi(ptr); 
     71 
    5472                                simplifstep.mModfaces.push_back(modVertex); 
    55                                 ptr=strtok(NULL," "); 
     73 
     74                                ptr     =       strtok(NULL," "); 
    5675                        } 
    5776                } 
     77 
    5878                mSteps.push_back(simplifstep); 
    59                 //} 
    60  
    6179        } 
    62  
    6380} 
    6481 
     82//--------------------------------------------------------------------------- 
     83//      Saves simplification sequence. 
     84//--------------------------------------------------------------------------- 
    6585void MeshSimplificationSequence::Save(Serializer &s) 
    6686{ 
    67         //Stores the simplification sequence in a file 
     87        //      Stores the simplification sequence in a file. 
    6888        char simp[256]; 
    6989 
    70         //Name of the mesh 
     90        //      Name of the mesh. 
    7191        sprintf(simp,"%s\n",meshName); 
    7292        s.WriteData(simp,sizeof(char),strlen(simp)); 
    7393 
    74         for(unsigned int i=0; i<mSteps.size(); i++) 
     94        //      For each step. 
     95        for (unsigned int i     =       0; i < mSteps.size(); i++) 
    7596        { 
    7697                Geometry::MeshSimplificationSequence::Step paso = mSteps.operator [](i); 
    77                 //sprintf(simp,"%u %u %u %u %u &", paso.mV0, paso.mV1, paso.mT0, paso.mT1,paso.obligatorio); 
    78                 sprintf(simp,"%u %u %u %u %u %f &", paso.mV0, paso.mV1, paso.mT0, paso.mT1,paso.obligatorio,paso.x); 
     98                 
     99                sprintf(simp, 
     100                                                "%u %u %u %u %u %f &", 
     101                                                paso.mV0, 
     102                                                paso.mV1, 
     103                                                paso.mT0, 
     104                                                paso.mT1, 
     105                                                paso.obligatory, 
     106                                                paso.x); 
     107 
     108                //      Write step. 
    79109                s.WriteData(simp,sizeof(char),strlen(simp)); 
    80                 for (unsigned int j=0; j<paso.mModfaces.size(); j++) 
     110                 
     111                //      Triangles modified. 
     112                for (unsigned int j     =       0; j < paso.mModfaces.size(); j++) 
    81113                { 
    82114                        sprintf(simp," %u",paso.mModfaces.operator [](j)); 
    83115                        s.WriteData(simp,sizeof(char),strlen(simp)); 
    84116                } 
     117                 
     118                //      New line. 
    85119                s.WriteData("\n",sizeof(char),1); 
    86120        } 
    87121} 
    88122 
    89 void MeshSimplificationSequence::putMeshName(char *name)  
     123//--------------------------------------------------------------------------- 
     124//      Puts mesh name. 
     125//--------------------------------------------------------------------------- 
     126void MeshSimplificationSequence::putMeshName(char *name) 
    90127{ 
    91         meshName=name; 
     128        meshName        =       name; 
    92129} 
    93130 
    94 char *MeshSimplificationSequence::getMeshName(void)  
     131//--------------------------------------------------------------------------- 
     132//      Gets mesh name. 
     133//--------------------------------------------------------------------------- 
     134char *MeshSimplificationSequence::getMeshName(void) 
    95135{ 
    96136        return meshName; 
    97137} 
     138 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimplifier.cpp

    r1070 r1526  
    413413                current_step.z  =       VMI::mVMISteps[i].z; 
    414414 
    415                 current_step.obligatorio        =       VMI::mVMISteps[i].obligatory; 
     415                current_step.obligatory =       VMI::mVMISteps[i].obligatory; 
    416416 
    417417                //      For each face modificated. 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/AdjModel.cxx

    r1025 r1526  
    1717int Model::in_Vertex(const Vec3& p) 
    1818{ 
    19     Vertex *v = newVertex(p[X], p[Y], p[Z]); 
    20     bounds.addPoint(p); 
    21     return vertCount() - 1; 
     19        Vertex *v = newVertex(p[X], p[Y], p[Z]); 
     20        bounds.addPoint(p); 
     21        return vertCount() - 1; 
    2222} 
    2323 
     
    3636int Model::in_Face(int a, int b, int c, int n1, int n2, int n3, int t1, int t2, int t3) 
    3737{ 
    38     Vertex *v1 = vertices(a-1); 
    39     Vertex *v2 = vertices(b-1); 
    40     Vertex *v3 = vertices(c-1); 
    41          
    42     Face *t = newFace(v1, v2, v3); 
     38        Vertex *v1 = vertices(a-1); 
     39        Vertex *v2 = vertices(b-1); 
     40        Vertex *v3 = vertices(c-1); 
     41 
     42        Face *t = newFace(v1, v2, v3); 
    4343 
    4444        t->normals[0] = n1; 
     
    5555int Model::miin_Face(int a, int b, int c) 
    5656{ 
    57     Vertex *v1 = vertices(a-1); 
    58     Vertex *v2 = vertices(b-1); 
    59     Vertex *v3 = vertices(c-1); 
    60          
    61     Face *t = newFace(v1, v2, v3); 
     57        Vertex *v1 = vertices(a); 
     58        Vertex *v2 = vertices(b); 
     59        Vertex *v3 = vertices(c); 
     60 
     61        Face *t = newFace(v1, v2, v3); 
    6262 
    6363        t->normals[0] = a; 
     
    7575int Model::in_FColor(const Vec3& c) 
    7676{ 
    77     Face *f = faces(faces.length()-1); 
    78  
    79     if( !f->props ) 
    80         f->props = new FProp; 
    81  
    82     f->props->color = c; 
    83     return 0; 
     77        Face *f = faces(faces.length()-1); 
     78 
     79        if( !f->props ) 
     80        { 
     81                f->props = new FProp; 
     82        } 
     83 
     84        f->props->color = c; 
     85 
     86        return 0; 
    8487} 
    8588#endif 
     
    8891int Model::in_VColor(const Vec3& c) 
    8992{ 
    90     Vertex *v = vertices(vertices.length()-1); 
    91  
    92     if( !v->props ) 
    93         v->props = new VProp; 
    94  
    95     v->props->color = c; 
    96     return 0; 
     93        Vertex *v = vertices(vertices.length()-1); 
     94 
     95        if( !v->props ) 
     96        { 
     97                v->props = new VProp; 
     98        } 
     99 
     100        v->props->color = c; 
     101        return 0; 
    97102} 
    98103#endif 
     
    100105Vec3 Model::synthesizeNormal(Vertex *v) 
    101106{ 
    102     Vec3 n(0,0,0); 
    103     int n_count = 0; 
    104  
    105     edge_buffer& edges = v->edgeUses(); 
    106     for(int i=0; i<edges.length(); i++) 
    107     { 
    108         face_buffer& faces = edges(i)->faceUses(); 
    109  
    110         for(int j=0; j<faces.length(); j++) 
    111         { 
    112             n += faces(j)->plane().normal(); 
    113             n_count++; 
    114         } 
    115     } 
    116  
    117     if( n_count ) 
    118         n /= (real)n_count; 
    119     else 
    120     { 
     107        Vec3 n(0,0,0); 
     108        int n_count = 0; 
     109 
     110        edge_buffer& edges = v->edgeUses(); 
     111        for(int i=0; i<edges.length(); i++) 
     112        { 
     113                face_buffer& faces = edges(i)->faceUses(); 
     114 
     115                for(int j=0; j<faces.length(); j++) 
     116                { 
     117                        n += faces(j)->plane().normal(); 
     118                        n_count++; 
     119                } 
     120        } 
     121 
     122        if( n_count ) 
     123        { 
     124                n /= (real)n_count; 
     125        } 
     126        else 
     127        { 
    121128                std::cerr << "Vertex with no normals!!: " << v->uniqID; 
    122129                std::cerr << " / " << v->tempID << std::endl; 
    123     } 
    124     return n; 
     130        } 
     131        return n; 
    125132} 
    126133 
     
    138145Vertex *Model::newVertex(real x, real y, real z) 
    139146{ 
    140     Vertex *v = new Vertex(x, y, z); 
    141  
    142     v->vID = v->uniqID = vertices.add(v); 
    143  
    144 /*    if( logfile && selected_output&OUTPUT_MODEL_DEFN ) 
    145                 *logfile << "v " << x << " " << y << " " << z << std::endl; 
    146 */ 
    147     validVertCount++; 
    148  
    149     return v; 
     147        Vertex *v = new Vertex(x, y, z); 
     148 
     149        v->vID = v->uniqID = vertices.add(v); 
     150 
     151        /*    if( logfile && selected_output&OUTPUT_MODEL_DEFN ) 
     152         *logfile << "v " << x << " " << y << " " << z << std::endl; 
     153         */ 
     154        validVertCount++; 
     155 
     156        return v; 
    150157} 
    151158 
    152159Edge *Model::newEdge(Vertex *a, Vertex *b) 
    153160{ 
    154     Edge *e = new Edge(a, b); 
    155  
    156     e->uniqID = edges.add(e); 
    157     e->sym()->uniqID = e->uniqID; 
    158  
    159     validEdgeCount++; 
    160  
    161     return e; 
     161        Edge *e = new Edge(a, b); 
     162 
     163        e->uniqID = edges.add(e); 
     164        e->sym()->uniqID = e->uniqID; 
     165 
     166        validEdgeCount++; 
     167 
     168        return e; 
    162169} 
    163170 
    164171static Edge *get_edge(Model *m, Vertex *org, Vertex *v) 
    165172{ 
    166     edge_buffer& edge_uses = org->edgeUses(); 
    167  
    168     for(int i=0; i<edge_uses.length(); i++) 
    169         if( edge_uses(i)->dest() == v ) 
    170             return edge_uses(i); 
    171  
    172     Edge *e = m->newEdge(org, v); 
    173  
    174     return e; 
    175 } 
    176  
     173        edge_buffer& edge_uses = org->edgeUses(); 
     174 
     175        for (int i=0; i<edge_uses.length(); i++) 
     176        { 
     177                if ( edge_uses(i)->dest() == v ) 
     178                { 
     179                        return edge_uses(i); 
     180                } 
     181        } 
     182 
     183        Edge *e = m->newEdge(org, v); 
     184 
     185        return e; 
     186} 
    177187 
    178188Face *Model::newFace(Vertex *v1, Vertex *v2, Vertex *v3) 
    179189{ 
    180     Edge *e0 = get_edge(this, v1, v2);   // v1->edgeTo(m, v2); 
    181     Edge *e1 = get_edge(this, v2, v3);   // v2->edgeTo(m, v3); 
    182     Edge *e2 = get_edge(this, v3, v1);   // v3->edgeTo(m, v1); 
    183    
    184     Face *t = new Face(e0, e1, e2); 
    185  
    186     t->uniqID = faces.add(t); 
    187  
    188 /*    if( logfile && selected_output&OUTPUT_MODEL_DEFN ) 
    189         *logfile << "f " << v1->uniqID+1 << " " 
    190         << v2->uniqID+1 << " " << v3->uniqID+1 << std::endl; 
    191 */ 
    192     validFaceCount++; 
    193  
    194     return t; 
     190        Edge *e0 = get_edge(this, v1, v2);   // v1->edgeTo(m, v2); 
     191        Edge *e1 = get_edge(this, v2, v3);   // v2->edgeTo(m, v3); 
     192        Edge *e2 = get_edge(this, v3, v1);   // v3->edgeTo(m, v1); 
     193 
     194        Face *t = new Face(e0, e1, e2); 
     195 
     196        t->uniqID = faces.add(t); 
     197 
     198        /*    if( logfile && selected_output&OUTPUT_MODEL_DEFN ) 
     199         *logfile << "f " << v1->uniqID+1 << " " 
     200         << v2->uniqID+1 << " " << v3->uniqID+1 << std::endl; 
     201         */ 
     202        validFaceCount++; 
     203 
     204        return t; 
    195205} 
    196206 
     
    198208void Model::killVertex(Vertex *v) 
    199209{ 
    200     if( v->isValid() ) 
    201     { 
    202 /*      if( logfile && selected_output&OUTPUT_CONTRACTIONS ) 
    203                 *logfile << "v- " << v->uniqID+1 << std::endl; 
    204 */ 
    205         v->kill(); 
    206         validVertCount--; 
    207     } 
     210        if( v->isValid() ) 
     211        { 
     212                /*      if( logfile && selected_output&OUTPUT_CONTRACTIONS ) 
     213                 *logfile << "v- " << v->uniqID+1 << std::endl; 
     214                 */ 
     215                v->kill(); 
     216                validVertCount--; 
     217        } 
    208218} 
    209219 
    210220void Model::killEdge(Edge *e) 
    211221{ 
    212     if( e->isValid() ) 
    213     { 
    214         e->kill(); 
    215         validEdgeCount--; 
    216     } 
     222        if( e->isValid() ) 
     223        { 
     224                e->kill(); 
     225                validEdgeCount--; 
     226        } 
    217227} 
    218228 
    219229void Model::killFace(Face *f) 
    220230{ 
    221     if( f->isValid() ) 
    222     { 
    223 /*      if( logfile && selected_output&OUTPUT_CONTRACTIONS ) 
    224                 *logfile << "f- " << f->uniqID+1 << std::endl; 
    225 */ 
    226         f->kill(); 
    227         validFaceCount--; 
    228     } 
     231        if( f->isValid() ) 
     232        { 
     233                /*      if( logfile && selected_output&OUTPUT_CONTRACTIONS ) 
     234                 *logfile << "f- " << f->uniqID+1 << std::endl; 
     235                 */ 
     236                f->kill(); 
     237                validFaceCount--; 
     238        } 
    229239} 
    230240 
    231241void Model::reshapeVertex(Vertex *v, real x, real y, real z) 
    232242{ 
    233     v->set(x, y, z); 
     243        v->set(x, y, z); 
    234244 
    235245#ifdef LOG_LOWLEVEL_OPS 
    236     if( logfile ) 
    237         *logfile << "v! " << v->uniqID+1 << " " 
    238                  << x << " " << y << " " << z << endl; 
     246        if( logfile ) 
     247        { 
     248                *logfile << "v! " << v->uniqID+1 << " " 
     249                        << x << " " << y << " " << z << endl; 
     250        } 
    239251#endif 
    240252} 
     
    242254void Model::remapVertex(Vertex *from, Vertex *to) 
    243255{ 
    244     from->remapTo(to); 
     256        from->remapTo(to); 
    245257 
    246258#ifdef LOG_LOWLEVEL_OPS 
    247     if( logfile ) 
    248         *logfile << "v> " << from->uniqID+1 << " " << to->uniqID+1 << endl; 
    249 #endif 
    250 } 
    251  
    252  
     259        if( logfile ) 
     260        { 
     261                *logfile << "v> " << from->uniqID+1 << " " << to->uniqID+1 << endl; 
     262        } 
     263#endif 
     264} 
    253265 
    254266void Model::contract(Vertex *v1, 
     
    257269                     face_buffer& changed) 
    258270{ 
    259     int i; 
    260  
    261 /*    if( logfile && selected_output&OUTPUT_CONTRACTIONS ) 
    262     { 
    263         *logfile << "v% (" << v1->uniqID+1; 
     271        int i; 
     272 
     273        /*    if( logfile && selected_output&OUTPUT_CONTRACTIONS ) 
     274                                { 
     275         *logfile << "v% (" << v1->uniqID+1; 
     276         for(i=0; i<rest.length(); i++) 
     277         *logfile << " " << rest(i)->uniqID+1; 
     278 
     279         *logfile << ") " << to[X] << " " << to[Y] << " " << to[Z] << std::endl; 
     280         } 
     281         */ 
     282 
     283        // 
     284        // Collect all the faces that are going to be changed 
     285        // 
     286        contractionRegion(v1, rest, changed); 
     287 
     288        reshapeVertex(v1, to[X], to[Y], to[Z]); 
     289 
    264290        for(i=0; i<rest.length(); i++) 
    265             *logfile << " " << rest(i)->uniqID+1; 
    266          
    267         *logfile << ") " << to[X] << " " << to[Y] << " " << to[Z] << std::endl; 
    268     } 
    269 */ 
    270  
    271     // 
    272     // Collect all the faces that are going to be changed 
    273     // 
    274     contractionRegion(v1, rest, changed); 
    275  
    276     reshapeVertex(v1, to[X], to[Y], to[Z]); 
    277  
    278     for(i=0; i<rest.length(); i++) 
     291        { 
    279292                rest(i)->remapTo(v1); 
    280  
    281     removeDegeneracy(changed); 
     293        } 
     294 
     295        removeDegeneracy(changed); 
    282296} 
    283297 
    284298void Model::maybeFixFace(Face *F) 
    285299{ 
    286     // 
    287     // Invalid faces do not need to be fixed. 
     300        // 
     301        // Invalid faces do not need to be fixed. 
    288302#ifdef SAFETY 
    289     assert( F->isValid() ); 
    290 #endif 
    291  
    292     Vertex *v0=F->vertex(0); Vertex *v1=F->vertex(1); Vertex *v2=F->vertex(2); 
    293     Edge *e0 = F->edge(0); Edge *e1 = F->edge(1); Edge *e2 = F->edge(2); 
    294  
    295     bool a=(v0 == v1),  b=(v0 == v2),  c=(v1 == v2); 
    296  
    297     if( a && c ) 
    298     { 
    299         // This triangle has been reduced to a point 
    300         killEdge(e0); 
    301         killEdge(e1); 
    302         killEdge(e2); 
    303  
    304         killFace(F); 
    305     } 
    306     // 
    307     // In the following 3 cases, the triangle has become an edge 
    308     else if( a ) 
    309     { 
    310         killEdge(e0); 
    311         e1->remapTo(e2->sym()); 
    312         killFace(F); 
    313     } 
    314     else if( b ) 
    315     { 
    316         killEdge(e2); 
    317         e0->remapTo(e1->sym()); 
    318         killFace(F); 
    319     } 
    320     else if( c ) 
    321     { 
    322         killEdge(e1); 
    323         e0->remapTo(e2->sym()); 
    324         killFace(F); 
    325     } 
    326     else 
    327     { 
    328         // This triangle remains non-degenerate 
    329 /*              // SUS: recalcular la normal en los triangulos cambiados no degenerados 
    330  
    331                 simplif::Vertex * auxv0 = F->vertex(0); 
    332                 simplif::Vertex * auxv1 = F->vertex(1); 
    333                 simplif::Vertex * auxv2 = F->vertex(2); 
    334                 simplif::Vec3 vd1(auxv1->operator[](simplif::X) - auxv0->operator[](simplif::X),  
    335                                                 auxv1->operator[](simplif::Y) - auxv0->operator[](simplif::Y), 
    336                                                 auxv1->operator[](simplif::Z) - auxv0->operator[](simplif::Z)); 
    337                 simplif::Vec3 vd2(auxv2->operator[](simplif::X) - auxv0->operator[](simplif::X),  
    338                                                 auxv2->operator[](simplif::Y) - auxv0->operator[](simplif::Y), 
    339                                                 auxv2->operator[](simplif::Z) - auxv0->operator[](simplif::Z)); 
    340  
    341                 simplif::unitize(vd1); 
    342                 simplif::unitize(vd2); 
    343  
    344                 simplif::Vec3 vn = vd1 ^ vd2; 
    345                 simplif::unitize(vn); 
    346                  
     303        assert( F->isValid() ); 
     304#endif 
     305 
     306        Vertex *v0=F->vertex(0); Vertex *v1=F->vertex(1); Vertex *v2=F->vertex(2); 
     307        Edge *e0 = F->edge(0); Edge *e1 = F->edge(1); Edge *e2 = F->edge(2); 
     308 
     309        bool a=(v0 == v1),  b=(v0 == v2),  c=(v1 == v2); 
     310 
     311        if( a && c ) 
     312        { 
     313                // This triangle has been reduced to a point 
     314                killEdge(e0); 
     315                killEdge(e1); 
     316                killEdge(e2); 
     317 
     318                killFace(F); 
     319        } 
     320        // 
     321        // In the following 3 cases, the triangle has become an edge 
     322        else if( a ) 
     323        { 
     324                killEdge(e0); 
     325                e1->remapTo(e2->sym()); 
     326                killFace(F); 
     327        } 
     328        else if( b ) 
     329        { 
     330                killEdge(e2); 
     331                e0->remapTo(e1->sym()); 
     332                killFace(F); 
     333        } 
     334        else if( c ) 
     335        { 
     336                killEdge(e1); 
     337                e0->remapTo(e2->sym()); 
     338                killFace(F); 
     339        } 
     340        else 
     341        { 
     342                // This triangle remains non-degenerate 
     343                /*              // SUS: recalcular la normal en los triangulos cambiados no degenerados 
     344 
     345                                        simplif::Vertex * auxv0 = F->vertex(0); 
     346                                        simplif::Vertex * auxv1 = F->vertex(1); 
     347                                        simplif::Vertex * auxv2 = F->vertex(2); 
     348                                        simplif::Vec3 vd1(auxv1->operator[](simplif::X) - auxv0->operator[](simplif::X),  
     349                                        auxv1->operator[](simplif::Y) - auxv0->operator[](simplif::Y), 
     350                                        auxv1->operator[](simplif::Z) - auxv0->operator[](simplif::Z)); 
     351                                        simplif::Vec3 vd2(auxv2->operator[](simplif::X) - auxv0->operator[](simplif::X),  
     352                                        auxv2->operator[](simplif::Y) - auxv0->operator[](simplif::Y), 
     353                                        auxv2->operator[](simplif::Z) - auxv0->operator[](simplif::Z)); 
     354 
     355                                        simplif::unitize(vd1); 
     356                                        simplif::unitize(vd2); 
     357 
     358                                        simplif::Vec3 vn = vd1 ^ vd2; 
     359                                        simplif::unitize(vn); 
     360 
    347361                //auxf->vertex_normals[0] = vn; 
    348362                //auxf->vertex_normals[1] = vn; 
     
    358372                F->vertex_normals[2][simplif::Z] = vn[simplif::Z];*/ 
    359373 
    360     } 
     374        } 
    361375} 
    362376 
    363377void Model::removeDegeneracy(face_buffer& changed) 
    364378{ 
    365     for(int i=0; i<changed.length(); i++) 
     379        for(int i=0; i<changed.length(); i++) 
     380        { 
    366381                maybeFixFace(changed(i)); 
     382        } 
    367383} 
    368384 
    369385void Model::contractionRegion(Vertex *v1, 
    370                               const vert_buffer& vertices, 
    371                               face_buffer& changed) 
    372 { 
    373     changed.reset(); 
    374  
    375     // 
    376     // First, reset the marks on all reachable vertices 
    377     int i; 
    378  
    379     untagFaceLoop(v1); 
    380     for(i=0; i<vertices.length(); i++) 
     386                                                                                                const vert_buffer& vertices, 
     387                                                                                                face_buffer& changed) 
     388{ 
     389        changed.reset(); 
     390 
     391        // First, reset the marks on all reachable vertices 
     392        int i; 
     393 
     394        untagFaceLoop(v1); 
     395 
     396        for(i   =       0; i < vertices.length(); i++) 
     397        { 
    381398                untagFaceLoop(vertices(i)); 
    382  
    383     // 
    384     // Now, pick out all the unique reachable faces 
    385     collectFaceLoop(v1, changed); 
    386     for(i=0; i<vertices.length(); i++) 
     399        } 
     400 
     401        // Now, pick out all the unique reachable faces 
     402        collectFaceLoop(v1, changed); 
     403 
     404        for(i   =       0; i < vertices.length(); i++) 
     405        { 
    387406                collectFaceLoop(vertices(i), changed); 
     407        } 
    388408} 
    389409 
     
    391411void Model::contractionRegion(Vertex *v1, Vertex *v2, face_buffer& changed) 
    392412{ 
    393     changed.reset(); 
    394  
    395     // 
    396     // Clear marks on all reachable faces 
    397     untagFaceLoop(v1); 
    398     untagFaceLoop(v2); 
    399  
    400     // 
    401     // Collect all the unique reachable faces 
    402     collectFaceLoop(v1, changed); 
    403     collectFaceLoop(v2, changed); 
     413        changed.reset(); 
     414 
     415        // 
     416        // Clear marks on all reachable faces 
     417        untagFaceLoop(v1); 
     418        untagFaceLoop(v2); 
     419 
     420        // 
     421        // Collect all the unique reachable faces 
     422        collectFaceLoop(v1, changed); 
     423        collectFaceLoop(v2, changed); 
    404424} 
    405425 
     
    408428{ 
    409429#ifdef SAFETY 
    410     assert( v1 != v2); 
    411 #endif 
    412  
    413 /*    if( logfile && selected_output&OUTPUT_CONTRACTIONS ) 
    414         *logfile << "v% (" << v1->uniqID+1 << " " << v2->uniqID+1 << ") " 
    415                  << to[X] << " " 
    416                  << to[Y] << " " 
    417                  << to[Z] << std::endl; 
    418 */ 
    419     // 
    420     // Collect all the faces that are going to be changed 
    421     // 
    422     contractionRegion(v1, v2, changed); 
    423  
    424     reshapeVertex(v1, to[X], to[Y], to[Z]); 
    425  
    426     // 
    427     // Map v2 ---> v1.  This accomplishes the topological change that we want. 
    428     v2->remapTo(v1); 
    429  
    430     removeDegeneracy(changed); 
    431 } 
    432  
     430        assert( v1 != v2); 
     431#endif 
     432        // 
     433        // Collect all the faces that are going to be changed 
     434        // 
     435        contractionRegion(v1, v2, changed); 
     436 
     437        reshapeVertex(v1, to[X], to[Y], to[Z]); 
     438 
     439        // Map v2 ---> v1.  This accomplishes the topological change that we want. 
     440        v2->remapTo(v1); 
     441 
     442//      std::cout << "Contract(QslimInds): " << v2->validID() << " --> " << v1->validID() << std::endl; 
     443 
     444        removeDegeneracy(changed); 
     445} 
    433446 
    434447/* 
     
    494507} 
    495508*/ 
     509 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/AdjModel.h

    r1025 r1526  
    2222        class Model : public SMF_Model 
    2323        { 
    24         protected: 
    25                 vert_buffer vertices; 
    26                 edge_buffer edges; 
    27                 face_buffer faces; 
    28                 vec3_buffer normals; // SUS 
    29                 vec2_buffer texcoords; 
     24                protected: 
     25                         
     26                        vert_buffer vertices; 
     27                        edge_buffer edges; 
     28                        face_buffer faces; 
     29                        vec3_buffer normals; // SUS 
     30                        vec2_buffer texcoords; 
    3031 
    31         private: 
     32                private: 
    3233 
    33                 void maybeFixFace(Face *); 
     34                        void maybeFixFace(Face *); 
    3435 
    35         public: 
    36                 Model() { 
    37                         validVertCount = 0; 
    38                         validEdgeCount = 0; 
    39                         validFaceCount = 0; 
    40                 } 
     36                public: 
     37                         
     38                        Model() 
     39                        { 
     40                                validVertCount = 0; 
     41                                validEdgeCount = 0; 
     42                                validFaceCount = 0; 
     43                        } 
    4144 
    42                 ~Model(){ 
    43                         for (int i=0; i<vertices.length(); i++) 
    44                                 delete vertices[i]; 
    45                         for (int i=0; i<edges.length(); i++) 
    46                                 delete edges[i]; 
    47                         for (int i=0; i<faces.length(); i++) 
    48                                 delete faces[i]; 
    49                 } 
     45                        ~Model() 
     46                        { 
     47                                for (int i=0; i<vertices.length(); i++) 
     48                                { 
     49                                        delete vertices[i]; 
     50                                } 
    5051 
    51                 Bounds bounds; 
     52                                for (int i=0; i<edges.length(); i++) 
     53                                { 
     54                                        delete edges[i]; 
     55                                } 
    5256 
    53                 int validVertCount; 
    54                 int validEdgeCount; 
    55                 int validFaceCount; 
     57                                for (int i=0; i<faces.length(); i++) 
     58                                { 
     59                                        delete faces[i]; 
     60                                } 
     61                        } 
    5662 
    57                 // 
    58                 // Basic model accessor functions 
    59                 // 
    60                 simplif::Vertex *vertex(int i) { return vertices(i); } 
    61                 simplif::Vec3 & normal(int i){ return normals(i); } 
    62                 simplif::Vec2 & texcoord(int i){ return texcoords(i); } 
    63                 simplif::Edge *edge(int i) { return edges(i); } 
    64                 simplif::Face *face(int i) { return faces(i); } 
     63                        Bounds bounds; 
    6564 
    66                 int vertCount() { return vertices.length(); } 
    67                 int normCount() { return normals.length();  } 
    68                 int texcoordCount() { return texcoords.length();  } 
    69                 int edgeCount() { return edges.length();    } 
    70                 int faceCount() { return faces.length();    } 
     65                        int validVertCount; 
     66                        int validEdgeCount; 
     67                        int validFaceCount; 
    7168 
    72                 vert_buffer& allVertices() { return vertices; } 
    73                 edge_buffer& allEdges()    { return edges;    } 
    74                 face_buffer& allFaces()    { return faces;    } 
     69                        // 
     70                        // Basic model accessor functions 
     71                        // 
     72                        simplif::Vertex *vertex(int i) { return vertices(i); } 
     73                        simplif::Vec3 & normal(int i){ return normals(i); } 
     74                        simplif::Vec2 & texcoord(int i){ return texcoords(i); } 
     75                        simplif::Edge *edge(int i) { return edges(i); } 
     76                        simplif::Face *face(int i) { return faces(i); } 
    7577 
    76                 // 
    77                 // Simplification primitives 
    78                 // 
    79                 Vertex   *newVertex(real x=0.0, real y=0.0, real z=0.0); 
    80                 Edge     *newEdge(Vertex *,Vertex *); 
    81                 Face *newFace(Vertex *, Vertex *, Vertex *); 
     78                        int vertCount() { return vertices.length(); } 
     79                        int normCount() { return normals.length();  } 
     80                        int texcoordCount() { return texcoords.length();  } 
     81                        int edgeCount() { return edges.length();    } 
     82                        int faceCount() { return faces.length();    } 
    8283 
    83                 void killVertex(Vertex *); 
    84                 void killEdge(Edge *); 
    85                 void killFace(Face *); 
     84                        vert_buffer& allVertices() { return vertices; } 
     85                        edge_buffer& allEdges()    { return edges;    } 
     86                        face_buffer& allFaces()    { return faces;    } 
    8687 
    87                 void reshapeVertex(Vertex *, real, real, real); 
    88                 void remapVertex(Vertex *from, Vertex *to); 
     88                        // 
     89                        // Simplification primitives 
     90                        // 
     91                        Vertex   *newVertex(real x=0.0, real y=0.0, real z=0.0); 
     92                        Edge     *newEdge(Vertex *,Vertex *); 
     93                        Face *newFace(Vertex *, Vertex *, Vertex *); 
    8994 
    90                 void contract(Vertex *v1, Vertex *v2, const Vec3& to, 
    91                           face_buffer& changed); 
     95                        void killVertex(Vertex *); 
     96                        void killEdge(Edge *); 
     97                        void killFace(Face *); 
    9298 
    93                 void contract(Vertex *v1,  
    94                           const vert_buffer& others, 
    95                           const Vec3& to, 
    96                           face_buffer& changed); 
     99                        void reshapeVertex(Vertex *, real, real, real); 
     100                        void remapVertex(Vertex *from, Vertex *to); 
    97101 
     102                        void contract(Vertex *v1, Vertex *v2, const Vec3& to, 
     103                                        face_buffer& changed); 
    98104 
    99                 // 
    100                 // Simplification convenience procedures 
    101                 // 
    102                 void removeDegeneracy(face_buffer& changed); 
    103                 void contractionRegion(Vertex *v1, Vertex *v2, face_buffer& changed); 
    104                 void contractionRegion(Vertex *v1, 
    105                                    const vert_buffer& vertices, 
    106                                    face_buffer& changed); 
     105                        void contract(Vertex *v1,  
     106                                        const vert_buffer& others, 
     107                                        const Vec3& to, 
     108                                        face_buffer& changed); 
    107109 
    108                 // 
    109                 // SMF reader functions 
    110                 // 
    111                 int in_Vertex(const Vec3&); 
    112                 int in_Normal(const Vec3&); 
    113                 int in_TexCoord(const Vec2&); 
    114                 int in_Face(int v1, int v2, int v3, int n1, int n2, int n3, int t1, int t2, int t3); 
    115                 int miin_Face(int v1, int v2, int v3); 
     110                        // 
     111                        // Simplification convenience procedures 
     112                        // 
     113                        void removeDegeneracy(face_buffer& changed); 
     114                        void contractionRegion(Vertex *v1, Vertex *v2, face_buffer& changed); 
     115                        void contractionRegion(Vertex *v1, 
     116                                        const vert_buffer& vertices, 
     117                                        face_buffer& changed); 
    116118 
    117 /*      #ifdef SUPPORT_VCOLOR 
    118                 int in_VColor(const Vec3&); 
    119         #endif 
    120         #ifdef SUPPORT_FCOLOR 
    121                 int in_FColor(const Vec3&); 
    122         #endif 
     119                        // 
     120                        // SMF reader functions 
     121                        // 
     122                        int in_Vertex(const Vec3&); 
     123                        int in_Normal(const Vec3&); 
     124                        int in_TexCoord(const Vec2&); 
     125 
     126                        int in_Face(int v1, int v2, int v3,  
     127                                                                        int n1, int n2, int n3, 
     128                                                                        int t1, int t2, int t3); 
     129 
     130                        int miin_Face(int v1, int v2, int v3); 
     131 
     132                        /*      #ifdef SUPPORT_VCOLOR 
     133                                        int in_VColor(const Vec3&); 
     134#endif 
     135#ifdef SUPPORT_FCOLOR 
     136int in_FColor(const Vec3&); 
     137#endif 
    123138*/ 
    124                 // 
    125                 // Some random functions that are mostly temporary 
    126                 // 
     139                        // 
     140                        // Some random functions that are mostly temporary 
     141                        // 
    127142 
    128                 Vec3 synthesizeNormal(Vertex *); 
     143                        Vec3 synthesizeNormal(Vertex *); 
    129144        }; 
    130145} 
    131146 
    132  
    133147// NAUTILUS_ADJMODEL_INCLUDED 
    134148#endif 
     149 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/AdjPrims.cxx

    r1025 r1526  
    1818{ 
    1919#ifdef SAFETY 
    20     assert( edge_uses.length() == 0 ); 
    21 #endif 
    22     markInvalid(); 
    23     edge_uses.reset(); 
     20        assert( edge_uses.length() == 0 ); 
     21#endif 
     22        markInvalid(); 
     23        edge_uses.reset(); 
    2424} 
    2525 
    2626void Vertex::linkEdge(Edge *e) 
    2727{ 
    28     edge_uses.add(e); 
     28        edge_uses.add(e); 
    2929} 
    3030 
    3131void Vertex::unlinkEdge(Edge *e) 
    3232{ 
    33     int index = edge_uses.find(e); 
    34  
    35 #ifdef SAFETY 
    36     assert( index >= 0 ); 
    37 #endif 
    38     edge_uses.remove(index); 
    39     if( edge_uses.length() <= 0 ) 
    40         kill(); 
     33        int index = edge_uses.find(e); 
     34 
     35#ifdef SAFETY 
     36        assert( index >= 0 ); 
     37#endif 
     38        edge_uses.remove(index); 
     39        if( edge_uses.length() <= 0 ) 
     40                kill(); 
    4141} 
    4242 
     
    4545void Vertex::remapTo(Vertex *v) 
    4646{ 
    47     if( v != this ) 
    48     { 
    49                 for(int i=0; i<edge_uses.length(); i++) 
     47        if ( v != this ) 
     48        { 
     49                for (int i=0; i<edge_uses.length(); i++) 
    5050                { 
    5151                        assert( edge_uses(i)->org() == this ); 
     
    5454 
    5555                kill(); 
    56     } 
    57 } 
    58  
     56        } 
     57} 
    5958 
    6059Edge::Edge(Vertex *a, Vertex *b) 
    6160{ 
    62     v1 = a; 
    63     v1->linkEdge(this); 
    64  
    65     face_uses = new buffer<Face *>(2); 
    66  
    67     twin = new Edge(this, b); 
     61        v1 = a; 
     62        v1->linkEdge(this); 
     63 
     64        face_uses = new buffer<Face *>(2); 
     65 
     66        twin = new Edge(this, b); 
    6867} 
    6968 
    7069Edge::Edge(Edge *sibling, Vertex *org) 
    7170{ 
    72     v1 = org; 
    73     v1->linkEdge(this); 
    74  
    75     face_uses = sibling->face_uses; 
    76     twin = sibling; 
     71        v1 = org; 
     72        v1->linkEdge(this); 
     73 
     74        face_uses = sibling->face_uses; 
     75        twin = sibling; 
    7776} 
    7877 
    7978Edge::~Edge() 
    8079{ 
    81     if( twin ) 
    82     { 
    83         face_uses->f_r_e_e(); 
    84         delete face_uses; 
    85  
    86         twin->twin = NULL; 
    87         delete twin; 
    88     } 
     80        if ( twin ) 
     81        { 
     82                face_uses->f_r_e_e(); 
     83                delete face_uses; 
     84 
     85                twin->twin = NULL; 
     86                delete twin; 
     87        } 
    8988} 
    9089 
     
    9291{ 
    9392#ifdef SAFETY 
    94     assert( face_uses->length() == 0 ); 
    95 #endif 
    96     if( isValid() ) 
    97     { 
    98         org()->unlinkEdge(this); 
    99         dest()->unlinkEdge(sym()); 
    100         markInvalid(); 
    101         twin->markInvalid(); 
    102         face_uses->reset(); 
    103     } 
     93        assert( face_uses->length() == 0 ); 
     94#endif 
     95        if ( isValid() ) 
     96        { 
     97                org()->unlinkEdge(this); 
     98                dest()->unlinkEdge(sym()); 
     99                markInvalid(); 
     100                twin->markInvalid(); 
     101                face_uses->reset(); 
     102        } 
    104103} 
    105104 
    106105void Edge::linkFace(Face *face) 
    107106{ 
    108     face_uses->add(face); 
     107        face_uses->add(face); 
    109108} 
    110109 
    111110void Edge::unlinkFace(Face *face) 
    112111{ 
    113     int index = face_uses->find(face); 
    114  
    115 #ifdef SAFETY 
    116     assert( index>=0 ); 
    117 #endif 
    118     face_uses->remove(index); 
    119     if( face_uses->length() == 0 ) 
    120         kill(); 
     112        int index = face_uses->find(face); 
     113 
     114#ifdef SAFETY 
     115        assert( index>=0 ); 
     116#endif 
     117        face_uses->remove(index); 
     118        if( face_uses->length() == 0 ) 
     119                kill(); 
    121120} 
    122121 
    123122void Edge::remapTo(Edge *e) 
    124123{ 
    125     if( e != this ) 
    126     { 
    127         for(int i=0; i<face_uses->length(); i++) 
    128         { 
    129             (*face_uses)(i)->remapEdge(this, e); 
    130         } 
    131      
    132         // Disconnect from all faces and vertices 
    133         kill(); 
    134     } 
     124        if ( e != this ) 
     125        { 
     126                for (int i=0; i<face_uses->length(); i++) 
     127                { 
     128                        (*face_uses)(i)->remapEdge(this, e); 
     129                } 
     130 
     131                // Disconnect from all faces and vertices 
     132                kill(); 
     133        } 
    135134} 
    136135 
    137136void Edge::remapEndpoint(Vertex *from, Vertex *to) 
    138137{ 
    139     if( org()==from ) 
    140     { 
     138        if ( org() == from ) 
     139        { 
    141140                v1 = to; 
    142141                to->linkEdge(this); 
    143     } 
    144     else if( dest()==from ) 
    145     { 
     142        } 
     143        else if ( dest() == from ) 
     144        { 
    146145                twin->v1 = to; 
    147146                to->linkEdge(twin); 
    148     } 
    149     else 
    150     { 
     147        } 
     148        else 
     149        { 
    151150                std::cerr << "WARNING remapEndpoint: Illegal endpoint." << std::endl; 
    152     } 
    153  
    154     // 
    155     // The cached Plane equations for the faces attached to us may 
    156     // no longer be valid (in general, chances are pretty slim that they're OK) 
    157     for(int i=0; i<face_uses->length(); i++) 
    158     { 
     151        } 
     152 
     153        // 
     154        // The cached Plane equations for the faces attached to us may 
     155        // no longer be valid (in general, chances are pretty slim that they're OK) 
     156        for (int i      =       0; i < face_uses->length(); i++) 
     157        { 
    159158                face_uses->ref(i)->invalidatePlane(); 
    160     } 
    161 } 
    162  
     159        } 
     160} 
    163161 
    164162Face::Face(Edge *e0, Edge *e1, Edge *e2) 
    165163    : Face3(*e0->org(), *e1->org(), *e2->org()) 
    166164{ 
    167     edges[0] = e0; 
    168     edges[1] = e1; 
    169     edges[2] = e2; 
    170  
    171     edges[0]->linkFace(this); 
    172     edges[1]->linkFace(this); 
    173     edges[2]->linkFace(this); 
     165        edges[0] = e0; 
     166        edges[1] = e1; 
     167        edges[2] = e2; 
     168 
     169        edges[0]->linkFace(this); 
     170        edges[1]->linkFace(this); 
     171        edges[2]->linkFace(this); 
    174172 
    175173#ifdef SUPPORT_FCOLOR 
    176     props = NULL; 
     174        props = NULL; 
    177175#endif 
    178176} 
     
    180178void Face::kill() 
    181179{ 
    182     if( isValid() ) 
    183     { 
    184         if( edge(0)->isValid() ) 
    185             edge(0)->unlinkFace(this); 
    186  
    187         if( edge(1)->isValid() ) 
    188             edge(1)->unlinkFace(this); 
    189  
    190         if( edge(2)->isValid() ) 
    191             edge(2)->unlinkFace(this); 
    192  
    193         markInvalid(); 
    194     } 
     180        if( isValid() ) 
     181        { 
     182                if( edge(0)->isValid() ) 
     183                        edge(0)->unlinkFace(this); 
     184 
     185                if( edge(1)->isValid() ) 
     186                        edge(1)->unlinkFace(this); 
     187 
     188                if( edge(2)->isValid() ) 
     189                        edge(2)->unlinkFace(this); 
     190 
     191                markInvalid(); 
     192        } 
    195193} 
    196194 
    197195void Face::remapEdge(Edge *from, Edge *to) 
    198196{ 
    199     for(int i=0; i<3; i++) 
    200     { 
    201         if( edges[i] == from ) 
    202         { 
    203             edges[i] = to; 
    204             to->linkFace(this); 
    205         } 
    206         else if( edges[i] == from->sym() ) 
    207         { 
    208             edges[i] = to->sym(); 
    209             to->sym()->linkFace(this); 
    210         } 
    211     } 
    212  
    213     invalidatePlane(); 
    214 } 
    215  
     197        for (int i=0; i<3; i++) 
     198        { 
     199                if ( edges[i] == from ) 
     200                { 
     201                        edges[i] = to; 
     202                        to->linkFace(this); 
     203                } 
     204                else if ( edges[i] == from->sym() ) 
     205                { 
     206                        edges[i] = to->sym(); 
     207                        to->sym()->linkFace(this); 
     208                } 
     209        } 
     210 
     211        invalidatePlane(); 
     212} 
    216213 
    217214void simplif::untagFaceLoop(Vertex *v) 
    218215{ 
    219     edge_buffer& edges = v->edgeUses(); 
    220  
    221     for(int j=0; j<edges.length(); j++) 
    222     {        
    223         face_buffer& faces = edges(j)->faceUses(); 
    224         for(int k=0; k<faces.length(); k++) 
    225             faces(k)->untag(); 
    226     } 
     216        edge_buffer& edges = v->edgeUses(); 
     217 
     218        for (int j      =       0; j < edges.length(); j++) 
     219        {            
     220                face_buffer& faces = edges(j)->faceUses(); 
     221 
     222                for (int k      =       0; k < faces.length(); k++) 
     223                { 
     224                        faces(k)->untag(); 
     225                } 
     226        } 
    227227} 
    228228 
    229229void simplif::collectFaceLoop(Vertex *v, face_buffer& loop) 
    230230{ 
    231     edge_buffer& edges = v->edgeUses(); 
    232  
    233     for(int j=0; j<edges.length(); j++) 
    234     {        
    235         face_buffer& faces = edges(j)->faceUses(); 
    236         for(int k=0; k<faces.length(); k++) 
    237             if( !faces(k)->isTagged() ) 
    238             { 
    239                 loop.add(faces(k)); 
    240                 faces(k)->tag(); 
    241             } 
    242     } 
     231        edge_buffer& edges = v->edgeUses(); 
     232 
     233        for(int j=0; j<edges.length(); j++) 
     234        {            
     235                face_buffer& faces = edges(j)->faceUses(); 
     236                for(int k=0; k<faces.length(); k++) 
     237                        if( !faces(k)->isTagged() ) 
     238                        { 
     239                                loop.add(faces(k)); 
     240                                faces(k)->tag(); 
     241                        } 
     242        } 
    243243} 
    244244 
    245245int simplif::classifyEdge(Edge *e) 
    246246{ 
    247     int cls = e->faceUses().length(); 
    248  
    249     if( cls>3 ) cls=3; 
    250  
    251     return cls; 
     247        int cls = e->faceUses().length(); 
     248 
     249        if( cls>3 ) cls=3; 
     250 
     251        return cls; 
    252252} 
    253253 
    254254int simplif::classifyVertex(Vertex *v) 
    255255{ 
    256     int border_count = 0; 
    257     const edge_buffer& edges = v->edgeUses(); 
    258  
    259     for(int i=0; i<edges.length(); i++) 
    260         if( classifyEdge(edges(i)) == 1 ) 
    261             border_count++; 
    262  
    263     if( border_count == edges.length() ) 
    264         return VERTEX_BORDER_ONLY; 
    265     else  
    266         return (border_count > 0); 
    267 } 
     256        int border_count = 0; 
     257        const edge_buffer& edges = v->edgeUses(); 
     258 
     259        for(int i=0; i<edges.length(); i++) 
     260                if( classifyEdge(edges(i)) == 1 ) 
     261                        border_count++; 
     262 
     263        if( border_count == edges.length() ) 
     264                return VERTEX_BORDER_ONLY; 
     265        else  
     266                return (border_count > 0); 
     267} 
     268 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/AdjPrims.h

    r1025 r1526  
    2727        class Face; 
    2828 
    29  
    3029        typedef buffer<Vertex *> vert_buffer; 
    3130        typedef buffer<Edge *> edge_buffer; 
     
    3736        extern void collectFaceLoop(Vertex *v, face_buffer& faces); 
    3837 
    39         #define EDGE_BOGUS 0 
    40         #define EDGE_BORDER 1 
    41         #define EDGE_MANIFOLD 2 
    42         #define EDGE_NONMANIFOLD 3 
     38#define EDGE_BOGUS 0 
     39#define EDGE_BORDER 1 
     40#define EDGE_MANIFOLD 2 
     41#define EDGE_NONMANIFOLD 3 
    4342        extern int classifyEdge(Edge *); 
    4443 
    45         #define VERTEX_INTERIOR 0 
    46         #define VERTEX_BORDER 1 
    47         #define VERTEX_BORDER_ONLY 2 
     44#define VERTEX_INTERIOR 0 
     45#define VERTEX_BORDER 1 
     46#define VERTEX_BORDER_ONLY 2 
    4847        extern int classifyVertex(Vertex *); 
    4948 
     
    5251        // The actual class definitions 
    5352        // 
     53        //////////////////////////////////////////////////////////////////////// 
    5454 
    5555        class VProp 
    5656        { 
    57         public: 
    58                 Vec3 color; 
     57                public: 
     58                        Vec3 color; 
    5959        }; 
    6060 
    6161        class FProp 
    6262        { 
    63         public: 
    64                 Vec3 color; 
     63                public: 
     64                        Vec3 color; 
    6565        }; 
    6666 
     
    6868        { 
    6969                edge_buffer edge_uses; 
    70      
    71         public: 
    72         #ifdef SUPPORT_VCOLOR 
     70 
     71                public: 
     72#ifdef SUPPORT_VCOLOR 
    7373                VProp *props; 
    74         #endif 
     74#endif 
    7575 
    7676                Vertex(real x, real y, real z) : Vec3(x, y, z), edge_uses(6) { 
    77         #ifdef SUPPORT_VCOLOR 
    78                 props = NULL; 
    79         #endif 
     77#ifdef SUPPORT_VCOLOR 
     78                        props = NULL; 
     79#endif                   
    8080                } 
    8181                // 
     
    9292                void remapTo(Vertex *v); 
    9393 
    94                 unsigned int vID; 
     94                // SUS 
     95                int vID; // this can be -1 when the vertex becomes non-valid 
    9596        }; 
    96  
    9797 
    9898        class Edge : public NPrim 
    9999        { 
    100         private: 
     100                private: 
    101101 
    102                 Vertex *v1; 
     102                        Vertex *v1; 
    103103 
    104                 face_buffer *face_uses; 
    105                 Edge *twin; 
     104                        face_buffer *face_uses; 
     105                        Edge *twin; 
    106106 
    107                 Edge(Edge *twin, Vertex *org); // the twin constructor 
     107                        Edge(Edge *twin, Vertex *org); // the twin constructor 
    108108 
    109         public: 
    110                 Edge(Vertex *, Vertex *); 
    111                 ~Edge(); 
     109                public: 
    112110 
    113                 // 
    114                 // Fundamental Edge accessors 
    115                 // 
    116                 Vertex *org()  { return v1;       } 
    117                 Vertex *dest() { return twin->v1; } 
    118                 Edge *sym()    { return twin;     } 
     111                        Edge(Vertex *, Vertex *); 
     112                        ~Edge(); 
    119113 
    120                 // 
    121                 // Standard methods for all objects 
    122                 // 
    123                 void kill(); 
    124                 face_buffer& faceUses() { return *face_uses; } 
     114                        // 
     115                        // Fundamental Edge accessors 
     116                        // 
     117                        Vertex *org()  { return v1;       } 
     118                        Vertex *dest() { return twin->v1; } 
     119                        Edge *sym()    { return twin;     } 
    125120 
    126                 // 
    127                 // Basic primitives for manipulating model topology 
    128                 // 
    129                 void linkFace(Face *); 
    130                 void unlinkFace(Face *); 
    131                 void remapEndpoint(Vertex *from, Vertex *to); 
    132                 void remapTo(Edge *); 
     121                        // 
     122                        // Standard methods for all objects 
     123                        // 
     124                        void kill(); 
     125                        face_buffer& faceUses() { return *face_uses; } 
     126 
     127                        // 
     128                        // Basic primitives for manipulating model topology 
     129                        // 
     130                        void linkFace(Face *); 
     131                        void unlinkFace(Face *); 
     132                        void remapEndpoint(Vertex *from, Vertex *to); 
     133                        void remapTo(Edge *); 
    133134        }; 
    134135 
     
    137138                Edge *edges[3]; 
    138139 
    139  
    140         public: 
    141         #ifdef SUPPORT_FCOLOR 
     140                public: 
     141#ifdef SUPPORT_FCOLOR 
    142142                FProp *props; 
    143         #endif 
     143#endif 
    144144 
    145145                Face(Edge *, Edge *, Edge *); 
     
    148148                // Basic Face accessors 
    149149                // 
    150                 const Vec3& vertexPos(int i) const { return *edges[i]->org(); } 
    151                 void vertexPos(int, const Vec3&) { 
     150                const Vec3& vertexPos(int i) const{return *edges[i]->org();} 
     151 
     152                void vertexPos(int, const Vec3&) 
     153                { 
    152154                        fatal_error("Face: can't directly set vertex position."); 
    153155                } 
    154156 
    155                 Vertex *vertex(int i) { return edges[i]->org(); } 
    156                 const Vertex *vertex(int i) const { return edges[i]->org(); } 
    157                 Edge *edge(int i)               { return edges[i];        } 
    158  
     157                Vertex *vertex(int i){return edges[i]->org();} 
     158                const Vertex *vertex(int i) const{return edges[i]->org();} 
     159                Edge *edge(int i){return edges[i];} 
    159160 
    160161                // 
     
    173174} 
    174175 
    175  
    176176// NAUTILUS_ADJPRIMS_INCLUDED 
    177177#endif 
     178 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/SimplificationMethod.cpp

    r1025 r1526  
    66using namespace std; 
    77using namespace Geometry; 
     8using   namespace       simplif; 
    89 
    910#include <gfx/geom/ProxGrid.h> 
     
    1314//      Constructor 
    1415//--------------------------------------------------------------------------- 
    15 SimplificationMethod::SimplificationMethod(const Mesh *m)  
     16SimplificationMethod::SimplificationMethod(const Mesh *m) 
    1617{ 
    1718        objmesh                                                 =       m; 
     
    1920        first_index_submesh     =       new unsigned int[objmesh->mSubMeshCount]; 
    2021        indexMeshLeaves                 =       -1; 
     22 
     23        //      Create simplification sequence. 
     24        msimpseq        =       new MeshSimplificationSequence(); 
    2125} 
    2226 
     
    4145        simplif::vert_info& v1_info = vertex_info(v1); 
    4246 
    43         simplif::Mat4 Q = v0_info.Q + v1_info.Q; 
    44         simplif::real norm = v0_info.norm + v1_info.norm; 
     47        simplif::Mat4 Q                 =       v0_info.Q + v1_info.Q; 
     48        simplif::real norm      =       v0_info.norm + v1_info.norm; 
    4549 
    4650        auxpair->cost = simplif::quadrix_pair_target(Q, v0, v1, auxpair->candidate); 
    4751 
    48         if( simplif::will_weight_by_area ) 
     52        if ( simplif::will_weight_by_area ) 
     53        { 
    4954                auxpair->cost /= norm; 
    50  
    51         if( simplif::will_preserve_mesh_quality ) 
     55        } 
     56 
     57        if ( simplif::will_preserve_mesh_quality ) 
     58        { 
    5259                auxpair->cost += pair_mesh_penalty(M0, v0, v1, auxpair->candidate); 
    53  
     60        } 
    5461 
    5562        // 
     
    5764        //          the heap is implemented as a MAX heap. 
    5865        // 
    59         if( auxpair->isInHeap() ) 
     66        if ( auxpair->isInHeap() ) 
    6067        { 
    6168                heap->update(auxpair, (float)-auxpair->cost); 
     
    7077//      Reasign the new vertex to the adequate face 
    7178//--------------------------------------------------------------------------- 
    72 int SimplificationMethod::predict_face(simplif::Face& F, simplif::Vertex *v1, simplif::Vertex *v2, simplif::Vec3& vnew, simplif::Vec3& f1, simplif::Vec3& f2, simplif::Vec3& f3) 
     79int SimplificationMethod::predict_face( simplif::Face& F, 
     80                                                                                                                                                                simplif::Vertex *v1, 
     81                                                                                                                                                                simplif::Vertex *v2, 
     82                                                                                                                                                                simplif::Vec3& vnew, 
     83                                                                                                                                                                simplif::Vec3& f1, 
     84                                                                                                                                                                simplif::Vec3& f2, 
     85                                                                                                                                                                simplif::Vec3& f3) 
    7386{ 
    7487        int nmapped = 0; 
    7588 
    7689        if( F.vertex(0) == v1 || F.vertex(0) == v2 ) 
    77         { f1 = vnew;  nmapped++; } 
    78         else f1 = *F.vertex(0); 
     90        { 
     91                f1 = vnew;  nmapped++; 
     92        } 
     93        else 
     94        { 
     95                f1 = *F.vertex(0); 
     96        } 
    7997 
    8098        if( F.vertex(1) == v1 || F.vertex(1) == v2 ) 
    81         { f2 = vnew;  nmapped++; } 
    82         else f2 = *F.vertex(1); 
     99        { 
     100                f2 = vnew;  nmapped++; 
     101        } 
     102        else 
     103        { 
     104                f2 = *F.vertex(1); 
     105        } 
    83106 
    84107        if( F.vertex(2) == v1 || F.vertex(2) == v2 ) 
    85         { f3 = vnew;  nmapped++; } 
    86         else f3 = *F.vertex(2); 
     108        { 
     109                f3 = vnew;  nmapped++; 
     110        } 
     111        else 
     112        { 
     113                f3 = *F.vertex(2); 
     114        } 
    87115 
    88116        return nmapped; 
     
    93121//--------------------------------------------------------------------------- 
    94122//--------------------------------------------------------------------------- 
    95 simplif::real SimplificationMethod::pair_mesh_penalty(simplif::Model& M, simplif::Vertex *v1, simplif::Vertex *v2, simplif::Vec3& vnew) 
     123simplif::real SimplificationMethod::pair_mesh_penalty(simplif::Model& M, simplif::Vertex *v1, 
     124                                                                                                                                                 simplif::Vertex *v2, 
     125                                                                                                                                                 simplif::Vec3& vnew) 
    96126{ 
    97127        static simplif::face_buffer changed; 
     128 
    98129        changed.reset(); 
    99130 
     
    103134        simplif::real Nmin = 0; 
    104135 
    105         for(int i=0; i<changed.length(); i++) 
     136        for (int i      =       0; i < changed.length(); i++) 
    106137        { 
    107138                simplif::Face& F = *changed(i); 
     
    114145                { 
    115146                        simplif::Plane Pnew(f1, f2, f3); 
     147 
    116148                        simplif::real delta =  Pnew.normal() * F.plane().normal(); 
    117149 
    118                         if( Nmin > delta ) Nmin = delta; 
     150                        if( Nmin > delta ) 
     151                        { 
     152                                Nmin = delta; 
     153                        } 
    119154                } 
    120155        } 
     
    122157        //return (-Nmin) * MESH_INVERSION_PENALTY; 
    123158        if( Nmin < 0.0 ) 
     159        { 
    124160                return MESH_INVERSION_PENALTY; 
     161        } 
    125162        else 
     163        { 
    126164                return 0.0; 
     165        } 
    127166} 
    128167 
     
    130169//      Returns true if the givens vertices are a valid pair 
    131170//--------------------------------------------------------------------------- 
    132 bool SimplificationMethod::check_for_pair(simplif::Vertex *v0, simplif::Vertex *v1) 
     171bool SimplificationMethod::check_for_pair(simplif::Vertex *v0, 
     172                                                                                                                                                                        simplif::Vertex *v1) 
    133173{ 
    134174        const simplif::pair_buffer& pairs = vertex_info(v0).pairs; 
     
    137177        { 
    138178                if( pairs(i)->v0==v1 || pairs(i)->v1==v1 ) 
     179                { 
    139180                        return true; 
     181                } 
    140182        } 
    141183 
     
    146188//      Create a new pair with two given vertices 
    147189//--------------------------------------------------------------------------- 
    148 simplif::pair_info *SimplificationMethod::new_pair(simplif::Vertex *v0, simplif::Vertex *v1) 
     190simplif::pair_info *SimplificationMethod::new_pair(     simplif::Vertex *v0, 
     191                                                                                                                                                                                                                simplif::Vertex *v1) 
    149192{ 
    150193        simplif::vert_info& v0_info = vertex_info(v0); 
     
    152195 
    153196        simplif::pair_info *pair = new simplif::pair_info(v0,v1); 
     197 
    154198        v0_info.pairs.add(pair); 
    155199        v1_info.pairs.add(pair); 
     
    169213        v1_info.pairs.remove(v1_info.pairs.find(auxpair)); 
    170214 
    171         if( auxpair->isInHeap() ) 
     215        if ( auxpair->isInHeap() ) 
     216        { 
    172217                heap->kill(auxpair->getHeapPos()); 
     218        } 
    173219 
    174220        delete auxpair; 
     
    178224//      Contract a given pair 
    179225//--------------------------------------------------------------------------- 
    180 void SimplificationMethod::do_contract(simplif::Model& m, simplif::pair_info *auxpair) 
    181 { 
    182         simplif::Vertex *v0 = auxpair->v0;  simplif::Vertex *v1 = auxpair->v1; 
     226void SimplificationMethod::do_contract( simplif::Model& m, 
     227                                                                                                                                                                simplif::pair_info *auxpair) 
     228{ 
     229        simplif::Vertex *v0                                     = auxpair->v0; 
     230        simplif::Vertex *v1                                     = auxpair->v1; 
    183231        simplif::vert_info& v0_info = vertex_info(v0); 
    184232        simplif::vert_info& v1_info = vertex_info(v1); 
    185         simplif::Vec3 vnew = auxpair->candidate; 
     233        simplif::Vec3 vnew                                      = auxpair->candidate; 
     234 
    186235        int i; 
     236         
     237        // V0 must be always the alive vertex 
     238        // V1 must be always the removed vertex 
     239        if (vnew == (*v0)) 
     240        { 
     241                //      Simplification step. 
     242                simplifstep.mV0 = v0->vID; 
     243                simplifstep.mV1 = v1->vID; 
     244        } 
     245        else 
     246        { 
     247                //      Simplification step. 
     248                simplifstep.mV0 = v1->vID; 
     249                simplifstep.mV1 = v0->vID; 
     250                v0->vID = v1->vID; 
     251        } 
    187252 
    188253        // Make v0 be the new vertex 
    189         v0_info.Q += v1_info.Q; 
    190         v0_info.norm += v1_info.norm; 
     254        v0_info.Q               += v1_info.Q; 
     255        v0_info.norm    += v1_info.norm; 
    191256 
    192257        simplif::Vec3 p(vnew); 
    193         simplif::Vec3 v0antes(v0->operator[](simplif::X),v0->operator[](simplif::Y),v0->operator[](simplif::Z)); 
    194  
    195         // Find the edge to remove (before remove it (contract())) 
    196         simplif::Edge *econ=NULL; 
    197         bool finded = false; 
    198         for (i=0; i<v0->edgeUses().length(); i++) 
    199         {                
    200                 econ = v0->edgeUses()(i); 
    201                 if (v1->vID == econ->org()->vID || v1->vID == econ->dest()->vID) 
    202                 { 
    203                         finded = true; 
    204                         break; 
    205                 } 
    206         } 
    207  
    208         assert(finded); 
    209  
    210  
    211         // Perform the actual contraction 
     258/*      simplif::Vec3 v0antes(v0->operator[](simplif::X), 
     259                                                  v0->operator[](simplif::Y), 
     260                                                  v0->operator[](simplif::Z));*/ 
     261 
     262        //      Perform the actual contraction. 
    212263        static simplif::face_buffer changed; 
     264 
    213265        changed.reset(); 
    214266        m.contract(v0, v1, vnew, changed); 
    215267 
    216         // Stores the simplification step 
    217         MeshSimplificationSequence::Step simplifstep; 
    218         simplif::Vec3 vdesp = p - v0antes; 
    219  
    220         // Stores the displacement in the simplification step 
    221         simplifstep.x=(float)vdesp[simplif::X]; 
    222         simplifstep.y = (float)vdesp[simplif::Y]; 
    223         simplifstep.z = (float)vdesp[simplif::Z]; 
    224          
    225         //      Submeshes which pertains each vertex 
    226         simplifstep.mV1 = v0->validID();  
    227  
    228         //      The simplification method returns as v1 the dead vertex. 
    229         simplifstep.mV0 = v1->validID(); 
     268        std::cout << "Simp seq: " << simplifstep.mV1 << " --> " << simplifstep.mV0 << std::endl; 
     269 
     270/*      simplif::Vec3 vdesp = p - v0antes; 
     271 
     272        //      Stores the displacement in the simplification step. 
     273        simplifstep.x   =       (float)vdesp[X]; 
     274        simplifstep.y = (float)vdesp[Y]; 
     275        simplifstep.z = (float)vdesp[Z];*/ 
     276 
     277        //      Stores the displacement in the simplification step. 
     278        simplifstep.x = (float)0.0f; 
     279        simplifstep.y = (float)0.0f; 
     280        simplifstep.z = (float)0.0f; 
    230281 
    231282        //      Number of triangles that are removed in this simplification step. 
     
    242293        int del_index   =       0; 
    243294 
    244         // mModfaces y mT0, mT1 of simplifstep stores the triangles id's -> geomesh has not triangles id's 
    245         for (i=0; i<changed.length(); i++) 
    246         { 
    247                 simplif::Face *auxface = changed(i); 
     295        //      Clears faces list. 
     296        simplifstep.mModfaces.clear(); 
     297 
     298        //      mModfaces y mT0, mT1 of simplifstep stores  
     299        //      the triangles id's -> geomesh has not triangles id's. 
     300        for (i  =       0;      i < changed.length();   i++) 
     301        { 
     302                simplif::Face *auxface  =       changed(i); 
    248303 
    249304                if (auxface->isValid()) 
    250305                { 
    251                         // Modified triangles 
     306                        //      Modified triangles. 
    252307                        simplifstep.mModfaces.push_back(auxface->validID()); 
    253308                } 
    254309                else 
    255310                { 
    256                         // Removed triangles 
    257                         if (_numDelTris==1)  
    258                         { 
    259                                 simplifstep.mT0=auxface->validID(); 
    260                                 simplifstep.mT1=auxface->validID(); 
     311                        //      Removed triangles. 
     312                        if (_numDelTris == 1) 
     313                        { 
     314                                simplifstep.mT0 =       auxface->validID(); 
     315                                simplifstep.mT1 =       auxface->validID(); 
    261316                        } 
    262317                        else 
    263318                        { 
    264                                 if(del_index==0) 
     319                                if(del_index == 0) 
    265320                                { 
    266                                         simplifstep.mT0=auxface->validID(); 
     321                                        simplifstep.mT0 =       auxface->validID(); 
    267322                                        del_index++; 
    268323                                } 
    269324                                else 
    270325                                { 
    271                                         simplifstep.mT1=auxface->validID(); 
     326                                        simplifstep.mT1 =       auxface->validID(); 
    272327                                } 
    273328                        } 
     
    275330        } 
    276331 
    277         decim_data.push_back(simplifstep); // Simplification sequence that make reference to the simplification method sequence 
     332        //      Simplification sequence that make reference to the  
     333        //      simplification method sequence. 
     334        //decim_data.push_back(simplifstep); 
     335 
     336        //      Adds new simplification step. 
     337        msimpseq->mSteps.push_back(simplifstep); 
    278338 
    279339#ifdef SUPPORT_VCOLOR 
    280         // 
    281         // If the vertices are colored, color the new vertex 
    282         // using the average of the old colors. 
     340        //      If the vertices are colored, color the new vertex 
     341        //      using the average of the old colors. 
    283342        v0->props->color += v1->props->color; 
    284343        v0->props->color /= 2; 
    285344#endif 
    286345 
    287         // Remove the pair that we just contracted 
     346        //      Remove the pair that we just contracted. 
    288347        delete_pair(auxpair); 
    289348 
    290         // Recalculate pairs associated with v0 
    291         for(i=0; i<v0_info.pairs.length(); i++) 
     349        //      Recalculate pairs associated with v0. 
     350        for (i  =       0;      i < v0_info.pairs.length();     i++) 
    292351        { 
    293352                simplif::pair_info *p = v0_info.pairs(i); 
     
    295354        } 
    296355 
    297         // Process pairs associated with now dead vertex 
    298         static simplif::pair_buffer condemned(6); // collect condemned pairs for execution 
     356        //      Process pairs associated with now dead vertex. 
     357        //      Collect condemned pairs for execution. 
     358        static simplif::pair_buffer condemned(6); 
     359 
    299360        condemned.reset(); 
    300361 
    301         for(i=0; i<v1_info.pairs.length(); i++) 
     362        for (i  =       0;      i < v1_info.pairs.length(); i++) 
    302363        { 
    303364                simplif::pair_info *p = v1_info.pairs(i); 
    304365 
    305366                simplif::Vertex *u; 
    306                 if( p->v0 == v1 )       
     367 
     368                if( p->v0 == v1 ) 
     369                { 
    307370                        u = p->v1; 
    308                 else  
    309                         if( p->v1 == v1)   
     371                } 
     372                else 
     373                { 
     374                        if( p->v1 == v1) 
     375                        { 
    310376                                u = p->v0; 
     377                        } 
    311378                        else 
     379                        { 
    312380                                std::cerr << "YOW!  This is a bogus pair." << endl; 
    313  
    314                 if( !check_for_pair(u, v0) ) 
    315                 { 
    316                         p->v0 = v0; 
    317                         p->v1 = u; 
     381                        } 
     382                } 
     383 
     384                if ( !check_for_pair(u, v0) ) 
     385                { 
     386                        p->v0   =       v0; 
     387                        p->v1   =       u; 
     388 
    318389                        v0_info.pairs.add(p); 
    319390                        compute_pair_info(p); 
    320391                } 
    321392                else 
     393                { 
    322394                        condemned.add(p); 
    323         } 
    324  
    325         for(i=0; i<condemned.length(); i++) 
     395                } 
     396        } 
     397 
     398        for (i  =       0;      i < condemned.length(); i++) 
     399        { 
    326400                // Do you have any last requests? 
    327401                delete_pair(condemned(i)); 
    328         v1_info.pairs.reset(); // safety precaution 
    329  
    330 } 
    331  
    332 //--------------------------------------------------------------------------- 
    333 //--------------------------------------------------------------------------- 
    334 bool SimplificationMethod::decimate_quadric(simplif::Vertex *v, simplif::Mat4& Q) 
     402        } 
     403 
     404        //      Safety precaution. 
     405        v1_info.pairs.reset(); 
     406} 
     407 
     408//--------------------------------------------------------------------------- 
     409//--------------------------------------------------------------------------- 
     410bool SimplificationMethod::decimate_quadric(simplif::Vertex *v, 
     411                                                                                                                                                                                simplif::Mat4& Q) 
    335412{ 
    336413        if( vinfo.length() > 0 ) 
     
    340417        } 
    341418        else 
     419        { 
    342420                return false; 
     421        } 
    343422} 
    344423 
     
    347426//--------------------------------------------------------------------------- 
    348427void SimplificationMethod::decimate_contract(simplif::Model& m) 
     428{ 
     429        simplif::heap_node      *top; 
     430        simplif::pair_info      *pair; 
     431        simplif::Vertex         *v0; 
     432        simplif::Vertex         *v1; 
     433        simplif::Vec3           candidate; 
     434 
     435        for (;;) 
     436        { 
     437                top     =       heap->extract(); 
     438                 
     439                if (!top) 
     440                { 
     441                        return; 
     442                } 
     443                 
     444                pair    =       (simplif::pair_info *)top->obj; 
     445 
     446                //      Remove all the vertices of the removed edges. 
     447                bool    sharededge      =       false; 
     448                 
     449                for (int        i       =       0;      i < pair->v0->edgeUses().length();      i++) 
     450                { 
     451                        simplif::Edge   *econ   =       pair->v0->edgeUses()(i); 
     452                         
     453                        if (pair->v1->vID == econ->org()->vID 
     454                                        || 
     455                                        pair->v1->vID == econ->dest()->vID) 
     456                        { 
     457                                sharededge      =       true; 
     458                                break; 
     459                        } 
     460                } 
     461 
     462                if (pair->isValid() && sharededge) 
     463                { 
     464                        break; 
     465                } 
     466 
     467                //      Deletes repetitions of pair in heap. 
     468                delete_pair(pair); 
     469        } 
     470 
     471        //      Copy pair. 
     472        v0      =       new Vertex(     pair->v0->operator[](0), 
     473                                                                                pair->v0->operator[](1), 
     474                                                                                pair->v0->operator[](2)); 
     475        v0->uniqID = pair->v0->uniqID; 
     476         
     477        v1      =       new Vertex(     pair->v1->operator[](0), 
     478                                                                                pair->v1->operator[](1), 
     479                                                                                pair->v1->operator[](2)); 
     480 
     481        v1->uniqID = pair->v1->uniqID; 
     482 
     483        candidate       =       pair->candidate; 
     484 
     485        //      First contract. 
     486        simplifstep.obligatory  =       0; 
     487 
     488        //      Debug. 
     489        cout    <<      "Contracting..."        <<      endl; 
     490 
     491        //      Contract main pair. 
     492        do_contract(m, pair); 
     493 
     494        //      Twin contract and lonely vertex contract. 
     495        simplifstep.obligatory  =       1; 
     496 
     497        //      Attempt to maintain valid vertex information. 
     498        M0.validVertCount--; 
     499 
     500        //      Find an edge of the same coordinates and different vertex identifiers. 
     501        removeTwinEdges(m,v0,v1,candidate); 
     502 
     503        //      Move vertex of non twin edges. 
     504        contractLonelyVertices(m,v0,v1,candidate); 
     505 
     506        //      Free Memory. 
     507        delete  v0; 
     508        delete  v1; 
     509} 
     510 
     511//--------------------------------------------------------------------------- 
     512//      Contract lonely vertex that has the same coords that the contracted one. 
     513//--------------------------------------------------------------------------- 
     514void    SimplificationMethod::contractLonelyVertices(   simplif::Model  &m,     simplif::Vertex *v0, 
     515                                                                                                                                                        simplif::Vertex *v1, 
     516                                                                                                                                                        simplif::Vec3   candidate) 
     517{ 
     518        bool                            lonely_vertex_found; 
     519        simplif::Vertex         *vert; 
     520        simplif::Vertex         *new_vert; 
     521        simplif::Vertex         *lonely_vert; 
     522        simplif::Edge           *edge; 
     523        simplif::heap_node      *top; 
     524        simplif::pair_info      *pair; 
     525        simplif::vert_info      new_vert_info; 
     526        Geometry::GeoVertex     vertex_added; 
     527        simplif::Vertex         *take_bone_from_vert; 
     528 
     529        //      Gets the vertex that is not the candidate. 
     530        if ((*v0) == candidate) 
     531        { 
     532                vert = v1; 
     533                take_bone_from_vert = v0; 
     534        } 
     535        else if ((*v1) == candidate) 
     536        { 
     537                vert = v0; 
     538                take_bone_from_vert = v1; 
     539        } 
     540 
     541        //      For all vertex. 
     542        for (int        i = 0; i < heap->getSize();     i++) 
     543        { 
     544                //      Initialize lonely vertex flag. 
     545                lonely_vertex_found     =       false; 
     546 
     547                //      Gets the current pair. 
     548                top             =       heap->getElement(i); 
     549                pair    =       (simplif::pair_info *)top->obj; 
     550 
     551                if (pair->v0->isValid() && (*vert) == (*pair->v0)) 
     552                { 
     553                        lonely_vert     =       pair->v0; 
     554                        lonely_vertex_found     =       true; 
     555                } 
     556                else if (pair->v1->isValid() && (*vert) == (*pair->v1)) 
     557                { 
     558                        lonely_vert     =       pair->v1; 
     559                        lonely_vertex_found     =       true; 
     560                } 
     561 
     562                //      If a lonely vertex is found. Creates new vertex and contract. 
     563                if (lonely_vertex_found) 
     564                { 
     565                        new_vert        =       m.newVertex(candidate[X],candidate[Y],candidate[Z]);     
     566                        edge            =       m.newEdge(new_vert,lonely_vert); 
     567 
     568            // We assume here the there are the same number of vertices and texture coordinates and normals 
     569 
     570                        // assign a texture coordinate for the vbertex 
     571                        simplif::Vec2 newtexcoord = m.texcoord(lonely_vert->validID()); 
     572                        m.in_TexCoord(newtexcoord); 
     573 
     574                        // assign a normal coordinate for the vbertex 
     575                        simplif::Vec3 newnormal = m.normal(lonely_vert->validID()); 
     576                        m.in_Normal(newnormal); 
     577 
     578                        //      Adds new vertex information to simplification sequence. 
     579                        vertex_added.id                 =       new_vert->vID; 
     580                        vertex_added.bonefrom   =       take_bone_from_vert->vID; 
     581                        vertex_added.position   =       Vector3(candidate[X],candidate[Y],candidate[Z]); 
     582 
     583                        simplif::Vec2 tc = m.texcoord(new_vert->validID()); 
     584                        vertex_added.texcoord   =       Vector2(tc[X],tc[Y]); 
     585 
     586                        simplif::Vec3 vn = m.normal(new_vert->validID()); 
     587                        vertex_added.normal             =       Vector3(vn[X],vn[Y],vn[Z]); 
     588 
     589                        msimpseq->mNewVertices.push_back(vertex_added); 
     590 
     591                        pair                    =       new_pair(new_vert,lonely_vert); 
     592                        pair->candidate =       candidate; 
     593 
     594                        pair->notInHeap(); 
     595/*                      vinfo(new_vert->validID()).Q            =       vinfo(lonely_vert->validID()).Q; 
     596                        vinfo(new_vert->validID()).norm =       vinfo(lonely_vert->validID()).norm;*/ 
     597 
     598                        //      Debug. 
     599                        cout    <<      "Contracting new pair..."       <<      endl; 
     600 
     601                        //      Contract twin pair. 
     602                        do_contract(m, pair); 
     603                        M0.validVertCount--; 
     604                } 
     605        } 
     606} 
     607 
     608//--------------------------------------------------------------------------- 
     609//      Find a twin edge of the given one. 
     610//--------------------------------------------------------------------------- 
     611void SimplificationMethod::removeTwinEdges(     simplif::Model  &m, 
     612                                                                                                                                                                                simplif::Vertex *v0, 
     613                                                                                                                                                                                simplif::Vertex *v1, 
     614                                                                                                                                                                                simplif::Vec3           candidate) 
     615{ 
     616        bool                                                            twin_found; 
     617        simplif::heap_node      *top; 
     618        simplif::pair_info      *pair; 
     619        simplif::Vertex                 *aux_vert; 
     620 
     621        //      Find a twin edge in heap. 
     622        for (int        i       =       0;      i < heap->getSize(); i++) 
     623        { 
     624                //      Initialize twin flag. 
     625                twin_found      =       false; 
     626 
     627                //      Gets the current pair. 
     628                top             =       heap->getElement(i); 
     629                pair    =       (simplif::pair_info *)top->obj; 
     630 
     631                if (pair->v0->isValid()==false || pair->v1->isValid()==false) 
     632                        continue;  
     633 
     634                if (v0->operator[](0) == pair->v0->operator[](0) 
     635                                && 
     636                                v0->operator[](1) == pair->v0->operator[](1) 
     637                                && 
     638                                v0->operator[](2) == pair->v0->operator[](2)) 
     639                { 
     640                        if (v1->operator[](0) == pair->v1->operator[](0) 
     641                                        && 
     642                                        v1->operator[](1) == pair->v1->operator[](1) 
     643                                        && 
     644                                        v1->operator[](2) == pair->v1->operator[](2)) 
     645                        { 
     646                                //      Debug. 
     647                                cout    <<      "Twin contracted (NO Swap)..."  <<      endl; 
     648 
     649                                //      Active twin flag. 
     650                                twin_found      = true; 
     651                        } 
     652                } 
     653                else 
     654                { 
     655                        //      If there is a twin edge in reverse order. 
     656                        if (v0->operator[](0) == pair->v1->operator[](0) 
     657                                        && 
     658                                        v0->operator[](1) == pair->v1->operator[](1) 
     659                                        && 
     660                                        v0->operator[](2) == pair->v1->operator[](2)) 
     661                        { 
     662                                if (v1->operator[](0) == pair->v0->operator[](0) 
     663                                                && 
     664                                                v1->operator[](1) == pair->v0->operator[](1) 
     665                                                && 
     666                                                v1->operator[](2) == pair->v0->operator[](2)) 
     667                                { 
     668                                        //      Debug. 
     669                                        cout    <<      "Twin contracted (Swap)..."     <<      endl; 
     670 
     671                                        //      Swap. 
     672                                        aux_vert        =       pair->v0; 
     673                                        pair->v0        =       pair->v1; 
     674                                        pair->v1        =       aux_vert; 
     675 
     676                                        //      Active twin flag. 
     677                                        twin_found      =       true; 
     678                                } 
     679                        } 
     680                } 
     681 
     682                //      If a twin edge has been found. 
     683                if (twin_found) 
     684                { 
     685                        //      Extract twin edge from heap. 
     686                        top             =       heap->extract(i); 
     687                        pair    =       (simplif::pair_info *)top->obj; 
     688 
     689                        //      Copy candidate. 
     690                        pair->candidate =       candidate; 
     691 
     692                        //      Contract twin pair. 
     693                        do_contract(m, pair); 
     694                        i--; 
     695                        M0.validVertCount--; 
     696                } 
     697        } 
     698} 
     699 
     700//--------------------------------------------------------------------------- 
     701//--------------------------------------------------------------------------- 
     702simplif::real SimplificationMethod::decimate_error(simplif::Vertex *v) 
     703{ 
     704        simplif::vert_info& info = vertex_info(v); 
     705 
     706        simplif::real err = simplif::quadrix_evaluate_vertex(*v, info.Q); 
     707 
     708    if( simplif::will_weight_by_area ) 
     709                { 
     710                        err /= info.norm; 
     711                } 
     712 
     713    return err; 
     714} 
     715 
     716//--------------------------------------------------------------------------- 
     717//      Extract the minimum cost of the the valid nodes (not simplified) 
     718//--------------------------------------------------------------------------- 
     719simplif::real SimplificationMethod::decimate_min_error() 
    349720{ 
    350721        simplif::heap_node *top; 
     
    353724        for(;;) 
    354725        { 
    355                 top = heap->extract(); 
    356                 if( !top ) return; 
     726                top = heap->top(); 
     727                 
     728                if( !top ) 
     729                { 
     730                        return -1.0; 
     731                } 
     732 
    357733                pair = (simplif::pair_info *)top->obj; 
    358734 
    359                 //Remove all the vertices of the removed edges 
    360                 bool sharededge= false; 
    361                 for (int i=0; i<pair->v0->edgeUses().length(); i++) 
    362                 {                
    363                         simplif::Edge *econ = pair->v0->edgeUses()(i); 
    364                         if (pair->v1->vID == econ->org()->vID || pair->v1->vID == econ->dest()->vID) 
    365                         { 
    366                                 sharededge= true; 
    367                                 break; 
    368                         } 
    369  
    370                 } 
    371  
    372                 if( pair->isValid() && sharededge) 
     735                if( pair->isValid() ) 
     736                { 
    373737                        break; 
    374  
    375                 delete_pair(pair); 
    376         } 
    377  
    378         do_contract(m, pair); 
    379  
    380         M0.validVertCount--;  // Attempt to maintain valid vertex information 
    381 } 
    382  
    383 //--------------------------------------------------------------------------- 
    384 //--------------------------------------------------------------------------- 
    385 simplif::real SimplificationMethod::decimate_error(simplif::Vertex *v) 
    386 { 
    387         simplif::vert_info& info = vertex_info(v); 
    388  
    389         simplif::real err = simplif::quadrix_evaluate_vertex(*v, info.Q); 
    390  
    391     if( simplif::will_weight_by_area ) 
    392                 err /= info.norm; 
    393  
    394     return err; 
    395 } 
    396  
    397 //--------------------------------------------------------------------------- 
    398 //      Extract the minimum cost of the the valid nodes (not simplified) 
    399 //--------------------------------------------------------------------------- 
    400 simplif::real SimplificationMethod::decimate_min_error() 
    401 { 
    402         simplif::heap_node *top; 
    403         simplif::pair_info *pair; 
    404  
    405         for(;;) 
    406         { 
    407                 top = heap->top(); 
    408                 if( !top ) return -1.0; 
    409                 pair = (simplif::pair_info *)top->obj; 
    410  
    411                 if( pair->isValid() ) 
    412                         break; 
     738                } 
    413739 
    414740                top = heap->extract(); 
     
    442768        int i,j; 
    443769 
    444         vinfo.init(m.vertCount()); 
    445  
    446         if( simplif::will_use_vertex_constraint ) 
    447                 for(i=0; i<m.vertCount(); i++) 
    448                 { 
    449                         simplif::Vertex *v = m.vertex(i); 
    450                         if( v->isValid() ) 
     770        //      Reserve memory for vert_info array. 
     771        vinfo.init(m.vertCount()*10); 
     772 
     773        if (simplif::will_use_vertex_constraint) 
     774        { 
     775                //      For each vertex, calculate contraints. 
     776                for     (i      =       0;      i < m.vertCount();      i++) 
     777                { 
     778                        simplif::Vertex *v      =       m.vertex(i); 
     779                         
     780                        if (v->isValid()) 
     781                        { 
    451782                                vertex_info(v).Q = simplif::quadrix_vertex_constraint(*v); 
    452                 } 
    453  
    454         for(i=0; i<m.faceCount(); i++) 
    455                 if( m.face(i)->isValid() ) 
    456                 { 
    457                         if( simplif::will_use_plane_constraint ) 
     783                        } 
     784                } 
     785        } 
     786 
     787        //      Sets the fill value of the vinfo buffer. 
     788        //vinfo.setFill(m.vertCount()); 
     789 
     790        //      For each face, recalculate constraints. 
     791        for (i  =       0;      i < m.faceCount();      i++) 
     792        { 
     793                if (m.face(i)->isValid()) 
     794                { 
     795                        if (simplif::will_use_plane_constraint) 
    458796                        { 
    459797                                simplif::Mat4 Q = simplif::quadrix_plane_constraint(*m.face(i)); 
    460798                                simplif::real norm = 0.0; 
    461799 
    462                                 if( simplif::will_weight_by_area ) 
     800                                if (simplif::will_weight_by_area) 
    463801                                { 
    464                                         norm = m.face(i)->area(); 
    465                                         Q *= norm; 
     802                                        norm    =               m.face(i)->area(); 
     803                                        Q                       *=      norm; 
    466804                                } 
    467805 
    468                                 for(j=0; j<3; j++) 
     806                                for (j  =       0;      j < 3;  j++) 
    469807                                { 
    470                                         vertex_info(m.face(i)->vertex(j)).Q += Q; 
    471                                         vertex_info(m.face(i)->vertex(j)).norm += norm; 
    472  
     808                                        vertex_info(m.face(i)->vertex(j)).Q                     +=      Q; 
     809                                        vertex_info(m.face(i)->vertex(j)).norm  +=      norm; 
    473810                                } 
    474811                        } 
    475812                } 
    476  
    477         if( simplif::will_constrain_boundaries ) 
    478         { 
    479                 for(i=0; i<m.edgeCount(); i++) 
    480                         if( m.edge(i)->isValid() && simplif::check_for_discontinuity(m.edge(i)) ) 
     813        } 
     814 
     815        if (simplif::will_constrain_boundaries) 
     816        { 
     817                //      For each edge, recalculate constraints. 
     818                for (i  =       0;      i < m.edgeCount();      i++) 
     819                { 
     820                        if (m.edge(i)->isValid() && simplif::check_for_discontinuity(m.edge(i))) 
    481821                        { 
    482822                                simplif::Mat4 B = simplif::quadrix_discontinuity_constraint(m.edge(i)); 
    483823                                simplif::real norm = 0.0; 
    484824 
    485                                 if( simplif::will_weight_by_area ) 
     825                                if (simplif::will_weight_by_area) 
    486826                                { 
    487                                         norm = simplif::norm2(*m.edge(i)->org() - *m.edge(i)->dest()); 
    488                                         B *= norm; 
     827                                        norm    =               simplif::norm2(*m.edge(i)->org() - *m.edge(i)->dest()); 
     828                                        B                       *=      norm; 
    489829                                } 
    490830 
     
    495835                                vertex_info(m.edge(i)->dest()).norm += norm; 
    496836                        } 
    497         } 
    498  
     837                } 
     838        } 
     839 
     840        //      Create heap. 
    499841        heap = new simplif::Heap(m.validEdgeCount); 
    500842 
    501843        int pair_count = 0; 
    502844 
    503         for(i=0; i<m.edgeCount(); i++) 
    504                 if( m.edge(i)->isValid() ) 
     845        //      For each edge, add pairs to heap. 
     846        for (i  =       0;      i < m.edgeCount();      i++) 
     847        { 
     848                if (m.edge(i)->isValid()) 
    505849                { 
    506850                        simplif::pair_info *pair = new_pair(m.edge(i)->org(), m.edge(i)->dest()); 
     
    509853                        pair_count++; 
    510854                } 
    511  
    512         if( limit<0 ) 
    513         { 
    514                 limit = m.bounds.radius * 0.05; 
    515         } 
    516         proximity_limit = limit * limit; 
    517         if( proximity_limit > 0 ) 
     855        } 
     856 
     857        if (limit < 0) 
     858        { 
     859                limit   =       m.bounds.radius * 0.05; 
     860        } 
     861         
     862        proximity_limit =       limit * limit; 
     863         
     864        if (proximity_limit > 0) 
    518865        { 
    519866                simplif::ProxGrid grid(m.bounds.min, m.bounds.max, limit); 
    520                 for(i=0; i<m.vertCount(); i++) 
     867                 
     868                //      Add points to grid. 
     869                for (i  =       0;      i < m.vertCount();      i++) 
     870                { 
    521871                        grid.addPoint(m.vertex(i)); 
     872                } 
    522873 
    523874                simplif::buffer<simplif::Vec3 *> nearby(32); 
    524                 for(i=0; i<m.vertCount(); i++) 
     875                 
     876                //      For each vertex. 
     877                for (i  =       0;      i < m.vertCount();      i++) 
    525878                { 
    526879                        nearby.reset(); 
    527880                        grid.proximalPoints(m.vertex(i), nearby); 
    528881 
    529                         for(j=0; j<nearby.length(); j++) 
     882                        for (j  =       0;      j < nearby.length();    j++) 
    530883                        { 
    531884                                simplif::Vertex *v1 = m.vertex(i); 
    532885                                simplif::Vertex *v2 = (simplif::Vertex *)nearby(j); 
    533886 
    534                                 if( v1->isValid() && v2->isValid() ) 
     887                                if (v1->isValid() && v2->isValid()) 
    535888                                { 
    536889#ifdef SAFETY 
    537890                                        assert(pair_is_valid(v1,v2)); 
    538891#endif 
    539                                         if( !check_for_pair(v1,v2) ) 
     892                                        if (!check_for_pair(v1,v2)) 
    540893                                        { 
    541894                                                simplif::pair_info *pair = new_pair(v1,v2); 
     
    544897                                        } 
    545898                                } 
    546  
    547899                        } 
    548900                } 
     
    555907void SimplificationMethod::simplifmethod_init(void) 
    556908{ 
    557         int i; 
    558  
    559909        // Change mesh structure. 
    560         geomesh2simplifModel(); 
    561  
     910        generateSimplifModel(); 
     911                 
    562912        M0.bounds.complete(); 
    563913 
     
    566916        initialFaceCount = M0.faceCount(); 
    567917 
    568         // Get rid of degenerate faces 
    569         for(i=0; i<M0.faceCount(); i++) 
    570                 if( !M0.face(i)->plane().isValid() ) 
     918        // Get rid of degenerate faces. 
     919        for (int        i       =       0;      i < M0.faceCount();     i++) 
     920        { 
     921                if (!M0.face(i)->plane().isValid()) 
     922                { 
    571923                        M0.killFace(M0.face(i)); 
     924                } 
     925        } 
    572926 
    573927        M0.removeDegeneracy(M0.allFaces()); 
    574928 
    575         // Get rid of unused vertices 
    576         for(i=0; i<M0.vertCount(); i++) 
    577         { 
    578                 if( M0.vertex(i)->edgeUses().length() == 0 ) 
     929        // Get rid of unused vertices. 
     930        for (int        i       =       0;      i < M0.vertCount();     i++) 
     931        { 
     932                if (M0.vertex(i)->edgeUses().length() == 0) 
     933                { 
    579934                        M0.vertex(i)->kill(); 
     935                } 
    580936        } 
    581937} 
     
    598954        } 
    599955 
    600         for (std::vector<MeshSimplificationSequence::Step>::iterator it= decim_data.begin(); it!=decim_data.end(); it++) 
     956        /* 
     957        for (   std::vector<MeshSimplificationSequence::Step>::iterator 
     958                                it      =       decim_data.begin(); 
     959                                it != decim_data.end(); 
     960                                it++) 
    601961        { 
    602962                it->mModfaces.clear(); 
    603963        } 
     964         
    604965        decim_data.clear(); 
    605  
    606         while( M0.validFaceCount > finalfaces/*simplif::face_target*/ 
    607                         && M0.validFaceCount > 1 
    608                         && decimate_min_error() < simplif::error_tolerance )  
     966        */ 
     967 
     968        //      Debug. 
     969        cout    <<      "M0.validFaceCount: "   <<      M0.validFaceCount       <<      endl; 
     970        cout    <<      "finalfaces: "                          <<      finalfaces                              <<      endl; 
     971         
     972        while ( M0.validFaceCount > finalfaces/*simplif::face_target*/ 
     973                                        && M0.validFaceCount > 1 
     974                                        && decimate_min_error() < simplif::error_tolerance ) 
    609975        { 
    610976                decimate_contract(M0); 
     
    6361002        previousValidVertCount  =       0; 
    6371003 
    638         percent =       (float)(2.0 * 100.0) /(float)((M0.validFaceCount - numvertices / 3.0)); 
     1004        percent =       (float)(2.0 * 100.0) 
     1005                                                / 
     1006                                                (float)((M0.validFaceCount - numvertices / 3.0)); 
    6391007 
    6401008        //      Update progress bar. 
     
    6441012        } 
    6451013 
    646         for (std::vector<MeshSimplificationSequence::Step>::iterator it= decim_data.begin(); it!=decim_data.end(); it++) 
     1014        /* 
     1015        for (   std::vector<MeshSimplificationSequence::Step>::iterator 
     1016                                it      =       decim_data.begin(); 
     1017                                it != decim_data.end(); 
     1018                                it++) 
    6471019        { 
    6481020                it->mModfaces.clear(); 
    6491021        } 
     1022         
    6501023        decim_data.clear(); 
     1024        */ 
     1025 
     1026        //      Debug. 
     1027        cout    <<      "M0.validVertCount:     "       <<      M0.validVertCount       <<      endl; 
     1028        cout    <<      "numvertices:   "       <<      numvertices     <<      endl; 
    6511029 
    6521030        while(  M0.validVertCount > numvertices /*simplif::face_target*/ 
     
    6801058{ 
    6811059        public: 
     1060 
    6821061                float x,y,z; 
    683                 _float3_(float x=0.0f, float y=0.0f, float z=0.0f){ this->x = x; this->y = y; this->z = z; } 
    684                 _float3_(const _float3_ &f){ x=f.x; y=f.y; z=f.z; } 
    685                 _float3_ & operator=(const _float3_ &f){ x=f.x; y=f.y; z=f.z; return *this; } 
     1062 
     1063                _float3_(float x=0.0f, float y=0.0f, float z=0.0f) 
     1064                { 
     1065                        this->x = x; this->y = y; this->z = z; 
     1066                } 
     1067 
     1068                _float3_(const _float3_ &f) 
     1069                { 
     1070                        x=f.x; y=f.y; z=f.z; 
     1071                } 
     1072 
     1073                _float3_ & operator=(const _float3_ &f) 
     1074                { 
     1075                        x=f.x; y=f.y; z=f.z; return *this; 
     1076                } 
     1077 
    6861078                bool operator<(const _float3_ &f) const  
    6871079                {  
     
    6961088}; 
    6971089 
    698  
    699 //--------------------------------------------------------------------------- 
    700 //Unify the model to work with it 
    701 //The vertices that have the same space coordinates are stored as an unique vertex 
    702 //in order to avoid holes in the simplification 
    703 //The necessary information to store correctly the decimation data is stored 
    704 //--------------------------------------------------------------------------- 
    705 void SimplificationMethod::geomesh2simplifModel(void) 
    706 { 
    707         std::map<_float3_,int> vertices_map; //Unique vertices (without repetitions) from all the submeshes 
    708         unsigned int num_final_verts = 0; //Number of unique vertices from all the submeshes 
    709  
    710         int num_final_verts2=0; 
    711         int num_repeated_verts=0; 
    712  
    713         int simplifindex; 
    714         for (size_t i=0; i<objmesh->mSubMeshCount; i++) //For all the submeshes 
    715         { 
    716                 if (i   !=      indexMeshLeaves) 
    717                 { 
    718                         //If the model has texture information 
    719                         if (objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS)  
    720                         { 
    721                                 //For all the vertices of each submesh 
    722                                 for (size_t j=0; j<objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; j++)  
    723                                 { 
    724                                         _float3_ auxvert(objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x,  
     1090//--------------------------------------------------------------------------- 
     1091//      Generate simplification model. 
     1092//--------------------------------------------------------------------------- 
     1093void    SimplificationMethod::generateSimplifModel(void) 
     1094{ 
     1095        int     face_index      =       0; 
     1096 
     1097        //      For each submesh. 
     1098        bool added_vertices = false; 
     1099        for (size_t     i =     0;      i       <       objmesh->mSubMeshCount; i++) 
     1100        { 
     1101                //      If is not a tree leaves submesh. 
     1102                if (i != indexMeshLeaves) 
     1103                { 
     1104                        //      For all the vertices of each submesh. 
     1105                        for (   size_t  j       =       0; 
     1106                                        j < objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; 
     1107                                        j++) 
     1108                        { 
     1109                                //      If the vertex is not in vertices_map, then is added. 
     1110                                M0.in_Vertex(simplif::Vec3( 
     1111                                                        objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x, 
    7251112                                                        objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 
    726                                                         objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z); 
    727  
    728                                         std::map<_float3_,int>::iterator mit = vertices_map.find(auxvert); 
    729                                         if (mit==vertices_map.end()) 
    730                                         { 
    731                                                 //If the vertex is not in vertices_map, then is added 
    732                                                 simplifindex=M0.in_Vertex(simplif::Vec3(objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x,  
    733                                                                         objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 
    734                                                                         objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z)); 
    735                                                 M0.in_Normal(simplif::Vec3(objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].x,  
    736                                                                         objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].y, 
    737                                                                         objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].z)); 
    738  
    739                                                 M0.in_TexCoord(simplif::Vec2(objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x,  
    740                                                                         objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y)); 
    741                                                 vertices_map[auxvert] = num_final_verts; 
    742                                                 num_final_verts ++; 
    743  
    744                                                 std::vector<int> v; 
    745                                                 submeshmap[simplifindex]=v; 
    746                                                 submeshmap[simplifindex].push_back((int)i); //Add the index of the mesh that contains the vertex 
    747                                                 std::vector<int> v2; 
    748                                                 vertexbuffermap[simplifindex]=v2; 
    749                                                 vertexbuffermap[simplifindex].push_back((int)j); //Add the index of vertex in the submesh 
    750  
    751                                                 // Debug 
    752                                                 num_final_verts2++; 
    753                                         } 
    754                                         else 
    755                                         { 
    756                                                 //the vertex is already in vertices_map, so store the reference of the first one with the same space coodinates 
    757                                                 simplifindex = mit->second; 
    758                                                 submeshmap[simplifindex].push_back((int)i); //Submeshes that contains the vertex 
    759                                                 vertexbuffermap[simplifindex].push_back((int)j); //Indices of the vertex buffers that contains the vertex 
    760  
    761                                                 // Debug 
    762                                                 num_repeated_verts++; 
    763                                         }        
    764                                 } 
    765                         } 
    766                         else //the model has not texture information 
    767                         {  
    768                                 //For all the vertices of each submesh 
    769                                 for (size_t j=0; j<objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; j++)  
    770                                 { 
    771                                         _float3_ auxvert(objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x,  
    772                                                         objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 
    773                                                         objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z); 
    774  
    775                                         std::map<_float3_,int>::iterator mit = vertices_map.find(auxvert); 
    776                                         if (mit==vertices_map.end()) 
    777                                         { 
    778                                                 //If the vertex is not in vertices_map, then is added 
    779                                                 simplifindex=M0.in_Vertex(simplif::Vec3(objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x,  
    780                                                                         objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 
    781                                                                         objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z)); 
    782                                                 M0.in_Normal(simplif::Vec3(objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].x,  
    783                                                                         objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].y, 
    784                                                                         objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].z)); 
    785                                                 M0.in_TexCoord(simplif::Vec2(0.0,0.0)); 
    786                                                 vertices_map[auxvert] = num_final_verts; 
    787                                                 num_final_verts ++; 
    788  
    789                                                 std::vector<int> v; 
    790                                                 submeshmap[simplifindex]=v; 
    791                                                 submeshmap[simplifindex].push_back((int)i); //Add the index of the mesh that contains the vertex 
    792                                                 std::vector<int> v2; 
    793                                                 vertexbuffermap[simplifindex]=v2; 
    794                                                 vertexbuffermap[simplifindex].push_back((int)j); //Add the index of vertex in the submesh 
    795                                         } 
    796                                         else 
    797                                         { 
    798                                                 //the vertex is already in vertices_map, so store the reference of the first one with the same space coodinates 
    799                                                 simplifindex = mit->second; 
    800                                                 submeshmap[simplifindex].push_back((int)i); //Submeshes that contains the vertex 
    801                                                 vertexbuffermap[simplifindex].push_back((int)j); //Indices of the vertex buffers that contains the vertex 
    802                                         }        
    803                                 } 
    804                         } 
    805                         if (objmesh->mSubMesh[i].mSharedVertexBuffer) 
    806                         { 
    807                                 printf("Shared break"); 
    808                                 break; 
    809                         } 
    810                 } 
    811         } 
    812  
    813         //Create the faces 
    814         unsigned int base_index=0; 
    815  
    816         number_of_triangles=0; //Number of triangles of the model 
    817         int face_index=0; 
    818  
    819         int index_in_vertices_map0,index_in_vertices_map1,index_in_vertices_map2; 
    820         for (size_t i=0; i<objmesh->mSubMeshCount; i++) //For all the submeshes 
    821         {  
    822                 if (i!=indexMeshLeaves) 
    823                 { 
    824                         for (Index j=0; j<objmesh->mSubMesh[i].mIndexCount; j+=3)  
    825                         { 
    826                                 //+1 is required because the first index in the simplification method is 1 
    827                                 //Index of the vertex in vertices_map 
    828                                 Index indice0=objmesh->mSubMesh[i].mIndex[j]; 
    829                                 _float3_ auxvert0(objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice0].x,  
    830                                                 objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice0].y, 
    831                                                 objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice0].z); 
    832                                 index_in_vertices_map0=vertices_map[auxvert0] + 1; 
    833  
    834                                 Index indice1=objmesh->mSubMesh[i].mIndex[j+1]; 
    835                                 _float3_ auxvert1(objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice1].x,  
    836                                                 objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice1].y, 
    837                                                 objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice1].z); 
    838                                 index_in_vertices_map1=vertices_map[auxvert1] + 1; 
    839  
    840                                 Index indice2=objmesh->mSubMesh[i].mIndex[j+2]; 
    841                                 _float3_ auxvert2(objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice2].x,  
    842                                                 objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice2].y, 
    843                                                 objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice2].z); 
    844                                 index_in_vertices_map2=vertices_map[auxvert2] + 1; 
    845  
    846                                 //Create a triangle with its indices in vertices_map 
    847                                 face_index=M0.miin_Face(index_in_vertices_map0,index_in_vertices_map1,index_in_vertices_map2); 
    848  
    849                                 //igeo allows to identify the submesh that contains the triangle 
    850                                 M0.face(face_index)->igeo=(int)i; 
    851                         } 
    852                 } 
    853         } 
    854         number_of_triangles=face_index; 
    855 } 
    856  
    857  
    858 //--------------------------------------------------------------------------- 
    859 //Wrties a file with the vertices, triangles and the simplification sequence 
    860 //--------------------------------------------------------------------------- 
    861 void SimplificationMethod::WriteOBJ(void) 
    862 { 
    863         MeshSimplificationSequence::Step stepaux; 
    864         vector<int> v0,v1,submesh0,submesh1; 
    865         std::ofstream obj("salida.lod"); 
    866         obj << "begin" << std::endl; 
    867         //vertices 
    868         for (size_t i=0; i<objmesh->mSubMeshCount; i++)  
    869         { 
    870                 for (size_t j=0; j<objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; j++)  
    871                 {        
    872                         obj << "v " <<  objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x << " " << 
    873                                 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y << " " << 
    874                                 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z << " " << std::endl; 
    875                 } 
    876         } 
    877  
    878  
    879         //faces 
    880         for (size_t i=0; i<objmesh->mSubMeshCount; i++)  
    881         { 
    882                 for (size_t j=0; j<objmesh->mSubMesh[i].mIndexCount; j=j+3)  
    883                 {        
    884                         obj << "f " <<  objmesh->mSubMesh[i].mIndex[j]+1 << " " <<  
    885                                 objmesh->mSubMesh[i].mIndex[j+1]+1 << " " <<  
    886                                 objmesh->mSubMesh[i].mIndex[j+2]+1 << std::endl; 
    887                 } 
    888         } 
    889  
    890         obj << "end" << std::endl; 
    891  
    892         for (unsigned i=0; i<decim_data.size(); i++)  
    893         { 
    894                 stepaux = decim_data.operator [](i); 
    895                 v0=vertexbuffermap[stepaux.mV0];  //vertexbuffer index 
    896                 submesh0=submeshmap[stepaux.mV0]; //displacement for each submesh 
    897                 v1=vertexbuffermap[stepaux.mV1]; 
    898                 submesh1=submeshmap[stepaux.mV1]; 
    899                 for (unsigned j=0; j<v0.size(); j++) 
    900                 { 
    901                         for (unsigned k=0; k<v1.size(); k++)  
    902                         { 
    903                                 //obtain the index of the VertexBuffer of each submesh and the displacemente by submesh 
    904                                 obj << "v% " << v1.operator [](k)+first_index_submesh[submesh1.operator [](k)] <<  
    905                                         " " << v0.operator [](j)+first_index_submesh[submesh0.operator [](j)] << " " <<  
    906                                         stepaux.x << " " << stepaux.y << " " << stepaux.z << " " << stepaux.mT0 << " " << 
    907                                         stepaux.mT1 << " & "; 
    908                                 if (stepaux.mModfaces.size()>0)  
    909                                 { 
    910                                         unsigned int ii=0; 
    911                                         for (ii=0; ii<stepaux.mModfaces.size()-1; ii++)  
    912                                         { 
    913                                                 obj << stepaux.mModfaces.operator [](ii) << " "; 
    914                                         } 
    915                                         obj << stepaux.mModfaces.operator [](ii) << std::endl; 
    916                                 } 
    917                                 else  
    918                                 {  
    919                                         obj << std::endl;  
    920                                 }                                        
    921                         } 
    922                 } 
    923         } 
    924         obj.close(); 
    925 } 
    926  
    927 //--------------------------------------------------------------------------- 
    928 //simplifmethod_init is executed to do some initalizations 
    929 //simplifmethod_run is executed to do the decimation 
    930 //Then, the simpified model is created and the decimation information is returned 
     1113                                                        objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z)); 
     1114 
     1115                                M0.in_Normal(simplif::Vec3( 
     1116                                                        objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].x, 
     1117                                                        objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].y, 
     1118                                                        objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].z)); 
     1119 
     1120                                M0.in_TexCoord(simplif::Vec2( 
     1121                                                        objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x, 
     1122                                                        objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y)); 
     1123 
     1124                                added_vertices = true; 
     1125                        } 
     1126                }        
     1127                 
     1128                //      If is shared vertex buffer object. 
     1129                if (objmesh->mSubMesh[i].mSharedVertexBuffer && added_vertices) 
     1130                { 
     1131                        printf("Shared break"); 
     1132                        break; 
     1133                } 
     1134        } 
     1135 
     1136        //      For each submesh. 
     1137        for (size_t     i = 0;  i < objmesh->mSubMeshCount;     i++) 
     1138        { 
     1139                if (i != indexMeshLeaves) 
     1140                { 
     1141                        for (Index      j       =       0;      j < objmesh->mSubMesh[i].mIndexCount;   j       +=      3) 
     1142                        { 
     1143                                //      +1 is required because the first index in the 
     1144                                //      simplification method is 1 
     1145                                //      Index of the vertex in vertices_map. 
     1146                                Index index0    =               objmesh->mSubMesh[i].mIndex[j]; 
     1147                                 
     1148                                Index index1    =               objmesh->mSubMesh[i].mIndex[j + 1]; 
     1149                                 
     1150                                Index index2    =               objmesh->mSubMesh[i].mIndex[j + 2]; 
     1151                                 
     1152                                //      Create a triangle with its indices in vertices_map. 
     1153                                face_index      =       M0.miin_Face( 
     1154                                                index0, 
     1155                                                index1, 
     1156                                                index2); 
     1157 
     1158                                //      igeo allows to identify the submesh that contains the triangle. 
     1159                                M0.face(face_index)->igeo       =       (int)i; 
     1160                        } 
     1161                } 
     1162        } 
     1163        number_of_triangles     =       face_index; 
     1164} 
     1165 
     1166//--------------------------------------------------------------------------- 
     1167//      simplifmethod_init is executed to do some initalizations 
     1168//      simplifmethod_run is executed to do the decimation 
     1169//      Then, the simpified model is created and the decimation  
     1170//      information is returned. 
    9311171//--------------------------------------------------------------------------- 
    9321172MeshSimplificationSequence *SimplificationMethod::Decimate(     float lod, 
     
    9381178        if (simpliftype == 0) 
    9391179        { 
    940                 //Percentage option 
     1180                //      Percentage option. 
    9411181                simplifmethod_run((int)(number_of_triangles*lod),upb); 
    9421182        } 
    9431183        else 
    9441184        { 
    945                 //Number of vertices option 
     1185                //      Number of vertices option. 
    9461186                simplifmethod_runv((int)lod,upb); 
    9471187        } 
     
    9531193        typedef std::vector<int> REPINDLIST; 
    9541194 
    955         MAPAINDIND *unique_verts_inds_by_geo = new MAPAINDIND[objmesh->mSubMeshCount];  
    956         REPINDLIST *ver_inds_rep_by_geo         = new REPINDLIST[objmesh->mSubMeshCount];  
     1195        MAPAINDIND *unique_verts_inds_by_geo = 
     1196                                                                                                                new MAPAINDIND[objmesh->mSubMeshCount]; 
     1197 
     1198        REPINDLIST *ver_inds_rep_by_geo = new REPINDLIST[objmesh->mSubMeshCount]; 
    9571199 
    9581200        //      Index counter by submesh. 
     
    9641206        } 
    9651207 
    966  
    9671208        //      Construct the model. 
     1209        std::cout << "M0.faceCount(): " << M0.faceCount() << std::endl; 
    9681210        for (int        i = 0;  i < M0.faceCount();     i++) 
    9691211        { 
     
    9761218 
    9771219                        //      Insert to each submesh its triangles. 
    978                         std::map<int,int>::iterator findit = unique_verts_inds_by_geo[igeo].find(auxface->vertex(0)->validID()); 
     1220                        std::map<int,int>::iterator findit = 
     1221                                unique_verts_inds_by_geo[igeo].find(auxface->vertex(0)->validID()); 
     1222                         
    9791223                        if (findit == unique_verts_inds_by_geo[igeo].end()) 
    9801224                        { 
    9811225                                //      If it is not added... add and map it. 
    982                                 unique_verts_inds_by_geo[igeo][auxface->vertex(0)->validID()] = inextvert[igeo]; 
     1226                                unique_verts_inds_by_geo[igeo][auxface->vertex(0)->validID()] = 
     1227                                                                                                                                                                                                                                                inextvert[igeo]; 
     1228                                 
    9831229                                inextvert[igeo]++; 
    984                         }                        
    985                         findit = unique_verts_inds_by_geo[igeo].find(auxface->vertex(1)->validID()); 
     1230                        } 
     1231 
     1232                        findit = 
     1233                                unique_verts_inds_by_geo[igeo].find(auxface->vertex(1)->validID()); 
     1234                         
    9861235                        if (findit == unique_verts_inds_by_geo[igeo].end()) 
    9871236                        { 
    9881237                                //      If it is not added... add and map it. 
    989                                 unique_verts_inds_by_geo[igeo][auxface->vertex(1)->validID()] = inextvert[igeo]; 
     1238                                unique_verts_inds_by_geo[igeo][auxface->vertex(1)->validID()] = 
     1239                                                                                                                                                                                                                                                inextvert[igeo]; 
    9901240                                inextvert[igeo]++; 
    991                         }                        
    992                         findit = unique_verts_inds_by_geo[igeo].find(auxface->vertex(2)->validID()); 
     1241                        } 
     1242                         
     1243                        findit =  
     1244                                unique_verts_inds_by_geo[igeo].find(auxface->vertex(2)->validID()); 
     1245                         
    9931246                        if (findit == unique_verts_inds_by_geo[igeo].end()) 
    9941247                        { 
    9951248                                //      If it is not added... add and map it. 
    996                                 unique_verts_inds_by_geo[igeo][auxface->vertex(2)->validID()] = inextvert[igeo]; 
     1249                                unique_verts_inds_by_geo[igeo][auxface->vertex(2)->validID()] =  
     1250                                                                                                                                                                                                                                                inextvert[igeo]; 
    9971251                                inextvert[igeo]++; 
    998                         }                        
     1252                        } 
    9991253 
    10001254                        //      Total number of indices by submesh. 
     
    10431297        bool copiedShared = false; 
    10441298 
     1299        //      For each submesh. 
    10451300        for (size_t     i = 0;  i < objmesh->mSubMeshCount;     i++) 
    10461301        { 
    1047                 mGeoMesh->mSubMesh[i].mStripCount                                       =       0; 
    1048                 mGeoMesh->mSubMesh[i].mStrip                                                    =       NULL; 
     1302                mGeoMesh->mSubMesh[i].mStripCount       =       0; 
     1303                mGeoMesh->mSubMesh[i].mStrip                    =       NULL; 
    10491304 
    10501305                mGeoMesh-> 
     
    10601315                        { 
    10611316                                mGeoMesh->mSubMesh[i].mBones.push_back(objmesh-> 
    1062                                                 mSubMesh[i].mBones[j]); 
     1317                                                                                                                                                                mSubMesh[i].mBones[j]); 
    10631318                        } 
    10641319                } 
     
    10681323                        //      Indices vectors. 
    10691324                        mGeoMesh->mSubMesh[i].mIndexCount       =       ver_inds_rep_by_geo[i].size(); 
     1325                         
    10701326                        mGeoMesh->mSubMesh[i].mIndex                    =       new Index[mGeoMesh-> 
    1071                                 mSubMesh[i].mIndexCount]; 
     1327                                                                                                                                                                                mSubMesh[i].mIndexCount]; 
    10721328 
    10731329                        //      Store the indices. 
     
    10751331                        { 
    10761332                                //      Obtain the indices that point at VertexBuffer. 
    1077                                 mGeoMesh->mSubMesh[i].mIndex[j] =       unique_verts_inds_by_geo[i].operator [](ver_inds_rep_by_geo[i].operator [](j)); 
     1333                                mGeoMesh->mSubMesh[i].mIndex[j] = 
     1334                                        unique_verts_inds_by_geo[i]. 
     1335                                                                operator [](ver_inds_rep_by_geo[i]. 
     1336                                                                operator [](j)); 
    10781337                        } 
    10791338 
     
    10961355                        } 
    10971356 
    1098                         mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount       =       unique_verts_inds_by_geo[i].size(); 
    1099                         mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo        =       objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo; 
     1357                        mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount       = 
     1358                                                                                                                                        unique_verts_inds_by_geo[i].size(); 
     1359                         
     1360                        mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo        = 
     1361                                                                                        objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo; 
    11001362 
    11011363                        //      Allocate memory for position, normal and texutre coordinates. 
    1102                         mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition  =       new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
    1103                         mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal            =       new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
    1104                         mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords =       new Vector2[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
     1364                        mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition  = 
     1365                                                new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
     1366                         
     1367                        mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal            = 
     1368                                                new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
     1369                         
     1370                        mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords = 
     1371                                                new Vector2[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
    11051372 
    11061373                        for (   MAPAINDIND::iterator mapit = unique_verts_inds_by_geo[i].begin(); 
     
    11141381                                //      Vertex coordinate. 
    11151382                                //      Construction of the submeshes. 
    1116                                 Vector3 v3((Real)M0.vertex(isrc)->operator [](0), 
    1117                                                 (Real)M0.vertex(isrc)->operator [](1), 
    1118                                                 (Real)M0.vertex(isrc)->operator [](2)); 
    1119                                 mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[idst]=v3; 
     1383                                Vector3 v3(     (Real)M0.vertex(isrc)->operator [](0), 
     1384                                                                                (Real)M0.vertex(isrc)->operator [](1), 
     1385                                                                                (Real)M0.vertex(isrc)->operator [](2)); 
     1386                                 
     1387                                mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[idst]    =       v3; 
    11201388 
    11211389                                //      Normal coordinates. 
    1122                                 Vector3 v3n((Real)M0.normal(isrc)(0), (Real)M0.normal(isrc)(1), (Real)M0.normal(isrc)(2)); 
    1123                                 mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[idst]=v3n; 
     1390                                Vector3 v3n(    (Real)M0.normal(isrc)(0), 
     1391                                                                                        (Real)M0.normal(isrc)(1), 
     1392                                                                                        (Real)M0.normal(isrc)(2)); 
     1393                                 
     1394                                mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[idst]      =       v3n; 
    11241395 
    11251396                                //      Texture coordinates. 
    1126                                 Vector2 v2((Real)M0.texcoord(isrc)(0), (Real)M0.texcoord(isrc)(1)); 
    1127                                 mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[idst]=v2; 
     1397                                Vector2 v2(     (Real)M0.texcoord(isrc)(0), 
     1398                                                                                (Real)M0.texcoord(isrc)(1)); 
     1399                                 
     1400                                mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[idst]   =       v2; 
    11281401                        } 
    11291402                } 
     
    11311404                { 
    11321405                        //      Leaves mesh. 
    1133                         mGeoMesh->mSubMesh[i].mIndexCount=objmesh->mSubMesh[i].mIndexCount; 
    1134                         mGeoMesh->mSubMesh[i].mIndex=new Index[mGeoMesh->mSubMesh[i].mIndexCount]; 
     1406                        mGeoMesh->mSubMesh[i].mIndexCount       =       objmesh->mSubMesh[i].mIndexCount; 
     1407                         
     1408                        mGeoMesh->mSubMesh[i].mIndex    =               new Index[mGeoMesh->mSubMesh[i].mIndexCount]; 
    11351409 
    11361410                        //      Copy the leaves submesh indexes. 
    1137                         for (unsigned int j=0; j<mGeoMesh->mSubMesh[i].mIndexCount; j++) 
     1411                        for (unsigned int       j       =       0;      j < mGeoMesh->mSubMesh[i].mIndexCount;  j++) 
    11381412                        {        
    1139                                 mGeoMesh->mSubMesh[i].mIndex[j]=objmesh->mSubMesh[i].mIndex[j]; 
     1413                                mGeoMesh->mSubMesh[i].mIndex[j] =       objmesh->mSubMesh[i].mIndex[j]; 
    11401414                        } 
    11411415 
    11421416                        //      Copy the leaves submesh vertices. 
    1143                         mGeoMesh->mSubMesh[i].mVertexBuffer=new VertexBuffer(); 
    1144                         mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount=objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; 
    1145                         mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo=objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo; 
     1417                        mGeoMesh->mSubMesh[i].mVertexBuffer     =       new VertexBuffer(); 
     1418                         
     1419                        mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount       = 
     1420                                                                                                                objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; 
     1421                         
     1422                        mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo        = 
     1423                                                                                                                objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo; 
    11461424 
    11471425                        //      Allocate memory for position, normal and texture coordinates. 
    1148                         mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition=new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
    1149                         mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal=new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
    1150                         mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords=new Vector2[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
     1426                        mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition  = 
     1427                                                        new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
     1428                         
     1429                        mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal    = 
     1430                                                        new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
     1431                         
     1432                        mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords = 
     1433                                                        new Vector2[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
    11511434 
    11521435                        for (   unsigned int j = 0; 
     
    11551438                        { 
    11561439                                //      Position. 
    1157                                 mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[j].x=objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x; 
    1158                                 mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[j].y=objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y; 
    1159                                 mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[j].z=objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z; 
     1440                                mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[j].x     = 
     1441                                                                        objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x; 
     1442                                 
     1443                                mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[j].y     = 
     1444                                                                        objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y; 
     1445                                 
     1446                                mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[j].z     = 
     1447                                                                        objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z; 
    11601448 
    11611449                                //      Normals. 
    1162                                 mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[j].x=objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].x; 
    1163                                 mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[j].y=objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].y; 
    1164                                 mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[j].z=objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].z; 
     1450                                mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[j].x       = 
     1451                                                                        objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].x; 
     1452                                 
     1453                                mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[j].y       = 
     1454                                                                        objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].y; 
     1455                                 
     1456                                mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[j].z       = 
     1457                                                                        objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].z; 
    11651458 
    11661459                                //      Textures. 
    1167                                 mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x=objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x; 
    1168                                 mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y=objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y; 
     1460                                mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x    = 
     1461                                                                        objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x; 
     1462                                 
     1463                                mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y    = 
     1464                                                                        objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y; 
    11691465                        } 
    11701466                } 
     
    11761472 
    11771473        //      Store the simplification steps in MeshSimplificationSequence. 
    1178         int acum        =       0; 
     1474        int     acum    =       0; 
    11791475 
    11801476        for (size_t i   =       0; i < objmesh->mSubMeshCount; i++) 
     
    11921488        } 
    11931489 
    1194         MeshSimplificationSequence::Step stepaux, newstep; 
    1195         vector<int> v0,v1,submesh0,submesh1; 
    1196         MeshSimplificationSequence *msimpseq; 
    1197  
    1198         msimpseq        =       new MeshSimplificationSequence(); 
    1199  
    1200         for (unsigned i = 0;    i < decim_data.size();  i++)  
    1201         { 
    1202                 stepaux         =       decim_data.operator [](i); 
    1203                 v0                              =       vertexbuffermap[stepaux.mV0];  // vertexbuffer index 
    1204                 submesh0        =       submeshmap[stepaux.mV0]; // displacement by submesh 
    1205                 v1                              =       vertexbuffermap[stepaux.mV1]; 
    1206                 submesh1        =       submeshmap[stepaux.mV1]; 
    1207  
    1208                 for (unsigned j = 0;    j < v0.size();  j++) 
    1209                 { 
    1210                         for (unsigned k = 0;    k < v1.size(); k++) 
    1211                         { 
    1212                                 //      Obtain the submesh index in VertexBuffer 
    1213                                 //      and the displacement by submesh 
    1214                                 newstep.mV0     =       v0.operator [](j)+first_index_submesh[submesh0.operator [](j)]; 
    1215                                 newstep.mV1     =       v1.operator [](k)+first_index_submesh[submesh1.operator [](k)]; 
    1216                                 newstep.x               =       stepaux.x; 
    1217                                 newstep.y               =       stepaux.y; 
    1218                                 newstep.z               =       stepaux.z; 
    1219  
    1220                                 // mT0 y mT1 are unique triangles identifiers 
    1221                                 // returned by the simplification method 
    1222                                 newstep.mT0     =       stepaux.mT0; 
    1223                                 newstep.mT1     =       stepaux.mT1; 
    1224  
    1225                                 if (j == v0.size() - 1 && k == v1.size() - 1) 
    1226                                 { 
    1227                                         newstep.obligatorio     =       0; 
    1228                                 } 
    1229                                 else 
    1230                                 { 
    1231                                         newstep.obligatorio     =       1; 
    1232                                 } 
    1233  
    1234                                 if (j == 0 && k == 0) 
    1235                                 { 
    1236                                         //      First simplification step. 
    1237                                         //      unique triangle identifiers  
    1238                                         //      returned by the simplification method. 
    1239                                         newstep.mModfaces       =       stepaux.mModfaces; 
    1240                                 } 
    1241                                 else  
    1242                                 { 
    1243                                         std::vector<Index>      vvacio; 
    1244  
    1245                                         newstep.mModfaces       =       vvacio; 
    1246                                 } 
    1247  
    1248                                 msimpseq->mSteps.push_back(newstep); 
    1249                         } 
    1250                 } 
    1251         } 
    1252  
    1253         // WriteOBJ(); 
     1490        vector<int>     v0; 
     1491        vector<int>     v1; 
     1492        vector<int>     submesh0; 
     1493        vector<int>     submesh1; 
     1494 
    12541495        return msimpseq; 
    12551496} 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/SimplificationMethod.h

    r1025 r1526  
    99#include <GeoMeshSimplifier.h> 
    1010 
     11using   namespace       Geometry; 
     12 
    1113class SimplificationMethod 
    1214{ 
    13 private: 
    14         Geometry::Mesh  *mGeoMesh; 
    15         void compute_pair_info(simplif::pair_info*); 
    16         simplif::Model M0; 
    17         simplif::array<simplif::vert_info> vinfo; 
    18         simplif::Heap *heap; 
    19         simplif::real proximity_limit;    // distance threshold squared 
    20         int initialVertCount; 
    21         int initialEdgeCount; 
    22         int initialFaceCount; 
     15        private: 
    2316 
    24         inline simplif::vert_info& vertex_info(simplif::Vertex *v) 
    25         { 
    26                 return vinfo(v->validID()); 
    27         } 
    28          
    29         simplif::real pair_mesh_penalty(simplif::Model& M, 
    30                                                                                                                                 simplif::Vertex *v1, 
    31                                                                                                                                 simplif::Vertex *v2, 
    32                                                                                                                                 simplif::Vec3& vnew); 
    33          
    34         int predict_face(simplif::Face& F, 
    35                                                                         simplif::Vertex *v1, 
    36                                                                         simplif::Vertex *v2, 
    37                                                                         simplif::Vec3& vnew, 
    38                                                                         simplif::Vec3& f1, 
    39                                                                         simplif::Vec3& f2, 
    40                                                                         simplif::Vec3& f3); 
    41          
    42         bool check_for_pair(simplif::Vertex *v0, simplif::Vertex *v1); 
    43          
    44         simplif::pair_info *new_pair(simplif::Vertex *v0, simplif::Vertex *v1); 
    45          
    46         void delete_pair(simplif::pair_info *pair); 
    47          
    48         void do_contract(simplif::Model& m, simplif::pair_info *pair); 
    49          
    50         bool decimate_quadric(simplif::Vertex *v, simplif::Mat4& Q); 
    51          
    52         void decimate_contract(simplif::Model& m); 
    53          
    54         simplif::real decimate_error(simplif::Vertex *v); 
    55          
    56         simplif::real decimate_min_error(); 
    57          
    58         simplif::real decimate_max_error(simplif::Model& m); 
    59          
    60         void decimate_init(simplif::Model& m, simplif::real limit); 
    61          
    62         bool pair_is_valid(simplif::Vertex *u, simplif::Vertex *v); 
    63          
    64         void simplifmethod_run(int,     Geometry::TIPOFUNC      upb=0); 
    65          
    66         void simplifmethod_runv(int,    Geometry::TIPOFUNC      upb=0); 
    67          
    68         void simplifmethod_init(void); 
     17                Geometry::Mesh  *mGeoMesh; 
    6918 
    70         //      To map the mesh with de simplification method structure. 
    71         //      Submeshes which pertains each vertex. 
    72         std::map<int,std::vector<int> > submeshmap; 
    73          
    74         //      Vertices of the VertexBuffer that point  
    75         //      at this vertex of the simplification method. 
    76         std::map<int,std::vector<int> > vertexbuffermap;  
     19                void compute_pair_info(simplif::pair_info*); 
    7720 
    78         //      Simplification sequence of the simplification method. 
    79         std::vector<Geometry::MeshSimplificationSequence::Step> decim_data; 
    80          
    81         std::string meshName; 
    82          
    83         void WriteOBJ(void); 
    84          
    85         unsigned int *first_index_submesh; 
    86          
    87         //std::vector<simplif::pair_info *> pointers_to_remove; 
     21                simplif::Model M0; 
    8822 
    89         int indexMeshLeaves; 
    90          
    91 public: 
    92          
    93         const Geometry::Mesh *objmesh; 
    94          
    95         //      Total number of triangles of all the submeshes. 
    96         int number_of_triangles; 
    97          
    98         SimplificationMethod(const Geometry::Mesh *m); 
    99          
    100         void geomesh2simplifModel(void); 
    101          
    102         Geometry::MeshSimplificationSequence *Decimate( float lod, 
    103                                                                                                                                                                                                         int simpliftype, 
    104                                                                                                                                                                                                         Geometry::TIPOFUNC      upb=0); 
    105          
    106         void setMeshLeaves(int meshLeaves); 
     23                simplif::array<simplif::vert_info> vinfo; 
    10724 
    108         ///     Gets mesh simplified. 
    109         Geometry::Mesh  *       GetMesh(); 
    110          
    111         ///Destructor 
    112         ~SimplificationMethod(); 
     25                simplif::Heap *heap; 
     26                simplif::real proximity_limit;    // distance threshold squared 
     27 
     28                int initialVertCount; 
     29                int initialEdgeCount; 
     30                int initialFaceCount; 
     31 
     32                //      Simplification sequence. 
     33                MeshSimplificationSequence      *msimpseq; 
     34 
     35                //      Stores the simplification step. 
     36                MeshSimplificationSequence::Step simplifstep; 
     37 
     38                inline simplif::vert_info& vertex_info(simplif::Vertex *v) 
     39                { 
     40                        return vinfo(v->validID()); 
     41                } 
     42 
     43                simplif::real pair_mesh_penalty(simplif::Model& M, 
     44                                simplif::Vertex *v1, 
     45                                simplif::Vertex *v2, 
     46                                simplif::Vec3& vnew); 
     47 
     48                int predict_face(simplif::Face& F, 
     49                                simplif::Vertex *v1, 
     50                                simplif::Vertex *v2, 
     51                                simplif::Vec3& vnew, 
     52                                simplif::Vec3& f1, 
     53                                simplif::Vec3& f2, 
     54                                simplif::Vec3& f3); 
     55 
     56                bool check_for_pair(simplif::Vertex *v0, simplif::Vertex *v1); 
     57 
     58                simplif::pair_info *new_pair(simplif::Vertex *v0, simplif::Vertex *v1); 
     59 
     60                void delete_pair(simplif::pair_info *pair); 
     61 
     62                void do_contract(simplif::Model& m, simplif::pair_info *pair); 
     63 
     64                bool decimate_quadric(simplif::Vertex *v, simplif::Mat4& Q); 
     65 
     66                void decimate_contract(simplif::Model& m); 
     67 
     68                simplif::real decimate_error(simplif::Vertex *v); 
     69 
     70                simplif::real decimate_min_error(); 
     71 
     72                simplif::real decimate_max_error(simplif::Model& m); 
     73 
     74                void decimate_init(simplif::Model& m, simplif::real limit); 
     75 
     76                bool pair_is_valid(simplif::Vertex *u, simplif::Vertex *v); 
     77 
     78                void simplifmethod_run(int,     Geometry::TIPOFUNC      upb=0); 
     79 
     80                void simplifmethod_runv(int,    Geometry::TIPOFUNC      upb=0); 
     81 
     82                void simplifmethod_init(void); 
     83 
     84                //      To map the mesh with de simplification method structure. 
     85                //      Submeshes which pertains each vertex. 
     86                std::map< int,  std::vector<int> > submeshmap; 
     87 
     88                //      Vertices of the VertexBuffer that point 
     89                //      at this vertex of the simplification method. 
     90                std::map< int,  std::vector<int> > vertexbuffermap; 
     91 
     92                //      Simplification sequence of the simplification method. 
     93                std::vector<Geometry::MeshSimplificationSequence::Step> decim_data; 
     94 
     95                std::string meshName; 
     96 
     97                unsigned int *first_index_submesh; 
     98 
     99                //std::vector<simplif::pair_info *> pointers_to_remove; 
     100 
     101                int indexMeshLeaves; 
     102 
     103                //      Contract lonely vertices that have same coords than the contracted one. 
     104                void    contractLonelyVertices( simplif::Model  &m, 
     105                                                                                                                                        simplif::Vertex *v0, 
     106                                                                                                                                        simplif::Vertex *v1, 
     107                                                                                                                                        simplif::Vec3           candidate); 
     108 
     109                //      Remove twin edges. 
     110                void    removeTwinEdges(simplif::Model  &m, 
     111                                                                                                        simplif::Vertex *v0, 
     112                                                                                                        simplif::Vertex *v1, 
     113                                                                                                        simplif::Vec3           candidate); 
     114 
     115        public: 
     116 
     117                const Geometry::Mesh *objmesh; 
     118 
     119                //      Total number of triangles of all the submeshes. 
     120                int number_of_triangles; 
     121 
     122                SimplificationMethod(const Geometry::Mesh *m); 
     123 
     124                void    generateSimplifModel(void); 
     125 
     126                Geometry::MeshSimplificationSequence *Decimate( float lod, 
     127                                int simpliftype, 
     128                                Geometry::TIPOFUNC      upb=0); 
     129 
     130                void setMeshLeaves(int meshLeaves); 
     131 
     132                ///     Gets mesh simplified. 
     133                Geometry::Mesh  *       GetMesh(); 
     134 
     135                ///     Destructor. 
     136                ~SimplificationMethod(); 
    113137}; 
    114138 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/avars.cxx

    r1025 r1526  
    1919bool simplif::will_preserve_mesh_quality = true; 
    2020bool simplif::will_constrain_boundaries = true; 
    21 simplif::real simplif::boundary_constraint_weight = 1.0; 
     21simplif::real simplif::boundary_constraint_weight = 10.0; 
    2222 
    2323bool simplif::will_weight_by_area = false; 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/geom/3D.cxx

    r1025 r1526  
    8585} 
    8686 
    87  
    88  
    89  
    9087//////////////////////////////////////////////////////////////////////// 
    9188// 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/geom/3D.h

    r1025 r1526  
    6363        }; 
    6464 
    65  
    6665        // 
    6766        // A triangular face in 3D (ie. a 2-simplex in E3) 
     
    9493} 
    9594 
    96  
    97  
    9895// GFXGEOM_3D_INCLUDED 
    9996#endif 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/tools/Array.h

    r1025 r1526  
    88{ 
    99        template<class T> 
    10         class array { 
    11         protected: 
    12                 T *data; 
    13                 int len; 
    14         public: 
    15                 array() { data=NULL; len=0; } 
    16                 array(int l) { init(l); } 
    17                 ~array() { f_r_e_e(); } 
     10                class array 
     11                { 
     12                        protected: 
     13                                T *data; 
     14                                int len; 
     15                        public: 
     16                                array() { data=NULL; len=0; } 
     17                                array(int l) { init(l); } 
     18                                ~array() { f_r_e_e(); } 
    1819 
     20                                inline void init(int l); 
     21                                inline void f_r_e_e(); 
     22                                inline void resize(int l); 
    1923 
    20                 inline void init(int l); 
    21                 inline void f_r_e_e(); 
    22                 inline void resize(int l); 
     24                                inline T& ref(int i); 
     25                                inline T& operator[](int i) { return data[i]; } 
     26                                inline T& operator()(int i) { return ref(i); } 
    2327 
    24                 inline T& ref(int i); 
    25                 inline T& operator[](int i) { return data[i]; } 
    26                 inline T& operator()(int i) { return ref(i); } 
     28                                inline const T& ref(int i) const; 
     29                                inline const T& operator[](int i) const { return data[i]; } 
     30                                inline const T& operator()(int i) const { return ref(i); } 
    2731 
    28                 inline const T& ref(int i) const; 
    29                 inline const T& operator[](int i) const { return data[i]; } 
    30                 inline const T& operator()(int i) const { return ref(i); } 
    31  
    32  
    33                 inline int length() const { return len; } 
    34                 inline int maxLength() const { return len; } 
    35         }; 
     32                                inline int length() const { return len; } 
     33                                inline int maxLength() const { return len; } 
     34                }; 
    3635 
    3736        template<class T> 
    38         inline void array<T>::init(int l) 
    39         { 
    40                 data = new T[l]; 
    41                 len = l; 
    42         } 
     37                inline void array<T>::init(int l) 
     38                { 
     39                        data = new T[l]; 
     40                        len = l; 
     41                } 
    4342 
    4443        template<class T> 
    45         inline void array<T>::f_r_e_e() 
    46         { 
    47                 if( data ) 
     44                inline void array<T>::f_r_e_e() 
    4845                { 
    49                 delete[] data; 
    50                 data = NULL; 
     46                        if( data ) 
     47                        { 
     48                                delete[] data; 
     49                                data = NULL; 
     50                        } 
    5151                } 
    52         } 
    5352 
    5453        template<class T> 
    55         inline T& array<T>::ref(int i) 
    56         { 
    57         #ifdef SAFETY 
    58                 assert( data ); 
    59                 assert( i>=0 && i<len ); 
    60         #endif 
    61                 return data[i]; 
    62         } 
     54                inline T& array<T>::ref(int i) 
     55                { 
     56#ifdef SAFETY 
     57                        assert( data ); 
     58                        assert( i>=0 && i<len ); 
     59#endif 
     60                        return data[i]; 
     61                } 
    6362 
    6463        template<class T> 
    65         inline const T& array<T>::ref(int i) const 
    66         { 
    67         #ifdef SAFETY 
    68                 assert( data ); 
    69                 assert( i>=0 && i<len ); 
    70         #endif 
    71                 return data[i]; 
    72         } 
     64                inline const T& array<T>::ref(int i) const 
     65                { 
     66#ifdef SAFETY 
     67                        assert( data ); 
     68                        assert( i>=0 && i<len ); 
     69#endif 
     70                        return data[i]; 
     71                } 
    7372 
    7473        template<class T> 
    75         inline void array<T>::resize(int l) 
    76         { 
    77                 T *old = data; 
    78                 data = new T[l]; 
    79                 data = (T *)memcpy(data,old,MIN(len,l)*sizeof(T)); 
    80                 len = l; 
    81                 delete[] old; 
    82         } 
     74                inline void array<T>::resize(int l) 
     75                { 
     76                        T *old = data; 
     77                        data = new T[l]; 
     78                        data = (T *)memcpy(data,old,MIN(len,l)*sizeof(T)); 
     79                        len = l; 
     80                        delete[] old; 
     81                } 
    8382} 
    8483 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/tools/Buffer.h

    r1025 r1526  
    2525                inline int length() const { return fill; } 
    2626                inline int maxLength() const { return len; } 
     27                inline void setFill(int l){fill =       l;} 
    2728        }; 
    28  
    2929 
    3030        template<class T> 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/tools/Heap.h

    r1025 r1526  
    1616        class Heapable 
    1717        { 
    18         private: 
    19                 int token; 
     18                private: 
    2019 
    21         public: 
    22                 Heapable() { notInHeap(); } 
     20                        int token; 
    2321 
    24                 inline int isInHeap() { return token!=NOT_IN_HEAP; } 
    25                 inline void notInHeap() { token = NOT_IN_HEAP; } 
    26                 inline int getHeapPos() { return token; } 
    27                 inline void setHeapPos(int t) { token=t; } 
     22                public: 
     23 
     24                        Heapable() { notInHeap(); } 
     25 
     26                        inline int isInHeap() { return token!=NOT_IN_HEAP; } 
     27                        inline void notInHeap() { token = NOT_IN_HEAP; } 
     28                        inline int getHeapPos() { return token; } 
     29                        inline void setHeapPos(int t) { token=t; } 
    2830        }; 
    2931 
     32        class heap_node 
     33        { 
     34                public: 
     35                        float import; 
     36                        Heapable *obj; 
    3037 
    31         class heap_node { 
    32         public: 
    33                 float import; 
    34                 Heapable *obj; 
    35  
    36                 heap_node() { obj=NULL; import=0.0; } 
    37                 heap_node(Heapable *t, float i=0.0) { obj=t; import=i; } 
    38                 heap_node(const heap_node& h) { import=h.import; obj=h.obj; } 
     38                        heap_node() { obj=NULL; import=0.0; } 
     39                        heap_node(Heapable *t, float i=0.0) { obj=t; import=i; } 
     40                        heap_node(const heap_node& h) { import=h.import; obj=h.obj; } 
    3941        }; 
    4042 
    41  
    42  
    43         class Heap : public array<heap_node> { 
    44  
     43        class Heap : public array<heap_node> 
     44        { 
    4545                // 
    4646                // The actual size of the heap.  array::length() 
     
    5757                void downheap(int i); 
    5858 
    59         public: 
     59                public: 
    6060 
    6161                Heap() { size=0; } 
    6262                Heap(int s) : array<heap_node>(s) { size=0; } 
    63  
    6463 
    6564                void insert(Heapable *, float); 
     
    6766 
    6867                heap_node *extract(); 
     68 
     69                //      Overhead method. 
     70                heap_node *extract(int i); 
     71 
    6972                heap_node *top() { return size<1 ? (heap_node *)NULL : &ref(0); } 
    7073                heap_node *kill(int i); 
     74 
     75                //      Gets heap size. 
     76                int     getSize(){return        size;} 
     77 
     78                //      Gets element at position i. 
     79                heap_node       *getElement(int i){return       &ref(i);} 
     80 
    7181        }; 
    7282 
    7383} 
    7484 
    75  
    7685// GFXTOOLS_HEAP_INCLUDED 
    7786#endif 
     87 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/tools/heap.cxx

    r1025 r1526  
    77void Heap::swap(int i,int j) 
    88{ 
    9     heap_node tmp = ref(i); 
     9        heap_node tmp = ref(i); 
    1010 
    11     ref(i) = ref(j); 
    12     ref(j) = tmp; 
     11        ref(i) = ref(j); 
     12        ref(j) = tmp; 
    1313 
    14     ref(i).obj->setHeapPos(i); 
    15     ref(j).obj->setHeapPos(j); 
     14        ref(i).obj->setHeapPos(i); 
     15        ref(j).obj->setHeapPos(j); 
    1616} 
    1717 
    1818void Heap::upheap(int i) 
    1919{ 
    20     if( i==0 ) return; 
     20        if( i==0 ) return; 
    2121 
    22     if( ref(i).import > ref(parent(i)).import ) { 
    23         swap(i,parent(i)); 
    24         upheap(parent(i)); 
    25     } 
     22        if( ref(i).import > ref(parent(i)).import ) 
     23        { 
     24                swap(i,parent(i)); 
     25                upheap(parent(i)); 
     26        } 
    2627} 
    2728 
    2829void Heap::downheap(int i) 
    2930{ 
    30     if (i>=size) return;        // perhaps just extracted the last 
     31        if (i>=size) return;        // perhaps just extracted the last 
    3132 
    32     int largest = i, 
    33         l = left(i), 
    34         r = right(i); 
     33        int largest = i, 
     34                        l = left(i), 
     35                        r = right(i); 
    3536 
    36     if( l<size && ref(l).import > ref(largest).import ) largest = l; 
    37     if( r<size && ref(r).import > ref(largest).import ) largest = r; 
     37        if( l<size && ref(l).import > ref(largest).import ) largest = l; 
     38        if( r<size && ref(r).import > ref(largest).import ) largest = r; 
    3839 
    39     if( largest != i ) { 
    40         swap(i,largest); 
    41         downheap(largest); 
    42     } 
     40        if( largest != i ) { 
     41                swap(i,largest); 
     42                downheap(largest); 
     43        } 
    4344} 
    44  
    45  
    4645 
    4746void Heap::insert(Heapable *t,float v) 
    4847{ 
    49     if( size == maxLength() ) 
    50     { 
    51         std::cerr << "NOTE: Growing heap from " << size << " to " << 2*size << std::endl; 
    52         resize(2*size); 
    53     } 
     48        if( size == maxLength() ) 
     49        { 
     50                std::cerr << "NOTE: Growing heap from " << size << " to " << 2*size << std::endl; 
     51                resize(2*size); 
     52        } 
    5453 
    55     int i = size++; 
     54        int i = size++; 
    5655 
    57     ref(i).obj = t; 
    58     ref(i).import = v; 
     56        ref(i).obj = t; 
     57        ref(i).import = v; 
    5958 
    60     ref(i).obj->setHeapPos(i); 
     59        ref(i).obj->setHeapPos(i); 
    6160 
    62     upheap(i); 
     61        upheap(i); 
    6362} 
    6463 
    6564void Heap::update(Heapable *t,float v) 
    6665{ 
    67     int i = t->getHeapPos(); 
     66        int i = t->getHeapPos(); 
    6867 
    69     if( i >= size ) 
    70     { 
     68        if( i >= size ) 
     69        { 
    7170                std::cerr << "WARNING: Attempting to update past end of heap!" << std::endl; 
    7271                return; 
    73     } 
    74     else if( i == NOT_IN_HEAP ) 
    75     { 
     72        } 
     73        else if( i == NOT_IN_HEAP ) 
     74        { 
    7675                std::cerr << "WARNING: Attempting to update object not in heap!" << std::endl; 
    7776                return; 
    78     } 
     77        } 
    7978 
    80     float old=ref(i).import; 
    81     ref(i).import = v; 
     79        float old=ref(i).import; 
     80        ref(i).import = v; 
    8281 
    83     if( v<old ) 
    84         downheap(i); 
    85     else 
    86         upheap(i); 
     82        if( v<old ) 
     83                downheap(i); 
     84        else 
     85                upheap(i); 
    8786} 
    88  
    89  
    9087 
    9188heap_node *Heap::extract() 
    9289{ 
    93     if( size<1 ) return 0; 
     90        if( size<1 ) return 0; 
    9491 
    95     swap(0,size-1); 
    96     size--; 
     92        swap(0,size-1); 
     93        size--; 
    9794 
    98     downheap(0); 
     95        downheap(0); 
    9996 
    100     ref(size).obj->notInHeap(); 
     97        ref(size).obj->notInHeap(); 
    10198 
    102     return &ref(size); 
     99        return &ref(size); 
     100} 
     101 
     102//      Overhead method. 
     103heap_node *Heap::extract(int i) 
     104{ 
     105        if( size<1 ) return 0; 
     106 
     107        swap(i,size-1); 
     108        size--; 
     109 
     110        downheap(i); 
     111 
     112        ref(size).obj->notInHeap(); 
     113 
     114        return &ref(size); 
    103115} 
    104116 
    105117heap_node *Heap::kill(int i) 
    106118{ 
    107     if( i>=size ) 
     119        if( i>=size ) 
    108120                std::cerr << "WARNING: Attempt to delete invalid heap node." << std::endl; 
    109121 
    110     swap(i, size-1); 
    111     size--; 
    112     ref(size).obj->notInHeap(); 
     122        swap(i, size-1); 
     123        size--; 
     124        ref(size).obj->notInHeap(); 
    113125 
    114     if( ref(i).import < ref(size).import ) 
     126        if( ref(i).import < ref(size).import ) 
    115127                downheap(i); 
    116     else 
     128        else 
    117129                upheap(i); 
    118130 
     131        return &ref(size); 
     132} 
    119133 
    120     return &ref(size); 
    121 } 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/Leaf.cpp

    r1026 r1526  
    1010        vertsLeaf[0] = vertsLeaf[1] = vertsLeaf[2] = vertsLeaf[3] =0;  
    1111        center[0] = center[1] = center[2] = 0; 
    12         normal[0] = normal[1] = normal[2] = 0; 
     12//      normal[0] = normal[1] = normal[2] = 0; 
    1313        leafNear=-1; 
    1414        parentLeafCount = 1; 
     
    4040        for ( int i=0;i<3;i++){ 
    4141                center[i] = aLeaf.center[i]; 
    42                 normal[i] = aLeaf.normal[i]; 
     42//              normal[i] = aLeaf.normal[i]; 
    4343        } 
    4444        for (i = 0L; i < 4; i++) 
     
    5353 
    5454 
     55RuntimeLeaf::RuntimeLeaf(void)  
     56{        
     57        vertsLeaf[0] = vertsLeaf[1] = vertsLeaf[2] = vertsLeaf[3] = 0; 
     58        parent = root = childLeft = childRight = -1; 
     59} 
    5560 
    5661//-------------------------------------------------------------------------------------------------------------------------------- 
    57 // Destructor. We must deallocate the memory allocated for pointers to vertices and edges 
     62// Copy constructor 
    5863//-------------------------------------------------------------------------------------------------------------------------------- 
    59 Leaf::~Leaf (void) 
     64RuntimeLeaf::RuntimeLeaf (const RuntimeLeaf& aLeaf) 
    6065{ 
     66        for (int i = 0L; i < 4; i++) 
     67                vertsLeaf[i] = aLeaf.vertsLeaf[i];  
     68        parent = aLeaf.parent; 
     69        childLeft = aLeaf.childLeft; 
     70        childRight = aLeaf.childRight; 
     71        root = aLeaf.root; 
    6172} 
    6273 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/VertexData.cpp

    r1105 r1526  
    11#include "VertexData.h" 
    22 
    3 Geometry::DefaultVertexData::DefaultVertexData(unsigned int numv):Geometry::VertexData(numv) 
     3/* 
     4void Geometry::DefaultIndexData::Init(unsigned int numi) 
    45{ 
    5         v = new float[numv*3]; 
    6         n = new float[numv*3]; 
    7         t = new float[numv*2]; 
    8 } 
    9 Geometry::DefaultVertexData::~DefaultVertexData(void) 
    10 { 
    11 /*      delete[] v; 
    12         delete[] n; 
    13         delete[] t;*/ 
    14 } 
    15  
    16 Geometry::VertexData *Geometry::DefaultVertexDataCreator(unsigned int numv) 
    17 {  
    18         return new DefaultVertexData(numv);  
    19 } 
    20  
    21  
    22 Geometry::DefaultIndexData::DefaultIndexData(unsigned int numi):Geometry::IndexData(numi) 
    23 { 
    24         indices = new unsigned int[numi];        
     6        indices = new unsigned int[numi]; 
    257} 
    268Geometry::DefaultIndexData::~DefaultIndexData(void) 
    279{ 
    28 /*      delete[] indices;*/ 
    2910} 
    3011 
    3112Geometry::IndexData *Geometry::DefaultIndexDataCreator(unsigned int numi) 
    3213{  
    33         return new DefaultIndexData(numi);  
     14        IndexData *ret = new DefaultIndexData(); 
     15//      ret->Init(numi); 
     16        return ret; 
    3417} 
    3518 
    36  
    37 /*Geometry::DefaultMultiIndexData::DefaultMultiIndexData(unsigned int numprims, unsigned int *numi):Geometry::MultiIndexData(numprims,numi) 
    38 { 
    39         indices = new unsigned int*[numprims];   
    40         for (unsigned int i=0; i<numprims; i++) 
    41                 indices[i]=new unsigned int[numi[i]]; 
    42 } 
    43 Geometry::DefaultMultiIndexData::~DefaultMultiIndexData(void) 
    44 { 
    45         for (unsigned int i=0; i<GetNumPrims(); i++) 
    46                 delete[] indices[i]; 
    47         delete[] indices; 
    48 } 
    49  
    50 Geometry::MultiIndexData *Geometry::DefaultMultiIndexDataCreator(unsigned int numprims, unsigned int *numi) 
    51 {  
    52         return new DefaultMultiIndexData(numprims,numi);  
    53 } 
    5419*/ 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/foliage.cpp

    r1083 r1526  
    1010// Parameters --> None 
    1111//-------------------------------------------------------------------------------------------------------------------------------- 
    12 Foliage::Foliage(const Geometry::SubMesh *leavesSubMesh, const Geometry::TreeSimplificationSequence * simpSeq, Geometry::CREATEVERTEXDATAFUNC vdfun, Geometry::CREATEINDEXDATAFUNC idfun):  
     12Foliage::Foliage(int leavessubmeshID,  
     13                                 const Geometry::SubMesh *leavesSubMesh,  
     14                                 const Geometry::TreeSimplificationSequence * simpSeq/*, 
     15                                 Geometry::CREATEVERTEXDATAFUNC vdfun*/):  
    1316Acth(NULL), 
    14 create_vertex_data_func(vdfun==NULL?Geometry::DefaultVertexDataCreator:vdfun), 
    15 create_index_data_func(idfun==NULL?Geometry::DefaultIndexDataCreator:idfun), 
    16 vertexdata(NULL), Leaves(NULL), MinDet(NULL) 
     17//create_vertex_data_func(vdfun==NULL?Geometry::DefaultVertexDataCreator:vdfun), 
     18//create_index_data_func(idfun==NULL?Geometry::DefaultIndexDataCreator:idfun), 
     19/*vertexdata(NULL),*/ Leaves(NULL), MinDet(NULL) 
    1720{ 
    1821        begin = final = -1; 
    19  
    20         ReadVertices(leavesSubMesh); 
     22//      indexdata=NULL; 
     23 
     24//      ReadVertices(leavesSubMesh); 
     25        int countv= int(leavesSubMesh->mVertexBuffer->mVertexCount); 
     26        Leaves = new RuntimeLeaf[countv*2]; 
     27        TotalVerts = countv; 
     28 
    2129        ReadLeafs(leavesSubMesh); 
    2230        if (!ReadSimpSeq(simpSeq)) exit(1); 
    2331        FillRoot(); 
    24         CalculateTexCoordsAndNorms(); 
    25  
    26         indexdata->SetNumValidIndices(0); 
     32//      CalculateTexCoordsAndNorms(); 
     33 
     34//      indexdata->SetNumValidIndices(0); 
    2735 
    2836        int h=0; 
     
    4452        final = leafCount-1; 
    4553        active_leaf_count = leafCount; 
     54        leavesSubMeshID=leavessubmeshID; 
    4655} 
    4756 
     
    5160Foliage::~Foliage (void) 
    5261{ 
    53         if (vertexdata) delete vertexdata; 
    54         if (indexdata) delete indexdata; 
     62//      if (vertexdata) delete vertexdata; 
     63//      if (indexdata) delete indexdata; 
    5564        delete[] Leaves; 
    5665        delete MinDet; 
     
    222231 
    223232 } 
    224  
     233/* 
    225234void Foliage::ReadVertices(const Geometry::SubMesh *submesh) 
    226235{ 
     
    228237        vertexdata = create_vertex_data_func(2*countv); 
    229238        Leaves = new Leaf[countv*2]; 
    230         indexdata = create_index_data_func(countv*2*3); // 3 indices x 2 triangulos x hoja 
     239        //indexdata = create_index_data_func(countv*2*3); // 3 indices x 2 triangulos x hoja 
    231240         
    232241        vertexdata->Begin(); 
     
    249258        float twox, twoy, twoz; 
    250259        float threex, threey, threez; 
    251  
    252 /*      Vertices[aHoja.vertsLeaf[0]].GetCoordinates (onex, oney, onez); 
    253         Vertices[aHoja.vertsLeaf[1]].GetCoordinates(twox, twoy, twoz); 
    254         Vertices[aHoja.vertsLeaf[2]].GetCoordinates (threex, threey, threez);*/ 
    255260 
    256261        vertexdata->GetVertexCoord(aleaf.vertsLeaf[0],onex,oney,onez); 
     
    286291        res[2]=v[2]/module; 
    287292} 
    288  
     293*/ 
    289294void Foliage::ReadLeafs(const Geometry::SubMesh *submesh) 
    290295{ 
     
    297302                Leaves[h].vertsLeaf[2] = submesh->mIndex[h*6+2]; 
    298303                Leaves[h].vertsLeaf[3] = submesh->mIndex[h*6+5]; 
    299                 Leaves[h].visible = 0; 
    300  
    301                 GetNormalH ( Leaves[h]); 
     304//              Leaves[h].visible = 0; 
     305 
     306//              GetNormalH ( Leaves[h]); 
    302307        } 
    303308} 
     
    316321                Leaves[tn].vertsLeaf[3] = it->mNewQuad[3]; 
    317322 
    318                 Leaves[tn].visible = 0; 
    319  
    320                 GetNormalH  (Leaves[tn]); 
     323//              Leaves[tn].visible = 0; 
     324 
     325//              GetNormalH  (Leaves[tn]); 
    321326 
    322327                tv1 = it->mV0/2; 
     
    433438} 
    434439 
    435 void Foliage::CalculateTexCoordsAndNorms(void) 
     440/*void Foliage::CalculateTexCoordsAndNorms(void) 
    436441{        
    437442        vertexdata->Begin(); 
     
    453458        vertexdata->End(); 
    454459} 
    455  
     460*/ 
    456461Foliage::Foliage(const Foliage *ar) 
    457462{ 
     
    465470        TotalVerts=ar->TotalVerts; 
    466471 
    467         create_vertex_data_func=ar->create_vertex_data_func; 
    468         create_index_data_func=ar->create_index_data_func; 
     472/*      create_vertex_data_func=ar->create_vertex_data_func; 
     473//      create_index_data_func=ar->create_index_data_func; 
    469474        vertexdata=create_vertex_data_func(ar->vertexdata->GetNumVertices()); 
    470475        vertexdata->Begin();  
     
    477482                vertexdata->SetVertexNormal(i,va,vb,vc); 
    478483        } 
    479         vertexdata->End(); 
    480         indexdata=create_index_data_func(ar->indexdata->GetNumMaxIndices()); 
    481         indexdata->Begin();  
     484        vertexdata->End();*/ 
     485/*      indexdata=create_index_data_func(ar->indexdata->GetNumMaxIndices()); 
     486        indexdata->Begin(ar->leavesSubMeshID,indexdata->GetNumMaxIndices()); 
    482487        for (unsigned int i=0; i<indexdata->GetNumMaxIndices(); i++)  
    483488                indexdata->SetIndex(i,ar->indexdata->GetIndex(i)); 
    484         indexdata->End(); 
    485  
    486         Leaves=new Leaf[vertexdata->GetNumVertices()]; 
     489        indexdata->End();*/ 
     490 
     491        Leaves=new RuntimeLeaf[TotalVerts]; 
    487492//      for (unsigned int i=0; i<vertexdata->GetNumVertices(); i++)  
    488493//              Leaves[i]=ar->Leaves[i]; 
    489         memcpy(Leaves,ar->Leaves,sizeof(Leaf)*vertexdata->GetNumVertices()); 
     494        memcpy(Leaves,ar->Leaves,sizeof(Leaf)*TotalVerts); 
    490495 
    491496        // esto no sé si devería haber akí 
    492         indexdata->SetNumValidIndices(0); 
     497//      indexdata->SetNumValidIndices(0); 
    493498 
    494499        int h=0; 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/foliage.h

    r1083 r1526  
    2626                int begin, final; 
    2727                int active_leaf_count; 
     28                int leavesSubMeshID; 
    2829 
    29                 Foliage (const Geometry::SubMesh *, const Geometry::TreeSimplificationSequence *, Geometry::CREATEVERTEXDATAFUNC vdfun=NULL, Geometry::CREATEINDEXDATAFUNC idfun=NULL); 
     30                Foliage (       int leavesSubMeshID,  
     31                                        const Geometry::SubMesh *,  
     32                                        const Geometry::TreeSimplificationSequence *    ); 
     33 
    3034                Foliage (const Foliage *); 
    3135                virtual ~Foliage (void); // Destructor 
     
    3337                void CalculateLOD(int nhojas); 
    3438 
    35                 Geometry::VertexData *vertexdata; 
    36                 Geometry::IndexData *indexdata; 
    37  
    38                 Leaf   *Leaves; 
     39                RuntimeLeaf   *Leaves; 
    3940                ActiveLeafNode  *MinDet; // first active leaf 
    4041                int leafCount; 
     
    4546 
    4647        private: 
    47                 Geometry::CREATEVERTEXDATAFUNC create_vertex_data_func;          
    48                 Geometry::CREATEINDEXDATAFUNC create_index_data_func; 
    4948 
    5049                bool IsActive( int num) const; 
     
    5958                bool ReadSimpSeq(const Geometry::TreeSimplificationSequence *); /// returns true when successful 
    6059                void FillRoot(void); 
    61  
    62                 void GetNormalH (Leaf&); 
    63  
    64                 void CrossProduct(const float *v1, const float *v2, float *res); 
    65                 void Normalize(const float *v, float *res); 
    66 //              void CalculaNormalesVertice(void); 
    67                 void CalculateTexCoordsAndNorms(void); 
    68  
    6960}; 
    7061 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/simplif.h

    r1025 r1526  
    1212        class pair_info : public Heapable 
    1313        { 
    14         public: 
    15                 Vertex *v0, *v1; 
     14                public: 
     15                        Vertex *v0, *v1; 
    1616 
    17                 Vec3 candidate; 
    18                 real cost; 
     17                        Vec3 candidate; 
     18                        real cost; 
    1919 
    20                 pair_info(Vertex *a,Vertex *b) { v0=a; v1=b; cost=HUGE; } 
     20                        pair_info(Vertex *a,Vertex *b) { v0=a; v1=b; cost=HUGE; } 
    2121 
    22                 bool isValid() { return v0->isValid() && v1->isValid(); } 
     22                        bool isValid() { return v0->isValid() && v1->isValid(); } 
    2323        }; 
    2424 
     
    2727        class vert_info 
    2828        { 
    29         public: 
     29                public: 
    3030 
    31                 pair_buffer pairs; 
     31                        pair_buffer pairs; 
    3232 
    33                 Mat4 Q; 
    34                 real norm; 
     33                        Mat4 Q; 
     34                        real norm; 
    3535 
    36                 vert_info() : Q(Mat4::zero) { pairs.init(2); norm=0.0; } 
     36                        vert_info() : Q(Mat4::zero) { pairs.init(2); norm=0.0; } 
    3737        }; 
    3838} 
     39 
  • GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshViewUI.h

    r1090 r1526  
    8787using   namespace       Geometry; 
    8888 
     89class GeoToolIndexData : public Geometry::IndexData 
     90{ 
     91public: 
     92        GeoToolIndexData(unsigned int submeshes):Geometry::IndexData(){ 
     93                submeshcount = submeshes; 
     94                indices=new unsigned int*[submeshcount]; 
     95                indexCount=new unsigned int[submeshcount]; 
     96                for (int i=0; i<submeshcount; i++) 
     97                { 
     98                        indices[i]=NULL; 
     99                        indexCount[i]=0; 
     100                } 
     101        } 
     102        virtual ~GeoToolIndexData(void){ 
     103                for (int i=0; i<submeshcount; i++) 
     104                        if (indices[i]) 
     105                                delete[] indices[i]; 
     106                delete[] indices; 
     107                delete[] indexCount; 
     108        } 
     109 
     110        virtual void Begin(unsigned int submesh, unsigned int numinds){ 
     111                if (indices[submesh])            
     112                        delete[] indices[submesh]; 
     113                indices[submesh] = new unsigned int[numinds];      
     114                indexCount[submesh] = numinds; 
     115                modifySubmesh=submesh; 
     116        } 
     117 
     118        virtual void SetIndex(unsigned int i, unsigned int index){ 
     119                indices[modifySubmesh][i] = index; 
     120        } 
     121 
     122        virtual void End(void){} 
     123        virtual void BorrowIndexData(const IndexData *){} 
     124 
     125        unsigned int submeshcount; 
     126        unsigned int **indices; 
     127        unsigned int *indexCount; 
     128        unsigned int modifySubmesh; 
     129}; 
     130 
    89131class GeoMeshViewUI 
    90132{ 
     
    109151        //      Lod tree object. 
    110152        LodTreeLibrary  *lodTreeLib; 
    111          
     153 
    112154        MeshSimplifier                  *mMeshSimplifier; 
    113155        TreeSimplifier                  *mTreeSimplifier; 
     
    117159 
    118160        MeshSimplificationSequence      *oMeshSimpSequence; 
    119         LodStripsConstructor            *oLodStrip; 
    120         GeoMeshLoader                           *geoMeshLoader; 
     161        LodStripsConstructor                            *oLodStrip; 
     162        GeoMeshLoader                                                           *geoMeshLoader; 
    121163 
    122164        inline void cb_menuFileOpen_i(fltk::Item*, void*); 
     
    288330 
    289331        public: 
     332 
     333        // the indexdata for the LOD models 
     334        GeoToolIndexData *lod_index_data; 
    290335 
    291336        GeoMeshView                                     *geoMeshView; 
  • GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp

    r1090 r1526  
    594594        //      For each strip. 
    595595//      MultiIndexData *dataInterface = lodStripsLib->dataRetrievalInterface; 
    596         IndexData *dataInterface = lodStripsLib->dataRetrievalInterface; 
     596/*      IndexData *dataInterface = lodStripsLib->dataRetrievalInterface; 
    597597        size_t triangle_count = dataInterface->GetNumValidIndices() - 2; 
    598 /*      for (int strip  =       0; strip < dataInterface->GetNumPrims(); strip++) 
    599         { 
    600 //              triangle_count  +=      lodStripsLib->mStrips[strip].size() - 2; 
    601                 triangle_count  +=      dataInterface->GetNumValidIndices(strip) - 2; 
    602         }*/ 
    603  
    604         return  triangle_count; 
     598 
     599        return  triangle_count;*/ 
     600 
     601        return lodStripsLib->GetCurrentTriangleCount(); 
    605602} 
    606603 
     
    716713                i       = 0; 
    717714 
    718 /*              if (getColorStrips()) 
     715                if (getColorStrips()) 
    719716                { 
    720717                        //      Gets the color of the strip. 
     
    728725                        //      Paint a new color. 
    729726                        glColor3f(r,g,b); 
    730                 }*/ 
     727                        GLfloat color[] =       {r,g,b,1.0f}; 
     728                        glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,color); 
     729                } 
    731730 
    732731 
     
    904903 
    905904                //      For each one of the strips. 
    906 /*              for (int strip = 0; strip < geosubmesh->mStripCount; strip++) 
    907                 { 
    908                         //      Paint the current strip. 
    909                         glBegin(GL_TRIANGLE_STRIP); 
    910  
    911                         if (getColorStrips()) 
    912                         { 
    913                                 //      Gets the color of the strip. 
    914                                 r       =       mStripColors[submesh][color_index].r; 
    915                                 g       =       mStripColors[submesh][color_index].g; 
    916                                 b       =       mStripColors[submesh][color_index].b; 
    917  
    918                                 //      Change to the next color. 
    919                                 color_index++; 
    920  
    921                                 //      Paint a new color. 
    922                                 glColor3f(r,g,b); 
    923                         } 
    924  
    925                         //      For each index of the strip. 
    926                         for (int index = 0; index < lodStripsLib->dataRetrievalInterface->GetNumValidIndices(current_strip); index++) 
    927                         { 
    928                                 position        =       lodStripsLib->dataRetrievalInterface->GetIndex(current_strip,index); 
    929  
    930                                 //      Gets the vertex normal. 
    931                                 vector3 =       geosubmesh->mVertexBuffer->mNormal[position]; 
    932  
    933                                 x                               =       vector3[0]; 
    934                                 y                               =       vector3[1]; 
    935                                 z                               =       vector3[2]; 
    936  
    937                                 //      Sets the vertex normal. 
    938                                 glNormal3f(x,y,z); 
    939  
    940                                 // set the texture coordinates if needed 
    941                                 if (usetex) 
    942                                 { 
    943                                         vector2 = geosubmesh->mVertexBuffer->mTexCoords[position]; 
    944                                         x                               =       vector2[0]; 
    945                                         y                               =       vector2[1]; 
    946                                         glTexCoord2f(x,y); 
    947                                 } 
    948  
    949                                 //      Gets the vertex coordinates. 
    950                                 vector3 =       geosubmesh->mVertexBuffer->mPosition[position]; 
    951  
    952                                 x                               =       vector3[0]; 
    953                                 y                               =       vector3[1]; 
    954                                 z                               =       vector3[2]; 
    955  
    956                                 //      Sets the vertex position. 
    957                                 glVertex3f(x,y,z); 
    958                         } 
    959  
    960                         //      Increments current strip. 
    961                         current_strip++; 
    962  
    963                         //      A strip is generated. 
    964                         glEnd(); 
    965  
    966                 }*/ 
    967  
    968905                int indices_to_render = lodStripsLib->GetValidIndexCount(submesh); 
    969906                int offset = lodStripsLib->GetValidOffset(submesh); 
    970907 
    971908                glBegin(GL_TRIANGLE_STRIP); 
    972                 //for (int index = 0; index < lodStripsLib->dataRetrievalInterface->GetNumValidIndices(); index ++) 
    973                 for (int index = offset; index < indices_to_render+offset; index ++) 
    974                 { 
    975                         position = lodStripsLib->dataRetrievalInterface->GetIndex(index); 
     909//              for (int index = offset; index < indices_to_render+offset; index ++) 
     910                for (int index = 0; index < mGeoMeshViewUI->lod_index_data->indexCount[submesh]; index ++) 
     911                { 
     912//                      position = lodStripsLib->dataRetrievalInterface->GetIndex(index); 
     913                        position = mGeoMeshViewUI->lod_index_data->indices[submesh][index]; 
    976914 
    977915                        //      Gets the vertex normal. 
     
    1045983 
    1046984                //      For each one of the strips. 
    1047 /*              for (int strip = 0; strip < geosubmesh->mStripCount; strip++) 
    1048                 { 
    1049                         //      Paint the current strip. 
    1050                         glBegin(GL_TRIANGLE_STRIP); 
    1051  
    1052                         if (getColorStrips()) 
    1053                         { 
    1054                                 //      Gets the color of the strip. 
    1055                                 r       =       mStripColors[submesh][color_index].r; 
    1056                                 g       =       mStripColors[submesh][color_index].g; 
    1057                                 b       =       mStripColors[submesh][color_index].b; 
    1058  
    1059                                 //      Change to the next color. 
    1060                                 color_index++; 
    1061  
    1062                                 //      Paint a new color. 
    1063                                 glColor3f(r,g,b); 
    1064                         } 
    1065  
    1066                         //      For each index of the strip. 
    1067                         for (int index = 0; index < lodTreeLib->CurrentLOD_Trunk_IndexCountByStrip(current_strip); index++) 
    1068                         { 
    1069                                 position = lodTreeLib->CurrentLOD_Trunk_Indices()->GetIndex(current_strip,index); 
    1070  
    1071                                 //      Gets the vertex normal. 
    1072                                 vector3 =       geosubmesh->mVertexBuffer->mNormal[position]; 
    1073  
    1074                                 x                               =       vector3[0]; 
    1075                                 y                               =       vector3[1]; 
    1076                                 z                               =       vector3[2]; 
    1077  
    1078                                 //      Sets the vertex normal. 
    1079                                 glNormal3f(x,y,z); 
    1080  
    1081                                 // set the texture coordinates if needed 
    1082                                 if (usetex) 
    1083                                 { 
    1084                                         vector2 = geosubmesh->mVertexBuffer->mTexCoords[position]; 
    1085                                         x                               =       vector2[0]; 
    1086                                         y                               =       vector2[1]; 
    1087                                         glTexCoord2f(x,y); 
    1088                                 } 
    1089  
    1090                                 //      Gets the vertex coordinates. 
    1091                                 vector3 =       geosubmesh->mVertexBuffer->mPosition[position]; 
    1092  
    1093                                 x                               =       vector3[0]; 
    1094                                 y                               =       vector3[1]; 
    1095                                 z                               =       vector3[2]; 
    1096  
    1097                                 //      Sets the vertex position. 
    1098                                 glVertex3f(x,y,z); 
    1099                         } 
    1100  
    1101                         //      Increments current strip. 
    1102                         current_strip++; 
    1103  
    1104                         //      A strip is generated. 
    1105                         glEnd(); 
    1106  
    1107                 }*/ 
    1108          
    1109 //              int indices_to_render = lodTreeLib->trunk->GetValidIndexCount(submesh); 
    1110985                int indices_to_render = lodTreeLib->GetValidTrunkIndexCount(submesh); 
    1111986                int begin_index = lodTreeLib->GetValidTrunkOffset(submesh); 
    1112987                         
    1113988                glBegin(GL_TRIANGLE_STRIP); 
    1114                 for (int index = begin_index; index < indices_to_render+begin_index; index ++) 
    1115                 { 
    1116                         position = lodTreeLib->CurrentLOD_Trunk_Indices()->GetIndex(index); 
     989//              for (int index = begin_index; index < indices_to_render+begin_index; index ++) 
     990                for (int index = 0; index < mGeoMeshViewUI->lod_index_data->indexCount[submesh]; index ++) 
     991                { 
     992//                      position = lodTreeLib->CurrentLOD_Trunk_Indices()->GetIndex(index); 
     993                        position = mGeoMeshViewUI->lod_index_data->indices[submesh][index]; 
    1117994 
    1118995                        //      Gets the vertex normal. 
     
    11571034 
    11581035        glBegin(GL_TRIANGLES); 
    1159         const Geometry::VertexData *foliage_verts = lodTreeLib->Get_Foliage_VertexData(); 
    1160         const Geometry::IndexData *foliage_inds = lodTreeLib->CurrentLOD_Foliage_Indices(); 
    1161         for (int j=0; j<lodTreeLib->CurrentLOD_Foliage_IndexCount(); j++) 
    1162         { 
    1163                 float vx,vy,vz; 
     1036        Geometry::SubMesh & foliageSubMesh = geoMesh->mSubMesh[lodTreeLib->GetLeavesSubMesh()]; 
     1037        Geometry::Vector3 auxv; 
     1038        for (int j=0; j<mGeoMeshViewUI->lod_index_data->indexCount[lodTreeLib->GetLeavesSubMesh()]; j++) 
     1039        {                
     1040                int k = mGeoMeshViewUI->lod_index_data->indices[lodTreeLib->GetLeavesSubMesh()][j]; 
    11641041                if (usetex) 
    11651042                { 
    1166                         foliage_verts->GetVertexTexCoord(foliage_inds->GetIndex(j),vx,vy); 
    1167                         glTexCoord2f(vx,vy); 
    1168                 } 
    1169                 foliage_verts->GetVertexNormal(foliage_inds->GetIndex(j),vx,vy,vz); 
    1170                 glNormal3f(vx,vy,vz); 
    1171                 foliage_verts->GetVertexCoord(foliage_inds->GetIndex(j),vx,vy,vz); 
    1172                 glVertex3f(vx,vy,vz); 
     1043                        Geometry::Vector2 tc = foliageSubMesh.mVertexBuffer->mTexCoords[k]; 
     1044                        glTexCoord2f(tc.x,tc.y); 
     1045                } 
     1046                auxv = foliageSubMesh.mVertexBuffer->mNormal[k]; 
     1047                glNormal3f(auxv.x,auxv.y,auxv.z); 
     1048                auxv = foliageSubMesh.mVertexBuffer->mPosition[k]; 
     1049                glVertex3f(auxv.x,auxv.y,auxv.z); 
    11731050        } 
    11741051        glEnd(); 
     
    12531130 
    12541131        glEnable (GL_POLYGON_OFFSET_LINE); 
    1255         glPolygonOffset(-1,-1); 
     1132        glPolygonOffset(-0.5,1); 
    12561133        glEnable(GL_DEPTH_TEST); 
    12571134        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     
    12691146        glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,color_blanco); 
    12701147 
    1271         glClearColor(0,0,0,0); 
     1148        glClearColor(0.3,0.3,0.3,0); 
    12721149         
    12731150        if (mCW) 
     
    12921169        { 
    12931170                enableColorStrips(); 
    1294                 glDisable(GL_LIGHTING); 
     1171                //glDisable(GL_LIGHTING); 
    12951172                glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 
    12961173                drawGeoMesh(false); 
     
    13041181        { 
    13051182                disableColorStrips(); 
    1306                 glDisable(GL_LIGHTING); 
    1307                 glColor3d(0.0, 0.0, 1.0); 
     1183                //glDisable(GL_LIGHTING); 
     1184                glColor3d(0.0, 0.0, 0.0); 
     1185                GLfloat color[] =       {0.0f,0.0f,0.0f,1.0f}; 
     1186                glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,color); 
     1187 
    13081188                glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 
    13091189                drawGeoMesh(true); 
     
    13131193                if (!mSolid) 
    13141194                { 
    1315                         enableColorStrips(); 
    1316                         glEnable(GL_LIGHTING); 
     1195                        disableColorStrips(); 
     1196                        //glEnable(GL_LIGHTING); 
    13171197                        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 
    13181198                        drawGeoMesh(false); 
  • GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp

    r1098 r1526  
    10751075                                        { 
    10761076                                                //      Create the simplification sequence. 
    1077                                                 createSimplificationSequence(); 
     1077                                                //createSimplificationSequence(); 
    10781078 
    10791079                                                //      Show build process. 
     
    11201120                                        { 
    11211121                                                //      Create the simplification sequence. 
    1122                                                 createSimplificationSequence(); 
     1122                                                //createSimplificationSequence(); 
    11231123                                                 
    1124                                                 delete  mMeshSimplifier; 
     1124                                                //delete        mMeshSimplifier; 
    11251125                                                geoMeshView->restoreContext(); 
    11261126 
     
    12111211 
    12121212                                //      Simplification sequence. 
    1213                                 oMeshSimpSequence = new MeshSimplificationSequence(); 
     1213                                //oMeshSimpSequence = new MeshSimplificationSequence(); 
    12141214 
    12151215                                //      Loads a simplification sequence file. 
    1216                                 oMeshSimpSequence->Load(Serializer("SimplifSequence.txt",Serializer::READ)); 
     1216                                //oMeshSimpSequence->Load(Serializer("SimplifSequence.txt",Serializer::READ)); 
     1217 
     1218                                //      Simplification sequence. 
     1219                                oMeshSimpSequence =     mMeshSimplifier->GetSimplificationSequence(); 
    12171220 
    12181221                                //      If the simplification sequence and the mesh exist. 
     
    12241227                                                        progress_function); 
    12251228 
    1226 //                                              oSerializer     = new Serializer(file_name,Serializer::Mode::WRITE); 
    1227  
    1228                     oLodStrip->UpdateMesh(); 
     1229                                        oLodStrip->UpdateMesh(); 
    12291230 
    12301231                                        //      Deletes the previous mesh. 
     
    12431244 
    12441245                                        mesh_saver      =       new     GeoMeshSaver(); 
    1245 //                                      file_name[strlen(file_name) - 4]        =       '\0'; 
    1246                                          
     1246                                        //                                      file_name[strlen(file_name) - 4]        =       '\0'; 
     1247 
    12471248                                        mesh_saver->leavesSubMesh=idMeshLeaves; 
    12481249                                        mesh_saver->leavesVB=origSubMeshVB; 
     
    12521253                                        delete  mesh_saver; 
    12531254                                        oLodStrip->Save(file_name); 
     1255 
     1256                                        //      Delete simplified mesh. 
     1257                                        delete  mMeshSimplifier; 
    12541258                                        //      Close file. 
    1255 //                                              delete  oSerializer;                             
     1259                                        //                                              delete  oSerializer;                             
    12561260                                } 
    12571261                                else 
     
    12621266 
    12631267                                //      Deletes the siplification sequence object. 
    1264                                 delete  oMeshSimpSequence; 
     1268                                //delete        oMeshSimpSequence; 
    12651269 
    12661270                                if (mApplicationState==LODTREES_AUTO) 
     
    21452149         
    21462150        secsimpl        =       mMeshSimplifier->GetSimplificationSequence(); 
    2147          
    2148         secsimpl->putMeshName(nombremesh); // Nombre del mesh para guardar la secuencia de simplificación 
     2151 
     2152        // Nombre del mesh para guardar la secuencia de simplificación. 
     2153        secsimpl->putMeshName(nombremesh);  
    21492154        secsimpl->Save(Geometry::Serializer("SimplifSequence.txt",Serializer::WRITE)); 
    2150  
    2151         //delete        secsimpl; 
    21522155} 
    21532156 
     
    23252328        { 
    23262329                delete  lodStripsLib; 
     2330                delete  lod_index_data; 
    23272331        } 
    23282332 
    23292333        //      New lod strips object. 
    2330         lodStripsLib    =       new     LodStripsLibrary(loddata, geomesh); 
     2334        lod_index_data  =       new GeoToolIndexData(geomesh->mSubMeshCount); 
     2335        lodStripsLib    =       new     LodStripsLibrary(loddata, geomesh, lod_index_data); 
    23312336 
    23322337        //      Sets the slider range. 
     
    23482353        //      If there is no lod strips object. 
    23492354        if (lodTreeLib) 
     2355        { 
    23502356                delete  lodTreeLib; 
     2357                delete  lod_index_data; 
     2358        } 
    23512359 
    23522360        //      New lod strips object. 
    23532361 
    2354         lodTreeLib = new Geometry::LodTreeLibrary(lodstripsdata,treesimpseq,geomesh/*,ileafSubMesh*/); 
     2362        lod_index_data  =       new GeoToolIndexData(geomesh->mSubMeshCount); 
     2363        lodTreeLib = new Geometry::LodTreeLibrary(lodstripsdata,treesimpseq,geomesh,lod_index_data); 
    23552364 
    23562365        //      Sets the slider range. 
     
    26692678 
    26702679                                { 
    2671                                         mMetricLabel    = new fltk::Output(26, 28, 5, 25, "Metric"); 
     2680                                        mMetricLabel    = new fltk::Output(26, 28, 0, 25, "Metric"); 
    26722681                                        fltk::Output* o =       mMetricLabel; 
    26732682                                        o->set_vertical(); 
     
    27152724 
    27162725                                { 
    2717                                         mMeshReductionLabel     = new fltk::Output(26, 124, 5, 25, "Mesh Reduction"); 
     2726                                        mMeshReductionLabel     = new fltk::Output(26, 124, 0, 25, "Mesh Reduction"); 
    27182727                                        fltk::Output* o =       mMeshReductionLabel; 
    27192728                                        o->set_vertical(); 
Note: See TracChangeset for help on using the changeset viewer.