Changeset 1199 for GTP/trunk/Lib/Vis/Preprocessing
- Timestamp:
- 08/11/06 15:23:47 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BoostPreprocessorThread.cpp
r1184 r1199 23 23 void BoostPreprocessorThread::Main() 24 24 { 25 25 Camera camera; 26 26 27 27 if (0) 28 28 { 29 29 // camera.LookAtBox(mPreprocessor->mKdTree->GetBox()); … … 36 36 camera.SnapImage("camera.jpg", mPreprocessor->mKdTree, mPreprocessor->mSceneGraph); 37 37 } 38 39 if (0) { 40 camera.LookInBox(mPreprocessor->mKdTree->GetBox()); 41 camera.SetPosition(camera.mPosition + Vector3(-250,0,-550)); 42 camera.SnapImage("camera2.jpg", mPreprocessor->mKdTree, mPreprocessor->mSceneGraph); 43 } 38 44 39 if (0) { 40 camera.LookInBox(mPreprocessor->mKdTree->GetBox()); 41 camera.SetPosition(camera.mPosition + Vector3(-250,0,-550)); 42 camera.SnapImage("camera2.jpg", mPreprocessor->mKdTree, mPreprocessor->mSceneGraph); 43 } 44 45 if (0) { 46 camera.SetPosition( mPreprocessor->mKdTree->GetBox().Center() - Vector3(0,-100,0) ); 47 camera.SetDirection(Vector3(1, 0, 0)); 48 camera.SnapImage("camera3.jpg", mPreprocessor->mKdTree, mPreprocessor->mSceneGraph); 49 } 50 51 if (mPreprocessor->mComputeVisibility) { 52 mPreprocessor->ComputeVisibility(); 53 // mPreprocessor->ExportPreprocessedData("scene.vis"); 54 mPreprocessor->PostProcessVisibility(); 55 } 56 57 cerr << "Preprocessor main finished...\n"; 45 if (0) { 46 camera.SetPosition( mPreprocessor->mKdTree->GetBox().Center() - Vector3(0,-100,0) ); 47 camera.SetDirection(Vector3(1, 0, 0)); 48 camera.SnapImage("camera3.jpg", mPreprocessor->mKdTree, mPreprocessor->mSceneGraph); 49 } 50 51 if (mPreprocessor->mComputeVisibility) { 52 mPreprocessor->ComputeVisibility(); 53 // mPreprocessor->ExportPreprocessedData("scene.vis"); 54 mPreprocessor->PostProcessVisibility(); 55 } 56 57 cerr << "Preprocessor main finished...\n"; 58 58 59 59 } … … 62 62 BoostPreprocessorThread::~BoostPreprocessorThread() 63 63 { 64 65 64 cerr << "Boost Preprocessor thread destructor ... \n"; 65 DEL_PTR(mThread); 66 66 } 67 67 … … 69 69 void BoostPreprocessorThread::InitThread() 70 70 { 71 71 mThread = new boost::thread(*this); 72 72 } 73 73 … … 75 75 void BoostPreprocessorThread::RunThread() 76 76 { 77 77 mThread->join(); 78 78 } 79 79 80 80 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1174 r1199 1816 1816 "false"); 1817 1817 1818 RegisterOption("RssTree.hybridDepth", optInt, "hybrid_depth=", "10"); 1818 1819 RegisterOption("RssTree.maxDepth", optInt, "kd_depth=", "12"); 1819 1820 RegisterOption("RssTree.minPvs", optInt, "kd_minpvs=", "1"); … … 1825 1826 RegisterOption("RssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0"); 1826 1827 RegisterOption("RssTree.randomize", optBool, "randomize=", "false"); 1827 RegisterOption("RssTree.splitType", optString, " split=", "queries");1828 RegisterOption("RssTree.splitType", optString, "rss_split=", "queries"); 1828 1829 RegisterOption("RssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false"); 1829 1830 … … 2354 2355 if (!GetParam(' ', 0, filename)) { 2355 2356 // user didn't specified environment file explicitly, so 2356 strcpy(filename, "default. Environment::GetSingleton()");2357 strcpy(filename, "default.env"); 2357 2358 } 2358 2359 -
GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
r1112 r1199 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (2.00a) (Qt 4.1.2) on: p o 10. VII 19:18:4520063 # Generated by qmake (2.00a) (Qt 4.1.2) on: pá 11. VIII 14:29:54 2006 4 4 # Project: preprocessor.pro 5 5 # Template: app -
GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp
r1076 r1199 164 164 Ray &ray, 165 165 float &nearestT, 166 Vector3 &nearestNormal, 166 167 int &nearestFace, 167 168 Intersectable *instance … … 170 171 float t; 171 172 int hit = 0; 172 if (RayFaceIntersection(faceIndex, ray, t, nearestT) == Ray::INTERSECTION) { 173 Vector3 normal; 174 if (RayFaceIntersection(faceIndex, ray, t, normal, nearestT) == Ray::INTERSECTION) { 173 175 switch (ray.GetType()) { 174 176 case Ray::GLOBAL_RAY: 175 ray.intersections.push_back(Ray::Intersection(t, instance, faceIndex));177 ray.intersections.push_back(Ray::Intersection(t, normal, instance, faceIndex)); 176 178 hit++; 177 179 break; 178 180 case Ray::LOCAL_RAY: 179 181 nearestT = t; 182 nearestNormal = normal; 180 183 nearestFace = faceIndex; 181 184 hit++; … … 183 186 case Ray::LINE_SEGMENT: 184 187 if (t <= 1.0f) { 185 ray.intersections.push_back(Ray::Intersection(t, instance, faceIndex));188 ray.intersections.push_back(Ray::Intersection(t, normal, instance, faceIndex)); 186 189 hit++; 187 190 } … … 205 208 int hits = 0; 206 209 float nearestT = MAX_FLOAT; 210 Vector3 nearestNormal; 207 211 int nearestFace = -1; 208 212 … … 214 218 faceIndex < mFaces.size(); 215 219 faceIndex++) { 216 hits += CastRayToFace(faceIndex, ray, nearestT, nearest Face, instance);220 hits += CastRayToFace(faceIndex, ray, nearestT, nearestNormal, nearestFace, instance); 217 221 if (mIsConvex && nearestFace != -1) 218 222 break; … … 221 225 if ( hits && ray.GetType() == Ray::LOCAL_RAY ) { 222 226 if (ray.intersections.size()) 223 ray.intersections[0] = Ray::Intersection(nearestT, instance, nearestFace);227 ray.intersections[0] = Ray::Intersection(nearestT, nearestNormal, instance, nearestFace); 224 228 else 225 ray.intersections.push_back(Ray::Intersection(nearestT, instance, nearestFace));229 ray.intersections.push_back(Ray::Intersection(nearestT, nearestNormal, instance, nearestFace)); 226 230 } 227 231 … … 240 244 int hits = 0; 241 245 float nearestT = MAX_FLOAT; 246 Vector3 nearestNormal; 242 247 int nearestFace = -1; 243 248 244 249 if (ray.GetType() == Ray::LOCAL_RAY && ray.intersections.size()) 245 250 nearestT = ray.intersections[0].mT; … … 248 253 fi != faces.end(); 249 254 fi++) { 250 hits += CastRayToFace(*fi, ray, nearestT, nearest Face, instance);255 hits += CastRayToFace(*fi, ray, nearestT, nearestNormal, nearestFace, instance); 251 256 if (mIsConvex && nearestFace != -1) 252 257 break; … … 255 260 if ( hits && ray.GetType() == Ray::LOCAL_RAY ) { 256 261 if (ray.intersections.size()) 257 ray.intersections[0] = Ray::Intersection(nearestT, instance, nearestFace);262 ray.intersections[0] = Ray::Intersection(nearestT, nearestNormal,instance, nearestFace); 258 263 else 259 ray.intersections.push_back(Ray::Intersection(nearestT, instance, nearestFace));264 ray.intersections.push_back(Ray::Intersection(nearestT, nearestNormal,instance, nearestFace)); 260 265 } 261 266 … … 316 321 const Ray &ray, 317 322 float &t, 323 Vector3 &normal, 318 324 const float nearestT 319 325 ) … … 342 348 } 343 349 350 normal = plane.mNormal; 351 344 352 t = (-plane.mD - DotProd(plane.mNormal, ray.GetLoc())) / dot; 345 353 -
GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h
r1020 r1199 176 176 Ray &ray, 177 177 float &nearestT, 178 Vector3 &nearestNormal, 178 179 int &nearestFace, 179 180 Intersectable *instance … … 183 184 int 184 185 RayFaceIntersection(const int faceIndex, 185 const Ray &ray, 186 float &t, 187 const float nearestT 188 ); 186 const Ray &ray, 187 float &t, 188 Vector3 &normal, 189 const float nearestT 190 ); 189 191 190 192 Plane3 GetFacePlane(const int faceIndex); -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1197 r1199 299 299 300 300 if (!mViewCellsManager) 301 302 301 return false; 302 303 303 mViewCellsManager->ApplyFilter(mKdTree, 304 304 mApplyVisibilityFilter ? mVisibilityFilterWidth : -1.0f, -
GTP/trunk/Lib/Vis/Preprocessing/src/Ray.cpp
r863 r1199 227 227 { 228 228 loc = vssRay.mOrigin; 229 sourceObject = Intersection(0, vssRay. mOriginObject, 0);229 sourceObject = Intersection(0, vssRay.GetDir(), vssRay.mOriginObject, 0); 230 230 mType = LOCAL_RAY; 231 231 … … 239 239 intersections.clear(); 240 240 if (vssRay.mTerminationObject) 241 intersections.push_back(Intersection(len, vssRay.mTerminationObject, 0));241 intersections.push_back(Intersection(len, -vssRay.GetDir(), vssRay.mTerminationObject, 0)); 242 242 243 243 Precompute(); -
GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h
r1112 r1199 39 39 float mT; 40 40 41 // the normal of the intersection 42 Vector3 mNormal; 43 41 44 // can be either mesh or a viewcell 42 45 Intersectable *mObject; … … 44 47 // the face of the intersectable 45 48 int mFace; 46 49 47 50 Intersection(const float t, 51 const Vector3 &normal, 48 52 Intersectable *object, 49 const int face):mT(t), mObject(object), mFace(face) {} 53 const int face):mT(t), 54 mNormal(normal), 55 mObject(object), mFace(face) {} 50 56 51 Intersection(): mT(0), m Object(NULL), mFace(0) {}57 Intersection(): mT(0), mNormal(0,0,0), mObject(NULL), mFace(0) {} 52 58 53 59 bool operator<( -
GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
r1151 r1199 23 23 static bool fromBoxVisibility = false; 24 24 25 #define ADD_RAYS_IN_PLACE 025 #define ADD_RAYS_IN_PLACE 1 26 26 27 27 RssPreprocessor::RssPreprocessor(): … … 122 122 int hits = 0; 123 123 static Ray ray; 124 Intersectable *objectA, *objectB; 125 Vector3 pointA, pointB; 126 124 127 // AxisAlignedBox3 box = Union(mKdTree->GetBox(), mViewCellsManager->GetViewSpaceBox()); 125 128 126 129 AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 127 130 … … 132 135 133 136 SetupRay(ray, viewPoint, direction); 134 135 if (!mDetectEmptyViewSpace) 136 ray.mFlags &= ~Ray::CULL_BACKFACES; 137 else 138 ray.mFlags |= Ray::CULL_BACKFACES; 139 137 ray.mFlags &= ~Ray::CULL_BACKFACES; 140 138 141 139 // cast ray to KD tree to find intersection with other objects 142 Intersectable *objectA, *objectB;143 Vector3 pointA, pointB;144 140 float bsize = Magnitude(box.Size()); 145 141 146 142 147 143 if (mKdTree->CastRay(ray)) { 148 144 objectA = ray.intersections[0].mObject; 149 145 pointA = ray.Extrap(ray.intersections[0].mT); 146 if (mDetectEmptyViewSpace) 147 if (DotProd(ray.intersections[0].mNormal, direction) >= 0) { 148 // discard the sample 149 return 0; 150 } 151 150 152 } else { 151 153 objectA = NULL; … … 158 160 } 159 161 160 161 if (mDetectEmptyViewSpace) { 162 SetupRay(ray, pointA, -direction); 163 } else 164 SetupRay(ray, viewPoint, -direction); 165 166 if (!mDetectEmptyViewSpace) 167 ray.mFlags &= ~Ray::CULL_BACKFACES; 168 else 169 ray.mFlags |= Ray::CULL_BACKFACES; 170 162 163 SetupRay(ray, viewPoint, -direction); 164 ray.mFlags &= ~Ray::CULL_BACKFACES; 165 171 166 if (mKdTree->CastRay(ray)) { 172 167 objectB = ray.intersections[0].mObject; 173 168 pointB = ray.Extrap(ray.intersections[0].mT); 169 if (mDetectEmptyViewSpace) 170 if (DotProd(ray.intersections[0].mNormal, direction) <= 0) { 171 // discard the sample 172 return 0; 173 } 174 174 } else { 175 175 objectB = NULL; … … 180 180 return 0; 181 181 } 182 183 // if (objectA == NULL && objectB != NULL) {184 if (mDetectEmptyViewSpace) {185 // cast again to ensure that there is no objectA186 SetupRay(ray, pointB, direction);187 ray.mFlags |= Ray::CULL_BACKFACES;188 if (mKdTree->CastRay(ray)) {189 objectA = ray.intersections[0].mObject;190 pointA = ray.Extrap(ray.intersections[0].mT);191 }192 }193 182 194 183 195 184 VssRay *vssRay = NULL; 196 197 185 bool validSample = (objectA != objectB); 198 186 if (validSample) { … … 207 195 vssRays.push_back(vssRay); 208 196 hits ++; 209 210 197 } 211 198 … … 587 574 cout<<"Generating initial rays..."<<endl<<flush; 588 575 589 GenerateRays(mInitialSamples/3, SPATIAL_BOX_BASED_DISTRIBUTION, rays); 590 GenerateRays(mInitialSamples/3, OBJECT_BASED_DISTRIBUTION, rays); 591 GenerateRays(mInitialSamples/3, DIRECTION_BASED_DISTRIBUTION, rays); 592 // GenerateRays(mInitialSamples/4, OBJECT_DIRECTION_BASED_DISTRIBUTION, rays); 593 576 if (mUseImportanceSampling) { 577 GenerateRays(mInitialSamples/3, SPATIAL_BOX_BASED_DISTRIBUTION, rays); 578 GenerateRays(mInitialSamples/3, OBJECT_BASED_DISTRIBUTION, rays); 579 GenerateRays(mInitialSamples/3, DIRECTION_BASED_DISTRIBUTION, rays); 580 // GenerateRays(mInitialSamples/4, OBJECT_DIRECTION_BASED_DISTRIBUTION, rays); 581 } else { 582 int rayType = SPATIAL_BOX_BASED_DISTRIBUTION; 583 if (mObjectBasedSampling) 584 rayType = OBJECT_BASED_DISTRIBUTION; 585 else 586 if (mDirectionalSampling) 587 rayType = DIRECTION_BASED_DISTRIBUTION; 588 cout<<"Generating rays..."<<endl; 589 GenerateRays(mRssSamplesPerPass, rayType, rays); 590 } 591 592 594 593 cout<<"Casting initial rays..."<<endl<<flush; 595 594 CastRays(rays, mVssRays); … … 904 903 905 904 906 if (!mUseImportanceSampling) 905 if (!mUseImportanceSampling) 907 906 CLEAR_CONTAINER(vssRays); 908 907 // otherwise the rays get deleted by the rss tree update according to RssTree.maxRays .... … … 919 918 if (mUseViewcells) { 920 919 921 920 if(0) 922 921 { 923 924 925 926 927 928 929 } 930 931 932 933 934 935 936 937 938 939 940 941 942 943 922 VssRayContainer selectedRays; 923 int desired = mViewCellsManager->GetVisualizationSamples(); 924 925 mVssRays.SelectRays(desired, selectedRays); 926 927 mViewCellsManager->Visualize(mObjects, selectedRays); 928 } 929 930 // view cells after sampling 931 mViewCellsManager->PrintStatistics(Debug); 932 933 //-- render simulation after merge 934 cout << "\nevaluating bsp view cells render time after sampling ... "; 935 936 mRenderSimulator->RenderScene(); 937 SimulationStatistics ss; 938 mRenderSimulator->GetStatistics(ss); 939 940 cout << " finished" << endl; 941 cout << ss << endl; 942 Debug << ss << endl; 944 943 945 944 } … … 959 958 960 959 961 // 960 //mViewCellsManager->ExportViewCells("visibility.xml", 962 961 // true); 963 962 -
GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
r1189 r1199 36 36 #define DEBUG_SPLITS 0 37 37 38 #define EVAL_VIEWCELLS 0 39 38 40 // Static variables 39 41 int … … 156 158 exit(1); 157 159 } 158 160 161 Environment::GetSingleton()->GetIntValue("RssTree.hybridDepth", mHybridDepth); 162 159 163 Environment::GetSingleton()->GetBoolValue("RssTree.randomize", randomize); 160 164 Environment::GetSingleton()->GetBoolValue("RssTree.splitUseOnlyDrivingAxis", mSplitUseOnlyDrivingAxis); … … 568 572 Debug<<"Split Info:"<<endl; 569 573 Debug<<"axis="<<info.axis<<" ratio="<<info.costRatio<<endl; 570 Debug<<"viewcells="<<info.viewCells<< 571 " viewcells back="<<info.viewCellsBack<< 572 " viewcells back="<<info.viewCellsFront<<endl; 574 Debug<<"rays="<<info.rays<< 575 " rays back="<<info.raysBack<< 576 " rays front="<<info.raysFront<<endl; 577 Debug<<"c="<<info.contribution<< 578 " c back="<<info.contributionBack<< 579 " c front="<<info.contributionFront<<endl; 580 581 // Debug<<"viewcells="<<info.viewCells<< 582 // " viewcells back="<<info.viewCellsBack<< 583 // " viewcells back="<<info.viewCellsFront<<endl; 573 584 #endif 574 585 … … 579 590 } 580 591 581 #if 0 592 #if 0 582 593 cout<< 583 594 "pvs="<<leaf->mPvsSize<< … … 620 631 switch (costMethod) { 621 632 case 0: { 622 // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position);623 633 float sum = info.pvsBack*(info.position - minBox) + info.pvsFront*(maxBox - info.position); 624 634 float newCost = ct_div_ci + sum/sizeBox; … … 627 637 break; 628 638 } 639 case 6: { 640 float sum = info.raysBack*(info.position - minBox) + info.raysFront*(maxBox - info.position); 641 float newCost = ct_div_ci + sum/sizeBox; 642 float oldCost = info.rays; 643 info.costRatio = newCost/oldCost; 644 break; 645 } 646 case 7: { 647 float benefit = 648 (sqr(info.contributionBack) + sqr(info.contributionFront))/ 649 (2.0f*sqr(info.contribution)); 650 info.costRatio = 1.0f/(benefit + Limits::Small); 651 break; 652 } 653 654 629 655 case 1: { 630 656 float newContrib = … … 690 716 ) 691 717 { 718 info.rays = 0; 692 719 info.raysBack = 0; 693 720 info.raysFront = 0; … … 699 726 700 727 728 701 729 float sumWeights = Limits::Small; 702 730 float sumWeightsBack = Limits::Small; … … 709 737 Intersectable::NewMail(); 710 738 739 #if EVAL_VIEWCELLS 711 740 // count the numebr of viewcells first 712 741 for(RssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); … … 714 743 ri++) 715 744 if ((*ri).mRay->IsActive()) { 745 716 746 ViewCellContainer::const_iterator it = (*ri).mRay->mViewCells.begin(); 717 747 for (; it != (*ri).mRay->mViewCells.end(); ++it) { … … 722 752 } 723 753 } 754 #endif 724 755 725 756 Intersectable::NewMail(3); … … 741 772 sumWeights += weight; 742 773 sumContribution += contribution; 743 774 info.rays++; 744 775 if (side <= 0) { 745 776 info.raysBack++; … … 755 786 756 787 AddObject2Pvs((*ri).GetObject(), side, info.pvsBack, info.pvsFront); 788 789 #if EVAL_VIEWCELLS 757 790 AddViewcells2Pvs((*ri).mRay->mViewCells, 758 791 side, 759 792 info.viewCellsBack, 760 793 info.viewCellsFront); 794 #endif 761 795 } 762 796 … … 775 809 else 776 810 info.contributionFront = 0.0f; 777 811 812 // info.costRatio = 0.1 + Random(0.5f); 813 // return; 814 778 815 GetCostRatio( 779 816 leaf, … … 804 841 bool allowDirSplit = Magnitude(sBox.Size())*dirSplitBoxSize < Magnitude(bbox.Size()); 805 842 843 bool useCyclingAxis = true; 844 845 if (splitType == ESplitHeuristic || 846 (splitType == ESplitHybrid && leaf->depth > mHybridDepth)) 847 useCyclingAxis = false; 848 849 int cyclingAxis = 0; 850 851 if (leaf->parent) 852 cyclingAxis = (leaf->parent->axis + 1)%5; 853 854 if (0 && useCyclingAxis) { 855 int axis = cyclingAxis; 856 info.position = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f; 857 info.axis = axis; 858 info.costRatio = 0.5f; // not true but good for speeding up the subdivision at the top levels! 859 info.raysBack = info.raysFront = leaf->rays.size()/2; 860 return; 861 } 862 806 863 807 864 for (int axis = 0; axis < 5; axis++) … … 811 868 ) { 812 869 nInfo[axis].axis = axis; 813 if (!mSplitUseOnlyDrivingAxis || axis == sAxis || axis == dAxis) { 870 if ((!useCyclingAxis && (!mSplitUseOnlyDrivingAxis || axis == sAxis || axis == dAxis)) 871 || (useCyclingAxis && (axis == cyclingAxis)) 872 ) { 814 873 815 874 if (splitType == ESplitRegular) { … … 828 887 } else 829 888 if (splitType == ESplitHybrid) { 830 if (leaf->depth > 7)889 if (leaf->depth > mHybridDepth) 831 890 EvalCostRatioHeuristic( 832 891 leaf, … … 894 953 currInfo.pvsFront = leaf->GetPvsSize(); 895 954 896 955 956 float sumWeights = Limits::Small; 957 float sumWeightsBack = Limits::Small; 958 float sumWeightsFront = Limits::Small; 959 960 float sumContribution = 0.0f; 961 float sumContributionBack = 0.0f; 962 float sumContributionFront = 0.0f; 963 964 897 965 float sizeBox = maxBox - minBox; 898 966 … … 904 972 905 973 currInfo.viewCells = 0; 974 currInfo.rays = 0; 906 975 907 976 Intersectable::NewMail(); … … 911 980 ri++) 912 981 if ((*ri).mRay->IsActive()) { 982 983 float weight, contribution; 984 GetRayContribution(*ri, weight, contribution); 985 986 sumWeights += weight; 987 sumContribution += contribution; 988 currInfo.rays++; 989 913 990 Intersectable *object = (*ri).GetObject(); 914 991 if (object) … … 919 996 object->mCounter++; 920 997 998 #if EVAL_VIEWCELLS 921 999 // and do the same for all viewcells 922 1000 ViewCellContainer::const_iterator it = (*ri).mRay->mViewCells.begin(); … … 931 1009 viewcell->mCounter++; 932 1010 } 933 } 934 1011 #endif 1012 } 1013 1014 if (sumWeights!=0.0f) 1015 currInfo.contribution = sumContribution/sumWeights; 1016 else 1017 currInfo.contribution = 0.0f; 1018 1019 sumWeightsFront = sumWeights; 1020 sumContributionFront = sumContribution; 1021 1022 sumWeightsBack = 0; 1023 sumContributionBack = 0; 1024 935 1025 currInfo.viewCellsBack = 0; 936 1026 currInfo.viewCellsFront = currInfo.viewCells; 937 1027 938 1028 Intersectable::NewMail(); 939 1029 940 1030 for(vector<SortableEntry>::const_iterator ci = splitCandidates->begin(); 941 1031 ci < splitCandidates->end(); … … 945 1035 currInfo.raysFront--; 946 1036 currInfo.raysBack++; 1037 947 1038 RssTreeNode::RayInfo *rayInfo = (RssTreeNode::RayInfo *) (*ci).data; 1039 1040 float weight, contribution; 1041 GetRayContribution(*rayInfo, weight, contribution); 1042 1043 sumWeightsBack += weight; 1044 sumContributionBack += contribution; 1045 1046 sumWeightsFront -= weight; 1047 sumContributionFront -= contribution; 1048 948 1049 Intersectable *object = rayInfo->GetObject(); 949 1050 if (object) { … … 955 1056 currInfo.pvsFront--; 956 1057 } 1058 1059 #if EVAL_VIEWCELLS 957 1060 ViewCellContainer::const_iterator it = rayInfo->mRay->mViewCells.begin(); 958 1061 for (; it != rayInfo->mRay->mViewCells.end(); ++it) { … … 965 1068 currInfo.viewCellsFront--; 966 1069 } 1070 #endif 1071 967 1072 break; 968 1073 } … … 973 1078 if (position > minBand && position < maxBand) { 974 1079 currInfo.position = position; 1080 1081 1082 if (sumWeightsBack!=0.0f) 1083 info.contributionBack = sumContributionBack/sumWeightsBack; 1084 else 1085 info.contributionBack = 0.0f; 1086 1087 if (sumWeightsFront!=0.0f) 1088 info.contributionFront = sumContributionFront/sumWeightsFront; 1089 else 1090 info.contributionFront = 0.0f; 975 1091 976 1092 GetCostRatio( … … 1192 1308 // update stats 1193 1309 stat.rayRefs -= (int)leaf->rays.size(); 1194 stat.rayRefs += info.raysBack + info.raysFront;1310 stat.rayRefs += back->rays.size() + front->rays.size(); 1195 1311 1196 1312 … … 2093 2209 } 2094 2210 2095 // int numberOfTries = numberOfRays*4; 2096 int numberOfTries = numberOfRays; 2097 int generated = 0; 2098 2099 Intersectable::NewMail(); 2100 vector<Intersectable *> pvs(0); 2101 pvs.reserve(leaf->GetPvsSize()); 2102 for(RssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 2103 ri != leaf->rays.end(); 2104 ri++) { 2105 Intersectable *object = (*ri).GetObject(); 2106 if (object) { 2107 if (!object->Mailed()) { 2108 object->Mail(); 2109 object->mCounter = 1; 2110 pvs.push_back(object); 2111 if (exporter) 2112 exporter->ExportIntersectable(object); 2113 } else { 2114 object->mCounter++; 2115 } 2116 } 2117 } 2118 // sort objects based on their mCounter 2119 sort(pvs.begin(), pvs.end(), Intersectable::GreaterCounter); 2120 2211 2121 2212 float extendedConvexCombinationProb = 0.0f; //0.7f 2122 2213 // float silhouetteCheckPercentage = 1.0f; //0.5f 2123 2214 float silhouetteCheckPercentage = 0.0f; //0.9f; // 0.5f; 2124 2215 float silhouetteObjectCheckPercentage = 0.8f; 2216 2217 // int numberOfTries = numberOfRays*4; 2218 int numberOfTries = numberOfRays; 2219 int generated = 0; 2220 2221 vector<Intersectable *> pvs(0); 2222 if (silhouetteCheckPercentage != 0.0f) { 2223 Intersectable::NewMail(); 2224 pvs.reserve(leaf->GetPvsSize()); 2225 for(RssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 2226 ri != leaf->rays.end(); 2227 ri++) { 2228 Intersectable *object = (*ri).GetObject(); 2229 if (object) { 2230 if (!object->Mailed()) { 2231 object->Mail(); 2232 object->mCounter = 1; 2233 pvs.push_back(object); 2234 if (exporter) 2235 exporter->ExportIntersectable(object); 2236 } else { 2237 object->mCounter++; 2238 } 2239 } 2240 } 2241 // sort objects based on their mCounter 2242 sort(pvs.begin(), pvs.end(), Intersectable::GreaterCounter); 2243 } 2244 2125 2245 for (int i=0; generated < numberOfRays && i < numberOfTries; i++) { 2126 2246 bool useExtendedConvexCombination = ((nrays >= 2) && (Random(1.0f) < … … 2345 2465 int 2346 2466 RssTree::PruneRays( 2347 const int desired2467 const int maxRays 2348 2468 ) 2349 2469 { 2350 bool globalPrunning = true;2470 bool globalPrunning = false; 2351 2471 2352 2472 stack<RssTreeNode *> tstack; 2353 2473 int prunned = 0; 2354 2474 2355 Debug<<"Prunning rays...\nOriginal size "<<stat.rayRefs<<endl; 2475 // prune more rays to amortize the procedure 2476 int desired = maxRays*0.8f; 2477 2478 Debug<<"Prunning rays...\nOriginal size "<<stat.rayRefs<<endl<<flush; 2356 2479 2357 2480 if (globalPrunning) { … … 2363 2486 GreaterWeightedPvsContribution); 2364 2487 2365 if ( desired>= allRays.size() )2488 if ( maxRays >= allRays.size() ) 2366 2489 return 0; 2367 2490 2368 2491 float contributionThreshold = allRays[desired]->mWeightedPvsContribution; 2369 2492 … … 2387 2510 // prune random rays from each leaf so that the ratio's remain the same 2388 2511 PushRoots(tstack); 2512 2513 if ( maxRays >= stat.rayRefs ) 2514 return 0; 2515 2389 2516 float ratio = desired/(float)stat.rayRefs; 2390 2517 … … 2412 2539 2413 2540 2414 Debug<<"Remained "<<stat.rayRefs<<" rays"<<endl ;2541 Debug<<"Remained "<<stat.rayRefs<<" rays"<<endl<<flush; 2415 2542 2416 2543 return prunned; … … 2572 2699 2573 2700 sumContributions += weight*ray->mPvsContribution; 2574 sumRelContributions += weight*ray->mRelativePvsContribution; 2701 //$$ 20.7. changed to sqr to pronouce higher contribution so that they do not get smoothed!! 2702 //sumRelContributions += weight*ray->mRelativePvsContribution; 2703 2704 sumRelContributions += sqr(weight*ray->mRelativePvsContribution); 2575 2705 2576 2706 //sumWeights += weight; -
GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h
r1112 r1199 682 682 int mDirSplitDepth; 683 683 684 // depth till which the regular splits are applied for hybrid split type 685 int mHybridDepth; 686 684 687 // maximal number of rays maintained in the rss tree 685 688 int mMaxRays; -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp
r1189 r1199 17 17 { 18 18 // this should increase coherence of the samples 19 Environment::GetSingleton()->GetIntValue("Sampling .samplesPerPass", mSamplesPerPass);20 Environment::GetSingleton()->GetIntValue("Sampling .totalSamples", mTotalSamples);21 19 Environment::GetSingleton()->GetIntValue("SamplingPreprocessor.samplesPerPass", mSamplesPerPass); 20 Environment::GetSingleton()->GetIntValue("SamplingPreprocessor.totalSamples", mTotalSamples); 21 22 22 mStats.open("stats.log"); 23 23 } … … 25 25 SamplingPreprocessor::~SamplingPreprocessor() 26 26 { 27 CLEAR_CONTAINER(mSampleRays); 28 CLEAR_CONTAINER(mVssSampleRays); 29 } 30 31 void 32 SamplingPreprocessor::SetupRay(Ray &ray, 33 const Vector3 &point, 34 const Vector3 &direction, 35 const int type, 36 const Ray::Intersection &origin) 37 { 38 ray.Clear(); 39 40 ray.mFlags |= Ray::STORE_KDLEAVES | Ray::STORE_BSP_INTERSECTIONS; 41 // cout<<point<<" "<<direction<<endl; 42 43 ray.Init(point, direction, type); 44 ray.sourceObject = origin; 27 CLEAR_CONTAINER(mSampleRays); 28 CLEAR_CONTAINER(mVssSampleRays); 29 } 30 31 Intersectable * 32 SamplingPreprocessor::CastRay( 33 const Vector3 &origin, 34 const Vector3 &direction 35 ) 36 { 37 38 static Ray ray; 39 AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 40 41 AxisAlignedBox3 sbox = box; 42 sbox.Enlarge(Vector3(-Limits::Small)); 43 if (!sbox.IsInside(origin)) 44 return 0; 45 46 ray.intersections.clear(); 47 // do not store anything else then intersections at the ray 48 ray.Init(origin, direction, Ray::LOCAL_RAY); 49 50 ray.mFlags &= ~Ray::CULL_BACKFACES; 51 52 53 54 // cast ray to KD tree to find intersection with other objects 55 Intersectable *objectA = NULL; 56 Vector3 pointA; 57 float bsize = Magnitude(box.Size()); 58 59 if (mKdTree->CastRay(ray)) { 60 if (!mDetectEmptyViewSpace || DotProd(ray.intersections[0].mNormal, direction) < 0) { 61 objectA = ray.intersections[0].mObject; 62 pointA = ray.Extrap(ray.intersections[0].mT); 63 } 64 } 65 return objectA; 45 66 } 46 67 … … 58 79 } 59 80 60 61 void62 SamplingPreprocessor::CastRays(const RayContainer &rays)63 {64 // cast ray to KD tree to find intersection with other objects65 RayContainer::const_iterator it, it_end = rays.end();66 67 VssRayContainer vssRays;68 for (it = rays.begin(); it != it_end; ++it) {69 mKdTree->CastRay(*(*it));70 vssRays.push_back(new VssRay(*(*it)));71 }72 73 mViewCellsManager->ComputeSampleContributions(vssRays, true, false);74 CLEAR_CONTAINER(vssRays);75 }76 77 int78 SamplingPreprocessor::CastRay(Ray &ray)79 {80 // cast ray to KD tree to find intersection with other objects81 mKdTree->CastRay(ray);82 VssRay vssRay(ray);83 84 mViewCellsManager->ComputeSampleContribution(vssRay, true, false);85 86 return vssRay.mPvsContribution;87 }88 89 90 91 int92 SamplingPreprocessor::CastEdgeSamples(93 Intersectable *object,94 const Vector3 &point,95 MeshInstance *mi,96 const int samples97 )98 {99 Ray ray;100 int maxTries = samples*10;101 int i;102 int rays = 0;103 int edgeSamplesContributions = 0;104 for (i=0; i < maxTries && rays < samples; i++) {105 // pickup a random face of each mesh106 Mesh *mesh = mi->GetMesh();107 int face = (int)RandomValue(0, (Real)((int)mesh->mFaces.size() - 1));108 109 Polygon3 poly(mesh->mFaces[face], mesh);110 poly.Scale(1.001f);111 // now extend a random edge of the face112 int edge = (int)RandomValue(0, (Real)((int)poly.mVertices.size() - 1));113 float t = RandomValue(0.0f, 1.0f);114 Vector3 target = t*poly.mVertices[edge] + (1.0f-t)*poly.mVertices[(edge + 1)%115 poly.mVertices.size()];116 SetupRay(ray, point, target - point, Ray::LOCAL_RAY, Ray::Intersection(0, object, 0));117 if (!mesh->CastRay(ray, mi)) {118 // the rays which intersect the mesh have been discarded since they are not tangent119 // to the mesh120 rays++;121 edgeSamplesContributions += CastRay(ray);122 }123 }124 return edgeSamplesContributions;125 }126 127 KdNode *128 SamplingPreprocessor::GetNodeToSample(Intersectable *object)129 {130 int pvsSize = object->mKdPvs.GetSize();131 KdNode *nodeToSample = NULL;132 133 bool samplePvsBoundary = false;134 if (pvsSize && samplePvsBoundary) {135 // this samples the nodes from the boundary of the current PVS136 // mail all nodes from the pvs137 Intersectable::NewMail();138 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin();139 140 for (; i != object->mKdPvs.mEntries.end(); i++) {141 KdNode *node = (*i).first;142 node->Mail();143 }144 145 int maxTries = 2*pvsSize;146 Debug << "Finding random neighbour" << endl;147 for (int tries = 0; tries < 10; tries++) {148 int index = (int)RandomValue(0, (Real)(pvsSize - 1));149 PvsData data;150 KdNode *node;151 object->mKdPvs.GetData(index, node, data);152 nodeToSample = mKdTree->FindRandomNeighbor(node, true);153 if (nodeToSample)154 break;155 }156 } else {157 // just pickup a random node158 // nodeToSample = mKdTree->GetRandomLeaf(Plane3(normal, point));159 nodeToSample = mKdTree->GetRandomLeaf();160 }161 return nodeToSample;162 }163 81 164 82 void … … 166 84 { 167 85 // mail all nodes from the pvs 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 86 Intersectable::NewMail(); 87 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 88 for (; i != object->mKdPvs.mEntries.end(); i++) { 89 KdNode *node = (*i).first; 90 node->Mail(); 91 } 92 Debug << "Get all neighbours from PVS" << endl; 93 vector<KdNode *> invisibleNeighbors; 94 // get all neighbors of all PVS nodes 95 i = object->mKdPvs.mEntries.begin(); 96 for (; i != object->mKdPvs.mEntries.end(); i++) { 97 KdNode *node = (*i).first; 98 mKdTree->FindNeighbors(node, invisibleNeighbors, true); 99 AxisAlignedBox3 box = object->GetBox(); 100 for (int j=0; j < invisibleNeighbors.size(); j++) { 101 int visibility = ComputeBoxVisibility(mSceneGraph, 102 mKdTree, 103 box, 104 mKdTree->GetBox(invisibleNeighbors[j]), 105 1e-6f); 106 // exit(0); 107 } 108 // now rank all the neighbors according to probability that a new 109 // sample creates some contribution 110 } 193 111 } 194 112 … … 197 115 { 198 116 199 /// rays per pass 200 RayContainer passRays; 201 202 203 mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox()); 204 205 Vector3 point, normal, direction; 206 //Ray ray; 207 117 Debug << "type: sampling" << endl; 118 119 cout<<"Sampling Preprocessor started\n"<<flush; 120 // cout<<"Memory/ray "<<sizeof(VssRay)+sizeof(RssTreeNode::RayInfo)<<endl; 121 122 Randomize(0); 123 208 124 long startTime = GetTime(); 209 125 210 int i;211 126 int totalSamples = 0; 212 127 213 int pvsSize = 0; 214 215 while (totalSamples < mTotalSamples) { 216 int passContributingSamples = 0; 217 int passSampleContributions = 0; 218 int passSamples = 0; 219 int index = 0; 220 221 int reverseSamples = 0; 222 223 for (i = 0; i < mObjects.size(); i++) { 224 225 KdNode *nodeToSample = NULL; 226 Intersectable *object = mObjects[i]; 227 228 int pvsSize = 0; 229 230 if (0 && pvsSize && mPass == 1000 ) { 231 VerifyVisibility(object); 128 // if not already loaded, construct view cells from file 129 if (!mLoadViewCells) 130 { 131 mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox()); 132 133 // construct view cells using it's own set of samples 134 mViewCellsManager->Construct(this); 135 136 //-- several visualizations and statistics 137 Debug << "view cells construction finished: " << endl; 138 mViewCellsManager->PrintStatistics(Debug); 139 } 140 141 142 143 int samples = 0; 144 int i=0; 145 while (samples < mTotalSamples) { 146 for (i=0; i < mSamplesPerPass; i++, samples++) { 147 148 if (i%10000 == 0) 149 cout<<"+"; 150 151 Vector3 origin, direction; 152 mViewCellsManager->GetViewPoint(origin); 153 direction = UniformRandomVector(); 154 155 156 ViewCell *viewcell = mViewCellsManager->GetViewCell(origin); 157 158 if (viewcell && viewcell->GetValid()) { 159 // cast rays in both directions to make the number of samples comparable 160 // with the global sampling method which also casts a "double" ray per sample 161 for (int j=0; j < 2; j++) { 162 Intersectable *object = CastRay(origin, direction); 163 if (object) { 164 // if ray not outside of view space 165 float contribution; 166 int pvsContribution = 0; 167 float relativePvsContribution = 0; 168 if (object) { 169 float pdf = 1.0f; 170 if (viewcell->GetPvs().GetSampleContribution(object, 171 pdf, 172 contribution)) 173 ++pvsContribution; 174 relativePvsContribution += contribution; 175 viewcell->GetPvs().AddSample(object, pdf); 232 176 } 233 234 int faceIndex = object->GetRandomSurfacePoint(point, normal); 235 236 bool viewcellSample = true; 237 //int sampleContributions; 238 bool debug = false; //(object->GetId() >= 2199); 239 if (viewcellSample) { 240 //mKdTree->GetRandomLeaf(Plane3(normal, point)); 241 242 nodeToSample = GetNodeToSample(object); 243 244 for (int k=0; k < mSamplesPerPass; k++) { 245 bool reverseSample = false; 246 247 if (nodeToSample) { 248 AxisAlignedBox3 box = mKdTree->GetBox(nodeToSample); 249 Vector3 pointToSample = box.GetRandomPoint(); 250 // pointToSample.y = 0.9*box.Min().y + 0.1*box.Max().y; 251 if (object->GetRandomVisibleSurfacePoint( point, normal, pointToSample, 3 )) { 252 direction = pointToSample - point; 253 } else { 254 reverseSamples++; 255 reverseSample = true; 256 direction = point - pointToSample; 257 point = pointToSample; 258 //Debug << "point: " << pointToSample << endl; 259 } 260 } 261 else { 262 direction = UniformRandomVector(normal); 263 } 264 265 Ray *ray = new Ray(); 266 267 // construct a ray 268 SetupRay(*ray, point, direction, Ray::LOCAL_RAY, 269 Ray::Intersection(0, reverseSample ? NULL : object, faceIndex)); 270 271 passRays.push_back(ray); 272 273 //-- CORR matt: put block inside loop 274 /*if (sampleContributions) { 275 passContributingSamples ++; 276 passSampleContributions += sampleContributions; 277 }*/ 278 } 279 } else { 280 // edge samples 281 // get random visible mesh 282 // object->GetRandomVisibleMesh(Plane3(normal, point)); 283 } 284 285 // CORR matt: must add all samples 286 passSamples += mSamplesPerPass; 177 } 178 direction = -direction; 287 179 } 288 289 //------------------- 290 // cast rays for view cells construction 291 ProcessViewCells(passRays, 292 mObjects, 293 passSampleContributions, 294 passContributingSamples); 295 296 CLEAR_CONTAINER(passRays); 297 298 totalSamples += passSamples; 299 300 // if (pass>10) 301 // HoleSamplingPass(); 302 303 mPass ++; 304 305 pvsSize += passSampleContributions; 306 307 float avgRayContrib = (passContributingSamples > 0) ? 308 passSampleContributions / (float)passContributingSamples : 0; 309 310 cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 311 cout << "#TotalSamples=" << totalSamples/1000 312 << "k #SampleContributions=" << passSampleContributions << " (" 313 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 314 << (float)pvsSize /(float)mObjects.size() << endl 315 << "avg ray contrib=" << avgRayContrib << endl 316 << "reverse samples [%]" << reverseSamples/(float)passSamples*100.0f << endl; 317 318 mStats << 319 "#Pass\n" <<mPass<<endl<< 320 "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 321 "#TotalSamples\n" << totalSamples<< endl<< 322 "#SampleContributions\n" << passSampleContributions << endl << 323 "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 324 "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl << 325 "#AvgRayContrib\n" << avgRayContrib << endl; 326 } 327 328 //cout << "#totalKdPvsSize=" << mKdTree->CollectLeafPvs() << endl; 329 180 } 181 182 if (samples > mTotalSamples) 183 break; 184 } 185 186 // mVssRays.PrintStatistics(mStats); 187 mStats << 188 "#Time\n" << TimeDiff(startTime, GetTime())*1e-3<<endl<< 189 "#TotalSamples\n" <<samples<<endl; 190 191 mViewCellsManager->PrintPvsStatistics(mStats); 192 // ComputeRenderError(); 193 } 194 330 195 // HoleSamplingPass(); 331 196 if (0) { 332 Exporter *exporter = Exporter::GetExporter("ray-density.x3d"); 333 exporter->SetExportRayDensity(true); 334 exporter->ExportKdTree(*mKdTree); 335 delete exporter; 336 } 337 338 // construct view cells if not already constructed 339 if (!mViewCellsManager->ViewCellsConstructed()) 340 mViewCellsManager->ConstructSubdivision(mObjects, mVssSampleRays); 341 197 Exporter *exporter = Exporter::GetExporter("ray-density.x3d"); 198 exporter->SetExportRayDensity(true); 199 exporter->ExportKdTree(*mKdTree); 200 delete exporter; 201 } 202 203 342 204 // $$JB temporary removed 343 205 // mViewCellsManager->PostProcess(objects, mSampleRays); … … 346 208 Debug << "view cells after post processing: " << endl; 347 209 mViewCellsManager->PrintStatistics(Debug); 348 210 349 211 //-- render simulation after merge 350 212 cout << "\nevaluating bsp view cells render time after merge ... "; 351 213 352 353 354 355 356 357 358 214 mRenderSimulator->RenderScene(); 215 SimulationStatistics ss; 216 mRenderSimulator->GetStatistics(ss); 217 218 cout << " finished" << endl; 219 cout << ss << endl; 220 Debug << ss << endl; 359 221 360 222 // $$JB temporary removed 361 223 //mViewCellsManager->Visualize(objects, mSampleRays); 362 224 363 225 return true; 364 226 } 365 227 366 void SamplingPreprocessor::ProcessViewCells(const RayContainer &newRays, 367 const ObjectContainer &objects, 368 int &sampleContributions, 369 int &contributingSamples) 370 { 371 // cast rays to view cells 372 CastRays(newRays); 373 374 // save rays for view cells construction 375 if (!mViewCellsManager->ViewCellsConstructed()) 376 { 377 if ((int)mVssSampleRays.size() < mViewCellsManager->GetConstructionSamples()) 378 { 379 RayContainer::const_iterator it, it_end = newRays.end(); 380 381 for (it = newRays.begin(); it != it_end; ++ it) 382 mVssSampleRays.push_back(new VssRay(*(*it))); 383 } 384 else 385 { 386 // construct view cells 387 mViewCellsManager->ConstructSubdivision(objects, mVssSampleRays); 388 389 // throw away samples 390 //CLEAR_CONTAINER(mVssSampleRays); 391 } 392 } 393 // Need rays (with ordered intersections) for post processing => collect new rays 394 if (((int)mSampleRays.size() < mViewCellsManager->GetPostProcessSamples()) || 395 ((int)mSampleRays.size() < mViewCellsManager->GetVisualizationSamples())) 396 { 397 RayContainer::const_iterator it, it_end = newRays.end(); 398 399 for (it = newRays.begin(); it != it_end; ++ it) 400 mSampleRays.push_back(new Ray(*(*it))); 401 } 402 } 403 404 } 228 229 } -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.h
r860 r1199 38 38 HoleSamplingPass(); 39 39 40 /** Casts a bundle of sample rays into the scene. 41 @param sampleContributions the number of sample contributions 42 @param contributingSamples the number of samples contributing 43 */ 44 void 45 CastRays(const RayContainer &rays); 46 47 /** Casts a single ray into the scene. 48 @returns sample contributions 49 */ 50 int CastRay(Ray &ray); 51 52 /** Verify if the exact visibility for this object was established. 53 */ 54 void 55 VerifyVisibility(Intersectable *object); 56 57 /** Sample the shiluette of objects in order to find visibility changes 58 along the visibility skeleton. 59 */ 60 int 61 CastEdgeSamples( 62 Intersectable *object, 63 const Vector3 &point, 64 MeshInstance *mi, 65 const int samples 66 ); 67 68 /** Processes the view cells during a pass. 69 @param newRays the newly cast rays 70 @param sampleContributions returns the accumulated contribution of the samples 71 @param contributingSamples returns the samples contributing to pvs 72 */ 73 74 void ProcessViewCells(const RayContainer &newRays, 75 const ObjectContainer &objects, 76 int &sampleContributions, 77 int &contributingSamples); 78 79 /** 80 Returns random node as target for the current sample ray. 81 */ 82 KdNode *GetNodeToSample(Intersectable *object); 83 40 41 Intersectable * 42 CastRay( 43 const Vector3 &origin, 44 const Vector3 &direction 45 ); 46 47 /** Verify if the exact visibility for this object was established. 48 */ 49 void 50 VerifyVisibility(Intersectable *object); 51 84 52 85 53 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1189 r1199 1833 1833 while (root->GetParent()) 1834 1834 { 1835 // <<<<<<< .mine 1836 // case PVS_IN_LEAVES: //-- store pvs only in leaves 1837 // { 1838 // // pvs is always stored directly in leaves 1839 // if (vc->IsLeaf()) 1840 // { 1841 // if (!countKdPvs) 1842 // pvsSize = vc->GetPvs().GetSize(); 1843 // else 1844 // pvsSize = CountKdPvs(dynamic_cast<ViewCellLeaf *>(vc)); 1845 // break; 1846 // } 1835 1847 root = root->GetParent(); 1836 1848 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1189 r1199 1692 1692 void ViewCellsManager::GetPvsStatistics(PvsStatistics &stat) 1693 1693 { 1694 // update pvs of view cells tree if necessary 1695 UpdatePvs(); 1696 1697 ViewCellContainer::const_iterator it = mViewCells.begin(); 1698 1699 stat.viewcells = 0; 1700 stat.minPvs = 100000000; 1701 stat.maxPvs = 0; 1702 stat.avgPvs = 0.0f; 1703 1704 for (; it != mViewCells.end(); ++ it) 1705 { 1706 ViewCell *viewcell = *it; 1707 1708 const int pvsSize = mViewCellsTree->GetPvsSize(viewcell); 1709 1710 if (pvsSize < stat.minPvs) 1711 stat.minPvs = pvsSize; 1712 if (pvsSize > stat.maxPvs) 1713 stat.maxPvs = pvsSize; 1714 1715 stat.avgPvs += pvsSize; 1716 1717 ++ stat.viewcells; 1718 } 1719 1720 if (stat.viewcells) 1721 stat.avgPvs/=stat.viewcells; 1694 // update pvs of view cells tree if necessary 1695 UpdatePvs(); 1696 1697 ViewCellContainer::const_iterator it = mViewCells.begin(); 1698 1699 stat.viewcells = 0; 1700 stat.minPvs = 100000000; 1701 stat.maxPvs = 0; 1702 stat.avgPvs = 0.0f; 1703 1704 for (; it != mViewCells.end(); ++ it) 1705 { 1706 ViewCell *viewcell = *it; 1707 1708 // bool mCountKdPvs = false; 1709 const int pvsSize = mViewCellsTree->GetPvsSize(viewcell); 1710 1711 1712 if (pvsSize < stat.minPvs) 1713 stat.minPvs = pvsSize; 1714 if (pvsSize > stat.maxPvs) 1715 stat.maxPvs = pvsSize; 1716 1717 stat.avgPvs += pvsSize; 1718 1719 ++ stat.viewcells; 1720 } 1721 1722 if (stat.viewcells) 1723 stat.avgPvs/=stat.viewcells; 1722 1724 } 1723 1725 -
GTP/trunk/Lib/Vis/Preprocessing/src/default.env
r1112 r1199 11 11 #filename ../data/vienna/vienna-buildings.x3d 12 12 #filename ../data/vienna/city1500_flat_1.x3d 13 #filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-plane.x3d;../data/vienna/vienna-roads.x3d 13 filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d 14 #;../data/vienna/vienna-plane.x3d;../data/vienna/vienna-roads.x3d 14 15 # filename ../data/vienna/viewcells-25-sel.x3d 15 16 #filename ../data/atlanta/atlanta2.x3d 16 # filename ../data/soda/soda.dat 17 #filename ../data/soda/soda.dat 18 #filename ../data/test1/test2.x3d 17 19 #filename ../data/soda/soda5.dat 18 20 #filename ../data/PowerPlant/ppsection1/part_a/g0.ply … … 22 24 #filename ../data/PowerPlant/selection3.plb 23 25 #filename ../data/PowerPlant/section10.plb;../data/PowerPlant/section14.plb 24 filename ../data/PowerPlant/selection.plb26 #filename ../data/PowerPlant/selection.plb 25 27 #filename ../data/PowerPlant/comps/ppsection1/comps.plb 26 28 } … … 29 31 # stored sample rays 30 32 samplesFilename rays.out 31 useGlRenderer true33 useGlRenderer false 32 34 useGlDebugger false 33 35 # type sampling … … 55 57 samplesPerPass 100000 56 58 initialSamples 100000 57 vssSamples 100000059 vssSamples 500000 58 60 vssSamplesPerPass 100000 59 61 useImportanceSampling true … … 71 73 maxDepth 40 72 74 minPvs 30 73 minRays 10075 minRays 20 74 76 minSize 0.001 75 77 maxCostRatio 2.0 … … 79 81 maxStaticMemory 100 80 82 81 #splitType regular82 splitType heuristic83 splitType regular 84 # splitType heuristic 83 85 # splitType hybrid 84 splitUseOnlyDrivingAxis true86 splitUseOnlyDrivingAxis false 85 87 86 88 interleaveDirSplits true … … 94 96 } 95 97 98 SamplingPreprocessor { 99 totalSamples 30000000 100 samplesPerPass 1000000 101 } 102 96 103 RssPreprocessor { 97 104 samplesPerPass 1000 98 initialSamples 100000099 vssSamples 500000000105 initialSamples 2000000 106 vssSamples 30000000 100 107 vssSamplesPerPass 1000000 101 108 useImportanceSampling true … … 128 135 # splitType heuristic 129 136 130 minRays 200137 minRays 100 131 138 minSize 0.001 132 maxCostRatio 0.98133 maxRayContribution 0.5139 maxCostRatio 1.0 140 maxRayContribution 1.0 134 141 maxRays 4000000 135 142 maxTotalMemory 200 136 143 maxStaticMemory 100 137 144 138 #splitType regular139 splitType heuristic145 splitType regular 146 # splitType heuristic 140 147 # splitType hybrid 148 hybridDepth 10 141 149 splitUseOnlyDrivingAxis false 150 #false 142 151 importanceBasedCost false 143 152 … … 190 199 191 200 192 SamplingPreprocessor {193 totalSamples 10000000194 samplesPerPass 3195 }196 201 197 202 … … 281 286 # filename ../data/soda/soda5-viewcells.xml 282 287 # filename ../scripts/viewcells_atlanta.xml 283 # filename ../data/soda/soda5-viewcells2.xml 288 # filename ../data/soda/soda-viewcells-5000.xml 289 # filename ../data/test1/test-viewcells.xml 284 290 285 291 # filename ../data/soda/soda5-viewcell-single.xm … … 288 294 289 295 # filename ../data/atlanta/viewcells_atlanta3.xml 296 290 297 # filename ../data/vienna/viewcells_vienna.xml 291 298 # filename ../data/vienna/viewcells_vienna2.xml 292 299 # filename ../data/vienna/vienna_simple-21-04-avs2-viewCells.xml 293 filename ../data/PowerPlant/power_plant_viewcells1.xml 300 filename ../data/vienna/vienna-viewcells-5000.xml 301 302 303 # filename ../data/PowerPlant/power_plant_viewcells1.xml 294 304 } 295 305 … … 303 313 304 314 305 VspKdTree {306 epsilon 1e-6307 308 Construction {309 samples 500000310 }311 312 Termination {313 maxDepth 40314 minPvs 0315 minRays 1316 minSize 0.001317 maxCostRatio 5.9318 maxViewCells 169319 missTolerance 4320 maxRayContribution 2.5321 }322 323 maxTotalMemory 100324 maxStaticMemory 40325 326 splitType regular327 #splitType heuristics328 splitUseOnlyDrivingAxis true329 ct_div_ci 0.0330 331 # maximal cost for merging a view cell332 PostProcess {333 maxCostRatio 0.005334 minViewCells 10000335 maxPvsSize 5000336 }337 338 339 Visualization {340 }341 }342 315 343 316 VspBspTree { -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r1197 r1199 1 #ifdef UNICODE 2 #undef UNICODE 3 #endif 4 1 5 #include <windows.h> 2 6 #include <stdio.h> … … 34 38 int LoadMyDll() 35 39 { 36 37 38 39 40 41 42 { 43 44 45 } 46 47 48 49 50 51 { 52 53 54 } 55 56 57 58 59 60 61 62 40 importFunction LoadRenderWidget; 41 42 // Load DLL file 43 HINSTANCE hinstLib = LoadLibrary("QtGlRenderer.dll"); 44 45 if (hinstLib == NULL) 46 { 47 cout << "ERROR: unable to load DLL\n"; 48 return 1; 49 } 50 51 // Get function pointer 52 LoadRenderWidget = (importFunction)GetProcAddress(hinstLib, "LoadRenderWidget"); 53 54 if (LoadRenderWidget == NULL) 55 { 56 cout << "ERROR: unable to find DLL function\n"; 57 return 1; 58 } 59 60 // load the render window 61 rendererWidget = LoadRenderWidget(preprocessor); 62 63 // Unload DLL file 64 //FreeLibrary(hinstLib); 65 66 return 0; 63 67 } 64 68 … … 103 107 104 108 Debug.open("debug.log"); 105 109 106 110 Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH); 107 111 MeshKdTree::ParseEnvironment(); … … 112 116 113 117 if (preprocessorType == "vss") 114 {118 { 115 119 preprocessor = new VssPreprocessor(); 116 }120 } 117 121 else 118 122 { -
GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro
r1112 r1199 13 13 14 14 15 win32:LIBPATH += GL $$NONGTP/Xerces/xerces/lib $$NONGTP/Devil/lib \16 "d:/Programs/NVIDIA Corporation/Cg/lib" $$NONGTP/glut 15 win32:LIBPATH += GL $$NONGTP/Xerces/xerces/lib $$NONGTP/Devil/lib $$NONGTP/Xe/xerces/lib \ 16 "d:/Programs/NVIDIA Corporation/Cg/lib" $$NONGTP/glut $$NONGTP/Boost/lib 17 17 18 18 unix:LIBPATH += ../support/src/xerces-c-src_2_7_0/lib ../support/devil/lib /usr/lib/qt3/lib64 … … 30 30 QT += opengl 31 31 32 win32:LIBS += xerces-c_2.lib devil.lib ilu.lib ilut.lib cg.lib cgGL.lib glew32.lib 32 win32:LIBS += xerces-c_2.lib devil.lib ilu.lib ilut.lib cg.lib cgGL.lib glew32.lib boost_thread-vc71-mt-1_33_1.lib 33 33 34 34 unix:LIBS += -lxerces-c -lIL -lILU -lILUT … … 53 53 GzBinFileInputStream.cpp GzFileInputSource.cpp \ 54 54 OcclusionQuery.cpp VspOspTree.cpp LogManager.cpp \ 55 SamplingStrategy.cpp 55 SamplingStrategy.cpp KdIntersectable.cpp BoostPreprocessorThread.cpp 56 56 57 57 #VspKdTree.cpp ResourceManager.cpp
Note: See TracChangeset
for help on using the changeset viewer.