Changeset 438 for trunk/VUT/GtpVisibilityPreprocessor
- Timestamp:
- 11/28/05 20:08:24 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r434 r438 1442 1442 RegisterOption("VssTree.minPvs", optInt, "kd_minpvs=", "1"); 1443 1443 RegisterOption("VssTree.minRays", optInt, "kd_minrays=", "10"); 1444 1445 1446 1447 1444 RegisterOption("VssTree.maxCostRatio", optFloat, "maxcost=", "0.95"); 1445 RegisterOption("VssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5"); 1446 1447 RegisterOption("VssTree.epsilon", optFloat, "kd_eps=", "1e-6"); 1448 1448 RegisterOption("VssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0"); 1449 1449 RegisterOption("VssTree.randomize", optBool, "randomize", "false"); … … 1470 1470 RegisterOption("VssTree.accessTimeThreshold", optInt, "accesstime=", "1000"); 1471 1471 RegisterOption("VssTree.minCollapseDepth", optInt, "colldepth=", "4"); 1472 1473 RegisterOption("VssTree.interleaveDirSplits", optBool, "interleavedirsplits", "true"); 1474 1475 RegisterOption("VssTree.dirSplitDepth", optInt, "dirsplidepth=", "10"); 1476 1477 1472 1478 } 1473 1479 -
trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
r434 r438 49 49 ExportKdTree(const KdTree &tree) = 0; 50 50 51 51 virtual bool 52 52 ExportVssTree(const VssTree &tree) = 0; 53 54 virtual bool 55 ExportVssTree2(const VssTree &tree, 56 const Vector3 direction 57 ) = 0; 53 58 54 59 virtual bool -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
r437 r438 236 236 237 237 if (mViewSpaceBox) { 238 exporter->SetForcedMaterial(RgbColor(1,0, 0));238 exporter->SetForcedMaterial(RgbColor(1,0,1)); 239 239 exporter->ExportBox(*mViewSpaceBox); 240 240 exporter->ResetForcedMaterial(); … … 257 257 bool 258 258 VssPreprocessor::ExportVssTree(char *filename, 259 VssTree *tree) 259 VssTree *tree, 260 const Vector3 &dir 261 ) 260 262 { 261 263 Exporter *exporter = Exporter::GetExporter(filename); 262 264 exporter->SetFilled(); 263 265 exporter->ExportScene(mSceneGraph->mRoot); 264 exporter->SetWireframe();265 bool result = exporter->ExportVssTree (*tree);266 // exporter->SetWireframe(); 267 bool result = exporter->ExportVssTree2( *tree, dir ); 266 268 delete exporter; 267 269 return result; … … 471 473 vssTree->Construct(mVssRays, mViewSpaceBox); 472 474 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 473 474 ExportVssTree("vss-tree.x3d", vssTree); 475 476 ExportVssTree("vss-tree-100.x3d", vssTree, Vector3(1,0,0)); 477 ExportVssTree("vss-tree-001.x3d", vssTree, Vector3(1,0,0)); 478 ExportVssTree("vss-tree-101.x3d", vssTree, Vector3(1,0,1)); 479 ExportVssTree("vss-tree-101m.x3d", vssTree, Vector3(-1,0,-1)); 475 480 476 481 ExportVssTreeLeaves(vssTree, 10); -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h
r434 r438 88 88 bool 89 89 ExportVssTree(char *filename, 90 VssTree *tree); 90 VssTree *tree, 91 const Vector3 &dir 92 ); 91 93 92 94 -
trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.cpp
r382 r438 9 9 bool 10 10 VssRay::ComputeMinMaxT(const AxisAlignedBox3 &box, 11 12 11 float &tmin, 12 float &tmax) const 13 13 { 14 14 … … 144 144 145 145 float 146 VssRay::GetDirParam(const int axis, const Vector3 dir) 147 { 148 return (axis == 0) ? atan2(dir.x, dir.z) : asin(dir.y); 149 } 150 151 float 146 152 VssRay::GetDirParametrization(const int axis) const 147 153 { 148 float angle; 149 Vector3 dir = GetNormalizedDir(); 150 if (axis == 0) { 151 angle = atan2(dir.x, dir.z); 152 } else { 153 angle = asin(dir.y); 154 } 155 return angle; 154 Vector3 dir = GetNormalizedDir(); 155 return GetDirParam(axis, dir); 156 156 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h
r434 r438 12 12 class VssRay { 13 13 public: 14 14 // various flags 15 15 enum { 16 16 FPosDirX = 1, // the direction of ray in X-axis is positive … … 19 19 }; 20 20 21 21 static int mailID; 22 22 int mMailbox; 23 23 24 25 26 27 24 // side of the ray - used for the ray classification 25 // char mSide; 26 27 // computed t 28 28 float mT; 29 29 30 31 32 33 30 // inverse of the ray size 31 float mInvSize; 32 33 // counter of references to this ray 34 34 short mRefCount; 35 36 35 36 // various flags 37 37 char mFlags; 38 38 … … 40 40 Vector3 mTermination; 41 41 42 43 44 45 46 47 48 49 50 51 52 42 /// Termination object for the ray 43 /// only the termination object is actually used 44 Intersectable *mOriginObject; 45 Intersectable *mTerminationObject; 46 47 ////////////////////////////// 48 VssRay(const Vector3 &origin, 49 const Vector3 &termination, 50 Intersectable *originObject, 51 Intersectable *terminationObject): 52 mMailbox(-1), 53 53 mOrigin(origin), 54 54 mTermination(termination), 55 56 57 55 mOriginObject(originObject), 56 mTerminationObject(terminationObject), 57 mRefCount(0), 58 58 mFlags(0), 59 59 mT(1.0f) 60 60 { 61 61 Precompute(); 62 62 } 63 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 64 VssRay(const Ray &ray): 65 mRefCount(0), 66 mFlags(0), 67 mMailbox(-1), 68 mOriginObject(ray.sourceObject.mObject), 69 mT(1.0f) 70 { 71 if (ray.sourceObject.mObject) 72 mOrigin = ray.Extrap(ray.sourceObject.mT); 73 else 74 mOrigin = ray.GetLoc(); 75 76 //Debug << "origin: " << mOrigin << endl; 77 78 if (!ray.intersections.empty()) 79 { 80 mTermination = ray.Extrap(ray.intersections[0].mT); 81 mTerminationObject = ray.intersections[0].mObject; 82 } 83 else 84 { 85 mTermination = ray.Extrap(1e6);//TODO: should be Limits::Infinity 86 mTerminationObject = NULL; 87 } 88 89 Precompute(); 90 } 91 91 92 92 void Precompute() { 93 93 mFlags = 0; 94 94 Vector3 dir = GetDir(); 95 95 96 96 #define BIDIRECTIONAL_RAY 0 97 97 #if BIDIRECTIONAL_RAY 98 99 100 101 102 103 98 if (dir.y < 0) { 99 // swap objects and poits 100 swap(mOriginObject, mTerminationObject); 101 swap(mOrigin, mTermination); 102 dir = -dir; 103 } 104 104 #endif 105 105 if (dir.x > 0.0f) mFlags |= FPosDirX; 106 106 if (dir.y > 0.0f) mFlags |= FPosDirY; 107 107 if (dir.z > 0.0f) mFlags |= FPosDirZ; … … 118 118 } 119 119 120 120 int HitCount() const { 121 121 #if BIDIRECTIONAL_RAY 122 123 124 125 126 122 if (mOriginObject && mTerminationObject) 123 return 2; 124 if (mOriginObject || mTerminationObject) 125 return 1; 126 return 0; 127 127 #else 128 128 return (mTerminationObject) ? 1 : 0; 129 129 #endif 130 131 132 130 } 131 132 Vector3 GetOrigin() const { return mOrigin; } 133 133 Vector3 GetTermination() const { return mTermination; } 134 134 Vector3 GetDir() const { return mTermination - mOrigin; } … … 136 136 Vector3 GetNormalizedDir() const { return (mTermination - mOrigin)*mInvSize; } 137 137 138 Vector3 Extrap(const float t) const { 139 return GetOrigin() + t * GetDir(); 140 } 141 142 float GetDirParametrization(const int axis) const; 143 144 float GetInvSize() const { return mInvSize; } 138 Vector3 Extrap(const float t) const { 139 return GetOrigin() + t * GetDir(); 140 } 141 142 float GetDirParametrization(const int axis) const; 143 144 static float VssRay::GetDirParam(const int axis, const Vector3 dir); 145 146 float GetSize() const { return 1.0f/mInvSize; } 147 float GetInvSize() const { return mInvSize; } 145 148 float GetOrigin(const int axis) const { return mOrigin[axis]; } 146 149 float GetTermination(const int axis) const { return mTermination[axis]; } … … 152 155 bool 153 156 ComputeMinMaxT(const AxisAlignedBox3 &box, 154 155 157 float &tmin, 158 float &tmax) const; 156 159 157 160 bool 158 161 Intersects(const AxisAlignedBox3 &box, 159 160 162 float &tmin, 163 float &tmax) const; 161 164 162 165 bool 163 166 IntersectsSphere(const Vector3 ¢er, 164 165 166 167 const float sqrRadius, 168 Vector3 &point, 169 float &t) const; 167 170 168 171 void … … 172 175 } 173 176 174 175 176 177 178 179 180 177 void SetupEndPoints(const Vector3 &origin, 178 const Vector3 &termination) 179 { 180 mOrigin = origin; 181 mTermination = termination; 182 Precompute(); 183 } 181 184 182 185 bool HasPosDir(const int axis) const { return mFlags & (1<<axis); } … … 198 201 else 199 202 if (mRefCount < 0) 200 203 mRefCount++; 201 204 else { 202 203 205 cerr<<"Trying to unref already deleted ray!"<<endl; 206 exit(1); 204 207 } 205 208 } 206 209 207 208 209 210 210 static Vector3 211 GetDirection(const float a, const float b) { 212 return Vector3(sin(a), sin(b), cos(a)); 213 } 211 214 212 215 }; -
trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.cpp
r435 r438 25 25 #include "Ray.h" 26 26 27 #define DEBUG_SPLIT_COST 0 27 28 28 29 // Static variables … … 119 120 environment->GetBoolValue("VssTree.splitUseOnlyDrivingAxis", mSplitUseOnlyDrivingAxis); 120 121 environment->GetBoolValue("VssTree.useRss", mUseRss); 121 122 123 environment->GetBoolValue("VssTree.interleaveDirSplits", mInterleaveDirSplits); 124 environment->GetIntValue("VssTree.dirSplitDepth", mDirSplitDepth); 125 122 126 root = NULL; 123 127 … … 230 234 mPvsSize = pvsSize; 231 235 mValidPvs = true; 236 232 237 } 233 238 } … … 316 321 stat.rays = leaf->rays.size(); 317 322 leaf->UpdatePvsSize(); 323 leaf->ComputeEntropyImportance(); 324 318 325 stat.initialPvsSize = leaf->GetPvsSize(); 319 326 // Subdivide(); … … 478 485 pvsFront 479 486 ); 480 487 #if DEBUG_SPLIT_COST 481 488 cout<<axis<<" r="<<costRatio<<endl; 482 489 #endif 483 490 if (costRatio > termMaxCostRatio) { 484 491 // cout<<"Too big cost ratio "<<costRatio<<endl; … … 675 682 bool allowDirSplit = Magnitude(sBox.Size())*dirSplitBoxSize < Magnitude(bbox.Size()); 676 683 677 678 for (axis = 0; axis < 5; axis++) { 679 if (!mSplitUseOnlyDrivingAxis || axis == sAxis || axis == dAxis) { 680 681 682 if (splitType == ESplitRegular) { 683 if (axis < 3) 684 nPosition[axis] = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f; 684 685 for (axis = 0; axis < 5; axis++) 686 if (mInterleaveDirSplits || 687 (axis < 3 && leaf->depth < mDirSplitDepth) || 688 (axis >= 3 && leaf->depth >= mDirSplitDepth) 689 ) { 690 if (!mSplitUseOnlyDrivingAxis || axis == sAxis || axis == dAxis) { 691 692 693 if (splitType == ESplitRegular) { 694 if (axis < 3) 695 nPosition[axis] = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f; 696 else 697 nPosition[axis] = (dBox.Min()[axis-3] + dBox.Max()[axis-3])*0.5f; 698 699 nCostRatio[axis] = EvalCostRatio(leaf, 700 axis, 701 nPosition[axis], 702 nRaysBack[axis], 703 nRaysFront[axis], 704 nPvsBack[axis], 705 nPvsFront[axis] 706 ); 707 } else 708 if (splitType == ESplitHeuristic) { 709 nCostRatio[axis] = EvalCostRatioHeuristic( 710 leaf, 711 axis, 712 nPosition[axis], 713 nRaysBack[axis], 714 nRaysFront[axis], 715 nPvsBack[axis], 716 nPvsFront[axis]); 717 } else 718 if (splitType == ESplitHybrid) { 719 if (leaf->depth > 7) 720 nCostRatio[axis] = EvalCostRatioHeuristic( 721 leaf, 722 axis, 723 nPosition[axis], 724 nRaysBack[axis], 725 nRaysFront[axis], 726 nPvsBack[axis], 727 nPvsFront[axis]); 728 else { 729 if (axis < 3) 730 nPosition[axis] = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f; 731 else 732 nPosition[axis] = (dBox.Min()[axis-3] + dBox.Max()[axis-3])*0.5f; 733 734 nCostRatio[axis] = EvalCostRatio(leaf, 735 axis, 736 nPosition[axis], 737 nRaysBack[axis], 738 nRaysFront[axis], 739 nPvsBack[axis], 740 nPvsFront[axis] 741 ); 742 } 743 } else { 744 cerr<<"VssTree: Unknown split heuristics\n"; 745 exit(1); 746 } 747 748 749 if ( bestAxis == -1) 750 bestAxis = axis; 685 751 else 686 nPosition[axis] = (dBox.Min()[axis-3] + dBox.Max()[axis-3])*0.5f; 687 688 nCostRatio[axis] = EvalCostRatio(leaf, 689 axis, 690 nPosition[axis], 691 nRaysBack[axis], 692 nRaysFront[axis], 693 nPvsBack[axis], 694 nPvsFront[axis] 695 ); 696 } else 697 if (splitType == ESplitHeuristic) { 698 nCostRatio[axis] = EvalCostRatioHeuristic( 699 leaf, 700 axis, 701 nPosition[axis], 702 nRaysBack[axis], 703 nRaysFront[axis], 704 nPvsBack[axis], 705 nPvsFront[axis]); 706 } else 707 if (splitType == ESplitHybrid) { 708 if (leaf->depth > 7) 709 nCostRatio[axis] = EvalCostRatioHeuristic( 710 leaf, 711 axis, 712 nPosition[axis], 713 nRaysBack[axis], 714 nRaysFront[axis], 715 nPvsBack[axis], 716 nPvsFront[axis]); 717 else { 718 if (axis < 3) 719 nPosition[axis] = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f; 720 else 721 nPosition[axis] = (dBox.Min()[axis-3] + dBox.Max()[axis-3])*0.5f; 722 723 nCostRatio[axis] = EvalCostRatio(leaf, 724 axis, 725 nPosition[axis], 726 nRaysBack[axis], 727 nRaysFront[axis], 728 nPvsBack[axis], 729 nPvsFront[axis] 730 ); 731 } 732 } else { 733 cerr<<"VssTree: Unknown split heuristics\n"; 734 exit(1); 735 } 736 737 738 if ( bestAxis == -1) 739 bestAxis = axis; 740 else 741 if ( nCostRatio[axis] < nCostRatio[bestAxis] ) 742 bestAxis = axis; 743 } 744 } 745 752 if ( nCostRatio[axis] < nCostRatio[bestAxis] ) 753 bestAxis = axis; 754 } 755 } 756 746 757 axis = bestAxis; 747 758 position = nPosition[bestAxis]; … … 775 786 minBox = box.Min(axis); 776 787 maxBox = box.Max(axis); 777 } 778 else { 788 } else { 779 789 box = GetDirBBox(leaf); 780 790 minBox = box.Min(axis-3); … … 1111 1121 front->SetPvsSize(pvsFront); 1112 1122 back->SetPvsSize(pvsBack); 1113 1123 // compute entropy as well 1124 front->ComputeEntropyImportance(); 1125 back->ComputeEntropyImportance(); 1126 1114 1127 // update stats 1115 1128 stat.rayRefs -= leaf->rays.size(); … … 1832 1845 VssTreeLeaf::GetImportance() const 1833 1846 { 1834 return GetAvgRayContribution(); 1835 } 1847 1848 if (1) { 1849 // return GetAvgRayContribution(); 1850 return GetPvsSize(); 1851 } else { 1852 return GetAvgRayContribution()*mEntropyImportance; 1853 } 1854 } 1855 1856 1857 float 1858 VssTreeLeaf::ComputePvsEntropy() 1859 { 1860 int samples = 0; 1861 Intersectable::NewMail(); 1862 // set all object as belonging to the fron pvs 1863 for(VssTreeNode::RayInfoContainer::iterator ri = rays.begin(); 1864 ri != rays.end(); 1865 ri++) 1866 if ((*ri).mRay->IsActive()) { 1867 Intersectable *object = (*ri).mRay->mTerminationObject; 1868 if (object) { 1869 if (!object->Mailed()) { 1870 object->Mail(); 1871 object->mCounter = 1; 1872 } else 1873 object->mCounter++; 1874 samples++; 1875 } 1876 } 1877 1878 float entropy = 0.0f; 1879 1880 if (samples > 1) { 1881 Intersectable::NewMail(); 1882 for(RayInfoContainer::const_iterator ri = rays.begin(); 1883 ri != rays.end(); 1884 ri++) 1885 if ((*ri).mRay->IsActive()) { 1886 Intersectable *object = (*ri).mRay->mTerminationObject; 1887 if (object) { 1888 if (!object->Mailed()) { 1889 object->Mail(); 1890 float p = object->mCounter/(float)samples; 1891 entropy -= p*log(p); 1892 } 1893 } 1894 } 1895 entropy = entropy/log((float)samples); 1896 } 1897 else 1898 entropy = 1.0f; 1899 1900 return entropy; 1901 } 1902 1903 float 1904 VssTreeLeaf::ComputeRayLengthEntropy() 1905 { 1906 // get sum of all ray lengths 1907 // consider only passing rays or originating rays 1908 float sum = 0.0f; 1909 int samples = 0; 1910 1911 for(RayInfoContainer::const_iterator ri = rays.begin(); 1912 ri != rays.end(); 1913 ri++) { 1914 int rayClass = (*ri).GetRayClass(); 1915 if ( 1916 rayClass == RayInfo::PASSING_RAY 1917 // || 1918 // rayClass == RayInfo::SOURCE_RAY 1919 // rayClass == RayInfo::TERMINATION_RAY 1920 ) { 1921 float c = 1.0f - (*ri).GetMaxT(); 1922 sum += (*ri).mRay->GetSize()*c; 1923 samples++; 1924 } 1925 } 1926 1927 float entropy = 0.0f; 1928 1929 if (samples > 1) { 1930 for(RayInfoContainer::const_iterator ri = rays.begin(); 1931 ri != rays.end(); 1932 ri++) { 1933 int rayClass = (*ri).GetRayClass(); 1934 if ( 1935 rayClass == RayInfo::PASSING_RAY 1936 // || 1937 // rayClass == RayInfo::SOURCE_RAY 1938 // rayClass == RayInfo::TERMINATION_RAY 1939 ) { 1940 float c = 1.0f - (*ri).GetMaxT(); 1941 float p = (*ri).mRay->GetSize()*c/sum; 1942 entropy -= p*log(p); 1943 } 1944 } 1945 entropy = entropy/log((float)samples); 1946 } else 1947 entropy = 1.0f; 1948 1949 return entropy; 1950 } 1951 1952 float 1953 VssTreeLeaf::ComputeRayTerminationEntropy() 1954 { 1955 1956 return 0.0f; 1957 } 1958 1959 1960 void 1961 VssTreeLeaf::ComputeEntropyImportance() 1962 { 1963 // mEntropy = 1.0f - ComputeRayLengthEntropy(); 1964 mEntropyImportance = 1.0f - ComputePvsEntropy(); 1965 1966 // cout<<"ei="<<mEntropyImportance<<" "; 1967 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.h
r435 r438 44 44 // totals number of rays 45 45 int rays; 46 46 // initial size of the pvs 47 47 int initialPvsSize; 48 48 // total number of query domains 49 49 int queryDomains; 50 50 // total number of ray references 51 51 int rayRefs; 52 52 53 53 // max depth nodes 54 54 int maxDepthNodes; 55 55 // max depth nodes 56 56 int minPvsNodes; 57 57 int minRaysNodes; 58 58 // max ray contribution nodes 59 59 int maxRayContribNodes; 60 60 // max depth nodes 61 61 int minSizeNodes; 62 62 int maxCostRatioNodes; … … 89 89 maxRayRefs = 0; 90 90 addedRayRefs = removedRayRefs = 0; 91 92 93 94 91 initialPvsSize = 0; 92 maxRayContribNodes = 0; 93 minSizeNodes = 0; 94 maxCostRatioNodes = 0; 95 95 } 96 96 … … 123 123 SortableEntry() {} 124 124 SortableEntry(const int t, const float v, void *d):type(t), 125 126 125 value(v), 126 data(d) {} 127 127 128 128 friend bool operator<(const SortableEntry &a, const SortableEntry &b) { … … 144 144 #define USE_FIXEDPOINT_T 0 145 145 146 struct RayInfo147 {146 struct RayInfo 147 { 148 148 // pointer to the actual ray 149 149 VssRay *mRay; … … 161 161 #if USE_FIXEDPOINT_T 162 162 #define FIXEDPOINT_ONE 0x7FFE 163 164 163 // mMaxT(0xFFFF) 164 mMaxT(FIXEDPOINT_ONE) 165 165 #else 166 166 mMaxT(1.0f) 167 167 #endif 168 168 {} 169 169 170 170 RayInfo(VssRay *r, 171 172 173 174 175 171 const float _min, 172 const float _max 173 ):mRay(r) { 174 SetMinT(_min); 175 SetMaxT(_max); 176 176 } 177 177 178 178 RayInfo(VssRay *r, 179 180 181 182 179 const short _min, 180 const float _max 181 ):mRay(r), mMinT(_min) { 182 SetMaxT(_max); 183 183 } 184 184 185 185 RayInfo(VssRay *r, 186 187 188 189 186 const float _min, 187 const short _max 188 ):mRay(r), mMaxT(_max) { 189 SetMinT(_min); 190 190 } 191 191 192 192 enum { 193 194 195 196 193 SOURCE_RAY = 0, 194 TERMINATION_RAY, 195 PASSING_RAY, 196 CONTAINED_RAY 197 197 }; 198 198 199 199 int GetRayClass() const { 200 200 201 202 201 bool startsBefore = GetMinT() > 0.0f; 202 bool terminatesAfter = GetMaxT() < 1.0f; 203 203 204 205 206 207 208 204 if (startsBefore && terminatesAfter) 205 return PASSING_RAY; 206 207 if (!startsBefore && !terminatesAfter) 208 return CONTAINED_RAY; 209 209 210 211 210 if (!startsBefore) 211 return SOURCE_RAY; 212 212 213 213 return TERMINATION_RAY; 214 214 } 215 215 216 216 friend bool operator<(const RayInfo &a, const RayInfo &b) { 217 217 return a.mRay < b.mRay; 218 218 } 219 219 220 220 221 221 float ExtrapOrigin(const int axis) const { 222 222 return mRay->GetOrigin(axis) + GetMinT()*mRay->GetDir(axis); 223 223 } 224 224 225 225 float ExtrapTermination(const int axis) const { 226 226 return mRay->GetOrigin(axis) + GetMaxT()*mRay->GetDir(axis); 227 227 } 228 228 229 229 Vector3 Extrap(const float t) const { 230 230 return mRay->Extrap(t); 231 231 } 232 232 … … 236 236 237 237 void SetMinT (const float t) { 238 238 mMinT = (short) (t*(float)(FIXEDPOINT_ONE)); 239 239 } 240 240 241 241 void SetMaxT (const float t) { 242 243 244 245 242 mMaxT = (short) (t*(float)(FIXEDPOINT_ONE)); 243 mMaxT++; 244 // if (mMaxT!=0xFFFF) 245 // mMaxT++; 246 246 } 247 247 #else … … 254 254 255 255 256 257 258 259 256 int ComputeRayIntersection(const int axis, 257 const float position, 258 float &t 259 ) const { 260 260 261 262 261 // intersect the ray with the plane 262 float denom = mRay->GetDir(axis); 263 263 264 265 266 264 if (fabs(denom) < 1e-20) 265 //if (denom == 0.0f) 266 return (mRay->GetOrigin(axis) > position) ? 1 : -1; 267 267 268 269 270 271 272 273 274 275 276 277 } 278 279 280 };281 282 283 268 t = (position - mRay->GetOrigin(axis))/denom; 269 270 if (t < GetMinT()) 271 return (denom > 0) ? 1 : -1; 272 273 if (t > GetMaxT()) 274 return (denom > 0) ? -1 : 1; 275 276 return 0; 277 } 278 279 280 }; 281 282 283 typedef vector<RayInfo> RayInfoContainer; 284 284 285 285 enum { EInterior, ELeaf }; … … 346 346 347 347 VssTreeInterior(VssTreeInterior *p):VssTreeNode(p), 348 back(NULL),349 front(NULL),350 accesses(0),351 lastAccessTime(-1)348 back(NULL), 349 front(NULL), 350 accesses(0), 351 lastAccessTime(-1) 352 352 { } 353 353 … … 383 383 else 384 384 if (axis == 1) 385 s<<"y ";385 s<<"y "; 386 386 else 387 s<<"z ";387 s<<"z "; 388 388 s<<position<<" "; 389 389 back->Print(s); … … 394 394 395 395 int ComputeRayIntersection(const RayInfo &rayData, 396 397 398 396 float &t 397 ) { 398 return rayData.ComputeRayIntersection(axis, position, t); 399 399 } 400 400 … … 409 409 { 410 410 private: 411 411 int mPvsSize; 412 412 public: 413 413 static int mailID; … … 415 415 416 416 RayInfoContainer rays; 417 418 419 420 421 417 int mPassingRays; 418 419 bool mValidPvs; 420 float mEntropyImportance; 421 422 422 423 423 VssTreeLeaf(VssTreeInterior *p, 424 425 424 const int nRays 425 ):VssTreeNode(p), rays(), mPvsSize(0), mPassingRays(0), mValidPvs(false) { 426 426 rays.reserve(nRays); 427 427 } … … 436 436 437 437 void AddRay(const RayInfo &data) { 438 438 mValidPvs = false; 439 439 rays.push_back(data); 440 440 data.mRay->Ref(); 441 if (data.GetRayClass() == RayInfo::PASSING_RAY) 442 mPassingRays++; 443 } 444 445 int GetPvsSize() const { 446 return mPvsSize; 447 } 448 void SetPvsSize(const int s) { 449 mPvsSize = s; 450 mValidPvs = true; 451 } 452 453 void 454 UpdatePvsSize(); 441 if (data.GetRayClass() == RayInfo::PASSING_RAY) 442 mPassingRays++; 443 } 444 445 int GetPvsSize() const { 446 return mPvsSize; 447 } 448 449 void SetPvsSize(const int s) { 450 mPvsSize = s; 451 mValidPvs = true; 452 } 453 454 void 455 UpdatePvsSize(); 456 457 float 458 ComputePvsEntropy(); 459 460 float 461 ComputeRayLengthEntropy(); 462 463 float 464 ComputeRayTerminationEntropy(); 465 466 void 467 ComputeEntropyImportance(); 455 468 456 469 void Mail() { mailbox = mailID; } … … 462 475 } 463 476 464 465 466 477 float GetAvgRayContribution() const { 478 return GetPvsSize()/((float)rays.size() + Limits::Small); 479 } 467 480 468 481 float GetImportance() const; 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 482 483 float GetSqrRayContribution() const { 484 return sqr(GetPvsSize()/((float)rays.size() + Limits::Small)); 485 } 486 487 // comparator for the 488 struct less_contribution : public 489 binary_function<const VssTreeLeaf *, const VssTreeLeaf *, bool> { 490 491 bool operator()(const VssTreeLeaf * a, const VssTreeLeaf *b) { 492 return a->GetAvgRayContribution() < b->GetAvgRayContribution(); 493 } 494 }; 495 496 struct greater_contribution : public 497 binary_function<const VssTreeLeaf *, const VssTreeLeaf *, bool> { 498 499 bool operator()(const VssTreeLeaf * a, const VssTreeLeaf *b) { 500 return a->GetAvgRayContribution() > b->GetAvgRayContribution(); 501 } 502 }; 503 504 friend bool GreaterContribution(const VssTreeLeaf * a, const VssTreeLeaf *b) { 505 return a->GetAvgRayContribution() > b->GetAvgRayContribution(); 506 } 507 495 508 }; 496 509 … … 521 534 522 535 TraversalData(VssTreeNode *n, 523 524 536 const AxisAlignedBox3 &b, 537 const int d): 525 538 node(n), bbox(b), depth(d) {} 526 539 … … 531 544 532 545 bool operator()(const TraversalData a, const TraversalData b) { 533 546 return a.priority < b.priority; 534 547 } 535 548 … … 540 553 541 554 friend bool operator<(const TraversalData &a, 542 555 const TraversalData &b) { 543 556 // return a.node->queries.size() < b.node->queries.size(); 544 557 VssTreeLeaf *leafa = (VssTreeLeaf *) a.node; 545 558 VssTreeLeaf *leafb = (VssTreeLeaf *) b.node; 546 559 #if 0 547 548 549 550 560 return 561 leafa->rays.size()*a.bbox.GetVolume() 562 < 563 leafb->rays.size()*b.bbox.GetVolume(); 551 564 #endif 552 565 #if 0 553 554 555 556 566 return 567 leafa->GetPvsSize()*a.bbox.GetVolume() 568 < 569 leafb->GetPvsSize()*b.bbox.GetVolume(); 557 570 #endif 558 571 #if 0 559 560 561 562 572 return 573 leafa->GetPvsSize() 574 < 575 leafb->GetPvsSize(); 563 576 #endif 564 577 #if 0 565 566 567 568 578 return 579 leafa->GetPvsSize()/(leafa->rays.size()+1) 580 > 581 leafb->GetPvsSize()/(leafb->rays.size()+1); 569 582 #endif 570 583 #if 1 571 572 573 574 584 return 585 leafa->GetPvsSize()*leafa->rays.size() 586 < 587 leafb->GetPvsSize()*leafb->rays.size(); 575 588 #endif 576 589 } … … 586 599 RayTraversalData() {} 587 600 RayTraversalData(VssTreeNode *n, 588 601 const VssTreeNode::RayInfo &data): 589 602 rayData(data), node(n) {} 590 603 }; … … 619 632 float termMinSize; 620 633 621 634 // minimal pvs per node to still get subdivided 622 635 int termMinPvs; 623 636 624 637 // minimal ray number per node to still get subdivided 625 638 int termMinRays; 626 639 … … 628 641 float termMaxCostRatio; 629 642 630 631 643 // maximal contribution per ray to subdivide the node 644 float termMaxRayContribution; 632 645 633 646 634 647 // randomized construction 635 648 bool randomize; 636 649 637 650 // type of the splitting to use fo rthe tree construction 638 651 enum {ESplitRegular, ESplitHeuristic, ESplitHybrid }; 639 652 int splitType; 640 653 641 bool mSplitUseOnlyDrivingAxis; 642 643 // use ray space subdivision instead of view space subdivision 644 bool mUseRss; 645 654 bool mSplitUseOnlyDrivingAxis; 655 656 // use ray space subdivision instead of view space subdivision 657 bool mUseRss; 658 659 // interleave directional and spatial splits based on their costs 660 // if false directional splits are only performed after spatial splits 661 bool mInterleaveDirSplits; 662 663 // depth at which directional splits are performed if mInterleaveDirSplits is false 664 int mDirSplitDepth; 665 646 666 // maximal size of the box on which the refdir splitting can be performed 647 667 // (relative to the scene bbox … … 662 682 int accessTimeThreshold; 663 683 664 684 // minimal depth at which to perform collapse 665 685 int minCollapseDepth; 666 686 … … 670 690 ///////////////////////////// 671 691 672 692 VssStatistics stat; 673 693 674 694 … … 678 698 virtual void 679 699 Construct( 680 681 682 700 VssRayContainer &rays, 701 AxisAlignedBox3 *forcedBoundingBox = NULL 702 ); 683 703 684 704 // incemental construction 685 705 virtual void UpdateRays(VssRayContainer &remove, 686 687 688 689 690 691 692 693 694 695 706 VssRayContainer &add 707 ); 708 709 virtual void AddRays( 710 VssRayContainer &add 711 ) 712 { 713 VssRayContainer remove; 714 UpdateRays(remove, add); 715 } 696 716 697 717 … … 702 722 VssTreeNode * 703 723 SubdivideNode(VssTreeLeaf *leaf, 704 705 706 707 724 const AxisAlignedBox3 &box, 725 AxisAlignedBox3 &backBox, 726 AxisAlignedBox3 &frontBox 727 ); 708 728 709 729 VssTreeNode * … … 712 732 int 713 733 SelectPlane(VssTreeLeaf *leaf, 714 715 716 717 718 719 720 734 const AxisAlignedBox3 &box, 735 float &position, 736 int &raysBack, 737 int &raysFront, 738 int &pvsBack, 739 int &pvsFront 740 ); 721 741 722 742 void 723 743 SortSplitCandidates( 724 725 726 744 VssTreeLeaf *node, 745 const int axis 746 ); 727 747 728 748 … … 742 762 743 763 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 764 float 765 BestCostRatio( 766 VssTreeLeaf *node, 767 int &axis, 768 float &position, 769 int &raysBack, 770 int &raysFront, 771 int &pvsBack, 772 int &pvsFront 773 ); 774 775 float 776 EvalCostRatio( 777 VssTreeLeaf *node, 778 const int axis, 779 const float position, 780 int &raysBack, 781 int &raysFront, 782 int &pvsBack, 783 int &pvsFront 784 ); 785 786 float 787 EvalCostRatioHeuristic( 788 VssTreeLeaf *node, 789 const int axis, 790 float &position, 791 int &raysBack, 792 int &raysFront, 793 int &pvsBack, 794 int &pvsFront 795 ); 796 797 float 798 GetCostRatio( 799 VssTreeLeaf *leaf, 800 const int axis, 801 const float position, 802 const int raysBack, 803 const int raysFront, 804 const int pvsBack, 805 const int pvsFront 806 ); 787 807 788 808 AxisAlignedBox3 GetBBox(const VssTreeNode *node) const { … … 838 858 VssTreeNode * 839 859 SubdivideLeaf( 840 841 860 VssTreeLeaf *leaf 861 ); 842 862 843 863 void 844 864 RemoveRay(VssRay *ray, 845 846 847 848 849 850 851 852 853 865 vector<VssTreeLeaf *> *affectedLeaves, 866 const bool removeAllScheduledRays 867 ); 868 869 // void 870 // AddRay(VssRay *ray); 871 void 872 AddRay(VssTreeNode::RayInfo &info); 873 854 874 void 855 875 TraverseInternalNode( 856 857 858 859 876 RayTraversalData &data, 877 stack<RayTraversalData> &tstack); 878 879 void 860 880 EvaluateLeafStats(const TraversalData &data); 861 881 862 882 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 883 int 884 GetRootPvsSize() const { 885 return GetPvsSize(bbox); 886 } 887 888 int 889 GetPvsSize(const AxisAlignedBox3 &box) const; 890 891 void 892 GetRayContributionStatistics( 893 float &minRayContribution, 894 float &maxRayContribution, 895 float &avgRayContribution 896 ); 897 898 int 899 GenerateRays(const float ratioPerLeaf, 900 SimpleRayContainer &rays); 901 902 int 903 GenerateRays(const int numberOfRays, 904 const int numberOfLeaves, 905 SimpleRayContainer &rays); 886 906 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 907 float 908 GetAvgPvsSize(); 909 910 int 911 UpdateSubdivision(); 912 913 bool 914 TerminationCriteriaSatisfied(VssTreeLeaf *leaf); 915 916 void 917 CollectLeaves(vector<VssTreeLeaf *> &leaves); 918 919 bool 920 ClipRay( 921 VssTreeNode::RayInfo &rayInfo, 922 const AxisAlignedBox3 &box 923 ); 924 925 VssTreeNode *GetRoot() const { return root; } 926 927 bool 928 ValidLeaf(VssTreeLeaf *leaf) const; 929 930 void 931 GenerateLeafRays(VssTreeLeaf *leaf, 932 const int numberOfRays, 933 SimpleRayContainer &rays); 914 934 915 935 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r436 r438 725 725 726 726 bool 727 X3dExporter::ExportVssTree(const VssTree &tree) 727 X3dExporter::ExportVssTree(const VssTree &tree 728 ) 728 729 { 729 730 stack<VssTreeNode *> tStack; … … 763 764 764 765 Vector3 direction = VssRay::GetDirection(v.x, v.y); 765 direction.Normalize(); 766 if (Magnitude(direction) > Limits::Small) 767 direction.Normalize(); 768 else 769 direction = Vector3(0, 1, 0); 766 770 float k = 100.0f*leaf->GetImportance(); 767 771 // get 4 corners of the ray directions … … 775 779 776 780 ExportMesh(mesh); 777 778 781 ExportRays(rays); 782 CLEAR_CONTAINER(rays); 779 783 delete mesh; 784 return true; 785 } 786 787 bool 788 X3dExporter::ExportVssTree2(const VssTree &tree, 789 const Vector3 direction 790 ) 791 { 792 stack<VssTreeNode *> tStack; 793 794 795 mUseForcedMaterial = true; 796 797 Vector3 dirParam; 798 799 dirParam.x = VssRay::GetDirParam(0, Normalize(direction)); 800 dirParam.y = VssRay::GetDirParam(1, Normalize(direction)); 801 802 float maxImportance = 0.0f; 803 tStack.push(tree.GetRoot()); 804 while (!tStack.empty()) { 805 806 VssTreeNode *node = tStack.top(); 807 tStack.pop(); 808 809 if (!node->IsLeaf()) { 810 VssTreeInterior *interior = (VssTreeInterior *)node; 811 if (interior->axis < 3) { 812 tStack.push(interior->front); 813 tStack.push(interior->back); 814 } else { 815 if (dirParam[interior->axis-3] < interior->position) 816 tStack.push(interior->back); 817 else 818 tStack.push(interior->front); 819 } 820 } else { 821 VssTreeLeaf *leaf = (VssTreeLeaf *)node; 822 if (tree.ValidLeaf(leaf)) { 823 float i = leaf->GetImportance(); 824 if (i > maxImportance) 825 maxImportance = i; 826 } 827 } 828 } 829 830 tStack.push(tree.GetRoot()); 831 while (!tStack.empty()) { 832 833 VssTreeNode *node = tStack.top(); 834 tStack.pop(); 835 836 837 if (!node->IsLeaf()) { 838 VssTreeInterior *interior = (VssTreeInterior *)node; 839 if (interior->axis < 3) { 840 tStack.push(interior->front); 841 tStack.push(interior->back); 842 } else { 843 if (dirParam[interior->axis-3] < interior->position) 844 tStack.push(interior->back); 845 else 846 tStack.push(interior->front); 847 } 848 } else { 849 VssTreeLeaf *leaf = (VssTreeLeaf *)node; 850 if (tree.ValidLeaf(leaf)) { 851 AxisAlignedBox3 box; 852 box = tree.GetBBox(leaf); 853 Mesh *mesh = new Mesh; 854 AddBoxToMesh(box, mesh); 855 856 // get 4 corners of the ray directions 857 858 mForcedMaterial.mDiffuseColor.b = 1.0f; 859 mForcedMaterial.mDiffuseColor.r = leaf->GetImportance()/maxImportance; 860 mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r; 861 862 ExportMesh(mesh); 863 delete mesh; 864 } 865 } 866 } 867 868 mUseForcedMaterial = false; 869 780 870 return true; 781 871 } … … 808 898 { 809 899 float importance = 810 811 900 vc->mPassingRays.mContributions / (float)vc->mPassingRays.mRays; 901 812 902 mForcedMaterial.mDiffuseColor.r = importance; 813 903 mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r; 814 904 ExportViewCell(vc); 815 } 905 } 816 906 } else 817 907 { -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
r434 r438 39 39 ExportKdTree(const KdTree &tree); 40 40 41 41 bool 42 42 ExportVssTree(const VssTree &tree); 43 43 44 bool 45 ExportVssTree2(const VssTree &tree, 46 const Vector3 direction 47 ); 48 44 49 bool 45 50 ExportVspKdTree(const VspKdTree &tree, const int maxPvs); -
trunk/VUT/GtpVisibilityPreprocessor/src/default.env
r435 r438 15 15 # filename ../data/atlanta/atlanta2.x3d 16 16 # filename ../data/soda/soda.dat 17 17 filename ../data/soda/soda5.dat 18 18 } 19 19 … … 25 25 VssPreprocessor { 26 26 samplesPerPass 100000 27 initialSamples 20000027 initialSamples 500000 28 28 vssSamples 1000000 29 29 vssSamplesPerPass 50000 … … 39 39 minRays 100 40 40 minSize 0.001 41 maxCostRatio 0.9841 maxCostRatio 2.0 42 42 maxRayContribution 0.05 43 43 44 44 maxTotalMemory 200 45 maxStaticMemory 5045 maxStaticMemory 100 46 46 47 47 splitType regular … … 49 49 # splitType hybrid 50 50 splitUseOnlyDrivingAxis true 51 52 interleaveDirSplits false 53 dirSplitDepth 12 51 54 52 55 numberOfEndPointDomains 10000
Note: See TracChangeset
for help on using the changeset viewer.