Changeset 1786 for GTP/trunk/Lib/Vis
- Timestamp:
- 11/24/06 00:24:41 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1785 r1786 52 52 BvhNode::BvhNode(): 53 53 mParent(NULL), 54 mTimeStamp(0) 54 mTimeStamp(0), 55 mRenderCost(-1) 56 55 57 { 56 58 … … 60 62 mParent(NULL), 61 63 mBoundingBox(bbox), 62 mTimeStamp(0) 64 mTimeStamp(0), 65 mRenderCost(-1) 63 66 { 64 67 } … … 68 71 mBoundingBox(bbox), 69 72 mParent(parent), 70 mTimeStamp(0) 73 mTimeStamp(0), 74 mRenderCost(-1) 71 75 { 72 76 } … … 301 305 Environment::GetSingleton()->GetIntValue("BvHierarchy.maxTests", mMaxTests); 302 306 // Environment::GetSingleton()->GetBoolValue("BvHierarchy.Construction.useInitialSubdivision", mApplyInitialPartition); 303 304 mInitialObjectsSize = 50; 307 Environment::GetSingleton()->GetIntValue("BvHierarchy.Construction.Initial.minObjects", mInitialMinObjects); 308 Environment::GetSingleton()->GetFloatValue("BvHierarchy.Construction.Initial.maxAreaRatio", mInitialMaxAreaRatio); 309 Environment::GetSingleton()->GetFloatValue("BvHierarchy.Construction.Initial.minArea", mInitialMinArea); 305 310 306 311 //mMemoryConst = (float)(sizeof(VspLeaf) + sizeof(VspViewCell)); … … 334 339 Debug << "bvh mem const: " << mMemoryConst << endl; 335 340 Debug << "apply initial partition: " << mApplyInitialPartition << endl; 341 Debug << "min objects: " << mInitialMinObjects << endl; 342 Debug << "max area ratio: " << mInitialMaxAreaRatio << endl; 343 Debug << "min area: " << mInitialMinArea << endl; 344 336 345 Debug << endl; 337 346 } … … 496 505 BvhSubdivisionCandidate *backCandidate = 497 506 new BvhSubdivisionCandidate(tBackData); 498 507 499 508 EvalSubdivisionCandidate(*frontCandidate); 500 509 EvalSubdivisionCandidate(*backCandidate); … … 2150 2159 2151 2160 if (mApplyInitialPartition) 2152 { 2153 cout << "§§§§§§§§here41 "<<oSubdivisionCandidate->mParentData.mSortedObjects[3]->size()<<endl; 2161 {cout << "here29"<<endl; 2154 2162 ApplyInitialSubdivision(oSubdivisionCandidate, tQueue); 2155 2163 } … … 2158 2166 tQueue.Push(oSubdivisionCandidate); 2159 2167 } 2168 cout << "!!size: " << GetStatistics().Leaves() << endl; 2160 2169 } 2161 2170 … … 2510 2519 {cout << "here2"<<endl; 2511 2520 SubdivisionCandidate *candidate = tempQueue.Top(); 2512 t Queue.Pop();2521 tempQueue.Pop(); 2513 2522 2514 2523 BvhSubdivisionCandidate *bsc = 2515 2524 dynamic_cast<BvhSubdivisionCandidate *>(candidate); 2516 cout << "§§§§§§§§here49 "<< bsc->mParentData.mSortedObjects[3]->size()<<endl; 2517 cout << "here87 "<<((BvhSubdivisionCandidate *)firstCandidate)->mParentData.mNode->mObjects.size()<<endl; 2518 const bool globalCriteriaMet = 2519 GlobalTerminationCriteriaMet(bsc->mParentData); 2520 cout << "here5"<<endl; 2525 cout << "§§§§§§§§here49 "<< bsc->mParentData.mSortedObjects[3]->size() << " " << mInitialMinObjects << endl; 2526 2527 const bool globalCriteriaMet = GlobalTerminationCriteriaMet(bsc->mParentData); 2528 2521 2529 if (!InitialTerminationCriteriaMet(bsc->mParentData)) 2522 {cout << "here9"<<bsc->mParentData.mNode->mObjects.size()<<endl; 2530 { 2531 cout << "here12"<<endl; 2532 cout << "here9"<<bsc->mParentData.mNode->mObjects.size()<<endl; 2523 2533 BvhNode *node = Subdivide(tempQueue, bsc, globalCriteriaMet); 2524 cout << "here12"<<endl; 2534 2525 2535 // not needed anymore 2526 2536 delete bsc; 2527 2537 } 2528 2538 else // initial preprocessing finished for this candidate 2529 {cout << "here15"<<endl; 2539 {cout << "here14"<<endl; 2540 // add to "real" traversal queue 2530 2541 tQueue.Push(bsc); 2531 2542 } … … 2544 2555 2545 2556 ObjectContainer::const_iterator oit, oit_end = objects->end(); 2546 cout<<" $$$$$$$$$$$$$$$$$$$"<<endl;2557 cout<<"here104"<<endl; 2547 2558 for (oit = objects->begin(); oit != objects->end(); ++ oit) 2548 2559 { 2549 2560 //cout << (*oit)->GetBox().SurfaceArea() << " "; 2550 2561 } 2551 cout<<"$$$$$$$$$$$$$$$$$$$"<<endl; 2552 float maxAreaDiff = 0.0f;2562 2563 float maxAreaDiff = -1.0f; 2553 2564 2554 2565 ObjectContainer::const_iterator backObjectsStart = objects->begin(); 2555 2566 2556 2567 for (oit = objects->begin(); oit != (objects->end() - 1); ++ oit) 2557 { 2568 {//cout << "h"; 2558 2569 Intersectable *objS = *oit; 2559 2570 Intersectable *objL = *(oit + 1); 2560 2571 2561 2572 const float areaDiff = 2562 fabs(objS->GetBox().SurfaceArea() - objL->GetBox().SurfaceArea());2573 objL->GetBox().SurfaceArea() - objS->GetBox().SurfaceArea(); 2563 2574 2564 2575 if (areaDiff > maxAreaDiff) 2565 2576 { 2577 //cout << "here5 " << areaDiff << " " << maxAreaDiff << endl; 2566 2578 maxAreaDiff = areaDiff; 2567 2579 backObjectsStart = oit + 1; … … 2583 2595 2584 2596 2597 inline static float AreaRatio(Intersectable *smallObj, Intersectable *largeObj) 2598 { 2599 const float areaSmall = smallObj->GetBox().SurfaceArea(); 2600 const float areaLarge = largeObj->GetBox().SurfaceArea(); 2601 2602 return areaSmall / (areaLarge - areaSmall + Limits::Small); 2603 } 2604 2605 2585 2606 bool BvHierarchy::InitialTerminationCriteriaMet(const BvhTraversalData &tData) const 2586 2607 { 2587 2608 return (0 2588 || ((int)tData.mNode->mObjects.size() < mInitialObjectsSize) 2589 || (tData.mNode->mObjects.back()->GetBox().SurfaceArea() < mMinInitialSurfaceArea) 2609 || ((int)tData.mNode->mObjects.size() < mInitialMinObjects) 2610 || (tData.mNode->mObjects.back()->GetBox().SurfaceArea() < mInitialMinArea) 2611 || (AreaRatio(tData.mNode->mObjects.front(), tData.mNode->mObjects.back()) > mInitialMaxAreaRatio) 2590 2612 ); 2591 2613 } 2592 2614 2593 2615 2594 } 2616 // HACK 2617 float BvHierarchy::GetRenderCostIncrementially(BvhNode *node) const 2618 { 2619 if (node->mRenderCost < 0) 2620 { 2621 //cout <<"p"; 2622 if (node->IsLeaf()) 2623 { 2624 BvhLeaf *leaf = dynamic_cast<BvhLeaf *>(node); 2625 node->mRenderCost = EvalAbsCost(leaf->mObjects); 2626 } 2627 else 2628 { 2629 BvhInterior *interior = dynamic_cast<BvhInterior *>(node); 2630 2631 node->mRenderCost = GetRenderCostIncrementially(interior->GetFront()) + 2632 GetRenderCostIncrementially(interior->GetBack()); 2633 } 2634 } 2635 2636 return node->mRenderCost; 2637 } 2638 2639 2640 } -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r1785 r1786 207 207 inline void SetTimeStamp(const int timeStamp) { mTimeStamp = timeStamp; }; 208 208 209 ///////////////////////////////////// 210 //-- mailing options 211 212 // static void NewMail(const int reserve = 1) { 213 // sMailId += sReservedMailboxes; 214 // sReservedMailboxes = reserve; 215 // } 216 217 // void Mail() { mMailbox = sMailId; } 218 // bool Mailed() const { return mMailbox == sMailId; } 219 220 // void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 221 // bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 222 223 // int IncMail() { return ++ mMailbox - sMailId; } 224 225 // static int sMailId; 226 // //int mMailbox; 227 // static int sReservedMailboxes; 228 229 230 231 ///////////////////////////////////////////// 209 210 //////////////////////// 232 211 //-- inherited functions from Intersectable 233 212 … … 266 245 267 246 /////////////////////////////////// 247 248 float mRenderCost; 268 249 269 250 protected: … … 644 625 void CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects); 645 626 627 float GetRenderCostIncrementially(BvhNode *node) const; 628 629 646 630 protected: 647 631 … … 911 895 bool InitialTerminationCriteriaMet(const BvhTraversalData &tData) const; 912 896 913 float mMinInitialSurfaceArea;914 int mInitialObjectsSize;915 897 916 898 protected: … … 1007 989 float mMemoryConst; 1008 990 991 int mMaxTests; 992 1009 993 bool mIsInitialSubdivision; 1010 994 1011 995 bool mApplyInitialPartition; 1012 1013 int mMaxTests; 996 997 int mInitialMinObjects; 998 float mInitialMaxAreaRatio; 999 float mInitialMinArea; 1014 1000 }; 1015 1001 -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1785 r1786 2505 2505 "false"); 2506 2506 2507 RegisterOption("BvHierarchy.Construction.Initial.minObjects", 2508 optInt, 2509 "bvh_construction_use_initial_min_objects=", 2510 "100000"); 2511 2512 RegisterOption("BvHierarchy.Construction.Initial.minArea", 2513 optFloat, 2514 "bvh_construction_use_initial_min_area=", 2515 "0.0001"); 2516 2517 RegisterOption("BvHierarchy.Construction.Initial.maxAreaRatio", 2518 optFloat, 2519 "bvh_construction_use_initial_max_area_ratio=", 2520 "0.1"); 2521 2507 2522 RegisterOption("BvHierarchy.minRaysForVisibility", 2508 2523 optInt, -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1784 r1786 29 29 #define USE_FIXEDPOINT_T 0 30 30 31 31 #define STUPID_METHOD 0 32 32 33 33 /*******************************************************************/ … … 1787 1787 // hack for choosing which node to account for 1788 1788 if (intersect->IsLeaf()) 1789 { 1789 1790 activeNode = dynamic_cast<BvhLeaf *>(intersect)->GetActiveNode(); 1791 } 1790 1792 else 1793 { 1791 1794 activeNode = intersect; 1795 } 1792 1796 1793 1797 if (!activeNode->Mailed()) … … 1795 1799 activeNode->Mail(); 1796 1800 1801 #if STUPID_METHOD 1802 1797 1803 ObjectContainer objects; 1798 activeNode->CollectObjects(objects); 1799 1804 activeNode->CollectObjects(objects); 1805 rc += mBvHierarchy->EvalAbsCost(objects); 1806 #else 1807 rc += mBvHierarchy->GetRenderCostIncrementially(activeNode); 1808 #endif 1800 1809 ++ pvsEntries; 1801 rc += mBvHierarchy->EvalAbsCost(objects);1802 1810 } 1803 1811 } … … 1810 1818 //////////////// 1811 1819 //-- pvs is not stored with the interiors => reconstruct 1812 ViewCell *root = vc;1813 1820 1814 1821 // add pvs from leaves … … 1824 1831 if (!vc->GetPvs().Empty()) 1825 1832 { 1833 if (vc->IsLeaf()) cout << " l " << pvs.GetSize(); 1834 else cout << " i " << pvs.GetSize(); 1826 1835 pvs.MergeInPlace(vc->GetPvs()); 1827 1836 } 1828 1837 else if (!vc->IsLeaf()) // interior cells: go down to leaf level 1829 1838 { 1839 cout <<" t"; 1830 1840 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 1831 1841 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); … … 1836 1846 } 1837 1847 } 1838 } 1839 } 1848 else cout <<"k"; 1849 } 1850 } 1851 1852 1853 // TODO matt: implement this function for different storing methods 1854 void HierarchyManager::PullUpPvsIncrementally(ViewCell *viewCell) const 1855 { 1856 //////////////// 1857 //-- pvs is not stored with the interiors => reconstruct 1858 1859 // early exit: pvs is already pulled up to this view cell 1860 if (!viewCell->GetPvs().Empty()) 1861 return; 1862 1863 // add pvs from leaves 1864 stack<ViewCell *> tstack; 1865 tstack.push(viewCell); 1866 1867 ViewCell *vc = viewCell; 1868 1869 while (!tstack.empty()) 1870 { 1871 vc = tstack.top(); 1872 tstack.pop(); 1873 1874 // add newly found pvs to merged pvs: break here even for interior 1875 if (!vc->GetPvs().Empty()) 1876 { 1877 /*if (vc->IsLeaf()) 1878 cout << " l " << viewCell->GetPvs().GetSize(); 1879 else cout << " i " << viewCell->GetPvs().GetSize(); 1880 */ 1881 viewCell->GetPvs().MergeInPlace(vc->GetPvs()); 1882 } 1883 else if (!vc->IsLeaf()) // interior cells: go down to leaf level 1884 { 1885 //cout <<" t"; 1886 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 1887 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 1888 1889 for (it = interior->mChildren.begin(); it != it_end; ++ it) 1890 { 1891 tstack.push(*it); 1892 } 1893 } 1894 } 1895 } 1896 1897 1898 1899 // TODO matt: implement this function for different storing methods 1900 void HierarchyManager::GetPvsRecursive(ViewCell *vc, ObjectPvs &pvs) const 1901 { 1902 //////////////// 1903 //-- pvs is not stored with the interiors => reconstruct 1904 if (vc->IsLeaf() || !vc->GetPvs().Empty()) 1905 { 1906 pvs = vc->GetPvs(); 1907 } 1908 else 1909 { 1910 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 1911 #if 0 1912 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 1913 const int childPvsSize = (int)interior->mChildren.size(); 1914 vector<ObjectPvs> childPvs; 1915 childPvs.resize((int)interior->mChildren.size()); 1916 1917 int i = 0; 1918 for (it = interior->mChildren.begin(); it != it_end; ++ it, ++ i) 1919 { 1920 GetPvsRecursive(*it, childPvs[i]); 1921 pvs.MergeInPlace(childPvs[i]); 1922 } 1923 #else 1924 1925 ObjectPvs leftPvs, rightPvs; 1926 1927 GetPvsRecursive(interior->mChildren[0], leftPvs); 1928 GetPvsRecursive(interior->mChildren[1], rightPvs); 1929 1930 ObjectPvs::Merge(pvs, leftPvs, rightPvs); 1931 #endif 1932 } 1933 } 1934 1840 1935 1841 1936 int HierarchyManager::ExtractStatistics(const int maxSplits, … … 1868 1963 ViewCell::NewMail(); 1869 1964 1965 cout << "\n**************viewcells: " << viewCells.size() << endl; 1870 1966 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 1871 1967 { 1872 1968 ViewCell *vc = *vit; 1873 1969 1970 //cout << "\nhere5: "; 1874 1971 float rc = 0; 1875 ObjectPvs pvs;1876 1877 //mVspTree->mViewCellsTree->GetPvs(vc, pvs);1972 1973 #if STUPID_METHOD 1974 ObjectPvs pvs; 1878 1975 GetPvsIncrementally(vc, pvs); 1879 1880 1976 vc->SetPvs(pvs); 1977 #else 1978 //PullUpPvsIncrementally(vc); 1979 ObjectPvs pvs; 1980 GetPvsRecursive(vc, pvs); 1981 vc->SetPvs(pvs); 1982 #endif 1881 1983 1882 1984 vc->Mail(); … … 1884 1986 if (useFilter) 1885 1987 { 1988 const long startT = GetTime(); 1886 1989 ObjectPvs filteredPvs; 1887 1990 mVspTree->mViewCellsManager->ApplyFilter2(vc, false, 1.0f, filteredPvs); 1991 const long endT = GetTime(); 1992 1993 cout << "filter computed in " << TimeDiff(startT, endT) * 1e-3f << " secs" << endl; 1888 1994 ComputePvs(filteredPvs, rc, pvsEntries); 1889 1995 } 1890 1996 else 1891 1997 { 1892 ComputePvs( pvs, rc, pvsEntries);1998 ComputePvs(vc->GetPvs(), rc, pvsEntries); 1893 1999 } 1894 2000 … … 1915 2021 } 1916 2022 2023 // store current level 1917 2024 mOldViewCells = viewCells; 1918 2025 … … 2098 2205 vector<HierarchySubdivisionStats> subStatsContainer; 2099 2206 2100 int splits = (1 + mHierarchyStats.Leaves() / splitsStepSize) * splitsStepSize;2207 int splits = (1 + (mHierarchyStats.Leaves() - 1) / splitsStepSize) * splitsStepSize; 2101 2208 cout << "splits: " << splits << endl; 2102 2209 … … 2133 2240 2134 2241 if (splits == 0) 2242 { 2135 2243 break; 2136 2244 } 2137 2245 splits -= splitsStepSize; 2138 2246 2139 cout << subStats.mNumSplits << " ";2247 cout << "splits: " << subStats.mNumSplits << " "; 2140 2248 } 2141 2249 -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r1779 r1786 524 524 void ComputePvs(const ObjectPvs &pvs, float &rc, int &pvsEntries); 525 525 void GetPvsIncrementally(ViewCell *vc, ObjectPvs &pvs) const; 526 void PullUpPvsIncrementally(ViewCell *viewCell) const; 527 void GetPvsRecursive(ViewCell *vc, ObjectPvs &pvs) const; 526 528 protected: 527 529 … … 636 638 637 639 ViewCellContainer mOldViewCells; 640 641 ObjectPvs mOldPvs; 638 642 }; 639 643 -
GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp
r1757 r1786 55 55 56 56 if (hittriangle != -1 ) { 57 if (hittriangle >= mPreprocessor.mFaceParents.size()) 58 cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 59 else { 60 hitA.mObject = mPreprocessor.mFaceParents[hittriangle].mObject; 57 Intersectable *intersect = mPreprocessor.GetParentObject(hittriangle); 58 59 if (intersect) 60 { 61 hitA.mObject = intersect; 61 62 hitA.mNormal = Vector3(normal[0], normal[1], normal[2]); 62 63 // Get the normal of that face … … 77 78 dist); 78 79 79 if (hittriangle != -1 ) { 80 if (hittriangle >= mPreprocessor.mFaceParents.size()) 81 cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 82 else 83 { 84 hitB.mObject = mPreprocessor.mFaceParents[hittriangle].mObject; 85 hitB.mNormal = Vector3(normal[0], normal[1], normal[2]); 86 // Get the normal of that face 87 // Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 88 // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 89 //-rays[index+i].mDirection; // $$ temporary 90 hitB.mPoint = simpleRay.Extrap(dist); 91 } 80 Intersectable *intersect = mPreprocessor.GetParentObject(hittriangle); 81 82 if (intersect) 83 { 84 hitB.mObject = intersect; 85 hitB.mNormal = Vector3(normal[0], normal[1], normal[2]); 86 // Get the normal of that face 87 // Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 88 // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 89 //-rays[index+i].mDirection; // $$ temporary 90 hitB.mPoint = simpleRay.Extrap(dist); 92 91 } 93 92 } … … 170 169 171 170 for (i=0; i < num; i++) 172 171 { 173 172 Intersection hitA(rays[i].mOrigin), hitB(rays[i].mOrigin); 174 173 175 174 #if DEBUG_RAYCAST 176 Debug<<"FH\n"<<flush; 177 #endif 178 179 if (forward_hit_triangles[i] != -1 ) { 180 if (forward_hit_triangles[i] >= mPreprocessor.mFaceParents.size()) 181 cerr<<"Warning: triangle index out of range! "<<forward_hit_triangles[i]<<endl; 182 else { 183 hitA.mObject = mPreprocessor.mFaceParents[forward_hit_triangles[i]].mObject; 175 Debug<<"FH\n"<<flush; 176 #endif 177 Intersectable *intersect = mPreprocessor.GetParentObject(forward_hit_triangles[i]); 178 179 if (intersect) 180 { 181 hitA.mObject = intersect; 184 182 // Get the normal of that face 185 hitA.mNormal = hitA.mObject->GetNormal(mPreprocessor.mFaceParents[forward_hit_triangles[i]].mFaceIndex); 183 hitA.mNormal = mPreprocessor.GetParentNormal(forward_hit_triangles[i]); 184 186 185 //-rays[index+i].mDirection; // $$ temporary 187 186 hitA.mPoint = rays[index+i].Extrap(forward_dist[i]); 187 } 188 189 #if DEBUG_RAYCAST 190 Debug<<"BH\n"<<flush; 191 #endif 192 193 if (castDoubleRay) 194 { 195 Intersectable *intersect = mPreprocessor.GetParentObject(backward_hit_triangles[i]); 196 197 if (intersect) 198 { 199 hitB.mObject = intersect; 200 hitB.mNormal = mPreprocessor.GetParentNormal(backward_hit_triangles[i]); 201 202 // normalB = rays[index+i].mDirection; // $$ temporary 203 hitB.mPoint = rays[index+i].Extrap(-backward_dist[i]); 188 204 } 189 } 190 #if DEBUG_RAYCAST 191 Debug<<"BH\n"<<flush; 192 #endif 193 194 if (castDoubleRay && (backward_hit_triangles[i] != -1)) { 195 if (backward_hit_triangles[i] >= mPreprocessor.mFaceParents.size()) 196 cerr<<"Warning: triangle index out of range! "<<backward_hit_triangles[i]<<endl; 197 else { 198 hitB.mObject = mPreprocessor.mFaceParents[backward_hit_triangles[i]].mObject; 199 hitB.mNormal = hitB.mObject->GetNormal(mPreprocessor.mFaceParents[backward_hit_triangles[i]].mFaceIndex); 200 201 // normalB = rays[index+i].mDirection; // $$ temporary 202 hitB.mPoint = rays[index+i].Extrap(-backward_dist[i]); 203 } 204 } 205 206 #if DEBUG_RAYCAST 207 Debug<<"PR\n"<<flush; 208 #endif 209 210 ProcessRay( 211 rays[index + i], 212 hitA, 213 hitB, 214 vssRays, 215 sbox, 216 castDoubleRay, 217 pruneInvalidRays 218 ); 219 } 220 205 } 206 207 #if DEBUG_RAYCAST 208 Debug<<"PR\n"<<flush; 209 #endif 210 211 ProcessRay(rays[index + i], 212 hitA, 213 hitB, 214 vssRays, 215 sbox, 216 castDoubleRay, 217 pruneInvalidRays 218 ); 219 } 220 221 221 #if DEBUG_RAYCAST 222 222 Debug<<"C16F\n"<<flush; -
GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp
r1765 r1786 56 56 return mItem.GetNormal(); 57 57 } 58 58 59 59 60 int -
GTP/trunk/Lib/Vis/Preprocessing/src/Parser.h
r1379 r1786 22 22 const bool loadMeshes = true, 23 23 std::vector<FaceParentInfo> *parents = NULL) 24 {return false;} ;24 {return false;} 25 25 26 26 }; -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1785 r1786 247 247 FaceContainer faces; 248 248 249 if (parents) 250 cout << "using face parents" << endl; 251 else 252 cout << "not using face parents" << endl; 253 249 254 while (1) 250 255 { … … 370 375 } 371 376 return result; 377 } 378 379 380 Intersectable *Preprocessor::GetParentObject(const int index) const 381 { 382 if (index == -1) 383 return NULL; 384 385 if (!mFaceParents.empty()) 386 { 387 if (index >= (int)mFaceParents.size()) 388 { 389 cerr<<"Warning: triangle index out of range! "<<index<<endl; 390 return NULL; 391 } 392 else 393 { 394 return mFaceParents[index].mObject; 395 } 396 } 397 else 398 { 399 if (index >= (int)mObjects.size()) 400 { 401 cerr<<"Warning: triangle index out of range! "<<index<<endl; 402 return NULL; 403 } 404 else 405 { 406 return mObjects[index]; 407 } 408 } 409 } 410 411 412 Vector3 Preprocessor::GetParentNormal(const int index) const 413 { 414 if (!mFaceParents.empty()) 415 { 416 return mFaceParents[index].mObject->GetNormal(mFaceParents[index].mFaceIndex); 417 } 418 else 419 { 420 return mObjects[index]->GetNormal(0); 421 } 372 422 } 373 423 … … 392 442 int rayCastMethod; 393 443 Environment::GetSingleton()->GetIntValue("Preprocessor.rayCastMethod", rayCastMethod); 394 vector<FaceParentInfo> *fi = ( rayCastMethod == RayCaster::INTEL_RAYCASTER) ?444 vector<FaceParentInfo> *fi = ((rayCastMethod == RayCaster::INTEL_RAYCASTER) || (!mLoadMeshes)) ? 395 445 &mFaceParents : NULL; 396 446 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r1785 r1786 121 121 bool ExportKdTree(const string filename); 122 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 123 virtual int 124 GenerateRays(const int number, 125 const SamplingStrategy &strategy, 126 SimpleRayContainer &rays); 127 128 virtual int GenerateRays(const int number, 129 const int raysType, 130 SimpleRayContainer &rays); 131 132 bool GenerateRayBundle(SimpleRayContainer &rayBundle, 133 const SimpleRay &mainRay, 134 const int number, 135 const int shuffleType) const; 136 137 virtual void CastRays(SimpleRayContainer &rays, 138 VssRayContainer &vssRays, 139 const bool castDoubleRays, 140 const bool pruneInvalidRays = true); 141 142 142 /** Returns a view cells manager of the given name. 143 143 */ … … 148 148 bool InitRayCast(const string externKdTree, const string internKdTree); 149 149 150 bool ExportObj(const string filename, const ObjectContainer &objects); 151 150 bool ExportObj(const string filename, const ObjectContainer &objects); 151 152 Intersectable *GetParentObject(const int index) const; 153 Vector3 GetParentNormal(const int index) const; 152 154 //////////////////////////////////////////////// 153 155 … … 202 204 bool mExportObj; 203 205 204 206 ofstream mStats; 205 207 206 208 GlRendererBuffer *renderer; … … 214 216 bool ExportBinaryObj(const string filename, SceneGraphNode *root); 215 217 216 217 218 void SetupRay(Ray &ray, const Vector3 &point, const Vector3 &direction) const; 218 219 219 220 void EvalPvsStat(); 220 221 221 virtual void 222 EvalViewCellHistogram(); 222 virtual void EvalViewCellHistogram(); 223 223 224 224 ///////////////////////// … … 229 229 /// samples used for construction of the VSP OSP tree. 230 230 int mVspOspConstructionSamples; 231 /** Simulates rendering of the scene. 232 */ 231 /// Simulates rendering of the scene. 233 232 RenderSimulator *mRenderSimulator; 234 233 -
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
r1764 r1786 407 407 void Pvs<T, S>::MergeInPlace(const Pvs<T, S> &a) 408 408 { 409 // early exit 410 if (a.Empty()) 411 { 412 return; 413 } 414 else if (Empty()) 415 { 416 mEntries.reserve(a.GetSize()); 417 mEntries = a.mEntries; 418 mSamples = a.mSamples; 419 return; 420 } 421 409 422 ObjectPvs interPvs; 410 423 … … 467 480 mEntries.clear(); 468 481 mSamples = 0; 469 vector<PvsEntry<T,S> >().swap(mEntries); 482 483 if (trim) 484 { 485 vector<PvsEntry<T,S> >().swap(mEntries); 486 } 470 487 } 471 488 … … 473 490 template <typename T, typename S> void Pvs<T, S>::Trim() 474 491 { 475 vector<PvsEntry<T,S> >(mEntries).swap(mEntries); //trim vi492 vector<PvsEntry<T,S> >(mEntries).swap(mEntries); 476 493 } 477 494 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1772 r1786 529 529 float totalRenderCost = 0; 530 530 531 ////////////////// 531 532 //-- compute statistics values of initial view cells 533 532 534 mViewCellsManager->EvaluateRenderStatistics(totalRenderCost, 533 535 mExpectedCost, … … 537 539 mAvgRenderCost); 538 540 539 541 ///////////// 540 542 //-- fill merge queue 541 543 vector<MergeCandidate> candidates; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1785 r1786 2591 2591 2592 2592 2593 void ViewCellsManager::MergeViewCellsEfficient(ObjectPvs &pvs, const ViewCellContainer &viewCells) const 2594 { 2595 LocalMergeTree mergeTree(viewCells); 2596 mergeTree.Merge(pvs); 2597 } 2598 2599 #if 1 2593 2600 PvsFilterStatistics 2594 2601 ViewCellsManager::ApplyFilter2(ViewCell *viewCell, … … 2602 2609 AxisAlignedBox3 vbox = GetViewCellBox(viewCell); 2603 2610 Vector3 center = vbox.Center(); 2604 // COpy the PVS2611 // copy the PVS 2605 2612 ObjectPvs basePvs = viewCell->GetPvs(); 2606 2613 Intersectable::NewMail(); … … 2740 2747 return stats; 2741 2748 } 2749 #else 2750 PvsFilterStatistics 2751 ViewCellsManager::ApplyFilter2(ViewCell *viewCell, 2752 const bool useViewSpaceFilter, 2753 const float filterSize, 2754 ObjectPvs &pvs 2755 ) 2756 {cout << "x"; 2757 PvsFilterStatistics stats; 2758 2759 AxisAlignedBox3 vbox = GetViewCellBox(viewCell); 2760 Vector3 center = vbox.Center(); 2761 // copy the PVS 2762 ObjectPvs basePvs = viewCell->GetPvs(); 2763 Intersectable::NewMail(); 2764 2765 ObjectPvsIterator pit = basePvs.GetIterator(); 2766 2767 #if !USE_KD_PVS 2768 // first mark all object from this pvs 2769 while (pit.HasMoreEntries()) { 2770 ObjectPvsEntry entry = pit.Next(); 2771 2772 Intersectable *object = entry.mObject; 2773 object->Mail(); 2774 } 2775 #endif 2776 2777 int pvsSize = 0; 2778 int nPvsSize = 0; 2779 float samples = (float)basePvs.GetSamples(); 2742 2780 2781 Debug<<"f #s="<<samples<<"pvs size = "<<basePvs.GetSize(); 2782 // cout<<"Filter size = "<<filterSize<<endl; 2783 // cout<<"vbox = "<<vbox<<endl; 2784 // cout<<"center = "<<center<<endl; 2785 2786 2787 // Minimal number of local samples to take into account 2788 // the local sampling density. 2789 // The size of the filter is a minimum of the conservative 2790 // local sampling density estimate (#rays intersecting teh viewcell and 2791 // the object) 2792 // and gobal estimate for the view cell 2793 // (total #rays intersecting the viewcell) 2794 #define MIN_LOCAL_SAMPLES 5 2795 2796 float viewCellRadius = 0.5f*Magnitude(vbox.Diagonal()); 2743 2797 2798 // now compute the filter box around the current viewCell 2799 2800 if (useViewSpaceFilter) { 2801 // float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 2802 float radius = viewCellRadius/100.0f; 2803 vbox.Enlarge(radius); 2804 cout<<"vbox = "<<vbox<<endl; 2805 ViewCellContainer viewCells; 2806 ComputeBoxIntersections(vbox, viewCells); 2807 ObjectPvs pvs; 2808 MergeViewCellsEfficient(pvs, viewCells); 2809 basePvs = pvs; 2810 2811 // update samples and globalC 2812 samples = (float)pvs.GetSamples(); 2813 // cout<<"neighboring viewcells = "<<i-1<<endl; 2814 // cout<<"Samples' = "<<samples<<endl; 2815 } 2816 2817 // Minimal number of samples so that filtering takes place 2818 #define MIN_SAMPLES 100 2819 if (samples > MIN_SAMPLES) { 2820 float globalC = 2.0f*filterSize/sqrt(samples); 2821 2822 pit = basePvs.GetIterator(); 2823 2824 ObjectContainer objects; 2825 2826 while (pit.HasMoreEntries()) 2827 { 2828 ObjectPvsEntry entry = pit.Next(); 2829 2830 Intersectable *object = entry.mObject; 2831 // compute filter size based on the distance and the numebr of samples 2832 AxisAlignedBox3 box = object->GetBox(); 2833 2834 float distance = Distance(center, box.Center()); 2835 float globalRadius = distance*globalC; 2836 2837 int objectSamples = (int)entry.mData.mSumPdf; 2838 float localRadius = MAX_FLOAT; 2839 if (objectSamples > MIN_LOCAL_SAMPLES) 2840 localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 2841 sqrt((float)objectSamples); 2842 2843 // cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 2844 2845 // now compute the filter size 2846 float radius; 2847 2848 if (localRadius < globalRadius) { 2849 radius = localRadius; 2850 stats.mLocalFilterCount++; 2851 } else { 2852 radius = globalRadius; 2853 stats.mGlobalFilterCount++; 2854 } 2855 2856 stats.mAvgFilterRadius += radius; 2857 2858 // cout<<"box = "<<box<<endl; 2859 // cout<<"distance = "<<distance<<endl; 2860 // cout<<"radiues = "<<radius<<endl; 2861 2862 box.Enlarge(Vector3(radius)); 2863 2864 objects.clear(); 2865 // $$ warning collect objects takes only unmailed ones! 2866 CollectObjects(box, objects); 2867 // cout<<"collected objects="<<objects.size()<<endl; 2868 ObjectContainer::const_iterator noi = objects.begin(); 2869 for (; noi != objects.end(); ++ noi) { 2870 Intersectable *o = *noi; 2871 // $$ JB warning: pdfs are not correct at this point! 2872 pvs.AddSampleDirty(o, Limits::Small); 2873 } 2874 } 2875 stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 2876 } 2877 2878 Debug<<" nPvs size = "<<pvs.GetSize()<<endl; 2879 2880 #if !USE_KD_PVS 2881 // copy the base pvs to the new pvs 2882 pit = basePvs.GetIterator(); 2883 while (pit.HasMoreEntries()) { 2884 ObjectPvsEntry entry = pit.Next(); 2885 pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf); 2886 } 2887 #endif 2888 viewCell->SetFilteredPvsSize(pvs.GetSize()); 2889 2890 Intersectable::NewMail(); 2891 return stats; 2892 } 2893 #endif 2744 2894 2745 2895 … … 6031 6181 //dummyStrat.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION); 6032 6182 6033 CastPassSamples(samplesPerPass, mStrategies, evaluationSamples); 6183 CastPassSamples(samplesPerPass, dummyStrat, evaluationSamples); 6184 //CastPassSamples(samplesPerPass, mStrategies, evaluationSamples); 6034 6185 6035 6186 castSamples += samplesPerPass; … … 6118 6269 } 6119 6270 #endif 6120 } 6271 6272 6273 LocalMergeTree::LocalMergeTree(const ViewCellContainer &viewCells): 6274 mViewCells(viewCells) 6275 { 6276 mRoot = Subdivide(0, (int)mViewCells.size()); 6277 } 6278 6279 6280 void LocalMergeTree::Merge(ObjectPvs &mergedPvs) 6281 { 6282 Merge(mRoot, mergedPvs); 6283 } 6284 6285 6286 void LocalMergeTree::Merge(LocalMergeNode *node, ObjectPvs &mergedPvs) 6287 { 6288 //////////////// 6289 //-- pvs is not stored with the interiors => reconstruct 6290 if (node->IsLeaf()) 6291 { 6292 LocalMergeLeaf *leaf = dynamic_cast<LocalMergeLeaf *>(node); 6293 mergedPvs = leaf->mViewCell->GetPvs(); 6294 } 6295 else 6296 { 6297 LocalMergeInterior *interior = dynamic_cast<LocalMergeInterior *>(node); 6298 6299 ObjectPvs leftPvs, rightPvs; 6300 6301 Merge(interior->mLeft, leftPvs); 6302 Merge(interior->mRight, rightPvs); 6303 6304 ObjectPvs::Merge(mergedPvs, leftPvs, rightPvs); 6305 } 6306 } 6307 6308 6309 LocalMergeNode *LocalMergeTree::Subdivide(const int leftIdx, const int rightIdx) 6310 { 6311 if (leftIdx == rightIdx) 6312 { 6313 return new LocalMergeLeaf(mViewCells[leftIdx]); 6314 } 6315 6316 LocalMergeInterior *interior = new LocalMergeInterior(); 6317 6318 const int midSplit = (leftIdx + rightIdx) / 2; 6319 6320 interior->mLeft = Subdivide(leftIdx, midSplit); 6321 interior->mRight = Subdivide(midSplit, rightIdx); 6322 6323 return interior; 6324 } 6325 6326 6327 6328 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1773 r1786 38 38 class BvHierarchy; 39 39 class ViewCellsTree; 40 class ViewCell; 40 41 41 42 struct AxisAlignedPlane; … … 64 65 // some characteristic values could be stored as well 65 66 }; 67 68 69 class LocalMergeNode 70 { 71 public: 72 virtual ~LocalMergeNode() {}; 73 virtual bool IsLeaf() const = 0; 74 }; 75 76 77 class LocalMergeLeaf: public LocalMergeNode 78 { 79 public: 80 LocalMergeLeaf(ViewCell *vc): mViewCell(vc) {}; 81 virtual ~LocalMergeLeaf() {}; 82 virtual bool IsLeaf() const { return true; } 83 84 ViewCell *mViewCell; 85 }; 86 87 88 class LocalMergeInterior: public LocalMergeNode 89 { 90 public: 91 92 virtual ~LocalMergeInterior() {DEL_PTR(mLeft); DEL_PTR(mRight);} 93 virtual bool IsLeaf() const { return false; } 94 95 LocalMergeNode *mLeft; 96 LocalMergeNode *mRight; 97 }; 98 99 100 class LocalMergeTree 101 { 102 public: 103 104 LocalMergeTree(const ViewCellContainer &viewCells); 105 106 void Merge(ObjectPvs &mergedPvs); 107 108 protected: 109 110 void Merge(LocalMergeNode *node, ObjectPvs &mergedPvs); 111 LocalMergeNode *Subdivide(const int leftIdx, const int rightIdx); 112 113 LocalMergeNode *mRoot; 114 const ViewCellContainer &mViewCells; 115 }; 116 66 117 67 118 /** Manages different higher order operations on the view cells. … … 452 503 bool GetExportPvs() const; 453 504 505 /** Efficiently merges the view cells in the container. 506 */ 507 void MergeViewCellsEfficient(ObjectPvs &pvs, const ViewCellContainer &viewCells) const; 508 509 454 510 ///////////////////////////// 455 511 // static members
Note: See TracChangeset
for help on using the changeset viewer.