- Timestamp:
- 01/25/06 01:44:46 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r573 r574 20 20 ViewCellsManager::ViewCellsManager(): 21 21 mRenderer(NULL), 22 mInitialSamples(0), 22 23 mConstructionSamples(0), 23 24 mPostProcessSamples(0), … … 35 36 36 37 37 ViewCellsManager::ViewCellsManager(int constructionSamples):38 mConstructionSamples(constructionSamples),39 mRenderer(NULL),40 mPostProcessSamples(0),41 mVisualizationSamples(0),42 mTotalAreaValid(false),43 mTotalArea(0.0f),44 mViewCellsFinished(false),45 mMaxPvsSize(9999999),46 mMinPvsSize(0), // one means only empty view cells are invalid47 mMaxPvsRatio(1.0)48 {49 mViewSpaceBox.Initialize();50 ParseEnvironment();51 }52 53 54 38 void ViewCellsManager::ParseEnvironment() 55 39 { … … 61 45 environment->GetBoolValue("ViewCells.pruneEmptyViewCells", emptyViewCells); 62 46 environment->GetBoolValue("ViewCells.processOnlyValidViewCells", mOnlyValidViewCells); 47 48 environment->GetIntValue("ViewCells.Construction.samples", mConstructionSamples); 49 environment->GetIntValue("ViewCells.PostProcess.samples", mPostProcessSamples); 50 environment->GetIntValue("ViewCells.Visualization.samples", mVisualizationSamples); 51 52 environment->GetIntValue("ViewCells.Construction.samplesPerPass", mSamplesPerPass); 63 53 64 54 mMinPvsSize = emptyViewCells ? 1 : 0; … … 88 78 89 79 90 int ViewCellsManager::CastPassSamples(int samplesPerPass, 91 int sampleType, 92 VssRayContainer *outRays) const 93 { 94 VssRayContainer passSamples; 80 int ViewCellsManager::CastPassSamples(const int samplesPerPass, 81 const int sampleType, 82 VssRayContainer &passSamples) const 83 { 95 84 SimpleRayContainer simpleRays; 96 85 … … 102 91 preprocessor->CastRays(simpleRays, passSamples); 103 92 104 const int numSamples = (int)passSamples.size(); 105 93 return (int)passSamples.size(); 94 } 95 96 97 /// helper function which destroys rays or copies them into the output ray container 98 inline void addOutRays(VssRayContainer &rays, VssRayContainer *outRays) 99 { 100 cout << "disposing samples ... "; 106 101 if (outRays) 107 102 { 108 while (!passSamples.empty()) 109 outRays->push_back(passSamples.back()); 103 VssRayContainer::const_iterator it, it_end = rays.end(); 104 105 for (it = rays.begin(); it != it_end; ++ it) 106 { 107 outRays->push_back(*it); 108 } 110 109 } 111 110 else 112 111 { 113 CLEAR_CONTAINER(passSamples); 114 } 115 116 return numSamples; 112 CLEAR_CONTAINER(rays); 113 } 114 cout << "finished" << endl; 117 115 } 118 116 … … 123 121 SimpleRayContainer simpleRays; 124 122 125 VssRayContainer constructionSamples; 126 123 VssRayContainer initialSamples; 124 125 cout << "view cell construction: casting " << mInitialSamples << " initial samples ... "; 127 126 //-- construction rays => we use uniform samples for this 128 CastPassSamples(mConstructionSamples, 129 Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION, 130 &constructionSamples); 127 CastPassSamples(mInitialSamples, 128 Preprocessor::DIRECTION_BASED_DISTRIBUTION, 129 //Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION, 130 initialSamples); 131 131 132 cout << "finished" << endl; 133 132 134 // construct view cells 133 const int initialSamples = Construct(preprocessor->mObjects, constructionSamples); 134 135 numSamples += initialSamples; 136 137 if (outRays) 138 { 139 while (!constructionSamples.empty()) 140 outRays->push_back(constructionSamples.back()); 141 } 142 else 143 { 144 CLEAR_CONTAINER(constructionSamples); 145 } 146 135 const int numInitialSamples = 136 ConstructSubdivision(preprocessor->mObjects, initialSamples); 137 138 numSamples += numInitialSamples; 139 140 // rays can be passed or deleted 141 addOutRays(initialSamples, outRays); 142 147 143 148 144 //-- guided rays are used for further sampling 149 const int desiredImportanceSamples = 5000000; 150 const int importanceRayPerPass = 1000000; 151 152 const int n = desiredImportanceSamples; //+initialSamples; 145 const int n = mConstructionSamples; //+initialSamples; 146 147 bool dirSamples = false; 153 148 154 149 while (numSamples < n) 155 150 { 156 numSamples += CastPassSamples(importanceRayPerPass, 157 Preprocessor::RSS_BASED_DISTRIBUTION, 158 //Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION, 159 outRays); 151 cout << "casting " << mSamplesPerPass << " samples ... "; 152 VssRayContainer constructionSamples; 153 154 const int samplingType = 155 dirSamples ? 156 Preprocessor::DIRECTION_BASED_DISTRIBUTION : 157 Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION; 158 159 dirSamples = !dirSamples; // toggle sampling 160 numSamples += CastPassSamples(mSamplesPerPass, 161 samplingType, 162 constructionSamples); 163 164 cout << "finished" << endl; 165 166 cout << "computing sample contribution for " << (int)constructionSamples.size() << " samples ... "; 167 168 // TODO: leak? 169 ComputeSampleContributions(constructionSamples, true, false); 170 cout << "finished" << endl; 171 172 173 addOutRays(constructionSamples, outRays); 174 175 cout << "total samples: " << numSamples << endl; 160 176 } 161 177 … … 165 181 166 182 //-- construction rays => we use uniform samples for this 167 CastPassSamples(m ax(mPostProcessSamples, mVisualizationSamples),168 Preprocessor:: SPATIAL_BOX_BASED_DISTRIBUTION,169 &postProcessSamples);183 CastPassSamples(mPostProcessSamples, 184 Preprocessor::DIRECTION_BASED_DISTRIBUTION, 185 postProcessSamples); 170 186 187 cout << "starting post processing and visualization" << endl; 188 189 // store viewCells for postprocessing 190 const bool storeViewCells = true; 191 ComputeSampleContributions(postProcessSamples, true, storeViewCells); 171 192 // merge the view cells 172 193 PostProcess(preprocessor->mObjects, postProcessSamples); 173 // several visualizations 174 Visualize(preprocessor->mObjects, postProcessSamples); 175 176 if (outRays) 177 { 178 while (!postProcessSamples.empty()) 179 outRays->push_back(postProcessSamples.back()); 180 } 181 else 182 { 183 CLEAR_CONTAINER(postProcessSamples); 184 } 194 195 196 //-- visualization 197 VssRayContainer visualizationSamples; 198 199 //-- construction rays => we use uniform samples for this 200 CastPassSamples(mVisualizationSamples, 201 Preprocessor::DIRECTION_BASED_DISTRIBUTION, 202 visualizationSamples); 203 204 ComputeSampleContributions(visualizationSamples, true, storeViewCells); 205 206 //Debug << "visualizationsamples: " << mVisualizationSamples << " " << visualizationSamples.size() << endl; 207 // different visualizations 208 Visualize(preprocessor->mObjects, visualizationSamples); 209 210 addOutRays(visualizationSamples, outRays); 185 211 186 212 return numSamples; … … 293 319 float 294 320 ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays, 295 const bool addRays 321 const bool addRays, 322 const bool storeViewCells 296 323 ) 297 324 { … … 304 331 float sum = 0.0f; 305 332 for (it = rays.begin(); it != it_end; ++ it) { 306 sum += ComputeSampleContributions(*(*it), addRays );333 sum += ComputeSampleContributions(*(*it), addRays, storeViewCells); 307 334 //ComputeSampleContributions(*(*it), addRays); 308 335 // sum += (*it)->mPvsContribution; … … 466 493 { 467 494 mConstructionSamples = constructionSamples; 495 } 496 497 498 void ViewCellsManager::SetInitialSamples(const int initialSamples) 499 { 500 mInitialSamples = initialSamples; 468 501 } 469 502 … … 554 587 { 555 588 mViewCells.clear(); 556 557 589 CollectViewCells(); 558 590 … … 610 642 } 611 643 644 612 645 float ViewCellsManager::ComputeSampleContributions(VssRay &ray, 613 const bool addRays) 646 const bool addRays, 647 const bool storeViewCells) 614 648 { 615 649 ViewCellContainer viewcells; … … 635 669 636 670 // copy viewcells memory efficiently 637 const bool storeViewcells = !addRays;638 639 if (storeView cells)671 //const bool storeViewcells = !addRays; 672 673 if (storeViewCells) 640 674 { 641 675 ray.mViewCells.reserve(viewcells.size()); … … 732 766 for (it = mViewCells.begin(); it != it_end; ++ it) 733 767 { 734 ExportColor(exporter, *it); 735 ExportVcGeometry(exporter, *it); 768 if (!mOnlyValidViewCells || (*it)->GetValid()) 769 { 770 ExportColor(exporter, *it); 771 ExportVcGeometry(exporter, *it); 772 } 736 773 } 737 774 } … … 778 815 779 816 780 BspViewCellsManager::BspViewCellsManager(BspTree *bspTree, 781 int constructionSamples): 782 ViewCellsManager(constructionSamples), 783 mBspTree(bspTree) 784 { 817 BspViewCellsManager::BspViewCellsManager(BspTree *bspTree): 818 ViewCellsManager(), mBspTree(bspTree) 819 { 820 environment->GetIntValue("BspTree.Construction.samples", mInitialSamples); 785 821 } 786 822 … … 798 834 799 835 800 int BspViewCellsManager::Construct (const ObjectContainer &objects,801 836 int BspViewCellsManager::ConstructSubdivision(const ObjectContainer &objects, 837 const VssRayContainer &rays) 802 838 { 803 839 // if view cells were already constructed … … 811 847 VssRayContainer savedRays; 812 848 813 const int limit = min(m ConstructionSamples, (int)rays.size());849 const int limit = min(mInitialSamples, (int)rays.size()); 814 850 815 851 VssRayContainer::const_iterator it, it_end = rays.end(); … … 846 882 847 883 // recast rest of the rays 848 ComputeSampleContributions(savedRays );884 ComputeSampleContributions(savedRays, true, false); 849 885 850 886 … … 937 973 938 974 939 // $$JB we do not have connectivity information from the ray in the moment940 // perhaps we could recast the rays or remember the cells traversed inside the941 // vssray (which would on other hand create some overhead)942 975 //-- merge or subdivide view cells 943 976 int merged = 0; 944 977 945 vector<BspIntersection>::const_iterator iit; 946 CLEAR_CONTAINER(mBspRays); 947 ConstructBspRays(rays, mPostProcessSamples); 948 949 for (int i = 0; i < (int)mBspRays.size(); ++ i) 950 { 951 BspRay *ray = mBspRays[i]; 952 953 // traverse leaves stored in the rays and compare and merge consecutive 954 // leaves (i.e., the neighbors in the tree) 955 if (ray->intersections.size() < 2) 956 continue; 957 #if 0 958 iit = ray->intersections.begin(); 959 960 BspLeaf *previousLeaf = (*iit).mLeaf; 961 ++ iit; 962 963 for (; iit != ray->intersections.end(); ++ iit) 964 { 965 BspLeaf *leaf = (*iit).mLeaf; 966 967 if (ShouldMerge(leaf, previousLeaf)) 968 { 969 MergeBspLeafViewCells(leaf, previousLeaf); 970 971 ++ merged; 972 } 973 974 previousLeaf = leaf; 975 } 976 #endif 977 } 978 978 // TODO 979 979 980 //-- stats and visualizations 980 981 cout << "finished" << endl; … … 984 985 Debug << "Postprocessing: Merged " << merged << " view cells in " 985 986 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" 986 << "using " << (int)mBspRays.size() << " samples" << endl << endl; 987 988 CLEAR_CONTAINER(mBspRays); 987 << "using " << (int)rays.size() << " samples" << endl << endl; 989 988 990 989 // reset view cells and stats … … 997 996 BspViewCellsManager::~BspViewCellsManager() 998 997 { 999 CLEAR_CONTAINER(mBspRays);1000 998 } 1001 999 … … 1012 1010 if (!ViewCellsConstructed()) 1013 1011 return; 1014 CLEAR_CONTAINER(mBspRays); 1015 ConstructBspRays(sampleRays, mVisualizationSamples); 1016 1012 1017 1013 if (1) // export view cells 1018 1014 { … … 1070 1066 1071 1067 exporter->SetFilled(); 1072 1073 // export rays1074 if (0)1075 {1076 VssRayContainer outRays;1077 1078 int raysSize = min((int)mBspRays.size(), mVisualizationSamples);1079 1080 for (int i = 0; i < raysSize; ++ i)1081 // only rays piercing geometry1082 outRays.push_back(mBspRays[i]->vssRay);1083 1084 // export rays1085 exporter->ExportRays(outRays, RgbColor(1, 1, 0));1086 }1087 1068 1088 1069 if (mExportGeometry) … … 1345 1326 1346 1327 1347 int KdViewCellsManager::Construct (const ObjectContainer &objects,1328 int KdViewCellsManager::ConstructSubdivision(const ObjectContainer &objects, 1348 1329 const VssRayContainer &rays) 1349 1330 { … … 1359 1340 1360 1341 // cast rays 1361 ComputeSampleContributions(rays );1342 ComputeSampleContributions(rays, true, false); 1362 1343 1363 1344 EvaluateViewCellsStats(); … … 1605 1586 1606 1587 1607 VspKdViewCellsManager::VspKdViewCellsManager(VspKdTree *vspKdTree, 1608 int constructionSamples): 1609 ViewCellsManager(constructionSamples), 1610 mVspKdTree(vspKdTree) 1611 { 1588 VspKdViewCellsManager::VspKdViewCellsManager(VspKdTree *vspKdTree): 1589 ViewCellsManager(), mVspKdTree(vspKdTree) 1590 { 1591 environment->GetIntValue("VspKdTree.Construction.samples", mInitialSamples); 1612 1592 mVspKdTree->SetViewCellsManager(this); 1613 1593 } … … 1636 1616 1637 1617 1638 int VspKdViewCellsManager::Construct (const ObjectContainer &objects,1639 1618 int VspKdViewCellsManager::ConstructSubdivision(const ObjectContainer &objects, 1619 const VssRayContainer &rays) 1640 1620 { 1641 1621 // if view cells already constructed … … 1647 1627 1648 1628 GetRaySets(rays, 1649 m ConstructionSamples,1629 mInitialSamples, 1650 1630 constructionRays, 1651 1631 &savedRays); … … 1676 1656 long startTime = GetTime(); 1677 1657 // recast rest of rays 1678 ComputeSampleContributions(savedRays );1658 ComputeSampleContributions(savedRays, true, false); 1679 1659 1680 1660 Debug << "Computed remaining ray contribution in " << TimeDiff(startTime, GetTime()) * 1e-3 … … 1950 1930 } 1951 1931 1932 1933 1952 1934 /**************************************************************************/ 1953 1935 /* VspBspViewCellsManager implementation */ … … 1955 1937 1956 1938 1957 VspBspViewCellsManager::VspBspViewCellsManager(VspBspTree *vspBspTree, 1958 int constructionSamples): 1959 ViewCellsManager(constructionSamples), 1960 mVspBspTree(vspBspTree) 1961 { 1939 VspBspViewCellsManager::VspBspViewCellsManager(VspBspTree *vspBspTree): 1940 ViewCellsManager(), mVspBspTree(vspBspTree) 1941 { 1942 environment->GetIntValue("VspBspTree.Construction.samples", mInitialSamples); 1962 1943 mVspBspTree->SetViewCellsManager(this); 1963 1944 } … … 1980 1961 void VspBspViewCellsManager::CollectViewCells() 1981 1962 { 1982 mVspBspTree->CollectViewCells(mViewCells, mOnlyValidViewCells);1963 mVspBspTree->CollectViewCells(mViewCells, true); 1983 1964 } 1984 1965 … … 2003 1984 2004 1985 2005 int VspBspViewCellsManager::Construct (const ObjectContainer &objects,1986 int VspBspViewCellsManager::ConstructSubdivision(const ObjectContainer &objects, 2006 1987 const VssRayContainer &rays) 2007 1988 { … … 2016 1997 VssRayContainer sampleRays; 2017 1998 2018 int limit = min (m ConstructionSamples, (int)rays.size());1999 int limit = min (mInitialSamples, (int)rays.size()); 2019 2000 2020 2001 VssRayContainer constructionRays; 2021 2002 VssRayContainer savedRays; 2022 2003 2023 Debug << " construction samples: " << mConstructionSamples << " rays: " << (int)rays.size() << endl;2024 GetRaySets(rays, m ConstructionSamples, constructionRays, &savedRays);2025 2026 Debug << " constructionrays: " << (int)constructionRays.size() << endl;2004 Debug << "samples used for subdivision: " << mInitialSamples << " rays: " << (int)rays.size() << endl; 2005 GetRaySets(rays, mInitialSamples, constructionRays, &savedRays); 2006 2007 Debug << "initial rays: " << (int)constructionRays.size() << endl; 2027 2008 Debug << "saved rays: " << (int)savedRays.size() << endl; 2028 2009 … … 2075 2056 cout << "Computing remaining ray contributions ... "; 2076 2057 // recast rest of rays 2077 ComputeSampleContributions(savedRays );2058 ComputeSampleContributions(savedRays, true, false); 2078 2059 cout << "finished" << endl; 2079 2060 … … 2116 2097 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl << endl; 2117 2098 2118 cout << "reseting view cell stats ... ";2119 ResetViewCells();2120 cout << "finished" << endl;2121 2099 2122 2100 //BspLeaf::NewMail(); 2123 2101 if (1) // export merged view cells 2124 2102 { 2103 2104 cout << "reseting view cells ... "; 2105 ResetViewCells(); 2106 cout << "finished" << endl; 2107 2125 2108 Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 2126 2109 Debug << "\nView cells after merge:\n" << mViewCellsStats << endl; … … 2198 2181 2199 2182 // check if new view cells turned invalid 2183 SetValidity(mMinPvsSize, mMaxPvsSize); 2184 // update valid view space according to valid view cells 2200 2185 mVspBspTree->ValidateTree(); 2201 ResetViewCells(); 2186 2187 // recompute view cell statistics 2188 mViewCellsStats.Reset(); 2189 EvaluateViewCellsStats(); 2190 // has to be recomputed 2191 mTotalAreaValid = false; 2202 2192 2203 2193 … … 2283 2273 // collapse sibling leaves that share the same view cell 2284 2274 mVspBspTree->CollapseTree(); 2285 2275 // recompute view cell list and statistics 2286 2276 ResetViewCells(); 2287 2277 … … 2447 2437 #if 1 2448 2438 //-- some rays for output 2449 vector<BspRay *> bspRays; 2450 mVspBspTree->ConstructBspRays(bspRays, rays); 2451 2452 const int raysOut = min((int)bspRays.size(), mVisualizationSamples); 2439 const int raysOut = min((int)rays.size(), mVisualizationSamples); 2440 2453 2441 #endif 2454 2442 … … 2459 2447 VssRayContainer vcRays; 2460 2448 Intersectable::NewMail(); 2461 #if 0 // largest view cell pvs first 2462 BspViewCell *vc = dynamic_cast<BspViewCell *>(mViewCells[i]); 2463 #else 2464 BspViewCell *vc = dynamic_cast<BspViewCell *> 2465 (mViewCells[Random((int)mViewCells.size())]); 2466 #endif 2467 2468 #if 1 2469 // check whether we can add the current ray to the output rays 2470 for (int k = 0; k < raysOut; ++ k) 2471 { 2472 BspRay *ray = bspRays[k]; 2473 for (int j = 0; j < (int)ray->intersections.size(); ++ j) 2449 BspViewCell *vc; 2450 2451 if (0) // largest view cell pvs first 2452 { 2453 vc = dynamic_cast<BspViewCell *>(mViewCells[i]); 2454 } 2455 else 2456 { 2457 vc = dynamic_cast<BspViewCell *> 2458 (mViewCells[Random((int)mViewCells.size())]); 2459 } 2460 2461 if (1) 2462 { 2463 // check whether we can add the current ray to the output rays 2464 for (int k = 0; k < raysOut; ++ k) 2474 2465 { 2475 BspLeaf *leaf = ray->intersections[j].mLeaf; 2476 if (vc == leaf->GetViewCell()) 2477 vcRays.push_back(ray->vssRay); 2466 VssRay *ray = rays[k]; 2467 for (int j = 0; j < (int)ray->mViewCells.size(); ++ j) 2468 { 2469 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(ray->mViewCells[j]); 2470 BspLeaf *leaf = bspVc->mLeaves[0]; 2471 if (vc == bspVc) 2472 vcRays.push_back(ray); 2473 } 2478 2474 } 2479 2475 } 2480 #endif 2476 2481 2477 //bspLeaves[j]->Mail(); 2482 2478 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); … … 2495 2491 << ", leaves=" << (int)vc->mLeaves.size() << endl; 2496 2492 2493 2497 2494 //-- export rays piercing this view cell 2498 #if 1 2499 exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 2500 #endif 2501 #if 0 2502 vector<BspLeaf *>::const_iterator lit, lit_end = vc->mLeaves.end(); 2503 2504 for (lit = vc->mLeaves.begin(); lit != lit_end; ++ lit) 2505 exporter->ExportRays((*lit)->mVssRays); 2506 #endif 2495 if (1) 2496 { 2497 exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 2498 } 2499 else 2500 { 2501 vector<BspLeaf *>::const_iterator lit, lit_end = vc->mLeaves.end(); 2502 2503 for (lit = vc->mLeaves.begin(); lit != lit_end; ++ lit) 2504 exporter->ExportRays((*lit)->mVssRays); 2505 } 2506 2507 2507 2508 m.mDiffuseColor = RgbColor(1, 0, 0); 2508 2509 exporter->SetForcedMaterial(m); … … 2513 2514 exporter->SetFilled(); 2514 2515 2516 2515 2517 // output PVS of view cell 2516 2518 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 2517 2519 { 2520 2518 2521 Intersectable *intersect = (*it).first; 2519 2522 … … 2528 2531 } 2529 2532 2533 2530 2534 DEL_PTR(exporter); 2531 2535 cout << "finished" << endl; 2532 2536 } 2533 2537 2534 #if 12535 CLEAR_CONTAINER(bspRays);2536 #endif2537 2538 Debug << endl; 2538 2539 }
Note: See TracChangeset
for help on using the changeset viewer.