- Timestamp:
- 02/19/07 09:16:59 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/simplify.cpp
r2103 r2127 10 10 #include "../include/saliency.h" 11 11 #include "../include/histogram.h" 12 #include "../include/buffers.h" 12 13 13 14 //#define RECOMPUTE_THE_WHOLE_HEAP … … 59 60 60 61 bheap_t *VMI::initHeap(Mesh *mesh) { 61 GLuint i;62 int i; 62 63 double cost; 63 64 bheap_t *h = NULL; … … 152 153 153 154 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));172 155 } 173 156 … … 243 226 /////////////////////////////////////////////////////////////////////////////// 244 227 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++) {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++) { 249 232 250 233 t = c->deleted[j].id; … … 257 240 } 258 241 259 for (j=0; j< (GLuint)c->numMod; j++) {242 for (j=0; j<c->numMod; j++) { 260 243 261 244 t = c->modified[j].id; … … 276 259 } 277 260 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++) {261 void 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++) { 282 265 283 266 t = c->deleted[j].id; … … 290 273 } 291 274 292 for (j=0; j< (GLuint)c->numMod; j++) {275 for (j=0; j<c->numMod; j++) { 293 276 294 277 t = c->modified[j].id; … … 308 291 } 309 292 } 310 311 293 /////////////////////////////////////////////////////////////////////////////// 294 #ifdef CHECK_LOCAL_INVERSION 295 int 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 312 338 313 339 GLdouble VMI::computeEdgeCost(Mesh *mesh, int e) { … … 318 344 GLdouble newI; 319 345 #endif 320 GLuint i, *histoAux = NULL;346 int i, *histoAux = NULL; 321 347 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 322 354 323 355 chooseBestEndPoints(mesh, e); … … 327 359 328 360 // 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 331 367 // 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 333 375 334 376 #ifdef MI // Mutual Information … … 365 407 //printf(" I0:%f Is: %f\n", auxE[i], initialIs[i]); 366 408 367 cost += (ABS(auxIs[i] - initialIs[i]) * cameras[i].weight * sal);409 cost += (ABS(auxIs[i] - initialIs[i]) * cameras[i].weight); 368 410 369 411 // Restore old informations … … 405 447 newI = computeCS(mesh, histogram[i]); 406 448 #endif 407 cost += (ABS(initialIs[i] - newI) * cameras[i].weight * sal);449 cost += (ABS(initialIs[i] - newI) * cameras[i].weight); 408 450 } 409 451 undoChange(mesh, c); … … 417 459 // Free memory 418 460 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 419 468 420 469 } else cost = FLT_MAX; … … 422 471 deleteChange(c); 423 472 424 return cost; 425 } 473 return (cost * sal); 474 } 475 476 int 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 426 494 /* Get a valid edge from the heap */ 427 495 int getMinValidEdge(Mesh *mesh, bheap_t *h) { … … 431 499 e = bh_min(h); 432 500 433 while ( mesh->edges[e].enable == FALSE) {501 while (!isValidEdge_(mesh, e)) { 434 502 /* delete invalid edge */ 435 503 bh_delete(h, e); … … 473 541 474 542 /////////////////////////////////////////////////////////////////////////// 475 void VMI::simplifyModel(Mesh *mesh, GLuint numDemandedTri)543 void VMI::simplifyModel(Mesh *mesh, int numDemandedTri) 476 544 { 477 545 int e; … … 558 626 bh_delete(h, e); 559 627 628 updateHWAcceleration(c); 629 560 630 // Get projected areas after the edge collapse 561 631 getProjectedAreas(histogram, numCameras); … … 563 633 computeCameraIs(histogram, numCameras, initialIs); 564 634 565 deleteEdges(mesh, c); 566 modifyEdges(mesh, c); 635 updateEdgeAdj(mesh, c); 636 637 modifyEdges(mesh, c); 567 638 568 639 // Update the heap according to the edge collapse … … 751 822 752 823 Edge *econ; 753 float x,y,z;754 824 int *lv1; 755 825 int v0; … … 797 867 v1 = (*lb1).second; 798 868 799 lv1 = edgesAdjToVertex(mesh,v1,&num_edges); 869 lv1 = mesh->vertices[v1].edges; 870 num_edges = mesh->vertices[v1].numEdges; 800 871 801 872 // Edje iterator. … … 857 928 858 929 deleteVertexOfMap(mesh, c->u); 859 deleteEdges(mesh, c);860 930 updateEdgeAdj(mesh, c); 931 modifyEdges(mesh, c); 861 932 deleteChange(c); 862 933 … … 910 981 lonely_vert = (*it).second; 911 982 912 le = edgesAdjToVertex(mesh,lonely_vert,&num_edges); 983 le = mesh->vertices[lonely_vert].edges; 984 985 num_edges = mesh->vertices[lonely_vert].numEdges; 913 986 914 987 // Find an edge width v coordinates. … … 977 1050 978 1051 deleteVertexOfMap(mesh, c->u); 979 deleteEdges(mesh, c);980 1052 updateEdgeAdj(mesh, c); 1053 modifyEdges(mesh, c); 981 1054 deleteChange(c); 982 1055 } … … 1069 1142 1070 1143 deleteVertexOfMap(mesh, c->u); 1071 deleteEdges(mesh, c);1072 1144 updateEdgeAdj(mesh, c); 1145 modifyEdges(mesh, c); 1073 1146 deleteChange(c); 1074 1147 }
Note: See TracChangeset
for help on using the changeset viewer.