- Timestamp:
- 01/02/09 13:47:05 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp
r3239 r3241 1 1 #include "VisibilitySolutionConverter.h" 2 #include " SimpleTri.h"3 #include " SimpleVec.h"2 #include "Triangle3.h" 3 #include "Vector3.h" 4 4 #include "gzstream.h" 5 5 #include <iostream> … … 133 133 { 134 134 // no face normals? => create normals 135 const SimpleTri tri(vertices[indices[idx1]], 136 vertices[indices[idx2]], 137 vertices[indices[idx3]]); 138 139 const SimpleVec n = tri.GetNormal(); 135 const CHCDemoEngine::Triangle3 136 tri(vertices[indices[idx1]], 137 vertices[indices[idx2]], 138 vertices[indices[idx3]]); 139 140 const CHCDemoEngine::Vector3 n = tri.GetNormal(); 140 141 141 142 faceNormals.push_back(n); … … 182 183 183 184 // convert the triangles to geometry 184 geom->mVertices = new SimpleVec[numElements];185 geom->mNormals = new SimpleVec[numElements];185 geom->mVertices = new CHCDemoEngine::Vector3[numElements]; 186 geom->mNormals = new CHCDemoEngine::Vector3[numElements]; 186 187 geom->mTexCoords = new TexCoord[numElements]; 187 188 … … 244 245 } 245 246 247 // update bvh bounding boxes with loaded geometry 248 UpdateNodeBox(mRoot); 249 250 cout << "writing scene" << endl; 251 246 252 if (!WriteScene(sceneOutputFilename)) 247 253 { … … 249 255 return false; 250 256 } 257 258 cout << "writing bvh" << endl; 251 259 252 260 if (!WriteBvh(bvhOutputFilename)) … … 315 323 case 'n' : 316 324 sscanf(str + 2, "%f %f %f", &x, &y, &z); 317 tempNormals.push_back( SimpleVec(x, y, z));325 tempNormals.push_back(CHCDemoEngine::Vector3(x, y, z)); 318 326 break; 319 327 case 't': … … 325 333 //const float scale = 5e-3f; 326 334 const float scale = 0.1f; 327 tempVertices.push_back( SimpleVec(x * scale, y * scale, z * scale));335 tempVertices.push_back(CHCDemoEngine::Vector3(x * scale, y * scale, z * scale)); 328 336 //cout <<"v " << x << " " << y << " "<< z << " "; 329 337 } … … 388 396 sscanf(str + 1, "%f %f %f", &x, &y, &z); 389 397 const float scale = 0.1f; 390 vertices.push_back( SimpleVec(x * scale, y * scale, z * scale));398 vertices.push_back(CHCDemoEngine::Vector3(x * scale, y * scale, z * scale)); 391 399 break; 392 400 } … … 406 414 { 407 415 // no face normals? => create normals 408 const SimpleTritri(vertices[i + 0],409 vertices[i + 1], 410 vertices[i + 2]);411 412 const SimpleVecn = tri.GetNormal();416 const CHCDemoEngine::Triangle3 tri(vertices[i + 0], 417 vertices[i + 1], 418 vertices[i + 2]); 419 420 const CHCDemoEngine::Vector3 n = tri.GetNormal(); 413 421 414 422 normals.push_back(n); … … 433 441 str.write(reinterpret_cast<char *>(&vertexCount), sizeof(int)); 434 442 435 str.write(reinterpret_cast<char *>(geom->mVertices), sizeof( SimpleVec) * vertexCount);436 str.write(reinterpret_cast<char *>(geom->mNormals), sizeof( SimpleVec) * vertexCount);443 str.write(reinterpret_cast<char *>(geom->mVertices), sizeof(CHCDemoEngine::Vector3) * vertexCount); 444 str.write(reinterpret_cast<char *>(geom->mNormals), sizeof(CHCDemoEngine::Vector3) * vertexCount); 437 445 438 446 int texCoordCount = 0;//geom->mTexcoordCount; … … 463 471 if (hasMaterial) 464 472 { 465 SimpleVecambient, diffuse, spec, emm;473 CHCDemoEngine::Vector3 ambient, diffuse, spec, emm; 466 474 467 475 ambient.x = ambient.y = ambient.z = 0.2f; … … 472 480 diffuse.z = RandomColor(0.5f); 473 481 474 spec.x = spec.y = spec.z =.0f;482 spec.x = spec.y = spec.z = .0f; 475 483 emm = spec; 476 484 477 485 // only write rgb part of the material 478 str.write(reinterpret_cast<char *>(&ambient), sizeof( SimpleVec));479 str.write(reinterpret_cast<char *>(&diffuse), sizeof( SimpleVec));480 str.write(reinterpret_cast<char *>(&spec), sizeof( SimpleVec));481 str.write(reinterpret_cast<char *>(&emm), sizeof( SimpleVec));486 str.write(reinterpret_cast<char *>(&ambient), sizeof(CHCDemoEngine::Vector3)); 487 str.write(reinterpret_cast<char *>(&diffuse), sizeof(CHCDemoEngine::Vector3)); 488 str.write(reinterpret_cast<char *>(&spec), sizeof(CHCDemoEngine::Vector3)); 489 str.write(reinterpret_cast<char *>(&emm), sizeof(CHCDemoEngine::Vector3)); 482 490 } 483 491 } … … 550 558 vector<TexCoord> _texCoords; 551 559 552 for (size_t i = 0; i < mBvhNodes.size(); ++ i) 553 { 554 BvhNode *node = mBvhNodes[i]; 555 556 //for (size_t j = 0; j < node->mTriangleIds.size(); ++ j) 560 mGeometry.reserve(mBvhLeaves.size()); 561 562 mNumShapes = (int)mBvhLeaves.size(); 563 564 for (size_t i = 0; i < mBvhLeaves.size(); ++ i) 565 { 566 BvhLeaf *node = mBvhLeaves[i]; 567 557 568 for (int j = node->first; j <= node->last; ++ j) 558 569 { 559 570 const int idx = 3 * mGlobalTriangleIds[j]; 560 561 //if (idx >= maxVertices * 3) continue;562 571 563 572 for (int k = 0; k < 3; ++ k) … … 569 578 } 570 579 571 if (!_vertices.empty()) 572 { 573 ++ mNumShapes; 574 LoadShape(_vertices, _normals, _texCoords); 575 } 580 LoadShape(_vertices, _normals, _texCoords); 581 582 node->geometry = mGeometry.back(); 576 583 577 584 _vertices.clear(); … … 610 617 } 611 618 612 //if (mRoot) delete mRoot;619 const size_t numNodes = buffer[5]; 613 620 614 621 mNumNodes = 0; // this was set to 1 in constructor! … … 616 623 mRoot = LoadNode(fr, 0); 617 624 618 if (mNumNodes != buffer[5])625 if (mNumNodes != numNodes) 619 626 { 620 627 cerr << "Warning: Loaded " << mNumNodes << … … 625 632 626 633 return true; 634 } 635 636 637 void VisibilitySolutionConverter::UpdateLeafBox(BvhLeaf *leaf) 638 { 639 leaf->box.Initialize(); 640 641 Geometry *geom = leaf->geometry; 642 643 for (size_t i = 0; i < geom->mVertexCount; ++ i) 644 { 645 CHCDemoEngine::Vector3 v = geom->mVertices[i]; 646 leaf->box.Include(v); 647 } 627 648 } 628 649 … … 655 676 interior->front = front; 656 677 interior->back = back; 657 658 //interior->bmin = Minimize(front->bmin, back->bmin);659 //interior->bmax = Maximize(front->bmax, back->bmax);660 678 661 679 return (BvhNode *)interior; … … 664 682 { 665 683 // leaf 666 //Debug << "Info: Loading leaf (id: " << numberOfNodes << ", depth: " << depth << ")" << endl;667 684 BvhLeaf *leaf = new BvhLeaf(); 668 685 … … 673 690 674 691 leaf->depth = depth; 675 //UpdateLeafBox(leaf); 676 677 mBvhNodes.push_back(leaf); 692 693 mBvhLeaves.push_back(leaf); 678 694 679 695 return (BvhNode *)leaf; … … 765 781 vertices.reserve(numTriangles * 3); 766 782 cout << "loading " << numTriangles * 3 << " vertices (" 767 << numTriangles * 3 * sizeof(SimpleVec) /(1024 * 1024) << " MB)" << endl;783 << numTriangles * 3 * sizeof(CHCDemoEngine::Vector3) / (1024 * 1024) << " MB)" << endl; 768 784 769 785 int i = 0; … … 771 787 while (1) 772 788 { 773 SimpleVec v; 774 775 inStream.read(reinterpret_cast<char *>(&v), sizeof(SimpleVec)); 789 CHCDemoEngine::Vector3 v; 790 inStream.read(reinterpret_cast<char *>(&v), sizeof(CHCDemoEngine::Vector3)); 776 791 777 792 // end of file reached … … 810 825 for (it = vertices.begin(); it != it_end; ++ it) 811 826 { 812 SimpleVecv = *it;813 ofile.write(reinterpret_cast<char *>(&v), sizeof( SimpleVec));827 CHCDemoEngine::Vector3 v = *it; 828 ofile.write(reinterpret_cast<char *>(&v), sizeof(CHCDemoEngine::Vector3)); 814 829 } 815 830 … … 832 847 nodeType = TYPE_INTERIOR; 833 848 834 cerr << "error: wrong node type: " << nodeType << endl;835 836 849 stream.write(reinterpret_cast<char *>(&nodeType), sizeof(int)); 837 850 838 SimpleVec bMin, bMax; 851 CHCDemoEngine::Vector3 bMin = node->box.Min(); 852 CHCDemoEngine::Vector3 bMax = node->box.Max(); 839 853 840 854 stream.write(reinterpret_cast<char *>(&(node->first)), sizeof(int)); 841 855 stream.write(reinterpret_cast<char *>(&(node->last)), sizeof(int)); 842 856 843 stream.write(reinterpret_cast<char *>(&node->bmin), sizeof(SimpleVec)); 844 stream.write(reinterpret_cast<char *>(&node->bmax), sizeof(SimpleVec)); 857 stream.write(reinterpret_cast<char *>(&bMin), sizeof(CHCDemoEngine::Vector3)); 858 stream.write(reinterpret_cast<char *>(&bMin), sizeof(CHCDemoEngine::Vector3)); 859 } 860 861 862 void VisibilitySolutionConverter::UpdateNodeBox(BvhNode *node) 863 { 864 if (!node->IsLeaf()) 865 { 866 BvhInterior *interior = (BvhInterior *)node; 867 node->box = Union(interior->front->box, interior->back->box); 868 869 UpdateNodeBox(interior->front); 870 UpdateNodeBox(interior->back); 871 } 872 else 873 { 874 UpdateLeafBox((BvhLeaf *)node); 875 } 845 876 } 846 877 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.h
r3240 r3241 3 3 4 4 5 #include "SimpleVec.h" 5 #include "Vector3.h" 6 #include "Triangle3.h" 6 7 #include <string> 7 8 #include <vector> 8 9 #include "AxisAlignedBox3.h" 9 10 11 10 12 11 typedef std::vector< SimpleVec> VertexArray;13 typedef std::vector<CHCDemoEngine::Vector3> VertexArray; 12 14 typedef std::pair<float, float> TexCoord; 13 15 … … 15 17 16 18 struct BvhInterior; 19 20 21 22 struct Geometry 23 { 24 CHCDemoEngine::Vector3 *mVertices; 25 CHCDemoEngine::Vector3 *mNormals; 26 TexCoord *mTexCoords; 27 28 int mVertexCount; 29 int mTexcoordCount; 30 }; 31 17 32 18 33 struct BvhNode … … 36 51 int Count() const { return last - first + 1; } 37 52 38 SimpleVec bmin; 39 SimpleVec bmax; 53 CHCDemoEngine::AxisAlignedBox3 box; 40 54 41 55 BvhInterior *parent; … … 54 68 struct BvhLeaf: public BvhNode 55 69 { 56 //Color color; 57 int texture; 70 Geometry *geometry; 58 71 59 BvhLeaf(): BvhNode(), texture(0) {}72 BvhLeaf(): BvhNode(), geometry(NULL) {} 60 73 }; 61 74 … … 79 92 protected: 80 93 81 struct Geometry82 {83 SimpleVec *mVertices;84 SimpleVec *mNormals;85 TexCoord *mTexCoords;86 87 int mVertexCount;88 int mTexcoordCount;89 };90 94 91 95 void LoadShape(const VertexArray &vertices, … … 136 140 void WriteNextNode(ogzstream &stream, BvhNode *parent); 137 141 142 void UpdateLeafBox(BvhLeaf *leaf); 143 144 void UpdateNodeBox(BvhNode *node); 138 145 139 146 … … 146 153 std::vector<int> mGlobalTriangleIds; 147 154 148 std::vector<Bvh Node *> mBvhNodes;155 std::vector<BvhLeaf *> mBvhLeaves; 149 156 150 157 BvhNode *mRoot;
Note: See TracChangeset
for help on using the changeset viewer.