Changeset 2194 for GTP/trunk/Lib/Geom
- Timestamp:
- 03/06/07 14:26:14 (18 years ago)
- Location:
- GTP/trunk/Lib/Geom/shared
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoMeshSimpSequence.h
r2090 r2194 60 60 Index mV0; 61 61 Index mV1; 62 IndexmT0;63 IndexmT1;62 int mT0; 63 int mT1; 64 64 float x; 65 65 float y; -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoMeshSimplifier.h
r2127 r2194 110 110 /// Class constructor. Retrieves a pointer to a valid Geometry::Mesh object to simplify. 111 111 MeshSimplifier( const Geometry::Mesh *, 112 Geometry::TIPOFUNC upb=0);112 Geometry::TIPOFUNC upb=0); 113 113 114 114 /// Virtual class destructor. -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimplifier.cpp
r2127 r2194 224 224 VMI::vTexCoords = vTexCoords; 225 225 226 227 228 226 mGeoMesh = new Mesh(); 229 227 … … 252 250 253 251 if (VMI::bLoadCamerasFromFile == GL_FALSE) 254 VMI::cameras = VMI::setCameras(VMI::radius, VMI::cameraType, &VMI::numCameras); 252 VMI::cameras = VMI::setCameras( VMI::radius, 253 VMI::cameraType, 254 &VMI::numCameras); 255 255 256 256 VMI::histogram = VMI::initHistogram( VMI::mesh->currentNumTriangles, 257 VMI::numCameras);257 VMI::numCameras); 258 258 259 259 VMI::initialIs = VMI::initIs(VMI::numCameras); … … 272 272 } 273 273 274 /// Starts the simplification process. Receives as a parameter the 275 /// LOD factor in a range of [0,1]. Implements the 274 /// Starts the simplification process. Receives as a parameter the 275 /// LOD factor in a range of [0,1]. Implements the 276 276 /// Simplifier::Simplify method to perform an image based simplification. 277 277 void ViewPointDrivenSimplifier::Simplify(Real percent) … … 333 333 334 334 VMI::contractInitialMesh(VMI::mesh); 335 335 336 336 // Load a geometry mesh for vmi mesh. 337 337 loadMesh(); … … 431 431 vmi_mesh->vertices[i].z = vertex_buffer->mPosition[i].z; 432 432 433 vmi_mesh->vertices[i].numTriangles = 0; 434 vmi_mesh->vertices[i].triangles = NULL; 435 vmi_mesh->vertices[i].numEdges = 0; 436 vmi_mesh->vertices[i].edges = NULL; 437 vmi_mesh->vertices[i].enable = GL_TRUE; 438 vmi_mesh->vertices[i].movable = GL_TRUE; 433 vmi_mesh->vertices[i].numTriangles = 0; 434 vmi_mesh->vertices[i].triangles = NULL; 435 vmi_mesh->vertices[i].numEdges = 0; 436 vmi_mesh->vertices[i].edges = NULL; 437 vmi_mesh->vertices[i].enable = GL_TRUE; 439 438 } 440 439 … … 468 467 vmi_mesh->triangles[index].indices[2] = geosubmesh->mIndex[(3 * i) + 2]; 469 468 470 vmi_mesh->triangles[index].area = computeTriangleArea(vmi_mesh->vertices, 471 &vmi_mesh->triangles[index]); 472 computeTriangleNormal(vmi_mesh->vertices, &vmi_mesh->triangles[index]); 469 vmi_mesh->triangles[index].area = computeTriangleArea( 470 vmi_mesh->vertices, 471 &vmi_mesh->triangles[index]); 472 473 computeTriangleNormal(vmi_mesh->vertices, 474 &vmi_mesh->triangles[index]); 473 475 474 476 vmi_mesh->triangles[index].saliency = 0.0; … … 482 484 483 485 // Reallocate memory for the new adjacent triangle. 484 vmi_mesh->vertices[v1].triangles = (int *)realloc(vmi_mesh->vertices[v1].triangles, (vmi_mesh->vertices[v1].numTriangles + 1) * sizeof(int)); 486 vmi_mesh->vertices[v1].triangles = 487 (int *)realloc(vmi_mesh->vertices[v1].triangles, 488 (vmi_mesh->vertices[v1].numTriangles + 1) 489 * 490 sizeof(int)); 485 491 486 492 VMI::addItem( (int *)vmi_mesh->vertices[v1].triangles, … … 503 509 // E = 3 T / 2 504 510 vmi_mesh->edges = (VMI::Edge *)malloc(sizeof(VMI::Edge) 505 506 511 * 512 vmi_mesh->numTriangles * 3); 507 513 508 514 if (vmi_mesh->edges == NULL) … … 554 560 vmi_mesh->numEdges = n; 555 561 556 for (i=0; i<vmi_mesh->numEdges; i++) { 562 for (i = 0; i < vmi_mesh->numEdges; i++) 563 { 557 564 v1 = vmi_mesh->edges[i].u; 558 565 v2 = vmi_mesh->edges[i].v; 559 566 560 vmi_mesh->vertices[v1].edges = 561 (int *)realloc(vmi_mesh->vertices[v1].edges, (vmi_mesh->vertices[v1].numEdges + 1) * sizeof(int)); 567 vmi_mesh->vertices[v1].edges = 568 (int *)realloc(vmi_mesh->vertices[v1].edges, 569 (vmi_mesh->vertices[v1].numEdges + 1) * sizeof(int)); 570 562 571 // Adding edge i adjacent to vertex v1 563 VMI::addItem(vmi_mesh->vertices[v1].edges, &vmi_mesh->vertices[v1].numEdges, i); 564 565 vmi_mesh->vertices[v2].edges = 566 (int *)realloc(vmi_mesh->vertices[v2].edges, (vmi_mesh->vertices[v2].numEdges + 1) * sizeof(int)); 572 VMI::addItem( vmi_mesh->vertices[v1].edges, 573 &vmi_mesh->vertices[v1].numEdges, 574 i); 575 576 vmi_mesh->vertices[v2].edges = 577 (int *)realloc(vmi_mesh->vertices[v2].edges, 578 (vmi_mesh->vertices[v2].numEdges + 1) * sizeof(int)); 579 567 580 // Adding edge i adjacent to vertex v2 568 VMI::addItem(vmi_mesh->vertices[v2].edges, &vmi_mesh->vertices[v2].numEdges, i); 581 VMI::addItem( vmi_mesh->vertices[v2].edges, 582 &vmi_mesh->vertices[v2].numEdges, 583 i); 569 584 } 570 585 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/SimplificationMethod.cpp
r2089 r2194 230 230 // Contract a given pair 231 231 //------------------------------------------------------------------------- 232 void SimplificationMethod::do_contract( simplif::Model& m, 233 simplif::pair_info *auxpair) 232 void SimplificationMethod::do_contract( simplif::Model &m, 233 simplif::pair_info *auxpair, 234 int obligatory) 234 235 { 235 236 simplif::Vertex *v0 = auxpair->v0; … … 243 244 vertex_map_str lb; 244 245 vertex_map_str ub; 246 247 // Stores the simplification step. 248 MeshSimplificationSequence::Step simplifstep; 245 249 246 250 // V0 must be always the alive vertex … … 338 342 339 343 int del_index = 0; 344 345 // Initialize deleted triangles. 346 simplifstep.mT0 = -1; 347 simplifstep.mT1 = -1; 348 349 // Sets obligatory flag. 350 simplifstep.obligatory = obligatory; 340 351 341 352 // Clears faces list. … … 519 530 (vertexMultimap.find(f0) != vertexMultimap.end()) 520 531 && 521 (vertexMultimap.find(f1) != vertexMultimap.end())) 532 (vertexMultimap.find(f1) != vertexMultimap.end()) 533 && 534 ((*pair->v0) != (*pair->v1))) 522 535 { 523 536 break; … … 551 564 candidate = pair->candidate; 552 565 553 // First contract.554 simplifstep.obligatory = 0;555 556 566 // Debug. 557 567 cout << "Contracting... " … … 559 569 560 570 // Contract main pair. 561 do_contract(m, pair); 562 563 // Twin contract and lonely vertex contract. 564 simplifstep.obligatory = 1; 571 do_contract(m, pair, 0); 565 572 566 573 // Attempt to maintain valid vertex information. … … 600 607 float x,y,z; 601 608 609 /* 602 610 if ((*v0) != (*v1)) 603 611 { 612 */ 604 613 // Gets the vertex that is not the candidate. 605 614 if ((*v1) == candidate) … … 621 630 lonely_vert = m.vertex((*it).second); 622 631 632 // Debug. 633 if ((*it).second == 10988) 634 { 635 cout << "Lonely: " 636 << lonely_vert->vID 637 << endl; 638 } 639 623 640 for (int i = 0; i < lonely_vert->edgeUses().length(); i++) 624 641 { … … 671 688 672 689 // Contract twin pair. 673 do_contract(m, pair );690 do_contract(m, pair, 1); 674 691 M0.validVertCount--; 675 692 } … … 686 703 z = (*new_vert)[Z]; 687 704 705 simplif::Vertex *v; 706 707 // Debug. 708 if (new_vert->vID == 10988) 709 { 710 cout << "[" 711 << x 712 << "," 713 << y 714 << "," 715 << z 716 << "]" 717 << endl; 718 719 720 v = m.vertex(10988); 721 } 722 688 723 // Adds new vertex to multimap. 689 724 vertexMultimap.insert(vertex_pair(_float3_(x,y,z),new_vert->vID)); … … 724 759 pair->notInHeap(); 725 760 761 // Debug. 762 cout << "new: " 763 << new_vert->vID 764 << "(" 765 << (*new_vert)[X] 766 << "," 767 << (*new_vert)[Y] 768 << "," 769 << (*new_vert)[Z] 770 << ") lonely: " 771 << lonely_vert->vID 772 << "(" 773 << (*lonely_vert)[X] 774 << "," 775 << (*lonely_vert)[Y] 776 << "," 777 << (*lonely_vert)[Z] 778 << ")" 779 << endl; 780 726 781 // Contract new pair. 727 do_contract(m, pair );782 do_contract(m, pair, 1); 728 783 M0.validVertCount--; 729 784 } 730 785 } 731 } 786 /* 787 } 788 */ 732 789 } 733 790 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/SimplificationMethod.h
r2087 r2194 36 36 } 37 37 38 /* 39 bool operator==(const _float3_ &f) const 40 { 41 float F3_EPS; 42 float dx; 43 float dy; 44 float dz; 45 46 F3_EPS = 1e-12; 47 dx = x - f.x; 48 dy = y - f.y; 49 dz = z - f.z; 50 51 return (dx*dx + dy*dy + dz*dz) < F3_EPS; 52 } 53 */ 54 38 55 bool operator<(const _float3_ &f) const 39 56 { … … 73 90 MeshSimplificationSequence *msimpseq; 74 91 75 // Stores the simplification step.76 MeshSimplificationSequence::Step simplifstep;77 78 92 inline simplif::vert_info& vertex_info(simplif::Vertex *v) 79 93 { … … 100 114 void delete_pair(simplif::pair_info *pair); 101 115 102 void do_contract(simplif::Model& m, simplif::pair_info *pair); 116 void do_contract( simplif::Model& m, 117 simplif::pair_info *pair, 118 int obligatory); 103 119 104 120 bool decimate_quadric(simplif::Vertex *v, simplif::Mat4& Q); -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/buffers.h
r2127 r2194 1 #ifndef __ interleave_h_2 #define __ interleave_h_1 #ifndef __buffers_h_ 2 #define __buffers_h_ 3 3 4 4 #include "GL/glut.h" … … 21 21 } Vertex_; 22 22 23 extern GLuint vertex_buf, color_buf; 24 25 extern Vertex_ *buf_vertices; 26 extern Color *buf_colors; 27 28 extern Vertex_ *pbuf_vertices; 29 extern Color *pbuf_colors; 30 31 extern void saveVertexBuffer(Change *c, VertexIL *dest); 32 extern void loadVertexBuffer(VertexIL *src, Change *c); 23 extern VertexIL *saveVertexBuffer(Change *c, Vertex_ *verts, Color *cols); 24 extern void loadVertexBuffer(VertexIL *src, Change *c, Vertex_ *verts, Color *cols); 25 extern VertexIL *saveVertexBufferGPU(Change *c); 26 extern void loadVertexBufferGPU(VertexIL *src, Change *c); 33 27 34 28 extern VertexIL *setupInterleave(Mesh *mesh, Color *colors); 35 29 extern void setupVertexArray(Mesh *mesh, Color *colors); 36 extern void updateVertexArray(Mesh *mesh, Change *c );30 extern void updateVertexArray(Mesh *mesh, Change *c, Vertex_ *verts, Color *cols); 37 31 extern void setupVertexBufferObjects(Mesh *mesh, Color *colors); 38 32 extern void updateVertexBufferObjects(Mesh *mesh, Change *c); -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/change.h
r2127 r2194 85 85 86 86 extern void modifyEdges(Mesh *mesh, Change *c); 87 extern int find( int *edges, int num, int v_);87 extern int find(Mesh *mesh, int *edges, int num, int v_); 88 88 extern void updateEdgeAdj(Mesh *mesh, Change *c) ; 89 89 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/global.h
r2127 r2194 9 9 #include "color.h" 10 10 #include "change.h" 11 #include "buffers.h" 11 12 12 13 // For progress update. … … 132 133 extern GLsizei width, height; 133 134 135 extern GLuint vertex_buf, color_buf; 136 137 extern Vertex_ *buf_vertices; 138 extern Color *buf_colors; 139 134 140 extern int vmiWin; 135 141 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/mesh.h
r2127 r2194 13 13 int *edges; 14 14 int enable; 15 int movable; // If vertex is part of a border.16 15 } Vertex; 17 16 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/simplify.h
r2127 r2194 28 28 extern void initVertexMultimap( Mesh *mesh, 29 29 multimap<int,int> &vertexMultimap); 30 ///////////////////////////////////////////////////////////////////////// ////30 ///////////////////////////////////////////////////////////////////////// 31 31 // Coordinates class. 32 ///////////////////////////////////////////////////////////////////////// ////32 ///////////////////////////////////////////////////////////////////////// 33 33 class _float3_ 34 34 { -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/buffers.cpp
r2127 r2194 7 7 #include "../include/global.h" 8 8 9 namespace VMI 10 { 11 Vertex_ *buf_vertices = NULL; 12 Color *buf_colors = NULL; 13 14 Vertex_ *pbuf_vertices; 15 Color *pbuf_colors; 16 17 GLuint vertex_buf = 0, 18 color_buf = 0; 19 20 } 21 22 using namespace VMI; 23 24 void VMI::saveVertexBuffer(Change *c, VertexIL *dest) { 25 int j, t, n = 0, m; 9 using namespace VMI; 10 11 12 13 VertexIL *VMI::saveVertexBuffer(Change *c, Vertex_ *verts, Color *cols) { 14 int i, j, t, n = 0, m; 15 VertexIL *dest; 16 17 dest = (VertexIL *)malloc((c->numDel + c->numMod + 1) * 3 * sizeof(VertexIL)); 26 18 27 19 // Save vertex coordinates and color for deleted triangles … … 32 24 m = 3 * t; 33 25 34 dest[n].x = buf_vertices[m + 0].x; 35 dest[n].y = buf_vertices[m + 0].y; 36 dest[n].z = buf_vertices[m + 0].z; 37 dest[n].a = buf_colors[m + 0].a; 38 dest[n].b = buf_colors[m + 0].b; 39 dest[n].r = buf_colors[m + 0].r; 40 dest[n].g = buf_colors[m + 0].g; 41 n++; 42 43 dest[n].x = buf_vertices[m + 1].x; 44 dest[n].y = buf_vertices[m + 1].y; 45 dest[n].z = buf_vertices[m + 1].z; 46 dest[n].a = buf_colors[m + 1].a; 47 dest[n].b = buf_colors[m + 1].b; 48 dest[n].r = buf_colors[m + 1].r; 49 dest[n].g = buf_colors[m + 1].g; 50 n++; 51 52 dest[n].x = buf_vertices[m + 2].x; 53 dest[n].y = buf_vertices[m + 2].y; 54 dest[n].z = buf_vertices[m + 2].z; 55 dest[n].a = buf_colors[m + 2].a; 56 dest[n].b = buf_colors[m + 2].b; 57 dest[n].r = buf_colors[m + 2].r; 58 dest[n].g = buf_colors[m + 2].g; 59 n++; 26 for (i=0; i<3; i++) { 27 dest[n].x = verts[m + i].x; 28 dest[n].y = verts[m + i].y; 29 dest[n].z = verts[m + i].z; 30 dest[n].a = cols[m + i].a; 31 dest[n].b = cols[m + i].b; 32 dest[n].r = cols[m + i].r; 33 dest[n].g = cols[m + i].g; 34 n++; 35 } 60 36 } 61 37 // Save vertex coordinates for modified triangles … … 66 42 m = 3 * t; 67 43 68 dest[n].x = buf_vertices[m + 0].x; 69 dest[n].y = buf_vertices[m + 0].y; 70 dest[n].z = buf_vertices[m + 0].z; 71 n++; 72 73 dest[n].x = buf_vertices[m + 1].x; 74 dest[n].y = buf_vertices[m + 1].y; 75 dest[n].z = buf_vertices[m + 1].z; 76 n++; 77 78 dest[n].x = buf_vertices[m + 2].x; 79 dest[n].y = buf_vertices[m + 2].y; 80 dest[n].z = buf_vertices[m + 2].z; 81 n++; 82 } 83 } 84 85 void VMI::loadVertexBuffer(VertexIL *src, Change *c) { 86 int j, t, n = 0, m; 87 44 for (i=0; i<3; i++) { 45 dest[n].x = verts[m + i].x; 46 dest[n].y = verts[m + i].y; 47 dest[n].z = verts[m + i].z; 48 n++; 49 } 50 } 51 52 return dest; 53 } 54 55 VertexIL *VMI::saveVertexBufferGPU(Change *c) { 56 Vertex_ *verts; 57 Color *cols; 58 VertexIL *dest; 59 60 glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buf); 61 // Map the buffer object 62 verts = (Vertex_ *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_READ_ONLY); 63 64 glBindBufferARB(GL_ARRAY_BUFFER_ARB, color_buf); 65 // Map the buffer object 66 cols = (Color *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_READ_ONLY); 67 68 // Update GPU buffers 69 dest = saveVertexBuffer(c, verts, cols); 70 71 // Unmap buffers 72 glBindBuffer(GL_ARRAY_BUFFER_ARB, vertex_buf); 73 if (!glUnmapBufferARB(GL_ARRAY_BUFFER_ARB)) { 74 // Handle error case 75 } 76 glBindBuffer(GL_ARRAY_BUFFER_ARB, color_buf); 77 if (!glUnmapBufferARB(GL_ARRAY_BUFFER_ARB)) { 78 // Handle error case 79 } 80 81 return dest; 82 } 83 84 void VMI::loadVertexBuffer(VertexIL *src, Change *c, Vertex_ *verts, Color *cols) { 85 int i, j, t, n = 0, m; 86 88 87 // Load vertex coordinates and color for deleted triangles 89 88 for (j=0; j<c->numDel; j++) { … … 92 91 93 92 m = 3 * t; 94 95 buf_vertices[m + 0].x = src[n].x; 96 buf_vertices[m + 0].y = src[n].y; 97 buf_vertices[m + 0].z = src[n].z; 98 buf_colors[m + 0].a = src[n].a; 99 buf_colors[m + 0].b = src[n].b; 100 buf_colors[m + 0].r = src[n].r; 101 buf_colors[m + 0].g = src[n].g; 102 n++; 103 104 buf_vertices[m + 1].x = src[n].x; 105 buf_vertices[m + 1].y = src[n].y; 106 buf_vertices[m + 1].z = src[n].z; 107 buf_colors[m + 1].a = src[n].a; 108 buf_colors[m + 1].b = src[n].b; 109 buf_colors[m + 1].r = src[n].r; 110 buf_colors[m + 1].g = src[n].g; 111 n++; 112 113 buf_vertices[m + 2].x = src[n].x; 114 buf_vertices[m + 2].y = src[n].y; 115 buf_vertices[m + 2].z = src[n].z; 116 buf_colors[m + 2].a = src[n].a; 117 buf_colors[m + 2].b = src[n].b; 118 buf_colors[m + 2].r = src[n].r; 119 buf_colors[m + 2].g = src[n].g; 120 n++; 93 94 for (i=0; i<3; i++) { 95 verts[m + i].x = src[n].x; 96 verts[m + i].y = src[n].y; 97 verts[m + i].z = src[n].z; 98 cols[m + i].a = src[n].a; 99 cols[m + i].b = src[n].b; 100 cols[m + i].r = src[n].r; 101 cols[m + i].g = src[n].g; 102 n++; 103 } 121 104 } 122 105 // Load vertex coordinates for modified triangles … … 126 109 127 110 m = 3 * t; 128 129 buf_vertices[m + 0].x = src[n].x; 130 buf_vertices[m + 0].y = src[n].y; 131 buf_vertices[m + 0].z = src[n].z; 132 n++; 133 134 buf_vertices[m + 1].x = src[n].x; 135 buf_vertices[m + 1].y = src[n].y; 136 buf_vertices[m + 1].z = src[n].z; 137 n++; 138 139 buf_vertices[m + 2].x = src[n].x; 140 buf_vertices[m + 2].y = src[n].y; 141 buf_vertices[m + 2].z = src[n].z; 142 n++; 111 112 for (i=0; i<3; i++) { 113 verts[m + i].x = src[n].x; 114 verts[m + i].y = src[n].y; 115 verts[m + i].z = src[n].z; 116 n++; 117 } 118 } 119 } 120 121 void VMI::loadVertexBufferGPU(VertexIL *src, Change *c) { 122 Vertex_ *verts; 123 Color *cols; 124 125 glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buf); 126 // Map the buffer object 127 verts = (Vertex_ *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY); 128 129 glBindBufferARB(GL_ARRAY_BUFFER_ARB, color_buf); 130 // Map the buffer object 131 cols = (Color *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY); 132 133 // Update GPU buffers 134 loadVertexBuffer(src, c, verts, cols); 135 136 // Unmap buffers 137 glBindBuffer(GL_ARRAY_BUFFER_ARB, vertex_buf); 138 if (!glUnmapBufferARB(GL_ARRAY_BUFFER_ARB)) { 139 // Handle error case 140 } 141 glBindBuffer(GL_ARRAY_BUFFER_ARB, color_buf); 142 if (!glUnmapBufferARB(GL_ARRAY_BUFFER_ARB)) { 143 // Handle error case 143 144 } 144 145 } … … 146 147 void VMI::setupVertexArray(Mesh *mesh, Color *colors) 147 148 { 148 int i, v1, v2, v3, n = 0;149 int i, j, v, n = 0; 149 150 GLubyte r, g, b, a; 150 151 … … 153 154 154 155 buf_vertices = (Vertex_ *)malloc(mesh->numTriangles * 3 * sizeof(Vertex_)); 155 156 156 buf_colors = (Color *)malloc(mesh->numTriangles * 3 * sizeof(Color)); 157 157 … … 167 167 168 168 for (i=0; i<mesh->numTriangles; i++) { 169 170 v1= mesh->triangles[i].indices[0]; 171 v2= mesh->triangles[i].indices[1]; 172 v3= mesh->triangles[i].indices[2]; 173 174 if (mesh->triangles[i].enable == TRUE) { 175 176 r = colors[i].r; 177 g = colors[i].g; 178 b = colors[i].b; 179 a = colors[i].a; 180 181 buf_colors[n].r = r; 182 buf_colors[n].g = g; 183 buf_colors[n].b = b; 184 buf_colors[n].a = a; 185 buf_vertices[n].x = mesh->vertices[v1].x; 186 buf_vertices[n].y = mesh->vertices[v1].y; 187 buf_vertices[n].z = mesh->vertices[v1].z; 188 n++; 189 190 buf_colors[n].r = r; 191 buf_colors[n].g = g; 192 buf_colors[n].b = b; 193 buf_colors[n].a = a; 194 buf_vertices[n].x = mesh->vertices[v2].x; 195 buf_vertices[n].y = mesh->vertices[v2].y; 196 buf_vertices[n].z = mesh->vertices[v2].z; 197 n++; 198 199 buf_colors[n].r = r; 200 buf_colors[n].g = g; 201 buf_colors[n].b = b; 202 buf_colors[n].a = a; 203 buf_vertices[n].x = mesh->vertices[v3].x; 204 buf_vertices[n].y = mesh->vertices[v3].y; 205 buf_vertices[n].z = mesh->vertices[v3].z; 206 n++; 207 } else { 208 209 buf_colors[n].r = 0; 210 buf_colors[n].g = 0; 211 buf_colors[n].b = 0; 212 buf_colors[n].a = 0; 213 buf_vertices[n].x = 0; 214 buf_vertices[n].y = 0; 215 buf_vertices[n].z = 0; 216 n++; 217 218 buf_colors[n].r = 0; 219 buf_colors[n].g = 0; 220 buf_colors[n].b = 0; 221 buf_colors[n].a = 0; 222 buf_vertices[n].x = 0; 223 buf_vertices[n].y = 0; 224 buf_vertices[n].z = 0; 225 n++; 226 227 buf_colors[n].r = 0; 228 buf_colors[n].g = 0; 229 buf_colors[n].b = 0; 230 buf_colors[n].a = 0; 231 buf_vertices[n].x = 0; 232 buf_vertices[n].y = 0; 233 buf_vertices[n].z = 0; 234 n++; 235 } 169 if (mesh->triangles[i].enable == TRUE) { 170 171 r = colors[i].r; 172 g = colors[i].g; 173 b = colors[i].b; 174 a = colors[i].a; 175 176 for (j=0; j<3; j++) { 177 178 v = mesh->triangles[i].indices[j]; 179 180 buf_colors[n].r = r; 181 buf_colors[n].g = g; 182 buf_colors[n].b = b; 183 buf_colors[n].a = a; 184 buf_vertices[n].x = mesh->vertices[v].x; 185 buf_vertices[n].y = mesh->vertices[v].y; 186 buf_vertices[n].z = mesh->vertices[v].z; 187 n++; 188 } 189 } else { 190 for (j=0; j<3; j++) { 191 192 buf_colors[n].r = 0; 193 buf_colors[n].g = 0; 194 buf_colors[n].b = 0; 195 buf_colors[n].a = 0; 196 buf_vertices[n].x = 0; 197 buf_vertices[n].y = 0; 198 buf_vertices[n].z = 0; 199 n++; 200 } 201 } 236 202 } 237 203 #ifdef VERTEX_ARRAY … … 243 209 glVertexPointer(3, GL_FLOAT, 0, buf_vertices); 244 210 #endif 245 246 pbuf_colors = buf_colors;247 pbuf_vertices = buf_vertices;248 211 } 249 212 … … 253 216 254 217 glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buf); 255 glBufferDataARB(GL_ARRAY_BUFFER_ARB, mesh->numTriangles * 3 * 3 * sizeof(float), buf_vertices, GL_STATIC_DRAW_ARB); //upload data218 glBufferDataARB(GL_ARRAY_BUFFER_ARB, mesh->numTriangles * 3 * sizeof(Vertex_), buf_vertices, GL_STATIC_DRAW_ARB); //upload data 256 219 257 220 glVertexPointer(3, GL_FLOAT, 0,0); … … 265 228 glEnableClientState(GL_VERTEX_ARRAY); 266 229 glEnableClientState(GL_COLOR_ARRAY); 267 268 //free(buf_vertices);269 //buf_vertices = NULL;270 271 //free(buf_colors);272 //buf_colors =NULL;273 } 274 275 void VMI::updateVertexArray(Mesh *mesh, Change *c )276 { 277 int i, v1, v2, v3, t, n;230 231 free(buf_vertices); 232 buf_vertices = NULL; 233 234 free(buf_colors); 235 buf_colors =NULL; 236 } 237 238 void VMI::updateVertexArray(Mesh *mesh, Change *c, Vertex_ *verts, Color * cols) 239 { 240 int i, j, v, t, n; 278 241 279 242 // The deleted triangles are now in background color 280 243 for (i=0; i<c->numDel; i++) { 281 244 t = c->deleted[i].id; 282 245 283 246 n = t * 3; 284 285 buf_colors[n + 0].r = 0; 286 buf_colors[n + 0].g = 0; 287 buf_colors[n + 0].b = 0; 288 buf_colors[n + 0].a = 0; 289 290 buf_colors[n + 1].r = 0; 291 buf_colors[n + 1].g = 0; 292 buf_colors[n + 1].b = 0; 293 buf_colors[n + 1].a = 0; 294 295 buf_colors[n + 2].r = 0; 296 buf_colors[n + 2].g = 0; 297 buf_colors[n + 2].b = 0; 298 buf_colors[n + 2].a = 0; 299 300 buf_vertices[n + 0].x = 0; 301 buf_vertices[n + 0].y = 0; 302 buf_vertices[n + 0].z = 0; 303 304 buf_vertices[n + 1].x = 0; 305 buf_vertices[n + 1].y = 0; 306 buf_vertices[n + 1].z = 0; 307 308 buf_vertices[n + 2].x = 0; 309 buf_vertices[n + 2].y = 0; 310 buf_vertices[n + 2].z = 0; 247 248 for (j=0; j<3; j++) { 249 cols[n + j].r = 0; 250 cols[n + j].g = 0; 251 cols[n + j].b = 0; 252 cols[n + j].a = 0; 253 254 verts[n + j].x = 0; 255 verts[n + j].y = 0; 256 verts[n + j].z = 0; 257 } 311 258 } 312 259 … … 317 264 n = t * 3; 318 265 319 v1= mesh->triangles[t].indices[0]; 320 v2= mesh->triangles[t].indices[1]; 321 v3= mesh->triangles[t].indices[2]; 322 323 buf_vertices[n + 0].x = mesh->vertices[v1].x; 324 buf_vertices[n + 0].y = mesh->vertices[v1].y; 325 buf_vertices[n + 0].z = mesh->vertices[v1].z; 326 327 buf_vertices[n + 1].x = mesh->vertices[v2].x; 328 buf_vertices[n + 1].y = mesh->vertices[v2].y; 329 buf_vertices[n + 1].z = mesh->vertices[v2].z; 330 331 buf_vertices[n + 2].x = mesh->vertices[v3].x; 332 buf_vertices[n + 2].y = mesh->vertices[v3].y; 333 buf_vertices[n + 2].z = mesh->vertices[v3].z; 266 for (j=0; j<3; j++) { 267 268 v= mesh->triangles[t].indices[j]; 269 270 verts[n + j].x = mesh->vertices[v].x; 271 verts[n + j].y = mesh->vertices[v].y; 272 verts[n + j].z = mesh->vertices[v].z; 273 } 334 274 } 335 275 } 336 276 337 277 void VMI::updateVertexBufferObjects(Mesh *mesh, Change *c) { 278 Vertex_ *verts; 279 Color *cols; 338 280 339 281 glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buf); 340 282 // Map the buffer object 341 buf_vertices = (Vertex_ *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY);283 verts = (Vertex_ *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY); 342 284 343 285 glBindBufferARB(GL_ARRAY_BUFFER_ARB, color_buf); 344 286 // Map the buffer object 345 buf_colors = (Color *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY); 346 347 updateVertexArray(mesh, c); 287 cols = (Color *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY); 288 289 // Update GPU buffers 290 updateVertexArray(mesh, c, verts, cols); 348 291 349 292 // Unmap buffers … … 360 303 VertexIL *VMI::setupInterleave(Mesh *mesh, Color *colors) 361 304 { 362 int i, v1, v2, v3, n = 0;305 int i, j, v, n = 0; 363 306 GLubyte r, g, b, a; 364 307 VertexIL *interleave = NULL; … … 374 317 375 318 if (mesh->triangles[i].enable == TRUE) { 376 v1= mesh->triangles[i].indices[0]; 377 v2= mesh->triangles[i].indices[1]; 378 v3= mesh->triangles[i].indices[2]; 379 380 r = colors[i].r; 319 320 r = colors[i].r; 381 321 g = colors[i].g; 382 322 b = colors[i].b; 383 323 a = colors[i].a; 384 385 interleave[n].tx = 0.0f; 386 interleave[n].ty = 0.0f; 387 interleave[n].r = r; 388 interleave[n].g = g; 389 interleave[n].b = b; 390 interleave[n].a = a; 391 interleave[n].x = mesh->vertices[v1].x; 392 interleave[n].y = mesh->vertices[v1].y; 393 interleave[n].z = mesh->vertices[v1].z; 394 n++; 395 396 interleave[n].tx = 0.0f; 397 interleave[n].ty = 0.0f; 398 interleave[n].r = r; 399 interleave[n].g = g; 400 interleave[n].b = b; 401 interleave[n].a = a; 402 interleave[n].x = mesh->vertices[v2].x; 403 interleave[n].y = mesh->vertices[v2].y; 404 interleave[n].z = mesh->vertices[v2].z; 405 n++; 406 407 interleave[n].tx = 0.0f; 408 interleave[n].ty = 0.0f; 409 interleave[n].r = r; 410 interleave[n].g = g; 411 interleave[n].b = b; 412 interleave[n].a = a; 413 interleave[n].x = mesh->vertices[v3].x; 414 interleave[n].y = mesh->vertices[v3].y; 415 interleave[n].z = mesh->vertices[v3].z; 416 n++; 324 325 for (j=0; j<3; j++) { 326 327 v= mesh->triangles[i].indices[j]; 328 329 interleave[n].tx = 0.0f; 330 interleave[n].ty = 0.0f; 331 interleave[n].r = r; 332 interleave[n].g = g; 333 interleave[n].b = b; 334 interleave[n].a = a; 335 interleave[n].x = mesh->vertices[v].x; 336 interleave[n].y = mesh->vertices[v].y; 337 interleave[n].z = mesh->vertices[v].z; 338 n++; 339 } 417 340 } 418 341 } … … 435 358 void VMI::updateAllColorInterleave(VertexIL *interleave, int num, Color *colors) 436 359 { 437 int i, n = 0;360 int i, j, n = 0; 438 361 GLubyte r, g, b, a; 439 362 440 363 for (i=1; i<=num; i++) { // Triangles start at 1 441 364 442 365 r = colors[i].r; 443 366 g = colors[i].g; 444 367 b = colors[i].b; 445 368 a = colors[i].a; 446 447 interleave[n].r = r; 448 interleave[n].g = g; 449 interleave[n].b = b; 450 interleave[n].a = a; 451 n++; 452 453 interleave[n].r = r; 454 interleave[n].g = g; 455 interleave[n].b = b; 456 interleave[n].a = a; 457 n++; 458 459 interleave[n].r = r; 460 interleave[n].g = g; 461 interleave[n].b = b; 462 interleave[n].a = a; 463 n++; 369 370 for (j=0; j<3; j++) { 371 interleave[n].r = r; 372 interleave[n].g = g; 373 interleave[n].b = b; 374 interleave[n].a = a; 375 n++; 376 } 464 377 } 465 378 } -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/change.cpp
r2127 r2194 313 313 } 314 314 315 int VMI::find( int *edges, int num, int v_) {315 int VMI::find(Mesh *mesh, int *edges, int num, int v_) { 316 316 int i; 317 318 317 int u, v; 319 318 320 321 319 for(i=0; i<num; i++) { 322 320 323 321 u = mesh->edges[edges[i]].u; 324 325 322 v = mesh->edges[edges[i]].v; 326 323 … … 333 330 void VMI::updateEdgeAdj(Mesh *mesh, Change *c) { 334 331 int i; 335 336 332 int v, e; 337 333 … … 346 342 else v = mesh->edges[e].u; 347 343 348 if (!find(mesh ->vertices[c->v].edges, mesh->vertices[c->v].numEdges, v))344 if (!find(mesh, mesh->vertices[c->v].edges, mesh->vertices[c->v].numEdges, v)) 349 345 addItem(mesh->vertices[c->v].edges, &mesh->vertices[c->v].numEdges, e); 350 346 else mesh->edges[e].enable = FALSE; … … 427 423 << endl; 428 424 425 if (c->numDel == 0) 426 { 427 step.mT0 = -1; 428 step.mT1 = -1; 429 } 429 430 // If only one triangle has been deleted. 430 if (c->numDel == 1)431 else if (c->numDel == 1) 431 432 { 432 433 step.mT0 = c->deleted[0].id; -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/histogram.cpp
r2127 r2194 343 343 344 344 w += (WIN_MARGIN * 2); 345 if (w > width) w = width;345 if (w + ox> width) w = width - ox; 346 346 h += (WIN_MARGIN * 2); 347 if (h > height) h = height;347 if (h + oy> height) h = height - oy; 348 348 349 349 //printf("(%d,%d)\n", ox, oy); -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/main.cpp
r2127 r2194 37 37 GLuint fb, depth_rb, color_tex; 38 38 39 #ifdef VERTEX_ARRAY_INTERLEAVE 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 39 49 int vmiWin = 0; 40 50 … … 48 58 void VMI::init(void) 49 59 { 50 // Clear color 51 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 52 53 // Initialize viewing values 54 glMatrixMode(GL_PROJECTION); 55 glLoadIdentity(); 56 gluPerspective(fov, (GLdouble)width / height, 0.1, 40.0); 57 58 //glPixelStorei(GL_PACK_ALIGNMENT, 1); 59 //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 60 61 glShadeModel(GL_FLAT); 62 63 glDisable(GL_BLEND); 64 65 glEnable(GL_CULL_FACE); // important 66 67 glEnable(GL_DEPTH_TEST); 68 69 if (GL_TRUE != glewIsSupported((const char*) "GL_EXT_framebuffer_object")) 70 { 71 fprintf(stderr,"GL_EXT_framebuffer_object extension is not available!\n"); 72 exit(1); 73 } else { 74 // create objects 75 glGenFramebuffersEXT(1, &fb); // frame buffer 76 glGenTextures(1, &color_tex); // texture 77 glGenRenderbuffersEXT(1, &depth_rb); // render buffer 78 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); 79 80 // initialize color texture 81 glBindTexture(GL_TEXTURE_2D, color_tex); 82 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, 83 GL_RGBA, GL_UNSIGNED_BYTE, NULL); 84 // texture parameters 85 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 86 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 87 88 // attach texture to framebuffer color buffer 89 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 90 GL_COLOR_ATTACHMENT0_EXT, 91 GL_TEXTURE_2D, color_tex, 0); 92 // initialize depth renderbuffer 93 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb); 94 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, 95 GL_DEPTH_COMPONENT24, width, height); 96 // attach renderbuffer to framebuffer depth buffer 97 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, 98 GL_DEPTH_ATTACHMENT_EXT, 99 GL_RENDERBUFFER_EXT, depth_rb); 100 101 // Check framebuffer completeness at the end of initialization. 102 CHECK_FRAMEBUFFER_STATUS(); 103 } 104 /*if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_fragment_shader")) 105 { 106 fprintf(stderr,"GL_ARB_fragment_shader extension is not available!\n"); 107 } 108 if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_vertex_shader")) 109 { 110 fprintf(stderr,"GL_ARB_vertex_shader extension is not available!\n"); 111 } 112 if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_shader_objects")) 113 { 114 fprintf(stderr,"GL_ARB_shader_objects extension is not available!\n"); 115 }*/ 116 if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_vertex_buffer_object")) 117 { 118 fprintf(stderr,"GL_ARB_vertex_buffer_object extension is not available!\n"); 119 } else { 60 // Clear color 61 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 62 63 // Initialize viewing values 64 glMatrixMode(GL_PROJECTION); 65 glLoadIdentity(); 66 gluPerspective(fov, (GLdouble)width / height, 0.1, 40.0); 67 68 //glPixelStorei(GL_PACK_ALIGNMENT, 1); 69 //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 70 71 glShadeModel(GL_FLAT); 72 73 glDisable(GL_BLEND); 74 75 glEnable(GL_CULL_FACE); // important 76 77 glEnable(GL_DEPTH_TEST); 78 79 if (GL_TRUE != glewIsSupported((const char*) "GL_EXT_framebuffer_object")) 80 { 81 fprintf(stderr, 82 "GL_EXT_framebuffer_object extension is not available!\n"); 83 exit(1); 84 } 85 else 86 { 87 // create objects 88 glGenFramebuffersEXT(1, &fb); // frame buffer 89 glGenTextures(1, &color_tex); // texture 90 glGenRenderbuffersEXT(1, &depth_rb); // render buffer 91 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); 92 93 // initialize color texture 94 glBindTexture(GL_TEXTURE_2D, color_tex); 95 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, 96 GL_RGBA, GL_UNSIGNED_BYTE, NULL); 97 // texture parameters 98 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 99 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 100 101 // attach texture to framebuffer color buffer 102 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 103 GL_COLOR_ATTACHMENT0_EXT, 104 GL_TEXTURE_2D, color_tex, 0); 105 // initialize depth renderbuffer 106 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb); 107 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, 108 GL_DEPTH_COMPONENT24, width, height); 109 // attach renderbuffer to framebuffer depth buffer 110 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, 111 GL_DEPTH_ATTACHMENT_EXT, 112 GL_RENDERBUFFER_EXT, depth_rb); 113 114 // Check framebuffer completeness at the end of initialization. 115 CHECK_FRAMEBUFFER_STATUS(); 116 } 117 /*if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_fragment_shader")) 118 { 119 fprintf(stderr,"GL_ARB_fragment_shader extension is not available!\n"); 120 } 121 if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_vertex_shader")) 122 { 123 fprintf(stderr,"GL_ARB_vertex_shader extension is not available!\n"); 124 } 125 if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_shader_objects")) 126 { 127 fprintf(stderr,"GL_ARB_shader_objects extension is not available!\n"); 128 }*/ 129 if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_vertex_buffer_object")) 130 { 131 fprintf(stderr, 132 "GL_ARB_vertex_buffer_object extension is not available!\n"); 133 } 134 else 135 { 120 136 #ifdef VERTEX_BUFFER_OBJECTS 121 122 glGenBuffersARB(1, &vertex_buf); 123 124 glGenBuffersARB(1, &color_buf); 125 #endif 126 } 127 if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_occlusion_query")) 128 { 129 fprintf(stderr,"GL_ARB_occlusion_query extension is not available!\n"); 130 } else { 137 glGenBuffersARB(1, &vertex_buf); 138 139 glGenBuffersARB(1, &color_buf); 140 #endif 141 } 142 143 if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_occlusion_query")) 144 { 145 fprintf(stderr, 146 "GL_ARB_occlusion_query extension is not available!\n"); 147 } 148 else 149 { 131 150 #ifdef USE_OCCLUSION_QUERY 132 // Generate a list of occlusion queries 133 queries = (GLuint *)malloc(mesh->currentNumTriangles * sizeof(GLuint)); 134 glGenQueriesARB(mesh->currentNumTriangles, queries);y 135 #endif 136 } 137 if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_imaging")) 138 { 139 fprintf(stderr,"GL_ARB_imaging extension is not available!\n"); 140 } 141 if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_multitexture")) 142 { 143 fprintf(stderr,"GL_ARB_multitexture extension is not available!\n"); 144 } 151 // Generate a list of occlusion queries 152 queries = (GLuint *)malloc(mesh->currentNumTriangles * sizeof(GLuint)); 153 glGenQueriesARB(mesh->currentNumTriangles, queries); 154 #endif 155 } 156 157 if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_imaging")) 158 { 159 fprintf(stderr,"GL_ARB_imaging extension is not available!\n"); 160 } 161 162 if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_multitexture")) 163 { 164 fprintf(stderr,"GL_ARB_multitexture extension is not available!\n"); 165 } 166 145 167 #ifdef _WIN32 146 147 148 149 150 #endif 151 152 // Allocate memory for the image pixels 153 154 155 // Allocate memory for colors 156 157 158 // Set a different color for every triangle 159 168 if (GL_TRUE != wglewIsSupported((const char*) "WGL_EXT_swap_control")) 169 { 170 fprintf(stderr,"WGL_EXT_swap_control extension is not available!\n"); 171 } 172 #endif 173 174 // Allocate memory for the image pixels. 175 pixels = (GLubyte *)malloc(width * height * 4 * sizeof(GLubyte)); 176 177 // Allocate memory for colors. 178 colors = initColors(mesh->currentNumTriangles); 179 180 // Set a different color for every triangle. 181 setColors4(colors, mesh->currentNumTriangles); 160 182 } 161 183 … … 246 268 #endif 247 269 #ifdef VERTEX_ARRAY_INTERLEAVE 248 glInterleavedArrays (GL_T2F_C4UB_V3F, 0, inter twined);270 glInterleavedArrays (GL_T2F_C4UB_V3F, 0, interleave); 249 271 glDrawArrays(GL_TRIANGLES, 0, mesh->currentNumTriangles * 3); 250 272 #endif … … 444 466 #ifdef VERTEX_BUFFER_OBJECTS 445 467 glDeleteBuffersARB(1, &vertex_buf); 446 447 468 glDeleteBuffersARB(1, &color_buf); 448 449 //free(pbuf_vertices);450 //free(pbuf_colors);451 469 452 470 buf_vertices = NULL; … … 455 473 #endif 456 474 #ifdef VERTEX_ARRAY 457 //free(pbuf_vertices);458 //free(pbuf_colors);475 free(buf_vertices); 476 free(buf_colors); 459 477 460 478 buf_vertices = NULL; 461 479 buf_colors = NULL; 480 #endif 481 #ifdef VERTEX_ARRAY_INTERLEAVE 482 free(interleave); 483 interleave = NULL; 462 484 #endif 463 485 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/mesh.cpp
r2127 r2194 443 443 } 444 444 445 void VMI::deleteMesh(Mesh *mesh) { 445 void VMI::deleteMesh(Mesh *mesh) 446 { 446 447 int i; 447 448 448 if (NULL != mesh) { 449 for (i=0; i<mesh->numVertices; i++) { 449 if (NULL != mesh) 450 { 451 for (i=0; i<mesh->numVertices; i++) 452 { 450 453 if (mesh->vertices[i].triangles != NULL) 451 454 free(mesh->vertices[i].triangles); … … 453 456 if (mesh->vertices[i].edges != NULL) 454 457 free(mesh->vertices[i].edges); 455 456 458 } 459 457 460 if (mesh->vertices != NULL) free(mesh->vertices); 458 461 mesh->numVertices = 0; … … 550 553 if (numVertices > 0) { 551 554 // Add the first 552 list = mesh->vertices[vertices[0]].edges;553 numEdges = mesh->vertices[vertices[0]].numEdges;555 list = mesh->vertices[vertices[0]].edges; 556 numEdges = mesh->vertices[vertices[0]].numEdges; 554 557 555 558 // Allocate memory … … 563 566 for (i=1; i<numVertices; i++) { 564 567 565 list = mesh->vertices[vertices[i]].edges;566 numEdges = mesh->vertices[vertices[i]].numEdges;568 list = mesh->vertices[vertices[i]].edges; 569 numEdges = mesh->vertices[vertices[i]].numEdges; 567 570 568 571 // Reallocate memory -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/simplify.cpp
r2127 r2194 28 28 vector<Geometry::Vector2> VMI::vTexCoords; 29 29 30 ////////////////////////////////////////////////////////////////////////// /////30 ////////////////////////////////////////////////////////////////////////// 31 31 32 32 void VMI::bh_mydump(Mesh *mesh, bheap_t *h) { … … 56 56 exit(1); 57 57 } 58 } 58 } 59 59 } 60 60 … … 73 73 for (i = 0; i <mesh->numEdges; i++) { 74 74 75 // Update progress bar. 76 mUPB(percent); 75 if (mUPB) 76 { 77 // Update progress bar. 78 mUPB(percent); 79 } 77 80 78 81 if (mesh->edges[i].enable == TRUE) { … … 226 229 /////////////////////////////////////////////////////////////////////////////// 227 230 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++) { 232 233 t = c->deleted[j].id; 234 235 for (i=0; i<numCameras; i++) { 236 237 dest[n] = histogram[i][t + 1]; 238 n++; 239 } 240 } 241 242 for (j=0; j<c->numMod; j++) { 243 244 t = c->modified[j].id; 245 246 for (i=0; i<numCameras; i++) { 247 248 dest[n] = histogram[i][t + 1]; 249 n++; 250 } 251 } 252 253 // Save background area 254 for (i=0; i<numCameras; i++) { 255 256 dest[n] = histogram[i][0]; 257 n++; 258 } 231 int *saveProjectedAreas(int **histogram, int numCameras, Change *c) { 232 int i, j, t, n = 0; 233 int *dest; 234 235 // Allocate memory 236 dest = (int *)malloc((c->numDel + c->numMod + 1) * numCameras * sizeof(int)); 237 238 for (j=0; j<c->numDel; j++) { 239 240 t = c->deleted[j].id; 241 242 for (i=0; i<numCameras; i++) { 243 244 dest[n] = histogram[i][t + 1]; 245 n++; 246 } 247 } 248 249 for (j=0; j<c->numMod; j++) { 250 251 t = c->modified[j].id; 252 253 for (i=0; i<numCameras; i++) { 254 255 dest[n] = histogram[i][t + 1]; 256 n++; 257 } 258 } 259 260 // Save background area 261 for (i=0; i<numCameras; i++) { 262 263 dest[n] = histogram[i][0]; 264 n++; 265 } 266 267 return dest; 259 268 } 260 269 … … 365 374 penalized = check_local_inversion(mesh, c); 366 375 #endif 367 // Allocate memory 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); 376 #ifdef VERTEX_ARRAY 377 vb = saveVertexBuffer(c, buf_vertices, buf_colors); 378 #endif 379 #ifdef VERTEX_BUFFER_OBJECTS 380 vb = saveVertexBufferGPU(c); 374 381 #endif 375 382 … … 388 395 } 389 396 390 saveProjectedAreas(histogram, numCameras, c, histoAux);397 histoAux = saveProjectedAreas(histogram, numCameras, c); 391 398 // Apply the edge collapse 392 399 doChange(mesh, c); … … 424 431 /////////////////////////////////////////////////////////////////////////////// 425 432 426 saveProjectedAreas(histogram, numCameras, c, histoAux);433 histoAux = saveProjectedAreas(histogram, numCameras, c); 427 434 428 435 doChange(mesh, c); … … 459 466 // Free memory 460 467 free(histoAux); 461 #if defined(VERTEX_BUFFER_OBJECTS) || defined(VERTEX_ARRAY) 462 loadVertexBuffer(vb, c); 468 #ifdef VERTEX_ARRAY 469 loadVertexBuffer(vb, c, buf_vertices, buf_colors); 470 free(vb); 471 #endif 472 #ifdef VERTEX_BUFFER_OBJECTS 473 loadVertexBufferGPU(vb, c); 463 474 free(vb); 464 475 #endif … … 499 510 e = bh_min(h); 500 511 501 while (!isValidEdge_(mesh, e) ) {512 while (!isValidEdge_(mesh, e) && (h->n >0)) { 502 513 /* delete invalid edge */ 503 514 bh_delete(h, e); … … 510 521 511 522 /* Get the mininum edge cost from the heap using lazy evaluation */ 512 int getMinEdge(Mesh *mesh, bheap_t *h) { 523 int getMinEdge(Mesh *mesh, bheap_t *h) 524 { 513 525 double cost; 514 526 int e; … … 517 529 e = getMinValidEdge(mesh, h); 518 530 519 while (bh_is_dirty(h, e) ) {531 while (bh_is_dirty(h, e) && (h->n >0)) { 520 532 /* delete edge from heap */ 521 533 bh_delete(h, e); … … 560 572 if (bSaveLog == TRUE) 561 573 { 562 #ifdef SALIENCY 574 #ifdef SALIENCY 563 575 sprintf(s,"%s_%s_S.log", filename, EXT); 564 576 #else … … 573 585 if (!file) 574 586 { 575 fprintf(stderr, "simplifyModel() failed: can't open file \"%s\" to write.\n", s); 587 fprintf(stderr, 588 "simplifyModel() failed: can't open file \"%s\" to write.\n", 589 s); 590 576 591 exit(1); 577 592 } … … 592 607 printf("Starting simplification...\n"); 593 608 594 while (mesh->currentNumTriangles > numDemandedTri /*&& cost == 0.0*/)609 while (mesh->currentNumTriangles > numDemandedTri && (h->n >0)/*&& cost == 0.0*/) 595 610 { 596 611 // Get the edge that has the minimum cost … … 600 615 c = createChange(mesh, e); 601 616 602 // Apply the edge collapse 603 doChange(mesh, c); 604 //deleteVertexOfMap(mesh, c->u); 605 606 // Write Simplification sequence. 607 saveSimplificationSequence(c,0); 608 609 //contractTwinVertices(mesh, c->u, c->v); // vertex u is removed 610 611 if (bSaveLog == TRUE) writeChange(file, c); 612 613 cost = h->a[h->p[e]].key; 614 615 /* 616 printf( "Edge collapse e%d(%d,%d) %f MIN d %d m %d\n", 617 c->e, 618 c->u, 619 c->v, 620 cost, 621 c->numDel, 622 c->numMod); 623 */ 624 625 mesh->edges[e].enable = FALSE; 626 bh_delete(h, e); 627 628 updateHWAcceleration(c); 629 630 // Get projected areas after the edge collapse 631 getProjectedAreas(histogram, numCameras); 632 633 computeCameraIs(histogram, numCameras, initialIs); 634 635 updateEdgeAdj(mesh, c); 636 637 modifyEdges(mesh, c); 638 639 // Update the heap according to the edge collapse 640 h = updateHeap(h, mesh, c); 641 642 mUPB((float)c->numDel * percent); 617 // Check whether edge collapse is a valid change 618 if (c->numDel > 0) { 619 // Apply the edge collapse 620 doChange(mesh, c); 621 //deleteVertexOfMap(mesh, c->u); 622 623 // Write Simplification sequence. 624 saveSimplificationSequence(c,0); 625 626 //contractTwinVertices(mesh, c->u, c->v); // vertex u is removed 627 628 if (bSaveLog == TRUE) writeChange(file, c); 629 630 cost = h->a[h->p[e]].key; 631 632 /* 633 printf( "Edge collapse e%d(%d,%d) %f MIN d %d m %d\n", 634 c->e, 635 c->u, 636 c->v, 637 cost, 638 c->numDel, 639 c->numMod); 640 */ 641 642 mesh->edges[e].enable = FALSE; 643 bh_delete(h, e); 644 645 updateHWAcceleration(c); 646 647 // Get projected areas after the edge collapse 648 getProjectedAreas(histogram, numCameras); 649 650 computeCameraIs(histogram, numCameras, initialIs); 651 652 updateEdgeAdj(mesh, c); 653 modifyEdges(mesh, c); 654 655 // Update the heap according to the edge collapse 656 h = updateHeap(h, mesh, c); 657 658 if (mUPB) 659 { 660 mUPB((float)c->numDel * percent); 661 } 662 } 663 else 664 { 665 mesh->edges[e].enable = FALSE; 666 bh_delete(h, e); 667 } 643 668 644 669 deleteChange(c); -
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp
r2127 r2194 26 26 geoMeshView->deactiveLodTree(); 27 27 28 BuildLoadTextureSubMeshMenu();28 //BuildLoadTextureSubMeshMenu(); 29 29 30 30 // Repaint the window. … … 1238 1238 break; 1239 1239 1240 // A ñadido 23-12-20051240 // A?adido 23-12-2005 1241 1241 case SELECT_LEAVES: 1242 1242 … … 2160 2160 if (mPercent->value()) 2161 2161 { 2162 // Simplificaci ón por porcentaje2163 if (mMeshReduction->fvalue() <= 100.0 && 2162 // Simplificaci?n por porcentaje 2163 if (mMeshReduction->fvalue() <= 100.0 && 2164 2164 mMeshReduction->fvalue() > 0.0) 2165 2165 { … … 2167 2167 percent = percent / 100.0; 2168 2168 2169 // Simplifica el geomesh -> Par ámetro es un factor LOD [0,1].2169 // Simplifica el geomesh -> Par?metro es un factor LOD [0,1]. 2170 2170 2171 2171 mMeshSimplifier->Simplify(percent); … … 2193 2193 else 2194 2194 { 2195 // Simplificar hasta un n úmero de vértices.2195 // Simplificar hasta un n?mero de v?rtices. 2196 2196 uint32 v = (uint32)mMeshReduction->fvalue(); 2197 2197 2198 // Simplifica el geomesh -> Par ámetro es un factor LOD [0,1].2198 // Simplifica el geomesh -> Par?metro es un factor LOD [0,1]. 2199 2199 mMeshSimplifier->Simplify(v); 2200 2200 … … 2285 2285 secsimpl = mMeshSimplifier->GetSimplificationSequence(); 2286 2286 2287 // Nombre del mesh para guardar la secuencia de simplificaci ón.2287 // Nombre del mesh para guardar la secuencia de simplificaci?n. 2288 2288 secsimpl->putMeshName(nombremesh); 2289 2289 secsimpl->Save(Geometry::Serializer("SimplifSequence.txt",Serializer::WRITE));
Note: See TracChangeset
for help on using the changeset viewer.