Ignore:
Timestamp:
03/30/07 11:38:28 (17 years ago)
Author:
gumbau
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimplifier.cpp

    r2291 r2300  
    4242 
    4343//------------------------------------------------------------------------- 
     44//      Erase submeshes that have not indices. 
     45//------------------------------------------------------------------------- 
     46void    MeshSimplifier::eraseVoidSubMeshes(Mesh *geoMesh) 
     47{ 
     48        SubMesh *geosubmesh; 
     49        size_t  valid_submesh_count; 
     50        size_t  submesh; 
     51 
     52        valid_submesh_count     =       0; 
     53 
     54        //      For each submesh. 
     55        for     (size_t i       =       0; i < geoMesh->mSubMeshCount;  i++) 
     56        { 
     57                //      Debug. 
     58                cout    <<      "Indices of submesh " 
     59                                        <<      i 
     60                                        <<      ": " 
     61                                        <<      geoMesh->mSubMesh[i].mIndexCount 
     62                                        <<      endl; 
     63 
     64                if ((geoMesh->mSubMesh[i].mIndexCount > 0) 
     65                                || 
     66                                (indexMeshLeaves == i)) 
     67                { 
     68                        valid_submesh_count++; 
     69                } 
     70        } 
     71 
     72        //      Reassign submesh count. 
     73        geoMesh->mSubMeshCount  =       valid_submesh_count; 
     74 
     75        //      Reserve memory for valid submeshes. 
     76        geosubmesh      =       new     SubMesh[valid_submesh_count]; 
     77 
     78        submesh =       0; 
     79         
     80        //      For each submesh. 
     81        for (size_t i = 0; i < geoMesh->mSubMeshCount; i++) 
     82        { 
     83                //      If leaves submesh is found. 
     84                if (indexMeshLeaves == i) 
     85                { 
     86                        geosubmesh[i].mStripCount       =       0; 
     87                        geosubmesh[i].mStrip                    =       NULL; 
     88 
     89                        geosubmesh[i].mSharedVertexBuffer       =       false; 
     90 
     91                        strcpy( geosubmesh[i].mMaterialName, 
     92                                        mInitialMesh->mSubMesh[i].mMaterialName); 
     93 
     94                        //      Copy submesh bones. 
     95                        if (!mInitialMesh->mSubMesh[i].mBones.empty()) 
     96                        { 
     97                                for (   size_t j = 0; 
     98                                                j < mInitialMesh->mSubMesh[i].mBones.size(); 
     99                                                j++) 
     100                                { 
     101                                        geosubmesh[i].mBones.push_back(mInitialMesh-> 
     102                                                        mSubMesh[i].mBones[j]); 
     103                                } 
     104                        } 
     105 
     106                        //      Leaves mesh. 
     107                        geosubmesh[i].mIndexCount       =        
     108                                mInitialMesh->mSubMesh[i].mIndexCount; 
     109 
     110                        geosubmesh[i].mIndex    = 
     111                                new Geometry::Index[geosubmesh[i].mIndexCount]; 
     112 
     113                        memcpy( geosubmesh[i].mIndex, 
     114                                        mInitialMesh->mSubMesh[i].mIndex, 
     115                                        mInitialMesh->mSubMesh[i].mIndexCount * sizeof(Index)); 
     116 
     117                        //      Copy the leaves submesh vertices. 
     118                        geosubmesh[i].mVertexBuffer     = 
     119                                mInitialMesh->mSubMesh[i].mVertexBuffer->Clone(); 
     120 
     121                        //      Next valid submesh. 
     122                        submesh++; 
     123                } 
     124                else if (geoMesh->mSubMesh[i].mIndexCount > 0) 
     125                { 
     126                        geosubmesh[submesh].mSharedVertexBuffer = 
     127                                                                        geoMesh->mSubMesh[i].mSharedVertexBuffer; 
     128 
     129                        geosubmesh[submesh].mVertexBuffer       =       geoMesh->mVertexBuffer; 
     130 
     131                        geosubmesh[submesh].mType                               =       geoMesh->mSubMesh[i].mType; 
     132 
     133                        geosubmesh[submesh].mStripCount =       geoMesh->mSubMesh[i].mStripCount; 
     134 
     135                        geosubmesh[submesh].mIndexCount =       geoMesh->mSubMesh[i].mIndexCount; 
     136 
     137                        //      Reserve memory for indices. 
     138                        geosubmesh[submesh].mIndex      = 
     139                                                                                                        new Index[geosubmesh[submesh].mIndexCount]; 
     140 
     141                        //      Copy indices. 
     142                        memcpy( geosubmesh[submesh].mIndex, 
     143                                        geoMesh->mSubMesh[i].mIndex, 
     144                                        geoMesh->mSubMesh[i].mIndexCount * sizeof(Index)); 
     145 
     146                        //      Reserve memory for array of strips. 
     147                        geosubmesh[submesh].mStrip      = 
     148                                new Index*[geoMesh->mSubMesh[submesh].mStripCount]; 
     149 
     150                        //      Copy strip list of the submesh. 
     151                        for (size_t j = 0; j < geoMesh->mSubMesh[i].mStripCount; j++) 
     152                        { 
     153                                geosubmesh[submesh].mStrip[j]   =       geoMesh->mSubMesh[i].mStrip[j]; 
     154                        } 
     155 
     156                        strcpy( geosubmesh[submesh].mMaterialName, 
     157                                        geoMesh->mSubMesh[i].mMaterialName); 
     158 
     159                        for (size_t     j       =       0;      j < geoMesh->mSubMesh[i].mBones.size(); j++) 
     160                        { 
     161                                geosubmesh[submesh].mBones 
     162                                        .push_back(geoMesh->mSubMesh[i].mBones[j]); 
     163                        } 
     164 
     165                        //      Next valid submesh. 
     166                        submesh++; 
     167                } 
     168        } 
     169 
     170        //      Delete submeshes. 
     171        delete  []geoMesh->mSubMesh; 
     172 
     173        geoMesh->mSubMesh       =       geosubmesh; 
     174} 
     175 
     176//------------------------------------------------------------------------- 
    44177// Returns the simplified mesh. 
    45178//------------------------------------------------------------------------- 
    46179Mesh *  MeshSimplifier::GetMesh() 
    47180{ 
     181        //      Delete void submeshes. 
     182        eraseVoidSubMeshes(mGeoMesh); 
     183 
    48184        return mGeoMesh; 
    49185} 
     
    146282// method to perform an image based simplification. 
    147283//------------------------------------------------------------------------- 
    148 void GeometryBasedSimplifier::Simplify(Real paramlod) 
     284int     GeometryBasedSimplifier::Simplify(Real paramlod) 
    149285{ 
    150286        SimplificationMethod *m_qslim   =       new SimplificationMethod(mInitialMesh); 
     
    157293 
    158294        delete  m_qslim; 
     295 
     296        return  NO_GL_ERROR; 
    159297} 
    160298 
     
    165303// perform an image based simplification. 
    166304//------------------------------------------------------------------------- 
    167 void GeometryBasedSimplifier::Simplify(uint32 numvertices) 
     305int     GeometryBasedSimplifier::Simplify(uint32 numvertices) 
    168306{ 
    169307        SimplificationMethod *m_qslim   =       new SimplificationMethod(mInitialMesh); 
     
    176314 
    177315        delete m_qslim; 
     316 
     317        return  NO_GL_ERROR; 
    178318} 
    179319 
     
    235375        //      Loads the vmi mesh structure for a geometry mesh given. 
    236376        VMI::mesh = initMeshStructure(mGeoMesh); 
     377} 
     378 
     379//      Init VMI options. 
     380int     ViewPointDrivenSimplifier::init(void) 
     381{ 
     382        int     error; 
    237383 
    238384        // RGB and Alpha. 
     
    245391        glewInit(); 
    246392 
    247         VMI::init(); 
     393        error   =       VMI::init(); 
    248394 
    249395        if (VMI::bLoadCamerasFromFile == GL_FALSE) 
     
    256402 
    257403        VMI::initialIs  =       VMI::initIs(VMI::numCameras); 
     404 
     405        return  error; 
    258406} 
    259407 
     
    273421///     LOD factor in a range of [0,1]. Implements the 
    274422///     Simplifier::Simplify method to perform an image based simplification. 
    275 void ViewPointDrivenSimplifier::Simplify(Real percent) 
    276 { 
     423int ViewPointDrivenSimplifier::Simplify(Real percent) 
     424{ 
     425        int error; 
     426 
     427        error   =        init(); 
     428 
    277429        VMI::numDemandedTriangles = (int)(VMI::mesh->numTriangles * percent); 
    278430 
     
    284436        } 
    285437 
    286         VMI::display(); 
    287  
    288         //      Cleans firts simplification. 
    289         VMI::freeMemory(); 
    290  
    291         VMI::mesh =     initMeshStructure(mInitialMesh); 
    292  
    293         VMI::contractInitialMesh(VMI::mesh); 
    294  
    295         //      Load a geometry mesh for vmi mesh. 
    296         loadMesh(); 
    297          
    298         GetMeshSimpSequence(); 
    299  
    300         //      Sort bones. 
    301         bonesReassignament(); 
     438        if (error == NO_GL_ERROR) 
     439        { 
     440                VMI::display(); 
     441 
     442                //      Cleans firts simplification. 
     443                VMI::freeMemory(); 
     444 
     445                VMI::mesh =     initMeshStructure(mInitialMesh); 
     446 
     447                VMI::contractInitialMesh(VMI::mesh); 
     448 
     449                //      Load a geometry mesh for vmi mesh. 
     450                loadMesh(); 
     451 
     452                GetMeshSimpSequence(); 
     453 
     454                //      Sort bones. 
     455                bonesReassignament(); 
     456        } 
     457 
     458        return  error; 
    302459} 
    303460 
     
    308465///     an image based simplification. 
    309466//------------------------------------------------------------------------- 
    310 void ViewPointDrivenSimplifier::Simplify(uint32 numVertices) 
     467int ViewPointDrivenSimplifier::Simplify(uint32 numVertices) 
    311468{ 
    312469        float   percent; 
     470        int     error; 
     471 
     472        error   =        init(); 
    313473 
    314474        percent =       (numVertices    *       100.0) / VMI::mesh->numVertices; 
    315475 
    316         VMI::numDemandedTriangles = (int)(VMI::mesh->numTriangles * (percent / 100)); 
     476        VMI::numDemandedTriangles = (int)(VMI::mesh->numTriangles 
     477                                                                                                                                                * 
     478                                                                                                                                                (percent / 100)); 
    317479 
    318480        if ((VMI::numDemandedTriangles == 0) 
     
    323485        } 
    324486 
    325         VMI::display(); 
    326  
    327         //      Cleans firts simplification. 
    328         VMI::freeMemory(); 
    329  
    330         VMI::mesh =     initMeshStructure(mInitialMesh); 
    331  
    332         VMI::contractInitialMesh(VMI::mesh); 
    333          
    334         //      Load a geometry mesh for vmi mesh. 
    335         loadMesh(); 
    336          
    337         GetMeshSimpSequence(); 
    338  
    339         //      Sort bones. 
    340         bonesReassignament(); 
     487        if (error == NO_GL_ERROR) 
     488        { 
     489                VMI::display(); 
     490 
     491                //      Cleans firts simplification. 
     492                VMI::freeMemory(); 
     493 
     494                VMI::mesh =     initMeshStructure(mInitialMesh); 
     495 
     496                VMI::contractInitialMesh(VMI::mesh); 
     497 
     498                //      Load a geometry mesh for vmi mesh. 
     499                loadMesh(); 
     500 
     501                GetMeshSimpSequence(); 
     502 
     503                //      Sort bones. 
     504                bonesReassignament(); 
     505        } 
     506 
     507        return  error; 
    341508} 
    342509 
Note: See TracChangeset for help on using the changeset viewer.