Changeset 1877


Ignore:
Timestamp:
12/11/06 08:31:01 (17 years ago)
Author:
bittner
Message:

sampling updates

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

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h

    r1867 r1877  
    184184  Vector3 GetRandomPoint() const; 
    185185  Vector3 GetRandomSurfacePoint() const; 
    186         Vector3 GetUniformRandomSurfacePoint() const; 
     186  Vector3 GetUniformRandomSurfacePoint() const; 
    187187 
    188188  Vector3 GetPoint(const Vector3 &p) const { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp

    r1867 r1877  
    25042504 
    25052505 
    2506 void BvHierarchy::CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects) 
     2506void BvHierarchy::CollectObjects(const AxisAlignedBox3 &box, 
     2507                                                                 ObjectContainer &objects) 
    25072508{ 
    25082509  stack<BvhNode *> nodeStack; 
    2509  
     2510   
    25102511  nodeStack.push(mRoot); 
    25112512 
    2512   while (!nodeStack.empty())  
    2513         { 
     2513  while (!nodeStack.empty()) { 
    25142514        BvhNode *node = nodeStack.top(); 
    25152515         
    25162516        nodeStack.pop(); 
    2517          
    2518         if (node->IsLeaf())  
    2519           { 
    2520                 BvhLeaf *leaf = (BvhLeaf *)node; 
    2521                 if (Overlap(box, leaf->GetBoundingBox())) { 
    2522                   Intersectable *object = leaf; 
    2523                   if (!object->Mailed()) { 
    2524                         object->Mail(); 
    2525                         objects.push_back(object); 
    2526                   } 
    2527                 } 
    2528           }  
     2517        if (node->IsLeaf()) { 
     2518          BvhLeaf *leaf = (BvhLeaf *)node; 
     2519          if (Overlap(box, leaf->GetBoundingBox())) { 
     2520                Intersectable *object = leaf; 
     2521                if (!object->Mailed()) { 
     2522                  object->Mail(); 
     2523                  objects.push_back(object); 
     2524                } 
     2525          } 
     2526        }  
    25292527        else  
    25302528          { 
    25312529                BvhInterior *interior = (BvhInterior *)node; 
    2532                  
    2533                 if (Overlap(box, interior->GetBoundingBox())) 
    2534                   nodeStack.push(interior->GetFront()); 
    2535                  
    2536                 if (Overlap(box, interior->GetBoundingBox())) 
    2537                   nodeStack.push(interior->GetBack()); 
     2530                if (Overlap(box, interior->GetBoundingBox())) { 
     2531                  bool pushed = false; 
     2532                  if (!interior->GetFront()->Mailed()) { 
     2533                        nodeStack.push(interior->GetFront()); 
     2534                        pushed = true; 
     2535                  } 
     2536                  if (!interior->GetBack()->Mailed()) { 
     2537                        nodeStack.push(interior->GetBack()); 
     2538                        pushed = true; 
     2539                  } 
     2540                  // avoid traversal of this node in the next query 
     2541                  if (!pushed) 
     2542                        interior->Mail(); 
     2543                } 
    25382544          } 
    2539         } 
     2545  } 
    25402546} 
    25412547 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1844 r1877  
    221221        int NumberOfFaces() const { return 6; }; 
    222222         
    223         int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point,  
     223  int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point,  
    224224                                                          GtpVisibilityPreprocessor::Vector3 &normal) 
    225225        { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r1876 r1877  
    19151915                                        "false"); 
    19161916 
     1917        RegisterOption("RssPreprocessor.distributions", 
     1918                                   optString, 
     1919                                   "rss_distributions=", 
     1920                                   "rss+spatial+object"); 
     1921         
    19171922        RegisterOption("RssTree.hybridDepth", optInt, "hybrid_depth=", "10"); 
    19181923        RegisterOption("RssTree.maxDepth", optInt, "kd_depth=", "12"); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h

    r1867 r1877  
    113113  virtual float GetArea() const {return 0; } 
    114114  virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0; 
     115  virtual int GetRandomSurfacePoint(const float u, 
     116                                                                        const float v, 
     117                                                                        Vector3 &point, 
     118                                                                        Vector3 &normal) { 
     119        cerr<<"GetRandomSurfacePoint(u,v...) not yet implemented"<<endl; 
     120        return 1; 
     121  } 
    115122 
    116123  virtual int GetRandomEdgePoint(Vector3 &point, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp

    r1867 r1877  
    8787 
    8888 
     89int 
     90TriangleIntersectable::GetRandomSurfacePoint(const float u, 
     91                                                                                         const float v, 
     92                                                                                         Vector3 &point, 
     93                                                                                         Vector3 &normal) 
     94{ 
     95  // random barycentric coordinates 
     96  float a = u; 
     97  float b = v; 
     98  float c = 1.0f - u - v; 
     99   
     100  point = mItem.mVertices[0] * a + mItem.mVertices[1] * b + mItem.mVertices[2] * c; 
     101  normal = mItem.GetNormal(); 
     102   
     103  return 0; 
     104} 
     105 
     106 
     107 
    89108int TriangleIntersectable::GetRandomVisibleSurfacePoint(Vector3 &point, 
    90109                                                                                                                Vector3 &normal, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h

    r1768 r1877  
    136136 
    137137 
     138 
    138139template<typename T> 
    139140int IntersectableWrapper<T>::GetRandomEdgePoint(Vector3 &point, 
     
    203204        int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 
    204205 
     206        int GetRandomSurfacePoint(const float u, 
     207                                                          const float v, 
     208                                                          Vector3 &point, Vector3 &normal); 
     209 
     210         
    205211        int GetRandomVisibleSurfacePoint(Vector3 &point, 
    206212                                                                         Vector3 &normal, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Makefile

    r1876 r1877  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (2.00a) (Qt 4.1.2) on: pá 8. XII 21:21:57 2006 
     3# Generated by qmake (2.00a) (Qt 4.1.2) on: ne 10. XII 21:55:07 2006 
    44# Project:  preprocessor.pro 
    55# Template: app 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h

    r1867 r1877  
    184184        int Compress() {return 0;} 
    185185        int GetSize() const {return (int)mEntries.size();} 
    186         bool Empty() const {return mEntries.empty();} 
    187  
     186  bool Empty() const {return mEntries.empty();} 
     187 
     188  void Reserve(const int n) { mEntries.reserve(n); } 
    188189        /** Normalize the visibility of entries in order to get  
    189190                comparable results. 
     
    231232        */ 
    232233        void Sort(); 
     234 
     235  /** Sort pvs entries assume that the pvs contains unique entries 
     236   */ 
     237  void SimpleSort(); 
    233238 
    234239        /** Adds sample to PVS. Assumes that the pvs is sorted 
     
    307312                // way we can achieve logarithmic behaviour for insertion and find 
    308313                const int dirtySize = (int)mEntries.size() - mLastSorted; 
    309                 return dirtySize > (int)(log((double)mEntries.size()) / log(2.0)); 
     314                return dirtySize > 4*(int)(log((double)mEntries.size()) / log(2.0)); 
    310315        } 
    311316 
     
    362367        mEntries = newPvs.mEntries; 
    363368        mLastSorted = (int)mEntries.size(); 
     369} 
     370 
     371template <typename T, typename S> 
     372void Pvs<T, S>::SimpleSort() 
     373{ 
     374  sort(mEntries.begin(), mEntries.end()); 
     375  mLastSorted = (int)mEntries.size(); 
    364376} 
    365377 
     
    587599                                         const bool checkDirty) 
    588600{ 
    589         bool found = false; 
    590  
    591         PvsEntry<T, S> dummy(sample, PvsData()); 
    592  
    593         // only check clean part 
    594         // $$ TMP JB 
    595         // mLastSorted = 0; 
    596         vector<PvsEntry<T, S> >::iterator sorted_end = mEntries.begin() + mLastSorted; 
    597  
    598         // binary search 
    599         it = lower_bound(mEntries.begin(), sorted_end, dummy); 
    600  
    601         if ((it != mEntries.end()) && ((*it).mObject == sample)) 
    602                 found = true; 
    603  
    604         // sample not found yet => search further in the unsorted part 
    605         if (!found && checkDirty) 
    606         { 
    607                 vector<PvsEntry<T, S> >::const_iterator dit, dit_end = mEntries.end(); 
    608  
    609                 for (dit = sorted_end; (dit != dit_end) && ((*dit).mObject != sample); ++ dit) ; 
    610                  
    611                 if ((dit != mEntries.end()) && ((*dit).mObject == sample)) 
    612                         found = true; 
    613         } 
    614          
    615         return found; 
     601  bool found = false; 
     602   
     603  PvsEntry<T, S> dummy(sample, PvsData()); 
     604   
     605  // only check clean part 
     606  vector<PvsEntry<T, S> >::iterator sorted_end = mEntries.begin() + mLastSorted; 
     607   
     608  // binary search 
     609  it = lower_bound(mEntries.begin(), sorted_end, dummy); 
     610   
     611  if ((it != mEntries.end()) && ((*it).mObject == sample)) 
     612        found = true; 
     613   
     614  // sample not found yet => search further in the unsorted part 
     615  if (!found && checkDirty) { 
     616        vector<PvsEntry<T, S> >::const_iterator dit, dit_end = mEntries.end(); 
     617         
     618        for (dit = sorted_end; (dit != dit_end) && ((*dit).mObject != sample); ++ dit) ; 
     619         
     620        if (dit != dit_end) 
     621          found = true; 
     622  } 
     623   
     624  return found; 
    616625} 
    617626 
     
    698707        const bool entryFound = Find(sample, it); 
    699708 
    700         if (entryFound) 
    701         { 
    702                 S &data = (*it).mData; 
    703  
    704                 data.mSumPdf += pdf; 
    705                 //contribution = pdf / data.mSumPdf; 
    706  
    707                 return false; 
    708         } 
    709         else  
    710         { 
    711                 AddSampleDirty(sample, pdf); 
    712                 //contribution = 1.0f; 
    713  
    714                 return true; 
     709        if (entryFound) { 
     710          S &data = (*it).mData; 
     711           
     712          data.mSumPdf += pdf; 
     713          //contribution = pdf / data.mSumPdf; 
     714           
     715          return false; 
     716        } 
     717        else { 
     718          AddSampleDirty(sample, pdf); 
     719          //contribution = 1.0f; 
     720          return true; 
    715721        } 
    716722} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp

    r1876 r1877  
    148148         
    149149  if (viewcell) { 
    150                 mViewCellsManager->ApplyFilter2(viewcell, 
    151                                                                                                                                                 false, 
    152                                                                                                                                                 1.0f, 
    153                                                                                                                                                 pvs); 
    154                  
    155                 pvsSize = 0; 
    156                 SetupCamera(); 
    157                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    158                 glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE); 
     150        mViewCellsManager->ApplyFilter2(viewcell, 
     151                                                                        false, 
     152                                                                        1.0f, 
     153                                                                        pvs); 
     154         
     155        pvsSize = 0; 
     156        SetupCamera(); 
     157        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     158        glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE); 
    159159                 
    160160           
  • GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h

    r1867 r1877  
    324324  static int sSimpleRayId; 
    325325  SimpleRay(): mType(Ray::LOCAL_RAY) { 
    326         mId = sSimpleRayId++; 
     326        //      mId = sSimpleRayId++; 
    327327  } 
    328328   
    329329  SimpleRay(const Vector3 &o, const Vector3 &d, const float p=1.0f): 
    330330        mOrigin(o), mDirection(d), mPdf(p), mType(Ray::LOCAL_RAY) {      
    331         mId = sSimpleRayId++; 
     331        //      mId = sSimpleRayId++; 
    332332  } 
    333333         
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp

    r1876 r1877  
    6868  case SamplingStrategy::RSS_BASED_DISTRIBUTION: 
    6969  case SamplingStrategy::RSS_SILHOUETTE_BASED_DISTRIBUTION: 
    70                 if (mRssTree) { 
    71                   result = GenerateImportanceRays(mRssTree, number, rays); 
    72                 } 
    73                 break; 
    74                  
     70        if (mRssTree) { 
     71          result = GenerateImportanceRays(mRssTree, number, rays); 
     72        } 
     73        break; 
     74         
    7575  default: 
    7676        result = Preprocessor::GenerateRays(number, strategy, rays); 
     
    411411  for (int i=0; i < distributions.size(); i++) { 
    412412        distributions[i]->mRatio = distributions[i]->mContribution/ 
    413           (TIME_WEIGHT*distributions[i]->mTime + 
    414            (1 - TIME_WEIGHT)*distributions[i]->mRays); 
     413          (Limits::Small + 
     414           (TIME_WEIGHT*distributions[i]->mTime + 
     415                (1 - TIME_WEIGHT)*distributions[i]->mRays) 
     416           ); 
    415417 
    416418#if 1 
     
    438440        Halton<4> halton; 
    439441 
    440 //      for (int i=1; i < 7; i++)  
    441 //        cout<<i<<" prime= "<<FindPrime(i)<<endl; 
     442        //      for (int i=1; i < 7; i++)  
     443        //        cout<<i<<" prime= "<<FindPrime(i)<<endl; 
    442444         
    443445        Material mA, mB; 
     
    467469   
    468470  // use ray buffer to export ray animation 
    469   const bool useRayBuffer = true; 
     471  const bool useRayBuffer = false; 
    470472   
    471473  vector<VssRayContainer> rayBuffer(50); 
     
    492494  int rssSamples = 0; 
    493495 
    494   if (mUseRssTree) 
    495                 mDistributions.push_back(new RssBasedDistribution(*this)); 
    496  
    497    
    498   if (1) { 
    499         // mDistributions.push_back(new SpatialBoxBasedDistribution(*this)); 
    500         //  mDistributions.push_back(new DirectionBasedDistribution(*this)); 
    501         mDistributions.push_back(new ObjectDirectionBasedDistribution(*this)); 
    502         //  mDistributions.push_back(new ReverseObjectBasedDistribution(*this)); 
    503         mDistributions.push_back(new ObjectBasedDistribution(*this)); 
    504         mDistributions.push_back(new ReverseViewSpaceBorderBasedDistribution(*this)); 
    505   } else { 
    506         mDistributions.push_back(new GlobalLinesDistribution(*this)); 
    507         mDistributions.push_back(new SpatialBoxBasedDistribution(*this)); 
     496  // now decode distribution string 
     497  char buff[1024]; 
     498  Environment::GetSingleton()->GetStringValue("RssPreprocessor.distributions", 
     499                                                                                          buff); 
     500   
     501  char *curr = buff; 
     502  mUseRssTree = false; 
     503  while (1) { 
     504        char *e = strchr(curr,'+'); 
     505        if (e!=NULL) { 
     506          *e=0; 
     507        } 
     508         
     509        if (strcmp(curr, "rss")==0) { 
     510          mDistributions.push_back(new RssBasedDistribution(*this)); 
     511          mUseRssTree = true; 
     512        } else 
     513          if (strcmp(curr, "object")==0) { 
     514                mDistributions.push_back(new ObjectBasedDistribution(*this)); 
     515          } else 
     516                if (strcmp(curr, "spatial")==0) { 
     517                  mDistributions.push_back(new SpatialBoxBasedDistribution(*this)); 
     518                } else 
     519                  if (strcmp(curr, "global")==0) { 
     520                        mDistributions.push_back(new GlobalLinesDistribution(*this)); 
     521                  } else 
     522                        if (strcmp(curr, "direction")==0) { 
     523                          mDistributions.push_back(new DirectionBasedDistribution(*this)); 
     524                        } else 
     525                          if (strcmp(curr, "object_direction")==0) { 
     526                                mDistributions.push_back(new ObjectDirectionBasedDistribution(*this)); 
     527                          } else 
     528                                if (strcmp(curr, "reverse_object")==0) { 
     529                                  mDistributions.push_back(new ReverseObjectBasedDistribution(*this)); 
     530                                } else 
     531                                  if (strcmp(curr, "reverse_viewspace_border")==0) { 
     532                                        mDistributions.push_back(new ReverseViewSpaceBorderBasedDistribution(*this)); 
     533                                  }  
     534         
     535        if (e==NULL) 
     536          break; 
     537        curr = e+1; 
    508538  } 
    509539   
     
    517547        cout<<"Generating initial rays..."<<endl<<flush; 
    518548         
    519         if (mUseImportanceSampling) { 
    520           int count = 0; 
    521           int i; 
    522  
    523           // Generate initial samples 
    524           for (i=0; i < mDistributions.size(); i++) 
    525                 if (mDistributions[i]->mType != SamplingStrategy::RSS_BASED_DISTRIBUTION) 
    526                   count++; 
    527            
    528           for (i=0; i < mDistributions.size(); i++) 
    529                 if (mDistributions[i]->mType != SamplingStrategy::RSS_BASED_DISTRIBUTION) 
    530                   GenerateRays(mInitialSamples/count, 
    531                                            *mDistributions[i], 
    532                                            rays); 
    533            
    534         } else { 
    535           int rayType = SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION; 
    536           if (mObjectBasedSampling) 
    537                 rayType = SamplingStrategy::OBJECT_BASED_DISTRIBUTION; 
    538           else 
    539                 if (mDirectionalSampling) 
    540                   rayType = SamplingStrategy::DIRECTION_BASED_DISTRIBUTION; 
    541           cout<<"Generating rays..."<<endl; 
    542  
    543           Preprocessor::GenerateRays(mRssSamplesPerPass, rayType, rays); 
    544         } 
     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         
    545564         
    546565         
    547566        cout<<"Casting initial rays..."<<endl<<flush; 
    548567        CastRays(rays, mVssRays, true, pruneInvalidRays); 
    549  
     568         
    550569        ExportObjectRays(mVssRays, 1546); 
    551570  } 
     
    574593  } 
    575594         
    576   if (mUseViewcells) { 
    577  
    578         cout<<"Computing sample contributions..."<<endl<<flush; 
    579         // evaluate contributions of the intitial rays 
    580         mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 
    581         cout<<"done.\n"<<flush; 
    582  
    583         long time = GetTime(); 
    584         totalTime = TimeDiff(startTime, time)*1e-3f; 
    585         lastTime = time; 
    586          
    587         mStats << 
    588           "#Pass\n" <<mPass<<endl<< 
    589           "#RssPass\n" <<rssPass<<endl<< 
    590           "#Time\n" << totalTime <<endl<< 
    591           "#TotalSamples\n" <<totalSamples<<endl<< 
    592           "#RssSamples\n" <<rssSamples<<endl; 
    593  
    594         { 
    595           VssRayContainer contributingRays; 
    596           mVssRays.GetContributingRays(contributingRays, 0); 
    597           mStats<<"#NUM_CONTRIBUTING_RAYS\n"<<(int)contributingRays.size()<<endl; 
    598           if (mExportRays) { 
    599                 char filename[64]; 
    600                 sprintf(filename, "rss-crays-%04d.x3d", 0); 
    601                 ExportRays(filename, contributingRays, mExportNumRays); 
    602           } 
    603         } 
    604          
    605            
    606         // viewcells->UpdatePVS(newVssRays); 
    607         Debug<<"Valid viewcells before set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; 
    608         // cull viewcells with PVS > median (0.5f) 
    609         //mViewCellsManager->SetValidityPercentage(0, 0.5f);  
    610         //      mViewCellsManager->SetValidityPercentage(0, 1.0f);  
    611         Debug<<"Valid viewcells after set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; 
    612  
    613         mVssRays.PrintStatistics(mStats); 
    614         mViewCellsManager->PrintPvsStatistics(mStats); 
    615  
    616  
    617         if (0) { 
    618           char str[64]; 
    619           sprintf(str, "tmp/v-"); 
    620            
    621           // visualization 
    622           const bool exportRays = true; 
    623           const bool exportPvs = true; 
    624           ObjectContainer objects; 
    625           mViewCellsManager->ExportSingleViewCells(objects, 
    626                                                                                            1000, 
    627                                                                                            false, 
    628                                                                                            exportPvs, 
    629                                                                                            exportRays, 
    630                                                                                            10000, 
    631                                                                                            str); 
    632         } 
    633            
     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; 
     599   
     600  long time = GetTime(); 
     601  totalTime = TimeDiff(startTime, time)*1e-3f; 
     602  lastTime = time; 
     603   
     604  mStats << 
     605        "#Pass\n" <<mPass<<endl<< 
     606        "#RssPass\n" <<rssPass<<endl<< 
     607        "#Time\n" << totalTime <<endl<< 
     608        "#TotalSamples\n" <<totalSamples<<endl<< 
     609        "#RssSamples\n" <<rssSamples<<endl; 
     610   
     611  { 
     612        VssRayContainer contributingRays; 
     613        mVssRays.GetContributingRays(contributingRays, 0); 
     614        mStats<<"#NUM_CONTRIBUTING_RAYS\n"<<(int)contributingRays.size()<<endl; 
     615        if (mExportRays) { 
     616          char filename[64]; 
     617          sprintf(filename, "rss-crays-%04d.x3d", 0); 
     618          ExportRays(filename, contributingRays, mExportNumRays); 
     619        } 
     620  } 
     621   
     622   
     623  // viewcells->UpdatePVS(newVssRays); 
     624  Debug<<"Valid viewcells before set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; 
     625  // cull viewcells with PVS > median (0.5f) 
     626  //mViewCellsManager->SetValidityPercentage(0, 0.5f);  
     627  //    mViewCellsManager->SetValidityPercentage(0, 1.0f);  
     628  Debug<<"Valid viewcells after set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; 
     629   
     630  mVssRays.PrintStatistics(mStats); 
     631  mViewCellsManager->PrintPvsStatistics(mStats); 
     632   
     633   
     634  if (0) { 
     635        char str[64]; 
     636        sprintf(str, "tmp/v-"); 
     637         
     638        // visualization 
     639        const bool exportRays = true; 
     640        const bool exportPvs = true; 
     641        ObjectContainer objects; 
     642        mViewCellsManager->ExportSingleViewCells(objects, 
     643                                                                                         1000, 
     644                                                                                         false, 
     645                                                                                         exportPvs, 
     646                                                                                         exportRays, 
     647                                                                                         10000, 
     648                                                                                         str); 
     649  } 
     650   
     651  if (renderer) { 
    634652        ComputeRenderError(); 
    635653  } 
    636  
    637   //  return 1; 
    638654   
    639655  rssPass++; 
     
    647663  //  mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 
    648664 
    649   if (mUseImportanceSampling) { 
    650  
    651         if (mUseRssTree) { 
    652           mRssTree->Construct(mObjects, mVssRays); 
    653          
    654           mRssTree->stat.Print(mStats); 
    655           cout<<"RssTree root PVS size = "<<mRssTree->GetRootPvsSize()<<endl; 
    656            
    657           if (mExportRssTree) { 
    658                 ExportRssTree("rss-tree-100.x3d", mRssTree, Vector3(1,0,0)); 
    659                 ExportRssTree("rss-tree-001.x3d", mRssTree, Vector3(0,0,1)); 
    660                 ExportRssTree("rss-tree-101.x3d", mRssTree, Vector3(1,0,1)); 
    661                 ExportRssTree("rss-tree-101m.x3d", mRssTree, Vector3(-1,0,-1)); 
    662                 ExportRssTreeLeaves(mRssTree, 10); 
    663           } 
    664         } 
    665  
    666         if (mExportPvs) { 
    667           ExportPvs("rss-pvs-initial.x3d", mRssTree); 
    668         } 
    669   } 
    670  
     665  if (mUseRssTree) { 
     666        mRssTree->Construct(mObjects, mVssRays); 
     667         
     668        mRssTree->stat.Print(mStats); 
     669        cout<<"RssTree root PVS size = "<<mRssTree->GetRootPvsSize()<<endl; 
     670         
     671        if (mExportRssTree) { 
     672          ExportRssTree("rss-tree-100.x3d", mRssTree, Vector3(1,0,0)); 
     673          ExportRssTree("rss-tree-001.x3d", mRssTree, Vector3(0,0,1)); 
     674          ExportRssTree("rss-tree-101.x3d", mRssTree, Vector3(1,0,1)); 
     675          ExportRssTree("rss-tree-101m.x3d", mRssTree, Vector3(-1,0,-1)); 
     676          ExportRssTreeLeaves(mRssTree, 10); 
     677        } 
     678  } 
     679   
     680  if (mExportPvs) { 
     681        ExportPvs("rss-pvs-initial.x3d", mRssTree); 
     682  } 
     683   
     684   
    671685  // keep only rss 
    672686  //  mDistributions.resize(1); 
     
    678692        static VssRayContainer tmpVssRays; 
    679693 
    680         rays.reserve((int)(1.1f*mRssSamplesPerPass)); 
     694        cout<<"H1"<<endl<<flush; 
     695 
     696        //rays.reserve((int)(1.1f*mRssSamplesPerPass)); 
     697 
     698        cout<<"H10"<<endl<<flush; 
    681699 
    682700        rays.clear(); 
    683701        vssRays.clear(); 
    684702        tmpVssRays.clear(); 
    685  
     703         
    686704        int castRays = 0; 
    687         if (mUseImportanceSampling) { 
    688  
    689           NormalizeRatios(mDistributions); 
    690            
    691           long t1; 
    692  
    693           for (int i=0; i < mDistributions.size(); i++) { 
    694                 t1 = GetTime(); 
    695                 rays.clear(); 
    696                 tmpVssRays.clear(); 
    697                 if (mDistributions[i]->mRatio != 0) { 
    698                   GenerateRays(int(mRssSamplesPerPass*mDistributions[i]->mRatio), 
    699                                            *mDistributions[i], 
    700                                            rays); 
    701                    
    702                   rays.NormalizePdf((float)rays.size()); 
    703                    
    704                   CastRays(rays, tmpVssRays, true, pruneInvalidRays); 
    705                   castRays += (int)rays.size(); 
    706  
    707                   cout<<"Computing sample contributions..."<<endl<<flush; 
    708  
     705 
     706        cout<<"H11"<<endl<<flush; 
     707 
     708        NormalizeRatios(mDistributions); 
     709         
     710        long t1; 
     711        cout<<"H2"<<endl<<flush; 
     712        for (int i=0; i < mDistributions.size(); i++) { 
     713          t1 = GetTime(); 
     714          rays.clear(); 
     715          tmpVssRays.clear(); 
     716          if (mDistributions[i]->mRatio != 0) { 
     717                GenerateRays(int(mRssSamplesPerPass*mDistributions[i]->mRatio), 
     718                                         *mDistributions[i], 
     719                                         rays); 
     720                 
     721                rays.NormalizePdf((float)rays.size()); 
     722                 
     723                CastRays(rays, tmpVssRays, true, pruneInvalidRays); 
     724                castRays += (int)rays.size(); 
     725                 
     726                cout<<"Computing sample contributions..."<<endl<<flush; 
     727                 
    709728#if ADD_RAYS_IN_PLACE  
    710                   mDistributions[i]->mContribution = 
    711                         mViewCellsManager->ComputeSampleContributions(tmpVssRays, true, false); 
     729                float contribution = 
     730                  mViewCellsManager->ComputeSampleContributions(tmpVssRays, true, false); 
    712731#else 
    713                   mDistributions[i]->mContribution = 
    714                         mViewCellsManager->ComputeSampleContributions(tmpVssRays, false, true); 
     732                float contribution = 
     733                  mViewCellsManager->ComputeSampleContributions(tmpVssRays, false, true); 
    715734#endif 
    716                   cout<<"done."<<endl; 
    717                 } 
    718  
    719                 mDistributions[i]->mTime = TimeDiff(t1, GetTime()); 
    720                 //              mDistributions[i]->mRays = (int)rays.size(); 
    721                 mDistributions[i]->mRays = (int)tmpVssRays.size() + 1; 
    722                 //              mStats<<"#RssRelContrib"<<endl<<contributions[0]/nrays[0]<<endl; 
    723                 vssRays.insert(vssRays.end(), tmpVssRays.begin(), tmpVssRays.end() ); 
    724           } 
    725  
    726           EvaluateRatios(mDistributions); 
    727            
    728           // add contributions of all rays at once... 
    729 #if !ADD_RAYS_IN_PLACE  
    730           mViewCellsManager->AddSampleContributions(vssRays); 
    731 #endif     
    732         } 
    733         else { 
    734                 int rayType = SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION; 
    735           if (mObjectBasedSampling) 
    736                   rayType = SamplingStrategy::OBJECT_BASED_DISTRIBUTION; 
    737           else 
    738                 if (mDirectionalSampling) 
    739                         rayType = SamplingStrategy::DIRECTION_BASED_DISTRIBUTION; 
    740  
    741           cout<<"Generating rays..."<<endl; 
    742  
    743           Preprocessor::GenerateRays(mRssSamplesPerPass, rayType, rays); 
    744           cout<<"done."<<endl; 
    745  
    746           cout<<"Casting rays..."<<endl;          CastRays(rays, vssRays, true); 
    747           cout<<"done."<<endl; 
    748           castRays += (int)rays.size(); 
    749           if (mUseViewcells) { 
    750                 /// compute view cell contribution of rays 
    751                 cout<<"Computing sample contributions..."<<endl; 
    752                 mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 
     735                mDistributions[i]->mContribution = contribution; 
     736                mDistributions[i]->mTotalContribution += contribution; 
     737                 
    753738                cout<<"done."<<endl; 
    754739          } 
    755                  
    756740           
    757         } 
     741          mDistributions[i]->mTime = TimeDiff(t1, GetTime()); 
     742          //            mDistributions[i]->mRays = (int)rays.size(); 
     743          mDistributions[i]->mRays = (int)tmpVssRays.size(); 
     744          mDistributions[i]->mTotalRays = (int)tmpVssRays.size(); 
     745 
     746          //            mStats<<"#RssRelContrib"<<endl<<contributions[0]/nrays[0]<<endl; 
     747          vssRays.insert(vssRays.end(), tmpVssRays.begin(), tmpVssRays.end() ); 
     748        } 
     749         
     750        EvaluateRatios(mDistributions); 
     751         
     752        // add contributions of all rays at once... 
     753#if !ADD_RAYS_IN_PLACE  
     754        mViewCellsManager->AddSampleContributions(vssRays); 
     755#endif     
     756         
     757   
    758758        totalSamples += castRays; 
    759759        rssSamples += (int)vssRays.size(); 
    760  
     760         
    761761        cout<<"Generated "<<castRays<<" rays, progress "<<100.0f*totalSamples/((float) mRssSamples + 
    762762                                                                                                                                                   mInitialSamples)<<"%\n"; 
    763763         
    764  
     764         
    765765        long time = GetTime(); 
    766766        totalTime += TimeDiff(lastTime, time); 
     
    773773          "#TotalSamples\n" <<totalSamples<<endl<< 
    774774          "#RssSamples\n" <<rssSamples<<endl; 
    775  
    776  
    777         if (mUseViewcells) { 
    778           Debug<<"Print statistics...\n"<<flush; 
    779           vssRays.PrintStatistics(mStats); 
    780           mViewCellsManager->PrintPvsStatistics(mStats); 
    781           Debug<<"done.\n"<<flush; 
    782         } 
    783  
    784  
     775         
     776         
     777        Debug<<"Print statistics...\n"<<flush; 
     778        vssRays.PrintStatistics(mStats); 
     779        mViewCellsManager->PrintPvsStatistics(mStats); 
     780        Debug<<"done.\n"<<flush; 
     781         
    785782        if (renderer && mPass > 0) { 
     783          Debug<<"Computing render errror..."<<endl<<flush; 
    786784          char buf[100]; 
    787           if (mUseImportanceSampling) 
    788                 { 
    789                   sprintf(buf, "snap/i-%02d-", mPass); 
    790                    
    791                   renderer->SetSnapPrefix(buf); 
    792                 } 
    793           else 
    794                 { 
    795                   sprintf(buf, "snap/r-%02d-", mPass); 
    796                    
    797                   renderer->SetSnapPrefix(buf); 
    798                 } 
     785          sprintf(buf, "snap/i-%02d-", mPass); 
     786           
     787          renderer->SetSnapPrefix(buf); 
    799788           
    800789          renderer->SetSnapErrorFrames(true); 
    801         } 
    802          
    803         ComputeRenderError(); 
     790          ComputeRenderError(); 
     791          Debug<<"done."<<endl<<flush; 
     792        } 
    804793         
    805794        // epxort rays before adding them to the tree -> some of them can be deleted 
    806  
     795         
    807796        if (mExportRays) { 
     797          Debug<<"Exporting rays..."<<endl<<flush; 
    808798          char filename[64]; 
    809           if (mUseImportanceSampling) 
    810                 sprintf(filename, "rss-rays-i%04d.x3d", rssPass); 
    811           else 
    812                 sprintf(filename, "rss-rays-%04d.x3d", rssPass); 
     799          sprintf(filename, "rss-rays-i%04d.x3d", rssPass); 
    813800           
    814            
    815  
    816801          if (useRayBuffer) 
    817802                vssRays.SelectRays(mExportNumRays, rayBuffer[mPass], true); 
     
    825810          sprintf(filename, "rss-crays-%04d.x3d", rssPass); 
    826811          ExportRays(filename, contributingRays, mExportNumRays); 
     812 
     813          Debug<<"done."<<endl<<flush; 
    827814        } 
    828815 
     
    831818        // already when adding into the tree 
    832819        // do not add those rays which have too low or no contribution.... 
    833  
    834          
    835         if (mUseRssTree && mUseImportanceSampling) { 
     820        if (mUseRssTree) { 
    836821          Debug<<"Adding rays...\n"<<flush; 
    837822          mRssTree->AddRays(vssRays); 
     
    856841         
    857842         
    858         if (!mUseImportanceSampling || !mUseRssTree) 
     843        if (!mUseRssTree) 
    859844          CLEAR_CONTAINER(vssRays); 
    860845        // otherwise the rays get deleted by the rss tree update according to RssTree.maxRays .... 
     
    869854  } 
    870855   
    871   if (mUseViewcells) { 
    872  
    873         if(0) { 
    874           VssRayContainer selectedRays; 
    875           int desired = mViewCellsManager->GetVisualizationSamples(); 
    876            
    877           mVssRays.SelectRays(desired, selectedRays); 
    878            
    879           mViewCellsManager->Visualize(mObjects, selectedRays); 
    880           } 
    881          
    882         // view cells after sampling 
    883         mViewCellsManager->PrintStatistics(Debug); 
    884          
    885         EvalViewCellHistogram(); 
    886          
    887         //-- render simulation after merge 
    888         cout << "\nevaluating bsp view cells render time after sampling ... "; 
    889          
    890         mRenderSimulator->RenderScene(); 
    891         SimulationStatistics ss; 
    892         mRenderSimulator->GetStatistics(ss); 
    893          
    894         cout << " finished" << endl; 
    895         cout << ss << endl; 
    896         Debug << ss << endl; 
    897   } 
    898  
    899  
    900   if (useRayBuffer && mExportRays && mUseImportanceSampling) { 
     856  if(0) { 
     857        VssRayContainer selectedRays; 
     858        int desired = mViewCellsManager->GetVisualizationSamples(); 
     859         
     860        mVssRays.SelectRays(desired, selectedRays); 
     861         
     862        mViewCellsManager->Visualize(mObjects, selectedRays); 
     863  } 
     864   
     865  // view cells after sampling 
     866  mViewCellsManager->PrintStatistics(Debug); 
     867 
     868  EvalViewCellHistogram(); 
     869   
     870  //-- render simulation after merge 
     871  cout << "\nEvaluating view cells render time after sampling ... "; 
     872   
     873  mRenderSimulator->RenderScene(); 
     874  SimulationStatistics ss; 
     875  mRenderSimulator->GetStatistics(ss); 
     876   
     877  cout << " finished" << endl; 
     878  cout << ss << endl; 
     879  Debug << ss << endl; 
     880   
     881  if (useRayBuffer && mExportRays) { 
    901882        char filename[64]; 
    902883        sprintf(filename, "rss-rays-i.x3d"); 
     
    905886        ExportRayAnimation(filename, rayBuffer); 
    906887  } 
    907            
    908  
     888   
     889   
    909890  // do not delete rss tree now - can be used for visualization.. 
    910891#if 0 
     
    914895#endif 
    915896 
    916   //mViewCellsManager->ExportViewCells("visibility.xml", 
    917   //                                                                     true); 
    918    
    919897   
    920898  return true; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp

    r1876 r1877  
    675675          float oldCost = (float)leaf->rays.size()*pvsSize; 
    676676          info.costRatio = newCost/oldCost; 
     677          break; 
    677678        } 
    678679        } 
     
    14161417 
    14171418  int inactive=0; 
     1419  Debug<<"Deleting rays..."<<endl<<flush; 
    14181420 
    14191421  for(VssRayContainer::const_iterator ri = remove.begin(); 
     
    14281430  } 
    14291431 
     1432  Debug<<"done."<<endl<<flush; 
    14301433 
    14311434  //  cout<<"all/inactive"<<remove.size()<<"/"<<inactive<<endl; 
    1432    
     1435  Debug<<"Adding rays..."<<endl<<flush; 
     1436 
    14331437  for(VssRayContainer::const_iterator ri = add.begin(); 
    14341438      ri != add.end(); 
     
    14391443  } 
    14401444 
     1445  Debug<<"done."<<endl<<flush; 
     1446 
    14411447  stat.rayRefs += add.size() - remove.size(); 
    14421448 
     1449  Debug<<"Updating statistics..."<<endl<<flush; 
    14431450  UpdateTreeStatistics(); 
     1451  Debug<<"done."<<endl<<flush; 
     1452 
    14441453  // check whether the tree should be prunned 
    14451454  if (stat.rayRefs > mMaxRays) { 
     1455        Debug<<"Prunning rays..."<<endl<<flush; 
    14461456        PruneRays(mMaxRays); 
     1457        Debug<<"done."<<endl<<flush; 
    14471458        //      UpdateTreeStatistics(); 
    14481459  } 
    1449    
     1460 
    14501461} 
    14511462 
     
    24862497 
    24872498int 
    2488 RssTree::PruneRays(RssTreeLeaf *leaf, 
    2489                                    const float contributionThreshold) 
     2499RssTree::PruneRaysRandom(RssTreeLeaf *leaf, 
     2500                                                 const float ratio) 
    24902501{ 
    24912502  int i; 
     
    24932504   
    24942505  for (j=0, i=0; i < leaf->rays.size(); i++) { 
    2495          
    2496         if (leaf->rays[i].mRay->mWeightedPvsContribution > contributionThreshold) { 
    2497           // copy a valid sample 
    2498           leaf->rays[j] = leaf->rays[i]; 
    2499           j++; 
    2500         } else { 
    2501           // delete the ray 
    2502           leaf->rays[i].mRay->Unref(); 
    2503           if (leaf->rays[i].mRay->RefCount() != 0) { 
    2504                 cerr<<"Error: refcount!=0, but"<<leaf->rays[j].mRay->RefCount()<<endl; 
    2505                 exit(1); 
    2506           } 
    2507           delete leaf->rays[i].mRay; 
    2508         } 
    2509   } 
    2510  
    2511  
    2512   leaf->rays.resize(j); 
    2513   int removed = (i-j); 
    2514   stat.rayRefs -= removed; 
    2515   return removed; 
    2516 } 
    2517  
    2518 int 
    2519 RssTree::PruneRaysRandom(RssTreeLeaf *leaf, 
    2520                                                  const float ratio) 
    2521 { 
    2522   int i; 
    2523   int j; 
    2524    
    2525   for (j=0, i=0; i < leaf->rays.size(); i++) { 
    2526          
    25272506        if (Random(1.0f) < ratio) { 
    25282507          // copy a valid sample 
     
    25862565                                   ) 
    25872566{ 
    2588   bool globalPrunning = false; 
    25892567 
    25902568  stack<RssTreeNode *> tstack; 
     
    25962574  Debug<<"Prunning rays...\nOriginal size "<<stat.rayRefs<<endl<<flush; 
    25972575 
    2598   if (globalPrunning) { 
    2599         VssRayContainer allRays; 
    2600         allRays.reserve(stat.rayRefs); 
    2601         CollectRays(allRays); 
    2602         sort(allRays.begin(), 
    2603                  allRays.end(), 
    2604                  GreaterWeightedPvsContribution); 
    2605          
    2606         if ( maxRays >= allRays.size() ) 
    2607           return 0; 
    2608  
    2609         float contributionThreshold = allRays[desired]->mWeightedPvsContribution; 
    2610          
    2611         PushRoots(tstack); 
    2612          
    2613         while (!tstack.empty()) { 
    2614           RssTreeNode *node = tstack.top(); 
    2615           tstack.pop(); 
    2616            
    2617           if (node->IsLeaf()) { 
    2618                 RssTreeLeaf *leaf = (RssTreeLeaf *)node; 
    2619                 prunned += PruneRays(leaf, contributionThreshold); 
    2620           } else { 
    2621                 RssTreeInterior *in = (RssTreeInterior *)node; 
    2622                 // both nodes for directional splits 
    2623                 tstack.push(in->front); 
    2624                 tstack.push(in->back); 
    2625           } 
    2626         } 
    2627   } else { 
    2628         // prune random rays from each leaf so that the ratio's remain the same 
    2629         PushRoots(tstack); 
    2630  
    2631         if ( maxRays >= stat.rayRefs ) 
    2632           return 0; 
    2633          
    2634         float ratio = desired/(float)stat.rayRefs; 
    2635          
    2636         while (!tstack.empty()) { 
    2637           RssTreeNode *node = tstack.top(); 
    2638           tstack.pop(); 
    2639            
    2640           if (node->IsLeaf()) { 
    2641                 RssTreeLeaf *leaf = (RssTreeLeaf *)node; 
    2642                 // prunned += PruneRaysRandom(leaf, ratio); 
    2643                 prunned += PruneRaysContribution(leaf, ratio); 
    2644           } else { 
    2645                 RssTreeInterior *in = (RssTreeInterior *)node; 
    2646                 // both nodes for directional splits 
    2647                 tstack.push(in->front); 
    2648                 tstack.push(in->back); 
    2649           } 
    2650         } 
    2651  
    2652          
    2653  
    2654  
    2655   } 
    2656    
    2657    
     2576  // prune random rays from each leaf so that the ratio's remain the same 
     2577  PushRoots(tstack); 
     2578   
     2579  if ( maxRays >= stat.rayRefs ) 
     2580        return 0; 
     2581   
     2582  float ratio = desired/(float)stat.rayRefs; 
     2583   
     2584  while (!tstack.empty()) { 
     2585        RssTreeNode *node = tstack.top(); 
     2586        tstack.pop(); 
     2587         
     2588        if (node->IsLeaf()) { 
     2589          RssTreeLeaf *leaf = (RssTreeLeaf *)node; 
     2590          prunned += PruneRaysRandom(leaf, ratio); 
     2591          //prunned += PruneRaysContribution(leaf, ratio); 
     2592        } else { 
     2593          RssTreeInterior *in = (RssTreeInterior *)node; 
     2594          // both nodes for directional splits 
     2595          tstack.push(in->front); 
     2596          tstack.push(in->back); 
     2597        } 
     2598  } 
    26582599   
    26592600  Debug<<"Remained "<<stat.rayRefs<<" rays"<<endl<<flush; 
     
    28362777RssTree::ComputeImportance(RssTreeLeaf *leaf)  
    28372778{ 
     2779  if (leaf->mTotalRays) 
     2780        leaf->mImportance = leaf->mTotalContribution / leaf->mTotalRays; 
     2781  else 
     2782        leaf->mImportance = 0.0f; 
     2783  return; 
     2784   
    28382785  if (0)  
    28392786        leaf->mImportance = leaf->GetAvgRayContribution(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h

    r1876 r1877  
    433433  RayInfoContainer rays; 
    434434  int mTotalRays; 
    435          
     435  float mTotalContribution; 
     436   
    436437  bool mValidPvs; 
    437438   
     
    440441  RssTreeLeaf(RssTreeInterior *p, 
    441442                          const int nRays 
    442                           ):RssTreeNode(p), rays(), mPvsSize(0), mTotalRays(0), mValidPvs(false) { 
     443                          ):RssTreeNode(p), rays(), mPvsSize(0), mTotalRays(0), 
     444                                mTotalContribution(0.0f), mValidPvs(false) { 
    443445    rays.reserve(nRays); 
    444446  } 
     
    455457   
    456458  void AddRay(const RayInfo &data) { 
    457                 mValidPvs = false; 
    458     rays.push_back(data); 
    459                 mTotalRays++; 
    460                 data.mRay->Ref(); 
     459        mValidPvs = false; 
     460        rays.push_back(data); 
     461        mTotalRays++; 
     462        mTotalContribution += 
     463          ABS_CONTRIBUTION_WEIGHT*data.mRay->mPvsContribution + 
     464          (1.0f - ABS_CONTRIBUTION_WEIGHT)*data.mRay->mRelativePvsContribution; 
     465        data.mRay->Ref(); 
    461466  } 
    462467         
     
    10661071 
    10671072  int 
    1068   PruneRays(RssTreeLeaf *leaf, 
    1069                         const float contributionThreshold); 
    1070   int 
    10711073  PruneRaysRandom(RssTreeLeaf *leaf, 
    10721074                                  const float ratio); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp

    r1867 r1877  
    1111 
    1212SamplingStrategy::SamplingStrategy(const Preprocessor &preprocessor):  
    13   mPreprocessor(preprocessor), mRatio(1.0f) 
    14 { 
     13  mPreprocessor(preprocessor), mRatio(1.0f),  mTotalRays(0), mTotalContribution(0.0f) 
     14{ 
     15   
    1516} 
    1617 
     
    7172        Vector3 origin, direction;  
    7273 
    73         mPreprocessor.mViewCellsManager->GetViewPoint(origin); 
    74  
     74        float r[5]; 
     75        mHalton.GetNext(5, r); 
     76 
     77        mPreprocessor.mViewCellsManager->GetViewPoint(origin, Vector3(r[2],r[3],r[4])); 
     78         
    7579        Vector3 point; 
    7680        Vector3 normal; 
    77         //cout << "y"; 
    78         const int i = (int)RandomValue(0, (float)mPreprocessor.mObjects.size() - 0.5f); 
     81 
     82        r[0] *= mPreprocessor.mObjects.size()-1; 
     83        const int i = (int)r[0]; 
    7984 
    8085        Intersectable *object = mPreprocessor.mObjects[i]; 
    8186 
    82         object->GetRandomSurfacePoint(point, normal); 
     87        // take the remainder as a parameter over objects surface 
     88        r[0] -= (float)i; 
     89         
     90        object->GetRandomSurfacePoint(r[0], r[1], point, normal); 
     91 
    8392        direction = point - origin; 
    84  
    85         // $$ jb the pdf is yet not correct for all sampling methods! 
    86         const float c = Magnitude(direction); 
    87  
     93         
     94        const float c = Magnitude(direction); 
     95         
    8896        if (c <= Limits::Small)  
    8997                return false; 
     
    176184 
    177185  float r[6]; 
    178   halton.GetNext(r); 
     186  mHalton.GetNext(6, r); 
    179187  mPreprocessor.mViewCellsManager->GetViewPoint(origin, Vector3(r[0],r[1],r[2])); 
    180188   
     
    405413  for (i=0; i < tries; i++) { 
    406414        float r[4]; 
    407         halton.GetNext(r); 
     415        mHalton.GetNext(4, r); 
    408416         
    409417#if 0 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h

    r1867 r1877  
    5757        int mType; 
    5858        int mRays; 
    59         float mContribution; 
     59        float mContribution; 
    6060        float mTime; 
    6161        float mRatio; 
    6262 
     63  int mTotalRays; 
     64  float mTotalContribution; 
    6365protected: 
    6466 
     
    7173{ 
    7274 public: 
    73          
     75  HaltonSequence mHalton; 
     76   
    7477  ObjectBasedDistribution(const Preprocessor &preprocessor): 
    7578        SamplingStrategy(preprocessor) { 
     
    136139{ 
    137140 public: 
    138   Halton<6> halton; 
     141  HaltonSequence mHalton; 
    139142  SpatialBoxBasedDistribution(const Preprocessor &preprocessor): 
    140143        SamplingStrategy(preprocessor){ 
     
    205208{ 
    206209public: 
    207   Halton<4> halton; 
     210  HaltonSequence mHalton; 
    208211  //HaltonSequence mHalton; 
    209212 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1867 r1877  
    120120mPvsCost(0), 
    121121mEntriesInPvs(0), 
    122 mPvsSizeValid(false) 
     122mPvsSizeValid(false), 
     123mFilteredPvsSize(0) 
    123124{ 
    124125        mId = -100; 
     
    133134mMergeCost(0), 
    134135mPvsCost(0), 
    135 mPvsSizeValid(false) 
     136mPvsSizeValid(false), 
     137mFilteredPvsSize(0) 
    136138//mMailbox(0) 
    137139{ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1876 r1877  
    2727 
    2828 
    29 // warning: Should not count origin object for sampling  
    30 // because it disturbs heuristics 
    31 #define SAMPLE_ORIGIN_OBJECTS 0  // matt temp 
    3229 
    3330// $$JB HACK 
     
    18711868                 
    18721869                if (evaluateFilter) { 
    1873                   ObjectPvs filteredPvs = viewcell->GetPvs(); 
     1870                  ObjectPvs filteredPvs; 
    18741871                  PvsFilterStatistics fstat = ApplyFilter2(viewcell, 
    1875                                                                                                                                                                                         false, 
    1876                                                                                                                                                                                         2.0f, 
    1877                                                                                                                                                                                         filteredPvs); 
     1872                                                                                                  false, 
     1873                                                                                                  2.0f, 
     1874                                                                                                  filteredPvs); 
    18781875                   
    18791876                  float filteredCost = filteredPvs.EvalPvsCost(); 
    18801877                  stat.avgFilteredPvs += filteredCost; 
    18811878                  stat.avgFilterContribution += filteredCost - pvsCost; 
    1882  
     1879                   
    18831880                  stat.avgFilterRadius += fstat.mAvgFilterRadius; 
    18841881                  int sum = fstat.mGlobalFilterCount + fstat.mLocalFilterCount; 
     
    18871884                          (float) sum; 
    18881885                  } 
    1889                    
    18901886                   
    18911887                } else { 
     
    20122008 
    20132009 
    2014 float ViewCellsManager::ComputeSampleContribution(VssRay &ray, 
     2010 
     2011#define PVS_ADD_DIRTY 1 
     2012 
     2013float 
     2014ViewCellsManager::ComputeSampleContribution(VssRay &ray, 
    20152015                                                                                                  const bool addRays, 
    20162016                                                                                                  const bool storeViewCells) 
     
    20182018  ray.mPvsContribution = 0; 
    20192019  ray.mRelativePvsContribution = 0.0f; 
    2020  
     2020   
    20212021  if (ray.mTerminationObject==NULL) 
    20222022        return 0.0f; 
     
    20262026  static Ray hray; 
    20272027  hray.Init(ray); 
    2028   //hray.mFlags |= Ray::CULL_BACKFACES; 
    2029   //Ray hray(ray); 
    2030    
     2028 
    20312029  float tmin = 0, tmax = 1.0; 
    20322030   
     
    20392037  ViewCell::NewMail(); 
    20402038   
    2041   //    if (ray.mPdf!=1.0f) 
    2042   //      cout<<ray.mPdf<<" "; 
    2043    
    2044    
    20452039  // traverse the view space subdivision 
    20462040  CastLineSegment(origin, termination, viewcells); 
    20472041   
    20482042  if (storeViewCells) 
    2049         {       // copy viewcells memory efficiently 
     2043        {        
     2044          // copy viewcells memory efficiently 
    20502045          ray.mViewCells.reserve(viewcells.size()); 
    20512046          ray.mViewCells = viewcells; 
    20522047        } 
    2053    
    2054   Intersectable *obj = GetIntersectable(ray, true); 
    20552048   
    20562049  ViewCellContainer::const_iterator it = viewcells.begin(); 
    20572050   
     2051  Intersectable *terminationObj = GetIntersectable(ray, true); 
     2052   
     2053   
    20582054  for (; it != viewcells.end(); ++ it)  
    20592055        { 
    20602056          ViewCell *viewcell = *it; 
    2061           // tests if view cell is in valid view space 
     2057           
    20622058          if (viewcell->GetValid()) 
    2063                 { 
     2059                {       // if ray not outside of view space 
    20642060                  float contribution; 
    20652061                   
    2066                   if (ray.mTerminationObject)  {                         
    2067                         if (viewcell->GetPvs().GetSampleContribution(obj, 
    2068                                                                                                                  ray.mPdf, 
    2069                                                                                                                  contribution)) { 
    2070                           ++ ray.mPvsContribution; 
     2062                  if (terminationObj)  
     2063                        { 
     2064                          // todo: maybe not correct for kd node pvs 
     2065                          if (viewcell->GetPvs().GetSampleContribution( 
     2066                                                                                                                   terminationObj, ray.mPdf, contribution)) 
     2067                                { 
     2068                                  ++ ray.mPvsContribution; 
     2069                                  if (addRays) { 
     2070#if PVS_ADD_DIRTY 
     2071                                        viewcell->GetPvs().AddSampleDirtyCheck(terminationObj, ray.mPdf); 
     2072                                        if (viewcell->GetPvs().RequiresResort()) { 
     2073                                          viewcell->GetPvs().SimpleSort(); 
     2074                                        } 
     2075#else 
     2076                                        viewcell->GetPvs().AddSample(terminationObj, ray.mPdf); 
     2077#endif 
     2078                                  } 
     2079                                } 
     2080                           
     2081                          ray.mRelativePvsContribution += contribution; 
    20712082                        } 
    2072                          
    2073                         ray.mRelativePvsContribution += contribution; 
    2074                         // $$ test of different contribution measure 
    2075                         //                                      ray.mRelativePvsContribution += 1.0f/(viewcell->GetPvs().GetSize() + 10.0f); 
    2076                          
    2077                   } 
    2078                    
    2079 #if SAMPLE_ORIGIN_OBJECTS 
    2080                    
    2081                   // for directional sampling it is important to count only contributions 
    2082                   // made in one direction!!! 
    2083                   // the other contributions of this sample will be counted for the oposite ray! 
    2084  
    2085                         if (ray.mOriginObject &&  
    2086                                 viewcell->GetPvs().GetSampleContribution(ray.mOriginObject, 
    2087                                                                                                                                                                                                  ray.mPdf, 
    2088                                                                                                                                                                                                  contribution)) 
    2089                                 { 
    2090                                         ++ ray.mPvsContribution; 
    2091                                         ray.mRelativePvsContribution += contribution; 
    2092                                 } 
    2093 #endif 
    2094                 } 
    2095         } 
    2096  
    2097         // if true, the sampled entities are stored in the pvs 
    2098         if (addRays) 
    2099         { 
    2100                 for (it = viewcells.begin(); it != viewcells.end(); ++ it)  
    2101                 { 
    2102                         ViewCell *viewcell = *it; 
    2103              
    2104                         if (viewcell->GetValid()) 
    2105                         { 
    2106                                 // if view point is valid, add new object to the pvs 
    2107                           if (ray.mTerminationObject) 
    2108                                 {  
    2109                                   viewcell->GetPvs().AddSample(obj, ray.mPdf); 
    2110                                 }                                
    2111 #if SAMPLE_ORIGIN_OBJECTS 
    2112                                  if (ray.mOriginObject) 
    2113                                  {  
    2114                                          viewcell->GetPvs().AddSample(ray.mOriginObject, ray.mPdf); 
    2115                                  } 
    2116 #endif 
    2117                         } 
    2118                 } 
    2119         } 
    2120  
    2121         return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution + 
    2122           (1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution; 
    2123 } 
     2083                } 
     2084        } 
     2085   
     2086  return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution + 
     2087        (1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution; 
     2088} 
     2089 
    21242090 
    21252091 
     
    26272593 
    26282594 
    2629 #if 1 
    26302595PvsFilterStatistics 
    26312596ViewCellsManager::ApplyFilter2(ViewCell *viewCell, 
    2632                                                                                                                         const bool useViewSpaceFilter, 
    2633                                                                                                                         const float filterSize, 
    2634                                                                                                                         ObjectPvs &pvs, 
    2635                                                                                                                         vector<AxisAlignedBox3> *filteredBoxes 
    2636                                                                                                                         ) 
    2637 { 
    2638         //cout<<"y"; 
     2597                                                          const bool useViewSpaceFilter, 
     2598                                                          const float filterSize, 
     2599                                                          ObjectPvs &pvs, 
     2600                                                          vector<AxisAlignedBox3> *filteredBoxes 
     2601                                                          ) 
     2602{ 
     2603  //cout<<"y"; 
    26392604  PvsFilterStatistics stats; 
    26402605 
     
    26422607  Vector3 center = vbox.Center(); 
    26432608  // copy the PVS 
     2609  Intersectable::NewMail(); 
    26442610  ObjectPvs basePvs = viewCell->GetPvs(); 
    2645   Intersectable::NewMail(); 
    2646  
    26472611  ObjectPvsIterator pit = basePvs.GetIterator(); 
    26482612 
     2613  pvs.Reserve(viewCell->GetFilteredPvsSize()); 
     2614 
    26492615#if !USE_KD_PVS 
    2650   // first mark all object from this pvs 
     2616  // first mark all objects from this pvs 
    26512617  while (pit.HasMoreEntries()) {                 
    2652                 ObjectPvsEntry entry = pit.Next(); 
    2653                  
    2654                 Intersectable *object = entry.mObject; 
    2655                 object->Mail(); 
     2618        ObjectPvsEntry entry = pit.Next(); 
     2619         
     2620        Intersectable *object = entry.mObject; 
     2621        object->Mail(); 
    26562622  } 
    26572623#endif 
    2658  
     2624   
    26592625  int pvsSize = 0; 
    26602626  int nPvsSize = 0; 
     
    26812647   
    26822648  if (useViewSpaceFilter) { 
    2683                 //      float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 
    2684                 float radius = viewCellRadius/100.0f; 
    2685                 vbox.Enlarge(radius); 
    2686                 cout<<"vbox = "<<vbox<<endl; 
    2687                 ViewCellContainer viewCells; 
    2688                 ComputeBoxIntersections(vbox, viewCells); 
    2689                  
    2690                 ViewCellContainer::const_iterator it = viewCells.begin(), 
    2691                         it_end = viewCells.end(); 
    2692                 int i = 0; 
    2693                 for (i=0; it != it_end; ++ it, ++ i) 
    2694                         if ((*it) != viewCell) { 
    2695                                 //cout<<"v"<<i<<" pvs="<<(*it)->GetPvs().mEntries.size()<<endl; 
    2696                                 basePvs.MergeInPlace((*it)->GetPvs()); 
    2697                         } 
    2698                  
    2699                 // update samples and globalC 
    2700                 samples = (float)pvs.GetSamples(); 
    2701                 //      cout<<"neighboring viewcells = "<<i-1<<endl; 
    2702                 //      cout<<"Samples' = "<<samples<<endl; 
     2649        //      float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 
     2650        float radius = viewCellRadius/100.0f; 
     2651        vbox.Enlarge(radius); 
     2652        cout<<"vbox = "<<vbox<<endl; 
     2653        ViewCellContainer viewCells; 
     2654        ComputeBoxIntersections(vbox, viewCells); 
     2655         
     2656        ViewCellContainer::const_iterator it = viewCells.begin(), 
     2657          it_end = viewCells.end(); 
     2658        int i = 0; 
     2659        for (i=0; it != it_end; ++ it, ++ i) 
     2660          if ((*it) != viewCell) { 
     2661                //cout<<"v"<<i<<" pvs="<<(*it)->GetPvs().mEntries.size()<<endl; 
     2662                basePvs.MergeInPlace((*it)->GetPvs()); 
     2663          } 
     2664         
     2665        // update samples and globalC 
     2666        samples = (float)pvs.GetSamples(); 
     2667        //      cout<<"neighboring viewcells = "<<i-1<<endl; 
     2668        //      cout<<"Samples' = "<<samples<<endl; 
    27032669  } 
    2704          
     2670   
    27052671  // Minimal number of samples so that filtering takes place 
    27062672#define MIN_SAMPLES  50 
    2707  
     2673   
    27082674  if (samples > MIN_SAMPLES) { 
    2709                 float globalC = 2.0f*filterSize/sqrt(samples); 
    2710                  
    2711                 pit = basePvs.GetIterator(); 
    2712                  
    2713                 ObjectContainer objects; 
    2714                  
    2715                 while (pit.HasMoreEntries()) 
    2716                         {                
    2717                                 ObjectPvsEntry entry = pit.Next(); 
    2718                                  
    2719                                 Intersectable *object = entry.mObject; 
    2720                                 // compute filter size based on the distance and the numebr of samples 
    2721                                 AxisAlignedBox3 box = object->GetBox(); 
    2722                                  
    2723                                 float distance = Distance(center, box.Center()); 
    2724                                 float globalRadius = distance*globalC; 
    2725                                  
    2726                                 int objectSamples = (int)entry.mData.mSumPdf; 
    2727                                 float localRadius = MAX_FLOAT; 
    2728                                  
    2729                                 localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 
    2730                                         sqrt((float)objectSamples); 
    2731                                  
    2732                                 //      cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 
    2733                                  
    2734                                 // now compute the filter size 
    2735                                 float radius; 
    2736  
     2675        float globalC = 2.0f*filterSize/sqrt(samples); 
     2676         
     2677        pit = basePvs.GetIterator(); 
     2678         
     2679        ObjectContainer objects; 
     2680         
     2681        while (pit.HasMoreEntries()) {           
     2682          ObjectPvsEntry entry = pit.Next(); 
     2683           
     2684          Intersectable *object = entry.mObject; 
     2685          // compute filter size based on the distance and the numebr of samples 
     2686          AxisAlignedBox3 box = object->GetBox(); 
     2687           
     2688          float distance = Distance(center, box.Center()); 
     2689          float globalRadius = distance*globalC; 
     2690           
     2691          int objectSamples = (int)entry.mData.mSumPdf; 
     2692          float localRadius = MAX_FLOAT; 
     2693           
     2694          localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 
     2695                sqrt((float)objectSamples); 
     2696           
     2697          //    cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 
     2698           
     2699          // now compute the filter size 
     2700          float radius; 
     2701           
    27372702#if 0 
    2738                                 if (objectSamples <= 1) { 
    2739                                         if (localRadius > globalRadius) { 
    2740                                                 radius = 0.5flRadius; 
    2741                                                 stats.mLocalFilterCount++; 
    2742                                         } else { 
    2743                                                 radius = globalRadius; 
    2744                                                 stats.mGlobalFilterCount++; 
    2745                                         } 
    2746                                 } else { 
    2747                                         radius = localRadius; 
    2748                                         stats.mLocalFilterCount++; 
    2749                                 } 
     2703          if (objectSamples <= 1) { 
     2704                if (localRadius > globalRadius) { 
     2705                  radius = 0.5flRadius; 
     2706                  stats.mLocalFilterCount++; 
     2707                } else { 
     2708                  radius = globalRadius; 
     2709                  stats.mGlobalFilterCount++; 
     2710                } 
     2711          } else { 
     2712                radius = localRadius; 
     2713                stats.mLocalFilterCount++; 
     2714          } 
    27502715#else 
    2751                                 radius = 0.5f*globalRadius + 0.5f*localRadius; 
    2752                                 stats.mLocalFilterCount++; 
    2753                                 stats.mGlobalFilterCount++; 
     2716          radius = 0.5f*globalRadius + 0.5f*localRadius; 
     2717          stats.mLocalFilterCount++; 
     2718          stats.mGlobalFilterCount++; 
    27542719#endif 
    2755                                  
    2756                                 stats.mAvgFilterRadius += radius; 
    2757                                  
    2758                                 // cout<<"box = "<<box<<endl; 
    2759                                 //      cout<<"distance = "<<distance<<endl; 
    2760                                 //      cout<<"radiues = "<<radius<<endl; 
    2761                                  
    2762                                 box.Enlarge(Vector3(radius)); 
    2763                                 if (filteredBoxes) 
    2764                                         filteredBoxes->push_back(box); 
    2765                                 objects.clear(); 
    2766                                 // $$ warning collect objects takes only unmailed ones! 
    2767                                 CollectObjects(box, objects); 
    2768                                 //      cout<<"collected objects="<<objects.size()<<endl; 
    2769                                 ObjectContainer::const_iterator noi = objects.begin(); 
    2770                                 for (; noi != objects.end(); ++ noi) { 
    2771                                         Intersectable *o = *noi; 
    2772                                         // $$ JB warning: pdfs are not correct at this point!      
    2773                                         pvs.AddSampleDirty(o, Limits::Small); 
    2774                                 } 
    2775                         } 
    2776                 stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 
     2720           
     2721          stats.mAvgFilterRadius += radius; 
     2722           
     2723          // cout<<"box = "<<box<<endl; 
     2724          //    cout<<"distance = "<<distance<<endl; 
     2725          //    cout<<"radiues = "<<radius<<endl; 
     2726           
     2727          box.Enlarge(Vector3(radius)); 
     2728 
     2729          if (filteredBoxes) 
     2730                filteredBoxes->push_back(box); 
     2731 
     2732          objects.clear(); 
     2733          // $$ warning collect objects takes only unmailed ones! 
     2734          CollectObjects(box, objects); 
     2735          //    cout<<"collected objects="<<objects.size()<<endl; 
     2736          ObjectContainer::const_iterator noi = objects.begin(); 
     2737          for (; noi != objects.end(); ++ noi) { 
     2738                Intersectable *o = *noi; 
     2739                // $$ JB warning: pdfs are not correct at this point!      
     2740                pvs.AddSampleDirty(o, Limits::Small); 
     2741          } 
     2742        } 
     2743        stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 
    27772744  } 
    27782745   
    27792746  Debug<<" nPvs size = "<<pvs.GetSize()<<endl; 
    2780  
     2747   
    27812748#if !USE_KD_PVS 
    27822749  // copy the base pvs to the new pvs 
    27832750  pit = basePvs.GetIterator(); 
    27842751  while (pit.HasMoreEntries()) {                 
    2785                 ObjectPvsEntry entry = pit.Next(); 
    2786                 pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf); 
     2752        ObjectPvsEntry entry = pit.Next(); 
     2753        pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf); 
    27872754  } 
    27882755#endif 
     2756   
     2757  pvs.SimpleSort(); 
    27892758  viewCell->SetFilteredPvsSize(pvs.GetSize()); 
    27902759   
     
    27922761  return stats; 
    27932762} 
    2794 #else 
    2795 PvsFilterStatistics 
    2796 ViewCellsManager::ApplyFilter2(ViewCell *viewCell, 
    2797                                                            const bool useViewSpaceFilter, 
    2798                                                            const float filterSize, 
    2799                                                            ObjectPvs &pvs 
    2800                                                            ) 
    2801 { 
    2802         cout << "x"; 
    2803         PvsFilterStatistics stats; 
    2804  
    2805         AxisAlignedBox3 vbox = GetViewCellBox(viewCell); 
    2806         Vector3 center = vbox.Center(); 
    2807         // copy the PVS 
    2808         ObjectPvs basePvs;// = viewCell->GetPvs(); 
    2809         Intersectable::NewMail(); 
    2810  
    2811         ObjectPvsIterator pit = viewCell->GetPvs().GetIterator(); 
    2812  
    2813 #if !USE_KD_PVS 
    2814         // first mark all object from this pvs 
    2815         while (pit.HasMoreEntries())  
    2816         {                
    2817                 ObjectPvsEntry entry = pit.Next(); 
    2818  
    2819                 Intersectable *object = entry.mObject; 
    2820                 object->Mail(); 
    2821         } 
    2822 #endif 
    2823  
    2824         int pvsSize = 0; 
    2825         int nPvsSize = 0; 
    2826         float samples = (float)viewCell->GetPvs().GetSamples(); 
    2827  
    2828         Debug<<"f #s="<<samples<<"pvs size = "<<viewCell->GetPvs().GetSize(); 
    2829         //  cout<<"Filter size = "<<filterSize<<endl; 
    2830         //  cout<<"vbox = "<<vbox<<endl; 
    2831         //  cout<<"center = "<<center<<endl; 
    2832  
    2833  
    2834         // Minimal number of local samples to take into account 
    2835         // the local sampling density. 
    2836         // The size of the filter is a minimum of the conservative 
    2837         // local sampling density estimate (#rays intersecting teh viewcell and 
    2838         // the object) 
    2839         // and gobal estimate for the view cell 
    2840         // (total #rays intersecting the viewcell) 
    2841 #define MIN_LOCAL_SAMPLES 5 
    2842  
    2843         float viewCellRadius = 0.5f*Magnitude(vbox.Diagonal()); 
    2844  
    2845         // now compute the filter box around the current viewCell 
    2846  
    2847         if (useViewSpaceFilter)  
    2848         { 
    2849                 //      float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 
    2850                 float radius = viewCellRadius/100.0f; 
    2851                 vbox.Enlarge(radius); 
    2852                 cout<<"vbox = "<<vbox<<endl; 
    2853                 ViewCellContainer viewCells; 
    2854                 ComputeBoxIntersections(vbox, viewCells); 
    2855                  
    2856                 MergeViewCellsEfficient(basePvs, viewCells); 
    2857                 cout << "basepvs size " << basePvs.GetSize() << endl; 
    2858                 // update samples and globalC 
    2859                 samples = (float)pvs.GetSamples(); 
    2860                 //      cout<<"neighboring viewcells = "<<i-1<<endl; 
    2861                 //      cout<<"Samples' = "<<samples<<endl; 
    2862         } 
    2863         else 
    2864         { 
    2865                 basePvs = viewCell->GetPvs(); 
    2866         } 
    2867  
    2868         // Minimal number of samples so that filtering takes place 
    2869 #define MIN_SAMPLES  100 
    2870         if (samples > MIN_SAMPLES)  
    2871         { 
    2872                 float globalC = 2.0f*filterSize/sqrt(samples); 
    2873  
    2874                 pit = basePvs.GetIterator(); 
    2875  
    2876                 ObjectContainer objects; 
    2877  
    2878                 while (pit.HasMoreEntries()) 
    2879                 {                
    2880                         ObjectPvsEntry entry = pit.Next(); 
    2881  
    2882                         Intersectable *object = entry.mObject; 
    2883                         // compute filter size based on the distance and the numebr of samples 
    2884                         AxisAlignedBox3 box = object->GetBox(); 
    2885  
    2886                         float distance = Distance(center, box.Center()); 
    2887                         float globalRadius = distance*globalC; 
    2888  
    2889                         int objectSamples = (int)entry.mData.mSumPdf; 
    2890                         float localRadius = MAX_FLOAT; 
    2891  
    2892                         if (objectSamples > MIN_LOCAL_SAMPLES) 
    2893                         { 
    2894                                 localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 
    2895                                                                 sqrt((float)objectSamples); 
    2896                         } 
    2897  
    2898                         //      cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 
    2899  
    2900                         // now compute the filter size 
    2901                         float radius; 
    2902  
    2903                         if (localRadius < globalRadius)  
    2904                         { 
    2905                                 radius = localRadius; 
    2906                                 stats.mLocalFilterCount++; 
    2907                         }  
    2908                         else  
    2909                         { 
    2910                                 radius = globalRadius; 
    2911                                 stats.mGlobalFilterCount++; 
    2912                         } 
    2913  
    2914                         stats.mAvgFilterRadius += radius; 
    2915  
    2916                         // cout<<"box = "<<box<<endl; 
    2917                         //      cout<<"distance = "<<distance<<endl; 
    2918                         //      cout<<"radiues = "<<radius<<endl; 
    2919  
    2920                         box.Enlarge(Vector3(radius)); 
    2921                         objects.clear(); 
    2922  
    2923                         // $$ warning collect objects takes only unmailed ones! 
    2924                         CollectObjects(box, objects); 
    2925  
    2926                         //      cout<<"collected objects="<<objects.size()<<endl; 
    2927                         ObjectContainer::const_iterator noi = objects.begin(); 
    2928                         for (; noi != objects.end(); ++ noi)  
    2929                         { 
    2930                                 Intersectable *o = *noi; 
    2931                                 // $$ JB warning: pdfs are not correct at this point!      
    2932                                 pvs.AddSampleDirty(o, Limits::Small); 
    2933                         } 
    2934                 } 
    2935  
    2936                 stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 
    2937         } 
    2938  
    2939         Debug<<" nPvs size = "<<pvs.GetSize()<<endl; 
    2940  
    2941 #if !USE_KD_PVS 
    2942         // copy the base pvs to the new pvs 
    2943         pit = basePvs.GetIterator(); 
    2944         while (pit.HasMoreEntries())  
    2945         {                
    2946                 ObjectPvsEntry entry = pit.Next(); 
    2947                 pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf); 
    2948         } 
    2949 #endif 
    2950         viewCell->SetFilteredPvsSize(pvs.GetSize()); 
    2951  
    2952         Intersectable::NewMail(); 
    2953          
    2954         return stats; 
    2955 } 
    2956 #endif 
    29572763 
    29582764 
     
    60435849         
    60445850 
    6045 #define PVS_ADD_DIRTY 1 
    6046  
    6047 float 
    6048 VspOspViewCellsManager::ComputeSampleContribution(VssRay &ray, 
    6049                                                                                                   const bool addRays, 
    6050                                                                                                   const bool storeViewCells) 
    6051 { 
    6052   ray.mPvsContribution = 0; 
    6053   ray.mRelativePvsContribution = 0.0f; 
    6054    
    6055   if (ray.mTerminationObject==NULL) 
    6056         return 0.0f; 
    6057    
    6058   ViewCellContainer viewcells; 
    6059    
    6060   static Ray hray; 
    6061   hray.Init(ray); 
    6062  
    6063   float tmin = 0, tmax = 1.0; 
    6064    
    6065   if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 
    6066         return 0; 
    6067    
    6068   Vector3 origin = hray.Extrap(tmin); 
    6069   Vector3 termination = hray.Extrap(tmax); 
    6070    
    6071   ViewCell::NewMail(); 
    6072    
    6073   // traverse the view space subdivision 
    6074   CastLineSegment(origin, termination, viewcells); 
    6075    
    6076   if (storeViewCells) 
    6077         {        
    6078           // copy viewcells memory efficiently 
    6079           ray.mViewCells.reserve(viewcells.size()); 
    6080           ray.mViewCells = viewcells; 
    6081         } 
    6082    
    6083   ViewCellContainer::const_iterator it = viewcells.begin(); 
    6084    
    6085   Intersectable *terminationObj = GetIntersectable(ray, true); 
    6086    
    6087 #if SAMPLE_ORIGIN_OBJECTS 
    6088   Intersectable *originObj = GetIntersectable(ray, false); 
    6089 #endif 
    6090    
    6091   for (; it != viewcells.end(); ++ it)  
    6092         { 
    6093           ViewCell *viewcell = *it; 
    6094            
    6095           if (viewcell->GetValid()) 
    6096                 {       // if ray not outside of view space 
    6097                   float contribution; 
    6098                    
    6099                   if (terminationObj)  
    6100                         { 
    6101                           // todo: maybe not correct for kd node pvs 
    6102                           if (viewcell->GetPvs().GetSampleContribution( 
    6103                                                                                                                    terminationObj, ray.mPdf, contribution)) 
    6104                                 { 
    6105                                   ++ ray.mPvsContribution; 
    6106                                 } 
    6107                            
    6108                           ray.mRelativePvsContribution += contribution; 
    6109                         } 
    6110                    
    6111                   //////////////// 
    6112                   //-- for directional sampling it is important to count  
    6113                   //-- only contributions made in one direction! 
    6114                   //-- the other contributions of this sample will be counted for the opposite ray! 
    6115                    
    6116 #if SAMPLE_ORIGIN_OBJECTS 
    6117                    
    6118                   if (originObj &&  
    6119                           viewcell->GetPvs().GetSampleContribution(originObj, 
    6120                                                                                                            ray.mPdf, 
    6121                                                                                                            contribution)) 
    6122                         { 
    6123                           ++ ray.mPvsContribution; 
    6124                           ray.mRelativePvsContribution += contribution; 
    6125                         } 
    6126 #endif 
    6127                 } 
    6128         } 
    6129    
    6130   if (!addRays) { 
    6131         return ray.mRelativePvsContribution; 
    6132   } 
    6133    
    6134   // sampled objects are stored in the pvs 
    6135   for (it = viewcells.begin(); it != viewcells.end(); ++ it)  { 
    6136         ViewCell *viewCell = *it; 
    6137          
    6138         if (!viewCell->GetValid()) 
    6139           break; 
    6140          
    6141         //$$JB hack 
    6142          
    6143 #if PVS_ADD_DIRTY 
    6144         viewCell->GetPvs().AddSampleDirtyCheck(terminationObj, ray.mPdf); 
    6145 #else 
    6146         viewCell->GetPvs().AddSample(terminationObj, ray.mPdf); 
    6147 #endif 
    6148          
    6149 #if SAMPLE_ORIGIN_OBJECTS 
    6150 #if PVS_ADD_DIRTY 
    6151         viewCell->GetPvs().AddSampleDirtyCheck(originObj, ray.mPdf); 
    6152 #else 
    6153         viewCell->GetPvs().AddSample(originObj, ray.mPdf); 
    6154 #endif 
    6155 #endif 
    6156         if (viewCell->GetPvs().RequiresResort()) { 
    6157           viewCell->GetPvs().Sort();                     
    6158         } 
    6159   } 
    6160    
    6161   return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution + 
    6162         (1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution; 
    6163 } 
    61645851 
    61655852 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1867 r1877  
    11281128        /** Stores sample contribution for kd cells or objects. 
    11291129        */ 
    1130         virtual float ComputeSampleContribution(VssRay &ray,  
    1131                                                                                         const bool addRays, 
    1132                                                                                         const bool storeViewCells); 
     1130  //    virtual float ComputeSampleContribution(VssRay &ray,  
     1131  //                                                                                    const bool addRays, 
     1132  //                                                                                    const bool storeViewCells); 
    11331133 
    11341134        ViewCellsManager *LoadViewCells(const string &filename,  
  • GTP/trunk/Lib/Vis/Preprocessing/src/default.env

    r1876 r1877  
    8989 
    9090RssPreprocessor { 
     91 
     92        distributions rss+spatial+object 
     93 
    9194        samplesPerPass 1000 
    9295        initialSamples 2000000 
    93         vssSamples 20000000 
    94         vssSamplesPerPass 3000000 
     96        vssSamples 50000000 
     97        vssSamplesPerPass 2000000 
    9598        useImportanceSampling true 
    9699 
     
    102105                rssTree false 
    103106                rays true 
    104                 numRays 10000 
     107                numRays 5000 
    105108        } 
    106109 
     
    128131        maxCostRatio 1.0 
    129132        maxRayContribution 1.0 
    130         maxRays         10000000 
     133        maxRays         1000000 
    131134        maxTotalMemory  400 
    132135        maxStaticMemory 200 
     
    137140        hybridDepth             10 
    138141        splitUseOnlyDrivingAxis false 
    139 #false 
    140142        importanceBasedCost false 
    141143 
  • GTP/trunk/Lib/Vis/Preprocessing/src/run_test2

    r1867 r1877  
    22 
    33#COMMAND="./release/preprocessor.exe -preprocessor_quit_on_finish+" 
    4 COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter+" 
     4COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter-" 
    55 
    66#SCENE="../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d" 
Note: See TracChangeset for help on using the changeset viewer.