Ignore:
Timestamp:
03/06/07 14:26:14 (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

    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); 
Note: See TracChangeset for help on using the changeset viewer.