Changeset 1884


Ignore:
Timestamp:
12/13/06 01:13:15 (17 years ago)
Author:
bittner
Message:

temporary version, rss preprocessor not functional

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

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/Makefile

    r1883 r1884  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (2.00a) (Qt 4.1.2) on: po 11. XII 10:42:23 2006 
     3# Generated by qmake (2.00a) (Qt 4.1.2) on: st 13. XII 00:50:24 2006 
    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-msvc2005\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \ 
     65Makefile: preprocessor.pro  C:/Qt/4.1.2/mkspecs/win32-msvc.net\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/Preprocessor.cpp

    r1883 r1884  
    10171017 
    10181018 
    1019 SamplingStrategy *Preprocessor::GenerateSamplingStrategy(const int strategyId) const 
     1019SamplingStrategy *Preprocessor::GenerateSamplingStrategy(const int strategyId) 
    10201020{ 
    10211021        switch (strategyId) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1867 r1884  
    9696        /** Returns the specified sample strategy, NULL if no valid strategy. 
    9797        */ 
    98         SamplingStrategy *GenerateSamplingStrategy(const int strategyId) const; 
     98        SamplingStrategy *GenerateSamplingStrategy(const int strategyId); 
    9999 
    100100        /** Export preprocessor data. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp

    r1883 r1884  
    537537        curr = e+1; 
    538538  } 
     539 
     540  mMixtureDistribution = new MixtureDistribution(*this); 
     541  mMixtureDistribution->mDistributions = mDistributions; 
     542  mMixtureDistribution->Init(); 
     543  bool oldGenerator = false; 
    539544   
    540545  if (mLoadInitialSamples) { 
     
    545550        SimpleRayContainer rays; 
    546551         
    547         cout<<"Generating initial rays..."<<endl<<flush; 
    548          
    549         int count = 0; 
    550         int i; 
    551          
    552         // Generate initial samples 
    553         for (i=0; i < mDistributions.size(); i++) 
    554           if (mDistributions[i]->mType != SamplingStrategy::RSS_BASED_DISTRIBUTION) 
    555                 count++; 
    556          
    557         for (i=0; i < mDistributions.size(); i++) 
    558           if (mDistributions[i]->mType != SamplingStrategy::RSS_BASED_DISTRIBUTION) 
    559                 GenerateRays(mInitialSamples/count, 
    560                                          *mDistributions[i], 
    561                                          rays); 
    562          
    563          
    564          
    565          
    566         cout<<"Casting initial rays..."<<endl<<flush; 
    567         CastRays(rays, mVssRays, true, pruneInvalidRays); 
    568          
    569         ExportObjectRays(mVssRays, 1546); 
     552        if (oldGenerator) { 
     553           
     554          cout<<"Generating initial rays..."<<endl<<flush; 
     555           
     556          int count = 0; 
     557          int i; 
     558           
     559          // Generate initial samples 
     560          for (i=0; i < mDistributions.size(); i++) 
     561                if (mDistributions[i]->mType != SamplingStrategy::RSS_BASED_DISTRIBUTION) 
     562                  count++; 
     563           
     564          for (i=0; i < mDistributions.size(); i++) 
     565                if (mDistributions[i]->mType != SamplingStrategy::RSS_BASED_DISTRIBUTION) 
     566                  GenerateRays(mInitialSamples/count, 
     567                                           *mDistributions[i], 
     568                                           rays); 
     569 
     570          cout<<"Casting initial rays..."<<endl<<flush; 
     571          CastRays(rays, mVssRays, true, pruneInvalidRays); 
     572           
     573          ExportObjectRays(mVssRays, 1546); 
     574 
     575          cout<<"Computing sample contributions..."<<endl<<flush; 
     576          // evaluate contributions of the intitial rays 
     577          mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 
     578          cout<<"done.\n"<<flush; 
     579           
     580        } else { 
     581          const int batch = 1000; 
     582          for (int i=0; i < mInitialSamples; i+=batch) { 
     583                rays.clear(); 
     584                mVssRays.clear(); 
     585                mMixtureDistribution->GenerateSamples(batch, rays); 
     586                CastRays(rays, mVssRays, true, pruneInvalidRays); 
     587                mMixtureDistribution->ComputeContributions(mVssRays); 
     588          } 
     589        } 
    570590  } 
    571591   
     
    593613  } 
    594614         
    595   cout<<"Computing sample contributions..."<<endl<<flush; 
    596   // evaluate contributions of the intitial rays 
    597   mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 
    598   cout<<"done.\n"<<flush; 
    599615   
    600616  long time = GetTime(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.h

    r1867 r1884  
    77#include "Preprocessor.h" 
    88#include "VssRay.h" 
     9#include "SamplingStrategy.h" 
    910 
    1011namespace GtpVisibilityPreprocessor { 
     
    2223public: 
    2324  vector<SamplingStrategy *> mDistributions; 
     25  MixtureDistribution *mMixtureDistribution; 
    2426  int mSamplesPerPass; 
    2527  int mRssSamplesPerPass; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp

    r1883 r1884  
    19221922   
    19231923  GenerateLeafRay(params, rays, node->bbox, node->dirBBox); 
    1924  
    1925  
    19261924} 
    19271925 
     
    31173115 
    31183116 
    3119  
    3120  
    3121 } 
     3117bool 
     3118RssBasedDistribution::GenerateSample(SimpleRay &ray) 
     3119{ 
     3120  float r[5]; 
     3121 
     3122  if (mRssTree == NULL) 
     3123        return false; 
     3124   
     3125  mHalton.GetNext(5, r); 
     3126 
     3127  SimpleRayContainer rays; 
     3128  mRssTree->GenerateRay(r, rays); 
     3129  ray = rays[0]; 
     3130   
     3131  return false; 
     3132} 
     3133 
     3134void 
     3135RssBasedDistribution::Update(VssRayContainer &vssRays) 
     3136{ 
     3137  if (mRssTree == NULL) { 
     3138        mRssTree = new RssTree; 
     3139        mRssTree->SetPass(mPass); 
     3140         
     3141        /// compute view cell contribution of rays if view cells manager already constructed 
     3142        //  mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 
     3143         
     3144        mRssTree->Construct(mPreprocessor.mObjects, vssRays); 
     3145        mRssTree->stat.Print(mPreprocessor.mStats); 
     3146        cout<<"RssTree root PVS size = "<<mRssTree->GetRootPvsSize()<<endl; 
     3147         
     3148  } else { 
     3149        Debug<<"Adding rays...\n"<<flush; 
     3150        mRssTree->AddRays(vssRays); 
     3151        Debug<<"done.\n"<<flush; 
     3152        if (1) { 
     3153          //    if (mUpdateSubdivision) { 
     3154          Debug<<"Updating rss tree...\n"<<flush; 
     3155          int subdivided = mRssTree->UpdateSubdivision(); 
     3156          Debug<<"done.\n"<<flush; 
     3157          cout<<"subdivided leafs = "<<subdivided<<endl; 
     3158          cout<<"#total leaves = "<<mRssTree->stat.Leaves()<<endl; 
     3159        } 
     3160  } 
     3161  mPass++; 
     3162} 
     3163 
     3164} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h

    r1877 r1884  
    2727 
    2828#include "Containers.h" 
     29#include "SamplingStrategy.h" 
    2930 
    3031namespace GtpVisibilityPreprocessor { 
     
    11151116}; 
    11161117 
     1118 
     1119class RssBasedDistribution: public SamplingStrategy 
     1120{ 
     1121 public: 
     1122  HaltonSequence mHalton; 
     1123  RssTree *mRssTree; 
     1124  // id of sampling pass (a pass is defined by two consecutive updates) 
     1125  int mPass; 
     1126 
     1127  RssBasedDistribution(Preprocessor &preprocessor): 
     1128        SamplingStrategy(preprocessor){ 
     1129        mType = RSS_BASED_DISTRIBUTION; 
     1130        mRssTree = NULL; 
     1131        mPass = 0; 
     1132  } 
     1133   
     1134  virtual void Update(VssRayContainer &vssRays); 
     1135   
     1136private: 
     1137 
     1138  virtual bool GenerateSample(SimpleRay &ray); 
     1139   
    11171140}; 
    11181141 
     1142 
     1143}; 
     1144 
    11191145#endif // __RSSTREE_H__ 
    11201146 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp

    r1883 r1884  
    1010 
    1111 
    12 SamplingStrategy::SamplingStrategy(const Preprocessor &preprocessor):  
     12SamplingStrategy::SamplingStrategy(Preprocessor &preprocessor):  
    1313  mPreprocessor(preprocessor), mRatio(1.0f),  mTotalRays(0), mTotalContribution(0.0f) 
    1414{ 
     
    401401 
    402402 
    403 bool 
    404 RssBasedDistribution::GenerateSample(SimpleRay &ray) 
    405 { 
    406   return false; 
    407 } 
    408403 
    409404 
     
    463458MixtureDistribution::Init() 
    464459{ 
    465    
    466 } 
    467    
    468   // Generate a new sample according to a mixture distribution 
     460  for (int i=0; i < mDistributions.size(); i++) { 
     461        // small non-zero value 
     462        mDistributions[i]->mRays = 1; 
     463        // unit contribution per ray 
     464        if (1 || mDistributions[i]->mType != RSS_BASED_DISTRIBUTION) 
     465          mDistributions[i]->mContribution = 1.0f; 
     466        else 
     467          mDistributions[i]->mContribution = 0.0f; 
     468  } 
     469  UpdateRatios(); 
     470} 
     471 
     472void 
     473MixtureDistribution::Reset() 
     474{ 
     475  for (int i=0; i < mDistributions.size(); i++) { 
     476        // small non-zero value 
     477        mDistributions[i]->mRays = 1; 
     478        // unit contribution per ray 
     479        mDistributions[i]->mContribution = 1.0f; 
     480  } 
     481  UpdateRatios(); 
     482} 
     483 
     484// Generate a new sample according to a mixture distribution 
    469485bool 
    470486MixtureDistribution::GenerateSample(SimpleRay &ray) 
    471487{ 
    472  
    473   return false; 
     488  float r; 
     489  mHalton.GetNext(1, &r); 
     490 
     491  // pickup a distribution 
     492  for (int i=0; i < mDistributions.size(); i++) 
     493        if (r < mDistributions[i]->mRatio) 
     494          break; 
     495   
     496  return mDistributions[i]->GenerateSample(ray); 
    474497} 
    475498 
    476499  // add contributions of the sample to the strategies 
    477500void 
    478 MixtureDistribution::UpdateContributions(VssRayContainer &vssRays) 
    479 { 
    480  
    481 } 
    482  
    483 } 
    484  
    485  
     501MixtureDistribution::ComputeContributions(VssRayContainer &vssRays) 
     502{ 
     503  int i; 
     504   
     505  VssRayContainer::iterator it = vssRays.begin(); 
     506 
     507  for(; it != vssRays.end(); ++it) { 
     508        VssRay *ray = *it; 
     509        for (i=0; i < mDistributions.size()-1; i++) 
     510          if (mDistributions[i]->mType == ray->mDistribution) 
     511                break; 
     512        float contribution = 
     513          mPreprocessor.mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 
     514        mDistributions[i]->mContribution + contribution; 
     515        mDistributions[i]->mRays ++; 
     516  } 
     517 
     518  // now update the distributions with all the rays 
     519  for (i=0; i < mDistributions.size(); i++) 
     520        mDistributions[i]->Update(vssRays); 
     521   
     522   
     523  UpdateRatios(); 
     524} 
     525 
     526void 
     527MixtureDistribution::UpdateRatios() 
     528{ 
     529  // now compute importance (ratio) of all distributions 
     530  float sum = 0.0f; 
     531  int i; 
     532  for (i=0; i < mDistributions.size(); i++) { 
     533        float importance = mDistributions[i]->mContribution/mDistributions[i]->mRays; 
     534        mDistributions[i]->mRatio = importance; 
     535        sum += importance; 
     536  } 
     537   
     538   
     539  mDistributions[0]->mRatio /= sum; 
     540  for (i=1; i < mDistributions.size(); i++) { 
     541        float r = mDistributions[i]->mRatio / sum; 
     542        mDistributions[i]->mRatio = mDistributions[i-1]->mRatio + r; 
     543  } 
     544   
     545  cout<<"ratios: "; 
     546  for (i=0; i < mDistributions.size(); i++) 
     547        cout<<mDistributions[i]->mRatio<<" "; 
     548  cout<<endl; 
     549} 
     550} 
     551 
     552 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h

    r1883 r1884  
    4545        /** Default constructor 
    4646        */ 
    47         SamplingStrategy(const Preprocessor &preprocessor); 
     47        SamplingStrategy(Preprocessor &preprocessor); 
    4848 
    4949        virtual ~SamplingStrategy(); 
     
    5555        virtual int GenerateSamples(const int number, SimpleRayContainer &rays); 
    5656 
    57 private: 
    5857 
    5958        virtual bool GenerateSample(SimpleRay &ray) = 0; 
     59   
     60 
     61 
     62  virtual void Update(VssRayContainer &vssRays) {} 
     63 
     64 
     65 
     66  friend bool LowerRatio(const SamplingStrategy *a, const SamplingStrategy *b) { 
     67        return a->mRatio < b->mRatio; 
     68  } 
    6069 
    6170public: 
     
    7180protected: 
    7281 
    73         const Preprocessor &mPreprocessor; 
     82  Preprocessor &mPreprocessor; 
    7483 
    7584}; 
     
    8190  HaltonSequence mHalton; 
    8291   
    83   ObjectBasedDistribution(const Preprocessor &preprocessor): 
     92  ObjectBasedDistribution(Preprocessor &preprocessor): 
    8493        SamplingStrategy(preprocessor) { 
    8594        mType = OBJECT_BASED_DISTRIBUTION; 
     
    95104 public: 
    96105         
    97          ReverseObjectBasedDistribution(const Preprocessor &preprocessor): 
     106         ReverseObjectBasedDistribution(Preprocessor &preprocessor): 
    98107           SamplingStrategy(preprocessor) { 
    99108           mType = REVERSE_OBJECT_BASED_DISTRIBUTION; 
     
    110119   
    111120public: 
    112          ObjectDirectionBasedDistribution(const Preprocessor &preprocessor): 
     121         ObjectDirectionBasedDistribution(Preprocessor &preprocessor): 
    113122         SamplingStrategy(preprocessor) { 
    114123           mType = OBJECT_DIRECTION_BASED_DISTRIBUTION; 
     
    122131{ 
    123132 public: 
    124   DirectionBasedDistribution(const Preprocessor &preprocessor): 
     133  DirectionBasedDistribution(Preprocessor &preprocessor): 
    125134        SamplingStrategy(preprocessor){ 
    126135        mType = DIRECTION_BASED_DISTRIBUTION; 
     
    134143{ 
    135144 public: 
    136          DirectionBoxBasedDistribution(const Preprocessor &preprocessor): 
     145         DirectionBoxBasedDistribution(Preprocessor &preprocessor): 
    137146           SamplingStrategy(preprocessor){ 
    138147           mType = DIRECTION_BOX_BASED_DISTRIBUTION; 
     
    148157 public: 
    149158  HaltonSequence mHalton; 
    150   SpatialBoxBasedDistribution(const Preprocessor &preprocessor): 
     159  SpatialBoxBasedDistribution(Preprocessor &preprocessor): 
    151160        SamplingStrategy(preprocessor){ 
    152161        mType = DIRECTION_BOX_BASED_DISTRIBUTION; 
     
    161170{ 
    162171 public: 
    163          ViewSpaceBorderBasedDistribution(const Preprocessor &preprocessor): 
     172         ViewSpaceBorderBasedDistribution(Preprocessor &preprocessor): 
    164173           SamplingStrategy(preprocessor){ 
    165174           mType = SPATIAL_BOX_BASED_DISTRIBUTION; 
     
    174183{ 
    175184 public: 
    176          ReverseViewSpaceBorderBasedDistribution(const Preprocessor &preprocessor): 
     185         ReverseViewSpaceBorderBasedDistribution(Preprocessor &preprocessor): 
    177186           SamplingStrategy(preprocessor){ 
    178187           mType = SPATIAL_BOX_BASED_DISTRIBUTION; 
     
    184193 
    185194 
    186 class RssBasedDistribution: public SamplingStrategy 
    187 { 
    188  public: 
    189   RssBasedDistribution(const Preprocessor &preprocessor): 
    190         SamplingStrategy(preprocessor){ 
    191         mType = RSS_BASED_DISTRIBUTION; 
    192   } 
    193  
    194  
    195   virtual int GenerateSamples(const int number, SimpleRayContainer &ray) { 
    196         // TBD!!! 
    197         return 0; 
    198   } 
    199  
    200 private: 
    201   virtual bool GenerateSample(SimpleRay &ray); 
    202    
    203 }; 
    204195 
    205196 
     
    207198{ 
    208199 public: 
    209   ViewCellBorderBasedDistribution(const Preprocessor &preprocessor): 
     200  ViewCellBorderBasedDistribution(Preprocessor &preprocessor): 
    210201        SamplingStrategy(preprocessor) {} 
    211202   
     
    219210  HaltonSequence mHalton; 
    220211 
    221   GlobalLinesDistribution(const Preprocessor &preprocessor): 
     212  GlobalLinesDistribution(Preprocessor &preprocessor): 
    222213        SamplingStrategy(preprocessor) { 
    223214        mType = GLOBAL_LINES_DISTRIBUTION; 
     
    234225{ 
    235226 public: 
    236          ObjectsInteriorDistribution(const Preprocessor &preprocessor): 
     227         ObjectsInteriorDistribution(Preprocessor &preprocessor): 
    237228         SamplingStrategy(preprocessor) {} 
    238229          
     
    249240  vector<SamplingStrategy *> mDistributions; 
    250241 
    251   MixtureDistribution(const Preprocessor &preprocessor): 
     242  MixtureDistribution(Preprocessor &preprocessor): 
    252243        SamplingStrategy(preprocessor) 
    253244  { 
     
    256247  // has to called before first usage 
    257248  void Init(); 
     249 
     250  // equalize distribution contributions 
     251  void 
     252  Reset(); 
    258253   
    259254  // Generate a new sample according to a mixture distribution 
     
    261256 
    262257  // add contributions of the sample to the strategies 
    263   void UpdateContributions(VssRayContainer &vssRays); 
    264    
    265 protected: 
    266   // distributions sorted according to their contribution 
    267   // used for new sample generation accordint to the pdf 
    268   vector<SamplingStrategy *> mSortedDistributions; 
     258  void ComputeContributions(VssRayContainer &vssRays); 
     259 
     260  void 
     261  UpdateRatios(); 
     262 
    269263   
    270264}; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/default.env

    r1883 r1884  
    9090RssPreprocessor { 
    9191 
    92         distributions rss+spatial+object_direction 
     92#       distributions rss+spatial+object_direction 
     93        distributions object_direction+spatial 
    9394#       distributions object_direction 
    9495 
Note: See TracChangeset for help on using the changeset viewer.