Changeset 2323 for GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs
- Timestamp:
- 04/12/07 09:25:16 (18 years ago)
- Location:
- GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/mesh.h
r2194 r2323 47 47 extern double computeTriangleVolume(Vertex *vertices, Triangle *t); 48 48 49 extern int addEdge(Mesh *mesh, int u, int v); 50 extern int addTriangle(Mesh *mesh, int curGroup, int v1, int v2, int v3); 51 extern int addVertex(Mesh *mesh, float x, float y, float z); 52 49 53 extern Vertex *addVertex(Vertex *list, int *n, float x, float y, float z, int *pos); 50 54 extern int findEdge(Edge *e, int num, int _u, int _v); -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/mesh.cpp
r2194 r2323 212 212 t->normal[2] = cpz / r; 213 213 } 214 int VMI::addEdge(Mesh *mesh, int u, int v) { 215 int n = mesh->numEdges; 216 217 mesh->edges[n].u = u; 218 mesh->edges[n].v = v; 219 mesh->edges[n].enable = TRUE; 220 221 mesh->vertices[u].edges = 222 (int *)realloc(mesh->vertices[u].edges, (mesh->vertices[u].numEdges + 1) * sizeof(int)); 223 // Adding edge n adjacent to vertex u 224 addItem(mesh->vertices[u].edges, &mesh->vertices[u].numEdges, n); 225 226 mesh->vertices[v].edges = 227 (int *)realloc(mesh->vertices[v].edges, (mesh->vertices[v].numEdges + 1) * sizeof(int)); 228 // Adding edge n adjacent to vertex v 229 addItem(mesh->vertices[v].edges, &mesh->vertices[v].numEdges, n); 230 231 mesh->numEdges++; 232 233 return n; 234 } 235 236 int VMI::addVertex(Mesh *mesh, float x, float y, float z) { 237 int n = mesh->numVertices; 238 239 mesh->vertices[n].x = x; 240 mesh->vertices[n].y = y; 241 mesh->vertices[n].z = z; 242 mesh->vertices[n].numTriangles = 0; 243 mesh->vertices[n].triangles = NULL; 244 mesh->vertices[n].numEdges = 0; 245 mesh->vertices[n].edges = NULL; 246 mesh->vertices[n].enable = TRUE; 247 248 mesh->numVertices++; 249 250 return n; 251 } 252 253 int VMI::addTriangle(Mesh *mesh, int curGroup, int v1, int v2, int v3) { 254 int j, n = mesh->numTriangles; 255 256 mesh->triangles[n].id = n; 257 mesh->triangles[n].group = curGroup; // set group 258 mesh->triangles[n].submesh = curGroup; // set group 259 mesh->triangles[n].indices[0] = v1; 260 mesh->triangles[n].indices[1] = v2; 261 mesh->triangles[n].indices[2] = v3; 262 mesh->triangles[n].area = computeTriangleArea(mesh->vertices, &mesh->triangles[n]); 263 //printf("\n%d a: %f",i , mesh->triangles[i].area); 264 computeTriangleNormal(mesh->vertices, &mesh->triangles[n]); 265 mesh->triangles[n].saliency = 0.0; 266 mesh->triangles[n].enable = TRUE; 267 268 for (j=0; j<3; j++) { 269 // Adding triangle n adjacent to 3 vertices 270 v1 = mesh->triangles[n].indices[j]; 271 272 // Reallocate memory for the new adjacent triangle 273 mesh->vertices[v1].triangles = 274 (int *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(int)); 275 addItem(mesh->vertices[v1].triangles, &mesh->vertices[v1].numTriangles, n); 276 } 277 278 mesh->numTriangles++; 279 280 return n; 281 } 214 282 215 283 Mesh *VMI::initMesh(GLMmodel* pmodel) { 216 217 int i, j, curGroup, v1, v2, v3, n, m, t; 218 int e; 219 Mesh *mesh; 220 GLMgroup *group; 221 222 mesh = (Mesh *)malloc (sizeof(Mesh)); 223 224 if (mesh == NULL) { 225 fprintf(stderr, "Error allocating memory\n"); 226 exit(1); 227 } 228 229 mesh->vertices = (Vertex *)malloc (sizeof(Vertex) * pmodel->numvertices); 230 231 if (mesh->vertices == NULL) { 232 fprintf(stderr, "Error allocating memory\n"); 233 exit(1); 234 } 235 236 mesh->triangles = (Triangle *)malloc (sizeof(Triangle) * pmodel->numtriangles); 237 238 if (mesh->triangles == NULL) { 239 fprintf(stderr, "Error allocating memory\n"); 240 exit(1); 241 } 284 int i, e; 285 int v1, v2, v3; 286 float x, y, z; 287 //int *vlist = NULL, j, num; 288 Mesh *mesh; 289 #ifdef OUTPUT_SEVERAL_GROUPS 290 int t; 291 int curGroup; 292 GLMgroup *group; 293 #endif 294 295 mesh = (Mesh *)malloc (sizeof(Mesh)); 296 297 if (mesh == NULL) { 298 fprintf(stderr, "Error allocating memory\n"); 299 exit(1); 300 } 301 302 mesh->vertices = (Vertex *)malloc (sizeof(Vertex) * pmodel->numvertices); 303 mesh->numVertices = 0; 304 305 if (mesh->vertices == NULL) { 306 fprintf(stderr, "Error allocating memory\n"); 307 exit(1); 308 } 309 310 mesh->triangles = (Triangle *)malloc (sizeof(Triangle) * pmodel->numtriangles); 311 mesh->numTriangles = 0; 312 313 if (mesh->triangles == NULL) { 314 fprintf(stderr, "Error allocating memory\n"); 315 exit(1); 316 } 242 317 243 318 printf("Adding vertices..."); 244 for (i=1; i<=(int)pmodel->numvertices; i++) { // Vertices start at 1 245 mesh->vertices[i - 1].x = pmodel->vertices[3 * i + 0]; 246 mesh->vertices[i - 1].y = pmodel->vertices[3 * i + 1]; 247 mesh->vertices[i - 1].z = pmodel->vertices[3 * i + 2]; 248 mesh->vertices[i - 1].numTriangles = 0; 249 mesh->vertices[i - 1].triangles = NULL; 250 mesh->vertices[i - 1].numEdges = 0; 251 mesh->vertices[i - 1].edges = NULL; 252 mesh->vertices[i - 1].enable = GL_TRUE; 253 } 319 for (i=1; i<=(int)pmodel->numvertices; i++) { // Vertices start at 1 320 321 x = pmodel->vertices[3 * i + 0]; 322 y = pmodel->vertices[3 * i + 1]; 323 z = pmodel->vertices[3 * i + 2]; 324 325 addVertex(mesh, x, y, z); 326 } 254 327 printf("Ok\n"); 255 mesh-> numVertices = pmodel->numvertices;256 mesh->currentNumVertices = pmodel->numvertices;328 mesh->currentNumVertices = mesh->numVertices; 329 printf("Number of vertices: %d\n", mesh->numVertices); 257 330 258 331 printf("Adding triangles..."); 259 260 332 #ifdef OUTPUT_SEVERAL_GROUPS 261 333 group = pmodel->groups; 262 334 curGroup=0; // current group 263 while(group) { 264 265 for (i=0; i<(int)group->numtriangles; i++) { 266 267 t = group->triangles[i]; 268 269 mesh->triangles[t].id = t; 270 mesh->triangles[t].group = curGroup; // set group 271 mesh->triangles[t].indices[0] = pmodel->triangles[t].vindices[0] - 1; 272 mesh->triangles[t].indices[1] = pmodel->triangles[t].vindices[1] - 1; 273 mesh->triangles[t].indices[2] = pmodel->triangles[t].vindices[2] - 1; 274 mesh->triangles[t].area = computeTriangleArea(mesh->vertices, &mesh->triangles[t]); 275 //printf("\n%d a: %f",i , mesh->triangles[i].area); 276 computeTriangleNormal(mesh->vertices, &mesh->triangles[t]); 277 278 mesh->triangles[t].saliency = 0.0; 279 280 mesh->triangles[t].enable = GL_TRUE; 281 282 for (j=0; j<3; j++) { 283 // Adding triangle i adjacent to 3 vertices 284 v1 = mesh->triangles[t].indices[j]; 285 286 // Reallocate memory for the new adjacent triangle 287 mesh->vertices[v1].triangles = 288 (int *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(int)); 289 addItem((int *)mesh->vertices[v1].triangles, (int *)&mesh->vertices[v1].numTriangles, t); 290 } 291 } 292 curGroup++; 293 group = group->next; 294 } 335 while(group) { 336 337 for (i=0; i<(int)group->numtriangles; i++) { 338 339 t = group->triangles[i]; 340 341 v1 = pmodel->triangles[t].vindices[0] - 1; 342 v2 = pmodel->triangles[t].vindices[1] - 1; 343 v3 = pmodel->triangles[t].vindices[2] - 1; 344 345 // not a degenerated triangle 346 if ((v1 != v2) && (v2 != v3) && (v1 != v3)) { 347 348 addTriangle(mesh, curGroup, v1, v2, v3); 349 } 350 } 351 curGroup++; 352 group = group->next; 353 } 295 354 #else // One single group 296 for (i=0; i<pmodel->numtriangles; i++) { 297 mesh->triangles[i].id = i; 298 mesh->triangles[i].indices[0] = (int)pmodel->triangles[i].vindices[0] - 1; 299 mesh->triangles[i].indices[1] = (int)pmodel->triangles[i].vindices[1] - 1; 300 mesh->triangles[i].indices[2] = (int)pmodel->triangles[i].vindices[2] - 1; 301 mesh->triangles[i].area = computeTriangleArea(mesh->vertices, &mesh->triangles[i]); 302 //printf("\n%d a: %f",i , mesh->triangles[i].area); 303 computeTriangleNormal(mesh->vertices, &mesh->triangles[i]); 304 305 mesh->triangles[i].saliency = 0.0; 306 307 mesh->triangles[i].enable = GL_TRUE; 308 309 for (j=0; j<3; j++) { 310 // Adding triangle i adjacent to 3 vertices 311 v1 = mesh->triangles[i].indices[j]; 312 313 // Reallocate memory for the new adjacent triangle 314 mesh->vertices[v1].triangles = 315 (int *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(int)); 316 addItem((int *)mesh->vertices[v1].triangles, (int *)&mesh->vertices[v1].numTriangles, i); 317 } 318 } 355 for (i=0; i<(int)pmodel->numtriangles; i++) { 356 357 v1 = pmodel->triangles[i].vindices[0] - 1; 358 v2 = pmodel->triangles[i].vindices[1] - 1; 359 v3 = pmodel->triangles[i].vindices[2] - 1; 360 361 // not a degenerated triangle 362 if ((v1 != v2) && (v2 != v3) && (v1 != v3)) { 363 364 addTriangle(mesh, 1, v1, v2, v3); 365 } 366 } 319 367 printf("\n"); 320 368 #endif 369 printf("Ok\n"); 370 mesh->currentNumTriangles = mesh->numTriangles; 371 printf("Number of triangles: %d\n", mesh->numTriangles); 372 printf("Number of degenerated triangles: %d\n", pmodel->numtriangles - mesh->numTriangles); 373 374 mesh->edges = (Edge *)malloc (sizeof(Edge) * mesh->numTriangles * 3); // E = 3 T / 2 375 mesh->numEdges = 0; 376 377 if (mesh->edges == NULL) { 378 fprintf(stderr, "Error allocating memory\n"); 379 exit(1); 380 } 381 382 printf("Adding edges..."); 383 384 /*for (i=0; i<mesh->numVertices; i++) { 385 vlist = verticesAdjToVertex(mesh, i, &num); 386 387 for (j=0; j<num; j++) { 388 389 if (i < vlist[j]) { 390 391 addEdge(mesh, i, vlist[j]); 392 } 393 } 394 free(vlist); 395 }*/ 396 397 for (i=0; i<mesh->numTriangles; i++) { 398 399 v1 = mesh->triangles[i].indices[0]; 400 v2 = mesh->triangles[i].indices[1]; 401 v3 = mesh->triangles[i].indices[2]; 402 403 ///////////////////////////////////////////////////////////////////////////////// 404 // edge (v1,v2) 405 if ((e = findEdge(mesh->edges, mesh->numEdges, v1, v2)) == -1) { 406 407 addEdge(mesh, v1, v2); 408 } 409 ///////////////////////////////////////////////////////////////////////////////// 410 // edge (v2,v3) 411 if ((e = findEdge(mesh->edges, mesh->numEdges, v2, v3)) == -1) { 412 413 addEdge(mesh, v2, v3); 414 } 415 ///////////////////////////////////////////////////////////////////////////////// 416 // edge (v3,v1) 417 if ((e = findEdge(mesh->edges, mesh->numEdges, v3, v1)) == -1) { 418 419 addEdge(mesh, v3, v1); 420 } 421 } 321 422 printf("Ok\n"); 322 323 mesh->numTriangles = pmodel->numtriangles;324 mesh->currentNumTriangles = pmodel->numtriangles;325 printf("Number of triangles: %d\n", mesh->numTriangles);326 327 mesh->edges = (Edge *)malloc (sizeof(Edge) * mesh->numTriangles * 3); // E = 3 T / 2328 329 if (mesh->edges == NULL) {330 fprintf(stderr, "Error allocating memory\n");331 exit(1);332 }333 334 printf("Adding edges...");335 n = 0;336 337 for (i=0; i<mesh->numTriangles; i++) {338 t = 0;339 v1 = mesh->triangles[i].indices[0];340 v2 = mesh->triangles[i].indices[1];341 v3 = mesh->triangles[i].indices[2];342 343 /////////////////////////////////////////////////////////////////////////////////344 // edge (v1,v2)345 if ((e = findEdge(mesh->edges, n, v1, v2)) == -1) {346 mesh->edges[n].u = v1;347 mesh->edges[n].v = v2;348 mesh->edges[n].enable = GL_TRUE;349 m = n;350 n++;351 } else m = e;352 353 /////////////////////////////////////////////////////////////////////////////////354 // edge (v2,v3)355 if (( e = findEdge(mesh->edges, n, v2, v3)) == -1) {356 mesh->edges[n].u = v2;357 mesh->edges[n].v = v3;358 mesh->edges[n].enable = GL_TRUE;359 m = n;360 n++;361 } else m = e;362 363 /////////////////////////////////////////////////////////////////////////////////364 // edge (v3,v1)365 if ((e = findEdge(mesh->edges, n, v3, v1)) == -1) {366 mesh->edges[n].u = v3;367 mesh->edges[n].v = v1;368 mesh->edges[n].enable = GL_TRUE;369 m = n;370 n++;371 } else m = e;372 }373 printf("Ok\n");374 mesh->numEdges = n;375 376 for (i=0; i<mesh->numEdges; i++) {377 v1 = mesh->edges[i].u;378 v2 = mesh->edges[i].v;379 380 mesh->vertices[v1].edges =381 (int *)realloc(mesh->vertices[v1].edges, (mesh->vertices[v1].numEdges + 1) * sizeof(int));382 // Adding edge i adjacent to vertex v1383 addItem(mesh->vertices[v1].edges, &mesh->vertices[v1].numEdges, i);384 385 mesh->vertices[v2].edges =386 (int *)realloc(mesh->vertices[v2].edges, (mesh->vertices[v2].numEdges + 1) * sizeof(int));387 // Adding edge i adjacent to vertex v2388 addItem(mesh->vertices[v2].edges, &mesh->vertices[v2].numEdges, i);389 }390 423 391 424 return mesh; -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/saliency.cpp
r2127 r2323 58 58 59 59 double VMI::computeTriangleSaliency(Mesh *mesh, int **histogram, int numCameras, int k) { 60 int i, l, v0, v1, v2;61 int *triangles = NULL,n = 0;60 int i, j, t, v0; 61 int n = 0; 62 62 double sal = 0.0; 63 63 64 v0 = mesh->triangles[k].indices[0]; 65 v1 = mesh->triangles[k].indices[1]; 66 v2 = mesh->triangles[k].indices[2]; 67 68 /* Allocating memory */ 69 triangles = (int *)malloc((mesh->vertices[v0].numTriangles + 70 mesh->vertices[v1].numTriangles + 71 mesh->vertices[v2].numTriangles) * sizeof(int)); 72 73 for(i=0; i<mesh->vertices[v0].numTriangles; i++) { 74 l = mesh->vertices[v0].triangles[i]; 64 for (j=0; j<3; j++) { 75 65 76 if (l != k) 77 addItem(triangles, &n, l); 78 } 79 80 for(i=0; i<mesh->vertices[v1].numTriangles; i++) { 81 l = mesh->vertices[v1].triangles[i]; 66 v0 = mesh->triangles[k].indices[j]; 82 67 83 if (l != k) 84 addItem(triangles, &n, l); 85 } 86 87 for(i=0; i<mesh->vertices[v2].numTriangles; i++) { 88 l = mesh->vertices[v2].triangles[i]; 89 90 if (l != k) 91 addItem(triangles, &n, l); 92 } 93 94 //printItemList(triangles, n); 95 96 for(i=0; i<n; i++) { 97 //printf("\n%d %d", k, triangles[i]); 98 //sal += computeJS(histogram, numCameras, k, triangles[i]); 99 sal = MAX ( sal, computeJS(histogram, numCameras, k, triangles[i])); 68 for(i=0; i<mesh->vertices[v0].numTriangles; i++) { 69 t = mesh->vertices[v0].triangles[i]; 70 71 if (t != k) { 72 //printf("\n%d %d", k, triangles[i]); 73 //sal += computeJS(histogram, numCameras, k, t); 74 sal = MAX(sal, computeJS(histogram, numCameras, k, t)); 75 76 n++; 77 } 78 } 100 79 } 101 80 //printf("\nT%d Sal: %f\n", k, (sal / n)); 102 81 //getchar(); 103 82 104 free(triangles);105 106 83 return (sal /*/ n*/); 107 84 }
Note: See TracChangeset
for help on using the changeset viewer.