Changeset 2300 for GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs
- Timestamp:
- 03/30/07 11:38:28 (18 years ago)
- Location:
- GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/SimplificationMethod.cpp
r2291 r2300 1465 1465 1466 1466 //------------------------------------------------------------------------- 1467 // Erase submeshes that have not indices.1468 //-------------------------------------------------------------------------1469 void SimplificationMethod::eraseVoidSubMeshes(Mesh *geoMesh)1470 {1471 SubMesh *geosubmesh;1472 size_t valid_submesh_count;1473 size_t submesh;1474 1475 valid_submesh_count = 0;1476 1477 // For each submesh.1478 for (size_t i = 0; i < geoMesh->mSubMeshCount; i++)1479 {1480 // Debug.1481 cout << "Indices of submesh "1482 << i1483 << ": "1484 << geoMesh->mSubMesh[i].mIndexCount1485 << endl;1486 1487 if ((geoMesh->mSubMesh[i].mIndexCount > 0)1488 ||1489 (indexMeshLeaves == i))1490 {1491 valid_submesh_count++;1492 }1493 }1494 1495 // Reassign submesh count.1496 geoMesh->mSubMeshCount = valid_submesh_count;1497 1498 // Reserve memory for valid submeshes.1499 geosubmesh = new SubMesh[valid_submesh_count];1500 1501 submesh = 0;1502 1503 // For each submesh.1504 for (size_t i = 0; i < geoMesh->mSubMeshCount; i++)1505 {1506 // If leaves submesh is found.1507 if (indexMeshLeaves == i)1508 {1509 geosubmesh[i].mStripCount = 0;1510 geosubmesh[i].mStrip = NULL;1511 1512 geosubmesh[i].mSharedVertexBuffer = false;1513 1514 strcpy( geosubmesh[i].mMaterialName,1515 mInitialMesh->mSubMesh[i].mMaterialName);1516 1517 // Copy submesh bones.1518 if (!mInitialMesh->mSubMesh[i].mBones.empty())1519 {1520 for ( size_t j = 0;1521 j < mInitialMesh->mSubMesh[i].mBones.size();1522 j++)1523 {1524 geosubmesh[i].mBones.push_back(mInitialMesh->1525 mSubMesh[i].mBones[j]);1526 }1527 }1528 1529 // Leaves mesh.1530 geosubmesh[i].mIndexCount =1531 mInitialMesh->mSubMesh[i].mIndexCount;1532 1533 geosubmesh[i].mIndex =1534 new Geometry::Index[geosubmesh[i].mIndexCount];1535 1536 memcpy( geosubmesh[i].mIndex,1537 mInitialMesh->mSubMesh[i].mIndex,1538 mInitialMesh->mSubMesh[i].mIndexCount * sizeof(Index));1539 1540 // Copy the leaves submesh vertices.1541 geosubmesh[i].mVertexBuffer =1542 mInitialMesh->mSubMesh[i].mVertexBuffer->Clone();1543 1544 // Next valid submesh.1545 submesh++;1546 }1547 else if (geoMesh->mSubMesh[i].mIndexCount > 0)1548 {1549 geosubmesh[submesh].mSharedVertexBuffer =1550 geoMesh->mSubMesh[i].mSharedVertexBuffer;1551 1552 geosubmesh[submesh].mVertexBuffer = geoMesh->mVertexBuffer;1553 1554 geosubmesh[submesh].mType = geoMesh->mSubMesh[i].mType;1555 1556 geosubmesh[submesh].mStripCount = geoMesh->mSubMesh[i].mStripCount;1557 1558 geosubmesh[submesh].mIndexCount = geoMesh->mSubMesh[i].mIndexCount;1559 1560 // Reserve memory for indices.1561 geosubmesh[submesh].mIndex =1562 new Index[geosubmesh[submesh].mIndexCount];1563 1564 // Copy indices.1565 memcpy( geosubmesh[submesh].mIndex,1566 geoMesh->mSubMesh[i].mIndex,1567 geoMesh->mSubMesh[i].mIndexCount * sizeof(Index));1568 1569 // Reserve memory for array of strips.1570 geosubmesh[submesh].mStrip =1571 new Index*[geoMesh->mSubMesh[submesh].mStripCount];1572 1573 // Copy strip list of the submesh.1574 for (size_t j = 0; j < geoMesh->mSubMesh[i].mStripCount; j++)1575 {1576 geosubmesh[submesh].mStrip[j] = geoMesh->mSubMesh[i].mStrip[j];1577 }1578 1579 strcpy( geosubmesh[submesh].mMaterialName,1580 geoMesh->mSubMesh[i].mMaterialName);1581 1582 for (size_t j = 0; j < geoMesh->mSubMesh[i].mBones.size(); j++)1583 {1584 geosubmesh[submesh].mBones1585 .push_back(geoMesh->mSubMesh[i].mBones[j]);1586 }1587 1588 // Next valid submesh.1589 submesh++;1590 }1591 }1592 1593 // Delete submeshes.1594 delete []geoMesh->mSubMesh;1595 1596 geoMesh->mSubMesh = geosubmesh;1597 }1598 1599 //-------------------------------------------------------------------------1600 1467 // Fill up vertices. 1601 1468 //------------------------------------------------------------------------- … … 1878 1745 Mesh * SimplificationMethod::GetMesh() 1879 1746 { 1880 // Delete void submeshes.1881 eraseVoidSubMeshes(mGeoMesh);1882 1883 1747 return mGeoMesh; 1884 1748 } -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/SimplificationMethod.h
r2291 r2300 191 191 void addNewBoneAssignments(); 192 192 193 void eraseVoidSubMeshes(Mesh *geoMesh);194 195 193 public: 196 194 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/global.h
r2194 r2300 142 142 extern char filename[MAX_CHAR]; 143 143 144 extern voidinit(void);144 extern int init(void); 145 145 146 146 extern void resetProjectedAreas(int **histogram, int numCameras); -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/vmi_simplifier.h
r2127 r2300 2 2 #include <stdlib.h> 3 3 #include <time.h> 4 5 4 #include "GL/glew.h" 6 5 #ifdef _WIN32 … … 15 14 #include "buffers.h" 16 15 16 #define NO_GL_ERROR 0x00 17 #define FRAMEBUFFER_ERROR 0x01 18 #define VERTEX_BUFFER_ERROR 0x02 19 #define OCCLUSION_QUERY_ERROR 0x04 20 #define IMAGING_ERROR 0x08 21 #define MULTITEXTURE_ERROR 0x10 22 #define SWAP_CONTROL_ERROR 0x20 23 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/main.cpp
r2194 r2300 3 3 namespace VMI 4 4 { 5 GLMmodel *pmodel = NULL; // The .obj model6 7 GLubyte *pixels = NULL;8 9 Camera *cameras = NULL;10 int numCameras = 0;11 12 Color *colors = NULL;13 14 int **histogram = NULL;15 GLuint *queries = NULL;16 17 Mesh *mesh = NULL;18 19 GLdouble *initialIs = NULL;20 21 GLsizei width = 256,22 23 24 GLboolean bEnableOffScreen = GL_TRUE,25 26 27 28 29 30 int cameraType = 0,31 32 33 GLdouble radius = 1.3, fov = 60.0;34 35 char filename[MAX_CHAR] = {'\0'};36 37 GLuint fb, depth_rb, color_tex;5 GLMmodel *pmodel = NULL; // The .obj model 6 7 GLubyte *pixels = NULL; 8 9 Camera *cameras = NULL; 10 int numCameras = 0; 11 12 Color *colors = NULL; 13 14 int **histogram = NULL; 15 GLuint *queries = NULL; 16 17 Mesh *mesh = NULL; 18 19 GLdouble *initialIs = NULL; 20 21 GLsizei width = 256, 22 height = 256; 23 24 GLboolean bEnableOffScreen = GL_TRUE, 25 bBeQuiet = GL_FALSE, 26 bSaveLog = GL_FALSE, 27 bLoadCamerasFromFile = GL_FALSE, 28 bRemoveRedundantVertices = GL_TRUE; 29 30 int cameraType = 0, 31 numDemandedTriangles = 0; 32 33 GLdouble radius = 1.3, fov = 60.0; 34 35 char filename[MAX_CHAR] = {'\0'}; 36 37 GLuint fb, depth_rb, color_tex; 38 38 39 39 #ifdef VERTEX_ARRAY_INTERLEAVE 40 VertexIL *interleave = NULL;41 #endif 42 43 GLuint vertex_buf = 0,44 45 46 Vertex_ *buf_vertices = NULL;47 Color *buf_colors = NULL;48 49 int vmiWin = 0;50 51 // For progress update.52 Geometry::TIPOFUNC mUPB;40 VertexIL *interleave = NULL; 41 #endif 42 43 GLuint vertex_buf = 0, 44 color_buf = 0; 45 46 Vertex_ *buf_vertices = NULL; 47 Color *buf_colors = NULL; 48 49 int vmiWin = 0; 50 51 // For progress update. 52 Geometry::TIPOFUNC mUPB; 53 53 54 54 } … … 56 56 using namespace VMI; 57 57 58 void VMI::init(void) 59 { 58 int VMI::init(void) 59 { 60 // Initialize error status. 61 int error = NO_GL_ERROR; 62 60 63 // Clear color 61 64 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); … … 81 84 fprintf(stderr, 82 85 "GL_EXT_framebuffer_object extension is not available!\n"); 83 exit(1); 86 87 error = error | FRAMEBUFFER_ERROR; 84 88 } 85 89 else … … 131 135 fprintf(stderr, 132 136 "GL_ARB_vertex_buffer_object extension is not available!\n"); 137 138 error = error | VERTEX_BUFFER_ERROR; 133 139 } 134 140 else … … 144 150 { 145 151 fprintf(stderr, 146 "GL_ARB_occlusion_query extension is not available!\n"); 152 "GL_ARB_occlusion_query extension is not available!\n"); 153 154 error = error | OCCLUSION_QUERY_ERROR; 147 155 } 148 156 else … … 158 166 { 159 167 fprintf(stderr,"GL_ARB_imaging extension is not available!\n"); 168 169 error = error | IMAGING_ERROR; 160 170 } 161 171 … … 163 173 { 164 174 fprintf(stderr,"GL_ARB_multitexture extension is not available!\n"); 175 176 error = error | MULTITEXTURE_ERROR; 165 177 } 166 178 … … 169 181 { 170 182 fprintf(stderr,"WGL_EXT_swap_control extension is not available!\n"); 183 184 error = error | SWAP_CONTROL_ERROR; 171 185 } 172 186 #endif … … 180 194 // Set a different color for every triangle. 181 195 setColors4(colors, mesh->currentNumTriangles); 196 197 return error; 182 198 } 183 199 184 200 void VMI::applyHWAcceleration(void) { 185 201 186 202 #ifdef VERTEX_ARRAY_INTERLEAVE 187 203 setupInterleave(mesh, colors); 188 204 #endif 189 205 #ifdef VERTEX_ARRAY 190 206 setupVertexArray(mesh, colors); 191 207 #endif 192 208 #ifdef VERTEX_BUFFER_OBJECTS 193 209 setupVertexBufferObjects(mesh, colors); 194 210 #endif 195 211 … … 197 213 198 214 void VMI::updateHWAcceleration(Change *c) { 199 215 200 216 #ifdef VERTEX_ARRAY_INTERLEAVE 201 202 217 if (interleave != NULL) free(interleave); 218 interleave = setupInterleave(mesh, colors); 203 219 #endif 204 220 #ifdef VERTEX_ARRAY 205 221 updateVertexArray(mesh, c); 206 222 #endif 207 223 #ifdef VERTEX_BUFFER_OBJECTS 208 224 updateVertexBufferObjects(mesh, c); 209 225 #endif 210 226 … … 212 228 213 229 void VMI::setOrthographicProjection(void) { 214 215 216 217 218 219 220 221 222 223 230 // Switch to projection mode 231 glMatrixMode(GL_PROJECTION); 232 // Save previous matrix which contains the 233 // settings for the perspective projection 234 glPushMatrix(); 235 // Reset matrix 236 glLoadIdentity(); 237 glOrtho(0.0, (GLdouble)HISTOGRAM_SIZE, 0.0, (GLdouble)height, -1.0, 1.0); 238 glMatrixMode(GL_MODELVIEW); 239 glLoadIdentity(); 224 240 } 225 241 226 242 void VMI::resetPerspectiveProjection(void) { 227 228 229 230 231 232 233 243 // Set the current matrix to GL_PROJECTION 244 glMatrixMode(GL_PROJECTION); 245 // Restore previous settings 246 glPopMatrix(); 247 // Get back to GL_MODELVIEW matrix 248 glMatrixMode(GL_MODELVIEW); 249 glLoadIdentity(); 234 250 } 235 251 236 252 void VMI::renderBitmapString(float x, float y, void *font, char *string) { 237 238 239 240 241 242 253 char *c; 254 // Set position to start drawing fonts 255 glRasterPos2f(x, y); 256 // Loop all the characters in the string 257 for (c=string; *c != '\0'; c++) 258 glutBitmapCharacter(font, *c); 243 259 } 244 260 245 261 void VMI::renderGeometry(void) { 246 262 #ifdef IMMEDIATE_MODE 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 263 int i, v1, v2, v3; 264 265 // Immediate mode 266 glBegin (GL_TRIANGLES); 267 for (i=0; i<mesh->numTriangles; i++) { 268 if (mesh->triangles[i].enable == TRUE) { 269 270 v1= mesh->triangles[i].indices[0]; 271 v2= mesh->triangles[i].indices[1]; 272 v3= mesh->triangles[i].indices[2]; 273 274 glColor4ub(colors[i].r, colors[i].g, colors[i].b, colors[i].a); 275 glVertex3f(mesh->vertices[v1].x, mesh->vertices[v1].y, mesh->vertices[v1].z); 276 glVertex3f(mesh->vertices[v2].x, mesh->vertices[v2].y, mesh->vertices[v2].z); 277 glVertex3f(mesh->vertices[v3].x, mesh->vertices[v3].y, mesh->vertices[v3].z); 278 } 279 } 280 glEnd(); 265 281 #else 266 282 #ifdef VERTEX_ARRAY 267 283 glDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); 268 284 #endif 269 285 #ifdef VERTEX_ARRAY_INTERLEAVE 270 271 286 glInterleavedArrays (GL_T2F_C4UB_V3F, 0, interleave); 287 glDrawArrays(GL_TRIANGLES, 0, mesh->currentNumTriangles * 3); 272 288 #endif 273 289 #ifdef VERTEX_BUFFER_OBJECTS 274 glDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); 275 #endif 276 277 #endif 278 } 290 glDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); 291 #endif 292 293 #endif 294 } 295 279 296 void VMI::drawTexture(void) { 280 297 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 298 // Clear color and depth buffers 299 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 300 301 setOrthographicProjection(); 302 303 glEnable(GL_TEXTURE_2D); 304 glBindTexture(GL_TEXTURE_2D, color_tex); 305 glBegin(GL_QUADS); 306 307 glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); 308 glTexCoord2f(1.0f, 0.0f); glVertex2f(width, 0.0f); 309 glTexCoord2f(1.0f, 1.0f); glVertex2f(width, height); 310 glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, height); 311 312 glEnd(); 313 glFlush(); 314 glDisable(GL_TEXTURE_2D); 315 316 resetPerspectiveProjection(); 317 318 glutSwapBuffers(); 302 319 } 303 320 304 321 void VMI::resetProjectedAreas(int **histogram, int numCameras) { 305 306 307 308 309 322 int i = 0; 323 324 // Reset the projected areas for all cameras 325 for (i=0; i<numCameras; i++) 326 resetSWHistogram(histogram[i], mesh->numTriangles); 310 327 } 311 328 312 329 void VMI::getProjectedAreas(int **histogram, int numCameras) 313 330 { 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 ///////////////////////////////////////////////////////////////////////////340 341 342 331 int i; 332 333 // draw to the frame buffer 334 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); 335 336 //glDrawBuffer(GL_BACK); 337 //glReadBuffer(GL_BACK); 338 339 // Get the projected areas for all cameras 340 for (i=0; i<numCameras; i++) { 341 342 // Clear color and depth buffers 343 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 344 345 glMatrixMode(GL_MODELVIEW); 346 glLoadIdentity(); 347 348 // Camera i 349 gluLookAt(cameras[i].eyeX, cameras[i].eyeY, cameras[i].eyeZ, 350 cameras[i].centerX, cameras[i].centerY, cameras[i].centerZ, 351 cameras[i].upX, cameras[i].upY, cameras[i].upZ); 352 353 renderGeometry(); 354 glFlush(); 355 356 /////////////////////////////////////////////////////////////////////// 357 358 resetSWHistogram(histogram[i], mesh->numTriangles); 359 343 360 #ifdef USE_OCCLUSION_QUERY 344 361 getSWHistoByOcclusionQuery(mesh, colors, histogram[i]); 345 362 #else // HYBRID_HW_SW_HISTOGRAM 346 347 #endif 348 349 350 351 352 353 354 355 ///////////////////////////////////////////////////////////////////////////363 getSWHistogram(histogram[i], pixels); 364 #endif 365 } 366 367 // draw to the window, reading from the color texture 368 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 369 370 if (!bEnableOffScreen) drawTexture(); 371 372 ///////////////////////////////////////////////////////////////////////// 356 373 } 357 374 void VMI::getProjectedAreasWin(int **histogram, int numCameras, Change *c) 358 375 { 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 ///////////////////////////////////////////////////////////////////////////394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 ///////////////////////////////////////////////////////////////////////////376 int i, j, t, background; 377 int del_area, mod_area; 378 GLfloat min[3], max[3]; 379 380 // draw to the frame buffer 381 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); 382 383 //printChange(c); 384 getBoundingBox(c, min, max); 385 //printf("\n(%f,%f,%f)-(%f,%f,%f)\n", min[0], min[1], min[2], max[0], max[1], max[2]); 386 387 // Update HW acceleration OpenGL Technique 388 updateHWAcceleration(c); 389 390 //glDrawBuffer(GL_BACK); 391 //glReadBuffer(GL_BACK); 392 393 // Get the projected areas for all cameras 394 for (i=0; i<numCameras; i++) { 395 396 // Clear color and depth buffers 397 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 398 399 glMatrixMode(GL_MODELVIEW); 400 glLoadIdentity(); 401 402 // Camera i 403 gluLookAt(cameras[i].eyeX, cameras[i].eyeY, cameras[i].eyeZ, 404 cameras[i].centerX, cameras[i].centerY, cameras[i].centerZ, 405 cameras[i].upX, cameras[i].upY, cameras[i].upZ); 406 407 renderGeometry(); 408 glFlush(); 409 410 //////////////////////////////////////////////////////////////////////// 411 background = histogram[i][0]; 412 //printf("b: %d\n", histogram[i][0]); 413 414 del_area = 0; 415 mod_area = 0; 416 417 for (j=0; j<c->numDel; j++) { 418 t = c->deleted[j].id; 419 del_area += histogram[i][t + 1]; 420 421 histogram[i][t + 1] = 0; 422 } 423 424 for (j=0; j<c->numMod; j++) { 425 t = c->modified[j].id; 426 del_area += histogram[i][t + 1]; 427 428 histogram[i][t + 1] = 0; 429 } 430 431 getSWHistogramWin(histogram[i], pixels, min, max, c); 432 433 for (j=0; j<c->numMod; j++) { 434 t = c->modified[j].id; 435 mod_area += histogram[i][t + 1]; 436 437 //printf("t%d: %d\n",t, histogram[i][t + 1]); 438 } 439 histogram[i][0] = background + (del_area - mod_area); 440 //printf("b: %d\n", histogram[i][0]); 441 } 442 //getchar(); 443 444 // draw to the window, reading from the color texture 445 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 446 447 if (!bEnableOffScreen) drawTexture(); 448 449 //////////////////////////////////////////////////////////////////////// 433 450 } 434 451 435 452 void VMI::freeMemory(void) { 436 453 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 454 // Free memory 455 deleteMesh(mesh); 456 457 //glmDelete(pmodel); 458 459 free(pixels); 460 461 free(cameras); 462 463 free(colors); 464 465 deleteHistogram(histogram, numCameras); 466 467 free(initialIs); 468 469 glDeleteRenderbuffersEXT(1, &depth_rb); 470 471 glDeleteRenderbuffersEXT(1, &color_tex); 472 473 glDeleteFramebuffersEXT(1, &fb); 457 474 #ifdef USE_OCCLUSION_QUERY 458 459 #endif 460 461 462 463 464 475 glDeleteQueriesARB(mesh->currentNumTriangles, queries); 476 #endif 477 478 if (vmiWin != 0) 479 { 480 glutDestroyWindow(vmiWin); 481 } 465 482 466 483 #ifdef VERTEX_BUFFER_OBJECTS 467 468 469 470 471 484 glDeleteBuffersARB(1, &vertex_buf); 485 glDeleteBuffersARB(1, &color_buf); 486 487 buf_vertices = NULL; 488 buf_colors = NULL; 472 489 473 490 #endif 474 491 #ifdef VERTEX_ARRAY 475 476 477 478 479 492 free(buf_vertices); 493 free(buf_colors); 494 495 buf_vertices = NULL; 496 buf_colors = NULL; 480 497 #endif 481 498 #ifdef VERTEX_ARRAY_INTERLEAVE 482 483 499 free(interleave); 500 interleave = NULL; 484 501 #endif 485 502 … … 494 511 495 512 histogram = NULL; 496 513 queries = NULL; 497 514 498 515 mesh = NULL; … … 516 533 517 534 // Apply HW acceleration OpenGL Technique 518 535 applyHWAcceleration(); 519 536 520 537 getProjectedAreas(histogram, numCameras); … … 555 572 556 573 #ifdef SALIENCY 557 574 sprintf(s,"%s_%d_%d_%s_S.obj", filename, numCameras, mesh->currentNumTriangles, EXT); 558 575 #else 559 576 sprintf(s,"%s_%d_%d_%s.obj", filename, numCameras, mesh->currentNumTriangles, EXT); 560 577 #endif 561 578
Note: See TracChangeset
for help on using the changeset viewer.