- Timestamp:
- 03/06/07 14:26:14 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/simplify.cpp
r2127 r2194 28 28 vector<Geometry::Vector2> VMI::vTexCoords; 29 29 30 ////////////////////////////////////////////////////////////////////////// /////30 ////////////////////////////////////////////////////////////////////////// 31 31 32 32 void VMI::bh_mydump(Mesh *mesh, bheap_t *h) { … … 56 56 exit(1); 57 57 } 58 } 58 } 59 59 } 60 60 … … 73 73 for (i = 0; i <mesh->numEdges; i++) { 74 74 75 // Update progress bar. 76 mUPB(percent); 75 if (mUPB) 76 { 77 // Update progress bar. 78 mUPB(percent); 79 } 77 80 78 81 if (mesh->edges[i].enable == TRUE) { … … 226 229 /////////////////////////////////////////////////////////////////////////////// 227 230 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 } 231 int *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; 259 268 } 260 269 … … 365 374 penalized = check_local_inversion(mesh, c); 366 375 #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); 374 381 #endif 375 382 … … 388 395 } 389 396 390 saveProjectedAreas(histogram, numCameras, c, histoAux);397 histoAux = saveProjectedAreas(histogram, numCameras, c); 391 398 // Apply the edge collapse 392 399 doChange(mesh, c); … … 424 431 /////////////////////////////////////////////////////////////////////////////// 425 432 426 saveProjectedAreas(histogram, numCameras, c, histoAux);433 histoAux = saveProjectedAreas(histogram, numCameras, c); 427 434 428 435 doChange(mesh, c); … … 459 466 // Free memory 460 467 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); 463 474 free(vb); 464 475 #endif … … 499 510 e = bh_min(h); 500 511 501 while (!isValidEdge_(mesh, e) ) {512 while (!isValidEdge_(mesh, e) && (h->n >0)) { 502 513 /* delete invalid edge */ 503 514 bh_delete(h, e); … … 510 521 511 522 /* Get the mininum edge cost from the heap using lazy evaluation */ 512 int getMinEdge(Mesh *mesh, bheap_t *h) { 523 int getMinEdge(Mesh *mesh, bheap_t *h) 524 { 513 525 double cost; 514 526 int e; … … 517 529 e = getMinValidEdge(mesh, h); 518 530 519 while (bh_is_dirty(h, e) ) {531 while (bh_is_dirty(h, e) && (h->n >0)) { 520 532 /* delete edge from heap */ 521 533 bh_delete(h, e); … … 560 572 if (bSaveLog == TRUE) 561 573 { 562 #ifdef SALIENCY 574 #ifdef SALIENCY 563 575 sprintf(s,"%s_%s_S.log", filename, EXT); 564 576 #else … … 573 585 if (!file) 574 586 { 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 576 591 exit(1); 577 592 } … … 592 607 printf("Starting simplification...\n"); 593 608 594 while (mesh->currentNumTriangles > numDemandedTri /*&& cost == 0.0*/)609 while (mesh->currentNumTriangles > numDemandedTri && (h->n >0)/*&& cost == 0.0*/) 595 610 { 596 611 // Get the edge that has the minimum cost … … 600 615 c = createChange(mesh, e); 601 616 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 } 643 668 644 669 deleteChange(c);
Note: See TracChangeset
for help on using the changeset viewer.