Changeset 2582 for GTP/trunk/Lib/Vis
- Timestamp:
- 01/09/08 11:14:26 (17 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 26 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
r2575 r2582 1552 1552 // from the sphere center 1553 1553 1554 const float *minp = &(mMin [0]);1555 const float *maxp = &(mMax [0]);1556 const float *pcenter = &(point [0]);1554 const float *minp = &(mMin.x); 1555 const float *maxp = &(mMax.x); 1556 const float *pcenter = &(point.x); 1557 1557 1558 1558 // for x-axis -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r2575 r2582 2978 2978 result = false; 2979 2979 } 2980 delete envFilename;2980 delete [] envFilename; 2981 2981 2982 2982 // Parse the command line; options given on the command line subsume -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
r2575 r2582 376 376 Vector3 up(0,1,0); 377 377 378 if ( abs(DotProd(mViewDirection, up)) > 0.99f)379 378 if (fabs(DotProd(mViewDirection, up)) > 0.99f) 379 up = Vector3(1, 0, 0); 380 380 381 381 glLoadIdentity(); -
GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp
r2575 r2582 60 60 } 61 61 62 63 int IntelRayCaster::CastRay( 64 const SimpleRay &simpleRay, 65 VssRayContainer &vssRays, 66 const AxisAlignedBox3 &box, 67 const bool castDoubleRay, 68 const bool pruneInvalidRays 69 ) 62 // Using packet of 4 rays supposing that these are coherent 63 // We give a box to which each ray is clipped to before the 64 // ray shooting is computed ! 65 void IntelRayCaster::CastRaysPacket4(const Vector3 &minBox, 66 const Vector3 &maxBox, 67 const Vector3 origin4[], 68 const Vector3 dirs4[], 69 int result4[], 70 float dist4[]) 71 { 72 for (int i = 0; i < 4; i++) { 73 mlrtaStoreRayASEye4(&origin4[i].x, &dirs4[i].x, i); 74 } 75 76 mlrtaTraverseGroupASEye4(&minBox.x, &maxBox.x, result4, dist4); 77 return; 78 } 79 80 81 82 int IntelRayCaster::CastRay(const SimpleRay &simpleRay, 83 VssRayContainer &vssRays, 84 const AxisAlignedBox3 &box, 85 const bool castDoubleRay, 86 const bool pruneInvalidRays 87 ) 70 88 { 71 89 //cout << "intel ray" << endl; -
GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.h
r2176 r2582 38 38 } 39 39 40 // Using packet of 4 rays supposing that these are coherent 41 // We give a box to which each ray is clipped to before the 42 // ray shooting is computed ! 43 virtual void CastRaysPacket4(const Vector3 &minBox, 44 const Vector3 &maxBox, 45 const Vector3 origin4[], 46 const Vector3 direction4[], 47 int result4[], 48 float dist4[]); 49 40 50 virtual int CastRay(const SimpleRay &simpleRay, 41 51 VssRayContainer &vssRays, -
GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.cpp
r2575 r2582 1 1 #include "Intersectable.h" 2 2 #include "SimpleRay.h" 3 //#include "ktbconf.h"4 3 5 4 using namespace std; … … 8 7 #define ALIGN16 __declspec(align(16)) 9 8 #else 10 ALIGN16 GALIGN16 9 #ifdef USE_HAVRAN_RAYCASTER 10 #include "ktbconf.h" 11 #define ALIGN16 GALIGN16 12 #else 13 #define ALIGN16 14 #endif 11 15 #endif 12 16 -
GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
r2575 r2582 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (2.00a) (Qt 4.1.2) on: ?t 3. I 15:47:3120083 # Generated by qmake (2.00a) (Qt 4.1.2) on: st 9. I 11:11:49 2008 4 4 # Project: preprocessor.pro 5 5 # Template: app -
GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp
r2574 r2582 27 27 //#define Q_SEARCH_STEPS 3 28 28 29 #define SORT_RAY_ENTRIES 1 29 // VH - commened out !!!!! 8/1/2008 30 // #define SORT_RAY_ENTRIES 1 30 31 31 32 // use avg ray contribution as importance … … 367 368 static Vector3 dirs[packetSize]; 368 369 static Vector3 shifts[packetSize]; 370 static Vector3 origs[packetSize]; 369 371 // now find the silhouette along the line 370 372 int i; … … 378 380 shifts[i] = r*line; 379 381 dirs[i] = Normalize(newPivot + shifts[i] - termination ); 380 mlrtaStoreRayASEye4(&termination.x, 381 &dirs[i].x, 382 i); 383 } 384 385 mlrtaTraverseGroupASEye4(&box.Min().x, 386 &box.Max().x, 387 hit_triangles, 388 dist); 382 origs[i] = termination; 383 // mlrtaStoreRayASEye4(&termination.x, &dirs[i].x, i); 384 } 385 386 // mlrtaTraverseGroupASEye4(&box.Min().x, &box.Max().x, hit_triangles, dist); 387 assert(preprocessor->mRayCaster); 388 preprocessor->mRayCaster->CastRaysPacket4(box.Min(), 389 box.Max(), 390 origs, dirs, 391 hit_triangles, 392 dist); 389 393 390 394 for (i=0; i < packetSize; i++) { 391 395 if (hit_triangles[i] == -1) { 392 393 396 // break on first passing ray 397 break; 394 398 } 395 399 } … … 473 477 static Vector3 dirs[packetSize]; 474 478 static Vector3 shifts[packetSize]; 479 static Vector3 origs[packetSize]; 475 480 // mutate the 476 481 float alpha = RandomValue(0.0f, Real(2.0*M_PI)); … … 491 496 shifts[i] = r*line; 492 497 dirs[i] = Normalize(ray.mTermination + shifts[i] - origin ); 493 mlrtaStoreRayASEye4(&origin.x, 494 &dirs[i].x, 495 i); 496 } 497 498 mlrtaTraverseGroupASEye4(&box.Min().x, 499 &box.Max().x, 500 hit_triangles, 501 dist); 498 origs[i] = origin; 499 //mlrtaStoreRayASEye4(&origin.x, &dirs[i].x, i); 500 } 501 502 // mlrtaTraverseGroupASEye4(&box.Min().x, &box.Max().x, hit_triangles, dist); 503 assert(preprocessor->mRayCaster); 504 preprocessor->mRayCaster->CastRaysPacket4(box.Min(), box.Max(), 505 origs, dirs, hit_triangles, dist); 502 506 503 507 for (i=0; i < packetSize; i++) { -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r2580 r2582 589 589 590 590 mKdTree->Construct(); 591 sceneBox = mKdTree->GetBox(); 591 592 592 593 cout << "finished kd tree construction in " << TimeDiff(startTime, GetTime()) * 1e-3 … … 1103 1104 1104 1105 bool Preprocessor::InitRayCast(const string &externKdTree, 1105 1106 const string &internKdTree) 1106 1107 { 1107 1108 // always try to load the kd tree … … 1220 1221 1221 1222 const long t1 = GetTime(); 1222 1223 if (rays.size() > 10000) 1224 { 1225 1226 mRayCaster->SortRays(rays); 1223 1224 // !!!!!!!!!!!!!!!! VH no sorting 1225 if (0 && 1226 rays.size() > 10000) 1227 { 1228 1229 mRayCaster->SortRays(rays); 1227 1230 cout<<"Rays sorted in "<<TimeDiff(t1, GetTime())<<" ms."<<endl; 1228 1231 } … … 1260 1263 #endif 1261 1264 } 1262 cerr<<"Deternmining PVS objects"<<endl;1265 // cerr<<"Determining PVS objects"<<endl; 1263 1266 DeterminePvsObjects(vssRays); 1264 1267 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r2580 r2582 208 208 /// kD-tree organizing the scene graph (occluders + occludees) + viewcells 209 209 KdTree *mKdTree; 210 AxisAlignedBox3 sceneBox; 210 211 /// View space partition bsp tree 211 212 VspBspTree *mVspBspTree; -
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
r2570 r2582 5 5 #include "common.h" 6 6 #include <math.h> 7 //#include "PvsBB.h" 7 8 #include "PvsBase.h" 8 9 #include "ObjectPvs.h" 9 10 10 11 11 12 namespace GtpVisibilityPreprocessor { 12 13 13 14 /** Iterator over the pvs. 15 */ 16 template<typename T, typename S> 17 class PvsIterator 18 { 19 public: 20 PvsIterator<T, S>(){} 21 PvsIterator<T, S>(const typename vector<PvsEntry<T, S> >::const_iterator &itCurrent, 22 const typename vector<PvsEntry<T, S> >::const_iterator &itEnd): 23 mItCurrent(itCurrent), mItEnd(itEnd) 24 { 25 } 26 27 inline bool HasMoreEntries() const { return (mItCurrent != mItEnd); } 28 29 inline T Next(S &pdf) { 30 pdf = (*mItCurrent).mData; 31 return (*(mItCurrent ++)).mObject; 32 } 33 34 inline T Next() { return (*(mItCurrent ++)).mObject; } 35 36 37 private: 38 39 typename vector<PvsEntry<T, S> >::const_iterator mItCurrent; 40 typename vector<PvsEntry<T, S> >::const_iterator mItEnd; 41 }; 42 43 44 struct VerbosePvsStats 45 { 46 VerbosePvsStats(): mDistanceWeightedTriangles(0), mDistanceWeightedPvs(0), mWeightedTriangles(0) 47 {} 48 49 float mDistanceWeightedTriangles; 50 float mDistanceWeightedPvs; 51 float mWeightedTriangles; 52 }; 53 54 55 /** Template class representing the Potentially Visible Set (PVS) 56 mainly from a view cell, but also e.g., from objects. 57 */ 58 template<typename T, typename S> 59 class VerbosePvs 60 { 61 template<typename T, typename S> friend class PvsIterator; 62 63 public: 64 65 VerbosePvs(): mSamples(0), mEntries(), mLastSorted(0), mQueriesSinceSort(0) 66 {} 67 68 /** creates pvs and initializes it with the given entries. 69 Assumes that entries are sorted. 70 */ 71 VerbosePvs(const vector<PvsEntry<T, S> > &samples); 72 virtual ~VerbosePvs() {}; 73 74 /** Compresses PVS lossless or lossy. 75 */ 76 int Compress() { return 0; } 77 78 inline int GetSize() const { return (int)mEntries.size(); } 79 80 inline bool Empty() const { return mEntries.empty(); } 81 82 inline void Reserve(const int n) { mEntries.reserve(n); } 83 /** Normalize the visibility of entries in order to get 84 comparable results. 85 */ 86 void NormalizeMaximum(); 87 /** Merges pvs of a into this pvs. 88 Warning: very slow! 89 */ 90 void MergeInPlace(const VerbosePvs<T, S> &a); 91 /** Difference of pvs to pvs b. 92 @returns number of different entries. 93 */ 94 int Diff(const VerbosePvs<T, S> &b); 95 /** Finds sample in PVS. 96 @param checkDirty if dirty part of the pvs should be checked for entry 97 (warning: linear runtime in dirty part) 98 @returns iterator on the sample if found, else the place where 99 it would be added in the sorted vector. 100 */ 101 bool Find(T sample, 102 typename vector<PvsEntry<T, S> >::iterator &it, 103 const bool checkDirty = true); 104 105 bool GetSampleContribution(T sample, const float pdf, float &contribution); 106 /** Adds sample to PVS. 107 @returns contribution of sample (0 or 1) 108 */ 109 float AddSample(T sample, const float pdf); 110 /** Adds sample to PVS without checking for presence of the sample 111 warning: pvs remains unsorted! 112 */ 113 void AddSampleDirty(T sample, const float pdf); 114 /** Adds sample dirty (on the end of the vector) but 115 first checks if sample is already in clean part of the pvs. 116 */ 117 bool AddSampleDirtyCheck(T sample, const float pdf); 118 /** Sort pvs entries. This should always be called after a 119 sequence of AddSampleDirty calls 120 */ 121 void Sort(); 122 /** Sort pvs entries assume that the pvs contains unique entries 123 */ 124 void SimpleSort(); 125 /** Adds sample to PVS. 126 @returns PvsData 127 */ 128 typename std::vector<PvsEntry<T, S> >::iterator 129 AddSample2(T sample, const float pdf); 130 /** Subtracts one pvs from another one. 131 WARNING: could contains bugs 132 @returns new pvs size 133 */ 134 int SubtractPvs(const VerbosePvs<T, S> &pvs); 135 136 /** Returns PVS data, i.e., how often it was seen from the view cell, 137 and the object itsef. 138 */ 139 void GetData(const int index, T &entry, S &data); 140 141 /** Collects the PVS entries and returns them in the vector. 142 */ 143 void CollectEntries(std::vector<T> &entries); 144 145 /** Removes sample from PVS if reference count is zero. 146 @param visibleSamples number of references to be removed 147 */ 148 bool RemoveSample(T sample, const float pdf); 149 150 /** Compute continuous PVS difference 151 */ 152 void ComputeContinuousPvsDifference(VerbosePvs<T, S> &pvs, 153 float &pvsReduction, 154 float &pvsEnlargement); 155 156 /** Clears the pvs. 157 */ 158 void Clear(const bool trim = true); 159 /** Trim the vector containing the pvs. 160 */ 161 void Trim(); 162 163 static int GetEntrySizeByte(); 164 static float GetEntrySize(); 165 166 /** Compute continuous PVS difference 167 */ 168 float GetPvsHomogenity(VerbosePvs<T, S> &pvs); 169 170 static void Merge(VerbosePvs<T, S> &mergedPvs, 171 const VerbosePvs<T, S> &a, 172 const VerbosePvs<T, S> &b); 173 174 inline int GetSamples() const { return mSamples; } 175 176 /** If there is an unsorted part in the pvs. 177 */ 178 bool IsDirty() const { return mLastSorted < mEntries.size(); } 179 180 /** If this pvs requires a resort to stay efficient. 181 */ 182 bool RequiresResort() const 183 { 184 // the last part should not be more than log of the sorted part. this 185 // way we can achieve logarithmic behaviour for insertion and find 186 const int n = mEntries.size(); 187 const int dirtySize = n - mLastSorted; 188 189 const double LOG2E = 1.442695040f; 190 191 const float logN = log((float)max(1, n))/LOG2E; 192 const float logS = log((float)max(1, mLastSorted))/LOG2E; 193 const float logD = log((float)max(1, dirtySize))/LOG2E; 194 195 if (8*(n + 2*dirtySize*logD) < 196 mQueriesSinceSort*((mLastSorted*logS + dirtySize*dirtySize/2)/n - logN)) 197 { 198 // cout<<"Q="<<mQueriesSinceSort<<" N="<<n<<" D="<<dirtySize<<endl; 199 return true; 200 } 201 202 return false; 203 } 204 205 /** If this pvs requires a resort to stay efficient. 206 */ 207 bool RequiresResortLog() const 208 { 209 // the last part should not be more than log of the sorted part. this 210 // way we can achieve logarithmic behaviour for insertion and find 211 const int dirtySize = (int)mEntries.size() - mLastSorted; 212 return dirtySize > 4 * (int)(log((double)mEntries.size()) / log(2.0)); 213 } 214 215 inline int GetLastSorted() const { return mLastSorted; } 216 217 typename PvsIterator<T, S> GetIterator() const; 218 219 VerbosePvsStats mStats; 220 221 protected: 222 223 /** Merge pvs 1 from begin iterator to end iterator with 224 pvs 2 from begin iterator to end iterator. 225 */ 226 static void Merge(VerbosePvs<T, S> &mergedPvs, 227 const typename std::vector<PvsEntry<T, S> >::const_iterator &aBegin, 228 const typename std::vector<PvsEntry<T, S> >::const_iterator &aEnd, 229 const typename std::vector<PvsEntry<T, S> >::const_iterator &bBegin, 230 const typename std::vector<PvsEntry<T, S> >::const_iterator &bEnd, 231 const int aSamples, 232 const int bSamples); 233 234 235 ////////////////////////////// 236 237 /// vector of PVS entries 238 vector<PvsEntry<T, S> > mEntries; 239 240 /// Number of samples used to create the PVS 241 int mSamples; 242 243 /// Last sorted entry in the pvs (important for find and merge) 244 int mLastSorted; 245 246 int mQueriesSinceSort; 247 }; 248 14 inline int operator< (PvsEntry<Intersectable*, PvsData> const &a, 15 PvsEntry<Intersectable*, PvsData> const &b) 16 { 17 return a.mObject < b.mObject; 18 } 249 19 250 20 template <typename T, typename S> … … 261 31 void VerbosePvs<T, S>::Sort() 262 32 { 263 vector<PvsEntry<T, S> >::iterator it = mEntries.begin() + mLastSorted;264 vector<PvsEntry<T, S> >::iterator it_end = mEntries.end();33 typename vector<PvsEntry<T, S> >::iterator it = mEntries.begin() + mLastSorted; 34 typename vector<PvsEntry<T, S> >::iterator it_end = mEntries.end(); 265 35 266 36 // throw out double entries 267 std::vector<PvsEntry<T, S> >::iterator newEnd = unique(it, it_end);37 typename std::vector<PvsEntry<T, S> >::iterator newEnd = unique(it, it_end); 268 38 sort(it, newEnd); 269 39 … … 287 57 { 288 58 // sort(mEntries.begin(), mEntries.end()); 289 59 typename vector<PvsEntry<T, S> >::iterator it = mEntries.begin() + mLastSorted; 290 60 291 61 sort(it, mEntries.end()); … … 312 82 313 83 // Uses sum of log differences, which corresponds to entropy 314 vector<PvsEntry<T, S> >::iterator it;84 typename vector<PvsEntry<T, S> >::iterator it; 315 85 316 86 for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it) … … 319 89 float aSumPdf = 0.0f; 320 90 321 vector<PvsEntry<T, S> >::iterator oit;91 typename vector<PvsEntry<T, S> >::iterator oit; 322 92 const bool entryFound = Find((*it).mObject, oit); 323 93 … … 361 131 else 362 132 { 363 133 typename vector<PvsEntry<T, S> >::iterator oit; 364 134 365 135 const bool entryFound = b.Find((*it).mObject, oit); … … 391 161 int dif = 0; 392 162 393 std::vector<PvsEntry<T, S> >::const_iterator it;163 typename std::vector<PvsEntry<T, S> >::const_iterator it; 394 164 395 165 for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it) 396 166 { 397 167 typename vector<PvsEntry<T, S> >::iterator bit; 398 168 const bool entryFound = Find((*it).first, bit); 399 169 … … 436 206 const VerbosePvs<T, S> &b) 437 207 { 438 208 typename std::vector<PvsEntry<T, S> >::const_iterator ait = 439 209 a.mEntries.begin(), ait_end = a.mEntries.end(); 440 std::vector<PvsEntry<T, S> >::const_iterator bit =210 typename std::vector<PvsEntry<T, S> >::const_iterator bit = 441 211 b.mEntries.begin(), bit_end = b.mEntries.end(); 442 212 … … 458 228 const int bSamples) 459 229 { 460 461 std::vector<PvsEntry<T, S> >::const_iterator bit = bBegin;230 typename std::vector<PvsEntry<T, S> >::const_iterator ait = aBegin; 231 typename std::vector<PvsEntry<T, S> >::const_iterator bit = bBegin; 462 232 463 233 for (; (ait != aEnd); ++ ait) … … 525 295 template <typename T, typename S> 526 296 bool VerbosePvs<T, S>::Find(T sample, 527 528 297 typename vector<PvsEntry<T, S> >::iterator &it, 298 const bool checkDirty) 529 299 { 530 300 bool found = false; … … 533 303 534 304 // only check clean part 535 vector<PvsEntry<T, S> >::iterator sorted_end = mEntries.begin() + mLastSorted;305 typename vector<PvsEntry<T, S> >::iterator sorted_end = mEntries.begin() + mLastSorted; 536 306 mQueriesSinceSort++; 537 307 … … 545 315 if (!found && checkDirty) 546 316 { 547 317 typename vector<PvsEntry<T, S> >::iterator dit, dit_end = mEntries.end(); 548 318 549 319 for (dit = sorted_end; (dit != dit_end) && ((*dit).mObject != sample); ++ dit); … … 563 333 void VerbosePvs<T, S>::GetData(const int index, T &entry, S &data) 564 334 { 565 335 typename std::vector<PvsEntry<T, S> >::iterator i = mEntries.begin(); 566 336 for (int k = 0; k != index && i != mEntries.end(); ++ i, ++ k); 567 337 … … 576 346 ++ mSamples; 577 347 578 vector<PvsEntry<T, S> >::iterator it;348 typename vector<PvsEntry<T, S> >::iterator it; 579 349 const bool entryFound = Find(sample, it); 580 350 … … 609 379 ++ mSamples; 610 380 611 vector<PvsEntry<T, S> >::iterator it;381 typename vector<PvsEntry<T, S> >::iterator it; 612 382 const bool entryFound = Find(sample, it); 613 383 … … 633 403 ++ mSamples; 634 404 635 vector<PvsEntry<T, S> >::iterator it;405 typename vector<PvsEntry<T, S> >::iterator it; 636 406 const bool entryFound = Find(sample, it); 637 407 … … 656 426 float &contribution) 657 427 { 658 428 typename vector<PvsEntry<T, S> >::iterator it; 659 429 const bool entryFound = Find(sample, it); 660 430 … … 678 448 -- mSamples; 679 449 680 vector<PvsEntry<T, S> >::iterator it;450 typename vector<PvsEntry<T, S> >::iterator it; 681 451 const bool entryFound = Find(sample, it); 682 452 … … 703 473 const int samples = mSamples - pvs.mSamples; 704 474 705 std::vector<PvsEntry<T, S> >::706 475 typename std::vector<PvsEntry<T, S> >:: 476 const_iterator it, it_end = pvs.mEntries.end(); 707 477 708 478 // output PVS of view cell … … 719 489 void VerbosePvs<T, S>::CollectEntries(std::vector<T> &entries) 720 490 { 721 722 491 typename std::vector<PvsEntry<T, S> >:: 492 const_iterator it, it_end = mEntries.end(); 723 493 724 494 // output PVS of view cell … … 731 501 void VerbosePvs<T, S>::NormalizeMaximum() 732 502 { 733 std::vector<PvsEntry<T, S> >::503 typename std::vector<PvsEntry<T, S> >:: 734 504 const_iterator it, it_end = mEntries.end(); 735 505 … … 739 509 for (it = mEntries.begin(); it != it_end; ++ it) { 740 510 float sum = (*it)->second.sumPdf; 741 if (sum > max Sum)742 max Sum = sum;743 } 744 745 max Sum = 1.0f / maxSum;511 if (sum > maxPdfSum) 512 maxPdfSum = sum; 513 } 514 515 maxPdfSum = 1.0f / maxPdfSum; 746 516 747 517 for (it = mEntries.begin(); it != it_end; ++ it) { 748 (*it)->second.sumPdf *= max Sum;518 (*it)->second.sumPdf *= maxPdfSum; 749 519 } 750 520 } … … 776 546 777 547 template <typename T, typename S> 778 typenamePvsIterator<T, S> VerbosePvs<T, S>::GetIterator() const548 PvsIterator<T, S> VerbosePvs<T, S>::GetIterator() const 779 549 { 780 550 PvsIterator<T, S> pit(mEntries.begin(), mEntries.end()); -
GTP/trunk/Lib/Vis/Preprocessing/src/PvsBase.h
r2530 r2582 6 6 7 7 8 9 8 namespace GtpVisibilityPreprocessor { 10 11 9 12 10 /** Information stored with a PVS entry. Consists of the number 13 11 the object was seen from the view cell. 14 12 */ 13 struct PvsData 14 { 15 public: 16 PvsData() {} 17 PvsData(const float sumPdf): 18 mSumPdf(sumPdf) {} 19 20 // $$JB in order to return meaningfull values 21 // it assumes that the sum pdf has been normalized somehow!!! 22 inline float GetVisibility() { return mSumPdf; } 23 24 /// sum of probability density of visible sample rays 25 float mSumPdf; 26 }; 27 28 29 class MailablePvsData 30 { 31 public: 32 // sum of probability density of visible sample rays 33 float mSumPdf; 34 int mCounter; 35 36 MailablePvsData() {} 37 MailablePvsData(const float sumPdf): 38 mSumPdf(sumPdf) {} 39 40 // $$JB in order to return meaningfull values 41 // it assumes that the sum pdf has been normalized somehow!!! 42 inline float GetVisibility() { return mSumPdf; } 43 44 45 /////////////// 46 // Mailing stuff 47 48 // last mail id -> warning not thread safe! 49 // both mailId and mailbox should be unique for each thread!!! 50 static int sMailId; 51 static int sReservedMailboxes; 52 53 static void NewMail(const int reserve = 1) 54 { 55 sMailId += sReservedMailboxes; 56 sReservedMailboxes = reserve; 57 } 58 59 void Mail() { mMailbox = sMailId; } 60 bool Mailed() const { return mMailbox == sMailId; } 61 62 void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 63 bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 64 65 int IncMail() { return ++ mMailbox - sMailId; } 66 67 ////////////////////////////////////////// 68 69 protected: 70 71 int mMailbox; 72 73 }; 74 75 76 /** Information stored with a PVS entry. Consists of the number 77 the object was seen from the view cell. 78 */ 15 79 template<typename T, typename S> 16 80 struct PvsEntry … … 25 89 S mData; 26 90 27 28 29 30 91 //template<typename T, typename S> 92 friend int operator< (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b); 93 //template<typename T, typename S> 94 friend int operator== (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b); 31 95 }; 32 96 … … 60 124 } 61 125 62 /** Information stored with a PVS entry. Consists of the number 63 the object was seen from the view cell.126 127 /** Iterator over the pvs. 64 128 */ 65 struct PvsData 66 { 67 public: 68 PvsData() {} 69 PvsData(const float sumPdf): 70 mSumPdf(sumPdf) {} 71 72 // $$JB in order to return meaningfull values 73 // it assumes that the sum pdf has been normalized somehow!!! 74 inline float GetVisibility() { return mSumPdf; } 75 76 /// sum of probability density of visible sample rays 77 float mSumPdf; 78 }; 79 80 81 class MailablePvsData 82 { 83 public: 84 // sum of probability density of visible sample rays 85 float mSumPdf; 86 int mCounter; 87 88 MailablePvsData() {} 89 MailablePvsData(const float sumPdf): 90 mSumPdf(sumPdf) {} 91 92 // $$JB in order to return meaningfull values 93 // it assumes that the sum pdf has been normalized somehow!!! 94 inline float GetVisibility() { return mSumPdf; } 95 96 97 /////////////// 98 // Mailing stuff 99 100 // last mail id -> warning not thread safe! 101 // both mailId and mailbox should be unique for each thread!!! 102 static int sMailId; 103 static int sReservedMailboxes; 104 105 static void NewMail(const int reserve = 1) 129 template<typename T, typename S> 130 class PvsIterator 131 { 132 public: 133 PvsIterator<T, S>(){} 134 PvsIterator<T, S>(const typename vector<PvsEntry<T, S> >::const_iterator &itCurrent, 135 const typename vector<PvsEntry<T, S> >::const_iterator &itEnd): 136 mItCurrent(itCurrent), mItEnd(itEnd) 106 137 { 107 sMailId += sReservedMailboxes; 108 sReservedMailboxes = reserve; 109 } 110 111 void Mail() { mMailbox = sMailId; } 112 bool Mailed() const { return mMailbox == sMailId; } 113 114 void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 115 bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 116 117 int IncMail() { return ++ mMailbox - sMailId; } 118 119 ////////////////////////////////////////// 138 } 139 140 inline bool HasMoreEntries() const { return (mItCurrent != mItEnd); } 141 142 inline T Next(S &pdf) { 143 pdf = (*mItCurrent).mData; 144 return (*(mItCurrent ++)).mObject; 145 } 146 147 inline T Next() { return (*(mItCurrent ++)).mObject; } 148 149 150 private: 151 152 typename vector<PvsEntry<T, S> >::const_iterator mItCurrent; 153 typename vector<PvsEntry<T, S> >::const_iterator mItEnd; 154 }; 155 156 157 158 159 struct VerbosePvsStats 160 { 161 VerbosePvsStats(): mDistanceWeightedTriangles(0), mDistanceWeightedPvs(0), mWeightedTriangles(0) 162 {} 163 164 float mDistanceWeightedTriangles; 165 float mDistanceWeightedPvs; 166 float mWeightedTriangles; 167 }; 168 169 170 /** Template class representing the Potentially Visible Set (PVS) 171 mainly from a view cell, but also e.g., from objects. 172 */ 173 template<typename T, typename S> 174 class VerbosePvs 175 { 176 template<typename T1, typename S1> friend class PvsIterator; 177 178 public: 179 180 VerbosePvs(): mSamples(0), mEntries(), mLastSorted(0), mQueriesSinceSort(0) 181 {} 182 183 /** creates pvs and initializes it with the given entries. 184 Assumes that entries are sorted. 185 */ 186 VerbosePvs(const vector<PvsEntry<T, S> > &samples); 187 virtual ~VerbosePvs() {}; 188 189 /** Compresses PVS lossless or lossy. 190 */ 191 int Compress() { return 0; } 192 193 inline int GetSize() const { return (int)mEntries.size(); } 194 195 inline bool Empty() const { return mEntries.empty(); } 196 197 inline void Reserve(const int n) { mEntries.reserve(n); } 198 /** Normalize the visibility of entries in order to get 199 comparable results. 200 */ 201 void NormalizeMaximum(); 202 /** Merges pvs of a into this pvs. 203 Warning: very slow! 204 */ 205 void MergeInPlace(const VerbosePvs<T, S> &a); 206 /** Difference of pvs to pvs b. 207 @returns number of different entries. 208 */ 209 int Diff(const VerbosePvs<T, S> &b); 210 /** Finds sample in PVS. 211 @param checkDirty if dirty part of the pvs should be checked for entry 212 (warning: linear runtime in dirty part) 213 @returns iterator on the sample if found, else the place where 214 it would be added in the sorted vector. 215 */ 216 bool Find(T sample, 217 typename vector<PvsEntry<T, S> >::iterator &it, 218 const bool checkDirty = true); 219 220 bool GetSampleContribution(T sample, const float pdf, float &contribution); 221 /** Adds sample to PVS. 222 @returns contribution of sample (0 or 1) 223 */ 224 float AddSample(T sample, const float pdf); 225 /** Adds sample to PVS without checking for presence of the sample 226 warning: pvs remains unsorted! 227 */ 228 void AddSampleDirty(T sample, const float pdf); 229 /** Adds sample dirty (on the end of the vector) but 230 first checks if sample is already in clean part of the pvs. 231 */ 232 bool AddSampleDirtyCheck(T sample, const float pdf); 233 /** Sort pvs entries. This should always be called after a 234 sequence of AddSampleDirty calls 235 */ 236 void Sort(); 237 /** Sort pvs entries assume that the pvs contains unique entries 238 */ 239 void SimpleSort(); 240 /** Adds sample to PVS. 241 @returns PvsData 242 */ 243 typename std::vector<PvsEntry<T, S> >::iterator 244 AddSample2(T sample, const float pdf); 245 /** Subtracts one pvs from another one. 246 WARNING: could contains bugs 247 @returns new pvs size 248 */ 249 int SubtractPvs(const VerbosePvs<T, S> &pvs); 250 251 /** Returns PVS data, i.e., how often it was seen from the view cell, 252 and the object itsef. 253 */ 254 void GetData(const int index, T &entry, S &data); 255 256 /** Collects the PVS entries and returns them in the vector. 257 */ 258 void CollectEntries(std::vector<T> &entries); 259 260 /** Removes sample from PVS if reference count is zero. 261 @param visibleSamples number of references to be removed 262 */ 263 bool RemoveSample(T sample, const float pdf); 264 265 /** Compute continuous PVS difference 266 */ 267 void ComputeContinuousPvsDifference(VerbosePvs<T, S> &pvs, 268 float &pvsReduction, 269 float &pvsEnlargement); 270 271 /** Clears the pvs. 272 */ 273 void Clear(const bool trim = true); 274 /** Trim the vector containing the pvs. 275 */ 276 void Trim(); 277 278 static int GetEntrySizeByte(); 279 static float GetEntrySize(); 280 281 /** Compute continuous PVS difference 282 */ 283 float GetPvsHomogenity(VerbosePvs<T, S> &pvs); 284 285 static void Merge(VerbosePvs<T, S> &mergedPvs, 286 const VerbosePvs<T, S> &a, 287 const VerbosePvs<T, S> &b); 288 289 inline int GetSamples() const { return mSamples; } 290 291 /** If there is an unsorted part in the pvs. 292 */ 293 bool IsDirty() const { return mLastSorted < mEntries.size(); } 294 295 /** If this pvs requires a resort to stay efficient. 296 */ 297 bool RequiresResort() const 298 { 299 // the last part should not be more than log of the sorted part. this 300 // way we can achieve logarithmic behaviour for insertion and find 301 const int n = mEntries.size(); 302 const int dirtySize = n - mLastSorted; 303 304 const double LOG2E = 1.442695040f; 305 306 const float logN = log((float) Max(1, n))/LOG2E; 307 const float logS = log((float) Max(1, mLastSorted))/LOG2E; 308 const float logD = log((float) Max(1, dirtySize))/LOG2E; 309 310 if (8*(n + 2*dirtySize*logD) < 311 mQueriesSinceSort*((mLastSorted*logS + dirtySize*dirtySize/2)/n - logN)) 312 { 313 // cout<<"Q="<<mQueriesSinceSort<<" N="<<n<<" D="<<dirtySize<<endl; 314 return true; 315 } 316 317 return false; 318 } 319 320 /** If this pvs requires a resort to stay efficient. 321 */ 322 bool RequiresResortLog() const 323 { 324 // the last part should not be more than log of the sorted part. this 325 // way we can achieve logarithmic behaviour for insertion and find 326 const int dirtySize = (int)mEntries.size() - mLastSorted; 327 return dirtySize > 4 * (int)(log((double)mEntries.size()) / log(2.0)); 328 } 329 330 inline int GetLastSorted() const { return mLastSorted; } 331 332 PvsIterator<T, S> GetIterator() const; 333 334 VerbosePvsStats mStats; 120 335 121 336 protected: 122 337 123 int mMailbox; 124 125 }; 338 /** Merge pvs 1 from begin iterator to end iterator with 339 pvs 2 from begin iterator to end iterator. 340 */ 341 static void Merge(VerbosePvs<T, S> &mergedPvs, 342 const typename std::vector<PvsEntry<T, S> >::const_iterator &aBegin, 343 const typename std::vector<PvsEntry<T, S> >::const_iterator &aEnd, 344 const typename std::vector<PvsEntry<T, S> >::const_iterator &bBegin, 345 const typename std::vector<PvsEntry<T, S> >::const_iterator &bEnd, 346 const int aSamples, 347 const int bSamples); 348 349 350 ////////////////////////////// 351 352 /// vector of PVS entries 353 vector<PvsEntry<T, S> > mEntries; 354 355 /// Number of samples used to create the PVS 356 int mSamples; 357 358 /// Last sorted entry in the pvs (important for find and merge) 359 int mLastSorted; 360 361 int mQueriesSinceSort; 362 }; 363 126 364 127 365 } -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h
r2575 r2582 67 67 const bool pruneInvalidRays = true); 68 68 69 // Using packet of 4 rays supposing that these are coherent 70 virtual void CastRaysPacket4(Vector3 origin4[], 71 Vector3 direction4[], 72 int result4[], 73 float dist4[]) { } 74 75 // Using packet of 4 rays supposing that these are coherent 76 // We give a box to which each ray is clipped to before the 77 // ray shooting is computed ! 78 virtual void CastRaysPacket4(const Vector3 &minBox, 79 const Vector3 &maxBox, 80 const Vector3 origin4[], 81 const Vector3 direction4[], 82 int result4[], 83 float dist4[]) { } 84 69 85 // Just for testing concept 70 86 virtual void CastRaysPacket2x2(RayPacket2x2 &raysPack, -
GTP/trunk/Lib/Vis/Preprocessing/src/ReverseGvs.cpp
r2546 r2582 361 361 static float dist[packetSize]; 362 362 static Vector3 dirs[packetSize]; 363 static Vector3 origs[packetSize]; 363 364 static Vector3 shifts[packetSize]; 364 365 // now find the silhouette along the line … … 373 374 shifts[i] = r*line; 374 375 dirs[i] = Normalize(newPivot + shifts[i] - termination ); 375 mlrtaStoreRayASEye4(&termination.x, 376 &dirs[i].x, 377 i); 378 } 379 380 mlrtaTraverseGroupASEye4(&box.Min().x, 381 &box.Max().x, 382 hit_triangles, 383 dist); 376 origs[i] = termination; 377 // mlrtaStoreRayASEye4(&termination.x, &dirs[i].x, i); 378 } 379 380 // mlrtaTraverseGroupASEye4(&box.Min().x, &box.Max().x, hit_triangles, dist); 381 assert(preprocessor->mRayCaster); 382 preprocessor->mRayCaster->CastRaysPacket4(&box.Min(), &box.Max(), origs, 383 dirs, hit_triangles, dist); 384 384 385 385 for (i=0; i < packetSize; i++) { … … 467 467 static float dist[packetSize]; 468 468 static Vector3 dirs[packetSize]; 469 static Vector3 origs[packetSize]; 469 470 static Vector3 shifts[packetSize]; 470 471 // mutate the … … 486 487 shifts[i] = r*line; 487 488 dirs[i] = Normalize(ray.mTermination + shifts[i] - origin ); 488 mlrtaStoreRayASEye4(&origin.x, 489 &dirs[i].x, 490 i); 491 } 492 493 mlrtaTraverseGroupASEye4(&box.Min().x, 494 &box.Max().x, 495 hit_triangles, 496 dist); 489 // mlrtaStoreRayASEye4(&origin.x, &dirs[i].x, i); 490 origs[i] = origin; 491 } 492 493 // mlrtaTraverseGroupASEye4(&box.Min().x, &box.Max().x, hit_triangles, dist); 494 assert(preprocessor->mRayCaster); 495 preprocessor->mRayCaster->CastRaysPacket4(box.Min(), box.Max(), origs, 496 dirs, hit_triangles, dist); 497 497 498 498 for (i=0; i < packetSize; i++) { -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r2580 r2582 227 227 r[2])); 228 228 229 direction = mPreprocessor. mKdTree->GetBox().GetRandomPoint(Vector3(r[3],229 direction = mPreprocessor.sceneBox.GetRandomPoint(Vector3(r[3], 230 230 r[4], 231 231 r[5]) -
GTP/trunk/Lib/Vis/Preprocessing/src/Vector3.h
r2575 r2582 41 41 42 42 // Functions to get at the std::vector components 43 float& operator[] ( int inx) {43 float& operator[] (const int inx) { 44 44 #ifndef __VECTOR_HACK 45 45 if (inx == 0) … … 60 60 #endif 61 61 62 const float & operator[] (int inx) const {62 const float &operator[] (const int inx) const { 63 63 #ifndef __VECTOR_HACK 64 64 if (inx == 0) … … 66 66 else 67 67 if (inx == 1) 68 return y;68 return y; 69 69 else 70 return z;70 return z; 71 71 #else 72 72 return *(&x+inx); -
GTP/trunk/Lib/Vis/Preprocessing/src/common.h
r2575 r2582 22 22 23 23 // use perftimer 24 #define PERFTIMER 24 // #define PERFTIMER 25 26 #define USE_HAVRAN_RAYCASTER 25 27 26 28 namespace GtpVisibilityPreprocessor { -
GTP/trunk/Lib/Vis/Preprocessing/src/default.env
r2574 r2582 52 52 useGlRenderer true 53 53 useGlDebugger false 54 # 0 = INTERNAL 1 = MLRT54 # 0 = INTERNAL 1 = MLRT 2 = HAVRAN 55 55 rayCastMethod 1 56 56 … … 280 280 281 281 # filename ../data/Arena/viewcells-5000.xml 282 filename ../data/Arena/viewcells-20000.xml282 # filename ../data/Arena/viewcells-20000.xml 283 283 284 284 # filename ../data/atlanta/atlanta_viewcells_large.x3d … … 511 511 } 512 512 513 # settings for havran ray caster 514 TestDoubleRays true 515 516 BSP { 517 termCrit auto 518 #termCrit auto2 519 #termCrit adhoc 520 # For Arena 521 #maxDepthAllowed 15 522 #maxListLength 8 523 # For Vienna 524 #maxDepthAllowed 22 525 #maxListLength 6 526 } 527 -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r2579 r2582 26 26 #include "GlobalLinesRenderer.h" 27 27 #include "RayCaster.h" 28 //#include " testrt.h"28 //#include "vlastimil/testrt.h" 29 29 30 30 #include "ViewCellsManager.h" … … 177 177 //be ignored. Use it as you will! 178 178 //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() { 179 180 //#define _CRT_SET 181 179 182 #ifdef _CRT_SET 180 183 _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF); … … 218 221 } 219 222 223 220 224 //Debug << "using pvs type " << PVS_TYPE << endl; 221 225 -
GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro
r2575 r2582 1 1 CONFIG += release 2 #CONFIG += debug 2 3 CONFIG += console warn_off thread mlrt qt 3 4 4 5 TEMPLATE = app 6 7 #CONFIG -= qt 5 8 6 9 TARGET = preprocessor … … 82 85 CONFIG(qt) { 83 86 win32:LIBS += cg.lib cgGL.lib 84 DEFINES += USE_QT87 #DEFINES += USE_QT 85 88 } 86 89 … … 117 120 Timer/BenchTimer.cpp Timer/merror.cpp \ 118 121 Intersectable.cpp TraversalTree.cpp ObjectPvs.cpp ObjectsParser.cpp \ 119 FilterBasedDistribution.cpp DifferenceSampling.cpp HavranRayCaster.cpp 122 FilterBasedDistribution.cpp DifferenceSampling.cpp HavranRayCaster.cpp \ 123 OcclusionQuery.cpp 120 124 121 125 122 126 SOURCES += BoostPreprocessorThread.cpp 123 127 128 INCLUDEPATH+=havran 129 SOURCES += havran/allocgo2.cpp havran/ktbai.cpp havran/ktbtrav.cpp \ 130 havran/ktb.cpp havran/ktball.cpp havran/sbbox.cpp \ 131 havran/ktb8b.cpp havran/ktbftrav.cpp havran/timer.cpp 132 133 124 134 CONFIG(qt) { 125 135 HEADERS += QtInterface/QtPreprocessorThread.h QtInterface/QtGlRenderer.h \ 126 136 QtInterface/QtGlViewer.h 127 SOURCES += OcclusionQuery.cppQtInterface/QtPreprocessorThread.cpp \137 SOURCES += QtInterface/QtPreprocessorThread.cpp \ 128 138 QtInterface/QtGlRenderer.cpp QtInterface/QtGlViewer.cpp 139 SOURCES += QtInterface/LogReader.cpp QtInterface/LogWriter.cpp 129 140 } else { 130 SOURCES += BoostPreprocessorThread.cpp141 #SOURCES += BoostPreprocessorThread.cpp 131 142 } 132 143 -
GTP/trunk/Lib/Vis/Preprocessing/src/run_test2
r2575 r2582 29 29 #VIEWCELLS=../data/test1/test-viewcells.xml 30 30 31 SCENE=../data/Arena/arena-high-lods.obj32 VIEWCELLS=../data/Arena/viewcells-5000.xml.gz31 #SCENE=../data/Arena/arena-high-lods.obj 32 #VIEWCELLS=../data/Arena/viewcells-5000.xml.gz 33 33 34 34 35 #SCENE=../data/vienna/vienna_cropped.obj36 #VIEWCELLS=../data/vienna/vienna_cropped-gradient-viewcells.xml.gz35 SCENE=../data/vienna/vienna_cropped.obj 36 VIEWCELLS=../data/vienna/vienna_cropped-gradient-viewcells.xml.gz 37 37 #VIEWCELLS=../data/vienna/vienna-sequential-30000-single-viewcell.xml 38 38
Note: See TracChangeset
for help on using the changeset viewer.