Changeset 1790 for GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
- Timestamp:
- 11/25/06 04:07:13 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
r1789 r1790 206 206 @returns iterator on the sample. 207 207 */ 208 typename vector<PvsEntry<T, S> >::iterator Find(T sample, const bool checkDirty = true); 208 bool Find(T sample, 209 typename vector<PvsEntry<T, S> >::iterator &it, 210 const bool checkDirty = true); 209 211 210 212 bool GetSampleContribution(T sample, const float pdf, float &contribution); … … 391 393 float aSumPdf = 0.0f; 392 394 393 vector<PvsEntry<T, S> >::iterator oit = Find((*it).mObject); 394 395 const bool entryFound = (it != mEntries.end()) && ((*it).mObject == (*oit).mObject); 395 vector<PvsEntry<T, S> >::iterator oit; 396 const bool entryFound = Find((*it).mObject, oit); 396 397 397 398 if (entryFound) … … 427 428 (*it).mData.mSumPdf = -aSumPdf; 428 429 } else { 429 vector<PvsEntry<T, S> >::iterator oit = b.Find((*it).mObject);430 431 const bool entryFound = (it != mEntries.end()) && ((*it).mObject == (*oit).mObject);432 430 vector<PvsEntry<T, S> >::iterator oit; 431 432 const bool entryFound = b.Find((*it).mObject, oit); 433 433 434 if (entryFound) { 434 435 bSumPdf = (*oit).mData.mSumPdf; … … 461 462 for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it) 462 463 { 463 std::vector<PvsEntry<T, S> >::const_iterator bit = Find((*it).first); 464 if (bit == mEntries.end()) ++ dif; 464 vector<PvsEntry<T, S> >::iterator bit; 465 const bool entryFound = Find((*it).first, bit); 466 467 if (!entryFound) ++ dif; 465 468 } 466 469 … … 586 589 587 590 template <typename T, typename S> 588 typename std::vector<PvsEntry<T, S> >::iterator Pvs<T, S>::Find(T sample, const bool checkDirty) 589 { 591 bool Pvs<T, S>::Find(T sample, 592 typename vector<PvsEntry<T, S> >::iterator &it, 593 const bool checkDirty) 594 { 595 bool found = false; 596 590 597 PvsEntry<T, S> dummy(sample, PvsData()); 591 598 … … 593 600 //mLastSorted = 0; 594 601 vector<PvsEntry<T, S> >::iterator sorted_end = mEntries.begin() + mLastSorted; 595 if (sorted_end != mEntries.end()) 596 cout << "not entries end!! " << endl; 602 597 603 // binary search 598 vector<PvsEntry<T, S> >::iterator it = lower_bound(mEntries.begin(), sorted_end, dummy); 604 it = lower_bound(mEntries.begin(), sorted_end, dummy); 605 606 if ((it != mEntries.end()) && ((*it).mObject == sample)) 607 found = true; 599 608 600 609 // sample not found yet => search further in the unsorted part 601 if (checkDirty && 602 ((it == mEntries.end()) || ((*it).mObject != sample))) 603 { 604 vector<PvsEntry<T, S> >::const_iterator it_end = mEntries.end(); 605 for (it = sorted_end; (it != it_end) && ((*it).mObject != sample); ++ it); 606 } 607 else cout << "f "; 608 return it; 610 if (!found && checkDirty) 611 { 612 vector<PvsEntry<T, S> >::const_iterator dit, dit_end = mEntries.end(); 613 614 for (dit = sorted_end; (dit != dit_end) && ((*dit).mObject != sample); ++ dit); 615 616 if ((dit != mEntries.end()) && ((*dit).mObject == sample)) 617 found = true; 618 } 619 620 return found; 609 621 } 610 622 … … 625 637 { 626 638 ++ mSamples; 627 cout << "! "; 628 std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 629 630 if ((it != mEntries.end()) && ((*it).mObject == sample)) 631 { cout << "g"; 639 640 vector<PvsEntry<T, S> >::iterator it; 641 const bool entryFound = Find(sample, it); 642 643 if (entryFound) 644 { 632 645 S &data = (*it).mData; 633 646 data.mSumPdf += pdf; … … 635 648 } 636 649 else 637 { cout << "t";650 { 638 651 PvsEntry<T, S> entry(sample, pdf); 639 652 mEntries.insert(it, entry); … … 641 654 return pdf; 642 655 } 643 cout << " $";644 656 } 645 657 … … 654 666 655 667 template <typename T, typename S> 656 typename vector< PvsEntry<T, S> >::iterator Pvs<T, S>::AddSample2(T sample, const float pdf) 668 typename vector< PvsEntry<T, S> >::iterator Pvs<T, S>::AddSample2(T sample, 669 const float pdf) 657 670 { 658 671 ++ mSamples; 659 672 660 std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 661 662 if ((it != mEntries.end()) && ((*it).mObject == sample)) 673 vector<PvsEntry<T, S> >::iterator it; 674 const bool entryFound == Find(sample, it); 675 676 if (entryFound) 663 677 { 664 678 S &data = (*it).second; … … 674 688 return it; 675 689 } 676 677 678 /*template <typename T, typename S>679 bool Pvs<T, S>::AddSample(T sample,680 const float pdf,681 float &contribution)682 {683 ++ mSamples;684 685 std::vector<PvsEntry<T, S> >::iterator it = Find(sample);686 687 if ((it != mEntries.end()) && ((*it).mObject == sample))688 {689 S &data = (*it).mData;690 691 data.mSumPdf += pdf;692 contribution = pdf / data.mSumPdf;693 694 return false;695 }696 else697 {698 PvsEntry<T, S> entry(sample, pdf);699 700 mEntries.insert(it, entry);701 contribution = 1.0f;702 ++ mLastSorted;703 704 return true;705 }706 }*/707 690 708 691 … … 717 700 ++ mSamples; 718 701 719 std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 720 721 if ((it != mEntries.end()) && ((*it).mObject == sample)) 702 vector<PvsEntry<T, S> >::iterator it; 703 const bool entryFound = Find(sample, it); 704 705 if (entryFound) 722 706 { 723 707 S &data = (*it).mData; … … 743 727 float &contribution) 744 728 { 745 std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 746 747 if (it != mEntries.end() && ((*it).mObject == sample)) 729 vector<PvsEntry<T, S> >::iterator it; 730 const bool entryFound = Find(sample, it); 731 732 if (entryFound) 748 733 { 749 734 S &data = (*it).mData; … … 764 749 -- mSamples; 765 750 766 std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 767 768 if (it == mEntries.end()) 751 vector<PvsEntry<T, S> >::iterator it; 752 const bool entryFound = Find(sample, it); 753 754 if (!entryFound) 769 755 return false; 770 756
Note: See TracChangeset
for help on using the changeset viewer.