Changeset 551 for trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
- Timestamp:
- 01/18/06 23:35:50 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r548 r551 83 83 // maximum and minimum number of view cells 84 84 environment->GetIntValue("VspBspTree.Termination.maxViewCells", mMaxViewCells); 85 86 environment->GetBoolValue("VspBspTree.splitUseOnlyDrivingAxis", mOnlyDrivingAxis); 87 88 //-- merge options 85 89 environment->GetIntValue("VspBspTree.PostProcess.minViewCells", mMergeMinViewCells); 86 90 environment->GetFloatValue("VspBspTree.PostProcess.maxCostRatio", mMergeMaxCostRatio); 87 88 environment->GetBoolValue("VspBspTree.splitUseOnlyDrivingAxis", mOnlyDrivingAxis);89 91 environment->GetBoolValue("VspBspTree.PostProcess.useRaysForMerge", mUseRaysForMerge); 90 92 … … 116 118 Debug << "max plane candidates: " << mMaxRayCandidates << endl; 117 119 Debug << "randomize: " << randomize << endl; 118 120 Debug << "minimum view cells: " << mMergeMinViewCells << endl; 121 Debug << "using area for pvs: " << mUseAreaForPvs << endl; 119 122 Debug << "Split plane strategy: "; 120 123 if (mSplitPlaneStrategy & RANDOM_POLYGON) … … 870 873 871 874 //TODO: for kd split geometry already is box 872 if (1 && mUseAreaForPvs)875 if (1) 873 876 { 874 877 PolygonContainer::const_iterator it, it_end = tData.mGeometry->mPolys.end(); … … 1012 1015 { // volume 1013 1016 pBack = pFront = pOverall * 0.5f; 1017 1018 #if 0 1014 1019 // box length substitute for probability 1015 #if 01016 1020 const float minBox = box.Min(axis); 1017 1021 const float maxBox = box.Max(axis); … … 1603 1607 { 1604 1608 ViewCell::NewMail(); 1605 CollectViewCells(mRoot, onlyValid, viewCells); 1609 1610 CollectViewCells(mRoot, onlyValid, viewCells, true); 1606 1611 } 1607 1612 … … 1901 1906 1902 1907 1908 typedef pair<BspNode *, BspNodeGeometry *> bspNodePair; 1909 1903 1910 int VspBspTree::FindNeighbors(BspNode *n, vector<BspLeaf *> &neighbors, 1904 1911 const bool onlyUnmailed) const 1905 1912 { 1906 BspNodeGeometry geom; 1907 ConstructGeometry(n, geom); 1908 1909 stack<BspNode *> nodeStack; 1910 nodeStack.push(mRoot); 1911 1913 stack<bspNodePair> nodeStack; 1914 1915 BspNodeGeometry nodeGeom; 1916 ConstructGeometry(n, nodeGeom); 1917 1912 1918 // split planes from the root to this node 1913 1919 // needed to verify that we found neighbor leaf … … 1915 1921 ExtractHalfSpaces(n, halfSpaces); 1916 1922 1923 1924 BspNodeGeometry *rgeom = new BspNodeGeometry(); 1925 ConstructGeometry(mRoot, *rgeom); 1926 1927 nodeStack.push(bspNodePair(mRoot, rgeom)); 1928 1929 1917 1930 while (!nodeStack.empty()) 1918 1931 { 1919 BspNode *node = nodeStack.top(); 1932 BspNode *node = nodeStack.top().first; 1933 BspNodeGeometry *geom = nodeStack.top().second; 1934 1920 1935 nodeStack.pop(); 1921 1936 1922 if (node->IsLeaf()) 1923 1924 { // test if this leaf is in valid view space 1925 if (node->TreeValid() && 1926 node != n && 1927 (!onlyUnmailed || !node->Mailed())) 1937 bool isAdjacent = true; 1938 1939 // test all planes of current node if still adjacent 1940 for (int i = 0; (i < halfSpaces.size()) && isAdjacent && (node != n); ++ i) 1941 { 1942 const int cf = 1943 Polygon3::ClassifyPlane(geom->mPolys, 1944 halfSpaces[i], 1945 mEpsilon); 1946 1947 if (cf == Polygon3::BACK_SIDE) 1928 1948 { 1929 // test all planes of current node if candidate really 1930 // is neighbour 1931 BspNodeGeometry neighborCandidate; 1932 ConstructGeometry(node, neighborCandidate); 1933 1934 bool isAdjacent = true; 1935 for (int i = 0; (i < halfSpaces.size()) && isAdjacent; ++ i) 1949 isAdjacent = false; 1950 } 1951 } 1952 1953 if (isAdjacent) 1954 { 1955 1956 if (node->IsLeaf()) 1957 { 1958 // test if this leaf is in valid view space 1959 if (node->TreeValid() && 1960 node != n && 1961 (!onlyUnmailed || !node->Mailed())) 1936 1962 { 1937 const int cf = 1938 Polygon3::ClassifyPlane(neighborCandidate.mPolys, 1939 halfSpaces[i], 1940 mEpsilon); 1941 1942 if (cf == Polygon3::BACK_SIDE) 1943 isAdjacent = false; 1963 // neighbor was found 1964 neighbors.push_back(dynamic_cast<BspLeaf *>(node)); 1944 1965 } 1945 // neighbor was found1946 if (isAdjacent)1947 neighbors.push_back(dynamic_cast<BspLeaf *>(node));1948 1966 } 1949 }1950 else1951 {1952 BspInterior *interior = dynamic_cast<BspInterior *>(node);1953 1954 const int cf = Polygon3::ClassifyPlane(geom.mPolys,1955 interior->GetPlane(),1956 mEpsilon);1957 1958 if (cf == Polygon3::FRONT_SIDE)1959 nodeStack.push(interior->GetFront());1960 1967 else 1961 if (cf == Polygon3::BACK_SIDE) 1962 nodeStack.push(interior->GetBack()); 1968 { 1969 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1970 1971 const int cf = Polygon3::ClassifyPlane(nodeGeom.mPolys, 1972 interior->GetPlane(), 1973 mEpsilon); 1974 1975 BspNode *front = interior->GetFront(); 1976 BspNode *back = interior->GetBack(); 1977 1978 BspNodeGeometry *fGeom = new BspNodeGeometry(); 1979 BspNodeGeometry *bGeom = new BspNodeGeometry(); 1980 1981 geom->SplitGeometry(*fGeom, 1982 *bGeom, 1983 interior->GetPlane(), 1984 mBox, 1985 mEpsilon); 1986 1987 if (cf == Polygon3::FRONT_SIDE) 1988 { 1989 nodeStack.push(bspNodePair(interior->GetFront(), fGeom)); 1990 DEL_PTR(bGeom); 1991 } 1963 1992 else 1964 1993 { 1965 // random decision 1966 nodeStack.push(interior->GetBack()); 1967 nodeStack.push(interior->GetFront()); 1994 if (cf == Polygon3::BACK_SIDE) 1995 { 1996 nodeStack.push(bspNodePair(interior->GetBack(), bGeom)); 1997 DEL_PTR(fGeom); 1998 } 1999 else 2000 { // random decision 2001 nodeStack.push(bspNodePair(front, fGeom)); 2002 nodeStack.push(bspNodePair(back, bGeom)); 2003 } 1968 2004 } 1969 } 2005 } 2006 } 2007 2008 DEL_PTR(geom); 1970 2009 } 1971 2010 … … 2642 2681 if (0) 2643 2682 { 2683 cout << "finding additional merge candidates using geometry" << endl; 2644 2684 vector<BspLeaf *> leaves; 2645 2685 CollectLeaves(leaves, true); … … 2702 2742 mergeStats.Start(); 2703 2743 // TODO: REMOVE LATER for performance! 2704 const bool showMergeStats = true;2744 const bool showMergeStats = false; 2705 2745 //BspMergeCandidate::sOverallCost = mBox.SurfaceArea() * mStat.maxPvs; 2706 2746 long startTime = GetTime(); 2707 2747 2708 2748 if (mUseRaysForMerge) 2749 { 2750 cout << "collecting merge candidates (rays) ... "; 2709 2751 mergeStats.nodes = CollectMergeCandidates(rays); 2752 cout << "fininshed collecting candidates" << endl; 2753 } 2710 2754 else 2711 2755 { … … 2714 2758 mergeStats.nodes = CollectMergeCandidates(leaves); 2715 2759 } 2760 2716 2761 2717 2762 mergeStats.collectTime = TimeDiff(startTime, GetTime()); … … 2722 2767 int pass = 0; 2723 2768 const int nextPass = 200; 2769 2770 cout << "starting merge ... "; 2724 2771 2725 2772 //-- use priority queue to merge leaf pairs … … 2744 2791 2745 2792 MergeViewCells(mc.GetLeaf1(), mc.GetLeaf2()); 2746 -- nViewCells; 2747 2793 2748 2794 2749 2795 // increase absolute merge cost … … 2774 2820 << "#CurrentPvs\n" << mc.GetLeaf1()->GetViewCell()->GetPvs().GetSize() << endl; 2775 2821 2822 cout << "exporting view cells ... "; 2776 2823 ViewCellContainer viewCells; 2777 2824 CollectViewCells(mRoot, false, viewCells); 2778 2825 2826 2779 2827 char s[64]; 2780 2828 sprintf(s, "merged_viewcells%07d.x3d", nViewCells); … … 2784 2832 { 2785 2833 exporter->ExportGeometry(objects); 2786 Debug << "vc size " << viewCells.size() << endl;2834 Debug << "vc size " << (int)viewCells.size() << " merge queue size: " << (int)mMergeQueue.size() << endl; 2787 2835 ViewCellContainer::const_iterator it, it_end = viewCells.end(); 2788 2836 … … 2794 2842 delete exporter; 2795 2843 } 2844 cout << "finished " << endl; 2796 2845 } 2797 2846 } 2847 2848 -- nViewCells; 2798 2849 ++ mergeStats.merged; 2799 2800 2850 } 2801 2851 // merge candidate not valid, because one of the leaves was already … … 2807 2857 } 2808 2858 } 2809 2859 cout << "finished merge" << endl; 2810 2860 mergeStats.mergeTime = TimeDiff(startTime, GetTime()); 2811 2861 mergeStats.Stop(); … … 2911 2961 2912 2962 2913 float GetShuffledVcCost(BspLeaf *leaf, BspViewCell *vc1, BspViewCell *vc2, bool useArea)2963 float VspBspTree::GetShuffledVcCost(BspLeaf *leaf, BspViewCell *vc1, BspViewCell *vc2) const 2914 2964 { 2915 2965 //const int pvs1 = SubtractedPvsSize(vc1, leaf, *leaf->mPvs); … … 2917 2967 const int pvs2 = AddedPvsSize(vc2->GetPvs(), *leaf->mPvs); 2918 2968 2969 if (pvs1 + pvs2 > mViewCellsManager->GetMaxPvsSize()) 2970 return 1e15f; 2971 2919 2972 float p1, p2; 2920 2973 2921 if ( useArea)2974 if (mUseAreaForPvs) 2922 2975 { 2923 2976 p1 = vc1->GetArea() - leaf->mProbability; … … 3004 3057 // the view cell should not be empty after the shuffle 3005 3058 if (vc1->mLeaves.size() > 1) 3006 shuffledCost1 = GetShuffledVcCost(leaf1, vc1, vc2 , mUseAreaForPvs);3059 shuffledCost1 = GetShuffledVcCost(leaf1, vc1, vc2); 3007 3060 if (vc2->mLeaves.size() > 1) 3008 shuffledCost2 = GetShuffledVcCost(leaf2, vc2, vc1 , mUseAreaForPvs);3061 shuffledCost2 = GetShuffledVcCost(leaf2, vc2, vc1); 3009 3062 3010 3063 // shuffling unsuccessful
Note: See TracChangeset
for help on using the changeset viewer.