Changeset 1743


Ignore:
Timestamp:
11/13/06 15:34:15 (18 years ago)
Author:
bittner
Message:

merge with new pvs

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

Legend:

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

    r1742 r1743  
    15171517 
    15181518 
     1519Intersectable *HierarchyManager::GetIntersectable(Intersectable *obj, 
     1520                                                                                                  const Vector3 &point) const 
     1521{ 
     1522   
     1523  if (!obj) 
     1524        return NULL; 
     1525   
     1526  switch (mObjectSpaceSubdivisionType) 
     1527        { 
     1528        case HierarchyManager::KD_BASED_OBJ_SUBDIV: 
     1529          { 
     1530                KdLeaf *leaf = mOspTree->GetLeaf(point, NULL); 
     1531                return mOspTree->GetOrCreateKdIntersectable(leaf); 
     1532          } 
     1533        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
     1534          { 
     1535                BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 
     1536                return mBvHierarchy->GetOrCreateBvhIntersectable(leaf); 
     1537          } 
     1538        default: 
     1539          return obj; 
     1540        } 
     1541} 
     1542 
    15191543Intersectable *HierarchyManager::GetIntersectable(const VssRay &ray,  
    15201544                                                                                                  const bool isTermination) const 
    15211545{ 
    1522  
    1523         Intersectable *obj; 
     1546  Intersectable *obj = NULL; 
    15241547        Vector3 pt; 
    15251548        KdNode *node; 
     
    15271550        ray.GetSampleData(isTermination, pt, &obj, &node); 
    15281551         
    1529         if (!obj) return NULL; 
     1552        if (!obj) 
     1553          return NULL; 
    15301554 
    15311555        switch (mObjectSpaceSubdivisionType) 
     
    15331557        case HierarchyManager::KD_BASED_OBJ_SUBDIV: 
    15341558                { 
    1535                         KdLeaf *leaf = mOspTree->GetLeaf(pt, node); 
     1559                  KdLeaf *leaf = mOspTree->GetLeaf(pt, node); 
    15361560                        return mOspTree->GetOrCreateKdIntersectable(leaf); 
    15371561                } 
     
    15421566                } 
    15431567        default: 
    1544                 return obj; 
    1545         } 
     1568          break; 
     1569        } 
     1570        return obj; 
    15461571} 
    15471572 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1736 r1743  
    269269        */ 
    270270        Intersectable *GetIntersectable(const VssRay &ray, const bool isTermination) const; 
    271  
     271   
     272  Intersectable *GetIntersectable(Intersectable *obj, 
     273                                                                  const Vector3 &point) const; 
     274   
    272275        /** Export object space partition bounding boxes. 
    273276        */ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h

    r1736 r1743  
    102102  //////////////////////////////////////////////////// 
    103103  virtual AxisAlignedBox3 GetBox() const = 0; 
    104   virtual int CastRay(GtpVisibilityPreprocessor::Ray &ray) = 0; 
     104  virtual int CastRay(Ray &ray) = 0; 
    105105   
    106106  virtual bool IsConvex() const = 0; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Makefile

    r1737 r1743  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (2.00a) (Qt 4.1.2) on: ?t 9. XI 13:27:58 2006 
     3# Generated by qmake (2.00a) (Qt 4.1.2) on: po 13. XI 15:12:57 2006 
    44# Project:  preprocessor.pro 
    55# Template: app 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1740 r1743  
    10841084                        i ++; 
    10851085                  } 
    1086                 if (i % 10000 == 0) 
     1086 
     1087                if (rays.size() > 10000 && i % 10000 == 0) 
    10871088                  cout<<"\r"<<i<<"/"<<(int)rays.size()<<"\r"; 
    10881089        } 
    1089         cout<<endl; 
     1090 
     1091        if (rays.size() > 10000) { 
     1092          cout<<endl; 
    10901093         
    10911094        long t2 = GetTime(); 
     
    10961099        else 
    10971100                cout << rays.size() / (1e3f * TimeDiff(t1, t2)) << "M rays/s" << endl; 
    1098 #endif   
     1101#endif 
     1102        } 
    10991103} 
    11001104 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp

    r1737 r1743  
    286286         
    287287        // Render PVS 
    288         ObjectPvsMap::const_iterator it = viewcell->GetPvs().mEntries.begin(); 
    289  
    290         pvsSize = viewcell->GetPvs().mEntries.size(); 
    291          
    292         for (; it != viewcell->GetPvs().mEntries.end(); ++ it) { 
    293           Intersectable *object = (*it).first; 
     288        ObjectPvsIterator it = viewcell->GetPvs().GetIterator(); 
     289 
     290        pvsSize = viewcell->GetPvs().GetSize(); 
     291         
     292        for (; it.HasMoreEntries(); ) { 
     293          ObjectPvsEntry entry = it.Next(); 
     294          Intersectable *object = entry.mObject; 
    294295          RenderIntersectable(object); 
    295296        } 
     
    348349           
    349350          // Render PVS 
    350           ObjectPvsMap::const_iterator it = viewcell->GetPvs().mEntries.begin(); 
    351            
    352           for (; it != viewcell->GetPvs().mEntries.end(); ++ it) { 
    353                 Intersectable *object = (*it).first; 
     351          ObjectPvsIterator it = viewcell->GetPvs().GetIterator(); 
     352          for (; it.HasMoreEntries(); ) { 
     353                ObjectPvsEntry entry = it.Next(); 
     354                Intersectable *object = entry.mObject; 
    354355                RenderIntersectable(object); 
    355356          } 
     
    958959  PrVs prvs; 
    959960   
    960   if (!mUseFilter) { 
     961  if (1 || !mUseFilter) { 
    961962        viewcell = mViewCellsManager->GetViewCell(mViewPoint, true); 
    962963  } else { 
     
    968969  if (viewcell) { 
    969970        // copy the pvs so that it can be filtered... 
    970         ObjectPvs pvs = viewcell->GetPvs(); 
    971  
    972         if (mUseSpatialFilter) { 
    973           // 9.11. 2006 -> experiment with new spatial filter 
     971         
     972        ObjectPvs &pvs = mPvsCache.mPvs; 
     973         
     974        if (mPvsCache.mViewCell != viewcell) { 
     975          mPvsCache.Reset(); 
     976          mPvsCache.mViewCell = viewcell; 
     977           
     978          if (mUseSpatialFilter) { 
     979                // 9.11. 2006 -> experiment with new spatial filter 
    974980#if 0 
    975           mViewCellsManager->ApplySpatialFilter(mKdTree, 
    976                                                                                         mSpatialFilterSize* 
    977                                                                                         Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 
    978                                                                                         pvs); 
     981                mViewCellsManager->ApplySpatialFilter(mKdTree, 
     982                                                                                          mSpatialFilterSize* 
     983                                                                                          Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 
     984                                                                                          pvs); 
    979985#else 
    980           // mSpatialFilter size is in range 0.001 - 0.1 
    981           mViewCellsManager->ApplyFilter2(viewcell, 
    982                                                                           mUseFilter, 
    983                                                                           100*mSpatialFilterSize, 
    984                                                                           pvs); 
     986                // mSpatialFilter size is in range 0.001 - 0.1 
     987                mViewCellsManager->ApplyFilter2(viewcell, 
     988                                                                                mUseFilter, 
     989                                                                                100*mSpatialFilterSize, 
     990                                                                                pvs); 
    985991#endif 
    986         } 
    987          
    988          
    989         ObjectPvsMap::const_iterator it = pvs.mEntries.begin(); 
    990          
    991         mPvsSize = pvs.mEntries.size(); 
    992            
    993         for (; it != pvs.mEntries.end(); ++ it) { 
    994           Intersectable *object = (*it).first; 
     992          } else 
     993                pvs = viewcell->GetPvs(); 
     994        } 
     995 
     996        // Render PVS 
     997        ObjectPvsIterator it = pvs.GetIterator(); 
     998         
     999        mPvsSize = pvs.GetSize(); 
     1000         
     1001        for (; it.HasMoreEntries(); ) { 
     1002          ObjectPvsEntry entry = it.Next(); 
     1003          Intersectable *object = entry.mObject; 
    9951004           
    9961005          if (mRenderVisibilityEstimates) { 
    997                 float visibility = mTransferFunction*log10((*it).second.mSumPdf + 1); // /5.0f 
     1006                 
     1007                float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f 
    9981008                glColor3f(visibility, 0.0f, 0.0f); 
    9991009                mUseForcedColors = true; 
     
    10211031        } 
    10221032         
    1023         if (mUseFilter) 
     1033        if (0 && mUseFilter) 
    10241034          mViewCellsManager->DeleteLocalMergeTree(viewcell); 
     1035 
    10251036  } else { 
    10261037        ObjectContainer::const_iterator oi = mObjects.begin(); 
     
    17411752 
    17421753        //const int p = vc->GetPvs().CountObjectsInPvs(); 
    1743         const int p = vc->GetPvs().Size(); 
     1754        const int p = vc->GetPvs().GetSize(); 
    17441755        if (p > maxPvs) 
    17451756          maxPvs = p; 
     
    17591770        } else { 
    17601771          //      const float importance = 5.0f*mTransferFunction * ((float)vc->GetPvs().CountObjectsInPvs() / (float)maxPvs); 
    1761           const float importance = 5.0f*mTransferFunction * ((float)vc->GetPvs().Size() / (float)maxPvs); 
     1772          const float importance = 5.0f*mTransferFunction * ((float)vc->GetPvs().GetSize() / (float)maxPvs); 
    17621773          c = RgbColor(importance, 1.0f - importance, 0.0f); 
    17631774        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.h

    r1694 r1743  
    169169  void SetCutScene(bool); 
    170170 
    171    
     171}; 
     172 
     173 
     174struct PvsCache { 
     175  PvsCache():mViewCell(NULL) {} 
     176  Reset() { mViewCell = NULL; mPvs.Clear(); } 
     177  ViewCell *mViewCell; 
     178  ObjectPvs mPvs; 
    172179}; 
    173180 
     
    205212  float mManipulatorLastQuat[4]; 
    206213  float mManipulatorScale; 
     214  PvsCache mPvsCache; 
    207215   
    208216  QtRendererControlWidget *mControlWidget; 
     
    300308  void SetUseFilter(bool b) { 
    301309   mUseFilter = b; 
     310   mPvsCache.Reset(); 
    302311   updateGL(); 
    303312 } 
     
    305314  void SetUseSpatialFilter(bool b) { 
    306315        mUseSpatialFilter = b; 
     316        mPvsCache.Reset(); 
    307317        updateGL(); 
    308318  } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp

    r1715 r1743  
    99#include "ViewCellsManager.h" 
    1010#include "RenderSimulator.h" 
     11#include "VssRay.h" 
    1112 
    1213 
     
    3031} 
    3132 
    32 Intersectable * 
    33 SamplingPreprocessor::CastRay( 
    34                                                           const Vector3 &origin, 
    35                                                           const Vector3 &direction 
    36                                                           ) 
    37 { 
    38   AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 
    39    
    40   AxisAlignedBox3 sbox = box; 
    41   sbox.Enlarge(Vector3(-Limits::Small)); 
    42   if (!sbox.IsInside(origin)) 
    43         return 0; 
    44    
    45   Vector3 point, normal; 
    46   Intersectable *object; 
    4733 
    48   // cast ray to KD tree to find intersection with other objects 
    49 #if 0 
    50   object = CastSimpleRay(origin, 
    51                                                  direction, 
    52                                                  mKdTree->GetBox(), 
    53                                                  point, 
    54                                                  normal 
    55                                                  ); 
    56 #endif 
    57  
    58   if (mDetectEmptyViewSpace && DotProd(normal, direction) >= 0) { 
    59         object = NULL; 
    60   } 
    61    
    62   return object; 
    63 } 
    64  
    65 void 
    66 SamplingPreprocessor::HoleSamplingPass() 
    67 { 
    68   vector<KdLeaf *> leaves; 
    69   mKdTree->CollectLeaves(leaves); 
    70    
    71   // go through all the leaves and evaluate their passing contribution 
    72   for (int i=0 ; i < leaves.size(); i++) { 
    73     KdLeaf *leaf = leaves[i]; 
    74     cout<<leaf->mPassingRays<<endl; 
    75   } 
    76 } 
    7734 
    7835 
     
    12784        ConstructViewCells(); 
    12885  } 
    129      
     86 
     87  int intersectables, faces; 
     88  mSceneGraph->GetStatistics(intersectables, faces); 
     89   
    13090  int samples = 0; 
    13191  int i=0; 
    13292  while (samples < mTotalSamples) { 
    133         for (i=0; i < mSamplesPerPass; i++, samples++) { 
     93        for (i=0; i < mSamplesPerPass;) { 
     94          SimpleRayContainer rays; 
     95          VssRayContainer vssRays; 
     96          vector<ViewCell *> viewcells; 
     97          for (; rays.size() < 16; ) { 
     98                if (i%10000 == 0) 
     99                  cout<<"+"; 
     100 
     101                Vector3 origin, direction; 
     102                mViewCellsManager->GetViewPoint( origin ); 
     103                 
     104                direction = UniformRandomVector(); 
     105                ViewCell *viewcell = mViewCellsManager->GetViewCell(origin); 
     106                 
     107                if (viewcell && viewcell->GetValid()) { 
     108                  viewcells.push_back(viewcell); 
     109                  // cast rays in both directions to make the number of samples comparable 
     110                  // with the global sampling method which also casts a "double" ray per sample 
     111                  rays.push_back(SimpleRay(origin, direction)); 
     112                  i++; 
     113                  samples++; 
     114                } 
     115          } 
    134116           
    135           if (i%10000 == 0) 
    136                 cout<<"+"; 
    137            
    138           Vector3 origin, direction; 
    139           mViewCellsManager->GetViewPoint(origin); 
    140           direction = UniformRandomVector(); 
     117          CastRays(rays, 
     118                           vssRays, 
     119                           true, 
     120                           false); 
    141121 
    142            
    143           ViewCell *viewcell = mViewCellsManager->GetViewCell(origin); 
    144            
    145           if (viewcell && viewcell->GetValid()) { 
    146                 // cast rays in both directions to make the number of samples comparable 
    147                 // with the global sampling method which also casts a "double" ray per sample 
    148                 for (int j=0; j < 2; j++) { 
    149                   Intersectable *object = CastRay(origin, direction); 
    150                   if (object) { 
    151                         // if ray not outside of view space 
     122          if (vssRays.size()!=32) { 
     123                cerr<<"wrong number of rays "<<vssRays.size()<<endl; 
     124                exit(1); 
     125          } 
     126                 
     127          for (int j=0; j < vssRays.size(); j++) { 
     128                Intersectable *obj = mViewCellsManager->GetIntersectable(*(vssRays[j]), true); 
     129                if (obj) { 
     130                  // if ray not outside of view space 
    152131                        float contribution; 
    153132                        int pvsContribution = 0; 
    154133                        float relativePvsContribution = 0; 
    155                         if (object) { 
    156                           float pdf = 1.0f; 
    157                           if (viewcell->GetPvs().GetSampleContribution(object, 
    158                                                                                                                    pdf, 
    159                                                                                                                    contribution)) 
    160                                 ++pvsContribution; 
    161                           relativePvsContribution += contribution; 
    162                           viewcell->GetPvs().AddSample(object, pdf); 
    163                         } 
    164                   } 
    165                   direction = -direction; 
     134                        float pdf = 1.0f; 
     135                        ViewCell *viewcell = viewcells[j/2]; 
     136                        if (viewcell->GetPvs().GetSampleContribution(obj, 
     137                                                                                                                 pdf, 
     138                                                                                                                 contribution))  
     139                          ++pvsContribution; 
     140                        relativePvsContribution += contribution; 
     141                        viewcell->GetPvs().AddSample(obj, pdf); 
    166142                } 
    167143          } 
     144           
    168145           
    169146          if (samples > mTotalSamples) 
    170147                break; 
    171148        } 
    172          
     149 
     150        Debug<<"Valid viewcells before set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; 
     151        mViewCellsManager->SetValidity(0, intersectables/2); 
     152        Debug<<"Valid viewcells after set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; 
     153 
    173154        //      mVssRays.PrintStatistics(mStats); 
    174155        mStats << 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.h

    r1221 r1743  
    3434                   const Ray::Intersection &source); 
    3535   
    36   /** Refined sampling for finding "holes", i.e., difficult visibility. 
    37    */ 
    38   void 
    39   HoleSamplingPass(); 
    4036   
    4137   
    42   Intersectable * 
    43   CastRay( 
    44                   const Vector3 &origin, 
    45                   const Vector3 &direction 
    46                   ); 
    4738   
    4839  /** Verify if the exact visibility for this object was established. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1742 r1743  
    314314} 
    315315 
     316Intersectable * 
     317ViewCellsManager::GetIntersectable(const VssRay &ray, const bool isTermination) const 
     318{ 
     319  return isTermination ? ray.mTerminationObject : ray.mOriginObject; 
     320} 
    316321 
    317322void 
     
    25912596  // first determine the average size of the filter 
    25922597 
     2598  pvs = viewCell->GetPvs(); 
    25932599  Intersectable::NewMail(); 
    2594  
     2600   
    25952601  ObjectPvsIterator pit = pvs.GetIterator(); 
    25962602 
     
    27122718          ObjectContainer::const_iterator noi = objects.begin(); 
    27132719          for (; noi != objects.end(); ++ noi) { 
    2714                   Intersectable *o = *noi; 
    2715                   // $$ JB warning: pdfs are not correct at this point!    
    2716                   nPvs.AddSample(o, Limits::Small); 
    2717                   nPvsSize ++; 
     2720                Intersectable *o = *noi; 
     2721                // $$ JB warning: pdfs are not correct at this point!      
     2722                nPvs.AddSample(o, Limits::Small); 
     2723                nPvsSize ++; 
    27182724          } 
    27192725  } 
     
    27212727   
    27222728  pvs.MergeInPlace(nPvs); 
    2723  
     2729   
    27242730  Intersectable::NewMail(); 
    27252731} 
     
    50935099} 
    50945100 
     5101Intersectable * 
     5102VspOspViewCellsManager::GetIntersectable(const VssRay &ray, const bool isTermination) const 
     5103{ 
     5104  return mHierarchyManager->GetIntersectable(ray, isTermination); 
     5105} 
    50955106 
    50965107HierarchyManager *VspOspViewCellsManager::CreateHierarchyManager(const string &hierarchyType) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1740 r1743  
    178178        ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const; 
    179179 
     180 
     181  virtual Intersectable * 
     182  GetIntersectable(const VssRay &ray, const bool isTermination) const; 
     183 
    180184        /** Sets maximal number of samples used for the  
    181185                construction of the view cells. 
     
    10671071        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const; 
    10681072 
     1073  virtual Intersectable * 
     1074  GetIntersectable(const VssRay &ray, const bool isTermination) const; 
     1075 
    10691076        bool ViewCellsConstructed() const; 
    10701077 
  • GTP/trunk/Lib/Vis/Preprocessing/src/default.env

    r1737 r1743  
    5151#       type render 
    5252        detectEmptyViewSpace true 
    53 #       pvsRenderErrorSamples 0 
    54         pvsRenderErrorSamples 1000 
     53        pvsRenderErrorSamples 0 
     54#       pvsRenderErrorSamples 1000 
    5555        quitOnFinish true 
    5656        computeVisibility true 
     
    7575 
    7676SamplingPreprocessor { 
    77         totalSamples 10000000 
     77        totalSamples 100000000 
    7878        samplesPerPass 1000000 
    7979} 
     
    8282        samplesPerPass 1000 
    8383        initialSamples 2000000 
    84         vssSamples 50000000 
     84        vssSamples 100000000 
    8585#       vssSamples 1000000 
    8686        vssSamplesPerPass 3000000 
Note: See TracChangeset for help on using the changeset viewer.