Changeset 2300


Ignore:
Timestamp:
03/30/07 11:38:28 (17 years ago)
Author:
gumbau
Message:
 
Location:
GTP/trunk/Lib/Geom/shared
Files:
8 edited

Legend:

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

    r2291 r2300  
    2424                        float x,y,z; 
    2525                        inline _coord_( float x =       0.0f, 
    26                                         float y =       0.0f, 
    27                                         float z =       0.0f) 
    28                         { this->x = x; this->y = y; this->z = z; } 
     26                                                                                        float y =       0.0f, 
     27                                                                                        float z =       0.0f) 
     28                        { 
     29                                this->x = x; 
     30                                this->y = y; 
     31                                this->z = z; 
     32                        } 
    2933 
    3034                        inline _coord_(const _coord_ &f) 
    31                         { 
    32                                 x       =       f.x; 
    33                                 y=f.y; 
    34                                 z=f.z; 
    35                         } 
    36  
    37                         inline _coord_ & operator=(const _coord_ &f) 
    3835                        { 
    3936                                x       =       f.x; 
    4037                                y       =       f.y; 
    4138                                z       =       f.z; 
    42  
    43                                 return *this; 
     39                        } 
     40 
     41                        inline _coord_ & operator=(const _coord_ &f) 
     42                        { 
     43                                x       =       f.x; 
     44                                y       =       f.y; 
     45                                z       =       f.z; 
     46 
     47                                return  *this; 
    4448                        } 
    4549 
     
    122126 
    123127                        /// Starts the simplification process. Receives as a parameter the LOD factor in a range of [0,1]. This is a pure virtual method and must be overloaded in a derived class that implements a simplification algorithm. 
    124                         virtual void Simplify(Geometry::Real)=0; 
     128                        virtual int Simplify(Geometry::Real)=0; 
    125129 
    126130                        /// Starts the simplification process. Receives as a parameter the number of vertices of the resulting mesh. This is a pure virtual method and must be overloaded in a derived class that implements a simplification algorithm. 
    127                         virtual void Simplify(Geometry::uint32)=0; 
     131                        virtual int Simplify(Geometry::uint32)=0; 
    128132 
    129133                        /// Returns the simplified mesh. 
     
    150154                        //      Sort mesh bones. 
    151155                        void    sortBones(); 
     156 
     157                private: 
     158 
     159                        void    eraseVoidSubMeshes(Mesh *geoMesh); 
    152160        }; 
    153161 
     
    190198                        void bonesReassignament(); 
    191199 
     200                        //      Init VMI options. 
     201                        int     init(void); 
     202 
    192203                public: 
    193204 
     
    206217 
    207218                        /// Starts the simplification process. Receives as a parameter the LOD factor in a range of [0,1]. Implements the Simplifier::Simplify method to perform an image based simplification. 
    208                         void Simplify(Geometry::Real); 
     219                        int     Simplify(Geometry::Real); 
    209220 
    210221                        /// Starts the simplification process. Receives as a parameter the number of vertices of the resulting mesh. Implements the Simplifier::Simplify method to perform an image based simplification. 
    211                         void Simplify(Geometry::uint32); 
     222                        int Simplify(Geometry::uint32); 
    212223 
    213224                        // Returns the simplified mesh. 
     
    234245 
    235246                        /// Starts the simplification process. Receives as a parameter the LOD factor in a range of [0,1]. Implements the Simplifier::Simplify method to perform an image based simplification. 
    236                         void Simplify(Geometry::Real); 
     247                        int     Simplify(Geometry::Real); 
    237248 
    238249                        /// Starts the simplification process. Receives as a parameter the number of vertices of the resulting mesh. Implements the Simplifier::Simplify method to perform an image based simplification. 
    239                         void Simplify(Geometry::uint32); 
     250                        int Simplify(Geometry::uint32); 
    240251        }; 
    241252} // end of Geometry namespace; 
  • 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 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/SimplificationMethod.cpp

    r2291 r2300  
    14651465 
    14661466//------------------------------------------------------------------------- 
    1467 //      Erase submeshes that have not indices. 
    1468 //------------------------------------------------------------------------- 
    1469 void    SimplificationMethod::eraseVoidSubMeshes(Mesh   *geoMesh) 
    1470 { 
    1471         SubMesh *geosubmesh; 
    1472         size_t  valid_submesh_count; 
    1473         size_t  submesh; 
    1474  
    1475         valid_submesh_count     =       0; 
    1476  
    1477         //      For each submesh. 
    1478         for     (size_t i       =       0; i < geoMesh->mSubMeshCount;  i++) 
    1479         { 
    1480                 //      Debug. 
    1481                 cout    <<      "Indices of submesh " 
    1482                                         <<      i 
    1483                                         <<      ": " 
    1484                                         <<      geoMesh->mSubMesh[i].mIndexCount 
    1485                                         <<      endl; 
    1486  
    1487                 if ((geoMesh->mSubMesh[i].mIndexCount > 0) 
    1488                                 || 
    1489                                 (indexMeshLeaves == i)) 
    1490                 { 
    1491                         valid_submesh_count++; 
    1492                 } 
    1493         } 
    1494  
    1495         //      Reassign submesh count. 
    1496         geoMesh->mSubMeshCount  =       valid_submesh_count; 
    1497  
    1498         //      Reserve memory for valid submeshes. 
    1499         geosubmesh      =       new     SubMesh[valid_submesh_count]; 
    1500  
    1501         submesh =       0; 
    1502          
    1503         //      For each submesh. 
    1504         for (size_t i = 0; i < geoMesh->mSubMeshCount; i++) 
    1505         { 
    1506                 //      If leaves submesh is found. 
    1507                 if (indexMeshLeaves == i) 
    1508                 { 
    1509                         geosubmesh[i].mStripCount       =       0; 
    1510                         geosubmesh[i].mStrip                    =       NULL; 
    1511  
    1512                         geosubmesh[i].mSharedVertexBuffer       =       false; 
    1513  
    1514                         strcpy( geosubmesh[i].mMaterialName, 
    1515                                         mInitialMesh->mSubMesh[i].mMaterialName); 
    1516  
    1517                         //      Copy submesh bones. 
    1518                         if (!mInitialMesh->mSubMesh[i].mBones.empty()) 
    1519                         { 
    1520                                 for (   size_t j = 0; 
    1521                                                 j < mInitialMesh->mSubMesh[i].mBones.size(); 
    1522                                                 j++) 
    1523                                 { 
    1524                                         geosubmesh[i].mBones.push_back(mInitialMesh-> 
    1525                                                         mSubMesh[i].mBones[j]); 
    1526                                 } 
    1527                         } 
    1528  
    1529                         //      Leaves mesh. 
    1530                         geosubmesh[i].mIndexCount       =        
    1531                                 mInitialMesh->mSubMesh[i].mIndexCount; 
    1532  
    1533                         geosubmesh[i].mIndex    = 
    1534                                 new Geometry::Index[geosubmesh[i].mIndexCount]; 
    1535  
    1536                         memcpy( geosubmesh[i].mIndex, 
    1537                                         mInitialMesh->mSubMesh[i].mIndex, 
    1538                                         mInitialMesh->mSubMesh[i].mIndexCount * sizeof(Index)); 
    1539  
    1540                         //      Copy the leaves submesh vertices. 
    1541                         geosubmesh[i].mVertexBuffer     = 
    1542                                 mInitialMesh->mSubMesh[i].mVertexBuffer->Clone(); 
    1543  
    1544                         //      Next valid submesh. 
    1545                         submesh++; 
    1546                 } 
    1547                 else if (geoMesh->mSubMesh[i].mIndexCount > 0) 
    1548                 { 
    1549                         geosubmesh[submesh].mSharedVertexBuffer = 
    1550                                                                         geoMesh->mSubMesh[i].mSharedVertexBuffer; 
    1551  
    1552                         geosubmesh[submesh].mVertexBuffer       =       geoMesh->mVertexBuffer; 
    1553  
    1554                         geosubmesh[submesh].mType                               =       geoMesh->mSubMesh[i].mType; 
    1555  
    1556                         geosubmesh[submesh].mStripCount =       geoMesh->mSubMesh[i].mStripCount; 
    1557  
    1558                         geosubmesh[submesh].mIndexCount =       geoMesh->mSubMesh[i].mIndexCount; 
    1559  
    1560                         //      Reserve memory for indices. 
    1561                         geosubmesh[submesh].mIndex      = 
    1562                                                                                                         new Index[geosubmesh[submesh].mIndexCount]; 
    1563  
    1564                         //      Copy indices. 
    1565                         memcpy( geosubmesh[submesh].mIndex, 
    1566                                         geoMesh->mSubMesh[i].mIndex, 
    1567                                         geoMesh->mSubMesh[i].mIndexCount * sizeof(Index)); 
    1568  
    1569                         //      Reserve memory for array of strips. 
    1570                         geosubmesh[submesh].mStrip      = 
    1571                                 new Index*[geoMesh->mSubMesh[submesh].mStripCount]; 
    1572  
    1573                         //      Copy strip list of the submesh. 
    1574                         for (size_t j = 0; j < geoMesh->mSubMesh[i].mStripCount; j++) 
    1575                         { 
    1576                                 geosubmesh[submesh].mStrip[j]   =       geoMesh->mSubMesh[i].mStrip[j]; 
    1577                         } 
    1578  
    1579                         strcpy( geosubmesh[submesh].mMaterialName, 
    1580                                         geoMesh->mSubMesh[i].mMaterialName); 
    1581  
    1582                         for (size_t     j       =       0;      j < geoMesh->mSubMesh[i].mBones.size(); j++) 
    1583                         { 
    1584                                 geosubmesh[submesh].mBones 
    1585                                         .push_back(geoMesh->mSubMesh[i].mBones[j]); 
    1586                         } 
    1587  
    1588                         //      Next valid submesh. 
    1589                         submesh++; 
    1590                 } 
    1591         } 
    1592  
    1593         //      Delete submeshes. 
    1594         delete  []geoMesh->mSubMesh; 
    1595  
    1596         geoMesh->mSubMesh       =       geosubmesh; 
    1597 } 
    1598  
    1599 //------------------------------------------------------------------------- 
    16001467//      Fill up vertices. 
    16011468//------------------------------------------------------------------------- 
     
    18781745Mesh    *       SimplificationMethod::GetMesh() 
    18791746{ 
    1880         //      Delete void submeshes. 
    1881         eraseVoidSubMeshes(mGeoMesh); 
    1882  
    18831747        return  mGeoMesh; 
    18841748} 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/SimplificationMethod.h

    r2291 r2300  
    191191                void    addNewBoneAssignments(); 
    192192 
    193                 void    eraseVoidSubMeshes(Mesh *geoMesh); 
    194  
    195193        public: 
    196194 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/global.h

    r2194 r2300  
    142142extern char filename[MAX_CHAR]; 
    143143 
    144 extern void init(void); 
     144extern int      init(void); 
    145145 
    146146extern void resetProjectedAreas(int **histogram, int numCameras); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/vmi_simplifier.h

    r2127 r2300  
    22#include <stdlib.h> 
    33#include <time.h> 
    4  
    54#include "GL/glew.h" 
    65#ifdef _WIN32 
     
    1514#include "buffers.h" 
    1615 
     16#define NO_GL_ERROR                                             0x00 
     17#define FRAMEBUFFER_ERROR                       0x01 
     18#define VERTEX_BUFFER_ERROR             0x02 
     19#define OCCLUSION_QUERY_ERROR   0x04 
     20#define IMAGING_ERROR                                   0x08 
     21#define MULTITEXTURE_ERROR              0x10 
     22#define SWAP_CONTROL_ERROR              0x20 
     23 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/main.cpp

    r2194 r2300  
    33namespace VMI  
    44{ 
    5 GLMmodel *pmodel = NULL; // The .obj model 
    6  
    7 GLubyte *pixels = NULL; 
    8  
    9 Camera *cameras = NULL; 
    10 int numCameras = 0; 
    11  
    12 Color *colors = NULL; 
    13  
    14 int **histogram = NULL; 
    15 GLuint *queries = NULL; 
    16  
    17 Mesh *mesh = NULL; 
    18  
    19 GLdouble *initialIs = NULL; 
    20  
    21 GLsizei width  = 256, 
    22         height = 256; 
    23  
    24 GLboolean bEnableOffScreen = GL_TRUE, 
    25           bBeQuiet         = GL_FALSE, 
    26           bSaveLog         = GL_FALSE, 
    27           bLoadCamerasFromFile = GL_FALSE, 
    28           bRemoveRedundantVertices = GL_TRUE; 
    29  
    30 int cameraType = 0, 
    31        numDemandedTriangles = 0; 
    32  
    33 GLdouble radius = 1.3, fov = 60.0; 
    34  
    35 char filename[MAX_CHAR] = {'\0'}; 
    36  
    37 GLuint fb, depth_rb, color_tex; 
     5        GLMmodel *pmodel = NULL; // The .obj model 
     6 
     7        GLubyte *pixels = NULL; 
     8 
     9        Camera *cameras = NULL; 
     10        int numCameras = 0; 
     11 
     12        Color *colors = NULL; 
     13 
     14        int **histogram = NULL; 
     15        GLuint *queries = NULL; 
     16 
     17        Mesh *mesh = NULL; 
     18 
     19        GLdouble *initialIs = NULL; 
     20 
     21        GLsizei width  = 256, 
     22                                        height = 256; 
     23 
     24        GLboolean bEnableOffScreen = GL_TRUE, 
     25                                                bBeQuiet         = GL_FALSE, 
     26                                                bSaveLog         = GL_FALSE, 
     27                                                bLoadCamerasFromFile = GL_FALSE, 
     28                                                bRemoveRedundantVertices = GL_TRUE; 
     29 
     30        int cameraType = 0, 
     31                        numDemandedTriangles = 0; 
     32 
     33        GLdouble radius = 1.3, fov = 60.0; 
     34 
     35        char filename[MAX_CHAR] = {'\0'}; 
     36 
     37        GLuint fb, depth_rb, color_tex; 
    3838 
    3939#ifdef VERTEX_ARRAY_INTERLEAVE 
    40 VertexIL *interleave = NULL; 
    41 #endif 
    42  
    43 GLuint vertex_buf = 0, 
    44       color_buf = 0; 
    45  
    46 Vertex_ *buf_vertices = NULL; 
    47 Color   *buf_colors = NULL; 
    48  
    49 int vmiWin = 0; 
    50  
    51 //      For progress update. 
    52 Geometry::TIPOFUNC      mUPB; 
     40        VertexIL *interleave = NULL; 
     41#endif 
     42 
     43        GLuint vertex_buf = 0, 
     44                                color_buf = 0; 
     45 
     46        Vertex_ *buf_vertices = NULL; 
     47        Color   *buf_colors = NULL; 
     48 
     49        int vmiWin = 0; 
     50 
     51        //      For progress update. 
     52        Geometry::TIPOFUNC      mUPB; 
    5353 
    5454} 
     
    5656using namespace VMI; 
    5757 
    58 void VMI::init(void) 
    59 { 
     58int     VMI::init(void) 
     59{ 
     60        //      Initialize error status. 
     61        int     error   =       NO_GL_ERROR; 
     62 
    6063        // Clear color 
    6164        glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 
     
    8184                fprintf(stderr, 
    8285                                                "GL_EXT_framebuffer_object extension is not available!\n"); 
    83                 exit(1); 
     86                 
     87                error   =       error | FRAMEBUFFER_ERROR; 
    8488        } 
    8589        else 
     
    131135                fprintf(stderr, 
    132136                                "GL_ARB_vertex_buffer_object extension is not available!\n"); 
     137 
     138                error   =       error | VERTEX_BUFFER_ERROR; 
    133139        } 
    134140        else 
     
    144150        { 
    145151                fprintf(stderr, 
    146                                 "GL_ARB_occlusion_query extension is not available!\n"); 
     152                                                "GL_ARB_occlusion_query extension is not available!\n"); 
     153 
     154                error   =       error | OCCLUSION_QUERY_ERROR; 
    147155        } 
    148156        else 
     
    158166        { 
    159167                fprintf(stderr,"GL_ARB_imaging extension is not available!\n"); 
     168 
     169                error   =       error | IMAGING_ERROR; 
    160170        } 
    161171 
     
    163173        { 
    164174                fprintf(stderr,"GL_ARB_multitexture extension is not available!\n"); 
     175 
     176                error   =       error | MULTITEXTURE_ERROR; 
    165177        } 
    166178 
     
    169181        { 
    170182                fprintf(stderr,"WGL_EXT_swap_control extension is not available!\n"); 
     183 
     184                error   =       error | SWAP_CONTROL_ERROR; 
    171185        } 
    172186#endif 
     
    180194        // Set a different color for every triangle. 
    181195        setColors4(colors, mesh->currentNumTriangles); 
     196 
     197        return error; 
    182198} 
    183199 
    184200void VMI::applyHWAcceleration(void) { 
    185      
     201 
    186202#ifdef VERTEX_ARRAY_INTERLEAVE 
    187     setupInterleave(mesh, colors); 
     203        setupInterleave(mesh, colors); 
    188204#endif 
    189205#ifdef VERTEX_ARRAY 
    190     setupVertexArray(mesh, colors); 
     206        setupVertexArray(mesh, colors); 
    191207#endif 
    192208#ifdef VERTEX_BUFFER_OBJECTS 
    193     setupVertexBufferObjects(mesh, colors); 
     209        setupVertexBufferObjects(mesh, colors); 
    194210#endif 
    195211 
     
    197213 
    198214void VMI::updateHWAcceleration(Change *c) { 
    199     
     215 
    200216#ifdef VERTEX_ARRAY_INTERLEAVE 
    201     if (interleave != NULL) free(interleave); 
    202     interleave = setupInterleave(mesh, colors); 
     217        if (interleave != NULL) free(interleave); 
     218        interleave = setupInterleave(mesh, colors); 
    203219#endif 
    204220#ifdef VERTEX_ARRAY 
    205     updateVertexArray(mesh, c); 
     221        updateVertexArray(mesh, c); 
    206222#endif 
    207223#ifdef VERTEX_BUFFER_OBJECTS 
    208     updateVertexBufferObjects(mesh, c); 
     224        updateVertexBufferObjects(mesh, c); 
    209225#endif 
    210226 
     
    212228 
    213229void VMI::setOrthographicProjection(void) { 
    214     // Switch to projection mode 
    215     glMatrixMode(GL_PROJECTION); 
    216     // Save previous matrix which contains the  
    217     // settings for the perspective projection 
    218     glPushMatrix(); 
    219     // Reset matrix 
    220     glLoadIdentity(); 
    221     glOrtho(0.0, (GLdouble)HISTOGRAM_SIZE, 0.0, (GLdouble)height, -1.0, 1.0); 
    222     glMatrixMode(GL_MODELVIEW); 
    223     glLoadIdentity(); 
     230        // Switch to projection mode 
     231        glMatrixMode(GL_PROJECTION); 
     232        // Save previous matrix which contains the  
     233        // settings for the perspective projection 
     234        glPushMatrix(); 
     235        // Reset matrix 
     236        glLoadIdentity(); 
     237        glOrtho(0.0, (GLdouble)HISTOGRAM_SIZE, 0.0, (GLdouble)height, -1.0, 1.0); 
     238        glMatrixMode(GL_MODELVIEW); 
     239        glLoadIdentity(); 
    224240} 
    225241 
    226242void VMI::resetPerspectiveProjection(void) { 
    227     // Set the current matrix to GL_PROJECTION 
    228     glMatrixMode(GL_PROJECTION); 
    229     // Restore previous settings 
    230     glPopMatrix(); 
    231     // Get back to GL_MODELVIEW matrix 
    232     glMatrixMode(GL_MODELVIEW); 
    233     glLoadIdentity(); 
     243        // Set the current matrix to GL_PROJECTION 
     244        glMatrixMode(GL_PROJECTION); 
     245        // Restore previous settings 
     246        glPopMatrix(); 
     247        // Get back to GL_MODELVIEW matrix 
     248        glMatrixMode(GL_MODELVIEW); 
     249        glLoadIdentity(); 
    234250} 
    235251 
    236252void VMI::renderBitmapString(float x, float y, void *font, char *string) { 
    237     char *c; 
    238     // Set position to start drawing fonts 
    239     glRasterPos2f(x, y); 
    240     // Loop all the characters in the string 
    241     for (c=string; *c != '\0'; c++) 
    242         glutBitmapCharacter(font, *c); 
     253        char *c; 
     254        // Set position to start drawing fonts 
     255        glRasterPos2f(x, y); 
     256        // Loop all the characters in the string 
     257        for (c=string; *c != '\0'; c++) 
     258                glutBitmapCharacter(font, *c); 
    243259} 
    244260 
    245261void VMI::renderGeometry(void) { 
    246262#ifdef IMMEDIATE_MODE 
    247     int i, v1, v2, v3; 
    248  
    249     // Immediate mode 
    250     glBegin (GL_TRIANGLES); 
    251     for (i=0; i<mesh->numTriangles; i++) { 
    252         if (mesh->triangles[i].enable == TRUE) { 
    253              
    254             v1= mesh->triangles[i].indices[0]; 
    255             v2= mesh->triangles[i].indices[1]; 
    256             v3= mesh->triangles[i].indices[2]; 
    257              
    258             glColor4ub(colors[i].r, colors[i].g, colors[i].b, colors[i].a); 
    259             glVertex3f(mesh->vertices[v1].x, mesh->vertices[v1].y, mesh->vertices[v1].z); 
    260             glVertex3f(mesh->vertices[v2].x, mesh->vertices[v2].y, mesh->vertices[v2].z); 
    261             glVertex3f(mesh->vertices[v3].x, mesh->vertices[v3].y, mesh->vertices[v3].z); 
    262         } 
    263     } 
    264     glEnd(); 
     263        int i, v1, v2, v3; 
     264 
     265        // Immediate mode 
     266        glBegin (GL_TRIANGLES); 
     267        for (i=0; i<mesh->numTriangles; i++) { 
     268                if (mesh->triangles[i].enable == TRUE) { 
     269 
     270                        v1= mesh->triangles[i].indices[0]; 
     271                        v2= mesh->triangles[i].indices[1]; 
     272                        v3= mesh->triangles[i].indices[2]; 
     273 
     274                        glColor4ub(colors[i].r, colors[i].g, colors[i].b, colors[i].a); 
     275                        glVertex3f(mesh->vertices[v1].x, mesh->vertices[v1].y, mesh->vertices[v1].z); 
     276                        glVertex3f(mesh->vertices[v2].x, mesh->vertices[v2].y, mesh->vertices[v2].z); 
     277                        glVertex3f(mesh->vertices[v3].x, mesh->vertices[v3].y, mesh->vertices[v3].z); 
     278                } 
     279        } 
     280        glEnd(); 
    265281#else 
    266282#ifdef VERTEX_ARRAY 
    267     glDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); 
     283        glDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); 
    268284#endif 
    269285#ifdef VERTEX_ARRAY_INTERLEAVE 
    270     glInterleavedArrays (GL_T2F_C4UB_V3F, 0, interleave); 
    271     glDrawArrays(GL_TRIANGLES, 0, mesh->currentNumTriangles * 3); 
     286        glInterleavedArrays (GL_T2F_C4UB_V3F, 0, interleave); 
     287        glDrawArrays(GL_TRIANGLES, 0, mesh->currentNumTriangles * 3); 
    272288#endif 
    273289#ifdef VERTEX_BUFFER_OBJECTS 
    274     glDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); 
    275 #endif 
    276  
    277 #endif 
    278 } 
     290        glDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); 
     291#endif 
     292 
     293#endif 
     294} 
     295 
    279296void VMI::drawTexture(void) { 
    280297 
    281     // Clear color and depth buffers 
    282     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    283  
    284     setOrthographicProjection(); 
    285  
    286     glEnable(GL_TEXTURE_2D); 
    287     glBindTexture(GL_TEXTURE_2D, color_tex); 
    288     glBegin(GL_QUADS); 
    289      
    290     glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); 
    291     glTexCoord2f(1.0f, 0.0f); glVertex2f(width, 0.0f);  
    292     glTexCoord2f(1.0f, 1.0f); glVertex2f(width, height); 
    293     glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, height); 
    294  
    295     glEnd(); 
    296     glFlush(); 
    297     glDisable(GL_TEXTURE_2D); 
    298  
    299     resetPerspectiveProjection(); 
    300  
    301     glutSwapBuffers(); 
     298        // Clear color and depth buffers 
     299        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     300 
     301        setOrthographicProjection(); 
     302 
     303        glEnable(GL_TEXTURE_2D); 
     304        glBindTexture(GL_TEXTURE_2D, color_tex); 
     305        glBegin(GL_QUADS); 
     306 
     307        glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); 
     308        glTexCoord2f(1.0f, 0.0f); glVertex2f(width, 0.0f);  
     309        glTexCoord2f(1.0f, 1.0f); glVertex2f(width, height); 
     310        glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, height); 
     311 
     312        glEnd(); 
     313        glFlush(); 
     314        glDisable(GL_TEXTURE_2D); 
     315 
     316        resetPerspectiveProjection(); 
     317 
     318        glutSwapBuffers(); 
    302319} 
    303320 
    304321void VMI::resetProjectedAreas(int **histogram, int numCameras) { 
    305     int i = 0; 
    306  
    307     // Reset the projected areas for all cameras 
    308     for (i=0; i<numCameras; i++) 
    309         resetSWHistogram(histogram[i], mesh->numTriangles); 
     322        int i = 0; 
     323 
     324        // Reset the projected areas for all cameras 
     325        for (i=0; i<numCameras; i++) 
     326                resetSWHistogram(histogram[i], mesh->numTriangles); 
    310327} 
    311328 
    312329void VMI::getProjectedAreas(int **histogram, int numCameras) 
    313330{ 
    314     int i; 
    315  
    316     // draw to the frame buffer 
    317     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); 
    318  
    319     //glDrawBuffer(GL_BACK); 
    320     //glReadBuffer(GL_BACK); 
    321  
    322     // Get the projected areas for all cameras 
    323     for (i=0; i<numCameras; i++) { 
    324          
    325         // Clear color and depth buffers 
    326         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    327          
    328         glMatrixMode(GL_MODELVIEW); 
    329         glLoadIdentity(); 
    330          
    331         // Camera  i 
    332         gluLookAt(cameras[i].eyeX, cameras[i].eyeY, cameras[i].eyeZ, 
    333                   cameras[i].centerX, cameras[i].centerY, cameras[i].centerZ, 
    334                   cameras[i].upX, cameras[i].upY, cameras[i].upZ); 
    335          
    336         renderGeometry(); 
    337         glFlush(); 
    338          
    339         /////////////////////////////////////////////////////////////////////////// 
    340          
    341         resetSWHistogram(histogram[i], mesh->numTriangles); 
    342          
     331        int i; 
     332 
     333        // draw to the frame buffer 
     334        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); 
     335 
     336        //glDrawBuffer(GL_BACK); 
     337        //glReadBuffer(GL_BACK); 
     338 
     339        // Get the projected areas for all cameras 
     340        for (i=0; i<numCameras; i++) { 
     341 
     342                // Clear color and depth buffers 
     343                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     344 
     345                glMatrixMode(GL_MODELVIEW); 
     346                glLoadIdentity(); 
     347 
     348                // Camera  i 
     349                gluLookAt(cameras[i].eyeX, cameras[i].eyeY, cameras[i].eyeZ, 
     350                                cameras[i].centerX, cameras[i].centerY, cameras[i].centerZ, 
     351                                cameras[i].upX, cameras[i].upY, cameras[i].upZ); 
     352 
     353                renderGeometry(); 
     354                glFlush(); 
     355 
     356                /////////////////////////////////////////////////////////////////////// 
     357 
     358                resetSWHistogram(histogram[i], mesh->numTriangles); 
     359 
    343360#ifdef USE_OCCLUSION_QUERY 
    344         getSWHistoByOcclusionQuery(mesh, colors, histogram[i]); 
     361                getSWHistoByOcclusionQuery(mesh, colors, histogram[i]); 
    345362#else // HYBRID_HW_SW_HISTOGRAM 
    346         getSWHistogram(histogram[i], pixels); 
    347 #endif 
    348     } 
    349  
    350     // draw to the window, reading from the color texture 
    351     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
    352  
    353     if (!bEnableOffScreen) drawTexture(); 
    354      
    355     /////////////////////////////////////////////////////////////////////////// 
     363                getSWHistogram(histogram[i], pixels); 
     364#endif 
     365        } 
     366 
     367        // draw to the window, reading from the color texture 
     368        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
     369 
     370        if (!bEnableOffScreen) drawTexture(); 
     371 
     372        ///////////////////////////////////////////////////////////////////////// 
    356373} 
    357374void VMI::getProjectedAreasWin(int **histogram, int numCameras, Change *c) 
    358375{ 
    359     int i, j, t, background; 
    360     int del_area, mod_area; 
    361     GLfloat min[3], max[3]; 
    362  
    363     // draw to the frame buffer 
    364     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); 
    365  
    366     //printChange(c); 
    367     getBoundingBox(c, min, max); 
    368     //printf("\n(%f,%f,%f)-(%f,%f,%f)\n", min[0], min[1], min[2], max[0], max[1], max[2]); 
    369      
    370     // Update HW acceleration OpenGL Technique 
    371     updateHWAcceleration(c); 
    372  
    373     //glDrawBuffer(GL_BACK); 
    374     //glReadBuffer(GL_BACK); 
    375  
    376     // Get the projected areas for all cameras 
    377     for (i=0; i<numCameras; i++) { 
    378          
    379         // Clear color and depth buffers 
    380         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    381          
    382         glMatrixMode(GL_MODELVIEW); 
    383         glLoadIdentity(); 
    384          
    385         // Camera  i 
    386         gluLookAt(cameras[i].eyeX, cameras[i].eyeY, cameras[i].eyeZ, 
    387                   cameras[i].centerX, cameras[i].centerY, cameras[i].centerZ, 
    388                   cameras[i].upX, cameras[i].upY, cameras[i].upZ); 
    389          
    390         renderGeometry(); 
    391         glFlush(); 
    392          
    393         /////////////////////////////////////////////////////////////////////////// 
    394         background = histogram[i][0]; 
    395         //printf("b: %d\n", histogram[i][0]); 
    396  
    397         del_area = 0; 
    398         mod_area = 0; 
    399  
    400         for (j=0; j<c->numDel; j++) { 
    401             t = c->deleted[j].id; 
    402             del_area += histogram[i][t + 1]; 
    403  
    404             histogram[i][t + 1] = 0; 
    405         } 
    406  
    407         for (j=0; j<c->numMod; j++) { 
    408             t = c->modified[j].id; 
    409             del_area += histogram[i][t + 1]; 
    410  
    411             histogram[i][t + 1] = 0; 
    412         } 
    413          
    414         getSWHistogramWin(histogram[i], pixels, min, max, c);  
    415  
    416         for (j=0; j<c->numMod; j++) { 
    417             t = c->modified[j].id; 
    418             mod_area += histogram[i][t + 1]; 
    419  
    420             //printf("t%d: %d\n",t, histogram[i][t + 1]); 
    421         } 
    422         histogram[i][0] = background + (del_area - mod_area); 
    423         //printf("b: %d\n", histogram[i][0]); 
    424     } 
    425     //getchar(); 
    426  
    427     // draw to the window, reading from the color texture 
    428     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
    429  
    430     if (!bEnableOffScreen) drawTexture(); 
    431      
    432     /////////////////////////////////////////////////////////////////////////// 
     376        int i, j, t, background; 
     377        int del_area, mod_area; 
     378        GLfloat min[3], max[3]; 
     379 
     380        // draw to the frame buffer 
     381        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); 
     382 
     383        //printChange(c); 
     384        getBoundingBox(c, min, max); 
     385        //printf("\n(%f,%f,%f)-(%f,%f,%f)\n", min[0], min[1], min[2], max[0], max[1], max[2]); 
     386 
     387        // Update HW acceleration OpenGL Technique 
     388        updateHWAcceleration(c); 
     389 
     390        //glDrawBuffer(GL_BACK); 
     391        //glReadBuffer(GL_BACK); 
     392 
     393        // Get the projected areas for all cameras 
     394        for (i=0; i<numCameras; i++) { 
     395 
     396                // Clear color and depth buffers 
     397                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     398 
     399                glMatrixMode(GL_MODELVIEW); 
     400                glLoadIdentity(); 
     401 
     402                // Camera  i 
     403                gluLookAt(cameras[i].eyeX, cameras[i].eyeY, cameras[i].eyeZ, 
     404                                cameras[i].centerX, cameras[i].centerY, cameras[i].centerZ, 
     405                                cameras[i].upX, cameras[i].upY, cameras[i].upZ); 
     406 
     407                renderGeometry(); 
     408                glFlush(); 
     409 
     410                //////////////////////////////////////////////////////////////////////// 
     411                background = histogram[i][0]; 
     412                //printf("b: %d\n", histogram[i][0]); 
     413 
     414                del_area = 0; 
     415                mod_area = 0; 
     416 
     417                for (j=0; j<c->numDel; j++) { 
     418                        t = c->deleted[j].id; 
     419                        del_area += histogram[i][t + 1]; 
     420 
     421                        histogram[i][t + 1] = 0; 
     422                } 
     423 
     424                for (j=0; j<c->numMod; j++) { 
     425                        t = c->modified[j].id; 
     426                        del_area += histogram[i][t + 1]; 
     427 
     428                        histogram[i][t + 1] = 0; 
     429                } 
     430 
     431                getSWHistogramWin(histogram[i], pixels, min, max, c);  
     432 
     433                for (j=0; j<c->numMod; j++) { 
     434                        t = c->modified[j].id; 
     435                        mod_area += histogram[i][t + 1]; 
     436 
     437                        //printf("t%d: %d\n",t, histogram[i][t + 1]); 
     438                } 
     439                histogram[i][0] = background + (del_area - mod_area); 
     440                //printf("b: %d\n", histogram[i][0]); 
     441        } 
     442        //getchar(); 
     443 
     444        // draw to the window, reading from the color texture 
     445        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
     446 
     447        if (!bEnableOffScreen) drawTexture(); 
     448 
     449        //////////////////////////////////////////////////////////////////////// 
    433450} 
    434451 
    435452void VMI::freeMemory(void) { 
    436453 
    437           // Free memory 
    438     deleteMesh(mesh); 
    439  
    440     //glmDelete(pmodel); 
    441  
    442     free(pixels); 
    443  
    444     free(cameras); 
    445  
    446     free(colors); 
    447      
    448     deleteHistogram(histogram, numCameras); 
    449  
    450     free(initialIs); 
    451      
    452     glDeleteRenderbuffersEXT(1, &depth_rb); 
    453      
    454     glDeleteRenderbuffersEXT(1, &color_tex); 
    455      
    456     glDeleteFramebuffersEXT(1, &fb); 
     454        // Free memory 
     455        deleteMesh(mesh); 
     456 
     457        //glmDelete(pmodel); 
     458 
     459        free(pixels); 
     460 
     461        free(cameras); 
     462 
     463        free(colors); 
     464 
     465        deleteHistogram(histogram, numCameras); 
     466 
     467        free(initialIs); 
     468 
     469        glDeleteRenderbuffersEXT(1, &depth_rb); 
     470 
     471        glDeleteRenderbuffersEXT(1, &color_tex); 
     472 
     473        glDeleteFramebuffersEXT(1, &fb); 
    457474#ifdef USE_OCCLUSION_QUERY 
    458     glDeleteQueriesARB(mesh->currentNumTriangles, queries); 
    459 #endif 
    460  
    461                 if (vmiWin != 0) 
    462                 { 
    463                         glutDestroyWindow(vmiWin); 
    464                 } 
     475        glDeleteQueriesARB(mesh->currentNumTriangles, queries); 
     476#endif 
     477 
     478        if (vmiWin != 0) 
     479        { 
     480                glutDestroyWindow(vmiWin); 
     481        } 
    465482 
    466483#ifdef VERTEX_BUFFER_OBJECTS 
    467     glDeleteBuffersARB(1, &vertex_buf); 
    468     glDeleteBuffersARB(1, &color_buf); 
    469  
    470                 buf_vertices = NULL; 
    471     buf_colors = NULL; 
     484        glDeleteBuffersARB(1, &vertex_buf); 
     485        glDeleteBuffersARB(1, &color_buf); 
     486 
     487        buf_vertices = NULL; 
     488        buf_colors = NULL; 
    472489 
    473490#endif 
    474491#ifdef VERTEX_ARRAY 
    475     free(buf_vertices); 
    476     free(buf_colors); 
    477  
    478                 buf_vertices = NULL; 
    479     buf_colors = NULL; 
     492        free(buf_vertices); 
     493        free(buf_colors); 
     494 
     495        buf_vertices = NULL; 
     496        buf_colors = NULL; 
    480497#endif 
    481498#ifdef VERTEX_ARRAY_INTERLEAVE 
    482                 free(interleave); 
    483                 interleave = NULL; 
     499        free(interleave); 
     500        interleave = NULL; 
    484501#endif 
    485502 
     
    494511 
    495512        histogram = NULL; 
    496   queries = NULL; 
     513        queries = NULL; 
    497514 
    498515        mesh = NULL; 
     
    516533 
    517534        // Apply HW acceleration OpenGL Technique 
    518   applyHWAcceleration(); 
     535        applyHWAcceleration(); 
    519536 
    520537        getProjectedAreas(histogram, numCameras); 
     
    555572 
    556573#ifdef SALIENCY 
    557     sprintf(s,"%s_%d_%d_%s_S.obj", filename, numCameras, mesh->currentNumTriangles, EXT); 
     574        sprintf(s,"%s_%d_%d_%s_S.obj", filename, numCameras, mesh->currentNumTriangles, EXT); 
    558575#else 
    559     sprintf(s,"%s_%d_%d_%s.obj", filename, numCameras, mesh->currentNumTriangles, EXT); 
     576        sprintf(s,"%s_%d_%d_%s.obj", filename, numCameras, mesh->currentNumTriangles, EXT); 
    560577#endif 
    561578 
  • GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp

    r2291 r2300  
    11191119                                        mGeoMesh        =       mesh_aux; 
    11201120 
     1121                                        // Visualize mesh. 
     1122                                        geoMeshView->setMesh(mGeoMesh); 
     1123 
    11211124                                        //      Simplify the mesh object. 
    11221125                                        if(simplifyEdgeCollapse()) 
     
    11721175                                        undo(); 
    11731176 
    1174  
    11751177                                        std::cout << "Simplificando tronco..."; 
    11761178                                        std::cout << "OK!" << std::endl; 
     
    11841186                                        //      Gets the mesh Shared Vertex. 
    11851187                                        mGeoMesh        =       mesh_aux; 
     1188 
     1189                                        // Visualize mesh. 
     1190                                        geoMeshView->setMesh(mGeoMesh); 
    11861191 
    11871192                                        //      Simplify the mesh object. 
     
    11981203                                } 
    11991204                                 
    1200                                 break;  
     1205                                break; 
    12011206 
    12021207                        case    LODSTRIPS_AUTO: 
     
    12271232                                        //      Gets the mesh Shared Vertex. 
    12281233                                        mGeoMesh        =       mesh_aux; 
     1234 
     1235                                        // Visualize mesh. 
     1236                                        geoMeshView->setMesh(mGeoMesh); 
    12291237 
    12301238                                        //      Simplify the mesh object. 
     
    21252133bool GeoMeshViewUI::simplifyEdgeCollapse() 
    21262134{ 
    2127         Real    percent; 
     2135        int                     error; 
    21282136 
    21292137        //      Free memory. 
     
    21332141        } 
    21342142 
    2135         //    If input field empty. 
     2143        //      If input field empty. 
    21362144        if (mMeshReduction->fvalue() <= 0.0) 
    21372145        { 
     
    21612169        } 
    21622170 
    2163         mMeshSimplifier->setMeshLeaves(idMeshLeaves); 
    2164  
    21652171        if (mPercent->value()) 
    21662172        { 
     
    21692175                                mMeshReduction->fvalue() > 0.0) 
    21702176                { 
    2171                         percent =       mMeshReduction->fvalue(); 
    2172                         percent =       percent / 100.0; 
    2173  
    2174                         mMeshSimplifier->Simplify(percent); 
    2175  
    2176                         //      Deletes the previous mesh. 
    2177                         delete mUndoMesh; 
    2178  
    2179                         mUndoMesh       =       new Mesh(); 
    2180  
    2181                         //      Sets the undo mesh. 
    2182                         *mUndoMesh      =       *mGeoMesh; 
    2183  
    2184                         delete    mGeoMesh; 
    2185  
    2186                         mGeoMesh        =       mMeshSimplifier->GetMesh(); 
     2177                        Real    value; 
     2178 
     2179                        value   =       mMeshReduction->fvalue(); 
     2180                        value   =       value / 100.0; 
     2181 
     2182                        error   =       mMeshSimplifier->Simplify(value); 
    21872183                } 
    21882184                else 
     
    21972193        { 
    21982194                //      Simplification until number of vertices. 
    2199                 uint32 v        =       (uint32)mMeshReduction->fvalue(); 
    2200  
    2201                 mMeshSimplifier->Simplify(v); 
    2202  
     2195                uint32 value    =       (uint32)mMeshReduction->fvalue(); 
     2196 
     2197                error   =       mMeshSimplifier->Simplify(value); 
     2198        } 
     2199 
     2200        //      If no error happens. 
     2201        if (error == NO_GL_ERROR) 
     2202        { 
    22032203                //      Deletes the previous mesh. 
    22042204                delete mUndoMesh; 
     
    22092209                *mUndoMesh      =       *mGeoMesh; 
    22102210 
    2211                 delete  mGeoMesh; 
     2211                delete    mGeoMesh; 
    22122212 
    22132213                mGeoMesh        =       mMeshSimplifier->GetMesh(); 
     2214        } 
     2215        //      If and error happens. 
     2216        else 
     2217        { 
     2218                char    error_message[512]=""; 
     2219 
     2220                if ((error & FRAMEBUFFER_ERROR) == FRAMEBUFFER_ERROR) 
     2221                { 
     2222                        strcat( error_message, 
     2223                                        "GL_EXT_framebuffer_object extension not found.\n"); 
     2224                } 
     2225 
     2226                if ((error & VERTEX_BUFFER_ERROR) == VERTEX_BUFFER_ERROR) 
     2227                { 
     2228                        strcat( error_message, 
     2229                                        "GL_ARB_vertex_buffer_object extension not found.\n"); 
     2230                } 
     2231 
     2232                if ((error & OCCLUSION_QUERY_ERROR) 
     2233                                == 
     2234                                OCCLUSION_QUERY_ERROR) 
     2235                { 
     2236                        strcat( error_message, 
     2237                                        "GL_ARB_occlusion_query extension not found.\n"); 
     2238                } 
     2239 
     2240                if ((error & IMAGING_ERROR) == IMAGING_ERROR) 
     2241                { 
     2242                        strcat( error_message, 
     2243                                        "GL_ARB_imaging extension not found.\n"); 
     2244                } 
     2245 
     2246                if ((error & MULTITEXTURE_ERROR) == MULTITEXTURE_ERROR) 
     2247                { 
     2248                        strcat( error_message, 
     2249                                        "GL_ARB_multitexture extension not found.\n"); 
     2250                } 
     2251 
     2252                if ((error & SWAP_CONTROL_ERROR) == SWAP_CONTROL_ERROR) 
     2253                { 
     2254                        strcat( error_message, 
     2255                                        "WGL_EXT_swap_control extension not found.\n"); 
     2256                } 
     2257 
     2258                strcat( error_message, 
     2259                                                "\nUpdating the video card driver may resolve the problem."); 
     2260 
     2261                fltk::alert(error_message); 
     2262 
     2263                return  false; 
    22142264        } 
    22152265 
     
    22612311 
    22622312                        mUndoMesh       =       new Mesh(); 
    2263                          
     2313 
    22642314                        //      Sets the undo mesh. 
    22652315                        *mUndoMesh      =       *mGeoMesh; 
     
    22682318 
    22692319                        mGeoMesh        =       mTreeSimplifier->GetMesh(); 
    2270                          
     2320 
    22712321                        geoMeshView->setMesh(mGeoMesh); 
    22722322                } 
Note: See TracChangeset for help on using the changeset viewer.