- Timestamp:
- 12/14/05 19:38:39 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp
r386 r466 131 131 Vector3 target = xv + yv + mDirection; 132 132 133 ray.intersections.clear(); 134 ray.kdLeaves.clear(); 135 ray.testedObjects.clear(); 136 ray.bspIntersections.clear(); 137 133 ray.Clear(); 138 134 ray.Init(mPosition, target, Ray::LOCAL_RAY); 139 135 -
trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
r462 r466 73 73 virtual bool 74 74 ExportRays(const RayContainer &rays, 75 76 77 78 79 75 const float length=1000, 76 const RgbColor &color = RgbColor(1,1,1) 77 ) = 0; 78 79 virtual bool 80 80 ExportRays(const VssRayContainer &rays, 81 82 83 81 const RgbColor &color = RgbColor(1,1,1) 82 ) = 0; 83 84 84 virtual void 85 85 ExportViewCells(const ViewCellContainer &viewCells) = 0; -
trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp
r462 r466 792 792 // $$ JB TEMPORARY solution -> should add object PVS or explictly computed 793 793 // kd tree PVS 794 if (leaf->mKdPvs.AddSample(node)) 794 float contribution; 795 if (leaf->mKdPvs.AddSample(node, contribution)) 795 796 totalPvsSize++; 796 797 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h
r406 r466 31 31 { 32 32 public: 33 Pvs(): mSamples(0), mEntries() {} 33 Pvs(): mSamples(0), mEntries() {} 34 35 int mSamples; 36 37 int Compress() {return 0;} 38 int GetSize() const {return (int)mEntries.size();} 39 bool Empty() const {return mEntries.size() == 0;} 40 /** Merges pvs of a and pvs of b into this pvs. 41 */ 42 void Merge(const Pvs<T> &a, const Pvs<T> &b); 43 /** Difference of pvs to pvs b. 44 @returns number of different entries. 45 */ 46 int Diff(const Pvs<T> &b); 47 48 PvsData<T> *Find(T sample); 49 bool AddSample(T sample, float &contribution); 50 int AddSample(T sample); 34 51 35 int mSamples; 36 37 int Compress() {return 0;} 38 int GetSize() const {return (int)mEntries.size();} 39 bool Empty() const {return mEntries.size() == 0;} 40 /** Merges pvs of a and pvs of b into this pvs. 41 */ 42 void Merge(const Pvs<T> &a, const Pvs<T> &b); 43 /** Difference of pvs to pvs b. 44 @returns number of different entries. 45 */ 46 int Diff(const Pvs<T> &b); 47 48 PvsData<T> *Find(T sample); 49 int AddSample(T sample); 50 51 void GetData(const int index, T &entry, PvsData<T> &data); 52 std::map<T, PvsData<T>, LtSample<T> > mEntries; 52 void GetData(const int index, T &entry, PvsData<T> &data); 53 std::map<T, PvsData<T>, LtSample<T> > mEntries; 53 54 }; 54 55 … … 116 117 int Pvs<T>::AddSample(T sample) 117 118 { 118 int result; 119 PvsData<T> *data = Find(sample); 119 float dummy; 120 return AddSample(sample, dummy) ? 1 : 0; 121 } 120 122 121 if (data) 122 { 123 data->mVisibleSamples ++; 124 result = 0; 125 126 } 127 else 128 { 129 mEntries[sample] = PvsData<T>(1); 130 result = 1; 131 } 132 133 return result; 123 template <typename T> 124 bool Pvs<T>::AddSample(T sample, float &contribution) 125 { 126 PvsData<T> *data = Find(sample); 127 128 if (data) { 129 data->mVisibleSamples++; 130 contribution = 1.0f/data->mVisibleSamples; 131 return false; 132 } 133 else { 134 mEntries[sample] = PvsData<T>(1); 135 contribution = 1.0f; 136 return true; 137 } 134 138 } 135 139 -
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp
r448 r466 220 220 } 221 221 222 Ray::Ray(const VssRay &vssRay): 223 loc(vssRay.mOrigin), 224 sourceObject(0, vssRay.mOriginObject, 0), 225 mType(LOCAL_RAY) 226 { 227 float len = vssRay.Length(); 228 229 if (!len) 230 len = Limits::Small; 231 232 dir = vssRay.GetDir() / len; 233 234 if (vssRay.mTerminationObject) 235 intersections.push_back(Intersection(len, vssRay.mTerminationObject, 0)); 236 237 Precompute(); 238 } 222 void 223 Ray::Init(const VssRay &vssRay) 224 { 225 loc = vssRay.mOrigin; 226 sourceObject = Intersection(0, vssRay.mOriginObject, 0); 227 mType = LOCAL_RAY; 228 229 float len = vssRay.Length(); 230 231 if (!len) 232 len = Limits::Small; 233 234 dir = vssRay.GetDir() / len; 235 236 if (vssRay.mTerminationObject) 237 intersections.push_back(Intersection(len, vssRay.mTerminationObject, 0)); 238 239 Precompute(); 240 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h
r448 r466 59 59 }; 60 60 61 struct BspIntersection {62 // the point of intersection63 float mT;64 65 BspLeaf *mLeaf;66 67 BspIntersection(const float t, BspLeaf *l):68 mT(t), mLeaf(l) {}69 70 BspIntersection() {}71 72 bool operator<(const BspIntersection &b) const {73 return mT <b.mT; }74 };75 61 76 62 // I should have some abstract cell data type !!! here … … 80 66 81 67 vector<Intersection> intersections; 82 vector<BspIntersection> bspIntersections;68 // vector<BspIntersection> bspIntersections; 83 69 vector<KdLeaf *> kdLeaves; 84 70 vector<Intersectable *> testedObjects; … … 107 93 /** Construct ray from a vss ray. 108 94 */ 109 Ray(const VssRay &vssRay); 110 95 Ray(const VssRay &vssRay) { 96 Init(vssRay); 97 } 98 99 void Clear() { 100 intersections.clear(); 101 kdLeaves.clear(); 102 testedObjects.clear(); 103 // bspIntersections.clear(); 104 } 105 106 void Init(const VssRay &vssRay); 107 111 108 Intersectable *GetIntersectionObject(const int i) const { 112 109 return intersections[i].mObject; -
trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp
r464 r466 525 525 526 526 // viewcells->UpdatePVS(newVssRays); 527 // get viewcells as kd tree boxes 528 vector<AxisAlignedBox3> kdViewcells; 529 530 if (0) { 531 vector<KdLeaf *> leaves; 532 mKdTree->CollectLeaves(leaves); 533 vector<KdLeaf *>::const_iterator it; 534 int targetLeaves = 50; 535 float prob = targetLeaves/(float)leaves.size(); 536 for (it = leaves.begin(); it != leaves.end(); ++it) 537 if (RandomValue(0.0f,1.0f) < prob) 538 kdViewcells.push_back(mKdTree->GetBox(*it)); 539 540 float avgPvs = GetAvgPvsSize(rssTree, kdViewcells); 541 cout<<"Initial average PVS size = "<<avgPvs<<endl; 542 } 543 544 527 545 528 int samples = 0; 546 529 int pass = 0; … … 563 546 for (int i=0; i < rays.size(); i++) 564 547 CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays); 565 548 549 if (mUseViewcells) { 550 551 552 /// compute view cell contribution of rays 553 mViewCellsManager->ComputeSampleContributions(vssRays 554 ); 555 556 557 float pvs = rssTree->GetAvgPvsSize(); 558 cout<<"*****************************\n"; 559 cout<<samples<<" avgPVS ="<<pvs<<endl; 560 cout<<"RssTree root PVS size = "<<rssTree->GetRootPvsSize()<<endl; 561 cout<<"*****************************\n"; 562 } 563 564 565 566 566 rssTree->AddRays(vssRays); 567 567 568 568 if (mUpdateSubdivision) { 569 569 int subdivided = rssTree->UpdateSubdivision(); 570 570 cout<<"subdivided leafs = "<<subdivided<<endl; 571 571 cout<<"#total leaves = "<<rssTree->stat.Leaves()<<endl; 572 573 572 } 574 573 575 574 if (mUseViewcells) { 576 float avgPvs = GetAvgPvsSize(rssTree, kdViewcells);577 cout<<"Average PVS size = "<<avgPvs<<endl;575 // float avgPvs = GetAvgPvsSize(rssTree, kdViewcells); 576 // cout<<"Average PVS size = "<<avgPvs<<endl; 578 577 } 579 578 … … 590 589 samples+=num; 591 590 592 if (mUseViewcells) {593 594 //-- prepare traversal rays for view cell intersections595 RayContainer passRays;596 597 VssRayContainer::const_iterator it, it_end = vssRays.end();598 599 for (it = vssRays.begin(); it != it_end; ++ it)600 passRays.push_back(new Ray(*(*it)));601 602 int sampleContributions = 0;603 int contributingSamples = 0;604 605 /// compute view cell contribution of rays606 mViewCellsManager->ComputeSampleContributions(passRays,607 sampleContributions,608 contributingSamples);609 610 //-- save rays for post processing611 if (((int)storedRays.size() < mViewCellsManager->GetPostProcessSamples()) ||612 ((int)storedRays.size() < mViewCellsManager->GetVisualizationSamples()))613 {614 RayContainer::const_iterator it, it_end = passRays.end();615 616 for (it = passRays.begin(); it != it_end; ++ it)617 storedRays.push_back(new Ray(*(*it)));618 }619 else620 {621 CLEAR_CONTAINER(passRays);622 }623 624 float pvs = rssTree->GetAvgPvsSize();625 cout<<"*****************************\n";626 cout<<samples<<" avgPVS ="<<pvs<<endl;627 cout<<"sample contributions ="<<sampleContributions<<endl;628 cout<<"contributing sample ="<<contributingSamples<<endl;629 cout<<"RssTree root PVS size = "<<rssTree->GetRootPvsSize()<<endl;630 cout<<"*****************************\n";631 }632 591 633 592 if (mExportPvs) { … … 645 604 646 605 if (mUseViewcells) { 606 607 VssRayContainer storedRays; 608 rssTree->CollectRays(storedRays, Max( 609 mViewCellsManager->GetPostProcessSamples(), 610 mViewCellsManager->GetVisualizationSamples())); 647 611 648 612 //-- post process view cells … … 651 615 //-- several visualizations and statistics 652 616 mViewCellsManager->PrintStatistics(Debug); 653 654 //-- render simulation after merge 655 cout << "\nevaluating render time of final view cells ... "; 656 657 const SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 658 659 cout << " finished" << endl; 660 661 cout << ss << endl; 662 Debug << ss << endl; 663 617 664 618 mViewCellsManager->Visualize(mObjects, storedRays); 665 } 666 619 620 CLEAR_CONTAINER(storedRays); 621 622 //-- render simulation after merge 623 cout << "\nevaluating bsp view cells render time after merge ... "; 624 625 const SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 626 627 cout << " finished" << endl; 628 cout << ss << endl; 629 Debug << ss << endl; 630 631 } 632 667 633 delete rssTree; 668 634 -
trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.cpp
r464 r466 2051 2051 return box; 2052 2052 } 2053 2054 2055 int 2056 RssTree::CollectRays(VssRayContainer &rays, 2057 const int number) 2058 { 2059 VssRayContainer allRays; 2060 CollectRays(allRays); 2061 2062 int desired = min(number, (int)allRays.size()); 2063 float prob = desired/(float)allRays.size(); 2064 while (rays.size() < desired) { 2065 VssRayContainer::const_iterator it = allRays.begin(); 2066 for (; it != allRays.end() && rays.size() < desired; it++) { 2067 if (Random(1.0f) < prob) 2068 rays.push_back(*it); 2069 } 2070 } 2071 return rays.size(); 2072 } 2073 2074 2075 int 2076 RssTree::CollectRays(VssRayContainer &rays 2077 ) 2078 { 2079 VssRay::NewMail(); 2080 2081 stack<RssTreeNode *> tstack; 2082 tstack.push(root); 2083 2084 while (!tstack.empty()) { 2085 RssTreeNode *node = tstack.top(); 2086 tstack.pop(); 2087 2088 if (node->IsLeaf()) { 2089 RssTreeLeaf *leaf = (RssTreeLeaf *)node; 2090 // update pvs size 2091 RssTreeNode::RayInfoContainer::const_iterator it = leaf->rays.begin(); 2092 for (;it != leaf->rays.end(); ++it) 2093 if (!(*it).mRay->Mailed()) { 2094 (*it).mRay->Mail(); 2095 rays.push_back((*it).mRay); 2096 } 2097 } else { 2098 RssTreeInterior *in = (RssTreeInterior *)node; 2099 // both nodes for directional splits 2100 tstack.push(in->front); 2101 tstack.push(in->back); 2102 } 2103 } 2104 2105 return rays.size(); 2106 } -
trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.h
r464 r466 857 857 ); 858 858 859 int 860 CollectRays(VssRayContainer &rays, 861 const int number); 862 863 int 864 CollectRays(VssRayContainer &rays 865 ); 866 859 867 }; 860 868 -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r462 r466 32 32 const Ray::Intersection &origin) 33 33 { 34 ray.intersections.clear(); 35 ray.kdLeaves.clear(); 36 ray.testedObjects.clear(); 37 ray.bspIntersections.clear(); 34 ray.Clear(); 38 35 39 36 ray.mFlags |= Ray::STORE_KDLEAVES | Ray::STORE_BSP_INTERSECTIONS; … … 59 56 60 57 void 61 SamplingPreprocessor::CastRays(const RayContainer &rays, 62 int &sampleContributions, 63 int &contributingSamples) 58 SamplingPreprocessor::CastRays(const RayContainer &rays) 64 59 { 65 // cast ray to KD tree to find intersection with other objects 66 RayContainer::const_iterator it, it_end = rays.end(); 67 68 for (it = rays.begin(); it != it_end; ++it) 69 mKdTree->CastRay(*(*it)); 70 71 // for KD tree, intersecting view cells are already known, so no 72 // additional ray must be cast to them 73 const bool castRaysToViewCells = 74 (mViewCellsManager->GetType() != ViewCellsManager::KD); 75 76 mViewCellsManager->ComputeSampleContributions(rays, 77 sampleContributions, 78 contributingSamples, 79 castRaysToViewCells); 60 // cast ray to KD tree to find intersection with other objects 61 RayContainer::const_iterator it, it_end = rays.end(); 62 63 VssRayContainer vssRays; 64 for (it = rays.begin(); it != it_end; ++it) { 65 mKdTree->CastRay(*(*it)); 66 vssRays.push_back(new VssRay(*(*it))); 67 } 68 69 mViewCellsManager->ComputeSampleContributions(vssRays); 70 CLEAR_CONTAINER(vssRays); 80 71 } 81 72 … … 84 75 { 85 76 // cast ray to KD tree to find intersection with other objects 86 mKdTree->CastRay(ray); 87 88 bool castRayToViewCells = mViewCellsManager->GetType() != ViewCellsManager::KD; 89 90 return mViewCellsManager->ComputeSampleContributions(ray, castRayToViewCells); 77 mKdTree->CastRay(ray); 78 VssRay vssRay(ray); 79 mViewCellsManager->ComputeSampleContributions(vssRay); 80 return vssRay.mPvsContribution; 91 81 } 92 82 … … 395 385 mViewCellsManager->Construct(objects, mVssSampleRays); 396 386 397 mViewCellsManager->PostProcess(objects, mSampleRays); 387 // $$JB temporary removed 388 // mViewCellsManager->PostProcess(objects, mSampleRays); 398 389 399 390 //-- several visualizations and statistics … … 409 400 Debug << ss << endl; 410 401 411 mViewCellsManager->Visualize(objects, mSampleRays); 402 // $$JB temporary removed 403 //mViewCellsManager->Visualize(objects, mSampleRays); 412 404 413 405 return true; … … 419 411 int &contributingSamples) 420 412 { 421 422 CastRays(newRays, sampleContributions, contributingSamples);423 424 425 413 // cast rays to view cells 414 CastRays(newRays); 415 416 // save rays for view cells construction 417 if (!mViewCellsManager->ViewCellsConstructed()) 426 418 { 427 419 if ((int)mVssSampleRays.size() < mViewCellsManager->GetConstructionSamples()) 428 420 { 429 430 431 432 433 } 434 421 RayContainer::const_iterator it, it_end = newRays.end(); 422 423 for (it = newRays.begin(); it != it_end; ++ it) 424 mVssSampleRays.push_back(new VssRay(*(*it))); 425 } 426 else 435 427 { 436 437 438 439 440 441 } 442 } 443 444 445 428 // construct view cells 429 mViewCellsManager->Construct(objects, mVssSampleRays); 430 431 // throw away samples 432 //CLEAR_CONTAINER(mVssSampleRays); 433 } 434 } 435 // Need rays (with ordered intersections) for post processing => collect new rays 436 if (((int)mSampleRays.size() < mViewCellsManager->GetPostProcessSamples()) || 437 ((int)mSampleRays.size() < mViewCellsManager->GetVisualizationSamples())) 446 438 { 447 448 449 450 451 } 452 } 439 RayContainer::const_iterator it, it_end = newRays.end(); 440 441 for (it = newRays.begin(); it != it_end; ++ it) 442 mSampleRays.push_back(new Ray(*(*it))); 443 } 444 } -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h
r463 r466 28 28 const Vector3 &point, 29 29 const Vector3 &direction, 30 31 32 33 34 30 const int type, 31 const Ray::Intersection &source); 32 33 /** Refined sampling for finding "holes", i.e., difficult visibility. 34 */ 35 35 void 36 36 HoleSamplingPass(); 37 38 37 38 /** Casts a bundle of sample rays into the scene. 39 39 @param sampleContributions the number of sample contributions 40 40 @param contributingSamples the number of samples contributing 41 41 */ 42 42 void 43 CastRays(const RayContainer &rays, 44 int &sampleContributions, 45 int &contributingSamples); 43 CastRays(const RayContainer &rays); 46 44 47 45 /** Casts a single ray into the scene. -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r463 r466 1764 1764 } 1765 1765 1766 int BspTree::CastRay(Ray &ray) 1766 int 1767 BspTree::_CastRay(Ray &ray) 1767 1768 { 1768 1769 int hits = 0; … … 1833 1834 if (!leaf->mViewCell->Mailed()) 1834 1835 { 1835 ray.bspIntersections.push_back(Ray::BspIntersection(maxt, leaf));1836 // ray.bspIntersections.push_back(Ray::BspIntersection(maxt, leaf)); 1836 1837 leaf->mViewCell->Mail(); 1837 1838 ++ hits; … … 1859 1860 1860 1861 return hits; 1862 } 1863 1864 1865 int 1866 BspTree::CastLineSegment(const Vector3 &origin, 1867 const Vector3 &termination, 1868 vector<ViewCell *> &viewcells 1869 ) 1870 { 1871 int hits = 0; 1872 stack<BspRayTraversalData> tStack; 1873 1874 float mint = 0.0f, maxt = 1.0f; 1875 1876 Intersectable::NewMail(); 1877 1878 Vector3 entp = origin; 1879 Vector3 extp = termination; 1880 1881 BspNode *node = mRoot; 1882 BspNode *farChild = NULL; 1883 1884 while (1) { 1885 if (!node->IsLeaf()) { 1886 BspInterior *in = dynamic_cast<BspInterior *>(node); 1887 1888 Plane3 splitPlane = in->GetPlane(); 1889 const int entSide = splitPlane.Side(entp); 1890 const int extSide = splitPlane.Side(extp); 1891 1892 if (entSide < 0) { 1893 node = in->GetBack(); 1894 1895 if(extSide <= 0) // plane does not split ray => no far child 1896 continue; 1897 1898 farChild = in->GetFront(); // plane splits ray 1899 1900 } else 1901 if (entSide > 0) { 1902 node = in->GetFront(); 1903 1904 if (extSide >= 0) // plane does not split ray => no far child 1905 continue; 1906 1907 farChild = in->GetBack(); // plane splits ray 1908 } 1909 else // ray and plane are coincident 1910 { 1911 // WHAT TO DO IN THIS CASE ? 1912 //break; 1913 node = in->GetFront(); 1914 continue; 1915 } 1916 1917 // push data for far child 1918 tStack.push(BspRayTraversalData(farChild, extp, maxt)); 1919 1920 // find intersection of ray segment with plane 1921 float t; 1922 extp = splitPlane.FindIntersection(origin, extp, &t); 1923 maxt *= t; 1924 1925 } else { 1926 // reached leaf => intersection with view cell 1927 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 1928 1929 if (!leaf->mViewCell->Mailed()) { 1930 viewcells.push_back(leaf->mViewCell); 1931 leaf->mViewCell->Mail(); 1932 hits++; 1933 } 1934 1935 //-- fetch the next far child from the stack 1936 if (tStack.empty()) 1937 break; 1938 1939 entp = extp; 1940 mint = maxt; // NOTE: need this? 1941 1942 BspRayTraversalData &s = tStack.top(); 1943 1944 node = s.mNode; 1945 extp = s.mExitPoint; 1946 maxt = s.mMaxT; 1947 1948 tStack.pop(); 1949 } 1950 } 1951 return hits; 1861 1952 } 1862 1953 … … 2355 2446 int contribution = 0; 2356 2447 Ray *ray = (*it)->mRay; 2357 2448 float relContribution; 2358 2449 if (!ray->intersections.empty()) 2359 contribution += vc->GetPvs().AddSample(ray->intersections[0].mObject);2450 contribution += vc->GetPvs().AddSample(ray->intersections[0].mObject, relContribution); 2360 2451 2361 2452 if (ray->sourceObject.mObject) 2362 contribution += vc->GetPvs().AddSample(ray->sourceObject.mObject );2453 contribution += vc->GetPvs().AddSample(ray->sourceObject.mObject, relContribution); 2363 2454 2364 2455 if (contribution) -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r463 r466 407 407 @returns the number of intersections with objects stored in the tree. 408 408 */ 409 int CastRay(Ray &ray); 409 int 410 _CastRay(Ray &ray); 411 412 413 int 414 CastLineSegment(const Vector3 &origin, 415 const Vector3 &termination, 416 ViewCellContainer &viewcells 417 ); 410 418 411 419 /// bsp tree construction types … … 838 846 }; 839 847 848 struct BspIntersection { 849 // the point of intersection 850 float mT; 851 852 BspLeaf *mLeaf; 853 854 BspIntersection(const float t, BspLeaf *l): 855 mT(t), mLeaf(l) {} 856 857 BspIntersection() {} 858 859 bool operator<(const BspIntersection &b) const { 860 return mT <b.mT; } 861 }; 862 840 863 #endif -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r465 r466 67 67 } 68 68 69 void ViewCellsManager::ComputeSampleContributions(const RayContainer &rays, 70 int &sampleContributions, 71 int &contributingSamples, 72 const bool castRays) 73 { 74 // view cells not yet constructed 75 if (!ViewCellsConstructed()) 76 return; 77 78 RayContainer::const_iterator it, it_end = rays.end(); 79 80 sampleContributions = 0; 81 contributingSamples = 0; 82 83 for (it = rays.begin(); it != it_end; ++ it) 84 { 85 sampleContributions += ComputeSampleContributions(*(*it), castRays); 86 contributingSamples += sampleContributions > 0; 87 } 69 void 70 ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays 71 ) 72 { 73 // view cells not yet constructed 74 if (!ViewCellsConstructed()) 75 return; 76 77 VssRayContainer::const_iterator it, it_end = rays.end(); 78 for (it = rays.begin(); it != it_end; ++ it) { 79 ComputeSampleContributions(*(*it)); 80 } 88 81 } 89 82 … … 277 270 } 278 271 279 int BspViewCellsManager::ComputeSampleContributions(Ray &ray, const bool castRay) 280 { 281 // view cells not yet constructed 282 if (!ViewCellsConstructed()) 283 return 0; 284 285 int contributingSamples = 0; 286 287 if (castRay) 288 mBspTree->CastRay(ray); 289 290 //if (mBspTree->bspIntersections.empty()) return 0; 291 292 Intersectable *tObject = 293 !ray.intersections.empty() ? ray.intersections[0].mObject : NULL; 294 295 Intersectable *sObject = ray.sourceObject.mObject; 296 297 if (sObject || tObject) 298 { 299 // object can be seen from the view cell => add to view cell pvs 300 for (int j = 0; j < (int)ray.bspIntersections.size(); ++ j) 301 { 302 BspLeaf *leaf = ray.bspIntersections[j].mLeaf; 303 304 // if ray not outside of view space 305 if (leaf->GetViewCell() != mBspTree->GetRootCell()) 306 { 307 if (sObject) 308 { 309 contributingSamples += 310 leaf->GetViewCell()->GetPvs().AddSample(sObject); 311 } 312 313 if (tObject) 314 { 315 contributingSamples += 316 leaf->GetViewCell()->GetPvs().AddSample(tObject); 317 } 318 } 319 } 320 } 321 322 // rays passing through this viewcell 323 if (0) 324 for (int j = 1; j < ((int)ray.bspIntersections.size() - 1); ++ j) 325 { 326 BspLeaf *leaf = ray.bspIntersections[j].mLeaf; 327 328 if (leaf->GetViewCell() != mBspTree->GetRootCell()) 329 leaf->GetViewCell()-> 330 AddPassingRay(ray, contributingSamples ? 1 : 0); 331 } 332 333 return contributingSamples; 334 } 335 336 int BspViewCellsManager::PostProcess(const ObjectContainer &objects, 337 const RayContainer &rays) 338 { 339 if (!ViewCellsConstructed()) 272 void 273 ViewCellsManager::ComputeSampleContributions(VssRay &ray) 274 { 275 276 ViewCellContainer viewcells; 277 278 CastLineSegment(ray.mOrigin, 279 ray.mTermination, 280 viewcells 281 ); 282 283 ViewCellContainer::const_iterator it = viewcells.begin(); 284 for (; it != viewcells.end(); ++it) { 285 ViewCell *viewcell = *it; 286 287 // if ray not outside of view space 288 float contribution; 289 bool added = 290 viewcell->GetPvs().AddSample(ray.mTerminationObject, 291 contribution 292 ); 293 if (added) 294 ray.mPvsContribution++; 295 296 ray.mRelativePvsContribution += contribution; 297 } 298 299 } 300 301 int 302 BspViewCellsManager::CastLineSegment(const Vector3 &origin, 303 const Vector3 &termination, 304 ViewCellContainer &viewcells 305 ) 306 { 307 return mBspTree->CastLineSegment(origin, termination, viewcells); 308 } 309 310 int 311 BspViewCellsManager::PostProcess(const ObjectContainer &objects, 312 const VssRayContainer &rays) 313 { 314 if (!ViewCellsConstructed()) 340 315 { 341 316 Debug << "view cells not constructed" << endl; … … 391 366 long startTime = GetTime(); 392 367 368 // $$JB we do not have connectivity information from the ray in the moment 369 // perhaps we could recast the rays or rember the cells traversed inside the 370 // vssray (which would on other hand create some overhead) 393 371 //-- merge or subdivide view cells 394 372 int merged = 0; 373 #if 0 395 374 396 375 RayContainer::const_iterator rit, rit_end = rays.end(); … … 427 406 } 428 407 } 429 408 #endif 430 409 //-- stats and visualizations 431 410 cout << "finished" << endl; … … 443 422 444 423 void BspViewCellsManager::Visualize(const ObjectContainer &objects, 445 const RayContainer &sampleRays)446 { 447 448 449 450 451 452 453 454 455 { 456 457 458 459 460 { 461 462 463 464 } 465 466 424 const VssRayContainer &sampleRays) 425 { 426 if (!ViewCellsConstructed()) 427 return; 428 429 //-- recount pvs 430 ViewCellsStatistics vcStats; 431 mBspTree->EvaluateViewCellsStats(vcStats); 432 433 if (1) // export view cells 434 { 435 cout << "exporting view cells after merge ... "; 436 Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 437 438 if (exporter) 439 { 440 exporter->ExportBspViewCellPartition(*mBspTree, vcStats.maxPvs); 441 //exporter->ExportBspViewCellPartition(*mBspTree, 0); 442 delete exporter; 443 } 444 445 cout << "finished" << endl; 467 446 } 468 469 470 471 472 473 474 { 475 476 477 478 } 479 480 447 448 //-- visualization of the BSP splits 449 bool exportSplits = false; 450 environment->GetBoolValue("BspTree.Visualization.exportSplits", exportSplits); 451 452 if (exportSplits) 453 { 454 cout << "exporting splits ... "; 455 ExportSplits(objects, sampleRays); 456 cout << "finished" << endl; 457 } 458 459 ExportBspPvs(objects, sampleRays); 481 460 } 482 461 … … 488 467 489 468 void BspViewCellsManager::ExportSplits(const ObjectContainer &objects, 490 const RayContainer &sampleRays)469 const VssRayContainer &sampleRays) 491 470 { 492 471 Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); … … 510 489 if (0) 511 490 { 512 RayContainer outRays; 513 514 int raysSize = min((int)sampleRays.size(), mVisualizationSamples); 515 516 for (int i = 0; i < raysSize; ++ i) 517 { 518 // only rays piercing geometry 519 if (!sampleRays[i]->intersections.empty()) 520 outRays.push_back(sampleRays[i]); 521 } 522 523 // export rays 524 exporter->ExportRays(outRays, 1000, RgbColor(1, 1, 0)); 525 } 526 491 VssRayContainer outRays; 492 493 int raysSize = min((int)sampleRays.size(), mVisualizationSamples); 494 495 for (int i = 0; i < raysSize; ++ i) 496 { 497 // only rays piercing geometry 498 outRays.push_back(sampleRays[i]); 499 } 500 501 // export rays 502 exporter->ExportRays(outRays, RgbColor(1, 1, 0)); 503 } 504 527 505 if (0) 528 529 506 exporter->ExportGeometry(objects); 507 530 508 delete exporter; 531 509 } … … 533 511 534 512 void BspViewCellsManager::ExportBspPvs(const ObjectContainer &objects, 535 const RayContainer &sampleRays) 536 { 537 const int leafOut = 10; 538 539 ViewCell::NewMail(); 540 541 //-- some rays for output 542 const int raysOut = min((int)sampleRays.size(), mVisualizationSamples); 543 Debug << "visualization using " << raysOut << " samples" << endl; 544 545 546 if (1) 547 { 548 //-- some random view cells and rays for output 549 vector<BspLeaf *> bspLeaves; 550 551 for (int i = 0; i < leafOut; ++ i) 552 bspLeaves.push_back(mBspTree->GetRandomLeaf()); 553 554 for (int i = 0; i < bspLeaves.size(); ++ i) 555 { 556 BspLeaf *leaf = bspLeaves[i]; 557 558 RayContainer vcRays; 559 560 cout << "creating output for view cell " << i << " ... "; 561 562 // check whether we can add the current ray to the output rays 563 for (int k = 0; k < raysOut; ++ k) 564 { 565 Ray *ray = sampleRays[k]; 566 567 for (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 513 const VssRayContainer &sampleRays) 514 { 515 const int leafOut = 10; 516 517 ViewCell::NewMail(); 518 519 //-- some rays for output 520 const int raysOut = min((int)sampleRays.size(), mVisualizationSamples); 521 Debug << "visualization using " << raysOut << " samples" << endl; 522 523 //$$ JB 524 #if 0 525 526 if (1) 527 { 528 //-- some random view cells and rays for output 529 vector<BspLeaf *> bspLeaves; 530 531 for (int i = 0; i < leafOut; ++ i) 532 bspLeaves.push_back(mBspTree->GetRandomLeaf()); 533 534 535 for (int i = 0; i < bspLeaves.size(); ++ i) 536 { 537 BspLeaf *leaf = bspLeaves[i]; 538 539 RayContainer vcRays; 540 541 cout << "creating output for view cell " << i << " ... "; 542 543 // check whether we can add the current ray to the output rays 544 for (int k = 0; k < raysOut; ++ k) 545 { 546 Ray *ray = sampleRays[k]; 547 548 for (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 568 549 { 569 570 571 550 BspLeaf *leaf2 = ray->bspIntersections[j].mLeaf; 551 552 if (leaf->GetViewCell() == leaf2->GetViewCell()) 572 553 { 573 554 vcRays.push_back(ray); 574 555 } 575 556 } 576 557 } 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 { 599 600 601 602 558 559 Intersectable::NewMail(); 560 561 BspViewCell *vc = dynamic_cast<BspViewCell *>(leaf->GetViewCell()); 562 563 //bspLeaves[j]->Mail(); 564 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 565 566 Exporter *exporter = Exporter::GetExporter(s); 567 exporter->SetFilled(); 568 569 exporter->SetWireframe(); 570 //exporter->SetFilled(); 571 572 Material m;//= RandomMaterial(); 573 m.mDiffuseColor = RgbColor(1, 1, 0); 574 exporter->SetForcedMaterial(m); 575 576 if (vc->GetMesh()) 577 exporter->ExportViewCell(vc); 578 else 579 { 580 PolygonContainer vcGeom; 581 // export view cell geometry 582 mBspTree->ConstructGeometry(vc, vcGeom); 583 exporter->ExportPolygons(vcGeom); 603 584 CLEAR_CONTAINER(vcGeom); 604 585 } 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 { 622 623 586 587 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 588 << ", piercing rays=" << (int)vcRays.size() << endl; 589 590 // export rays piercing this view cell 591 exporter->ExportRays(vcRays, 1000, RgbColor(0, 1, 0)); 592 593 m.mDiffuseColor = RgbColor(1, 0, 0); 594 exporter->SetForcedMaterial(m); 595 596 // exporter->SetWireframe(); 597 exporter->SetFilled(); 598 599 ViewCellPvsMap::iterator it, it_end = vc->GetPvs().mEntries.end(); 600 // output PVS of view cell 601 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 602 { 603 Intersectable *intersect = (*it).first; 604 if (!intersect->Mailed()) 624 605 { 625 626 606 exporter->ExportIntersectable(intersect); 607 intersect->Mail(); 627 608 } 628 609 } 629 630 631 632 } 633 } 634 635 { 636 637 638 639 640 641 642 643 644 645 { 646 610 611 DEL_PTR(exporter); 612 cout << "finished" << endl; 613 } 614 } 615 else 616 { 617 ViewCellContainer viewCells; 618 RayContainer vcRays; 619 620 mBspTree->CollectViewCells(viewCells); 621 stable_sort(viewCells.begin(), viewCells.end(), vc_gt); 622 623 int limit = min(leafOut, (int)viewCells.size()); 624 625 for (int i = 0; i < limit; ++ i) 626 { 627 cout << "creating output for view cell " << i << " ... "; 647 628 648 629 Intersectable::NewMail(); … … 721 702 } 722 703 } 704 #endif 723 705 } 724 706 … … 822 804 823 805 int KdViewCellsManager::PostProcess(const ObjectContainer &objects, 824 const RayContainer &rays)806 const VssRayContainer &rays) 825 807 { 826 808 return 0; … … 828 810 829 811 void KdViewCellsManager::Visualize(const ObjectContainer &objects, 830 const RayContainer &sampleRays)812 const VssRayContainer &sampleRays) 831 813 { 832 814 if (!ViewCellsConstructed()) … … 837 819 int limit = min(mVisualizationSamples, (int)sampleRays.size()); 838 820 839 RayContainer *rays = newRayContainer[pvsOut];821 VssRayContainer *rays = new VssRayContainer[pvsOut]; 840 822 841 823 for (int i = 0; i < limit; ++ i) 842 824 { 843 Ray *ray = sampleRays[i]; 844 845 if (!ray->intersections.empty()) 846 { 847 // check whether we can add this to the rays 848 for (int j = 0; j < pvsOut; j++) 849 { 850 if (objects[j] == ray->intersections[0].mObject) 851 { 852 rays[j].push_back(ray); 853 } 854 } 855 } 856 } 825 VssRay *ray = sampleRays[i]; 826 827 // check whether we can add this to the rays 828 for (int j = 0; j < pvsOut; j++) 829 { 830 if (objects[j] == ray->mTerminationObject) 831 { 832 rays[j].push_back(ray); 833 } 834 } 835 } 836 857 837 858 838 bool exportRays = false; 859 839 if (exportRays) { 860 840 Exporter *exporter = NULL; 861 841 exporter = Exporter::GetExporter("sample-rays.x3d"); 862 842 exporter->SetWireframe(); … … 864 844 865 845 for (i=0; i < pvsOut; i++) 866 exporter->ExportRays(rays[i], 1000,RgbColor(1, 0, 0));846 exporter->ExportRays(rays[i], RgbColor(1, 0, 0)); 867 847 exporter->SetFilled(); 868 848 … … 893 873 } 894 874 895 exporter->ExportRays(rays[k], 1000,RgbColor(0, 1, 0));875 exporter->ExportRays(rays[k], RgbColor(0, 1, 0)); 896 876 exporter->SetFilled(); 897 877 … … 914 894 } 915 895 916 int KdViewCellsManager::ComputeSampleContributions(Ray &ray, const bool castRay)917 {918 // view cells not yet constructed919 if (!ViewCellsConstructed())920 return 0;921 922 if (castRay)923 mKdTree->CastRay(ray);924 925 if (ray.kdLeaves.empty())926 return 0;927 928 Intersectable *tObject =929 !ray.intersections.empty() ? ray.intersections[0].mObject : NULL;930 931 Intersectable *sObject =932 ray.sourceObject.mObject;933 934 int contributingSamples = 0;935 936 int objects = 0;937 938 if (sObject)939 objects++;940 if (tObject)941 objects++;942 943 for (int j = 1; j < ((int)ray.kdLeaves.size() - 1); ++ j)944 {945 ray.kdLeaves[j]->AddPassingRay2(ray, objects,946 (int)ray.kdLeaves.size());947 }948 949 if (!objects)950 return 0;951 952 for (int j=0; j < ray.kdLeaves.size(); j++)953 {954 KdNode *node = GetNodeForPvs(ray.kdLeaves[j]);955 956 if (sObject)957 contributingSamples += sObject->mKdPvs.AddSample(node);958 if (tObject)959 contributingSamples += tObject->mKdPvs.AddSample(node);960 }961 962 return contributingSamples;963 }964 896 965 897 … … 976 908 void KdViewCellsManager::PrintStatistics(ostream &s) const 977 909 { 910 } 911 912 913 int 914 KdViewCellsManager::CastLineSegment(const Vector3 &origin, 915 const Vector3 &termination, 916 ViewCellContainer &viewcells 917 ) 918 { 919 920 return 0; 978 921 } 979 922 … … 1031 974 } 1032 975 1033 int VspKdViewCellsManager::ComputeSampleContributions(Ray &ray, const bool castRay) 1034 { 1035 // view cells not yet constructed 976 977 ViewCell *VspKdViewCellsManager::GenerateViewCell(Mesh *mesh) const 978 { 979 return new VspKdViewCell(mesh); 980 } 981 982 int VspKdViewCellsManager::PostProcess(const ObjectContainer &objects, 983 const VssRayContainer &rays) 984 { 1036 985 if (!ViewCellsConstructed()) 1037 986 return 0; 1038 987 1039 // if (castRay)1040 // mVspKdTree->CastRay(ray);1041 1042 int sampleContributions = 0;1043 1044 return sampleContributions;1045 }1046 1047 ViewCell *VspKdViewCellsManager::GenerateViewCell(Mesh *mesh) const1048 {1049 return new VspKdViewCell(mesh);1050 }1051 1052 int VspKdViewCellsManager::PostProcess(const ObjectContainer &objects,1053 const RayContainer &rays)1054 {1055 if (!ViewCellsConstructed())1056 return 0;1057 1058 988 return mVspKdTree->MergeLeaves(); 1059 989 } 1060 990 1061 991 void VspKdViewCellsManager::Visualize(const ObjectContainer &objects, 1062 const RayContainer &sampleRays)992 const VssRayContainer &sampleRays) 1063 993 { 1064 994 if (!ViewCellsConstructed()) … … 1079 1009 1080 1010 if (exportRays) 1081 {1011 { 1082 1012 int raysSize = 2000; 1083 1013 float prob = raysSize / (float)sampleRays.size(); … … 1085 1015 exporter->SetWireframe(); 1086 1016 1087 RayContainer rays;1017 VssRayContainer rays; 1088 1018 1089 1019 for (int i = 0; i < sampleRays.size(); ++ i) … … 1093 1023 } 1094 1024 1095 exporter->ExportRays(rays, 1000,RgbColor(1, 0, 0));1025 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 1096 1026 } 1097 1027 … … 1165 1095 exporter->SetWireframe(); 1166 1096 1167 RayContainer rays;1097 VssRayContainer rays; 1168 1098 1169 1099 for (int i = 0; i < sampleRays.size(); ++ i) 1170 1100 { 1171 1172 1173 } 1174 exporter->ExportRays(rays, 1000,RgbColor(1, 0, 0));1101 if (RandomValue(0,1) < prob) 1102 rays.push_back(sampleRays[i]); 1103 } 1104 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 1175 1105 } 1176 1106 … … 1191 1121 } 1192 1122 1123 1124 int 1125 VspKdViewCellsManager::CastLineSegment(const Vector3 &origin, 1126 const Vector3 &termination, 1127 ViewCellContainer &viewcells 1128 ) 1129 { 1130 1131 return 0; 1132 } 1193 1133 1194 1134 /**********************************************************************/ … … 1252 1192 } 1253 1193 1254 int VspBspViewCellsManager::ComputeSampleContributions(Ray &ray, const bool castRay)1255 {1256 // view cells not yet constructed1257 if (!ViewCellsConstructed())1258 return 0;1259 1260 int contributingSamples = 0;1261 1262 if (castRay)1263 mVspBspTree->CastRay(ray);1264 1265 Intersectable *tObject =1266 !ray.intersections.empty() ? ray.intersections[0].mObject : NULL;1267 1268 Intersectable *sObject = ray.sourceObject.mObject;1269 1270 if (sObject || tObject)1271 {1272 // object can be seen from the view cell => add to view cell pvs1273 for (int j = 0; j < (int)ray.bspIntersections.size(); ++ j)1274 {1275 BspLeaf *leaf = ray.bspIntersections[j].mLeaf;1276 1277 // if ray not in unbounded space1278 if (leaf->GetViewCell() != mVspBspTree->GetRootCell())1279 {1280 if (sObject)1281 {1282 contributingSamples +=1283 leaf->GetViewCell()->GetPvs().AddSample(sObject);1284 }1285 1286 if (tObject)1287 {1288 contributingSamples +=1289 leaf->GetViewCell()->GetPvs().AddSample(tObject);1290 }1291 }1292 }1293 }1294 1295 // rays passing through this viewcell1296 if (0)1297 for (int j = 1; j < ((int)ray.bspIntersections.size() - 1); ++ j)1298 {1299 BspLeaf *leaf = ray.bspIntersections[j].mLeaf;1300 1301 if (leaf->GetViewCell() != mVspBspTree->GetRootCell())1302 leaf->GetViewCell()->1303 AddPassingRay(ray, contributingSamples ? 1 : 0);1304 }1305 1306 return contributingSamples;1307 }1308 1194 1309 1195 int VspBspViewCellsManager::PostProcess(const ObjectContainer &objects, 1310 const RayContainer &rays)1196 const VssRayContainer &rays) 1311 1197 { 1312 1198 if (!ViewCellsConstructed()) … … 1356 1242 1357 1243 1244 // $$JB we do not have connectivity information from the ray in the moment 1245 // perhaps we could recast the rays or rember the cells traversed inside the 1246 // vssray (which would on other hand create some overhead) 1358 1247 //-- merge or subdivide view cells 1359 1248 int merged = 0; 1249 #if 0 1360 1250 1361 1251 RayContainer::const_iterator rit, rit_end = rays.end(); … … 1366 1256 for (int i = 0; i < limit; ++ i) 1367 1257 { 1368 1369 1370 1371 1372 1373 1374 1375 1258 VssRay *ray = rays[i]; 1259 1260 // traverse leaves stored in the rays and compare and merge consecutive 1261 // leaves (i.e., the neighbors in the tree) 1262 if (ray->bspIntersections.size() < 2) 1263 continue; 1264 1265 iit = ray->bspIntersections.begin(); 1376 1266 1377 1267 BspLeaf *previousLeaf = (*iit).mLeaf; … … 1392 1282 } 1393 1283 } 1394 1284 #endif 1395 1285 //-- stats and visualizations 1396 1286 cout << "finished" << endl; … … 1409 1299 1410 1300 void VspBspViewCellsManager::Visualize(const ObjectContainer &objects, 1411 const RayContainer &sampleRays)1301 const VssRayContainer &sampleRays) 1412 1302 { 1413 1303 if (!ViewCellsConstructed()) … … 1448 1338 1449 1339 void VspBspViewCellsManager::ExportSplits(const ObjectContainer &objects, 1450 const RayContainer &sampleRays)1340 const VssRayContainer &sampleRays) 1451 1341 { 1452 1342 Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); … … 1471 1361 if (0) 1472 1362 { 1473 1363 VssRayContainer outRays; 1474 1364 1475 1365 int raysSize = min((int)sampleRays.size(), mVisualizationSamples); … … 1478 1368 { 1479 1369 // only rays piercing geometry 1480 if (!sampleRays[i]->intersections.empty()) 1481 outRays.push_back(sampleRays[i]); 1370 outRays.push_back(sampleRays[i]); 1482 1371 } 1483 1372 1484 1373 // export rays 1485 exporter->ExportRays(outRays, 1000,RgbColor(1, 1, 0));1374 exporter->ExportRays(outRays, RgbColor(1, 1, 0)); 1486 1375 } 1487 1376 … … 1494 1383 1495 1384 void VspBspViewCellsManager::ExportBspPvs(const ObjectContainer &objects, 1496 const RayContainer &sampleRays)1385 const VssRayContainer &sampleRays) 1497 1386 { 1498 1387 const int leafOut = 10; … … 1514 1403 for (int i = 0; i < (int)vspBspLeaves.size(); ++ i) 1515 1404 { 1516 RayContainer vcRays; 1517 cout << "creating output for view cell " << i << " ... "; 1518 1405 VssRayContainer vcRays; 1406 cout << "creating output for view cell " << i << " ... "; 1407 1408 //$$JB 1409 #if 0 1519 1410 // check whether we can add the current ray to the output rays 1520 1411 for (int k = 0; k < raysOut; ++ k) 1521 1412 { 1522 1413 VssRay *ray = sampleRays[k]; 1523 1414 1524 1415 for (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) … … 1532 1423 } 1533 1424 } 1534 1425 #endif 1535 1426 1536 1427 Intersectable::NewMail(); … … 1570 1461 1571 1462 // export rays piercing this view cell 1572 exporter->ExportRays(vcRays, 1000,RgbColor(1, 0, 0));1463 exporter->ExportRays(vcRays, RgbColor(1, 0, 0)); 1573 1464 exporter->ExportRays(vspBspLeaves[i]->mVssRays, RgbColor(1, 1, 1)); 1574 1465 … … 1621 1512 { 1622 1513 cout << "creating output for view cell " << i << " ... "; 1623 RayContainer vcRays;1514 VssRayContainer vcRays; 1624 1515 Intersectable::NewMail(); 1625 1516 BspViewCell *vc = dynamic_cast<BspViewCell *>(viewCells[i]); 1626 1517 1627 1518 cout << "creating output for view cell " << i << " ... "; 1519 //$$ JB 1520 #if 0 1628 1521 // check whether we can add the current ray to the output rays 1629 1522 for (int k = 0; k < raysOut; ++ k) 1630 1523 { 1631 1524 Ray *ray = sampleRays[k]; 1632 1525 1633 1526 for (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) … … 1641 1534 } 1642 1535 } 1643 1536 #endif 1644 1537 //bspLeaves[j]->Mail(); 1645 1538 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); … … 1670 1563 1671 1564 // export rays piercing this view cell 1672 exporter->ExportRays(vcRays, 1000,RgbColor(0, 1, 0));1565 exporter->ExportRays(vcRays, RgbColor(0, 1, 0)); 1673 1566 1674 1567 m.mDiffuseColor = RgbColor(1, 0, 0); … … 1771 1664 } 1772 1665 1666 1667 int 1668 VspBspViewCellsManager::CastLineSegment(const Vector3 &origin, 1669 const Vector3 &termination, 1670 ViewCellContainer &viewcells 1671 ) 1672 { 1673 return mVspBspTree->CastLineSegment(origin, termination, viewcells); 1674 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
r463 r466 29 29 30 30 public: 31 32 33 34 31 32 /// view cell container types 33 enum {BSP, KD, VSP_KD, VSP_BSP}; 34 35 35 /** Constructor taking the maximal number of samples used for construction 36 36 */ … … 56 56 @param contributingSamples returns the number of contributingSamples 57 57 */ 58 void ComputeSampleContributions(const RayContainer &rays, 59 int &sampleContributions, 60 int &contributingSamples, 61 const bool castRays = true); 62 63 64 /** Computes sample contribution of a simgle ray to the view cells PVS. 65 @param ray finds intersections with view cells and holds the contribution 66 @param castRay true if ray should be cast to gain the information, false if ray 67 is already holding the information and need not be recast. 68 69 @returns number of sample contributions 70 */ 71 virtual int ComputeSampleContributions(Ray &ray, const bool castRay = true) = 0; 72 58 void ComputeSampleContributions(const VssRayContainer &rays 59 ); 60 61 62 /** Computes sample contribution of a simgle ray to the view cells PVS. 63 @param ray finds intersections with view cells and holds the contribution 64 @param castRay true if ray should be cast to gain the information, false if ray 65 is already holding the information and need not be recast. 66 67 @returns number of sample contributions 68 */ 69 virtual void ComputeSampleContributions(VssRay &ray 70 ); 71 73 72 /** Prints out statistics of the view cells. 74 73 */ … … 77 76 /** Post processes view cells givemŽa number of rays. 78 77 */ 79 80 constRayContainer &rays) = 0;78 virtual int PostProcess(const ObjectContainer &objects, 79 const VssRayContainer &rays) = 0; 81 80 82 81 /** Show visualization of the view cells. 83 82 */ 84 83 virtual void Visualize(const ObjectContainer &objects, 85 const RayContainer &sampleRays) = 0;84 const VssRayContainer &sampleRays) = 0; 86 85 87 86 /** type of the view cell container. … … 157 156 */ 158 157 virtual bool ViewCellsConstructed() const = 0; 159 158 159 /** cast line segment to get a list of unique viewcells which are intersected 160 by this line segment */ 161 162 virtual int CastLineSegment(const Vector3 &origin, 163 const Vector3 &termination, 164 ViewCellContainer &viewcells 165 ) = 0; 166 160 167 161 168 protected: … … 205 212 AxisAlignedBox3 *sceneBbox); 206 213 207 int ComputeSampleContributions(Ray &ray, const bool castRay = false);208 214 209 215 int PostProcess(const ObjectContainer &objects, 210 const RayContainer &rays);216 const VssRayContainer &rays); 211 217 212 218 void Visualize(const ObjectContainer &objects, 213 const RayContainer &sampleRays);219 const VssRayContainer &sampleRays); 214 220 215 221 int GetType() const; … … 222 228 223 229 ~BspViewCellsManager(); 230 231 int CastLineSegment(const Vector3 &origin, 232 const Vector3 &termination, 233 ViewCellContainer &viewcells 234 ); 235 224 236 protected: 225 237 … … 241 253 /** Exports visualization of the BSP splits. 242 254 */ 243 void ExportSplits(const ObjectContainer &objects, const RayContainer &sampleRays);255 void ExportSplits(const ObjectContainer &objects, const VssRayContainer &sampleRays); 244 256 245 257 /** Exports visualization of the BSP PVS. 246 258 */ 247 void ExportBspPvs(const ObjectContainer &objects, const RayContainer &sampleRays);259 void ExportBspPvs(const ObjectContainer &objects, const VssRayContainer &sampleRays); 248 260 249 261 }; … … 263 275 AxisAlignedBox3 *sceneBbox); 264 276 265 int CastRay(const Ray &ray); 277 int CastLineSegment(const Vector3 &origin, 278 const Vector3 &termination, 279 ViewCellContainer &viewcells 280 ) ; 266 281 267 282 int PostProcess(const ObjectContainer &objects, 268 const RayContainer &rays);283 const VssRayContainer &rays); 269 284 270 285 void Visualize(const ObjectContainer &objects, 271 const RayContainer &sampleRays);286 const VssRayContainer &sampleRays); 272 287 273 288 int GetType() const; … … 284 299 KdNode *GetNodeForPvs(KdLeaf *leaf); 285 300 286 int ComputeSampleContributions(Ray &ray, const bool castRay = true);287 301 288 302 /// the BSP tree. … … 310 324 AxisAlignedBox3 *sceneBbox); 311 325 312 int ComputeSampleContributions(Ray &ray, const bool castRay = true);313 326 314 327 int PostProcess(const ObjectContainer &objects, 315 const RayContainer &rays);328 const VssRayContainer &rays); 316 329 317 330 void Visualize(const ObjectContainer &objects, 318 const RayContainer &sampleRays);331 const VssRayContainer &sampleRays); 319 332 320 333 int GetType() const; … … 325 338 326 339 ViewCell *GenerateViewCell(Mesh *mesh) const; 340 341 342 int CastLineSegment(const Vector3 &origin, 343 const Vector3 &termination, 344 ViewCellContainer &viewcells 345 ) ; 327 346 328 347 protected: … … 350 369 AxisAlignedBox3 *sceneBbox); 351 370 352 int ComputeSampleContributions(Ray &ray, const bool castRay = false);353 371 354 372 int PostProcess(const ObjectContainer &objects, 355 const RayContainer &rays);373 const VssRayContainer &rays); 356 374 357 375 void Visualize(const ObjectContainer &objects, 358 const RayContainer &sampleRays);376 const VssRayContainer &sampleRays); 359 377 360 378 int GetType() const; … … 365 383 366 384 void PrintStatistics(ostream &s) const; 385 386 int CastLineSegment(const Vector3 &origin, 387 const Vector3 &termination, 388 ViewCellContainer &viewcells 389 ) ; 367 390 368 391 protected: … … 385 408 /** Exports visualization of the BSP splits. 386 409 */ 387 void ExportSplits(const ObjectContainer &objects, const RayContainer &sampleRays);410 void ExportSplits(const ObjectContainer &objects, const VssRayContainer &sampleRays); 388 411 389 412 /** Exports visualization of the BSP PVS. 390 413 */ 391 void ExportBspPvs(const ObjectContainer &objects, const RayContainer &sampleRays);414 void ExportBspPvs(const ObjectContainer &objects, const VssRayContainer &sampleRays); 392 415 393 416 }; -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r463 r466 1710 1710 return splits; 1711 1711 } 1712 1713 1714 int 1715 VspBspTree::CastLineSegment(const Vector3 &origin, 1716 const Vector3 &termination, 1717 vector<ViewCell *> &viewcells 1718 ) 1719 { 1720 int hits = 0; 1721 stack<BspRayTraversalData> tStack; 1722 1723 float mint = 0.0f, maxt = 1.0f; 1724 1725 Intersectable::NewMail(); 1726 1727 Vector3 entp = origin; 1728 Vector3 extp = termination; 1729 1730 BspNode *node = mRoot; 1731 BspNode *farChild = NULL; 1732 1733 while (1) { 1734 if (!node->IsLeaf()) { 1735 BspInterior *in = dynamic_cast<BspInterior *>(node); 1736 1737 Plane3 splitPlane = in->GetPlane(); 1738 const int entSide = splitPlane.Side(entp); 1739 const int extSide = splitPlane.Side(extp); 1740 1741 if (entSide < 0) { 1742 node = in->GetBack(); 1743 1744 if(extSide <= 0) // plane does not split ray => no far child 1745 continue; 1746 1747 farChild = in->GetFront(); // plane splits ray 1748 1749 } else 1750 if (entSide > 0) { 1751 node = in->GetFront(); 1752 1753 if (extSide >= 0) // plane does not split ray => no far child 1754 continue; 1755 1756 farChild = in->GetBack(); // plane splits ray 1757 } 1758 else // ray and plane are coincident 1759 { 1760 // WHAT TO DO IN THIS CASE ? 1761 //break; 1762 node = in->GetFront(); 1763 continue; 1764 } 1765 1766 // push data for far child 1767 tStack.push(BspRayTraversalData(farChild, extp, maxt)); 1768 1769 // find intersection of ray segment with plane 1770 float t; 1771 extp = splitPlane.FindIntersection(origin, extp, &t); 1772 maxt *= t; 1773 1774 } else { 1775 // reached leaf => intersection with view cell 1776 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 1777 1778 if (!leaf->GetViewCell()->Mailed()) { 1779 viewcells.push_back(leaf->GetViewCell()); 1780 leaf->GetViewCell()->Mail(); 1781 hits++; 1782 } 1783 1784 //-- fetch the next far child from the stack 1785 if (tStack.empty()) 1786 break; 1787 1788 entp = extp; 1789 mint = maxt; // NOTE: need this? 1790 1791 BspRayTraversalData &s = tStack.top(); 1792 1793 node = s.mNode; 1794 extp = s.mExitPoint; 1795 maxt = s.mMaxT; 1796 1797 tStack.pop(); 1798 } 1799 } 1800 return hits; 1801 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
r463 r466 208 208 float GetEpsilon() const; 209 209 210 211 int 212 CastLineSegment(const Vector3 &origin, 213 const Vector3 &termination, 214 ViewCellContainer &viewcells 215 ); 216 210 217 protected: 211 218 … … 427 434 int &contributingSamples); 428 435 436 437 438 429 439 /// Pointer to the root of the tree 430 440 BspNode *mRoot; -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
r465 r466 2035 2035 2036 2036 if (ray->mTerminationObject) 2037 2037 vc->GetPvs().AddSample(ray->mTerminationObject); 2038 2038 2039 2039 if (ray->mOriginObject) 2040 2040 vc->GetPvs().AddSample(ray->mOriginObject); 2041 2041 } 2042 2042 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
r465 r466 42 42 ) 43 43 { 44 ray. intersections.clear();44 ray.Clear(); 45 45 // do not store anything else then intersections at the ray 46 46 ray.Init(point, direction, Ray::LOCAL_RAY); … … 450 450 } 451 451 452 ObjectContainer objects; 453 mSceneGraph->CollectObjects(&objects); 452 mSceneGraph->CollectObjects(&mObjects); 454 453 455 454 // construct view cells 456 mViewCellsManager->Construct( objects, mVssRays, mViewSpaceBox);455 mViewCellsManager->Construct(mObjects, mVssRays, mViewSpaceBox); 457 456 458 457 vssTree = new VssTree; … … 509 508 num = GenerateImportanceRays(vssTree, num, rays); 510 509 } 511 510 512 511 for (int i=0; i < rays.size(); i++) 513 512 CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays); … … 534 533 535 534 //-- prepare traversal rays for view cell intersections 536 RayContainer passRays;537 538 VssRayContainer::const_iterator it, it_end = vssRays.end();539 540 for (it = vssRays.begin(); it != it_end; ++ it)541 passRays.push_back(new Ray(*(*it)));542 543 int sampleContributions = 0;544 int contributingSamples = 0;545 546 535 /// compute view cell contribution of rays 547 /* mViewCellsManager->ComputeSampleContributions(passRays, 548 sampleContributions, 549 contributingSamples); 550 551 //-- save rays for post processing 552 if (((int)storedRays.size() < mViewCellsManager->GetPostProcessSamples()) || 553 ((int)storedRays.size() < mViewCellsManager->GetVisualizationSamples())) 554 { 555 RayContainer::const_iterator it, it_end = passRays.end(); 556 557 for (it = passRays.begin(); it != it_end; ++ it) 558 storedRays.push_back(new Ray(*(*it))); 559 } 560 else 561 { 562 CLEAR_CONTAINER(passRays); 563 } 564 */ 536 mViewCellsManager->ComputeSampleContributions(vssRays); 537 565 538 samples+=num; 566 539 float pvs = vssTree->GetAvgPvsSize(); 567 540 cout<<"*****************************\n"; 568 541 cout<<samples<<" avgPVS ="<<pvs<<endl; 569 cout<<"sample contributions ="<<sampleContributions<<endl;570 cout<<"contributing sample ="<<contributingSamples<<endl;571 542 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 572 543 cout<<"*****************************\n"; … … 576 547 } 577 548 578 cout << "here" << endl; 579 //-- post process view cells 580 mViewCellsManager->PostProcess(objects, storedRays); 581 582 //-- several visualizations and statistics 583 mViewCellsManager->PrintStatistics(Debug); 549 { 550 VssRayContainer storedRays; 551 vssTree->CollectRays(storedRays, Max( 552 mViewCellsManager->GetPostProcessSamples(), 553 mViewCellsManager->GetVisualizationSamples())); 554 555 //-- post process view cells 556 mViewCellsManager->PostProcess(mObjects, storedRays); 557 558 //-- several visualizations and statistics 559 mViewCellsManager->PrintStatistics(Debug); 560 561 mViewCellsManager->Visualize(mObjects, storedRays); 562 563 CLEAR_CONTAINER(storedRays); 564 } 584 565 585 566 //-- render simulation after merge 586 567 cout << "\nevaluating bsp view cells render time after merge ... "; 587 568 588 569 const SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 589 570 590 571 cout << " finished" << endl; 591 572 cout << ss << endl; 592 573 Debug << ss << endl; 593 594 mViewCellsManager->Visualize(objects, storedRays); 595 596 CLEAR_CONTAINER(storedRays); 574 597 575 598 576 delete vssTree; 599 577 600 578 return true; 601 579 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.cpp
r463 r466 1954 1954 // cout<<"ei="<<mEntropyImportance<<" "; 1955 1955 } 1956 1957 1958 int 1959 VssTree::CollectRays(VssRayContainer &rays, 1960 const int number) 1961 { 1962 VssRayContainer allRays; 1963 CollectRays(allRays); 1964 1965 int desired = min(number, (int)allRays.size()); 1966 float prob = desired/(float)allRays.size(); 1967 while (rays.size() < desired) { 1968 VssRayContainer::const_iterator it = allRays.begin(); 1969 for (; it != allRays.end() && rays.size() < desired; it++) { 1970 if (Random(1.0f) < prob) 1971 rays.push_back(*it); 1972 } 1973 } 1974 return rays.size(); 1975 } 1976 1977 1978 int 1979 VssTree::CollectRays(VssRayContainer &rays 1980 ) 1981 { 1982 VssRay::NewMail(); 1983 1984 stack<VssTreeNode *> tstack; 1985 tstack.push(root); 1986 1987 while (!tstack.empty()) { 1988 VssTreeNode *node = tstack.top(); 1989 tstack.pop(); 1990 1991 if (node->IsLeaf()) { 1992 VssTreeLeaf *leaf = (VssTreeLeaf *)node; 1993 // update pvs size 1994 VssTreeNode::RayInfoContainer::const_iterator it = leaf->rays.begin(); 1995 for (;it != leaf->rays.end(); ++it) 1996 if (!(*it).mRay->Mailed()) { 1997 (*it).mRay->Mail(); 1998 rays.push_back((*it).mRay); 1999 } 2000 } else { 2001 VssTreeInterior *in = (VssTreeInterior *)node; 2002 // both nodes for directional splits 2003 tstack.push(in->front); 2004 tstack.push(in->back); 2005 } 2006 } 2007 2008 return rays.size(); 2009 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.h
r446 r466 918 918 SimpleRayContainer &rays); 919 919 920 920 int 921 CollectRays(VssRayContainer &rays, 922 const int number); 923 924 int 925 CollectRays(VssRayContainer &rays 926 ); 927 921 928 }; 922 929
Note: See TracChangeset
for help on using the changeset viewer.