Ignore:
Timestamp:
02/19/07 09:16:59 (17 years ago)
Author:
gumbau
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/simplify.cpp

    r2103 r2127  
    1010#include "../include/saliency.h" 
    1111#include "../include/histogram.h" 
     12#include "../include/buffers.h" 
    1213 
    1314//#define RECOMPUTE_THE_WHOLE_HEAP 
     
    5960 
    6061bheap_t *VMI::initHeap(Mesh *mesh) { 
    61         GLuint i; 
     62        int i; 
    6263        double cost; 
    6364        bheap_t *h = NULL; 
     
    152153 
    153154        return h; 
    154 } 
    155  
    156 GLdouble VMI::computeEdgeLength(Vertex *vertices, int u, int v) { 
    157         GLfloat ux, uy, uz, vx, vy ,vz, rx, ry, rz; 
    158  
    159         ux = vertices[u].x; 
    160         uy = vertices[u].y; 
    161         uz = vertices[u].z; 
    162  
    163         vx = vertices[v].x; 
    164         vy = vertices[v].y; 
    165         vz = vertices[v].z; 
    166  
    167         rx = ux - vx; 
    168         ry = uy - vy; 
    169         rz = uz - vz; 
    170  
    171         return sqrt((rx * rx) + (ry * ry) + (rz * rz)); 
    172155} 
    173156 
     
    243226/////////////////////////////////////////////////////////////////////////////// 
    244227 
    245 void saveProjectedAreas(GLuint **histogram, GLuint numCameras, Change *c, GLuint *dest) { 
    246         GLuint i, j, t, n = 0; 
    247  
    248         for (j=0; j<(GLuint)c->numDel; j++) { 
     228void 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++) { 
    249232 
    250233                t = c->deleted[j].id; 
     
    257240        } 
    258241 
    259         for (j=0; j<(GLuint)c->numMod; j++) {  
     242        for (j=0; j<c->numMod; j++) {  
    260243 
    261244                t = c->modified[j].id; 
     
    276259} 
    277260 
    278 void loadProjectedAreas(GLuint *src, GLuint numCameras, Change *c, GLuint **histogram) { 
    279         GLuint i, j, t, n = 0; 
    280  
    281         for (j=0; j<(GLuint)c->numDel; j++) {  
     261void loadProjectedAreas(int *src, int numCameras, Change *c, int **histogram) { 
     262        int i, j, t, n = 0; 
     263 
     264        for (j=0; j<c->numDel; j++) {  
    282265 
    283266                t = c->deleted[j].id; 
     
    290273        } 
    291274 
    292         for (j=0; j<(GLuint)c->numMod; j++) {  
     275        for (j=0; j<c->numMod; j++) {  
    293276 
    294277                t = c->modified[j].id; 
     
    308291        } 
    309292} 
    310  
    311293/////////////////////////////////////////////////////////////////////////////// 
     294#ifdef CHECK_LOCAL_INVERSION 
     295int check_local_inversion(Mesh *mesh, Change *c) { 
     296    int i, t; 
     297    int v0, v1, v2; 
     298    double vol_before; 
     299    double vol_after; 
     300    Triangle tri; 
     301     
     302    for(i=0; i<mesh->vertices[c->u].numTriangles; i++) { 
     303         
     304        t = mesh->vertices[c->u].triangles[i]; 
     305         
     306        v0 = mesh->triangles[t].indices[0]; 
     307        v1 = mesh->triangles[t].indices[1]; 
     308        v2 = mesh->triangles[t].indices[2]; 
     309         
     310        if ((v0 != c->v) && (v1 != c->v) && (v2 != c->v)) { 
     311             
     312            //printf("%d\n", t); 
     313            memcpy(&tri, &mesh->triangles[t], sizeof(Triangle)); 
     314             
     315            vol_before = computeTriangleVolume(mesh->vertices, &tri); 
     316 
     317            //printf("t:[%d,%d,%d]\n", tri.indices[0], tri.indices[1], tri.indices[2]); 
     318            //printf("v:%f\n", vol_before); 
     319           
     320            if (tri.indices[0] == c->u) tri.indices[0] = c->v; 
     321            if (tri.indices[1] == c->u) tri.indices[1] = c->v; 
     322            if (tri.indices[2] == c->u) tri.indices[2] = c->v; 
     323             
     324            vol_after = computeTriangleVolume(mesh->vertices, &tri); 
     325 
     326            //printf("t:[%d,%d,%d]\n", tri.indices[0], tri.indices[1], tri.indices[2]); 
     327            //printf("v:%f\n", vol_after); 
     328 
     329            if (((vol_before > 0) && (vol_after < 0)) ||  
     330                ((vol_before < 0) && (vol_after > 0))) 
     331 
     332                return TRUE; 
     333        } 
     334    } 
     335    return FALSE; 
     336} 
     337#endif 
    312338 
    313339GLdouble VMI::computeEdgeCost(Mesh *mesh, int e) { 
     
    318344        GLdouble newI; 
    319345#endif 
    320         GLuint i, *histoAux = NULL; 
     346        int i, *histoAux = NULL; 
    321347        Change *c; 
     348#if defined(VERTEX_BUFFER_OBJECTS) || defined(VERTEX_ARRAY) 
     349    VertexIL *vb = NULL; 
     350#endif 
     351#ifdef CHECK_LOCAL_INVERSION 
     352    int penalized; 
     353#endif 
    322354 
    323355        chooseBestEndPoints(mesh, e); 
     
    327359 
    328360        // Compute cost only for boundary or manifold edges 
    329         if (c->numDel == 2 
    330                         /*(c->numDel <3) && (c->numDel > 0)*/) { 
     361        if (/*c->numDel == 2*/ 
     362                        (c->numDel <3) && (c->numDel > 0)) { 
     363 
     364#ifdef CHECK_LOCAL_INVERSION 
     365        penalized = check_local_inversion(mesh, c); 
     366#endif 
    331367                // Allocate memory 
    332                 histoAux = (GLuint *)malloc((c->numDel + c->numMod + 1) * numCameras * sizeof(GLuint)); 
     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); 
     374#endif 
    333375 
    334376#ifdef MI // Mutual Information 
     
    365407                        //printf("  I0:%f Is: %f\n", auxE[i], initialIs[i]); 
    366408 
    367                         cost += (ABS(auxIs[i] - initialIs[i]) * cameras[i].weight * sal); 
     409                        cost += (ABS(auxIs[i] - initialIs[i]) * cameras[i].weight); 
    368410 
    369411                        // Restore old informations 
     
    405447                        newI = computeCS(mesh, histogram[i]); 
    406448#endif 
    407                         cost += (ABS(initialIs[i] - newI) * cameras[i].weight * sal); 
     449                        cost += (ABS(initialIs[i] - newI) * cameras[i].weight); 
    408450                } 
    409451                undoChange(mesh, c); 
     
    417459                // Free memory 
    418460                free(histoAux); 
     461#if defined(VERTEX_BUFFER_OBJECTS) || defined(VERTEX_ARRAY) 
     462        loadVertexBuffer(vb, c); 
     463        free(vb); 
     464#endif 
     465#ifdef CHECK_LOCAL_INVERSION 
     466        if (penalized) cost *= 5; 
     467#endif 
    419468 
    420469        } else cost = FLT_MAX; 
     
    422471        deleteChange(c); 
    423472 
    424         return cost; 
    425 } 
     473        return (cost * sal); 
     474} 
     475 
     476int isValidEdge_(Mesh *mesh, int e) { 
     477    int u , v; 
     478 
     479    if (mesh->edges[e].enable == FALSE) return FALSE; 
     480    else { 
     481        u = mesh->edges[e].u; 
     482        v = mesh->edges[e].v; 
     483 
     484        if (u == v) { 
     485 
     486            mesh->edges[e].enable = FALSE; 
     487            return FALSE; 
     488        } 
     489    } 
     490 
     491    return TRUE; 
     492} 
     493 
    426494/* Get a valid edge from the heap */ 
    427495int getMinValidEdge(Mesh *mesh, bheap_t *h) { 
     
    431499        e = bh_min(h); 
    432500 
    433         while (mesh->edges[e].enable == FALSE) { 
     501        while (!isValidEdge_(mesh, e)) { 
    434502                /* delete invalid edge */ 
    435503                bh_delete(h, e); 
     
    473541 
    474542/////////////////////////////////////////////////////////////////////////// 
    475 void VMI::simplifyModel(Mesh *mesh, GLuint numDemandedTri) 
     543void VMI::simplifyModel(Mesh *mesh, int numDemandedTri) 
    476544{ 
    477545        int                     e; 
     
    558626                bh_delete(h, e); 
    559627 
     628                updateHWAcceleration(c); 
     629 
    560630                // Get projected areas after the edge collapse 
    561631                getProjectedAreas(histogram, numCameras); 
     
    563633                computeCameraIs(histogram, numCameras, initialIs); 
    564634 
    565                 deleteEdges(mesh, c); 
    566                 modifyEdges(mesh, c); 
     635                updateEdgeAdj(mesh, c); 
     636 
     637    modifyEdges(mesh, c); 
    567638 
    568639                // Update the heap according to the edge collapse 
     
    751822 
    752823        Edge            *econ; 
    753         float           x,y,z; 
    754824        int                     *lv1; 
    755825        int                     v0; 
     
    797867                        v1      =       (*lb1).second; 
    798868 
    799                         lv1     =       edgesAdjToVertex(mesh,v1,&num_edges); 
     869                        lv1     =       mesh->vertices[v1].edges; 
     870                        num_edges = mesh->vertices[v1].numEdges; 
    800871 
    801872                        //      Edje iterator. 
     
    857928 
    858929                        deleteVertexOfMap(mesh, c->u); 
    859                         deleteEdges(mesh, c); 
    860                         modifyEdges(mesh, c); 
     930                        updateEdgeAdj(mesh, c); 
     931      modifyEdges(mesh, c); 
    861932                        deleteChange(c); 
    862933 
     
    910981                        lonely_vert     =       (*it).second; 
    911982 
    912                         le      =       edgesAdjToVertex(mesh,lonely_vert,&num_edges); 
     983                        le      =       mesh->vertices[lonely_vert].edges; 
     984 
     985                        num_edges = mesh->vertices[lonely_vert].numEdges; 
    913986 
    914987                        //      Find an edge width v coordinates. 
     
    9771050 
    9781051                                deleteVertexOfMap(mesh, c->u); 
    979                                 deleteEdges(mesh, c); 
    980                                 modifyEdges(mesh, c); 
     1052                                updateEdgeAdj(mesh, c); 
     1053        modifyEdges(mesh, c); 
    9811054                                deleteChange(c); 
    9821055                        } 
     
    10691142 
    10701143                                deleteVertexOfMap(mesh, c->u); 
    1071                                 deleteEdges(mesh, c); 
    1072                                 modifyEdges(mesh, c); 
     1144                                updateEdgeAdj(mesh, c); 
     1145        modifyEdges(mesh, c); 
    10731146                                deleteChange(c); 
    10741147                        } 
Note: See TracChangeset for help on using the changeset viewer.