Changeset 3244
- Timestamp:
- 01/03/09 17:32:10 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r3236 r3244 1161 1161 mBox = mRoot->GetBox(); 1162 1162 1163 // compute and print stats 1163 // compute and print stats for whole (static + dynamic) bvh 1164 1164 ComputeBvhStats(mRoot, mBvhStats); 1165 1165 PrintBvhStats(mBvhStats); 1166 1166 1167 // also output dynamic stats 1167 1168 if (mDynamicGeometrySize) 1168 1169 { … … 1475 1476 l->mArea = l->mBox.SurfaceArea(); 1476 1477 1477 cout << " updating dynamic branch " << l->mFirst << " " << l->mLast<< endl;1478 cout << "creating dynamic bvh branch" << endl; 1478 1479 1479 1480 if (mDynamicGeometrySize) -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp
r3242 r3244 72 72 if (!stream.is_open()) return NULL; 73 73 74 cout << " loading bvh" << endl;74 cout << "\n*******************\nloading bvh ..." << endl; 75 75 76 76 Bvh *bvh = new Bvh(staticEntities, dynamicEntities, maxDepthForTestingChildren); … … 82 82 bvh->mNumNodes = 3; 83 83 84 cout << " *******************\nbox: " << root->mBox << " area: " << root->mArea<< endl;84 cout << "static bvh bb: " << root->mBox << endl; 85 85 86 86 tQueue.push(root); … … 111 111 } 112 112 113 cout << "... finished loading " << bvh->mNumNodes - 2 << " static bvh nodes" << endl; 114 115 113 116 /////////// 114 117 //-- create dynamic part of the hierarchy … … 121 124 bvh->PostProcess(); 122 125 123 cout << "... finished loading " << bvh->mNumNodes << " nodes" << endl; 124 cout << "scene box: " << bvh->mBox << endl; 126 cout << "bvh bb: " << bvh->mBox << endl; 125 127 126 128 return bvh; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
r3102 r3244 55 55 mRenderDynamicObjects(true) 56 56 { 57 mStats.Reset(); 57 58 } 58 59 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.cpp
r3243 r3244 24 24 while (!node->IsLeaf()) 25 25 { 26 //cout << "pt: " << point[node->mAxis] << " " << node->mPosition << endl; 26 27 if (point[node->mAxis] < node->mPosition) 27 28 node = node->mBack; … … 29 30 node = node->mFront; 30 31 } 32 33 //cout << "vc: " << node->mViewCell->GetBox() << " pvs " << node->mViewCell->mPvs.Size() << endl; 31 34 32 35 return node->mViewCell; … … 36 39 bool ViewCellsTree::LoadFromFile(const std::string &filename) 37 40 { 38 cout << " Info:Loading view cells from file '" + filename + "'";41 cout << "Loading view cells from file '" + filename + "'"; 39 42 40 43 FILE *fr = fopen(filename.c_str(), "rb"); … … 48 51 bool result = _LoadFromFile(fr); 49 52 50 cout << " Info: done. " << endl;53 cout << "finished loading view cells. " << endl; 51 54 fclose(fr); 52 55 … … 58 61 { 59 62 int buffer[256]; 60 fread(buffer, sizeof(int), 3, fr);63 fread(buffer, sizeof(int), 2, fr); 61 64 62 65 if (buffer[0] != MAGIC) … … 75 78 fread(&mBox, sizeof(AxisAlignedBox3), 1, fr); 76 79 80 Vector3 v1(mBox.Min().x, -mBox.Min().z, mBox.Min().y); 81 Vector3 v2(mBox.Max().x, -mBox.Max().z, mBox.Max().y); 82 83 Vector3 newMin = v1; 84 Vector3 newMax = v2; 85 86 Minimize(newMin, v2); 87 Maximize(newMax, v1); 88 89 mBox.SetMin(newMin); 90 mBox.SetMax(newMax); 91 77 92 stack<ViewCellsTreeNode **> nodeStack; 93 nodeStack.push(&mRoot); 78 94 79 nodeStack.push(&mRoot); 95 cout << "view cells bounds " << mBox << endl; 96 97 int numViewCells = 0; 80 98 81 99 while (!nodeStack.empty()) … … 85 103 node = new ViewCellsTreeNode(); 86 104 87 fread(&node->mAxis, sizeof(int), 1, fr); 105 ++ numViewCells; 106 107 int axis; 108 fread(&axis, sizeof(int), 1, fr); 109 110 // exchange y and z axis like we have to do for the scene 111 if (axis == 2) axis = 1; 112 else if (axis == 1) axis = 2; 113 114 node->mAxis = axis; 115 116 if (node->mAxis > 2 || node->mAxis < -1) cout << "a " << node->mAxis << " "; 88 117 89 118 if (!node->IsLeaf()) 90 119 { 91 fread(&node->mPosition, sizeof(float), 1, fr); 120 float pos; 121 fread(&pos, sizeof(float), 1, fr); 122 123 if (axis == 1) pos = -pos; 124 node->mPosition = pos; 125 92 126 nodeStack.push(&node->mFront); 93 127 nodeStack.push(&node->mBack); … … 95 129 } 96 130 131 cout << "loaded " << numViewCells << " view cells" << endl; 97 132 return true; 98 133 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.h
r3243 r3244 25 25 void SetBox(const AxisAlignedBox3 &box) { mBox = box; } 26 26 27 AxisAlignedBox3 GetBox() const { return mBox; } 27 28 28 29 // the pvs associated with the viewcell … … 42 43 ViewCellsTreeNode(): mAxis(-1), mViewCell(NULL) {} 43 44 44 bool IsLeaf() { return m ViewCell != NULL; }45 bool IsLeaf() { return mAxis == -1; } 45 46 46 47 47 48 /////////////////////// 49 50 /// split mAxis 51 int mAxis; 48 52 49 53 union … … 58 62 ViewCellsTreeNode *mBack; 59 63 ViewCellsTreeNode *mFront; 60 61 /// split mAxis62 int mAxis;63 64 }; 64 65 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp
r3243 r3244 20 20 FILE *fr = fopen(filename.c_str(), "rb"); 21 21 22 cout << " Info:Loading visibility solution from file '" + filename + "'" << endl;22 cout << "Loading visibility solution from file '" + filename + "'" << endl; 23 23 24 24 if (fr == NULL) … … 34 34 fread(&totalTime, sizeof(float), 1, fr); 35 35 36 cout << "loading view cells" << endl; 37 36 38 ViewCellsTree *viewCellsTree = new ViewCellsTree(); 37 39 38 40 bool ok = viewCellsTree->_LoadFromFile(fr); 41 42 cout << "finished loading view cells" << endl; 43 39 44 40 45 if (ok) 41 46 { 42 // skip bvh loading47 // skip loading of bvh nodes 43 48 int buffer[6]; 44 49 fread(buffer, sizeof(int), 6, fr); 45 50 46 const size_t numNodes = buffer[5]; 47 51 const int numNodes = buffer[5]; 52 const int numTriangleIds = buffer[2]; 53 54 // skip triangle ids 55 cout << "skipping " << numTriangleIds << " triangle ids" << endl; 56 57 int tid; 58 for (int i = 0; i < numTriangleIds; ++ i) 59 fread(&tid, sizeof(int), 1, fr); 60 61 cout << "skipping " << numNodes << " bvh nodes" << endl; 62 48 63 for (int i = 0; i < numNodes; ++ i) 49 64 fread(buffer, sizeof(int), 4, fr); 50 65 66 67 cout << "allocating view cells" << endl; 68 51 69 AllocateLeafViewCells(viewCellsTree); 52 70 71 cout << "loading pvss" << endl; 72 53 73 ok = LoadPvs(fr, bvh); 74 75 cout << "finished loading pvss" << endl; 54 76 } 55 77 … … 57 79 58 80 if (ok) 59 c err << "Info: visibility solution loaded" << endl;81 cout << "Visibility solution loaded" << endl; 60 82 else 61 cerr << " Info: loading visibility solution failed." << endl;83 cerr << "Error: loading visibility solution failed." << endl; 62 84 63 85 return viewCellsTree; … … 99 121 fread(&number, sizeof(int), 1, fw); 100 122 101 if ( number == 0)102 { 103 cerr << " Info: Warningempty PVSs in visibility solution" << endl;123 if (!number) 124 { 125 cerr << "Warning: empty PVSs in visibility solution" << endl; 104 126 return true; 105 127 } … … 107 129 if (number != mViewCells.size()) 108 130 { 109 cerr << " Info: Number of view cellsdoes not match when loading PVSs!" << endl;131 cerr << "Warning: Number of view cells (" << number << ", " << (int)mViewCells.size() << ") does not match when loading PVSs!" << endl; 110 132 return false; 111 133 } … … 160 182 if (node->IsLeaf()) 161 183 { 162 if ( node->mViewCell == NULL)184 if (!node->mViewCell) 163 185 { 164 186 node->mViewCell = new ViewCell(); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3243 r3244 139 139 bool makeSnapShot = false; 140 140 141 ViewCellsTree *viewCellsTree = NULL; 142 141 143 142 144 /// the technique used for rendering … … 267 269 int maxBatchSize = 50; 268 270 int trianglesPerVirtualLeaf = INITIAL_TRIANGLES_PER_VIRTUAL_LEAVES; 271 269 272 270 273 ////////////// … … 349 352 SceneQuery *GetOrCreateSceneQuery(); 350 353 354 void RenderPvs(); 355 351 356 352 357 // new view projection matrix of the camera … … 619 624 VisibilitySolutionLoader visLoader; 620 625 621 ViewCellsTree *viewCellsTree = visLoader.Load(vis_filename, bvh);626 viewCellsTree = visLoader.Load(vis_filename, bvh); 622 627 623 628 … … 1249 1254 { 1250 1255 // actually render the scene geometry using the specified algorithm 1251 traverser->RenderScene(); 1256 //traverser->RenderScene(); 1257 1258 RenderPvs(); 1252 1259 } 1253 1260 … … 1256 1263 //-- do the rest of the rendering 1257 1264 1258 // re setdepth pass and render visible objects1265 // return from depth pass and render visible objects 1259 1266 if ((renderMethod == RENDER_DEPTH_PASS) || 1260 1267 (renderMethod == RENDER_DEPTH_PASS_DEFERRED)) … … 2035 2042 DEL_PTR(walkThroughPlayer); 2036 2043 DEL_PTR(statsWriter); 2044 DEL_PTR(viewCellsTree); 2037 2045 2038 2046 ResourceManager::DelSingleton(); … … 2508 2516 return sampleCount; 2509 2517 } 2518 2519 2520 void RenderPvs() 2521 { 2522 ViewCell *vc = viewCellsTree->GetViewCell(camera->GetPosition()); 2523 2524 for (int i = 0; i < vc->mPvs.Size(); ++ i) 2525 { 2526 SceneEntity *ent = vc->mPvs.GetEntry(i); 2527 ent->Render(&renderState); 2528 } 2529 }
Note: See TracChangeset
for help on using the changeset viewer.