Changeset 1686 for GTP/trunk/Lib/Vis/Preprocessing/src
- Timestamp:
- 10/27/06 03:05:49 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1684 r1686 131 131 } 132 132 133 133 134 void BvhLeaf::CollectObjects(ObjectContainer &objects) 134 135 { 135 ObjectContainer::const_iterator oit, oit_end = objects.end();136 for (oit = objects.begin(); oit != oit_end; ++ oit)136 ObjectContainer::const_iterator oit, oit_end = mObjects.end(); 137 for (oit = mObjects.begin(); oit != oit_end; ++ oit) 137 138 { 138 139 objects.push_back(*oit); … … 330 331 return nRays; 331 332 } 332 333 334 void BvHierarchy::UpdateNode(const BvhSubdivisionCandidate &sc)335 {336 BvhInterior *node = NULL;//sc->mParentData.mNode;337 //AssociateObjectsWithLeaf(node->GetBack());338 //AssociateObjectsWithLeaf(node->GetFront());339 340 node->mRenderCostDecr = sc.GetRenderCostDecrease();341 node->mPvsEntriesIncr = sc.GetPvsEntriesIncr();342 }343 333 344 334 … … 906 896 else 907 897 { 908 // just add up areas of the object bbs898 // just add up areas of the objects itself 909 899 // (as we are not sampling volumetric visibility, 910 900 // this should provide better heuristics 911 const float area = obox.SurfaceArea();901 const float area = //obox.SurfaceArea(); 912 902 913 903 al += area; … … 1905 1895 //-- add first candidate for object space partition 1906 1896 1907 BvhSubdivisionCandidate *oSubdivisionCandidate = 1908 new BvhSubdivisionCandidate(oData); 1909 1897 BvhSubdivisionCandidate *oSubdivisionCandidate = new BvhSubdivisionCandidate(oData); 1898 1899 // evaluate priority 1910 1900 EvalSubdivisionCandidate(*oSubdivisionCandidate); 1911 1901 bvhLeaf->SetSubdivisionCandidate(oSubdivisionCandidate); … … 2115 2105 float BvHierarchy::GetMemUsage() const 2116 2106 { 2117 return (float) 2118 (sizeof(BvHierarchy) 2119 + mBvhStats.Leaves() * sizeof(BvhLeaf) 2120 + mBvhStats.Interior() * sizeof(BvhInterior) 2121 ) / (1024.0f * 1024.0f); 2122 } 2123 2124 2125 SubdivisionCandidate *BvHierarchy::CreateSubdivisionCandidate(BvhInterior *oldNode) 2126 { 2127 return new BvhSubdivisionCandidate(BvhTraversalData()); 2128 } 2129 2130 2131 BvhNode *BvHierarchy::SubdivideAndCopy(SplitQueue &tQueue, 2132 SubdivisionCandidate *splitCandidate, 2133 const bool globalCriteriaMet, 2134 BvhNode *originalNode) 2135 { 2136 BvhSubdivisionCandidate *sc = dynamic_cast<BvhSubdivisionCandidate *>(splitCandidate); 2107 return (float)(sizeof(BvHierarchy) 2108 + mBvhStats.Leaves() * sizeof(BvhLeaf) 2109 + mBvhStats.Interior() * sizeof(BvhInterior) 2110 ) / float(1024 * 1024); 2111 } 2112 2113 2114 BvhNode *BvHierarchy::SubdivideAndCopy(SplitQueue &tQueue, 2115 SubdivisionCandidate *splitCandidate) 2116 { 2117 BvhSubdivisionCandidate *sc = 2118 dynamic_cast<BvhSubdivisionCandidate *>(splitCandidate); 2137 2119 BvhTraversalData &tData = sc->mParentData; 2138 2120 … … 2149 2131 2150 2132 BvhInterior *oldInterior = dynamic_cast<BvhInterior *>(oldNode); 2151 //sc->SetSplitPlane(oldInterior->mSplitPlane); 2152 2133 2153 2134 oldInterior->GetFront()->CollectObjects(sc->mFrontObjects); 2154 2135 oldInterior->GetBack()->CollectObjects(sc->mBackObjects); 2155 EvalSubdivisionCandidate(*sc); 2136 2137 // evaluate the changes in render cost and pvs entries 2138 EvalSubdivisionCandidate(*sc, false); 2156 2139 2157 2140 // create new interior node and two leaf node 2158 2141 currentNode = SubdivideNode(*sc, tFrontData, tBackData); 2159 2142 2160 // evaluate the changes in render cost and pvs entries2161 EvalSubdivisionCandidate(*sc, false);2162 2163 2143 currentNode->mRenderCostDecr = oldNode->mRenderCostDecr + sc->GetRenderCostDecrease(); 2164 2144 currentNode->mPvsEntriesIncr = oldNode->mPvsEntriesIncr + sc->GetPvsEntriesIncr(); -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r1684 r1686 604 604 // hacks in order to provide interleaved heurisitcs 605 605 606 void UpdateNode(const BvhSubdivisionCandidate &sc); 607 608 SubdivisionCandidate *CreateSubdivisionCandidate(BvhInterior *oldNode); 609 610 BvhNode *SubdivideAndCopy(SplitQueue &tQueue, 611 SubdivisionCandidate *splitCandidate, 612 const bool globalCriteriaMet, 613 BvhNode *originalNode); 606 BvhNode *SubdivideAndCopy(SplitQueue &tQueue, SubdivisionCandidate *splitCandidate); 614 607 615 608 ///////////////////////////////// -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1684 r1686 361 361 362 362 363 void HierarchyManager::ConstructInterleavedWithGradient(const VssRayContainer &sampleRays, 363 void HierarchyManager::ConstructInterleavedWithGradient(const VssRayContainer &sampleRays, 364 364 const ObjectContainer &objects, 365 365 AxisAlignedBox3 *forcedViewSpace) … … 456 456 { 457 457 // decide upon next split type 458 const float vspPriority = viewSpaceQueue.Top() ? viewSpaceQueue.Top()->GetPriority() : -1e20 ;459 const float ospPriority = objectSpaceQueue.Top() ? objectSpaceQueue.Top()->GetPriority() : -1e20 ;458 const float vspPriority = viewSpaceQueue.Top() ? viewSpaceQueue.Top()->GetPriority() : -1e20f; 459 const float ospPriority = objectSpaceQueue.Top() ? objectSpaceQueue.Top()->GetPriority() : -1e20f; 460 460 461 461 cout << "new decicion, vsp: " << vspPriority << ", osp: " << ospPriority << endl; … … 945 945 while (!splitQueue.Empty()) 946 946 { 947 const float threshold = oldCandidate ? oldCandidate->GetPriority() : 1e20 ;947 const float threshold = oldCandidate ? oldCandidate->GetPriority() : 1e20f; 948 948 SubdivisionCandidate *sc = NextSubdivisionCandidate(splitQueue); 949 949 … … 1630 1630 1631 1631 1632 void HierarchyManager::EvaluateSubdivision(const VssRayContainer &sampleRays, 1633 const ObjectContainer &objects, 1634 const string &filename) 1635 { 1636 mHierarchyStats.Reset(); 1637 mHierarchyStats.Start(); 1638 1639 mHierarchyStats.mNodes = 2; 1640 1632 void HierarchyManager::EvaluateSubdivision(const VssRayContainer &sampleRays, const ObjectContainer &objects, 1633 const string &filename) 1634 { 1641 1635 VspTree *oldVspTree = mVspTree; 1636 ViewCellsManager *vm = mVspTree->mViewCellsManager; 1642 1637 BvHierarchy *oldHierarchy = mBvHierarchy; 1643 1638 1644 1639 mBvHierarchy = new BvHierarchy(); 1645 1640 mBvHierarchy->mHierarchyManager = this; 1646 1641 mBvHierarchy->mViewCellsManager = vm; 1642 1647 1643 mVspTree = new VspTree(); 1648 1644 mVspTree->mHierarchyManager = this; 1645 mVspTree->mViewCellsManager = vm; 1649 1646 1650 1647 // create first nodes … … 1652 1649 InitialiseObjectSpaceSubdivision(objects); 1653 1650 1654 // hack: assume that object space can be seen from view space1655 mHierarchyStats.mTotalCost = mInitialRenderCost = (float)objects.size();1656 1657 // only one entry for start1658 mHierarchyStats.mPvsEntries = 1;1659 mHierarchyStats.mMemory = (float)ObjectPvs::GetEntrySizeByte();1660 1661 EvalSubdivisionStats();1662 Debug << "setting total cost to " << mHierarchyStats.mTotalCost << endl;1663 1664 1651 const long startTime = GetTime(); 1665 cout << "Constructing view space / object space tree ... \n"; 1666 1667 ExportStats(filename, objects, oldVspTree, oldHierarchy); 1668 1669 cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 1670 1671 mHierarchyStats.Stop(); 1672 mVspTree->mVspStats.Stop(); 1673 1674 FinishObjectSpaceSubdivision(objects, !mUseMultiLevelConstruction); 1675 } 1676 1677 1678 void HierarchyManager::ExportStats(const string &mergeStats, 1679 const ObjectContainer &objects, 1680 VspTree *oldVspTree, 1681 BvHierarchy *oldHierarchy) 1682 { 1652 cout << "Constructing evaluation hierarchies ... \n"; 1653 1683 1654 ofstream stats; 1684 stats.open( mergeStats.c_str());1655 stats.open(filename.c_str()); 1685 1656 SplitQueue tQueue; 1686 1657 … … 1688 1659 VspNode *oldVspRoot = oldVspTree->GetRoot(); 1689 1660 1690 SubdivisionCandidate *firstVsp = mVspTree->CreateSubdivisionCandidate(dynamic_cast<VspInterior *>(oldVspRoot)); 1691 SubdivisionCandidate *firstBvh = mBvHierarchy->CreateSubdivisionCandidate(dynamic_cast<BvhInterior *>(oldBvhRoot)); 1692 1693 /* 1694 BvhQueue bvhQueue; 1695 VspQueue vspQueue; 1696 //ViewCellsQueue viewCellsQueue; 1697 1698 bvhQueue.push(mHierarchyManager->mBvHierarchy->GetRoot()); 1699 vspQueue.push(mHierarchyManager->GetVspTree()->GetRoot()); 1700 1701 int numSteps = 1; 1702 1703 const AxisAlignedBox3 box = mViewSpaceBox; 1704 const float vol = box.GetVolume(); 1705 */ 1706 float totalRenderCost = (float)objects.size();//(float)mViewCellsTree->GetPvsSize(mViewCellsTree->GetRoot()); 1707 int entriesInPvs = 1;//mViewCellsTree->GetPvsEntries(mViewCellsTree->GetRoot()); 1661 RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 1662 1663 SubdivisionCandidate *firstVsp = mVspTree->PrepareConstruction(sampleRays, *viewSpaceRays); 1664 SubdivisionCandidate *firstBvh = mBvHierarchy->PrepareConstruction(sampleRays, objects); 1665 1666 firstVsp->mEvaluationHack = oldVspRoot; 1667 firstBvh->mEvaluationHack = oldBvhRoot; 1668 1669 tQueue.Push(firstVsp); 1670 tQueue.Push(firstBvh); 1671 1672 ExportStats(stats, tQueue, objects); 1673 1674 cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 1675 RemoveRayRefs(objects); 1676 1677 // view cells needed only for evaluation 1678 ViewCellContainer viewCells; 1679 mVspTree->CollectViewCells(viewCells, false); 1680 CLEAR_CONTAINER(viewCells); 1681 1682 // helper trees can be destroyed 1683 DEL_PTR(mVspTree); 1684 DEL_PTR(mBvHierarchy); 1685 1686 // reset hierarchies 1687 mVspTree = oldVspTree; 1688 mBvHierarchy = oldHierarchy; 1689 1690 // reinstall old bv refs 1691 vector<BvhLeaf *> leaves; 1692 mBvHierarchy->CollectLeaves(leaves); 1693 vector<BvhLeaf *>::const_iterator bit, bit_end = leaves.end(); 1694 1695 for (bit = leaves.begin(); bit != bit_end; ++ bit) 1696 { 1697 mBvHierarchy->AssociateObjectsWithLeaf(*bit); 1698 } 1699 } 1700 1701 1702 void HierarchyManager::ExportStats(ofstream &stats, 1703 SplitQueue &tQueue, 1704 const ObjectContainer &objects) 1705 { 1706 float totalRenderCost = (float)objects.size(); 1707 int entriesInPvs = 1; 1708 int steps = 0; 1708 1709 1709 1710 cout << "exporting vsposp stats ... " << endl; … … 1718 1719 //-- or the reverse order of subdivision for subdivision-only 1719 1720 //-- view cell hierarchies. 1720 int steps = 0;1721 1721 1722 while (!tQueue.Empty()) 1722 1723 { … … 1724 1725 1725 1726 cout << "next candidate: " << nextCandidate->GetPriority() << endl; 1726 nextCandidate->Apply(tQueue, false); 1727 1728 if (nextCandidate->Type() == SubdivisionCandidate::VIEW_SPACE) 1729 mVspTree->SubdivideAndCopy(tQueue, nextCandidate); 1730 else 1731 mBvHierarchy->SubdivideAndCopy(tQueue, nextCandidate); 1727 1732 1728 1733 totalRenderCost -= nextCandidate->GetRenderCostDecrease(); … … 1733 1738 const float memoryCost = (float)entriesInPvs * (float)ObjectPvs::GetEntrySize(); 1734 1739 UpdateStats(stats, steps, totalRenderCost, entriesInPvs, memoryCost, false); 1735 1736 /*if (nextCandidate->Type() == SubdivisionCandidate::VIEW_SPACE) 1737 { 1738 cout << "v"; 1739 VspNode *vspNode = NULL; 1740 1741 //vspNode->mParent->SetupChildLink(); 1742 if (!vspNode->IsLeaf()) 1743 { 1744 SubdivisionCandidate sc = new VspSubdivisionCandidate(); 1745 1746 mVspTree->EvalPriority(sc, false); 1747 1748 UpdateStats(stats, splits 1749 totalRenderCost -= vspNode->mRenderCostDecr; 1750 entriesInPvs += vspNode->mPvsEntriesIncr; 1751 1752 steps ++; 1753 1754 const float memoryCost = (float)entriesInPvs * (float)ObjectPvs::GetEntrySize(); 1755 UpdateStats(stats, steps, totalRenderCost, entriesInPvs, memoryCost, true); 1756 1757 VspNode *front = dynamic_cast<VspInterior *>(vspNode)->GetFront(); 1758 VspNode *back= dynamic_cast<VspInterior *>(vspNode)->GetBack(); 1759 1760 RecreateLeaves(); 1761 if (!front->IsLeaf()) 1762 { 1763 SuddivisionCandidate *candidate = new SubdivisionCandidate; 1764 candidate->mParentData.mNode ? front; 1765 candidate->mParentData.mrays = 0; 1766 1767 SuddivisionCandidate *candidate2 = new SubdivisionCandidate; 1768 candidate->mParentData.mNode = back; 1769 candidate->mParentData.mrays = 0; 1770 1771 1772 vspQueue.push(front); 1773 if (!back->IsLeaf()) 1774 vspQueue.push(back); 1775 1776 } 1777 } 1778 else // object space split 1779 { 1780 cout << "o"; 1781 1782 BvhNode *bvhNode = NULL; 1783 1784 if (!bvhNode->IsLeaf()) 1785 { 1786 totalRenderCost -= bvhNode->mRenderCostDecr; 1787 entriesInPvs += bvhNode->mPvsEntriesIncr; 1788 1789 steps ++; 1790 const float memoryCost = (float)entriesInPvs * (float)ObjectPvs::GetEntrySize(); 1791 UpdateStats(stats, steps, totalRenderCost, entriesInPvs, memoryCost, false); 1792 1793 // BvhNode *front = dynamic_cast<BvhInterior *>(bvhNode)->GetFront(); 1794 // BvhNode *back= dynamic_cast<BvhInterior *>(bvhNode)->GetBack(); 1795 1796 // if (!front->IsLeaf()) 1797 // bvhQueue.push(front); 1798 // if (!back->IsLeaf()) 1799 // bvhQueue.push(back); 1800 } 1801 }*/ 1802 } 1740 } 1741 1803 1742 stats.close(); 1804 1743 } 1805 1744 1806 /* 1807 while (!(bvhQueue.empty() && vspQueue.empty())) 1808 { 1809 const float vspCost = !vspQueue.empty() ? vspQueue.top()->GetMergeCost() : -99999999.0; 1810 const float ospCost = !bvhQueue.empty() ? bvhQueue.top()->GetMergeCost() : -99999999.0; 1811 1812 if (vspCost > ospCost) 1813 { 1814 cout << "vsp: " << (int)-vspCost << endl; 1815 cout << "v"; 1816 VspNode *vspNode = vspQueue.top(); 1817 1818 if (!vspNode) 1819 { 1820 cerr << "big error!" << endl; 1821 break; 1822 } 1823 1824 vspQueue.pop(); 1825 1826 vspNode->mParent->SetupChildLink(); 1827 1828 if (!vspNode->IsLeaf()) 1829 { 1830 SubdivisionCandidate sc = new VspSubdivisionCandidate(); 1831 1832 mVspTree->EvalPriority(sc, false); 1833 1834 UpdateStats(stats, splits 1835 totalRenderCost -= vspNode->mRenderCostDecr; 1836 entriesInPvs += vspNode->mPvsEntriesIncr; 1837 1838 splits ++; 1839 1840 const float memoryCost = (float)entriesInPvs * (float)ObjectPvs::GetEntrySize(); 1841 UpdateStats(stats, i, totalRenderCost, entriesInPvs, memoryCost, true); 1842 1843 VspNode *front = dynamic_cast<VspInterior *>(vspNode)->GetFront(); 1844 VspNode *back= dynamic_cast<VspInterior *>(vspNode)->GetBack(); 1845 1846 RecreateLeaves(); 1847 if (!front->IsLeaf()) 1848 { 1849 SuddivisionCandidate *candidate = new SubdivisionCandidate; 1850 candidate->mParentData.mNode ? front; 1851 candidate->mParentData.mrays = 0; 1852 SuddivisionCandidate *candidate2 = new SubdivisionCandidate; 1853 candidate->mParentData.mNode = back; 1854 candidate->mParentData.mrays = 0; 1855 1856 1857 vspQueue.push(front); 1858 if (!back->IsLeaf()) 1859 vspQueue.push(back); 1860 } 1861 } 1862 } 1863 else // object space split 1864 { 1865 cout << "o"; 1866 BvhNode *bvhNode = bvhQueue.top(); 1867 cout << "bvh: " << (int)-ospCost << endl; 1868 if (!bvhNode) 1869 { 1870 cerr << "big error!" << endl; 1871 break; 1872 } 1873 bvhQueue.pop(); 1874 1875 if (!bvhNode->IsLeaf()) 1876 { 1877 totalRenderCost -= bvhNode->mRenderCostDecr; 1878 entriesInPvs += bvhNode->mPvsEntriesIncr; 1879 1880 i ++; 1881 const float memoryCost = (float)entriesInPvs * (float)ObjectPvs::GetEntrySize(); 1882 UpdateStats(stats, i, totalRenderCost, entriesInPvs, memoryCost, false); 1883 1884 BvhNode *front = dynamic_cast<BvhInterior *>(bvhNode)->GetFront(); 1885 BvhNode *back= dynamic_cast<BvhInterior *>(bvhNode)->GetBack(); 1886 1887 if (!front->IsLeaf()) 1888 bvhQueue.push(front); 1889 if (!back->IsLeaf()) 1890 bvhQueue.push(back); 1891 } 1892 } 1893 cout << i << endl; 1894 1895 } 1896 */ 1897 1898 1899 } 1745 1746 } -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r1684 r1686 235 235 inline float GetMemoryConst() const { return mMemoryConst; } 236 236 237 float mInitialRenderCost; 237 238 void EvaluateSubdivision(const VssRayContainer &sampleRays, 239 const ObjectContainer &objects, 240 const string &filename); 241 242 float mInitialRenderCost; 243 238 244 239 245 protected: … … 440 446 441 447 442 void EvaluateSubdivision(const VssRayContainer &sampleRays, 443 const ObjectContainer &objects, 444 const string &filename); 445 446 void ExportStats(const string &mergeStats, const ObjectContainer &objects, VspTree *oldVspTree, BvHierarchy *oldBvHierarchy); 448 /////////////////////////// 449 450 void ExportStats(ofstream &stats, SplitQueue &tQueue, const ObjectContainer &objects); 451 447 452 protected: 448 453 -
GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h
r1680 r1686 110 110 virtual int NumberOfFaces() const = 0; 111 111 virtual int Type() const = 0; 112 112 virtual float GetArea() const {return 0; } 113 113 virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0; 114 114 -
GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h
r1615 r1686 186 186 Vector3 GetNormal(const int idx) const; 187 187 188 float GetArea() const {return mItem.GetArea();} 188 189 int Type() const 189 190 { … … 193 194 int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 194 195 195 int GetRandomVisibleSurfacePoint( 196 Vector3 &point, 197 Vector3 &normal, 198 const Vector3 &viewpoint, 199 const int maxTries); 196 int GetRandomVisibleSurfacePoint(Vector3 &point, 197 Vector3 &normal, 198 const Vector3 &viewpoint, 199 const int maxTries); 200 200 }; 201 201 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
r1632 r1686 1017 1017 // add predefined view cell to leaf 1018 1018 viewCell = dynamic_cast<BspViewCell *>(tData.mViewCell); 1019 // from now on out of bounds cell can be handled as any other cell, 1020 // responsibility for deleting has been shifted 1019 1020 // out of bounds cell can be handled as any other view cell, 1021 // responsibility for deleting it has the view cells manager. 1021 1022 if (IsOutOfBounds(viewCell)) 1022 1023 { -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1680 r1686 61 61 mViewCellsFinished(false), 62 62 mMaxPvsSize(9999999), 63 mMinPvsSize(0), // one means only empty view cells are invalid63 mMinPvsSize(0), 64 64 mMaxPvsRatio(1.0), 65 65 mViewCellPvsIsUpdated(false), … … 907 907 908 908 while (castSamples < numSamples) 909 { 909 { 910 /////////////// 911 //-- we have to use uniform sampling strategy for construction rays 912 910 913 VssRayContainer evaluationSamples; 911 912 914 const int samplingType = mEvaluationSamplingType; 913 /* dirSamples ? 914 Preprocessor::DIRECTION_BASED_DISTRIBUTION : 915 Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION; 916 */ 915 917 916 long startTime = GetTime(); 918 919 //-- construction rays => we use uniform samples for this920 917 921 918 cout << "casting " << samplesPerPass << " samples ... "; … … 943 940 startTime = GetTime(); 944 941 cout << "compute new statistics ... " << endl; 945 942 943 /////////// 944 //-- output stats 945 946 sprintf(str, "-%09d-eval.log", castSamples); 947 string fileName = string(statsPrefix) + string(str); 948 946 949 /////////////// 947 950 //-- propagate pvs or pvs size information … … 949 952 ObjectPvs pvs; 950 953 UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), pvs); 951 952 ///////////953 //-- output stats954 sprintf(str, "-%09d-eval.log", castSamples);955 string fileName = string(statsPrefix) + string(str);956 954 957 955 ExportStats(fileName); … … 5535 5533 } 5536 5534 5535 //////////////// 5537 5536 //-- for directional sampling it is important to count only contributions 5538 5537 //-- made in one direction! … … 5618 5617 } 5619 5618 5620 5619 #if 1 5621 5620 #if TEST_EVALUATION 5622 5621 void VspOspViewCellsManager::EvalViewCellPartition() … … 5699 5698 } 5700 5699 5700 #else 5701 5702 void VspOspViewCellsManager::EvalViewCellPartition() 5703 { 5704 int samplesPerPass; 5705 int numSamples; 5706 int castSamples = 0; 5707 char str[64]; 5708 5709 Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samplesPerPass", samplesPerPass); 5710 Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samples", numSamples); 5711 5712 char statsPrefix[100]; 5713 Environment::GetSingleton()->GetStringValue("ViewCells.Evaluation.statsPrefix", statsPrefix); 5714 5715 Debug << "view cell evaluation samples per pass: " << samplesPerPass << endl; 5716 Debug << "view cell evaluation samples: " << numSamples << endl; 5717 Debug << "view cell stats prefix: " << statsPrefix << endl; 5718 5719 // should directional sampling be used? 5720 bool dirSamples = 5721 (mEvaluationSamplingType == SamplingStrategy::DIRECTION_BASED_DISTRIBUTION); 5722 5723 cout << "reseting pvs ... "; 5724 5725 const bool startFromZero = true; 5726 5727 // reset pvs and start over from zero 5728 if (startFromZero) 5729 { 5730 mViewCellsTree->ResetPvs(); 5731 } 5732 else // start from current sampless 5733 { 5734 // statistics before casting more samples 5735 cout << "compute new statistics ... "; 5736 sprintf(str, "-%09d-eval.log", castSamples); 5737 string fName = string(statsPrefix) + string(str); 5738 5739 mViewCellsTree->ExportStats(fName); 5740 cout << "finished" << endl; 5741 } 5742 5743 cout << "finished" << endl; 5744 cout << "Evaluating view cell partition ... " << endl; 5745 5746 while (castSamples < numSamples) 5747 { 5748 /////////////// 5749 //-- we have to use uniform sampling strategy for construction rays 5750 5751 VssRayContainer evaluationSamples; 5752 const int samplingType = mEvaluationSamplingType; 5753 5754 long startTime = GetTime(); 5755 5756 cout << "casting " << samplesPerPass << " samples ... "; 5757 Debug << "casting " << samplesPerPass << " samples ... "; 5758 5759 CastPassSamples(samplesPerPass, samplingType, evaluationSamples); 5760 5761 castSamples += samplesPerPass; 5762 5763 Real timeDiff = TimeDiff(startTime, GetTime()); 5764 Debug << "finished in " << timeDiff * 1e-3 << " secs" << endl; 5765 cout << "finished in " << timeDiff * 1e-3 << " secs" << endl; 5766 5767 cout << "computing sample contributions of " << (int)evaluationSamples.size() << " samples ... "; 5768 Debug << "computing sample contributions of " << (int)evaluationSamples.size() << " samples ... "; 5769 5770 startTime = GetTime(); 5771 5772 ComputeSampleContributions(evaluationSamples, true, false); 5773 5774 timeDiff = TimeDiff(startTime, GetTime()); 5775 cout << "finished in " << timeDiff * 1e-3 << " secs" << endl; 5776 Debug << "finished in " << timeDiff * 1e-3 << " secs" << endl; 5777 5778 startTime = GetTime(); 5779 cout << "compute new statistics ... " << endl; 5780 5781 /////////// 5782 //-- output stats 5783 5784 sprintf(str, "-%09d-eval.log", castSamples); 5785 string filename = string(statsPrefix) + string(str); 5786 5787 mHierarchyManager->EvaluateSubdivision(evaluationSamples, mPreprocessor->mObjects, filename); 5788 5789 timeDiff = TimeDiff(startTime, GetTime()); 5790 cout << "finished in " << timeDiff * 1e-3 << " secs" << endl; 5791 Debug << "statistis compted in " << timeDiff * 1e-3 << " secs" << endl; 5792 5793 disposeRays(evaluationSamples, NULL); 5794 } 5795 } 5701 5796 #endif 5702 } 5797 #endif 5798 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1679 r1686 377 377 void CollectViewCells(const int n); 378 378 379 /** Sets current view cells set to active, i.e., the sampling is done in this view cell set. 379 /** Sets current view cells set to active, 380 i.e., the sampling is done in this view cell set. 380 381 */ 381 382 void SetViewCellsActive(); … … 393 394 int GetMaxFilterSize() const; 394 395 395 /** Deletes interior nodes from the tree which have negative merge cost set (local merge). 396 /** Deletes interior nodes from the tree which have negative 397 merge cost set (local merge). 396 398 */ 397 399 void DeleteLocalMergeTree(ViewCell *vc) const; … … 495 497 @returns true if the sample gives a contribution to the pvs. 496 498 */ 497 virtual bool AddSampleToPvs( 498 Intersectable *obj, 499 const Vector3 &hitPoint, 500 ViewCell *vc, 501 const float pdf, 502 float &contribution) const; 499 virtual bool AddSampleToPvs(Intersectable *obj, 500 const Vector3 &hitPoint, 501 ViewCell *vc, 502 const float pdf, 503 float &contribution) const; 503 504 504 505 /** Exports single view cells for visualization. … … 512 513 @param visRays additional rays 513 514 */ 514 virtual 515 void ExportSingleViewCells( 516 const ObjectContainer &objects, 517 const int maxViewCells, 518 const bool sortViewCells, 519 const bool exportPvs, 520 const bool exportRays, 521 const int maxRays, 522 const string prefix, 523 VssRayContainer *visRays = NULL) = NULL; 515 virtual void ExportSingleViewCells(const ObjectContainer &objects, 516 const int maxViewCells, 517 const bool sortViewCells, 518 const bool exportPvs, 519 const bool exportRays, 520 const int maxRays, 521 const string prefix, 522 VssRayContainer *visRays = NULL) = NULL; 524 523 525 524 … … 589 588 /** Exports the view cell partition. 590 589 */ 591 void ExportViewCellsForViz( 592 Exporter *exporter, 593 const AxisAlignedBox3 *box, 594 const AxisAlignedPlane *clipPlane = NULL, 595 const bool colorCode = 0) const; 590 void ExportViewCellsForViz(Exporter *exporter, 591 const AxisAlignedBox3 *box, 592 const AxisAlignedPlane *clipPlane = NULL, 593 const bool colorCode = 0) const; 596 594 597 595 /** Sets exporter color. … … 701 699 702 700 // only for debugging 703 VssRayContainer storedRays; 701 VssRayContainer storedRays; 702 704 703 ////////////////// 705 704 //-- visualization options … … 787 786 ViewCell *ConstructSpatialMergeTree(BspNode *root); 788 787 789 void ExportSingleViewCells(790 const ObjectContainer &objects,791 const int maxViewCells,792 const bool sortViewCells,793 const bool exportPvs,794 const bool exportRays,795 const int maxRays,796 const string prefix,797 VssRayContainer *visRays = NULL);798 799 protected:800 801 void CollectViewCells();802 803 /// the BSP tree.804 BspTree *mBspTree;805 vector<BspRay *> mBspRays;806 807 private:808 809 /** Constructs a spatial merge tree only 2 levels deep.810 */811 ViewCell *ConstructDummyMergeTree(BspNode *root);812 813 /** Exports visualization of the BSP splits.814 */815 void ExportSplits(const ObjectContainer &objects);816 817 /** test if subdivision is valid in terms of volume / area.818 */819 void TestSubdivision();820 };821 822 823 /**824 Manages different higher order operations on the KD type view cells.825 */826 class KdViewCellsManager: public ViewCellsManager827 {828 829 public:830 831 KdViewCellsManager(ViewCellsTree *viewCellsTree, KdTree *tree);832 833 int ConstructSubdivision(const ObjectContainer &objects,834 const VssRayContainer &rays);835 836 int CastLineSegment(const Vector3 &origin,837 const Vector3 &termination,838 ViewCellContainer &viewcells);839 840 int PostProcess(const ObjectContainer &objects,841 const VssRayContainer &rays);842 843 void Visualize(const ObjectContainer &objects,844 const VssRayContainer &sampleRays);845 846 int GetType() const;847 848 bool ViewCellsConstructed() const;849 850 ViewCell *GenerateViewCell(Mesh *mesh) const;851 852 /** Prints out statistics of this approach.853 */854 // virtual void PrintStatistics(ostream &s) const;855 ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const856 { return NULL; }857 858 float GetProbability(ViewCell *viewCell);859 860 void CreateMesh(ViewCell *vc);861 862 void ExportViewCellGeometry(863 Exporter *exporter,864 ViewCell *vc,865 const AxisAlignedBox3 *box,866 const AxisAlignedPlane *clipPlane = NULL867 ) const;868 869 870 void CollectMergeCandidates(const VssRayContainer &rays,871 vector<MergeCandidate> &candidates);872 873 void ExportSingleViewCells(874 const ObjectContainer &objects,875 const int maxViewCells,876 const bool sortViewCells,877 const bool exportPvs,878 const bool exportRays,879 const int maxRays,880 const string prefix,881 VssRayContainer *visRays = NULL);882 883 protected:884 885 /** Collects view cells from a hierarchy.886 */887 void CollectViewCells();888 889 KdNode *GetNodeForPvs(KdLeaf *leaf);890 891 ////////////////////////////////////////892 893 /// the BSP tree.894 KdTree *mKdTree;895 896 /// depth of the KD tree nodes with represent the view cells897 int mKdPvsDepth;898 899 900 };901 902 903 /** Manages different higher order operations on the view cells.904 */905 class VspBspViewCellsManager: public ViewCellsManager906 {907 908 public:909 910 VspBspViewCellsManager(ViewCellsTree *viewCellsTree, VspBspTree *tree);911 ~VspBspViewCellsManager();912 913 int ConstructSubdivision(const ObjectContainer &objects,914 const VssRayContainer &rays);915 916 int PostProcess(const ObjectContainer &objects,917 const VssRayContainer &rays);918 919 void Visualize(const ObjectContainer &objects,920 const VssRayContainer &sampleRays);921 922 int GetType() const;923 924 ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;925 926 bool ViewCellsConstructed() const;927 928 929 int CastLineSegment(const Vector3 &origin,930 const Vector3 &termination,931 ViewCellContainer &viewcells);932 933 float GetProbability(ViewCell *viewCell);934 935 ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;936 937 bool GetViewPoint(Vector3 &viewPoint) const;938 939 bool ViewPointValid(const Vector3 &viewPoint) const;940 941 void CreateMesh(ViewCell *vc);942 943 bool ExportViewCells(944 const string filename,945 const bool exportPvs,946 const ObjectContainer &objects);947 948 int CastBeam(Beam &beam);949 950 void ExportViewCellGeometry(951 Exporter *exporter,952 ViewCell *vc,953 const AxisAlignedBox3 *box,954 const AxisAlignedPlane *clipPlane = NULL955 ) const;956 957 958 void Finalize(ViewCell *viewCell, const bool createMesh);959 960 void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);961 962 void ExportSingleViewCells(963 const ObjectContainer &objects,964 const int maxViewCells,965 const bool sortViewCells,966 const bool exportPvs,967 const bool exportRays,968 const int maxRays,969 const string prefix,970 VssRayContainer *visRays = NULL);971 972 973 protected:974 975 int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const;976 977 /** Merges view cells according to some criteria978 */979 void MergeViewCells(const VssRayContainer &rays,980 const ObjectContainer &objects);981 982 void RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects);983 984 void CollectViewCells();985 986 /** Returns maximal depth difference of view cell987 leaves in tree.988 */989 int GetMaxTreeDiff(ViewCell *vc) const;990 991 /** Prepare view cells for use after loading them from disc.992 */993 void PrepareLoadedViewCells();994 995 /** Constructs merge hierarchy which corresponds to the spatial hierarchy.996 */997 ViewCell *ConstructSpatialMergeTree(BspNode *root);998 999 /// HACK for testing visibility filter functionality1000 void TestFilter(const ObjectContainer &objects);1001 1002 /** Visualization of the pvs difference to exact visubility using1003 from point queries.1004 */1005 void VisualizeWithFromPointQueries();1006 1007 /** Evaluate from point queries for the current scene.1008 */1009 void EvalFromPointQueries();1010 1011 /** Exports visualization of the BSP splits.1012 */1013 void ExportSplits(const ObjectContainer &objects,1014 const VssRayContainer &rays);1015 1016 /// the view space partition BSP tree.1017 VspBspTree *mVspBspTree;1018 1019 1020 private:1021 1022 /** test if subdivision is valid in terms of volume / area.1023 */1024 void TestSubdivision();1025 };1026 1027 #define TEST_EVALUATION 01028 1029 /**1030 Manages different higher order operations on the view cells.1031 */1032 class VspOspViewCellsManager: public ViewCellsManager1033 {1034 1035 public:1036 1037 VspOspViewCellsManager(ViewCellsTree *vcTree, HierarchyManager *hm);1038 1039 ~VspOspViewCellsManager();1040 1041 int ConstructSubdivision(const ObjectContainer &objects,1042 const VssRayContainer &rays);1043 1044 int PostProcess(const ObjectContainer &objects,1045 const VssRayContainer &rays);1046 1047 void Visualize(const ObjectContainer &objects,1048 const VssRayContainer &sampleRays);1049 1050 int GetType() const;1051 1052 ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;1053 1054 bool ViewCellsConstructed() const;1055 1056 1057 int CastLineSegment(const Vector3 &origin,1058 const Vector3 &termination,1059 ViewCellContainer &viewcells);1060 1061 float GetProbability(ViewCell *viewCell);1062 1063 ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;1064 1065 bool GetViewPoint(Vector3 &viewPoint) const;1066 1067 bool ViewPointValid(const Vector3 &viewPoint) const;1068 1069 void CreateMesh(ViewCell *vc);1070 1071 bool ExportViewCells(const string filename,1072 const bool exportPvs,1073 const ObjectContainer &objects);1074 1075 int CastBeam(Beam &beam);1076 1077 void Finalize(ViewCell *viewCell, const bool createMesh);1078 1079 /** Stores sample contribution for kd cells or objects.1080 */1081 virtual float ComputeSampleContribution(VssRay &ray,1082 const bool addRays,1083 const bool storeViewCells);1084 1085 ViewCellsManager *LoadViewCells(const string &filename,1086 ObjectContainer *objects,1087 const bool finalizeViewCells,1088 BoundingBoxConverter *bconverter);1089 1090 bool AddSampleToPvs(Intersectable *obj,1091 const Vector3 &hitPoint,1092 ViewCell *vc,1093 const float pdf,1094 float &contribution) const;1095 1096 788 void ExportSingleViewCells(const ObjectContainer &objects, 1097 789 const int maxViewCells, … … 1105 797 protected: 1106 798 1107 #if TEST_EVALUATION 1108 virtual void EvalViewCellPartition(); 1109 #endif 1110 1111 /** Exports view cell geometry. 1112 */ 799 void CollectViewCells(); 800 801 /// the BSP tree. 802 BspTree *mBspTree; 803 vector<BspRay *> mBspRays; 804 805 private: 806 807 /** Constructs a spatial merge tree only 2 levels deep. 808 */ 809 ViewCell *ConstructDummyMergeTree(BspNode *root); 810 811 /** Exports visualization of the BSP splits. 812 */ 813 void ExportSplits(const ObjectContainer &objects); 814 815 /** test if subdivision is valid in terms of volume / area. 816 */ 817 void TestSubdivision(); 818 }; 819 820 821 /** 822 Manages different higher order operations on the KD type view cells. 823 */ 824 class KdViewCellsManager: public ViewCellsManager 825 { 826 827 public: 828 829 KdViewCellsManager(ViewCellsTree *viewCellsTree, KdTree *tree); 830 831 int ConstructSubdivision(const ObjectContainer &objects, 832 const VssRayContainer &rays); 833 834 int CastLineSegment(const Vector3 &origin, 835 const Vector3 &termination, 836 ViewCellContainer &viewcells); 837 838 int PostProcess(const ObjectContainer &objects, 839 const VssRayContainer &rays); 840 841 void Visualize(const ObjectContainer &objects, 842 const VssRayContainer &sampleRays); 843 844 int GetType() const; 845 846 bool ViewCellsConstructed() const; 847 848 ViewCell *GenerateViewCell(Mesh *mesh) const; 849 850 /** Prints out statistics of this approach. 851 */ 852 // virtual void PrintStatistics(ostream &s) const; 853 ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const 854 { return NULL; } 855 856 float GetProbability(ViewCell *viewCell); 857 858 void CreateMesh(ViewCell *vc); 859 1113 860 void ExportViewCellGeometry(Exporter *exporter, 1114 861 ViewCell *vc, … … 1116 863 const AxisAlignedPlane *clipPlane = NULL) const; 1117 864 865 866 void CollectMergeCandidates(const VssRayContainer &rays, 867 vector<MergeCandidate> &candidates); 868 869 void ExportSingleViewCells(const ObjectContainer &objects, 870 const int maxViewCells, 871 const bool sortViewCells, 872 const bool exportPvs, 873 const bool exportRays, 874 const int maxRays, 875 const string prefix, 876 VssRayContainer *visRays = NULL); 877 878 protected: 879 880 /** Collects view cells from a hierarchy. 881 */ 882 void CollectViewCells(); 883 884 KdNode *GetNodeForPvs(KdLeaf *leaf); 885 886 //////////////////////////////////////// 887 888 /// the BSP tree. 889 KdTree *mKdTree; 890 891 /// depth of the KD tree nodes with represent the view cells 892 int mKdPvsDepth; 893 894 895 }; 896 897 898 /** Manages different higher order operations on the view cells. 899 */ 900 class VspBspViewCellsManager: public ViewCellsManager 901 { 902 903 public: 904 905 VspBspViewCellsManager(ViewCellsTree *viewCellsTree, VspBspTree *tree); 906 ~VspBspViewCellsManager(); 907 908 int ConstructSubdivision(const ObjectContainer &objects, 909 const VssRayContainer &rays); 910 911 int PostProcess(const ObjectContainer &objects, 912 const VssRayContainer &rays); 913 914 void Visualize(const ObjectContainer &objects, 915 const VssRayContainer &sampleRays); 916 917 int GetType() const; 918 919 ViewCell *GenerateViewCell(Mesh *mesh = NULL) const; 920 921 bool ViewCellsConstructed() const; 922 923 924 int CastLineSegment(const Vector3 &origin, 925 const Vector3 &termination, 926 ViewCellContainer &viewcells); 927 928 float GetProbability(ViewCell *viewCell); 929 930 ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const; 931 932 bool GetViewPoint(Vector3 &viewPoint) const; 933 934 bool ViewPointValid(const Vector3 &viewPoint) const; 935 936 void CreateMesh(ViewCell *vc); 937 938 bool ExportViewCells(const string filename, 939 const bool exportPvs, 940 const ObjectContainer &objects); 941 942 int CastBeam(Beam &beam); 943 944 void ExportViewCellGeometry(Exporter *exporter, 945 ViewCell *vc, 946 const AxisAlignedBox3 *box, 947 const AxisAlignedPlane *clipPlane = NULL) const; 948 949 950 void Finalize(ViewCell *viewCell, const bool createMesh); 951 952 void CollectMergeCandidates(const VssRayContainer &rays, 953 vector<MergeCandidate> &candidates); 954 955 void ExportSingleViewCells(const ObjectContainer &objects, 956 const int maxViewCells, 957 const bool sortViewCells, 958 const bool exportPvs, 959 const bool exportRays, 960 const int maxRays, 961 const string prefix, 962 VssRayContainer *visRays = NULL); 963 964 965 protected: 966 1118 967 int ComputeBoxIntersections(const AxisAlignedBox3 &box, 1119 968 ViewCellContainer &viewCells) const; 1120 969 970 /** Merges view cells according to some criteria 971 */ 972 void MergeViewCells(const VssRayContainer &rays, 973 const ObjectContainer &objects); 974 975 void RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects); 976 977 void CollectViewCells(); 978 979 /** Returns maximal depth difference of view cell 980 leaves in tree. 981 */ 982 int GetMaxTreeDiff(ViewCell *vc) const; 983 984 /** Prepare view cells for use after loading them from disc. 985 */ 986 void PrepareLoadedViewCells(); 987 988 /** Constructs merge hierarchy which corresponds to the spatial hierarchy. 989 */ 990 ViewCell *ConstructSpatialMergeTree(BspNode *root); 991 992 /// HACK for testing visibility filter functionality 993 void TestFilter(const ObjectContainer &objects); 994 995 /** Visualization of the pvs difference to exact visubility using 996 from point queries. 997 */ 998 void VisualizeWithFromPointQueries(); 999 1000 /** Evaluate from point queries for the current scene. 1001 */ 1002 void EvalFromPointQueries(); 1003 1004 /** Exports visualization of the BSP splits. 1005 */ 1006 void ExportSplits(const ObjectContainer &objects, 1007 const VssRayContainer &rays); 1008 1009 1010 ///////////////////////// 1011 1012 /// the view space partition BSP tree. 1013 VspBspTree *mVspBspTree; 1014 1015 1016 private: 1017 1018 /** test if subdivision is valid in terms of volume / area. 1019 */ 1020 void TestSubdivision(); 1021 }; 1022 1023 #define TEST_EVALUATION 0 1024 1025 /** 1026 Manages different higher order operations on the view cells. 1027 */ 1028 class VspOspViewCellsManager: public ViewCellsManager 1029 { 1030 1031 public: 1032 1033 VspOspViewCellsManager(ViewCellsTree *vcTree, HierarchyManager *hm); 1034 1035 ~VspOspViewCellsManager(); 1036 1037 int ConstructSubdivision(const ObjectContainer &objects, 1038 const VssRayContainer &rays); 1039 1040 int PostProcess(const ObjectContainer &objects, 1041 const VssRayContainer &rays); 1042 1043 void Visualize(const ObjectContainer &objects, 1044 const VssRayContainer &sampleRays); 1045 1046 int GetType() const; 1047 1048 ViewCell *GenerateViewCell(Mesh *mesh = NULL) const; 1049 1050 bool ViewCellsConstructed() const; 1051 1052 1053 int CastLineSegment(const Vector3 &origin, 1054 const Vector3 &termination, 1055 ViewCellContainer &viewcells); 1056 1057 float GetProbability(ViewCell *viewCell); 1058 1059 ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const; 1060 1061 bool GetViewPoint(Vector3 &viewPoint) const; 1062 1063 bool ViewPointValid(const Vector3 &viewPoint) const; 1064 1065 void CreateMesh(ViewCell *vc); 1066 1067 bool ExportViewCells(const string filename, 1068 const bool exportPvs, 1069 const ObjectContainer &objects); 1070 1071 int CastBeam(Beam &beam); 1072 1073 void Finalize(ViewCell *viewCell, const bool createMesh); 1074 1075 /** Stores sample contribution for kd cells or objects. 1076 */ 1077 virtual float ComputeSampleContribution(VssRay &ray, 1078 const bool addRays, 1079 const bool storeViewCells); 1080 1081 ViewCellsManager *LoadViewCells(const string &filename, 1082 ObjectContainer *objects, 1083 const bool finalizeViewCells, 1084 BoundingBoxConverter *bconverter); 1085 1086 bool AddSampleToPvs(Intersectable *obj, 1087 const Vector3 &hitPoint, 1088 ViewCell *vc, 1089 const float pdf, 1090 float &contribution) const; 1091 1092 void ExportSingleViewCells(const ObjectContainer &objects, 1093 const int maxViewCells, 1094 const bool sortViewCells, 1095 const bool exportPvs, 1096 const bool exportRays, 1097 const int maxRays, 1098 const string prefix, 1099 VssRayContainer *visRays = NULL); 1100 1101 protected: 1102 1103 //#if TEST_EVALUATION 1104 virtual void EvalViewCellPartition(); 1105 //#endif 1106 1107 /** Exports view cell geometry. 1108 */ 1109 void ExportViewCellGeometry(Exporter *exporter, 1110 ViewCell *vc, 1111 const AxisAlignedBox3 *box, 1112 const AxisAlignedPlane *clipPlane = NULL) const; 1113 1114 int ComputeBoxIntersections(const AxisAlignedBox3 &box, 1115 ViewCellContainer &viewCells) const; 1116 1121 1117 void CollectViewCells(); 1122 1118 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r1684 r1686 721 721 tBackData.mMaxCostMisses = maxCostMisses; 722 722 723 newNode->mRenderCostDecr = sc->GetRenderCostDecrease(); 724 newNode->mPvsEntriesIncr = sc->GetPvsEntriesIncr(); 725 723 //newNode->mRenderCostDecr = sc->GetRenderCostDecrease(); 724 //newNode->mPvsEntriesIncr = sc->GetPvsEntriesIncr(); 725 726 // set the time stamp so the order of traversal can be reconstructed 727 newNode->mTimeStamp = mHierarchyManager->mTimeStamp ++; 728 726 729 mTotalCost -= sc->GetRenderCostDecrease(); 727 730 mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - tData.mPvs; … … 978 981 #endif 979 982 980 // set the time stamp so the order of traversal can be reconstructed981 interior->mTimeStamp = mHierarchyManager->mTimeStamp ++;982 983 983 return interior; 984 }985 986 void VspTree::UpdateNode(const AxisAlignedPlane &splitPlane,987 VspTraversalData &tData,988 VspTraversalData &frontData,989 VspTraversalData &backData)990 {991 VspLeaf *leaf = dynamic_cast<VspLeaf *>(tData.mNode);992 /*993 // replace a link from node's parent994 if (parent)995 {996 parent->ReplaceChildLink(leaf, interior);997 interior->SetParent(parent);998 }999 else // new root1000 {1001 mRoot = interior;1002 }1003 1004 VspLeaf *frontLeaf = new VspLeaf(interior);1005 VspLeaf *backLeaf = new VspLeaf(interior);1006 1007 // and setup child links1008 interior->SetupChildLinks(frontLeaf, backLeaf);1009 1010 // add bounding box1011 interior->SetBoundingBox(tData.mBoundingBox);1012 1013 // set front and back leaf1014 frontData.mNode = frontLeaf;1015 backData.mNode = backLeaf;1016 1017 // explicitely create front and back view cell1018 CreateViewCell(frontData, false);1019 CreateViewCell(backData, false);1020 */1021 984 } 1022 985 … … 3321 3284 3322 3285 3323 SubdivisionCandidate *VspTree::CreateSubdivisionCandidate(VspInterior *oldNode) 3324 { 3325 return new VspSubdivisionCandidate(oldNode->GetPlane(), VspTraversalData()); 3326 } 3327 3328 } 3286 VspNode *VspTree::SubdivideAndCopy(SplitQueue &tQueue, 3287 SubdivisionCandidate *splitCandidate) 3288 { 3289 // todo remove dynamic cast 3290 VspSubdivisionCandidate *sc = dynamic_cast<VspSubdivisionCandidate *>(splitCandidate); 3291 3292 VspTraversalData &tData = sc->mParentData; 3293 VspNode *newNode = tData.mNode; 3294 VspNode *oldNode = (VspNode *)splitCandidate->mEvaluationHack; 3295 3296 if (!oldNode->IsLeaf()) 3297 { 3298 /////////// 3299 //-- continue subdivision 3300 3301 VspTraversalData tFrontData; 3302 VspTraversalData tBackData; 3303 3304 VspInterior *oldInterior = dynamic_cast<VspInterior *>(oldNode); 3305 3306 // create new interior node and two leaf node 3307 const AxisAlignedPlane splitPlane = oldInterior->GetPlane(); 3308 const int maxCostMisses = sc->GetMaxCostMisses(); 3309 3310 newNode = SubdivideNode(splitPlane, tData, tFrontData, tBackData); 3311 3312 // how often was max cost ratio missed in this branch? 3313 tFrontData.mMaxCostMisses = maxCostMisses; 3314 tBackData.mMaxCostMisses = maxCostMisses; 3315 3316 newNode->mRenderCostDecr = oldNode->mRenderCostDecr + sc->GetRenderCostDecrease(); 3317 newNode->mPvsEntriesIncr = oldNode->mPvsEntriesIncr + sc->GetPvsEntriesIncr(); 3318 3319 ///////////// 3320 //-- evaluate new split candidates for global greedy cost heuristics 3321 3322 VspSubdivisionCandidate *frontCandidate = new VspSubdivisionCandidate(tFrontData); 3323 VspSubdivisionCandidate *backCandidate = new VspSubdivisionCandidate(tBackData); 3324 3325 frontCandidate->SetPriority((float)-oldInterior->GetFront()->mTimeStamp); 3326 backCandidate->SetPriority((float)-oldInterior->GetFront()->mTimeStamp); 3327 3328 frontCandidate->mEvaluationHack = oldInterior->GetFront(); 3329 backCandidate->mEvaluationHack = oldInterior->GetBack(); 3330 3331 // cross reference 3332 tFrontData.mNode->SetSubdivisionCandidate(frontCandidate); 3333 tBackData.mNode->SetSubdivisionCandidate(backCandidate); 3334 3335 tQueue.Push(frontCandidate); 3336 tQueue.Push(backCandidate); 3337 3338 // note: leaf is not destroyed because it is needed to collect 3339 // dirty candidates in hierarchy manager 3340 } 3341 3342 if (newNode->IsLeaf()) // subdivision terminated 3343 { 3344 // view cell is created during subdivision 3345 VspLeaf *leaf = dynamic_cast<VspLeaf *>(newNode); 3346 ViewCell *viewCell = leaf->GetViewCell(); 3347 3348 int conSamp = 0; 3349 float sampCon = 0.0f; 3350 3351 #if 0 3352 ///////////// 3353 //-- store pvs optained from rays 3354 3355 AddSamplesToPvs(leaf, *tData.mRays, sampCon, conSamp); 3356 3357 // update scalar pvs size value 3358 ObjectPvs &pvs = viewCell->GetPvs(); 3359 mViewCellsManager->UpdateScalarPvsSize(viewCell, pvs.CountObjectsInPvs(), pvs.GetSize()); 3360 3361 mVspStats.contributingSamples += conSamp; 3362 mVspStats.sampleContributions += (int)sampCon; 3363 #endif 3364 if (mStoreRays) 3365 { 3366 ////////// 3367 //-- store rays piercing this view cell 3368 RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 3369 for (it = tData.mRays->begin(); it != it_end; ++ it) 3370 { 3371 (*it).mRay->Ref(); 3372 leaf->mVssRays.push_back((*it).mRay); 3373 //leaf->mVssRays.push_back(new VssRay(*(*it).mRay)); 3374 } 3375 } 3376 3377 // finally evaluate statistics for this leaf 3378 EvaluateLeafStats(tData); 3379 // detach subdivision candidate: this leaf is no candidate for 3380 // splitting anymore 3381 tData.mNode->SetSubdivisionCandidate(NULL); 3382 // detach node so it won't get deleted 3383 tData.mNode = NULL; 3384 } 3385 3386 return newNode; 3387 } 3388 3389 } -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
r1684 r1686 693 693 #endif 694 694 695 void UpdateNode(const AxisAlignedPlane &splitPlane, 696 VspTraversalData &tData, 697 VspTraversalData &frontData, 698 VspTraversalData &backData); 699 700 SubdivisionCandidate *CreateSubdivisionCandidate(VspInterior *oldNode); 695 VspNode *SubdivideAndCopy(SplitQueue &tQueue, SubdivisionCandidate *splitCandidate); 701 696 702 697 protected:
Note: See TracChangeset
for help on using the changeset viewer.