Changeset 1952


Ignore:
Timestamp:
01/07/07 23:25:57 (17 years ago)
Author:
bittner
Message:

mutation strategy

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp

    r1942 r1952  
    77#include "ArchModeler2MLRT.hxx" 
    88 
    9 #define DEBUG_RAYCAST 0  
     9#define DEBUG_RAYCAST 0 
    1010 
    1111 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Makefile

    r1946 r1952  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (2.00a) (Qt 4.1.2) on: pá 5. I 19:57:11 2007 
     3# Generated by qmake (2.00a) (Qt 4.1.2) on: ne 7. I 23:22:46 2007 
    44# Project:  preprocessor.pro 
    55# Template: app 
     
    6363        $(MAKE) -f $(MAKEFILE).Debug uninstall 
    6464 
    65 Makefile: preprocessor.pro  C:/Qt/4.1.2/mkspecs/win32-msvc.net\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \ 
     65Makefile: preprocessor.pro  C:/Qt/4.1.2/mkspecs/win32-msvc2005\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \ 
    6666                C:\Qt\4.1.2\mkspecs\features\qt_config.prf \ 
    6767                C:\Qt\4.1.2\mkspecs\features\exclusive_builds.prf \ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp

    r1942 r1952  
    4545                                                          Vector3 &clippedTermination) 
    4646{ 
     47   
    4748  Ray ray(origin, termination - origin, Ray::LINE_SEGMENT);      
    4849  ray.Precompute(); 
     
    132133 
    133134#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 
    140138         
    141139        if (pruneInvalidRays)  
    142140        { 
    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); 
    153151        const bool validB = //castDoubleRay &&  
    154                 ValidateRay(simpleRay.mOrigin, -simpleRay.mDirection, box, hitB); 
     152          ValidateRay(simpleRay.mOrigin, -simpleRay.mDirection, box, hitB); 
     153         
    155154         
    156155#if DEBUG_RAYCAST 
     
    159158         
    160159        // 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; 
    170163           
     164          // reset both contributions of this ray 
     165          hitA.mObject = NULL; 
     166          hitB.mObject = NULL; 
     167        } 
     168         
    171169        // 8.11. 2007 JB 
    172170        // degenerate rays checked by geometrical constraint... 
     
    185183                                                          clipB)) 
    186184                return 0; 
     185 
    187186          if (!pruneInvalidRays || hitA.mObject) { 
    188187                VssRay *vssRay = new VssRay( 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp

    r1942 r1952  
    1717HaltonSequence SpatialBoxBasedDistribution::sHalton; 
    1818HaltonSequence ObjectDirectionBasedDistribution::sHalton; 
     19HaltonSequence DirectionBasedDistribution::sHalton; 
     20HaltonSequence MutationBasedDistribution::sHalton; 
    1921 
    2022 
     
    153155bool DirectionBasedDistribution::GenerateSample(SimpleRay &ray) 
    154156{        
    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; 
    170178} 
    171179 
     
    630638                                  if (strcmp(curr, "reverse_viewspace_border")==0) { 
    631639                                        mDistributions.push_back(new ReverseViewSpaceBorderBasedDistribution(mPreprocessor)); 
    632                                   }  
     640                                  } else 
     641                                        if (strcmp(curr, "mutation")==0) { 
     642                                          mDistributions.push_back(new MutationBasedDistribution(mPreprocessor)); 
     643                                        }  
     644         
    633645         
    634646        if (e==NULL) 
     
    641653} 
    642654 
    643 } 
    644  
    645  
     655 
     656 
     657void 
     658MutationBasedDistribution::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 
     686bool 
     687MutationBasedDistribution::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 
     788MutationBasedDistribution::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  
    99namespace GtpVisibilityPreprocessor { 
    1010 
    11  
     11  class VssRay; 
    1212class Preprocessor; 
    1313struct SimpleRay; 
     
    4040                REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION, 
    4141          GLOBAL_LINES_DISTRIBUTION, 
    42           GVS 
     42          GVS, 
     43          MUTATION_BASED_DISTRIBUTION 
     44 
    4345        }; 
    4446 
     
    146148private: 
    147149  virtual bool GenerateSample(SimpleRay &ray); 
     150  static HaltonSequence sHalton; 
    148151}; 
    149152 
     
    216219private: 
    217220  virtual bool GenerateSample(SimpleRay &ray); 
     221}; 
     222 
     223class MutationBasedDistribution: public SamplingStrategy 
     224{ 
     225public: 
     226  MutationBasedDistribution(Preprocessor &preprocessor); 
     227  virtual void Update(VssRayContainer &vssRays); 
     228 
     229  virtual bool RequiresRays() { return true; } 
     230 
     231private: 
     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; 
    218246}; 
    219247 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1949 r1952  
    20392039                  PvsFilterStatistics fstat = ApplyFilter2(viewcell, 
    20402040                                                                                                   false, 
    2041                                                                                                    2.0f, 
     2041                                                                                                   4.0f, 
    20422042                                                                                                   filteredPvs); 
    20432043                   
  • GTP/trunk/Lib/Vis/Preprocessing/src/default.env

    r1942 r1952  
    7373        } 
    7474        Export { 
    75                 rays true 
     75                rays false 
    7676                numRays 5000 
    7777        } 
     
    104104        samplesPerPass 1000000 
    105105        initialSamples 2000000 
    106         vssSamples 20000000 
     106        vssSamples 500000000 
    107107        vssSamplesPerPass 5000000 
    108108        useImportanceSampling true 
     
    137137        maxCostRatio 1.0 
    138138        maxRayContribution 1.0 
    139         maxRays         2000000 
     139        maxRays         1000000 
    140140        maxTotalMemory  400 
    141141        maxStaticMemory 200 
  • GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro

    r1942 r1952  
    116116 
    117117CONFIG(qt) { 
    118 HEADERS += QtPreprocessorThread.h QtInterface/QtGlRenderer.h \ 
     118HEADERS += QtInterface/QtPreprocessorThread.h QtInterface/QtGlRenderer.h \ 
    119119QtInterface/QtGlViewer.h 
    120 SOURCES += OcclusionQuery.cpp QtPreprocessorThread.cpp \ 
     120SOURCES += OcclusionQuery.cpp QtInterface/QtPreprocessorThread.cpp \ 
    121121QtInterface/QtGlRenderer.cpp QtInterface/QtGlViewer.cpp  
    122122} else { 
Note: See TracChangeset for help on using the changeset viewer.