Changeset 3238
- Timestamp:
- 01/02/09 03:37:07 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r3232 r3238 888 888 </File> 889 889 </Filter> 890 <File891 RelativePath=".\default.env"892 >893 </File>894 <File895 RelativePath=".\ReadMe.txt"896 >897 </File>898 890 </Files> 899 891 <Globals> -
GTP/trunk/App/Demos/Vis/FriendlyCulling/MainApp.vcproj
r3019 r3238 196 196 > 197 197 </File> 198 <File 199 RelativePath=".\default.env" 200 > 201 </File> 202 <File 203 RelativePath=".\Readme.txt" 204 > 205 </File> 198 206 </Filter> 199 207 <Filter -
GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp
r3236 r3238 14 14 15 15 #define BVH_VERSION 2.1 16 17 const int maxVertices = 20000000; 18 19 20 21 static string ReplaceSuffix(const string &str, 22 const string &a, 23 const string &b) 24 { 25 string result = str; 26 27 int pos = (int)str.rfind(a, (int)str.size() - 1); 28 if (pos == str.size() - a.size()) 29 { 30 result.replace(pos, a.size(), b); 31 } 32 33 return result; 34 } 16 35 17 36 … … 92 111 if (indices.size() > 2) 93 112 { 94 // change orientation of faces?95 #if 196 113 int idx1 = 0; 97 114 int idx2 = (int)indices.size() - 2; 98 115 int idx3 = (int)indices.size() - 1; 99 #else 100 int idx3 = 0; 101 int idx2 = (int)indices.size() - 2; 102 int idx1 = (int)indices.size() - 1; 103 #endif 116 104 117 faceVertices.push_back(vertices[indices[idx1]]); 105 118 faceVertices.push_back(vertices[indices[idx2]]); … … 172 185 geom->mTexcoordCount = (int)texCoords.size(); 173 186 174 cout << "number of vertices=" << numElements << endl;187 //cout << "number of vertices=" << numElements << endl; 175 188 176 189 for (int i = 0; i < numElements; ++ i) 177 190 { 178 #if 1179 191 // convert to our camera system: change y and z 180 192 geom->mVertices[i].x = vertices[i].x; … … 186 198 geom->mNormals[i].z = normals[i].y; 187 199 188 #else189 geom->mVertices[i].x = vertices[i].x;190 geom->mVertices[i].y = vertices[i].y;191 geom->mVertices[i].z = vertices[i].z;192 193 geom->mNormals[i].x = normals[i].x;194 geom->mNormals[i].y = normals[i].y;195 geom->mNormals[i].z = normals[i].z;196 197 #endif198 199 200 if (i < geom->mTexcoordCount) 200 201 { … … 229 230 if (!LoadSolution(bvhInputFilename)) 230 231 { 231 cerr << "could not read file" << endl;232 cerr << "could not read solution file" << endl; 232 233 return false; 233 234 } … … 255 256 256 257 257 bool VisibilitySolutionConverter::ReadScene(const string &filename) 258 bool VisibilitySolutionConverter::ReadScene(const string &filename) 259 { 260 VertexArray vertices; 261 VertexArray normals; 262 vector<TexCoord> texCoords; 263 264 if (ReadSimpleObj(filename, vertices, normals, texCoords)) 265 //if (ReadObj(filename, vertices, normals, texCoords)) 266 { 267 ConstructBvhObjects(vertices, normals, texCoords); 268 return true; 269 } 270 271 return false; 272 } 273 274 275 bool VisibilitySolutionConverter::ReadObj(const string &filename, 276 VertexArray &vertices, 277 VertexArray &normals, 278 vector<TexCoord> &texcoords) 258 279 { 259 280 FILE *file; 260 281 261 if ((file = fopen(filename.c_str(), "r")) == NULL) 262 { 263 return false; 264 } 265 266 VertexArray faceVertices; 267 VertexArray faceNormals; 268 vector<TexCoord> faceTexcoords; 269 270 VertexArray vertices; 271 VertexArray normals; 272 vector<TexCoord> texcoords; 282 if ((file = fopen(filename.c_str(), "r")) == NULL) return false; 283 284 VertexArray tempVertices; 285 VertexArray tempNormals; 286 vector<TexCoord> tempTexcoords; 273 287 274 288 vector<int> indices; … … 280 294 while (fgets(str, len, file) != NULL) 281 295 { 282 if (line % 1000000 == 0)296 if (line % 500000 == 0) 283 297 cout << line << " " << str << endl; 284 298 … … 291 305 float x, y, z; 292 306 293 if (vertices.size() >= 1000000* 3) continue;307 //if (tempVertices.size() >= maxVertices * 3) continue; 294 308 295 309 switch (str[1]) … … 297 311 case 'n' : 298 312 sscanf(str + 2, "%f %f %f", &x, &y, &z); 299 normals.push_back(SimpleVec(x, y, z));313 tempNormals.push_back(SimpleVec(x, y, z)); 300 314 break; 301 315 case 't': 302 316 sscanf(str + 2, "%f %f", &x, &y); 303 te xcoords.push_back(pair<float, float>(x, y));317 tempTexcoords.push_back(pair<float, float>(x, y)); 304 318 break; 305 319 default: … … 307 321 //const float scale = 5e-3f; 308 322 const float scale = 0.1f; 309 vertices.push_back(SimpleVec(x * scale, y * scale, z * scale));323 tempVertices.push_back(SimpleVec(x * scale, y * scale, z * scale)); 310 324 //cout <<"v " << x << " " << y << " "<< z << " "; 311 325 } … … 317 331 //-- indices in the current line 318 332 319 if (faceVertices.size() >= 1000000 * 3) continue; 320 333 //if (tempVertices.size() >= maxVertices * 3) continue; 321 334 LoadIndices(str, 322 vertices, normals, texcoords,323 faceVertices, faceNormals, faceTexcoords);335 tempVertices, tempNormals, tempTexcoords, 336 vertices, normals, texcoords); 324 337 325 338 break; … … 332 345 } 333 346 334 if (!faceVertices.empty())335 {336 ++ mNumShapes;337 338 ConstructBvhObjects(faceVertices, faceNormals, faceTexcoords);339 340 faceVertices.clear();341 faceNormals.clear();342 faceTexcoords.clear();343 }344 345 347 fclose(file); 346 347 return true; 348 } 348 349 return !vertices.empty(); 350 } 351 352 353 bool VisibilitySolutionConverter::ReadSimpleObj(const string &filename, 354 VertexArray &vertices, 355 VertexArray &normals, 356 vector<TexCoord> &texcoords) 357 { 358 const string binFilename = ReplaceSuffix(filename, ".obj", ".bn"); 359 360 if (!ReadBinObj(binFilename, vertices, 1)) 361 { 362 cout << "binary dump " << binFilename << " not available, loading ascii obj" << endl; 363 364 FILE *file; 365 if ((file = fopen(filename.c_str(), "r")) == NULL) return false; 366 367 int line = 0; 368 const int len = 10000; 369 char str[len]; 370 371 while (fgets(str, len, file) != NULL) 372 { 373 if (line % 500000 == 0) 374 cout << line << " " << str << endl; 375 376 ++ line; 377 378 switch (str[0]) 379 { 380 case 'v': // vertex or normal 381 { 382 float x, y, z; 383 384 sscanf(str + 1, "%f %f %f", &x, &y, &z); 385 const float scale = 0.1f; 386 vertices.push_back(SimpleVec(x * scale, y * scale, z * scale)); 387 break; 388 } 389 default: 390 // throw away line 391 break; 392 } 393 } 394 395 fclose(file); 396 397 cout << "dumping " << vertices.size() << " to binary " << binFilename << endl; 398 ExportBinObj(binFilename, vertices); 399 } 400 401 for (size_t i = 0; i < vertices.size(); i += 3) 402 { 403 // no face normals? => create normals 404 const SimpleTri tri(vertices[i + 0], 405 vertices[i + 1], 406 vertices[i + 2]); 407 408 const SimpleVec n = tri.GetNormal(); 409 410 normals.push_back(n); 411 normals.push_back(n); 412 normals.push_back(n); 413 } 414 415 return !vertices.empty(); 416 } 417 349 418 350 419 … … 473 542 const vector<TexCoord> &texCoords) 474 543 { 475 cout << "vtx: " << vertices.size() << endl; 544 VertexArray _vertices; 545 VertexArray _normals; 546 vector<TexCoord> _texCoords; 476 547 477 548 for (size_t i = 0; i < mBvhNodes.size(); ++ i) 478 549 { 479 VertexArray _vertices;480 VertexArray _normals;481 vector<TexCoord> _texCoords;482 483 550 BvhNode *node = mBvhNodes[i]; 484 551 485 552 //for (size_t j = 0; j < node->mTriangleIds.size(); ++ j) 486 for (int j = node->first; j < node->last; ++ j)553 for (int j = node->first; j <= node->last; ++ j) 487 554 { 488 555 const int idx = 3 * mGlobalTriangleIds[j]; 489 556 490 // cout << "idx: " << idx << " ";491 492 if (idx < 1000000 * 3)557 //if (idx >= maxVertices * 3) continue; 558 559 for (int k = 0; k < 3; ++ k) 493 560 { 494 for (int k = 0; k < 3; ++ k) 495 { 496 _vertices.push_back(vertices[idx + k]); 497 _normals.push_back(normals[idx + k]); 498 //_texCoords.push_back(texCoords[idx + k]); 499 } 561 _vertices.push_back(vertices[idx + k]); 562 _normals.push_back(normals[idx + k]); 563 //_texCoords.push_back(texCoords[idx + k]); 500 564 } 501 565 } … … 506 570 LoadShape(_vertices, _normals, _texCoords); 507 571 } 572 573 _vertices.clear(); 574 _normals.clear(); 575 _texCoords.clear(); 508 576 } 509 577 } … … 663 731 fread(&totalTime, sizeof(float), 1, fr); 664 732 665 //viewCellsTree = new ViewCellsTree; 666 //bool ok = viewCellsTree->_LoadFromFile(fr); 667 733 // just need to convert objects => read dummy visibility tree 668 734 bool ok = ReadDummyTree(fr); 669 735 670 if (ok) 671 { 672 //AllocateLeafViewCells(); 673 674 //objectsTree = new Bvh(*scene); 675 //ok = objectsTree->_LoadFromFile(fr); 676 ok = ReadBvh(fr); 677 678 /*if (ok) 679 { 680 AllocatePvsObjects(); 681 ok = LoadPvs(fr); 682 } 683 */ 684 } 736 // read bvh to optain objects (= the leaves of the bvh) 737 if (ok) ok = ReadBvh(fr); 685 738 686 739 fclose(fr); … … 695 748 696 749 697 #if 0 698 bool VisibilitySolution::LoadPvs(FILE *fw) 699 { 700 int number, entries; 701 702 fread(&number, sizeof(int), 1, fw); 703 704 if (number == 0) 705 { 706 Message("Info: Warning empty PVSs in visibility solution"); 707 return true; 708 } 709 710 if (number != viewCells.size()) 711 { 712 Message("Info: Number of view cells does not match when loading PVSs!"); 713 return false; 714 } 715 716 for (int i=0; i < number; i++) 717 { 718 fread(&entries, sizeof(int), 1, fw); 750 bool VisibilitySolutionConverter::ReadBinObj(const string &filename, 751 VertexArray &vertices, 752 float scale) 753 { 754 igzstream inStream(filename.c_str()); 755 756 if (!inStream.is_open()) return false; 757 758 cout << "binary obj dump available, loading " << filename.c_str() << endl; 759 760 // read in triangle size 761 int numTriangles; 762 763 const int t = 500000; 764 inStream.read(reinterpret_cast<char *>(&numTriangles), sizeof(int)); 765 vertices.reserve(numTriangles * 3); 766 cout << "loading " << numTriangles * 3 << " vertices (" 767 << numTriangles * 3 * sizeof(SimpleVec) / (1024 * 1024) << " MB)" << endl; 768 769 int i = 0; 770 771 while (1) 772 { 773 SimpleVec v; 719 774 720 for (int j=0; j < entries; j++) 721 { 722 int objectId; 723 float time; 724 fread(&objectId, sizeof(int), 1, fw); 725 fread(&time, sizeof(float), 1, fw); 726 viewCells[i]->pvs.Insert(objectId, time); 727 } 728 } 775 inStream.read(reinterpret_cast<char *>(&v), sizeof(SimpleVec)); 776 777 // end of file reached 778 if (inStream.eof()) break; 779 780 //v *= scale; 781 vertices.push_back(v); 782 783 if (((i ++) % t) == 0) 784 cout << "\r" << i << "/" << numTriangles * 3 << "\r"; 785 } 786 787 cout << "finished loading vertices" << endl; 788 789 if (i != numTriangles * 3) 790 cerr << "warning: " << numTriangles * 3 << " != " << i << endl; 791 792 inStream.close(); 793 729 794 return true; 730 795 } 731 796 732 797 733 bool ViewCellsTree::_LoadFromFile(FILE *fr) 734 { 735 int buffer[256]; 736 fread(buffer, sizeof(int), 3, fr); 737 738 if (buffer[0] != MAGIC) 739 { 740 Message( "Error: Wrong file type"); 741 return false; 742 } 743 744 if (buffer[1] != (int)(1000*VIEWCELLS_VERSION)) 745 { 746 Message( "Error: Wrong viewcells version" ); 747 748 return false; 749 } 750 751 // get the bounding box 752 fread(&box, sizeof(AxisAlignedBox3), 1, fr); 753 754 stack<ViewCellsTreeNode **> nodeStack; 755 nodeStack.push(&root); 756 757 while(!nodeStack.empty()) 758 { 759 ViewCellsTreeNode *&node = *nodeStack.top(); 760 761 nodeStack.pop(); 762 node = new ViewCellsTreeNode; 763 764 fread(&node->axis, sizeof(int), 1, fr); 765 766 if (!node->IsLeaf()) 767 { 768 fread(&node->position, sizeof(float), 1, fr); 769 770 nodeStack.push(&node->front); 771 nodeStack.push(&node->back); 772 } 773 } 774 798 bool VisibilitySolutionConverter::ExportBinObj(const string &filename, 799 const VertexArray &vertices) 800 { 801 ogzstream ofile(filename.c_str()); 802 if (!ofile.is_open()) return false; 803 804 int numTriangles = (int)vertices.size() / 3; 805 806 ofile.write(reinterpret_cast<char *>(&numTriangles), sizeof(int)); 807 808 VertexArray::const_iterator it, it_end = vertices.end(); 809 810 for (it = vertices.begin(); it != it_end; ++ it) 811 { 812 SimpleVec v = *it; 813 ofile.write(reinterpret_cast<char *>(&v), sizeof(SimpleVec)); 814 } 815 816 cout << "exported " << numTriangles * 3 << " vertices" << endl; 817 818 ofile.close(); 819 775 820 return true; 776 821 } 777 #endif -
GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.h
r3235 r3238 110 110 bool ReadDummyTree(FILE *fr); 111 111 112 bool ReadObj(const std::string &filename, 113 VertexArray &vertices, 114 VertexArray &normals, 115 std::vector<TexCoord> &texcoords); 116 117 bool ReadSimpleObj(const std::string &filename, 118 VertexArray &vertices, 119 VertexArray &normals, 120 std::vector<TexCoord> &texcoords); 112 121 122 bool ReadBinObj(const std::string &filename, 123 VertexArray &vertices, 124 float scale); 125 126 bool ExportBinObj(const std::string &filename, 127 const VertexArray &vertices); 113 128 114 129 ////////////////////////////////// -
GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/main.cpp
r3235 r3238 23 23 } 24 24 25 std::cin.get();25 //std::cin.get(); 26 26 cout << "conversion successful" << endl; 27 27 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
r3230 r3238 7 7 # misc stuff 8 8 9 filename=city 9 10 useLODs=1 10 11 # shadow map size -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp
r3114 r3238 50 50 if (tech->IsDepthWriteEnabled() != mBuckets[idx]->mDepthWriteEnabled) { return false; } 51 51 52 //if (tech->IsColorWriteEnabled()) cout << "x";53 54 52 const bool hasTexture = (tech->GetTexture() != NULL); 55 53 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r3237 r3238 109 109 int shapeId; 110 110 str.read(reinterpret_cast<char *>(&shapeId), sizeof(int)); 111 cout<<"x";112 111 113 112 Geometry *geom = mGeometryTable[shapeId]; 114 cout<<"y";115 116 113 Material *mat = mMaterialTable[shapeId]; 117 cout<<"z";118 114 // create shape 119 115 Shape *shape = new Shape(geom, mat); 120 cout<<"w";121 116 122 117 mShapes.push_back(shape); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp
r3236 r3238 15 15 mGeometry(geometry), 16 16 mMaterial(mat) 17 { std::cout<<"i";17 { 18 18 mCenter = GetBoundingBox().Center(); 19 std::cout<<"R";19 20 20 } 21 21 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3237 r3238 58 58 #include "WalkThroughRecorder.h" 59 59 #include "StatsWriter.h" 60 #include "Halton.h"61 60 62 61 … … 127 126 string statsFilename("stats"); 128 127 128 string filename("city"); 129 130 129 131 /// the walkThroughRecorder 130 132 WalkThroughRecorder *walkThroughRecorder = NULL; … … 428 430 env.GetStringParam(string("recordedFramesSuffix"), recordedFramesSuffix); 429 431 env.GetStringParam(string("statsFilename"), statsFilename); 432 env.GetStringParam(string("filename"), filename); 430 433 431 434 //env.GetStringParam(string("modelPath"), model_path); … … 458 461 cout << "recorded frames suffix: " << recordedFramesSuffix << endl; 459 462 cout << "stats filename: " << statsFilename << endl; 463 cout << "filename: " << filename << endl; 460 464 461 465 //cout << "model path: " << model_path << endl; … … 528 532 //-- load the static scene geometry 529 533 530 LoadModel( "city.dem", sceneEntities);534 LoadModel(filename + ".dem", sceneEntities); 531 535 532 536 … … 587 591 //-- load the associated static bvh 588 592 589 const string bvh_filename = string(model_path + "city.bvh");593 const string bvh_filename = string(model_path + filename + ".bvh"); 590 594 591 595 BvhLoader bvhLoader; … … 660 664 frameTimer.Start(); 661 665 662 Halton::TestHalton(7, 1); 663 Halton::TestHalton(7, 2); 664 665 HaltonSequence::TestHalton(15, 2); 666 HaltonSequence::TestHalton(15, 1); 667 668 Halton::TestPrime(); 666 //Halton::TestHalton(7, 2); 667 //HaltonSequence::TestHalton(15, 2); 668 //Halton::TestPrime(); 669 669 670 670 // the rendering loop
Note: See TracChangeset
for help on using the changeset viewer.