Changeset 2300 for GTP/trunk/Lib/Geom/shared/GTGeometry
- Timestamp:
- 03/30/07 11:38:28 (18 years ago)
- Location:
- GTP/trunk/Lib/Geom/shared/GTGeometry
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoMeshSimplifier.h
r2291 r2300 24 24 float x,y,z; 25 25 inline _coord_( float x = 0.0f, 26 float y = 0.0f, 27 float z = 0.0f) 28 { this->x = x; this->y = y; this->z = z; } 26 float y = 0.0f, 27 float z = 0.0f) 28 { 29 this->x = x; 30 this->y = y; 31 this->z = z; 32 } 29 33 30 34 inline _coord_(const _coord_ &f) 31 {32 x = f.x;33 y=f.y;34 z=f.z;35 }36 37 inline _coord_ & operator=(const _coord_ &f)38 35 { 39 36 x = f.x; 40 37 y = f.y; 41 38 z = f.z; 42 43 return *this; 39 } 40 41 inline _coord_ & operator=(const _coord_ &f) 42 { 43 x = f.x; 44 y = f.y; 45 z = f.z; 46 47 return *this; 44 48 } 45 49 … … 122 126 123 127 /// Starts the simplification process. Receives as a parameter the LOD factor in a range of [0,1]. This is a pure virtual method and must be overloaded in a derived class that implements a simplification algorithm. 124 virtual voidSimplify(Geometry::Real)=0;128 virtual int Simplify(Geometry::Real)=0; 125 129 126 130 /// Starts the simplification process. Receives as a parameter the number of vertices of the resulting mesh. This is a pure virtual method and must be overloaded in a derived class that implements a simplification algorithm. 127 virtual voidSimplify(Geometry::uint32)=0;131 virtual int Simplify(Geometry::uint32)=0; 128 132 129 133 /// Returns the simplified mesh. … … 150 154 // Sort mesh bones. 151 155 void sortBones(); 156 157 private: 158 159 void eraseVoidSubMeshes(Mesh *geoMesh); 152 160 }; 153 161 … … 190 198 void bonesReassignament(); 191 199 200 // Init VMI options. 201 int init(void); 202 192 203 public: 193 204 … … 206 217 207 218 /// Starts the simplification process. Receives as a parameter the LOD factor in a range of [0,1]. Implements the Simplifier::Simplify method to perform an image based simplification. 208 voidSimplify(Geometry::Real);219 int Simplify(Geometry::Real); 209 220 210 221 /// Starts the simplification process. Receives as a parameter the number of vertices of the resulting mesh. Implements the Simplifier::Simplify method to perform an image based simplification. 211 voidSimplify(Geometry::uint32);222 int Simplify(Geometry::uint32); 212 223 213 224 // Returns the simplified mesh. … … 234 245 235 246 /// Starts the simplification process. Receives as a parameter the LOD factor in a range of [0,1]. Implements the Simplifier::Simplify method to perform an image based simplification. 236 voidSimplify(Geometry::Real);247 int Simplify(Geometry::Real); 237 248 238 249 /// Starts the simplification process. Receives as a parameter the number of vertices of the resulting mesh. Implements the Simplifier::Simplify method to perform an image based simplification. 239 voidSimplify(Geometry::uint32);250 int Simplify(Geometry::uint32); 240 251 }; 241 252 } // end of Geometry namespace; -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimplifier.cpp
r2291 r2300 42 42 43 43 //------------------------------------------------------------------------- 44 // Erase submeshes that have not indices. 45 //------------------------------------------------------------------------- 46 void MeshSimplifier::eraseVoidSubMeshes(Mesh *geoMesh) 47 { 48 SubMesh *geosubmesh; 49 size_t valid_submesh_count; 50 size_t submesh; 51 52 valid_submesh_count = 0; 53 54 // For each submesh. 55 for (size_t i = 0; i < geoMesh->mSubMeshCount; i++) 56 { 57 // Debug. 58 cout << "Indices of submesh " 59 << i 60 << ": " 61 << geoMesh->mSubMesh[i].mIndexCount 62 << endl; 63 64 if ((geoMesh->mSubMesh[i].mIndexCount > 0) 65 || 66 (indexMeshLeaves == i)) 67 { 68 valid_submesh_count++; 69 } 70 } 71 72 // Reassign submesh count. 73 geoMesh->mSubMeshCount = valid_submesh_count; 74 75 // Reserve memory for valid submeshes. 76 geosubmesh = new SubMesh[valid_submesh_count]; 77 78 submesh = 0; 79 80 // For each submesh. 81 for (size_t i = 0; i < geoMesh->mSubMeshCount; i++) 82 { 83 // If leaves submesh is found. 84 if (indexMeshLeaves == i) 85 { 86 geosubmesh[i].mStripCount = 0; 87 geosubmesh[i].mStrip = NULL; 88 89 geosubmesh[i].mSharedVertexBuffer = false; 90 91 strcpy( geosubmesh[i].mMaterialName, 92 mInitialMesh->mSubMesh[i].mMaterialName); 93 94 // Copy submesh bones. 95 if (!mInitialMesh->mSubMesh[i].mBones.empty()) 96 { 97 for ( size_t j = 0; 98 j < mInitialMesh->mSubMesh[i].mBones.size(); 99 j++) 100 { 101 geosubmesh[i].mBones.push_back(mInitialMesh-> 102 mSubMesh[i].mBones[j]); 103 } 104 } 105 106 // Leaves mesh. 107 geosubmesh[i].mIndexCount = 108 mInitialMesh->mSubMesh[i].mIndexCount; 109 110 geosubmesh[i].mIndex = 111 new Geometry::Index[geosubmesh[i].mIndexCount]; 112 113 memcpy( geosubmesh[i].mIndex, 114 mInitialMesh->mSubMesh[i].mIndex, 115 mInitialMesh->mSubMesh[i].mIndexCount * sizeof(Index)); 116 117 // Copy the leaves submesh vertices. 118 geosubmesh[i].mVertexBuffer = 119 mInitialMesh->mSubMesh[i].mVertexBuffer->Clone(); 120 121 // Next valid submesh. 122 submesh++; 123 } 124 else if (geoMesh->mSubMesh[i].mIndexCount > 0) 125 { 126 geosubmesh[submesh].mSharedVertexBuffer = 127 geoMesh->mSubMesh[i].mSharedVertexBuffer; 128 129 geosubmesh[submesh].mVertexBuffer = geoMesh->mVertexBuffer; 130 131 geosubmesh[submesh].mType = geoMesh->mSubMesh[i].mType; 132 133 geosubmesh[submesh].mStripCount = geoMesh->mSubMesh[i].mStripCount; 134 135 geosubmesh[submesh].mIndexCount = geoMesh->mSubMesh[i].mIndexCount; 136 137 // Reserve memory for indices. 138 geosubmesh[submesh].mIndex = 139 new Index[geosubmesh[submesh].mIndexCount]; 140 141 // Copy indices. 142 memcpy( geosubmesh[submesh].mIndex, 143 geoMesh->mSubMesh[i].mIndex, 144 geoMesh->mSubMesh[i].mIndexCount * sizeof(Index)); 145 146 // Reserve memory for array of strips. 147 geosubmesh[submesh].mStrip = 148 new Index*[geoMesh->mSubMesh[submesh].mStripCount]; 149 150 // Copy strip list of the submesh. 151 for (size_t j = 0; j < geoMesh->mSubMesh[i].mStripCount; j++) 152 { 153 geosubmesh[submesh].mStrip[j] = geoMesh->mSubMesh[i].mStrip[j]; 154 } 155 156 strcpy( geosubmesh[submesh].mMaterialName, 157 geoMesh->mSubMesh[i].mMaterialName); 158 159 for (size_t j = 0; j < geoMesh->mSubMesh[i].mBones.size(); j++) 160 { 161 geosubmesh[submesh].mBones 162 .push_back(geoMesh->mSubMesh[i].mBones[j]); 163 } 164 165 // Next valid submesh. 166 submesh++; 167 } 168 } 169 170 // Delete submeshes. 171 delete []geoMesh->mSubMesh; 172 173 geoMesh->mSubMesh = geosubmesh; 174 } 175 176 //------------------------------------------------------------------------- 44 177 // Returns the simplified mesh. 45 178 //------------------------------------------------------------------------- 46 179 Mesh * MeshSimplifier::GetMesh() 47 180 { 181 // Delete void submeshes. 182 eraseVoidSubMeshes(mGeoMesh); 183 48 184 return mGeoMesh; 49 185 } … … 146 282 // method to perform an image based simplification. 147 283 //------------------------------------------------------------------------- 148 voidGeometryBasedSimplifier::Simplify(Real paramlod)284 int GeometryBasedSimplifier::Simplify(Real paramlod) 149 285 { 150 286 SimplificationMethod *m_qslim = new SimplificationMethod(mInitialMesh); … … 157 293 158 294 delete m_qslim; 295 296 return NO_GL_ERROR; 159 297 } 160 298 … … 165 303 // perform an image based simplification. 166 304 //------------------------------------------------------------------------- 167 voidGeometryBasedSimplifier::Simplify(uint32 numvertices)305 int GeometryBasedSimplifier::Simplify(uint32 numvertices) 168 306 { 169 307 SimplificationMethod *m_qslim = new SimplificationMethod(mInitialMesh); … … 176 314 177 315 delete m_qslim; 316 317 return NO_GL_ERROR; 178 318 } 179 319 … … 235 375 // Loads the vmi mesh structure for a geometry mesh given. 236 376 VMI::mesh = initMeshStructure(mGeoMesh); 377 } 378 379 // Init VMI options. 380 int ViewPointDrivenSimplifier::init(void) 381 { 382 int error; 237 383 238 384 // RGB and Alpha. … … 245 391 glewInit(); 246 392 247 VMI::init();393 error = VMI::init(); 248 394 249 395 if (VMI::bLoadCamerasFromFile == GL_FALSE) … … 256 402 257 403 VMI::initialIs = VMI::initIs(VMI::numCameras); 404 405 return error; 258 406 } 259 407 … … 273 421 /// LOD factor in a range of [0,1]. Implements the 274 422 /// Simplifier::Simplify method to perform an image based simplification. 275 void ViewPointDrivenSimplifier::Simplify(Real percent) 276 { 423 int ViewPointDrivenSimplifier::Simplify(Real percent) 424 { 425 int error; 426 427 error = init(); 428 277 429 VMI::numDemandedTriangles = (int)(VMI::mesh->numTriangles * percent); 278 430 … … 284 436 } 285 437 286 VMI::display(); 287 288 // Cleans firts simplification. 289 VMI::freeMemory(); 290 291 VMI::mesh = initMeshStructure(mInitialMesh); 292 293 VMI::contractInitialMesh(VMI::mesh); 294 295 // Load a geometry mesh for vmi mesh. 296 loadMesh(); 297 298 GetMeshSimpSequence(); 299 300 // Sort bones. 301 bonesReassignament(); 438 if (error == NO_GL_ERROR) 439 { 440 VMI::display(); 441 442 // Cleans firts simplification. 443 VMI::freeMemory(); 444 445 VMI::mesh = initMeshStructure(mInitialMesh); 446 447 VMI::contractInitialMesh(VMI::mesh); 448 449 // Load a geometry mesh for vmi mesh. 450 loadMesh(); 451 452 GetMeshSimpSequence(); 453 454 // Sort bones. 455 bonesReassignament(); 456 } 457 458 return error; 302 459 } 303 460 … … 308 465 /// an image based simplification. 309 466 //------------------------------------------------------------------------- 310 voidViewPointDrivenSimplifier::Simplify(uint32 numVertices)467 int ViewPointDrivenSimplifier::Simplify(uint32 numVertices) 311 468 { 312 469 float percent; 470 int error; 471 472 error = init(); 313 473 314 474 percent = (numVertices * 100.0) / VMI::mesh->numVertices; 315 475 316 VMI::numDemandedTriangles = (int)(VMI::mesh->numTriangles * (percent / 100)); 476 VMI::numDemandedTriangles = (int)(VMI::mesh->numTriangles 477 * 478 (percent / 100)); 317 479 318 480 if ((VMI::numDemandedTriangles == 0) … … 323 485 } 324 486 325 VMI::display(); 326 327 // Cleans firts simplification. 328 VMI::freeMemory(); 329 330 VMI::mesh = initMeshStructure(mInitialMesh); 331 332 VMI::contractInitialMesh(VMI::mesh); 333 334 // Load a geometry mesh for vmi mesh. 335 loadMesh(); 336 337 GetMeshSimpSequence(); 338 339 // Sort bones. 340 bonesReassignament(); 487 if (error == NO_GL_ERROR) 488 { 489 VMI::display(); 490 491 // Cleans firts simplification. 492 VMI::freeMemory(); 493 494 VMI::mesh = initMeshStructure(mInitialMesh); 495 496 VMI::contractInitialMesh(VMI::mesh); 497 498 // Load a geometry mesh for vmi mesh. 499 loadMesh(); 500 501 GetMeshSimpSequence(); 502 503 // Sort bones. 504 bonesReassignament(); 505 } 506 507 return error; 341 508 } 342 509 -
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.