Changeset 1974


Ignore:
Timestamp:
01/14/07 19:59:25 (17 years ago)
Author:
bittner
Message:

mutation updates, ray sorting, merge

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

Legend:

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

    r1968 r1974  
    15971597                "false"); 
    15981598 
     1599        RegisterOption("ViewCells.useKdPvsAfterFiltering", 
     1600                                   optBool,  
     1601                                   "view_cells_use_kd_pvs_after_filtering",  
     1602                                   "false"); 
     1603 
    15991604 
    16001605 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r1867 r1974  
    826826} 
    827827 
     828void 
     829KdTree::CollectKdObjects(const AxisAlignedBox3 &box, 
     830                                                 ObjectContainer &objects, 
     831                                                 const float maxArea 
     832                                                 ) 
     833{ 
     834  stack<KdNode *> nodeStack; 
     835   
     836  nodeStack.push(mRoot); 
     837 
     838  while (!nodeStack.empty()) { 
     839    KdNode *node = nodeStack.top(); 
     840    nodeStack.pop(); 
     841        if (node->IsLeaf() || (GetSurfaceArea(node) <= maxArea) ) { 
     842          Intersectable *object = GetOrCreateKdIntersectable(node); 
     843          if (!object->Mailed()) { 
     844                object->Mail(); 
     845                objects.push_back(object); 
     846          } 
     847        } else { 
     848      KdInterior *interior = (KdInterior *)node; 
     849           
     850          if ( box.Max()[interior->mAxis] > interior->mPosition ) 
     851                nodeStack.push(interior->mFront); 
     852           
     853          if (box.Min()[interior->mAxis] < interior->mPosition) 
     854                nodeStack.push(interior->mBack); 
     855    } 
     856  } 
     857} 
    828858 
    829859void 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h

    r1761 r1974  
    345345 
    346346  void 
     347  CollectKdObjects(const AxisAlignedBox3 &box, 
     348                                   ObjectContainer &objects, 
     349                                   const float maxArea 
     350                                   ); 
     351 
     352  void 
    347353  CollectObjects(KdNode *n, ObjectContainer &objects); 
    348354 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Makefile

    r1967 r1974  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (2.00a) (Qt 4.1.2) on: st 10. I 21:33:14 2007 
     3# Generated by qmake (2.00a) (Qt 4.1.2) on: ne 14. I 01:57:15 2007 
    44# Project:  preprocessor.pro 
    55# Template: app 
     
    6363        $(MAKE) -f $(MAKEFILE).Debug uninstall 
    6464 
    65 Makefile: preprocessor.pro  C:/Qt/4.1.2/mkspecs/win32-msvc.net\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \ 
     65Makefile: preprocessor.pro  C:/Qt/4.1.2/mkspecs/win32-msvc2005\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \ 
    6666                C:\Qt\4.1.2\mkspecs\features\qt_config.prf \ 
    6767                C:\Qt\4.1.2\mkspecs\features\exclusive_builds.prf \ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1972 r1974  
    11491149                                           ) 
    11501150{ 
    1151         const long t1 = GetTime(); 
    1152  
     1151 
     1152 
     1153  const long t1 = GetTime(); 
     1154 
     1155#if 0 
     1156  mRayCaster->SortRays(rays); 
     1157  cout<<"Rays sorted in "<<TimeDiff(t1, GetTime())<<" s."<<endl; 
     1158#endif 
     1159   
    11531160        SimpleRayContainer::const_iterator rit, rit_end = rays.end(); 
    11541161 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h

    r1969 r1974  
    339339        //      mId = sSimpleRayId++; 
    340340  } 
     341 
     342  float GetParam(const int axis) const { 
     343        if (axis < 3) 
     344          return mOrigin[axis]; 
     345        else 
     346          return mDirection[axis-3]; 
     347  } 
    341348   
    342349  Vector3 Extrap(const float t) const { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp

    r1966 r1974  
    120120} 
    121121 
     122void 
     123RayCaster::SortRays(SimpleRayContainer &rays) 
     124{ 
     125  _SortRays(rays, 0, rays.size()-1, 0); 
     126} 
     127                                         
     128void 
     129RayCaster::_SortRays(SimpleRayContainer &rays, 
     130                                         const int l, 
     131                                         const int r, 
     132                                         const int axis) 
     133{ 
     134  // pick-up a pivot 
     135  int     i=l,j=r; 
     136  float x = rays[(l+r)/2].GetParam(axis); 
     137  do { 
     138        while(rays[i].GetParam(axis) < x) 
     139          i++; 
     140        while(x < rays[j].GetParam(axis)) 
     141          j--; 
     142         
     143        if (i <= j) { 
     144          swap(rays[i], rays[j]); 
     145          i++; 
     146          j--; 
     147        } 
     148  } while (i<=j); 
     149   
     150  if (l + 16 < j ) 
     151        _SortRays(rays, l, j, (axis+1)%6); 
     152   
     153  if (i + 16 < r) 
     154    _SortRays(rays, i, r, (axis+1)%6);  
     155} 
     156   
     157                                         
    122158 
    123159int 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h

    r1972 r1974  
    6060                                                         const bool pruneInvalidRays = true 
    6161                                                         ) = 0; 
     62 
     63 
     64  virtual void 
     65  SortRays(SimpleRayContainer &rays); 
     66 
    6267         
    6368 
    6469protected: 
    65         struct Intersection 
     70  void 
     71  _SortRays(SimpleRayContainer &rays, 
     72                        const int l, 
     73                        const int r, 
     74                        const int axis); 
     75 
     76  struct Intersection 
    6677        { 
    6778                Intersection(): mObject(NULL), mFaceId(0) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp

    r1968 r1974  
    66#include "AxisAlignedBox3.h" 
    77#include "RssTree.h" 
     8#include "Vector2.h" 
     9#include "RndGauss.h" 
    810 
    911namespace GtpVisibilityPreprocessor { 
     
    566568} 
    567569 
    568 #define RAY_CAST_TIME 0.9f 
    569 #define VIEWCELL_CAST_TIME 0.1f 
     570#define RAY_CAST_TIME 0.7f 
     571#define VIEWCELL_CAST_TIME 0.3f 
    570572 
    571573void 
     
    589591  } 
    590592 
    591    
    592    
    593593  if (sum == 0.0f) 
    594594        sum = Limits::Small; 
    595  
     595   
    596596  const float minratio = 0.01f; 
    597   float threshold = minratio*sum; 
    598  
    599   // recaluate the sum 
     597   
     598  for (i=0; i < mDistributions.size(); i++) { 
     599        mDistributions[i]->mRatio /= sum; 
     600        if (mDistributions[i]->mRatio < minratio)  
     601          mDistributions[i]->mRatio = minratio; 
     602  } 
     603 
     604  // recaluate the sum after clip 
    600605  sum = 0.0f; 
    601   for (i=0; i < mDistributions.size(); i++) { 
    602         if (mDistributions[i]->mRatio < threshold) { 
    603           mDistributions[i]->mRatio = threshold; 
    604         } 
     606  for (i=0; i < mDistributions.size(); i++) 
    605607        sum += mDistributions[i]->mRatio; 
    606   } 
    607    
    608   mDistributions[0]->mRatio /= sum; 
     608 
     609  for (i=0; i < mDistributions.size(); i++) 
     610        mDistributions[i]->mRatio /= sum; 
    609611   
    610612  for (i=1; i < mDistributions.size(); i++) { 
    611         float r = mDistributions[i]->mRatio / sum; 
    612         mDistributions[i]->mRatio = mDistributions[i-1]->mRatio + r; 
    613   } 
    614    
     613        mDistributions[i]->mRatio = mDistributions[i-1]->mRatio + mDistributions[i]->mRatio; 
     614  } 
    615615   
    616616  cout<<"ratios: "; 
     
    692692  cerr<<"Muattion update..."<<endl; 
    693693  cerr<<"rays = "<<mRays.size()<<endl; 
    694   if (mRays.size()) 
    695         cerr<<"Oversampling factor = "<<mRays[0].mSamples<<endl; 
     694  if (mRays.size()) { 
     695        cerr<<"Oversampling factors = "<< 
     696          GetEntry(0).mSamples<<" "<< 
     697          GetEntry(1).mSamples<<" "<< 
     698          GetEntry(2).mSamples<<" "<< 
     699          GetEntry(3).mSamples<<" "<< 
     700          GetEntry(4).mSamples<<" "<< 
     701          GetEntry(5).mSamples<<" ... "<< 
     702          GetEntry(mRays.size()-6).mSamples<<" "<< 
     703          GetEntry(mRays.size()-5).mSamples<<" "<< 
     704          GetEntry(mRays.size()-4).mSamples<<" "<< 
     705          GetEntry(mRays.size()-3).mSamples<<" "<< 
     706          GetEntry(mRays.size()-2).mSamples<<" "<< 
     707          GetEntry(mRays.size()-1).mSamples<<endl; 
     708  } 
     709  int contributingRays = 0; 
    696710  for (int i=0; i < vssRays.size(); i++) { 
    697711        if (vssRays[i]->mPvsContribution) { 
     712          contributingRays++; 
    698713          if (mRays.size() < mMaxRays) { 
    699714                VssRay *newRay = new VssRay(*vssRays[i]); 
     
    712727        } 
    713728  } 
     729   
     730  float pContributingRays = contributingRays/(float)vssRays.size(); 
     731  float importance = 1.0f/(pContributingRays + 1e-5); 
     732  // set this values for last contributingRays 
     733  int index = mBufferStart - 1; 
     734  int i; 
     735  for (i=0; i < contributingRays; i++, index--) { 
     736        if (index < 0) 
     737          index = mRays.size()-1; 
     738        mRays[index].mImportance = importance; 
     739  } 
     740 
     741   
     742  // compute cdf 
     743  mRays[0].mCdf = mRays[0].mImportance/(mRays[0].mSamples+1); 
     744  for (i=1; i < mRays.size(); i++)  
     745        mRays[i].mCdf = mRays[i-1].mCdf + mRays[i].mImportance/(mRays[i].mSamples+1); 
     746   
     747  float scale = 1.0f/mRays[i-1].mCdf; 
     748  for (i=0; i < mRays.size(); i++) { 
     749        mRays[i].mCdf *= scale; 
     750  } 
     751 
     752  cout<<"Importance = "<< 
     753        GetEntry(0).mImportance<<" "<< 
     754        GetEntry(mRays.size()-1).mImportance<<endl; 
     755   
    714756  cerr<<"Mutation update done."<<endl; 
    715  
    716 } 
    717  
    718 bool 
    719 MutationBasedDistribution::GenerateSample(SimpleRay &sray) 
    720 { 
    721   float r[5]; 
    722  
    723   if (mRays.size() == 0) { 
    724         // use direction based distribution 
    725         Vector3 origin, direction; 
    726         static HaltonSequence halton; 
    727          
    728         halton.GetNext(5, r); 
    729         mPreprocessor.mViewCellsManager->GetViewPoint(origin, 
    730                                                                                                   Vector3(r[0], r[1], r[2])); 
    731          
    732  
    733         direction = UniformRandomVector(r[3], r[4]); 
    734          
    735         const float pdf = 1.0f; 
    736         sray = SimpleRay(origin, direction, MUTATION_BASED_DISTRIBUTION, pdf); 
    737  
    738         return true; 
    739   }  
    740    
    741   //  int index = (int) (r[0]*mRays.size()); 
    742   //  if (index >= mRays.size()) { 
    743   //    cerr<<"mutation: index out of bounds\n"; 
    744   //    exit(1); 
    745   //  } 
    746  
    747   // get tail of the buffer 
    748   int index = (mLastIndex+1)%mRays.size(); 
    749   if (mRays[index].mSamples > mRays[mLastIndex].mSamples) { 
    750         // search back for index where this is valid 
    751         index = (mLastIndex - 1 + mRays.size())%mRays.size(); 
    752         for (int i=0; i < mRays.size(); i++) { 
    753           if (mRays[index].mSamples > mRays[mLastIndex].mSamples) 
    754                 break; 
    755           index = (index - 1 + mRays.size())%mRays.size(); 
    756         } 
    757         // go one step back 
    758         index = (index+1)%mRays.size(); 
    759   } 
    760    
    761   VssRay *ray = mRays[index].mRay; 
    762   mRays[index].mSamples++; 
    763   mLastIndex = index; 
    764  
    765   mRays[index].mHalton.GetNext(4, r); 
    766    
     757} 
     758 
     759 
     760Vector3 
     761MutationBasedDistribution::ComputeOriginMutation(const VssRay &ray, 
     762                                                                                                 const Vector3 &U, 
     763                                                                                                 const Vector3 &V, 
     764                                                                                                 const Vector2 vr2, 
     765                                                                                                 const float radius 
     766                                                                                                 ) 
     767{ 
     768#if 0 
    767769  Vector3 v; 
    768   // mutate the origin 
    769   Vector3 d = ray->GetDir(); 
    770770  if (d.DrivingAxis() == 0) 
    771771        v = Vector3(0, r[0]-0.5f, r[1]-0.5f); 
     
    775775        else 
    776776          v = Vector3(r[0]-0.5f, r[1]-0.5f, 0); 
    777  
    778   v=v*mOriginMutationSize; 
    779  
    780   Vector3 origin = ray->mOrigin + v; 
    781    
     777  return v*(2*radius); 
     778#endif 
     779#if 0 
     780  return (U*(r[0] - 0.5f) + V*(r[1] - 0.5f))*(2*radius); 
     781#endif 
     782 
     783 
     784  // Output random variable 
     785  Vector2 gaussvec2;  
     786   
     787  // Here we apply transform to gaussian, so 2D bivariate 
     788  // normal distribution 
     789  //  float sigma = ComputeSigmaFromRadius(radius); 
     790  float sigma = radius; 
     791  GaussianOn2D(vr2, 
     792                           sigma, // input 
     793                           gaussvec2);  // output 
     794 
     795         
     796    // Here we tranform the point correctly to 3D space using base 
     797    // vectors of the 3D space defined by the direction 
     798    Vector3 shift = gaussvec2.xx * U + gaussvec2.yy * V; 
     799         
     800        //      cout<<shift<<endl; 
     801        return shift; 
     802} 
     803 
     804Vector3 
     805MutationBasedDistribution::ComputeTerminationMutation(const VssRay &ray, 
     806                                                                                                          const Vector3 &U, 
     807                                                                                                          const Vector3 &V, 
     808                                                                                                          const Vector2 vr2, 
     809                                                                                                          const float radius 
     810                                                                                                          ) 
     811{ 
     812#if 0 
     813  Vector3 v; 
    782814  // mutate the termination 
    783815  if (d.DrivingAxis() == 0) 
     
    788820        else 
    789821          v = Vector3(r[2]-0.5f, r[3]-0.5f, 0); 
     822   
     823  //   Vector3 nv; 
     824   
     825  //   if (Magnitude(v) > Limits::Small) 
     826  //    nv = Normalize(v); 
     827  //   else 
     828  //    nv = v; 
     829   
     830  //  v = nv*size + v*size; 
     831 
     832  return v*(4.0f*radius); 
     833#endif 
     834#if 0 
     835  return (U*(vr2.xx - 0.5f) + V*(vr2.yy - 0.5f))*(4.0f*radius); 
     836#endif 
     837  Vector2 gaussvec2;  
     838#if 1 
     839  float sigma = radius; 
     840  GaussianOn2D(vr2, 
     841                           sigma, // input 
     842                           gaussvec2);  // output 
     843  Vector3 shift = gaussvec2.xx * U + gaussvec2.yy * V; 
     844  //    cout<<shift<<endl; 
     845  return shift; 
     846#endif 
     847#if 0 
     848  // Here we estimate standard deviation (sigma) from radius 
     849  float sigma = 1.1f*ComputeSigmaFromRadius(radius); 
     850  Vector3 vr3(vr2.xx, vr2.yy, RandomValue(0,1)); 
     851  PolarGaussianOnDisk(vr3, 
     852                                          sigma, 
     853                                          radius, // input 
     854                                          gaussvec2); // output 
     855   
     856  // Here we tranform the point correctly to 3D space using base 
     857  // vectors of the 3D space defined by the direction 
     858  Vector3 shift = gaussvec2.xx * U + gaussvec2.yy * V; 
     859   
     860  //    cout<<shift<<endl; 
     861  return shift; 
     862#endif 
     863} 
     864 
     865 
     866bool 
     867MutationBasedDistribution::GenerateSample(SimpleRay &sray) 
     868{ 
     869  float rr[5]; 
     870 
     871  if (mRays.size() == 0) { 
     872        // use direction based distribution 
     873        Vector3 origin, direction; 
     874        static HaltonSequence halton; 
     875         
     876        halton.GetNext(5, rr); 
     877        mPreprocessor.mViewCellsManager->GetViewPoint(origin, 
     878                                                                                                  Vector3(rr[0], rr[1], rr[2])); 
     879         
     880 
     881        direction = UniformRandomVector(rr[3], rr[4]); 
     882         
     883        const float pdf = 1.0f; 
     884        sray = SimpleRay(origin, direction, MUTATION_BASED_DISTRIBUTION, pdf); 
     885 
     886        return true; 
     887  }  
     888 
     889  int index; 
     890#if 1 
     891  // get tail of the buffer 
     892  index = (mLastIndex+1)%mRays.size(); 
     893  if (mRays[index].GetSamplingFactor() > 
     894          mRays[mLastIndex].GetSamplingFactor()) { 
     895        // search back for index where this is valid 
     896        index = (mLastIndex - 1 + mRays.size())%mRays.size(); 
     897        for (int i=0; i < mRays.size(); i++) { 
     898           
     899          //      if (mRays[index].mSamples > mRays[mLastIndex].mSamples) 
     900          //            break; 
     901          if (mRays[index].GetSamplingFactor() > 
     902                  mRays[mLastIndex].GetSamplingFactor() ) 
     903                break; 
     904          index = (index - 1 + mRays.size())%mRays.size(); 
     905        } 
     906        // go one step back 
     907        index = (index+1)%mRays.size(); 
     908  } 
     909#else 
     910  static HaltonSequence iHalton; 
     911  iHalton.GetNext(1, rr); 
     912  //rr[0] = RandomValue(0,1); 
     913  // use binary search to find index with this cdf 
     914  int l=0, r=mRays.size()-1; 
     915  while(l<r) { 
     916        int i = (l+r)/2; 
     917        if (rr[0] < mRays[i].mCdf ) 
     918          r = i; 
     919        else 
     920          l = i+1; 
     921  } 
     922  index = l; 
     923  //  if (rr[0] >= mRays[r].mCdf) 
     924  //    index = r; 
     925  //  else 
     926  //    index = l; 
     927         
     928         
     929#endif 
     930  //  cout<<index<<" "<<rr[0]<<" "<<mRays[index].mCdf<<" "<<mRays[(index+1)%mRays.size()].mCdf<<endl; 
     931   
     932  VssRay *ray = mRays[index].mRay; 
     933  mRays[index].mSamples++; 
     934  mLastIndex = index; 
     935 
     936  mRays[index].mHalton.GetNext(4, rr); 
     937 
     938  // mutate the origin 
     939  Vector3 d = ray->GetDir(); 
     940 
    790941 
    791942  AxisAlignedBox3 box = ray->mTerminationObject->GetBox(); 
    792   float size = 2.0f*Magnitude(box.Diagonal()); 
    793   if (size < Limits::Small) 
     943  float objectRadius = 0.5f*Magnitude(box.Diagonal()); 
     944  //  cout<<objectRadius<<endl; 
     945  if (objectRadius < Limits::Small) 
    794946        return false; 
    795947   
    796 //   Vector3 nv; 
    797    
    798 //   if (Magnitude(v) > Limits::Small) 
    799 //      nv = Normalize(v); 
    800 //   else 
    801 //      nv = v; 
    802    
    803 //  v = nv*size + v*size; 
    804  
    805   v = v*size; 
    806  
    807   //  Vector3 termination = ray->mTermination + v; 
    808   Vector3 termination = box.Center() + v; 
     948  // Compute right handed coordinate system from direction 
     949  Vector3 U, V; 
     950  Vector3 nd = Normalize(d); 
     951  nd.RightHandedBase(U, V); 
     952 
     953  Vector3 origin = ray->mOrigin; 
     954  Vector3 termination = ray->mTermination; //box.Center(); //ray->mTermination; //box.Center(); 
     955 
     956  float radiusExtension = 1.0f; 
     957  //  + mRays[index].mSamples/50.0f; 
     958   
     959  //  origin += ComputeOriginMutation(*ray, U, V, Vector2(r[0], r[1]), 0.5f*mOriginMutationSize*radiusExtension); 
     960  origin += ComputeOriginMutation(*ray, U, V, 
     961                                                                  Vector2(rr[0], rr[1]), 
     962                                                                  objectRadius*radiusExtension); 
     963  termination += ComputeTerminationMutation(*ray, U, V, 
     964                                                                                        Vector2(rr[2], rr[3]), 
     965                                                                                        objectRadius*radiusExtension); 
    809966   
    810967  Vector3 direction = termination - origin; 
    811  
     968   
    812969  if (Magnitude(direction) < Limits::Small) 
    813970        return false; 
    814  
     971   
    815972  // shift the origin a little bit 
    816973  origin += direction*0.5f; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h

    r1968 r1974  
    66 
    77#include "Halton.h" 
    8  
    98namespace GtpVisibilityPreprocessor { 
    109 
    11   class VssRay; 
     10class Vector2; 
     11class Vector3; 
     12class VssRay; 
    1213class Preprocessor; 
    1314struct SimpleRay; 
    1415class SimpleRayContainer; 
     16 
    1517struct VssRayContainer; 
    1618 
     
    238240        int mSamples; 
    239241        HaltonSequence mHalton; 
    240  
     242        float mImportance; 
     243        float mCdf; 
     244 
     245        float GetSamplingFactor() const { return mSamples/mImportance; } 
    241246        RayEntry() {} 
    242         RayEntry(VssRay *r):mRay(r), mSamples(0), mHalton() {} 
     247        RayEntry(VssRay *r):mRay(r), mSamples(0), mHalton(), mImportance(1.0f) {} 
    243248  }; 
     249 
     250 
     251  Vector3 
     252  ComputeOriginMutation(const VssRay &ray, 
     253                                                const Vector3 &U, 
     254                                                const Vector3 &V, 
     255                                                const Vector2 vr2, 
     256                                                const float radius 
     257                                                ); 
     258 
     259  Vector3 
     260  ComputeTerminationMutation(const VssRay &ray, 
     261                                                         const Vector3 &U, 
     262                                                         const Vector3 &V, 
     263                                                         const Vector2 vr2, 
     264                                                         const float radius 
     265                                                         ); 
     266 
     267  RayEntry &GetEntry(const int index) { 
     268        return mRays[(mBufferStart+index)%mRays.size()]; 
     269  } 
    244270   
    245271  vector<RayEntry> mRays; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1972 r1974  
    667667 
    668668 
     669 
     670 
     671ViewCellsManager *ViewCellsManager::LoadViewCells(const string &filename,  
     672                                                                                                  ObjectContainer *objects, 
     673                                                                                                  bool finalizeViewCells, 
     674                                                                                                  BoundingBoxConverter *bconverter) 
     675                                                                                                  
     676{ 
     677        ViewCellsParser parser; 
     678        ViewCellsManager *vm = NULL; 
     679 
     680        const long startTime = GetTime(); 
     681        bool success = parser.ParseViewCellsFile(filename, &vm, objects, bconverter); 
     682 
     683        cout<<"viewcells parsed "<<endl<<flush; 
     684         
     685        if (success) 
     686        { 
     687                //vm->ResetViewCells(); 
     688                //hack 
     689                vm->mViewCells.clear(); 
     690                ViewCellContainer leaves; 
     691                vm->mViewCellsTree->CollectLeaves(vm->mViewCellsTree->GetRoot(), leaves); 
     692 
     693                ViewCellContainer::const_iterator it, it_end = leaves.end(); 
     694 
     695                for (it = leaves.begin(); it != it_end; ++ it) 
     696                { 
     697                        vm->mViewCells.push_back(*it); 
     698                } 
     699                vm->mViewCellsFinished = true; 
     700                vm->mMaxPvsSize = (int)objects->size(); 
     701 
     702                if (finalizeViewCells) 
     703                { 
     704                        // create the meshes and compute volumes 
     705                        vm->FinalizeViewCells(true); 
     706                        // vm->mViewCellsTree->AssignRandomColors(); 
     707                } 
     708 
     709                Debug << (int)vm->mViewCells.size() << " view cells loaded in " 
     710                          << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     711        } 
     712        else 
     713        { 
     714                Debug << "Error: loading view cells failed!" << endl; 
     715                DEL_PTR(vm); 
     716        } 
     717 
     718        return vm; 
     719} 
     720 
     721 
     722bool VspBspViewCellsManager::ExportViewCells(const string filename,  
     723                                                                                         const bool exportPvs,  
     724                                                                                         const ObjectContainer &objects) 
     725{ 
     726        if (!ViewCellsConstructed() || !ViewCellsTreeConstructed()) 
     727        { 
     728                return false; 
     729        } 
     730 
     731        cout << "exporting view cells to xml ... "; 
     732 
     733        OUT_STREAM stream(filename.c_str()); 
     734 
     735        // for output we need unique ids for each view cell 
     736        CreateUniqueViewCellIds(); 
     737 
     738        stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl; 
     739        stream << "<VisibilitySolution>" << endl; 
     740 
     741        if (exportPvs)  
     742        { 
     743                //-- export bounding boxes 
     744                stream << "<BoundingBoxes>" << endl; 
     745 
     746                if (mUseKdPvs) 
     747                { 
     748                        vector<KdIntersectable *>::iterator kit, kit_end = GetPreprocessor()->mKdTree->mKdIntersectables.end(); 
     749 
     750                        int id = 0; 
     751                        for (kit = GetPreprocessor()->mKdTree->mKdIntersectables.begin(); kit != kit_end; ++ kit, ++ id) 
     752                        { 
     753                                Intersectable *obj = *kit; 
     754                                const AxisAlignedBox3 box = obj->GetBox(); 
     755                   
     756                                obj->SetId(id); 
     757         
     758                                stream << "<BoundingBox" << " id=\"" << id << "\"" 
     759                                           << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 
     760                                           << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 
     761                        } 
     762                } 
     763                else 
     764                { 
     765                        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     766                 
     767                        for (oit = objects.begin(); oit != oit_end; ++ oit) 
     768                        { 
     769                                const AxisAlignedBox3 box = (*oit)->GetBox(); 
     770 
     771                                //////////// 
     772                                //-- the bounding boxes 
     773 
     774                                stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\"" 
     775                                           << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 
     776                                           << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 
     777                        } 
     778                } 
     779 
     780                stream << "</BoundingBoxes>" << endl; 
     781        } 
     782 
     783         
     784        ///////////// 
     785        //-- export the view cells and the pvs 
     786 
     787        const int numViewCells = mCurrentViewCellsStats.viewCells; 
     788        stream << "<ViewCells number=\"" << numViewCells << "\" >" << endl; 
     789 
     790        mViewCellsTree->Export(stream, exportPvs); 
     791 
     792        stream << "</ViewCells>" << endl; 
     793 
     794 
     795        ////////// 
     796        //-- export the view space hierarchy 
     797         
     798        stream << "<ViewSpaceHierarchy type=\"bsp\"" 
     799                   << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\"" 
     800                   << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\">" << endl; 
     801 
     802        mVspBspTree->Export(stream); 
     803        stream << "</ViewSpaceHierarchy>" << endl; 
     804 
     805        stream << "</VisibilitySolution>" << endl; 
     806 
     807        stream.close(); 
     808        cout << "finished" << endl; 
     809 
     810        return true; 
     811} 
     812 
    669813void ViewCellsManager::EvalViewCellHistogram(const string filename,  
    670814                                                                                         const int nViewCells) 
     
    757901        outstream.close(); 
    758902} 
    759  
    760  
    761 ViewCellsManager *ViewCellsManager::LoadViewCells(const string &filename,  
    762                                                                                                   ObjectContainer *objects, 
    763                                                                                                   bool finalizeViewCells, 
    764                                                                                                   BoundingBoxConverter *bconverter) 
    765                                                                                                   
    766 { 
    767         ViewCellsParser parser; 
    768         ViewCellsManager *vm = NULL; 
    769  
    770         const long startTime = GetTime(); 
    771         bool success = parser.ParseViewCellsFile(filename, &vm, objects, bconverter); 
    772  
    773         cout<<"viewcells parsed "<<endl<<flush; 
    774          
    775         if (success) 
    776         { 
    777                 //vm->ResetViewCells(); 
    778                 //hack 
    779                 vm->mViewCells.clear(); 
    780                 ViewCellContainer leaves; 
    781                 vm->mViewCellsTree->CollectLeaves(vm->mViewCellsTree->GetRoot(), leaves); 
    782  
    783                 ViewCellContainer::const_iterator it, it_end = leaves.end(); 
    784  
    785                 for (it = leaves.begin(); it != it_end; ++ it) 
    786                 { 
    787                         vm->mViewCells.push_back(*it); 
    788                 } 
    789                 vm->mViewCellsFinished = true; 
    790                 vm->mMaxPvsSize = (int)objects->size(); 
    791  
    792                 if (finalizeViewCells) 
    793                 { 
    794                         // create the meshes and compute volumes 
    795                         vm->FinalizeViewCells(true); 
    796                         // vm->mViewCellsTree->AssignRandomColors(); 
    797                 } 
    798  
    799                 Debug << (int)vm->mViewCells.size() << " view cells loaded in " 
    800                           << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    801         } 
    802         else 
    803         { 
    804                 Debug << "Error: loading view cells failed!" << endl; 
    805                 DEL_PTR(vm); 
    806         } 
    807  
    808         return vm; 
    809 } 
    810  
    811  
    812 bool VspBspViewCellsManager::ExportViewCells(const string filename,  
    813                                                                                          const bool exportPvs,  
    814                                                                                          const ObjectContainer &objects) 
    815 { 
    816         if (!ViewCellsConstructed() || !ViewCellsTreeConstructed()) 
    817         { 
    818                 return false; 
    819         } 
    820  
    821         cout << "exporting view cells to xml ... "; 
    822  
    823         OUT_STREAM stream(filename.c_str()); 
    824  
    825         // for output we need unique ids for each view cell 
    826         CreateUniqueViewCellIds(); 
    827  
    828         stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl; 
    829         stream << "<VisibilitySolution>" << endl; 
    830  
    831         if (exportPvs)  
    832         { 
    833                 //-- export bounding boxes 
    834                 stream << "<BoundingBoxes>" << endl; 
    835  
    836                 if (mUseKdPvs) 
    837                 { 
    838                         vector<KdIntersectable *>::iterator kit, kit_end = GetPreprocessor()->mKdTree->mKdIntersectables.end(); 
    839  
    840                         int id = 0; 
    841                         for (kit = GetPreprocessor()->mKdTree->mKdIntersectables.begin(); kit != kit_end; ++ kit, ++ id) 
    842                         { 
    843                                 Intersectable *obj = *kit; 
    844                                 const AxisAlignedBox3 box = obj->GetBox(); 
    845                    
    846                                 obj->SetId(id); 
    847          
    848                                 stream << "<BoundingBox" << " id=\"" << id << "\"" 
    849                                            << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 
    850                                            << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 
    851                         } 
    852                 } 
    853                 else 
    854                 { 
    855                         ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    856                  
    857                         for (oit = objects.begin(); oit != oit_end; ++ oit) 
    858                         { 
    859                                 const AxisAlignedBox3 box = (*oit)->GetBox(); 
    860  
    861                                 //////////// 
    862                                 //-- the bounding boxes 
    863  
    864                                 stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\"" 
    865                                            << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 
    866                                            << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 
    867                         } 
    868                 } 
    869  
    870                 stream << "</BoundingBoxes>" << endl; 
    871         } 
    872  
    873          
    874         ///////////// 
    875         //-- export the view cells and the pvs 
    876  
    877         const int numViewCells = mCurrentViewCellsStats.viewCells; 
    878         stream << "<ViewCells number=\"" << numViewCells << "\" >" << endl; 
    879  
    880         mViewCellsTree->Export(stream, exportPvs); 
    881  
    882         stream << "</ViewCells>" << endl; 
    883  
    884  
    885         ////////// 
    886         //-- export the view space hierarchy 
    887          
    888         stream << "<ViewSpaceHierarchy type=\"bsp\"" 
    889                    << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\"" 
    890                    << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\">" << endl; 
    891  
    892         mVspBspTree->Export(stream); 
    893         stream << "</ViewSpaceHierarchy>" << endl; 
    894  
    895         stream << "</VisibilitySolution>" << endl; 
    896  
    897         stream.close(); 
    898         cout << "finished" << endl; 
    899  
    900         return true; 
    901 } 
    902  
    903903 
    904904void ViewCellsManager::EvalViewCellHistogramForPvsSize(const string filename,  
     
    12691269                        filename = string(statsPrefix) + string(s); 
    12701270 
    1271                         EvalViewCellHistogramForPvsSize(filename, pass); 
     1271                        EvalViewCellHistogram(filename, pass); 
     1272                        //                      EvalViewCellHistogramForPvsSize(filename, pass); 
    12721273                } 
    12731274        } 
     
    19921993  stat.maxPvs = 0; 
    19931994  stat.avgPvs = 0.0f; 
     1995  stat.avgPvsEntries = 0.0f; 
    19941996  stat.avgFilteredPvs = 0.0f; 
     1997  stat.avgFilteredPvsEntries = 0.0f; 
    19951998  stat.avgFilterContribution = 0.0f; 
    19961999  stat.avgFilterRadius = 0; 
     
    20162019          if (viewcell->GetValid()) { 
    20172020                const float pvsCost = mViewCellsTree->GetPvsCost(viewcell); 
    2018                  
     2021 
    20192022                if (pvsCost < stat.minPvs) 
    20202023                  stat.minPvs = pvsCost; 
     
    20242027                stat.avgPvs += pvsCost; 
    20252028 
     2029                const float pvsEntries = mViewCellsTree->GetPvsEntries(viewcell); 
     2030                stat.avgPvsEntries += pvsEntries; 
     2031                 
    20262032 
    20272033                if (mPerViewCellStat[i].pvsSize > 0.0f) 
     
    20372043                if (evaluateFilter) { 
    20382044                  ObjectPvs filteredPvs; 
     2045                   
    20392046                  PvsFilterStatistics fstat = ApplyFilter2(viewcell, 
    20402047                                                                                                   false, 
     
    20432050                   
    20442051                  float filteredCost = filteredPvs.EvalPvsCost(); 
     2052 
    20452053                  stat.avgFilteredPvs += filteredCost; 
     2054                  stat.avgFilteredPvsEntries += filteredPvs.GetSize(); 
     2055                   
    20462056                  stat.avgFilterContribution += filteredCost - pvsCost; 
    20472057                   
     
    20662076  if (stat.viewcells) { 
    20672077        stat.avgPvs/=stat.viewcells; 
     2078        stat.avgPvsEntries/=stat.viewcells; 
    20682079        stat.avgFilteredPvs/=stat.viewcells; 
    20692080        stat.avgFilterContribution/=stat.viewcells; 
     
    20892100  GetPvsStatistics(pvsStat); 
    20902101  s<<"#AVG_PVS\n"<<pvsStat.avgPvs<<endl; 
     2102  s<<"#AVG_ENTRIES_PVS\n"<<pvsStat.avgPvsEntries<<endl; 
    20912103  s<<"#AVG_FILTERED_PVS\n"<<pvsStat.avgFilteredPvs<<endl; 
     2104  s<<"#AVG_FILTERED_ENTRIES_PVS\n"<<pvsStat.avgFilteredPvsEntries<<endl; 
    20922105  s<<"#AVG_FILTER_CONTRIBUTION\n"<<pvsStat.avgFilterContribution<<endl; 
    20932106  s<<"#AVG_FILTER_RADIUS\n"<<pvsStat.avgFilterRadius<<endl; 
     
    29913004          objects.clear(); 
    29923005          // $$ warning collect objects takes only unmailed ones! 
    2993           CollectObjects(box, objects); 
     3006          if (mUseKdPvsAfterFiltering) { 
     3007                float area = GetPreprocessor()->mKdTree->GetBox().SurfaceArea()*KD_PVS_AREA; 
     3008                GetPreprocessor()->mKdTree->CollectKdObjects(box, objects, area); 
     3009          } else 
     3010                CollectObjects(box, objects); 
     3011           
    29943012          //    cout<<"collected objects="<<objects.size()<<endl; 
    29953013          ObjectContainer::const_iterator noi = objects.begin(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1942 r1974  
    9292          float maxPvs; 
    9393          float avgPvs; 
     94          float avgPvsEntries; 
     95           
    9496          float avgFilteredPvs; 
     97          float avgFilteredPvsEntries; 
     98 
    9599          float avgFilterContribution; 
    96100          float avgFilterRadius; 
     
    775779 
    776780        bool mUseKdPvs; 
     781        bool mUseKdPvsAfterFiltering; 
    777782 
    778783        MixtureDistribution *mMixtureDistribution; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/default.env

    r1967 r1974  
    3636} 
    3737 
     38 
    3839Preprocessor { 
    39         totalSamples 10000000 
     40        totalSamples 250000000 
    4041        samplesPerPass 1000000 
    4142#       initialSamples 2000000 
     
    5051        rayCastMethod 1 
    5152         
    52         type sampling 
     53#       type sampling 
    5354#       type vss 
    5455#       type rss 
    55 #       type combined 
     56        type combined 
    5657#       type render 
    5758        detectEmptyViewSpace true 
     
    196197ViewCells { 
    197198        useKdPvs true 
     199        useKdPvsAfterFiltering true 
    198200        # samples used for view cell construction 
    199201        Construction { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro

    r1952 r1974  
    111111Trackball.cpp ObjExporter.cpp SubdivisionCandidate.cpp \ 
    112112Mailable.cpp \ 
    113 CombinedPreprocessor.cpp  
     113CombinedPreprocessor.cpp Vector2.cpp 
    114114 
    115115SOURCES += BoostPreprocessorThread.cpp  
  • GTP/trunk/Lib/Vis/Preprocessing/src/run_test2

    r1966 r1974  
    2929VIEWCELLS=../data/vienna/vienna_cropped-gradient-viewcells.xml.gz 
    3030 
    31 PREFIX=../work/plots/osp2-1e5 
     31PREFIX=../work/plots/osp-1e5 
    3232 
    3333#SCENE=../data/atlanta/atlanta2.x3d 
     
    3636 
    3737 
    38 $COMMAND -preprocessor=sampling -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 
    39 -preprocessor_visibility_file=$PREFIX-r-reference.xml \ 
    40 -view_cells_filter_max_size=1 -preprocessor_stats=$PREFIX-r-reference.log \ 
    41 -preprocessor_histogram_file=$PREFIX-r-reference.hlog 
     38# $COMMAND -preprocessor=sampling -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 
     39# -preprocessor_visibility_file=$PREFIX-r-reference.xml \ 
     40# -view_cells_filter_max_size=1 -preprocessor_stats=$PREFIX-r-reference.log \ 
     41# -preprocessor_histogram_file=$PREFIX-r-reference.hlog 
    4242 
    4343# $COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 
    44 # -rss_distributions=direction -view_cells_filter_max_size=1 \ 
    45 # -preprocessor_visibility_file=$PREFIX-r-reference-global.xml \ 
    46 # -preprocessor_stats=$PREFIX-r-reference-global.log \ 
    47 # -preprocessor_histogram_file=$PREFIX-r-reference-global.hlog 
     44#  -rss_distributions=direction -view_cells_filter_max_size=1 \ 
     45#  -preprocessor_visibility_file=$PREFIX-r-reference-global.xml \ 
     46#  -preprocessor_stats=$PREFIX-r-reference-global.log \ 
     47#  -preprocessor_histogram_file=$PREFIX-r-reference-global.hlog 
    4848 
    49 # $COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 
    50 # -rss_distributions=mutation+object_direction+spatial -view_cells_filter_max_size=1 \ 
    51 # -preprocessor_visibility_file=$PREFIX-i-mixed-b1-n4c.xml \ 
    52 # -preprocessor_stats=$PREFIX-i-mixed-b1-n4c.log \ 
    53 # -preprocessor_histogram_file=$PREFIX-i-mixed-b1-n4c.hlog 
     49$COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 
     50 -rss_distributions=mutation+object_direction+spatial -view_cells_filter_max_size=1 \ 
     51 -preprocessor_visibility_file=$PREFIX-i-mixed-b1-n4e.xml \ 
     52 -preprocessor_stats=$PREFIX-i-mixed-b1-n4e.log \ 
     53 -preprocessor_histogram_file=$PREFIX-i-mixed-b1-n4e.hlog 
    5454 
    5555# $COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 
Note: See TracChangeset for help on using the changeset viewer.