- Timestamp:
- 06/09/06 08:24:19 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/simplify.cpp
r983 r1007 424 424 /////////////////////////////////////////////////////////////////////////////// 425 425 426 void VMI::simplifyModel(Mesh *mesh, GLuint numDemandedTri) { 427 int e; 428 Change *c; 429 FILE* file = NULL; 430 char s[MAX_CHAR]; 431 double cost = 0.0; 432 bheap_t *h = NULL; 433 float percent = (40.0) / (float)(mesh->numTriangles - numDemandedTri); 434 435 if (numDemandedTri > mesh->currentNumTriangles) return; 436 437 if (bSaveLog == TRUE) { // Save changes into a file 426 void VMI::simplifyModel(Mesh *mesh, GLuint numDemandedTri) 427 { 428 int e; 429 Change *c; 430 FILE *file = NULL; 431 FILE *file_simp_seq = NULL; 432 char s[MAX_CHAR]; 433 double cost = 0.0; 434 bheap_t *h = NULL; 435 float percent = (40.0) / (float)(mesh->numTriangles - numDemandedTri); 436 437 if (numDemandedTri > mesh->currentNumTriangles) 438 { 439 return; 440 } 441 442 // Save changes into a file 443 if (bSaveLog == TRUE) 444 { 438 445 #ifdef SALIENCY 439 446 #ifdef KL // Kullback-Leibler 440 447 sprintf(s,"%s_VKL_S.log", filename); 441 448 #endif 442 449 #ifdef MI // Mutual Information 443 450 sprintf(s,"%s_VMI_S.log", filename); 444 451 #endif 445 452 #ifdef HE // Hellinger 446 453 sprintf(s,"%s_VHE_S.log", filename); 447 454 #endif 448 455 #ifdef CS // Chi-Square 449 456 sprintf(s,"%s_VCS_S.log", filename); 450 457 #endif 451 458 #else 452 459 #ifdef KL // Kullback-Leibler 453 460 sprintf(s,"%s_VKL.log", filename); 454 461 #endif 455 462 #ifdef MI // Mutual Information 456 463 sprintf(s,"%s_VMI.log", filename); 457 464 #endif 458 465 #ifdef HE // Hellinger 459 466 sprintf(s,"%s_VHE.log", filename); 460 467 #endif 461 468 #ifdef CS // Chi-Square 462 sprintf(s,"%s_VCS.log", filename); 463 #endif 464 #endif 465 466 glmWriteOBJ(pmodel, s, GLM_NONE); 467 468 /* open the file */ 469 file = fopen(s, "a+"); 470 if (!file) { 471 fprintf(stderr, "simplifyModel() failed: can't open file \"%s\" to write.\n", s); 472 exit(1); 473 } 474 } 475 476 h = initHeap(mesh); 477 478 printf("Starting simplification...\n"); 479 480 while (mesh->currentNumTriangles > numDemandedTri /*&& cost == 0.0*/) { 481 482 // Get the edge that has the minimum cost 483 e = bh_min(h); 484 485 c = createChange(mesh, e); 486 487 // Apply the edge collapse 488 computeChanges(mesh, c); 489 doChange(mesh, c); 490 491 if (bSaveLog == TRUE) writeChange(file, c); 492 493 cost = h->a[h->p[e]].key; 494 printf("Edge collapse e%d(%d,%d) %f MIN d %d m %d\n",c->e, c->u, c->v, cost, c->numDel, c->numMod); 495 496 mesh->edges[e].enable = FALSE; 497 bh_delete(h, e); 498 499 // Get projected areas after the edge collapse 500 getProjectedAreas(histogram, numCameras); 501 502 computeCameraIs(histogram, numCameras, initialIs); 503 504 // Update the heap according to the edge collapse 505 h = updateHeap(h, mesh, c); 506 507 mUPB((float)c->numDel * percent); 508 509 deleteChange(c); 510 511 printf("t %d\n", mesh->currentNumTriangles); 512 } 513 514 if (bSaveLog == TRUE) { 515 fclose(file); 516 printf("Log file written...Ok\n"); 517 } 518 519 bh_free(h); 520 } 469 sprintf(s,"%s_VCS.log", filename); 470 #endif 471 #endif 472 473 glmWriteOBJ(pmodel, s, GLM_NONE); 474 475 /* open the file */ 476 file = fopen(s, "a+"); 477 478 if (!file) 479 { 480 fprintf(stderr, "simplifyModel() failed: can't open file \"%s\" to write.\n", s); 481 exit(1); 482 } 483 } 484 485 // Open file of simplification sequence. 486 file_simp_seq = fopen("SimplifSequence.txt", "w"); 487 488 if (!file_simp_seq) 489 { 490 fprintf(stderr, 491 "simplifyModel() failed: ", 492 "can't open file \"SimplifSequence\" to write.\n"); 493 } 494 495 h = initHeap(mesh); 496 497 printf("Starting simplification...\n"); 498 499 while (mesh->currentNumTriangles > numDemandedTri /*&& cost == 0.0*/) 500 { 501 // Get the edge that has the minimum cost 502 e = bh_min(h); 503 504 c = createChange(mesh, e); 505 506 // Apply the edge collapse 507 computeChanges(mesh, c); 508 doChange(mesh, c); 509 510 if (bSaveLog == TRUE) writeChange(file, c); 511 512 // Write Simplification sequence. 513 saveSimplificationSequence(c); 514 515 cost = h->a[h->p[e]].key; 516 517 printf( "Edge collapse e%d(%d,%d) %f MIN d %d m %d\n", 518 c->e, 519 c->u, 520 c->v, 521 cost, 522 c->numDel, 523 c->numMod); 524 525 mesh->edges[e].enable = FALSE; 526 527 bh_delete(h, e); 528 529 // Get projected areas after the edge collapse 530 getProjectedAreas(histogram, numCameras); 531 532 computeCameraIs(histogram, numCameras, initialIs); 533 534 // Update the heap according to the edge collapse 535 h = updateHeap(h, mesh, c); 536 537 mUPB((float)c->numDel * percent); 538 539 deleteChange(c); 540 541 printf("t %d\n", mesh->currentNumTriangles); 542 } 543 544 if (bSaveLog == TRUE) 545 { 546 fclose(file); 547 printf("Log file written...Ok\n"); 548 } 549 550 // Close simplification sequence file. 551 fclose(file_simp_seq); 552 553 bh_free(h); 554 } 555
Note: See TracChangeset
for help on using the changeset viewer.