Changeset 1121 for GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
- Timestamp:
- 07/12/06 00:52:51 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
r1111 r1121 22 22 23 23 #define USE_FIXEDPOINT_T 0 24 #define COUNT_OBJECTS 124 #define COUNT_OBJECTS 0 25 25 26 26 //-- static members … … 50 50 void VspTreeStatistics::Print(ostream &app) const 51 51 { 52 app << "===== VspTree statistics ===============\n";52 app << "=========== VspTree statistics ===============\n"; 53 53 54 54 app << setprecision(4); … … 99 99 //app << "#N_PVS: " << pvs << endl; 100 100 101 app << "===== END OF VspTree statistics ==========\n";101 app << "========== END OF VspTree statistics ==========\n"; 102 102 } 103 103 … … 352 352 //-- partition criteria 353 353 Environment::GetSingleton()->GetFloatValue("VspTree.Construction.epsilon", mEpsilon); 354 Environment::GetSingleton()->GetFloatValue("VspTree.Construction.renderCostDecreaseWeight", mRenderCostDecreaseWeight); 354 355 355 356 // if only the driving axis is used for axis aligned split … … 392 393 Debug << "use cost heuristics: " << mUseCostHeuristics << endl; 393 394 Debug << "subdivision stats log: " << subdivisionStatsLog << endl; 394 395 Debug << "render cost decrease weight: " << mRenderCostDecreaseWeight << endl; 396 395 397 Debug << "circulating axis: " << mCirculatingAxis << endl; 396 398 Debug << "minband: " << mMinBand << endl; … … 598 600 tBackData.mMaxCostMisses = maxCostMisses; 599 601 600 602 601 603 if (1) 602 604 { … … 620 622 } 621 623 622 624 623 625 //-- evaluate new split candidates for global greedy cost heuristics 624 626 VspSplitCandidate *frontCandidate = new VspSplitCandidate(tFrontData); … … 630 632 tQueue.Push(frontCandidate); 631 633 tQueue.Push(backCandidate); 632 634 635 // delete old view cell 636 delete tData.mNode->GetViewCell(); 633 637 // delete old leaf node 634 638 DEL_PTR(tData.mNode); … … 747 751 parent->ReplaceChildLink(leaf, interior); 748 752 interior->SetParent(parent); 753 754 // remove "parent" view cell from pvs of all objects (traverse trough rays) 755 RemoveParentViewCellReferences(tData.mNode->GetViewCell()); 749 756 } 750 757 else // new root … … 770 777 CreateViewCell(backData); 771 778 772 // TODO:779 773 780 // create front and back view cell 774 // remove "parent" view cell from pvs of all objects (traverse trough rays)775 781 // add front and back view cell to "Potentially Visbilie View Cells" 776 782 // of the objects in front and back pvs 777 RemoveParentViewCellReferences(tData.mNode->GetViewCell());778 783 AddViewCellReferences(frontLeaf->GetViewCell()); 779 784 AddViewCellReferences(backLeaf->GetViewCell()); 780 781 785 782 786 interior->mTimeStamp = mTimeStamp ++; … … 1144 1148 void VspTree::AddContriToPvs(KdLeaf *leaf, int &pvs) const 1145 1149 { 1146 if ( !leaf->Mailed())1147 {1148 leaf->Mail();1149 1150 // add objects without those which are part of several kd leaves 1151 pvs += ((int)leaf->mObjects.size() - (int)leaf->mMultipleObjects.size());1152 1153 //-- handle objects of several kd leaves separately 1154 ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end();1155 1156 for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 1157 {1158 Intersectable *object = *oit;1159 1160 // object not previously in left pvs 1161 if (!object->Mailed())1162 {1163 object->Mail();1164 ++ pvs;1165 }1150 if (leaf->Mailed()) 1151 return; 1152 1153 leaf->Mail(); 1154 1155 // add objects without those which are part of several kd leaves 1156 pvs += ((int)leaf->mObjects.size() - (int)leaf->mMultipleObjects.size()); 1157 1158 //-- handle objects of several kd leaves separately 1159 ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 1160 1161 for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 1162 { 1163 Intersectable *object = *oit; 1164 1165 // object not previously in left pvs 1166 if (!object->Mailed()) 1167 { 1168 object->Mail(); 1169 ++ pvs; 1166 1170 } 1167 1171 } … … 1513 1517 // take render cost of node into account 1514 1518 // otherwise danger of being stuck in a local minimum!! 1515 const float factor = 0.99f;1519 const float factor = mRenderCostDecreaseWeight; 1516 1520 1517 1521 const float normalizedOldRenderCost = oldRenderCost / mBoundingBox.GetVolume(); … … 2554 2558 2555 2559 2556 2557 2558 2560 int VspTree::ComputeBoxIntersections(const AxisAlignedBox3 &box, 2559 2561 ViewCellContainer &viewCells) const … … 2606 2608 2607 2609 2610 2611 void VspTree::CollectDirtyCandidates(VspSplitCandidate *sc, 2612 vector<SplitCandidate *> &dirtyList) 2613 { 2614 VspLeaf *node = sc->mParentData.mNode; 2615 2616 ViewCellLeaf *vc = node->GetViewCell(); 2617 2618 ObjectPvsMap::const_iterator oit, oit_end = vc->GetPvs().mEntries.end(); 2619 2620 KdLeaf::NewMail(); 2621 2622 for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 2623 { 2624 Intersectable *obj = (*oit).first; 2625 2626 set<KdLeaf *>::const_iterator kit, kit_end = obj->mKdLeaves.end(); 2627 2628 for (kit = obj->mKdLeaves.begin(); kit != kit_end; ++ kit) 2629 { 2630 KdLeaf *leaf = *kit; 2631 2632 if (!leaf->Mailed()) 2633 { 2634 leaf->Mail(); 2635 dirtyList.push_back(leaf->mSplitCandidate); 2636 } 2637 } 2638 } 2639 } 2640 2641 2608 2642 /*****************************************************************/ 2609 2643 /* class OspTree implementation */ … … 2655 2689 2656 2690 Environment::GetSingleton()->GetFloatValue("OspTree.Construction.splitBorder", mSplitBorder); 2657 //mSplitBorder = 0.1f; 2658 2659 2691 Environment::GetSingleton()->GetFloatValue("OspTree.Construction.renderCostDecreaseWeight", mRenderCostDecreaseWeight); 2692 2660 2693 //-- debug output 2661 2694 … … 2679 2712 2680 2713 Debug << "split borders: " << mSplitBorder << endl; 2714 Debug << "render cost decrease weight: " << mRenderCostDecreaseWeight << endl; 2681 2715 2682 2716 … … 2761 2795 const AxisAlignedBox3 box = (*mi)->GetBox(); 2762 2796 2763 if (box.Max(axis) > position )2797 if (box.Max(axis) > position + mEpsilon) 2764 2798 ++ objectsFront; 2765 2799 2766 if (box.Min(axis) < position )2800 if (box.Min(axis) < position - mEpsilon) 2767 2801 ++ objectsBack; 2768 2802 } … … 2843 2877 // delete old leaf node 2844 2878 DEL_PTR(tData.mNode); 2845 DEL_PTR(tData.mNode->mViewCell);2846 2879 } 2847 2880 … … 2892 2925 { 2893 2926 // matt: TODO 2894 Debug << "here888 " << mTermMaxLeaves << " " << mOspStats.Leaves() << endl;2895 2927 return ( 2896 2928 (mOspStats.Leaves() >= mTermMaxLeaves) … … 2952 2984 int &objectsBack) 2953 2985 { 2954 2986 // sort so we can use a sweep 2955 2987 SortSplitCandidates(node, axis); 2956 2988 … … 2984 3016 2985 3017 float sum = (float)pvsSize * sizeBox; 3018 float dummy1 = 0; 3019 float dummy2 = 0; 2986 3020 2987 3021 vector<SortableEntry>::const_iterator ci, ci_end = mSplitCandidates->end(); 2988 3022 cout << "***********" << endl; 2989 3023 //-- traverse through visibility events 2990 3024 for (ci = mSplitCandidates->begin(); ci != ci_end; ++ ci) 2991 3025 { 3026 int pvslold = pvsl; 2992 3027 EvalPvsIncr(*ci, pvsl, pvsr); 3028 3029 cout << "incr: " << ci->mObject->mViewCellPvs.GetSize() << " obj id " 3030 << ci->mObject->GetId() << endl; 2993 3031 2994 3032 // Note: sufficient to compare size of bounding boxes of front and back side? … … 2997 3035 sum = pvsl * ((*ci).value - minBox) + pvsr * (maxBox - (*ci).value); 2998 3036 2999 //Debug << "pos=" << (*ci).value << "\t pvs=(" << pvsl << "," << pvsr << ")" << "\t cost= " << sum << endl; 3037 cout << "pos=" << (*ci).value << "\t pvs=(" << pvsl << "," 3038 << pvsr << ")" << "\t cost= " << sum << endl; 3000 3039 3001 3040 if (sum < minSum) … … 3012 3051 } 3013 3052 3014 3015 // -- compute cost 3053 //-- compute cost 3016 3054 3017 3055 const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize(); … … 3035 3073 3036 3074 //if (axis != 1) 3037 Debug << "axis=" << axis << " costRatio=" << ratio << " pos=" << position << " t=" << (position - minBox) / (maxBox - minBox) 3038 <<"\t pb=(" << pvsBack << ")\t pf=(" << pvsFront << ")" << endl; 3075 Debug << "axis=" << axis << " costRatio=" << ratio << " pos=" 3076 << position << " t=" << (position - minBox) / (maxBox - minBox) 3077 << "\t pb=(" << pvsBack << ")\t pf=(" << pvsFront << ")" << endl; 3039 3078 3040 3079 return ratio; 3041 3080 } 3042 3081 3082 3043 3083 void OspTree::SortSplitCandidates(KdLeaf *node, const int axis) 3044 3084 { 3045 3085 mSplitCandidates->clear(); 3046 3086 3047 int requestedSize = 2 *(int)node->mObjects.size();3087 int requestedSize = 2 * (int)node->mObjects.size(); 3048 3088 3049 3089 // creates a sorted split candidates array … … 3074 3114 stable_sort(mSplitCandidates->begin(), mSplitCandidates->end()); 3075 3115 } 3076 3077 3116 3078 3117 … … 3085 3124 return object->mViewCellPvs.GetSize(); 3086 3125 #endif 3126 } 3127 3128 3129 const OspTreeStatistics &OspTree::GetStatistics() const 3130 { 3131 return mOspStats; 3087 3132 } 3088 3133 … … 3124 3169 break; 3125 3170 } 3171 3172 cout << "pvs left: " << pvsLeft << " pvs right " << pvsRight << endl; 3126 3173 } 3127 3174 … … 3241 3288 float OspTree::EvalViewCellPvsIncr(Intersectable *object) const 3242 3289 { 3243 // TODO3290 #if COUNT_OBJECTS 3244 3291 return 1; 3292 #else 3293 return (float)object->mViewCellPvs.GetSize(); 3294 #endif 3245 3295 } 3246 3296 … … 3276 3326 const float pvsIncr = EvalViewCellPvsIncr(obj); 3277 3327 totalPvs += pvsIncr; 3328 cout << "totalpvs " << totalPvs << " incr " << pvsIncr << endl; 3278 3329 3279 3330 if (box.Max(candidatePlane.mAxis) > candidatePlane.mPosition) … … 3310 3361 const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack; 3311 3362 3312 Debug << "old: " << oldRenderCost << " new: " << newRenderCost << " decrease: " << oldRenderCost - newRenderCost << endl; 3363 Debug << "old: " << oldRenderCost << " new: " << newRenderCost << " decrease: " 3364 << oldRenderCost - newRenderCost << endl; 3313 3365 const float renderCostDecrease = (oldRenderCost - newRenderCost) / mBoundingBox.GetVolume(); 3314 3366 3315 3367 // take render cost of node into account 3316 3368 // otherwise danger of being stuck in a local minimum!! 3317 const float factor = 0.99f;3369 const float factor = mRenderCostDecreaseWeight; 3318 3370 3319 3371 const float normalizedOldRenderCost = oldRenderCost / mBoundingBox.GetVolume(); 3320 3321 3372 return factor * renderCostDecrease + (1.0f - factor) * normalizedOldRenderCost; 3322 3373 } … … 3429 3480 3430 3481 3482 void OspTree::CollectViewCells(KdLeaf *leaf, ViewCellContainer &viewCells) 3483 { 3484 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 3485 3486 ViewCell::NewMail(); 3487 3488 // loop through all object and collect view cell pvs of this node 3489 for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 3490 { 3491 Intersectable *obj = *oit; 3492 3493 ViewCellPvsMap::const_iterator vit, vit_end = obj->mViewCellPvs.mEntries.end(); 3494 3495 for (vit = obj->mViewCellPvs.mEntries.begin(); vit != vit_end; ++ vit) 3496 { 3497 ViewCell *vc = (*vit).first; 3498 3499 if (!vc->Mailed()) 3500 { 3501 vc->Mail(); 3502 viewCells.push_back(vc); 3503 } 3504 } 3505 } 3506 3507 } 3508 3509 3510 void OspTree::CollectDirtyCandidates(OspSplitCandidate *sc, 3511 vector<SplitCandidate *> &dirtyList) 3512 { 3513 KdLeaf *node = sc->mParentData.mNode; 3514 3515 ObjectContainer::const_iterator oit, oit_end = node->mObjects.end(); 3516 3517 ViewCellContainer viewCells; 3518 3519 CollectViewCells(node, viewCells); 3520 3521 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 3522 3523 // through split candidates corresponding to view cell pvs of this 3524 // node into dirty list 3525 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 3526 { 3527 VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit); 3528 3529 VspLeaf *leaf = vc->mLeaf; 3530 dirtyList.push_back(leaf->GetSplitCandidate()); 3531 } 3532 } 3533 3534 3535 int OspTree::ComputePvsSize(const ObjectContainer &objects) const 3536 { 3537 int pvsSize = 0; 3538 3539 ObjectContainer::const_iterator oit, oit_end = objects.end(); 3540 3541 for (oit = objects.begin(); oit != oit_end; ++ oit) 3542 { 3543 pvsSize += (*oit)->mViewCellPvs.GetSize(); 3544 } 3545 3546 return pvsSize; 3547 } 3548 3549 3431 3550 /********************************************************************/ 3432 3551 /* class HierarchyManager implementation */ … … 3445 3564 SplitCandidate *splitCandidate = mTQueue.Top(); 3446 3565 3447 Debug<< "next candidate: " << splitCandidate->Type()3566 cout << "next candidate: " << splitCandidate->Type() 3448 3567 << ", priority: " << splitCandidate->GetPriority() << endl; 3449 3568 … … 3454 3573 3455 3574 3456 void HierarchyManager::PrepareConstruction(const VssRayContainer &sampleRays, 3457 const ObjectContainer &objects, 3458 AxisAlignedBox3 *forcedViewSpace, 3459 RayInfoContainer &rays) 3460 { 3461 mVspTree.PrepareConstruction(sampleRays, forcedViewSpace); 3575 void HierarchyManager::ProcessRays(const VssRayContainer &sampleRays, 3576 RayInfoContainer &rays, 3577 ObjectContainer &sampledObjects) 3578 { 3579 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 3462 3580 3463 3581 long startTime = GetTime(); … … 3467 3585 Intersectable::NewMail(); 3468 3586 3469 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 3470 3471 //-- store rays 3587 //-- store rays and objects 3472 3588 for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 3473 3589 { 3474 3590 VssRay *ray = *rit; 3475 3476 3591 float minT, maxT; 3477 3478 3592 static Ray hray; 3593 3479 3594 hray.Init(*ray); 3480 3595 … … 3489 3604 rays.push_back(RayInfo(ray, minT / len, maxT / len)); 3490 3605 } 3606 3607 // store objects 3608 if (ray->mTerminationObject && !ray->mTerminationObject->Mailed()) 3609 { 3610 ray->mTerminationObject->Mail(); 3611 sampledObjects.push_back(ray->mTerminationObject); 3612 } 3613 3614 if (ray->mOriginObject && !ray->mOriginObject->Mailed()) 3615 { 3616 ray->mOriginObject->Mail(); 3617 sampledObjects.push_back(ray->mOriginObject); 3618 } 3491 3619 } 3492 3620 3493 3621 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 3494 3495 3496 int pvsSize = mVspTree.ComputePvsSize(rays); 3497 3622 } 3623 3624 3625 void HierarchyManager::PrepareVsp(const VssRayContainer &sampleRays, 3626 AxisAlignedBox3 *forcedViewSpace, 3627 RayInfoContainer &rays) 3628 { 3629 // prepare bounding box 3630 mVspTree.PrepareConstruction(sampleRays, forcedViewSpace); 3631 3632 // get clipped rays 3633 ObjectContainer sampledObjects; 3634 ProcessRays(sampleRays, rays, sampledObjects); 3635 3636 //const int pvsSize = mVspTree.ComputePvsSize(rays); 3637 const int pvsSize = (int)sampledObjects.size(); 3638 3639 cout << "here450 pvs size: " << pvsSize << endl; 3498 3640 // -- prepare view space partition 3499 3641 … … 3507 3649 0, 3508 3650 &rays, 3509 //(int)objects.size(),3510 3651 pvsSize, 3511 3652 prop, … … 3513 3654 3514 3655 3656 // create first view cell 3657 mVspTree.CreateViewCell(vData); 3658 3659 // add first view cell to all the objects view cell pvs 3660 ObjectPvsMap::const_iterator oit, 3661 oit_end = leaf->GetViewCell()->GetPvs().mEntries.end(); 3662 3663 cout << "here23 " << leaf->GetViewCell()->GetPvs().mEntries.size(); 3664 3665 for (oit = leaf->GetViewCell()->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 3666 { 3667 Intersectable *obj = (*oit).first; 3668 cout << "obj: " << obj->GetId() << endl; 3669 obj->mViewCellPvs.AddSample(leaf->GetViewCell(), 1); 3670 } 3671 3515 3672 // compute first split candidate 3516 3673 VspTree::VspSplitCandidate *splitCandidate = new VspTree::VspSplitCandidate(vData); … … 3518 3675 3519 3676 mTQueue.Push(splitCandidate); 3520 3521 3522 //-- object space partition 3523 3677 } 3678 3679 3680 void HierarchyManager::PrepareOsp(const ObjectContainer &objects, 3681 AxisAlignedBox3 *forcedViewSpace) 3682 { 3524 3683 mOspTree.PrepareConstruction(objects, forcedViewSpace); 3525 3684 … … 3530 3689 mOspTree.mRoot = kdleaf; 3531 3690 3532 3691 // TODO matt: this is something different than pvs size. 3692 const int pvsSize = mOspTree.ComputePvsSize(objects); 3693 const float prop = mOspTree.mBoundingBox.GetVolume(); 3694 3695 cout << "here40 pvs size: " << pvsSize << endl; 3533 3696 // first osp traversal data 3534 3697 OspTree::OspTraversalData oData(kdleaf, … … 3542 3705 3543 3706 // compute first split candidate 3544 OspTree::OspSplitCandidate *oSplitCandidate = new OspTree::OspSplitCandidate(oData); 3707 OspTree::OspSplitCandidate *oSplitCandidate = 3708 new OspTree::OspSplitCandidate(oData); 3545 3709 mOspTree.EvalSplitCandidate(*oSplitCandidate); 3546 3710 3547 mTQueue.Push(splitCandidate); 3711 mTQueue.Push(oSplitCandidate); 3712 } 3713 3714 3715 void HierarchyManager::PrepareConstruction(const VssRayContainer &sampleRays, 3716 const ObjectContainer &objects, 3717 AxisAlignedBox3 *forcedViewSpace, 3718 RayInfoContainer &rays) 3719 { 3720 PrepareVsp(sampleRays, forcedViewSpace, rays); 3721 PrepareOsp(objects, forcedViewSpace); 3548 3722 } 3549 3723 … … 3561 3735 { 3562 3736 RayInfoContainer *rays = new RayInfoContainer(); 3563 3564 mVspTree.PrepareConstruction(sampleRays, forcedViewSpace); 3737 PrepareVsp(sampleRays, forcedViewSpace, *rays); 3565 3738 3566 3739 long startTime = GetTime(); 3567 3568 cout << "storing rays ... "; 3569 3570 Intersectable::NewMail(); 3571 3572 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 3573 3574 //-- store rays 3575 for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 3576 { 3577 VssRay *ray = *rit; 3578 3579 float minT, maxT; 3580 3581 static Ray hray; 3582 hray.Init(*ray); 3583 3584 // TODO: not very efficient to implictly cast between rays types 3585 if (mVspTree.GetBoundingBox().GetRaySegment(hray, minT, maxT)) 3586 { 3587 float len = ray->Length(); 3588 3589 if (!len) 3590 len = Limits::Small; 3591 3592 rays->push_back(RayInfo(ray, minT / len, maxT / len)); 3593 } 3594 } 3595 3596 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 3597 3598 const int pvsSize = mVspTree.ComputePvsSize(*rays); 3599 3600 3601 // -- prepare view space partition 3602 3603 // add first candidate for view space partition 3604 VspLeaf *vspleaf = new VspLeaf(); 3605 3606 mVspTree.mRoot = vspleaf; 3607 const float prop = mVspTree.mBoundingBox.GetVolume(); 3608 3609 // first vsp traversal data 3610 VspTree::VspTraversalData vData(vspleaf, 3611 0, 3612 rays, 3613 pvsSize, 3614 prop, 3615 mVspTree.mBoundingBox); 3616 3617 3618 //-- compute first split candidate 3619 VspTree::VspSplitCandidate *splitCandidate = new VspTree::VspSplitCandidate(vData); 3620 mVspTree.EvalSplitCandidate(*splitCandidate); 3621 3622 mTQueue.Push(splitCandidate); 3623 3740 cout << "starting vsp contruction ... " << endl; 3624 3741 int i = 0; 3625 3742 … … 3631 3748 GlobalTerminationCriteriaMet(splitCandidate); 3632 3749 3633 //cout << "vsp nodes: " << i ++ << endl;3750 cout << "vsp nodes: " << i ++ << endl; 3634 3751 3635 3752 // cost ratio of cost decrease / totalCost 3636 3753 const float costRatio = splitCandidate->GetPriority() / mTotalCost; 3637 // Debug<< "cost ratio: " << costRatio << endl;3754 //cout << "cost ratio: " << costRatio << endl; 3638 3755 3639 3756 if (costRatio < mTermMinGlobalCostRatio) … … 3646 3763 dynamic_cast<VspTree::VspSplitCandidate *>(splitCandidate); 3647 3764 3765 3648 3766 VspNode *r = mVspTree.Subdivide(mTQueue, *sc, globalTerminationCriteriaMet); 3649 3767 3650 3768 DEL_PTR(splitCandidate); 3651 3769 } … … 3654 3772 mVspTree.mVspStats.Stop(); 3655 3773 3656 Debug << "object space" << endl; 3774 startTime = GetTime(); 3775 cout << "starting osp contruction ... " << endl; 3657 3776 3658 3777 //-- object space partition 3659 3660 mOspTree.PrepareConstruction(objects, forcedViewSpace); 3661 3662 // add first candidate for view space partition 3663 KdLeaf *leaf = new KdLeaf(NULL, 0); 3664 leaf->mObjects = objects; 3665 3666 mOspTree.mRoot = leaf; 3667 3668 3669 //-- first osp traversal data 3670 OspTree::OspTraversalData oData(leaf, 3671 0, 3672 pvsSize, 3673 prop, 3674 mOspTree.mBoundingBox); 3675 3676 3677 mOspTree.ProcessLeafObjects(leaf, NULL); 3678 3679 // compute first split candidate 3680 OspTree::OspSplitCandidate *oSplitCandidate = new OspTree::OspSplitCandidate(oData); 3681 mOspTree.EvalSplitCandidate(*oSplitCandidate); 3682 3683 mTQueue.Push(oSplitCandidate); 3778 PrepareOsp(objects, forcedViewSpace); 3684 3779 3685 3780 i = 0; … … 3733 3828 while (!FinishedConstruction()) 3734 3829 { 3735 SplitCandidate *splitCandidate = NextSplitCandidate();3736 3830 mCurrentCandidate = NextSplitCandidate(); 3831 3737 3832 const bool globalTerminationCriteriaMet = 3738 GlobalTerminationCriteriaMet( splitCandidate);3833 GlobalTerminationCriteriaMet(mCurrentCandidate); 3739 3834 3740 3835 cout << "view cells: " << i ++ << endl; 3741 3836 3742 3837 // cost ratio of cost decrease / totalCost 3743 const float costRatio = splitCandidate->GetPriority() / mTotalCost;3838 const float costRatio = mCurrentCandidate->GetPriority() / mTotalCost; 3744 3839 //Debug << "cost ratio: " << costRatio << endl; 3745 3840 … … 3750 3845 3751 3846 // we have either a object space or view space split 3752 if ( splitCandidate->Type() == SplitCandidate::VIEW_SPACE)3847 if (mCurrentCandidate->Type() == SplitCandidate::VIEW_SPACE) 3753 3848 { 3754 3849 VspTree::VspSplitCandidate *sc = 3755 dynamic_cast<VspTree::VspSplitCandidate *>( splitCandidate);3850 dynamic_cast<VspTree::VspSplitCandidate *>(mCurrentCandidate); 3756 3851 3757 3852 VspNode *r = mVspTree.Subdivide(mTQueue, *sc, globalTerminationCriteriaMet); … … 3760 3855 { 3761 3856 OspTree::OspSplitCandidate *sc = 3762 dynamic_cast<OspTree::OspSplitCandidate *>( splitCandidate);3857 dynamic_cast<OspTree::OspSplitCandidate *>(mCurrentCandidate); 3763 3858 3764 3859 KdNode *r = mOspTree.Subdivide(mTQueue, *sc, globalTerminationCriteriaMet); 3765 3860 } 3766 3861 3767 DEL_PTR(splitCandidate); 3862 // reevaluate affected candidates 3863 RepairQueue(); 3864 3865 DEL_PTR(mCurrentCandidate); 3768 3866 } 3769 3867 … … 3780 3878 3781 3879 3782 void HierarchyManager::RepairQueue(const vector<SplitCandidate *> &dirtyList) 3880 void HierarchyManager::CollectDirtyCandidates(vector<SplitCandidate *> &dirtyList) 3881 { 3882 // we have either a object space or view space split 3883 if (mCurrentCandidate->Type() == SplitCandidate::VIEW_SPACE) 3884 { 3885 VspTree::VspSplitCandidate *sc = 3886 dynamic_cast<VspTree::VspSplitCandidate *>(mCurrentCandidate); 3887 3888 mVspTree.CollectDirtyCandidates(sc, dirtyList); 3889 } 3890 else // object space split 3891 { 3892 OspTree::OspSplitCandidate *sc = 3893 dynamic_cast<OspTree::OspSplitCandidate *>(mCurrentCandidate); 3894 3895 mOspTree.CollectDirtyCandidates(sc, dirtyList); 3896 } 3897 } 3898 3899 3900 void HierarchyManager::RepairQueue() 3783 3901 { 3784 3902 // TODO … … 3799 3917 // split candidate 3800 3918 3919 // collect list of "dirty" candidates 3920 vector<SplitCandidate *> dirtyList; 3921 CollectDirtyCandidates(dirtyList); 3922 3923 //-- reevaluate the dirty list 3801 3924 vector<SplitCandidate *>::const_iterator sit, sit_end = dirtyList.end(); 3802 3925
Note: See TracChangeset
for help on using the changeset viewer.