Changeset 3243
- Timestamp:
- 01/02/09 23:07:07 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r3242 r3243 651 651 </File> 652 652 <File 653 RelativePath=".\src\Pvs.cpp"654 >655 </File>656 <File657 653 RelativePath=".\src\RenderQueue.cpp" 658 654 > -
GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp
r3242 r3243 5 5 #include <iostream> 6 6 #include <queue> 7 #include <stack> 7 8 8 9 … … 416 417 { 417 418 // no face normals? => create normals 418 const CHCDemoEngine::Triangle3 tri(vertices[i + 0], 419 vertices[i + 1], 420 vertices[i + 2]); 419 const CHCDemoEngine::Triangle3 420 tri(vertices[i], vertices[i + 1], vertices[i + 2]); 421 421 422 422 const CHCDemoEngine::Vector3 n = tri.GetNormal(); … … 498 498 ogzstream ofile(filename.c_str()); 499 499 500 if (!ofile.is_open()) 501 return false; 502 503 500 if (!ofile.is_open()) return false; 501 504 502 int textureCount = 0; 505 503 ofile.write(reinterpret_cast<char *>(&textureCount), sizeof(int)); … … 541 539 ofile.write(reinterpret_cast<char *>(&dist), sizeof(float)); 542 540 543 int shapesPerEnt = 1;544 ofile.write(reinterpret_cast<char *>(&shapesPerEnt ), sizeof(int));541 int shapesPerEntity = 1; 542 ofile.write(reinterpret_cast<char *>(&shapesPerEntity), sizeof(int)); 545 543 546 544 int shapeId = i; … … 765 763 bool ok = ReadDummyTree(fr); 766 764 767 // read bvh to optainobjects (= the leaves of the bvh)765 // read bvh to determine objects (= the leaves of the bvh) 768 766 if (ok) ok = ReadBvh(fr); 769 767 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.h
r3242 r3243 144 144 145 145 146 146 147 ////////////////////////////////// 147 148 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
r3242 r3243 16 16 statsFilename=mystats.log 17 17 18 visibilitySolution=vienna_full-8x3-refu 18 19 19 20 ############ -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.h
r3202 r3243 104 104 /** Sets the minimum for one dimension. 105 105 */ 106 void SetMin(int axis, constfloat value);106 void SetMin(int axis, float value); 107 107 /** Sets the maximum for one dimension. 108 108 */ 109 void SetMax(int axis, constfloat value);109 void SetMax(int axis, float value); 110 110 /** Decrease box by given splitting plane 111 111 */ -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h
r3123 r3243 154 154 */ 155 155 inline int CountPrimitives() const; 156 /** This is an imporantent function once you have one or more157 view po int changeswithin a frame (e.g., camera view and shadow view for156 /** This function is important in case you have more than one 157 view position within a frame (e.g., camera view and shadow view for 158 158 shadow mapping), because each camera needs its own state in 159 159 order to not break temporal coherency. 160 160 */ 161 inline static void SetCurrentState(int _state) { sCurrentState = _state; }161 inline static void SetCurrentState(int _state); 162 162 163 163 … … 180 180 /// stores the visibility related info 181 181 VisibilityInfo mVisibility[NUM_STATES]; 182 183 // members used to speed up view frustum culling 182 /// when the node was last rendered 183 int mLastRenderedFrame[NUM_STATES]; 184 185 186 /////////////// 187 //-- members that help to speed up view frustum culling 188 184 189 /// masks out planes of the frustum that do not have to be tested against 185 190 int mPlaneMask[NUM_STATES]; … … 188 193 */ 189 194 int mPreferredPlane[NUM_STATES]; 190 /// when the node was last rendered 191 int mLastRenderedFrame[NUM_STATES]; 195 192 196 193 197 //////////////////// … … 406 410 407 411 412 void BvhNode::SetCurrentState(int _state) 413 { 414 sCurrentState = _state; 415 } 416 408 417 409 418 /** Internal node of the bv hierarchy. -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Pvs.h
r3242 r3243 2 2 #define __PVS_H 3 3 4 4 #include "common.h" 5 6 5 7 namespace CHCDemoEngine 6 8 { … … 14 16 public: 15 17 16 Pvs() : mEntries() {18 Pvs() {}; 17 19 18 entries.set_deleted_key(-1); 19 entries.set_empty_key(-2); 20 void Clear() { mEntries.clear(); } 20 21 21 };22 bool Empty() const { return mEntries.empty(); } 22 23 23 int GetSize() const { 24 return (int)entries.size(); 25 } 24 SceneEntity *GetEntry(int i) const { return mEntries[i]; } 25 26 int Size() { return (int)mEntries.size(); } 27 28 void AddEntry(SceneEntity *ent) { mEntries.push_back(ent); } 26 29 27 30 28 bool Empty() const { 29 return entries.empty(); 30 } 31 protected: 31 32 32 /** Adds object to PVS.33 @returns contribution of sample (0 or 1)34 */35 bool Insert(const int id, const float time = 0.0f) {36 37 pair<PVS_ITERATOR, bool> result = entries.insert(pair<int, float>(id,time));38 39 return result.second;40 }41 42 bool Find(const int id) {43 PVS_ITERATOR it;44 return Find(id, it);45 }46 47 bool Find(const int id, PVS_ITERATOR &it) {48 it = entries.find(id);49 50 // already in map51 return (it != entries.end());52 }53 54 void Clear() {55 entries.clear();56 }57 58 static void Merge(Pvs &mergedPvs,59 const Pvs &a,60 const Pvs &b)61 {62 mergedPvs.entries.insert(a.entries.begin(), a.entries.end());63 mergedPvs.entries.insert(b.entries.begin(), b.entries.end());64 }65 66 // just an estimate - could not find proper reference how to67 // calculate memory occupied by hash_map and hash_set!68 int GetMemoryUsage() const {69 70 return sizeof(Pvs) + sizeof(HASH_SET::value_type)*entries.bucket_count();71 }72 73 protected:74 33 /// hash table of PVS entries 75 HASH_SET entries; 76 34 SceneEntityContainer mEntries; 77 35 }; 78 36 79 80 /** Iterator over a hash pvs.81 */82 class PvsIterator83 {84 protected:85 86 CONST_PVS_ITERATOR itCurrent;87 CONST_PVS_ITERATOR itEnd;88 89 public:90 91 PvsIterator() {}92 93 PvsIterator(Pvs &pvs):94 itCurrent(pvs.entries.begin()), itEnd(pvs.entries.end())95 {96 }97 98 bool HasMoreEntries() const99 {100 return (itCurrent != itEnd);101 }102 103 void Next() {104 ++itCurrent;105 }106 107 int Current() const {108 109 return (*itCurrent).first;110 111 }112 float CurrentTime() const {113 114 return (*itCurrent).second;115 116 }117 118 };119 120 #if 0121 // iterator of the PVS at the given time stamp122 // onnly works properly in PVS_TIME_STAMPS is defined123 // otherwise behaves the same as PvsIterator124 125 class PvsTimeIterator : public PvsIterator126 {127 protected:128 float time;129 public:130 131 PvsTimeIterator(Pvs &pvs, const float _time):132 PvsIterator(pvs), time(_time)133 {134 // find the first entry satisfying the time constraint135 for (;HasMoreEntries(); ++itCurrent)136 if ((*itCurrent).second <= time)137 break;138 }139 140 void Next() {141 for (++itCurrent; HasMoreEntries(); ++itCurrent)142 if ((*itCurrent).second <= time)143 break;144 }145 146 };147 148 #endif149 37 } 150 38 151 39 #endif 152 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h
r3120 r3243 112 112 static bool GetUseLODs() { return sUseLODs; } 113 113 114 115 int mId;116 117 114 protected: 118 115 … … 143 140 /// the center of gravity of this entity 144 141 Vector3 mCenter; 142 143 int mId; 145 144 146 145 static bool sUseLODs; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.cpp
r3242 r3243 2 2 #include "Timer/PerfTimer.h" 3 3 #include <stack> 4 #include <string> 4 5 5 6 using namespace std; 6 7 7 8 9 // MAGIC of all bin exports 10 #ifndef MAGIC 11 #define MAGIC 0x827923 12 #endif 13 14 #define VIEWCELLS_VERSION 1.0f 15 8 16 namespace CHCDemoEngine 9 17 { 10 18 19 11 20 ViewCell *ViewCellsTree::GetViewCell(const Vector3 &point) const 12 21 { 13 ViewCellsTreeNode *node = root;22 ViewCellsTreeNode *node = mRoot; 14 23 15 24 while (!node->IsLeaf()) 16 25 { 17 if (point[node-> axis] < node->position)18 node = node-> back;26 if (point[node->mAxis] < node->mPosition) 27 node = node->mBack; 19 28 else 20 node = node-> front;29 node = node->mFront; 21 30 } 22 31 23 return node-> viewCell;32 return node->mViewCell; 24 33 } 25 34 26 35 27 bool ViewCellsTree::LoadFromFile(const st ring &filename)36 bool ViewCellsTree::LoadFromFile(const std::string &filename) 28 37 { 29 cout << ("Info: Loading view cells from file '" + filename + "'" );38 cout << "Info: Loading view cells from file '" + filename + "'"; 30 39 31 40 FILE *fr = fopen(filename.c_str(), "rb"); 32 41 33 if (fr == NULL) { 34 Message("Error: Cannot open file for reading"); 42 if (!fr) 43 { 44 cerr << "Error: Cannot open file for reading" << endl; 35 45 return false; 36 46 } … … 38 48 bool result = _LoadFromFile(fr); 39 49 40 Debug<< "Info: done. " << endl;50 cout << "Info: done. " << endl; 41 51 fclose(fr); 42 52 … … 50 60 fread(buffer, sizeof(int), 3, fr); 51 61 52 if (buffer[0] != MAGIC) { 53 Message( "Error: Wrong file type"); 62 if (buffer[0] != MAGIC) 63 { 64 cerr << "Error: Wrong file type" << endl; 54 65 return false; 55 66 } 56 67 57 if (buffer[1] != (int)(1000*VIEWCELLS_VERSION)) { 58 Message( "Error: Wrong viewcells version" ); 68 if (buffer[1] != (int)(1000 * VIEWCELLS_VERSION)) 69 { 70 cerr << "Error: Wrong viewcells version" << endl; 59 71 return false; 60 72 } 61 73 62 74 // get the bounding box 63 fread(& box, sizeof(AxisAlignedBox3), 1, fr);75 fread(&mBox, sizeof(AxisAlignedBox3), 1, fr); 64 76 65 77 stack<ViewCellsTreeNode **> nodeStack; 66 78 67 nodeStack.push(& root);79 nodeStack.push(&mRoot); 68 80 69 while(!nodeStack.empty()) { 81 while (!nodeStack.empty()) 82 { 70 83 ViewCellsTreeNode *&node = *nodeStack.top(); 71 84 nodeStack.pop(); 72 node = new ViewCellsTreeNode; 73 fread(&node->axis, sizeof(int), 1, fr); 74 if (!node->IsLeaf()) { 75 fread(&node->position, sizeof(float), 1, fr); 76 nodeStack.push(&node->front); 77 nodeStack.push(&node->back); 85 node = new ViewCellsTreeNode(); 86 87 fread(&node->mAxis, sizeof(int), 1, fr); 88 89 if (!node->IsLeaf()) 90 { 91 fread(&node->mPosition, sizeof(float), 1, fr); 92 nodeStack.push(&node->mFront); 93 nodeStack.push(&node->mBack); 78 94 } 79 95 } … … 83 99 84 100 85 void ViewCellsTree::_ExportToFile(FILE *file)86 {87 int buffer[256];88 int i=0;89 buffer[i++] = MAGIC;90 buffer[i++] = VIEWCELLS_VERSION*1000;91 92 fwrite(buffer, sizeof(int), i, file);93 94 fwrite(&mMaxDepth, sizeof(float), 1, file);95 96 fwrite(&box, sizeof(AxisAlignedBox3), 1, file);97 98 stack<ViewCellsTreeNode *> nodeStack;99 100 nodeStack.push(root);101 102 while (!nodeStack.empty()) {103 ViewCellsTreeNode *node = nodeStack.top();104 nodeStack.pop();105 106 fwrite(&node->axis, sizeof(int), 1, file);107 if (!node->IsLeaf()) {108 fwrite(&node->position, sizeof(float), 1, file);109 nodeStack.push(node->front);110 nodeStack.push(node->back);111 }112 }113 101 } 114 115 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.h
r3242 r3243 5 5 #include "Pvs.h" 6 6 #include "AxisAlignedBox3.h" 7 7 #include "common.h" 8 8 9 9 … … 19 19 ViewCell(): mPvs() {} 20 20 21 int GetId() const { return mId; } 22 23 void SetId(int id) { mId = id; } 24 25 void SetBox(const AxisAlignedBox3 &box) { mBox = box; } 26 27 28 // the pvs associated with the viewcell 29 Pvs mPvs; 30 21 31 protected: 22 32 … … 25 35 // bounding box of the viewcell 26 36 AxisAlignedBox3 mBox; 27 // the pvs associated with the viewcell28 Pvs mPvs;29 30 37 }; 31 38 … … 33 40 struct ViewCellsTreeNode 34 41 { 35 union36 {37 // split position - 4B38 float position;39 // the viewcell associated with this node (NULL for non terminal nodes) - 4B40 ViewCell *viewCell;41 };42 43 44 42 ViewCellsTreeNode(): mAxis(-1), mViewCell(NULL) {} 45 43 46 bool IsLeaf() { return mAxis == -1; } 47 48 bool IsVirtualLeaf() { return mViewCell != NULL; } 44 bool IsLeaf() { return mViewCell != NULL; } 49 45 50 46 51 47 /////////////////////// 52 48 53 // children of the node - 8B 54 ViewCellsTreeNode *mBack, *mFront; 49 union 50 { 51 // split position - 4B 52 float mPosition; 53 // the viewcell associated with this node (NULL for non terminal nodes) 54 ViewCell *mViewCell; 55 }; 55 56 56 // kd tree split params 57 // split axis - 4B 57 /// children of the node 58 ViewCellsTreeNode *mBack; 59 ViewCellsTreeNode *mFront; 60 61 /// split mAxis 58 62 int mAxis; 59 63 }; … … 62 66 class ViewCellsTree 63 67 { 68 friend class VisibilitySolutionLoader; 69 64 70 public: 65 71 … … 77 83 ViewCell *GetViewCell(const Vector3 &point) const; 78 84 79 bool LoadFromFile(const st ring &filename);85 bool LoadFromFile(const std::string &filename); 80 86 81 87 … … 87 93 //////////////////////// 88 94 89 float mMaxDepth;95 int mMaxDepth; 90 96 AxisAlignedBox3 mBox; 91 97 ViewCellsTreeNode *mRoot; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp
r3242 r3243 1 1 #include "VisibilitySolutionLoader.h" 2 #include "ViewCellsTree.h" 3 #include "Bvh.h" 4 #include <stack> 2 5 3 6 … … 8 11 { 9 12 10 bool VisibilitySolutionLoader::Load(const std::string &filename 11 ViewCellsTree *viewCells) 13 14 typedef vector<ViewCell *> ViewCellsContainer; 15 16 17 ViewCellsTree *VisibilitySolutionLoader::Load(const std::string &filename, 18 Bvh *bvh) 12 19 { 20 FILE *fr = fopen(filename.c_str(), "rb"); 21 22 cout << "Info: Loading visibility solution from file '" + filename + "'" << endl; 23 24 if (fr == NULL) 25 { 26 cerr << "Error: Cannot open file for reading" << endl; 27 return NULL; 28 } 29 30 float totalSamples; 31 float totalTime; 32 33 fread(&totalSamples, sizeof(float), 1, fr); 34 fread(&totalTime, sizeof(float), 1, fr); 35 36 ViewCellsTree *viewCellsTree = new ViewCellsTree(); 37 38 bool ok = viewCellsTree->_LoadFromFile(fr); 39 40 if (ok) 41 { 42 // skip bvh loading 43 int buffer[6]; 44 fread(buffer, sizeof(int), 6, fr); 45 46 const size_t numNodes = buffer[5]; 47 48 for (int i = 0; i < numNodes; ++ i) 49 fread(buffer, sizeof(int), 4, fr); 50 51 AllocateLeafViewCells(viewCellsTree); 52 53 ok = LoadPvs(fr, bvh); 54 } 55 56 fclose(fr); 57 58 if (ok) 59 cerr << "Info: visibility solution loaded" << endl; 60 else 61 cerr << "Info: loading visibility solution failed." << endl; 62 63 return viewCellsTree; 64 } 65 66 67 bool VisibilitySolutionLoader::CreateIdSortedList(Bvh *bvh, BvhNodeContainer &nodes) 68 { 69 std::stack<BvhNode *> tStack; 70 tStack.push(bvh->GetRoot()); 71 72 while (!tStack.empty()) 73 { 74 BvhNode *node = tStack.top(); 75 tStack.pop(); 76 77 nodes.push_back(node); 78 79 if (!node->IsLeaf()) 80 { 81 BvhInterior *interior = static_cast<BvhInterior *>(node); 82 83 BvhNode *front = interior->GetFront(); 84 BvhNode *back = interior->GetBack(); 85 86 tStack.push(front); 87 tStack.push(back); 88 } 89 } 90 13 91 return true; 14 92 } 15 93 94 95 bool VisibilitySolutionLoader::LoadPvs(FILE *fw, Bvh *bvh) 96 { 97 int number, entries; 98 99 fread(&number, sizeof(int), 1, fw); 100 101 if (number == 0) 102 { 103 cerr << "Info: Warning empty PVSs in visibility solution" << endl; 104 return true; 105 } 106 107 if (number != mViewCells.size()) 108 { 109 cerr << "Info: Number of view cells does not match when loading PVSs!" << endl; 110 return false; 111 } 112 113 BvhNodeContainer nodes; 114 CreateIdSortedList(bvh, nodes); 115 116 for (int i = 0; i < number; ++ i) 117 { 118 fread(&entries, sizeof(int), 1, fw); 119 120 for (int j=0; j < entries; ++ j) 121 { 122 int objectId; 123 float time; 124 125 fread(&objectId, sizeof(int), 1, fw); 126 fread(&time, sizeof(float), 1, fw); 127 128 BvhNode *node = nodes[objectId]; 129 130 int geometrySize; 131 SceneEntity **entities; 132 entities = bvh->GetGeometry(node, geometrySize); 133 134 for (int k = 0; k < geometrySize; ++ k) 135 { 136 mViewCells[i]->mPvs.AddEntry(entities[k]); 137 } 138 } 139 } 140 141 return true; 16 142 } 143 144 145 void VisibilitySolutionLoader::AllocateLeafViewCells(ViewCellsTree *viewCellsTree) 146 { 147 stack< pair<ViewCellsTreeNode *, AxisAlignedBox3> > nodeStack; 148 149 nodeStack.push(pair<ViewCellsTreeNode *, AxisAlignedBox3> 150 (viewCellsTree->mRoot, viewCellsTree->mBox)); 151 152 int id = 0; 153 154 mViewCells.clear(); 155 156 while (!nodeStack.empty()) 157 { 158 ViewCellsTreeNode *node = nodeStack.top().first; 159 160 if (node->IsLeaf()) 161 { 162 if (node->mViewCell == NULL) 163 { 164 node->mViewCell = new ViewCell(); 165 node->mViewCell->SetId(id ++); 166 node->mViewCell->SetBox(nodeStack.top().second); 167 } 168 169 mViewCells.push_back(node->mViewCell); 170 171 nodeStack.pop(); 172 } 173 else 174 { 175 AxisAlignedBox3 box = nodeStack.top().second; 176 nodeStack.pop(); 177 178 AxisAlignedBox3 newBox = box; 179 newBox.SetMin(node->mAxis, node->mPosition); 180 181 nodeStack.push( 182 pair<ViewCellsTreeNode *, AxisAlignedBox3>(node->mFront, newBox) 183 ); 184 185 newBox = box; 186 newBox.SetMax(node->mAxis, node->mPosition); 187 188 nodeStack.push( 189 pair<ViewCellsTreeNode *, AxisAlignedBox3>(node->mBack, newBox) 190 ); 191 } 192 } 193 194 cout << "#of viewcells = " << id << endl; 195 } 196 197 198 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.h
r3242 r3243 2 2 #define _VISIBILITYSOLUTIONLOADER_H 3 3 4 #include "common.h" 5 6 7 namespace CHCDemoEngine 8 { 4 9 5 10 class ViewCellsTree; 6 7 namespace CHCDemoEngine 8 { 11 struct ViewCell; 12 class Bvh; 13 14 typedef std::vector<ViewCell *> ViewCellsContainer; 15 9 16 10 17 /** Loads a preprocessed visibility solution. … … 14 21 public: 15 22 16 VisibilitySolutionLoader() ;23 VisibilitySolutionLoader(): mNumNodes(0) {}; 17 24 18 ~VisibilitySolutionLoader();25 ViewCellsTree *Load(const std::string &filename, Bvh *bvh); 19 26 20 bool Load(const std::string &filename21 ViewCellsTree *viewCells);22 27 23 28 protected: 29 /** Creates list of bvh nodes where the index 30 is equivalent to the id of this node in the bvh. 31 */ 32 bool CreateIdSortedList(Bvh *bvh, BvhNodeContainer &nodes); 33 34 bool LoadPvs(FILE *fw, Bvh *bvh); 35 36 void AllocateLeafViewCells(ViewCellsTree *viewCellsTree); 37 38 39 /////////////// 24 40 25 41 int mNumNodes; 42 43 ViewCellsContainer mViewCells; 26 44 }; 27 45 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3242 r3243 58 58 #include "WalkThroughRecorder.h" 59 59 #include "StatsWriter.h" 60 #include "VisibilitySolutionLoader.h" 61 #include "ViewCellsTree.h" 60 62 61 63 … … 127 129 128 130 string filename("city"); 131 string visibilitySolution(""); 129 132 130 133 … … 430 433 env.GetStringParam(string("statsFilename"), statsFilename); 431 434 env.GetStringParam(string("filename"), filename); 435 env.GetStringParam(string("visibilitySolution"), visibilitySolution); 432 436 433 437 //env.GetStringParam(string("modelPath"), model_path); … … 461 465 cout << "stats filename: " << statsFilename << endl; 462 466 cout << "filename: " << filename << endl; 467 cout << "visibilitySolution: " << visibilitySolution << endl; 468 463 469 464 470 //cout << "model path: " << model_path << endl; … … 604 610 /// set the depth of the bvh depending on the triangles per leaf node 605 611 bvh->SetVirtualLeaves(trianglesPerVirtualLeaf); 612 613 /////////// 614 //-- load the visibility solution 615 616 const string vis_filename = 617 string(model_path + visibilitySolution + ".vis"); 618 619 VisibilitySolutionLoader visLoader; 620 621 ViewCellsTree *viewCellsTree = visLoader.Load(vis_filename, bvh); 622 606 623 607 624 // set far plane based on scene extent
Note: See TracChangeset
for help on using the changeset viewer.