Changeset 2194


Ignore:
Timestamp:
03/06/07 14:26:14 (17 years ago)
Author:
gumbau
Message:
 
Location:
GTP/trunk/Lib/Geom/shared
Files:
17 edited

Legend:

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

    r2090 r2194  
    6060                                Index mV0; 
    6161                                Index   mV1; 
    62                                 Index mT0; 
    63                                 Index   mT1; 
     62                                int             mT0; 
     63                                int             mT1; 
    6464                                float x; 
    6565                                float   y; 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoMeshSimplifier.h

    r2127 r2194  
    110110                        /// Class constructor. Retrieves a pointer to a valid Geometry::Mesh object to simplify. 
    111111                        MeshSimplifier( const Geometry::Mesh    *, 
    112                                         Geometry::TIPOFUNC              upb=0); 
     112                                                                                        Geometry::TIPOFUNC              upb=0); 
    113113 
    114114                        /// Virtual class destructor. 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimplifier.cpp

    r2127 r2194  
    224224        VMI::vTexCoords =       vTexCoords; 
    225225 
    226          
    227  
    228226        mGeoMesh        =       new Mesh(); 
    229227 
     
    252250 
    253251        if (VMI::bLoadCamerasFromFile == GL_FALSE) 
    254                 VMI::cameras = VMI::setCameras(VMI::radius, VMI::cameraType, &VMI::numCameras); 
     252                VMI::cameras = VMI::setCameras( VMI::radius,  
     253                                                                                                                                                VMI::cameraType, 
     254                                                                                                                                                &VMI::numCameras); 
    255255 
    256256        VMI::histogram  =       VMI::initHistogram(     VMI::mesh->currentNumTriangles, 
    257                         VMI::numCameras); 
     257                                                                                                                                                                VMI::numCameras); 
    258258 
    259259        VMI::initialIs  =       VMI::initIs(VMI::numCameras); 
     
    272272} 
    273273 
    274 /// Starts the simplification process. Receives as a parameter the  
    275 ///     LOD factor in a range of [0,1]. Implements the  
     274/// Starts the simplification process. Receives as a parameter the 
     275///     LOD factor in a range of [0,1]. Implements the 
    276276///     Simplifier::Simplify method to perform an image based simplification. 
    277277void ViewPointDrivenSimplifier::Simplify(Real percent) 
     
    333333 
    334334        VMI::contractInitialMesh(VMI::mesh); 
    335  
     335         
    336336        //      Load a geometry mesh for vmi mesh. 
    337337        loadMesh(); 
     
    431431                vmi_mesh->vertices[i].z = vertex_buffer->mPosition[i].z; 
    432432 
    433                 vmi_mesh->vertices[i].numTriangles = 0; 
    434                 vmi_mesh->vertices[i].triangles = NULL; 
    435                 vmi_mesh->vertices[i].numEdges = 0; 
    436                 vmi_mesh->vertices[i].edges = NULL; 
    437                 vmi_mesh->vertices[i].enable    = GL_TRUE; 
    438                 vmi_mesh->vertices[i].movable = GL_TRUE; 
     433                vmi_mesh->vertices[i].numTriangles      = 0; 
     434                vmi_mesh->vertices[i].triangles                 = NULL; 
     435                vmi_mesh->vertices[i].numEdges                  = 0; 
     436                vmi_mesh->vertices[i].edges                                     = NULL; 
     437                vmi_mesh->vertices[i].enable                            = GL_TRUE; 
    439438        } 
    440439         
     
    468467                        vmi_mesh->triangles[index].indices[2] = geosubmesh->mIndex[(3 * i) + 2]; 
    469468 
    470                         vmi_mesh->triangles[index].area = computeTriangleArea(vmi_mesh->vertices,  
    471                                         &vmi_mesh->triangles[index]); 
    472                         computeTriangleNormal(vmi_mesh->vertices, &vmi_mesh->triangles[index]); 
     469                        vmi_mesh->triangles[index].area = computeTriangleArea( 
     470                                                                                                                                                                                vmi_mesh->vertices,  
     471                                                                                                                                                                                &vmi_mesh->triangles[index]); 
     472 
     473                        computeTriangleNormal(vmi_mesh->vertices, 
     474                                                                                                                &vmi_mesh->triangles[index]); 
    473475 
    474476                        vmi_mesh->triangles[index].saliency = 0.0; 
     
    482484 
    483485                                // Reallocate memory for the new adjacent triangle. 
    484                                 vmi_mesh->vertices[v1].triangles = (int *)realloc(vmi_mesh->vertices[v1].triangles, (vmi_mesh->vertices[v1].numTriangles + 1) * sizeof(int)); 
     486                                vmi_mesh->vertices[v1].triangles =  
     487                                                                                        (int *)realloc(vmi_mesh->vertices[v1].triangles, 
     488                                                                                        (vmi_mesh->vertices[v1].numTriangles + 1) 
     489                                                                                        * 
     490                                                                                        sizeof(int)); 
    485491 
    486492                                VMI::addItem(   (int *)vmi_mesh->vertices[v1].triangles, 
     
    503509        // E = 3 T / 2 
    504510        vmi_mesh->edges = (VMI::Edge *)malloc(sizeof(VMI::Edge) 
    505                                                                                                                                                 * 
    506                                                                                                                                                 vmi_mesh->numTriangles * 3); 
     511                                                                                * 
     512                                                                                vmi_mesh->numTriangles * 3); 
    507513 
    508514        if (vmi_mesh->edges == NULL) 
     
    554560        vmi_mesh->numEdges = n; 
    555561 
    556         for (i=0; i<vmi_mesh->numEdges; i++) { 
     562        for (i  =       0; i < vmi_mesh->numEdges; i++) 
     563        { 
    557564                v1 = vmi_mesh->edges[i].u; 
    558565                v2 = vmi_mesh->edges[i].v; 
    559566 
    560                 vmi_mesh->vertices[v1].edges =  
    561                         (int *)realloc(vmi_mesh->vertices[v1].edges, (vmi_mesh->vertices[v1].numEdges + 1) * sizeof(int)); 
     567                vmi_mesh->vertices[v1].edges    = 
     568                                                        (int *)realloc(vmi_mesh->vertices[v1].edges, 
     569                                                        (vmi_mesh->vertices[v1].numEdges + 1) * sizeof(int)); 
     570 
    562571                // Adding edge i adjacent to vertex v1 
    563                 VMI::addItem(vmi_mesh->vertices[v1].edges, &vmi_mesh->vertices[v1].numEdges, i); 
    564  
    565                 vmi_mesh->vertices[v2].edges =  
    566                         (int *)realloc(vmi_mesh->vertices[v2].edges, (vmi_mesh->vertices[v2].numEdges + 1) * sizeof(int)); 
     572                VMI::addItem(   vmi_mesh->vertices[v1].edges, 
     573                                                                        &vmi_mesh->vertices[v1].numEdges, 
     574                                                                        i); 
     575 
     576                vmi_mesh->vertices[v2].edges = 
     577                                                                (int *)realloc(vmi_mesh->vertices[v2].edges, 
     578                                                                (vmi_mesh->vertices[v2].numEdges + 1) * sizeof(int)); 
     579 
    567580                // Adding edge i adjacent to vertex v2 
    568                 VMI::addItem(vmi_mesh->vertices[v2].edges, &vmi_mesh->vertices[v2].numEdges, i); 
     581                VMI::addItem(   vmi_mesh->vertices[v2].edges, 
     582                                                                        &vmi_mesh->vertices[v2].numEdges, 
     583                                                                        i); 
    569584        } 
    570585 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/SimplificationMethod.cpp

    r2089 r2194  
    230230//      Contract a given pair 
    231231//------------------------------------------------------------------------- 
    232 void SimplificationMethod::do_contract( simplif::Model& m, 
    233                                                                                                                                                                 simplif::pair_info *auxpair) 
     232void SimplificationMethod::do_contract( simplif::Model                  &m, 
     233                                                                                                                                                                simplif::pair_info      *auxpair, 
     234                                                                                                                                                                int                                                                     obligatory) 
    234235{ 
    235236        simplif::Vertex                 *v0                     = auxpair->v0; 
     
    243244        vertex_map_str                  lb; 
    244245        vertex_map_str                  ub; 
     246 
     247        //      Stores the simplification step. 
     248        MeshSimplificationSequence::Step simplifstep; 
    245249         
    246250        // V0 must be always the alive vertex 
     
    338342 
    339343        int del_index   =       0; 
     344 
     345        //      Initialize deleted triangles. 
     346        simplifstep.mT0 =       -1; 
     347        simplifstep.mT1 =       -1; 
     348 
     349        //      Sets obligatory flag. 
     350        simplifstep.obligatory  =       obligatory; 
    340351 
    341352        //      Clears faces list. 
     
    519530                                (vertexMultimap.find(f0) != vertexMultimap.end()) 
    520531                                && 
    521                                 (vertexMultimap.find(f1) != vertexMultimap.end())) 
     532                                (vertexMultimap.find(f1) != vertexMultimap.end()) 
     533                                && 
     534                                ((*pair->v0) != (*pair->v1))) 
    522535                { 
    523536                        break; 
     
    551564        candidate       =       pair->candidate; 
    552565 
    553         //      First contract. 
    554         simplifstep.obligatory  =       0; 
    555  
    556566        //      Debug. 
    557567        cout    <<      "Contracting... " 
     
    559569 
    560570        //      Contract main pair. 
    561         do_contract(m, pair); 
    562  
    563         //      Twin contract and lonely vertex contract. 
    564         simplifstep.obligatory  =       1; 
     571        do_contract(m, pair, 0); 
    565572 
    566573        //      Attempt to maintain valid vertex information. 
     
    600607        float                                                           x,y,z; 
    601608 
     609        /* 
    602610        if ((*v0) != (*v1)) 
    603611        { 
     612        */ 
    604613                //      Gets the vertex that is not the candidate. 
    605614                if ((*v1) == candidate) 
     
    621630                        lonely_vert     =       m.vertex((*it).second); 
    622631 
     632                        //      Debug. 
     633                        if ((*it).second == 10988) 
     634                        { 
     635                                cout    <<      "Lonely: " 
     636                                                        <<      lonely_vert->vID 
     637                                                        <<      endl; 
     638                        } 
     639                         
    623640                        for (int        i       =       0;      i < lonely_vert->edgeUses().length();   i++) 
    624641                        { 
     
    671688 
    672689                                //      Contract twin pair. 
    673                                 do_contract(m, pair); 
     690                                do_contract(m, pair, 1); 
    674691                                M0.validVertCount--; 
    675692                        } 
     
    686703                                z       =       (*new_vert)[Z]; 
    687704 
     705                                simplif::Vertex *v; 
     706 
     707                                //      Debug. 
     708                                if (new_vert->vID == 10988) 
     709                                { 
     710                                        cout    <<      "[" 
     711                                                                <<      x 
     712                                                                <<      "," 
     713                                                                <<      y 
     714                                                                <<      "," 
     715                                                                <<      z 
     716                                                                <<      "]" 
     717                                                                <<      endl; 
     718 
     719                                         
     720                                        v       =       m.vertex(10988); 
     721                                } 
     722 
    688723                                //      Adds new vertex to multimap. 
    689724                                vertexMultimap.insert(vertex_pair(_float3_(x,y,z),new_vert->vID)); 
     
    724759                                pair->notInHeap(); 
    725760 
     761                                //      Debug. 
     762                                cout    <<      "new: " 
     763                                                        <<      new_vert->vID 
     764                                                        <<      "(" 
     765                                                        <<      (*new_vert)[X] 
     766                                                        <<      "," 
     767                                                        <<      (*new_vert)[Y] 
     768                                                        <<      "," 
     769                                                        <<      (*new_vert)[Z] 
     770                                                        <<      ") lonely: " 
     771                                                        <<      lonely_vert->vID 
     772                                                        <<      "(" 
     773                                                        <<      (*lonely_vert)[X] 
     774                                                        <<      "," 
     775                                                        <<      (*lonely_vert)[Y] 
     776                                                        <<      "," 
     777                                                        <<      (*lonely_vert)[Z] 
     778                                                        <<      ")" 
     779                                                        <<      endl; 
     780 
    726781                                //      Contract new pair. 
    727                                 do_contract(m, pair); 
     782                                do_contract(m, pair, 1); 
    728783                                M0.validVertCount--; 
    729784                        } 
    730785                } 
    731         } 
     786        /* 
     787        } 
     788        */ 
    732789} 
    733790 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/SimplificationMethod.h

    r2087 r2194  
    3636                } 
    3737 
     38                /* 
     39                bool operator==(const _float3_  &f) const 
     40                { 
     41                        float   F3_EPS; 
     42                        float dx; 
     43                        float dy; 
     44                        float dz; 
     45                         
     46                        F3_EPS  =       1e-12; 
     47                        dx                      =       x - f.x; 
     48                        dy                      =       y - f.y; 
     49                        dz                      =       z - f.z; 
     50 
     51                        return (dx*dx + dy*dy + dz*dz) < F3_EPS; 
     52                } 
     53                */ 
     54 
    3855                bool operator<(const _float3_ &f) const 
    3956                { 
     
    7390                MeshSimplificationSequence      *msimpseq; 
    7491 
    75                 //      Stores the simplification step. 
    76                 MeshSimplificationSequence::Step simplifstep; 
    77  
    7892                inline simplif::vert_info& vertex_info(simplif::Vertex *v) 
    7993                { 
     
    100114                void delete_pair(simplif::pair_info *pair); 
    101115 
    102                 void do_contract(simplif::Model& m, simplif::pair_info *pair); 
     116                void do_contract(       simplif::Model&                 m, 
     117                                                                                        simplif::pair_info      *pair, 
     118                                                                                        int                                                                     obligatory); 
    103119 
    104120                bool decimate_quadric(simplif::Vertex *v, simplif::Mat4& Q); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/buffers.h

    r2127 r2194  
    1 #ifndef __interleave_h_ 
    2 #define __interleave_h_ 
     1#ifndef __buffers_h_ 
     2#define __buffers_h_ 
    33 
    44#include "GL/glut.h" 
     
    2121} Vertex_; 
    2222 
    23 extern GLuint vertex_buf, color_buf; 
    24  
    25 extern Vertex_ *buf_vertices; 
    26 extern Color   *buf_colors; 
    27  
    28 extern Vertex_ *pbuf_vertices; 
    29 extern Color   *pbuf_colors; 
    30  
    31 extern void saveVertexBuffer(Change *c, VertexIL *dest); 
    32 extern void loadVertexBuffer(VertexIL *src, Change *c); 
     23extern VertexIL *saveVertexBuffer(Change *c, Vertex_ *verts, Color *cols); 
     24extern void loadVertexBuffer(VertexIL *src, Change *c, Vertex_ *verts, Color *cols); 
     25extern VertexIL *saveVertexBufferGPU(Change *c); 
     26extern void loadVertexBufferGPU(VertexIL *src, Change *c); 
    3327 
    3428extern VertexIL *setupInterleave(Mesh *mesh, Color *colors); 
    3529extern void setupVertexArray(Mesh *mesh, Color *colors); 
    36 extern void updateVertexArray(Mesh *mesh, Change *c); 
     30extern void updateVertexArray(Mesh *mesh, Change *c, Vertex_ *verts, Color *cols); 
    3731extern void setupVertexBufferObjects(Mesh *mesh, Color *colors); 
    3832extern void updateVertexBufferObjects(Mesh *mesh, Change *c); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/change.h

    r2127 r2194  
    8585 
    8686        extern void modifyEdges(Mesh *mesh, Change *c); 
    87   extern int find(int *edges, int num, int v_); 
     87  extern int find(Mesh *mesh, int *edges, int num, int v_); 
    8888        extern void updateEdgeAdj(Mesh *mesh, Change *c) ; 
    8989 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/global.h

    r2127 r2194  
    99#include "color.h" 
    1010#include "change.h" 
     11#include "buffers.h" 
    1112 
    1213//      For progress update. 
     
    132133extern GLsizei width, height; 
    133134 
     135extern GLuint vertex_buf, color_buf; 
     136 
     137extern Vertex_ *buf_vertices; 
     138extern Color   *buf_colors; 
     139 
    134140extern int vmiWin; 
    135141 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/mesh.h

    r2127 r2194  
    1313          int *edges; 
    1414    int enable; 
    15                 int     movable;        //      If vertex is part of a border. 
    1615} Vertex; 
    1716 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/simplify.h

    r2127 r2194  
    2828        extern void     initVertexMultimap(     Mesh *mesh, 
    2929                                                                                                                                        multimap<int,int> &vertexMultimap); 
    30         ///////////////////////////////////////////////////////////////////////////// 
     30        ///////////////////////////////////////////////////////////////////////// 
    3131        //      Coordinates class. 
    32         ///////////////////////////////////////////////////////////////////////////// 
     32        ///////////////////////////////////////////////////////////////////////// 
    3333        class _float3_ 
    3434        { 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/buffers.cpp

    r2127 r2194  
    77#include "../include/global.h" 
    88 
    9 namespace       VMI 
    10 { 
    11 Vertex_ *buf_vertices = NULL; 
    12 Color   *buf_colors = NULL; 
    13  
    14 Vertex_ *pbuf_vertices; 
    15 Color   *pbuf_colors; 
    16  
    17 GLuint vertex_buf = 0, 
    18        color_buf = 0; 
    19  
    20 } 
    21  
    22 using namespace VMI; 
    23  
    24 void VMI::saveVertexBuffer(Change *c, VertexIL *dest) { 
    25     int j, t, n = 0, m; 
     9using namespace VMI; 
     10 
     11 
     12 
     13VertexIL *VMI::saveVertexBuffer(Change *c, Vertex_ *verts, Color *cols) { 
     14    int i, j, t, n = 0, m; 
     15    VertexIL *dest; 
     16     
     17    dest = (VertexIL *)malloc((c->numDel + c->numMod + 1) * 3 * sizeof(VertexIL)); 
    2618     
    2719    // Save vertex coordinates and color for deleted triangles 
     
    3224        m = 3 * t; 
    3325         
    34         dest[n].x = buf_vertices[m + 0].x; 
    35         dest[n].y = buf_vertices[m + 0].y; 
    36         dest[n].z = buf_vertices[m + 0].z; 
    37         dest[n].a = buf_colors[m + 0].a; 
    38         dest[n].b = buf_colors[m + 0].b; 
    39         dest[n].r = buf_colors[m + 0].r; 
    40         dest[n].g = buf_colors[m + 0].g; 
    41         n++; 
    42          
    43         dest[n].x = buf_vertices[m + 1].x; 
    44         dest[n].y = buf_vertices[m + 1].y; 
    45         dest[n].z = buf_vertices[m + 1].z; 
    46         dest[n].a = buf_colors[m + 1].a; 
    47         dest[n].b = buf_colors[m + 1].b; 
    48         dest[n].r = buf_colors[m + 1].r; 
    49         dest[n].g = buf_colors[m + 1].g; 
    50         n++; 
    51          
    52         dest[n].x = buf_vertices[m + 2].x; 
    53         dest[n].y = buf_vertices[m + 2].y; 
    54         dest[n].z = buf_vertices[m + 2].z; 
    55         dest[n].a = buf_colors[m + 2].a; 
    56         dest[n].b = buf_colors[m + 2].b; 
    57         dest[n].r = buf_colors[m + 2].r; 
    58         dest[n].g = buf_colors[m + 2].g; 
    59         n++; 
     26                for (i=0; i<3; i++) { 
     27                        dest[n].x = verts[m + i].x; 
     28                        dest[n].y = verts[m + i].y; 
     29                        dest[n].z = verts[m + i].z; 
     30                        dest[n].a = cols[m + i].a; 
     31                        dest[n].b = cols[m + i].b; 
     32                        dest[n].r = cols[m + i].r; 
     33                        dest[n].g = cols[m + i].g; 
     34                        n++; 
     35                } 
    6036    } 
    6137    // Save vertex coordinates for modified triangles 
     
    6642        m = 3 * t; 
    6743         
    68         dest[n].x = buf_vertices[m + 0].x; 
    69         dest[n].y = buf_vertices[m + 0].y; 
    70         dest[n].z = buf_vertices[m + 0].z; 
    71         n++; 
    72          
    73         dest[n].x = buf_vertices[m + 1].x; 
    74         dest[n].y = buf_vertices[m + 1].y; 
    75         dest[n].z = buf_vertices[m + 1].z; 
    76         n++; 
    77          
    78         dest[n].x = buf_vertices[m + 2].x; 
    79         dest[n].y = buf_vertices[m + 2].y; 
    80         dest[n].z = buf_vertices[m + 2].z; 
    81         n++; 
    82     } 
    83 } 
    84  
    85 void VMI::loadVertexBuffer(VertexIL *src, Change *c) { 
    86     int j, t, n = 0, m; 
    87      
     44                for (i=0; i<3; i++) { 
     45                        dest[n].x = verts[m + i].x; 
     46                        dest[n].y = verts[m + i].y; 
     47                        dest[n].z = verts[m + i].z; 
     48                        n++; 
     49                } 
     50    } 
     51     
     52    return dest; 
     53} 
     54 
     55VertexIL *VMI::saveVertexBufferGPU(Change *c) { 
     56    Vertex_ *verts; 
     57        Color *cols; 
     58    VertexIL *dest; 
     59     
     60    glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buf); 
     61    // Map the buffer object 
     62        verts = (Vertex_ *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_READ_ONLY); 
     63         
     64    glBindBufferARB(GL_ARRAY_BUFFER_ARB, color_buf); 
     65    // Map the buffer object 
     66        cols = (Color *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_READ_ONLY); 
     67         
     68        // Update GPU buffers 
     69        dest = saveVertexBuffer(c, verts, cols); 
     70         
     71        // Unmap buffers 
     72    glBindBuffer(GL_ARRAY_BUFFER_ARB, vertex_buf); 
     73    if (!glUnmapBufferARB(GL_ARRAY_BUFFER_ARB)) { 
     74        // Handle error case 
     75    } 
     76    glBindBuffer(GL_ARRAY_BUFFER_ARB, color_buf); 
     77    if (!glUnmapBufferARB(GL_ARRAY_BUFFER_ARB)) { 
     78        // Handle error case 
     79    } 
     80 
     81    return dest; 
     82} 
     83 
     84void VMI::loadVertexBuffer(VertexIL *src, Change *c, Vertex_ *verts, Color *cols) { 
     85    int i, j, t, n = 0, m; 
     86 
    8887    // Load vertex coordinates and color for deleted triangles 
    8988    for (j=0; j<c->numDel; j++) {  
     
    9291         
    9392        m = 3 * t; 
    94  
    95         buf_vertices[m + 0].x = src[n].x; 
    96         buf_vertices[m + 0].y = src[n].y; 
    97         buf_vertices[m + 0].z = src[n].z; 
    98         buf_colors[m + 0].a = src[n].a; 
    99         buf_colors[m + 0].b = src[n].b; 
    100         buf_colors[m + 0].r = src[n].r; 
    101         buf_colors[m + 0].g = src[n].g; 
    102         n++; 
    103  
    104         buf_vertices[m + 1].x = src[n].x; 
    105         buf_vertices[m + 1].y = src[n].y; 
    106         buf_vertices[m + 1].z = src[n].z; 
    107         buf_colors[m + 1].a = src[n].a; 
    108         buf_colors[m + 1].b = src[n].b; 
    109         buf_colors[m + 1].r = src[n].r; 
    110         buf_colors[m + 1].g = src[n].g; 
    111         n++; 
    112  
    113         buf_vertices[m + 2].x = src[n].x; 
    114         buf_vertices[m + 2].y = src[n].y; 
    115         buf_vertices[m + 2].z = src[n].z; 
    116         buf_colors[m + 2].a = src[n].a; 
    117         buf_colors[m + 2].b = src[n].b; 
    118         buf_colors[m + 2].r = src[n].r; 
    119         buf_colors[m + 2].g = src[n].g; 
    120         n++; 
     93                 
     94                for (i=0; i<3; i++) { 
     95                        verts[m + i].x = src[n].x; 
     96                        verts[m + i].y = src[n].y; 
     97                        verts[m + i].z = src[n].z; 
     98                        cols[m + i].a = src[n].a; 
     99                        cols[m + i].b = src[n].b; 
     100                        cols[m + i].r = src[n].r; 
     101                        cols[m + i].g = src[n].g; 
     102                        n++; 
     103                } 
    121104    } 
    122105    // Load vertex coordinates for modified triangles 
     
    126109         
    127110        m = 3 * t; 
    128  
    129         buf_vertices[m + 0].x = src[n].x; 
    130         buf_vertices[m + 0].y = src[n].y; 
    131         buf_vertices[m + 0].z = src[n].z; 
    132         n++; 
    133  
    134         buf_vertices[m + 1].x = src[n].x; 
    135         buf_vertices[m + 1].y = src[n].y; 
    136         buf_vertices[m + 1].z = src[n].z; 
    137         n++; 
    138  
    139         buf_vertices[m + 2].x = src[n].x; 
    140         buf_vertices[m + 2].y = src[n].y; 
    141         buf_vertices[m + 2].z = src[n].z; 
    142         n++; 
     111                 
     112                for (i=0; i<3; i++) { 
     113                        verts[m + i].x = src[n].x; 
     114                        verts[m + i].y = src[n].y; 
     115                        verts[m + i].z = src[n].z; 
     116                        n++; 
     117                } 
     118    } 
     119} 
     120 
     121void VMI::loadVertexBufferGPU(VertexIL *src, Change *c) { 
     122        Vertex_ *verts; 
     123        Color *cols; 
     124     
     125    glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buf); 
     126    // Map the buffer object 
     127        verts = (Vertex_ *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY); 
     128         
     129    glBindBufferARB(GL_ARRAY_BUFFER_ARB, color_buf); 
     130    // Map the buffer object 
     131        cols = (Color *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY); 
     132         
     133        // Update GPU buffers 
     134        loadVertexBuffer(src, c, verts, cols); 
     135         
     136        // Unmap buffers 
     137    glBindBuffer(GL_ARRAY_BUFFER_ARB, vertex_buf); 
     138    if (!glUnmapBufferARB(GL_ARRAY_BUFFER_ARB)) { 
     139        // Handle error case 
     140    } 
     141    glBindBuffer(GL_ARRAY_BUFFER_ARB, color_buf); 
     142    if (!glUnmapBufferARB(GL_ARRAY_BUFFER_ARB)) { 
     143        // Handle error case 
    143144    } 
    144145} 
     
    146147void VMI::setupVertexArray(Mesh *mesh, Color *colors) 
    147148{ 
    148     int i, v1, v2, v3, n = 0; 
     149    int i, j, v, n = 0; 
    149150    GLubyte r, g, b, a; 
    150151 
     
    153154 
    154155    buf_vertices = (Vertex_ *)malloc(mesh->numTriangles * 3 * sizeof(Vertex_)); 
    155  
    156156    buf_colors = (Color *)malloc(mesh->numTriangles * 3 * sizeof(Color)); 
    157157 
     
    167167 
    168168    for (i=0; i<mesh->numTriangles; i++) { 
    169  
    170         v1= mesh->triangles[i].indices[0]; 
    171         v2= mesh->triangles[i].indices[1]; 
    172         v3= mesh->triangles[i].indices[2]; 
    173          
    174         if (mesh->triangles[i].enable == TRUE) { 
    175              
    176             r = colors[i].r; 
    177             g = colors[i].g; 
    178             b = colors[i].b; 
    179             a = colors[i].a; 
    180              
    181             buf_colors[n].r = r; 
    182             buf_colors[n].g = g; 
    183             buf_colors[n].b = b; 
    184             buf_colors[n].a = a; 
    185             buf_vertices[n].x = mesh->vertices[v1].x; 
    186             buf_vertices[n].y = mesh->vertices[v1].y; 
    187             buf_vertices[n].z = mesh->vertices[v1].z; 
    188             n++; 
    189              
    190             buf_colors[n].r = r; 
    191             buf_colors[n].g = g; 
    192             buf_colors[n].b = b; 
    193             buf_colors[n].a = a; 
    194             buf_vertices[n].x = mesh->vertices[v2].x; 
    195             buf_vertices[n].y = mesh->vertices[v2].y; 
    196             buf_vertices[n].z = mesh->vertices[v2].z; 
    197             n++; 
    198              
    199             buf_colors[n].r = r; 
    200             buf_colors[n].g = g; 
    201             buf_colors[n].b = b; 
    202             buf_colors[n].a = a; 
    203             buf_vertices[n].x = mesh->vertices[v3].x; 
    204             buf_vertices[n].y = mesh->vertices[v3].y; 
    205             buf_vertices[n].z = mesh->vertices[v3].z; 
    206             n++; 
    207         } else { 
    208           
    209             buf_colors[n].r = 0; 
    210             buf_colors[n].g = 0; 
    211             buf_colors[n].b = 0; 
    212             buf_colors[n].a = 0; 
    213             buf_vertices[n].x = 0; 
    214             buf_vertices[n].y = 0; 
    215             buf_vertices[n].z = 0; 
    216             n++; 
    217              
    218             buf_colors[n].r = 0; 
    219             buf_colors[n].g = 0; 
    220             buf_colors[n].b = 0; 
    221             buf_colors[n].a = 0; 
    222             buf_vertices[n].x = 0; 
    223             buf_vertices[n].y = 0; 
    224             buf_vertices[n].z = 0; 
    225             n++; 
    226              
    227             buf_colors[n].r = 0; 
    228             buf_colors[n].g = 0; 
    229             buf_colors[n].b = 0; 
    230             buf_colors[n].a = 0; 
    231             buf_vertices[n].x = 0; 
    232             buf_vertices[n].y = 0; 
    233             buf_vertices[n].z = 0; 
    234             n++; 
    235         } 
     169                if (mesh->triangles[i].enable == TRUE) { 
     170 
     171                        r = colors[i].r; 
     172                        g = colors[i].g; 
     173                        b = colors[i].b; 
     174                        a = colors[i].a; 
     175                         
     176                        for (j=0; j<3; j++) { 
     177                                 
     178                                v = mesh->triangles[i].indices[j]; 
     179                                 
     180                                buf_colors[n].r = r; 
     181                                buf_colors[n].g = g; 
     182                                buf_colors[n].b = b; 
     183                                buf_colors[n].a = a; 
     184                                buf_vertices[n].x = mesh->vertices[v].x; 
     185                                buf_vertices[n].y = mesh->vertices[v].y; 
     186                                buf_vertices[n].z = mesh->vertices[v].z; 
     187                                n++; 
     188                        } 
     189                } else { 
     190                        for (j=0; j<3; j++) { 
     191                                 
     192                                buf_colors[n].r = 0; 
     193                                buf_colors[n].g = 0; 
     194                                buf_colors[n].b = 0; 
     195                                buf_colors[n].a = 0; 
     196                                buf_vertices[n].x = 0; 
     197                                buf_vertices[n].y = 0; 
     198                                buf_vertices[n].z = 0; 
     199                                n++; 
     200                        } 
     201                } 
    236202    } 
    237203#ifdef VERTEX_ARRAY 
     
    243209    glVertexPointer(3, GL_FLOAT, 0, buf_vertices); 
    244210#endif 
    245  
    246     pbuf_colors = buf_colors; 
    247     pbuf_vertices = buf_vertices; 
    248211} 
    249212 
     
    253216     
    254217    glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buf); 
    255     glBufferDataARB(GL_ARRAY_BUFFER_ARB, mesh->numTriangles * 3 * 3 * sizeof(float), buf_vertices, GL_STATIC_DRAW_ARB); //upload data 
     218    glBufferDataARB(GL_ARRAY_BUFFER_ARB, mesh->numTriangles * 3 * sizeof(Vertex_), buf_vertices, GL_STATIC_DRAW_ARB); //upload data 
    256219 
    257220    glVertexPointer(3, GL_FLOAT, 0,0); 
     
    265228    glEnableClientState(GL_VERTEX_ARRAY); 
    266229    glEnableClientState(GL_COLOR_ARRAY); 
    267      
    268     //free(buf_vertices); 
    269     //buf_vertices = NULL; 
    270      
    271     //free(buf_colors); 
    272     //buf_colors = NULL; 
    273 } 
    274  
    275 void VMI::updateVertexArray(Mesh *mesh, Change *c) 
    276 { 
    277     int i, v1, v2, v3, t, n; 
     230 
     231        free(buf_vertices); 
     232        buf_vertices = NULL; 
     233 
     234    free(buf_colors); 
     235        buf_colors =NULL; 
     236} 
     237 
     238void VMI::updateVertexArray(Mesh *mesh, Change *c, Vertex_ *verts, Color * cols) 
     239{ 
     240    int i, j, v, t, n; 
    278241 
    279242    // The deleted triangles are now in background color 
    280243    for (i=0; i<c->numDel; i++) { 
    281244        t = c->deleted[i].id; 
    282  
     245                 
    283246        n = t * 3; 
    284  
    285         buf_colors[n + 0].r = 0; 
    286         buf_colors[n + 0].g = 0; 
    287         buf_colors[n + 0].b = 0; 
    288         buf_colors[n + 0].a = 0; 
    289  
    290         buf_colors[n + 1].r = 0; 
    291         buf_colors[n + 1].g = 0; 
    292         buf_colors[n + 1].b = 0; 
    293         buf_colors[n + 1].a = 0; 
    294  
    295         buf_colors[n + 2].r = 0; 
    296         buf_colors[n + 2].g = 0; 
    297         buf_colors[n + 2].b = 0; 
    298         buf_colors[n + 2].a = 0; 
    299  
    300         buf_vertices[n + 0].x = 0; 
    301         buf_vertices[n + 0].y = 0; 
    302         buf_vertices[n + 0].z = 0; 
    303  
    304         buf_vertices[n + 1].x = 0; 
    305         buf_vertices[n + 1].y = 0; 
    306         buf_vertices[n + 1].z = 0; 
    307  
    308         buf_vertices[n + 2].x = 0; 
    309         buf_vertices[n + 2].y = 0; 
    310         buf_vertices[n + 2].z = 0; 
     247                 
     248                for (j=0; j<3; j++) { 
     249                        cols[n + j].r = 0; 
     250                        cols[n + j].g = 0; 
     251                        cols[n + j].b = 0; 
     252                        cols[n + j].a = 0; 
     253                         
     254                        verts[n + j].x = 0; 
     255                        verts[n + j].y = 0; 
     256                        verts[n + j].z = 0; 
     257                } 
    311258    } 
    312259 
     
    317264        n = t * 3; 
    318265 
    319         v1= mesh->triangles[t].indices[0]; 
    320         v2= mesh->triangles[t].indices[1]; 
    321         v3= mesh->triangles[t].indices[2]; 
    322  
    323         buf_vertices[n + 0].x = mesh->vertices[v1].x; 
    324         buf_vertices[n + 0].y = mesh->vertices[v1].y; 
    325         buf_vertices[n + 0].z = mesh->vertices[v1].z; 
    326  
    327         buf_vertices[n + 1].x = mesh->vertices[v2].x; 
    328         buf_vertices[n + 1].y = mesh->vertices[v2].y; 
    329         buf_vertices[n + 1].z = mesh->vertices[v2].z; 
    330  
    331         buf_vertices[n + 2].x = mesh->vertices[v3].x; 
    332         buf_vertices[n + 2].y = mesh->vertices[v3].y; 
    333         buf_vertices[n + 2].z = mesh->vertices[v3].z; 
     266                for (j=0; j<3; j++) { 
     267                         
     268                        v= mesh->triangles[t].indices[j]; 
     269                         
     270                        verts[n + j].x = mesh->vertices[v].x; 
     271                        verts[n + j].y = mesh->vertices[v].y; 
     272                        verts[n + j].z = mesh->vertices[v].z; 
     273                } 
    334274    } 
    335275} 
    336276 
    337277void VMI::updateVertexBufferObjects(Mesh *mesh, Change *c) { 
     278        Vertex_ *verts; 
     279        Color *cols; 
    338280     
    339281    glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buf); 
    340282    // Map the buffer object 
    341         buf_vertices = ( Vertex_ *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY); 
     283        verts = (Vertex_ *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY); 
    342284 
    343285    glBindBufferARB(GL_ARRAY_BUFFER_ARB, color_buf); 
    344286    // Map the buffer object 
    345         buf_colors = (Color   *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY); 
    346  
    347     updateVertexArray(mesh, c); 
     287        cols = (Color *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY); 
     288 
     289        // Update GPU buffers 
     290    updateVertexArray(mesh, c, verts, cols); 
    348291 
    349292    // Unmap buffers 
     
    360303VertexIL *VMI::setupInterleave(Mesh *mesh, Color *colors) 
    361304{ 
    362     int i, v1, v2, v3, n = 0; 
     305    int i, j, v, n = 0; 
    363306    GLubyte r, g, b, a; 
    364307    VertexIL *interleave = NULL; 
     
    374317         
    375318        if (mesh->triangles[i].enable == TRUE) { 
    376             v1= mesh->triangles[i].indices[0]; 
    377             v2= mesh->triangles[i].indices[1]; 
    378             v3= mesh->triangles[i].indices[2]; 
    379              
    380             r = colors[i].r; 
     319                         
     320                        r = colors[i].r; 
    381321            g = colors[i].g; 
    382322            b = colors[i].b; 
    383323            a = colors[i].a; 
    384              
    385             interleave[n].tx = 0.0f; 
    386             interleave[n].ty = 0.0f; 
    387             interleave[n].r = r; 
    388             interleave[n].g = g; 
    389             interleave[n].b = b; 
    390             interleave[n].a = a; 
    391             interleave[n].x = mesh->vertices[v1].x; 
    392             interleave[n].y = mesh->vertices[v1].y; 
    393             interleave[n].z = mesh->vertices[v1].z; 
    394             n++; 
    395              
    396             interleave[n].tx = 0.0f; 
    397             interleave[n].ty = 0.0f; 
    398             interleave[n].r = r; 
    399             interleave[n].g = g; 
    400             interleave[n].b = b; 
    401             interleave[n].a = a; 
    402             interleave[n].x = mesh->vertices[v2].x; 
    403             interleave[n].y = mesh->vertices[v2].y; 
    404             interleave[n].z = mesh->vertices[v2].z; 
    405             n++; 
    406              
    407             interleave[n].tx = 0.0f; 
    408             interleave[n].ty = 0.0f; 
    409             interleave[n].r = r; 
    410             interleave[n].g = g; 
    411             interleave[n].b = b; 
    412             interleave[n].a = a; 
    413             interleave[n].x = mesh->vertices[v3].x; 
    414             interleave[n].y = mesh->vertices[v3].y; 
    415             interleave[n].z = mesh->vertices[v3].z; 
    416             n++; 
     324                         
     325                        for (j=0; j<3; j++) { 
     326                                 
     327                                v= mesh->triangles[i].indices[j]; 
     328                                 
     329                                interleave[n].tx = 0.0f; 
     330                                interleave[n].ty = 0.0f; 
     331                                interleave[n].r = r; 
     332                                interleave[n].g = g; 
     333                                interleave[n].b = b; 
     334                                interleave[n].a = a; 
     335                                interleave[n].x = mesh->vertices[v].x; 
     336                                interleave[n].y = mesh->vertices[v].y; 
     337                                interleave[n].z = mesh->vertices[v].z; 
     338                                n++; 
     339                        } 
    417340        } 
    418341    } 
     
    435358void VMI::updateAllColorInterleave(VertexIL *interleave, int num, Color *colors) 
    436359{ 
    437     int i, n = 0; 
     360    int i, j, n = 0; 
    438361    GLubyte r, g, b, a; 
    439  
     362         
    440363    for (i=1; i<=num; i++) { // Triangles start at 1 
    441  
     364                 
    442365        r = colors[i].r; 
    443366        g = colors[i].g; 
    444367        b = colors[i].b; 
    445368        a = colors[i].a; 
    446  
    447         interleave[n].r = r; 
    448         interleave[n].g = g; 
    449         interleave[n].b = b; 
    450         interleave[n].a = a; 
    451         n++; 
    452  
    453         interleave[n].r = r; 
    454         interleave[n].g = g; 
    455         interleave[n].b = b; 
    456         interleave[n].a = a; 
    457         n++; 
    458  
    459         interleave[n].r = r; 
    460         interleave[n].g = g; 
    461         interleave[n].b = b; 
    462         interleave[n].a = a; 
    463         n++; 
     369                 
     370                for (j=0; j<3; j++) { 
     371                        interleave[n].r = r; 
     372                        interleave[n].g = g; 
     373                        interleave[n].b = b; 
     374                        interleave[n].a = a; 
     375                        n++; 
     376                } 
    464377    } 
    465378} 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/change.cpp

    r2127 r2194  
    313313} 
    314314 
    315 int VMI::find(int *edges, int num, int v_) { 
     315int VMI::find(Mesh *mesh, int *edges, int num, int v_) { 
    316316        int i; 
    317  
    318317        int u, v; 
    319318 
    320  
    321319        for(i=0; i<num; i++) { 
    322320 
    323321                u = mesh->edges[edges[i]].u; 
    324  
    325322                v = mesh->edges[edges[i]].v; 
    326323 
     
    333330void VMI::updateEdgeAdj(Mesh *mesh, Change *c) { 
    334331        int i; 
    335  
    336332        int v, e; 
    337333 
     
    346342                else v = mesh->edges[e].u; 
    347343                 
    348                 if (!find(mesh->vertices[c->v].edges, mesh->vertices[c->v].numEdges, v)) 
     344                if (!find(mesh, mesh->vertices[c->v].edges, mesh->vertices[c->v].numEdges, v)) 
    349345                        addItem(mesh->vertices[c->v].edges, &mesh->vertices[c->v].numEdges, e); 
    350346                else mesh->edges[e].enable = FALSE; 
     
    427423                                <<      endl; 
    428424 
     425        if (c->numDel == 0) 
     426        { 
     427                step.mT0        =        -1; 
     428                step.mT1        =        -1; 
     429        } 
    429430        //      If only one triangle has been deleted. 
    430         if (c->numDel == 1) 
     431        else if (c->numDel == 1) 
    431432        { 
    432433                step.mT0        =       c->deleted[0].id; 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/histogram.cpp

    r2127 r2194  
    343343 
    344344    w += (WIN_MARGIN * 2); 
    345     if (w > width)  w = width; 
     345    if (w + ox> width)  w = width - ox; 
    346346    h += (WIN_MARGIN * 2); 
    347     if (h > height) h = height; 
     347    if (h + oy> height) h = height - oy; 
    348348 
    349349    //printf("(%d,%d)\n", ox, oy); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/main.cpp

    r2127 r2194  
    3737GLuint fb, depth_rb, color_tex; 
    3838 
     39#ifdef VERTEX_ARRAY_INTERLEAVE 
     40VertexIL *interleave = NULL; 
     41#endif 
     42 
     43GLuint vertex_buf = 0, 
     44       color_buf = 0; 
     45 
     46Vertex_ *buf_vertices = NULL; 
     47Color   *buf_colors = NULL; 
     48 
    3949int vmiWin = 0; 
    4050 
     
    4858void VMI::init(void) 
    4959{ 
    50     // Clear color 
    51     glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 
    52      
    53     // Initialize viewing values 
    54     glMatrixMode(GL_PROJECTION); 
    55     glLoadIdentity(); 
    56     gluPerspective(fov, (GLdouble)width / height, 0.1, 40.0); 
    57      
    58     //glPixelStorei(GL_PACK_ALIGNMENT, 1); 
    59     //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 
    60      
    61     glShadeModel(GL_FLAT); 
    62      
    63     glDisable(GL_BLEND); 
    64  
    65     glEnable(GL_CULL_FACE); // important 
    66  
    67     glEnable(GL_DEPTH_TEST); 
    68  
    69     if (GL_TRUE != glewIsSupported((const char*) "GL_EXT_framebuffer_object")) 
    70     { 
    71         fprintf(stderr,"GL_EXT_framebuffer_object extension is not available!\n"); 
    72         exit(1); 
    73     } else { 
    74          // create objects 
    75         glGenFramebuffersEXT(1, &fb);        // frame buffer 
    76         glGenTextures(1, &color_tex);        // texture 
    77         glGenRenderbuffersEXT(1, &depth_rb); // render buffer 
    78         glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); 
    79  
    80         // initialize color texture 
    81         glBindTexture(GL_TEXTURE_2D, color_tex); 
    82         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, 
    83                      GL_RGBA, GL_UNSIGNED_BYTE, NULL); 
    84         // texture parameters 
    85         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    86         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
    87  
    88         // attach texture to framebuffer color buffer 
    89         glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 
    90                                   GL_COLOR_ATTACHMENT0_EXT, 
    91                                   GL_TEXTURE_2D, color_tex, 0); 
    92         // initialize depth renderbuffer 
    93         glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb); 
    94         glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, 
    95                                  GL_DEPTH_COMPONENT24, width, height); 
    96         // attach renderbuffer to framebuffer depth buffer 
    97         glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, 
    98                                      GL_DEPTH_ATTACHMENT_EXT, 
    99                                      GL_RENDERBUFFER_EXT, depth_rb); 
    100  
    101         // Check framebuffer completeness at the end of initialization. 
    102         CHECK_FRAMEBUFFER_STATUS(); 
    103     } 
    104     /*if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_fragment_shader")) 
    105     { 
    106         fprintf(stderr,"GL_ARB_fragment_shader extension is not available!\n"); 
    107     } 
    108     if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_vertex_shader")) 
    109     { 
    110         fprintf(stderr,"GL_ARB_vertex_shader extension is not available!\n"); 
    111     } 
    112     if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_shader_objects")) 
    113     { 
    114         fprintf(stderr,"GL_ARB_shader_objects extension is not available!\n"); 
    115     }*/ 
    116     if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_vertex_buffer_object")) 
    117     { 
    118         fprintf(stderr,"GL_ARB_vertex_buffer_object extension is not available!\n"); 
    119     } else { 
     60        // Clear color 
     61        glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 
     62 
     63        // Initialize viewing values 
     64        glMatrixMode(GL_PROJECTION); 
     65        glLoadIdentity(); 
     66        gluPerspective(fov, (GLdouble)width / height, 0.1, 40.0); 
     67 
     68        //glPixelStorei(GL_PACK_ALIGNMENT, 1); 
     69        //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 
     70 
     71        glShadeModel(GL_FLAT); 
     72 
     73        glDisable(GL_BLEND); 
     74 
     75        glEnable(GL_CULL_FACE); // important 
     76 
     77        glEnable(GL_DEPTH_TEST); 
     78 
     79        if (GL_TRUE != glewIsSupported((const char*) "GL_EXT_framebuffer_object")) 
     80        { 
     81                fprintf(stderr, 
     82                                                "GL_EXT_framebuffer_object extension is not available!\n"); 
     83                exit(1); 
     84        } 
     85        else 
     86        { 
     87                // create objects 
     88                glGenFramebuffersEXT(1, &fb);        // frame buffer 
     89                glGenTextures(1, &color_tex);        // texture 
     90                glGenRenderbuffersEXT(1, &depth_rb); // render buffer 
     91                glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); 
     92 
     93                // initialize color texture 
     94                glBindTexture(GL_TEXTURE_2D, color_tex); 
     95                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, 
     96                                GL_RGBA, GL_UNSIGNED_BYTE, NULL); 
     97                // texture parameters 
     98                glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
     99                glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
     100 
     101                // attach texture to framebuffer color buffer 
     102                glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 
     103                                GL_COLOR_ATTACHMENT0_EXT, 
     104                                GL_TEXTURE_2D, color_tex, 0); 
     105                // initialize depth renderbuffer 
     106                glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb); 
     107                glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, 
     108                                GL_DEPTH_COMPONENT24, width, height); 
     109                // attach renderbuffer to framebuffer depth buffer 
     110                glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, 
     111                                GL_DEPTH_ATTACHMENT_EXT, 
     112                                GL_RENDERBUFFER_EXT, depth_rb); 
     113 
     114                // Check framebuffer completeness at the end of initialization. 
     115                CHECK_FRAMEBUFFER_STATUS(); 
     116        } 
     117        /*if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_fragment_shader")) 
     118                { 
     119                fprintf(stderr,"GL_ARB_fragment_shader extension is not available!\n"); 
     120                } 
     121                if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_vertex_shader")) 
     122                { 
     123                fprintf(stderr,"GL_ARB_vertex_shader extension is not available!\n"); 
     124                } 
     125                if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_shader_objects")) 
     126                { 
     127                fprintf(stderr,"GL_ARB_shader_objects extension is not available!\n"); 
     128                }*/ 
     129        if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_vertex_buffer_object")) 
     130        { 
     131                fprintf(stderr, 
     132                                "GL_ARB_vertex_buffer_object extension is not available!\n"); 
     133        } 
     134        else 
     135        { 
    120136#ifdef VERTEX_BUFFER_OBJECTS 
    121          
    122         glGenBuffersARB(1, &vertex_buf); 
    123          
    124         glGenBuffersARB(1, &color_buf); 
    125 #endif 
    126     } 
    127     if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_occlusion_query")) 
    128     { 
    129         fprintf(stderr,"GL_ARB_occlusion_query extension is not available!\n"); 
    130     } else { 
     137                glGenBuffersARB(1, &vertex_buf); 
     138 
     139                glGenBuffersARB(1, &color_buf); 
     140#endif 
     141        } 
     142 
     143        if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_occlusion_query")) 
     144        { 
     145                fprintf(stderr, 
     146                                "GL_ARB_occlusion_query extension is not available!\n"); 
     147        } 
     148        else 
     149        { 
    131150#ifdef USE_OCCLUSION_QUERY 
    132         // Generate a list of occlusion queries 
    133         queries = (GLuint *)malloc(mesh->currentNumTriangles * sizeof(GLuint)); 
    134         glGenQueriesARB(mesh->currentNumTriangles, queries);y 
    135 #endif 
    136     } 
    137     if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_imaging")) 
    138     { 
    139         fprintf(stderr,"GL_ARB_imaging extension is not available!\n"); 
    140     } 
    141     if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_multitexture")) 
    142     { 
    143         fprintf(stderr,"GL_ARB_multitexture extension is not available!\n"); 
    144     } 
     151                // Generate a list of occlusion queries 
     152                queries = (GLuint *)malloc(mesh->currentNumTriangles * sizeof(GLuint)); 
     153                glGenQueriesARB(mesh->currentNumTriangles, queries); 
     154#endif 
     155        } 
     156 
     157        if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_imaging")) 
     158        { 
     159                fprintf(stderr,"GL_ARB_imaging extension is not available!\n"); 
     160        } 
     161 
     162        if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_multitexture")) 
     163        { 
     164                fprintf(stderr,"GL_ARB_multitexture extension is not available!\n"); 
     165        } 
     166 
    145167#ifdef _WIN32 
    146     if (GL_TRUE != wglewIsSupported((const char*) "WGL_EXT_swap_control")) 
    147     { 
    148         fprintf(stderr,"WGL_EXT_swap_control extension is not available!\n"); 
    149     } 
    150 #endif 
    151      
    152     // Allocate memory for the image pixels 
    153     pixels = (GLubyte *)malloc(width * height * 4 * sizeof(GLubyte)); 
    154      
    155     // Allocate memory for colors 
    156     colors = initColors(mesh->currentNumTriangles); 
    157  
    158     // Set a different color for every triangle  
    159     setColors4(colors, mesh->currentNumTriangles); 
     168        if (GL_TRUE != wglewIsSupported((const char*) "WGL_EXT_swap_control")) 
     169        { 
     170                fprintf(stderr,"WGL_EXT_swap_control extension is not available!\n"); 
     171        } 
     172#endif 
     173 
     174        // Allocate memory for the image pixels. 
     175        pixels = (GLubyte *)malloc(width * height * 4 * sizeof(GLubyte)); 
     176 
     177        // Allocate memory for colors. 
     178        colors = initColors(mesh->currentNumTriangles); 
     179 
     180        // Set a different color for every triangle. 
     181        setColors4(colors, mesh->currentNumTriangles); 
    160182} 
    161183 
     
    246268#endif 
    247269#ifdef VERTEX_ARRAY_INTERLEAVE 
    248     glInterleavedArrays (GL_T2F_C4UB_V3F, 0, intertwined); 
     270    glInterleavedArrays (GL_T2F_C4UB_V3F, 0, interleave); 
    249271    glDrawArrays(GL_TRIANGLES, 0, mesh->currentNumTriangles * 3); 
    250272#endif 
     
    444466#ifdef VERTEX_BUFFER_OBJECTS 
    445467    glDeleteBuffersARB(1, &vertex_buf); 
    446      
    447468    glDeleteBuffersARB(1, &color_buf); 
    448  
    449     //free(pbuf_vertices); 
    450     //free(pbuf_colors); 
    451469 
    452470                buf_vertices = NULL; 
     
    455473#endif 
    456474#ifdef VERTEX_ARRAY 
    457     //free(pbuf_vertices); 
    458     //free(pbuf_colors); 
     475    free(buf_vertices); 
     476    free(buf_colors); 
    459477 
    460478                buf_vertices = NULL; 
    461479    buf_colors = NULL; 
     480#endif 
     481#ifdef VERTEX_ARRAY_INTERLEAVE 
     482                free(interleave); 
     483                interleave = NULL; 
    462484#endif 
    463485 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/mesh.cpp

    r2127 r2194  
    443443} 
    444444 
    445 void VMI::deleteMesh(Mesh *mesh) { 
     445void VMI::deleteMesh(Mesh *mesh) 
     446{ 
    446447        int i; 
    447448 
    448         if (NULL != mesh) { 
    449                 for (i=0; i<mesh->numVertices; i++) { 
     449        if (NULL != mesh) 
     450        { 
     451                for (i=0; i<mesh->numVertices; i++) 
     452                { 
    450453                        if (mesh->vertices[i].triangles != NULL) 
    451454                                free(mesh->vertices[i].triangles); 
     
    453456                        if (mesh->vertices[i].edges != NULL) 
    454457                                free(mesh->vertices[i].edges); 
    455  
    456458                } 
     459 
    457460                if (mesh->vertices != NULL) free(mesh->vertices); 
    458461                mesh->numVertices = 0; 
     
    550553    if (numVertices > 0) { 
    551554        // Add the first 
    552                 list = mesh->vertices[vertices[0]].edges; 
    553                 numEdges = mesh->vertices[vertices[0]].numEdges; 
     555                    list = mesh->vertices[vertices[0]].edges; 
     556                    numEdges = mesh->vertices[vertices[0]].numEdges; 
    554557 
    555558        // Allocate memory 
     
    563566        for (i=1; i<numVertices; i++) { 
    564567 
    565                         list = mesh->vertices[vertices[i]].edges; 
    566                     numEdges = mesh->vertices[vertices[i]].numEdges; 
     568                              list = mesh->vertices[vertices[i]].edges; 
     569                        numEdges = mesh->vertices[vertices[i]].numEdges; 
    567570 
    568571            // Reallocate memory 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/simplify.cpp

    r2127 r2194  
    2828vector<Geometry::Vector2>       VMI::vTexCoords; 
    2929 
    30 /////////////////////////////////////////////////////////////////////////////// 
     30////////////////////////////////////////////////////////////////////////// 
    3131 
    3232void VMI::bh_mydump(Mesh *mesh, bheap_t *h) { 
     
    5656                        exit(1); 
    5757                } 
    58         }     
     58        } 
    5959} 
    6060 
     
    7373        for (i = 0; i <mesh->numEdges; i++) { 
    7474 
    75                 //      Update progress bar. 
    76                 mUPB(percent); 
     75                if (mUPB) 
     76                { 
     77                        //      Update progress bar. 
     78                        mUPB(percent); 
     79                } 
    7780 
    7881                if (mesh->edges[i].enable == TRUE) { 
     
    226229/////////////////////////////////////////////////////////////////////////////// 
    227230 
    228 void saveProjectedAreas(int **histogram, int numCameras, Change *c, int *dest) { 
    229         int i, j, t, n = 0; 
    230  
    231         for (j=0; j<c->numDel; j++) { 
    232  
    233                 t = c->deleted[j].id; 
    234  
    235                 for (i=0; i<numCameras; i++) { 
    236  
    237                         dest[n] = histogram[i][t + 1]; 
    238                         n++; 
    239                 } 
    240         } 
    241  
    242         for (j=0; j<c->numMod; j++) {  
    243  
    244                 t = c->modified[j].id; 
    245  
    246                 for (i=0; i<numCameras; i++) { 
    247  
    248                         dest[n] = histogram[i][t + 1]; 
    249                         n++; 
    250                 }    
    251         } 
    252  
    253         // Save background area 
    254         for (i=0; i<numCameras; i++) { 
    255  
    256                 dest[n] = histogram[i][0]; 
    257                 n++; 
    258         } 
     231int *saveProjectedAreas(int **histogram, int numCameras, Change *c) { 
     232    int i, j, t, n = 0; 
     233    int *dest; 
     234     
     235    // Allocate memory 
     236    dest = (int *)malloc((c->numDel + c->numMod + 1) * numCameras * sizeof(int)); 
     237         
     238    for (j=0; j<c->numDel; j++) {  
     239         
     240        t = c->deleted[j].id; 
     241 
     242        for (i=0; i<numCameras; i++) { 
     243             
     244            dest[n] = histogram[i][t + 1]; 
     245            n++; 
     246        } 
     247    } 
     248     
     249    for (j=0; j<c->numMod; j++) {  
     250         
     251        t = c->modified[j].id; 
     252         
     253        for (i=0; i<numCameras; i++) { 
     254             
     255            dest[n] = histogram[i][t + 1]; 
     256            n++; 
     257        }    
     258    } 
     259 
     260    // Save background area 
     261    for (i=0; i<numCameras; i++) { 
     262         
     263        dest[n] = histogram[i][0]; 
     264        n++; 
     265    } 
     266     
     267    return dest; 
    259268} 
    260269 
     
    365374        penalized = check_local_inversion(mesh, c); 
    366375#endif 
    367                 // Allocate memory 
    368                 histoAux = (int *)malloc((c->numDel + c->numMod + 1) * numCameras * sizeof(int)); 
    369  
    370 #if defined(VERTEX_BUFFER_OBJECTS) || defined(VERTEX_ARRAY) 
    371         vb = (VertexIL *)malloc((c->numDel + c->numMod + 1) * 3 * sizeof(VertexIL)); 
    372  
    373         saveVertexBuffer(c, vb); 
     376#ifdef VERTEX_ARRAY 
     377        vb = saveVertexBuffer(c, buf_vertices, buf_colors); 
     378#endif 
     379#ifdef VERTEX_BUFFER_OBJECTS 
     380        vb = saveVertexBufferGPU(c); 
    374381#endif 
    375382 
     
    388395                } 
    389396 
    390                 saveProjectedAreas(histogram, numCameras, c, histoAux); 
     397                histoAux = saveProjectedAreas(histogram, numCameras, c); 
    391398    // Apply the edge collapse 
    392399                doChange(mesh, c); 
     
    424431                /////////////////////////////////////////////////////////////////////////////// 
    425432 
    426                 saveProjectedAreas(histogram, numCameras, c, histoAux); 
     433                histoAux = saveProjectedAreas(histogram, numCameras, c); 
    427434 
    428435                doChange(mesh, c); 
     
    459466                // Free memory 
    460467                free(histoAux); 
    461 #if defined(VERTEX_BUFFER_OBJECTS) || defined(VERTEX_ARRAY) 
    462         loadVertexBuffer(vb, c); 
     468#ifdef VERTEX_ARRAY 
     469                loadVertexBuffer(vb, c, buf_vertices, buf_colors); 
     470                free(vb); 
     471#endif 
     472#ifdef VERTEX_BUFFER_OBJECTS 
     473                loadVertexBufferGPU(vb, c); 
    463474        free(vb); 
    464475#endif 
     
    499510        e = bh_min(h); 
    500511 
    501         while (!isValidEdge_(mesh, e)) { 
     512        while (!isValidEdge_(mesh, e) && (h->n >0)) { 
    502513                /* delete invalid edge */ 
    503514                bh_delete(h, e); 
     
    510521 
    511522/* Get the mininum edge cost from the heap using lazy evaluation */ 
    512 int getMinEdge(Mesh *mesh, bheap_t *h) { 
     523int getMinEdge(Mesh *mesh, bheap_t *h) 
     524{ 
    513525        double cost; 
    514526        int e; 
     
    517529        e = getMinValidEdge(mesh, h); 
    518530 
    519         while (bh_is_dirty(h, e)) { 
     531        while (bh_is_dirty(h, e) && (h->n >0)) { 
    520532                /* delete edge from heap */ 
    521533                bh_delete(h, e); 
     
    560572        if (bSaveLog == TRUE) 
    561573        { 
    562 #ifdef SALIENCY        
     574#ifdef SALIENCY 
    563575                sprintf(s,"%s_%s_S.log", filename, EXT); 
    564576#else 
     
    573585                if (!file) 
    574586                { 
    575                         fprintf(stderr, "simplifyModel() failed: can't open file \"%s\" to write.\n", s); 
     587                        fprintf(stderr, 
     588                                                        "simplifyModel() failed: can't open file \"%s\" to write.\n", 
     589                                                        s); 
     590 
    576591                        exit(1); 
    577592                } 
     
    592607        printf("Starting simplification...\n"); 
    593608 
    594         while (mesh->currentNumTriangles > numDemandedTri /*&& cost == 0.0*/) 
     609        while (mesh->currentNumTriangles > numDemandedTri && (h->n >0)/*&& cost == 0.0*/) 
    595610        { 
    596611                // Get the edge that has the minimum cost 
     
    600615                c = createChange(mesh, e); 
    601616 
    602                 // Apply the edge collapse 
    603                 doChange(mesh, c); 
    604                 //deleteVertexOfMap(mesh, c->u); 
    605  
    606                 // Write Simplification sequence. 
    607                 saveSimplificationSequence(c,0); 
    608  
    609                 //contractTwinVertices(mesh, c->u, c->v); // vertex u is removed 
    610  
    611                 if (bSaveLog == TRUE) writeChange(file, c); 
    612  
    613                 cost = h->a[h->p[e]].key; 
    614  
    615                 /* 
    616                 printf( "Edge collapse e%d(%d,%d) %f MIN d %d m %d\n", 
    617                                 c->e, 
    618                                 c->u, 
    619                                 c->v, 
    620                                 cost, 
    621                                 c->numDel, 
    622                                 c->numMod); 
    623                 */ 
    624  
    625                 mesh->edges[e].enable = FALSE; 
    626                 bh_delete(h, e); 
    627  
    628                 updateHWAcceleration(c); 
    629  
    630                 // Get projected areas after the edge collapse 
    631                 getProjectedAreas(histogram, numCameras); 
    632  
    633                 computeCameraIs(histogram, numCameras, initialIs); 
    634  
    635                 updateEdgeAdj(mesh, c); 
    636  
    637     modifyEdges(mesh, c); 
    638  
    639                 // Update the heap according to the edge collapse 
    640                 h = updateHeap(h, mesh, c); 
    641  
    642                 mUPB((float)c->numDel * percent); 
     617                // Check whether edge collapse is a valid change 
     618                if (c->numDel > 0) { 
     619                        // Apply the edge collapse 
     620                        doChange(mesh, c); 
     621                        //deleteVertexOfMap(mesh, c->u); 
     622 
     623                        // Write Simplification sequence. 
     624                        saveSimplificationSequence(c,0); 
     625 
     626                        //contractTwinVertices(mesh, c->u, c->v); // vertex u is removed 
     627 
     628                        if (bSaveLog == TRUE) writeChange(file, c); 
     629 
     630                        cost = h->a[h->p[e]].key; 
     631 
     632                        /* 
     633                                 printf(        "Edge collapse e%d(%d,%d) %f MIN d %d m %d\n", 
     634                                 c->e, 
     635                                 c->u, 
     636                                 c->v, 
     637                                 cost, 
     638                                 c->numDel, 
     639                                 c->numMod); 
     640                                 */ 
     641 
     642                        mesh->edges[e].enable = FALSE; 
     643                        bh_delete(h, e); 
     644 
     645                        updateHWAcceleration(c); 
     646 
     647                        // Get projected areas after the edge collapse 
     648                        getProjectedAreas(histogram, numCameras); 
     649 
     650                        computeCameraIs(histogram, numCameras, initialIs); 
     651 
     652                        updateEdgeAdj(mesh, c); 
     653                        modifyEdges(mesh, c); 
     654 
     655                        // Update the heap according to the edge collapse 
     656                        h = updateHeap(h, mesh, c); 
     657 
     658                        if (mUPB) 
     659                        { 
     660                                mUPB((float)c->numDel * percent); 
     661                        } 
     662                } 
     663                else 
     664                { 
     665                        mesh->edges[e].enable = FALSE; 
     666                        bh_delete(h, e); 
     667                } 
    643668 
    644669                deleteChange(c); 
  • GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp

    r2127 r2194  
    2626        geoMeshView->deactiveLodTree(); 
    2727 
    28         BuildLoadTextureSubMeshMenu(); 
     28        //BuildLoadTextureSubMeshMenu(); 
    2929 
    3030        //      Repaint the window. 
     
    12381238                                break; 
    12391239 
    1240                                 // Añadido 23-12-2005 
     1240                                // A?adido 23-12-2005 
    12411241                        case    SELECT_LEAVES: 
    12421242 
     
    21602160        if (mPercent->value()) 
    21612161        { 
    2162                 // Simplificación por porcentaje 
    2163                 if (mMeshReduction->fvalue() <= 100.0 &&  
     2162                // Simplificaci?n por porcentaje 
     2163                if (mMeshReduction->fvalue() <= 100.0 && 
    21642164                                mMeshReduction->fvalue() > 0.0) 
    21652165                { 
     
    21672167                        percent =       percent / 100.0; 
    21682168 
    2169                         //      Simplifica el geomesh -> Parámetro es un factor LOD [0,1]. 
     2169                        //      Simplifica el geomesh -> Par?metro es un factor LOD [0,1]. 
    21702170 
    21712171                        mMeshSimplifier->Simplify(percent); 
     
    21932193        else 
    21942194        { 
    2195                 //      Simplificar hasta un número de vértices. 
     2195                //      Simplificar hasta un n?mero de v?rtices. 
    21962196                uint32 v        =       (uint32)mMeshReduction->fvalue(); 
    21972197 
    2198                 //      Simplifica el geomesh -> Parámetro es un factor LOD [0,1]. 
     2198                //      Simplifica el geomesh -> Par?metro es un factor LOD [0,1]. 
    21992199                mMeshSimplifier->Simplify(v); 
    22002200 
     
    22852285        secsimpl        =       mMeshSimplifier->GetSimplificationSequence(); 
    22862286 
    2287         // Nombre del mesh para guardar la secuencia de simplificación. 
     2287        // Nombre del mesh para guardar la secuencia de simplificaci?n. 
    22882288        secsimpl->putMeshName(nombremesh);  
    22892289        secsimpl->Save(Geometry::Serializer("SimplifSequence.txt",Serializer::WRITE)); 
Note: See TracChangeset for help on using the changeset viewer.