Changeset 2323


Ignore:
Timestamp:
04/12/07 09:25:16 (17 years ago)
Author:
gumbau
Message:
 
Location:
GTP/trunk/Lib/Geom/shared
Files:
5 edited

Legend:

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

    r2300 r2323  
    5555        for     (size_t i       =       0; i < geoMesh->mSubMeshCount;  i++) 
    5656        { 
    57                 //      Debug. 
    58                 cout    <<      "Indices of submesh " 
    59                                         <<      i 
    60                                         <<      ": " 
    61                                         <<      geoMesh->mSubMesh[i].mIndexCount 
    62                                         <<      endl; 
    63  
    6457                if ((geoMesh->mSubMesh[i].mIndexCount > 0) 
    6558                                || 
     
    6962                } 
    7063        } 
    71  
    72         //      Reassign submesh count. 
    73         geoMesh->mSubMeshCount  =       valid_submesh_count; 
    7464 
    7565        //      Reserve memory for valid submeshes. 
     
    171161        delete  []geoMesh->mSubMesh; 
    172162 
    173         geoMesh->mSubMesh       =       geosubmesh; 
     163        geoMesh->mSubMeshCount  =       valid_submesh_count; 
     164        geoMesh->mSubMesh                               =       geosubmesh; 
    174165} 
    175166 
     
    377368} 
    378369 
     370//------------------------------------------------------------------------ 
    379371//      Init VMI options. 
     372//------------------------------------------------------------------------ 
    380373int     ViewPointDrivenSimplifier::init(void) 
    381374{ 
     
    394387 
    395388        if (VMI::bLoadCamerasFromFile == GL_FALSE) 
    396                 VMI::cameras = VMI::setCameras( VMI::radius,  
     389                VMI::cameras = VMI::setCameras( VMI::radius, 
    397390                                                                                                                                                VMI::cameraType, 
    398391                                                                                                                                                &VMI::numCameras); 
     
    535528VMI::Mesh *     ViewPointDrivenSimplifier::initMeshStructure(Mesh       *geoMesh) 
    536529{ 
    537         GLuint                          i, j, v1, v2, v3, n, e, t; 
     530        GLuint                          i, j, v1, v2, v3, e; 
     531        float x, y, z; 
    538532        VMI::Mesh               *vmi_mesh; 
    539533        SubMesh                         *geosubmesh; 
    540534        VertexBuffer    *vertex_buffer; 
    541535        int                                             mesh_index_count; 
    542         int                                             index; 
    543536 
    544537        //      Reallocate memory for vmi mesh object. 
     
    558551                                                                                                                                                                * 
    559552                                                                                                                                                                vertex_buffer->mVertexCount); 
     553        vmi_mesh->numVertices = 0; 
    560554 
    561555        if (vmi_mesh->vertices == NULL) 
     
    579573                                                                                                                                                                                * 
    580574                                                                                                                                                                                (mesh_index_count / 3)); 
     575        vmi_mesh->numTriangles = 0; 
    581576 
    582577        if (vmi_mesh->triangles == NULL) 
     
    592587        { 
    593588                // Vertices start at 0. 
    594                 vmi_mesh->vertices[i].x = vertex_buffer->mPosition[i].x; 
    595                 vmi_mesh->vertices[i].y = vertex_buffer->mPosition[i].y; 
    596                 vmi_mesh->vertices[i].z = vertex_buffer->mPosition[i].z; 
    597  
    598                 vmi_mesh->vertices[i].numTriangles      = 0; 
    599                 vmi_mesh->vertices[i].triangles                 = NULL; 
    600                 vmi_mesh->vertices[i].numEdges                  = 0; 
    601                 vmi_mesh->vertices[i].edges                                     = NULL; 
    602                 vmi_mesh->vertices[i].enable                            = GL_TRUE; 
     589                x = vertex_buffer->mPosition[i].x; 
     590                y = vertex_buffer->mPosition[i].y; 
     591                z = vertex_buffer->mPosition[i].z; 
     592 
     593                addVertex(vmi_mesh, x, y, z); 
    603594        } 
    604595         
    605596        printf("Ok\n"); 
    606         vmi_mesh->numVertices = int(vertex_buffer->mVertexCount); 
    607         vmi_mesh->currentNumVertices = int(vertex_buffer->mVertexCount); 
     597        vmi_mesh->currentNumVertices = vmi_mesh->numVertices; 
    608598 
    609599        printf("Vertices: %d\n",vmi_mesh->numVertices); 
     
    611601        //      Fill up triangles. 
    612602        printf("Adding triangles..."); 
    613          
    614         //      Initialize index of triangle. 
    615         index   =       0; 
    616603         
    617604        //      For each submesh. 
     
    626613                for (i = 0; i < (geosubmesh->mIndexCount / 3); i++) 
    627614                { 
    628                         vmi_mesh->triangles[index].id                           = index; 
    629                         vmi_mesh->triangles[index].submesh              = submesh; 
    630                         vmi_mesh->triangles[index].indices[0] = geosubmesh->mIndex[(3 * i)]; 
    631                         vmi_mesh->triangles[index].indices[1] = geosubmesh->mIndex[(3 * i) + 1]; 
    632                         vmi_mesh->triangles[index].indices[2] = geosubmesh->mIndex[(3 * i) + 2]; 
    633  
    634                         vmi_mesh->triangles[index].area = computeTriangleArea( 
    635                                                                                                                                                                                 vmi_mesh->vertices,  
    636                                                                                                                                                                                 &vmi_mesh->triangles[index]); 
    637  
    638                         computeTriangleNormal(vmi_mesh->vertices, 
    639                                                                                                                 &vmi_mesh->triangles[index]); 
    640  
    641                         vmi_mesh->triangles[index].saliency = 0.0; 
    642  
    643                         vmi_mesh->triangles[index].enable = GL_TRUE; 
    644  
    645                         for (j = 0; j < 3; j++) 
    646                         { 
    647                                 // Adding triangle index adjacent to 3 vertices. 
    648                                 v1 = vmi_mesh->triangles[index].indices[j]; 
    649  
    650                                 // Reallocate memory for the new adjacent triangle. 
    651                                 vmi_mesh->vertices[v1].triangles =  
    652                                                                                         (int *)realloc(vmi_mesh->vertices[v1].triangles, 
    653                                                                                         (vmi_mesh->vertices[v1].numTriangles + 1) 
    654                                                                                         * 
    655                                                                                         sizeof(int)); 
    656  
    657                                 VMI::addItem(   (int *)vmi_mesh->vertices[v1].triangles, 
    658                                                                                         (int *)&vmi_mesh->vertices[v1].numTriangles, 
    659                                                                                         index); 
    660                         } 
    661  
    662                         //      Increments triangle count. 
    663                         index++; 
     615                        v1 = geosubmesh->mIndex[(3 * i)]; 
     616                        v2 = geosubmesh->mIndex[(3 * i) + 1]; 
     617                        v3 = geosubmesh->mIndex[(3 * i) + 2]; 
     618 
     619                        // not a degenerated triangle 
     620                        //if ((v1 != v2) && (v2 != v3) && (v1 != v3)) { 
     621 
     622                                addTriangle(vmi_mesh, submesh, v1, v2, v3); 
     623                        //} 
    664624                } 
    665625        } 
     
    667627        printf("Ok\n"); 
    668628 
    669         vmi_mesh->numTriangles                          = mesh_index_count / 3; 
    670         vmi_mesh->currentNumTriangles = mesh_index_count / 3; 
    671  
    672         printf("Num Triangles: %d\n",vmi_mesh->numTriangles); 
     629        vmi_mesh->currentNumTriangles = vmi_mesh->numTriangles; 
     630        printf("Number of triangles: %d\n", vmi_mesh->numTriangles); 
     631        //printf("Number of degenerated triangles: %d\n", pmodel->numtriangles - vmi_mesh->numTriangles); 
    673632         
    674633        // E = 3 T / 2 
     
    676635                                                                                * 
    677636                                                                                vmi_mesh->numTriangles * 3); 
     637        vmi_mesh->numEdges = 0; 
    678638 
    679639        if (vmi_mesh->edges == NULL) 
     
    684644 
    685645        printf("Adding edges..."); 
    686         n = 0; 
    687646 
    688647        //      For each triangle adds three edges. 
    689648        for (i  =       0; i < vmi_mesh->numTriangles; i++) 
    690649        { 
    691                 t               =       0; 
    692650                v1      =       vmi_mesh->triangles[i].indices[0]; 
    693651                v2      =       vmi_mesh->triangles[i].indices[1]; 
    694652                v3      =       vmi_mesh->triangles[i].indices[2]; 
    695653 
    696                 if ((e = findEdge(vmi_mesh->edges, n, v1, v2)) == -1) 
    697                 { 
    698                         vmi_mesh->edges[n].u                                            =       v1; 
    699                         vmi_mesh->edges[n].v                                            =       v2; 
    700                         vmi_mesh->edges[n].enable                       =       GL_TRUE; 
    701  
    702                         n++; 
    703                 } 
    704  
    705                 if ((e = findEdge(vmi_mesh->edges, n, v2, v3)) == -1) 
    706                 { 
    707                         vmi_mesh->edges[n].u                                            = v2; 
    708                         vmi_mesh->edges[n].v                                            = v3; 
    709                         vmi_mesh->edges[n].enable                       = GL_TRUE; 
    710  
    711                         n++; 
     654                if ((e = findEdge(vmi_mesh->edges, vmi_mesh->numEdges, v1, v2)) == -1) 
     655                { 
     656                        addEdge(vmi_mesh, v1, v2); 
     657                } 
     658 
     659                if ((e = findEdge(vmi_mesh->edges, vmi_mesh->numEdges, v2, v3)) == -1) 
     660                { 
     661                        addEdge(vmi_mesh, v2, v3); 
    712662                } 
    713663                 
    714                 if ((e = findEdge(vmi_mesh->edges, n, v3, v1)) == -1) 
    715                 { 
    716                         vmi_mesh->edges[n].u                                            = v3; 
    717                         vmi_mesh->edges[n].v                                            = v1; 
    718                         vmi_mesh->edges[n].enable                       = GL_TRUE; 
    719  
    720                         n++; 
     664                if ((e = findEdge(vmi_mesh->edges, vmi_mesh->numEdges, v3, v1)) == -1) 
     665                { 
     666                        addEdge(vmi_mesh, v3, v1); 
    721667                } 
    722668        } 
    723669         
    724670        printf("Ok\n"); 
    725         vmi_mesh->numEdges = n; 
    726  
    727         for (i  =       0; i < vmi_mesh->numEdges; i++) 
    728         { 
    729                 v1 = vmi_mesh->edges[i].u; 
    730                 v2 = vmi_mesh->edges[i].v; 
    731  
    732                 vmi_mesh->vertices[v1].edges    = 
    733                                                         (int *)realloc(vmi_mesh->vertices[v1].edges, 
    734                                                         (vmi_mesh->vertices[v1].numEdges + 1) * sizeof(int)); 
    735  
    736                 // Adding edge i adjacent to vertex v1 
    737                 VMI::addItem(   vmi_mesh->vertices[v1].edges, 
    738                                                                         &vmi_mesh->vertices[v1].numEdges, 
    739                                                                         i); 
    740  
    741                 vmi_mesh->vertices[v2].edges = 
    742                                                                 (int *)realloc(vmi_mesh->vertices[v2].edges, 
    743                                                                 (vmi_mesh->vertices[v2].numEdges + 1) * sizeof(int)); 
    744  
    745                 // Adding edge i adjacent to vertex v2 
    746                 VMI::addItem(   vmi_mesh->vertices[v2].edges, 
    747                                                                         &vmi_mesh->vertices[v2].numEdges, 
    748                                                                         i); 
    749         } 
    750671 
    751672        //      Creates vertex multimap. 
     
    942863 
    943864                        mGeoMesh->mBones.push_back(bone); 
     865 
    944866                        vertex_found    =       true; 
    945867                } 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/mesh.h

    r2194 r2323  
    4747extern double computeTriangleVolume(Vertex *vertices, Triangle *t); 
    4848 
     49extern int addEdge(Mesh *mesh, int u, int v); 
     50extern int addTriangle(Mesh *mesh, int curGroup, int v1, int v2, int v3); 
     51extern int addVertex(Mesh *mesh, float x, float y, float z); 
     52 
    4953extern Vertex *addVertex(Vertex *list, int *n, float x, float y, float z, int *pos); 
    5054extern int findEdge(Edge *e, int num, int _u, int _v); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/mesh.cpp

    r2194 r2323  
    212212    t->normal[2] = cpz / r; 
    213213} 
     214int VMI::addEdge(Mesh *mesh, int u, int v) { 
     215        int n = mesh->numEdges; 
     216         
     217        mesh->edges[n].u = u; 
     218        mesh->edges[n].v = v; 
     219        mesh->edges[n].enable = TRUE; 
     220         
     221        mesh->vertices[u].edges =  
     222                (int *)realloc(mesh->vertices[u].edges, (mesh->vertices[u].numEdges + 1) * sizeof(int)); 
     223        // Adding edge n adjacent to vertex u 
     224        addItem(mesh->vertices[u].edges, &mesh->vertices[u].numEdges, n); 
     225         
     226        mesh->vertices[v].edges =  
     227                (int *)realloc(mesh->vertices[v].edges, (mesh->vertices[v].numEdges + 1) * sizeof(int)); 
     228        // Adding edge n adjacent to vertex v 
     229        addItem(mesh->vertices[v].edges, &mesh->vertices[v].numEdges, n); 
     230         
     231        mesh->numEdges++; 
     232         
     233        return n; 
     234} 
     235 
     236int VMI::addVertex(Mesh *mesh, float x, float y, float z) { 
     237        int n = mesh->numVertices; 
     238 
     239        mesh->vertices[n].x = x; 
     240        mesh->vertices[n].y = y; 
     241        mesh->vertices[n].z = z; 
     242        mesh->vertices[n].numTriangles = 0; 
     243        mesh->vertices[n].triangles = NULL; 
     244        mesh->vertices[n].numEdges = 0; 
     245        mesh->vertices[n].edges = NULL; 
     246        mesh->vertices[n].enable = TRUE; 
     247 
     248        mesh->numVertices++; 
     249 
     250        return n; 
     251} 
     252 
     253int VMI::addTriangle(Mesh *mesh, int curGroup, int v1, int v2, int v3) { 
     254        int j, n = mesh->numTriangles; 
     255 
     256        mesh->triangles[n].id = n; 
     257        mesh->triangles[n].group = curGroup; // set group 
     258        mesh->triangles[n].submesh = curGroup; // set group 
     259        mesh->triangles[n].indices[0] = v1; 
     260        mesh->triangles[n].indices[1] = v2; 
     261        mesh->triangles[n].indices[2] = v3; 
     262        mesh->triangles[n].area = computeTriangleArea(mesh->vertices, &mesh->triangles[n]); 
     263        //printf("\n%d a: %f",i , mesh->triangles[i].area); 
     264        computeTriangleNormal(mesh->vertices, &mesh->triangles[n]); 
     265        mesh->triangles[n].saliency = 0.0; 
     266        mesh->triangles[n].enable = TRUE; 
     267 
     268        for (j=0; j<3; j++) { 
     269                // Adding triangle n adjacent to 3 vertices 
     270                v1 = mesh->triangles[n].indices[j]; 
     271 
     272                // Reallocate memory for the new adjacent triangle 
     273                mesh->vertices[v1].triangles =  
     274                        (int *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(int)); 
     275                addItem(mesh->vertices[v1].triangles, &mesh->vertices[v1].numTriangles, n); 
     276        } 
     277 
     278        mesh->numTriangles++; 
     279 
     280        return n; 
     281} 
    214282 
    215283Mesh *VMI::initMesh(GLMmodel* pmodel) { 
    216  
    217     int i, j, curGroup, v1, v2, v3, n, m, t; 
    218     int e; 
    219     Mesh *mesh; 
    220     GLMgroup *group; 
    221  
    222     mesh = (Mesh *)malloc (sizeof(Mesh)); 
    223      
    224     if (mesh == NULL) { 
    225         fprintf(stderr, "Error allocating memory\n"); 
    226         exit(1); 
    227     } 
    228  
    229     mesh->vertices = (Vertex *)malloc (sizeof(Vertex) * pmodel->numvertices); 
    230      
    231     if (mesh->vertices == NULL) { 
    232         fprintf(stderr, "Error allocating memory\n"); 
    233         exit(1); 
    234     } 
    235  
    236     mesh->triangles = (Triangle *)malloc (sizeof(Triangle) * pmodel->numtriangles); 
    237      
    238     if (mesh->triangles == NULL) { 
    239         fprintf(stderr, "Error allocating memory\n"); 
    240         exit(1); 
    241     } 
     284        int i, e; 
     285        int v1, v2, v3; 
     286        float x, y, z; 
     287        //int *vlist = NULL, j, num; 
     288        Mesh *mesh; 
     289#ifdef OUTPUT_SEVERAL_GROUPS 
     290                int t; 
     291                int curGroup; 
     292                GLMgroup *group; 
     293#endif 
     294 
     295                mesh = (Mesh *)malloc (sizeof(Mesh)); 
     296 
     297                if (mesh == NULL) { 
     298                        fprintf(stderr, "Error allocating memory\n"); 
     299                        exit(1); 
     300                } 
     301 
     302                mesh->vertices = (Vertex *)malloc (sizeof(Vertex) * pmodel->numvertices); 
     303                mesh->numVertices = 0; 
     304 
     305                if (mesh->vertices == NULL) { 
     306                        fprintf(stderr, "Error allocating memory\n"); 
     307                        exit(1); 
     308                } 
     309 
     310                mesh->triangles = (Triangle *)malloc (sizeof(Triangle) * pmodel->numtriangles); 
     311                mesh->numTriangles = 0; 
     312 
     313                if (mesh->triangles == NULL) { 
     314                        fprintf(stderr, "Error allocating memory\n"); 
     315                        exit(1); 
     316                } 
    242317     
    243318    printf("Adding vertices..."); 
    244     for (i=1; i<=(int)pmodel->numvertices; i++) { // Vertices start at 1 
    245         mesh->vertices[i - 1].x = pmodel->vertices[3 * i + 0]; 
    246         mesh->vertices[i - 1].y = pmodel->vertices[3 * i + 1]; 
    247         mesh->vertices[i - 1].z = pmodel->vertices[3 * i + 2]; 
    248         mesh->vertices[i - 1].numTriangles = 0; 
    249         mesh->vertices[i - 1].triangles = NULL; 
    250                                 mesh->vertices[i - 1].numEdges = 0; 
    251         mesh->vertices[i - 1].edges = NULL; 
    252         mesh->vertices[i - 1].enable = GL_TRUE; 
    253     } 
     319                for (i=1; i<=(int)pmodel->numvertices; i++) { // Vertices start at 1 
     320 
     321                        x = pmodel->vertices[3 * i + 0]; 
     322                        y = pmodel->vertices[3 * i + 1]; 
     323                        z = pmodel->vertices[3 * i + 2]; 
     324 
     325                        addVertex(mesh, x, y, z); 
     326                } 
    254327    printf("Ok\n"); 
    255     mesh->numVertices = pmodel->numvertices; 
    256     mesh->currentNumVertices = pmodel->numvertices; 
     328    mesh->currentNumVertices = mesh->numVertices; 
     329    printf("Number of vertices: %d\n", mesh->numVertices); 
    257330 
    258331    printf("Adding triangles..."); 
    259  
    260332#ifdef OUTPUT_SEVERAL_GROUPS 
    261333    group = pmodel->groups; 
    262334    curGroup=0; // current group 
    263     while(group) { 
    264          
    265         for (i=0; i<(int)group->numtriangles; i++) { 
    266              
    267             t = group->triangles[i]; 
    268  
    269             mesh->triangles[t].id = t; 
    270             mesh->triangles[t].group = curGroup; // set group 
    271             mesh->triangles[t].indices[0] = pmodel->triangles[t].vindices[0] - 1; 
    272             mesh->triangles[t].indices[1] = pmodel->triangles[t].vindices[1] - 1; 
    273             mesh->triangles[t].indices[2] = pmodel->triangles[t].vindices[2] - 1; 
    274             mesh->triangles[t].area = computeTriangleArea(mesh->vertices, &mesh->triangles[t]); 
    275             //printf("\n%d a: %f",i , mesh->triangles[i].area); 
    276             computeTriangleNormal(mesh->vertices, &mesh->triangles[t]); 
    277              
    278             mesh->triangles[t].saliency = 0.0; 
    279              
    280             mesh->triangles[t].enable = GL_TRUE; 
    281              
    282             for (j=0; j<3; j++) { 
    283                 // Adding triangle i adjacent to 3 vertices 
    284                 v1 = mesh->triangles[t].indices[j]; 
    285                  
    286                 // Reallocate memory for the new adjacent triangle 
    287                 mesh->vertices[v1].triangles =  
    288                                         (int *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(int)); 
    289                 addItem((int *)mesh->vertices[v1].triangles, (int *)&mesh->vertices[v1].numTriangles, t); 
    290             } 
    291         } 
    292         curGroup++; 
    293         group = group->next; 
    294     } 
     335                while(group) { 
     336 
     337                        for (i=0; i<(int)group->numtriangles; i++) { 
     338 
     339                                t = group->triangles[i]; 
     340 
     341                                v1 = pmodel->triangles[t].vindices[0] - 1; 
     342                                v2 = pmodel->triangles[t].vindices[1] - 1; 
     343                                v3 = pmodel->triangles[t].vindices[2] - 1; 
     344 
     345                                // not a degenerated triangle 
     346                                if ((v1 != v2) && (v2 != v3) && (v1 != v3)) { 
     347 
     348                                        addTriangle(mesh, curGroup, v1, v2, v3); 
     349                                } 
     350                        } 
     351                        curGroup++; 
     352                        group = group->next; 
     353                } 
    295354#else // One single group 
    296     for (i=0; i<pmodel->numtriangles; i++) { 
    297         mesh->triangles[i].id = i; 
    298         mesh->triangles[i].indices[0] = (int)pmodel->triangles[i].vindices[0] - 1; 
    299         mesh->triangles[i].indices[1] = (int)pmodel->triangles[i].vindices[1] - 1; 
    300         mesh->triangles[i].indices[2] = (int)pmodel->triangles[i].vindices[2] - 1; 
    301         mesh->triangles[i].area = computeTriangleArea(mesh->vertices, &mesh->triangles[i]); 
    302         //printf("\n%d a: %f",i , mesh->triangles[i].area); 
    303         computeTriangleNormal(mesh->vertices, &mesh->triangles[i]); 
    304  
    305         mesh->triangles[i].saliency = 0.0; 
    306  
    307         mesh->triangles[i].enable = GL_TRUE; 
    308          
    309         for (j=0; j<3; j++) { 
    310             // Adding triangle i adjacent to 3 vertices 
    311             v1 = mesh->triangles[i].indices[j]; 
    312     
    313             // Reallocate memory for the new adjacent triangle 
    314             mesh->vertices[v1].triangles =  
    315                             (int *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(int)); 
    316             addItem((int *)mesh->vertices[v1].triangles, (int *)&mesh->vertices[v1].numTriangles, i); 
    317         } 
    318     } 
     355                for (i=0; i<(int)pmodel->numtriangles; i++) { 
     356 
     357                        v1 = pmodel->triangles[i].vindices[0] - 1; 
     358                        v2 = pmodel->triangles[i].vindices[1] - 1; 
     359                        v3 = pmodel->triangles[i].vindices[2] - 1; 
     360 
     361                        // not a degenerated triangle 
     362                        if ((v1 != v2) && (v2 != v3) && (v1 != v3)) { 
     363 
     364                                addTriangle(mesh, 1, v1, v2, v3); 
     365                        } 
     366                } 
    319367    printf("\n"); 
    320368#endif 
     369                printf("Ok\n"); 
     370                mesh->currentNumTriangles = mesh->numTriangles; 
     371                printf("Number of triangles: %d\n", mesh->numTriangles); 
     372                printf("Number of degenerated triangles: %d\n", pmodel->numtriangles - mesh->numTriangles); 
     373 
     374                mesh->edges = (Edge *)malloc (sizeof(Edge) * mesh->numTriangles * 3);  // E = 3 T / 2 
     375                mesh->numEdges = 0; 
     376 
     377                if (mesh->edges == NULL) { 
     378                        fprintf(stderr, "Error allocating memory\n"); 
     379                        exit(1); 
     380                } 
     381 
     382    printf("Adding edges..."); 
     383 
     384    /*for (i=0; i<mesh->numVertices; i++) { 
     385        vlist = verticesAdjToVertex(mesh, i, &num); 
     386         
     387        for (j=0; j<num; j++) { 
     388             
     389            if  (i < vlist[j]) { 
     390                                 
     391                                addEdge(mesh, i, vlist[j]); 
     392            } 
     393        } 
     394        free(vlist); 
     395    }*/ 
     396 
     397                for (i=0; i<mesh->numTriangles; i++) { 
     398 
     399                        v1 = mesh->triangles[i].indices[0]; 
     400                        v2 = mesh->triangles[i].indices[1]; 
     401                        v3 = mesh->triangles[i].indices[2]; 
     402 
     403                        ///////////////////////////////////////////////////////////////////////////////// 
     404                        // edge (v1,v2) 
     405                        if ((e = findEdge(mesh->edges, mesh->numEdges, v1, v2)) == -1) { 
     406 
     407                                addEdge(mesh, v1, v2); 
     408                        } 
     409                        ///////////////////////////////////////////////////////////////////////////////// 
     410                        // edge (v2,v3) 
     411                        if ((e = findEdge(mesh->edges, mesh->numEdges, v2, v3)) == -1) { 
     412 
     413                                addEdge(mesh, v2, v3); 
     414                        } 
     415                        ///////////////////////////////////////////////////////////////////////////////// 
     416                        // edge (v3,v1) 
     417                        if ((e = findEdge(mesh->edges, mesh->numEdges, v3, v1)) == -1) { 
     418 
     419                                addEdge(mesh, v3, v1); 
     420                        } 
     421                } 
    321422    printf("Ok\n"); 
    322  
    323     mesh->numTriangles = pmodel->numtriangles; 
    324     mesh->currentNumTriangles = pmodel->numtriangles; 
    325     printf("Number of triangles: %d\n", mesh->numTriangles); 
    326  
    327     mesh->edges = (Edge *)malloc (sizeof(Edge) * mesh->numTriangles * 3);  // E = 3 T / 2 
    328      
    329     if (mesh->edges == NULL) { 
    330         fprintf(stderr, "Error allocating memory\n"); 
    331         exit(1); 
    332     } 
    333      
    334     printf("Adding edges..."); 
    335     n = 0; 
    336  
    337     for (i=0; i<mesh->numTriangles; i++) { 
    338         t = 0; 
    339         v1 = mesh->triangles[i].indices[0]; 
    340         v2 = mesh->triangles[i].indices[1]; 
    341         v3 = mesh->triangles[i].indices[2]; 
    342          
    343         ///////////////////////////////////////////////////////////////////////////////// 
    344                 // edge (v1,v2) 
    345         if ((e = findEdge(mesh->edges, n, v1, v2)) == -1) { 
    346             mesh->edges[n].u = v1; 
    347             mesh->edges[n].v = v2; 
    348             mesh->edges[n].enable = GL_TRUE; 
    349             m = n; 
    350             n++; 
    351         } else m = e; 
    352  
    353         ///////////////////////////////////////////////////////////////////////////////// 
    354         // edge (v2,v3) 
    355         if (( e = findEdge(mesh->edges, n, v2, v3)) == -1) { 
    356             mesh->edges[n].u = v2; 
    357             mesh->edges[n].v = v3; 
    358             mesh->edges[n].enable = GL_TRUE; 
    359             m = n; 
    360             n++; 
    361         } else m = e; 
    362  
    363         ///////////////////////////////////////////////////////////////////////////////// 
    364         // edge (v3,v1) 
    365         if ((e = findEdge(mesh->edges, n, v3, v1)) == -1) { 
    366             mesh->edges[n].u = v3; 
    367             mesh->edges[n].v = v1; 
    368             mesh->edges[n].enable = GL_TRUE; 
    369             m = n; 
    370             n++; 
    371         } else m = e; 
    372     } 
    373     printf("Ok\n"); 
    374     mesh->numEdges = n; 
    375  
    376                 for (i=0; i<mesh->numEdges; i++) { 
    377                         v1 = mesh->edges[i].u; 
    378                         v2 = mesh->edges[i].v; 
    379  
    380                         mesh->vertices[v1].edges =  
    381                                 (int *)realloc(mesh->vertices[v1].edges, (mesh->vertices[v1].numEdges + 1) * sizeof(int)); 
    382                         // Adding edge i adjacent to vertex v1 
    383                         addItem(mesh->vertices[v1].edges, &mesh->vertices[v1].numEdges, i); 
    384  
    385                         mesh->vertices[v2].edges =  
    386                                 (int *)realloc(mesh->vertices[v2].edges, (mesh->vertices[v2].numEdges + 1) * sizeof(int)); 
    387                         // Adding edge i adjacent to vertex v2 
    388                         addItem(mesh->vertices[v2].edges, &mesh->vertices[v2].numEdges, i); 
    389                 } 
    390423 
    391424    return mesh; 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/saliency.cpp

    r2127 r2323  
    5858 
    5959double VMI::computeTriangleSaliency(Mesh *mesh, int **histogram, int numCameras, int k) { 
    60     int i, l, v0, v1, v2; 
    61     int *triangles = NULL, n = 0; 
     60    int i, j, t, v0; 
     61    int n = 0; 
    6262    double sal = 0.0; 
    6363     
    64     v0 = mesh->triangles[k].indices[0]; 
    65     v1 = mesh->triangles[k].indices[1]; 
    66     v2 = mesh->triangles[k].indices[2]; 
    67      
    68     /* Allocating memory */ 
    69     triangles = (int *)malloc((mesh->vertices[v0].numTriangles + 
    70                                mesh->vertices[v1].numTriangles + 
    71                                mesh->vertices[v2].numTriangles) * sizeof(int)); 
    72  
    73     for(i=0; i<mesh->vertices[v0].numTriangles; i++) { 
    74         l = mesh->vertices[v0].triangles[i]; 
     64    for (j=0; j<3; j++) { 
    7565         
    76         if (l != k)  
    77             addItem(triangles, &n, l); 
    78     } 
    79      
    80     for(i=0; i<mesh->vertices[v1].numTriangles; i++) { 
    81         l = mesh->vertices[v1].triangles[i]; 
     66        v0 = mesh->triangles[k].indices[j]; 
    8267         
    83         if (l != k)  
    84             addItem(triangles, &n, l); 
    85     } 
    86      
    87     for(i=0; i<mesh->vertices[v2].numTriangles; i++) { 
    88         l = mesh->vertices[v2].triangles[i]; 
    89          
    90         if (l != k)  
    91             addItem(triangles, &n, l); 
    92     } 
    93      
    94     //printItemList(triangles, n); 
    95      
    96     for(i=0; i<n; i++) { 
    97         //printf("\n%d %d", k, triangles[i]); 
    98         //sal += computeJS(histogram, numCameras, k, triangles[i]); 
    99                 sal = MAX ( sal, computeJS(histogram, numCameras, k, triangles[i])); 
     68        for(i=0; i<mesh->vertices[v0].numTriangles; i++) { 
     69            t = mesh->vertices[v0].triangles[i]; 
     70             
     71            if (t != k) { 
     72                //printf("\n%d %d", k, triangles[i]); 
     73                //sal += computeJS(histogram, numCameras, k, t); 
     74                sal = MAX(sal, computeJS(histogram, numCameras, k, t)); 
     75                 
     76                n++; 
     77            } 
     78        } 
    10079    } 
    10180    //printf("\nT%d Sal: %f\n", k, (sal / n)); 
    10281    //getchar(); 
    10382     
    104     free(triangles); 
    105  
    10683    return (sal /*/ n*/); 
    10784} 
  • GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp

    r2300 r2323  
    413413//------------------------------------------------------------------------- 
    414414inline void GeoMeshViewUI::cb_menuEditPan_i(fltk::Item  *item, void*) 
    415 {        
     415{ 
    416416        //      If the item is activated. 
    417417        if (item->value()) 
     
    496496                geoMeshView->deactiveSolid(); 
    497497        } 
    498                                                                          
     498 
    499499        //      Repaint the canvas. 
    500500        //geoMeshView->redraw(); 
     
    790790//      Leaves collapse Callback 
    791791//------------------------------------------------------------------------- 
    792 inline void GeoMeshViewUI::cb_menuSimplifyLeavesCollapse_i(fltk::Item*, void*) 
     792inline void GeoMeshViewUI::cb_menuSimplifyLeavesCollapse_i(     fltk::Item      *, 
     793                                                                                                                                                                                                                                                void                            *) 
    793794{ 
    794795        //      Show title. 
     
    896897                                                                                cb_menuLodTreesGenerate_i(o,v); 
    897898} 
    898  
    899899 
    900900//------------------------------------------------------------------------- 
     
    10381038} 
    10391039 
    1040  
    1041  
    10421040//------------------------------------------------------------------------- 
    10431041//      About Callback 
     
    11031101                                } 
    11041102                                 
    1105                                 //      if the mesh is stripified. 
     1103                                //      If the mesh is stripified. 
    11061104                                if (error) 
    11071105                                { 
     
    11191117                                        mGeoMesh        =       mesh_aux; 
    11201118 
    1121                                         // Visualize mesh. 
     1119                                        //      Visualize mesh. 
    11221120                                        geoMeshView->setMesh(mGeoMesh); 
    11231121 
     
    11281126                                        } 
    11291127 
    1130                                         // Visualize mesh. 
     1128                                        //      Visualize mesh. 
    11311129                                        geoMeshView->setMesh(mGeoMesh); 
    11321130 
     
    11341132                                break; 
    11351133 
    1136                                 // Simplify leaves 
     1134                                //      Simplify leaves 
    11371135                        case    LEAVES_COLLAPSE: 
    11381136 
     
    13471345                                        delete mUndoMesh; 
    13481346 
    1349  
    13501347                                        mUndoMesh       =       new Mesh(); 
    13511348 
     
    16171614} 
    16181615 
    1619 //--------------------------------------------------------------------------- 
     1616//------------------------------------------------------------------------- 
    16201617//      Show the Simlify Leaves Collapse. 
    1621 //--------------------------------------------------------------------------- 
     1618//------------------------------------------------------------------------- 
    16221619void    GeoMeshViewUI::showLeavesCollapse() 
    16231620{ 
     
    20212018                //      If the mesh does not have shared vertex. 
    20222019                if (!geoSubMesh->mSharedVertexBuffer) 
    2023                 {                        
     2020                { 
    20242021                        //      Adds the vertex of the submesh to the total count. 
    20252022                        vertex_count    +=      geoSubMesh->mVertexBuffer->mVertexCount; 
     
    20892086                { 
    20902087                        strip_count     +=      geoSubMesh->mStripCount; 
    2091                 }        
     2088                } 
    20922089        } 
    20932090 
     
    23512348        tree_sequencer  =       mTreeSimplifier->GetSimplificationSequence(); 
    23522349         
    2353         tree_sequencer->putMeshName(nombremesh);         
     2350        tree_sequencer->putMeshName(nombremesh); 
    23542351        tree_sequencer->Save(Serializer(filename,Serializer::APPEND)); 
    23552352 
     
    24832480} 
    24842481 
     2482//------------------------------------------------------------------------- 
    24852483//      Method that updates the porgress bar. 
     2484//------------------------------------------------------------------------- 
    24862485float GeoMeshViewUI::updateProgressBar(float v) 
    24872486{ 
     
    25382537//      Initialize the lodTreelibrary for visualization. 
    25392538//------------------------------------------------------------------------- 
    2540 void    GeoMeshViewUI::setLodTreesLibrary(const LodStripsLibraryData *lodstripsdata, const TreeSimplificationSequence *treesimpseq, Mesh *geomesh/*, uint32 ileafSubMesh*/) 
     2539void    GeoMeshViewUI::setLodTreesLibrary( 
     2540                                                                                                        const LodStripsLibraryData                              *lodstripsdata, 
     2541                                                                                                        const TreeSimplificationSequence        *treesimpseq, 
     2542                                                                                                        Mesh                                                                                                                    *geomesh) 
    25412543{ 
    25422544        //      If there is no lod strips object. 
     
    25482550 
    25492551        //      New lod strips object. 
    2550  
    25512552        lod_index_data  =       new GeoToolIndexData(geomesh->mSubMeshCount); 
    2552         lodTreeLib = new Geometry::LodTreeLibrary(lodstripsdata,treesimpseq,geomesh,lod_index_data); 
     2553 
     2554        lodTreeLib      =       new Geometry::LodTreeLibrary(   lodstripsdata, 
     2555                                                                                                                                                                                        treesimpseq, 
     2556                                                                                                                                                                                        geomesh, 
     2557                                                                                                                                                                                        lod_index_data); 
    25532558 
    25542559        //      Sets the slider range. 
     
    26162621                        //      Translate the MB count to a char value. 
    26172622                        sprintf(char_value, 
    2618                                         "MB %.3f", 
    2619                                         (float)geoMeshLoader->getFileSize()/1024/1024); 
     2623                                                        "MB %.3f", 
     2624                                                        (float)geoMeshLoader->getFileSize()/1024/1024); 
    26202625 
    26212626                        mMB->label(char_value); 
     
    27472752        //      Initialize the lod strip object. 
    27482753        lodStripsLib    =       NULL; 
    2749         lodTreeLib      =       NULL; 
    2750  
    2751         //      Identify the mesh that stores the leaves 
     2754        lodTreeLib              =       NULL; 
     2755 
     2756        //      Identify the mesh that stores the leaves. 
    27522757        idMeshLeaves    =       -1; 
    27532758 
Note: See TracChangeset for help on using the changeset viewer.