Ignore:
Timestamp:
06/20/06 13:02:00 (18 years ago)
Author:
gumbau
Message:
 
Location:
GTP/trunk/Lib/Geom/shared/GTGeometry
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoMeshSimplifier.h

    r1007 r1024  
    2222        -# The simplified mesh, contained in a Geometry::Mesh object. 
    2323        -# Simplification sequence, represented by a Geometry::MeshSimplificationSequence object. 
    24          
    2524        */ 
    2625 
     
    6766                        //      Progress bar function. 
    6867                        Geometry::TIPOFUNC      mUPB; 
     68 
     69                        //      Sort mesh bones. 
     70                        void    sortBones(); 
    6971        }; 
    7072 
     
    113115                // Returns the simplified mesh. 
    114116                //Mesh *GetMesh(); 
    115  
    116  
    117117        }; 
    118  
    119118 
    120119        /// Implementation of a simplification algorithm based on geometry information. 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimplifier.cpp

    r1014 r1024  
    5959{ 
    6060        return msimpsequence; 
     61} 
     62 
     63//--------------------------------------------------------------------------- 
     64//      Sort mesh bones. 
     65//--------------------------------------------------------------------------- 
     66void    MeshSimplifier::sortBones() 
     67{ 
     68        Mesh                                                                    *mesh_copy; 
     69        int                                                                             n; 
     70        int                                                                     o; 
     71        int                                                                             p; 
     72        VertexBoneAssignment    assign; 
     73        VertexBuffer                                    *mesh_vb; 
     74        VertexBuffer                                    *undo_vb; 
     75        SubMesh                                                         *geosubmesh; 
     76        SubMesh                                                         *undosubmesh; 
     77         
     78        //      Gets a copy of the mesh. 
     79        mesh_copy               =       new Mesh(); 
     80        *mesh_copy      =       *mGeoMesh; 
     81         
     82        //      For each submesh. 
     83        for (size_t     i       =       0; i < mGeoMesh->mSubMeshCount; i++) 
     84        { 
     85                geosubmesh      =       &mGeoMesh->mSubMesh[i]; 
     86                undosubmesh     =       &mesh_copy->mSubMesh[i]; 
     87                 
     88                //      If there is submesh bones. 
     89                if (!geosubmesh->mBones.empty()) 
     90                { 
     91                        assign.boneIndex        =       0; 
     92                        assign.weight                   =       1; 
     93 
     94                        geosubmesh->mBones.clear(); 
     95 
     96                        for (int        m       =       0;      m < geosubmesh->mVertexBuffer->mVertexCount;    m++) 
     97                        { 
     98                                assign.vertexIndex      =       m; 
     99                                 
     100                                geosubmesh->mBones.push_back(assign); 
     101                        } 
     102 
     103                        //      Change bones. 
     104                        for (int        m = 0;  m < geosubmesh->mBones.size();  m++) 
     105                        { 
     106                                n       =       geosubmesh->mBones[m].vertexIndex; 
     107 
     108                                //      Initialize o. 
     109                                o       =       0; 
     110 
     111                                mesh_vb =       geosubmesh->mVertexBuffer; 
     112                                undo_vb =       undosubmesh->mVertexBuffer; 
     113 
     114                                while (!( 
     115                                                        (mesh_vb->mPosition[n].x == undo_vb->mPosition[o].x) 
     116                                                        && 
     117                                                        (mesh_vb->mPosition[n].y == undo_vb->mPosition[o].y) 
     118                                                        && 
     119                                                        (mesh_vb->mPosition[n].z == undo_vb->mPosition[o].z) 
     120                                                        )) 
     121                                { 
     122                                        o++; 
     123                                } 
     124 
     125                                //      Initialize p. 
     126                                p       =       0; 
     127 
     128                                while (undosubmesh->mBones[p].vertexIndex != o) 
     129                                { 
     130                                        p++; 
     131                                } 
     132 
     133                                //      Same bone for 'm' and 'p'. 
     134                                geosubmesh->mBones[m].boneIndex =       undosubmesh->mBones[p].boneIndex; 
     135                        } 
     136                } 
     137        } 
     138 
     139        //      Delete copy of the mesh. 
     140        delete  mesh_copy; 
    61141} 
    62142 
     
    306386 
    307387//--------------------------------------------------------------------------- 
    308 //      Init vmi mesh structure for a geometry mesh given. 
     388//      Class for join triangle holes. 
     389//--------------------------------------------------------------------------- 
     390class _coord_ 
     391{ 
     392        public: 
     393                float x,y,z; 
     394                inline _coord_( float x =       0.0f, 
     395                                                                                float y =       0.0f, 
     396                                                                                float z =       0.0f) 
     397                { this->x = x; this->y = y; this->z = z; } 
     398                 
     399                inline _coord_(const _coord_ &f) 
     400                { 
     401                        x       =       f.x; 
     402                        y=f.y; 
     403                        z=f.z; 
     404                } 
     405                 
     406                inline _coord_ & operator=(const _coord_ &f) 
     407                { 
     408                        x       =       f.x; 
     409                        y       =       f.y; 
     410                        z       =       f.z; 
     411                         
     412                        return *this; 
     413                } 
     414                 
     415                inline bool operator<(const _coord_ &f) const 
     416                { 
     417                        if (x<f.x-0.0001) return true; 
     418                        if (x>f.x+0.0001) return false; 
     419                        if (y<f.y-0.0001) return true; 
     420                        if (y>f.y+0.0001) return false; 
     421                        if (z<f.z-0.0001) return true; 
     422                        if (z>f.z+0.0001) return false; 
     423                         
     424                        return  false; 
     425                } 
     426}; 
     427 
     428//--------------------------------------------------------------------------- 
     429//      Initialize the mesh of VMI module. 
    309430//--------------------------------------------------------------------------- 
    310431VMI::Mesh *     ViewPointDrivenSimplifier::initMeshStructure(Mesh       *geoMesh) 
     
    360481 
    361482        printf("Adding vertices..."); 
    362          
    363483        //      Fill up vertices. 
     484        std::map<_coord_, int> uniquevertices; 
     485        std::map<int, int> newindices; 
    364486        for (i = 0; i < vertex_buffer->mVertexCount; i++) 
    365487        { 
     488                _coord_ vertex_aux; 
     489                vertex_aux.x= vertex_buffer->mPosition[i].x; 
     490                vertex_aux.y= vertex_buffer->mPosition[i].y; 
     491                vertex_aux.z= vertex_buffer->mPosition[i].z; 
     492                //New index 
     493                if (uniquevertices.find(vertex_aux)==uniquevertices.end()) 
     494                { 
     495                        uniquevertices[vertex_aux]= i; 
     496                        newindices[i]= i; 
     497 
     498                        VMI::INTVECTOR intvectoraux; 
     499                        intvectoraux.push_back(i); 
     500                        VMI::inversemap[i]= intvectoraux; 
     501 
     502                }else//The map of unique vertices already contains this vertex 
     503                { 
     504                        int newindex= uniquevertices[vertex_aux]; 
     505                        newindices[i]= newindex; 
     506 
     507                        VMI::inversemap[newindex].push_back(i);; 
     508                } 
     509 
    366510                // Vertices start at 0. 
    367511                vmi_mesh->vertices[i].x = vertex_buffer->mPosition[i].x; 
     
    394538                        vmi_mesh->triangles[index].id                           = index; 
    395539                        vmi_mesh->triangles[index].submesh              = submesh; 
    396                         vmi_mesh->triangles[index].indices[0] = geosubmesh->mIndex[(3 * i)]; 
    397                         vmi_mesh->triangles[index].indices[1] = geosubmesh->mIndex[(3 * i) + 1]; 
    398                         vmi_mesh->triangles[index].indices[2] = geosubmesh->mIndex[(3 * i) + 2]; 
     540                        vmi_mesh->triangles[index].indices[0] = newindices[geosubmesh->mIndex[(3 * i)]]; 
     541                        vmi_mesh->triangles[index].indices[1] = newindices[geosubmesh->mIndex[(3 * i) + 1]]; 
     542                        vmi_mesh->triangles[index].indices[2] = newindices[geosubmesh->mIndex[(3 * i) + 2]]; 
    399543 
    400544                        vmi_mesh->triangles[index].area = computeTriangleArea(vmi_mesh->vertices,  
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/change.h

    r1009 r1024  
    44#include        "mesh.h" 
    55#include        <vector> 
     6#include        <map> 
    67 
    78namespace       VMI 
    89{ 
     10        typedef std::vector<int> INTVECTOR; 
     11 
    912        typedef struct change 
    1013        { 
     
    6366        //      Save simplification sequence in Geometry Game Tools format. 
    6467        extern void     saveSimplificationSequence(Change       *c); 
     68 
     69        extern std::map<int, INTVECTOR> inversemap; 
    6570} 
    6671 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/change.cpp

    r1009 r1024  
    332332} 
    333333 
     334namespace VMI{ 
     335std::map<int, INTVECTOR> inversemap; 
     336} 
     337 
    334338//      Save simplification sequence in Geometry Game Tools format. 
    335339extern void     VMI::saveSimplificationSequence(Change  *c) 
    336340{ 
    337         vmiStep step; 
    338         step.mV0        =       c->u; 
    339         step.mV1        =       c->v; 
    340  
    341         //      If only one triangle has been deleted. 
    342         if (c->numDel == 1) 
    343         { 
    344                 step.mT0        =       c->deleted[0].id; 
    345                 step.mT1        =       c->deleted[0].id; 
    346         } 
    347         //      If two triangles have been deleted. 
    348         else 
    349         { 
    350                 step.mT0        =       c->deleted[0].id; 
    351                 step.mT1        =       c->deleted[1].id; 
    352         } 
    353  
    354         step.x  =       0.0; 
    355         step.y  =       0.0; 
    356         step.z  =       0.0; 
    357  
    358         //      Write obligatory field. 
    359         step.obligatory =       0; 
    360  
    361         //      List of new triangles. 
    362         //      For each modified triangle. 
    363         for (int        i = 0;  i < c->numMod;  i++) 
    364         { 
    365                 step.mModfaces.push_back(c->modified[i].id); 
    366         } 
    367  
    368         //      Add step to list of changes. 
    369         mVMISteps.push_back(step); 
    370 } 
    371  
     341 
     342        int stepnum= 1; 
     343        for(INTVECTOR::iterator it= inversemap[c->u].begin(); it!=inversemap[c->u].end(); it++) 
     344        { 
     345                vmiStep step; 
     346                step.mV0        =       *it; 
     347                step.mV1        =       c->v; 
     348 
     349                //      If only one triangle has been deleted. 
     350                if (c->numDel == 1) 
     351                { 
     352                        step.mT0        =       c->deleted[0].id; 
     353                        step.mT1        =       c->deleted[0].id; 
     354                } 
     355                //      If two triangles have been deleted. 
     356                else 
     357                { 
     358                        step.mT0        =       c->deleted[0].id; 
     359                        step.mT1        =       c->deleted[1].id; 
     360                } 
     361 
     362                step.x  =       0.0; 
     363                step.y  =       0.0; 
     364                step.z  =       0.0; 
     365 
     366                //      Write obligatory field. 
     367                if (stepnum==inversemap[c->u].size()) 
     368                        step.obligatory =       0; 
     369                else 
     370                        step.obligatory =       1; 
     371                stepnum++; 
     372 
     373                //      List of new triangles. 
     374                //      For each modified triangle. 
     375                for (int        i = 0;  i < c->numMod;  i++) 
     376                { 
     377                        step.mModfaces.push_back(c->modified[i].id); 
     378                } 
     379 
     380                //      Add step to list of changes. 
     381                mVMISteps.push_back(step); 
     382        } 
     383} 
Note: See TracChangeset for help on using the changeset viewer.