Changeset 1109
- Timestamp:
- 07/10/06 17:59:24 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
r1089 r1109 201 201 /** PVS consisting of visible KdTree nodes */ 202 202 KdPvs mKdPvs; 203 203 204 /// pvs of view cells seeing this node. 205 // ViewCellPvs mViewCellPvs; 206 204 207 /** pointer to view cell. 205 208 */ -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
r1108 r1109 232 232 233 233 234 void VspInterior::SetupChildLinks(VspNode * b, VspNode *f)235 { 236 mBack = b ;237 mFront = f ;234 void VspInterior::SetupChildLinks(VspNode *front, VspNode *back) 235 { 236 mBack = back; 237 mFront = front; 238 238 } 239 239 … … 551 551 { 552 552 RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 553 553 554 for (it = tData.mRays->begin(); it != it_end; ++ it) 554 555 { … … 564 565 565 566 mVspStats.contributingSamples += conSamp; 566 mVspStats.sampleContributions += (int)sampCon;567 mVspStats.sampleContributions += (int)sampCon; 567 568 568 569 // finally evaluate statistics for this leaf … … 638 639 { 639 640 //-- create new view cell 640 CreateViewCell(tData);641 //CreateViewCell(tData); 641 642 642 643 //-- store additional info … … 677 678 splitCandidate.SetPriority(priority); 678 679 splitCandidate.mMaxCostMisses = success ? splitCandidate.mParentData.mMaxCostMisses : splitCandidate.mParentData.mMaxCostMisses + 1; 679 680 680 //Debug << "p: " << tData.mNode << " depth: " << tData.mDepth << endl; 681 681 } … … 703 703 *backData.mRays); 704 704 705 706 //Debug << "f: " << frontData.mRays->size() << " b: " << backData.mRays->size() << "d: " << tData.mRays->size() << endl; 707 //-- compute pvs 708 frontData.mPvs = ComputePvsSize(*frontData.mRays); 709 backData.mPvs = ComputePvsSize(*backData.mRays); 710 711 // split front and back node geometry and compute area 712 tData.mBoundingBox.Split(splitPlane.mAxis, splitPlane.mPosition, 713 frontData.mBoundingBox, backData.mBoundingBox); 714 715 716 frontData.mProbability = frontData.mBoundingBox.GetVolume(); 717 backData.mProbability = tData.mProbability - frontData.mProbability; 718 719 720 /////////////////////////////////////////// 721 // subdivide further 722 723 // store maximal and minimal depth 724 if (tData.mDepth > mVspStats.maxDepth) 725 { 726 Debug << "max depth increases to " << tData.mDepth << " at " << mVspStats.Leaves() << " leaves" << endl; 727 mVspStats.maxDepth = tData.mDepth; 728 } 729 730 // two more leaves 731 mVspStats.nodes += 2; 732 733 VspInterior *interior = new VspInterior(splitPlane); 734 735 #ifdef _DEBUG 736 Debug << interior << endl; 737 #endif 738 739 740 //-- create front and back leaf 741 742 VspInterior *parent = leaf->GetParent(); 743 744 // replace a link from node's parent 745 if (parent) 746 { 747 parent->ReplaceChildLink(leaf, interior); 748 interior->SetParent(parent); 749 } 750 else // new root 751 { 752 mRoot = interior; 753 } 754 755 VspLeaf *frontLeaf = new VspLeaf(interior); 756 VspLeaf *backLeaf = new VspLeaf(interior); 757 758 // and setup child links 759 interior->SetupChildLinks(frontLeaf, backLeaf); 760 761 // add bounding box 762 interior->SetBoundingBox(tData.mBoundingBox); 763 764 // set front and back leaf 765 frontData.mNode = frontLeaf; 766 backData.mNode = backLeaf; 767 768 // explicitely create front and back view cell 769 CreateViewCell(frontData); 770 CreateViewCell(backData); 771 705 772 // TODO: 706 773 // create front and back view cell … … 708 775 // add front and back view cell to "Potentially Visbilie View Cells" 709 776 // of the objects in front and back pvs 710 711 //Debug << "f: " << frontData.mRays->size() << " b: " << backData.mRays->size() << "d: " << tData.mRays->size() << endl; 712 //-- compute pvs 713 frontData.mPvs = ComputePvsSize(*frontData.mRays); 714 backData.mPvs = ComputePvsSize(*backData.mRays); 715 716 // split front and back node geometry and compute area 717 tData.mBoundingBox.Split(splitPlane.mAxis, splitPlane.mPosition, 718 frontData.mBoundingBox, backData.mBoundingBox); 719 720 721 frontData.mProbability = frontData.mBoundingBox.GetVolume(); 722 backData.mProbability = tData.mProbability - frontData.mProbability; 723 724 725 /////////////////////////////////////////// 726 // subdivide further 727 728 // store maximal and minimal depth 729 if (tData.mDepth > mVspStats.maxDepth) 730 { 731 Debug << "max depth increases to " << tData.mDepth << " at " << mVspStats.Leaves() << " leaves" << endl; 732 mVspStats.maxDepth = tData.mDepth; 733 } 734 735 mVspStats.nodes += 2; 736 737 738 VspInterior *interior = new VspInterior(splitPlane); 739 740 #ifdef _DEBUG 741 Debug << interior << endl; 742 #endif 743 744 745 //-- create front and back leaf 746 747 VspInterior *parent = leaf->GetParent(); 748 749 // replace a link from node's parent 750 if (parent) 751 { 752 parent->ReplaceChildLink(leaf, interior); 753 interior->SetParent(parent); 754 } 755 else // new root 756 { 757 mRoot = interior; 758 } 759 760 // and setup child links 761 interior->SetupChildLinks(new VspLeaf(interior), new VspLeaf(interior)); 762 763 // add bounding box 764 interior->SetBoundingBox(tData.mBoundingBox); 765 766 // set front and back leaf 767 frontData.mNode = interior->GetFront(); 768 backData.mNode = interior->GetBack(); 777 RemoveParentViewCellReferences(tData.mNode->mViewCell); 778 AddViewCellReferences(frontLeaf->mViewCell); 779 AddViewCellReferences(backLeaf->mViewCell); 780 769 781 770 782 interior->mTimeStamp = mTimeStamp ++; … … 774 786 775 787 776 777 void VspTree::ProcessViewCellObjects(ViewCell *parent, ViewCell *front, ViewCell *back) const 778 { 779 if (parent) 780 { 781 // remove the parents from the object pvss 782 ObjectPvsMap::const_iterator oit, oit_end = parent->GetPvs().mEntries.end(); 783 784 for (oit = parent->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 785 { 786 Intersectable *object = (*oit).first; 787 // HACK: make sure that the view cell is removed from the pvs 788 const float high_contri = 9999999; 789 object->mViewCellPvs.RemoveSample(parent, high_contri); 790 } 791 } 792 793 if (front) 794 { 795 // Add front view cell to the object pvsss 796 ObjectPvsMap::const_iterator oit, oit_end = front->GetPvs().mEntries.end(); 797 798 for (oit = front->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 799 { 800 Intersectable *object = (*oit).first; 801 object->mViewCellPvs.AddSample(front, 1); 802 } 803 } 804 805 if (back) 806 { 807 // Add back view cell to the object pvsss 808 ObjectPvsMap::const_iterator oit, oit_end = back->GetPvs().mEntries.end(); 809 810 for (oit = back->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 811 { 812 Intersectable *object = (*oit).first; 813 object->mViewCellPvs.AddSample(back, 1); 788 /*void VspTree::RemoveParentViewCellReferences(VspTraversalData &parentData) 789 { 790 RayInfoContainer::const_iterator it, it_end = parentData.mRays->end(); 791 792 KdLeaf::NewMail(); 793 Intersectable::NewMail(); 794 795 ViewCell *vc = parentData.mNode->mViewCell; 796 797 const float highestContri = 1e25; 798 799 // add contributions from samples to the PVS 800 for (it = parentData.mRays->begin(); it != it_end; ++ it) 801 { 802 VssRay *ray = (*it).mRay; 803 804 Intersectable *obj = ray->mTerminationObject; 805 806 if (obj && !obj->Mailed()) 807 { 808 obj->Mail(); 809 // reduce object reference count by one 810 -- obj->mViewCellPvs; 811 812 set<KdLeaf *>::const_iterator kit, kit_end = obj->mKdLeaves.end(); 813 814 for (kit = obj->mKdLeaves.begin(); kit != kit_end; ++ kit) 815 { 816 KdLeaf *leaf = *kit; 817 818 if (!leaf->Mailed()) 819 { 820 leaf->Mail(); 821 leaf->mViewCellPvs.RemoveSample(vc, highestContri); 822 } 823 } 824 } 825 826 Intersectable *obj = ray->mOriginObject; 827 828 if (obj && !obj->Mailed()) 829 { 830 obj->Mail(); 831 // reduce object reference count by one 832 -- obj->mViewCellPvs; 833 834 set<KdLeaf *>::const_iterator kit, kit_end = obj->mKdLeaves.end(); 835 836 for (kit = obj->mKdLeaves.begin(); kit != kit_end; ++ kit) 837 { 838 KdLeaf *leaf = *kit; 839 840 if (!leaf->Mailed()) 841 { 842 leaf->Mail(); 843 leaf->mViewCellPvs.RemoveSample(vc, highestContri); 844 } 845 } 846 } 847 } 848 }*/ 849 850 851 void VspTree::RemoveParentViewCellReferences(ViewCell *parent) const 852 { 853 KdLeaf::NewMail(); 854 855 // remove the parents from the object pvss 856 ObjectPvsMap::const_iterator oit, oit_end = parent->GetPvs().mEntries.end(); 857 858 for (oit = parent->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 859 { 860 Intersectable *object = (*oit).first; 861 // HACK: make sure that the view cell is removed from the pvs 862 const float high_contri = 9999999; 863 864 // remove reference count of view cells 865 -- object->mViewCellPvs; 866 867 set<KdLeaf *>::const_iterator kit, kit_end = obj->mKdLeaves.end(); 868 869 for (kit = obj->mKdLeaves.begin(); kit != kit_end; ++ kit) 870 { 871 KdLeaf *leaf = *kit; 872 873 if (!leaf->Mailed()) 874 { 875 leaf->mViewCellPvs.RemoveSample(parent, high_contri); 876 leaf->Mail(); 877 } 878 } 879 } 880 } 881 882 883 void VspTree::AddViewCellReferences(ViewCell *vc) const 884 { 885 KdLeaf::NewMail(); 886 887 // Add front view cell to the object pvsss 888 ObjectPvsMap::const_iterator oit, oit_end = front->GetPvs().mEntries.end(); 889 890 for (oit = front->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 891 { 892 Intersectable *object = (*oit).first; 893 894 // increase reference count of view cells 895 ++ object->mViewCellPvs; 896 897 set<KdLeaf *>::const_iterator kit, kit_end = obj->mKdLeaves.end(); 898 899 for (kit = obj->mKdLeaves.begin(); kit != kit_end; ++ kit) 900 { 901 KdLeaf *leaf = *kit; 902 903 if (!leaf->Mailed()) 904 { 905 leaf->mViewCellPvs.AddSample(front, 1); 906 leaf->Mail(); 907 } 814 908 } 815 909 } … … 838 932 float contribution; 839 933 840 if (ray->mTerminationObject) 841 { 842 if (vc->AddPvsSample(ray->mTerminationObject, ray->mPdf, contribution)) 934 Intersectable *obj = ray->mTerminationObject; 935 936 if (obj) 937 { 938 if (vc->AddPvsSample(obj, ray->mPdf, contribution)) 843 939 { 844 940 madeContrib = true; … … 847 943 sc += contribution; 848 944 } 849 850 if (ray->mOriginObject) 851 { 852 if (vc->AddPvsSample(ray->mOriginObject, ray->mPdf, contribution)) 945 946 Intersectable *obj = ray->mOriginObject; 947 948 if (obj) 949 { 950 if (vc->AddPvsSample(obj, ray->mPdf, contribution)) 853 951 { 854 952 madeContrib = true; … … 857 955 sc += contribution; 858 956 } 859 860 sampleContributions += sc; 957 861 958 862 959 if (madeContrib) … … 2772 2869 // delete old leaf node 2773 2870 DEL_PTR(tData.mNode); 2871 DEL_PTR(tData.mNode->mViewCell); 2774 2872 } 2775 2873 … … 3427 3525 3428 3526 // add first candidate for view space partition 3429 mVspTree.mRoot = new VspLeaf(); 3527 VspLeaf *leaf = new VspLeaf(); 3528 mVspTree.mRoot = leaf; 3430 3529 const float prop = mVspTree.mBoundingBox.GetVolume(); 3431 3530 3432 3531 // first vsp traversal data 3433 VspTree::VspTraversalData vData( mVspTree.mRoot,3532 VspTree::VspTraversalData vData(leaf, 3434 3533 0, 3435 3534 &rays, … … 3452 3551 3453 3552 // add first candidate for view space partition 3454 KdLeaf * leaf = new KdLeaf(NULL, 0);3455 leaf->mObjects = objects;3456 3457 mOspTree.mRoot = leaf;3553 KdLeaf *kdleaf = new KdLeaf(NULL, 0); 3554 kdleaf->mObjects = objects; 3555 3556 mOspTree.mRoot = kdleaf; 3458 3557 3459 3558 3460 3559 // first osp traversal data 3461 OspTree::OspTraversalData oData( leaf,3560 OspTree::OspTraversalData oData(kdleaf, 3462 3561 0, 3463 3562 pvsSize, … … 3466 3565 3467 3566 3468 mOspTree.ProcessLeafObjects( leaf, NULL);3567 mOspTree.ProcessLeafObjects(kdleaf, NULL); 3469 3568 3470 3569 // compute first split candidate … … 3529 3628 3530 3629 // add first candidate for view space partition 3531 mVspTree.mRoot = new VspLeaf(); 3630 VspLeaf *vspleaf = new VspLeaf(); 3631 3632 mVspTree.mRoot = vspleaf; 3532 3633 const float prop = mVspTree.mBoundingBox.GetVolume(); 3533 3634 3534 3635 // first vsp traversal data 3535 VspTree::VspTraversalData vData( mVspTree.mRoot,3636 VspTree::VspTraversalData vData(vspleaf, 3536 3637 0, 3537 3638 rays, -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
r1108 r1109 367 367 */ 368 368 void ReplaceChildLink(VspNode *oldChild, VspNode *newChild); 369 369 370 /** Replace front and back child. 370 371 */ 371 void SetupChildLinks(VspNode * b, VspNode *f);372 void SetupChildLinks(VspNode *front, VspNode *back); 372 373 373 374 friend ostream &operator<<(ostream &s, const VspInterior &A) … … 467 468 public: 468 469 /// the current node 469 Vsp Node*mNode;470 VspLeaf *mNode; 470 471 /// current depth 471 472 int mDepth; … … 502 503 {} 503 504 504 VspTraversalData(Vsp Node*node,505 VspTraversalData(VspLeaf *node, 505 506 const int depth, 506 507 RayInfoContainer *rays, … … 732 733 ViewCellsTree *mViewCellsTree; 733 734 735 /** Remove the references of the parent view cell from the kd nodes associated with 736 the objects. 737 */ 738 void RemoveParentViewCellReferences(ViewCell *parent); 739 /** Adds references to the view cell to the kd nodes associated with the objects. 740 */ 741 void AddViewCellReferences(ViewCell *vc) const; 742 734 743 735 744 protected: … … 751 760 752 761 SortableEntry() {} 753 SortableEntry(const int t, const float v, VssRay *r): type(t),754 762 SortableEntry(const int t, const float v, VssRay *r): 763 type(t), value(v), ray(r) 755 764 { 756 765 }
Note: See TracChangeset
for help on using the changeset viewer.