Changeset 503 for trunk/VUT/GtpVisibilityPreprocessor/src
- Timestamp:
- 01/05/06 20:41:52 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp
r492 r503 1786 1786 1787 1787 Vector3 invDirection; 1788 const float eps = 1e-6 ;1789 const float invEps = 1e6 ;1788 const float eps = 1e-6f; 1789 const float invEps = 1e6f; 1790 1790 1791 1791 // it does change the ray direction very slightly, … … 1793 1793 1794 1794 if (fabs(direction.x) < eps) { 1795 if (direction.x < 0.0 )1795 if (direction.x < 0.0f) 1796 1796 invDirection.x = -invEps; 1797 1797 else … … 1799 1799 } 1800 1800 else 1801 invDirection.x = 1.0 / direction.x;1801 invDirection.x = 1.0f / direction.x; 1802 1802 1803 1803 if (fabs(direction.y) < eps) { … … 1808 1808 } 1809 1809 else 1810 invDirection.y = 1.0 / direction.y;1810 invDirection.y = 1.0f / direction.y; 1811 1811 1812 1812 if (fabs(direction.z) < eps) { 1813 if (direction.z < 0.0 )1813 if (direction.z < 0.0f) 1814 1814 invDirection.z = -invEps; 1815 1815 else … … 1817 1817 } 1818 1818 else 1819 invDirection.z = 1.0 / direction.z;1820 1821 1822 1823 if (fabs(direction.x) < 0.001 ) {1819 invDirection.z = 1.0f / direction.z; 1820 1821 1822 1823 if (fabs(direction.x) < 0.001f) { 1824 1824 if (mMin.x < origin.x && mMax.x > origin.x) { 1825 1825 minx = -MAXFLOAT; -
trunk/VUT/GtpVisibilityPreprocessor/src/Containers.h
r372 r503 13 13 class Polygon3; 14 14 class Ray; 15 class Mesh; 15 16 16 17 /** Container storing polygons used during BSP tree construction. … … 40 41 typedef vector<HierarchyNode *> NodeContainer; 41 42 42 43 43 typedef vector<SceneGraphNode *> SceneGraphNodeContainer; 44 44 45 typedef vector<Mesh *> MeshContainer; 45 46 46 47 -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r501 r503 1229 1229 "view_cells_max_pvs=", 1230 1230 "300"); 1231 1232 RegisterOption("ViewCells.PostProcess.minPvsDif", 1233 optInt, 1234 "view_cells_post_process_min_pvs_dif=", 1235 "10"); 1236 1237 RegisterOption("ViewCells.PostProcess.maxPvs", 1238 optInt, 1239 "view_cells_post_process_max_pvs=", 1240 "300"); 1241 1242 RegisterOption("ViewCells.PostProcess.minPvs", 1243 optString, 1244 "view_cells_post_process_min_pvs", 1245 "10"); 1246 1231 1247 1232 RegisterOption("ViewCells.filename", 1248 1233 optString, -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r483 r503 1 1 #include "Polygon3.h" 2 #include "Mesh.h"3 2 #include "Mesh.h" 4 3 #include "AxisAlignedBox3.h" 5 4 #include "Ray.h" 5 #include "Triangle3.h" 6 6 7 7 Polygon3::Polygon3(): … … 471 471 return revPoly; 472 472 } 473 474 475 void Polygon3::Triangulate(vector<Triangle3> &triangles) 476 { 477 int i = 1; 478 int j = 0; 479 int k = mVertices.size() - 1; 480 int count = 0; 481 482 while (i < k) 483 { 484 triangles.push_back(Triangle3(mVertices[i], mVertices[j], mVertices[k])); 485 486 if ((count ++) % 2) 487 j = i ++; 488 else 489 j = k --; 490 } 491 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
r448 r503 98 98 int CastRay(const Ray &ray, float &t, const float nearestT); 99 99 100 100 /** The polygon is triangulated. 101 */ 102 void Triangulate(vector<Triangle3> &triangles); 103 101 104 /** The piercing rays of the polygon are inherited by the child fragments 102 105 @parm front_piece the front fragment inheriting the front rays -
trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp
r502 r503 692 692 693 693 694 totalSamples += rays.size();695 rssSamples += vssRays.size();694 totalSamples += (int)rays.size(); 695 rssSamples += (int)vssRays.size(); 696 696 697 697 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
r485 r503 23 23 } 24 24 25 25 26 const ObjectPvs &ViewCell::GetPvs() const 26 27 { … … 33 34 } 34 35 36 35 37 int ViewCell::Type() const 36 38 { 37 39 return VIEW_CELL; 38 40 } 41 39 42 40 43 void ViewCell::AddPassingRay(const Ray &ray, const int contributions) … … 54 57 mVolume = volume; 55 58 } 59 60 61 void ViewCell::SetMesh(Mesh *mesh) 62 { 63 mMesh = mesh; 64 } 65 56 66 57 67 void ViewCell::UpdateViewCellsStats(ViewCellsStatistics &vcStat) -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h
r479 r503 116 116 */ 117 117 void SetArea(float area); 118 119 /** Updates the view cell statstics for this particular view cell. 120 */ 118 121 virtual void UpdateViewCellsStats(ViewCellsStatistics &vcStat); 119 122 … … 123 126 /// Rays piercing this view cell. 124 127 RayContainer mPiercingRays; 128 129 /** Sets the mesh for this view cell. 130 */ 131 void SetMesh(Mesh *mesh); 125 132 126 133 protected: -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r502 r503 8 8 #include "Ray.h" 9 9 #include "AxisAlignedBox3.h" 10 #include "Triangle3.h" 11 10 12 #include <stack> 11 13 … … 423 425 app << "#N_INVALIDLEAVES (number of invalid leaves )\n" << invalidLeaves << endl; 424 426 427 app << "#N_RAYS (number of rays / leaf)\n" << AvgRays() << endl; 425 428 //app << "#N_PVS: " << pvs << endl; 426 429 … … 776 779 777 780 // constrruct root node geometry 778 BspNodeGeometry * cell= new BspNodeGeometry();779 ConstructGeometry(mRoot, * cell);781 BspNodeGeometry *geom = new BspNodeGeometry(); 782 ConstructGeometry(mRoot, *geom); 780 783 781 784 BspTraversalData tData(mRoot, polys, 0, mRootCell, rays, 782 ComputePvsSize(*rays), cell->GetArea(), cell);785 ComputePvsSize(*rays), geom->GetArea(), geom); 783 786 784 787 tStack.push(tData); … … 1809 1812 // accumulate depth to compute average depth 1810 1813 mStat.accumDepth += data.mDepth; 1811 1814 // accumulate rays to compute rays / leaf 1815 mStat.accumRays += (int)data.mRays->size(); 1812 1816 1813 1817 if (data.mDepth >= mTermMaxDepth) … … 2196 2200 } 2197 2201 2198 void BspTree::ConstructGeometry(BspNode *n, BspNodeGeometry &cell) const 2199 { 2200 PolygonContainer polys; 2201 ConstructGeometry(n, polys); 2202 cell.mPolys = polys; 2203 } 2204 2205 void BspTree::ConstructGeometry(BspViewCell *vc, PolygonContainer &cell) const 2202 void BspTree::ConstructGeometry(BspViewCell *vc, BspNodeGeometry &geom) const 2206 2203 { 2207 2204 vector<BspLeaf *> leaves = vc->mLeaves; … … 2210 2207 2211 2208 for (it = leaves.begin(); it != it_end; ++ it) 2212 ConstructGeometry(*it, cell);2213 } 2214 2215 2216 void BspTree::ConstructGeometry(BspNode *n, PolygonContainer &cell) const2209 ConstructGeometry(*it, geom); 2210 } 2211 2212 2213 void BspTree::ConstructGeometry(BspNode *n, BspNodeGeometry &geom) const 2217 2214 { 2218 2215 vector<Plane3> halfSpaces; … … 2291 2288 2292 2289 if (candidates[i]) 2293 cell.push_back(candidates[i]);2290 geom.mPolys.push_back(candidates[i]); 2294 2291 } 2295 2292 } … … 2299 2296 const bool onlyUnmailed) const 2300 2297 { 2301 PolygonContainer cell; 2302 2303 ConstructGeometry(n, cell); 2298 BspNodeGeometry geom; 2299 ConstructGeometry(n, geom); 2304 2300 2305 2301 stack<BspNode *> nodeStack; … … 2319 2315 if (node != n && (!onlyUnmailed || !node->Mailed())) 2320 2316 { 2321 // test all planes of current node if candidate really2322 // is neighbour2323 PolygonContainer neighborCandidate;2324 ConstructGeometry(node, neighborCandidate);2317 // test all planes of current node if neighbour 2318 // candidate really is neighbour 2319 BspNodeGeometry candidateGeom; 2320 ConstructGeometry(node, candidateGeom); 2325 2321 2326 2322 bool isAdjacent = true; … … 2328 2324 { 2329 2325 const int cf = 2330 Polygon3::ClassifyPlane( neighborCandidate,2326 Polygon3::ClassifyPlane(candidateGeom.mPolys, 2331 2327 halfSpaces[i], 2332 2328 mEpsilon); … … 2338 2334 if (isAdjacent) 2339 2335 neighbors.push_back(dynamic_cast<BspLeaf *>(node)); 2340 2341 CLEAR_CONTAINER(neighborCandidate);2342 2336 } 2343 2337 } … … 2346 2340 BspInterior *interior = dynamic_cast<BspInterior *>(node); 2347 2341 2348 const int cf = Polygon3::ClassifyPlane( cell,2342 const int cf = Polygon3::ClassifyPlane(geom.mPolys, 2349 2343 interior->mPlane, 2350 2344 mEpsilon); … … 2364 2358 } 2365 2359 2366 CLEAR_CONTAINER(cell);2367 2360 return (int)neighbors.size(); 2368 2361 } 2362 2369 2363 2370 2364 BspLeaf *BspTree::GetRandomLeaf(const Plane3 &halfspace) … … 2387 2381 { 2388 2382 BspInterior *interior = dynamic_cast<BspInterior *>(node); 2389 2390 2383 BspNode *next; 2391 2384 2392 PolygonContainer cell; 2393 2385 BspNodeGeometry geom; 2394 2386 // todo: not very efficient: constructs full cell everytime 2395 ConstructGeometry(interior, cell);2396 2397 const int cf = Polygon3::ClassifyPlane( cell,2387 ConstructGeometry(interior, geom); 2388 2389 const int cf = Polygon3::ClassifyPlane(geom.mPolys, 2398 2390 halfspace, 2399 2391 mEpsilon); … … 2534 2526 /*************************************************************/ 2535 2527 2528 2536 2529 BspNodeGeometry::~BspNodeGeometry() 2537 2530 { 2538 2531 CLEAR_CONTAINER(mPolys); 2539 2532 } 2533 2540 2534 2541 2535 float BspNodeGeometry::GetArea() const … … 2543 2537 return Polygon3::GetArea(mPolys); 2544 2538 } 2539 2540 2541 void BspNodeGeometry::AddToMesh(Mesh &mesh) 2542 { 2543 PolygonContainer::const_iterator it, it_end = mPolys.end(); 2544 int vcount = 0; 2545 2546 for (it = mPolys.begin(); it != mPolys.end(); ++ it) 2547 { 2548 Polygon3 *poly = *it; 2549 2550 vector<Triangle3> triangles; 2551 poly->Triangulate(triangles); 2552 vector<Triangle3>::const_iterator tit, tit_end = triangles.end(); 2553 2554 for (tit = triangles.begin(); tit != tit_end; ++ tit) 2555 { 2556 mesh.mVertices.push_back((*tit).mVertices[0]); 2557 mesh.mVertices.push_back((*tit).mVertices[1]); 2558 mesh.mVertices.push_back((*tit).mVertices[2]); 2559 2560 Face *face = new Face(vcount ++, vcount ++, vcount ++); 2561 mesh.AddFace(face); 2562 } 2563 } 2564 } 2565 2545 2566 2546 2567 void BspNodeGeometry::SplitGeometry(BspNodeGeometry &front, -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r492 r503 44 44 */ 45 45 void ComputeBoundingBox(AxisAlignedBox3 &box); 46 46 47 /** Splits the polygon and returns the part of the polygon inside of the node geometry. 47 48 */ 48 49 Polygon3 *SplitPolygon(Polygon3 *poly, const float epsilon) const; 49 50 51 /** Adds node geometry to mesh. 52 @note the mesh vertices will not be connected 53 */ 54 void AddToMesh(Mesh &mesh); 55 56 /** The polygons the geometry consists of. 57 */ 50 58 PolygonContainer mPolys; 51 59 }; … … 132 140 /// polygon splits 133 141 int polySplits; 142 /// accumulated number of rays refs 143 int accumRays; 134 144 135 145 // Constructor … … 145 155 // TODO: computation wrong 146 156 double AvgDepth() const { return accumDepth / (double)Leaves();}; 147 157 double AvgRays() const { return accumRays / (double)Leaves();}; 158 148 159 void Reset() 149 160 { … … 170 181 invalidLeaves = 0; 171 182 polySplits = 0; 183 accumRays = 0; 172 184 } 173 185 … … 458 470 @returns the number of intersections with objects stored in the tree. 459 471 */ 460 int 461 _CastRay(Ray &ray); 462 463 464 int 465 CastLineSegment(const Vector3 &origin, 466 const Vector3 &termination, 467 ViewCellContainer &viewcells 468 ); 469 470 ViewCell * 471 GetViewCell(const Vector3 &point); 472 int _CastRay(Ray &ray); 473 474 475 int CastLineSegment(const Vector3 &origin, 476 const Vector3 &termination, 477 ViewCellContainer &viewcells 478 ); 479 480 ViewCell *GetViewCell(const Vector3 &point); 472 481 473 482 /// bsp tree construction types … … 483 492 const bool onlyUnmailed) const; 484 493 485 /** Constructs geometry associated with the half space intersections 486 leading to this node. 487 */ 488 void ConstructGeometry(BspNode *n, PolygonContainer &cell) const; 494 /** Constructs geometry of view cell returning a BSP node geometry type. 495 */ 496 void ConstructGeometry(BspNode *n, BspNodeGeometry &cell) const; 489 497 490 498 /** Construct geometry of view cell. 491 499 */ 492 void ConstructGeometry(BspViewCell *vc, PolygonContainer &cell) const; 493 494 /** Constructs geometry of view cell returning a BSP node geometry type. 495 */ 496 void ConstructGeometry(BspNode *n, BspNodeGeometry &cell) const; 500 void ConstructGeometry(BspViewCell *vc, BspNodeGeometry &geom) const; 497 501 498 502 /** Returns random leaf of BSP tree. … … 788 792 void AddToPvs(BspLeaf *leaf, 789 793 const BoundedRayContainer &rays, 790 int &sampleContributions, 794 int &sampleContributions, 791 795 int &contributingSamples); 792 796 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r502 r503 37 37 void ViewCellsManager::ParseEnvironment() 38 38 { 39 // post processing stuff 40 environment->GetIntValue("ViewCells.PostProcess.minPvsDif", mMinPvsDif); 41 environment->GetIntValue("ViewCells.PostProcess.minPvs", mMinPvs); 42 environment->GetIntValue("ViewCells.PostProcess.maxPvs", mMaxPvs); 43 39 // visualization stuff 44 40 environment->GetBoolValue("ViewCells.Visualization.exportRays", mExportRays); 45 41 environment->GetBoolValue("ViewCells.Visualization.exportGeometry", mExportGeometry); 46 42 47 43 char buf[50]; 48 44 49 45 environment->GetStringValue("ViewCells.Visualization.colorCode", buf); 50 46 51 47 if (strcmp(buf, "PVS") == 0) 52 48 mColorCode = 1; … … 65 61 { 66 62 DEL_PTR(mRenderer); 67 68 63 CLEAR_CONTAINER(mViewCells); 64 CLEAR_CONTAINER(mMeshContainer); 69 65 } 70 66 … … 73 69 { 74 70 X3dParser parser; 75 71 76 72 environment->GetFloatValue("ViewCells.height", parser.mViewCellHeight); 77 73 78 74 bool success = parser.ParseFile(filename, *this); 79 75 Debug << (int)mViewCells.size() << " view cells loaded" << endl; … … 102 98 if (!ViewCellsConstructed()) 103 99 return; 104 100 105 101 VssRayContainer::const_iterator it, it_end = rays.end(); 106 102 107 for (it = rays.begin(); it != it_end; ++ it) 108 { 103 for (it = rays.begin(); it != it_end; ++ it) 104 { 109 105 ComputeSampleContributions(*(*it)); 110 106 } … … 143 139 144 140 145 void ViewCellsManager::DeriveViewCells(const ObjectContainer &objects, 146 ViewCellContainer &viewCells, 141 void ViewCellsManager::DeriveViewCells(const ObjectContainer &objects, 142 ViewCellContainer &viewCells, 147 143 const int maxViewCells) const 148 144 { 149 145 // maximal max viewcells 150 int limit = maxViewCells > 0 ? 146 int limit = maxViewCells > 0 ? 151 147 Min((int)objects.size(), maxViewCells) : (int)objects.size(); 152 148 … … 154 150 { 155 151 Intersectable *object = objects[i]; 156 152 157 153 // extract the mesh instances 158 154 if (object->Type() == Intersectable::MESH_INSTANCE) … … 168 164 169 165 170 ViewCell *ViewCellsManager::ExtrudeViewCell(const Triangle3 &baseTri, 166 ViewCell *ViewCellsManager::ExtrudeViewCell(const Triangle3 &baseTri, 171 167 const float height) const 172 168 { 173 169 // one mesh per view cell 174 170 Mesh *mesh = new Mesh(); 175 171 176 172 //-- construct prism 177 173 178 // bottom 174 // bottom 179 175 mesh->mFaces.push_back(new Face(2,1,0)); 180 176 // top … … 188 184 Vector3 triNorm = baseTri.GetNormal(); 189 185 190 Triangle3 topTri; 186 Triangle3 topTri; 191 187 192 188 // add base vertices and calculate top vertices 193 189 for (int i = 0; i < 3; ++ i) 194 190 mesh->mVertices.push_back(baseTri.mVertices[i]); 195 196 // add top vertices 191 192 // add top vertices 197 193 for (int i = 0; i < 3; ++ i) 198 194 mesh->mVertices.push_back(baseTri.mVertices[i] + height * triNorm); 199 195 200 196 mesh->Preprocess(); 201 197 … … 217 213 218 214 std::merge(front.mPiercingRays.begin(), front.mPiercingRays.end(), 219 back.mPiercingRays.begin(), back.mPiercingRays.end(), 215 back.mPiercingRays.begin(), back.mPiercingRays.end(), 220 216 vc->mPiercingRays.begin()); 221 217 … … 321 317 { 322 318 mViewCells.clear(); 323 319 324 320 CollectViewCells(); 325 321 mViewCellsStats.Reset(); … … 336 332 337 333 ViewCellContainer viewcells; 338 334 339 335 ray.mPvsContribution = 0; 340 336 ray.mRelativePvsContribution = 0.0f; … … 343 339 Ray hray(ray); 344 340 float tmin = 0, tmax = 1.0; 345 341 346 342 //hray.Init(ray.GetOrigin(), ray.GetDir(), Ray::LINE_SEGMENT); 347 343 if (!GetSceneBbox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 348 344 return; 349 345 350 346 Vector3 origin = hray.Extrap(tmin); 351 347 Vector3 termination = hray.Extrap(tmax); 352 348 353 349 CastLineSegment(origin, 354 350 termination, 355 351 viewcells); 356 352 357 353 // copy viewcells memory efficiently 358 354 const bool storeViewcells = false; … … 361 357 ray.mViewCells = viewcells; 362 358 } 363 359 364 360 ViewCellContainer::const_iterator it = viewcells.begin(); 365 361 … … 367 363 368 364 if (addInPlace) { 369 for (; it != viewcells.end(); ++it) { 365 for (; it != viewcells.end(); ++it) { 370 366 ViewCell *viewcell = *it; 371 367 372 368 // if ray not outside of view space 373 369 float contribution; 374 bool added = 370 bool added = 375 371 viewcell->GetPvs().AddSample(ray.mTerminationObject, 376 372 contribution … … 378 374 if (added) 379 375 ray.mPvsContribution++; 380 376 381 377 ray.mRelativePvsContribution += contribution; 382 378 } 383 379 } else { 384 for (; it != viewcells.end(); ++it) { 380 for (; it != viewcells.end(); ++it) { 385 381 ViewCell *viewcell = *it; 386 382 // if ray not outside of view space … … 390 386 )) 391 387 ray.mPvsContribution++; 392 388 393 389 ray.mRelativePvsContribution += contribution; 394 390 } 395 391 396 for (it = viewcells.begin(); it != viewcells.end(); ++it) { 392 for (it = viewcells.begin(); it != viewcells.end(); ++it) { 397 393 ViewCell *viewcell = *it; 398 394 // if ray not outside of view space … … 405 401 void ViewCellsManager::GetRaySets(const VssRayContainer &sourceRays, 406 402 const int maxSize, 407 VssRayContainer &usedRays, 403 VssRayContainer &usedRays, 408 404 VssRayContainer *savedRays) const 409 405 { … … 461 457 462 458 459 460 void ViewCellsManager::CreateViewCellsMeshes() 461 { 462 // convert to meshes 463 ViewCellContainer::const_iterator it, it_end = mViewCells.end(); 464 465 for (it = mViewCells.begin(); it != it_end; ++ it) 466 { 467 CreateMesh(*it); 468 } 469 } 470 463 471 /**********************************************************************/ 464 472 /* BspViewCellsManager implementation */ … … 466 474 467 475 468 BspViewCellsManager::BspViewCellsManager(BspTree *bspTree, 476 BspViewCellsManager::BspViewCellsManager(BspTree *bspTree, 469 477 int constructionSamples): 470 ViewCellsManager(constructionSamples), 478 ViewCellsManager(constructionSamples), 471 479 mBspTree(bspTree) 472 480 { … … 486 494 487 495 488 int BspViewCellsManager::Construct(const ObjectContainer &objects, 496 int BspViewCellsManager::Construct(const ObjectContainer &objects, 489 497 const VssRayContainer &rays) 490 498 { … … 494 502 495 503 int sampleContributions = 0; 496 504 497 505 // construct view cells using the collected samples 498 506 RayContainer constructionRays; … … 513 521 } 514 522 515 if (mViewCells.empty()) 516 { 517 // no view cells loaded 523 if (mViewCells.empty()) 524 { 525 // no view cells loaded 518 526 mBspTree->Construct(objects, constructionRays); 519 527 // collect final view cells 520 528 mBspTree->CollectViewCells(mViewCells); 521 } 529 } 522 530 else 523 531 { … … 529 537 530 538 Debug << mBspTree->GetStatistics() << endl; 531 532 EvaluateViewCellsStats();539 540 //EvaluateViewCellsStats(); 533 541 Debug << "\nView cells after construction:\n" << mViewCellsStats << endl; 534 542 … … 536 544 ComputeSampleContributions(savedRays); 537 545 546 538 547 return sampleContributions; 539 548 } 540 549 550 541 551 void BspViewCellsManager::CollectViewCells() 542 552 { 543 553 mBspTree->CollectViewCells(mViewCells); 544 554 } 555 545 556 546 557 float BspViewCellsManager::GetProbability(ViewCell *viewCell) … … 553 564 #endif 554 565 } 555 566 556 567 557 568 float BspViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) const … … 575 586 576 587 577 int BspViewCellsManager::PostProcess(const ObjectContainer &objects, 588 int BspViewCellsManager::PostProcess(const ObjectContainer &objects, 578 589 const VssRayContainer &rays) 579 590 { … … 601 612 cout << "exporting initial view cells (=leaves) ... "; 602 613 Exporter *exporter = Exporter::GetExporter("view_cells.x3d"); 603 614 604 615 if (exporter) 605 616 { … … 607 618 exporter->SetFilled(); 608 619 ExportViewCells(exporter); 609 620 610 621 if (mExportGeometry) 611 622 { … … 624 635 625 636 cout << "starting post processing using " << mPostProcessSamples << " samples ... "; 626 637 627 638 long startTime = GetTime(); 628 639 … … 637 648 CLEAR_CONTAINER(mBspRays); 638 649 ConstructBspRays(rays, mPostProcessSamples); 639 650 640 651 for (int i = 0; i < (int)mBspRays.size(); ++ i) 641 { 652 { 642 653 BspRay *ray = mBspRays[i]; 643 654 644 655 // traverse leaves stored in the rays and compare and merge consecutive 645 656 // leaves (i.e., the neighbors in the tree) 646 657 if (ray->intersections.size() < 2) 647 658 continue; 648 659 649 660 iit = ray->intersections.begin(); 650 661 651 662 BspLeaf *previousLeaf = (*iit).mLeaf; 652 663 ++ iit; 653 664 654 665 for (; iit != ray->intersections.end(); ++ iit) 655 666 { … … 657 668 658 669 if (ShouldMerge(leaf, previousLeaf)) 659 { 670 { 660 671 MergeBspLeafViewCells(leaf, previousLeaf); 661 672 662 673 ++ merged; 663 674 } 664 675 665 676 previousLeaf = leaf; 666 677 } … … 673 684 674 685 Debug << "Postprocessing: Merged " << merged << " view cells in " 675 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" 686 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" 676 687 << "using " << (int)mBspRays.size() << " samples" << endl << endl; 677 688 678 689 CLEAR_CONTAINER(mBspRays); 679 690 … … 704 715 CLEAR_CONTAINER(mBspRays); 705 716 ConstructBspRays(sampleRays, mVisualizationSamples); 706 717 707 718 if (1) // export view cells 708 719 { … … 715 726 delete exporter; 716 727 } 717 728 718 729 cout << "finished" << endl; 719 } 730 } 720 731 721 732 //-- visualization of the BSP splits 722 733 bool exportSplits = false; 723 734 environment->GetBoolValue("BspTree.Visualization.exportSplits", exportSplits); 724 735 725 736 if (exportSplits) 726 737 { … … 734 745 735 746 736 inline bool vc_gt(ViewCell *a, ViewCell *b) 737 { 747 inline bool vc_gt(ViewCell *a, ViewCell *b) 748 { 738 749 return a->GetPvs().GetSize() > b->GetPvs().GetSize(); 739 750 } … … 744 755 Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 745 756 746 if (exporter) 747 { 748 Material m; 757 if (exporter) 758 { 759 Material m; 749 760 m.mDiffuseColor = RgbColor(1, 0, 0); 750 761 exporter->SetForcedMaterial(m); 751 762 exporter->SetWireframe(); 752 763 753 764 exporter->ExportBspSplits(*mBspTree, true); 754 765 … … 759 770 760 771 exporter->SetFilled(); 761 772 762 773 // export rays 763 774 if (0) 764 775 { 765 776 VssRayContainer outRays; 766 777 767 778 int raysSize = min((int)mBspRays.size(), mVisualizationSamples); 768 779 … … 770 781 // only rays piercing geometry 771 782 outRays.push_back(mBspRays[i]->vssRay); 772 773 // export rays 783 784 // export rays 774 785 exporter->ExportRays(outRays, RgbColor(1, 1, 0)); 775 786 } … … 786 797 { 787 798 const int leafOut = 10; 788 799 789 800 ViewCell::NewMail(); 790 801 791 802 //-- some rays for output 792 803 const int raysOut = min((int)mBspRays.size(), mVisualizationSamples); 793 804 794 805 cout << "visualization using " << mVisualizationSamples << " samples" << endl; 795 806 Debug << "\nOutput view cells: " << endl; 796 807 797 808 // sort view cells to get largest view cells 798 809 #if 0 799 810 stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt); 800 811 #endif 801 int limit = min(leafOut, (int)mViewCells.size()); 802 812 int limit = min(leafOut, (int)mViewCells.size()); 813 803 814 for (int i = 0; i < limit; ++ i) 804 815 { … … 815 826 #if 0 816 827 // check whether we can add the current ray to the output rays 817 for (int k = 0; k < raysOut; ++ k) 828 for (int k = 0; k < raysOut; ++ k) 818 829 { 819 830 BspRay *ray = mBspRays[k]; … … 821 832 { 822 833 BspLeaf *leaf = ray->intersections[j].mLeaf; 823 if (vc == leaf->GetViewCell()) 834 if (vc == leaf->GetViewCell()) 824 835 vcRays.push_back(ray->vssRay); 825 836 } … … 830 841 831 842 Exporter *exporter = Exporter::GetExporter(s); 832 843 833 844 exporter->SetWireframe(); 834 845 … … 841 852 else 842 853 { 843 PolygonContainervcGeom;844 854 BspNodeGeometry vcGeom; 855 845 856 //-- export view cell 846 857 mBspTree->ConstructGeometry(vc, vcGeom); 847 exporter->ExportPolygons(vcGeom); 848 CLEAR_CONTAINER(vcGeom); 849 } 850 851 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 858 exporter->ExportPolygons(vcGeom.mPolys); 859 } 860 861 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 852 862 << ", piercing rays=" << (int)vcRays.size() 853 863 << ", leaves=" << (int)vc->mLeaves.size() << endl; 854 864 855 865 856 866 // export rays piercing this view cell 857 867 #if 0 … … 871 881 872 882 // output PVS of view cell 873 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 883 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 874 884 { 875 885 Intersectable *intersect = (*it).first; … … 882 892 exporter->ExportIntersectable(intersect); 883 893 intersect->Mail(); 884 } 885 } 886 894 } 895 } 896 887 897 DEL_PTR(exporter); 888 898 cout << "finished" << endl; … … 895 905 bool BspViewCellsManager::MergeBspLeafViewCells(BspLeaf *front, BspLeaf *back) const 896 906 { 897 BspViewCell *viewCell = 898 dynamic_cast<BspViewCell *>(MergeViewCells(*front->GetViewCell(), 907 BspViewCell *viewCell = 908 dynamic_cast<BspViewCell *>(MergeViewCells(*front->GetViewCell(), 899 909 *back->GetViewCell())); 900 910 901 911 if (!viewCell) 902 912 return false; … … 910 920 911 921 vector<BspLeaf *>::const_iterator it; 912 922 913 923 for (it = fLeaves.begin(); it != fLeaves.end(); ++ it) 914 924 { … … 921 931 viewCell->mLeaves.push_back(*it); 922 932 } 923 933 924 934 DEL_PTR(fVc); 925 935 DEL_PTR(bVc); … … 940 950 if (fvc->GetPvs().GetSize() + fdiff < mMaxPvs) 941 951 { 942 if ((fvc->GetPvs().GetSize() < mMinPvs) || 952 if ((fvc->GetPvs().GetSize() < mMinPvs) || 943 953 (bvc->GetPvs().GetSize() < mMinPvs) || 944 954 ((fdiff < mMinPvsDif) && (bvc->GetPvs().Diff(fvc->GetPvs()) < mMinPvsDif))) … … 947 957 } 948 958 } 949 959 950 960 return false; 951 961 } … … 979 989 980 990 981 void BspViewCellsManager::ExportColor(Exporter *exporter, 991 void BspViewCellsManager::ExportColor(Exporter *exporter, 982 992 ViewCell *vc) const 983 993 { … … 994 1004 case 1: // pvs 995 1005 { 996 importance = (float)vc->GetPvs().GetSize() / 1006 importance = (float)vc->GetPvs().GetSize() / 997 1007 (float)mViewCellsStats.maxPvs; 998 1008 } … … 1002 1012 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(vc); 1003 1013 1004 importance = (float)bspVc->mLeaves.size() / 1014 importance = (float)bspVc->mLeaves.size() / 1005 1015 (float)mViewCellsStats.maxLeaves; 1006 1016 } … … 1019 1029 m.mDiffuseColor.r = importance; 1020 1030 m.mDiffuseColor.g = 1.0f - m.mDiffuseColor.r; 1021 1031 1022 1032 exporter->SetForcedMaterial(m); 1023 1033 } 1024 1034 1025 void BspViewCellsManager::ExportVcGeometry(Exporter *exporter, 1035 void BspViewCellsManager::ExportVcGeometry(Exporter *exporter, 1026 1036 ViewCell *vc) const 1027 1037 { … … 1030 1040 else 1031 1041 { 1032 PolygonContainer cell;1042 BspNodeGeometry geom; 1033 1043 mBspTree->ConstructGeometry( 1034 dynamic_cast<BspViewCell *>(vc), cell); 1035 exporter->ExportPolygons(cell); 1036 } 1044 dynamic_cast<BspViewCell *>(vc), geom); 1045 exporter->ExportPolygons(geom.mPolys); 1046 } 1047 } 1048 1049 1050 void BspViewCellsManager::CreateMesh(ViewCell *vc) 1051 { 1037 1052 } 1038 1053 … … 1048 1063 /* KdViewCellsManager implementation */ 1049 1064 /**********************************************************************/ 1065 1066 1050 1067 1051 1068 KdViewCellsManager::KdViewCellsManager(KdTree *kdTree): … … 1085 1102 } 1086 1103 1087 int KdViewCellsManager::Construct(const ObjectContainer &objects, 1104 int KdViewCellsManager::Construct(const ObjectContainer &objects, 1088 1105 const VssRayContainer &rays) 1089 1106 { … … 1097 1114 // create the view cells 1098 1115 mKdTree->CreateAndCollectViewCells(mViewCells); 1099 1116 1100 1117 // cast rays 1101 1118 ComputeSampleContributions(rays); … … 1112 1129 } 1113 1130 1114 int KdViewCellsManager::PostProcess(const ObjectContainer &objects, 1131 int KdViewCellsManager::PostProcess(const ObjectContainer &objects, 1115 1132 const VssRayContainer &rays) 1116 1133 { … … 1135 1152 { 1136 1153 const int leafOut = 10; 1137 1154 1138 1155 ViewCell::NewMail(); 1139 1156 1140 1157 //-- some rays for output 1141 1158 const int raysOut = min((int)sampleRays.size(), mVisualizationSamples); … … 1144 1161 //-- some random view cells and rays for output 1145 1162 vector<KdLeaf *> kdLeaves; 1146 1163 1147 1164 for (int i = 0; i < leafOut; ++ i) 1148 1165 kdLeaves.push_back(dynamic_cast<KdLeaf *>(mKdTree->GetRandomLeaf())); 1149 1166 1150 1167 for (int i = 0; i < kdLeaves.size(); ++ i) 1151 1168 { 1152 1169 KdLeaf *leaf = kdLeaves[i]; 1153 1170 RayContainer vcRays; 1154 1171 1155 1172 cout << "creating output for view cell " << i << " ... "; 1156 #if 0 1173 #if 0 1157 1174 // check whether we can add the current ray to the output rays 1158 for (int k = 0; k < raysOut; ++ k) 1175 for (int k = 0; k < raysOut; ++ k) 1159 1176 { 1160 1177 Ray *ray = sampleRays[k]; 1161 1178 1162 1179 for (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 1163 1180 { 1164 1181 BspLeaf *leaf2 = ray->bspIntersections[j].mLeaf; 1165 1166 if (leaf->GetViewCell() == leaf2->GetViewCell()) 1182 1183 if (leaf->GetViewCell() == leaf2->GetViewCell()) 1167 1184 { 1168 1185 vcRays.push_back(ray); … … 1170 1187 } 1171 1188 } 1172 #endif 1189 #endif 1173 1190 Intersectable::NewMail(); 1174 1191 1175 1192 ViewCell *vc = leaf->mViewCell; 1176 1193 1177 1194 //bspLeaves[j]->Mail(); 1178 1195 char s[64]; sprintf(s, "kd-pvs%04d.x3d", i); 1179 1196 1180 1197 Exporter *exporter = Exporter::GetExporter(s); 1181 1198 exporter->SetFilled(); … … 1183 1200 exporter->SetWireframe(); 1184 1201 //exporter->SetFilled(); 1185 1202 1186 1203 Material m;//= RandomMaterial(); 1187 1204 m.mDiffuseColor = RgbColor(1, 1, 0); 1188 1205 exporter->SetForcedMaterial(m); 1189 1206 1190 1207 AxisAlignedBox3 box = mKdTree->GetBox(leaf); 1191 1208 exporter->ExportBox(box); 1192 1209 1193 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 1210 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 1194 1211 << ", piercing rays=" << (int)vcRays.size() << endl; 1195 1212 1196 1213 // export rays piercing this view cell 1197 exporter->ExportRays(vcRays, 1000, RgbColor(0, 1, 0)); 1198 1214 exporter->ExportRays(vcRays, 1000, RgbColor(0, 1, 0)); 1215 1199 1216 m.mDiffuseColor = RgbColor(1, 0, 0); 1200 1217 exporter->SetForcedMaterial(m); 1201 1218 1202 1219 // exporter->SetWireframe(); 1203 1220 exporter->SetFilled(); 1204 1221 1205 1222 ObjectPvsMap::iterator it, it_end = vc->GetPvs().mEntries.end(); 1206 1223 // output PVS of view cell 1207 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 1224 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 1208 1225 { 1209 1226 Intersectable *intersect = (*it).first; … … 1212 1229 exporter->ExportIntersectable(intersect); 1213 1230 intersect->Mail(); 1214 } 1231 } 1215 1232 } 1216 1233 1217 1234 DEL_PTR(exporter); 1218 1235 cout << "finished" << endl; … … 1226 1243 { 1227 1244 VssRay *ray = sampleRays[i]; 1228 1245 1229 1246 // check whether we can add this to the rays 1230 for (int j = 0; j < pvsOut; j++) 1247 for (int j = 0; j < pvsOut; j++) 1231 1248 { 1232 1249 if (objects[j] == ray->mTerminationObject) … … 1237 1254 } 1238 1255 1239 if (exportRays) 1256 if (exportRays) 1240 1257 { 1241 1258 Exporter *exporter = NULL; … … 1243 1260 exporter->SetWireframe(); 1244 1261 exporter->ExportKdTree(*mKdTree); 1245 1246 for (i=0; i < pvsOut; i++) 1262 1263 for (i=0; i < pvsOut; i++) 1247 1264 exporter->ExportRays(rays[i], RgbColor(1, 0, 0)); 1248 1265 1249 1266 exporter->SetFilled(); 1250 1267 1251 1268 delete exporter; 1252 1269 } 1253 1270 1254 for (int k=0; k < pvsOut; k++) 1271 for (int k=0; k < pvsOut; k++) 1255 1272 { 1256 1273 Intersectable *object = objects[k]; 1257 char s[64]; 1274 char s[64]; 1258 1275 sprintf(s, "sample-pvs%04d.x3d", k); 1259 1276 1260 1277 Exporter *exporter = Exporter::GetExporter(s); 1261 1278 exporter->SetWireframe(); 1262 1279 1263 1280 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 1264 1281 Intersectable::NewMail(); 1265 1282 1266 1283 // avoid adding the object to the list 1267 1284 object->Mail(); 1268 1285 ObjectContainer visibleObjects; 1269 1270 for (; i != object->mKdPvs.mEntries.end(); i++) 1286 1287 for (; i != object->mKdPvs.mEntries.end(); i++) 1271 1288 { 1272 1289 KdNode *node = (*i).first; 1273 1290 exporter->ExportBox(mKdTree->GetBox(node)); 1274 1291 1275 1292 mKdTree->CollectObjects(node, visibleObjects); 1276 1293 } 1277 1294 1278 1295 exporter->ExportRays(rays[k], RgbColor(0, 1, 0)); 1279 1296 exporter->SetFilled(); 1280 1297 1281 1298 for (int j = 0; j < visibleObjects.size(); j++) 1282 1299 exporter->ExportIntersectable(visibleObjects[j]); 1283 1300 1284 1301 Material m; 1285 1302 m.mDiffuseColor = RgbColor(1, 0, 0); 1286 1303 exporter->SetForcedMaterial(m); 1287 1304 exporter->ExportIntersectable(object); 1288 1305 1289 1306 delete exporter; 1290 1307 } 1291 } 1308 } 1292 1309 } 1293 1310 … … 1300 1317 1301 1318 1302 void KdViewCellsManager::ExportVcGeometry(Exporter *exporter, 1319 void KdViewCellsManager::ExportVcGeometry(Exporter *exporter, 1303 1320 ViewCell *vc) const 1304 1321 { … … 1335 1352 1336 1353 1354 void KdViewCellsManager::CreateMesh(ViewCell *vc) 1355 { 1356 } 1357 1337 1358 /**********************************************************************/ 1338 1359 /* VspKdViewCellsManager implementation */ … … 1340 1361 1341 1362 1342 VspKdViewCellsManager::VspKdViewCellsManager(VspKdTree *vspKdTree, 1363 VspKdViewCellsManager::VspKdViewCellsManager(VspKdTree *vspKdTree, 1343 1364 int constructionSamples): 1344 ViewCellsManager(constructionSamples), 1365 ViewCellsManager(constructionSamples), 1345 1366 mVspKdTree(vspKdTree) 1346 1367 { … … 1364 1385 } 1365 1386 1387 1366 1388 void VspKdViewCellsManager::CollectViewCells() 1367 1389 { … … 1369 1391 } 1370 1392 1371 int VspKdViewCellsManager::Construct(const ObjectContainer &objects, 1393 int VspKdViewCellsManager::Construct(const ObjectContainer &objects, 1372 1394 const VssRayContainer &rays) 1373 1395 { … … 1375 1397 if (ViewCellsConstructed()) 1376 1398 return 0; 1377 1399 1378 1400 VssRayContainer constructionRays; 1379 1401 VssRayContainer savedRays; 1380 1402 1381 GetRaySets(rays, 1382 mConstructionSamples, 1383 constructionRays, 1403 GetRaySets(rays, 1404 mConstructionSamples, 1405 constructionRays, 1384 1406 &savedRays); 1385 1386 Debug << "constructing vsp kd tree using " 1407 1408 Debug << "constructing vsp kd tree using " 1387 1409 << (int)constructionRays.size() << " samples" << endl; 1388 1410 … … 1397 1419 1398 1420 // collapse siblings belonging to the same view cell 1421 mVspKdTree->RefineViewCells(rays); 1422 1423 // collapse siblings belonging to the same view cell 1399 1424 mVspKdTree->CollapseTree(); 1400 1401 // collapse siblings belonging to the same view cell1402 mVspKdTree->RefineViewCells(rays);1403 1425 1404 1426 // evaluale view cell stats … … 1410 1432 // recast rest of rays 1411 1433 ComputeSampleContributions(savedRays); 1412 1413 Debug << "Computed remaining ray contribution in " << TimeDiff(startTime, GetTime()) * 1e-3 1434 1435 Debug << "Computed remaining ray contribution in " << TimeDiff(startTime, GetTime()) * 1e-3 1414 1436 << " secs" << endl; 1415 1437 … … 1428 1450 } 1429 1451 1430 int VspKdViewCellsManager::PostProcess(const ObjectContainer &objects, 1452 int VspKdViewCellsManager::PostProcess(const ObjectContainer &objects, 1431 1453 const VssRayContainer &rays) 1432 1454 { … … 1454 1476 1455 1477 //-- export leaf building blocks 1456 Exporter *exporter = Exporter::GetExporter("vspkdtree.x3d"); 1478 Exporter *exporter = Exporter::GetExporter("vspkdtree.x3d"); 1457 1479 if (!exporter) 1458 1480 return; … … 1462 1484 exporter->ExportVspKdTree(*mVspKdTree); 1463 1485 1464 if (mExportGeometry) 1486 if (mExportGeometry) 1465 1487 exporter->ExportGeometry(objects); 1466 1488 1467 if (mExportRays) 1468 { 1469 const float prob = (float)mVisualizationSamples 1489 if (mExportRays) 1490 { 1491 const float prob = (float)mVisualizationSamples 1470 1492 / ((float)sampleRays.size() + Limits::Small); 1471 1493 … … 1491 1513 if (!ViewCellsConstructed()) 1492 1514 return; 1493 1515 1494 1516 //-- export single view cells 1495 1517 for (int i = 0; i < 10; ++ i) … … 1498 1520 sprintf(s, "vsp_viewcell%04d.x3d", i); 1499 1521 Exporter *exporter = Exporter::GetExporter(s); 1500 const int idx = 1522 const int idx = 1501 1523 (int)RandomValue(0.0, (Real)((int)mViewCells.size() - 1)); 1502 1524 1503 VspKdViewCell *vc = dynamic_cast<VspKdViewCell *>(mViewCells[idx]); 1525 VspKdViewCell *vc = dynamic_cast<VspKdViewCell *>(mViewCells[idx]); 1504 1526 1505 1527 cout << "Output view cell " << i << " with pvs size " << vc->GetPvs().GetSize() << endl; … … 1508 1530 Material m; 1509 1531 m.mDiffuseColor = RgbColor(0, 1, 1); 1510 1532 1511 1533 exporter->SetForcedMaterial(m); 1512 1534 exporter->SetWireframe(); … … 1517 1539 if (mExportRays) 1518 1540 { 1519 vector<VspKdLeaf *>::const_iterator it, 1541 vector<VspKdLeaf *>::const_iterator it, 1520 1542 it_end = vc->mLeaves.end(); 1521 1543 … … 1540 1562 if ((*it)->mTerminationObject == NULL) 1541 1563 castRays.push_back(*it); 1542 else 1564 else 1543 1565 initRays.push_back(*it); 1544 1566 } … … 1560 1582 exporter->SetFilled(); 1561 1583 1562 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 1584 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 1563 1585 { 1564 1586 Intersectable *intersect = (*it).first; … … 1571 1593 exporter->ExportIntersectable(intersect); 1572 1594 intersect->Mail(); 1573 } 1595 } 1574 1596 } 1575 1597 … … 1578 1600 1579 1601 //-- export final view cells 1580 Exporter *exporter = Exporter::GetExporter("vspkdtree_merged.x3d"); 1581 1602 Exporter *exporter = Exporter::GetExporter("vspkdtree_merged.x3d"); 1603 1582 1604 //if (exportGeometry) exporter->SetWireframe(); 1583 1605 //else exporter->SetFilled(); … … 1585 1607 ExportViewCells(exporter); 1586 1608 1587 if (mExportGeometry) 1609 if (mExportGeometry) 1588 1610 { 1589 1611 exporter->SetFilled(); … … 1591 1613 } 1592 1614 1593 if (mExportRays) 1594 { 1595 const float prob = (float)mVisualizationSamples 1615 if (mExportRays) 1616 { 1617 const float prob = (float)mVisualizationSamples 1596 1618 / ((float)sampleRays.size() + Limits::Small); 1597 1619 1598 1620 exporter->SetWireframe(); 1599 1621 1600 1622 VssRayContainer rays; 1601 1623 1602 1624 for (int i = 0; i < sampleRays.size(); ++ i) 1603 1625 { … … 1605 1627 rays.push_back(sampleRays[i]); 1606 1628 } 1607 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 1629 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 1608 1630 } 1609 1631 … … 1630 1652 if (mColorCode == 0) // Random color 1631 1653 return; 1632 1654 1633 1655 float importance = 0; 1634 1656 … … 1637 1659 case 1: // pvs 1638 1660 { 1639 importance = (float)vc->GetPvs().GetSize() / 1661 importance = (float)vc->GetPvs().GetSize() / 1640 1662 (float)mViewCellsStats.maxPvs; 1641 1663 } … … 1645 1667 VspKdViewCell *vspKdVc = dynamic_cast<VspKdViewCell *>(vc); 1646 1668 1647 importance = (float)vspKdVc->mLeaves.size() / 1669 importance = (float)vspKdVc->mLeaves.size() / 1648 1670 (float)mViewCellsStats.maxLeaves; 1649 1671 } … … 1651 1673 case 3: // merged tree depth difference 1652 1674 { 1653 //importance = (float)GetMaxTreeDiff(vc) / 1675 //importance = (float)GetMaxTreeDiff(vc) / 1654 1676 // (float)(mVspBspTree->GetStatistics().maxDepth * 2); 1655 1677 } … … 1668 1690 1669 1691 1670 void VspKdViewCellsManager::ExportVcGeometry(Exporter *exporter, 1692 void VspKdViewCellsManager::ExportVcGeometry(Exporter *exporter, 1671 1693 ViewCell *vc) const 1672 1694 { … … 1684 1706 1685 1707 1686 /************************************************************************/ 1687 /* VspBspViewCellsManager implementation */ 1688 /************************************************************************/ 1689 1690 1691 VspBspViewCellsManager::VspBspViewCellsManager(VspBspTree *vspBspTree, 1708 void VspKdViewCellsManager::CreateMesh(ViewCell *vc) 1709 { 1710 } 1711 1712 /**************************************************************************/ 1713 /* VspBspViewCellsManager implementation */ 1714 /**************************************************************************/ 1715 1716 1717 VspBspViewCellsManager::VspBspViewCellsManager(VspBspTree *vspBspTree, 1692 1718 int constructionSamples): 1693 ViewCellsManager(constructionSamples), 1719 ViewCellsManager(constructionSamples), 1694 1720 mVspBspTree(vspBspTree) 1695 1721 { … … 1719 1745 1720 1746 1721 float VspBspViewCellsManager::GetRendercost(ViewCell *viewCell, 1747 float VspBspViewCellsManager::GetRendercost(ViewCell *viewCell, 1722 1748 float objRendercost) const 1723 1749 { … … 1743 1769 } 1744 1770 1745 int VspBspViewCellsManager::Construct(const ObjectContainer &objects, 1771 int VspBspViewCellsManager::Construct(const ObjectContainer &objects, 1746 1772 const VssRayContainer &rays) 1747 1773 { 1748 // if view cells were already constructed 1749 if (ViewCellsConstructed()) 1750 return 0; 1751 1752 Debug << "Constructing bsp view cells" << endl; 1753 1754 int sampleContributions = 0; 1755 1756 VssRayContainer sampleRays; 1757 1758 int limit = min (mConstructionSamples, (int)rays.size()); 1759 1760 1774 // if view cells were already constructed 1775 if (ViewCellsConstructed()) 1776 return 0; 1777 1778 Debug << "Constructing bsp view cells" << endl; 1779 1780 int sampleContributions = 0; 1781 1782 VssRayContainer sampleRays; 1783 1784 int limit = min (mConstructionSamples, (int)rays.size()); 1785 1761 1786 VssRayContainer constructionRays; 1762 1787 VssRayContainer savedRays; … … 1768 1793 1769 1794 mVspBspTree->Construct(constructionRays, &mSceneBox); 1770 1795 1771 1796 Debug << mVspBspTree->GetStatistics() << endl; 1772 1797 … … 1774 1799 cout << "collapsing invalid tree regions ... "; 1775 1800 long startTime = GetTime(); 1776 int collapsedLeaves = mVspBspTree->CollapseTree(); 1801 int collapsedLeaves = mVspBspTree->CollapseTree(); 1777 1802 Debug << "collapsed in " << TimeDiff(startTime, GetTime()) * 1e-3 << " seconds" << endl; 1778 1803 cout << "finished" << endl; 1779 1804 1780 1805 cout << "reseting view cell stats ... "; 1781 1806 ResetViewCells(); 1782 1807 cout << "finished" << endl; 1783 1808 1784 1809 Debug << "\nView cells after construction:\n" << mViewCellsStats << endl; 1785 1810 … … 1788 1813 cout << "exporting initial view cells (=leaves) ... "; 1789 1814 Exporter *exporter = Exporter::GetExporter("view_cells.x3d"); 1790 1815 1791 1816 if (exporter) 1792 1817 { … … 1797 1822 if (0 && mExportRays) 1798 1823 exporter->ExportRays(rays, RgbColor(1, 1, 1)); 1799 1824 1800 1825 if (mExportGeometry) 1801 1826 exporter->ExportGeometry(objects); 1802 1827 1803 1828 delete exporter; 1804 1829 } … … 1807 1832 1808 1833 startTime = GetTime(); 1834 1835 //-- merge the individual view cells: Should be done here because it makes 1836 MergeViewCells(rays, objects); 1837 //-- refines the merged view cells 1838 RefineViewCells(rays); 1839 // collapse sibling leaves that share the same view cell 1840 mVspBspTree->CollapseTree(); 1841 1842 // reset view cells and stats 1843 ResetViewCells(); 1844 1809 1845 cout << "Computing remaining ray contributions ... "; 1810 1846 // recast rest of rays … … 1812 1848 cout << "finished" << endl; 1813 1849 1814 Debug << "Computed remaining ray contribution in " << TimeDiff(startTime, GetTime()) * 1e-3 1850 Debug << "Computed remaining ray contribution in " << TimeDiff(startTime, GetTime()) * 1e-3 1815 1851 << " secs" << endl; 1816 1852 1817 1853 cout << "construction finished" << endl; 1854 1818 1855 return sampleContributions; 1819 1856 } 1820 1857 1821 1858 1822 // matt TODO: remove 1823 int VspBspViewCellsManager::MergeViewCells(const VssRayContainer &rays) const 1824 { 1825 vector<BspIntersection>::const_iterator iit; 1826 vector<BspRay *>bspRays; 1827 int merged = 0; 1828 1829 mVspBspTree->ConstructBspRays(bspRays, rays); 1830 1831 for (int i = 0; i < (int)bspRays.size(); ++ i) 1832 { 1833 BspRay *ray = bspRays[i]; 1834 1835 // traverse leaves stored in the rays and compare and merge consecutive 1836 // leaves (i.e., the neighbors in the tree) 1837 if (ray->intersections.size() < 2) 1838 continue; 1839 1840 iit = ray->intersections.begin(); 1841 1842 BspLeaf *previousLeaf = (*iit).mLeaf; 1843 ++ iit; 1844 1845 for (; iit != ray->intersections.end(); ++ iit) 1846 { 1847 BspLeaf *leaf = (*iit).mLeaf; 1848 1849 if (ShouldMerge(leaf, previousLeaf)) 1850 { 1851 mVspBspTree->MergeViewCells(leaf, previousLeaf); 1852 ++ merged; 1853 } 1854 previousLeaf = leaf; 1855 } 1856 } 1857 CLEAR_CONTAINER(bspRays); 1858 1859 return merged; 1860 } 1861 1862 1863 int VspBspViewCellsManager::PostProcess(const ObjectContainer &objects, 1864 const VssRayContainer &rays) 1865 { 1866 if (!ViewCellsConstructed()) 1867 { 1868 Debug << "view cells not constructed" << endl; 1869 return 0; 1870 } 1871 1859 void VspBspViewCellsManager::MergeViewCells(const VssRayContainer &rays, 1860 const ObjectContainer &objects) 1861 { 1872 1862 //-- post processing of bsp view cells 1873 1863 int vcSize = 0; … … 1888 1878 //-- merge or subdivide view cells 1889 1879 int merged = 0; 1890 1880 1891 1881 cout << "starting merge using " << mPostProcessSamples << " samples ... "; 1892 1882 long startTime = GetTime(); 1893 1883 1884 // TODO: should be done BEFORE the ray casting 1894 1885 merged = mVspBspTree->MergeViewCells(postProcessRays); 1895 1886 … … 1901 1892 Debug << "Postprocessing: Merged " << merged << " view cells in " 1902 1893 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl << endl; 1903 1894 1904 1895 cout << "reseting view cell stats ... "; 1905 1896 ResetViewCells(); … … 1934 1925 cout << "finished" << endl; 1935 1926 } 1936 1927 } 1928 1929 1930 void VspBspViewCellsManager::RefineViewCells(const VssRayContainer &rays) 1931 { 1937 1932 Debug << "render time before refine:" << endl; 1938 1933 mRenderer->RenderScene(); 1934 SimulationStatistics ss; 1939 1935 dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 1940 1936 Debug << ss << endl; 1941 1937 1942 1938 cout << "Refining the merged view cells ... "; 1943 startTime = GetTime();1939 long startTime = GetTime(); 1944 1940 1945 1941 // refining the merged view cells … … 1953 1949 Debug << "Postprocessing: refined " << refined << " view cells in " 1954 1950 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl << endl; 1955 1956 // collapse sibling leaves that share the same view cell 1957 mVspBspTree->CollapseTree(); 1958 1959 // reset view cells and stats 1960 ResetViewCells(); 1961 1962 return merged; 1951 } 1952 1953 int VspBspViewCellsManager::PostProcess(const ObjectContainer &objects, 1954 const VssRayContainer &rays) 1955 { 1956 if (!ViewCellsConstructed()) 1957 { 1958 Debug << "view cells not constructed" << endl; 1959 return 0; 1960 } 1961 1962 CreateViewCellsMeshes(); 1963 1964 return 0; 1963 1965 } 1964 1966 … … 1993 1995 bool VspBspViewCellsManager::ViewPointValid(const Vector3 &viewPoint) const 1994 1996 { 1995 return mSceneBox.IsInside(viewPoint) && 1997 return mSceneBox.IsInside(viewPoint) && 1996 1998 mVspBspTree->ViewPointValid(viewPoint); 1997 1999 } … … 2026 2028 delete exporter; 2027 2029 } 2028 2030 2029 2031 cout << "finished" << endl; 2030 } 2032 } 2031 2033 2032 2034 //-- visualization of the BSP splits 2033 2035 bool exportSplits = false; 2034 2036 environment->GetBoolValue("VspBspTree.Visualization.exportSplits", exportSplits); 2035 2037 2036 2038 if (exportSplits) 2037 2039 { … … 2044 2046 ExportBspPvs(objects, visRays); 2045 2047 } 2046 2048 2047 2049 2048 2050 void VspBspViewCellsManager::ExportSplits(const ObjectContainer &objects, … … 2051 2053 Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 2052 2054 2053 if (exporter) 2054 { 2055 Material m; 2055 if (exporter) 2056 { 2057 Material m; 2056 2058 m.mDiffuseColor = RgbColor(1, 0, 0); 2057 2059 exporter->SetForcedMaterial(m); 2058 2060 exporter->SetWireframe(); 2059 2061 2060 2062 exporter->ExportBspSplits(*mVspBspTree, true); 2061 2063 … … 2066 2068 2067 2069 exporter->ResetForcedMaterial(); 2068 2070 2069 2071 // export rays 2070 2072 if (mExportRays) 2071 2073 exporter->ExportRays(rays, RgbColor(1, 1, 0)); 2072 2074 2073 2075 if (mExportGeometry) 2074 2076 exporter->ExportGeometry(objects); … … 2078 2080 } 2079 2081 2082 2080 2083 void VspBspViewCellsManager::ExportBspPvs(const ObjectContainer &objects, 2081 2084 const VssRayContainer &rays) 2082 2085 { 2083 2086 const int leafOut = 10; 2084 2087 2085 2088 ViewCell::NewMail(); 2086 2089 2087 2090 cout << "visualization using " << mVisualizationSamples << " samples" << endl; 2088 2091 Debug << "\nOutput view cells: " << endl; 2089 2092 2090 2093 // sort view cells to visualize the largest view cells 2091 2094 #if 0 2092 2095 stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt); 2093 2096 #endif 2094 int limit = min(leafOut, (int)mViewCells.size()); 2097 int limit = min(leafOut, (int)mViewCells.size()); 2095 2098 2096 2099 #if 1 … … 2105 2108 { 2106 2109 cout << "creating output for view cell " << i << " ... "; 2107 2110 2108 2111 VssRayContainer vcRays; 2109 2112 Intersectable::NewMail(); … … 2117 2120 #if 1 2118 2121 // check whether we can add the current ray to the output rays 2119 for (int k = 0; k < raysOut; ++ k) 2122 for (int k = 0; k < raysOut; ++ k) 2120 2123 { 2121 2124 BspRay *ray = bspRays[k]; … … 2123 2126 { 2124 2127 BspLeaf *leaf = ray->intersections[j].mLeaf; 2125 if (vc == leaf->GetViewCell()) 2128 if (vc == leaf->GetViewCell()) 2126 2129 vcRays.push_back(ray->vssRay); 2127 2130 } … … 2137 2140 exporter->SetForcedMaterial(m); 2138 2141 2139 ExportVcGeometry(exporter, vc); 2140 2141 2142 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 2142 ExportVcGeometry(exporter, vc); 2143 2144 2145 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 2143 2146 << ", piercing rays=" << (int)vcRays.size() 2144 2147 << ", leaves=" << (int)vc->mLeaves.size() << endl; 2145 2148 2146 2149 //-- export rays piercing this view cell 2147 2150 #if 1 … … 2163 2166 2164 2167 // output PVS of view cell 2165 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 2168 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 2166 2169 { 2167 2170 Intersectable *intersect = (*it).first; … … 2174 2177 exporter->ExportIntersectable(intersect); 2175 2178 intersect->Mail(); 2176 } 2177 } 2178 2179 } 2180 } 2181 2179 2182 DEL_PTR(exporter); 2180 2183 cout << "finished" << endl; … … 2188 2191 2189 2192 2190 bool VspBspViewCellsManager::ShouldMerge(BspLeaf *front, BspLeaf *back) const2191 {2192 ViewCell *fvc = front->GetViewCell();2193 ViewCell *bvc = back->GetViewCell();2194 2195 if (fvc == bvc)2196 return false;2197 2198 const int fdiff = fvc->GetPvs().Diff(bvc->GetPvs());2199 2200 if (fvc->GetPvs().GetSize() + fdiff < mMaxPvs)2201 {2202 if ((fvc->GetPvs().GetSize() < mMinPvs) ||2203 (bvc->GetPvs().GetSize() < mMinPvs) ||2204 ((fdiff < mMinPvsDif) &&2205 (bvc->GetPvs().Diff(fvc->GetPvs()) < mMinPvsDif)))2206 {2207 return true;2208 }2209 }2210 2211 return false;2212 }2213 2214 2215 2193 int VspBspViewCellsManager::CastLineSegment(const Vector3 &origin, 2216 2194 const Vector3 &termination, … … 2221 2199 2222 2200 2223 void VspBspViewCellsManager::ExportColor(Exporter *exporter, 2201 void VspBspViewCellsManager::ExportColor(Exporter *exporter, 2224 2202 ViewCell *vc) const 2225 2203 { 2226 2204 if (mColorCode == 0) // Random color 2227 2205 return; 2228 2206 2229 2207 float importance = 0; 2230 2208 … … 2233 2211 case 1: // pvs 2234 2212 { 2235 importance = (float)vc->GetPvs().GetSize() / 2213 importance = (float)vc->GetPvs().GetSize() / 2236 2214 (float)mViewCellsStats.maxPvs; 2237 2215 } … … 2241 2219 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(vc); 2242 2220 2243 importance = (float)bspVc->mLeaves.size() / 2221 importance = (float)bspVc->mLeaves.size() / 2244 2222 (float)mViewCellsStats.maxLeaves; 2245 2223 } … … 2247 2225 case 3: // merge tree differene 2248 2226 { 2249 importance = (float)GetMaxTreeDiff(vc) / 2227 importance = (float)GetMaxTreeDiff(vc) / 2250 2228 (float)(mVspBspTree->GetStatistics().maxDepth * 2); 2251 2229 } … … 2264 2242 2265 2243 2266 void VspBspViewCellsManager::ExportVcGeometry(Exporter *exporter, 2244 void VspBspViewCellsManager::ExportVcGeometry(Exporter *exporter, 2267 2245 ViewCell *vc) const 2268 2246 { 2269 2247 #if 1 2248 if (vc->GetMesh()) 2249 { 2250 exporter->ExportMesh(vc->GetMesh()); 2251 return; 2252 } 2253 2270 2254 BspNodeGeometry geom; 2271 2255 mVspBspTree-> 2272 ConstructGeometry(dynamic_cast<BspViewCell *>(vc), geom .mPolys);2256 ConstructGeometry(dynamic_cast<BspViewCell *>(vc), geom); 2273 2257 exporter->ExportPolygons(geom.mPolys); 2274 2258 #else 2275 2259 2276 2260 Material m2; 2277 2261 m2.mDiffuseColor.b = 0.3f + Random(0.7f); … … 2324 2308 2325 2309 2326 2327 2328 ViewCell * 2329 VspBspViewCellsManager::GetViewCell(const Vector3 &point) 2310 ViewCell *VspBspViewCellsManager::GetViewCell(const Vector3 &point) 2330 2311 { 2331 2312 if (!mVspBspTree) … … 2333 2314 return mVspBspTree->GetViewCell(point); 2334 2315 } 2316 2317 2318 void VspBspViewCellsManager::CreateMesh(ViewCell *vc) 2319 { 2320 BspNodeGeometry geom; 2321 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(vc); 2322 mVspBspTree->ConstructGeometry(bspVc, geom); 2323 2324 Mesh *mesh = new Mesh(); 2325 geom.AddToMesh(*mesh); 2326 vc->SetMesh(mesh); 2327 mMeshContainer.push_back(mesh); 2328 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
r502 r503 25 25 class ViewCellsStatistics; 26 26 class Exporter; 27 27 28 struct BspRay; 28 29 … … 171 172 virtual void GetPvsStatistics(PvsStatistics &stat); 172 173 173 174 174 /** Get a viewcell containing the specified point */ 175 virtual ViewCell *GetViewCell(const Vector3 &point) = 0; 175 176 176 virtual void 177 PrintPvsStatistics(ostream &s); 177 virtual void PrintPvsStatistics(ostream &s); 178 178 179 179 /** Returns probability that view point lies in one view cell. … … 233 233 void SetViewSpaceBox(const AxisAlignedBox3 &box); 234 234 235 /** Creates mesh for this view cell. 236 */ 237 virtual void CreateMesh(ViewCell *vc) = NULL; 235 238 236 239 protected: … … 265 268 */ 266 269 virtual void ExportVcGeometry(Exporter *exporter, ViewCell *vc) const = 0; 270 271 /** Creates meshes from the view cells. 272 */ 273 void CreateViewCellsMeshes(); 267 274 268 275 /// the view cell corresponding to space ouside the valid view space … … 291 298 /// the scene bounding box 292 299 AxisAlignedBox3 mSceneBox; 300 301 MeshContainer mMeshContainer; 293 302 294 303 //-- visualization options … … 343 352 AxisAlignedBox3 GetSceneBbox() const; 344 353 345 /** Get a viewcell containing the specified point */ 346 ViewCell *GetViewCell(const Vector3 &point); 354 /** Get a viewcell containing the specified point */ 355 ViewCell *GetViewCell(const Vector3 &point); 356 357 void CreateMesh(ViewCell *vc); 347 358 348 359 protected: … … 411 422 /** Prints out statistics of this approach. 412 423 */ 413 414 415 416 417 424 // virtual void PrintStatistics(ostream &s) const; 425 ViewCell *GetViewCell(const Vector3 &point) { return NULL; } 426 427 float GetProbability(ViewCell *viewCell); 428 float GetRendercost(ViewCell *viewCell, float objRendercost) const; 418 429 419 AxisAlignedBox3 GetSceneBbox() const; 430 AxisAlignedBox3 GetSceneBbox() const; 431 432 void CreateMesh(ViewCell *vc); 420 433 421 434 protected: … … 468 481 ViewCellContainer &viewcells); 469 482 470 483 ViewCell *GetViewCell(const Vector3 &point) { return NULL; } 471 484 472 485 float GetProbability(ViewCell *viewCell); … … 474 487 475 488 AxisAlignedBox3 GetSceneBbox() const; 489 490 void CreateMesh(ViewCell *vc); 491 476 492 protected: 477 493 … … 526 542 527 543 AxisAlignedBox3 GetSceneBbox() const; 528 529 544 545 ViewCell *GetViewCell(const Vector3 &point); 530 546 531 547 bool GetViewPoint(Vector3 &viewPoint) const; 532 548 533 549 bool ViewPointValid(const Vector3 &viewPoint) const; 550 551 void CreateMesh(ViewCell *vc); 552 534 553 protected: 535 /** DEPRECATED 536 */ 537 int MergeViewCells(const VssRayContainer &rays) const; 538 539 /** Returns true if front and back leaf should be merged. 540 */ 541 bool ShouldMerge(BspLeaf *front, BspLeaf *back) const; 554 555 /** Merges the view cells. 556 */ 557 void MergeViewCells(const VssRayContainer &rays, const ObjectContainer &objects); 558 559 void RefineViewCells(const VssRayContainer &rays); 542 560 543 561 void CollectViewCells(); -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r501 r503 835 835 836 836 837 /* 837 838 float VspBspTree::EvalCostRatio(const VspBspTraversalData &tData, 838 839 const AxisAlignedBox3 &box, … … 949 950 return (mCtDivCi + newCost) / oldCost; 950 951 } 951 952 */ 952 953 953 954 … … 1304 1305 1305 1306 1306 void VspBspTree::CollectLeaves(vector<BspLeaf *> &leaves) const 1307 void VspBspTree::CollectLeaves(vector<BspLeaf *> &leaves, 1308 const bool onlyUnmailed, 1309 const int maxPvsSize) const 1307 1310 { 1308 1311 stack<BspNode *> nodeStack; … … 1317 1320 { 1318 1321 // test if this leaf is in valid view space 1319 if (node->TreeValid()) 1322 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 1323 if (leaf->TreeValid() && 1324 (!onlyUnmailed || leaf->Mailed()) && 1325 ((maxPvsSize < 0) || (leaf->GetViewCell()->GetPvs().GetSize() <= maxPvsSize))) 1320 1326 { 1321 BspLeaf *leaf = (BspLeaf *)node;1322 1327 leaves.push_back(leaf); 1323 1328 } … … 1641 1646 1642 1647 void VspBspTree::ConstructGeometry(BspNode *n, 1643 BspNodeGeometry &cell) const 1644 { 1645 ConstructGeometry(n, cell.mPolys); 1646 } 1647 1648 1649 void VspBspTree::ConstructGeometry(BspNode *n, 1650 PolygonContainer &cell) const 1648 BspNodeGeometry &geom) const 1651 1649 { 1652 1650 vector<Plane3> halfSpaces; … … 1726 1724 1727 1725 if (candidatePolys[i]) 1728 cell.push_back(candidatePolys[i]);1726 geom.mPolys.push_back(candidatePolys[i]); 1729 1727 } 1730 1728 } … … 1732 1730 1733 1731 void VspBspTree::ConstructGeometry(BspViewCell *vc, 1734 PolygonContainer&vcGeom) const1732 BspNodeGeometry &vcGeom) const 1735 1733 { 1736 1734 vector<BspLeaf *> leaves = vc->mLeaves; … … 1745 1743 const bool onlyUnmailed) const 1746 1744 { 1747 PolygonContainergeom;1745 BspNodeGeometry geom; 1748 1746 ConstructGeometry(n, geom); 1749 1747 … … 1770 1768 // test all planes of current node if candidate really 1771 1769 // is neighbour 1772 PolygonContainerneighborCandidate;1770 BspNodeGeometry neighborCandidate; 1773 1771 ConstructGeometry(node, neighborCandidate); 1774 1772 … … 1777 1775 { 1778 1776 const int cf = 1779 Polygon3::ClassifyPlane(neighborCandidate ,1777 Polygon3::ClassifyPlane(neighborCandidate.mPolys, 1780 1778 halfSpaces[i], 1781 1779 mEpsilon); … … 1787 1785 if (isAdjacent) 1788 1786 neighbors.push_back(dynamic_cast<BspLeaf *>(node)); 1789 1790 CLEAR_CONTAINER(neighborCandidate);1791 1787 } 1792 1788 } … … 1795 1791 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1796 1792 1797 const int cf = Polygon3::ClassifyPlane(geom ,1793 const int cf = Polygon3::ClassifyPlane(geom.mPolys, 1798 1794 interior->GetPlane(), 1799 1795 mEpsilon); … … 1813 1809 } 1814 1810 1815 CLEAR_CONTAINER(geom);1816 1811 return (int)neighbors.size(); 1817 1812 } … … 1837 1832 { 1838 1833 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1839 1840 1834 BspNode *next; 1841 1842 PolygonContainer geom; 1835 BspNodeGeometry geom; 1843 1836 1844 1837 // todo: not very efficient: constructs full cell everytime 1845 1838 ConstructGeometry(interior, geom); 1846 1839 1847 const int cf = Polygon3::ClassifyPlane(geom, halfspace, mEpsilon); 1840 const int cf = 1841 Polygon3::ClassifyPlane(geom.mPolys, halfspace, mEpsilon); 1848 1842 1849 1843 if (cf == Polygon3::BACK_SIDE) … … 2248 2242 2249 2243 2250 int VspBspTree::CollectMergeCandidates() 2251 { 2252 vector<BspLeaf *> leaves; 2253 2254 // collect the leaves, e.g., the "voxels" that will build the view cells 2255 CollectLeaves(leaves); 2244 int VspBspTree::CollectMergeCandidates(const vector<BspLeaf *> leaves) 2245 { 2256 2246 BspLeaf::NewMail(); 2257 2247 … … 2291 2281 vector<BspRay *> bspRays; 2292 2282 2283 long startTime = GetTime(); 2293 2284 ConstructBspRays(bspRays, rays); 2285 Debug << (int)bspRays.size() << " bsp rays constructed in " << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 2286 2294 2287 map<BspLeaf *, vector<BspLeaf*> > neighborMap; 2295 2296 2288 vector<BspIntersection>::const_iterator iit; 2297 2289 2298 int leaves = 0;2290 int numLeaves = 0; 2299 2291 2300 2292 BspLeaf::NewMail(); … … 2321 2313 leaf->mArea * leaf->mPvs->GetSize(); 2322 2314 2323 ++ leaves;2315 ++ numLeaves; 2324 2316 } 2325 2317 … … 2345 2337 leaf->mArea * leaf->mPvs->GetSize(); 2346 2338 2347 ++ leaves;2339 ++ numLeaves; 2348 2340 } 2349 2341 … … 2379 2371 Debug << "neighbormap size: " << (int)neighborMap.size() << endl; 2380 2372 Debug << "mergequeue: " << (int)mMergeQueue.size() << endl; 2381 Debug << "leaves in queue: " << leaves << endl;2373 Debug << "leaves in queue: " << numLeaves << endl; 2382 2374 Debug << "overall cost: " << BspMergeCandidate::sOverallCost << endl; 2383 2375 2384 2376 CLEAR_CONTAINER(bspRays); 2385 2377 2386 return leaves; 2378 //-- collect the leaves which haven't been found by ray casting 2379 vector<BspLeaf *> leaves; 2380 CollectLeaves(leaves, true, mMaxPvs); 2381 Debug << "found " << (int)leaves.size() << " new leaves" << endl; 2382 //CollectMergeCandidates(leaves); 2383 2384 return numLeaves; 2387 2385 } 2388 2386 … … 2440 2438 mergeStats.nodes = CollectMergeCandidates(rays); 2441 2439 else 2442 mergeStats.nodes = CollectMergeCandidates(); 2440 { 2441 vector<BspLeaf *> leaves; 2442 CollectLeaves(leaves); 2443 mergeStats.nodes = CollectMergeCandidates(leaves); 2444 } 2443 2445 2444 2446 mergeStats.collectTime = TimeDiff(startTime, GetTime()); … … 2735 2737 } 2736 2738 2739 #define USE_ASCII 0 2740 bool VspBspTree::WriteVspBspTree() 2741 { 2742 char fileName[100]; 2743 environment->GetStringValue("VspBspTree.viewCellsFilename", fileName); 2744 2745 /*VssRayContainer::const_iterator it, it_end = samples.end(); 2746 2747 #if USE_ASCII 2748 ofstream samplesOut(fileName); 2749 if (!samplesOut.is_open()) 2750 return false; 2751 2752 for (it = samples.begin(); it != it_end; ++ it) 2753 { 2754 VssRay *ray = *it; 2755 int sourceid = ray->mOriginObject ? ray->mOriginObject->mId : -1; 2756 int termid = ray->mTerminationObject ? ray->mTerminationObject->mId : -1; 2757 2758 samplesOut << ray->GetOrigin().x << " " << ray->GetOrigin().y << " " << ray->GetOrigin().z << " " 2759 << ray->GetTermination().x << " " << ray->GetTermination().y << " " << ray->GetTermination().z << " " 2760 << sourceid << " " << termid << "\n"; 2761 } 2762 #else 2763 ofstream samplesOut(fileName, ios::binary); 2764 if (!samplesOut.is_open()) 2765 return false; 2766 2767 for (it = samples.begin(); it != it_end; ++ it) 2768 { 2769 VssRay *ray = *it; 2770 Vector3 origin(ray->GetOrigin()); 2771 Vector3 termination(ray->GetTermination()); 2772 2773 int sourceid = ray->mOriginObject ? ray->mOriginObject->mId : -1; 2774 int termid = ray->mTerminationObject ? ray->mTerminationObject->mId : -1; 2775 2776 samplesOut.write(reinterpret_cast<char *>(&origin), sizeof(Vector3)); 2777 samplesOut.write(reinterpret_cast<char *>(&termination), sizeof(Vector3)); 2778 samplesOut.write(reinterpret_cast<char *>(&sourceid), sizeof(int)); 2779 samplesOut.write(reinterpret_cast<char *>(&termid), sizeof(int)); 2780 } 2781 #endif 2782 2783 samplesOut.close(); 2784 */ 2785 return true; 2786 } 2787 2788 bool VspBspTree::LoadVspBspTree() 2789 { 2790 /*std::stable_sort(objects.begin(), objects.end(), ilt); 2791 char fileName[100]; 2792 environment->GetStringValue("Preprocessor.samplesFilename", fileName); 2793 2794 Vector3 origin, termination; 2795 // HACK: needed only for lower_bound algorithm to find the 2796 // intersected objects 2797 MeshInstance sObj(NULL); 2798 MeshInstance tObj(NULL); 2799 2800 #if USE_ASCII 2801 ifstream samplesIn(fileName, ios::binary); 2802 if (!samplesIn.is_open()) 2803 return false; 2804 2805 string buf; 2806 while (!(getline(samplesIn, buf)).eof()) 2807 { 2808 sscanf(buf.c_str(), "%f %f %f %f %f %f %d %d", 2809 &origin.x, &origin.y, &origin.z, 2810 &termination.x, &termination.y, &termination.z, 2811 &(sObj.mId), &(tObj.mId)); 2812 2813 Intersectable *sourceObj = NULL; 2814 Intersectable *termObj = NULL; 2815 2816 if (sObj.mId >= 0) 2817 { 2818 ObjectContainer::iterator oit = 2819 lower_bound(objects.begin(), objects.end(), &sObj, ilt); 2820 sourceObj = *oit; 2821 } 2822 2823 if (tObj.mId >= 0) 2824 { 2825 ObjectContainer::iterator oit = 2826 lower_bound(objects.begin(), objects.end(), &tObj, ilt); 2827 termObj = *oit; 2828 } 2829 2830 samples.push_back(new VssRay(origin, termination, sourceObj, termObj)); 2831 } 2832 #else 2833 ifstream samplesIn(fileName, ios::binary); 2834 if (!samplesIn.is_open()) 2835 return false; 2836 2837 while (1) 2838 { 2839 samplesIn.read(reinterpret_cast<char *>(&origin), sizeof(Vector3)); 2840 samplesIn.read(reinterpret_cast<char *>(&termination), sizeof(Vector3)); 2841 samplesIn.read(reinterpret_cast<char *>(&(sObj.mId)), sizeof(int)); 2842 samplesIn.read(reinterpret_cast<char *>(&(tObj.mId)), sizeof(int)); 2843 2844 if (samplesIn.eof()) 2845 break; 2846 2847 Intersectable *sourceObj = NULL; 2848 Intersectable *termObj = NULL; 2849 2850 if (sObj.mId >= 0) 2851 { 2852 ObjectContainer::iterator oit = 2853 lower_bound(objects.begin(), objects.end(), &sObj, ilt); 2854 sourceObj = *oit; 2855 } 2856 2857 if (tObj.mId >= 0) 2858 { 2859 ObjectContainer::iterator oit = 2860 lower_bound(objects.begin(), objects.end(), &tObj, ilt); 2861 termObj = *oit; 2862 } 2863 2864 samples.push_back(new VssRay(origin, termination, sourceObj, termObj)); 2865 } 2866 2867 #endif 2868 samplesIn.close(); 2869 */ 2870 return true; 2871 } 2872 2737 2873 2738 2874 /************************************************************************/ -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
r501 r503 56 56 /// how often this branch has missed the max-cost ratio 57 57 int mMaxCostMisses; 58 59 58 60 59 /** Returns average ray contribution. 61 60 */ … … 164 163 AxisAlignedBox3 *forcedBoundingBox); 165 164 166 /** Returns list of BSP leaves. 167 */ 168 void CollectLeaves(vector<BspLeaf *> &leaves) const; 165 /** Returns list of BSP leaves with pvs smaller than 166 a certain threshold. 167 @param onlyUnmailed if only the unmailed leaves should be considered 168 @param maxPvs the maximal pvs (-1 means unlimited) 169 */ 170 void CollectLeaves(vector<BspLeaf *> &leaves, 171 const bool onlyUnmailed = false, 172 const int maxPvs = -1) const; 169 173 170 174 /** Returns box which bounds the whole tree. … … 203 207 leading to this node. 204 208 */ 205 void ConstructGeometry(BspNode *n, PolygonContainer &cell) const; 206 207 /** Constructs geometry associated with the half space intersections 208 leading to this node. 209 */ 210 void ConstructGeometry(BspViewCell *vc, PolygonContainer &cell) const; 211 212 /** Construct geometry and stores it in a geometry node container. 213 */ 214 void ConstructGeometry(BspNode *n, BspNodeGeometry &cell) const; 209 void ConstructGeometry(BspNode *n, BspNodeGeometry &geom) const; 210 211 /** Construct geometry of view cell. 212 */ 213 void ConstructGeometry(BspViewCell *vc, BspNodeGeometry &geom) const; 215 214 216 215 /** Returns random leaf of BSP tree. … … 284 283 */ 285 284 BspViewCell *GetOutOfBoundsCell() const; 285 286 /** Writes tree to disc. 287 */ 288 bool WriteVspBspTree(); 289 290 /** Loads tree from disc. 291 */ 292 bool LoadVspBspTree(); 286 293 287 294 protected: … … 457 464 /** Evaluates cost ratio for axis aligned splits. 458 465 */ 459 float EvalCostRatio(const VspBspTraversalData &tData,466 /*float EvalCostRatio(const VspBspTraversalData &tData, 460 467 const AxisAlignedBox3 &box, 461 468 const int axis, … … 464 471 int &raysFront, 465 472 int &pvsBack, 466 int &pvsFront); 473 int &pvsFront);*/ 467 474 468 475 /** Selects an axis aligned split plane. … … 542 549 543 550 /** Collects candidates for the merge in the merge queue. 551 @param leaves the leaves to be merged 544 552 @returns number of leaves in queue 545 553 */ 546 int CollectMergeCandidates( );554 int CollectMergeCandidates(const vector<BspLeaf *> leaves); 547 555 /** Collects candidates for the merge in the merge queue. 548 556 @returns number of leaves in queue -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
r501 r503 2007 2007 } 2008 2008 } 2009 2009 2010 2010 2011 int VspKdTree::FindNeighbors(VspKdLeaf *n, -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r492 r503 964 964 for (it = leaves.begin(); it != it_end; ++ it) 965 965 { 966 PolygonContainer cell;967 tree.ConstructGeometry(*it, cell);966 BspNodeGeometry geom; 967 tree.ConstructGeometry(*it, geom); 968 968 969 ExportPolygons(cell); 970 971 CLEAR_CONTAINER(cell); 969 ExportPolygons(geom.mPolys); 972 970 } 973 971 }
Note: See TracChangeset
for help on using the changeset viewer.