Changeset 1133 for GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
- Timestamp:
- 07/13/06 09:06:21 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
r1129 r1133 324 324 mOutOfBoundsCell(NULL), 325 325 mStoreRays(false), 326 mTimeStamp(1) 326 mTimeStamp(1), 327 mOspTree(NULL) 327 328 { 328 329 bool randomize = false; … … 790 791 791 792 792 /*void VspTree::RemoveParentViewCellReferences(VspTraversalData &parentData) 793 { 794 RayInfoContainer::const_iterator it, it_end = parentData.mRays->end(); 795 796 KdLeaf::NewMail(); 797 Intersectable::NewMail(); 798 799 ViewCell *vc = parentData.mNode->mViewCell; 800 801 const float highestContri = 1e25; 802 803 // add contributions from samples to the PVS 804 for (it = parentData.mRays->begin(); it != it_end; ++ it) 805 { 806 VssRay *ray = (*it).mRay; 807 808 Intersectable *obj = ray->mTerminationObject; 809 810 if (obj && !obj->Mailed()) 811 { 812 obj->Mail(); 813 // reduce object reference count by one 814 -- obj->mViewCellPvs; 815 816 set<KdLeaf *>::const_iterator kit, kit_end = obj->mKdLeaves.end(); 817 818 for (kit = obj->mKdLeaves.begin(); kit != kit_end; ++ kit) 819 { 820 KdLeaf *leaf = *kit; 821 822 if (!leaf->Mailed()) 823 { 824 leaf->Mail(); 825 leaf->mViewCellPvs.RemoveSample(vc, highestContri); 826 } 827 } 828 } 829 830 Intersectable *obj = ray->mOriginObject; 831 832 if (obj && !obj->Mailed()) 833 { 834 obj->Mail(); 835 // reduce object reference count by one 836 -- obj->mViewCellPvs; 837 838 set<KdLeaf *>::const_iterator kit, kit_end = obj->mKdLeaves.end(); 839 840 for (kit = obj->mKdLeaves.begin(); kit != kit_end; ++ kit) 841 { 842 KdLeaf *leaf = *kit; 843 844 if (!leaf->Mailed()) 845 { 846 leaf->Mail(); 847 leaf->mViewCellPvs.RemoveSample(vc, highestContri); 848 } 849 } 850 } 851 } 852 }*/ 793 KdNode *VspTree::GetKdNode(VssRay &ray, const bool termination) const 794 { 795 if (termination) 796 { 797 if (!ray.mTerminationNode) 798 { 799 ray.mTerminationNode = mOspTree->GetRoot(); 800 } 801 802 ray.mTerminationNode = 803 mOspTree->GetLeaf(ray.mTermination, ray.mTerminationNode); 804 805 return ray.mTerminationNode; 806 } 807 else 808 { 809 if (!ray.mOriginNode) 810 { 811 ray.mOriginNode = mOspTree->GetRoot(); 812 } 813 814 ray.mOriginNode = 815 mOspTree->GetLeaf(ray.mOrigin, ray.mOriginNode); 816 817 return ray.mOriginNode; 818 } 819 } 853 820 854 821 … … 920 887 921 888 sc += contribution; 889 890 // potentially visible kd cells 891 const bool termination = true; 892 vc->AddKdPvsSample(GetKdLeaf(ray, termination)); 922 893 } 923 894 … … 932 903 933 904 sc += contribution; 905 906 // potentially visible kd cells 907 const bool termination = false; 908 vc->AddKdPvsSample(GetKdLeaf(ray, termination)); 934 909 } 935 910 … … 2826 2801 2827 2802 SplitObjects(splitPlane, leaf->mObjects, front->mObjects, back->mObjects); 2828 2829 ProcessLeafObjects(leaf, front, back); 2803 //ProcessLeafObjects(leaf, front, back); 2830 2804 2831 2805 backData.mNode = back; … … 2992 2966 2993 2967 float totalVol = PrepareHeuristics(node->mObjects); 2994 int voll = 0, volr = totalVol; 2968 float voll = 0; 2969 float volr = totalVol; 2995 2970 2996 2971 const int totalPvs = (int)node->mObjects.size(); … … 3024 2999 for (ci = mSplitCandidates->begin(); ci != ci_end; ++ ci) 3025 3000 { 3026 Eval PvsIncr(*ci, voll, volr);3001 EvalViewCellVolumeIncr(*ci, voll, volr); 3027 3002 3028 3003 cout << "incr: " << ci->mObject->mViewCellPvs.GetSize() << " obj id " … … 3060 3035 const float pFront = volFront; 3061 3036 3062 const float penaltyOld = totalPvs;//EvalPvsPenalty(pvsSize, lowerPvsLimit, upperPvsLimit);3063 const float penaltyFront = totalPvs - pvsBack;//EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit);3064 const float penaltyBack = pvsBack;//EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit);3037 const float penaltyOld = (float)totalPvs;//EvalPvsPenalty(pvsSize, lowerPvsLimit, upperPvsLimit); 3038 const float penaltyFront = (float)totalPvs - pvsBack;//EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit); 3039 const float penaltyBack = (float)pvsBack;//EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit); 3065 3040 3066 3041 const float oldRenderCost = penaltyOld * pOverall + Limits::Small; … … 3163 3138 3164 3139 3165 void OspTree::Eval PvsIncr(const SortableEntry &ci,3166 int &pvsLeft,3167 int &pvsRight) const3140 void OspTree::EvalViewCellVolumeIncr(const SortableEntry &ci, 3141 float &volLeft, 3142 float &volRight) const 3168 3143 { 3169 3144 Intersectable *obj = ci.mObject; … … 3172 3147 { 3173 3148 case SortableEntry::BOX_MIN: 3174 AddContriToPvs(obj, pvsLeft);3149 AddContriToPvs(obj, volLeft); 3175 3150 break; 3176 3151 3177 3152 case SortableEntry::BOX_MAX: 3178 RemoveContriFromPvs(obj, pvsRight);3153 RemoveContriFromPvs(obj, volRight); 3179 3154 break; 3180 3155 } 3181 3156 3182 cout << "pvs left: " << pvsLeft << " pvs right " << pvsRight << endl;3157 //cout << "vol left: " << volLeft << " vol right " << volRight << endl; 3183 3158 } 3184 3159 … … 3196 3171 3197 3172 3198 void OspTree::RemoveContriFromPvs(Intersectable *object, int &pvs) const3173 void OspTree::RemoveContriFromPvs(Intersectable *object, float &pvs) const 3199 3174 { 3200 3175 if (mUseEqualWeightForHeuristics) … … 3206 3181 3207 3182 3208 void OspTree::AddContriToPvs(Intersectable *object, int &pvs) const3183 void OspTree::AddContriToPvs(Intersectable *object, float &pvs) const 3209 3184 { 3210 3185 if (mUseEqualWeightForHeuristics) … … 3414 3389 } 3415 3390 3416 3391 #if DEPRECATED 3417 3392 void OspTree::ProcessLeafObjects(KdLeaf *parent, KdLeaf *front, KdLeaf *back) const 3418 3393 { … … 3491 3466 3492 3467 } 3493 3468 #endif 3494 3469 3495 3470 void OspTree::CollectLeaves(vector<KdLeaf *> &leaves) const … … 3608 3583 3609 3584 3585 KdLeaf *OspTree::GetLeaf(const Vector3 &pt, KdNode *node) const 3586 { 3587 if (node == NULL) 3588 node = mRoot; 3589 3590 stack<KdNode *> nodeStack; 3591 nodeStack.push(node); 3592 3593 KdLeaf *leaf = NULL; 3594 3595 while (!nodeStack.empty()) 3596 { 3597 KdNode *node = nodeStack.top(); 3598 nodeStack.pop(); 3599 3600 if (node->IsLeaf()) 3601 { 3602 leaf = dynamic_cast<KdLeaf *>(node); 3603 } 3604 else 3605 { 3606 KdInterior *interior = dynamic_cast<KdInterior *>(node); 3607 3608 // random decision 3609 if (interior->mPosition < pt[interior->mAxis]) 3610 nodeStack.push(interior->mBack); 3611 else 3612 nodeStack.push(interior->mFront); 3613 } 3614 } 3615 3616 return leaf; 3617 } 3618 3619 3620 KdNode *OspTree::GetRoot() const 3621 { 3622 return mRoot; 3623 } 3624 3625 3610 3626 /********************************************************************/ 3611 3627 /* class HierarchyManager implementation */ … … 3617 3633 mVspTree(vspTree), mOspTree(ospTree) 3618 3634 { 3635 mVspTree.mOspTree = &ospTree; 3619 3636 } 3620 3637 … … 3634 3651 3635 3652 void HierarchyManager::ProcessRays(const VssRayContainer &sampleRays, 3636 RayInfoContainer &rays, 3637 ObjectContainer &sampledObjects) 3653 RayInfoContainer &rays) 3638 3654 { 3639 3655 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); … … 3664 3680 rays.push_back(RayInfo(ray, minT / len, maxT / len)); 3665 3681 } 3666 3667 // store objects3668 if (ray->mTerminationObject && !ray->mTerminationObject->Mailed())3669 {3670 ray->mTerminationObject->Mail();3671 sampledObjects.push_back(ray->mTerminationObject);3672 }3673 3674 if (ray->mOriginObject && !ray->mOriginObject->Mailed())3675 {3676 ray->mOriginObject->Mail();3677 sampledObjects.push_back(ray->mOriginObject);3678 }3679 3682 } 3680 3683 … … 3683 3686 3684 3687 3685 void HierarchyManager::PrepareVsp(const VssRayContainer &sampleRays, 3686 AxisAlignedBox3 *forcedViewSpace, 3687 RayInfoContainer &rays) 3688 SplitCandidate *HierarchyManager::PrepareVsp(const VssRayContainer &sampleRays, 3689 AxisAlignedBox3 *forcedViewSpace, 3690 RayInfoContainer &rays 3691 ) 3688 3692 { 3689 3693 // prepare bounding box … … 3691 3695 3692 3696 // get clipped rays 3693 ObjectContainer sampledObjects; 3694 ProcessRays(sampleRays, rays, sampledObjects); 3695 3696 //const int pvsSize = mVspTree.ComputePvsSize(rays); 3697 const int pvsSize = (int)sampledObjects.size(); 3698 3697 ProcessRays(sampleRays, rays); 3698 3699 const int pvsSize = mVspTree.ComputePvsSize(rays); 3700 3699 3701 cout << "here450 pvs size: " << pvsSize << endl; 3700 3702 // -- prepare view space partition … … 3703 3705 VspLeaf *leaf = new VspLeaf(); 3704 3706 mVspTree.mRoot = leaf; 3707 3705 3708 const float prop = mVspTree.mBoundingBox.GetVolume(); 3706 3709 … … 3721 3724 oit_end = leaf->GetViewCell()->GetPvs().mEntries.end(); 3722 3725 3723 cout << "here23 " << leaf->GetViewCell()->GetPvs().mEntries.size();3724 3726 3725 3727 for (oit = leaf->GetViewCell()->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 3726 3728 { 3727 3729 Intersectable *obj = (*oit).first; 3728 cout << "obj: " << obj->GetId() << endl;3729 3730 obj->mViewCellPvs.AddSample(leaf->GetViewCell(), 1); 3730 3731 } 3731 3732 3732 3733 // compute first split candidate 3733 VspTree::VspSplitCandidate *splitCandidate = new VspTree::VspSplitCandidate(vData); 3734 VspTree::VspSplitCandidate *splitCandidate = 3735 new VspTree::VspSplitCandidate(vData); 3734 3736 mVspTree.EvalSplitCandidate(*splitCandidate); 3735 3737 3736 mTQueue.Push(splitCandidate);3737 } 3738 3739 3740 void HierarchyManager::PrepareOsp(const ObjectContainer &objects, 3741 AxisAlignedBox3 *forcedViewSpace)3738 return splitCandidate; 3739 } 3740 3741 3742 SplitCandidate * HierarchyManager::PrepareOsp(const ObjectContainer &objects, 3743 AxisAlignedBox3 *forcedViewSpace) 3742 3744 { 3743 3745 mOspTree.PrepareConstruction(objects, forcedViewSpace); … … 3762 3764 3763 3765 3764 mOspTree.ProcessLeafObjects(NULL, kdleaf, NULL);3766 //mOspTree.ProcessLeafObjects(NULL, kdleaf, NULL); 3765 3767 3766 3768 // compute first split candidate … … 3769 3771 mOspTree.EvalSplitCandidate(*oSplitCandidate); 3770 3772 3771 mTQueue.Push(oSplitCandidate);3773 return oSplitCandidate; 3772 3774 } 3773 3775 … … 3778 3780 RayInfoContainer &rays) 3779 3781 { 3780 PrepareVsp(sampleRays, forcedViewSpace, rays);3781 PrepareOsp(objects, forcedViewSpace);3782 mTQueue.Push(PrepareVsp(sampleRays, forcedViewSpace, rays)); 3783 mTQueue.Push(PrepareOsp(objects, forcedViewSpace)); 3782 3784 } 3783 3785 … … 3798 3800 // makes no sense otherwise because only one kd cell available 3799 3801 // during view space partition 3800 const int savedCountMethod = 3802 const int savedCountMethod = mVspTree.mPvsCountMethod; 3801 3803 mVspTree.mPvsCountMethod = VspTree::PER_OBJECT; 3802 3804 3803 PrepareVsp(sampleRays, forcedViewSpace, *rays);3805 mTQueue.Push(PrepareVsp(sampleRays, forcedViewSpace, *rays)); 3804 3806 3805 3807 long startTime = GetTime(); … … 3842 3844 3843 3845 //-- object space partition 3844 PrepareOsp(objects, forcedViewSpace);3846 mTQueue.Push(PrepareOsp(objects, forcedViewSpace)); 3845 3847 3846 3848 i = 0;
Note: See TracChangeset
for help on using the changeset viewer.