Changeset 1952 for GTP/trunk/Lib
- Timestamp:
- 01/07/07 23:25:57 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp
r1942 r1952 7 7 #include "ArchModeler2MLRT.hxx" 8 8 9 #define DEBUG_RAYCAST 0 9 #define DEBUG_RAYCAST 0 10 10 11 11 -
GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
r1946 r1952 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (2.00a) (Qt 4.1.2) on: pá 5. I 19:57:1120073 # Generated by qmake (2.00a) (Qt 4.1.2) on: ne 7. I 23:22:46 2007 4 4 # Project: preprocessor.pro 5 5 # Template: app … … 63 63 $(MAKE) -f $(MAKEFILE).Debug uninstall 64 64 65 Makefile: preprocessor.pro C:/Qt/4.1.2/mkspecs/win32-msvc .net\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \65 Makefile: preprocessor.pro C:/Qt/4.1.2/mkspecs/win32-msvc2005\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \ 66 66 C:\Qt\4.1.2\mkspecs\features\qt_config.prf \ 67 67 C:\Qt\4.1.2\mkspecs\features\exclusive_builds.prf \ -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
r1942 r1952 45 45 Vector3 &clippedTermination) 46 46 { 47 47 48 Ray ray(origin, termination - origin, Ray::LINE_SEGMENT); 48 49 ray.Precompute(); … … 132 133 133 134 #if DEBUG_RAYCAST 134 Debug<<"PRA"<<flush; 135 #endif 136 137 // regardless of the pruneInvalidRays setting reject rays whic degenerate to a point 138 // if (EpsilonEqualV3(hitA.mPoint, hitB.mPoint, Limits::Small)) 139 // return 0; 135 static int id=0; 136 Debug<<"PRA "<<id++<<endl<<flush; 137 #endif 140 138 141 139 if (pruneInvalidRays) 142 140 { 143 if (!hitA.mObject && !hitB.mObject)144 {145 return 0;146 }147 }148 149 const bool validA =150 ValidateRay(simpleRay.mOrigin, simpleRay.mDirection, box, hitA);151 152 // note: should we check for backward valitidy also for single rays?141 if (!hitA.mObject && !hitB.mObject) { 142 return 0; 143 } 144 if (EpsilonEqualV3(hitA.mPoint, hitB.mPoint, Limits::Small)) { 145 return 0; 146 } 147 } 148 149 // regardless of the pruneInvalidRays setting reject rays whic degenerate to a point 150 const bool validA = ValidateRay(simpleRay.mOrigin, simpleRay.mDirection, box, hitA); 153 151 const bool validB = //castDoubleRay && 154 ValidateRay(simpleRay.mOrigin, -simpleRay.mDirection, box, hitB); 152 ValidateRay(simpleRay.mOrigin, -simpleRay.mDirection, box, hitB); 153 155 154 156 155 #if DEBUG_RAYCAST … … 159 158 160 159 // reset both contributions 161 if (!validA || !validB) 162 { 163 if (pruneInvalidRays) 164 return 0; 165 166 // reset both contributions of this ray 167 hitA.mObject = NULL; 168 hitB.mObject = NULL; 169 } 160 if (!validA || !validB) { 161 if (pruneInvalidRays) 162 return 0; 170 163 164 // reset both contributions of this ray 165 hitA.mObject = NULL; 166 hitB.mObject = NULL; 167 } 168 171 169 // 8.11. 2007 JB 172 170 // degenerate rays checked by geometrical constraint... … … 185 183 clipB)) 186 184 return 0; 185 187 186 if (!pruneInvalidRays || hitA.mObject) { 188 187 VssRay *vssRay = new VssRay( -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r1942 r1952 17 17 HaltonSequence SpatialBoxBasedDistribution::sHalton; 18 18 HaltonSequence ObjectDirectionBasedDistribution::sHalton; 19 HaltonSequence DirectionBasedDistribution::sHalton; 20 HaltonSequence MutationBasedDistribution::sHalton; 19 21 20 22 … … 153 155 bool DirectionBasedDistribution::GenerateSample(SimpleRay &ray) 154 156 { 155 Vector3 origin, direction; 156 mPreprocessor.mViewCellsManager->GetViewPoint(origin); 157 158 direction = UniformRandomVector(); 159 const float c = Magnitude(direction); 160 161 if (c <= Limits::Small) 162 return false; 163 164 const float pdf = 1.0f; 165 166 direction *= 1.0f / c; 167 ray = SimpleRay(origin, direction, DIRECTION_BASED_DISTRIBUTION, pdf); 168 169 return true; 157 158 float r[5]; 159 sHalton.GetNext(5, r); 160 161 Vector3 origin, direction; 162 mPreprocessor.mViewCellsManager->GetViewPoint(origin, 163 Vector3(r[2],r[3],r[4]) 164 ); 165 166 direction = UniformRandomVector(r[0], r[1]); 167 const float c = Magnitude(direction); 168 169 if (c <= Limits::Small) 170 return false; 171 172 const float pdf = 1.0f; 173 174 direction *= 1.0f / c; 175 ray = SimpleRay(origin, direction, DIRECTION_BASED_DISTRIBUTION, pdf); 176 177 return true; 170 178 } 171 179 … … 630 638 if (strcmp(curr, "reverse_viewspace_border")==0) { 631 639 mDistributions.push_back(new ReverseViewSpaceBorderBasedDistribution(mPreprocessor)); 632 } 640 } else 641 if (strcmp(curr, "mutation")==0) { 642 mDistributions.push_back(new MutationBasedDistribution(mPreprocessor)); 643 } 644 633 645 634 646 if (e==NULL) … … 641 653 } 642 654 643 } 644 645 655 656 657 void 658 MutationBasedDistribution::Update(VssRayContainer &vssRays) 659 { 660 // for (int i=0; i < mRays.size(); i++) 661 // cout<<mRays[i].mSamples<<" "; 662 // cout<<endl; 663 664 for (int i=0; i < vssRays.size(); i++) { 665 VssRay *newRay = vssRays[i]; 666 if (newRay->mPvsContribution) { 667 // add this ray 668 newRay->Ref(); 669 if (mRays.size() < mMaxRays) 670 mRays.push_back(RayEntry(newRay)); 671 else { 672 // unref the old ray 673 VssRay *oldRay = mRays[mBufferStart].mRay; 674 oldRay->Unref(); 675 if (oldRay->RefCount() == 0) 676 delete oldRay; 677 mRays[mBufferStart] = RayEntry(newRay); 678 mBufferStart++; 679 if (mBufferStart >= mMaxRays) 680 mBufferStart = 0; 681 } 682 } 683 } 684 } 685 686 bool 687 MutationBasedDistribution::GenerateSample(SimpleRay &sray) 688 { 689 float r[5]; 690 sHalton.GetNext(5, r); 691 692 if (mRays.size() == 0) { 693 // use direction based distribution 694 Vector3 origin, direction; 695 mPreprocessor.mViewCellsManager->GetViewPoint(origin, 696 Vector3(r[0], r[1], r[2])); 697 698 direction = UniformRandomVector(r[3], r[4]); 699 700 const float pdf = 1.0f; 701 sray = SimpleRay(origin, direction, MUTATION_BASED_DISTRIBUTION, pdf); 702 703 return true; 704 } 705 706 // int index = (int) (r[0]*mRays.size()); 707 // if (index >= mRays.size()) { 708 // cerr<<"mutation: index out of bounds\n"; 709 // exit(1); 710 // } 711 712 // get tail of the buffer 713 int index = (mLastIndex+1)%mRays.size(); 714 if (mRays[index].mSamples > mRays[mLastIndex].mSamples) { 715 // search back for index where this is valid 716 index = (mLastIndex - 1 + mRays.size())%mRays.size(); 717 for (int i=0; i < mRays.size(); i++) { 718 if (mRays[index].mSamples > mRays[mLastIndex].mSamples) 719 break; 720 index = (index - 1 + mRays.size())%mRays.size(); 721 } 722 // go one step back 723 index = (index+1)%mRays.size(); 724 } 725 726 VssRay *ray = mRays[index].mRay; 727 mRays[index].mSamples++; 728 mLastIndex = index; 729 730 Vector3 v; 731 // mutate the origin 732 Vector3 d = ray->GetDir(); 733 if (d.DrivingAxis() == 0) 734 v = Vector3(0, r[1]-0.5f, r[2]-0.5f); 735 else 736 if (d.DrivingAxis() == 1) 737 v = Vector3(r[1]-0.5f, 0, r[2]-0.5f); 738 else 739 v = Vector3(r[1]-0.5f, r[2]-0.5f, 0); 740 741 v=v*mOriginMutationSize; 742 743 Vector3 origin = ray->mOrigin + v; 744 745 // mutate the termination 746 if (d.DrivingAxis() == 0) 747 v = Vector3(0, r[3]-0.5f, r[4]-0.5f); 748 else 749 if (d.DrivingAxis() == 1) 750 v = Vector3(r[3]-0.5f, 0, r[4]-0.5f); 751 else 752 v = Vector3(r[3]-0.5f, r[4]-0.5f, 0); 753 754 float size = 1.5f*Magnitude(ray->mTerminationObject->GetBox().Diagonal()); 755 if (size < Limits::Small) 756 return false; 757 758 // Vector3 nv; 759 760 // if (Magnitude(v) > Limits::Small) 761 // nv = Normalize(v); 762 // else 763 // nv = v; 764 765 // v = nv*size + v*size; 766 767 v = v*size; 768 769 Vector3 termination = ray->mTermination + v; 770 771 Vector3 direction = termination - origin; 772 773 if (Magnitude(direction) < Limits::Small) 774 return false; 775 776 // shift the origin a little bit 777 origin += direction*0.05f; 778 779 direction.Normalize(); 780 781 // $$ jb the pdf is yet not correct for all sampling methods! 782 const float pdf = 1.0f; 783 784 sray = SimpleRay(origin, direction, MUTATION_BASED_DISTRIBUTION, pdf); 785 return true; 786 } 787 788 MutationBasedDistribution::MutationBasedDistribution(Preprocessor &preprocessor) : 789 SamplingStrategy(preprocessor) 790 { 791 mType = MUTATION_BASED_DISTRIBUTION; 792 mBufferStart = 0; 793 mMaxRays = 1000000; 794 795 mOriginMutationSize = 2.0f; 796 mLastIndex = 0; 797 // mOriginMutationSize = Magnitude(preprocessor.mViewCellsManager-> 798 // GetViewSpaceBox().Diagonal())*1e-3; 799 800 } 801 802 } 803 804 -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
r1949 r1952 9 9 namespace GtpVisibilityPreprocessor { 10 10 11 11 class VssRay; 12 12 class Preprocessor; 13 13 struct SimpleRay; … … 40 40 REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION, 41 41 GLOBAL_LINES_DISTRIBUTION, 42 GVS 42 GVS, 43 MUTATION_BASED_DISTRIBUTION 44 43 45 }; 44 46 … … 146 148 private: 147 149 virtual bool GenerateSample(SimpleRay &ray); 150 static HaltonSequence sHalton; 148 151 }; 149 152 … … 216 219 private: 217 220 virtual bool GenerateSample(SimpleRay &ray); 221 }; 222 223 class MutationBasedDistribution: public SamplingStrategy 224 { 225 public: 226 MutationBasedDistribution(Preprocessor &preprocessor); 227 virtual void Update(VssRayContainer &vssRays); 228 229 virtual bool RequiresRays() { return true; } 230 231 private: 232 virtual bool GenerateSample(SimpleRay &ray); 233 static HaltonSequence sHalton; 234 struct RayEntry { 235 VssRay *mRay; 236 int mSamples; 237 RayEntry(); 238 RayEntry(VssRay *r):mRay(r), mSamples(0) {} 239 }; 240 241 vector<RayEntry> mRays; 242 int mMaxRays; 243 float mOriginMutationSize; 244 int mBufferStart; 245 int mLastIndex; 218 246 }; 219 247 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1949 r1952 2039 2039 PvsFilterStatistics fstat = ApplyFilter2(viewcell, 2040 2040 false, 2041 2.0f,2041 4.0f, 2042 2042 filteredPvs); 2043 2043 -
GTP/trunk/Lib/Vis/Preprocessing/src/default.env
r1942 r1952 73 73 } 74 74 Export { 75 rays true75 rays false 76 76 numRays 5000 77 77 } … … 104 104 samplesPerPass 1000000 105 105 initialSamples 2000000 106 vssSamples 20000000106 vssSamples 500000000 107 107 vssSamplesPerPass 5000000 108 108 useImportanceSampling true … … 137 137 maxCostRatio 1.0 138 138 maxRayContribution 1.0 139 maxRays 2000000139 maxRays 1000000 140 140 maxTotalMemory 400 141 141 maxStaticMemory 200 -
GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro
r1942 r1952 116 116 117 117 CONFIG(qt) { 118 HEADERS += Qt PreprocessorThread.h QtInterface/QtGlRenderer.h \118 HEADERS += QtInterface/QtPreprocessorThread.h QtInterface/QtGlRenderer.h \ 119 119 QtInterface/QtGlViewer.h 120 SOURCES += OcclusionQuery.cpp Qt PreprocessorThread.cpp \120 SOURCES += OcclusionQuery.cpp QtInterface/QtPreprocessorThread.cpp \ 121 121 QtInterface/QtGlRenderer.cpp QtInterface/QtGlViewer.cpp 122 122 } else {
Note: See TracChangeset
for help on using the changeset viewer.