Changeset 1189 for GTP/trunk/Lib/Vis
- Timestamp:
- 08/09/06 10:49:20 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp
r1184 r1189 9 9 10 10 namespace GtpVisibilityPreprocessor { 11 12 int MailablePvsData::sMailId = 1; 13 int MailablePvsData::sReservedMailboxes = 1; 11 14 12 15 -
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
r1184 r1189 4 4 #include <map> 5 5 #include <vector> 6 #include "common.h" 6 7 7 8 namespace GtpVisibilityPreprocessor { … … 15 16 16 17 template<typename T> 17 struct LtSample { 18 struct LtSample 19 { 18 20 bool operator()(const T a, const T b) const 19 21 { … … 25 27 the object was seen from the view cell. 26 28 */ 27 28 template<typename T> 29 struct PvsData { 29 class PvsData { 30 public: 31 // sum of probability density of visible sample rays 32 float mSumPdf; 33 34 PvsData() {} 35 PvsData(const float sumPdf): 36 mSumPdf(sumPdf) {} 37 38 // $$JB in order to return meaningfull values 39 // it assumes that the sum pdf has been normalized somehow!!! 40 float GetVisibility() 41 { 42 return mSumPdf; 43 } 44 }; 45 46 47 class MailablePvsData 48 { 30 49 //////////////////////////// 31 50 // Mailing stuff … … 56 75 // sum of probability density of visible sample rays 57 76 float mSumPdf; 58 59 PvsData<T>() {} 60 PvsData<T>(const float sumPdf): 77 int mCounter; 78 79 MailablePvsData() {} 80 MailablePvsData(const float sumPdf): 61 81 mSumPdf(sumPdf) {} 62 82 … … 69 89 }; 70 90 71 template<typename T> int PvsData<T>::sMailId = 1;72 template<typename T> int PvsData<T>::sReservedMailboxes = 1;73 91 74 92 /** Template class representing the Potentially Visible Set (PVS) 75 93 mainly from a view cell, but also e.g., from objects. 76 94 */ 77 template<typename T >95 template<typename T, typename S> 78 96 class Pvs 79 97 { … … 81 99 Pvs(): /*mSamples(0), */mEntries() {} 82 100 83 // int mSamples;84 101 //virtual ~Pvs(); 102 85 103 /** Compresses PVS lossless or lossy. 86 104 */ … … 96 114 /** Merges pvs of a into this pvs. 97 115 */ 98 void Merge(const Pvs<T > &a);116 void Merge(const Pvs<T, S> &a); 99 117 100 118 /** Difference of pvs to pvs b. 101 119 @returns number of different entries. 102 120 */ 103 int Diff(const Pvs<T > &b);121 int Diff(const Pvs<T, S> &b); 104 122 105 123 /** Finds sample in PVS. 106 124 @returns sample if found, NULL otherwise. 107 125 */ 108 PvsData<T>*Find(T sample);126 S *Find(T sample); 109 127 110 128 bool GetSampleContribution(T sample, const float pdf, float &contribution); … … 124 142 @returns PvsData 125 143 */ 126 PvsData<T>*AddSample2(T sample, const float pdf);144 S *AddSample2(T sample, const float pdf); 127 145 128 146 /** Adds one pvs to another one. 129 147 @returns new pvs size 130 148 */ 131 int AddPvs(const Pvs<T > &pvs);149 int AddPvs(const Pvs<T, S> &pvs); 132 150 133 151 /** Subtracts one pvs from another one. … … 135 153 @returns new pvs size 136 154 */ 137 int SubtractPvs(const Pvs<T > &pvs);155 int SubtractPvs(const Pvs<T, S> &pvs); 138 156 /** Returns PVS data, i.e., how often it was seen from the view cell, 139 157 and the object itsef. 140 158 */ 141 void GetData(const int index, T &entry, PvsData<T>&data);159 void GetData(const int index, T &entry, S &data); 142 160 143 161 /** Collects the PVS entries and returns them in the vector. … … 151 169 152 170 /** Compute continuous PVS difference */ 153 void ComputeContinuousPvsDifference(Pvs<T > &pvs,171 void ComputeContinuousPvsDifference(Pvs<T, S> &pvs, 154 172 float &pvsReduction, 155 173 float &pvsEnlargement); … … 161 179 162 180 /** Compute continuous PVS difference */ 163 float GetPvsHomogenity(Pvs<T > &pvs) {181 float GetPvsHomogenity(Pvs<T, S> &pvs) { 164 182 float 165 183 pvsReduction, … … 176 194 177 195 /// Map of PVS entries 178 std::map<T, PvsData<T>, LtSample<T> > mEntries;196 std::map<T, S, LtSample<T> > mEntries; 179 197 }; 180 198 … … 186 204 187 205 */ 188 template <typename T >206 template <typename T, typename S> 189 207 void 190 Pvs<T >::ComputeContinuousPvsDifference(Pvs<T> &b,208 Pvs<T, S>::ComputeContinuousPvsDifference(Pvs<T, S> &b, 191 209 float &pvsReduction, 192 210 float &pvsEnlargement) … … 195 213 pvsEnlargement = 0.0f; 196 214 // Uses sum of log differences, which corresponds to entropy 197 std::map<T, PvsData<T>, LtSample<T> >::iterator it;198 199 for (it = b.mEntries.begin(); 200 it != b.mEntries.end(); ++ it){215 std::map<T, S, LtSample<T> >::iterator it; 216 217 for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it) 218 { 201 219 float bSumPdf = (*it).second.mSumPdf; 202 220 float aSumPdf = 0.0f; 203 PvsData<T> *data = Find((*it).first); 204 if (data) { 205 aSumPdf = data->mSumPdf; 206 // mark this entry as processed to avoid double counting 207 data->mSumPdf = -aSumPdf; 221 S *data = Find((*it).first); 222 223 if (data) 224 { 225 aSumPdf = data->mSumPdf; 226 // mark this entry as processed to avoid double counting 227 data->mSumPdf = -aSumPdf; 208 228 } 209 229 … … 230 250 (*it).second.mSumPdf = -aSumPdf; 231 251 } else { 232 PvsData<T>*data = b.Find((*it).first);252 S *data = b.Find((*it).first); 233 253 if (data) { 234 254 bSumPdf = data->mSumPdf; … … 251 271 } 252 272 253 template <typename T >254 int Pvs<T >::Diff(const Pvs<T> &b)273 template <typename T, typename S> 274 int Pvs<T, S>::Diff(const Pvs<T, S> &b) 255 275 { 256 276 int dif = 0; 257 277 258 std::map<T, PvsData<T>, LtSample<T> >::const_iterator it;278 std::map<T, S, LtSample<T> >::const_iterator it; 259 279 260 280 for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it) 261 281 { 262 PvsData<T> *data = Find((*it).first);282 S data = Find((*it).first); 263 283 if (!data) ++ dif; 264 284 } … … 267 287 } 268 288 269 template <typename T> 270 void Pvs<T>::Merge(const Pvs<T> &a) 271 { 272 std::map<T, PvsData<T>, LtSample<T> >::const_iterator it; 289 template <typename T, typename S> void Pvs<T, S>::Merge(const Pvs<T, S> &a) 290 { 291 std::map<T, S, LtSample<T> >::const_iterator it; 273 292 274 293 for (it = a.mEntries.begin(); it != a.mEntries.end(); ++ it) 275 294 { 276 PvsData<T> *data = Find((*it).first); 277 278 if (data) 279 data->mSumPdf += (*it).second.mSumPdf; 280 else 281 mEntries.insert(*it); 282 } 283 } 284 285 template <typename T> void Pvs<T>::Clear() 295 AddSample((*it).first, (*it).second.mSumPdf); 296 } 297 } 298 299 300 template <typename T, typename S> void Pvs<T, S>::Clear() 286 301 { 287 302 mEntries.clear(); … … 289 304 290 305 291 template <typename T> 292 PvsData<T> *Pvs<T>::Find(T sample) 293 { 294 std::map<T, PvsData<T>, LtSample<T> >::iterator i = mEntries.find(sample); 295 if (i != mEntries.end()) { 296 return &(*i).second; 297 } else 298 return NULL; 299 } 300 301 template <typename T> 302 void Pvs<T>::GetData(const int index, 306 template <typename T, typename S> 307 S *Pvs<T, S>::Find(T sample) 308 { 309 std::map<T, S, LtSample<T> >::iterator i = mEntries.find(sample); 310 311 if (i != mEntries.end()) 312 { 313 return &(*i).second; 314 } 315 else 316 { 317 return NULL; 318 } 319 } 320 321 template <typename T, typename S> 322 void Pvs<T, S>::GetData(const int index, 303 323 T &entry, 304 PvsData<T>&data)305 { 306 std::map<T, PvsData<T>, LtSample<T> >::iterator i = mEntries.begin();324 S &data) 325 { 326 std::map<T, S, LtSample<T> >::iterator i = mEntries.begin(); 307 327 for (int k = 0; k != index && i != mEntries.end(); i++, k++); 308 328 309 329 entry = (*i).first; 310 330 data = (*i).second; 311 } 312 313 template <typename T> 331 332 } 333 334 template <typename T, typename S> 314 335 float 315 Pvs<T>::AddSample(T sample, const float pdf) 316 { 317 PvsData<T> *data = Find(sample); 318 319 if (data) { 320 data->mSumPdf += pdf; 321 return data->mSumPdf; 322 } 323 else { 324 mEntries[sample] = PvsData<T>(pdf); 325 return pdf; 326 } 327 } 328 329 template <typename T> 330 PvsData<T> * 331 Pvs<T>::AddSample2(T sample, const float pdf) 332 { 333 PvsData<T> *data = Find(sample); 334 335 if (data) { 336 data->mSumPdf += pdf; 337 } 338 else { 339 mEntries[sample] = PvsData<T>(pdf); 340 data = Find(sample); 341 } 342 return data; 343 } 344 345 template <typename T> 346 bool 347 Pvs<T>::AddSample(T sample, 336 Pvs<T, S>::AddSample(T sample, const float pdf) 337 { 338 S *data = Find(sample); 339 340 if (data) 341 { 342 data->mSumPdf += pdf; 343 return data->mSumPdf; 344 } 345 else 346 { 347 mEntries[sample] = S(pdf); 348 return pdf; 349 } 350 } 351 352 353 template <typename T, typename S> 354 S * Pvs<T, S>::AddSample2(T sample, const float pdf) 355 { 356 S *data = Find(sample); 357 358 if (data) 359 { 360 data->mSumPdf += pdf; 361 } 362 else 363 { 364 mEntries[sample] = S(pdf); 365 data = Find(sample); 366 } 367 368 return data; 369 } 370 371 template <typename T, typename S> 372 bool Pvs<T, S>::AddSample(T sample, 348 373 const float pdf, 349 374 float &contribution) 350 375 { 351 PvsData<T> *data = Find(sample); 352 353 if (data) { 376 S *data = Find(sample); 377 378 if (data) 379 { 354 380 data->mSumPdf += pdf; 355 contribution = pdf /data->mSumPdf;381 contribution = pdf / data->mSumPdf; 356 382 return false; 357 383 } 358 384 else { 359 mEntries[sample] = PvsData<T>(pdf);385 mEntries[sample] = S(pdf); 360 386 contribution = 1.0f; 361 387 return true; … … 363 389 } 364 390 365 template <typename T >391 template <typename T, typename S> 366 392 bool 367 Pvs<T >::GetSampleContribution(T sample,393 Pvs<T, S>::GetSampleContribution(T sample, 368 394 const float pdf, 369 395 float &contribution) 370 396 { 371 PvsData<T>*data = Find(sample);397 S *data = Find(sample); 372 398 373 399 if (data) { 374 contribution = pdf /(data->mSumPdf + pdf);400 contribution = pdf / (data->mSumPdf + pdf); 375 401 return false; 376 402 } … … 381 407 } 382 408 383 template <typename T >384 bool Pvs<T >::RemoveSample(T sample,409 template <typename T, typename S> 410 bool Pvs<T, S>::RemoveSample(T sample, 385 411 const float pdf) 386 412 { 387 std::map<T, PvsData<T>, LtSample<T> >::413 std::map<T, S, LtSample<T> >:: 388 414 iterator it = mEntries.find(sample); 389 415 … … 391 417 return false; 392 418 393 PvsData<T>*data = &(*it).second;419 S *data = &(*it).second; 394 420 395 421 data->mSumPdf -= pdf; 422 396 423 if (data->mSumPdf <= 0.0f) 397 mEntries.erase(it); 398 424 { 425 mEntries.erase(it); 426 } 427 399 428 return true; 400 429 } 401 430 402 template <typename T >403 int Pvs<T >::AddPvs(const Pvs<T> &pvs)404 { 405 std::map<T, PvsData<T>, LtSample<T> >::431 template <typename T, typename S> 432 int Pvs<T, S>::AddPvs(const Pvs<T, S> &pvs) 433 { 434 std::map<T, S, LtSample<T> >:: 406 435 const_iterator it, it_end = pvs.mEntries.end(); 407 436 408 437 float contri; 409 438 // output PVS of view cell 410 for (it = pvs.mEntries.begin(); it != it_end; ++ it) 411 AddSample((*it).first, (*it).second.mSumPdf, contri); 439 for (it = pvs.mEntries.begin(); it != it_end; ++ it) 440 { 441 AddSample((*it).first, (*it).second.mSumPdf, contri); 442 } 412 443 413 444 return GetSize(); 414 445 } 415 446 416 template <typename T >417 int Pvs<T >::SubtractPvs(const Pvs<T> &pvs)418 { 419 std::map<T, PvsData<T>, LtSample<T> >::447 template <typename T, typename S> 448 int Pvs<T, S>::SubtractPvs(const Pvs<T, S> &pvs) 449 { 450 std::map<T, S, LtSample<T> >:: 420 451 const_iterator it, it_end = pvs.mEntries.end(); 421 452 … … 427 458 } 428 459 429 template <typename T >430 void Pvs<T >::CollectEntries(std::vector<T> &entries)431 { 432 std::map<T, PvsData<T>, LtSample<T> >::460 template <typename T, typename S> 461 void Pvs<T, S>::CollectEntries(std::vector<T> &entries) 462 { 463 std::map<T, S, LtSample<T> >:: 433 464 const_iterator it, it_end = mEntries.end(); 434 465 … … 438 469 } 439 470 440 template <typename T >441 void Pvs<T >::NormalizeMaximum()442 { 443 std::map<T, PvsData<T>, LtSample<T> >::471 template <typename T, typename S> 472 void Pvs<T, S>::NormalizeMaximum() 473 { 474 std::map<T, S, LtSample<T> >:: 444 475 const_iterator it, it_end = mEntries.end(); 445 476 … … 453 484 } 454 485 455 maxSum = 1.0f /maxSum;486 maxSum = 1.0f / maxSum; 456 487 457 488 for (it = mEntries.begin(); it != it_end; ++ it) { … … 464 495 /** Class instantiating the Pvs template for kd tree nodes. 465 496 */ 466 class KdPvs: public Pvs<KdNode * >497 class KdPvs: public Pvs<KdNode *, PvsData> 467 498 { 468 499 public: … … 471 502 472 503 473 class ObjectPvs: public Pvs<Intersectable * >504 class ObjectPvs: public Pvs<Intersectable *, PvsData> 474 505 { 475 506 public: … … 483 514 //-- typedefs 484 515 485 typedef std::map<KdNode *, PvsData<KdNode *>, LtSample<KdNode *> > KdPvsMap; 486 typedef std::map<Intersectable *, PvsData<Intersectable *>, LtSample<Intersectable *> > ObjectPvsMap; 487 typedef std::map<ViewCell *, PvsData<ViewCell *>, LtSample<ViewCell *> > ViewCellPvsMap; 488 489 typedef PvsData<Intersectable *> ObjectPvsData; 490 typedef PvsData<KdNode *> KdPvsData; 491 492 typedef Pvs<ViewCell *> ViewCellPvs; 493 typedef PvsData<ViewCell *> ViewCellPvsData; 516 typedef std::map<KdNode *, PvsData, LtSample<KdNode *> > KdPvsMap; 517 typedef std::map<Intersectable *, PvsData, LtSample<Intersectable *> > ObjectPvsMap; 518 typedef std::map<ViewCell *, MailablePvsData, LtSample<ViewCell *> > ViewCellPvsMap; 519 520 521 typedef Pvs<ViewCell *, MailablePvsData> ViewCellPvs; 494 522 495 523 } -
GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
r1145 r1189 648 648 case 3: { 649 649 float newCost = info.raysBack*info.pvsBack + info.raysFront*info.pvsFront; 650 float oldCost = leaf->rays.size()*pvsSize;650 float oldCost = (float)leaf->rays.size()*pvsSize; 651 651 info.costRatio = newCost/oldCost; 652 652 } … … 675 675 case 3: { 676 676 float newCost = abs(info.raysBack - info.raysFront); 677 float oldCost = leaf->rays.size();677 float oldCost = (float)leaf->rays.size(); 678 678 info.costRatio = newCost/oldCost; 679 679 break; … … 1762 1762 RssTreeLeaf *leaf = (RssTreeLeaf *)node; 1763 1763 float c = leaf->GetImportance(); 1764 int num = (c*ratioPerLeaf + 0.5);1764 int num = int(c*ratioPerLeaf + 0.5f); 1765 1765 // cout<<num<<" "; 1766 1766 … … 2323 2323 RssTreeLeaf::RayInfo::GreaterWeightedPvsContribution); 2324 2324 2325 int desired = ratio*leaf->rays.size();2326 int removed = leaf->rays.size() - desired;2327 2328 for (i=desired; i < leaf->rays.size(); i++) {2325 int desired = int(ratio*leaf->rays.size()); 2326 int removed = (int)leaf->rays.size() - desired; 2327 2328 for (i=desired; i < (int)leaf->rays.size(); i++) { 2329 2329 // delete the ray 2330 2330 leaf->rays[i].mRay->Unref(); -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp
r1159 r1189 147 147 for (int tries = 0; tries < 10; tries++) { 148 148 int index = (int)RandomValue(0, (Real)(pvsSize - 1)); 149 KdPvsData data;149 PvsData data; 150 150 KdNode *node; 151 151 object->mKdPvs.GetData(index, node, data); -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1179 r1189 92 92 it_end = pvs2.mEntries.end(); 93 93 94 // look if the y arein second pvs94 // look if the entries are also in second pvs 95 95 for (it = pvs2.mEntries.begin(); it != it_end; ++ it) 96 96 { … … 1626 1626 } 1627 1627 1628 interior->GetPvs(). mEntries.clear();1628 interior->GetPvs().Clear(); 1629 1629 1630 1630 … … 1656 1656 { 1657 1657 if (!(*cit)->GetPvs().RemoveSample((*oit).first, Limits::Infinity)) 1658 { 1658 1659 Debug << "should not come here!" << endl; 1660 } 1659 1661 } 1660 1662 } … … 1985 1987 { 1986 1988 const float entrySize = 1987 sizeof(PvsData <Intersectable *>) + sizeof(Intersectable *);1989 sizeof(PvsData) + sizeof(Intersectable *); 1988 1990 1989 1991 return (float)GetStoredPvsEntriesNum(vc) * entrySize; … … 2286 2288 tstack.pop(); 2287 2289 2288 vc->GetPvs(). mEntries.clear();2290 vc->GetPvs().Clear(); 2289 2291 2290 2292 if (!vc->IsLeaf()) -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1184 r1189 2340 2340 Intersectable::NewMail(); 2341 2341 2342 std::map<Intersectable *, 2343 PvsData<Intersectable *>, 2344 LtSample<Intersectable *> >::const_iterator oi; 2342 ObjectPvsMap::const_iterator oi; 2345 2343 2346 for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++oi) { 2347 Intersectable *object = (*oi).first; 2348 object->Mail(); 2344 for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++ oi) 2345 { 2346 Intersectable *object = (*oi).first; 2347 object->Mail(); 2349 2348 } 2350 2349 2351 2350 ObjectPvs nPvs; 2352 int nPvsSize =0;2351 int nPvsSize = 0; 2353 2352 // now go through the pvs again 2354 2353 for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++oi) { … … 3418 3417 ObjectPvsMap::iterator it, it_end = vc->GetPvs().mEntries.end(); 3419 3418 // -- output PVS of view cell 3420 for (it = vc->GetPvs().mEntries.begin(); it != 3419 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 3421 3420 { 3422 3421 Intersectable *intersect = (*it).first; … … 5385 5384 { 5386 5385 //-- export pvs 5386 5387 Intersectable::NewMail(); 5388 KdLeaf::NewMail(); 5389 5390 vector<KdLeaf *> kdLeaves; 5391 5387 5392 ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 5388 5393 5389 Intersectable::NewMail();5390 5391 vector<KdLeaf *> kdLeaves;5392 5393 KdLeaf::NewMail();5394 5395 // export pvs entries5396 5394 for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 5397 5395 { … … 5803 5801 } 5804 5802 5805 Debug << " here295 " << rc / mVspTree->GetBoundingBox().GetVolume();5803 Debug << "\nhere295 " << rc / mVspTree->GetBoundingBox().GetVolume() << endl; 5806 5804 5807 5805 mViewCellsTree->ExportStats(fileName); -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r1168 r1189 499 499 mBspStats.Leaves() * sizeof(BspLeaf) + 500 500 mCreatedViewCells * sizeof(BspViewCell) + 501 mBspStats.pvs * sizeof( ObjectPvsData) +501 mBspStats.pvs * sizeof(PvsData) + 502 502 mBspStats.Interior() * sizeof(BspInterior) + 503 503 mBspStats.accumRays * sizeof(RayInfo)) / (1024.0f * 1024.0f); -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
r1186 r1189 22 22 namespace GtpVisibilityPreprocessor { 23 23 24 24 25 #define USE_FIXEDPOINT_T 0 25 26 … … 32 33 // variable for debugging volume contribution for heuristics 33 34 static float debugVol; 35 36 int VspNode::sMailId = 1; 34 37 35 38 // pvs penalty can be different from pvs size … … 40 43 // clamp to minmax values 41 44 if (pvs < lower) 45 { 42 46 return (float)lower; 47 } 43 48 else if (pvs > upper) 49 { 44 50 return (float)upper; 51 } 45 52 46 53 return (float)pvs; … … 48 55 49 56 50 int VspNode::sMailId = 1; 57 static bool ViewCellHasMultipleReferences(Intersectable *obj, 58 ViewCell *vc, 59 bool checkOnlyMailed) 60 { 61 MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 62 63 if (vdata) 64 { 65 //Debug << "sumpdf: " << vdata->mSumPdf << endl; 66 // more than one view cell sees this object inside different kd cells 67 if (!checkOnlyMailed || !vdata->Mailed()) 68 { 69 if (checkOnlyMailed) 70 vdata->Mail(); 71 72 if (vdata->mSumPdf > 1.5f) 73 return true; 74 } 75 } 76 77 return false; 78 } 51 79 52 80 … … 548 576 mVspStats.Leaves() * sizeof(VspLeaf) + 549 577 mCreatedViewCells * sizeof(VspViewCell) + 550 mVspStats.pvs * sizeof( ObjectPvsData) +578 mVspStats.pvs * sizeof(PvsData) + 551 579 mVspStats.Interior() * sizeof(VspInterior) + 552 580 mVspStats.accumRays * sizeof(RayInfo)) / (1024.0f * 1024.0f); … … 3203 3231 // This is important during the subdivision 3204 3232 3205 // ViewCellPvsData::NewMail();3233 //MailablePvsData::NewMail(); 3206 3234 UpdateViewCellsPvs(front, *frontData.mRays); 3207 3235 UpdateViewCellsPvs(back, *backData.mRays); … … 3409 3437 Debug << "BSP stats: " 3410 3438 << "Depth: " << data.mDepth << " (max: " << mTermMaxDepth << "), " 3411 // << "PVS: " << data.mPvs << " (min: " << mTermMinPvs << "), " 3412 << "Prob: " << data.mProbability << " (min: " << mTermMinProbability << "), " 3413 << "#pvs: " << data.mPvs << ")\n"; 3439 << "Prob: " << data.mProbability << " (min: " << mTermMinProbability << ")\n"; 3414 3440 #endif 3415 3441 } … … 3450 3476 SortSplitCandidates(tData, axis, minBand, maxBand); 3451 3477 3452 int numViewCells; 3453 3454 float totalVol = PrepareHeuristics(tData, numViewCells); 3478 float totalVol = 0;//PrepareHeuristics(tData); 3455 3479 float voll = 0; 3456 3480 float volr = totalVol; 3457 3481 3458 int vcl = 0; 3459 int vcr = numViewCells; 3460 3482 ViewCellContainer touchedViewCells; 3483 const float totalRenderCost = PrepareHeuristics(tData, touchedViewCells); 3484 float renderCost = totalRenderCost; 3485 3461 3486 /// this is kind of a reverse pvs 3462 3487 const int totalPvs = (int)tData.mNode->mObjects.size(); … … 3483 3508 int pvsFront = pvsr; 3484 3509 3485 float min Sum= 1e20f;3510 float minRenderCost = 1e20f; 3486 3511 3487 3512 debugVol = 0; 3488 3513 const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 3489 3514 3515 3490 3516 ///////////////////////////// 3491 3517 // the sweep heuristics 3492 3518 3493 3494 3519 Intersectable::NewMail(); 3495 3520 ViewCell::NewMail(); 3496 3497 3521 3498 3522 //-- traverse through events and find best split plane 3499 3523 … … 3506 3530 EvalHeuristicsContribution(tData.mNode, 3507 3531 *ci, 3508 voll, volr,3509 pvsl, pvsr3532 renderCost, 3533 touchedViewCells 3510 3534 ); 3511 3535 … … 3514 3538 if (((*ci).mPos >= minBand) && ((*ci).mPos <= maxBand)) 3515 3539 { 3516 // voll = view cells that see only left node (i.e., left pvs)3517 // volr = view cells that see only right node (i.e., right pvs)3518 // rest = view cells that see both nodes (i.e., total pvs)3519 sum = voll * pvsl + volr * pvsr + (totalVol - voll - volr) * totalPvs;3520 3521 3540 float currentPos; 3522 3541 … … 3527 3546 currentPos = (*ci).mPos; 3528 3547 3529 /*if ((totalVol - voll - volr - debugVol) / viewSpaceVol > 0.0001) 3530 Debug << "front and back volume: " << (totalVol - voll - volr) / viewSpaceVol << " error: " << (totalVol - voll - volr - debugVol) / viewSpaceVol << endl; 3531 Debug << "pos: " << currentPos 3532 << "\t (pvsl: " << pvsl << ", pvsr: " << pvsr << ")" 3533 << "\t (voll: " << voll << ", volr: " << volr << ")" 3534 << "\t (vcl: " << vcl << ", vcr: " << vcr << ", nvc: " << numViewCells << ")" 3535 << "\t sum: " << sum << endl; 3536 */ 3537 3538 if (sum < minSum) 3548 if (renderCost < minRenderCost) 3539 3549 { 3540 3550 splitPlaneFound = true; 3541 3542 minSum = sum; 3543 3544 pvsBack = pvsl; 3545 pvsFront = pvsr; 3546 3547 volBack = voll; 3548 volFront = volr; 3549 3551 Debug << "pos: " << position << endl; 3552 minRenderCost = renderCost; 3550 3553 position = currentPos; 3551 3554 } … … 3553 3556 } 3554 3557 3555 //-- compute cost3556 const float frontAndBackVol = totalVol - volFront - volBack;3557 3558 const float oldRenderCost = (float)totalPvs * totalVol + Limits::Small;3559 const float newRenderCost = (float)pvsFront * volFront +3560 (float)pvsBack * volBack +3561 (float)totalPvs * frontAndBackVol;3562 3563 3564 3558 if (splitPlaneFound) 3565 3559 { 3566 ratio = newRenderCost / oldRenderCost; 3567 } 3568 3569 //Debug << "axis=" << axis << " costRatio=" << ratio << " pos=" 3570 // << position << " t=" << (position - minBox) / (maxBox - minBox) 3571 // << "\t pb=(" << volBack << ")\t pf=(" << volFront << ")" << endl; 3572 3573 /* Debug << "\n§§§§ eval local cost §§§§" << endl 3574 << "back pvs: " << pvsBack << " front pvs: " << pvsFront << " total pvs: " << totalPvs << endl 3575 << "back p: " << volBack / viewSpaceVol << " front p " << volFront / viewSpaceVol << " p: " << totalVol / viewSpaceVol << endl 3576 << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl 3577 << "render cost decrease: " << oldRenderCost / viewSpaceVol - newRenderCost / viewSpaceVol << endl; 3578 */ 3579 if (oldRenderCost < newRenderCost) 3580 Debug << "\nwarning!!:\n" << "old rc: " << oldRenderCost * viewSpaceVol << " new rc: " << newRenderCost * viewSpaceVol << endl; 3581 3560 ratio = totalRenderCost / minRenderCost; 3561 } 3562 3563 Debug << "\n§§§§ eval local cost §§§§" << endl 3564 << "old rc: " << totalRenderCost / viewSpaceVol << " new rc: " << minRenderCost / viewSpaceVol << endl 3565 << "render cost decrease: " << (totalRenderCost - minRenderCost) / viewSpaceVol << endl; 3582 3566 3583 3567 return ratio; … … 3689 3673 3690 3674 3691 float OspTree::PrepareHeuristics(const VssRay &ray, int &numViewCells) 3692 { 3693 float vol = 0; 3694 numViewCells = 0; 3695 3675 void OspTree::PrepareHeuristics(const VssRay &ray, 3676 ViewCellContainer &touchedViewCells) 3677 { 3678 3679 // collect view cells and set mail + counter 3696 3680 ViewCellContainer viewCells; 3697 3698 3681 mVspTree->GetViewCells(VssRay(ray), viewCells); 3699 3682 … … 3706 3689 if (!vc->Mailed()) 3707 3690 { 3708 //Debug << "single vol: "<< vc->GetVolume() << endl; 3709 vc->Mail(); 3691 vc->Mail(); // set as belonging to front leaf 3710 3692 vc->mCounter = 0; 3711 vol += vc->GetVolume(); 3712 ++ numViewCells; 3693 touchedViewCells.push_back(vc); 3713 3694 } 3714 3695 … … 3716 3697 ++ vc->mCounter; 3717 3698 } 3718 3719 return vol; 3720 } 3721 3722 3723 float OspTree::PrepareHeuristics(const OspTraversalData &tData, int &numViewCells) 3699 } 3700 3701 3702 float OspTree::PrepareHeuristics(const OspTraversalData &tData, 3703 ViewCellContainer &touchedViewCells) 3724 3704 { 3725 float vol= 0;3726 3727 Intersectable::NewMail( );3728 ViewCell::NewMail( );3729 numViewCells = 0;3705 float renderCost = 0; 3706 3707 Intersectable::NewMail(3); 3708 ViewCell::NewMail(3); 3709 MailablePvsData::NewMail(); 3730 3710 3731 3711 KdLeaf *leaf = tData.mNode; … … 3736 3716 { 3737 3717 VssRay *ray = (*rit).mRay; 3738 3739 int newViewCells; 3740 3741 // if hitpoint with one of the objects is inside this node, we 3742 // evaluate the volume of the view cells seen by this ray 3743 if (EndPointInsideNode(leaf, *ray, true)) 3744 { 3745 vol += PrepareHeuristics(*ray, newViewCells); 3746 numViewCells += newViewCells; 3747 } 3748 3749 // count double if both hit points are within the kd node 3750 if (EndPointInsideNode(leaf, *ray, false)) 3751 { 3752 vol += PrepareHeuristics(*ray, newViewCells); 3753 numViewCells += newViewCells; 3754 } 3755 } 3756 3757 3758 return vol; 3759 } 3760 3761 3762 void OspTree::EvalHeuristicsContribution(KdLeaf *leaf, 3763 const SortableEntry &ci, 3764 float &volLeft, 3765 float &volRight, 3766 int &pvsLeft, 3767 int &pvsRight 3768 ) 3769 { 3770 Intersectable *obj = ci.mObject; 3771 VssRay *ray = ci.mRay; 3772 3773 // switch between different types of events 3774 switch (ci.mType) 3775 { 3776 // add reverse pvs to left side of split plane 3777 case SortableEntry::BOX_MIN: 3778 ++ pvsLeft; 3779 break; 3780 3781 case SortableEntry::BOX_MAX: 3782 -- pvsRight; 3783 break; 3784 3785 // compute volume contribution from view cells 3786 case SortableEntry::BOX_INTERSECT: 3787 // process ray if the hit point with termination / origin object 3788 // is inside this kd leaf 3789 if (EndPointInsideNode(leaf, *ray, true) || 3790 EndPointInsideNode(leaf, *ray, false)) 3791 { 3792 EvalVolumeContribution(*ray, volLeft, volRight); 3793 } 3794 break; 3795 default: 3796 cout << "should not come here" << endl; 3797 break; 3798 } 3799 3800 //cout << "vol left: " << volLeft << " vol right " << volRight << endl; 3801 } 3802 3803 3804 void OspTree::EvalVolumeContribution(const VssRay &ray, 3805 float &volLeft, 3806 float &volRight) 3718 PrepareHeuristics(*ray, touchedViewCells); 3719 } 3720 3721 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 3722 3723 for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 3724 { 3725 Intersectable *obj = *oit; 3726 obj->Mail(); // set as belonging to front leaf 3727 3728 ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 3729 3730 for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 3731 { 3732 ViewCell *vc = *vit; 3733 MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 3734 3735 if (!vdata) // should never happen 3736 continue; 3737 3738 if (!vdata->Mailed()) 3739 { 3740 vdata->Mail(); 3741 renderCost += vc->GetVolume(); 3742 } 3743 } 3744 } 3745 3746 Debug << "here32 " << touchedViewCells.size() << endl; 3747 return renderCost; 3748 } 3749 3750 3751 void OspTree::AddObjectContribution(KdLeaf *leaf, 3752 Intersectable *obj, 3753 ViewCellContainer &touchedViewCells, 3754 float &renderCost) 3755 { 3756 obj->Mail(2); // set as belonging to both leafs 3757 3758 ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 3759 3760 for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 3761 { 3762 ViewCell *vc = *vit; 3763 3764 // if obj not previously associated with this view cell => increase render cost 3765 if (vc->Mailed(1) && 3766 !ViewCellHasMultipleReferences(obj, vc, false)) 3767 { 3768 renderCost += vc->GetVolume(); 3769 } 3770 } 3771 } 3772 3773 3774 void OspTree::SubtractObjectContribution(KdLeaf *leaf, 3775 Intersectable * obj, 3776 ViewCellContainer &touchedViewCells, 3777 float &renderCost) 3778 { 3779 obj->Mail(1); // set as belonging to back leaf 3780 ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 3781 3782 for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 3783 { 3784 ViewCell *vc = *vit; 3785 3786 // if obj was previously associated with this view cell but is not now 3787 // => decrease render cost 3788 if (vc->Mailed() && 3789 !ViewCellHasMultipleReferences(obj, vc, false)) 3790 { 3791 renderCost -= vc->GetVolume(); 3792 } 3793 } 3794 } 3795 3796 3797 void OspTree::EvalRayContribution(KdLeaf *leaf, 3798 const VssRay &ray, 3799 float &renderCost) 3807 3800 { 3808 3801 ViewCellContainer viewCells; … … 3819 3812 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 3820 3813 { 3821 // view cells can also be seen from left child node 3822 ViewCell *viewCell = *vit; 3823 3824 const float vol = viewCell->GetVolume(); 3825 3826 if (!viewCell->Mailed()) 3827 { 3828 viewCell->Mail(); 3829 3830 // we now see view cell from both nodes 3831 // => remove ref to right child node 3832 volRight -= vol; 3833 3834 debugVol += vol; 3835 } 3836 3837 // last reference into the right node 3838 if (-- viewCell->mCounter == 0) 3839 { 3840 #if 0 3841 // view cell was previousy seen from right node only 3842 // => remove from right node (matt: need this?) 3843 if (!viewCell->Mailed()) 3844 volRight -= vol; 3845 else 3846 #endif 3847 // view cell was previously seen from both nodes => 3848 // contributes only to left node now 3849 volLeft += vol; 3850 debugVol -= vol; 3851 } 3852 } 3814 EvalViewCellContribution(leaf, *vit, renderCost); 3815 } 3816 } 3817 3818 3819 void OspTree::EvalViewCellContribution(KdLeaf *leaf, 3820 ViewCell *viewCell, 3821 float &renderCost) 3822 { 3823 // view cells can also be seen from left child node 3824 const float vol = viewCell->GetVolume(); 3825 3826 if (viewCell->Mailed()) 3827 { 3828 viewCell->NewMail(2); // view cell can be seen from both nodes 3829 3830 // we now see view cell from both nodes => add contri 3831 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 3832 3833 for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 3834 { 3835 Intersectable *obj = *oit; 3836 3837 // was render cost already added? 3838 if (!ViewCellHasMultipleReferences(obj, viewCell, false) || 3839 obj->Mailed(1)) 3840 { 3841 renderCost += viewCell->GetVolume(); 3842 } 3843 } 3844 } 3845 3846 if (-- viewCell->mCounter == 0) 3847 { 3848 ViewCell::NewMail(1); // view cell can be seen from back node only 3849 3850 //MailablePvsData::NewMail(); 3851 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 3852 3853 for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 3854 { 3855 Intersectable *obj = *oit; 3856 3857 // can render cost be be reduced? 3858 if (!ViewCellHasMultipleReferences(obj, viewCell, false) || 3859 obj->Mailed()) 3860 { 3861 renderCost -= viewCell->GetVolume(); 3862 } 3863 } 3864 } 3865 } 3866 3867 3868 void OspTree::EvalHeuristicsContribution(KdLeaf *leaf, 3869 const SortableEntry &ci, 3870 float &renderCost, 3871 ViewCellContainer &touchedViewCells) 3872 { 3873 Intersectable *obj = ci.mObject; 3874 VssRay *ray = ci.mRay; 3875 3876 // switch between different types of events 3877 switch (ci.mType) 3878 { 3879 case SortableEntry::BOX_MIN: 3880 cout << "<"; 3881 AddObjectContribution(leaf, ci.mObject, touchedViewCells, renderCost); 3882 break; 3883 3884 case SortableEntry::BOX_MAX: 3885 cout << ">"; 3886 SubtractObjectContribution(leaf, ci.mObject, touchedViewCells, renderCost); 3887 break; 3888 3889 // compute volume contribution from view cells 3890 case SortableEntry::BOX_INTERSECT: 3891 cout << "i"; 3892 // process ray if the hit point with termination / origin object 3893 // is inside this kd leaf 3894 EvalRayContribution(leaf, *ray, renderCost); 3895 break; 3896 3897 default: 3898 cout << "should not come here" << endl; 3899 break; 3900 } 3901 3902 //cout << "vol left: " << volLeft << " vol right " << volRight << endl; 3853 3903 } 3854 3904 … … 3956 4006 else 3957 4007 { 3958 return ray.mOriginObject && (GetLeaf(ray.mOrigin, ray.mOriginNode) == leaf); 4008 return false; // no origin object! 4009 return ray.mOriginObject && (GetLeaf(ray.mOrigin, ray.mOriginNode) == leaf); 3959 4010 } 3960 4011 } … … 3970 4021 ); 3971 4022 } 3972 3973 4023 3974 4024 … … 3992 4042 const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 3993 4043 3994 const bool originGt = 3995 ray->mOrigin[plane.mAxis] > plane.mPosition;3996 3997 const bool terminationGt = 3998 ray->mTermination[plane.mAxis] > plane.mPosition;4044 const bool originGt = (ray->mOrigin[plane.mAxis] >= plane.mPosition); 4045 const bool originLt = (ray->mOrigin[plane.mAxis] <= plane.mPosition); 4046 4047 const bool terminationGt = (ray->mTermination[plane.mAxis] >= plane.mPosition); 4048 const bool terminationLt = (ray->mTermination[plane.mAxis] <= plane.mPosition); 3999 4049 4000 4050 // add view cell volume to front volume 4001 const bool addToFront = ((originInside && originGt) || (terminationInside && terminationGt)); 4051 const bool addToFront = 4052 ((originInside && originGt) || (terminationInside && terminationGt)); 4002 4053 4003 4054 // add view cell volume to back volume 4004 const bool addToBack = ((originInside && !originGt) || (terminationInside && !terminationGt)); 4055 const bool addToBack = 4056 ((originInside && originLt/*!originGt*/) || (terminationInside && terminationLt/*terminationGt*/)); 4005 4057 4006 4058 // classify ray with respect to the child nodes the view cells contribute … … 4016 4068 4017 4069 4018 static bool ViewCellHasMultipleReferences(Intersectable *obj,4019 ViewCell *vc,4020 bool checkOnlyMailed)4021 {4022 ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc);4023 4024 if (vdata)4025 {4026 //Debug << "sumpdf: " << vdata->mSumPdf << endl;4027 // more than one view cell sees this object inside different kd cells4028 if (!checkOnlyMailed || !vdata->Mailed())4029 {4030 vdata->Mail();//return true;4031 if (vdata->mSumPdf > 1.5f)4032 return true;4033 }4034 }4035 4036 return false;4037 }4038 4039 4040 4070 int OspTree::ClassifyRays(const RayInfoContainer &rays, 4041 4071 KdLeaf *leaf, … … 4055 4085 Intersectable *obj = ray->mOriginObject; 4056 4086 4057 if ( obj)4058 { 4059 originGt = ray->mOrigin[plane.mAxis] > plane.mPosition;4087 if (0 && obj) 4088 { 4089 originGt = ray->mOrigin[plane.mAxis] >= plane.mPosition; 4060 4090 } 4061 4091 … … 4064 4094 if (obj) 4065 4095 { 4066 terminationGt = ray->mTermination[plane.mAxis] > plane.mPosition;4096 terminationGt = ray->mTermination[plane.mAxis] >= plane.mPosition; 4067 4097 } 4068 4098 … … 4084 4114 4085 4115 4086 #if 14116 #if 0 4087 4117 4088 4118 float OspTree::EvalRenderCostDecrease(const AxisAlignedPlane &candidatePlane, … … 4121 4151 VssRay *ray = (*rit).mRay; 4122 4152 4123 // test if intersection point with one of the objects is inside this node 4124 const bool originInside = EndPointInsideNode(leaf, *ray, false); 4125 const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 4126 4127 if (originInside || terminationInside) 4128 { 4129 // add volume to volumes of left and / or right children 4130 // if one of the ray end points is inside 4131 const int classification = ClassifyRay(ray, leaf, candidatePlane); 4132 4133 ViewCellContainer viewCells; 4134 mVspTree->GetViewCells(*ray, viewCells); 4153 // add volume to volumes of left and / or right children 4154 // if one of the ray end points is inside 4155 const int classification = ClassifyRay(ray, leaf, candidatePlane); 4156 4157 ViewCellContainer viewCells; 4158 mVspTree->GetViewCells(*ray, viewCells); 4135 4159 4136 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 4137 4138 // traverse through view cells and classify them according 4139 // to them being seen from to back / front / front and back node 4140 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 4141 { 4142 ViewCell *vc = *vit; 4143 4144 // if not previously mailed 4145 if (!vc->Mailed() && !vc->Mailed(1) && !vc->Mailed(2)) 4146 { 4147 touchedViewCells.push_back(vc); 4148 } 4149 4150 // classify / mail the view cell 4151 MailViewCell(vc, classification); 4152 } 4160 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 4161 4162 // traverse through view cells and classify them according 4163 // to them being seen from to back / front / front and back node 4164 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 4165 { 4166 ViewCell *vc = *vit; 4167 4168 // if not previously mailed 4169 if (!vc->Mailed() && !vc->Mailed(1) && !vc->Mailed(2)) 4170 { 4171 touchedViewCells.push_back(vc); 4172 } 4173 4174 // classify / mail the view cell 4175 MailViewCell(vc, classification); 4153 4176 } 4154 4177 } … … 4173 4196 float additionalBackRenderCost = 0; 4174 4197 4175 ViewCellPvsData::NewMail();4198 MailablePvsData::NewMail(); 4176 4199 4177 4200 for (rit = tData.mRays->begin(); rit != tData.mRays->end(); ++ rit) … … 4296 4319 float pFrontAndBack = 0; 4297 4320 4321 Intersectable::NewMail(3); 4322 KdLeaf *leaf = tData.mNode; 4323 4298 4324 const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 4299 4300 Intersectable::NewMail(3);4301 4302 KdLeaf *leaf = tData.mNode;4303 4325 const int totalPvs = (int)leaf->mObjects.size(); 4304 4326 … … 4330 4352 obj->Mail(1); 4331 4353 } 4332 //Debug << "here3 pt: " << obj << " mail: " << obj->mMailbox - Intersectable::sMailId << endl;4333 4354 } 4334 4355 … … 4369 4390 4370 4391 // classify / mail the view cell 4371 MailViewCell(vc, classification); 4372 4373 /*if (terminationInside) 4374 objectsMap[ray->mTerminationObject].push_back(vc); 4375 if (originInside) 4376 objectsMap[ray->mOriginObject].push_back(vc);*/ 4392 MailViewCell(vc, classification); 4377 4393 } 4378 4394 } … … 4394 4410 // the object would still be part of the pvs 4395 4411 4396 float frontRc = 0; 4397 float backRc = 0; 4412 float newRc = 0; 4398 4413 float rc = 0; 4399 4414 4400 ViewCellPvsData::NewMail(); 4401 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 4402 4403 //Debug << "here53 " << touchedViewCells.size() << endl; 4415 MailablePvsData::NewMail(); 4416 //ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 4417 4404 4418 for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 4405 4419 { … … 4410 4424 { 4411 4425 ViewCell *vc = *vit; 4412 /*ObjectPvsData *vdata = vc->GetPvs().Find(obj); 4426 4427 MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 4413 4428 4414 4429 if (!vdata) 4415 4430 { 4416 vc->GetPvs().AddSample(obj, 1); 4417 newCost += vc->GetVolume(); 4418 //prop += vc->GetVolume(); 4419 }*/ 4420 4421 ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc); 4422 4423 if (!vdata || !vdata->Mailed()) 4424 { 4425 newCost += vc->GetVolume(); 4426 if (!vdata) 4427 vdata = obj->mViewCellPvs.AddSample2(vc, 1); 4431 Debug << "here86 error!!"<<endl; 4432 continue; 4433 } 4434 4435 if (!vdata->Mailed()) 4436 { 4428 4437 vdata->Mail(); 4429 } 4430 } 4431 } 4432 4433 4434 } 4438 rc += vc->GetVolume(); 4439 4440 if ((vdata->mSumPdf > 1.5) || 4441 vc->Mailed(2) || 4442 obj->Mailed(2) || 4443 (obj->Mailed() && vc->Mailed()) || 4444 (obj->Mailed(1) && vc->Mailed(1)) 4445 ) 4446 { 4447 newRc += vc->GetVolume(); 4448 } 4449 } 4450 } 4451 } 4452 4435 4453 4436 4454 ///////////////////////////// … … 4443 4461 //-- pvs rendering heuristics 4444 4462 4445 const float oldRenderCost = pOverall * totalPvs;4463 const float oldRenderCost = rc;//pOverall * totalPvs; 4446 4464 4447 4465 // sum up the terms: … … 4450 4468 // b) the right node are weighted by the #right node objects 4451 4469 // c) both nodes are weighted by the #parent node objects 4452 const float newRenderCost = pvsFront * pFront + pvsBack * pBack + totalPvs * pFrontAndBack4453 + additionalFrontRenderCost + additionalBackRenderCost;4470 const float newRenderCost = newRc//pvsFront * pFront + pvsBack * pBack + totalPvs * pFrontAndBack 4471 ;// + additionalFrontRenderCost + additionalBackRenderCost; 4454 4472 4455 4473 // normalize volume with view space volume … … 4461 4479 << " front and back p " << pFrontAndBack / viewSpaceVol << " p: " << tData.mProbability / viewSpaceVol << endl 4462 4480 << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl 4463 << "render cost decrease: " << renderCostDecrease << endl 4464 << "additional front " << additionalFrontRenderCost / viewSpaceVol4465 << " additional back " << additionalBackRenderCost / viewSpaceVol << endl;4481 << "render cost decrease: " << renderCostDecrease << endl; 4482 //<< "additional front " << additionalFrontRenderCost / viewSpaceVol 4483 //<< " additional back " << additionalBackRenderCost / viewSpaceVol << endl; 4466 4484 4467 4485 if (oldRenderCost < newRenderCost * 0.99) … … 4477 4495 } 4478 4496 #endif 4497 4479 4498 4480 4499 void OspTree::ComputeBoundingBox(const ObjectContainer &objects, … … 4724 4743 // HACK: reset nodes for the case we have used object kd tree for 4725 4744 // tree building. 4726 ray->mOrigin = NULL;4745 ray->mOriginNode = NULL; 4727 4746 ray->mTerminationNode = NULL; 4728 4747 } … … 4809 4828 4810 4829 4811 int OspTree::SplitViewCells(const AxisAlignedPlane &candidatePlane,4812 const RayInfoContainer &rays,4813 KdLeaf *leaf,4814 ViewCellContainer &frontViewCells,4815 ViewCellContainer &backViewCells,4816 ViewCellContainer &frontAndBackViewCells) const4817 {4818 ViewCellContainer touchedViewCells;4819 RayInfoContainer touchedRays;4820 4821 // sum up volume seen from the objects of left and right children4822 // => the volume is the weight for the render cost equation4823 ViewCell::NewMail(3);4824 4825 RayInfoContainer::const_iterator rit, rit_end = rays.end();4826 4827 for (rit = rays.begin(); rit < rit_end; ++ rit)4828 {4829 VssRay *ray = (*rit).mRay;4830 4831 // test if intersection point with one of the objects is inside this node4832 const bool originInside = EndPointInsideNode(leaf, *ray, false);4833 const bool terminationInside = EndPointInsideNode(leaf, *ray, true);4834 4835 if (originInside || terminationInside)4836 {4837 touchedRays.push_back(*rit);4838 // add volume to volumes of left and / or right children4839 // if one of the ray end points is inside4840 const int classification = ClassifyRay(ray, leaf, candidatePlane);4841 4842 ViewCellContainer viewCells;4843 mVspTree->GetViewCells(*ray, viewCells);4844 4845 ViewCellContainer::const_iterator vit, vit_end = viewCells.end();4846 4847 // traverse through view cells and classify them according4848 // to them being seen from to back / front / front and back node4849 for (vit = viewCells.begin(); vit != vit_end; ++ vit)4850 {4851 ViewCell *vc = *vit;4852 4853 // if not previously mailed4854 if (!vc->Mailed() && !vc->Mailed(1) && !vc->Mailed(2))4855 {4856 touchedViewCells.push_back(vc);4857 }4858 4859 // classify / mail the view cell4860 MailViewCell(*vit, classification);4861 }4862 }4863 }4864 4865 // the important view cells4866 ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end();4867 4868 for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit)4869 {4870 ViewCell *vc = *vit;4871 4872 if (vc->Mailed())4873 frontViewCells.push_back(vc);4874 else if (vc->Mailed(1))4875 backViewCells.push_back(vc);4876 else if (vc->Mailed(2))4877 frontAndBackViewCells.push_back(vc);4878 }4879 4880 return 0;4881 }4882 4883 4884 4830 int OspTree::CheckViewCellsPvs(KdLeaf *leaf, 4885 4831 const RayInfoContainer &rays) const … … 4895 4841 VssRay *ray = (*rit).mRay; 4896 4842 4897 // test if intersection point with one of the objects is inside this node 4898 const bool originInside = EndPointInsideNode(leaf, *ray, false); 4899 const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 4900 4901 if (terminationInside) 4843 if (ray->mTerminationObject) 4902 4844 { 4903 4845 Intersectable *obj = ray->mTerminationObject; … … 4910 4852 } 4911 4853 4912 if ( originInside)4854 if (ray->mOriginObject) 4913 4855 { 4914 4856 Intersectable *obj = ray->mOriginObject; … … 4938 4880 4939 4881 4940 4941 4942 4882 KdIntersectable *OspTree::GetOrCreateKdIntersectable(KdNode *node) 4943 4883 { … … 4952 4892 4953 4893 // not in map => create new entry 4954 KdIntersectable *kdObj= new KdIntersectable(node); 4955 4894 KdIntersectable *kdObj = new KdIntersectable(node); 4956 4895 mKdIntersectables[node] = kdObj; 4957 4896 … … 5014 4953 if (cf >= 0) // front volume 5015 4954 { 5016 4955 // already in back volume => in both volumes 5017 4956 if (vc->Mailed(1)) 5018 4957 { … … 5072 5011 VssRay *ray = (*rit).mRay; 5073 5012 5074 // process ray if the hit point with termination / origin object5075 // is inside this kd leaf5076 if (!((EndPointInsideNode(leaf, *ray, true)) ||5077 (EndPointInsideNode(leaf, *ray, false))))5078 continue;5079 5080 5013 ViewCellContainer viewCells; 5081 mVspTree-> CastLineSegment(ray->mOrigin, ray->mTermination, viewCells);5014 mVspTree->GetViewCells(*ray, viewCells); 5082 5015 5083 5016 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); … … 5106 5039 contribution = 0; // todo 5107 5040 5108 ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc);5041 MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 5109 5042 5110 5043 if (!vdata) … … 5120 5053 5121 5054 return true; 5055 } 5056 5057 5058 void OspTree::CollectTouchedViewCells(const RayInfoContainer &rays, 5059 ViewCellContainer &touchedViewCells) const 5060 { 5061 ViewCell::NewMail(); 5062 5063 RayInfoContainer::const_iterator rit, rit_end = rays.end(); 5064 5065 for (rit = rays.begin(); rit != rit_end; ++ rit) 5066 { 5067 VssRay *ray = (*rit).mRay; 5068 5069 ViewCellContainer viewCells; 5070 mVspTree->GetViewCells(*ray, viewCells); 5071 5072 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 5073 5074 // traverse through view cells and classify them according 5075 // to them being seen from to back / front / front and back node 5076 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 5077 { 5078 ViewCell *vc = *vit; 5079 if (!vc->Mailed()) 5080 { 5081 vc->Mail(); 5082 touchedViewCells.push_back(vc); 5083 } 5084 } 5085 } 5122 5086 } 5123 5087 … … 5127 5091 5128 5092 { 5129 RayInfoContainer::const_iterator rit, rit_end = rays.end(); 5130 5131 //ViewCell::NewMail(); Intersectable::NewMail(); 5132 ViewCellPvsData::NewMail(); 5093 MailablePvsData::NewMail(); 5094 5095 /*RayInfoContainer::const_iterator rit, rit_end = rays.end(); 5133 5096 5134 5097 for (rit = rays.begin(); rit < rit_end; ++ rit) … … 5136 5099 VssRay *ray = (*rit).mRay; 5137 5100 5138 // test if intersection point with one of the objects is inside this node 5139 const bool originInside = EndPointInsideNode(leaf, *ray, false); 5140 const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 5141 5142 if (originInside || terminationInside) 5143 { 5144 ViewCellContainer viewCells; 5145 mVspTree->GetViewCells(*ray, viewCells); 5146 5147 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 5148 5149 // traverse through view cells and classify them according 5150 // to them being seen from to back / front / front and back node 5151 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 5152 { 5153 ViewCell *vc = *vit; 5154 5155 Intersectable *obj = ray->mTerminationObject; 5156 5157 if (obj) 5158 { 5159 float contri; 5160 AddViewCellToObjectPvs(obj, vc, contri, true); 5161 } 5162 5163 obj = ray->mOriginObject; 5164 5165 if (obj) 5166 { 5167 float contri; 5168 AddViewCellToObjectPvs(obj, vc, contri, true); 5169 } 5170 } 5101 ViewCellContainer viewCells; 5102 mVspTree->GetViewCells(*ray, viewCells); 5103 5104 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 5105 5106 // traverse through view cells and classify them according 5107 // to them being seen from to back / front / front and back node 5108 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 5109 { 5110 ViewCell *vc = *vit; 5111 5112 Intersectable *obj = ray->mTerminationObject; 5113 if (obj) 5114 { 5115 float contri; 5116 AddViewCellToObjectPvs(obj, vc, contri, true); 5117 } 5118 5119 obj = ray->mOriginObject; 5120 if (obj) 5121 { 5122 float contri; 5123 AddViewCellToObjectPvs(obj, vc, contri, true); 5124 } 5125 } 5126 }*/ 5127 5128 ViewCellContainer touchedViewCells; 5129 CollectTouchedViewCells(rays, touchedViewCells); 5130 5131 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 5132 5133 for (oit = leaf->mObjects.begin(); oit < oit_end; ++ oit) 5134 { 5135 Intersectable *obj = *oit; 5136 ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 5137 5138 // traverse through view cells and classify them according 5139 // to them being seen from to back / front / front and back node 5140 for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 5141 { 5142 ViewCell *vc = *vit; 5143 float contri; 5144 AddViewCellToObjectPvs(obj, vc, contri, true); 5171 5145 } 5172 5146 } … … 5181 5155 5182 5156 { 5183 RayInfoContainer::const_iterator rit, rit_end = rays.end(); 5184 //ViewCell::NewMail(); Intersectable::NewMail(); 5185 ViewCellPvsData::NewMail(); 5186 5157 MailablePvsData::NewMail(); 5158 5159 /*RayInfoContainer::const_iterator rit, rit_end = rays.end(); 5187 5160 for (rit = rays.begin(); rit < rit_end; ++ rit) 5188 5161 { … … 5190 5163 5191 5164 // test if intersection point with one of the objects is inside this node 5192 const bool originInside = EndPointInsideNode(leaf, *ray, false); 5193 const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 5194 5195 if (originInside || terminationInside) 5196 { 5197 ViewCellContainer viewCells; 5198 mVspTree->GetViewCells(*ray, viewCells); 5199 5200 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 5201 5202 // traverse through view cells and classify them according 5203 // to them being seen from to back / front / front and back node 5204 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 5205 { 5206 ViewCell *vc = *vit; 5207 5208 Intersectable *obj = ray->mTerminationObject; 5209 if (obj) 5165 ViewCellContainer viewCells; 5166 mVspTree->GetViewCells(*ray, viewCells); 5167 5168 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 5169 5170 // traverse through view cells and classify them according 5171 // to them being seen from to back / front / front and back node 5172 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 5173 { 5174 ViewCell *vc = *vit; 5175 Intersectable *obj = ray->mTerminationObject; 5176 5177 if (obj) 5178 { 5179 MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 5180 5181 if (vdata && !vdata->Mailed()) 5210 5182 { 5211 ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc); 5212 5213 if (vdata && !vdata->Mailed()) 5214 { 5215 vdata->Mail(); 5216 obj->mViewCellPvs.RemoveSample(vc, 1); 5217 } 5218 5183 vdata->Mail(); 5184 obj->mViewCellPvs.RemoveSample(vc, 1); 5219 5185 } 5220 5221 obj = ray->mOriginObject; 5222 if (obj) 5186 } 5187 5188 obj = ray->mOriginObject; 5189 5190 if (obj) 5191 { 5192 MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 5193 5194 if (vdata && !vdata->Mailed()) 5223 5195 { 5224 ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc); 5225 5226 if (vdata && !vdata->Mailed()) 5227 { 5228 vdata->Mail(); 5229 obj->mViewCellPvs.RemoveSample(vc, 1); 5230 } 5196 vdata->Mail(); 5197 obj->mViewCellPvs.RemoveSample(vc, 1); 5231 5198 } 5199 } 5200 } 5201 }*/ 5202 5203 ViewCellContainer touchedViewCells; 5204 CollectTouchedViewCells(rays, touchedViewCells); 5205 5206 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 5207 5208 for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 5209 { 5210 Intersectable *obj = *oit; 5211 5212 // traverse through view cells and classify them according 5213 // to them being seen from to back / front / front and back node 5214 ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 5215 5216 for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 5217 { 5218 ViewCell *vc = *vit; 5219 5220 MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 5221 5222 if (vdata && !vdata->Mailed()) 5223 { 5224 vdata->Mail(); 5225 obj->mViewCellPvs.RemoveSample(vc, 1); 5232 5226 } 5233 5227 } … … 5260 5254 KdLeafContainer::const_iterator kit, kit_end = leaves.end(); 5261 5255 5262 ViewCellPvsData::NewMail();5256 MailablePvsData::NewMail(); 5263 5257 5264 5258 for (kit = leaves.begin(); kit != kit_end; ++ kit) … … 5277 5271 5278 5272 // test if intersection point with one of the objects is inside this node 5279 5280 5273 const bool originInside = EndPointInsideNode(leaf, *ray, false); 5281 5274 const bool terminationInside = EndPointInsideNode(leaf, *ray, true); … … 5305 5298 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 5306 5299 5307 //Debug << "here53 " << touchedViewCells.size() << endl;5308 5300 for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 5309 5301 { … … 5314 5306 { 5315 5307 ViewCell *vc = *vit; 5316 /*ObjectPvsData *vdata = vc->GetPvs().Find(obj);5308 PvsData *vdata = vc->GetPvs().Find(obj); 5317 5309 5318 5310 if (!vdata) … … 5320 5312 vc->GetPvs().AddSample(obj, 1); 5321 5313 newCost += vc->GetVolume(); 5322 //prop += vc->GetVolume(); 5323 }*/ 5324 5325 ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc); 5314 } 5315 5316 /* MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 5326 5317 5327 5318 if (!vdata || !vdata->Mailed()) … … 5331 5322 vdata = obj->mViewCellPvs.AddSample2(vc, 1); 5332 5323 vdata->Mail(); 5333 } 5324 }*/ 5334 5325 } 5335 5326 } … … 5397 5388 { 5398 5389 ViewCell *vc = *vit; 5399 ObjectPvsData *vdata = vc->GetPvs().Find(obj);5390 PvsData *vdata = vc->GetPvs().Find(obj); 5400 5391 5401 5392 if (!vdata) … … 5426 5417 5427 5418 char subdivisionStatsLog[100]; 5428 Environment::GetSingleton()->GetStringValue("Hierarchy.subdivisionStats", subdivisionStatsLog); 5419 Environment::GetSingleton()->GetStringValue("Hierarchy.subdivisionStats", 5420 subdivisionStatsLog); 5429 5421 mSubdivisionStats.open(subdivisionStatsLog); 5430 5422 } … … 5533 5525 5534 5526 // probabilty is voume of all "seen" view cells 5535 #if 05527 #if 1 5536 5528 const float prop = mOspTree.EvalViewCellsVolume(kdleaf, rays); 5537 5529 #else … … 5545 5537 0, 5546 5538 &rays, 5547 (int)objects.size(),5539 0,//(int)objects.size(), 5548 5540 prop, 5549 5541 mOspTree.mBoundingBox); … … 5553 5545 OspTree::OspSplitCandidate *oSplitCandidate = 5554 5546 new OspTree::OspSplitCandidate(oData); 5547 5548 mOspTree.UpdateViewCellsPvs(kdleaf, rays); 5555 5549 5556 5550 mOspTree.EvalSplitCandidate(*oSplitCandidate); … … 5755 5749 ///////////////////////////////////////////////////////////// 5756 5750 5751 5757 5752 Debug << "\n$$$$$$$$$ osp tree construction $$$$$$$$$$\n" << endl; 5758 5753 cout << "starting osp contruction ... " << endl; … … 5784 5779 float rc = mOspTree.EvalRenderCost(sampleRays); 5785 5780 5786 Debug << " My render cost evalulation: " << rc << endl;5781 Debug << "here47 My render cost evalulation: " << rc << endl; 5787 5782 5788 5783 #if 0 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
r1186 r1189 1587 1587 int FilterRays(KdLeaf *leaf, const RayInfoContainer &rays, RayInfoContainer &filteredRays); 1588 1588 1589 int SplitViewCells(1590 const AxisAlignedPlane &candidatePlane,1591 const RayInfoContainer &rays,1592 KdLeaf *leaf,1593 ViewCellContainer &frontViewCells,1594 ViewCellContainer &backViewCells,1595 ViewCellContainer &frontAndBackViewCells) const;1596 1597 1589 /** Adds the object to the pvs of the front and back leaf with a given classification. 1598 1590 … … 1641 1633 /** Evaluate the contributions of view cell volume of the left and the right view cell. 1642 1634 */ 1643 void EvalVolumeContribution(const VssRay &ray, 1644 float &volLeft, 1645 float &volRight); 1646 1635 void EvalRayContribution(KdLeaf *leaf, 1636 const VssRay &ray, 1637 float &renderCost); 1638 void EvalViewCellContribution(KdLeaf *leaf, 1639 ViewCell *viewCell, 1640 float &renderCost); 1647 1641 /** Evaluates the influence on the pvs of the event. 1648 1642 @param ve the visibility event … … 1652 1646 void EvalHeuristicsContribution(KdLeaf *leaf, 1653 1647 const SortableEntry &ci, 1654 float &volLeft, 1655 float &volRight, 1656 int &pvsLeft, 1657 int &pvsRight); 1648 float &renderCost, 1649 ViewCellContainer &touchedViewCells); 1658 1650 1659 1651 /** Prepares objects for the cost heuristics. 1660 1652 @returns pvs size of the node 1661 1653 */ 1662 float PrepareHeuristics(const OspTraversalData &tData, int &numViewCells);1654 float PrepareHeuristics(const OspTraversalData &tData, ViewCellContainer &touchedViewCells); 1663 1655 1664 1656 /** Prepares heuristics for a particular ray. 1665 1657 */ 1666 float PrepareHeuristics(const VssRay &ray, int &numViewCells);1658 void PrepareHeuristics(const VssRay &ray, ViewCellContainer &touchedViewCells); 1667 1659 1668 1660 /** Prepares construction for vsp and osp trees. … … 1726 1718 1727 1719 int UpdateViewCellsPvs(KdLeaf *leaf, const RayInfoContainer &rays) const; 1728 int OspTree::CheckViewCellsPvs(KdLeaf *leaf,1720 int CheckViewCellsPvs(KdLeaf *leaf, 1729 1721 const RayInfoContainer &rays) const; 1730 1722 bool AddViewCellToObjectPvs( … … 1741 1733 RayInfoContainer &backRays) const; 1742 1734 1735 void CollectTouchedViewCells( 1736 const RayInfoContainer &rays, 1737 ViewCellContainer &touchedViewCells) const; 1738 1739 void AddObjectContribution(KdLeaf *leaf, 1740 Intersectable * obj, 1741 ViewCellContainer &touchedViewCells, 1742 float &renderCost); 1743 void SubtractObjectContribution(KdLeaf *leaf, 1744 Intersectable * obj, 1745 ViewCellContainer &touchedViewCells, 1746 float &renderCost); 1743 1747 protected: 1744 1748 -
GTP/trunk/Lib/Vis/QtRenderer/QtGlRenderer.cpp
r1171 r1189 277 277 278 278 // Render PVS 279 std::map<Intersectable *, 280 PvsData<Intersectable *>, 281 LtSample<Intersectable *> >::const_iterator it = viewcell->GetPvs().mEntries.begin(); 279 ObjectPvsMap::const_iterator it = viewcell->GetPvs().mEntries.begin(); 282 280 283 281 pvsSize = viewcell->GetPvs().mEntries.size(); … … 341 339 342 340 // Render PVS 343 std::map<Intersectable *, 344 PvsData<Intersectable *>, 345 LtSample<Intersectable *> >::const_iterator it = viewcell->GetPvs().mEntries.begin(); 341 ObjectPvsMap::const_iterator it = viewcell->GetPvs().mEntries.begin(); 346 342 347 343 for (; it != viewcell->GetPvs().mEntries.end(); ++ it) { … … 954 950 955 951 // read back the texture 956 std::map<Intersectable *, 957 PvsData<Intersectable *>, 958 LtSample<Intersectable *> >::const_iterator it = pvs.mEntries.begin(); 952 ObjectPvsMap::const_iterator it = pvs.mEntries.begin(); 959 953 960 954 mPvsSize = pvs.mEntries.size();
Note: See TracChangeset
for help on using the changeset viewer.