Changeset 1867 for GTP/trunk/Lib
- Timestamp:
- 12/08/06 17:10:14 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 45 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
r1824 r1867 2275 2275 halton.GenerateNext(); 2276 2276 2277 return mMin + size*Vector3(halton.GetNumber(1),2278 2279 halton.GetNumber(3));2280 2277 return GetRandomPoint(Vector3(halton.GetNumber(1), 2278 halton.GetNumber(2), 2279 halton.GetNumber(3))); 2280 2281 2281 #else 2282 return mMin + Vector3(RandomValue(0.0f, size.x),2283 RandomValue(0.0f, size.y),2284 RandomValue(0.0f, size.z));2282 return GetRandomPoint(Vector3(RandomValue(0.0f, 1.0f), 2283 RandomValue(0.0f, 1.0f), 2284 RandomValue(0.0f, 1.0f))); 2285 2285 #endif 2286 2286 } 2287 2287 2288 Vector3 2289 AxisAlignedBox3::GetRandomPoint(const Vector3 &r) const 2290 { 2291 return mMin + Size()*r; 2292 } 2288 2293 2289 2294 Vector3 AxisAlignedBox3::GetRandomSurfacePoint() const -
GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h
r1824 r1867 181 181 182 182 183 Vector3 GetRandomPoint(const Vector3 &r) const; 183 184 Vector3 GetRandomPoint() const; 184 185 Vector3 GetRandomSurfacePoint() const; -
GTP/trunk/Lib/Vis/Preprocessing/src/BoostPreprocessorThread.cpp
r1457 r1867 33 33 { 34 34 mThread = new boost::thread(*this); 35 36 PreprocessorThread::InitThread(); 37 } 38 39 int 40 BoostPreprocessorThread::GetCurrentThreadId() const 41 { 42 // $$ temporary implementation 43 return 0; 35 44 } 36 45 -
GTP/trunk/Lib/Vis/Preprocessing/src/BoostPreprocessorThread.h
r1457 r1867 25 25 void operator()(); 26 26 27 int 28 GetCurrentThreadId() const; 29 27 30 protected: 28 31 -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1844 r1867 27 27 #define USE_VOLUMES_FOR_HEURISTICS 1 28 28 29 //int BvhNode::sMailId = 10000; //2147483647;30 //int BvhNode::sReservedMailboxes = 1;29 //int BvhNode::sMailId = 10000; //2147483647; 30 //int BvhNode::sReservedMailboxes = 1; 31 31 32 32 BvHierarchy *BvHierarchy::BvhSubdivisionCandidate::sBvHierarchy = NULL; -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1843 r1867 1576 1576 "bsp_construction_input=", 1577 1577 "fromViewCells"); 1578 1578 1579 1579 RegisterOption("BspTree.subdivisionStats", 1580 1580 optString, -
GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.h
r1764 r1867 136 136 void SetWireframe() { mWireframe = true; } 137 137 void SetFilled() { mWireframe = false; } 138 138 139 139 void SetForcedMaterial(const Material &m) { 140 140 mForcedMaterial = m; -
GTP/trunk/Lib/Vis/Preprocessing/src/Halton.h
r860 r1867 7 7 namespace GtpVisibilityPreprocessor { 8 8 9 class Halton2 { 10 static float _invBases[2]; 11 float _prev[2]; 12 13 float halton(float baseRec, float prev) const { 14 float r = 1 - prev - 1e-10f; 15 if (baseRec < r) 16 return prev + baseRec; 9 inline float halton(float baseRec, float prev) { 10 float r = 1 - prev - 1e-10f; 11 if (baseRec < r) 12 return prev + baseRec; 17 13 float h = baseRec; 18 14 float hh; … … 22 18 } while (h >= r); 23 19 return prev + hh + h - 1; 20 } 21 22 template<int T> 23 class Halton { 24 float _invBases[T]; 25 float _prev[T]; 26 27 public: 28 29 void Reset() { 30 for (int i=0; i < T; i++) 31 _prev[i] = 0; 24 32 } 33 34 Halton() { 35 for (int i=0; i < T; i++) { 36 int base = FindPrime(i+1); 37 if (base == 1) 38 base++; 39 _invBases[i] = 1.0f/base; 40 } 41 Reset(); 42 } 43 44 void 45 GetNext(float *a) { 46 for (int i=0; i < T; i++) { 47 a[i] = halton(_invBases[i], _prev[i]); 48 _prev[i] = a[i]; 49 } 50 } 51 52 }; 53 54 class Halton2 { 55 static float _invBases[2]; 56 float _prev[2]; 25 57 26 58 public: … … 69 101 */ 70 102 inline int FindPrime(const int index) { 71 if(index < 1) { 72 cerr<<"FindPrime: The argument must be non-negative."<<endl; 73 return -1; 74 } 103 // if (index < 1) { 104 // cerr<<"FindPrime: The argument must be non-negative."<<endl; 105 // return -1; 106 // } 107 108 const int primes[] = {-1, 1, 3, 5, 7, 11, 13}; 109 if (index <= 6) 110 return primes[index]; 111 75 112 int prime = 1; 76 113 int found = 1; … … 115 152 int copyOfIndex = index; 116 153 if((base >= 2) && (index >= 1)) { 117 // changed by matt118 //if(base >= 2 & index >= 1) {119 154 while(copyOfIndex > 0) { 120 155 N1 = (copyOfIndex / base); -
GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp
r1786 r1867 93 93 94 94 return ProcessRay( 95 simpleRay,96 hitA,97 hitB,98 vssRays,99 box,100 castDoubleRay,101 pruneInvalidRays102 );95 simpleRay, 96 hitA, 97 hitB, 98 vssRays, 99 box, 100 castDoubleRay, 101 pruneInvalidRays 102 ); 103 103 } 104 104 -
GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp
r1829 r1867 29 29 { 30 30 if (simpleRay.mType == Ray::GLOBAL_RAY) 31 31 return CastGlobalRay(simpleRay, vssRays, box, pruneInvalidRays); 32 32 33 33 //cout << "internal ray" << endl; … … 87 87 static Ray ray; 88 88 int hits = 0; 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 89 mPreprocessor.SetupRay(ray, simpleRay.mOrigin, simpleRay.mDirection); 90 91 float tmin, tmax; 92 if (!(box.ComputeMinMaxT(ray, &tmin, &tmax) && (tmin < tmax))) 93 return 0; 94 95 // shift the ray origin to tmin 96 // Vector3 origin = ray.Extrap(tmin); 97 // mPreprocessor.SetupRay(ray, origin, simpleRay.mDirection); 98 ray.SetType(Ray::GLOBAL_RAY); 99 ray.mFlags &= ~Ray::CULL_BACKFACES; 100 101 102 VssRay *vssRay; 103 104 104 if (mKdTree->CastRay(ray)) { 105 // sort intersections 106 ray.SortIntersections(); 107 //cout<<"I="<<ray.intersections.size()<<endl; 108 109 110 Ray::Intersection &hit = ray.intersections[0]; 111 112 if (DotProd(hit.mNormal, ray.GetDir()) < 0) { 113 // insert intial segment 114 vssRay = new VssRay( 115 ray.Extrap(tmin), 116 ray.Extrap(hit.mT), 117 NULL, 118 hit.mObject, 119 mPreprocessor.mPass, 120 simpleRay.mPdf 121 ); 122 vssRay->mFlags |= VssRay::Valid; 123 vssRays.push_back(vssRay); 124 ++hits; 105 // sort intersections 106 ray.SortIntersections(); 107 // cout<<"I="<<ray.intersections.size()<<endl; 108 109 110 Ray::Intersection &hit = ray.intersections[0]; 111 112 if (DotProd(hit.mNormal, ray.GetDir()) < 0) { 113 // cout<<"F:"<<tmin<<" "<<hit.mT<<endl; 114 // insert intial segment 115 vssRay = new VssRay( 116 ray.Extrap(tmin), 117 ray.Extrap(hit.mT), 118 NULL, 119 hit.mObject, 120 mPreprocessor.mPass, 121 simpleRay.mPdf 122 ); 123 124 vssRay->mFlags |= VssRay::Valid; 125 vssRays.push_back(vssRay); 126 ++hits; 127 } 128 129 hit = ray.intersections[ray.intersections.size()-1]; 130 if (DotProd(hit.mNormal, ray.GetDir()) > 0) { 131 // cout<<"L:"<<tmax<<" "<<hit.mT<<endl; 132 133 // insert termination segment 134 vssRay = new VssRay( 135 ray.Extrap(tmax), 136 ray.Extrap(hit.mT), 137 NULL, 138 hit.mObject, 139 mPreprocessor.mPass, 140 simpleRay.mPdf 141 ); 142 vssRay->mFlags |= VssRay::Valid; 143 vssRays.push_back(vssRay); 144 ++hits; 145 } 146 147 // insert the rest of segments 148 for (int i=0; i < ray.intersections.size() - 1; i++) { 149 Ray::Intersection &hitA = ray.intersections[i]; 150 Ray::Intersection &hitB = ray.intersections[i + 1]; 151 if (hitB.mT - hitA.mT > Limits::Small) { 152 if (DotProd(hitA.mNormal, ray.GetDir()) > 0 && 153 DotProd(hitB.mNormal, ray.GetDir()) < 0 154 ) { 155 156 vssRay = new VssRay( 157 ray.Extrap(hitA.mT), 158 ray.Extrap(hitB.mT), 159 hitA.mObject, 160 hitB.mObject, 161 mPreprocessor.mPass, 162 simpleRay.mPdf 163 ); 164 vssRay->mFlags |= VssRay::Valid; 165 vssRays.push_back(vssRay); 166 ++hits; 167 168 vssRay = new VssRay( 169 ray.Extrap(hitB.mT), 170 ray.Extrap(hitA.mT), 171 hitB.mObject, 172 hitA.mObject, 173 mPreprocessor.mPass, 174 simpleRay.mPdf 175 ); 176 177 vssRay->mFlags |= VssRay::Valid; 178 vssRays.push_back(vssRay); 179 ++hits; 125 180 } 126 127 hit = ray.intersections[ray.intersections.size()-1]; 128 if (DotProd(hit.mNormal, ray.GetDir()) > 0) { 129 130 // insert termination segment 131 vssRay = new VssRay( 132 ray.Extrap(tmax), 133 ray.Extrap(hit.mT), 134 NULL, 135 hit.mObject, 136 mPreprocessor.mPass, 137 simpleRay.mPdf 138 ); 139 vssRay->mFlags |= VssRay::Valid; 140 vssRays.push_back(vssRay); 141 ++hits; 142 } 143 144 // insert the rest of segments 145 for (int i=0; i < ray.intersections.size() - 1; i++) { 146 Ray::Intersection &hitA = ray.intersections[i]; 147 Ray::Intersection &hitB = ray.intersections[i + 1]; 148 if (DotProd(hitA.mNormal, ray.GetDir()) > 0 && 149 DotProd(hitB.mNormal, ray.GetDir()) < 0 150 ) { 151 152 vssRay = new VssRay( 153 ray.Extrap(hitA.mT), 154 ray.Extrap(hitB.mT), 155 hitA.mObject, 156 hitB.mObject, 157 mPreprocessor.mPass, 158 simpleRay.mPdf 159 ); 160 vssRay->mFlags |= VssRay::Valid; 161 vssRays.push_back(vssRay); 162 ++hits; 163 164 vssRay = new VssRay( 165 ray.Extrap(hitB.mT), 166 ray.Extrap(hitA.mT), 167 hitB.mObject, 168 hitA.mObject, 169 mPreprocessor.mPass, 170 simpleRay.mPdf 171 ); 172 173 vssRay->mFlags |= VssRay::Valid; 174 vssRays.push_back(vssRay); 175 ++hits; 176 } 177 } 178 } 179 180 return hits; 181 } 182 } 183 } 184 185 return hits; 181 186 } 182 187 -
GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h
r1763 r1867 6 6 #include <set> 7 7 #include "VssRay.h" 8 #include "Mailable.h" 8 9 9 10 namespace GtpVisibilityPreprocessor { … … 74 75 75 76 Intersectable(): 76 77 mMailbox(0), 77 78 //mReferences(0), 78 79 mBvhLeaf(0), -
GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp
r1824 r1867 31 31 if (ray.GetType() == Ray::LOCAL_RAY && !ray.intersections.empty()) { 32 32 ray.intersections[0] = Ray::Intersection(nearestT, 33 34 35 33 nearestNormal, 34 this, 35 0); 36 36 } 37 37 else { 38 38 ray.intersections.push_back(Ray::Intersection(nearestT, 39 40 41 39 nearestNormal, 40 this, 41 0)); 42 42 } 43 43 -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r1824 r1867 677 677 ObjectContainer::const_iterator mi; 678 678 for ( mi = leaf->mObjects.begin(); 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 679 mi != leaf->mObjects.end(); 680 mi++) { 681 Intersectable *object = *mi; 682 if (!object->Mailed() ) { 683 object->Mail(); 684 if (ray.mFlags & Ray::STORE_TESTED_OBJECTS) 685 ray.testedObjects.push_back(object); 686 687 static int oi=1; 688 if (MeshDebug) 689 cout<<"Object "<<oi++; 690 691 hits += object->CastRay(ray); 692 693 if (MeshDebug) { 694 if (!ray.intersections.empty()) 695 cout<<"nearest t="<<ray.intersections[0].mT<<endl; 696 else 697 cout<<"nearest t=-INF"<<endl; 698 } 699 } 700 700 } 701 701 702 702 if (hits && ray.GetType() == Ray::LOCAL_RAY) 703 704 703 if (ray.intersections[0].mT <= maxt) 704 break; 705 705 706 706 // get the next node from the stack 707 707 if (tStack.empty()) 708 708 break; 709 709 710 710 entp = extp; 711 711 mint = maxt; 712 712 if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 713 713 break; 714 714 715 715 RayTraversalData &s = tStack.top(); -
GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
r1832 r1867 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (2.00a) (Qt 4.1.2) on: ?t 30. XI 15:32:50 20063 # Generated by qmake (2.00a) (Qt 4.1.2) on: pá 8. XII 16:33:20 2006 4 4 # Project: preprocessor.pro 5 5 # Template: app -
GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp
r1824 r1867 9 9 bool MeshDebug = false; 10 10 11 int Intersectable::sMailId = 1;//2147483647;12 int Intersectable::sReservedMailboxes = 1;11 //int Intersectable::sMailId = 1;//2147483647; 12 //int Intersectable::sReservedMailboxes = 1; 13 13 14 14 struct SortableVertex { … … 370 370 return Ray::INTERSECTION_OUT_OF_LIMITS; 371 371 372 if ( t >= nearestT) {372 if ((ray.GetType() == Ray::LOCAL_RAY) && (t >= nearestT)) { 373 373 return Ray::INTERSECTION_OUT_OF_LIMITS; // no intersection was found 374 374 } -
GTP/trunk/Lib/Vis/Preprocessing/src/MutualVisibility.cpp
r1328 r1867 160 160 } 161 161 162 // int id = Mailable::GetThreadId(); 162 163 for (i=0; i < 4; i++) { 163 164 RaySample *sample = &shaft.mSamples[i]; 164 165 for (j=0; j < sample->mIntersections.size(); j++) { 165 166 if (sample->mIntersections[j].mObject->IncMail() == 4) { 166 cerr<<"T";167 shaft.mError = 0.0f;168 return;167 cerr<<"T"; 168 shaft.mError = 0.0f; 169 return; 169 170 } 170 171 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1827 r1867 30 30 namespace GtpVisibilityPreprocessor { 31 31 32 const static bool ADDITIONAL_GEOMETRY_HACK = false; 33 34 32 const static bool ADDITIONAL_GEOMETRY_HACK = false; 33 34 Preprocessor *preprocessor = NULL; 35 35 36 // HACK: Artificially modify scene to watch rendercost changes 36 37 static void AddGeometry(SceneGraph *scene) … … 443 444 Environment::GetSingleton()->GetIntValue("Preprocessor.rayCastMethod", rayCastMethod); 444 445 vector<FaceParentInfo> *fi = 445 446 447 446 ((rayCastMethod == RayCaster::INTEL_RAYCASTER) && mLoadMeshes) ? 447 &mFaceParents : NULL; 448 448 449 if (files == 1) 449 {450 { 450 451 if (strstr(filename.c_str(), ".x3d")) 451 {452 { 452 453 parser = new X3dParser; 453 454 … … 984 985 int 985 986 Preprocessor::GenerateRays(const int number, 986 constSamplingStrategy &strategy,987 988 { 989 987 SamplingStrategy &strategy, 988 SimpleRayContainer &rays) 989 { 990 return strategy.GenerateSamples(number, rays); 990 991 } 991 992 … … 1096 1097 if (rayCastMethod == 0) 1097 1098 { 1099 cout << "ray cast method: internal" << endl; 1098 1100 mRayCaster = new InternalRayCaster(*this, mKdTree); 1099 cout << "ray cast method: internal" << endl;1100 1101 } 1101 1102 else 1102 1103 { 1103 1104 #ifdef GTP_INTERNAL 1104 mRayCaster = new IntelRayCaster(*this, externKdTree);1105 cout << "ray cast method: intel" << endl;1105 cout << "ray cast method: intel" << endl; 1106 mRayCaster = new IntelRayCaster(*this, externKdTree); 1106 1107 #endif 1107 1108 } 1108 1109 1109 1110 return true; 1110 1111 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r1786 r1867 9 9 10 10 11 12 11 namespace GtpVisibilityPreprocessor { 13 12 class PreprocessorThread; 13 14 14 class RenderSimulator; 15 15 class SceneGraph; … … 122 122 123 123 virtual int 124 125 constSamplingStrategy &strategy,126 SimpleRayContainer &rays);127 128 129 const int raysType,130 SimpleRayContainer &rays);124 GenerateRays(const int number, 125 SamplingStrategy &strategy, 126 SimpleRayContainer &rays); 127 128 virtual int GenerateRays(const int number, 129 const int raysType, 130 SimpleRayContainer &rays); 131 131 132 132 bool GenerateRayBundle(SimpleRayContainer &rayBundle, … … 136 136 137 137 virtual void CastRays(SimpleRayContainer &rays, 138 VssRayContainer &vssRays,139 const bool castDoubleRays,140 const bool pruneInvalidRays = true);138 VssRayContainer &vssRays, 139 const bool castDoubleRays, 140 const bool pruneInvalidRays = true); 141 141 142 142 /** Returns a view cells manager of the given name. … … 207 207 208 208 GlRendererBuffer *renderer; 209 210 void SetThread(PreprocessorThread *t) { 211 mThread = t; 212 } 213 214 PreprocessorThread *GetThread() const { 215 return mThread; 216 } 209 217 210 218 protected: … … 237 245 /// if box around view space should be used 238 246 bool mUseViewSpaceBox; 247 248 PreprocessorThread *mThread; 239 249 }; 240 250 251 extern Preprocessor *preprocessor; 241 252 242 253 } -
GTP/trunk/Lib/Vis/Preprocessing/src/PreprocessorThread.cpp
r1583 r1867 8 8 namespace GtpVisibilityPreprocessor { 9 9 10 11 vector<PreprocessorThread *> PreprocessorThread::sThreads; 10 12 11 13 PreprocessorThread::PreprocessorThread(Preprocessor *p): -
GTP/trunk/Lib/Vis/Preprocessing/src/PreprocessorThread.h
r1457 r1867 2 2 #define __PREPROCESSOR_THREAD_H 3 3 4 4 #include <vector> 5 using namespace std; 5 6 namespace GtpVisibilityPreprocessor 6 7 { 7 8 8 9 class Preprocessor; 10 9 11 10 12 /** This class represents a preprocessor thread. … … 13 15 { 14 16 public: 17 static vector<PreprocessorThread *> sThreads; 18 15 19 PreprocessorThread(Preprocessor *p); 16 20 virtual ~PreprocessorThread(); 17 21 18 virtual void InitThread() {} 22 virtual void InitThread() { 23 sThreads.push_back(this); 24 } 19 25 virtual void RunThread() {} 20 26 21 27 virtual void Main(); 22 28 29 // This function has to be defined by the thread library used... 30 virtual int GetCurrentThreadId() const = 0; 31 23 32 protected: 24 33 -
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
r1845 r1867 592 592 593 593 // only check clean part 594 //mLastSorted = 0; 594 // $$ TMP JB 595 // mLastSorted = 0; 595 596 vector<PvsEntry<T, S> >::iterator sorted_end = mEntries.begin() + mLastSorted; 596 597 … … 606 607 vector<PvsEntry<T, S> >::const_iterator dit, dit_end = mEntries.end(); 607 608 608 for (dit = sorted_end; (dit != dit_end) && ((*dit).mObject != sample); ++ dit) ;609 609 for (dit = sorted_end; (dit != dit_end) && ((*dit).mObject != sample); ++ dit) ; 610 610 611 if ((dit != mEntries.end()) && ((*dit).mObject == sample)) 611 612 found = true; -
GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp
r1832 r1867 327 327 QtGlRendererWidget::RenderPvs() 328 328 { 329 329 330 330 Intersectable::NewMail(); 331 331 … … 345 345 // copy the pvs so that it can be filtered... 346 346 347 ObjectPvs &pvs =mPvsCache.mPvs;347 // mPvsCache.mPvs; 348 348 349 349 if (mPvsCache.mViewCell != viewcell) { … … 352 352 353 353 if (mUseSpatialFilter) { 354 354 // 9.11. 2006 -> experiment with new spatial filter 355 355 #if 0 356 357 358 359 pvs);356 mViewCellsManager->ApplySpatialFilter(mKdTree, 357 mSpatialFilterSize* 358 Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 359 mPvsCache.mPvs); 360 360 #else 361 362 363 364 365 pvs,366 367 361 // mSpatialFilter size is in range 0.001 - 0.1 362 mViewCellsManager->ApplyFilter2(viewcell, 363 mUseFilter, 364 100*mSpatialFilterSize, 365 mPvsCache.mPvs, 366 &mPvsCache.filteredBoxes 367 ); 368 368 #endif 369 369 } else 370 pvs = viewcell->GetPvs();371 370 mPvsCache.mPvs = viewcell->GetPvs(); 371 372 372 emit PvsUpdated(); 373 373 } … … 378 378 RenderBox(mPvsCache.filteredBoxes[i]); 379 379 } else { 380 ObjectPvsIterator it = pvs.GetIterator();380 ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 381 381 382 mPvsSize = pvs.GetSize();382 mPvsSize = mPvsCache.mPvs.GetSize(); 383 383 for (; it.HasMoreEntries(); ) { 384 384 ObjectPvsEntry entry = it.Next(); -
GTP/trunk/Lib/Vis/Preprocessing/src/QtPreprocessorThread.cpp
r1770 r1867 29 29 } 30 30 31 int 32 QtPreprocessorThread::GetCurrentThreadId() const 33 { 34 QThread *thread = currentThread(); 35 for (int i=0; i < sThreads.size(); i++) 36 if (sThreads[i] == (QtPreprocessorThread *)thread) 37 return i+1; 38 return 0; 31 39 } 40 41 } 42 32 43 33 44 #endif -
GTP/trunk/Lib/Vis/Preprocessing/src/QtPreprocessorThread.h
r1842 r1867 16 16 ~QtPreprocessorThread(); 17 17 18 void InitThread() {} 18 void InitThread() { 19 PreprocessorThread::InitThread(); 20 } 19 21 void RunThread() { 20 22 start(QThread::LowPriority); 21 23 } 22 24 25 // This function has to be defined by the thread library used... 26 virtual int GetCurrentThreadId() const; 27 23 28 24 29 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/Ray.cpp
r1584 r1867 14 14 // that are converted to canonical space and thus the mailbox 15 15 // rayID identification does not work for them! 16 int 17 Ray::genID = 1; 18 19 // Precompute some Ray parameters. Most of them is used for 20 // ropes traversal. 16 int 17 Ray::genID = 1; 18 19 20 int 21 SimpleRay::sSimpleRayId = 1; 22 21 23 22 24 void -
GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h
r1824 r1867 316 316 struct SimpleRay 317 317 { 318 int mId; 318 319 Vector3 mOrigin; 319 320 Vector3 mDirection; 320 321 float mPdf; 321 int mType; 322 323 SimpleRay(): mType(Ray::LOCAL_RAY) {} 322 int mType; 323 324 static int sSimpleRayId; 325 SimpleRay(): mType(Ray::LOCAL_RAY) { 326 mId = sSimpleRayId++; 327 } 328 324 329 SimpleRay(const Vector3 &o, const Vector3 &d, const float p=1.0f): 325 mOrigin(o), mDirection(d), mPdf(p), mType(Ray::LOCAL_RAY) {} 330 mOrigin(o), mDirection(d), mPdf(p), mType(Ray::LOCAL_RAY) { 331 mId = sSimpleRayId++; 332 } 326 333 327 334 Vector3 Extrap(const float t) const { -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
r1824 r1867 39 39 /** Checks if ray is valid, (e.g., not in empty view space or outside the view space) 40 40 */ 41 bool RayCaster::ValidateRay(const Vector3 &origin, 42 const Vector3 &direction, 43 const AxisAlignedBox3 &box, 44 Intersection &hit) 41 bool 42 RayCaster::ValidateRay(const Vector3 &origin, 43 const Vector3 &direction, 44 const AxisAlignedBox3 &box, 45 Intersection &hit) 45 46 { 46 47 47 if (!hit.mObject) { 48 // compute intersection with the scene bounding box 48 49 #if EXACT_BOX_CLIPPING 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 50 static Ray ray; 51 mPreprocessor.SetupRay(ray, origin, direction); 52 53 float tmin, tmax; 54 if (box.ComputeMinMaxT(ray, &tmin, &tmax) && (tmin < tmax)) { 55 hit.mPoint = ray.Extrap(tmax); 56 } 57 else { 58 // cout<<" invalid hp "<<tmin<<" "<<tmax<<endl; 59 // cout<<" box "<<box<<endl; 60 // cout<<" origin "<<origin<<endl; 61 // cout<<" direction "<<direction<<endl; 62 // cout<< "inv dir"<<ray.GetInvDir()<<endl; 63 return false; 64 } 64 65 #else 65 66 hit.mPoint = origin + direction*Magnitude(box.Diagonal()); 66 67 #endif 67 } 68 else if (mPreprocessor.mDetectEmptyViewSpace) { 69 if (DotProd(hit.mNormal, direction) >= 0) { 68 } 69 else 70 if (mPreprocessor.mDetectEmptyViewSpace) { 71 if (DotProd(hit.mNormal, direction) >= -Limits::Small) { 70 72 hit.mObject = NULL; 71 73 return false; 72 74 } 73 75 } 74 75 76 77 return true; 76 78 } 77 79 78 80 79 int RayCaster::ProcessRay(const SimpleRay &simpleRay, 80 Intersection &hitA, 81 Intersection &hitB, 82 VssRayContainer &vssRays, 83 const AxisAlignedBox3 &box, 84 const bool castDoubleRay, 85 const bool pruneInvalidRays) 81 int 82 RayCaster::ProcessRay(const SimpleRay &simpleRay, 83 Intersection &hitA, 84 Intersection &hitB, 85 VssRayContainer &vssRays, 86 const AxisAlignedBox3 &box, 87 const bool castDoubleRay, 88 const bool pruneInvalidRays) 86 89 { 87 90 int hits = 0; … … 90 93 Debug<<"PRA"<<flush; 91 94 #endif 95 96 // regardless of the pruneInvalidRays setting reject rays whic degenerate to a point 97 if (EpsilonEqualV3(hitA.mPoint, hitB.mPoint, Limits::Small)) 98 return 0; 92 99 93 if (pruneInvalidRays) 94 { 100 if (pruneInvalidRays) { 95 101 if (!hitA.mObject && !hitB.mObject) { 96 102 return 0; … … 100 106 const bool validA = 101 107 ValidateRay(simpleRay.mOrigin, simpleRay.mDirection, box, hitA); 102 108 109 const bool validB = castDoubleRay && 110 ValidateRay(simpleRay.mOrigin, -simpleRay.mDirection, box, hitB); 111 103 112 #if DEBUG_RAYCAST 104 113 Debug<<"PR1"<<flush; 105 114 #endif 106 115 107 if (!validA && pruneInvalidRays) 108 { 116 // reset both contributions 117 if (!validA || !validB) { 118 if (pruneInvalidRays) 109 119 return 0; 110 } 120 // reset both contributions of this ray 121 hitA.mObject = NULL; 122 hitB.mObject = NULL; 123 } 124 111 125 112 const bool validB = castDoubleRay && 113 ValidateRay(simpleRay.mOrigin, -simpleRay.mDirection, box, hitB); 114 115 if (!validB && pruneInvalidRays) 116 { 117 return 0; 118 } 119 120 const bool validSample = !pruneInvalidRays || (hitA.mObject != hitB.mObject); 121 126 const bool validSample = true; 127 // 8.11. 2007 JB 128 // degenerate rays checked by geometrical constraint... 129 // !pruneInvalidRays || (hitA.mObject != hitB.mObject); 122 130 123 131 #if DEBUG_RAYCAST … … 126 134 127 135 if (validSample) { 128 if (!pruneInvalidRays || hitA.mObject) 129 { 130 VssRay *vssRay = new VssRay( 131 hitB.mPoint, 132 hitA.mPoint, 133 hitB.mObject, 134 hitA.mObject, 135 mPreprocessor.mPass, 136 simpleRay.mPdf 137 ); 138 if (validA) 139 vssRay->mFlags |= VssRay::Valid; 140 vssRays.push_back(vssRay); 141 ++ hits; 142 //cout << "vssray 1: " << *vssRay << " " << vssRay->mTermination - vssRay->mOrigin << endl; 143 } 144 136 if (!pruneInvalidRays || hitA.mObject) { 137 VssRay *vssRay = new VssRay( 138 hitB.mPoint, 139 hitA.mPoint, 140 hitB.mObject, 141 hitA.mObject, 142 mPreprocessor.mPass, 143 simpleRay.mPdf 144 ); 145 146 if (validA) 147 vssRay->mFlags |= VssRay::Valid; 148 vssRay->mGeneratingRayId = simpleRay.mId; 149 vssRays.push_back(vssRay); 150 ++ hits; 151 //cout << "vssray 1: " << *vssRay << " " << vssRay->mTermination - vssRay->mOrigin << endl; 152 } 153 145 154 #if DEBUG_RAYCAST 146 Debug<<"PR3"<<flush;155 Debug<<"PR3"<<flush; 147 156 #endif 148 157 … … 150 159 { 151 160 VssRay *vssRay = new VssRay( 152 153 154 155 156 157 158 161 hitA.mPoint, 162 hitB.mPoint, 163 hitA.mObject, 164 hitB.mObject, 165 mPreprocessor.mPass, 166 simpleRay.mPdf 167 ); 159 168 if (validB) 160 169 vssRay->mFlags |= VssRay::Valid; 161 170 171 vssRay->mGeneratingRayId = simpleRay.mId; 162 172 vssRays.push_back(vssRay); 163 173 ++ hits; … … 165 175 } 166 176 } 167 177 168 178 #if DEBUG_RAYCAST 169 179 Debug<<"PR4"<<flush; -
GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
r1824 r1867 13 13 #include "GlRenderer.h" 14 14 #include "SamplingStrategy.h" 15 15 #include "PreprocessorThread.h" 16 16 17 17 … … 19 19 20 20 21 static bool useViewSpaceBox = false; 22 static bool use2dSampling = false; 23 24 25 // not supported anymore! 26 static bool fromBoxVisibility = false; 21 const bool pruneRays = false; 22 23 27 24 28 25 #define ADD_RAYS_IN_PLACE 1 … … 62 59 RssPreprocessor::GenerateRays( 63 60 const int number, 64 const int sampleType, 65 SimpleRayContainer &rays 66 ) 61 SamplingStrategy &strategy, 62 SimpleRayContainer &rays) 67 63 { 68 64 int result = 0; … … 70 66 Debug<<"Generate rays...\n"<<flush; 71 67 72 switch (s ampleType) {68 switch (strategy.mType) { 73 69 case SamplingStrategy::RSS_BASED_DISTRIBUTION: 74 70 case SamplingStrategy::RSS_SILHOUETTE_BASED_DISTRIBUTION: 75 71 if (mRssTree) { 76 72 result = GenerateImportanceRays(mRssTree, number, rays); 77 73 } 78 74 break; 79 75 80 76 default: 81 result = Preprocessor::GenerateRays(number, sampleType, rays);82 } 83 77 result = Preprocessor::GenerateRays(number, strategy, rays); 78 } 79 84 80 // rays.NormalizePdf(); 85 81 Debug<<"done.\n"<<flush; … … 413 409 { 414 410 // now evaluate the ratios for the next pass 415 #define TIME_WEIGHT 0. 5f411 #define TIME_WEIGHT 0.0f 416 412 for (int i=0; i < distributions.size(); i++) { 417 413 distributions[i]->mRatio = distributions[i]->mContribution/ … … 437 433 438 434 Randomize(0); 435 436 if (1) { 437 Exporter *exporter = Exporter::GetExporter("samples.wrl"); 438 exporter->SetFilled(); 439 Halton<4> halton; 440 441 // for (int i=1; i < 7; i++) 442 // cout<<i<<" prime= "<<FindPrime(i)<<endl; 443 444 Material mA, mB; 445 mA.mDiffuseColor = RgbColor(1, 0, 0); 446 mB.mDiffuseColor = RgbColor(0, 1, 0); 447 448 for (int i=0; i < 10000; i++) { 449 float r[4]; 450 halton.GetNext(r); 451 Vector3 v1 = UniformRandomVector(r[0], r[1]); 452 Vector3 v2 = UniformRandomVector(r[2], r[3]); 453 454 const float size =0.002f; 455 AxisAlignedBox3 box(v1-Vector3(size), v1+Vector3(size)); 456 exporter->SetForcedMaterial(mA); 457 exporter->ExportBox(box); 458 AxisAlignedBox3 box2(v2-Vector3(size), v2+Vector3(size)); 459 460 exporter->SetForcedMaterial(mB); 461 exporter->ExportBox(box2); 462 } 463 delete exporter; 464 } 465 466 467 cout<<"COMPUTATION THREAD="<<GetThread()->GetCurrentThreadId()<<endl<<flush; 439 468 440 469 // use ray buffer to export ray animation 441 const bool useRayBuffer = false;470 const bool useRayBuffer = true; 442 471 443 472 vector<VssRayContainer> rayBuffer(50); … … 467 496 mDistributions.push_back(new RssBasedDistribution(*this)); 468 497 469 470 if (1) { 471 // mDistributions.push_back(new SpatialBoxBasedDistribution(*this)); 472 // mDistributions.push_back(new DirectionBasedDistribution(*this)); 473 mDistributions.push_back(new ObjectDirectionBasedDistribution(*this)); 474 // mDistributions.push_back(new ReverseObjectBasedDistribution(*this)); 475 mDistributions.push_back(new ObjectBasedDistribution(*this)); 476 mDistributions.push_back(new ReverseViewSpaceBorderBasedDistribution(*this)); 477 } else { 478 mDistributions.push_back(new GlobalLinesDistribution(*this)); 479 } 498 499 if (1) { 500 mDistributions.push_back(new SpatialBoxBasedDistribution(*this)); 501 // // mDistributions.push_back(new DirectionBasedDistribution(*this)); 502 // mDistributions.push_back(new ObjectDirectionBasedDistribution(*this)); 503 // // mDistributions.push_back(new ReverseObjectBasedDistribution(*this)); 504 // mDistributions.push_back(new ObjectBasedDistribution(*this)); 505 // mDistributions.push_back(new ReverseViewSpaceBorderBasedDistribution(*this)); 506 } else { 507 mDistributions.push_back(new GlobalLinesDistribution(*this)); 508 mDistributions.push_back(new SpatialBoxBasedDistribution(*this)); 509 } 480 510 481 511 if (mLoadInitialSamples) { … … 500 530 if (mDistributions[i]->mType != SamplingStrategy::RSS_BASED_DISTRIBUTION) 501 531 GenerateRays(mInitialSamples/count, 502 mDistributions[i]->mType,503 504 532 *mDistributions[i], 533 rays); 534 505 535 } else { 506 536 int rayType = SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION; … … 511 541 rayType = SamplingStrategy::DIRECTION_BASED_DISTRIBUTION; 512 542 cout<<"Generating rays..."<<endl; 513 GenerateRays(mRssSamplesPerPass, rayType, rays); 543 544 Preprocessor::GenerateRays(mRssSamplesPerPass, rayType, rays); 514 545 } 515 546 516 547 517 548 cout<<"Casting initial rays..."<<endl<<flush; 518 CastRays(rays, mVssRays, true );549 CastRays(rays, mVssRays, true, pruneRays); 519 550 520 551 ExportObjectRays(mVssRays, 1546); … … 578 609 // cull viewcells with PVS > median (0.5f) 579 610 //mViewCellsManager->SetValidityPercentage(0, 0.5f); 580 mViewCellsManager->SetValidityPercentage(0, 1.0f);611 // mViewCellsManager->SetValidityPercentage(0, 1.0f); 581 612 Debug<<"Valid viewcells after set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; 582 613 … … 584 615 mViewCellsManager->PrintPvsStatistics(mStats); 585 616 617 618 if (0) { 619 char str[64]; 620 sprintf(str, "tmp/v-"); 621 622 // visualization 623 const bool exportRays = true; 624 const bool exportPvs = true; 625 ObjectContainer objects; 626 mViewCellsManager->ExportSingleViewCells(objects, 627 1000, 628 false, 629 exportPvs, 630 exportRays, 631 10000, 632 str); 633 } 634 586 635 ComputeRenderError(); 587 636 } 637 638 // return 1; 588 639 589 640 rssPass++; … … 618 669 } 619 670 } 620 621 671 672 // keep only rss 673 mDistributions.resize(1); 622 674 623 675 while (1) { … … 646 698 if (mDistributions[i]->mRatio != 0) { 647 699 GenerateRays(int(mRssSamplesPerPass*mDistributions[i]->mRatio), 648 mDistributions[i]->mType,700 *mDistributions[i], 649 701 rays); 650 702 651 703 rays.NormalizePdf((float)rays.size()); 652 704 653 CastRays(rays, tmpVssRays, true );705 CastRays(rays, tmpVssRays, true, pruneRays); 654 706 castRays += (int)rays.size(); 655 707 708 cout<<"Computing sample contributions..."<<endl<<flush; 709 656 710 #if ADD_RAYS_IN_PLACE 657 711 mDistributions[i]->mContribution = … … 661 715 mViewCellsManager->ComputeSampleContributions(tmpVssRays, false, true); 662 716 #endif 717 cout<<"done."<<endl; 663 718 } 664 719 665 720 mDistributions[i]->mTime = TimeDiff(t1, GetTime()); 666 mDistributions[i]->mRays = (int)rays.size(); 721 // mDistributions[i]->mRays = (int)rays.size(); 722 mDistributions[i]->mRays = (int)tmpVssRays.size() + 1; 667 723 // mStats<<"#RssRelContrib"<<endl<<contributions[0]/nrays[0]<<endl; 668 724 vssRays.insert(vssRays.end(), tmpVssRays.begin(), tmpVssRays.end() ); … … 686 742 cout<<"Generating rays..."<<endl; 687 743 688 GenerateRays(mRssSamplesPerPass, rayType, rays);744 Preprocessor::GenerateRays(mRssSamplesPerPass, rayType, rays); 689 745 cout<<"done."<<endl; 690 746 … … 843 899 844 900 845 if (useRayBuffer && mExportRays && mUseImportanceSampling) {901 if (useRayBuffer && mExportRays && mUseImportanceSampling) { 846 902 char filename[64]; 847 903 sprintf(filename, "rss-rays-i.x3d"); -
GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.h
r1785 r1867 125 125 /** Redefininition of the get sample rays method from the preprocessor */ 126 126 int 127 GenerateRays( 128 const int number, 129 const int sampleType, 130 SimpleRayContainer &rays 131 ); 132 127 GenerateRays(const int number, 128 SamplingStrategy &strategy, 129 SimpleRayContainer &rays); 130 133 131 }; 134 132 -
GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
r1841 r1867 352 352 leaf->dirBBox.Initialize(); 353 353 leaf->dirBBox.SetMin(2, 0.0f); 354 leaf->dirBBox.SetMax(2, 1.0f);354 leaf->dirBBox.SetMax(2, 0.0f); 355 355 mRoots[0] = leaf; 356 356 stat.nodes = 1; … … 1237 1237 node->axis = axis; 1238 1238 node->position = info.position; 1239 // node->bbox = box; 1240 // node->dirBBox = GetDirBBox(leaf);1241 1239 1240 node->bbox = GetBBox(leaf); 1241 node->dirBBox = GetDirBBox(leaf); 1242 1242 1243 1243 RssTreeLeaf *back = new RssTreeLeaf(node, info.raysBack); … … 1245 1245 1246 1246 1247 // update halton generator1248 back->halton.index = leaf->halton.index;1249 front->halton.index = leaf->halton.index;1250 1247 1251 1248 // replace a link from node's parent … … 1810 1807 int leaves = 0; 1811 1808 1809 for (int i=0; i < mRoots.size(); i++) 1810 UpdateImportance(mRoots[i]); 1811 1812 1812 while (!tstack.empty()) { 1813 1813 RssTreeNode *node = tstack.top(); 1814 1815 1814 tstack.pop(); 1815 1816 1816 if (node->IsLeaf()) { 1817 1817 leaves++; 1818 1818 RssTreeLeaf *leaf = (RssTreeLeaf *)node; 1819 UpdatePvsSize(leaf); 1819 // updated above already 1820 // UpdatePvsSize(leaf); 1820 1821 1821 1822 sumPvsSize += leaf->GetPvsSize(); … … 1841 1842 sumImportance += imp; 1842 1843 1843 1844 1844 } else { 1845 1845 RssTreeInterior *in = (RssTreeInterior *)node; 1846 // both nodes for directional splits1847 1846 tstack.push(in->front); 1848 1847 tstack.push(in->back); … … 1858 1857 stat.avgWeightedRayContribution = sumWeightedRayContribution/(float)sumRays; 1859 1858 stat.rayRefs = (int)sumRays; 1860 } 1861 1862 1859 1860 } 1861 1862 void 1863 RssTree::UpdateImportance( 1864 RssTreeNode *node) 1865 { 1866 if (node->IsLeaf()) { 1867 UpdatePvsSize((RssTreeLeaf *)node); 1868 } else { 1869 RssTreeInterior *in = (RssTreeInterior *)node; 1870 UpdateImportance(in->front); 1871 UpdateImportance(in->back); 1872 node->mImportance = in->front->mImportance + in->back->mImportance; 1873 } 1874 } 1875 1876 // generate a single ray described by parameters in a unit cube 1877 void 1878 RssTree::GenerateRay(float *params, SimpleRayContainer &rays) 1879 { 1880 RssTreeNode *node; 1881 1882 // works only with single root now! 1883 node = mRoots[0]; 1884 1885 while (!node->IsLeaf()) { 1886 RssTreeInterior *in = (RssTreeInterior *)node; 1887 // decide whether to go left or right 1888 int axis = in->axis; 1889 float pos = in->GetRelativePosition(); 1890 1891 float r = in->back->GetImportance()/(in->back->GetImportance() + in->front->GetImportance()); 1892 1893 // cout<<"axis="<<axis<<" pos="<<pos<<endl; 1894 // cout<<GetBBox(in)<<endl; 1895 // cout<<GetDirBBox(in)<<endl; 1896 // cout<<"********"<<endl; 1897 1898 if (params[axis] < r) { 1899 node = in->back; 1900 params[axis] = params[axis] / pos; 1901 } else { 1902 node = in->front; 1903 params[axis] = (params[axis] - pos) / ( 1.0f - pos); 1904 } 1905 } 1906 1907 // cout<<params[0]<<" "<<params[1]<<" "<<params[2]<<" "<<params[3]<<" "<<params[4]<<endl; 1908 1909 GenerateLeafRay(params, rays, node->bbox, node->dirBBox); 1910 } 1863 1911 1864 1912 int … … 1867 1915 SimpleRayContainer &rays) 1868 1916 { 1917 1918 1919 1920 1869 1921 stack<RssTreeNode *> tstack; 1870 1922 PushRoots(tstack); … … 2195 2247 for (int i=0; i < numberOfRays; i++) { 2196 2248 // Debug<<i<<flush; 2197 2198 Vector3 origin, direction; 2199 Vector3 dirVector; 2200 2201 Vector3 pVector; 2202 Vector3 dVector; 2203 2204 bool useHalton = false; 2205 2206 2207 if (useHalton) { 2208 // generate a random 5D vector 2209 pVector = Vector3(leaf->halton.GetNumber(1), 2210 leaf->halton.GetNumber(2), 2211 leaf->halton.GetNumber(3)); 2212 2213 dVector = Vector3(leaf->halton.GetNumber(4), 2214 leaf->halton.GetNumber(5), 2215 0.0f); 2216 2217 leaf->halton.GenerateNext(); 2218 } else { 2219 pVector = Vector3(RandomValue(0.0f, 1.0f), 2220 RandomValue(0.0f, 1.0f), 2221 RandomValue(0.0f, 1.0f)); 2222 2223 dVector = Vector3(RandomValue(0.0f, 1.0f), 2224 RandomValue(0.0f, 1.0f), 2225 0.0f); 2226 } 2227 2228 origin = box.GetPoint(pVector); 2229 dirVector = dirBox.GetPoint(dVector); 2230 2231 direction = VssRay::GetInvDirParam(dirVector.x, dirVector.y); 2232 2233 // float dist = Min(avgLength*0.5f, Magnitude(GetBBox(leaf).Size())); 2234 float dist = 0.0f; 2235 float minT, maxT; 2236 2237 // compute interection of the ray with the box 2238 #if 1 2239 if (box.ComputeMinMaxT(origin, direction, &minT, &maxT) && minT < maxT) 2240 dist = (maxT + 1e-2*boxSize); 2241 #else 2242 dist = 0.5f*boxSize; 2243 #endif 2244 2245 origin += direction*dist; 2246 2247 #if 0 2248 static int counter = 0; 2249 // Debug<<counter++<<flush; 2250 2251 if (counter > 10374968) { 2252 Debug<<"size="<<rays.size()<<endl; 2253 Debug<<"capacity="<<rays.capacity()<<endl; 2254 Debug<<"o="<<origin<<endl; 2255 Debug<<"d="<<direction<<endl; 2256 } 2257 #endif 2258 //Debug<<"dir vector.x="<<dirVector.x<<"direction'.x="<<atan2(direction.x, direction.y)<<endl; 2259 rays.push_back(SimpleRay(origin, direction)); 2260 // Debug<<endl; 2261 2249 float r[5]; 2250 2251 r[0] = RandomValue(0.0f, 1.0f); 2252 r[1] = RandomValue(0.0f, 1.0f); 2253 r[2] = RandomValue(0.0f, 1.0f); 2254 r[3] = RandomValue(0.0f, 1.0f); 2255 r[4] = RandomValue(0.0f, 1.0f); 2256 2257 GenerateLeafRay(r, rays, box, dirBox); 2262 2258 } 2263 2259 … … 2269 2265 rays[i].mPdf = p; 2270 2266 } 2267 } 2268 2269 void 2270 RssTree::GenerateLeafRay( 2271 float *params, 2272 SimpleRayContainer &rays, 2273 const AxisAlignedBox3 &box, 2274 const AxisAlignedBox3 &dirBBox 2275 ) 2276 { 2277 Vector3 origin = bbox.GetPoint(Vector3(params[0], params[1], params[2])); 2278 Vector3 dirVector = dirBBox.GetPoint(Vector3(params[3], params[4], 0.0f)); 2279 Vector3 direction = VssRay::GetInvDirParam(dirVector.x, dirVector.y); 2280 2281 // float dist = Min(avgLength*0.5f, Magnitude(GetBBox(leaf).Size())); 2282 float dist = 0.0f; 2283 float minT, maxT; 2284 2285 float boxSize = Magnitude(bbox.Size()); 2286 // compute interection of the ray with the box 2287 #if 1 2288 if (bbox.ComputeMinMaxT(origin, direction, &minT, &maxT) && minT < maxT) 2289 dist = (maxT + 1e-2*boxSize); 2290 #else 2291 dist = 0.5f*boxSize; 2292 #endif 2293 2294 origin += direction*dist; 2295 2296 2297 //Debug<<"dir vector.x="<<dirVector.x<<"direction'.x="<<atan2(direction.x, direction.y)<<endl; 2298 rays.push_back(SimpleRay(origin, direction)); 2271 2299 } 2272 2300 … … 2378 2406 Vector3 dVector; 2379 2407 2380 bool useHalton = true; 2381 2382 if (useHalton) { 2383 // generate a random 5D vector 2384 pVector = Vector3(leaf->halton.GetNumber(1), 2385 leaf->halton.GetNumber(2), 2386 leaf->halton.GetNumber(3)); 2387 2388 dVector = Vector3(leaf->halton.GetNumber(4), 2389 leaf->halton.GetNumber(5), 2390 0.0f); 2391 2392 leaf->halton.GenerateNext(); 2393 } else { 2394 pVector = Vector3(RandomValue(0.0f, 1.0f), 2395 RandomValue(0.0f, 1.0f), 2396 RandomValue(0.0f, 1.0f)); 2397 2398 dVector = Vector3(RandomValue(0.0f, 1.0f), 2399 RandomValue(0.0f, 1.0f), 2400 0.0f); 2401 } 2408 pVector = Vector3(RandomValue(0.0f, 1.0f), 2409 RandomValue(0.0f, 1.0f), 2410 RandomValue(0.0f, 1.0f)); 2411 2412 dVector = Vector3(RandomValue(0.0f, 1.0f), 2413 RandomValue(0.0f, 1.0f), 2414 0.0f); 2415 2402 2416 2403 2417 origin = box.GetPoint(pVector); … … 2625 2639 if (node->IsLeaf()) { 2626 2640 RssTreeLeaf *leaf = (RssTreeLeaf *)node; 2627 // 2641 // prunned += PruneRaysRandom(leaf, ratio); 2628 2642 prunned += PruneRaysContribution(leaf, ratio); 2629 2643 } else { … … 2653 2667 { 2654 2668 2655 2669 float param[5]; 2670 2671 for (int i=0; i < numberOfRays; i++) { 2672 halton.GetNext(param); 2673 GenerateRay(param, rays); 2674 } 2675 2676 return rays.size(); 2677 2656 2678 vector<RssTreeLeaf *> leaves; 2657 2679 … … 2864 2886 2865 2887 // $$ 2866 sumWeights = (float)leaf->mTotalRays;2888 // sumWeights = leaf->mTotalRays; 2867 2889 2868 2890 //$$ test 30.11. 2006 … … 2890 2912 2891 2913 float 2892 RssTree Leaf::GetImportance() const2914 RssTreeNode::GetImportance() const 2893 2915 { 2894 2916 // return sqr(mImportance); … … 3129 3151 3130 3152 3131 } 3153 3154 3155 3156 } -
GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h
r1832 r1867 137 137 public: 138 138 139 139 140 struct RayInfo 140 141 { … … 162 163 } 163 164 165 164 166 #define USE_ORIGIN 1 165 167 … … 312 314 AxisAlignedBox3 dirBBox; 313 315 314 316 // evaluated importance of this node 317 float mImportance; 318 315 319 inline RssTreeNode(RssTreeInterior *p); 316 320 … … 328 332 } 329 333 330 334 float GetImportance() const; 335 331 336 332 337 }; … … 339 344 { 340 345 public: 341 // plane in local modellingcoordinates346 // plane in world coordinates 342 347 float position; 343 348 … … 359 364 virtual int GetAccessTime() { 360 365 return lastAccessTime; 366 } 367 368 float GetRelativePosition() const { 369 if (axis < 3) 370 return (position - bbox.Min(axis))/bbox.Size(axis); 371 else 372 return (position - dirBBox.Min(axis-3))/dirBBox.Size(axis-3); 361 373 } 362 374 … … 423 435 424 436 bool mValidPvs; 425 float mImportance; 426 427 HaltonSequence halton; 428 437 429 438 Beam mBeam; 430 439 … … 490 499 } 491 500 492 float GetImportance() const;493 501 494 502 float GetSqrRayContribution() const { … … 621 629 622 630 623 631 Halton<5> halton; 632 633 624 634 ///////////////////////////// 625 635 // Basic properties … … 1086 1096 PushRoots(stack<RayTraversalData> &st, RssTreeNode::RayInfo &info) const; 1087 1097 1088 1098 void 1099 UpdateImportance( 1100 RssTreeNode *node); 1101 1102 void 1103 GenerateRay(float *params, SimpleRayContainer &rays); 1104 1105 void 1106 GenerateLeafRay( 1107 float *params, 1108 SimpleRayContainer &rays, 1109 const AxisAlignedBox3 &box, 1110 const AxisAlignedBox3 &dirBBox 1111 ); 1112 1089 1113 }; 1090 1114 -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r1824 r1867 22 22 int 23 23 SamplingStrategy::GenerateSamples(const int number, 24 SimpleRayContainer &rays) const24 SimpleRayContainer &rays) 25 25 { 26 26 SimpleRay ray; … … 67 67 68 68 69 bool ObjectBasedDistribution::GenerateSample(SimpleRay &ray) const69 bool ObjectBasedDistribution::GenerateSample(SimpleRay &ray) 70 70 { 71 71 Vector3 origin, direction; … … 99 99 100 100 101 bool ObjectDirectionBasedDistribution::GenerateSample(SimpleRay &ray) const101 bool ObjectDirectionBasedDistribution::GenerateSample(SimpleRay &ray) 102 102 { 103 103 Vector3 origin, direction; … … 127 127 128 128 129 bool DirectionBasedDistribution::GenerateSample(SimpleRay &ray) const129 bool DirectionBasedDistribution::GenerateSample(SimpleRay &ray) 130 130 { 131 131 Vector3 origin, direction; … … 147 147 148 148 149 bool DirectionBoxBasedDistribution::GenerateSample(SimpleRay &ray) const149 bool DirectionBoxBasedDistribution::GenerateSample(SimpleRay &ray) 150 150 { 151 151 Vector3 origin, direction; … … 171 171 172 172 173 bool SpatialBoxBasedDistribution::GenerateSample(SimpleRay &ray) const 174 { 175 Vector3 origin, direction; 176 177 mPreprocessor.mViewCellsManager->GetViewPoint(origin); 178 direction = mPreprocessor.mKdTree->GetBox().GetRandomPoint() - origin; 179 //cout << "z"; 180 const float c = Magnitude(direction); 181 182 if (c <= Limits::Small) 183 return false; 184 185 const float pdf = 1.0f; 186 187 direction *= 1.0f / c; 188 ray = SimpleRay(origin, direction, pdf); 189 190 return true; 191 } 192 193 194 bool ReverseObjectBasedDistribution::GenerateSample(SimpleRay &ray) const 173 bool SpatialBoxBasedDistribution::GenerateSample(SimpleRay &ray) 174 { 175 Vector3 origin, direction; 176 177 float r[6]; 178 halton.GetNext(r); 179 mPreprocessor.mViewCellsManager->GetViewPoint(origin, Vector3(r[0],r[1],r[2])); 180 181 direction = mPreprocessor.mKdTree->GetBox().GetRandomPoint(Vector3(r[3], 182 r[4], 183 r[5]) 184 ) - origin; 185 //cout << "z"; 186 const float c = Magnitude(direction); 187 188 if (c <= Limits::Small) 189 return false; 190 191 const float pdf = 1.0f; 192 193 direction *= 1.0f / c; 194 ray = SimpleRay(origin, direction, pdf); 195 196 return true; 197 } 198 199 200 bool ReverseObjectBasedDistribution::GenerateSample(SimpleRay &ray) 195 201 { 196 202 Vector3 origin, direction; … … 230 236 231 237 232 bool ViewCellBorderBasedDistribution::GenerateSample(SimpleRay &ray) const238 bool ViewCellBorderBasedDistribution::GenerateSample(SimpleRay &ray) 233 239 { 234 240 Vector3 origin, direction; … … 274 280 275 281 #if 0 276 bool ObjectsInteriorDistribution::GenerateSample(SimpleRay &ray) const282 bool ObjectsInteriorDistribution::GenerateSample(SimpleRay &ray) 277 283 { 278 284 Vector3 origin, direction; … … 306 312 307 313 308 bool ReverseViewSpaceBorderBasedDistribution::GenerateSample(SimpleRay &ray) const314 bool ReverseViewSpaceBorderBasedDistribution::GenerateSample(SimpleRay &ray) 309 315 { 310 316 Vector3 origin, direction; … … 344 350 345 351 346 bool ViewSpaceBorderBasedDistribution::GenerateSample(SimpleRay &ray) const352 bool ViewSpaceBorderBasedDistribution::GenerateSample(SimpleRay &ray) 347 353 { 348 354 Vector3 origin, direction; … … 381 387 382 388 bool 383 RssBasedDistribution::GenerateSample(SimpleRay &ray) const389 RssBasedDistribution::GenerateSample(SimpleRay &ray) 384 390 { 385 391 return false; … … 388 394 389 395 bool 390 GlobalLinesDistribution::GenerateSample(SimpleRay &ray) const 391 { 392 Vector3 origin, termination, direction; 393 394 origin = mPreprocessor.mViewCellsManager->GetViewSpaceBox().GetRandomSurfacePoint(); 395 396 termination = mPreprocessor.mViewCellsManager->GetViewSpaceBox().GetRandomSurfacePoint(); 396 GlobalLinesDistribution::GenerateSample(SimpleRay &ray) 397 { 398 Vector3 origin, termination, direction; 399 400 float radius = 0.5f*Magnitude(mPreprocessor.mViewCellsManager->GetViewSpaceBox().Size()); 401 Vector3 center = mPreprocessor.mViewCellsManager->GetViewSpaceBox().Center(); 402 403 const int tries = 1000; 404 int i; 405 for (i=0; i < tries; i++) { 406 float r[4]; 407 halton.GetNext(r); 408 409 #if 0 410 #if 0 411 r[0] = RandomValue(0,1); 412 r[1] = RandomValue(0,1); 413 r[2] = RandomValue(0,1); 414 r[3] = RandomValue(0,1); 415 #else 416 r[0] = mHalton.GetNumber(1); 417 r[1] = mHalton.GetNumber(2); 418 r[2] = mHalton.GetNumber(3); 419 r[3] = mHalton.GetNumber(4); 420 mHalton.GenerateNext(); 421 #endif 422 #endif 423 origin = center + (radius*UniformRandomVector(r[0], r[1])); 424 termination = center + (radius*UniformRandomVector(r[2], r[3])); 397 425 398 426 direction = termination - origin; 399 427 //direction = UniformRandomVector(); 400 401 402 // $$ jb the pdf is yet not correct for all sampling methods! 403 const float c = Magnitude(direction); 404 if (c <= Limits::Small) 405 return false; 406 407 408 direction *= 1.0f / c; 409 410 // a little offset 411 // origin += direction * 0.001f; 412 413 // $$ jb the pdf is yet not correct for all sampling methods! 414 const float pdf = 1.0f; 415 428 429 430 // $$ jb the pdf is yet not correct for all sampling methods! 431 const float c = Magnitude(direction); 432 if (c <= Limits::Small) 433 return false; 434 435 direction *= 1.0f / c; 436 437 // check if the ray intersects the view space box 438 static Ray ray; 439 ray.Init(origin, direction, Ray::LOCAL_RAY); 440 441 float tmin, tmax; 442 if (mPreprocessor.mViewCellsManager-> 443 GetViewSpaceBox().ComputeMinMaxT(ray, &tmin, &tmax) && (tmin < tmax)) 444 break; 445 } 446 447 if (i!=tries) { 448 // $$ jb the pdf is yet not correct for all sampling methods! 449 const float pdf = 1.0f; 450 451 416 452 ray = SimpleRay(origin, direction, pdf); 417 453 ray.mType = Ray::GLOBAL_RAY; 418 454 return true; 419 } 420 421 } 422 423 455 } 456 457 return false; 458 } 459 460 } 461 462 -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
r1824 r1867 2 2 #define _SamplingStategy_H__ 3 3 4 #include "Halton.h" 4 5 5 6 namespace GtpVisibilityPreprocessor { … … 46 47 */ 47 48 48 virtual int GenerateSamples(const int number, SimpleRayContainer &rays) const;49 50 private: 51 52 virtual bool GenerateSample(SimpleRay &ray) const= 0;49 virtual int GenerateSamples(const int number, SimpleRayContainer &rays); 50 51 private: 52 53 virtual bool GenerateSample(SimpleRay &ray) = 0; 53 54 54 55 public: … … 77 78 78 79 private: 79 virtual bool GenerateSample(SimpleRay &ray) const;80 virtual bool GenerateSample(SimpleRay &ray); 80 81 }; 81 82 … … 91 92 92 93 private: 93 virtual bool GenerateSample(SimpleRay &ray) const;94 virtual bool GenerateSample(SimpleRay &ray); 94 95 }; 95 96 … … 103 104 } 104 105 private: 105 virtual bool GenerateSample(SimpleRay &ray) const;106 virtual bool GenerateSample(SimpleRay &ray); 106 107 }; 107 108 … … 115 116 } 116 117 private: 117 virtual bool GenerateSample(SimpleRay &ray) const;118 virtual bool GenerateSample(SimpleRay &ray); 118 119 }; 119 120 … … 128 129 129 130 private: 130 virtual bool GenerateSample(SimpleRay &ray) const;131 virtual bool GenerateSample(SimpleRay &ray); 131 132 }; 132 133 … … 135 136 { 136 137 public: 137 SpatialBoxBasedDistribution(const Preprocessor &preprocessor): 138 SamplingStrategy(preprocessor){ 139 mType = DIRECTION_BOX_BASED_DISTRIBUTION; 140 } 141 142 private: 143 virtual bool GenerateSample(SimpleRay &ray) const; 138 Halton<6> halton; 139 SpatialBoxBasedDistribution(const Preprocessor &preprocessor): 140 SamplingStrategy(preprocessor){ 141 mType = DIRECTION_BOX_BASED_DISTRIBUTION; 142 } 143 144 private: 145 virtual bool GenerateSample(SimpleRay &ray); 144 146 }; 145 147 … … 154 156 155 157 private: 156 virtual bool GenerateSample(SimpleRay &ray) const;158 virtual bool GenerateSample(SimpleRay &ray); 157 159 }; 158 160 … … 167 169 168 170 private: 169 virtual bool GenerateSample(SimpleRay &ray) const;171 virtual bool GenerateSample(SimpleRay &ray); 170 172 }; 171 173 … … 180 182 181 183 182 virtual int GenerateSamples(const int number, SimpleRayContainer &ray) const{184 virtual int GenerateSamples(const int number, SimpleRayContainer &ray) { 183 185 // TBD!!! 184 186 return 0; … … 186 188 187 189 private: 188 virtual bool GenerateSample(SimpleRay &ray) const;190 virtual bool GenerateSample(SimpleRay &ray); 189 191 190 192 }; … … 197 199 SamplingStrategy(preprocessor) {} 198 200 199 virtual bool GenerateSample(SimpleRay &ray) const;201 virtual bool GenerateSample(SimpleRay &ray); 200 202 }; 201 203 … … 203 205 { 204 206 public: 207 Halton<4> halton; 208 //HaltonSequence mHalton; 209 205 210 GlobalLinesDistribution(const Preprocessor &preprocessor): 206 207 208 209 210 virtual bool GenerateSample(SimpleRay &ray) const;211 SamplingStrategy(preprocessor) { 212 mType = GLOBAL_LINES_DISTRIBUTION; 213 } 214 215 virtual bool GenerateSample(SimpleRay &ray); 211 216 }; 212 217 … … 221 226 SamplingStrategy(preprocessor) {} 222 227 223 virtual bool GenerateSample(SimpleRay &ray) const;228 virtual bool GenerateSample(SimpleRay &ray); 224 229 }; 225 230 */ -
GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.cpp
r1715 r1867 29 29 30 30 31 int Triangle3::CastRay(const Ray &ray, float &t, const float nearestT, Vector3 &normal) const 31 int 32 Triangle3::CastRay(const Ray &ray, 33 float &t, 34 const float nearestT, 35 Vector3 &normal) const 32 36 { 33 37 #if 0 … … 38 42 39 43 Polygon3 poly(vertices); 44 45 int dummy = poly.CastRay(ray, t, nearestT); 46 normal = poly.GetNormal(); 40 47 41 int dummy = poly.CastRay(ray, t, nearestT); 42 43 cout << "polyversion code: " << dummy << " t: " << t << " nearestT: " << nearestT << endl; 48 // cout << "polyversion code: " << dummy << " t: " << t << " nearestT: " << nearestT << endl; 44 49 return dummy; 45 50 #endif … … 83 88 t = a / b; 84 89 85 if (t < 0.0) // ray goes away from triangle90 if (t <= Limits::Small) // ray goes away from triangle 86 91 { 87 return Ray::NO_INTERSECTION; // => no intersect92 return Ray::INTERSECTION_OUT_OF_LIMITS; 88 93 } 89 94 // already found nearer intersection … … 113 118 const float wu = DotProd(w, u); 114 119 const float wv = DotProd(w, v); 115 const float D = uv * uv - uu * vv; 120 121 122 const float D = uv * uv - uu * vv; 116 123 117 124 // get and test parametric coords 118 125 const float s = (uv * wv - vv * wu) / D; 119 126 120 if ((s < 0.0) || (s > 1.0)) // pt is outside triangle127 if ((s < -Limits::Small) || (s > 1.0f + Limits::Small)) // pt is outside triangle 121 128 { 122 129 return Ray::NO_INTERSECTION; … … 125 132 const float s2 = (uv * wu - uu * wv) / D; 126 133 127 if ((s2 < 0.0) || ((s + s2) > 1.0)) // pt is outside triangle134 if ((s2 < -Limits::Small) || ((s + s2) > 1.0f + Limits::Small)) // pt is outside triangle 128 135 { 129 136 return Ray::NO_INTERSECTION; -
GTP/trunk/Lib/Vis/Preprocessing/src/Vector3.cpp
r1832 r1867 196 196 #define USE_HALTON 0 197 197 198 198 199 Vector3 199 200 UniformRandomVector() … … 209 210 r2 = RandomValue(0.0f, 1.0f); 210 211 #endif 211 212 213 return UniformRandomVector(r1, r2); 214 } 215 216 Vector3 217 UniformRandomVector(const float r1, const float r2) 218 { 212 219 float cosTheta = 1.0f - 2*r1; 213 float sinTheta = sqrt(1 - sqr(cosTheta)); 214 float fi = 2.0f*M_PI*r2; 215 216 Vector3 dir(sinTheta*sin(fi), 217 cosTheta, 218 sinTheta*cos(fi)); 219 220 return dir; 220 float sinTheta = sqrt(1 - sqr(cosTheta)); 221 float fi = 2.0f*M_PI*r2; 222 223 Vector3 dir(sinTheta*sin(fi), 224 cosTheta, 225 sinTheta*cos(fi)); 226 227 return dir; 228 } 229 230 231 Vector3 232 CosineRandomVector(const Vector3 &normal) 233 { 234 // float r1 = RandomValue(0.0f, 1.0f); 235 // float r2 = RandomValue(0.0f, 1.0f); 236 float r1, r2; 237 238 #if USE_HALTON 239 halton2.GetNext(r1, r2); 240 #else 241 r1 = RandomValue(0.0f, 1.0f); 242 r2 = RandomValue(0.0f, 1.0f); 243 #endif 244 245 float theta = 2.0f*M_PI*r2; 246 float radius = sqrt(r1); 247 float x = radius*sin(theta); 248 float z = radius*cos(theta); 249 float y = sqrt(1.0f - x*x - z*z); 250 251 252 Vector3 dir(x, 253 y, 254 z); 255 256 257 // return Normalize(dir); 258 259 Matrix4x4 m = RotationVectorsMatrix( 260 normal, 261 Vector3(0,1,0)); 262 Matrix4x4 mi = Invert(m); 263 m = m*RotationVectorsMatrix( 264 Vector3(0,1,0), 265 Normalize(dir))*mi; 266 267 return TransformNormal(m, normal); 221 268 } 222 269 -
GTP/trunk/Lib/Vis/Preprocessing/src/Vector3.h
r1579 r1867 233 233 friend inline int EpsilonEqualV3(const Vector3 &v1, const Vector3 &v2); 234 234 235 friend Vector3 CosineRandomVector(const Vector3 &normal); 235 236 friend Vector3 UniformRandomVector(const Vector3 &normal); 236 237 friend Vector3 UniformRandomVector(); 237 238 239 friend Vector3 240 UniformRandomVector(const float r1, const float r2); 241 242 friend Vector3 UniformRandomVector(const Vector3 &normal, 243 const float r1, 244 const float r2 245 ); 246 238 247 239 248 }; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1843 r1867 34 34 myless<vector<ViewCell *>::value_type> > TraversalQueue; 35 35 36 int ViewCell::sMailId = 10000;//2147483647;37 int ViewCell::sReservedMailboxes = 1;36 int ViewCell::sMailId = 10000;//2147483647; 37 int ViewCell::sReservedMailboxes = 1; 38 38 39 39 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
r1842 r1867 284 284 //-- mailing stuff 285 285 286 static void NewMail(const int reserve = 1)287 {288 sMailId += sReservedMailboxes;289 sReservedMailboxes = reserve;290 }291 292 void Mail() { mMailbox = sMailId; }293 bool Mailed() const { return mMailbox == sMailId; }294 295 void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }296 bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }297 298 int IncMail() { return ++ mMailbox - sMailId; }286 // static void NewMail(const int reserve = 1) 287 // { 288 // sMailId += sReservedMailboxes; 289 // sReservedMailboxes = reserve; 290 // } 291 292 // void Mail() { mMailbox = sMailId; } 293 // bool Mailed() const { return mMailbox == sMailId; } 294 295 // void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 296 // bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 297 298 // int IncMail() { return ++ mMailbox - sMailId; } 299 299 300 300 301 301 // last mail id -> warning not thread safe! 302 302 // both mailId and mailbox should be unique for each thread!!! 303 static int sMailId; 304 static int sReservedMailboxes; 303 304 //static int sMailId; 305 //static int sReservedMailboxes; 305 306 306 307 int GetFilteredPvsSize() const { -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1846 r1867 1500 1500 bool ViewCellsManager::GetViewPoint(Vector3 &viewPoint) const 1501 1501 { 1502 viewPoint = mViewSpaceBox.GetRandomPoint(); 1503 return true; 1502 viewPoint = mViewSpaceBox.GetRandomPoint(); 1503 return true; 1504 } 1505 1506 bool ViewCellsManager::GetViewPoint(Vector3 &viewPoint, const Vector3 ¶ms) const 1507 { 1508 viewPoint = mViewSpaceBox.GetRandomPoint(params); 1509 return true; 1504 1510 } 1505 1511 … … 1532 1538 1533 1539 1534 float ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays, 1535 const bool addRays, 1536 const bool storeViewCells) 1537 { 1538 // view cells not yet constructed 1539 if (!ViewCellsConstructed()) 1540 return 0.0f; 1541 1542 float sum = 0.0f; 1543 VssRayContainer::const_iterator it, it_end = rays.end(); 1544 1545 for (it = rays.begin(); it != it_end; ++ it) 1546 { 1547 sum += ComputeSampleContribution(*(*it), addRays, storeViewCells); 1548 } 1549 1550 return sum; 1540 float 1541 ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays, 1542 const bool addRays, 1543 const bool storeViewCells) 1544 { 1545 // view cells not yet constructed 1546 if (!ViewCellsConstructed()) 1547 return 0.0f; 1548 1549 float sum = 0.0f; 1550 VssRayContainer::const_iterator it, it_end = rays.end(); 1551 1552 for (it = rays.begin(); it != it_end; ++ it) 1553 { 1554 sum += ComputeSampleContribution(*(*it), addRays, storeViewCells); 1555 } 1556 1557 return sum; 1551 1558 } 1552 1559 … … 2006 2013 2007 2014 float ViewCellsManager::ComputeSampleContribution(VssRay &ray, 2008 const bool addRays, 2009 const bool storeViewCells) 2010 { 2011 ViewCellContainer viewcells; 2012 2013 ray.mPvsContribution = 0; 2014 ray.mRelativePvsContribution = 0.0f; 2015 2016 static Ray hray; 2017 hray.Init(ray); 2018 //hray.mFlags |= Ray::CULL_BACKFACES; 2019 //Ray hray(ray); 2020 2021 float tmin = 0, tmax = 1.0; 2022 2023 if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 2024 return 0; 2025 2026 Vector3 origin = hray.Extrap(tmin); 2027 Vector3 termination = hray.Extrap(tmax); 2028 2029 ViewCell::NewMail(); 2030 2031 // if (ray.mPdf!=1.0f) 2032 // cout<<ray.mPdf<<" "; 2033 2034 2035 // traverse the view space subdivision 2036 CastLineSegment(origin, termination, viewcells); 2037 2038 if (storeViewCells) 2015 const bool addRays, 2016 const bool storeViewCells) 2017 { 2018 ray.mPvsContribution = 0; 2019 ray.mRelativePvsContribution = 0.0f; 2020 2021 if (ray.mTerminationObject==NULL) 2022 return 0.0f; 2023 2024 ViewCellContainer viewcells; 2025 2026 2027 2028 2029 static Ray hray; 2030 hray.Init(ray); 2031 //hray.mFlags |= Ray::CULL_BACKFACES; 2032 //Ray hray(ray); 2033 2034 float tmin = 0, tmax = 1.0; 2035 2036 if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 2037 return 0; 2038 2039 Vector3 origin = hray.Extrap(tmin); 2040 Vector3 termination = hray.Extrap(tmax); 2041 2042 ViewCell::NewMail(); 2043 2044 // if (ray.mPdf!=1.0f) 2045 // cout<<ray.mPdf<<" "; 2046 2047 2048 // traverse the view space subdivision 2049 CastLineSegment(origin, termination, viewcells); 2050 2051 if (storeViewCells) 2039 2052 { // copy viewcells memory efficiently 2040 ray.mViewCells.reserve(viewcells.size()); 2041 ray.mViewCells = viewcells; 2042 } 2043 2044 Intersectable *obj = GetIntersectable(ray, true); 2045 2046 ViewCellContainer::const_iterator it = viewcells.begin(); 2047 2048 for (; it != viewcells.end(); ++ it) 2049 { 2050 ViewCell *viewcell = *it; 2051 // tests if view cell is in valid view space 2052 if (viewcell->GetValid()) 2053 { 2054 float contribution; 2055 2056 if (ray.mTerminationObject) 2057 { 2058 if (viewcell->GetPvs().GetSampleContribution(obj, 2059 ray.mPdf, 2060 contribution)) 2061 { 2062 ++ ray.mPvsContribution; 2063 ray.mRelativePvsContribution += contribution; 2064 // $$ test of different contribution measure 2065 // ray.mRelativePvsContribution += 1.0f/(viewcell->GetPvs().GetSize() + 10.0f); 2066 2067 } 2053 ray.mViewCells.reserve(viewcells.size()); 2054 ray.mViewCells = viewcells; 2055 } 2056 2057 Intersectable *obj = GetIntersectable(ray, true); 2058 2059 ViewCellContainer::const_iterator it = viewcells.begin(); 2060 2061 for (; it != viewcells.end(); ++ it) 2062 { 2063 ViewCell *viewcell = *it; 2064 // tests if view cell is in valid view space 2065 if (viewcell->GetValid()) 2066 { 2067 float contribution; 2068 2069 if (ray.mTerminationObject) { 2070 if (viewcell->GetPvs().GetSampleContribution(obj, 2071 ray.mPdf, 2072 contribution)) { 2073 ++ ray.mPvsContribution; 2068 2074 } 2069 2075 2076 ray.mRelativePvsContribution += contribution; 2077 // $$ test of different contribution measure 2078 // ray.mRelativePvsContribution += 1.0f/(viewcell->GetPvs().GetSize() + 10.0f); 2079 2080 } 2081 2070 2082 #if SAMPLE_ORIGIN_OBJECTS 2071 2072 2073 2083 2084 // for directional sampling it is important to count only contributions 2085 // made in one direction!!! 2074 2086 // the other contributions of this sample will be counted for the oposite ray! 2075 2087 … … 2096 2108 { 2097 2109 // if view point is valid, add new object to the pvs 2098 2110 if (ray.mTerminationObject) 2099 2111 { 2100 2112 viewcell->GetPvs().AddSample(obj, ray.mPdf); 2101 2113 } 2102 2114 #if SAMPLE_ORIGIN_OBJECTS … … 6035 6047 6036 6048 #define PVS_ADD_DIRTY 1 6037 float VspOspViewCellsManager::ComputeSampleContribution(VssRay &ray, 6038 const bool addRays, 6039 const bool storeViewCells) 6040 { 6041 ViewCellContainer viewcells; 6042 6043 ray.mPvsContribution = 0; 6044 ray.mRelativePvsContribution = 0.0f; 6049 float 6050 VspOspViewCellsManager::ComputeSampleContribution(VssRay &ray, 6051 const bool addRays, 6052 const bool storeViewCells) 6053 { 6054 ray.mPvsContribution = 0; 6055 ray.mRelativePvsContribution = 0.0f; 6056 6057 if (ray.mTerminationObject==NULL) 6058 return 0.0f; 6059 6060 ViewCellContainer viewcells; 6061 6045 6062 6046 6063 static Ray hray; … … 6075 6092 6076 6093 Intersectable *terminationObj = GetIntersectable(ray, true); 6094 6095 #if SAMPLE_ORIGIN_OBJECTS 6077 6096 Intersectable *originObj = GetIntersectable(ray, false); 6097 #endif 6078 6098 6079 6099 for (; it != viewcells.end(); ++ it) … … 6087 6107 if (terminationObj) 6088 6108 { 6089 6090 6091 terminationObj, ray.mPdf, contribution))6109 // todo: maybe not correct for kd node pvs 6110 if (viewcell->GetPvs().GetSampleContribution( 6111 terminationObj, ray.mPdf, contribution)) 6092 6112 { 6093 6113 ++ ray.mPvsContribution; 6094 6114 } 6095 6096 6115 6116 ray.mRelativePvsContribution += contribution; 6097 6117 } 6098 6118 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1845 r1867 307 307 */ 308 308 virtual bool GetViewPoint(Vector3 &viewPoint) const; 309 310 virtual bool GetViewPoint(Vector3 &viewPoint, const Vector3 ¶ms) const; 309 311 310 312 /** Returns true if this view point is in the valid view space. -
GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h
r1824 r1867 14 14 class KdNode; 15 15 16 #define ABS_CONTRIBUTION_WEIGHT 0. 5f16 #define ABS_CONTRIBUTION_WEIGHT 0.9f 17 17 18 18 class VssRay { … … 30 30 }; 31 31 32 // Id of the generating SimpleRay 33 int mGeneratingRayId; 34 32 35 static int mailID; 33 36 int mMailbox; … … 69 72 // sum of relative ray contributions per object 70 73 float mRelativePvsContribution; 71 72 74 73 75 // weighted contribution to the pvs (based on the pass the ray was casted at) -
GTP/trunk/Lib/Vis/Preprocessing/src/default.env
r1824 r1867 25 25 #filename ../data/soda/soda.dat 26 26 #filename ../data/test1/test2.x3d 27 # filename ../data/soda/soda5.dat27 # filename ../data/soda/soda5.dat 28 28 #filename ../data/PowerPlant/ppsection1/part_a/g0.ply 29 29 #filename ../data/PowerPlant/ppsection1/part_b/g0.ply … … 53 53 pvsRenderErrorSamples 0 54 54 # pvsRenderErrorSamples 1000 55 quitOnFinish true55 quitOnFinish false 56 56 computeVisibility true 57 57 … … 90 90 RssPreprocessor { 91 91 samplesPerPass 1000 92 initialSamples 300000093 vssSamples 10000000094 vssSamplesPerPass 500000092 initialSamples 1000000 93 vssSamples 20000000 94 vssSamplesPerPass 1000000 95 95 useImportanceSampling true 96 96 -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r1842 r1867 48 48 using namespace GtpVisibilityPreprocessor; 49 49 50 Preprocessor *preprocessor = NULL;51 50 GlRendererWidget *rendererWidget = NULL; 52 51 … … 266 265 PreprocessorThread *pt; 267 266 268 269 267 #if USE_QT 270 268 // create a qt application first (must be created before any opengl widget ...) … … 280 278 #endif 281 279 280 preprocessor->SetThread(pt); 281 282 282 bool guiSupported = false; 283 283 -
GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro
r1832 r1867 107 107 InternalRayCaster.cpp IntelRayCaster.cpp \ 108 108 RayCaster.cpp PreprocessorFactory.cpp GvsPreprocessor.cpp \ 109 Trackball.cpp ObjExporter.cpp SubdivisionCandidate.cpp QtGlViewer.cpp 109 Trackball.cpp ObjExporter.cpp SubdivisionCandidate.cpp QtGlViewer.cpp Mailable.cpp 110 110 111 111 -
GTP/trunk/Lib/Vis/Preprocessing/src/run_test2
r1829 r1867 41 41 42 42 $COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 43 -rss_use_importance+ -rss_u pdate_subdivision+ -rss_split=hybrid -hybrid_depth=10 \43 -rss_use_importance+ -rss_use_rss_tree+ -rss_update_subdivision+ -rss_split=hybrid -hybrid_depth=10 \ 44 44 -view_cells_filter_max_size=1 -preprocessor_stats=$PREFIX-i-combined-update-ccb12-nn.log \ 45 45 -preprocessor_histogram_file=$PREFIX-i-combined-update-ccb12-nn.hlog … … 60 60 61 61 62 #$COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \63 #-rss_use_importance+ -rss_use_rss_tree- -view_cells_filter_max_size=1 \64 # -preprocessor_stats=$PREFIX-i-mixed-b1.log \65 # -preprocessor_histogram_file=$PREFIX-i-mixed-b1.hlog62 $COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 63 -rss_use_importance+ -rss_use_rss_tree- -view_cells_filter_max_size=1 \ 64 -preprocessor_stats=$PREFIX-i-mixed-b1-n.log \ 65 -preprocessor_histogram_file=$PREFIX-i-mixed-b1-n.hlog 66 66 67 67
Note: See TracChangeset
for help on using the changeset viewer.