- Timestamp:
- 12/23/05 21:35:53 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r479 r480 177 177 Simulation { 178 178 objRenderCost 1.0 179 vcOverhead 2.0179 vcOverhead 1.0 180 180 # always between 0 and 1 181 moveSpeed 0.000 02181 moveSpeed 0.0001 182 182 } 183 183 … … 223 223 VspBspTree { 224 224 Construction { 225 samples 100000225 samples 500000 226 226 epsilon 0.005 227 227 } … … 241 241 242 242 # maximal tested rays for split cost heuristics 243 maxTests 500243 maxTests 2000 244 244 245 245 # factors for evaluating split plane costs … … 258 258 minArea 0.0001 259 259 maxRayContribution 0.005 260 maxCostRatio 0. 9260 maxCostRatio 0.8 261 261 missTolerance 2 262 262 #maxAccRayLength 100 263 263 264 maxViewCells 1000264 maxViewCells 5000 265 265 266 266 # used for pvs criterium … … 289 289 290 290 PostProcess { 291 maxCostRatio 0.0 5291 maxCostRatio 0.005 292 292 minViewCells 700 293 293 maxPvsSize 500 -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r478 r480 1490 1490 optFloat, 1491 1491 "-vsp_kd_post_process_max_cost_ratio=", 1492 " 1.5");1492 "0.9"); 1493 1493 1494 1494 RegisterOption("VspKdTree.PostProcess.minViewCells", … … 1758 1758 optFloat, 1759 1759 "-vsp_bsp_post_process_max_cost_ratio=", 1760 " 1.5");1760 "0.9"); 1761 1761 1762 1762 RegisterOption("VspBspTree.PostProcess.minViewCells", -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r478 r480 236 236 mViewCellsManager->SetPostProcessSamples(postProcessSamples); 237 237 mViewCellsManager->SetVisualizationSamples(visSamples); 238 mViewCellsManager->SetRenderer(mRenderSimulator); 238 239 239 240 //Debug << "Visualization samples: " << mViewCellsManager->GetVisualizationSamples() << endl; -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp
r479 r480 83 83 // and the probability that a view cell border is crossed 84 84 loadPvsOverhead += GetCrossVcProbability() * mVcOverhead; 85 85 //Debug << "vccost: " << vcCost << " p in vc " << pInVc << " cross vc " << GetCrossVcProbability() << endl; 86 86 //-- update statistics 87 87 renderTime += vcCost; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r479 r480 976 976 vector<SortableEntry> &splitCandidates) const 977 977 { 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 978 splitCandidates.clear(); 979 980 int requestedSize = 2 * (int)polys.size(); 981 // creates a sorted split candidates array 982 splitCandidates.reserve(requestedSize); 983 984 PolygonContainer::const_iterator it, it_end = polys.end(); 985 986 AxisAlignedBox3 box; 987 988 // insert all queries 989 for(it = polys.begin(); it != it_end; ++ it) 990 { 991 box.Initialize(); 992 box.Include(*(*it)); 993 994 splitCandidates.push_back(SortableEntry(SortableEntry::POLY_MIN, box.Min(axis), *it)); 995 splitCandidates.push_back(SortableEntry(SortableEntry::POLY_MAX, box.Max(axis), *it)); 996 } 997 998 stable_sort(splitCandidates.begin(), splitCandidates.end()); 999 999 } 1000 1000 … … 2612 2612 return planePoly; 2613 2613 } 2614 2615 void BspNodeGeometry::ComputeBoundingBox(AxisAlignedBox3 &box) 2616 { 2617 Polygon3::IncludeInBox(mPolys, box); 2618 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r479 r480 28 28 ~BspNodeGeometry(); 29 29 30 /** Returns accumulated area of all polygons. 31 */ 30 32 float GetArea() const; 31 33 … … 39 41 const float epsilon) const; 40 42 43 /** Computes bounding box of the node. 44 */ 45 void ComputeBoundingBox(AxisAlignedBox3 &box); 46 /** Splits the polygon and returns the part of the polygon inside of the node geometry. 47 */ 41 48 Polygon3 *SplitPolygon(Polygon3 *poly, const float epsilon) const; 42 49 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r479 r480 14 14 15 15 ViewCellsManager::ViewCellsManager(): 16 mRender Simulator(NULL),16 mRenderer(NULL), 17 17 mConstructionSamples(0), 18 18 mPostProcessSamples(0), … … 29 29 ViewCellsManager::ViewCellsManager(int constructionSamples): 30 30 mConstructionSamples(constructionSamples), 31 mRender Simulator(NULL),31 mRenderer(NULL), 32 32 mPostProcessSamples(0), 33 33 mVisualizationSamples(0) … … 41 41 ViewCellsManager::~ViewCellsManager() 42 42 { 43 DEL_PTR(mRender Simulator);43 DEL_PTR(mRenderer); 44 44 45 45 CLEAR_CONTAINER(mViewCells); … … 176 176 } 177 177 178 void ViewCellsManager::SetRenderer(Renderer *renderer) 179 { 180 mRenderer = renderer; 181 } 178 182 179 183 ViewCell *ViewCellsManager::GenerateViewCell(Mesh *mesh) const … … 236 240 } 237 241 238 void 239 ViewCellsManager::PrintPvsStatistics(ostream &s) 242 void ViewCellsManager::PrintPvsStatistics(ostream &s) 240 243 { 241 244 s<<"############# Viewcell PVS STAT ##################\n"; … … 252 255 } 253 256 257 void ViewCellsManager::ResetViewCells() 258 { 259 mViewCells.clear(); 260 CollectViewCells(); 261 mViewCellsStats.Reset(); 262 EvaluateViewCellsStats(); 263 264 mTotalAreaValid = false; 265 } 266 254 267 void ViewCellsManager::ComputeSampleContributions(VssRay &ray) 255 268 { … … 313 326 314 327 for (it = mViewCells.begin(); it != it_end; ++ it) 328 { 329 //Debug << "area: " << GetArea(*it); 315 330 mTotalArea += GetArea(*it); 316 331 } 332 317 333 mTotalAreaValid = true; 318 334 … … 343 359 } 344 360 361 345 362 ViewCell *BspViewCellsManager::GenerateViewCell(Mesh *mesh) const 346 363 { 347 364 return new BspViewCell(mesh); 348 365 } 366 349 367 350 368 int BspViewCellsManager::Construct(const ObjectContainer &objects, … … 388 406 } 389 407 390 EvaluateViewCellsStats();391 392 408 // destroy rays created only for construction 393 409 CLEAR_CONTAINER(constructionRays); … … 395 411 Debug << mBspTree->GetStatistics() << endl; 396 412 413 EvaluateViewCellsStats(); 414 Debug << "\nView cells after construction:\n" << mViewCellsStats << endl; 415 397 416 // recast rest of the rays 398 417 ComputeSampleContributions(savedRays); … … 401 420 } 402 421 422 void BspViewCellsManager::CollectViewCells() 423 { 424 mBspTree->CollectViewCells(mViewCells); 425 } 403 426 404 427 float BspViewCellsManager::GetProbability(ViewCell *viewCell) … … 449 472 int pvsSize = 0; 450 473 474 EvaluateViewCellsStats(); 451 475 Debug << "original view cell partition:\n" << mViewCellsStats << endl; 452 476 477 mRenderer->RenderScene(); 478 SimulationStatistics ss; 479 dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 480 481 Debug << ss << endl; 482 453 483 if (1) // export view cells 454 484 { … … 529 559 530 560 // reset view cells and stats 531 mViewCells.clear(); 532 mTotalAreaValid = false; 533 mBspTree->CollectViewCells(mViewCells); 534 mViewCellsStats.Reset(); 535 EvaluateViewCellsStats(); 561 ResetViewCells(); 536 562 537 563 return merged; … … 876 902 } 877 903 904 void KdViewCellsManager::CollectViewCells() 905 { 906 //mKdTree->CollectViewCells(mViewCells); TODO 907 } 878 908 879 909 int KdViewCellsManager::Construct(const ObjectContainer &objects, … … 887 917 mKdTree->Construct(); 888 918 919 mTotalAreaValid = false; 889 920 // create the view cells 890 921 mKdTree->CreateAndCollectViewCells(mViewCells); 922 923 // cast rays 924 ComputeSampleContributions(rays); 925 891 926 EvaluateViewCellsStats(); 927 Debug << "\nView cells after construction:\n" << mViewCellsStats << endl; 892 928 893 929 return 0; … … 1119 1155 { 1120 1156 // volume or area substitutes for view point probability 1121 AxisAlignedBox3 box = mVspKdTree->GetBBox(mVspKdTree->GetRoot()); 1122 1123 return GetArea(viewCell) / box.SurfaceArea(); 1124 //return GetArea(viewCell) / GetAccVcArea(); 1157 #if 0 1158 return GetArea(viewCell) / GetSceneBbox().SurfaceArea(); 1159 #else 1160 return GetArea(viewCell) / GetAccVcArea(); 1161 #endif 1125 1162 } 1126 1163 … … 1131 1168 } 1132 1169 1170 void VspKdViewCellsManager::CollectViewCells() 1171 { 1172 mVspKdTree->CollectViewCells(mViewCells); 1173 } 1133 1174 1134 1175 int VspKdViewCellsManager::Construct(const ObjectContainer &objects, … … 1149 1190 1150 1191 mVspKdTree->Construct(constructionRays, sceneBbox); 1151 mVspKdTree->CollectViewCells(mViewCells);1152 EvaluateViewCellsStats();1153 1154 1192 Debug << mVspKdTree->GetStatistics() << endl; 1193 1194 ResetViewCells(); 1195 Debug << "\nView cells after construction:\n" << mViewCellsStats << endl; 1155 1196 1156 1197 // finally merge kd leaf building blocks to view cells … … 1352 1393 1353 1394 1395 void VspBspViewCellsManager::CollectViewCells() 1396 { 1397 mVspBspTree->CollectViewCells(mViewCells); 1398 } 1399 1400 1354 1401 float VspBspViewCellsManager::GetRendercost(ViewCell *viewCell, 1355 1402 float objRendercost) const … … 1392 1439 1393 1440 mVspBspTree->Construct(constructionRays); 1394 mVspBspTree->CollectViewCells(mViewCells);1395 EvaluateViewCellsStats();1396 1397 1441 Debug << mVspBspTree->GetStatistics() << endl; 1398 1442 1443 ResetViewCells(); 1444 1445 Debug << "\nView cells after construction:\n" << mViewCellsStats << endl; 1399 1446 // recast rest of rays 1400 1447 ComputeSampleContributions(savedRays); … … 1447 1494 int pvsSize = 0; 1448 1495 1496 EvaluateViewCellsStats(); 1449 1497 Debug << "original view cell partition:\n" << mViewCellsStats << endl; 1450 1498 1499 mRenderer->RenderScene(); 1500 SimulationStatistics ss; 1501 dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 1502 Debug << ss << endl; 1503 1451 1504 if (1) // export view cells 1452 1505 { … … 1532 1585 1533 1586 // reset view cells and stats 1534 mViewCells.clear(); 1535 mTotalAreaValid = false; 1536 mVspBspTree->CollectViewCells(mViewCells); 1537 mViewCellsStats.Reset(); 1538 EvaluateViewCellsStats(); 1587 ResetViewCells(); 1539 1588 1540 1589 return merged; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
r479 r480 10 10 class Intersectable; 11 11 class RenderSimulator; 12 class Renderer; 12 13 class Mesh; 13 14 struct Triangle3; … … 192 193 VssRayContainer &savedRays) const; 193 194 194 /** Returns accumulated area of all view cells. 195 */ 196 float GetAccVcArea(); 197 198 /** Returns area of one view cell. 199 */ 200 virtual float GetArea(ViewCell *viewCell) const; 201 202 /** Returns volume of view cells. 203 */ 204 virtual float GetVolume(ViewCell *viewCell) const; 205 206 virtual AxisAlignedBox3 GetSceneBbox() const = 0; 207 195 /** Returns accumulated area of all view cells. 196 */ 197 float GetAccVcArea(); 198 199 /** Returns area of one view cell. 200 */ 201 virtual float GetArea(ViewCell *viewCell) const; 202 203 /** Returns volume of view cells. 204 */ 205 virtual float GetVolume(ViewCell *viewCell) const; 206 207 virtual AxisAlignedBox3 GetSceneBbox() const = 0; 208 209 /** Sets the current renderer mainly for view cells statistics. 210 */ 211 void SetRenderer(Renderer *renderer); 212 213 208 214 protected: 215 216 /** Recollects view cells and resets statistics. 217 */ 218 void ResetViewCells(); 219 /** Collects the view cells in the view cell container. 220 */ 221 virtual void CollectViewCells() = 0; 222 209 223 /** Evaluates view cells statistics and stores it in 210 224 mViewCellsStatistics. … … 215 229 ViewCell *mUnbounded; 216 230 217 /// Simulates rendering218 Render Simulator *mRenderSimulator;231 /// Renders the view cells. 232 Renderer *mRenderer; 219 233 220 234 /// Loaded view cells … … 281 295 protected: 282 296 297 void CollectViewCells(); 298 283 299 /** Merges view cells front and back leaf view cell. 284 300 */ … … 348 364 protected: 349 365 350 KdNode *GetNodeForPvs(KdLeaf *leaf); 351 352 353 /// the BSP tree. 354 KdTree *mKdTree; 355 356 /// depth of the KD tree nodes with represent the view cells 357 int mKdPvsDepth; 366 void CollectViewCells(); 367 KdNode *GetNodeForPvs(KdLeaf *leaf); 368 369 370 /// the BSP tree. 371 KdTree *mKdTree; 372 373 /// depth of the KD tree nodes with represent the view cells 374 int mKdPvsDepth; 358 375 }; 359 376 … … 400 417 protected: 401 418 419 void CollectViewCells(); 420 402 421 /// the BSP tree. 403 422 VspKdTree *mVspKdTree; … … 459 478 bool ShouldMerge(BspLeaf *front, BspLeaf *back) const; 460 479 480 void CollectViewCells(); 481 461 482 /// the view space partition BSP tree. 462 483 VspBspTree *mVspBspTree; -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r479 r480 84 84 environment->GetIntValue("VspBspTree.Termination.maxViewCells", mMaxViewCells); 85 85 environment->GetIntValue("VspBspTree.PostProcess.minViewCells", mMergeMinViewCells); 86 environment->Get IntValue("VspBspTree.PostProcess.maxCostRatio", mMergeMaxCostRatio);86 environment->GetFloatValue("VspBspTree.PostProcess.maxCostRatio", mMergeMaxCostRatio); 87 87 88 88 … … 125 125 Debug << "pvs"; 126 126 } 127 128 mSplitCandidates = new vector<SortableEntry>; 127 129 128 130 Debug << endl; … … 140 142 DEL_PTR(mRoot); 141 143 DEL_PTR(mRootCell); 144 DEL_PTR(mSplitCandidates); 142 145 } 143 146 … … 236 239 long startTime = GetTime(); 237 240 238 cout << "Extracting polygons from rays ... ";241 cout << "Extracting polygons from rays ... "; 239 242 240 243 Intersectable::NewMail(); … … 430 433 ++ maxCostMisses; 431 434 432 if (maxCostMisses > =mTermMissTolerance)435 if (maxCostMisses > mTermMissTolerance) 433 436 { 434 437 // terminate branch because of max cost … … 555 558 } 556 559 557 void VspBspTree::SortSplitCandidates(const PolygonContainer &polys, 558 const int axis, 559 vector<SortableEntry> &splitCandidates) const 560 { 561 splitCandidates.clear(); 562 563 const int requestedSize = 2 * (int)polys.size(); 564 565 // creates a sorted split candidates array 566 splitCandidates.reserve(requestedSize); 567 568 PolygonContainer::const_iterator it, it_end = polys.end(); 569 570 AxisAlignedBox3 box; 571 572 // insert all queries 573 for(it = polys.begin(); it != it_end; ++ it) 574 { 575 box.Initialize(); 576 box.Include(*(*it)); 577 578 splitCandidates.push_back(SortableEntry(SortableEntry::POLY_MIN, box.Min(axis), *it)); 579 splitCandidates.push_back(SortableEntry(SortableEntry::POLY_MAX, box.Max(axis), *it)); 580 } 581 582 stable_sort(splitCandidates.begin(), splitCandidates.end()); 583 } 584 585 586 float VspBspTree::BestCostRatio(const PolygonContainer &polys, 587 const AxisAlignedBox3 &box, 588 const int axis, 589 float &position, 590 int &objectsBack, 591 int &objectsFront) const 592 { 593 vector<SortableEntry> splitCandidates; 594 595 SortSplitCandidates(polys, axis, splitCandidates); 596 560 void VspBspTree::SortSplitCandidates(const RayInfoContainer &rays, const int axis) 561 { 562 mSplitCandidates->clear(); 563 564 int requestedSize = 2 * (int)(rays.size()); 565 // creates a sorted split candidates array 566 if (mSplitCandidates->capacity() > 500000 && 567 requestedSize < (int)(mSplitCandidates->capacity()/10) ) 568 { 569 DEL_PTR(mSplitCandidates); 570 mSplitCandidates = new vector<SortableEntry>; 571 } 572 573 mSplitCandidates->reserve(requestedSize); 574 575 // insert all queries 576 for(RayInfoContainer::const_iterator ri = rays.begin(); ri < rays.end(); ++ ri) 577 { 578 bool positive = (*ri).mRay->HasPosDir(axis); 579 mSplitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMin : SortableEntry::ERayMax, 580 (*ri).ExtrapOrigin(axis), (void *)&*ri)); 581 582 mSplitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMax : SortableEntry::ERayMin, 583 (*ri).ExtrapTermination(axis), (void *)&*ri)); 584 } 585 586 stable_sort(mSplitCandidates->begin(), mSplitCandidates->end()); 587 } 588 589 float VspBspTree::BestCostRatioHeuristics(const RayInfoContainer &rays, 590 const AxisAlignedBox3 &box, 591 const int pvsSize, 592 int &axis, 593 float &position) 594 { 595 // AxisAlignedBox3 dirBox = GetDirBBox(node); 596 int raysBack; 597 int raysFront; 598 int pvsBack; 599 int pvsFront; 600 601 axis = box.Size().DrivingAxis(); 602 603 SortSplitCandidates(rays, axis); 604 597 605 // go through the lists, count the number of objects left and right 598 606 // and evaluate the following cost funcion: 599 // C = ct_div_ci + (ol + or)/queries 600 601 int objectsLeft = 0, objectsRight = (int)polys.size(); 602 607 // C = ct_div_ci + (ql*rl + qr*rr)/queries 608 609 int rl = 0, rr = (int)rays.size(); 610 int pl = 0, pr = pvsSize; 611 603 612 float minBox = box.Min(axis); 604 613 float maxBox = box.Max(axis); 605 float boxArea = box.SurfaceArea(); 606 607 float minBand = minBox + mAxisAlignedSplitBorder * (maxBox - minBox); 608 float maxBand = minBox + (1.0f - mAxisAlignedSplitBorder) * (maxBox - minBox); 609 614 float sizeBox = maxBox - minBox; 615 616 float minBand = minBox + 0.1f*(maxBox - minBox); 617 float maxBand = minBox + 0.9f*(maxBox - minBox); 618 619 float sum = rr*sizeBox; 610 620 float minSum = 1e20f; 611 vector<SortableEntry>::const_iterator ci, ci_end = splitCandidates.end(); 612 613 for(ci = splitCandidates.begin(); ci != ci_end; ++ ci) 614 { 615 switch ((*ci).type) 616 { 617 case SortableEntry::POLY_MIN: 618 ++ objectsLeft; 619 break; 620 case SortableEntry::POLY_MAX: 621 -- objectsRight; 622 break; 623 default: 624 break; 625 } 626 627 if ((*ci).value > minBand && (*ci).value < maxBand) 628 { 629 AxisAlignedBox3 lbox = box; 630 AxisAlignedBox3 rbox = box; 631 lbox.SetMax(axis, (*ci).value); 632 rbox.SetMin(axis, (*ci).value); 633 634 float sum = objectsLeft * lbox.SurfaceArea() + 635 objectsRight * rbox.SurfaceArea(); 636 637 if (sum < minSum) 621 622 Intersectable::NewMail(); 623 624 // set all object as belonging to the fron pvs 625 for(RayInfoContainer::const_iterator ri = rays.begin(); ri != rays.end(); ++ ri) 626 { 627 if ((*ri).mRay->IsActive()) 628 { 629 Intersectable *object = (*ri).mRay->mTerminationObject; 630 631 if (object) 632 if (!object->Mailed()) 633 { 634 object->Mail(); 635 object->mCounter = 1; 636 } 637 else 638 ++ object->mCounter; 639 } 640 } 641 642 Intersectable::NewMail(); 643 644 for (vector<SortableEntry>::const_iterator ci = mSplitCandidates->begin(); 645 ci < mSplitCandidates->end(); ++ ci) 646 { 647 VssRay *ray; 648 649 switch ((*ci).type) 650 { 651 case SortableEntry::ERayMin: 652 { 653 ++ rl; 654 ray = (VssRay *) (*ci).data; 655 Intersectable *object = ray->mTerminationObject; 656 if (object && !object->Mailed()) 657 { 658 object->Mail(); 659 ++ pl; 660 } 661 break; 662 } 663 case SortableEntry::ERayMax: 664 { 665 -- rr; 666 667 ray = (VssRay *) (*ci).data; 668 Intersectable *object = ray->mTerminationObject; 669 670 if (object) 671 { 672 if (-- object->mCounter == 0) 673 -- pr; 674 } 675 676 break; 677 } 678 } 679 680 // Note: sufficient to compare size of bounding boxes of front and back side? 681 if ((*ci).value > minBand && (*ci).value < maxBand) 682 { 683 sum = pl*((*ci).value - minBox) + pr*(maxBox - (*ci).value); 684 685 // cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl; 686 // cout<<"cost= "<<sum<<endl; 687 688 if (sum < minSum) 638 689 { 639 690 minSum = sum; 640 691 position = (*ci).value; 641 692 642 objectsBack = objectsLeft; 643 objectsFront = objectsRight; 693 raysBack = rl; 694 raysFront = rr; 695 696 pvsBack = pl; 697 pvsFront = pr; 698 644 699 } 645 700 } 646 701 } 647 648 const float oldCost = (float)polys.size(); 649 const float newCost = mAxisAlignedCtDivCi + minSum / boxArea; 650 const float ratio = newCost / oldCost; 651 652 653 #if 0 654 Debug << "====================" << endl; 655 Debug << "costRatio=" << ratio << " pos=" << position<<" t=" << (position - minBox)/(maxBox - minBox) 656 << "\t o=(" << objectsBack << "," << objectsFront << ")" << endl; 657 #endif 658 return ratio; 659 } 660 661 bool VspBspTree::SelectAxisAlignedPlane(Plane3 &plane, 662 const PolygonContainer &polys) const 702 703 float oldCost = (float)pvsSize; 704 float newCost = mCtDivCi + minSum / sizeBox; 705 float ratio = newCost / oldCost; 706 707 //Debug << "costRatio=" << ratio << " pos=" << position << " t=" << (position - minBox) / (maxBox - minBox) 708 // <<"\t q=(" << queriesBack << "," << queriesFront << ")\t r=(" << raysBack << "," << raysFront << ")" << endl; 709 710 return ratio; 711 } 712 713 714 float VspBspTree::SelectAxisAlignedPlane(Plane3 &plane, 715 const VspBspTraversalData &tData) 663 716 { 664 717 AxisAlignedBox3 box; … … 666 719 667 720 // create bounding box of region 668 Polygon3::IncludeInBox(polys, box); 669 670 int objectsBack = 0, objectsFront = 0; 721 RayInfoContainer::const_iterator ri, ri_end = tData.mRays->end(); 722 723 for(ri = tData.mRays->begin(); ri < ri_end; ++ ri) 724 box.Include((*ri).ExtrapTermination()); 725 671 726 int axis = 0; 672 float costRatio = MAX_FLOAT; 673 Vector3 position; 674 675 //-- area subdivision 676 for (int i = 0; i < 3; ++ i) 677 { 678 float p = 0; 679 const float r = BestCostRatio(polys, box, i, p, objectsBack, objectsFront); 727 const bool useCostHeuristics = false; 728 729 if (useCostHeuristics) 730 { 731 float position; 732 733 const float ratio = 734 BestCostRatioHeuristics(*tData.mRays, 735 box, 736 tData.mPvs, 737 axis, 738 position); 739 740 Vector3 normal(0,0,0); normal[axis] = 1; 741 plane = Plane3(normal, position); 742 743 return ratio; 744 } 745 746 //-- regular split 747 float nPosition[3]; 748 float nCostRatio[3]; 749 int bestAxis = -1; 750 751 bool mOnlyDrivingAxis = false; 752 753 const int sAxis = box.Size().DrivingAxis(); 680 754 681 if (r < costRatio) 682 { 683 costRatio = r; 684 axis = i; 685 position = p; 686 } 687 } 688 689 if (costRatio >= mTermMaxCostRatio) 690 return false; 691 692 Vector3 norm(0,0,0); norm[axis] = 1.0f; 693 plane = Plane3(norm, position); 694 695 return true; 696 } 755 for (axis = 0; axis < 3; ++ axis) 756 { 757 if (!mOnlyDrivingAxis || axis == sAxis) 758 { 759 if (!useCostHeuristics) 760 { 761 nPosition[axis] = (box.Min()[axis] + box.Max()[axis]) * 0.5f; 762 Vector3 normal(0,0,0); normal[axis] = 1; 763 764 nCostRatio[axis] = SplitPlaneCost(Plane3(normal, nPosition[axis]), tData); 765 } 766 767 if (bestAxis == -1) 768 { 769 bestAxis = axis; 770 } 771 772 else if (nCostRatio[axis] < nCostRatio[bestAxis]) 773 { 774 /*Debug << "pvs front " << nPvsBack[axis] 775 << " pvs back " << nPvsFront[axis] 776 << " overall pvs " << leaf->GetPvsSize() << endl;*/ 777 bestAxis = axis; 778 } 779 780 } 781 } 782 783 //-- assign best axis 784 Vector3 normal(0,0,0); normal[bestAxis] = 1; 785 plane = Plane3(normal, nPosition[bestAxis]); 786 787 return nCostRatio[bestAxis]; 788 } 789 697 790 698 791 bool VspBspTree::SelectPlane(Plane3 &plane, … … 700 793 VspBspTraversalData &data) 701 794 { 702 if ((mSplitPlaneStrategy & AXIS_ALIGNED) &&703 ((int)data.mRays->size() > mTermMinRaysForAxisAligned))704 { // TODO: candidates should be rays705 return SelectAxisAlignedPlane(plane, *data.mPolygons);706 }707 708 795 // simplest strategy: just take next polygon 709 796 if (mSplitPlaneStrategy & RANDOM_POLYGON) … … 740 827 } 741 828 829 742 830 Plane3 VspBspTree::ChooseCandidatePlane(const RayInfoContainer &rays) const 743 831 { … … 752 840 return Plane3(normal, pt); 753 841 } 842 754 843 755 844 Plane3 VspBspTree::ChooseCandidatePlane2(const RayInfoContainer &rays) const … … 822 911 int maxIdx = (int)data.mPolygons->size(); 823 912 913 float candidateCost; 914 824 915 for (int i = 0; i < limit; ++ i) 825 916 { … … 836 927 837 928 // evaluate current candidate 838 const float candidateCost = 839 SplitPlaneCost(poly->GetSupportingPlane(), data); 929 candidateCost = SplitPlaneCost(poly->GetSupportingPlane(), data); 840 930 841 931 if (candidateCost < lowestCost) … … 846 936 } 847 937 938 #if 0 848 939 //-- choose candidate planes extracted from rays 849 940 //-- different methods are available … … 851 942 { 852 943 plane = ChooseCandidatePlane3(*data.mRays); 853 c onst float candidateCost = SplitPlaneCost(plane, data);944 candidateCost = SplitPlaneCost(plane, data); 854 945 855 946 if (candidateCost < lowestCost) … … 858 949 lowestCost = candidateCost; 859 950 } 951 } 952 #endif 953 954 // axis aligned splits 955 candidateCost = SelectAxisAlignedPlane(plane, data); 956 957 if (candidateCost < lowestCost) 958 { 959 bestPlane = plane; 960 lowestCost = candidateCost; 860 961 } 861 962 … … 880 981 881 982 float VspBspTree::SplitPlaneCost(const Plane3 &candidatePlane, 882 const VspBspTraversalData &data) 983 const VspBspTraversalData &data) const 883 984 { 884 985 float cost = 0; … … 1957 2058 int merged = 0; 1958 2059 1959 Debug << "mergecost: " << mergeQueue.top().GetMergeCost() / BspMergeCandidate::sOverallCost << " " << mMergeMaxCostRatio << endl; 1960 Debug << "overall cost: " << BspMergeCandidate::sOverallCost << endl; 1961 1962 // use priority queue to merge leaves 2060 //-- use priority queue to merge leaf pairs 1963 2061 while (!mergeQueue.empty() && (vcSize > mMergeMinViewCells) && 1964 2062 (mergeQueue.top().GetMergeCost() < 1965 2063 mMergeMaxCostRatio * BspMergeCandidate::sOverallCost)) 1966 2064 { 1967 Debug << "mergecost: " << mergeQueue.top().GetMergeCost() / BspMergeCandidate::sOverallCost << " " << mMergeMaxCostRatio << endl;2065 //Debug << "mergecost: " << mergeQueue.top().GetMergeCost() / BspMergeCandidate::sOverallCost << " " << mMergeMaxCostRatio << endl; 1968 2066 BspMergeCandidate mc = mergeQueue.top(); 1969 2067 mergeQueue.pop(); -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
r479 r480 263 263 struct SortableEntry 264 264 { 265 enum {POLY_MIN, POLY_MAX}; 266 265 enum EType 266 { 267 ERayMin, 268 ERayMax 269 }; 270 267 271 int type; 268 272 float value; 269 Polygon3 *poly; 273 void *data; 274 270 275 SortableEntry() {} 271 SortableEntry(const int t, const float v, Polygon3 *poly): 272 type(t), value(v), poly(poly) {} 273 274 bool operator<(const SortableEntry &b) const 276 SortableEntry(const int t, const float v, void *d):type(t), 277 value(v), data(d) 275 278 { 276 return value < b.value; 277 } 279 } 280 281 friend bool operator<(const SortableEntry &a, const SortableEntry &b) 282 { 283 return a.value < b.value; 284 } 278 285 }; 279 286 … … 315 322 */ 316 323 float SplitPlaneCost(const Plane3 &candidatePlane, 317 const VspBspTraversalData &data) ;324 const VspBspTraversalData &data) const; 318 325 319 326 … … 375 382 int AddMeshToPolygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent); 376 383 377 /** Computes best cost ratio for the suface area heuristics for axis aligned 378 splits. This heuristics minimizes the cost for ray traversal. 379 @param polys the polygons guiding the ratio computation 380 @param box the bounding box of the leaf 381 @param axis the current split axis 382 @param position returns the split position 383 @param objectsBack the number of objects in the back of the split plane 384 @param objectsFront the number of objects in the front of the split plane 385 */ 386 float BestCostRatio(const PolygonContainer &polys, 387 const AxisAlignedBox3 &box, 388 const int axis, 389 float &position, 390 int &objectsBack, 391 int &objectsFront) const; 392 384 /** Selects a plane axis aligned. 385 */ 386 float SelectAxisAlignedPlane(Plane3 &plane, 387 const VspBspTraversalData &tData); 388 393 389 /** Sorts split candidates for surface area heuristics for axis aligned splits. 394 390 @param polys the input for choosing split candidates … … 396 392 @param splitCandidates returns sorted list of split candidates 397 393 */ 398 void SortSplitCandidates(const PolygonContainer &polys, 399 const int axis, 400 vector<SortableEntry> &splitCandidates) const; 394 void SortSplitCandidates(const RayInfoContainer &rays, const int axis); 395 396 /** Computes best cost for axis aligned planes. 397 */ 398 float BestCostRatioHeuristics(const RayInfoContainer &rays, 399 const AxisAlignedBox3 &box, 400 const int pvsSize, 401 int &axis, 402 float &position); 401 403 402 404 /** Selects an axis aligned split plane. … … 569 571 int mMergeMinViewCells; 570 572 /// maximal cost ratio for the merge 571 int mMergeMaxCostRatio;573 float mMergeMaxCostRatio; 572 574 573 575 ViewCellsManager *mViewCellsManager; … … 575 577 // if rays should be stored in leaves 576 578 bool mStoreRays; 579 580 vector<SortableEntry> *mSplitCandidates; 577 581 578 582 private: -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
r479 r480 80 80 81 81 VspKdNode::~VspKdNode() 82 {}; 82 { 83 }; 83 84 84 85 inline VspKdInterior *VspKdNode::GetParent() const … … 658 659 int &pvsFront) 659 660 { 660 int minDirDepth = 6;661 661 int axis = 0; 662 662 float costRatio = 0; … … 665 665 { 666 666 costRatio = BestCostRatioRegular(leaf, 667 box, 667 668 axis, 668 669 position, … … 675 676 { 676 677 costRatio = BestCostRatioHeuristic(leaf, 678 box, 677 679 axis, 678 680 position, … … 706 708 707 709 float VspKdTree::EvalCostRatio(VspKdLeaf *leaf, 710 const AxisAlignedBox3 &box, 708 711 const int axis, 709 712 const float position, … … 725 728 int pvsSize = leaf->GetPvsSize(); 726 729 727 Intersectable::NewMail(3);728 729 730 // this is the main ray classification loop! 730 731 for(RayInfoContainer::iterator ri = leaf->mRays.begin(); 731 732 ri != leaf->mRays.end(); ++ ri) 732 { 733 if (!(*ri).mRay->IsActive()) 734 continue; 735 736 // determine the side of this ray with respect to the plane 737 float t; 738 int side = (*ri).ComputeRayIntersection(axis, position, t); 739 // (*ri).mRay->mSide = side; 740 733 { 734 if (!(*ri).mRay->IsActive()) 735 continue; 736 737 // determine the side of this ray with respect to the plane 738 float t; 739 int side = (*ri).ComputeRayIntersection(axis, position, t); 740 741 741 if (side <= 0) 742 742 ++ raysBack; … … 757 757 else 758 758 { 759 AxisAlignedBox3 box = GetBBox(leaf); 760 759 #if 0 761 760 float minBox = box.Min(axis); 762 761 float maxBox = box.Max(axis); 762 763 763 float sizeBox = maxBox - minBox; 764 #else 765 766 float minBox = AxisAlignedBox3(box.Min(), position).SurfaceArea(); 767 float maxBox = AxisAlignedBox3(position, box.Max()).SurfaceArea(); 768 769 float sizeBox = box.SurfaceArea(); 770 #endif 764 771 765 772 // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); … … 777 784 778 785 float VspKdTree::BestCostRatioRegular(VspKdLeaf *leaf, 786 const AxisAlignedBox3 &box, 779 787 int &axis, 780 788 float &position, … … 791 799 int bestAxis = -1; 792 800 793 AxisAlignedBox3 sBox = GetBBox(leaf);794 795 const int sAxis = sBox.Size().DrivingAxis();801 //AxisAlignedBox3 sBox = GetBBox(leaf); 802 803 const int sAxis = box.Size().DrivingAxis(); 796 804 797 805 for (axis = 0; axis < 3; ++ axis) … … 800 808 { 801 809 802 nPosition[axis] = ( sBox.Min()[axis] + sBox.Max()[axis]) * 0.5f;810 nPosition[axis] = (box.Min()[axis] + box.Max()[axis]) * 0.5f; 803 811 804 812 nCostRatio[axis] = EvalCostRatio(leaf, 813 box, 805 814 axis, 806 815 nPosition[axis], … … 838 847 839 848 float VspKdTree::BestCostRatioHeuristic(VspKdLeaf *leaf, 849 const AxisAlignedBox3 &box, 840 850 int &axis, 841 851 float &position, … … 845 855 int &pvsFront) 846 856 { 847 AxisAlignedBox3 box = GetBBox(leaf);857 //AxisAlignedBox3 box = GetBBox(leaf); 848 858 // AxisAlignedBox3 dirBox = GetDirBBox(node); 849 859 … … 1065 1075 if (axis == -1) 1066 1076 { 1077 // cost ratio missed 1067 1078 ++ maxCostMisses; 1068 1069 if (maxCostMisses >= mTermMissTolerance) 1079 if (maxCostMisses > mTermMissTolerance) 1070 1080 return leaf; 1071 1081 } … … 2171 2181 2172 2182 // collapse siblings belonging to the same view cell 2173 CollapseTree(mRoot);2183 //CollapseTree(mRoot); 2174 2184 // revalidate leaves 2175 RepairVcLeafLists();2185 //RepairVcLeafLists(); 2176 2186 2177 2187 //Debug << "merged " << merged << " of " << savedVcSize << " leaves" << endl; -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
r479 r480 629 629 630 630 float BestCostRatioHeuristic(VspKdLeaf *node, 631 const AxisAlignedBox3 &box, 631 632 int &axis, 632 633 float &position, … … 636 637 int &pvsFront); 637 638 638 float BestCostRatioRegular(VspKdLeaf *node, 639 float BestCostRatioRegular(VspKdLeaf *node, 640 const AxisAlignedBox3 &box, 639 641 int &axis, 640 642 float &position, … … 645 647 646 648 float EvalCostRatio(VspKdLeaf *node, 649 const AxisAlignedBox3 &box, 647 650 const int axis, 648 651 const float position,
Note: See TracChangeset
for help on using the changeset viewer.