Changeset 574 for trunk/VUT/GtpVisibilityPreprocessor
- Timestamp:
- 01/25/06 01:44:46 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r573 r574 30 30 VssPreprocessor { 31 31 samplesPerPass 100000 32 initialSamples 600000032 initialSamples 0 33 33 vssSamples 0 34 34 vssSamplesPerPass 500000 … … 78 78 RssPreprocessor { 79 79 samplesPerPass 100000 80 initialSamples 500000 81 vssSamples 10000000 80 #initialSamples 500000 81 #vssSamples 10000000 82 #for view cell construction 83 initialSamples 0 84 vssSamples 0 82 85 vssSamplesPerPass 500000 83 86 useImportanceSampling true … … 171 174 172 175 ViewCells { 176 # samples used for view cell construction 177 Construction { 178 samples 5000000 179 samplesPerPass 500000 180 } 181 173 182 loadFromFile false 174 183 exportToFile false … … 196 205 Visualization { 197 206 # how much samples we use for visualization 198 samples 5000207 samples 100000 199 208 #colorCode PVS 200 209 #colorCode MergedLeaves -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r564 r574 1206 1206 "bspTree"); 1207 1207 1208 RegisterOption("ViewCells.Construction.samples", 1209 optInt, 1210 "view_cells_construction_samples=", 1211 "5000000"); 1212 1213 RegisterOption("ViewCells.Construction.samplesPerPass", 1214 optInt, 1215 "view_cells_construction_samples_per_pass=", 1216 "500000"); 1217 1208 1218 RegisterOption("ViewCells.PostProcess.samples", 1209 1219 optInt, -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r544 r574 7 7 Polygon3::Polygon3(): 8 8 mMaterial(NULL), mParent(NULL), mPiercingRays(0) 9 {} 9 { 10 // mostly there will be triangles 11 //mVertices.reserve(3); 12 } 10 13 11 14 Polygon3::Polygon3(const VertexContainer &vertices): 12 mVertices(vertices), mMaterial(NULL), mParent(NULL), mPiercingRays(0) 13 {} 15 mMaterial(NULL), mParent(NULL), mPiercingRays(0) 16 { 17 mVertices.reserve(vertices.size()); 18 mVertices = vertices; 19 } 20 14 21 15 22 Polygon3::Polygon3(MeshInstance *parent): … … 17 24 {} 18 25 26 19 27 Polygon3::Polygon3(Face *face, Mesh *parentMesh): 20 28 mMaterial(NULL), mParent(NULL), mPiercingRays(0) 21 29 { 30 mVertices.reserve(face->mVertexIndices.size()); 31 22 32 VertexIndexContainer::iterator it = face->mVertexIndices.begin(); 23 33 for (; it != face->mVertexIndices.end(); ++it) 24 34 { 25 35 mVertices.push_back(parentMesh->mVertices[*it]); 26 mMaterial = parentMesh->mMaterial; 27 } 28 } 36 } 37 38 mMaterial = parentMesh->mMaterial; 39 } 40 29 41 30 42 Plane3 Polygon3::GetSupportingPlane() const … … 32 44 return Plane3(mVertices[0], mVertices[1], mVertices[2]); 33 45 } 46 34 47 35 48 Vector3 Polygon3::GetNormal() const … … 113 126 } 114 127 128 115 129 float Polygon3::GetArea() const 116 130 { … … 123 137 } 124 138 139 125 140 int Polygon3::Side(const Plane3 &plane, 126 141 const float epsilon) const … … 136 151 } 137 152 153 138 154 int Polygon3::ClassifyPlane(const Plane3 &plane, 139 155 const float epsilon) const 140 156 { 141 VertexContainer::const_iterator it ;157 VertexContainer::const_iterator it, it_end = mVertices.end(); 142 158 143 159 bool onFrontSide = false; … … 146 162 int count = 0; 147 163 // find possible line-plane intersections 148 for (it = mVertices.begin(); it != mVertices.end(); ++ it)164 for (it = mVertices.begin(); it != it_end; ++ it) 149 165 { 150 166 const int side = plane.Side(*it, epsilon); … … 179 195 } 180 196 181 /*int Polygon3::ClassifyPlane(const Plane3 &plane) const182 {183 return ClassifyPlane(plane, Limits::Small);184 }*/185 186 197 187 198 Vector3 … … 212 223 return false; 213 224 214 #if 1 215 // check if area exceeds certain size 216 if (AREA_LIMIT > GetArea()) 217 { 218 //Debug << "area too small: " << GetArea() << endl; 219 return false; 220 } 221 #else 222 Vector3 vtx = mVertices.back(); 223 VertexContainer::const_iterator it, it_end = mVertices.end(); 224 225 for (it = mVertices.begin(); it != it_end; ++it) 226 { 227 if (!(EpsilonEqual(vtx, *it))) 228 { 229 //Debug << "Malformed vertices:\n" << *this << endl; 225 //TODO: remove for performance 226 #if 0 227 if (1) 228 { 229 // check if area exceeds certain size 230 if (GetArea() < AREA_LIMIT) 231 { 232 Debug << "area too small: " << GetArea() << endl; 230 233 return false; 231 234 } 232 vtx = *it; 233 } 234 #endif 235 } 236 else 237 { 238 Vector3 vtx = mVertices.back(); 239 VertexContainer::const_iterator it, it_end = mVertices.end(); 240 241 for (it = mVertices.begin(); it != it_end; ++it) 242 { 243 if (!(EpsilonEqualV3(vtx, *it))) 244 { 245 //Debug << "Malformed vertices:\n" << *this << endl; 246 return false; 247 } 248 vtx = *it; 249 } 250 } 251 #endif 252 235 253 return true; 236 254 } 255 237 256 238 257 void Polygon3::IncludeInBox(const PolygonContainer &polys, AxisAlignedBox3 &box) … … 243 262 box.Include(*(*it)); 244 263 } 264 245 265 246 266 // int_lineseg returns 1 if the given line segment intersects a 2D … … 283 303 } 284 304 305 285 306 int Polygon3::CastRay(const Ray &ray, float &t, const float nearestT) 286 307 { … … 353 374 return (count & 1) ? Ray::INTERSECTION : Ray::NO_INTERSECTION; 354 375 } 376 355 377 356 378 void Polygon3::InheritRays(Polygon3 &front_piece, … … 385 407 } 386 408 409 387 410 int Polygon3::ClassifyPlane(const PolygonContainer &polys, 388 411 const Plane3 &plane, … … 422 445 } 423 446 447 424 448 int Polygon3::ParentObjectsSize(const PolygonContainer &polys) 425 449 { … … 441 465 } 442 466 467 443 468 float Polygon3::GetArea(const PolygonContainer &cell) 444 469 { … … 448 473 for (pit = cell.begin(); pit != cell.end(); ++ pit) 449 474 { 450 if ((*pit)->mVertices.size() < 3)451 Debug << "ERROR" << endl;452 453 475 area += (*pit)->GetArea(); 454 476 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
r508 r574 150 150 static int ParentObjectsSize(const PolygonContainer &polys); 151 151 152 /** Area of the accumulated polygons. 153 */ 152 154 static float GetArea(const PolygonContainer &cell); 153 155 }; -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r567 r574 194 194 environment->GetStringValue("ViewCells.type", viewCellsStr); 195 195 196 int constructionSamples = 0;196 int initialSamples = 0; 197 197 198 198 if (strcmp(viewCellsStr, "kdTree") == 0) … … 206 206 Debug << "view cell type: Bsp" << endl; 207 207 208 environment->GetIntValue("BspTree.Construction.samples", constructionSamples); 209 mViewCellsManager = new BspViewCellsManager(mBspTree, constructionSamples); 208 mViewCellsManager = new BspViewCellsManager(mBspTree); 210 209 } 211 210 else if (strcmp(viewCellsStr, "vspBspTree") == 0) … … 215 214 Debug << "view cell type: VspBsp" << endl; 216 215 217 environment->GetIntValue("VspBspTree.Construction.samples", constructionSamples); 218 mViewCellsManager = new VspBspViewCellsManager(mVspBspTree, constructionSamples); 216 mViewCellsManager = new VspBspViewCellsManager(mVspBspTree); 219 217 } 220 218 else if (strcmp(viewCellsStr, "vspKdTree") == 0) … … 222 220 mVspKdTree = new VspKdTree(); 223 221 224 environment->GetIntValue("VspKdTree.Construction.samples", constructionSamples); 225 mViewCellsManager = new VspKdViewCellsManager(mVspKdTree, constructionSamples); 222 mViewCellsManager = new VspKdViewCellsManager(mVspKdTree); 226 223 } 227 224 else if (strcmp(viewCellsStr, "sceneDependent") == 0) … … 231 228 232 229 Debug << "view cell type: Bsp" << endl; 233 environment->GetIntValue("BspTree.Construction.samples", constructionSamples);234 mViewCellsManager = new BspViewCellsManager(mBspTree , constructionSamples);230 231 mViewCellsManager = new BspViewCellsManager(mBspTree); 235 232 } 236 233 else … … 248 245 mRenderSimulator = 249 246 new RenderSimulator(mViewCellsManager, objRenderCost, vcOverhead, moveSpeed); 250 251 int postProcessSamples = 0; 252 int visSamples = 0; 253 254 environment->GetIntValue("ViewCells.PostProcess.samples", postProcessSamples); 255 environment->GetIntValue("ViewCells.Visualization.samples", visSamples); 256 257 mViewCellsManager->SetPostProcessSamples(postProcessSamples); 258 mViewCellsManager->SetVisualizationSamples(visSamples); 247 259 248 mViewCellsManager->SetRenderer(mRenderSimulator); 260 249 261 262 250 //-- parse view cells construction method 263 251 environment->GetBoolValue("ViewCells.loadFromFile", mLoadViewCells); 264 252 char buf[100]; 253 265 254 if (mLoadViewCells) 266 255 { -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp
r564 r574 24 24 << avgRtWithoutOverhead << "\n"; 25 25 26 app << "#VALID_MAX_COST ( maximal cost of a valid view cell )\n" << validMaxCost << "\n"; 27 28 app << "#VALID_MIN_COST ( minimal cost of a valid view cell )\n" << validMinCost << "\n"; 29 30 app << "#VALID_AVG_RENDER_TIME ( average render time )\n" << validAvgRenderTime << "\n"; 31 32 app << "#VALID_AVG_RENDER_TIME_NO_OVERHEAD ( valid average render time without overhead )\n" 33 << validAvgRtWithoutOverhead << "\n"; 34 26 35 app << "===== END OF Render Simulation statistics ==========\n"; 27 36 } … … 31 40 mObjRenderCost(0.0f), 32 41 mVcOverhead(0.0f), 33 mMoveSpeed(0.0f), 34 mOnlyValid(false) 42 mMoveSpeed(0.0f) 35 43 {} 36 44 … … 43 51 mObjRenderCost(objRenderCost), 44 52 mVcOverhead(vcOverhead), 45 mMoveSpeed(moveSpeed), 46 mOnlyValid(false) 53 mMoveSpeed(moveSpeed) 47 54 { 48 55 } … … 55 62 56 63 57 void RenderSimulator::SetRenderOnlyValid(const bool renderOnlyValid)58 {59 mOnlyValid = renderOnlyValid;60 }61 62 63 64 void RenderSimulator::SetVcOverhead(const float vcOverhead) 64 65 { … … 66 67 } 67 68 69 68 70 void RenderSimulator::SetMoveSpeed(const float moveSpeed) 69 71 { 70 72 mMoveSpeed = moveSpeed; 71 73 } 74 72 75 73 76 bool RenderSimulator::RenderScene() … … 77 80 78 81 Real renderTime = 0; 79 82 Real validRenderTime = 0; 83 80 84 // overhead for loading the PVS of the view cells 81 85 float loadPvsOverhead = 0; 82 86 float validLoadPvsOverhead = 0; 87 83 88 ViewCellContainer::const_iterator it, 84 89 it_end = mViewCellsManager->GetViewCells().end(); … … 89 94 ViewCell *vc = *it; 90 95 91 if (mOnlyValid && !vc->GetValid())92 continue;96 const bool valid = !vc->GetValid(); 97 93 98 94 99 // probability of view cell … … 103 108 // speed and the probability that a view cell border is crossed 104 109 loadPvsOverhead += GetCrossVcProbability() * mVcOverhead; 105 106 //Debug << "vccost: " << vcCost << " p in vc " << pInVc 107 //<< " cross vc " << GetCrossVcProbability() << endl; 110 renderTime += vcCost; 108 111 109 112 //-- update statistics 110 renderTime += vcCost; 111 113 112 114 if (vcCost > mSimulationStatistics.maxCost) 113 115 mSimulationStatistics.maxCost = vcCost; 114 116 else if (vcCost < mSimulationStatistics.minCost) 115 117 mSimulationStatistics.minCost = vcCost; 118 119 //-- different statistics for only valid view cells 120 if (valid) 121 { 122 validLoadPvsOverhead += GetCrossVcProbability() * mVcOverhead; 123 validRenderTime += vcCost; 124 125 if (vcCost > mSimulationStatistics.validMaxCost) 126 mSimulationStatistics.validMaxCost = vcCost; 127 else if (vcCost < mSimulationStatistics.validMinCost) 128 mSimulationStatistics.validMinCost = vcCost; 129 } 116 130 } 117 131 118 132 mSimulationStatistics.avgRtWithoutOverhead = renderTime; 119 133 mSimulationStatistics.avgRenderTime = renderTime + loadPvsOverhead; 134 135 mSimulationStatistics.validAvgRtWithoutOverhead = renderTime; 136 mSimulationStatistics.validAvgRenderTime = renderTime + loadPvsOverhead; 120 137 121 138 mSimulationStatistics.Stop(); -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.h
r564 r574 19 19 float avgRtWithoutOverhead; 20 20 21 //-- options counting only valid view cells 22 23 /// view cell with the biggest "cost" 24 float validMaxCost; 25 /// view cell with the minimal "cost" 26 float validMinCost; 27 /// average render time 28 float validAvgRenderTime; 29 /// average render time with the overhead when crossing view cells 30 float validAvgRtWithoutOverhead; 31 21 32 void Reset() 22 33 { … … 25 36 avgRenderTime = 0; 26 37 avgRtWithoutOverhead = 0; 38 39 validMaxCost = 0; 40 validMinCost = 999999; 41 validAvgRenderTime = 0; 42 validAvgRtWithoutOverhead = 0; 27 43 } 28 44 … … 99 115 /// Simulation statistics 100 116 SimulationStatistics mSimulationStatistics; 101 102 /// if only valid view space should be rendered103 bool mOnlyValid;104 117 }; 105 118 -
trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp
r572 r574 441 441 442 442 } 443 else 444 { 445 // construct view cells using it's own set of samples 446 mViewCellsManager->Construct(this); 447 448 //-- several visualizations and statistics 449 Debug << "view cells after construction: " << endl; 450 mViewCellsManager->PrintStatistics(Debug); 451 } 443 452 444 453 int rssPass = 0; … … 476 485 477 486 if (mUseViewcells) { 478 // construct view cells479 if (!mLoadViewCells)480 mViewCellsManager->Construct(mObjects, mVssRays);481 482 483 487 484 488 // evaluate contributions of the intitial rays 485 mViewCellsManager->ComputeSampleContributions(mVssRays );489 mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 486 490 487 491 … … 502 506 mViewCellsManager->PrintPvsStatistics(mStats); 503 507 504 VssRayContainer selectedRays;505 int desired = Max(506 mViewCellsManager->GetPostProcessSamples(),507 mViewCellsManager->GetVisualizationSamples());508 509 mVssRays.SelectRays(desired, selectedRays);510 511 //-- post process view cells512 mViewCellsManager->PostProcess(mObjects, selectedRays);513 514 //-- several visualizations and statistics515 Debug << "view cells after post processing: " << endl;516 mViewCellsManager->PrintStatistics(Debug);517 518 if (1)519 mViewCellsManager->Visualize(mObjects, selectedRays);520 521 508 // viewcells->UpdatePVS(newVssRays); 522 509 Debug<<"Valid viewcells before set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; … … 534 521 535 522 /// compute view cell contribution of rays if view cells manager already constructed 536 mViewCellsManager->ComputeSampleContributions(mVssRays );523 mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 537 524 538 525 if (mUseImportanceSampling) { … … 571 558 CastRays(rays, tmpVssRays); 572 559 castRays += rays.size(); 573 float c1 = mViewCellsManager->ComputeSampleContributions(tmpVssRays, false );560 float c1 = mViewCellsManager->ComputeSampleContributions(tmpVssRays, false, true); 574 561 mStats<<"#RssRelContrib"<<endl<<c1/rays.size()<<endl; 575 562 … … 582 569 CastRays(rays, tmpVssRays); 583 570 castRays += rays.size(); 584 float c2 = mViewCellsManager->ComputeSampleContributions(tmpVssRays, false );571 float c2 = mViewCellsManager->ComputeSampleContributions(tmpVssRays, false, true); 585 572 mStats<<"#SpatialRelContrib"<<endl<<c2/rays.size()<<endl; 586 573 … … 596 583 CastRays(rays, tmpVssRays); 597 584 castRays += rays.size(); 598 float c3 = mViewCellsManager->ComputeSampleContributions(tmpVssRays, false );585 float c3 = mViewCellsManager->ComputeSampleContributions(tmpVssRays, false, true); 599 586 mStats<<"#DirectionalRelContrib"<<endl<<c3/rays.size()<<endl; 600 587 … … 622 609 if (mUseViewcells) { 623 610 /// compute view cell contribution of rays 624 mViewCellsManager->ComputeSampleContributions(vssRays );611 mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 625 612 } 626 613 … … 646 633 mViewCellsManager->PrintPvsStatistics(mStats); 647 634 } 648 649 635 650 636 ComputeRenderError(); 651 637 … … 709 695 if (mUseViewcells) { 710 696 711 712 //-- render simulation after merge 713 cout << "\nevaluating bsp view cells render time after merge ... "; 714 715 mRenderSimulator->RenderScene(); 716 SimulationStatistics ss; 717 mRenderSimulator->GetStatistics(ss); 718 719 cout << " finished" << endl; 720 cout << ss << endl; 721 Debug << ss << endl; 697 if(0) 698 { 699 VssRayContainer selectedRays; 700 int desired = mViewCellsManager->GetVisualizationSamples(); 701 702 mVssRays.SelectRays(desired, selectedRays); 703 704 mViewCellsManager->Visualize(mObjects, selectedRays); 705 } 706 707 // view cells after sampling 708 mViewCellsManager->PrintStatistics(Debug); 709 710 //-- render simulation after merge 711 cout << "\nevaluating bsp view cells render time after sampling ... "; 712 713 mRenderSimulator->RenderScene(); 714 SimulationStatistics ss; 715 mRenderSimulator->GetStatistics(ss); 716 717 cout << " finished" << endl; 718 cout << ss << endl; 719 Debug << ss << endl; 722 720 723 721 } -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r563 r574 67 67 } 68 68 69 mViewCellsManager->ComputeSampleContributions(vssRays, true );69 mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 70 70 CLEAR_CONTAINER(vssRays); 71 71 } … … 78 78 VssRay vssRay(ray); 79 79 80 mViewCellsManager->ComputeSampleContributions(vssRay );80 mViewCellsManager->ComputeSampleContributions(vssRay, true, false); 81 81 82 82 return vssRay.mPvsContribution; … … 384 384 // construct view cells if not already constructed 385 385 if (!mViewCellsManager->ViewCellsConstructed()) 386 mViewCellsManager->Construct (mObjects, mVssSampleRays);386 mViewCellsManager->ConstructSubdivision(mObjects, mVssSampleRays); 387 387 388 388 // $$JB temporary removed … … 394 394 395 395 //-- render simulation after merge 396 cout << "\nevaluating bsp view cells render time after merge ... ";397 398 //-- render simulation after merge399 396 cout << "\nevaluating bsp view cells render time after merge ... "; 400 397 … … 434 431 { 435 432 // construct view cells 436 mViewCellsManager->Construct (objects, mVssSampleRays);433 mViewCellsManager->ConstructSubdivision(objects, mVssSampleRays); 437 434 438 435 // throw away samples -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r573 r574 314 314 Debug << "splitting polygons of node " << this << " with plane " << mPlane << endl; 315 315 #endif 316 while (!polys.empty()) 317 { 318 Polygon3 *poly = polys.back(); 319 polys.pop_back(); 320 316 PolygonContainer::const_iterator it, it_end = polys.end(); 317 318 for (it = polys.begin(); it != polys.end(); ++ it) 319 { 320 Polygon3 *poly = *it; 321 321 322 //-- classify polygon 322 323 const int cf = poly->ClassifyPlane(plane, mEpsilon); … … 2538 2539 BspNodeGeometry::BspNodeGeometry(const BspNodeGeometry &rhs) 2539 2540 { 2541 mPolys.reserve(rhs.mPolys.size()); 2542 2540 2543 PolygonContainer::const_iterator it, it_end = rhs.mPolys.end(); 2541 2544 for (it = rhs.mPolys.begin(); it != it_end; ++ it) … … 2545 2548 } 2546 2549 } 2550 2547 2551 2548 2552 BspNodeGeometry::~BspNodeGeometry() … … 2700 2704 } 2701 2705 2706 2702 2707 Polygon3 *BspNodeGeometry::SplitPolygon(Polygon3 *planePoly, 2703 2708 const float epsilon) const -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r547 r574 29 29 BspNodeGeometry(const BspNodeGeometry &rhs); 30 30 31 //BspNodeGeometry(const PolygonContainer &polys); 32 31 33 ~BspNodeGeometry(); 32 34 … … 67 69 PolygonContainer mPolys; 68 70 }; 71 69 72 70 73 /** Data structure used for optimized ray casting. -
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 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
r573 r574 47 47 enum {BSP, KD, VSP_KD, VSP_BSP}; 48 48 49 /** Constructor taking the maximal number of samples used for construction 50 */ 51 ViewCellsManager(const int constructionSamples); 49 /** Constructor taking the initial and construction samples. 50 @param initialSamples the maximal number of samples used for creating the hierarchy 51 of view cells 52 @param constructionSamples the maximal number of samples used for construction 53 */ 54 ViewCellsManager(const int initialSamples, const int constructionSamples); 52 55 53 56 ViewCellsManager(); … … 62 65 /** Constructs view cell container with a given number of samples. 63 66 */ 64 virtual int Construct (const ObjectContainer &objects,67 virtual int ConstructSubdivision(const ObjectContainer &objects, 65 68 const VssRayContainer &rays) = 0; 66 69 … … 70 73 adding the contribution 71 74 @param addRays true if rays should be added to the PVSs of the viewcells they 72 intersect */ 75 intersect 76 @param storeViewCells true if view cells should be stored in the ray 77 */ 73 78 float ComputeSampleContributions(const VssRayContainer &rays, 74 const bool addContributions = true); 79 const bool addContributions, 80 const bool storeViewCells); 75 81 76 82 /** Add sample contributions to the viewcells they intersect */ … … 85 91 @returns number of sample contributions 86 92 */ 87 virtual float ComputeSampleContributions(VssRay &ray, const bool addRays = true);93 virtual float ComputeSampleContributions(VssRay &ray, const bool addRays, const bool storeViewCells); 88 94 89 95 virtual void AddSampleContributions(VssRay &ray); … … 147 153 void SetVisualizationSamples(const int visSamples); 148 154 155 /** Sets maximal number of samples used for the construction of the view cells. 156 */ 157 void SetConstructionSamples(const int constructionSamples); 158 149 159 /** Sets maximal number of samples used for the visualization of the view cells. 150 160 */ 151 void Set ConstructionSamples(const int constructionSamples);161 void SetInitialSamples(const int initialSamples); 152 162 153 163 /** Sets maximal number of samples used for the post processing of the view cells. … … 306 316 protected: 307 317 308 int CastPassSamples( int samplesPerPass,309 int sampleType,310 VssRayContainer *outRays) const;318 int CastPassSamples(const int samplesPerPass, 319 const int sampleType, 320 VssRayContainer &vssRays) const; 311 321 312 322 void ParseEnvironment(); … … 367 377 /// maximum number of samples taken for construction of the view cells 368 378 int mConstructionSamples; 379 int mSamplesPerPass; 380 int mInitialSamples; 369 381 int mPostProcessSamples; 370 382 int mVisualizationSamples; … … 409 421 used to construct the bsp tree. 410 422 */ 411 BspViewCellsManager(BspTree *tree , int constructionSamples);423 BspViewCellsManager(BspTree *tree); 412 424 413 425 ~BspViewCellsManager(); 414 426 415 int Construct (const ObjectContainer &objects,427 int ConstructSubdivision(const ObjectContainer &objects, 416 428 const VssRayContainer &rays); 417 429 … … 482 494 KdViewCellsManager(KdTree *tree); 483 495 484 int Construct (const ObjectContainer &objects,496 int ConstructSubdivision(const ObjectContainer &objects, 485 497 const VssRayContainer &rays); 486 498 … … 536 548 public: 537 549 538 VspKdViewCellsManager(VspKdTree *vspKdTree , int constructionSamples);539 540 int Construct (const ObjectContainer &objects,550 VspKdViewCellsManager(VspKdTree *vspKdTree); 551 552 int ConstructSubdivision(const ObjectContainer &objects, 541 553 const VssRayContainer &rays); 542 554 … … 595 607 public: 596 608 597 VspBspViewCellsManager(VspBspTree *tree , int constructionSamples);609 VspBspViewCellsManager(VspBspTree *tree); 598 610 ~VspBspViewCellsManager(); 599 611 600 int Construct (const ObjectContainer &objects,612 int ConstructSubdivision(const ObjectContainer &objects, 601 613 const VssRayContainer &rays); 602 614 -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r573 r574 178 178 const BspTreeStatistics &VspBspTree::GetStatistics() const 179 179 { 180 return m Stat;180 return mBspStats; 181 181 } 182 182 … … 273 273 AxisAlignedBox3 *forcedBoundingBox) 274 274 { 275 m Stat.nodes = 1;275 mBspStats.nodes = 1; 276 276 mBox.Initialize(); // initialise BSP tree bounding box 277 277 … … 353 353 mTermMinProbability *= mBox.GetVolume(); 354 354 355 m Stat.polys = (int)polys.size();355 mBspStats.polys = (int)polys.size(); 356 356 357 357 cout << "finished" << endl; … … 373 373 return 374 374 (sizeof(VspBspTree) + 375 m Stat.Leaves() * sizeof(BspLeaf) +376 m Stat.Interior() * sizeof(BspInterior) +377 m Stat.accumRays * sizeof(RayInfo)) / (1024.0f * 1024.0f);375 mBspStats.Leaves() * sizeof(BspLeaf) + 376 mBspStats.Interior() * sizeof(BspInterior) + 377 mBspStats.accumRays * sizeof(RayInfo)) / (1024.0f * 1024.0f); 378 378 } 379 379 … … 405 405 tStack.push(tData); 406 406 407 m Stat.Start();407 mBspStats.Start(); 408 408 cout << "Contructing vsp bsp tree ... \n"; 409 409 … … 439 439 << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 440 440 441 if (m Stat.Leaves() >= nleaves)441 if (mBspStats.Leaves() >= nleaves) 442 442 { 443 443 nleaves += 500; 444 444 445 cout << "leaves=" << m Stat.Leaves() << endl;445 cout << "leaves=" << mBspStats.Leaves() << endl; 446 446 Debug << "needed " 447 447 << TimeDiff(interTime, GetTime())*1e-3 << " secs to create 500 leaves" << endl; … … 453 453 cout << "finished\n"; 454 454 455 m Stat.Stop();455 mBspStats.Stop(); 456 456 } 457 457 … … 463 463 (data.mPvs <= mTermMinPvs) || 464 464 (data.mProbability <= mTermMinProbability) || 465 (m Stat.Leaves() >= mMaxViewCells) ||465 (mBspStats.Leaves() >= mMaxViewCells) || 466 466 (data.GetAvgRayContribution() > mTermMaxRayContribution) || 467 467 (data.mDepth >= mTermMaxDepth)); … … 509 509 AddToPvs(leaf, *tData.mRays, sampCon, conSamp); 510 510 511 m Stat.contributingSamples += conSamp;512 m Stat.sampleContributions +=(int) sampCon;511 mBspStats.contributingSamples += conSamp; 512 mBspStats.sampleContributions +=(int) sampCon; 513 513 514 514 //-- store additional info … … 526 526 PropagateUpValidity(leaf); 527 527 528 ++ m Stat.invalidLeaves;528 ++ mBspStats.invalidLeaves; 529 529 } 530 530 … … 572 572 { 573 573 // terminate branch because of max cost 574 ++ m Stat.maxCostNodes;574 ++ mBspStats.maxCostNodes; 575 575 return leaf; 576 576 } 577 577 } 578 578 579 m Stat.nodes += 2;579 mBspStats.nodes += 2; 580 580 581 581 //-- subdivide further … … 1160 1160 1161 1161 //! error also computed if cost ratio is missed 1162 ++ m Stat.splits[axis];1162 ++ mBspStats.splits[axis]; 1163 1163 isAxisAlignedSplit = true; 1164 1164 } … … 1509 1509 1510 1510 // store maximal and minimal depth 1511 if (data.mDepth > m Stat.maxDepth)1512 m Stat.maxDepth = data.mDepth;1513 1514 if (data.mPvs > m Stat.maxPvs)1515 m Stat.maxPvs = data.mPvs;1516 1517 if (data.mDepth < m Stat.minDepth)1518 m Stat.minDepth = data.mDepth;1511 if (data.mDepth > mBspStats.maxDepth) 1512 mBspStats.maxDepth = data.mDepth; 1513 1514 if (data.mPvs > mBspStats.maxPvs) 1515 mBspStats.maxPvs = data.mPvs; 1516 1517 if (data.mDepth < mBspStats.minDepth) 1518 mBspStats.minDepth = data.mDepth; 1519 1519 1520 1520 if (data.mDepth >= mTermMaxDepth) 1521 ++ m Stat.maxDepthNodes;1521 ++ mBspStats.maxDepthNodes; 1522 1522 // accumulate rays to compute rays / leaf 1523 m Stat.accumRays += (int)data.mRays->size();1523 mBspStats.accumRays += (int)data.mRays->size(); 1524 1524 1525 1525 if (data.mPvs < mTermMinPvs) 1526 ++ m Stat.minPvsNodes;1526 ++ mBspStats.minPvsNodes; 1527 1527 1528 1528 if ((int)data.mRays->size() < mTermMinRays) 1529 ++ m Stat.minRaysNodes;1529 ++ mBspStats.minRaysNodes; 1530 1530 1531 1531 if (data.GetAvgRayContribution() > mTermMaxRayContribution) 1532 ++ m Stat.maxRayContribNodes;1532 ++ mBspStats.maxRayContribNodes; 1533 1533 1534 1534 if (data.mProbability <= mTermMinProbability) 1535 ++ m Stat.minProbabilityNodes;1535 ++ mBspStats.minProbabilityNodes; 1536 1536 1537 1537 // accumulate depth to compute average depth 1538 m Stat.accumDepth += data.mDepth;1538 mBspStats.accumDepth += data.mDepth; 1539 1539 1540 1540 #ifdef _DEBUG … … 1655 1655 1656 1656 1657 void VspBspTree:: ValidateTree()1657 void VspBspTree::CollapseViewCells() 1658 1658 { 1659 1659 stack<BspNode *> nodeStack; … … 1664 1664 nodeStack.push(mRoot); 1665 1665 1666 const bool addToUnbounded = false;1667 1668 1666 while (!nodeStack.empty()) 1669 1667 { … … 1672 1670 1673 1671 if (node->IsLeaf()) 1674 1675 Bsp Leaf *leaf = dynamic_cast<BspLeaf *>(node);1676 1677 if (! addToUnbounded && node->TreeValid())1672 { 1673 BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 1674 1675 if (!viewCell->GetValid()) 1678 1676 { 1679 1677 BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 1680 1678 1681 if (!mViewCellsManager->CheckValidity(viewCell, 1682 mViewCellsManager->GetMinPvsSize(), 1683 mViewCellsManager->GetMaxPvsSize())) 1679 vector<BspLeaf *>::const_iterator it, it_end = viewCell->mLeaves.end(); 1680 for (it = viewCell->mLeaves.begin();it != it_end; ++ it) 1684 1681 { 1685 vector<BspLeaf *>::const_iterator it, it_end = viewCell->mLeaves.end(); 1686 for (it = viewCell->mLeaves.begin();it != it_end; ++ it) 1687 { 1688 BspLeaf *l = *it; 1689 1690 l->SetTreeValid(false); 1691 PropagateUpValidity(l); 1692 1693 if (addToUnbounded) 1694 l->SetViewCell(GetOrCreateOutOfBoundsCell()); 1695 1696 ++ mStat.invalidLeaves; 1697 } 1698 1699 // add to unbounded view cell or set to invalid 1700 if (addToUnbounded) 1701 { 1702 GetOrCreateOutOfBoundsCell()->GetPvs().AddPvs(viewCell->GetPvs()); 1703 DEL_PTR(viewCell); 1704 } 1705 else 1706 { 1707 viewCell->SetValid(false); 1708 } 1682 BspLeaf *l = *it; 1683 l->SetViewCell(GetOrCreateOutOfBoundsCell()); 1684 ++ mBspStats.invalidLeaves; 1709 1685 } 1686 1687 // add to unbounded view cell 1688 GetOrCreateOutOfBoundsCell()->GetPvs().AddPvs(viewCell->GetPvs()); 1689 DEL_PTR(viewCell); 1710 1690 } 1711 1691 } … … 1719 1699 } 1720 1700 1721 Debug << "invalid leaves: " << mStat.invalidLeaves << endl; 1722 } 1701 Debug << "invalid leaves: " << mBspStats.invalidLeaves << endl; 1702 } 1703 1704 1705 void VspBspTree::ValidateTree() 1706 { 1707 stack<BspNode *> nodeStack; 1708 1709 if (!mRoot) 1710 return; 1711 1712 nodeStack.push(mRoot); 1713 1714 mBspStats.invalidLeaves = 0; 1715 while (!nodeStack.empty()) 1716 { 1717 BspNode *node = nodeStack.top(); 1718 nodeStack.pop(); 1719 1720 if (node->IsLeaf()) 1721 { 1722 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 1723 1724 if (!leaf->GetViewCell()->GetValid()) 1725 ++ mBspStats.invalidLeaves; 1726 1727 // validity flags don't match => repair 1728 if (leaf->GetViewCell()->GetValid() != leaf->TreeValid()) 1729 { 1730 leaf->SetTreeValid(leaf->GetViewCell()->GetValid()); 1731 PropagateUpValidity(leaf); 1732 } 1733 } 1734 else 1735 { 1736 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1737 1738 nodeStack.push(interior->GetFront()); 1739 nodeStack.push(interior->GetBack()); 1740 } 1741 } 1742 1743 Debug << "invalid leaves: " << mBspStats.invalidLeaves << endl; 1744 } 1745 1723 1746 1724 1747 … … 1784 1807 int splits = 0; 1785 1808 1786 while (!rays.empty()) 1787 { 1788 RayInfo bRay = rays.back(); 1789 rays.pop_back(); 1790 1809 RayInfoContainer::const_iterator it, it_end = rays.end(); 1810 1811 for (it = rays.begin(); it != it_end; ++ it) 1812 { 1813 RayInfo bRay = *it; 1814 1791 1815 VssRay *ray = bRay.mRay; 1792 1816 float t; … … 2213 2237 int splits = 0; 2214 2238 2215 while (!polys.empty()) 2216 { 2217 Polygon3 *poly = polys.back(); 2218 polys.pop_back(); 2239 PolygonContainer::const_iterator it, it_end = polys.end(); 2240 2241 for (it = polys.begin(); it != polys.end(); ++ it) 2242 { 2243 Polygon3 *poly = *it; 2219 2244 2220 2245 // classify polygon … … 2632 2657 BspLeaf *leaf = *it; 2633 2658 2634 /// create leaf pvs (needed for post processing 2659 /// create leaf pvs (needed for post processing) 2635 2660 leaf->mPvs = new ObjectPvs(leaf->GetViewCell()->GetPvs()); 2636 2661 … … 2674 2699 int VspBspTree::CollectMergeCandidates(const VssRayContainer &rays) 2675 2700 { 2676 vector<BspRay *> bspRays;2677 2678 2701 ViewCell::NewMail(); 2679 2702 long startTime = GetTime(); 2680 ConstructBspRays(bspRays, rays); 2681 Debug << (int)bspRays.size() << " bsp rays constructed in " 2682 << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 2683 2703 2684 2704 map<BspLeaf *, vector<BspLeaf*> > neighborMap; 2685 vector<BspIntersection>::const_iterator iit;2705 ViewCellContainer::const_iterator iit; 2686 2706 2687 2707 int numLeaves = 0; … … 2689 2709 BspLeaf::NewMail(); 2690 2710 2691 for (int i = 0; i < (int) bspRays.size(); ++ i)2711 for (int i = 0; i < (int)rays.size(); ++ i) 2692 2712 { 2693 BspRay *ray = bspRays[i];2713 VssRay *ray = rays[i]; 2694 2714 2695 2715 // traverse leaves stored in the rays and compare and 2696 2716 // merge consecutive leaves (i.e., the neighbors in the tree) 2697 if (ray-> intersections.size() < 2)2717 if (ray->mViewCells.size() < 2) 2698 2718 continue; 2699 2719 2700 iit = ray->intersections.begin(); 2701 BspLeaf *leaf = (*(iit ++)).mLeaf; 2720 iit = ray->mViewCells.begin(); 2721 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*(iit ++)); 2722 BspLeaf *leaf = bspVc->mLeaves[0]; 2702 2723 2703 2724 // create leaf pvs (needed for post processing) … … 2715 2736 // traverse intersections 2716 2737 // consecutive leaves are neighbors => add them to queue 2717 for (; iit != ray-> intersections.end(); ++ iit)2738 for (; iit != ray->mViewCells.end(); ++ iit) 2718 2739 { 2719 2740 // next pair 2720 2741 BspLeaf *prevLeaf = leaf; 2721 leaf = (*iit).mLeaf; 2742 bspVc = dynamic_cast<BspViewCell *>(*iit); 2743 leaf = bspVc->mLeaves[0]; 2722 2744 2723 2745 // view space not valid or same view cell … … 2781 2803 Debug << "overall cost: " << BspMergeCandidate::sOverallCost << endl; 2782 2804 2783 CLEAR_CONTAINER(bspRays);2784 2785 2805 //-- collect the leaves which haven't been found by ray casting 2786 2806 if (0) … … 2857 2877 mergeStats.Start(); 2858 2878 2859 //BspMergeCandidate::sOverallCost = mBox.SurfaceArea() * m Stat.maxPvs;2879 //BspMergeCandidate::sOverallCost = mBox.SurfaceArea() * mBspStats.maxPvs; 2860 2880 long startTime = GetTime(); 2861 2881 2862 cout << "collecting merge candidates ... " ;2882 cout << "collecting merge candidates ... " << endl; 2863 2883 2864 2884 if (mUseRaysForMerge) … … 2880 2900 2881 2901 // number of view cells withouth the invalid ones 2882 int nViewCells = m Stat.Leaves() - mStat.invalidLeaves;2902 int nViewCells = mBspStats.Leaves() - mBspStats.invalidLeaves; 2883 2903 2884 2904 … … 3370 3390 void VspBspTree::PropagateUpValidity(BspNode *node) 3371 3391 { 3372 while (!node->IsRoot() && node->GetParent()->TreeValid()) 3373 { 3374 node = node->GetParent(); 3375 node->SetTreeValid(false); 3392 const bool isValid = node->TreeValid(); 3393 3394 // propagative up invalid flag until only invalid nodes exist over this node 3395 if (!isValid) 3396 { 3397 while (!node->IsRoot() && node->GetParent()->TreeValid()) 3398 { 3399 node = node->GetParent(); 3400 node->SetTreeValid(false); 3401 } 3402 } 3403 else 3404 { 3405 // propagative up valid flag until one of the subtrees is invalid 3406 while (!node->IsRoot() && !node->TreeValid()) 3407 { 3408 node = node->GetParent(); 3409 BspInterior *interior = dynamic_cast<BspInterior *>(node); 3410 3411 // the parent is valid iff both leaves are valid 3412 node->SetTreeValid(interior->GetBack()->TreeValid() && 3413 interior->GetFront()->TreeValid()); 3414 } 3376 3415 } 3377 3416 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
r573 r574 307 307 308 308 309 /** Checks validy of view cells. 310 if not valid, sets regions invalid and deletes view cell. 309 /** Checks if tree validity-flags are right 310 with respect to view cell valitiy. 311 If not, marks subtree as invalid. 311 312 */ 312 313 void ValidateTree(); 314 315 /** Invalid view cells are added to the unbounded space 316 */ 317 void CollapseViewCells(); 313 318 314 319 protected: … … 626 631 BspNode *mRoot; 627 632 628 BspTreeStatistics m Stat;633 BspTreeStatistics mBspStats; 629 634 630 635 /// Strategies for choosing next split plane. -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
r564 r574 27 27 environment->GetIntValue("VssPreprocessor.vssSamplesPerPass", mVssSamplesPerPass); 28 28 environment->GetBoolValue("VssPreprocessor.useImportanceSampling", mUseImportanceSampling); 29 environment->GetBoolValue("ViewCells.delayedConstruction", mDelayedViewCellsConstruction); 30 29 31 30 environment->GetBoolValue("VssPreprocessor.loadInitialSamples", mLoadInitialSamples); 32 31 environment->GetBoolValue("VssPreprocessor.storeInitialSamples", mStoreInitialSamples); … … 54 53 ray.Init(point, direction, Ray::LOCAL_RAY); 55 54 } 55 56 57 void 58 VssPreprocessor::CastRays( 59 SimpleRayContainer &rays, 60 VssRayContainer &vssRays 61 ) 62 { 63 for (int i=0; i < rays.size(); i++) 64 CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays); 65 } 66 56 67 57 68 int … … 529 540 mViewCellsManager->LoadViewCells(mViewCellsFilename, &mObjects); 530 541 } 531 542 else 543 { 544 // construct view cells using it's own set of samples 545 mViewCellsManager->Construct(this); 546 547 //-- several visualizations and statistics 548 Debug << "view cells after construction: " << endl; 549 mViewCellsManager->PrintStatistics(Debug); 550 } 551 532 552 533 553 VssTree *vssTree = NULL; … … 634 654 } 635 655 636 /// compute view cell contribution of rays if view cells manager already constructed637 mViewCellsManager->ComputeSampleContributions(mVssRays);638 639 // construct view cells640 if (!mDelayedViewCellsConstruction)641 mViewCellsManager->Construct(mObjects, mVssRays);642 643 656 vssTree = new VssTree; 644 657 // viewcells = Construct(mVssRays); … … 712 725 cout<<"Average PVS size = "<<avgPvs<<endl; 713 726 714 // construct view cells after vss715 if (!mViewCellsManager->ViewCellsConstructed() &&716 (samples + mInitialSamples >= mViewCellsManager->GetConstructionSamples()))717 {718 Debug << "samples " << samples << " initial " << mInitialSamples << " " << samples + mInitialSamples << endl;719 VssRayContainer constructionRays;720 vssTree->CollectRays(constructionRays, mViewCellsManager->GetConstructionSamples());721 722 Debug << "collected rays: " << constructionRays.size() << endl;723 724 // test if we really have enough rays725 //if (constructionRays.size() >= nSamples)726 mViewCellsManager->Construct(mObjects, constructionRays);727 }728 729 727 /// compute view cell contribution of rays 730 mViewCellsManager->ComputeSampleContributions(vssRays );728 mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 731 729 732 730 if (numExportRays) { … … 750 748 } 751 749 752 753 // at the latest create view cells here754 if (!mViewCellsManager->ViewCellsConstructed())755 {756 VssRayContainer constructionRays;757 758 vssTree->CollectRays(constructionRays,759 mViewCellsManager->GetConstructionSamples());760 Debug << "collected rays: " << constructionRays.size() << endl;761 762 mViewCellsManager->Construct(mObjects, constructionRays);763 }764 765 Debug << vssTree->stat << endl;766 VssRayContainer viewCellRays;767 768 // compute rays used for view cells construction769 int numRays = Max(mViewCellsManager->GetPostProcessSamples(),770 mViewCellsManager->GetVisualizationSamples());771 772 vssTree->CollectRays(viewCellRays, numRays);773 774 //-- post process view cells775 mViewCellsManager->PostProcess(mObjects, viewCellRays);776 777 750 if (mTestBeamSampling && mUseGlRenderer) 778 751 { … … 780 753 } 781 754 782 //-- several visualizations and statistics 783 Debug << "\nview cells after post processing: " << endl; 784 mViewCellsManager->PrintStatistics(Debug); 785 786 mViewCellsManager->Visualize(mObjects, viewCellRays); 787 755 Debug << vssTree->stat << endl; 756 757 if (0) 758 { 759 VssRayContainer viewCellRays; 760 761 // compute rays used for view cells construction 762 const int numRays = mViewCellsManager->GetVisualizationSamples(); 763 764 vssTree->CollectRays(viewCellRays, numRays); 765 } 766 788 767 //-- render simulation after merge 789 cout << "\nevaluating bsp view cells render time after merge... ";768 cout << "\nevaluating bsp view cells render time after sampling ... "; 790 769 mRenderSimulator->RenderScene(); 791 770 SimulationStatistics ss; -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h
r535 r574 37 37 VssRayContainer mVssRays; 38 38 39 bool mDelayedViewCellsConstruction;40 41 39 VssPreprocessor(); 42 40 ~VssPreprocessor(); … … 52 50 ); 53 51 52 void CastRays(SimpleRayContainer &rays, VssRayContainer &vssRays); 53 54 54 void 55 55 SetupRay(Ray &ray, -
trunk/VUT/GtpVisibilityPreprocessor/src/common.h
r434 r574 138 138 #endif 139 139 // Clears a container (i.e., a vector of pointers) and deletes the pointers 140 #if 0 140 141 #ifndef CLEAR_CONTAINER 141 142 #define CLEAR_CONTAINER(co) do { while (!(co).empty()) { \ … … 143 144 (co).pop_back();}} \ 144 145 while (0) 146 #endif 147 #endif 148 149 #ifndef CLEAR_CONTAINER 150 #define CLEAR_CONTAINER(co) do { for (int _i = 0; _i < (int)(co).size(); ++ _i) { \ 151 DEL_PTR((co)[_i]);} \ 152 (co).clear(); } \ 153 while (0) 145 154 #endif 146 155 -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r570 r574 67 67 68 68 QApplication *app = NULL; 69 69 70 70 if (p->mUseGlRenderer) { 71 71 // create a qt application first (must be created before any opengl widget...
Note: See TracChangeset
for help on using the changeset viewer.