Changeset 1133 for GTP/trunk/Lib/Vis
- Timestamp:
- 07/13/06 09:06:21 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h
r1077 r1133 31 31 32 32 /// kd leaves that this intersectable belongs to 33 set<KdLeaf *> mKdLeaves;33 //set<KdLeaf *> mKdLeaves; 34 34 35 35 enum { MESH_INSTANCE, TRANSFORMED_MESH_INSTANCE, SPHERE, VIEW_CELL, OGRE_MESH_INSTANCE }; -
GTP/trunk/Lib/Vis/Preprocessing/src/RayInfo.h
r860 r1133 12 12 class Vector3; 13 13 14 14 15 typedef vector<RayInfo> RayInfoContainer; 16 17 15 18 /** Structure holding additional info about 16 19 the ray during traversal. -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1121 r1133 252 252 const bool result = mPvs.AddSample(sample, pdf, contribution); 253 253 254 // update pvs size 254 // update pvs size scalar 255 255 mPvsSize = mPvs.GetSize(); 256 256 mPvsSizeValid = true; … … 260 260 261 261 262 bool ViewCell::AddKdPvsSample(KdLeaf *sample, 263 const float pdf, 264 float &contribution) 265 { 266 const bool result = mKdPvs.AddSample(sample, pdf, contribution); 267 268 return result; 269 } 262 270 263 271 /************************************************************************/ … … 1687 1695 Intersectable *obj = (*oit).first; 1688 1696 1689 set<KdLeaf *>::const_iterator kit, kit_end = obj->mKdLeaves.end(); 1690 1691 for (kit = obj->mKdLeaves.begin(); kit != kit_end; ++ kit) 1692 { 1693 KdLeaf *leaf = *kit; 1697 /* KdLeaf *leaf = ; 1694 1698 1695 1699 pvsSize += ((int)leaf->mObjects.size() - (int)leaf->mMultipleObjects.size()); … … 1709 1713 } 1710 1714 } 1711 } 1715 }*/ 1712 1716 } 1713 1717 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
r1121 r1133 191 191 bool AddPvsSample(Intersectable *sample, const float pdf, float &contribution); 192 192 193 193 bool AddKdPvsSample(KdLeaf *sample, const float pdf, float &contribution); 194 194 195 195 /// Rays piercing this view cell. … … 267 267 /// the potentially visible objects 268 268 ObjectPvs mPvs; 269 /// the potentially visible kd leaves 270 KdPvs mKdPvs; 269 271 270 272 float mVolume; … … 685 687 */ 686 688 ViewCell *GetInitialLeftViewCell() const; 689 /** Returns leaf view cell initially associated with this merge candidate. 690 */ 687 691 ViewCell *GetInitialRightViewCell() const; 688 692 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1129 r1133 5492 5492 5493 5493 // collect kd leaves 5494 //KdLeaf = 5494 5495 set<KdLeaf *>::const_iterator kdit, kdit_end = obj->mKdLeaves.end(); 5495 5496 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h
r1084 r1133 715 715 716 716 /////////////////////////////////////////////////////////// 717 718 717 719 protected: 718 720 -
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; -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
r1129 r1133 32 32 class KdInterior; 33 33 class KdLeaf; 34 class OspTree; 35 34 36 35 37 class KdTreeStatistics; … … 752 754 ViewCellsTree *mViewCellsTree; 753 755 756 OspTree *mOspTree; 757 754 758 protected: 755 759 … … 1004 1008 vector<SplitCandidate *> &dirtyList); 1005 1009 1010 KdNode *GetKdNode(VssRay &ray, const bool termination) const; 1011 1012 1006 1013 protected: 1007 1014 … … 1010 1017 1011 1018 ViewCellsManager *mViewCellsManager; 1019 1012 1020 vector<SortableEntry> *mSplitCandidates; 1013 1021 … … 1091 1099 int mCreatedViewCells; 1092 1100 1093 /// weight between 1101 /// weight between render cost decrease and node render cost 1094 1102 float mRenderCostDecreaseWeight; 1095 1103 }; … … 1335 1343 1336 1344 1345 KdLeaf *GetLeaf(const Vector3 &pt, KdNode *node) const; 1346 1347 1337 1348 /// pointer to the hierarchy of view cells 1338 1349 ViewCellsTree *mViewCellsTree; … … 1439 1450 ObjectContainer &back); 1440 1451 1452 #if DEPRECATED 1441 1453 /** does some post processing on the objects in the new child leaves. 1442 1454 */ 1443 1455 void ProcessLeafObjects(KdLeaf *parent, KdLeaf *front, KdLeaf *back) const; 1444 1456 #endif 1445 1457 /** Selects an axis aligned for the next split. 1446 1458 @returns cost for this split … … 1539 1551 @param rightPvs updates the right pvs 1540 1552 */ 1541 void Eval PvsIncr(const SortableEntry &ve,1542 int &pvsLeft,1543 int &pvsRight) const;1544 1545 void RemoveContriFromPvs(Intersectable *object, int &pvs) const;1546 void AddContriToPvs(Intersectable *object, int &pvs) const;1553 void EvalViewCellVolumeIncr(const SortableEntry &ve, 1554 float &volLeft, 1555 float &volRight) const; 1556 1557 void RemoveContriFromPvs(Intersectable *object, float &pvs) const; 1558 void AddContriToPvs(Intersectable *object, float &pvs) const; 1547 1559 1548 1560 /** Prepares objects for the cost heuristics. … … 1721 1733 void CollectDirtyCandidates(vector<SplitCandidate *> &dirtyList); 1722 1734 1723 voidPrepareVsp(const VssRayContainer &sampleRays,1735 SplitCandidate * PrepareVsp(const VssRayContainer &sampleRays, 1724 1736 AxisAlignedBox3 *forcedViewSpace, 1725 1737 RayInfoContainer &rays); 1726 1738 1727 void PrepareOsp(const ObjectContainer &objects, AxisAlignedBox3 *forcedViewSpace); 1739 SplitCandidate * PrepareOsp(const ObjectContainer &objects, 1740 AxisAlignedBox3 *forcedViewSpace); 1728 1741 1729 1742 void ProcessRays(const VssRayContainer &sampleRays, 1730 RayInfoContainer &rays, 1731 ObjectContainer &sampledObjects); 1743 RayInfoContainer &rays); 1732 1744 1733 1745 -
GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h
r1112 r1133 12 12 class AxisAlignedBox3; 13 13 class Intersectable; 14 class KdNode; 14 15 15 16 class VssRay { … … 50 51 ViewCellContainer mViewCells; 51 52 53 52 54 //////////////////////// 53 55 // members related to importance sampling … … 70 72 71 73 ////////////////////////////// 74 75 76 /// the kd node holding the termination point 77 KdNode *mTerminationNode; 78 /// the kd node holding the origin point 79 KdNode *mOriginNode; 80 81 72 82 VssRay( 73 83 const Vector3 &origin, … … 88 98 mViewCells(0), 89 99 mWeightedPvsContribution(0), 90 mPdf(pdf) 91 { 92 Precompute(); 93 } 100 mPdf(pdf), 101 mTerminationNode(NULL), 102 mOriginNode(NULL) 103 { 104 Precompute(); 105 } 94 106 95 107 VssRay(const Ray &ray): … … 100 112 mPass(0), 101 113 mViewCells(0), 102 mPdf(1.0f) 114 mPdf(1.0f), 115 mTerminationNode(NULL), 116 mOriginNode(NULL) 103 117 { 104 118 if (ray.sourceObject.mObject)
Note: See TracChangeset
for help on using the changeset viewer.