Changeset 2117 for GTP/trunk/Lib/Vis/Preprocessing/src/BitVectorPvs.h
- Timestamp:
- 02/15/07 13:19:17 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BitVectorPvs.h
r2116 r2117 13 13 typedef vector<bool> bit_vector; 14 14 15 15 16 /** Iterator over a bitvector pvs. 16 17 */ 17 #if 018 18 template<typename T, typename S> 19 19 class BitVectorPvsIterator … … 21 21 public: 22 22 23 HashPvsIterator<T, S>() {}24 25 HashPvsIterator<T, S>(const typename HASH_SET::const_iterator &itCurrent,26 const typename HASH_SET::const_iterator &itEnd):27 mItCurrent(it Current), mItEnd(itEnd)23 BitVectorPvsIterator<T, S>(const typename bit_vector::const_iterator &itBegin, 24 const typename bit_vector::const_iterator &itEnd 25 //,const int lastElement 26 ): 27 mItCurrent(itBegin), mItEnd(itEnd), mDistance(0)//, mLastElement 28 28 { 29 29 } … … 31 31 bool HasMoreEntries() const 32 32 { 33 return (mItCurrent != mItEnd); 34 } 35 36 PvsEntry<T, S> Next() 33 // find next element in bit vector 34 // warning: has to do traversal each time 35 typename bit_vector::const_iterator itNext = mItCurrent; 36 37 for (;(itNext != mItEnd) && !(*itNext); ++ itNext); 38 39 return (itNext != mItEnd); 40 } 41 42 T Next(S &pdf) 43 { 44 return Next(); 45 } 46 47 T Next() 37 48 { 38 49 // hack: create new pvs entry 39 return PvsEntry<T, S>(*(mItCurrent) ++, S(0.0)); 40 } 41 50 for (; !(*mItCurrent); ++ mItCurrent, ++ mDistance); 51 52 T sample = sObjects[mDistance]; 53 54 ++ mDistance; 55 ++ mItCurrent; 56 57 return sample; 58 } 59 60 61 // vector of objects corresponding to pvs entries 62 static vector<T> sObjects; 63 42 64 private: 43 typename HASH_SET::const_iterator mItCurrent; 44 typename HASH_SET::const_iterator mItEnd; 65 66 typename bit_vector::const_iterator mItCurrent; 67 //typename bit_vector::const_iterator mItNext; 68 typename bit_vector::const_iterator mItEnd; 69 70 // note: store distance explicitly because I 71 // don't know how efficient 72 // std::distance is on specialisation of vector<bool> 73 int mDistance; 45 74 }; 46 #endif 47 48 #if 0 75 76 49 77 /** Pvs implemented as bitvector 50 78 */ … … 56 84 public: 57 85 58 //HashPvs(): mEntries((Intersectable *)100) {}; 59 HashPvs() {}; 86 BitVectorPvs(); 60 87 //virtual ~HashPvs() {}; 61 88 … … 92 119 93 120 /** Finds sample in PVS. 94 @param checkDirty if dirty part of the pvs should be checked for entry 95 (warning: linear runtime in dirty part) 96 @returns iterator on the sample if found, else the place where 97 it would be added in the sorted vector. 98 */ 99 bool Find(T sample, typename HASH_SET::iterator &it); 100 101 typename HashPvsIterator<T, S> GetIterator() const; 121 */ 122 bool Find(T sample); 123 124 typename BitVectorPvsIterator<T, S> GetIterator() const; 102 125 103 126 /** Compute continuous PVS difference 104 127 */ 105 float GetPvsHomogenity( HashPvs<T, S> &pvs);106 107 static void Merge( HashPvs<T, S> &mergedPvs,108 const HashPvs<T, S> &a,109 const HashPvs<T, S> &b);128 float GetPvsHomogenity(BitVectorPvs<T, S> &pvs); 129 130 static void Merge(BitVectorPvs<T, S> &mergedPvs, 131 const BitVectorPvs<T, S> &a, 132 const BitVectorPvs<T, S> &b); 110 133 111 134 static int GetEntrySizeByte(); … … 121 144 } 122 145 123 void MergeInPlace(const HashPvs<T, S> &a)146 void MergeInPlace(const BitVectorPvs<T, S> &a) 124 147 { 125 148 cerr << "not implemented yet" << endl; … … 133 156 void Reserve(const int n) 134 157 { 158 mEntries.reserve(n); 159 } 160 161 /** Sort pvs entries assume that the pvs contains unique entries 162 */ 163 void SimpleSort() 164 { 135 165 // not necessary 136 166 } 137 167 138 /** Sort pvs entries assume that the pvs contains unique entries 139 */ 140 void SimpleSort() 141 { 142 // not necessary 143 } 144 145 int SubtractPvs(const HashPvs<T, S> &pvs) 168 int SubtractPvs(const BitVectorPvs<T, S> &pvs) 146 169 { 147 170 cerr << "not yet implemented" << endl; … … 151 174 /** Compute continuous PVS difference 152 175 */ 153 void ComputeContinuousPvsDifference( HashPvs<T, S> &pvs,176 void ComputeContinuousPvsDifference(BitVectorPvs<T, S> &pvs, 154 177 float &pvsReduction, 155 178 float &pvsEnlargement) … … 157 180 cerr << "not yet implemented" << endl; 158 181 } 182 183 184 static void SetPvsSize(const int pvsSize) { sPvsSize = pvsSize; }; 185 159 186 protected: 160 187 161 188 /// hash table of PVS entries 162 HASH_SETmEntries;189 bit_vector mEntries; 163 190 164 191 /// Number of samples used to create the PVS 165 192 int mSamples; 193 194 public: 195 static int sPvsSize; 166 196 }; 167 197 168 198 169 199 template <typename T, typename S> 170 bool HashPvs<T, S>::Find(T sample, typename HASH_SET::iterator &it) 171 { 172 it = mEntries.find(sample); 173 174 // already in map 175 return (it != mEntries.end()); 176 } 177 178 179 template <typename T, typename S> 180 int HashPvs<T, S>::GetSize() const 181 { 182 return (int)mEntries.size(); 183 } 184 185 186 template <typename T, typename S> 187 bool HashPvs<T, S>::Empty() const 188 { 189 return mEntries.empty(); 190 } 191 192 193 template <typename T, typename S> 194 float HashPvs<T, S>::AddSample(T sample, const float pdf) 195 { 196 HASH_SET::iterator it; 197 198 if (Find(sample, it)) 200 BitVectorPvs<T, S>::BitVectorPvs() 201 { 202 // initialize bit vector 203 mEntries.reserve(sPvsSize); 204 mEntries.resize(sPvsSize); 205 206 // set pvs entries to false 207 Clear(); 208 } 209 210 211 template <typename T, typename S> 212 bool BitVectorPvs<T, S>::Find(T sample) 213 { 214 return mEntries[sample->GetId()]; 215 } 216 217 218 template <typename T, typename S> 219 int BitVectorPvs<T, S>::GetSize() const 220 { 221 int size = 0; 222 bit_vector::const_iterator bit, bit_end = mEntries.end(); 223 224 for (bit = mEntries.begin(); bit != bit_end; ++ bit) 225 { 226 if (*bit) ++ size; 227 } 228 229 return size; 230 } 231 232 233 template <typename T, typename S> 234 bool BitVectorPvs<T, S>::Empty() const 235 { 236 bit_vector::const_iterator bit, bit_end = mEntries.end(); 237 238 for (bit = mEntries.begin(); bit != bit_end; ++ bit) 239 { 240 if (*bit) return false; 241 } 242 243 return true; 244 } 245 246 247 template <typename T, typename S> 248 float BitVectorPvs<T, S>::AddSample(T sample, const float pdf) 249 { 250 if (Find(sample)) 199 251 return 0.0f; 200 252 201 mEntries.insert(sample); 253 mEntries[sample->GetId()] = true; 254 202 255 return 1.0f; 203 256 } … … 205 258 206 259 template <typename T, typename S> 207 void HashPvs<T, S>::AddSampleDirty(T sample, const float pdf) 208 { 209 HASH_SET::iterator it; 210 211 // not yet in map 212 if (!Find(sample, it)) 213 { 214 mEntries.insert(sample); 215 } 216 } 217 218 219 template <typename T, typename S> 220 bool HashPvs<T, S>::AddSampleDirtyCheck(T sample, 260 void BitVectorPvs<T, S>::AddSampleDirty(T sample, const float pdf) 261 { 262 if (!Find(sample)) 263 { 264 mEntries[sample->GetId()] = true; 265 } 266 } 267 268 269 template <typename T, typename S> 270 bool BitVectorPvs<T, S>::AddSampleDirtyCheck(T sample, 221 271 const float pdf) 222 272 { 223 HASH_SET::iterator it; 224 225 // already in map 226 if (Find(sample, it)) 273 if (Find(sample)) 227 274 return false; 228 275 229 mEntries .insert(sample);276 mEntries[sample->GetId()] = true; 230 277 return true; 231 278 } … … 233 280 234 281 template <typename T, typename S> 235 void HashPvs<T, S>::Sort() 236 { 237 } 238 239 240 template <typename T, typename S> 241 void HashPvs<T, S>::Clear(const bool trim = true) 242 { 243 mEntries.clear(); 244 } 245 246 247 template <typename T, typename S> 248 bool HashPvs<T, S>::IsDirty() const 282 void BitVectorPvs<T, S>::Sort() 283 { 284 } 285 286 287 template <typename T, typename S> 288 void BitVectorPvs<T, S>::Clear(const bool trim = true) 289 { 290 bit_vector::iterator bit, bit_end = mEntries.end(); 291 for (bit = mEntries.begin(); bit != bit_end; ++ bit) 292 { 293 (*bit) = false; 294 } 295 } 296 297 298 template <typename T, typename S> 299 bool BitVectorPvs<T, S>::IsDirty() const 249 300 { 250 301 return false; … … 253 304 254 305 template <typename T, typename S> 255 bool HashPvs<T, S>::RequiresResort() const306 bool BitVectorPvs<T, S>::RequiresResort() const 256 307 { 257 308 return false; … … 260 311 261 312 template <typename T, typename S> 262 typename HashPvsIterator<T, S> HashPvs<T, S>::GetIterator() const263 { 264 HashPvsIterator<T, S> pit(mEntries.begin(), mEntries.end());313 typename BitVectorPvsIterator<T, S> BitVectorPvs<T, S>::GetIterator() const 314 { 315 BitVectorPvsIterator<T, S> pit(mEntries.begin(), mEntries.end()); 265 316 266 317 return pit; … … 269 320 270 321 template <typename T, typename S> 271 float HashPvs<T, S>::GetEntrySize()272 { 273 return (float)(sizeof( T)) / float(1024 * 1024);274 } 275 276 277 template <typename T, typename S> 278 int HashPvs<T, S>::GetEntrySizeByte()279 { 280 return sizeof( T);281 } 282 283 284 template <typename T, typename S> 285 float HashPvs<T, S>::GetPvsHomogenity(HashPvs<T, S> &pvs)322 float BitVectorPvs<T, S>::GetEntrySize() 323 { 324 return (float)(sizeof(bool)) / float(1024 * 1024); 325 } 326 327 328 template <typename T, typename S> 329 int BitVectorPvs<T, S>::GetEntrySizeByte() 330 { 331 return sizeof(bool); 332 } 333 334 335 template <typename T, typename S> 336 float BitVectorPvs<T, S>::GetPvsHomogenity(BitVectorPvs<T, S> &pvs) 286 337 { 287 338 float pvsReduction, pvsEnlargement; … … 294 345 295 346 template <typename T, typename S> 296 bool HashPvs<T, S>::GetSampleContribution(T sample,347 bool BitVectorPvs<T, S>::GetSampleContribution(T sample, 297 348 const float pdf, 298 349 float &contribution) 299 350 { 300 HASH_SET::iterator it; 301 const bool entryFound = Find(sample, it); 351 const bool entryFound = Find(sample); 302 352 303 353 if (entryFound) … … 315 365 316 366 template <typename T, typename S> 317 void HashPvs<T, S>::Merge(HashPvs<T, S> &mergedPvs, 318 const HashPvs<T, S> &a, 319 const HashPvs<T, S> &b) 320 { 367 void BitVectorPvs<T, S>::Merge(BitVectorPvs<T, S> &mergedPvs, 368 const BitVectorPvs<T, S> &a, 369 const BitVectorPvs<T, S> &b) 370 { 371 bit_vector::iterator bit, bit_end = mergedPvs.mEntries.end(); 372 bit_vector::const_iterator bitA = a.mEntries.begin(), bitB = b.mEntries.begin(); 373 374 for (bit = mergedPvs.mEntries.begin(); bit != bit_end; ++ bit, ++ bitA, ++ bitB) 375 { 376 (*bit) = (*bitA) | (*bitB); 377 } 378 } 379 380 381 template<typename T, typename S> 382 int BitVectorPvs<T, S>::sPvsSize = 0; 383 384 template<typename T, typename S> 385 vector<T> BitVectorPvsIterator<T, S>::sObjects; 386 321 387 } 322 388 323 389 #endif 324 390 325 }326 327 #endif328
Note: See TracChangeset
for help on using the changeset viewer.