Changeset 1007 for GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi
- Timestamp:
- 06/09/06 08:24:19 (19 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/change.h
r983 r1007 2 2 #define __change_h_ 3 3 4 #include "mesh.h" 4 #include "mesh.h" 5 #include <vector> 5 6 6 7 namespace VMI 7 8 { 8 typedef struct change { 9 int e; 10 int u, v; // Edge 11 int numDel; // Number of deleted triangles 12 Triangle *deleted; // List of deleted triangles 13 int numMod; // Number of modified triangles 14 Triangle *modified; // List of triangles deleted 15 } Change; 9 typedef struct change 10 { 11 int e; 12 int u, v; // Edge 13 int numDel; // Number of deleted triangles 14 Triangle *deleted; // List of deleted triangles 15 int numMod; // Number of modified triangles 16 Triangle *modified; // List of triangles deleted 17 } Change; 16 18 17 extern Change *createChange (Mesh *mesh, int e); 18 extern void writeChange(FILE* file, Change *c); 19 extern void deleteChange(Change *c); 20 extern void printChange(Change *c); 19 // Represents a simplification step in the sequence. 20 struct vmiStep 21 { 22 unsigned int mV0; 23 unsigned int mV1; 24 unsigned int mT0; 25 unsigned int mT1; 26 float x; 27 float y; 28 float z; 29 30 std::vector<unsigned int> mModfaces; 21 31 22 extern void modifyTriangle(Triangle *t, int c, int p); 23 extern int isATriangleToModify(Triangle *t, int c, int p); 24 extern int getTrianglesToModify(Mesh *mesh, int c, int p, Triangle *modified); 25 extern int isATriangleToDelete(Triangle *t, int c, int p); 26 extern int getTrianglesToDelete(Mesh *mesh, int numMod, Triangle *modified, Triangle *deleted, int c, int p); 32 // Indicates the the step is obligatory to execute 33 // joined width the following step. 34 unsigned int obligatory; 35 }; 27 36 28 extern void modifyTriangles(Mesh *mesh, Change *c); 29 extern void unmodifyTriangles(Mesh *mesh, Change *c); 30 extern void deleteTriangles(Mesh *mesh, Change *c); 31 extern void undeleteTriangles(Mesh *mesh, Change *c); 37 // Stores all the simplification steps. 38 extern std::vector<vmiStep> mVMISteps; 32 39 33 extern void printList(Triangle *list, int n); 34 extern void deleteItem(Triangle *list, int *n, int item); 40 extern Change *createChange (Mesh *mesh, int e); 41 extern void writeChange(FILE* file, Change *c); 42 extern void deleteChange(Change *c); 43 extern void printChange(Change *c); 35 44 36 extern void doChange(Mesh *mesh, Change *c); 37 extern void undoChange(Mesh *mesh, Change *c); 38 extern void computeChanges(Mesh *mesh, Change *c); 45 extern void modifyTriangle(Triangle *t, int c, int p); 46 extern int isATriangleToModify(Triangle *t, int c, int p); 47 extern int getTrianglesToModify(Mesh *mesh, int c, int p, Triangle *modified); 48 extern int isATriangleToDelete(Triangle *t, int c, int p); 49 extern int getTrianglesToDelete(Mesh *mesh, int numMod, Triangle *modified, Triangle *deleted, int c, int p); 39 50 51 extern void modifyTriangles(Mesh *mesh, Change *c); 52 extern void unmodifyTriangles(Mesh *mesh, Change *c); 53 extern void deleteTriangles(Mesh *mesh, Change *c); 54 extern void undeleteTriangles(Mesh *mesh, Change *c); 55 56 extern void printList(Triangle *list, int n); 57 extern void deleteItem(Triangle *list, int *n, int item); 58 59 extern void doChange(Mesh *mesh, Change *c); 60 extern void undoChange(Mesh *mesh, Change *c); 61 extern void computeChanges(Mesh *mesh, Change *c); 62 63 // Save simplification sequence in Geometry Game Tools format. 64 extern void saveSimplificationSequence(Change *c); 40 65 } 41 66 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/change.cpp
r983 r1007 9 9 10 10 using namespace VMI; 11 12 std::vector<VMI::vmiStep> VMI::mVMISteps; 11 13 12 14 Change *VMI::createChange (Mesh *mesh, int e) { … … 29 31 } 30 32 31 void VMI::deleteChange(Change *c) { 32 33 if (NULL != c) { 34 if (c->deleted != NULL) free(c->deleted); 35 if (c->modified != NULL) free(c->modified); 36 c->modified = NULL; 37 c->deleted = NULL; 38 c->numDel = 0; 39 c->numMod = 0; 40 41 free(c); 42 c = NULL; 43 } 44 } 45 46 void VMI::writeChange(FILE* file, Change *c) { 47 int i; 48 49 fputc('v',file); 50 fputc('%',file); 51 fprintf(file, " %d %d 0 0 0 ", c->v, c->u); 52 53 for (i=0; i<c->numDel; i++) { 54 fprintf(file, "%d ", c->deleted[i].id); 55 } 56 57 fputc('&',file); 58 for (i=0; i<c->numMod; i++) { 59 fprintf(file, " %d", c->modified[i].id); 60 } 61 62 fputc('\n',file); 63 } 64 65 void VMI::printChange(Change *c) { 66 int i; 67 68 if (NULL != c) { 69 70 printf("e%d(%d,%d)\n",c->e,c->u,c->v); 71 72 printf("d %d\n", c->numDel); 73 for (i=0;i<c->numDel;i++) { 74 printf(" %d", c->deleted[i].id); 75 } 76 printf("\n"); 77 printf("m %d\n", c->numMod); 78 for (i=0;i<c->numMod;i++) { 79 printf(" %d", c->modified[i].id); 80 } 81 printf("\n"); 82 } 83 } 84 85 void VMI::modifyTriangle(Triangle *t, int c, int p) { 86 87 if ((int)t->indices[0] == c) 88 t->indices[0]= p; 89 if ((int)t->indices[1] == c) 90 t->indices[1]= p; 91 if ((int)t->indices[2] == c) 92 t->indices[2]= p; 93 } 94 95 int VMI::isATriangleToModify(Triangle *t, int c, int p) { 96 int u = t->indices[0], 97 v = t->indices[1], 98 w = t->indices[2]; 99 100 if ((u == c) || (v == c) || (w == c)) return TRUE; 101 102 return FALSE; 103 } 104 105 void VMI::modifyTriangles(Mesh *mesh, Change *c) { 106 int i, t; 107 108 for (i=0; i<c->numMod; i++) { 109 t = c->modified[i].id; 110 modifyTriangle(&mesh->triangles[t], c->u, c->v); 111 112 //printf("New area of triangle %d:\n", t); 113 mesh->triangles[t].area = computeTriangleArea(mesh->vertices, &mesh->triangles[t]); 114 115 computeTriangleNormal(mesh->vertices, &mesh->triangles[t]); 116 } 117 } 118 119 void VMI::unmodifyTriangles(Mesh *mesh, Change *c) { 120 int i, t; 121 122 for (i=0; i<c->numMod; i++) { 123 t = c->modified[i].id; 124 125 memcpy(&mesh->triangles[t], &c->modified[i], sizeof(Triangle)); 126 /*printf("t(%d %d %d)\n", mesh->triangles[t].indices[0], 127 mesh->triangles[t].indices[1], 128 mesh->triangles[t].indices[2]);*/ 129 } 130 } 131 132 void VMI::deleteTriangles(Mesh *mesh, Change *c) { 133 int i, t; 134 135 for (i=0; i<c->numDel; i++) { 136 t = c->deleted[i].id; 137 138 //printf("Deleting triangle %d\n",t); 139 mesh->triangles[t].enable = FALSE; 140 mesh->currentNumTriangles--; 141 } 142 } 143 144 void VMI::undeleteTriangles(Mesh *mesh, Change *c) { 145 int i, t; 146 147 for (i=0; i<c->numDel; i++) { 148 t = c->deleted[i].id; 149 150 memcpy(&mesh->triangles[t], &c->deleted[i], sizeof(Triangle)); 151 /*printf("t(%d %d %d)\n", mesh->triangles[t].indices[0], 152 mesh->triangles[t].indices[1], 153 mesh->triangles[t].indices[2]);*/ 154 155 mesh->triangles[t].enable = TRUE; 156 mesh->currentNumTriangles++; 157 } 158 } 159 160 int VMI::getTrianglesToModify(Mesh *mesh, int c, int p, Triangle *modified) { 161 GLuint i, num = 0; 162 163 for (i=0; i<mesh->numTriangles; i++) { 164 if ((mesh->triangles[i].enable == TRUE) && 165 isATriangleToModify(&mesh->triangles[i], c, p)) { 166 167 //printf("Triangle to modify %d\n", i); 168 // Save the original values of the triangle 169 memcpy(&modified[num], &mesh->triangles[i], sizeof(Triangle)); 170 num++; 171 } 172 } 173 174 return num; 175 } 176 177 int VMI::isATriangleToDelete(Triangle *t, int c, int p) { 178 int u = t->indices[0], 179 v = t->indices[1], 180 w = t->indices[2]; 181 182 if (((u == c) && ( v == p)) || 183 ((u == c) && ( w == p)) || 184 ((v == c) && ( w == p))) 185 return TRUE; 186 if (((u == p) && ( v == c)) || 187 ((u == p) && ( w == c)) || 188 ((v == p) && ( w == c))) 189 return TRUE; 190 191 return FALSE; 192 } 193 194 int VMI::getTrianglesToDelete(Mesh *mesh, int numMod, Triangle *modified, Triangle *deleted, int c, int p) { 195 int i, num = 0; 196 GLuint t; 197 198 for (i=0; i<numMod; i++) { 199 t = modified[i].id; 200 201 if (isATriangleToDelete(&mesh->triangles[t], c, p)) { 202 203 //printf("Triangle to delete %d\n",t); 204 memcpy(&deleted[num], &modified[i], sizeof(Triangle)); 205 num++; 206 } 207 } 208 return num; 209 } 210 211 void VMI::printList(Triangle *list, int n) { 212 int i; 213 214 for (i=0; i<n; i++) 215 printf("%d ",list[i].id); 216 217 printf("\n"); 218 } 219 220 void VMI::deleteItem(Triangle *list, int *n, int item) { 221 int i, j; 222 223 for (i=0; i<*n; i++) { 224 if (list[i].id == (GLuint)item) { 225 // delete it 226 for (j =i + 1 ; j<*n; j++) 227 list[j - 1] = list[j]; 228 (*n)--; 229 i--; // Delete all ocurrencies of an item 230 } 231 } 33 void VMI::deleteChange(Change *c) 34 { 35 36 if (NULL != c) 37 { 38 if (c->deleted != NULL) free(c->deleted); 39 if (c->modified != NULL) free(c->modified); 40 c->modified = NULL; 41 c->deleted = NULL; 42 c->numDel = 0; 43 c->numMod = 0; 44 45 free(c); 46 c = NULL; 47 } 48 } 49 50 void VMI::writeChange(FILE* file, Change *c) 51 { 52 int i; 53 54 fputc('v',file); 55 fputc('%',file); 56 fprintf(file, " %d %d 0 0 0 ", c->v, c->u); 57 58 for (i=0; i<c->numDel; i++) { 59 fprintf(file, "%d ", c->deleted[i].id); 60 } 61 62 fputc('&',file); 63 for (i=0; i<c->numMod; i++) { 64 fprintf(file, " %d", c->modified[i].id); 65 } 66 67 fputc('\n',file); 68 } 69 70 void VMI::printChange(Change *c) 71 { 72 int i; 73 74 if (NULL != c) { 75 76 printf("e%d(%d,%d)\n",c->e,c->u,c->v); 77 78 printf("d %d\n", c->numDel); 79 for (i=0;i<c->numDel;i++) { 80 printf(" %d", c->deleted[i].id); 81 } 82 printf("\n"); 83 printf("m %d\n", c->numMod); 84 for (i=0;i<c->numMod;i++) { 85 printf(" %d", c->modified[i].id); 86 } 87 printf("\n"); 88 } 89 } 90 91 void VMI::modifyTriangle(Triangle *t, int c, int p) 92 { 93 94 if ((int)t->indices[0] == c) 95 t->indices[0]= p; 96 if ((int)t->indices[1] == c) 97 t->indices[1]= p; 98 if ((int)t->indices[2] == c) 99 t->indices[2]= p; 100 } 101 102 int VMI::isATriangleToModify(Triangle *t, int c, int p) 103 { 104 int u = t->indices[0], 105 v = t->indices[1], 106 w = t->indices[2]; 107 108 if ((u == c) || (v == c) || (w == c)) return TRUE; 109 110 return FALSE; 111 } 112 113 void VMI::modifyTriangles(Mesh *mesh, Change *c) 114 { 115 int i, t; 116 117 for (i=0; i<c->numMod; i++) 118 { 119 t = c->modified[i].id; 120 modifyTriangle(&mesh->triangles[t], c->u, c->v); 121 122 //printf("New area of triangle %d:\n", t); 123 mesh->triangles[t].area = computeTriangleArea(mesh->vertices, &mesh->triangles[t]); 124 125 computeTriangleNormal(mesh->vertices, &mesh->triangles[t]); 126 } 127 } 128 129 void VMI::unmodifyTriangles(Mesh *mesh, Change *c) 130 { 131 int i, t; 132 133 for (i=0; i<c->numMod; i++) { 134 t = c->modified[i].id; 135 136 memcpy(&mesh->triangles[t], &c->modified[i], sizeof(Triangle)); 137 /*printf("t(%d %d %d)\n", mesh->triangles[t].indices[0], 138 mesh->triangles[t].indices[1], 139 mesh->triangles[t].indices[2]);*/ 140 } 141 } 142 143 void VMI::deleteTriangles(Mesh *mesh, Change *c) 144 { 145 int i, t; 146 147 for (i=0; i<c->numDel; i++) 148 { 149 t = c->deleted[i].id; 150 151 //printf("Deleting triangle %d\n",t); 152 mesh->triangles[t].enable = FALSE; 153 mesh->currentNumTriangles--; 154 } 155 } 156 157 void VMI::undeleteTriangles(Mesh *mesh, Change *c) 158 { 159 int i, t; 160 161 for (i=0; i<c->numDel; i++) 162 { 163 t = c->deleted[i].id; 164 165 memcpy(&mesh->triangles[t], &c->deleted[i], sizeof(Triangle)); 166 /*printf("t(%d %d %d)\n", mesh->triangles[t].indices[0], 167 mesh->triangles[t].indices[1], 168 mesh->triangles[t].indices[2]);*/ 169 170 mesh->triangles[t].enable = TRUE; 171 mesh->currentNumTriangles++; 172 } 173 } 174 175 int VMI::getTrianglesToModify(Mesh *mesh, int c, int p, Triangle *modified) 176 { 177 GLuint i, num = 0; 178 179 for (i=0; i<mesh->numTriangles; i++) 180 { 181 if ((mesh->triangles[i].enable == TRUE) && 182 isATriangleToModify(&mesh->triangles[i], c, p)) 183 { 184 185 //printf("Triangle to modify %d\n", i); 186 // Save the original values of the triangle 187 memcpy(&modified[num], &mesh->triangles[i], sizeof(Triangle)); 188 num++; 189 } 190 } 191 192 return num; 193 } 194 195 int VMI::isATriangleToDelete(Triangle *t, int c, int p) 196 { 197 int u = t->indices[0], 198 v = t->indices[1], 199 w = t->indices[2]; 200 201 if (((u == c) && ( v == p)) || 202 ((u == c) && ( w == p)) || 203 ((v == c) && ( w == p))) 204 return TRUE; 205 if (((u == p) && ( v == c)) || 206 ((u == p) && ( w == c)) || 207 ((v == p) && ( w == c))) 208 return TRUE; 209 210 return FALSE; 211 } 212 213 int VMI::getTrianglesToDelete(Mesh *mesh, int numMod, Triangle *modified, Triangle *deleted, int c, int p) 214 { 215 int i, num = 0; 216 GLuint t; 217 218 for (i=0; i<numMod; i++) 219 { 220 t = modified[i].id; 221 222 if (isATriangleToDelete(&mesh->triangles[t], c, p)) 223 { 224 //printf("Triangle to delete %d\n",t); 225 memcpy(&deleted[num], &modified[i], sizeof(Triangle)); 226 num++; 227 } 228 } 229 return num; 230 } 231 232 void VMI::printList(Triangle *list, int n) 233 { 234 int i; 235 236 for (i=0; i<n; i++) 237 printf("%d ",list[i].id); 238 239 printf("\n"); 240 } 241 242 void VMI::deleteItem(Triangle *list, int *n, int item) 243 { 244 int i, j; 245 246 for (i=0; i<*n; i++) 247 { 248 if (list[i].id == (GLuint)item) 249 { 250 // delete it 251 for (j =i + 1 ; j<*n; j++) 252 list[j - 1] = list[j]; 253 (*n)--; 254 i--; // Delete all ocurrencies of an item 255 } 256 } 232 257 } 233 258 … … 235 260 236 261 // Compute the triangle mesh changes due to a heap node simplification 237 void VMI::computeChanges(Mesh *mesh, Change *c) { 238 Triangle m[MAX_NUM_TRI], d[MAX_NUM_TRI/2]; 239 int numMod = getTrianglesToModify(mesh, c->u, c->v, m); 240 int numDel = getTrianglesToDelete(mesh, numMod, m, d, c->u, c->v); 241 int i; 242 243 //printf("d %d\n",numDel); 244 //printList(d, numDel); 245 246 for (i=0; i<numDel; i++) 247 deleteItem(m, &numMod, d[i].id); 248 249 //printf("m %d\n",numMod); 250 //printList(m, numMod); 251 //getchar(); 252 253 c->numDel = numDel; 254 // Free memory 255 if (c->deleted != NULL) free(c->deleted); 256 // Allocate memory 257 c->deleted = (Triangle *)malloc(sizeof(Triangle) * numDel); 258 if (c->deleted == NULL) { 259 fprintf(stderr, "Error allocating memory\n"); 260 exit(1); 261 } 262 memcpy(c->deleted, d, sizeof(Triangle) * numDel); 263 264 c->numMod = numMod; 265 // Free memory 266 if (c->modified != NULL) free(c->modified); 267 // Allocate memory 268 c->modified = (Triangle *)malloc(sizeof(Triangle) * numMod); 269 if (c->modified == NULL) { 270 fprintf(stderr, "Error allocating memory\n"); 271 exit(1); 272 } 273 memcpy(c->modified, m, sizeof(Triangle) * numMod); 274 275 //printChange(c); 276 //getchar(); 262 void VMI::computeChanges(Mesh *mesh, Change *c) 263 { 264 Triangle m[MAX_NUM_TRI], d[MAX_NUM_TRI/2]; 265 int numMod = getTrianglesToModify(mesh, c->u, c->v, m); 266 int numDel = getTrianglesToDelete(mesh, numMod, m, d, c->u, c->v); 267 int i; 268 269 //printf("d %d\n",numDel); 270 //printList(d, numDel); 271 272 for (i=0; i<numDel; i++) 273 deleteItem(m, &numMod, d[i].id); 274 275 //printf("m %d\n",numMod); 276 //printList(m, numMod); 277 //getchar(); 278 279 c->numDel = numDel; 280 // Free memory 281 if (c->deleted != NULL) free(c->deleted); 282 // Allocate memory 283 c->deleted = (Triangle *)malloc(sizeof(Triangle) * numDel); 284 285 if (c->deleted == NULL) 286 { 287 fprintf(stderr, "Error allocating memory\n"); 288 exit(1); 289 } 290 291 memcpy(c->deleted, d, sizeof(Triangle) * numDel); 292 293 c->numMod = numMod; 294 295 // Free memory 296 if (c->modified != NULL) free(c->modified); 297 298 // Allocate memory 299 c->modified = (Triangle *)malloc(sizeof(Triangle) * numMod); 300 301 if (c->modified == NULL) 302 { 303 fprintf(stderr, "Error allocating memory\n"); 304 exit(1); 305 } 306 307 memcpy(c->modified, m, sizeof(Triangle) * numMod); 308 309 //printChange(c); 310 //getchar(); 277 311 } 278 312 279 313 // Update the triangle mesh due to a heap node simplification 280 void VMI::doChange(Mesh *mesh, Change *c) { 281 282 modifyTriangles(mesh, c); 283 284 deleteTriangles(mesh, c); 285 286 mesh->vertices[c->u].enable = FALSE; 287 mesh->currentNumVertices--; 288 } 289 290 void VMI::undoChange(Mesh *mesh, Change *c) { 291 292 unmodifyTriangles(mesh, c); 293 294 undeleteTriangles(mesh, c); 295 296 mesh->vertices[c->u].enable = TRUE; 297 mesh->currentNumVertices++; 298 } 314 void VMI::doChange(Mesh *mesh, Change *c) 315 { 316 modifyTriangles(mesh, c); 317 318 deleteTriangles(mesh, c); 319 320 mesh->vertices[c->u].enable = FALSE; 321 mesh->currentNumVertices--; 322 } 323 324 void VMI::undoChange(Mesh *mesh, Change *c) 325 { 326 unmodifyTriangles(mesh, c); 327 328 undeleteTriangles(mesh, c); 329 330 mesh->vertices[c->u].enable = TRUE; 331 mesh->currentNumVertices++; 332 } 333 334 // Save simplification sequence in Geometry Game Tools format. 335 extern void VMI::saveSimplificationSequence(Change *c) 336 { 337 vmiStep step; 338 step.mV0 = c->u; 339 step.mV1 = c->v; 340 341 // If only one triangle has been deleted. 342 if (c->numDel == 1) 343 { 344 step.mT0 = c->deleted[0].id; 345 step.mT1 = c->deleted[0].id; 346 } 347 // If two triangles have been deleted. 348 else 349 { 350 step.mT0 = c->deleted[0].id; 351 step.mT1 = c->deleted[1].id; 352 } 353 354 step.x = 0.0; 355 step.y = 0.0; 356 step.z = 0.0; 357 358 // Write obligatory field. 359 step.obligatory = 0; 360 361 // List of new triangles. 362 // For each modified triangle. 363 for (int i = 0; i < c->numMod; i++) 364 { 365 step.mModfaces.push_back(c->modified[i].id); 366 } 367 368 // Add step to list of changes. 369 mVMISteps.push_back(step); 370 } -
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.