- Timestamp:
- 12/19/05 18:57:00 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r469 r472 289 289 minRays 500 290 290 minSize 0.1 291 maxCostRatio 999.0 291 maxCostRatio 0.9 292 missTolerance 4 292 293 maxRayContribution 0.2 293 294 } … … 345 346 Termination { 346 347 # parameters used for autopartition 347 minRays 100 348 minPolygons -1 349 maxDepth 30 350 minPvs 100 351 minArea 0.01 352 maxRayContribution 0.005 353 #maxAccRayLength 100 348 minRays 100 349 minPolygons -1 350 maxDepth 30 351 minPvs 100 352 minArea 0.01 353 maxRayContribution 0.005 354 maxCostRatio 0.9 355 missTolerance 4 356 #maxAccRayLength 100 354 357 355 358 # used for pvs criterium -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r469 r472 139 139 return; 140 140 141 numParams = strlen(optParams) + 1;141 numParams = (int)strlen(optParams) + 1; 142 142 optionalParams = new char[numParams]; 143 143 strcpy(optionalParams, optParams); … … 390 390 if (options[i].value != NULL) { 391 391 // option was explicitly specified 392 value = strtod(options[i].value, NULL);392 value = (Real)strtod(options[i].value, NULL); 393 393 } else { 394 394 // option was not read, so use the default 395 value = strtod(options[i].defaultValue, NULL);395 value = (Real)strtod(options[i].defaultValue, NULL); 396 396 } 397 397 return true; … … 1315 1315 "100"); 1316 1316 1317 RegisterOption("BspTree.Termination. AxisAligned.maxCostRatio",1317 RegisterOption("BspTree.Termination.maxCostRatio", 1318 1318 optFloat, 1319 1319 "-bsp_term_axis_aligned_max_cost_ratio=", … … 1512 1512 "false"); 1513 1513 1514 RegisterOption("VspKdTree.Termination.maxCostRatio", 1515 optFloat, 1516 "-vsp_kd_term_max_cost_ratio=", 1517 "1.5"); 1518 1519 RegisterOption("VspKdTree.Termination.missTolerance", 1520 optInt, 1521 "-vsp_kd_term_miss_tolerance=", 1522 "4"); 1514 1523 1515 1524 /************************************************************************************/ … … 1663 1672 "1.5"); 1664 1673 1674 RegisterOption("VspBspTree.Termination.maxCostRatio", 1675 optFloat, 1676 "-vsp_bsp_term_max_cost_ratio=", 1677 "1.5"); 1678 1679 RegisterOption("VspBspTree.Termination.missTolerance", 1680 optInt, 1681 "-vsp_bsp_term_miss_tolerance=", 1682 "4"); 1665 1683 1666 1684 RegisterOption("VspBspTree.Termination.AxisAligned.ct_div_ci", -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r469 r472 195 195 196 196 //-- termination criteria for axis aligned split 197 environment->GetFloatValue("BspTree.Termination.AxisAligned.ct_div_ci", mA aCtDivCi);198 environment->GetFloatValue("BspTree.Termination. AxisAligned.maxCostRatio", mMaxCostRatio);197 environment->GetFloatValue("BspTree.Termination.AxisAligned.ct_div_ci", mAxisAlignedCtDivCi); 198 environment->GetFloatValue("BspTree.Termination.maxCostRatio", mMaxCostRatio); 199 199 environment->GetIntValue("BspTree.Termination.AxisAligned.minPolys", 200 200 mTermMinPolysForAxisAligned); … … 406 406 void BspTree::InsertPolygons(PolygonContainer *polys) 407 407 { 408 std::stack<BspTraversalData>tStack;408 BspTraversalStack tStack; 409 409 410 410 // traverse existing tree or create new tree … … 710 710 void BspTree::Construct(PolygonContainer *polys, BoundedRayContainer *rays) 711 711 { 712 std::stack<BspTraversalData>tStack;712 BspTraversalStack tStack; 713 713 714 714 mRoot = new BspLeaf(); … … 1042 1042 rbox.SetMin(axis, (*ci).value); 1043 1043 1044 float sum = objectsLeft * lbox.SurfaceArea() +1045 1044 const float sum = objectsLeft * lbox.SurfaceArea() + 1045 objectsRight * rbox.SurfaceArea(); 1046 1046 1047 1047 if (sum < minSum) … … 1056 1056 } 1057 1057 1058 float oldCost = (float)polys.size();1059 float newCost = mAaCtDivCi + minSum / boxArea;1060 float ratio = newCost / oldCost;1058 const float oldCost = (float)polys.size(); 1059 const float newCost = mAxisAlignedCtDivCi + minSum / boxArea; 1060 const float ratio = newCost / oldCost; 1061 1061 1062 1062 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r469 r472 346 346 347 347 typedef std::stack<BspTraversalData> BspTraversalStack; 348 //typedef std::priority_queue<BspTraversalData> BspTraversalStack; 348 349 349 350 /** Default constructor creating an empty tree. … … 353 354 ~BspTree(); 354 355 355 356 /** Returns detailed statistics of the BSP tree. 357 */ 356 358 const BspTreeStatistics &GetStatistics() const; 357 359 … … 797 799 798 800 /// axis aligned split criteria 799 float mA aCtDivCi;801 float mAxisAlignedCtDivCi; 800 802 float mSplitBorder; 801 803 float mMaxCostRatio; -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r469 r472 37 37 VspBspTree::VspBspTree(): 38 38 mRoot(NULL), 39 mPvsUseArea(true) 39 mPvsUseArea(true), 40 mNumCriteria(0) 40 41 { 41 42 mRootCell = new BspViewCell(); … … 50 51 environment->GetFloatValue("VspBspTree.Termination.maxRayContribution", mTermMaxRayContribution); 51 52 environment->GetFloatValue("VspBspTree.Termination.minAccRayLenght", mTermMinAccRayLength); 53 environment->GetFloatValue("VspBspTree.Termination.maxCostRatio", mTermMaxCostRatio); 54 environment->GetIntValue("VspBspTree.Termination.missTolerance", mTermMissTolerance); 52 55 53 56 //-- factors for bsp tree split plane heuristics … … 57 60 58 61 //-- termination criteria for axis aligned split 59 environment->GetFloatValue("VspBspTree.Termination.AxisAligned.ct_div_ci", mA aCtDivCi);60 environment->GetFloatValue("VspBspTree.Termination. AxisAligned.maxCostRatio",mMaxCostRatio);62 environment->GetFloatValue("VspBspTree.Termination.AxisAligned.ct_div_ci", mAxisAlignedCtDivCi); 63 environment->GetFloatValue("VspBspTree.Termination.maxCostRatio", mTermMaxCostRatio); 61 64 62 65 environment->GetIntValue("VspBspTree.Termination.AxisAligned.minRays", … … 67 70 environment->GetIntValue("VspBspTree.maxRayCandidates", mMaxRayCandidates); 68 71 environment->GetIntValue("VspBspTree.splitPlaneStrategy", mSplitPlaneStrategy); 69 environment->GetFloatValue("VspBspTree.AxisAligned.splitBorder", m SplitBorder);72 environment->GetFloatValue("VspBspTree.AxisAligned.splitBorder", mAxisAlignedSplitBorder); 70 73 71 74 environment->GetFloatValue("VspBspTree.Construction.epsilon", mEpsilon); … … 82 85 if (mSplitPlaneStrategy & RANDOM_POLYGON) 83 86 Debug << "random polygon "; 87 84 88 if (mSplitPlaneStrategy & AXIS_ALIGNED) 89 { 90 ++ mNumCriteria; 85 91 Debug << "axis aligned "; 92 } 86 93 if (mSplitPlaneStrategy & LEAST_RAY_SPLITS) 94 { 95 ++ mNumCriteria; 87 96 Debug << "least ray splits "; 97 } 88 98 if (mSplitPlaneStrategy & BALANCED_RAYS) 99 { 100 ++ mNumCriteria; 89 101 Debug << "balanced rays "; 102 } 90 103 if (mSplitPlaneStrategy & PVS) 104 { 105 ++ mNumCriteria; 91 106 Debug << "pvs"; 107 } 92 108 93 109 Debug << endl; … … 261 277 void VspBspTree::Construct(const PolygonContainer &polys, RayInfoContainer *rays) 262 278 { 263 std::stack<VspBspTraversalData>tStack;279 VspBspTraversalStack tStack; 264 280 265 281 mRoot = new BspLeaf(); … … 338 354 EvaluateLeafStats(tData); 339 355 340 //-- clean up 341 356 //-- clean up 342 357 DEL_PTR(tData.mPolygons); 343 358 DEL_PTR(tData.mRays); … … 361 376 362 377 // create new interior node and two leaf nodes 363 BspInterior *interior = 364 SubdivideNode(tData, tFrontData, tBackData, coincident); 365 378 BspNode *newNode = SubdivideNode(tData, tFrontData, tBackData, coincident); 379 380 // subdivide further 381 if (!newNode->IsLeaf()) 382 { 383 BspInterior *interior = dynamic_cast<BspInterior *>(newNode); 384 366 385 #ifdef _DEBUG 367 386 // if (frontPolys->empty() && backPolys->empty() && (coincident.size() > 2)) … … 371 390 #endif 372 391 373 // push the children on the stack 374 tStack.push(tFrontData); 375 tStack.push(tBackData); 392 // push the children on the stack 393 tStack.push(tFrontData); 394 tStack.push(tBackData); 395 396 // delete old leaf node 397 DEL_PTR(tData.mNode); 398 } 376 399 377 400 // cleanup 378 DEL_PTR(tData.mNode);379 380 401 DEL_PTR(tData.mPolygons); 381 402 DEL_PTR(tData.mRays); 382 403 DEL_PTR(tData.mGeometry); 383 404 384 return interior;385 } 386 387 Bsp Interior*VspBspTree::SubdivideNode(VspBspTraversalData &tData,388 389 390 405 return newNode; 406 } 407 408 BspNode *VspBspTree::SubdivideNode(VspBspTraversalData &tData, 409 VspBspTraversalData &frontData, 410 VspBspTraversalData &backData, 411 PolygonContainer &coincident) 391 412 { 392 413 mStat.nodes += 2; … … 394 415 BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode); 395 416 417 int maxCostMisses = tData.mMaxCostMisses; 418 396 419 // select subdivision plane 397 BspInterior *interior = new BspInterior(SelectPlane(leaf, tData)); 420 Plane3 splitPlane; 421 if (!SelectPlane(splitPlane, leaf, tData)) 422 { 423 ++ maxCostMisses; 424 425 if (maxCostMisses >= mTermMissTolerance) 426 return leaf; 427 } 428 429 // subdivide further 430 BspInterior *interior = new BspInterior(splitPlane); 398 431 399 432 #ifdef _DEBUG … … 414 447 coincident); 415 448 416 // compute pvs 449 450 //-- set left and right traversal data 451 frontData.mMaxCostMisses = maxCostMisses; 452 backData.mMaxCostMisses = maxCostMisses; 453 454 // compute pvs 417 455 frontData.mPvs = ComputePvsSize(*frontData.mRays); 418 456 backData.mPvs = ComputePvsSize(*backData.mRays); … … 426 464 mBox, 427 465 mEpsilon); 428 429 430 frontData.mArea = frontData.mGeometry->GetArea() ;431 backData.mArea = backData.mGeometry->GetArea() ;466 467 // area is normalized with view space area 468 frontData.mArea = frontData.mGeometry->GetArea() / mBox.SurfaceArea(); 469 backData.mArea = backData.mGeometry->GetArea() / mBox.SurfaceArea(); 432 470 } 433 471 … … 543 581 float boxArea = box.SurfaceArea(); 544 582 545 float minBand = minBox + m SplitBorder * (maxBox - minBox);546 float maxBand = minBox + (1.0f - m SplitBorder) * (maxBox - minBox);583 float minBand = minBox + mAxisAlignedSplitBorder * (maxBox - minBox); 584 float maxBand = minBox + (1.0f - mAxisAlignedSplitBorder) * (maxBox - minBox); 547 585 548 586 float minSum = 1e20f; … … 584 622 } 585 623 586 float oldCost = (float)polys.size();587 float newCost = mAaCtDivCi + minSum / boxArea;588 float ratio = newCost / oldCost;624 const float oldCost = (float)polys.size(); 625 const float newCost = mAxisAlignedCtDivCi + minSum / boxArea; 626 const float ratio = newCost / oldCost; 589 627 590 628 … … 615 653 { 616 654 float p = 0; 617 float r = BestCostRatio(polys, box, i, p, objectsBack, objectsFront);655 const float r = BestCostRatio(polys, box, i, p, objectsBack, objectsFront); 618 656 619 657 if (r < costRatio) … … 625 663 } 626 664 627 if (costRatio >= m MaxCostRatio)665 if (costRatio >= mTermMaxCostRatio) 628 666 return false; 629 667 … … 634 672 } 635 673 636 Plane3 VspBspTree::SelectPlane(BspLeaf *leaf, VspBspTraversalData &data) 674 bool VspBspTree::SelectPlane(Plane3 &plane, 675 BspLeaf *leaf, 676 VspBspTraversalData &data) 637 677 { 638 678 if ((mSplitPlaneStrategy & AXIS_ALIGNED) && 639 679 ((int)data.mRays->size() > mTermMinRaysForAxisAligned)) 640 { 641 Plane3 plane; 642 if (SelectAxisAlignedPlane(plane, *data.mPolygons)) // TODO: should be rays 643 return plane; 680 { // TODO: candidates should be rays 681 return SelectAxisAlignedPlane(plane, *data.mPolygons); 644 682 } 645 683 … … 651 689 const int randIdx = Random((int)data.mPolygons->size()); 652 690 Polygon3 *nextPoly = (*data.mPolygons)[randIdx]; 653 return nextPoly->GetSupportingPlane(); 691 692 plane = nextPoly->GetSupportingPlane(); 693 return true; 654 694 } 655 695 else … … 665 705 const Vector3 normal = (*data.mRays)[candidateIdx].mRay->GetDir(); 666 706 667 return Plane3(normal, pt); 668 } 669 670 return Plane3(); 707 plane = Plane3(normal, pt); 708 return true; 709 } 710 711 return false; 671 712 } 672 713 673 714 // use heuristics to find appropriate plane 674 return SelectPlaneHeuristics(leaf, data); 675 } 676 677 Plane3 VspBspTree::SelectPlaneHeuristics(BspLeaf *leaf, VspBspTraversalData &data) 715 return SelectPlaneHeuristics(plane, leaf, data); 716 } 717 718 bool VspBspTree::SelectPlaneHeuristics(Plane3 &bestPlane, 719 BspLeaf *leaf, 720 VspBspTraversalData &data) 678 721 { 679 722 float lowestCost = MAX_FLOAT; 680 Plane3 bestPlane;723 // intermediate plane 681 724 Plane3 plane; 682 725 683 int limit = Min((int)data.mPolygons->size(), mMaxPolyCandidates); 684 726 const int limit = Min((int)data.mPolygons->size(), mMaxPolyCandidates); 685 727 int candidateIdx = limit; 686 728 … … 774 816 } 775 817 818 // cost ratio miss 819 if (lowestCost > mTermMaxCostRatio) 820 return false; 821 776 822 #ifdef _DEBUG 777 823 Debug << "plane lowest cost: " << lowestCost << endl; 778 824 #endif 779 return bestPlane; 825 826 return true; 780 827 } 781 828 … … 802 849 const VspBspTraversalData &data) 803 850 { 804 float val= 0;851 float cost = 0; 805 852 806 853 float sumBalancedRays = 0; … … 933 980 934 981 const float raysSize = (float)data.mRays->size() + Limits::Small; 935 982 936 983 if (mSplitPlaneStrategy & LEAST_RAY_SPLITS) 937 val+= mLeastRaySplitsFactor * sumRaySplits / raysSize;984 cost += mLeastRaySplitsFactor * sumRaySplits / raysSize; 938 985 939 986 if (mSplitPlaneStrategy & BALANCED_RAYS) 940 val += mBalancedRaysFactor * fabs(sumBalancedRays) / raysSize; 941 942 const float denom = pOverall * (float)data.mPvs * 2.0f + Limits::Small; 943 987 cost += mBalancedRaysFactor * fabs(sumBalancedRays) / raysSize; 988 989 // pvs criterium 944 990 if (mSplitPlaneStrategy & PVS) 945 991 { 946 val += mPvsFactor * (frontPvs * pFront + (backPvs * pBack)) / denom; 992 const float oldCost = pOverall * (float)data.mPvs + Limits::Small; 993 994 cost += mPvsFactor * (frontPvs * pFront + (backPvs * pBack)) / oldCost; 947 995 948 996 // give penalty to unbalanced split … … 950 998 if (((pFront * 0.2 + Limits::Small) > pBack) || 951 999 (pFront < (pBack * 0.2 + Limits::Small))) 952 val+= 0.5;1000 cost += 0.5; 953 1001 } 954 1002 … … 958 1006 // << " backpvs: " << backPvs << " pBack: " << pBack << endl << endl; 959 1007 #endif 960 return val; 1008 1009 // normalize by number of criteria 1010 return cost / (float)(mNumCriteria + Limits::Small); 961 1011 } 962 1012 -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
r469 r472 10 10 #include "RayInfo.h" 11 11 #include "ViewCellBsp.h" 12 #include "ViewCell.h"13 12 14 13 class ViewCell; … … 51 50 /// current depth 52 51 int mDepth; 53 54 52 /// rays piercing this node 55 53 RayInfoContainer *mRays; … … 58 56 /// geometry of node as induced by planes 59 57 BspNodeGeometry *mGeometry; 60 61 58 /// pvs size 62 59 int mPvs; 63 60 /// how often this branch has missed the max-cost ratio 61 int mMaxCostMisses; 64 62 /** Returns average ray contribution. 65 63 */ … … 77 75 mPvs(0), 78 76 mArea(0.0), 79 mGeometry(NULL) 77 mGeometry(NULL), 78 mMaxCostMisses(0) 80 79 {} 81 80 … … 93 92 mPvs(pvs), 94 93 mArea(area), 95 mGeometry(geom) 94 mGeometry(geom), 95 mMaxCostMisses(0) 96 96 {} 97 97 … … 106 106 mPvs(0), 107 107 mArea(0), 108 mGeometry(geom) 108 mGeometry(geom), 109 mMaxCostMisses(0) 109 110 {} 111 112 friend bool operator<(const VspBspTraversalData &a, const VspBspTraversalData &b) 113 { 114 #if 0 115 return a.mPvs * a.mArea < b.mPvs * b.mArea; 116 #endif 117 #if 1 118 return a.mPvs * (int)a.mRays->size() < b.mPvs * (int)b.mRays->size(); 119 #endif 120 #if 0 121 return a.mPvs < b.mPvs; 122 #endif 123 #if 0 124 return 125 a.mPvs / (float)(a.mRays->size() + Limits::Small()) 126 > 127 b.mPvs / (float)(b.mRays->size() + Limits::Small()); 128 #endif 129 #if 0 130 return a.mPvs * (int)a.mRays->size() < b.mPvs * (int)b.mRays->size(); 131 #endif 132 } 110 133 }; 111 134 112 typedef std::stack<VspBspTraversalData> VspBspTraversalStack; 135 typedef std::priority_queue<VspBspTraversalData> VspBspTraversalStack; 136 //typedef std::stack<VspBspTraversalData> VspBspTraversalStack; 113 137 114 138 /** Default constructor creating an empty tree. … … 257 281 258 282 /** Selects the best possible splitting plane. 283 @param plane returns the split plane 259 284 @param leaf the leaf to be split 260 285 @param polys the polygon list on which the split decition is based 261 286 @param rays ray container on which selection may be based 262 287 @note the polygons can be reordered in the process 263 @returns the split plane 264 */ 265 Plane3 SelectPlane(BspLeaf *leaf, 266 VspBspTraversalData &data); 267 288 @returns true if the cost of the split is under maxCostRatio 289 290 */ 291 bool SelectPlane(Plane3 &plane, 292 BspLeaf *leaf, 293 VspBspTraversalData &data); 268 294 269 295 /** Strategies where the effect of the split plane is tested … … 274 300 float SplitPlaneCost(const Plane3 &candidatePlane, 275 301 const VspBspTraversalData &data); 276 277 302 278 303 … … 291 316 */ 292 317 293 Bsp Interior*SubdivideNode(VspBspTraversalData &tData,294 295 296 318 BspNode *SubdivideNode(VspBspTraversalData &tData, 319 VspBspTraversalData &frontData, 320 VspBspTraversalData &backData, 321 PolygonContainer &coincident); 297 322 298 323 /** Selects the split plane in order to construct a tree with 299 324 certain characteristics (e.g., balanced tree, least splits, 300 325 2.5d aligned) 326 @param bestPlane returns the split plane 301 327 @param polygons container of polygons 302 328 @param rays bundle of rays on which the split can be based 303 */ 304 Plane3 SelectPlaneHeuristics(BspLeaf *leaf, 305 VspBspTraversalData &data); 329 330 @returns true if the overall cost is under maxCostRatio 331 */ 332 bool SelectPlaneHeuristics(Plane3 &bestPlane, 333 BspLeaf *leaf, 334 VspBspTraversalData &data); 306 335 307 336 /** Extracts the meshes of the objects and adds them to polygons. … … 476 505 float mTermMinAccRayLength; 477 506 478 479 507 /// strategy to get the best split plane 480 508 int mSplitPlaneStrategy; … … 487 515 488 516 //-- axis aligned split criteria 489 float mAaCtDivCi; 490 float mSplitBorder; 491 float mMaxCostRatio; 517 float mAxisAlignedCtDivCi; 518 /// spezifies the split border of the axis aligned split 519 float mAxisAlignedSplitBorder; 520 521 /// maximal acceptable cost ratio 522 float mTermMaxCostRatio; 523 /// tolerance value indicating how often the max cost ratio can be failed 524 int mTermMissTolerance; 492 525 493 526 //-- factors guiding the split plane heuristics … … 498 531 /// if area or accumulated ray lenght should be used for PVS heuristics 499 532 bool mPvsUseArea; 500 533 /// tolerance for polygon split 501 534 float mEpsilon; 502 535 /// maximal number of test rays used to evaluate candidate split plane 503 536 int mMaxTests; 537 /// number of different bsp split plane criteria 538 int mNumCriteria; 504 539 505 540 private: -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
r471 r472 31 31 int VspKdLeaf::sMailId = 0; 32 32 int MergeCandidate::sMaxPvsSize = 150; 33 34 33 float MergeCandidate::sOverallCost = Limits::Small; 35 34 #define USE_FIXEDPOINT_T 0 36 35 … … 184 183 185 184 186 VspKdLeaf::VspKdLeaf(VspKdInterior *p, const int nRays): 187 VspKdNode(p), mRays(), mPvsSize(0), mValidPvs(false), mViewCell(NULL) 185 VspKdLeaf::VspKdLeaf(VspKdInterior *p, 186 const int nRays, 187 const int maxCostMisses): 188 VspKdNode(p), mRays(), mPvsSize(0), mValidPvs(false), mViewCell(NULL), 189 mMaxCostMisses(maxCostMisses) 188 190 { 189 191 mRays.reserve(nRays); … … 193 195 { 194 196 } 197 198 199 int VspKdLeaf::GetMaxCostMisses() 200 { 201 return mMaxCostMisses; 202 } 203 195 204 196 205 int VspKdLeaf::Type() const … … 343 352 environment->GetFloatValue("VspKdTree.Termination.minSize", mTermMinSize); 344 353 354 environment->GetIntValue("VspKdTree.Termination.missTolerance", mTermMissTolerance); 355 345 356 mTermMinSize = sqr(mTermMinSize); 346 357 … … 356 367 //environment->GetIntValue("ViewCells.maxViewCells", mMaxViewCells); 357 368 358 environment->GetIntValue("VspKdTree.PostProcess.minViewCells", mM inViewCells);359 environment->GetFloatValue("VspKdTree.PostProcess.maxCostRatio", mM axCostRatio);369 environment->GetIntValue("VspKdTree.PostProcess.minViewCells", mMergeMinViewCells); 370 environment->GetFloatValue("VspKdTree.PostProcess.maxCostRatio", mMergeMaxCostRatio); 360 371 environment->GetIntValue("VspKdTree.PostProcess.maxPvsSize", 361 372 MergeCandidate::sMaxPvsSize); … … 615 626 tStack.pop(); 616 627 617 VspKdNode *node = SubdivideNode( (VspKdLeaf *) data.mNode,618 628 VspKdNode *node = SubdivideNode(dynamic_cast<VspKdLeaf *>(data.mNode), 629 data.mBox, backBox, frontBox); 619 630 if (result == NULL) 620 631 result = node; … … 663 674 else if (splitType == ESplitHeuristic) 664 675 { 665 666 667 668 669 670 671 676 costRatio = BestCostRatioHeuristic(leaf, 677 axis, 678 position, 679 raysBack, 680 raysFront, 681 pvsBack, 682 pvsFront); 672 683 } 673 684 else … … 1022 1033 1023 1034 VspKdNode *VspKdTree::SubdivideNode(VspKdLeaf *leaf, 1024 1025 1026 1035 const AxisAlignedBox3 &box, 1036 AxisAlignedBox3 &backBBox, 1037 AxisAlignedBox3 &frontBBox) 1027 1038 { 1028 1039 if (TerminationCriteriaMet(leaf, box)) … … 1050 1061 //Debug << "rays back=" << raysBack << " rays front=" << raysFront << " pvs back=" << pvsBack << " pvs front=" << pvsFront << endl; 1051 1062 1063 int maxCostMisses = leaf->GetMaxCostMisses(); 1064 1052 1065 if (axis == -1) 1053 1066 { 1054 return leaf; 1067 ++ maxCostMisses; 1068 1069 if (maxCostMisses >= mTermMissTolerance) 1070 return leaf; 1055 1071 } 1056 1072 … … 1068 1084 frontBBox = box; 1069 1085 1070 VspKdLeaf *back = new VspKdLeaf(node, raysBack );1086 VspKdLeaf *back = new VspKdLeaf(node, raysBack, maxCostMisses); 1071 1087 back->SetPvsSize(pvsBack); 1072 VspKdLeaf *front = new VspKdLeaf(node, raysFront );1088 VspKdLeaf *front = new VspKdLeaf(node, raysFront, maxCostMisses); 1073 1089 front->SetPvsSize(pvsFront); 1074 1090 … … 1488 1504 else 1489 1505 { 1490 tstack.push( ((VspKdInterior *)node)->GetFront());1491 tstack.push( ((VspKdInterior *)node)->GetBack());1506 tstack.push(dynamic_cast<VspKdInterior *>(node)->GetFront()); 1507 tstack.push(dynamic_cast<VspKdInterior *>(node)->GetBack()); 1492 1508 } 1493 1509 } … … 1499 1515 1500 1516 if (newLeaf->mParent) 1517 { 1501 1518 newLeaf->mParent->ReplaceChildLink(sroot, newLeaf); 1502 1519 } 1503 1520 tstack.push(sroot); 1504 1521 … … 2078 2095 bool VspKdTree::MergeViewCells(VspKdLeaf *l1, VspKdLeaf *l2) 2079 2096 { 2080 //-- change pointer to view cells of all leaves associated with the previous view cells 2097 //-- change pointer to view cells of all leaves associated 2098 //-- with the previous view cells 2081 2099 VspKdViewCell *fVc = l1->GetViewCell(); 2082 2100 VspKdViewCell *bVc = l2->GetViewCell(); … … 2156 2174 2157 2175 for (nit = neighbors.begin(); nit != nit_end; ++ nit) 2158 mergeQueue.push(MergeCandidate(leaf, *nit)); 2176 { 2177 MergeCandidate mc = MergeCandidate(leaf, *nit); 2178 mergeQueue.push(mc); 2179 2180 MergeCandidate::sOverallCost += mc.GetLeaf1Cost(); 2181 MergeCandidate::sOverallCost += mc.GetLeaf2Cost(); 2182 } 2159 2183 } 2160 2184 } … … 2166 2190 // use priority queue to merge leaves 2167 2191 while (!mergeQueue.empty() && 2168 (vcSize > mMinViewCells))// && 2169 //(mergeQueue.top().GetMergeCost() < mMaxCostRatio)) 2192 (vcSize > mMergeMinViewCells) && 2193 (mergeQueue.top().GetMergeCost() < 2194 mMergeMaxCostRatio / MergeCandidate::sOverallCost)) 2170 2195 { 2171 2196 //Debug << mergeQueue.top().GetMergeCost() << " " << mMaxCostRatio << endl; … … 2184 2209 ++ merged; 2185 2210 -- vcSize; 2211 // increase absolute merge cost 2212 MergeCandidate::sOverallCost += mc.GetMergeCost(); 2186 2213 } 2187 2214 // merge candidate not valid, because one of the leaves was already … … 2230 2257 if (!viewCell->Mailed()) 2231 2258 { 2232 Debug << "jhere2" << endl;2233 2259 viewCell->mLeaves.clear(); 2234 2260 viewCell->Mail(); … … 2252 2278 return node; 2253 2279 2254 Debug << "here554444" << endl;2255 2280 VspKdInterior *interior = dynamic_cast<VspKdInterior *>(node); 2256 2281 … … 2300 2325 } 2301 2326 2327 float MergeCandidate::GetLeaf1Cost() const 2328 { 2329 VspKdViewCell *vc = mLeaf1->GetViewCell(); 2330 return vc->GetPvs().GetSize() * vc->GetVolume(); 2331 } 2332 2333 float MergeCandidate::GetLeaf2Cost() const 2334 { 2335 VspKdViewCell *vc = mLeaf2->GetViewCell(); 2336 return vc->GetPvs().GetSize() * vc->GetVolume(); 2337 } 2302 2338 2303 2339 void MergeCandidate::EvalMergeCost() … … 2313 2349 //-- (added size of left and right view cell times pvs size) 2314 2350 //-- to new rendering cost (size of merged view cell times pvs size) 2315 const float oldCost = 2316 (float)vc1->GetPvs().GetSize() * vc1->GetVolume() + 2317 (float)vc2->GetPvs().GetSize() * vc2->GetVolume(); 2318 2351 const float oldCost = GetLeaf1Cost() + GetLeaf2Cost(); 2352 2319 2353 const float newCost = 2320 2354 (float)vcPvs * (vc1->GetVolume() + vc2->GetVolume()); -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
r469 r472 76 76 float GetMergeCost() const; 77 77 78 /** Returns cost of leaf 1. 79 */ 80 float GetLeaf1Cost() const; 81 /** Returns cost of leaf 2. 82 */ 83 float GetLeaf2Cost() const; 84 78 85 /// maximal pvs size 79 86 static int sMaxPvsSize; 87 /// overall cost used to normalize cost ratio 88 static float sOverallCost; 80 89 81 90 protected: … … 305 314 @param p the parent node 306 315 @param nRays preallocates memory to store this number of rays 307 */ 308 VspKdLeaf(VspKdInterior *p, const int nRays); 316 @parma maxMisses how many times the max cost ratio was missed on the path to the leaf 317 */ 318 VspKdLeaf(VspKdInterior *p, const int nRays, const int maxCostMisses = 0); 309 319 310 320 virtual ~VspKdLeaf(); … … 365 375 VspKdViewCell *GetViewCell(); 366 376 377 /** Returns number of times the max cost ratio was missed until 378 this leaf. 379 */ 380 int GetMaxCostMisses(); 381 382 367 383 //////////////////////////////////////////// 368 384 … … 371 387 static int sMailId; 372 388 373 389 374 390 protected: 375 391 … … 381 397 int mMailbox; 382 398 399 /// rays intersecting this leaf. 383 400 RayInfoContainer mRays; 384 385 401 /// true if mPvsSize is valid => PVS does not have to be updated 386 402 bool mValidPvs; 387 388 403 /// the view cell associated with this leaf 389 404 VspKdViewCell *mViewCell; 405 /// number of times the max cost ratio was missed on the way to the leaf. 406 int mMaxCostMisses; 390 407 391 408 private: … … 453 470 // TraversalData(const TraversalData &s):node(s.node), bbox(s.bbox), depth(s.depth) {} 454 471 455 472 friend bool operator<(const TraversalData &a, const TraversalData &b) 456 473 { 457 474 // return a.node->queries.size() < b.node->queries.size(); … … 743 760 ViewCellsManager *mViewCellsManager; 744 761 745 /// maximal cost ratio of a merge746 float mMaxCostRatio;747 748 762 ///////////////////////////// 749 763 // Construction parameters … … 751 765 /// max depth of the tree 752 766 int mTermMaxDepth; 753 754 767 /// minimal ratio of the volume of the cell and the query volume 755 768 float mTermMinSize; 756 757 769 /// minimal pvs per node to still get subdivided 758 770 int mTermMinPvs; 759 760 771 /// minimal ray number per node to still get subdivided 761 772 int mTermMinRays; 762 763 /// maximal cost ration to subdivide a node 773 /// maximal acceptable cost ratio to continue subdivision 764 774 float mTermMaxCostRatio; 765 766 775 /// maximal contribution per ray to subdivide the node 767 776 float mTermMaxRayContribution; 777 /// tolerance value indicating how often the max cost ratio can be failed 778 int mTermMissTolerance; 779 780 /// maximal numbers of view cells 781 int mMaxViewCells; 782 783 /// maximal cost ratio of a merge 784 float mMergeMaxCostRatio; 785 786 /// minimal number of view cells 787 int mMergeMinViewCells; 768 788 769 789 /// if only the "driving axis", i.e., the axis with the biggest extent … … 771 791 bool mOnlyDrivingAxis; 772 792 773 /// maximal numbers of view cells774 int mMaxViewCells;775 776 /// minimal number of view cells777 int mMinViewCells;778 779 793 ///////////////////////////// 780 794 VspKdStatistics mStat;
Note: See TracChangeset
for help on using the changeset viewer.