Changeset 2127 for GTP/trunk/Lib/Geom/shared/GTGeometry/src
- Timestamp:
- 02/19/07 09:16:59 (18 years ago)
- Location:
- GTP/trunk/Lib/Geom/shared/GTGeometry/src
- Files:
-
- 2 added
- 2 deleted
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsConstructor.cpp
r2079 r2127 289 289 { 290 290 unsigned long int i; 291 unsigned long int j;292 291 unsigned long int t; 293 292 unsigned long int v; … … 301 300 302 301 tipoOrden Orden; 303 tipoOrden *Ord;304 302 bool bEncontrado; 305 303 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshLoader.cpp
r1526 r2127 1 /*======================================================================== ==1 /*======================================================================== 2 2 * (C) 2005 Universitat Jaume I 3 *======================================================================== ==3 *======================================================================== 4 4 * PROYECT: GAME TOOLS 5 *======================================================================== ==*/5 *========================================================================*/ 6 6 /* CONTENT: 7 7 * 8 8 * 9 9 * @file GeoMeshLoader.cpp 10 *======================================================================== ==*/10 *========================================================================*/ 11 11 12 12 #include "GeoMeshLoader.h" … … 18 18 using namespace std; 19 19 20 //------------------------------------------------------------------------- --20 //------------------------------------------------------------------------- 21 21 // Jump a chunk. 22 //------------------------------------------------------------------------- --22 //------------------------------------------------------------------------- 23 23 void GeoMeshLoader::jumpChunk(FILE *f) 24 24 { … … 29 29 } 30 30 31 //------------------------------------------------------------------------- --31 //------------------------------------------------------------------------- 32 32 // Read a chunk. 33 //------------------------------------------------------------------------- --33 //------------------------------------------------------------------------- 34 34 unsigned short GeoMeshLoader::readChunk(FILE *f) 35 35 { … … 42 42 } 43 43 44 //------------------------------------------------------------------------- --44 //------------------------------------------------------------------------- 45 45 // Read geometry vertex element. 46 //------------------------------------------------------------------------- --46 //------------------------------------------------------------------------- 47 47 void GeoMeshLoader::readGeometryVertexElement(FILE *f, Mesh *geoMesh) 48 48 { … … 112 112 } 113 113 114 //------------------------------------------------------------------------- --114 //------------------------------------------------------------------------- 115 115 // Read geometry vertex declaration. 116 //------------------------------------------------------------------------- --116 //------------------------------------------------------------------------- 117 117 void GeoMeshLoader::readGeometryVertexDeclaration(FILE *f, Mesh *geoMesh) 118 118 { … … 154 154 }// End readGeometryVertexDeclaration. 155 155 156 //------------------------------------------------------------------------- --156 //------------------------------------------------------------------------- 157 157 // Read geometry vertex buffer. 158 //--------------------------------------------------------------------------- 159 void GeoMeshLoader::readGeometryVertexBuffer(FILE *f, Mesh *geoMesh, int option) 158 //------------------------------------------------------------------------- 159 void GeoMeshLoader::readGeometryVertexBuffer( FILE *f, 160 Mesh *geoMesh, 161 int option) 160 162 { 161 163 unsigned short bindIndex; … … 287 289 mError = true; 288 290 } 289 290 } 291 292 //--------------------------------------------------------------------------- 291 } 292 293 //------------------------------------------------------------------------- 293 294 // Read Geometry. 294 //------------------------------------------------------------------------- --295 //------------------------------------------------------------------------- 295 296 void GeoMeshLoader::readGeometry(FILE *f, Mesh *geoMesh, int option) 296 297 { … … 379 380 } 380 381 381 //------------------------------------------------------------------------- --382 //------------------------------------------------------------------------- 382 383 // Read a submesh operation. 383 //------------------------------------------------------------------------- --384 //------------------------------------------------------------------------- 384 385 void GeoMeshLoader::readSubMeshOperation( FILE *f, 385 386 Mesh *geoMesh, … … 403 404 } 404 405 405 //------------------------------------------------------------------------- --406 //------------------------------------------------------------------------- 406 407 // Read a submesh. 407 //------------------------------------------------------------------------- --408 //------------------------------------------------------------------------- 408 409 void GeoMeshLoader::readSubMesh(FILE *f, Mesh *geoMesh, int option) 409 410 { … … 563 564 } 564 565 565 //------------------------------------------------------------------------- --566 //------------------------------------------------------------------------- 566 567 // Read a mesh lod information. 567 //------------------------------------------------------------------------- --568 //------------------------------------------------------------------------- 568 569 void GeoMeshLoader::readMeshLodInfo(FILE *f, Mesh *geoMesh) 569 570 { … … 600 601 } 601 602 602 //------------------------------------------------------------------------- --603 //------------------------------------------------------------------------- 603 604 // Read a submesh name table. 604 //------------------------------------------------------------------------- --605 //------------------------------------------------------------------------- 605 606 void GeoMeshLoader::readSubMeshNameTable(FILE *f, Mesh *geoMesh) 606 607 { … … 639 640 } 640 641 641 //------------------------------------------------------------------------- --642 //------------------------------------------------------------------------- 642 643 // Read a mesh file. 643 //------------------------------------------------------------------------- --644 //------------------------------------------------------------------------- 644 645 645 646 #include "GeoLodStripsLibrary.h" … … 869 870 870 871 871 //------------------------------------------------------------------------- --872 //------------------------------------------------------------------------- 872 873 // Allocate memory to the array of strips 873 //------------------------------------------------------------------------- --874 //------------------------------------------------------------------------- 874 875 SubMesh* GeoMeshLoader::BuildStripsGeoSubMesh(SubMesh* geoSubMesh) 875 876 { … … 969 970 } 970 971 971 //------------------------------------------------------------------------- --972 //------------------------------------------------------------------------- 972 973 // Remove degenerate triangles of a submesh given. 973 //------------------------------------------------------------------------- --974 //------------------------------------------------------------------------- 974 975 SubMesh * GeoMeshLoader::removeDegenerateTriangles(SubMesh *geoSubMesh) 975 976 { … … 1074 1075 } 1075 1076 1076 //------------------------------------------------------------------------- --1077 //------------------------------------------------------------------------- 1077 1078 // Loads a mesh. 1078 //------------------------------------------------------------------------- --1079 //------------------------------------------------------------------------- 1079 1080 Mesh* GeoMeshLoader::load(char *nameFileMesh) 1080 1081 { … … 1083 1084 char version[255]; 1084 1085 FILE *pFile; 1085 SubMesh 1086 SubMesh *geosubmesh; 1086 1087 1087 1088 // Debug. … … 1106 1107 1107 1108 geoMesh = NULL; 1109 1108 1110 if (lodstripsdata) 1111 { 1109 1112 delete lodstripsdata; 1110 lodstripsdata=NULL; 1113 } 1114 1115 lodstripsdata = NULL; 1111 1116 1112 1117 if (treesimpseq) 1118 { 1113 1119 delete treesimpseq; 1114 treesimpseq=NULL; 1120 } 1121 1122 treesimpseq = NULL; 1115 1123 1116 1124 // Open the mesh file. … … 1125 1133 geoMesh = new Mesh(); 1126 1134 1127 if (fileExt ==std::string("OBJ"))1135 if (fileExt == std::string("OBJ")) 1128 1136 { 1129 1137 mError = false; … … 1155 1163 1156 1164 cout << version << endl; 1157 1158 /*if (strcmp(version,"[MeshSerializer_v1.30]\n"))1159 {1160 // Debug.1161 cout << "Error: Wrong mesh version."1162 << endl1163 << "Only version 1.3 or older allowed."1164 << endl;1165 1166 // Error.1167 mError = true;1168 }*/1169 1165 1170 1166 while(!feof(pFile)) … … 1240 1236 } 1241 1237 1242 //------------------------------------------------------------------------- --1238 //------------------------------------------------------------------------- 1243 1239 // Sets coords between -1 and 1. 1244 //------------------------------------------------------------------------- --1240 //------------------------------------------------------------------------- 1245 1241 void GeoMeshLoader::normalizeModel(Mesh *geoMesh) 1246 1242 { … … 1390 1386 } 1391 1387 1392 //------------------------------------------------------------------------- --1388 //------------------------------------------------------------------------- 1393 1389 // Get the size in bytes of the file. 1394 //------------------------------------------------------------------------- --1390 //------------------------------------------------------------------------- 1395 1391 size_t GeoMeshLoader::getFileSize() 1396 1392 { … … 1398 1394 } 1399 1395 1400 //------------------------------------------------------------------------- --1396 //------------------------------------------------------------------------- 1401 1397 // Constructor 1402 //------------------------------------------------------------------------- --1398 //------------------------------------------------------------------------- 1403 1399 GeoMeshLoader::GeoMeshLoader() 1404 1400 { … … 1409 1405 } 1410 1406 1411 //------------------------------------------------------------------------- --1407 //------------------------------------------------------------------------- 1412 1408 // Destroyer. 1413 //------------------------------------------------------------------------- --1409 //------------------------------------------------------------------------- 1414 1410 GeoMeshLoader::~GeoMeshLoader() 1415 1411 { … … 1430 1426 } 1431 1427 1432 //------------------------------------------------------------------------- --1428 //------------------------------------------------------------------------- 1433 1429 // Read bones of the submesh. 1434 //------------------------------------------------------------------------- --1430 //------------------------------------------------------------------------- 1435 1431 void GeoMeshLoader::readSubMeshBoneAssignment(FILE *f, 1436 1432 SubMesh *geoSubMesh, … … 1452 1448 } 1453 1449 1454 //------------------------------------------------------------------------- --1450 //------------------------------------------------------------------------- 1455 1451 // Read bones of the main mesh. 1456 //------------------------------------------------------------------------- --1452 //------------------------------------------------------------------------- 1457 1453 void GeoMeshLoader::readMeshBoneAssignment(FILE *f, Mesh *geoMesh, int option) 1458 1454 { … … 1472 1468 } 1473 1469 1474 //------------------------------------------------------------------------- --1470 //------------------------------------------------------------------------- 1475 1471 // Read skeleton link. 1476 //------------------------------------------------------------------------- --1472 //------------------------------------------------------------------------- 1477 1473 void GeoMeshLoader::readSkeletonLink(FILE *f, Mesh *geoMesh, int option) 1478 1474 { … … 1490 1486 } 1491 1487 1492 //------------------------------------------------------------------------- --1488 //------------------------------------------------------------------------- 1493 1489 // Read bounding box settings. 1494 //------------------------------------------------------------------------- --1490 //------------------------------------------------------------------------- 1495 1491 void GeoMeshLoader::readMeshBounds(FILE *f, Mesh *geoMesh, int option) 1496 1492 { -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSaver.cpp
r1526 r2127 1 /*======================================================================== ==1 /*======================================================================== 2 2 * (C) 2005 Universitat Jaume I 3 *======================================================================== ==3 *======================================================================== 4 4 * PROYECT: GAME TOOLS 5 *======================================================================= ===*/5 *=======================================================================*/ 6 6 /* CONTENT: 7 7 * 8 8 * 9 9 * @file GeoMeshSaver.cpp 10 *======================================================================= ===*/10 *=======================================================================*/ 11 11 #include <GeoMeshSaver.h> 12 12 … … 14 14 using namespace std; 15 15 16 //------------------------------------------------------------------------- --16 //------------------------------------------------------------------------- 17 17 // Public: 18 //------------------------------------------------------------------------- --19 20 //------------------------------------------------------------------------- --18 //------------------------------------------------------------------------- 19 20 //------------------------------------------------------------------------- 21 21 // Constructors. 22 //------------------------------------------------------------------------- --22 //------------------------------------------------------------------------- 23 23 GeoMeshSaver::GeoMeshSaver() 24 24 { … … 29 29 } 30 30 31 //------------------------------------------------------------------------- --32 // Destr oyer.33 //------------------------------------------------------------------------- --31 //------------------------------------------------------------------------- 32 // Destructor. 33 //------------------------------------------------------------------------- 34 34 GeoMeshSaver::~GeoMeshSaver() 35 35 { … … 37 37 } 38 38 39 //------------------------------------------------------------------------- --39 //------------------------------------------------------------------------- 40 40 // Saves a Mesh into a file. 41 //------------------------------------------------------------------------- --41 //------------------------------------------------------------------------- 42 42 size_t GeoMeshSaver::save(Mesh *geoMesh, const char *fileNameMesh) 43 43 { … … 147 147 } 148 148 149 //------------------------------------------ 149 //------------------------------------------------------------------------- 150 150 // Private: 151 //------------------------------------------ 152 151 //------------------------------------------------------------------------- 152 153 //------------------------------------------------------------------------- 153 154 // Write the main mesh. 155 //------------------------------------------------------------------------- 154 156 void GeoMeshSaver::writeMesh(Mesh *geoMesh) 155 157 { … … 226 228 }// End write mesh. 227 229 230 //------------------------------------------------------------------------- 228 231 // Write a submesh. 232 //------------------------------------------------------------------------- 229 233 void GeoMeshSaver::writeSubMesh(SubMesh *geoSubMesh) 230 234 { … … 345 349 } 346 350 351 //------------------------------------------------------------------------- 347 352 // Write the submesh operation chunk and data. 353 //------------------------------------------------------------------------- 348 354 void GeoMeshSaver::writeSubMeshOperation(const SubMesh *geoSubMesh) 349 355 { … … 374 380 } 375 381 382 //------------------------------------------------------------------------- 376 383 // Write geometry. 384 //------------------------------------------------------------------------- 377 385 void GeoMeshSaver::writeGeometry(VertexBuffer *vertexBuffer) 378 386 { … … 581 589 } 582 590 591 //------------------------------------------------------------------------- 583 592 // Write Mesh Bounds. 593 //------------------------------------------------------------------------- 584 594 void GeoMeshSaver::writeMeshBounds(Mesh *geoMesh) 585 595 { … … 605 615 } 606 616 617 //------------------------------------------------------------------------- 607 618 // Calculate the mesh size in bytes. 619 //------------------------------------------------------------------------- 608 620 size_t GeoMeshSaver::calcMeshSize(const Mesh *geoMesh) 609 621 { … … 650 662 } 651 663 664 //------------------------------------------------------------------------- 652 665 // Calc the size in bytes for the submesh. 666 //------------------------------------------------------------------------- 653 667 size_t GeoMeshSaver::calcSubMeshSize(const SubMesh *geoSubMesh) 654 668 { … … 677 691 } 678 692 693 //------------------------------------------------------------------------- 679 694 // Calculate the geometry size in bytes. 695 //------------------------------------------------------------------------- 680 696 size_t GeoMeshSaver::calcGeometrySize(const VertexBuffer* vertexBuffer) 681 697 { … … 709 725 } 710 726 727 //------------------------------------------------------------------------- 711 728 // Calculate the skeleton link size in bytes. 729 //------------------------------------------------------------------------- 712 730 size_t GeoMeshSaver::calcSkeletonLinkSize(const Mesh *geoMesh) 713 731 { … … 723 741 } 724 742 743 //------------------------------------------------------------------------- 725 744 // Write the file header. 745 //------------------------------------------------------------------------- 726 746 void GeoMeshSaver::writeFileHeader(void) 727 747 { … … 734 754 } 735 755 756 //------------------------------------------------------------------------- 736 757 // Write a header chunk given. 758 //------------------------------------------------------------------------- 737 759 void GeoMeshSaver::writeChunkHeader(unsigned short id, 738 760 unsigned long size) … … 742 764 } 743 765 766 //------------------------------------------------------------------------- 744 767 // Write integers into the file. 768 //------------------------------------------------------------------------- 745 769 void GeoMeshSaver::writeInts(unsigned long id, 746 770 unsigned long count) … … 749 773 } 750 774 775 //------------------------------------------------------------------------- 751 776 // Write shorts into the file 777 //------------------------------------------------------------------------- 752 778 void GeoMeshSaver::writeShorts(unsigned short id, 753 779 unsigned long count) … … 756 782 } 757 783 784 //------------------------------------------------------------------------- 758 785 // Write float into the file. 786 //------------------------------------------------------------------------- 759 787 void GeoMeshSaver::writeFloats(float id, 760 788 unsigned long count) … … 763 791 } 764 792 793 //------------------------------------------------------------------------- 765 794 // Write a string into the file. 795 //------------------------------------------------------------------------- 766 796 void GeoMeshSaver::writeString(const String &string) 767 797 { … … 769 799 } 770 800 801 //------------------------------------------------------------------------- 771 802 // Write booleans into the file. 803 //------------------------------------------------------------------------- 772 804 void GeoMeshSaver::writeBools( const bool id, 773 805 unsigned long count) … … 776 808 } 777 809 810 //------------------------------------------------------------------------- 811 // Write skeleton filename. 812 //------------------------------------------------------------------------- 778 813 void GeoMeshSaver::writeSkeletonLink(const String& skelName) 779 814 { … … 788 823 } 789 824 825 //------------------------------------------------------------------------- 826 // Write bones assignmets. 827 //------------------------------------------------------------------------- 790 828 void GeoMeshSaver::writeMeshBoneAssignment(const VertexBoneAssignment& assign) 791 829 { … … 802 840 } 803 841 842 //------------------------------------------------------------------------- 843 // Write bones assignmets. 844 //------------------------------------------------------------------------- 804 845 void GeoMeshSaver::writeSubMeshBoneAssignment(const VertexBoneAssignment& assign) 805 846 { … … 816 857 } 817 858 859 //------------------------------------------------------------------------- 818 860 // unnormalize geometry model. 861 //------------------------------------------------------------------------- 819 862 void GeoMeshSaver::unnormalizeModel(Mesh *geoMesh) 820 863 { … … 859 902 continue; 860 903 } 861 904 862 905 // For each index of the strip. 863 906 for (size_t i = 0; i < vertex_buffer->mVertexCount; i++) -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimplifier.cpp
r2103 r2127 158 158 mGeoMesh = m_qslim->GetMesh(); 159 159 160 // Debug.161 cout << "Number of bone assignaments: "162 << mGeoMesh->mBones.size()163 << endl;164 165 // if the initial mesh had shared vertex,166 // convert the mesh to shared vertex167 //Mesh *sharedMesh = mGeoMesh->toSharedVertex();168 //delete mGeoMesh;169 //mGeoMesh = sharedMesh;170 171 // Sort bones.172 //sortBones();173 174 160 delete m_qslim; 175 161 } … … 191 177 mGeoMesh = m_qslim->GetMesh(); 192 178 193 // if the initial mesh had shared vertex,194 // convert the mesh to shared vertex195 //Mesh *sharedMesh = mGeoMesh->toSharedVertex();196 //delete mGeoMesh;197 //mGeoMesh = sharedMesh;198 199 // Sort bones.200 //sortBones();201 202 179 delete m_qslim; 203 180 } … … 453 430 vmi_mesh->vertices[i].y = vertex_buffer->mPosition[i].y; 454 431 vmi_mesh->vertices[i].z = vertex_buffer->mPosition[i].z; 455 432 456 433 vmi_mesh->vertices[i].numTriangles = 0; 457 434 vmi_mesh->vertices[i].triangles = NULL; 435 vmi_mesh->vertices[i].numEdges = 0; 436 vmi_mesh->vertices[i].edges = NULL; 458 437 vmi_mesh->vertices[i].enable = GL_TRUE; 459 438 vmi_mesh->vertices[i].movable = GL_TRUE; … … 503 482 504 483 // Reallocate memory for the new adjacent triangle. 505 vmi_mesh->vertices[v1].triangles = ( GLuint *)realloc(vmi_mesh->vertices[v1].triangles, (vmi_mesh->vertices[v1].numTriangles + 1) * sizeof(GLuint));484 vmi_mesh->vertices[v1].triangles = (int *)realloc(vmi_mesh->vertices[v1].triangles, (vmi_mesh->vertices[v1].numTriangles + 1) * sizeof(int)); 506 485 507 486 VMI::addItem( (int *)vmi_mesh->vertices[v1].triangles, … … 548 527 vmi_mesh->edges[n].u = v1; 549 528 vmi_mesh->edges[n].v = v2; 550 vmi_mesh->edges[n].triangles = NULL;551 vmi_mesh->edges[n].numTriangles = 0;552 529 vmi_mesh->edges[n].enable = GL_TRUE; 553 530 554 // Reallocate memory for the new adjacent triangle555 vmi_mesh->edges[n].triangles = (GLuint *)realloc(vmi_mesh->edges[n].triangles, (vmi_mesh->edges[n].numTriangles + 1) * sizeof(GLuint));556 557 // Adding triangle i adjacent to edge n558 VMI::addItem( (int *)vmi_mesh->edges[n].triangles,559 (int *)&vmi_mesh->edges[n].numTriangles,560 i);561 562 // Adding edge n adjacent to triangle i563 VMI::addItem((int *)vmi_mesh->triangles[i].edges, (int *)&t, n);564 531 n++; 565 }566 else567 {568 // Reallocate memory for the new adjacent triangle.569 vmi_mesh->edges[e].triangles = (GLuint *)realloc(vmi_mesh->edges[e].triangles, (vmi_mesh->edges[e].numTriangles + 1) * sizeof(GLuint));570 571 // Adding triangle i adjacent to edge e572 VMI::addItem( (int *)vmi_mesh->edges[e].triangles,573 (int *)&vmi_mesh->edges[e].numTriangles,574 i);575 576 // Adding edge e adjacent to triangle i577 VMI::addItem((int *)vmi_mesh->triangles[i].edges, (int *)&t, e);578 532 } 579 533 … … 582 536 vmi_mesh->edges[n].u = v2; 583 537 vmi_mesh->edges[n].v = v3; 584 vmi_mesh->edges[n].triangles = NULL;585 vmi_mesh->edges[n].numTriangles = 0;586 538 vmi_mesh->edges[n].enable = GL_TRUE; 587 539 588 // Reallocate memory for the new adjacent triangle589 vmi_mesh->edges[n].triangles = (GLuint *)realloc(vmi_mesh->edges[n].triangles, (vmi_mesh->edges[n].numTriangles + 1) * sizeof(GLuint));590 591 // Adding triangle i adjacent to edge n592 VMI::addItem((int *)vmi_mesh->edges[n].triangles, (int *)&vmi_mesh->edges[n].numTriangles, i);593 vmi_mesh->edges[n].triangles = NULL;594 vmi_mesh->edges[n].numTriangles = 0;595 596 // Adding edge n adjacent to triangle i597 VMI::addItem((int *)vmi_mesh->triangles[i].edges, (int *)&t, n);598 540 n++; 599 }600 else601 {602 // Reallocate memory for the new adjacent triangle603 vmi_mesh->edges[e].triangles = (GLuint *)realloc(vmi_mesh->edges[e].triangles, (vmi_mesh->edges[e].numTriangles + 1) * sizeof(GLuint));604 605 // Adding triangle i adjacent to edge e606 VMI::addItem( (int *)vmi_mesh->edges[e].triangles,607 (int *)&vmi_mesh->edges[e].numTriangles,608 i);609 610 // Adding edge e adjacent to triangle i611 VMI::addItem((int *)vmi_mesh->triangles[i].edges, (int *)&t, e);612 541 } 613 542 … … 616 545 vmi_mesh->edges[n].u = v3; 617 546 vmi_mesh->edges[n].v = v1; 618 vmi_mesh->edges[n].triangles = NULL;619 vmi_mesh->edges[n].numTriangles = 0;620 547 vmi_mesh->edges[n].enable = GL_TRUE; 621 548 622 // Reallocate memory for the new adjacent triangle.623 vmi_mesh->edges[n].triangles = (GLuint *)realloc(vmi_mesh->edges[n].triangles, (vmi_mesh->edges[n].numTriangles + 1) * sizeof(GLuint));624 625 // Adding triangle i adjacent to edge n626 VMI::addItem( (int *)vmi_mesh->edges[n].triangles,627 (int *)&vmi_mesh->edges[n].numTriangles,628 i);629 630 // Adding edge n adjacent to triangle i631 VMI::addItem((int *)vmi_mesh->triangles[i].edges, (int *)&t, n);632 549 n++; 633 }634 else635 {636 // Reallocate memory for the new adjacent triangle637 vmi_mesh->edges[e].triangles = (GLuint *)realloc(vmi_mesh->edges[e].triangles, (vmi_mesh->edges[e].numTriangles + 1) * sizeof(GLuint));638 639 // Adding triangle i adjacent to edge e640 VMI::addItem((int *)vmi_mesh->edges[e].triangles, (int *)&vmi_mesh->edges[e].numTriangles, i);641 642 // Adding edge e adjacent to triangle i643 VMI::addItem((int *)vmi_mesh->triangles[i].edges, (int *)&t, e);644 550 } 645 551 } … … 647 553 printf("Ok\n"); 648 554 vmi_mesh->numEdges = n; 555 556 for (i=0; i<vmi_mesh->numEdges; i++) { 557 v1 = vmi_mesh->edges[i].u; 558 v2 = vmi_mesh->edges[i].v; 559 560 vmi_mesh->vertices[v1].edges = 561 (int *)realloc(vmi_mesh->vertices[v1].edges, (vmi_mesh->vertices[v1].numEdges + 1) * sizeof(int)); 562 // 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)); 567 // Adding edge i adjacent to vertex v2 568 VMI::addItem(vmi_mesh->vertices[v2].edges, &vmi_mesh->vertices[v2].numEdges, i); 569 } 649 570 650 571 // Creates vertex multimap. … … 1133 1054 1134 1055 //------------------------------------------------------------------------- 1135 // Modify the joined vertices sequento to an split.1136 //-------------------------------------------------------------------------1137 MeshSimplificationSequence *1138 TextureConserver::WriteRealSimpSeq(MeshSimplificationSequence *simpseq)1139 {1140 bool edge_found;1141 1142 size_t v0;1143 size_t v1;1144 size_t vertex_count;1145 size_t i,j;1146 1147 VertexBuffer *mVB;1148 GeoVertex new_vertex;1149 1150 multimap<int, int>::iterator lb0;1151 multimap<int, int>::iterator ub0;1152 multimap<int, int>::iterator lb1;1153 multimap<int, int>::iterator ub1;1154 multimap<int, int>::iterator it0;1155 1156 MeshSimplificationSequence *real_seq;1157 MeshSimplificationSequence::Step current_step;1158 1159 // Initialize vertex count.1160 vertex_count = mGeoMesh->mVertexBuffer->mVertexCount;1161 1162 // Creates new simplification sequence.1163 real_seq = new MeshSimplificationSequence();1164 1165 // For each simplification step.1166 for (i = 0; i < simpseq->mSteps.size(); i++)1167 {1168 lb0 = mVertices.lower_bound(simpseq->mSteps[i].mV0);1169 ub0 = mVertices.upper_bound(simpseq->mSteps[i].mV0);1170 lb1 = mVertices.lower_bound(simpseq->mSteps[i].mV1);1171 ub1 = mVertices.upper_bound(simpseq->mSteps[i].mV1);1172 1173 // Removed vertex.1174 while (lb1 != ub1)1175 {1176 // Real index.1177 v1 = (*lb1).second;1178 1179 // Begin of iteration v0.1180 it0 = lb0;1181 1182 edge_found = false;1183 1184 // Remaining vertex.1185 while (it0 != ub0)1186 {1187 // Real index.1188 v0 = (*it0).second;1189 1190 // If edge exists.1191 if (mEdges->exists(v0,v1))1192 {1193 mEdges->contract(v1,v0);1194 1195 // Simplification sequence.1196 current_step.mV0 = v0;1197 current_step.mV1 = v1;1198 1199 real_seq->mSteps.push_back(current_step);1200 1201 edge_found = true;1202 }1203 1204 it0++;1205 }1206 1207 // If not found a valid edge.1208 if (!edge_found)1209 {1210 // Id new vertex.1211 new_vertex.id = vertex_count;1212 new_vertex.bonefrom = v0;1213 1214 // Simplification sequence.1215 current_step.mV0 = new_vertex.id;1216 current_step.mV1 = v1;1217 1218 real_seq->mSteps.push_back(current_step);1219 1220 // Contracts lonely vertex.1221 mEdges->contract(v1,new_vertex.id);1222 1223 // New vertex adquires position of v0.1224 new_vertex.position.x = mGeoMesh->mVertexBuffer->mPosition[v0].x;1225 new_vertex.position.y = mGeoMesh->mVertexBuffer->mPosition[v0].y;1226 new_vertex.position.z = mGeoMesh->mVertexBuffer->mPosition[v0].z;1227 1228 // New vertex adquires normal of lonely one.1229 new_vertex.normal.x = mGeoMesh->mVertexBuffer->mNormal[v1].x;1230 new_vertex.normal.y = mGeoMesh->mVertexBuffer->mNormal[v1].y;1231 new_vertex.normal.z = mGeoMesh->mVertexBuffer->mNormal[v1].z;1232 1233 // New vertex adquires the texture cood of the lonely one.1234 new_vertex.texcoord.x = mGeoMesh->mVertexBuffer->mTexCoords[v1].x;1235 new_vertex.texcoord.y = mGeoMesh->mVertexBuffer->mTexCoords[v1].y;1236 1237 // New vertex stored.1238 real_seq->mNewVertices.push_back(new_vertex);1239 1240 // New vertex added.1241 vertex_count++;1242 }1243 1244 lb1++;1245 }1246 }1247 1248 // Assigns new simplification sequence.1249 delete simpseq;1250 1251 return real_seq;1252 /*1253 // New vertex buffer to add new vertices.1254 mVB = new VertexBuffer();1255 1256 mVB->mPosition = new Vector3[vertex_count];1257 mVB->mNormal = new Vector3[vertex_count];1258 mVB->mTexCoords = new Vector2[vertex_count];1259 1260 mVB->mVertexInfo = mGeoMesh->mVertexBuffer->mVertexInfo;1261 1262 // Copy original vertices.1263 for (i = 0; i < mGeoMesh->mVertexBuffer->mVertexCount; i++)1264 {1265 mVB->mPosition[i].x = mGeoMesh->mVertexBuffer->mPosition[i].x;1266 mVB->mPosition[i].y = mGeoMesh->mVertexBuffer->mPosition[i].y;1267 mVB->mPosition[i].z = mGeoMesh->mVertexBuffer->mPosition[i].z;1268 1269 mVB->mNormal[i].x = mGeoMesh->mVertexBuffer->mNormal[i].x;1270 mVB->mNormal[i].y = mGeoMesh->mVertexBuffer->mNormal[i].y;1271 mVB->mNormal[i].z = mGeoMesh->mVertexBuffer->mNormal[i].z;1272 1273 mVB->mTexCoords[i].x = mGeoMesh->mVertexBuffer->mTexCoords[i].x;1274 mVB->mTexCoords[i].y = mGeoMesh->mVertexBuffer->mTexCoords[i].y;1275 }1276 1277 // Add new vertices.1278 j = mGeoMesh->mVertexBuffer->mVertexCount;1279 1280 for (i = 0; i < new_vertices.size(); i++)1281 {1282 mVB->mPosition[j].x = new_vertices[i].position.x;1283 mVB->mPosition[j].y = new_vertices[i].position.y;1284 mVB->mPosition[j].z = new_vertices[i].position.z;1285 1286 mVB->mNormal[j].x = new_vertices[i].normal.x;1287 mVB->mNormal[j].y = new_vertices[i].normal.y;1288 mVB->mNormal[j].z = new_vertices[i].normal.z;1289 1290 mVB->mTexCoords[j].x = new_vertices[i].texcoord.x;1291 mVB->mTexCoords[j].y = new_vertices[i].texcoord.y;1292 }1293 1294 // Free memory.1295 delete []mGeoMesh->mVertexBuffer;1296 1297 // Reassigns main vertex buffer with new vertices.1298 mGeoMesh->mVertexBuffer = mVB;1299 1300 // Reassign submesh vertex buffers.1301 for (i = 0; i < mGeoMesh->mSubMeshCount; i++)1302 {1303 mGeoMesh->mSubMesh[i].mVertexBuffer = mVB;1304 }1305 */1306 }1307 1308 //-------------------------------------------------------------------------1309 1056 // Return mesh that may have repeated vertices for texture aparence. 1310 1057 //------------------------------------------------------------------------- -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/camera.h
r2090 r2127 18 18 } Camera; 19 19 20 extern Camera *loadCameras(GLdouble radius, char* filename, GLuint *numCameras);21 extern void saveCameras(char* filename, Camera *cameras, GLuint numCameras);20 extern Camera *loadCameras(GLdouble radius, char* filename, int *numCameras); 21 extern void saveCameras(char* filename, Camera *cameras, int numCameras); 22 22 extern void copyToCameras(Camera *cameras, int numVertices, GLdouble vertices[][3]); 23 extern void setCameraWeights(Camera *cameras, GLuint numCameras, GLdouble *weights);24 extern Camera *setCameras(GLdouble radius, GLuint type, GLuint *numCameras);25 extern void printCameras(Camera *cameras, GLuint numCameras);23 extern void setCameraWeights(Camera *cameras, int numCameras, GLdouble *weights); 24 extern Camera *setCameras(GLdouble radius, int type, int *numCameras); 25 extern void printCameras(Camera *cameras, int numCameras); 26 26 27 27 extern void drawSphere(Camera *cameras, GLdouble radius, int slices, int stacks); -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/change.h
r2090 r2127 68 68 extern void modifyTriangle(Triangle *t, int c, int p); 69 69 extern int isATriangleToModify(Triangle *t, int c); 70 extern Triangle *getTrianglesToModify(Mesh *mesh, Change *c, GLuint *numMod);70 extern Triangle *getTrianglesToModify(Mesh *mesh, Change *c, int *numMod); 71 71 extern int isATriangleToDelete(Triangle *t, int c, int p); 72 extern Triangle *getTrianglesToDelete(Mesh *mesh, Change *c, GLuint *numDel);72 extern Triangle *getTrianglesToDelete(Mesh *mesh, Change *c, int *numDel); 73 73 74 74 extern void modifyTriangles(Mesh *mesh, Change *c); … … 85 85 86 86 extern void modifyEdges(Mesh *mesh, Change *c); 87 extern void deleteEdges(Mesh *mesh, Change *c); 87 extern int find(int *edges, int num, int v_); 88 extern void updateEdgeAdj(Mesh *mesh, Change *c) ; 88 89 89 90 // Save simplification sequence in Geometry Game Tools format. … … 92 93 //extern std::map<int, INTVECTOR> inversemap; 93 94 extern void swap(int *i, int *j); 94 extern int hasEdge(Triangle *t, int e); 95 extern void getEdges(Triangle *t, Change *c, int *d, int *a); 95 96 96 } 97 97 #endif -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/color.h
r2090 r2127 14 14 } Color; 15 15 16 extern Color *initColors( GLuint numColors);17 extern void fillAllColors(Color *colors, GLuint numColors, GLuint begin, GLuint end, GLubyte color);18 extern void setColors(Color *colors, GLuint numPasses, GLuint begin, GLuint end);19 extern void setColors2(Color *colors, GLuint numColors, GLuint begin, GLuint end);20 extern void setColors3(Color *colors, GLuint numColors, GLubyte color);21 extern void setColors4(Color *colors, GLuint numColors);22 extern void viewColors(Color *colors, GLuint numColors);16 extern Color *initColors(int numColors); 17 extern void fillAllColors(Color *colors, int numColors, int begin, int end, GLubyte color); 18 extern void setColors(Color *colors, int numPasses, int begin, int end); 19 extern void setColors2(Color *colors, int numColors, int begin, int end); 20 extern void setColors3(Color *colors, int numColors, GLubyte color); 21 extern void setColors4(Color *colors, int numColors); 22 extern void viewColors(Color *colors, int numColors); 23 23 24 24 } -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/global.h
r2090 r2127 60 60 //#define SALIENCY 61 61 62 #define CHECK_LOCAL_INVERSION 63 62 64 // Extension added into the filename 63 65 #ifdef KL // Kullback-Leibler … … 73 75 #define EXT "VCS" 74 76 #endif 75 76 //#define USE_EDGE_ADJACENCY77 77 78 78 #define CHECK_OPENGL_ERROR( cmd ) \ … … 109 109 110 110 extern Camera *cameras; 111 extern GLuint numCameras;111 extern int numCameras; 112 112 113 113 extern Color *colors; 114 114 115 extern GLuint **histogram,116 115 extern int **histogram; 116 extern GLuint *queries; 117 117 118 118 extern Mesh *mesh; … … 122 122 extern GLdouble radius; 123 123 extern GLdouble fov; 124 extern GLuint numDemandedTriangles,124 extern int numDemandedTriangles, 125 125 cameraType; 126 126 extern GLboolean bBeQuiet, … … 138 138 extern void init(void); 139 139 140 extern void renderScene(GLuint **histogram, GLuint numCameras); 141 extern void renderSceneWin(GLuint **histogram, GLuint numCameras, Change *c); 140 extern void resetProjectedAreas(int **histogram, int numCameras); 141 extern void getProjectedAreas(int **histogram, int numCameras); 142 extern void getProjectedAreasWin(int **histogram, int numCameras, Change *c); 142 143 143 144 extern void renderGeometry(void); … … 150 151 151 152 extern void applyHWAcceleration(void); 153 extern void updateHWAcceleration(Change *c); 152 154 extern void setOrthographicProjection(void); 153 155 extern void resetPerspectiveProjection(void); -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/histogram.h
r2090 r2127 11 11 { 12 12 13 extern void getSubHistogram( GLuint subHistoGram[][4]);14 extern void copySubHistogram(Color *colors, GLuint *histogram, GLuint begin, GLuint end, GLuint subHistoGram[][4]);15 extern void printHistogram( GLuint histoGram[][4]);16 extern void plotHistogram( GLuint histoGram[][4]);13 extern void getSubHistogram(int subHistoGram[][4]); 14 extern void copySubHistogram(Color *colors, int *histogram, int begin, int end, int subHistoGram[][4]); 15 extern void printHistogram(int histoGram[][4]); 16 extern void plotHistogram(int histoGram[][4]); 17 17 18 extern GLuint **initHistogram(GLuint numTriangles, GLuint numCameras);19 extern void deleteHistogram( GLuint **histogram, GLuint numCameras);20 extern void printFullHistogram( GLuint **histogram, GLuint numCameras, GLuint numTriangles);21 extern void getSWHistogram( GLuint *histogram, GLubyte *pixels);22 extern void getSWHistogramWin( GLuint *histogram, GLubyte *pixels, GLfloat min[3], GLfloat max[3], Change *c);23 extern void getSWHistoByOcclusionQuery(Mesh *mesh, Color *colors, GLuint *histogram);18 extern int **initHistogram(int numTriangles, int numCameras); 19 extern void deleteHistogram(int **histogram, int numCameras); 20 extern void printFullHistogram(int **histogram, int numCameras, int numTriangles); 21 extern void getSWHistogram(int *histogram, GLubyte *pixels); 22 extern void getSWHistogramWin(int *histogram, GLubyte *pixels, GLfloat min[3], GLfloat max[3], Change *c); 23 extern void getSWHistoByOcclusionQuery(Mesh *mesh, Color *colors, int *histogram); 24 24 25 extern void resetSWHistogram( GLuint *histogram, GLuint numTriangles);25 extern void resetSWHistogram(int *histogram, int numTriangles); 26 26 extern void getBoundingBox(Change *c, GLfloat min[3], GLfloat max[3]); 27 27 extern void getWindow(GLfloat min[3], GLfloat max[3], int minw[2], int maxw[2]); -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/mesh.h
r2090 r2127 7 7 8 8 typedef struct _Vertex { 9 GLfloat x, y, z; // Vertex coordinates 10 GLuint numTriangles; // Number of triangles 11 GLuint *triangles; // List of triangles 9 float x, y, z; // Vertex coordinates 10 int numTriangles; // Number of triangles 11 int *triangles; // List of triangles 12 int numEdges; 13 int *edges; 12 14 int enable; 13 15 int movable; // If vertex is part of a border. … … 15 17 16 18 typedef struct _Edge { 17 GLuint u, v; // Edge vertices 18 GLuint *triangles; // Edge triangles 19 GLuint numTriangles; // Number of triangles 19 int u, v; // Edge vertices 20 20 int enable; 21 21 } Edge; 22 22 23 23 typedef struct _Triangle { 24 GLuint id; // Triangle id 25 GLuint group; // Triangle group 26 GLuint submesh; // Triangle submesh 27 GLuint indices[3]; // Triangle vertices 28 GLuint edges[3]; // Triangle edges 29 GLfloat normal[3]; // Triangle normal 30 GLdouble area; // Triangle area 31 GLdouble saliency; // Triangle saliency 24 int id; // Triangle id 25 int group; // Triangle group 26 int submesh; // Triangle submesh 27 int indices[3]; // Triangle vertices 28 float normal[3]; // Triangle normal 29 double area; // Triangle area 30 double saliency; // Triangle saliency 32 31 int enable; 33 32 } Triangle; … … 35 34 typedef struct _Mesh { 36 35 Vertex *vertices; // Mesh vertices 37 GLuint numVertices; // Number of vertices38 GLuint currentNumVertices; // Current number of vertices36 int numVertices; // Number of vertices 37 int currentNumVertices; // Current number of vertices 39 38 Edge *edges; // Mesh edges 40 GLuint numEdges; // Number of edges39 int numEdges; // Number of edges 41 40 Triangle *triangles; // Mesh triangles 42 GLuint numTriangles; // Number of triangles43 GLuint currentNumTriangles; // Current number of triangles41 int numTriangles; // Number of triangles 42 int currentNumTriangles; // Current number of triangles 44 43 } Mesh; 45 44 46 45 extern GLdouble computeTriangleArea(Vertex *vertices, Triangle *t); 46 extern double computeEdgeLength(Vertex *vertices, int u, int v); 47 47 extern void computeTriangleNormal(Vertex *vertices, Triangle *t); 48 extern double computeTriangleVolume(Vertex *vertices, Triangle *t); 48 49 49 50 extern Vertex *addVertex(Vertex *list, int *n, float x, float y, float z, int *pos); 50 extern int findEdge(Edge *e, GLuint num, GLuint _u, GLuint _v);51 extern int findEdge(Edge *e, int num, int _u, int _v); 51 52 extern Edge *addEdge(Edge *list, int *n, int u, int v, int *pos); 52 extern GLboolean findVertex( GLfloat *vertices, GLuint num, GLfloat x, GLfloat y, GLfloat z, int *pos);53 extern GLboolean findVertex(float *vertices, int num, float x, float y, float z, int *pos); 53 54 54 55 extern Mesh *initMesh(GLMmodel* pmodel); … … 56 57 extern void printMesh(Mesh *mesh); 57 58 extern void saveModel(char *filename, GLMmodel* pmodel, Mesh *mesh); 58 extern void updateModel(GLMmodel* pmodel, Mesh *mesh, GLuint numVertices, GLuint numTriangles);59 extern void updateModel(GLMmodel* pmodel, Mesh *mesh, int numVertices, int numTriangles); 59 60 60 61 extern int *trianglesAdjToEdge(Mesh *mesh, int e, int *n); 61 62 extern int *verticesAdjToVertex(Mesh *mesh, int v, int *n); 62 extern int *edgesAdjToVertex(Mesh *mesh, int v, int *n);63 63 extern int *edgesAdjToVertices(Mesh *mesh, int *vertices, int numVertices, int *n); 64 64 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/metrics.h
r2090 r2127 8 8 namespace VMI 9 9 { 10 extern GLdouble computeMI(Mesh *mesh, GLuint **histogram, GLuint numCameras, GLuint cam);11 extern GLdouble decMI(GLdouble I, GLuint **histogram, GLuint numCameras, GLuint cam, Change *c);12 extern GLdouble incMI(GLdouble I, GLuint **histogram, GLuint numCameras, GLuint cam, Change *c);10 extern GLdouble computeMI(Mesh *mesh, int **histogram, int numCameras, int cam); 11 extern GLdouble decMI(GLdouble I, int **histogram, int numCameras, int cam, Change *c); 12 extern GLdouble incMI(GLdouble I, int **histogram, int numCameras, int cam, Change *c); 13 13 14 extern GLdouble computeHE(Mesh *mesh, GLuint *histogram);15 extern GLdouble computeKL(Mesh *mesh, GLuint *histogram);16 extern GLdouble computeCS(Mesh *mesh, GLuint *histogram);14 extern GLdouble computeHE(Mesh *mesh, int *histogram); 15 extern GLdouble computeKL(Mesh *mesh, int *histogram); 16 extern GLdouble computeCS(Mesh *mesh, int *histogram); 17 17 18 extern GLdouble computeMeanProjArea( GLuint **histogram, GLuint numCameras, int t);19 extern GLdouble computeJS( GLuint **histogram, GLuint numCameras, GLuint j, GLuint k);20 extern GLdouble computeEntropy( GLuint **histogram, GLuint numCameras, GLuint k);21 extern GLdouble computeMixedEntropy(GLdouble *mixed, GLuint numCameras);22 extern GLdouble computeMeanProjAreaNoBG( GLuint **histogram, GLuint numCameras, int t);18 extern GLdouble computeMeanProjArea(int **histogram, int numCameras, int t); 19 extern GLdouble computeJS(int **histogram, int numCameras, int j, int k); 20 extern GLdouble computeEntropy(int **histogram, int numCameras, int k); 21 extern GLdouble computeMixedEntropy(GLdouble *mixed, int numCameras); 22 extern GLdouble computeMeanProjAreaNoBG(int **histogram, int numCameras, int t); 23 23 24 extern void getProjectedAreas(GLuint **histogram, GLuint numCameras); 25 extern void getProjectedAreasWin(GLuint **histogram, GLuint numCameras, Change *c); 26 extern void resetProjectedAreas(GLuint **histogram, GLuint numCameras); 27 28 extern GLdouble *initIs(GLuint numCameras); 29 extern void computeCameraIs(GLuint **histogram, GLuint numCameras, GLdouble *mis); 30 extern void printIs(GLdouble *mis, GLuint numCameras); 24 extern GLdouble *initIs(int numCameras); 25 extern void computeCameraIs(int **histogram, int numCameras, GLdouble *mis); 26 extern void printIs(GLdouble *mis, int numCameras); 31 27 } 32 28 #endif -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/saliency.h
r2090 r2127 13 13 extern double percentile; 14 14 15 extern void computeSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras);16 extern void updateTriangleSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras, int v);15 extern void computeSaliency(Mesh *mesh, int **histogram, int numCameras); 16 extern void updateTriangleSaliency(Mesh *mesh, int **histogram, int numCameras, int v); 17 17 18 extern double computeTriangleSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras, GLuint k);18 extern double computeTriangleSaliency(Mesh *mesh, int **histogram, int numCameras, int k); 19 19 20 20 extern double computeEdgeSaliency(Mesh *mesh, Change *c, double p); -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/simplify.h
r2090 r2127 19 19 extern bheap_t *updateHeap(bheap_t *h, Mesh *mesh, Change *c); 20 20 21 extern void simplifyModel(Mesh *mesh, GLuint numDemandedTri);21 extern void simplifyModel(Mesh *mesh, int numDemandedTri); 22 22 23 23 24 24 extern void bh_mydump(Mesh *mesh, bheap_t *h); 25 extern GLdouble computeEdgeLength(Vertex *vertices, int u, int v);26 25 27 26 extern void chooseBestEndPoints(Mesh *mesh, int e); -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/vmi_simplifier.h
r983 r2127 13 13 #include "saliency.h" 14 14 #include "simplify.h" 15 #include " interleave.h"15 #include "buffers.h" 16 16 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/camera.cpp
r2090 r2127 14 14 //#define DRAW_DEBUG // just for debugging not necessary 15 15 16 Camera *VMI::loadCameras(GLdouble radius, char* filename, GLuint *numCameras) {16 Camera *VMI::loadCameras(GLdouble radius, char* filename, int *numCameras) { 17 17 FILE *fp; 18 18 Camera *cameras; 19 GLuint num, i;19 int num, i; 20 20 GLfloat eyeX, eyeY, eyeZ, 21 21 centerX, centerY, centerZ, … … 118 118 } 119 119 120 void VMI::saveCameras(char* filename, Camera *cameras, GLuint numCameras) {120 void VMI::saveCameras(char* filename, Camera *cameras, int numCameras) { 121 121 FILE *fp; 122 GLuint i;122 int i; 123 123 124 124 if((fp= fopen(filename, "wt"))== NULL) { … … 170 170 } 171 171 172 Camera *VMI::setCameras(GLdouble radius, GLuint type, GLuint *numCameras) {172 Camera *VMI::setCameras(GLdouble radius, int type, int *numCameras) { 173 173 Camera *cameras = NULL; 174 174 … … 221 221 } 222 222 223 void VMI::setCameraWeights(Camera *cameras, GLuint numCameras, GLdouble *weights) {224 GLuint i;223 void VMI::setCameraWeights(Camera *cameras, int numCameras, GLdouble *weights) { 224 int i; 225 225 226 226 for (i = 0; i<numCameras; i++) { … … 229 229 } 230 230 231 void VMI::printCameras(Camera *cameras, GLuint numCameras) {232 GLuint i;231 void VMI::printCameras(Camera *cameras, int numCameras) { 232 int i; 233 233 234 234 printf("\n"); -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/change.cpp
r2090 r2127 157 157 if (c->numMod > 0) { 158 158 mesh->vertices[c->v].triangles = 159 ( GLuint *)realloc(mesh->vertices[c->v].triangles,160 (mesh->vertices[c->v].numTriangles + mesh->vertices[c->u].numTriangles) * sizeof( GLuint));159 (int *)realloc(mesh->vertices[c->v].triangles, 160 (mesh->vertices[c->v].numTriangles + mesh->vertices[c->u].numTriangles) * sizeof(int)); 161 161 } 162 162 … … 193 193 } 194 194 195 int VMI::hasEdge(Triangle *t, int e) {196 int e0 = t->edges[0],197 e1 = t->edges[1],198 e2 = t->edges[2];199 200 if ((e == e0) || (e == e1) || (e == e2)) return TRUE;201 202 return FALSE;203 }204 205 void VMI::getEdges(Triangle *t, Change *c, int *l, int *r) {206 207 // Default edges208 *l = -1;209 *r = -1;210 211 // Set edge l and r212 if ((int)t->edges[0] == c->e) {213 *l = t->edges[1];214 *r = t->edges[2];215 if ((int)mesh->edges[*l].u == c->v || (int)mesh->edges[*l].v == c->v)216 swap(l, r);217 } else if ((int)t->edges[1] == c->e) {218 *l = t->edges[0];219 *r = t->edges[2];220 if ((int)mesh->edges[*l].u == c->v || (int)mesh->edges[*l].v == c->v)221 swap(l, r);222 } else if ((int)t->edges[2] == c->e) {223 *l = t->edges[0];224 *r = t->edges[1];225 if ((int)mesh->edges[*l].u == c->v || (int)mesh->edges[*l].v == c->v)226 swap(l, r);227 }228 }229 230 195 void VMI::swap(int *i, int *j) { 231 196 int t; … … 238 203 void VMI::deleteTriangles(Mesh *mesh, Change *c) 239 204 { 240 int i, j, t, v; 241 #ifdef USE_EDGE_ADJACENCY 242 int t1, l, r; 243 #endif 205 int i, j, t, v; 244 206 245 207 for (i=0; i<c->numDel; i++) { … … 255 217 } 256 218 257 #ifdef USE_EDGE_ADJACENCY258 // Update triangle edge adjancency259 // The modified triangles have to be calculated before260 // Set edge l and r261 getEdges(&c->deleted[i], c, &l, &r);262 //printf("e%d(%d,%d): l:%d r:%d\n", c->e, c->u, c->v, l, r);263 // Find triangle that contains edge l264 for (j=0; j<c->numMod; j++)265 if (hasEdge(&c->modified[j], l)) {266 // Change edge l by r in the Mesh267 t1 = c->modified[j].id;268 //printf("t:%d %d %d %d\n", t1, mesh->triangles[t1].edges[0], mesh->triangles[t1].edges[1] ,mesh->triangles[t1].edges[2]);269 if (mesh->triangles[t1].edges[0] == (GLuint)l) mesh->triangles[t1].edges[0] = r;270 if (mesh->triangles[t1].edges[1] == (GLuint)l) mesh->triangles[t1].edges[1] = r;271 if (mesh->triangles[t1].edges[2] == (GLuint)l) mesh->triangles[t1].edges[2] = r;272 //printf("t:%d %d %d %d\n", t1, mesh->triangles[t1].edges[0], mesh->triangles[t1].edges[1] ,mesh->triangles[t1].edges[2]);273 break;274 }275 276 // Delete edge l277 if (l != -1) mesh->edges[l].enable = FALSE;278 #endif279 219 mesh->triangles[t].enable = FALSE; 280 220 mesh->currentNumTriangles--; … … 301 241 addItem((int *)mesh->vertices[v].triangles,(int *)&mesh->vertices[v].numTriangles,t); 302 242 } 303 #ifdef USE_EDGE_ADJACENCY 304 // Enable adjacent edges 305 for (j=0; j<3; j++) { 306 mesh->edges[mesh->triangles[t].edges[j]].enable = TRUE; 307 } 308 #endif 243 309 244 mesh->triangles[t].enable = TRUE; 310 245 mesh->currentNumTriangles++; … … 312 247 } 313 248 314 Triangle *VMI::getTrianglesToModify(Mesh *mesh, Change *c, GLuint *numMod) {249 Triangle *VMI::getTrianglesToModify(Mesh *mesh, Change *c, int *numMod) { 315 250 int i, t; 316 251 Triangle *modified = NULL; … … 336 271 } 337 272 338 Triangle *VMI::getTrianglesToDelete(Mesh *mesh, Change *c, GLuint *numDel) {273 Triangle *VMI::getTrianglesToDelete(Mesh *mesh, Change *c, int *numDel) { 339 274 int i, t; 340 275 Triangle *deleted = NULL; … … 359 294 } 360 295 361 void VMI:: deleteEdges(Mesh *mesh, Change *c) {296 void VMI::modifyEdges(Mesh *mesh, Change *c) { 362 297 int i, e; 363 #ifndef USE_EDGE_ADJACENCY 364 int n0, n1, n2; 365 #else 366 int j, u, v; 367 #endif 368 369 #ifdef USE_EDGE_ADJACENCY 370 for (i=0; i<c->numDel; i++) { 298 299 for(i = 0; i < mesh->vertices[c->v].numEdges; i++) { 371 300 372 for (j=0; j<3; j++) { 373 e = c->deleted[i].edges[j]; 374 if (e != c->e) { 375 u = mesh->edges[e].u; 376 v = mesh->edges[e].v; 377 if (u == c->u || v == c->u) { 378 //printf("%d\n",j); 379 mesh->edges[e].enable = FALSE; 380 } 381 } 382 } 383 //getchar(); 384 } 385 #else 386 for (i=0; i<c->numDel; i++) { 387 388 n0 = c->deleted[i].indices[0]; 389 n1 = c->deleted[i].indices[1]; 390 n2 = c->deleted[i].indices[2]; 391 392 if ((n0 == c->u && n1 != c->v) || (n1 == c->u && n0 != c->v)) { 393 e = findEdge(mesh->edges, mesh->numEdges, n0, n1); 394 395 //printf("a\n"); 396 if (e != -1) 397 mesh->edges[e].enable = FALSE; 398 } 399 400 if ((n1 == c->u && n2 != c->v) || (n2 == c->u && n1 != c->v)) { 401 e = findEdge(mesh->edges, mesh->numEdges, n1, n2); 402 403 //printf("b\n"); 404 if (e != -1) 405 mesh->edges[e].enable = FALSE; 406 } 407 408 if ((n0 == c->u && n2 != c->v) || (n2 == c->u && n0 != c->v)) { 409 e = findEdge(mesh->edges, mesh->numEdges, n0, n2); 410 411 //printf("c\n"); 412 if (e != -1) 413 mesh->edges[e].enable = FALSE; 414 } 415 //getchar(); 416 } 417 #endif 418 } 419 420 void VMI::modifyEdges(Mesh *mesh, Change *c) { 421 int e, u, v; 422 423 // Update mesh and heap 424 for(e = 0; e < (int)mesh->numEdges; e++) { 425 301 e = mesh->vertices[c->v].edges[i]; 302 426 303 if (mesh->edges[e].enable == TRUE) { 427 304 428 305 // Modify edge 429 if ( (int)mesh->edges[e].u == c->u)306 if (mesh->edges[e].u == c->u) 430 307 mesh->edges[e].u = c->v; 431 308 432 if ( (int)mesh->edges[e].v == c->u)309 if (mesh->edges[e].v == c->u) 433 310 mesh->edges[e].v = c->v; 434 435 // Check edge436 u = mesh->edges[e].u;437 v = mesh->edges[e].v;438 439 // if the edge is not valid, we simply delete it440 if ((u == v) ||441 (u == c->u) || (v == c->u))442 443 mesh->edges[e].enable = FALSE;444 311 } 445 312 } 446 313 } 447 314 315 int VMI::find(int *edges, int num, int v_) { 316 int i; 317 318 int u, v; 319 320 321 for(i=0; i<num; i++) { 322 323 u = mesh->edges[edges[i]].u; 324 325 v = mesh->edges[edges[i]].v; 326 327 if (u == v_ || v == v_) return TRUE; 328 329 } 330 331 return FALSE; 332 } 333 void VMI::updateEdgeAdj(Mesh *mesh, Change *c) { 334 int i; 335 336 int v, e; 337 338 mesh->vertices[c->v].edges = 339 (int *)realloc(mesh->vertices[c->v].edges, 340 (mesh->vertices[c->v].numEdges + mesh->vertices[c->u].numEdges) * sizeof(int)); 341 342 for (i=0; i<mesh->vertices[c->u].numEdges; i++) { 343 344 e = mesh->vertices[c->u].edges[i]; 345 if (mesh->edges[e].u == c->u) v =mesh->edges[e].v; 346 else v = mesh->edges[e].u; 347 348 if (!find(mesh->vertices[c->v].edges, mesh->vertices[c->v].numEdges, v)) 349 addItem(mesh->vertices[c->v].edges, &mesh->vertices[c->v].numEdges, e); 350 else mesh->edges[e].enable = FALSE; 351 } 352 353 delItem(mesh->vertices[c->v].edges, &mesh->vertices[c->v].numEdges, c->e); 354 } 355 448 356 /////////////////////////////////////////////////////////////////////////////// 449 357 450 358 // Compute the triangle mesh changes due to a heap node simplification 451 359 void VMI::computeChange(Mesh *mesh, Change *c) { 452 GLuint numMod, numDel;360 int numMod, numDel; 453 361 Triangle *m = getTrianglesToModify(mesh, c, &numMod), 454 362 *d = getTrianglesToDelete(mesh, c, &numDel); -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/color.cpp
r2090 r2127 7 7 using namespace VMI; 8 8 9 Color *VMI::initColors( GLuint numColors) {9 Color *VMI::initColors(int numColors) { 10 10 Color *colors; 11 11 … … 25 25 } 26 26 27 void VMI::fillAllColors(Color *colors, GLuint numColors, GLuint begin, GLuint end, GLubyte color) {28 GLuint i;27 void VMI::fillAllColors(Color *colors, int numColors, int begin, int end, GLubyte color) { 28 int i; 29 29 30 30 if (end > numColors) return; … … 40 40 } 41 41 42 void VMI::setColors(Color *colors, GLuint numPasses, GLuint begin, GLuint end) {43 GLuint i, step = numPasses * MAX_NUM_COLORS;42 void VMI::setColors(Color *colors, int numPasses, int begin, int end) { 43 int i, step = numPasses * MAX_NUM_COLORS; 44 44 GLubyte r = 1, 45 45 g = 1, … … 86 86 } 87 87 88 void VMI::setColors2(Color *colors, GLuint numColors, GLuint begin, GLuint end) {89 GLuint i,88 void VMI::setColors2(Color *colors, int numColors, int begin, int end) { 89 int i, 90 90 channel = 0, 91 91 step = (numColors < MAX_NUM_COLORS) ? (MAX_NUM_COLORS / numColors) : 1; … … 133 133 } 134 134 135 void VMI::setColors3(Color *colors, GLuint numColors, GLubyte color) {136 GLuint i;135 void VMI::setColors3(Color *colors, int numColors, GLubyte color) { 136 int i; 137 137 138 138 for (i = 0; i < numColors; i++) { … … 148 148 } 149 149 150 void VMI::setColors4(Color *colors, GLuint numColors) {151 GLuint i, c = 1;150 void VMI::setColors4(Color *colors, int numColors) { 151 int i, c = 1; 152 152 153 153 for (i = 0; i < numColors; i++) { … … 164 164 } 165 165 166 void VMI::viewColors(Color *colors, GLuint numColors) {167 GLuint i;166 void VMI::viewColors(Color *colors, int numColors) { 167 int i; 168 168 169 169 printf("\n"); -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/histogram.cpp
r2090 r2127 14 14 using namespace VMI; 15 15 16 void VMI::printHistogram( GLuint histoGram[][4]) {16 void VMI::printHistogram(int histoGram[][4]) { 17 17 int i; 18 18 … … 23 23 } 24 24 25 void VMI::plotHistogram( GLuint histoGram[][4]) {25 void VMI::plotHistogram(int histoGram[][4]) { 26 26 int i; 27 GLuint iLargest = 0; // Largest histogram value27 int iLargest = 0; // Largest histogram value 28 28 GLfloat maxHeight = height / 2.0f; 29 29 … … 72 72 } 73 73 74 GLuint **VMI::initHistogram(GLuint numTriangles, GLuint numCameras) {75 GLuint i;76 GLuint **histogram;77 78 histogram = ( GLuint **)malloc(sizeof(GLuint *) * numCameras);74 int **VMI::initHistogram(int numTriangles, int numCameras) { 75 int i; 76 int **histogram; 77 78 histogram = (int **)malloc(sizeof(int *) * numCameras); 79 79 80 80 if (histogram == NULL) { … … 84 84 85 85 for (i=0; i<numCameras; i++) 86 histogram[i] = ( GLuint *)malloc(sizeof(GLuint) * (numTriangles + 1)); // + 1 because the last is the numPixels of the background86 histogram[i] = (int *)malloc(sizeof(int) * (numTriangles + 1)); // + 1 because the last is the numPixels of the background 87 87 88 88 // Fill the histogram buffer with 0 89 89 for (i=0; i<numCameras; i++) 90 memset(histogram[i], 0, sizeof( GLuint) * (numTriangles + 1));90 memset(histogram[i], 0, sizeof(int) * (numTriangles + 1)); 91 91 92 92 return histogram; 93 93 } 94 94 95 void VMI::deleteHistogram( GLuint **histogram, GLuint numCameras) {96 GLuint i;95 void VMI::deleteHistogram(int **histogram, int numCameras) { 96 int i; 97 97 98 98 for (i=0;i<numCameras;i++) … … 102 102 } 103 103 104 void VMI::printFullHistogram( GLuint **histogram, GLuint numCameras, GLuint numTriangles) {105 GLuint i, j;104 void VMI::printFullHistogram(int **histogram, int numCameras, int numTriangles) { 105 int i, j; 106 106 107 107 printf("\n"); … … 116 116 } 117 117 118 void VMI::getSubHistogram( GLuint subHistoGram[][4]) {118 void VMI::getSubHistogram(int subHistoGram[][4]) { 119 119 //printf("Computing histogram...\n"); 120 120 // Define the histogram … … 137 137 } 138 138 139 void VMI::copySubHistogram(Color *colors, GLuint *histogram, GLuint begin, GLuint end, GLuint subHistoGram[][4]) {140 GLuint i;139 void VMI::copySubHistogram(Color *colors, int *histogram, int begin, int end, int subHistoGram[][4]) { 140 int i; 141 141 GLubyte r, g, b, a; 142 GLuint h = 0;142 int h = 0; 143 143 144 144 for (i=begin; i<end; i++) { … … 165 165 } 166 166 167 void VMI::getSWHistogram( GLuint *histogram, GLubyte *pixels) {167 void VMI::getSWHistogram(int *histogram, GLubyte *pixels) { 168 168 GLubyte r, g, b, a; 169 GLuint i, t, p, numPixels = width * height;169 int i, t, p, numPixels = width * height; 170 170 171 171 glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); … … 188 188 189 189 void VMI::getBoundingBox(Change *c, GLfloat min[3], GLfloat max[3]) { 190 GLuint i, j, t, v;190 int i, j, t, v; 191 191 GLfloat maxx = 0.0f, minx = 0.0f, 192 192 maxy = 0.0f, miny = 0.0f, … … 194 194 195 195 /* get the max/mins */ 196 for (i=0; i< (GLuint)c->numMod; i++) {196 for (i=0; i<c->numMod; i++) { 197 197 t = c->modified[i].id; 198 198 … … 217 217 } 218 218 219 for (i=0; i< (GLuint)c->numDel; i++) {219 for (i=0; i<c->numDel; i++) { 220 220 t = c->deleted[i].id; 221 221 … … 322 322 } 323 323 324 void VMI::getSWHistogramWin( GLuint *histogram, GLubyte *pixels, GLfloat min[3], GLfloat max[3], Change *c) {324 void VMI::getSWHistogramWin(int *histogram, GLubyte *pixels, GLfloat min[3], GLfloat max[3], Change *c) { 325 325 GLubyte r, g, b, a; 326 GLuint i, t, p, numPixels,327 *histoAux = ( GLuint *)calloc(mesh->numTriangles + 1, sizeof(GLuint));326 int i, t, p, numPixels, 327 *histoAux = (int *)calloc(mesh->numTriangles + 1, sizeof(int)); 328 328 GLint minw[2], maxw[2], ox, oy, h, w; 329 329 … … 369 369 } 370 370 371 for (i=0; i< (GLuint)c->numMod; i++) {372 t = (GLuint)c->modified[i].id;371 for (i=0; i<c->numMod; i++) { 372 t = c->modified[i].id; 373 373 374 374 histogram[t + 1] = histoAux[t + 1]; … … 379 379 } 380 380 381 void VMI::getSWHistoByOcclusionQuery(Mesh *mesh, Color *colors, GLuint *histogram) {382 GLuint i, v1, v2, v3;381 void VMI::getSWHistoByOcclusionQuery(Mesh *mesh, Color *colors, int *histogram) { 382 int i, v1, v2, v3; 383 383 GLint area, totalArea = 0; 384 384 … … 432 432 } 433 433 434 void VMI::resetSWHistogram( GLuint *histogram, GLuint numTriangles) {434 void VMI::resetSWHistogram(int *histogram, int numTriangles) { 435 435 436 436 // Fill the histogram buffer with 0 437 memset(histogram, 0, sizeof( GLuint) * (numTriangles + 1));438 } 437 memset(histogram, 0, sizeof(int) * (numTriangles + 1)); 438 } -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/main.cpp
r2090 r2127 8 8 9 9 Camera *cameras = NULL; 10 GLuint numCameras = 0;10 int numCameras = 0; 11 11 12 12 Color *colors = NULL; 13 13 14 GLuint **histogram = NULL, 15 14 int **histogram = NULL; 15 GLuint *queries = NULL; 16 16 17 17 Mesh *mesh = NULL; … … 28 28 bRemoveRedundantVertices = GL_TRUE; 29 29 30 GLuint cameraType = 0,30 int cameraType = 0, 31 31 numDemandedTriangles = 0; 32 32 … … 174 174 } 175 175 176 void VMI::updateHWAcceleration(Change *c) { 177 178 #ifdef VERTEX_ARRAY_INTERLEAVE 179 if (interleave != NULL) free(interleave); 180 interleave = setupInterleave(mesh, colors); 181 #endif 182 #ifdef VERTEX_ARRAY 183 updateVertexArray(mesh, c); 184 #endif 185 #ifdef VERTEX_BUFFER_OBJECTS 186 updateVertexBufferObjects(mesh, c); 187 #endif 188 189 } 190 176 191 void VMI::setOrthographicProjection(void) { 177 192 // Switch to projection mode … … 208 223 void VMI::renderGeometry(void) { 209 224 #ifdef IMMEDIATE_MODE 210 GLuint i, v1, v2, v3;225 int i, v1, v2, v3; 211 226 212 227 // Immediate mode … … 228 243 #else 229 244 #ifdef VERTEX_ARRAY 230 glDrawArrays(GL_TRIANGLES, 0, mesh-> currentNumTriangles * 3);245 glDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); 231 246 #endif 232 247 #ifdef VERTEX_ARRAY_INTERLEAVE … … 235 250 #endif 236 251 #ifdef VERTEX_BUFFER_OBJECTS 237 glDrawArrays(GL_TRIANGLES, 0, mesh-> currentNumTriangles * 3);252 glDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); 238 253 #endif 239 254 … … 264 279 glutSwapBuffers(); 265 280 } 266 void VMI::renderScene(GLuint **histogram, GLuint numCameras) 267 { 268 GLuint i; 281 282 void VMI::resetProjectedAreas(int **histogram, int numCameras) { 283 int i = 0; 284 285 // Reset the projected areas for all cameras 286 for (i=0; i<numCameras; i++) 287 resetSWHistogram(histogram[i], mesh->numTriangles); 288 } 289 290 void VMI::getProjectedAreas(int **histogram, int numCameras) 291 { 292 int i; 269 293 270 294 // draw to the frame buffer 271 295 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); 272 273 // Apply HW acceleration OpenGL Technique 274 applyHWAcceleration(); 275 276 glDrawBuffer(GL_BACK); 277 glReadBuffer(GL_BACK); 296 297 //glDrawBuffer(GL_BACK); 298 //glReadBuffer(GL_BACK); 278 299 279 300 // Get the projected areas for all cameras … … 312 333 /////////////////////////////////////////////////////////////////////////// 313 334 } 314 void VMI:: renderSceneWin(GLuint **histogram, GLuint numCameras, Change *c)315 { 316 GLuint i, j, t, background;335 void VMI::getProjectedAreasWin(int **histogram, int numCameras, Change *c) 336 { 337 int i, j, t, background; 317 338 int del_area, mod_area; 318 339 GLfloat min[3], max[3]; … … 325 346 //printf("\n(%f,%f,%f)-(%f,%f,%f)\n", min[0], min[1], min[2], max[0], max[1], max[2]); 326 347 327 // ApplyHW acceleration OpenGL Technique328 applyHWAcceleration();329 330 glDrawBuffer(GL_BACK);331 glReadBuffer(GL_BACK);348 // Update HW acceleration OpenGL Technique 349 updateHWAcceleration(c); 350 351 //glDrawBuffer(GL_BACK); 352 //glReadBuffer(GL_BACK); 332 353 333 354 // Get the projected areas for all cameras … … 355 376 mod_area = 0; 356 377 357 for (j=0; j< ( GLuint)c->numDel; j++) {378 for (j=0; j<c->numDel; j++) { 358 379 t = c->deleted[j].id; 359 380 del_area += histogram[i][t + 1]; … … 362 383 } 363 384 364 for (j=0; j< ( GLuint)c->numMod; j++) {385 for (j=0; j<c->numMod; j++) { 365 386 t = c->modified[j].id; 366 387 del_area += histogram[i][t + 1]; … … 371 392 getSWHistogramWin(histogram[i], pixels, min, max, c); 372 393 373 for (j=0; j< ( GLuint)c->numMod; j++) {394 for (j=0; j<c->numMod; j++) { 374 395 t = c->modified[j].id; 375 396 mod_area += histogram[i][t + 1]; … … 425 446 426 447 glDeleteBuffersARB(1, &color_buf); 448 449 //free(pbuf_vertices); 450 //free(pbuf_colors); 451 452 buf_vertices = NULL; 453 buf_colors = NULL; 454 455 #endif 456 #ifdef VERTEX_ARRAY 457 //free(pbuf_vertices); 458 //free(pbuf_colors); 459 460 buf_vertices = NULL; 461 buf_colors = NULL; 427 462 #endif 428 463 … … 457 492 458 493 start = clock(); 494 495 // Apply HW acceleration OpenGL Technique 496 applyHWAcceleration(); 459 497 460 498 getProjectedAreas(histogram, numCameras); -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/mesh.cpp
r2090 r2127 53 53 /////////////////////////////////////////////////////////////////////////////// 54 54 55 int VMI::findEdge(Edge *e, GLuint num, GLuint _u, GLuint _v) {56 GLuint i, u, v;55 int VMI::findEdge(Edge *e, int num, int _u, int _v) { 56 int i, u, v; 57 57 int found = -1; 58 58 … … 85 85 newList[*n].u = u; 86 86 newList[*n].v = v; 87 88 // This edge has no triangle adjancency89 newList[*n].numTriangles = 0;90 newList[*n].triangles = NULL;91 87 92 88 // Enable the new edge … … 102 98 } 103 99 100 double VMI::computeEdgeLength(Vertex *vertices, int u, int v) { 101 float ux, uy, uz, vx, vy ,vz, rx, ry, rz; 102 103 ux = vertices[u].x; 104 uy = vertices[u].y; 105 uz = vertices[u].z; 106 107 vx = vertices[v].x; 108 vy = vertices[v].y; 109 vz = vertices[v].z; 110 111 rx = ux - vx; 112 ry = uy - vy; 113 rz = uz - vz; 114 115 return sqrt((rx * rx) + (ry * ry) + (rz * rz)); 116 } 117 118 double VMI::computeTriangleVolume(Vertex *vertices, Triangle *t) { 119 int i; 120 double m[3][3], vol; 121 122 // Compute triangle Volume 123 i = t->indices[0]; 124 m[0][0] = mesh->vertices[i].x; 125 m[0][1] = mesh->vertices[i].y; 126 m[0][2] = mesh->vertices[i].z; 127 128 i = t->indices[1]; 129 m[1][0] = mesh->vertices[i].x; 130 m[1][1] = mesh->vertices[i].y; 131 m[1][2] = mesh->vertices[i].z; 132 133 i = t->indices[2]; 134 m[2][0] = mesh->vertices[i].x; 135 m[2][1] = mesh->vertices[i].y; 136 m[2][2] = mesh->vertices[i].z; 137 138 vol = computeMatDet(m); 139 140 //printf("Triangle Volume: %f\n", vol) 141 return vol; 142 } 143 104 144 GLdouble VMI::computeTriangleArea(Vertex *vertices, Triangle *t) { 105 GLuint i;145 int i; 106 146 GLdouble v0[3], v1[3], v2[3], a; 107 147 … … 129 169 130 170 void VMI::computeTriangleNormal(Vertex *vertices, Triangle *t) { 131 GLuint i;171 int i; 132 172 GLfloat x0, y0, z0, 133 173 x1, y1, z1, … … 175 215 Mesh *VMI::initMesh(GLMmodel* pmodel) { 176 216 177 GLuint i, j, curGroup, v1, v2, v3, n, m, t;217 int i, j, curGroup, v1, v2, v3, n, m, t; 178 218 int e; 179 219 Mesh *mesh; … … 202 242 203 243 printf("Adding vertices..."); 204 for (i=1; i<= pmodel->numvertices; i++) { // Vertices start at 1244 for (i=1; i<=(int)pmodel->numvertices; i++) { // Vertices start at 1 205 245 mesh->vertices[i - 1].x = pmodel->vertices[3 * i + 0]; 206 246 mesh->vertices[i - 1].y = pmodel->vertices[3 * i + 1]; … … 208 248 mesh->vertices[i - 1].numTriangles = 0; 209 249 mesh->vertices[i - 1].triangles = NULL; 250 mesh->vertices[i - 1].numEdges = 0; 251 mesh->vertices[i - 1].edges = NULL; 210 252 mesh->vertices[i - 1].enable = GL_TRUE; 211 253 } … … 221 263 while(group) { 222 264 223 for (i=0; i< group->numtriangles; i++) {265 for (i=0; i<(int)group->numtriangles; i++) { 224 266 225 267 t = group->triangles[i]; … … 244 286 // Reallocate memory for the new adjacent triangle 245 287 mesh->vertices[v1].triangles = 246 ( GLuint *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(GLuint));288 (int *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(int)); 247 289 addItem((int *)mesh->vertices[v1].triangles, (int *)&mesh->vertices[v1].numTriangles, t); 248 290 } … … 254 296 for (i=0; i<pmodel->numtriangles; i++) { 255 297 mesh->triangles[i].id = i; 256 mesh->triangles[i].indices[0] = pmodel->triangles[i].vindices[0] - 1;257 mesh->triangles[i].indices[1] = pmodel->triangles[i].vindices[1] - 1;258 mesh->triangles[i].indices[2] = pmodel->triangles[i].vindices[2] - 1;298 mesh->triangles[i].indices[0] = (int)pmodel->triangles[i].vindices[0] - 1; 299 mesh->triangles[i].indices[1] = (int)pmodel->triangles[i].vindices[1] - 1; 300 mesh->triangles[i].indices[2] = (int)pmodel->triangles[i].vindices[2] - 1; 259 301 mesh->triangles[i].area = computeTriangleArea(mesh->vertices, &mesh->triangles[i]); 260 302 //printf("\n%d a: %f",i , mesh->triangles[i].area); … … 271 313 // Reallocate memory for the new adjacent triangle 272 314 mesh->vertices[v1].triangles = 273 ( GLuint *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(GLuint));315 (int *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(int)); 274 316 addItem((int *)mesh->vertices[v1].triangles, (int *)&mesh->vertices[v1].numTriangles, i); 275 317 } … … 304 346 mesh->edges[n].u = v1; 305 347 mesh->edges[n].v = v2; 306 mesh->edges[n].triangles = NULL;307 mesh->edges[n].numTriangles = 0;308 348 mesh->edges[n].enable = GL_TRUE; 309 349 m = n; 310 350 n++; 311 351 } else m = e; 312 // Reallocate memory for the new adjacent triangle313 mesh->edges[m].triangles =314 (GLuint *)realloc(mesh->edges[m].triangles, (mesh->edges[m].numTriangles + 1) * sizeof(GLuint));315 // Adding triangle i adjacent to edge m316 addItem((int *)mesh->edges[m].triangles, (int *)&mesh->edges[m].numTriangles, i);317 //printf("n:%d i:%d\n", m, i);318 319 // Adding edge m adjacent to triangle i320 addItem((int *)mesh->triangles[i].edges, (int *)&t, m);321 352 322 353 ///////////////////////////////////////////////////////////////////////////////// … … 325 356 mesh->edges[n].u = v2; 326 357 mesh->edges[n].v = v3; 327 mesh->edges[n].triangles = NULL;328 mesh->edges[n].numTriangles = 0;329 358 mesh->edges[n].enable = GL_TRUE; 330 359 m = n; 331 360 n++; 332 361 } else m = e; 333 // Reallocate memory for the new adjacent triangle334 mesh->edges[m].triangles =335 (GLuint *)realloc(mesh->edges[m].triangles, (mesh->edges[m].numTriangles + 1) * sizeof(GLuint));336 // Adding triangle i adjacent to edge m337 addItem((int *)mesh->edges[m].triangles, (int *)&mesh->edges[m].numTriangles, i);338 //printf("n:%d i:%d\n", m, i);339 340 // Adding edge m adjacent to triangle i341 addItem((int *)mesh->triangles[i].edges, (int *)&t, m);342 362 343 363 ///////////////////////////////////////////////////////////////////////////////// … … 346 366 mesh->edges[n].u = v3; 347 367 mesh->edges[n].v = v1; 348 mesh->edges[n].triangles = NULL;349 mesh->edges[n].numTriangles = 0;350 368 mesh->edges[n].enable = GL_TRUE; 351 369 m = n; 352 370 n++; 353 371 } else m = e; 354 // Reallocate memory for the new adjacent triangle355 mesh->edges[m].triangles =356 (GLuint *)realloc(mesh->edges[m].triangles, (mesh->edges[m].numTriangles + 1) * sizeof(GLuint));357 // Adding triangle i adjacent to edge m358 addItem((int *)mesh->edges[m].triangles, (int *)&mesh->edges[m].numTriangles, i);359 //printf("n:%d i:%d\n", m, i);360 361 // Adding edge m adjacent to triangle i362 addItem((int *)mesh->triangles[i].edges, (int *)&t, m);363 372 } 364 373 printf("Ok\n"); 365 374 mesh->numEdges = n; 366 375 376 for (i=0; i<mesh->numEdges; i++) { 377 v1 = mesh->edges[i].u; 378 v2 = mesh->edges[i].v; 379 380 mesh->vertices[v1].edges = 381 (int *)realloc(mesh->vertices[v1].edges, (mesh->vertices[v1].numEdges + 1) * sizeof(int)); 382 // Adding edge i adjacent to vertex v1 383 addItem(mesh->vertices[v1].edges, &mesh->vertices[v1].numEdges, i); 384 385 mesh->vertices[v2].edges = 386 (int *)realloc(mesh->vertices[v2].edges, (mesh->vertices[v2].numEdges + 1) * sizeof(int)); 387 // Adding edge i adjacent to vertex v2 388 addItem(mesh->vertices[v2].edges, &mesh->vertices[v2].numEdges, i); 389 } 390 367 391 return mesh; 368 392 } 369 393 370 394 void VMI::printMesh(Mesh *mesh) { 371 GLuint i, j;395 int i, j; 372 396 373 397 printf("Vertices (%d)\n", mesh->numVertices); … … 385 409 } 386 410 printf("]\n"); 411 412 printf(" e(%d)[", mesh->vertices[i].numEdges); 413 if (mesh->vertices[i].edges != NULL) { 414 printf("%d", mesh->vertices[i].edges[0]); 415 for (j=1; j<mesh->vertices[i].numEdges; j++) { 416 printf(",%d", mesh->vertices[i].edges[j]); 417 } 418 } 419 printf("]\n"); 387 420 } 388 421 … … 391 424 for (i=0; i<mesh->numEdges; i++) { 392 425 printf("e%d (%d,%d) %d\n", i, mesh->edges[i].u, mesh->edges[i].v, mesh->edges[i].enable); 393 printf(" t(%d)[", mesh->edges[i].numTriangles);394 if (mesh->edges[i].triangles != NULL) {395 printf("%d", mesh->edges[i].triangles[0]);396 for (j=1; j<mesh->edges[i].numTriangles; j++) {397 printf(",%d", mesh->edges[i].triangles[j]);398 }399 }400 printf("]\n");401 426 } 402 427 … … 406 431 printf("t%d (%d,%d,%d) %d\n", i, mesh->triangles[i].indices[0], mesh->triangles[i].indices[1], 407 432 mesh->triangles[i].indices[2], mesh->triangles[i].enable); 408 printf(" e(3)[");409 printf("%d", mesh->triangles[i].edges[0]);410 for (j=1; j<3; j++) {411 printf(",%d", mesh->triangles[i].edges[j]);412 }413 printf("]\n");414 433 415 434 printf(" n(3)["); … … 425 444 426 445 void VMI::deleteMesh(Mesh *mesh) { 427 GLuint i;446 int i; 428 447 429 448 if (NULL != mesh) { … … 432 451 free(mesh->vertices[i].triangles); 433 452 453 if (mesh->vertices[i].edges != NULL) 454 free(mesh->vertices[i].edges); 455 434 456 } 435 457 if (mesh->vertices != NULL) free(mesh->vertices); 436 458 mesh->numVertices = 0; 437 459 438 for (i=0; i<mesh->numEdges; i++) {439 if (mesh->edges[i].triangles != NULL)440 free(mesh->edges[i].triangles);441 }442 460 if (mesh->edges != NULL) free(mesh->edges); 443 461 mesh->numEdges = 0; … … 525 543 } 526 544 527 int *VMI::edgesAdjToVertex(Mesh *mesh, int v, int *n) {528 int *edges = NULL;529 int i, t, e;530 #ifndef USE_EDGE_ADJACENCY531 int n0, n1, n2;532 #else533 int j;534 #endif535 int num = 0;536 537 if (mesh->vertices[v].numTriangles > 0)538 edges = (int*)malloc(sizeof(int) * mesh->vertices[v].numTriangles * 2);539 540 for (i=0; i<(int)mesh->vertices[v].numTriangles; i++) {541 542 t = mesh->vertices[v].triangles[i];543 544 #ifdef USE_EDGE_ADJACENCY545 for (j=0; j<3; j++) {546 e = mesh->triangles[t].edges[j];547 548 if ((int)mesh->edges[e].u == v || (int)mesh->edges[e].v == v)549 550 addItem(edges, &num, e);551 }552 #else553 n0 = mesh->triangles[t].indices[0];554 n1 = mesh->triangles[t].indices[1];555 n2 = mesh->triangles[t].indices[2];556 557 if (((n0 == v) || (n1 == v)) &&558 ((e = findEdge(mesh->edges, mesh->numEdges, n0, n1)) != -1)) addItem(edges, &num, e);559 560 if (((n1 == v) || (n2 == v)) &&561 ((e = findEdge(mesh->edges, mesh->numEdges, n1, n2)) != -1)) addItem(edges, &num, e);562 563 if (((n0 == v) || (n2 == v)) &&564 ((e = findEdge(mesh->edges, mesh->numEdges, n0, n2)) != -1)) addItem(edges, &num, e);565 566 #endif567 }568 *n = num;569 570 return edges;571 }572 573 545 int *VMI::edgesAdjToVertices(Mesh *mesh, int *vertices, int numVertices, int *n) { 574 546 int *edges = NULL; … … 578 550 if (numVertices > 0) { 579 551 // Add the first 580 list = edgesAdjToVertex(mesh, vertices[0], &numEdges); 552 list = mesh->vertices[vertices[0]].edges; 553 numEdges = mesh->vertices[vertices[0]].numEdges; 581 554 582 555 // Allocate memory … … 585 558 memcpy(edges, list, sizeof(int) * numEdges); 586 559 587 free(list);588 589 560 num = numEdges; 590 561 … … 592 563 for (i=1; i<numVertices; i++) { 593 564 594 list = edgesAdjToVertex(mesh, vertices[i], &numEdges); 565 list = mesh->vertices[vertices[i]].edges; 566 numEdges = mesh->vertices[vertices[i]].numEdges; 595 567 596 568 // Reallocate memory 597 569 if (numEdges > 0) { 598 570 599 571 edges = (int *)realloc(edges, (num + numEdges + 1) * sizeof(int)); … … 601 573 for (j=0; j<numEdges; j++) 602 574 addItem(edges, &num, list[j]); 603 } 604 free(list); 575 } 605 576 } 606 577 } … … 610 581 } 611 582 612 GLboolean VMI::findVertex( GLfloat *vertices, GLuint num, GLfloat x, GLfloat y, GLfloat z, int *pos) {613 GLuint i;614 GLfloat _x, _y, _z;583 GLboolean VMI::findVertex(float *vertices, int num, float x, float y, float z, int *pos) { 584 int i; 585 float _x, _y, _z; 615 586 GLboolean found = GL_FALSE; 616 587 … … 648 619 newList[*n].numTriangles = 0; 649 620 newList[*n].triangles = NULL; 621 622 newList[*n].numEdges= 0; 623 newList[*n].edges = NULL; 650 624 651 625 // Enable the new vertex … … 663 637 664 638 665 void VMI::updateModel(GLMmodel* pmodel, Mesh *mesh, GLuint numVertices, GLuint numTriangles) {666 GLuint i , v1, v2 ,v3, numV = 1, numT = 0;639 void VMI::updateModel(GLMmodel* pmodel, Mesh *mesh, int numVertices, int numTriangles) { 640 int i , v1, v2 ,v3, numV = 1, numT = 0; 667 641 int pos; 668 GLfloat x, y, z;642 float x, y, z; 669 643 670 644 if (pmodel->vertices != NULL) free(pmodel->vertices); … … 726 700 727 701 void VMI::saveModel(char *filename, GLMmodel* pmodel, Mesh *mesh) { 728 GLuint i, j, g, numT = 0;702 int i, j, g, numT = 0; 729 703 GLMgroup *group; 730 704 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/metrics.cpp
r2090 r2127 13 13 using namespace VMI; 14 14 15 GLdouble VMI::computeMeanProjAreaNoBG( GLuint **histogram, GLuint numCameras, int t) {16 GLuint i;15 GLdouble VMI::computeMeanProjAreaNoBG(int **histogram, int numCameras, int t) { 16 int i; 17 17 GLdouble mean_proj_area = 0.0; 18 18 … … 24 24 } 25 25 26 GLdouble VMI::computeMeanProjArea( GLuint **histogram, GLuint numCameras, int t) {27 GLuint i;26 GLdouble VMI::computeMeanProjArea(int **histogram, int numCameras, int t) { 27 int i; 28 28 GLdouble mean_proj_area = 0.0, total_proj_area, resolution = width * height; 29 29 … … 38 38 /////////////////////////////////////////////////////////////////////////////// 39 39 // Mutual Information 40 GLdouble VMI::computeMI(Mesh *mesh, GLuint **histogram, GLuint numCameras, GLuint cam) {40 GLdouble VMI::computeMI(Mesh *mesh, int **histogram, int numCameras, int cam) { 41 41 GLdouble I = 0.0, pov, po, total_proj_area = width * height; 42 GLuint i;42 int i; 43 43 44 44 for (i=0; i<mesh->numTriangles; i++) { … … 66 66 } 67 67 68 GLdouble VMI::decMI(GLdouble I, GLuint **histogram, GLuint numCameras, GLuint cam, Change *c) {68 GLdouble VMI::decMI(GLdouble I, int **histogram, int numCameras, int cam, Change *c) { 69 69 GLdouble newI = I * numCameras, 70 70 pov = 0.0, po; … … 109 109 } 110 110 111 GLdouble VMI::incMI(GLdouble I, GLuint **histogram, GLuint numCameras, GLuint cam, Change *c) {111 GLdouble VMI::incMI(GLdouble I, int **histogram, int numCameras, int cam, Change *c) { 112 112 GLdouble newI = I * numCameras, 113 113 pov = 0.0, po; 114 114 GLsizei total_proj_area = width * height; 115 GLuint i, t;115 int i, t; 116 116 117 117 // increase entropy of modified triangles 118 for (i=0; i< (GLuint)c->numMod; i++) {118 for (i=0; i<c->numMod; i++) { 119 119 120 120 t = c->modified[i].id; … … 140 140 /////////////////////////////////////////////////////////////////////////////// 141 141 // Kullback-Leibler divergence 142 GLdouble VMI::computeKL(Mesh *mesh, GLuint *histogram) {142 GLdouble VMI::computeKL(Mesh *mesh, int *histogram) { 143 143 GLdouble I = 0.0, 144 144 total_real_area = 0.0, pi, tri_area; 145 145 GLsizei total_proj_area = (width * height) - histogram[0]; 146 GLuint i;146 int i; 147 147 148 148 // Compute total real area of all triangles … … 169 169 170 170 // Hellinger divergence (square root) 171 GLdouble VMI::computeHE(Mesh *mesh, GLuint *histogram) {171 GLdouble VMI::computeHE(Mesh *mesh, int *histogram) { 172 172 GLdouble I = 0.0, temp, 173 173 total_real_area = 0.0, pi, qi; 174 174 GLsizei total_proj_area = (width * height) - histogram[0]; 175 GLuint i;175 int i; 176 176 177 177 // Compute total real area of all triangles … … 203 203 204 204 // Chi-Square divergence (square root) 205 GLdouble VMI::computeCS(Mesh *mesh, GLuint *histogram) {205 GLdouble VMI::computeCS(Mesh *mesh, int *histogram) { 206 206 GLdouble I = 0.0, 207 207 total_real_area = 0.0, pi, qi; 208 208 GLsizei total_proj_area = (width * height) - histogram[0]; 209 GLuint i;209 int i; 210 210 211 211 /// Compute total real area of all triangles … … 231 231 } 232 232 /////////////////////////////////////////////////////////////////////////////// 233 GLdouble VMI::computeEntropy( GLuint **histogram, GLuint numCameras, GLuint k) {233 GLdouble VMI::computeEntropy(int **histogram, int numCameras, int k) { 234 234 GLdouble H = 0.0, POk, pi, 235 235 total_proj_area, resolution = width * height, pv = 1.0 / (GLdouble)numCameras; 236 GLuint i;236 int i; 237 237 238 238 for (i=0; i<numCameras; i++) { … … 253 253 } 254 254 255 GLdouble VMI::computeMixedEntropy(GLdouble *mixed, GLuint numCameras) {255 GLdouble VMI::computeMixedEntropy(GLdouble *mixed, int numCameras) { 256 256 GLdouble H = 0.0, pi; 257 GLuint i;257 int i; 258 258 259 259 for (i=0; i<numCameras; i++) { … … 269 269 /////////////////////////////////////////////////////////////////////////////// 270 270 // Jensen-Shannon divergence 271 GLdouble VMI::computeJS( GLuint **histogram, GLuint numCameras, GLuint j, GLuint k) {271 GLdouble VMI::computeJS(int **histogram, int numCameras, int j, int k) { 272 272 GLdouble js, Wj = 0.0, Wk = 0.0, POj, POk, pj, pk, total_proj_area, 273 273 resolution = width * height, pv = 1.0 / (GLdouble)numCameras, 274 274 *mixing = (GLdouble *)malloc(numCameras * sizeof(GLdouble)); 275 GLuint i;275 int i; 276 276 277 277 POj = computeMeanProjArea(histogram, numCameras, j + 1); … … 311 311 } 312 312 /////////////////////////////////////////////////////////////////////////////// 313 void VMI::getProjectedAreas(GLuint **histogram, GLuint numCameras) { 314 315 renderScene(histogram, numCameras); 316 } 317 318 void VMI::getProjectedAreasWin(GLuint **histogram, GLuint numCameras, Change *c) { 319 320 renderSceneWin(histogram, numCameras, c); 321 } 322 323 void VMI::resetProjectedAreas(GLuint **histogram, GLuint numCameras) { 324 GLuint i = 0; 325 326 // Reset the projected areas for all cameras 327 for (i=0; i<numCameras; i++) 328 resetSWHistogram(histogram[i], mesh->numTriangles); 329 } 330 331 GLdouble *VMI::initIs(GLuint numCameras) { 313 314 GLdouble *VMI::initIs(int numCameras) { 332 315 GLdouble *initialIs; 333 316 … … 346 329 } 347 330 348 void VMI::computeCameraIs( GLuint **histogram, GLuint numCameras, GLdouble *mis) {349 GLuint i = 0;331 void VMI::computeCameraIs(int **histogram, int numCameras, GLdouble *mis) { 332 int i = 0; 350 333 GLdouble meanI = 0.0; 351 334 … … 374 357 } 375 358 376 void VMI::printIs(GLdouble *mis, GLuint numCameras) {377 GLuint i;359 void VMI::printIs(GLdouble *mis, int numCameras) { 360 int i; 378 361 379 362 printf("\n"); -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/saliency.cpp
r2090 r2127 22 22 using namespace VMI; 23 23 24 void VMI::computeSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras) {25 GLuint i = 0;24 void VMI::computeSaliency(Mesh *mesh, int **histogram, int numCameras) { 25 int i = 0; 26 26 double sal; 27 27 … … 46 46 } 47 47 48 void updateTriangleSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras, int v) {48 void updateTriangleSaliency(Mesh *mesh, int **histogram, int numCameras, int v) { 49 49 int i, t; 50 50 … … 57 57 } 58 58 59 double VMI::computeTriangleSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras, GLuint k) {60 GLuint i, l, v0, v1, v2;59 double VMI::computeTriangleSaliency(Mesh *mesh, int **histogram, int numCameras, int k) { 60 int i, l, v0, v1, v2; 61 61 int *triangles = NULL, n = 0; 62 62 double sal = 0.0; … … 94 94 //printItemList(triangles, n); 95 95 96 for(i=0; i< (GLuint)n; i++) {96 for(i=0; i<n; i++) { 97 97 //printf("\n%d %d", k, triangles[i]); 98 98 //sal += computeJS(histogram, numCameras, k, triangles[i]); … … 137 137 void VMI::saveSaliencyMap(Mesh *mesh, char* filename) { 138 138 FILE *fp; 139 GLuint i;139 int i; 140 140 141 141 … … 162 162 void VMI::loadSaliencyMap(Mesh *mesh, char* filename) { 163 163 FILE *fp; 164 unsignedint i, num;164 int i, num; 165 165 float s; 166 166 … … 202 202 203 203 void VMI::viewSaliency(Mesh *mesh, Camera *cameras, int cam) { 204 GLuint i, v1, v2, v3;204 int i, v1, v2, v3; 205 205 float r, g, b; 206 206 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/simplify.cpp
r2103 r2127 10 10 #include "../include/saliency.h" 11 11 #include "../include/histogram.h" 12 #include "../include/buffers.h" 12 13 13 14 //#define RECOMPUTE_THE_WHOLE_HEAP … … 59 60 60 61 bheap_t *VMI::initHeap(Mesh *mesh) { 61 GLuint i;62 int i; 62 63 double cost; 63 64 bheap_t *h = NULL; … … 152 153 153 154 return h; 154 }155 156 GLdouble VMI::computeEdgeLength(Vertex *vertices, int u, int v) {157 GLfloat ux, uy, uz, vx, vy ,vz, rx, ry, rz;158 159 ux = vertices[u].x;160 uy = vertices[u].y;161 uz = vertices[u].z;162 163 vx = vertices[v].x;164 vy = vertices[v].y;165 vz = vertices[v].z;166 167 rx = ux - vx;168 ry = uy - vy;169 rz = uz - vz;170 171 return sqrt((rx * rx) + (ry * ry) + (rz * rz));172 155 } 173 156 … … 243 226 /////////////////////////////////////////////////////////////////////////////// 244 227 245 void saveProjectedAreas( GLuint **histogram, GLuint numCameras, Change *c, GLuint *dest) {246 GLuint i, j, t, n = 0;247 248 for (j=0; j< (GLuint)c->numDel; j++) {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++) { 249 232 250 233 t = c->deleted[j].id; … … 257 240 } 258 241 259 for (j=0; j< (GLuint)c->numMod; j++) {242 for (j=0; j<c->numMod; j++) { 260 243 261 244 t = c->modified[j].id; … … 276 259 } 277 260 278 void loadProjectedAreas( GLuint *src, GLuint numCameras, Change *c, GLuint **histogram) {279 GLuint i, j, t, n = 0;280 281 for (j=0; j< (GLuint)c->numDel; j++) {261 void loadProjectedAreas(int *src, int numCameras, Change *c, int **histogram) { 262 int i, j, t, n = 0; 263 264 for (j=0; j<c->numDel; j++) { 282 265 283 266 t = c->deleted[j].id; … … 290 273 } 291 274 292 for (j=0; j< (GLuint)c->numMod; j++) {275 for (j=0; j<c->numMod; j++) { 293 276 294 277 t = c->modified[j].id; … … 308 291 } 309 292 } 310 311 293 /////////////////////////////////////////////////////////////////////////////// 294 #ifdef CHECK_LOCAL_INVERSION 295 int check_local_inversion(Mesh *mesh, Change *c) { 296 int i, t; 297 int v0, v1, v2; 298 double vol_before; 299 double vol_after; 300 Triangle tri; 301 302 for(i=0; i<mesh->vertices[c->u].numTriangles; i++) { 303 304 t = mesh->vertices[c->u].triangles[i]; 305 306 v0 = mesh->triangles[t].indices[0]; 307 v1 = mesh->triangles[t].indices[1]; 308 v2 = mesh->triangles[t].indices[2]; 309 310 if ((v0 != c->v) && (v1 != c->v) && (v2 != c->v)) { 311 312 //printf("%d\n", t); 313 memcpy(&tri, &mesh->triangles[t], sizeof(Triangle)); 314 315 vol_before = computeTriangleVolume(mesh->vertices, &tri); 316 317 //printf("t:[%d,%d,%d]\n", tri.indices[0], tri.indices[1], tri.indices[2]); 318 //printf("v:%f\n", vol_before); 319 320 if (tri.indices[0] == c->u) tri.indices[0] = c->v; 321 if (tri.indices[1] == c->u) tri.indices[1] = c->v; 322 if (tri.indices[2] == c->u) tri.indices[2] = c->v; 323 324 vol_after = computeTriangleVolume(mesh->vertices, &tri); 325 326 //printf("t:[%d,%d,%d]\n", tri.indices[0], tri.indices[1], tri.indices[2]); 327 //printf("v:%f\n", vol_after); 328 329 if (((vol_before > 0) && (vol_after < 0)) || 330 ((vol_before < 0) && (vol_after > 0))) 331 332 return TRUE; 333 } 334 } 335 return FALSE; 336 } 337 #endif 312 338 313 339 GLdouble VMI::computeEdgeCost(Mesh *mesh, int e) { … … 318 344 GLdouble newI; 319 345 #endif 320 GLuint i, *histoAux = NULL;346 int i, *histoAux = NULL; 321 347 Change *c; 348 #if defined(VERTEX_BUFFER_OBJECTS) || defined(VERTEX_ARRAY) 349 VertexIL *vb = NULL; 350 #endif 351 #ifdef CHECK_LOCAL_INVERSION 352 int penalized; 353 #endif 322 354 323 355 chooseBestEndPoints(mesh, e); … … 327 359 328 360 // Compute cost only for boundary or manifold edges 329 if (c->numDel == 2 330 /*(c->numDel <3) && (c->numDel > 0)*/) { 361 if (/*c->numDel == 2*/ 362 (c->numDel <3) && (c->numDel > 0)) { 363 364 #ifdef CHECK_LOCAL_INVERSION 365 penalized = check_local_inversion(mesh, c); 366 #endif 331 367 // Allocate memory 332 histoAux = (GLuint *)malloc((c->numDel + c->numMod + 1) * numCameras * sizeof(GLuint)); 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); 374 #endif 333 375 334 376 #ifdef MI // Mutual Information … … 365 407 //printf(" I0:%f Is: %f\n", auxE[i], initialIs[i]); 366 408 367 cost += (ABS(auxIs[i] - initialIs[i]) * cameras[i].weight * sal);409 cost += (ABS(auxIs[i] - initialIs[i]) * cameras[i].weight); 368 410 369 411 // Restore old informations … … 405 447 newI = computeCS(mesh, histogram[i]); 406 448 #endif 407 cost += (ABS(initialIs[i] - newI) * cameras[i].weight * sal);449 cost += (ABS(initialIs[i] - newI) * cameras[i].weight); 408 450 } 409 451 undoChange(mesh, c); … … 417 459 // Free memory 418 460 free(histoAux); 461 #if defined(VERTEX_BUFFER_OBJECTS) || defined(VERTEX_ARRAY) 462 loadVertexBuffer(vb, c); 463 free(vb); 464 #endif 465 #ifdef CHECK_LOCAL_INVERSION 466 if (penalized) cost *= 5; 467 #endif 419 468 420 469 } else cost = FLT_MAX; … … 422 471 deleteChange(c); 423 472 424 return cost; 425 } 473 return (cost * sal); 474 } 475 476 int isValidEdge_(Mesh *mesh, int e) { 477 int u , v; 478 479 if (mesh->edges[e].enable == FALSE) return FALSE; 480 else { 481 u = mesh->edges[e].u; 482 v = mesh->edges[e].v; 483 484 if (u == v) { 485 486 mesh->edges[e].enable = FALSE; 487 return FALSE; 488 } 489 } 490 491 return TRUE; 492 } 493 426 494 /* Get a valid edge from the heap */ 427 495 int getMinValidEdge(Mesh *mesh, bheap_t *h) { … … 431 499 e = bh_min(h); 432 500 433 while ( mesh->edges[e].enable == FALSE) {501 while (!isValidEdge_(mesh, e)) { 434 502 /* delete invalid edge */ 435 503 bh_delete(h, e); … … 473 541 474 542 /////////////////////////////////////////////////////////////////////////// 475 void VMI::simplifyModel(Mesh *mesh, GLuint numDemandedTri)543 void VMI::simplifyModel(Mesh *mesh, int numDemandedTri) 476 544 { 477 545 int e; … … 558 626 bh_delete(h, e); 559 627 628 updateHWAcceleration(c); 629 560 630 // Get projected areas after the edge collapse 561 631 getProjectedAreas(histogram, numCameras); … … 563 633 computeCameraIs(histogram, numCameras, initialIs); 564 634 565 deleteEdges(mesh, c); 566 modifyEdges(mesh, c); 635 updateEdgeAdj(mesh, c); 636 637 modifyEdges(mesh, c); 567 638 568 639 // Update the heap according to the edge collapse … … 751 822 752 823 Edge *econ; 753 float x,y,z;754 824 int *lv1; 755 825 int v0; … … 797 867 v1 = (*lb1).second; 798 868 799 lv1 = edgesAdjToVertex(mesh,v1,&num_edges); 869 lv1 = mesh->vertices[v1].edges; 870 num_edges = mesh->vertices[v1].numEdges; 800 871 801 872 // Edje iterator. … … 857 928 858 929 deleteVertexOfMap(mesh, c->u); 859 deleteEdges(mesh, c);860 930 updateEdgeAdj(mesh, c); 931 modifyEdges(mesh, c); 861 932 deleteChange(c); 862 933 … … 910 981 lonely_vert = (*it).second; 911 982 912 le = edgesAdjToVertex(mesh,lonely_vert,&num_edges); 983 le = mesh->vertices[lonely_vert].edges; 984 985 num_edges = mesh->vertices[lonely_vert].numEdges; 913 986 914 987 // Find an edge width v coordinates. … … 977 1050 978 1051 deleteVertexOfMap(mesh, c->u); 979 deleteEdges(mesh, c);980 1052 updateEdgeAdj(mesh, c); 1053 modifyEdges(mesh, c); 981 1054 deleteChange(c); 982 1055 } … … 1069 1142 1070 1143 deleteVertexOfMap(mesh, c->u); 1071 deleteEdges(mesh, c);1072 1144 updateEdgeAdj(mesh, c); 1145 modifyEdges(mesh, c); 1073 1146 deleteChange(c); 1074 1147 }
Note: See TracChangeset
for help on using the changeset viewer.