Changeset 1761


Ignore:
Timestamp:
11/16/06 15:41:44 (18 years ago)
Author:
bittner
Message:

filter updates, kd + bvh PVS coexistence

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

Legend:

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

    r1760 r1761  
    2727#define USE_VOLUMES_FOR_HEURISTICS 1 
    2828 
    29 int BvhNode::sMailId = 10000; //2147483647; 
    30 int BvhNode::sReservedMailboxes = 1; 
     29//int BvhNode::sMailId = 10000; //2147483647; 
     30//int BvhNode::sReservedMailboxes = 1; 
    3131 
    3232BvHierarchy *BvHierarchy::BvhSubdivisionCandidate::sBvHierarchy = NULL; 
     
    18711871        if (!object)  
    18721872                return NULL; 
    1873          
    18741873        return object->mBvhLeaf; 
    18751874         
     
    23972396        nodeStack.pop(); 
    23982397         
    2399           if (node->IsLeaf())  
    2400                 { 
    2401           BvhLeaf *leaf = (BvhLeaf *)node; 
    2402           if (Overlap(box, leaf->GetBoundingBox())) { 
    2403                         Intersectable *object = leaf; 
    2404                 if (!object->Mailed()) { 
    2405                   object->Mail(); 
    2406                   objects.push_back(object); 
    2407                 } 
     2398        if (node->IsLeaf())  
     2399          { 
     2400                BvhLeaf *leaf = (BvhLeaf *)node; 
     2401                if (Overlap(box, leaf->GetBoundingBox())) { 
     2402                  Intersectable *object = leaf; 
     2403                  if (!object->Mailed()) { 
     2404                        object->Mail(); 
     2405                        objects.push_back(object); 
     2406                  } 
     2407                } 
     2408          }  
     2409        else  
     2410          { 
     2411                BvhInterior *interior = (BvhInterior *)node; 
     2412                 
     2413                if (Overlap(box, interior->GetBoundingBox())) 
     2414                  nodeStack.push(interior->GetFront()); 
     2415                 
     2416                if (Overlap(box, interior->GetBoundingBox())) 
     2417                  nodeStack.push(interior->GetBack()); 
    24082418          } 
    2409         }  
    2410           else  
    2411                 { 
    2412           BvhInterior *interior = (BvhInterior *)node; 
    2413            
    2414           if (Overlap(box, interior->GetBoundingBox())) 
    2415                 nodeStack.push(interior->GetFront()); 
    2416            
    2417           if (Overlap(box, interior->GetBoundingBox())) 
    2418                 nodeStack.push(interior->GetBack()); 
    2419         } 
    2420   } 
    2421 } 
    2422  
    2423 } 
     2419        } 
     2420} 
     2421 
     2422} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1758 r1761  
    206206        //-- mailing options 
    207207         
    208         static void NewMail(const int reserve = 1) { 
    209                 sMailId += sReservedMailboxes; 
    210                 sReservedMailboxes = reserve; 
    211         } 
    212          
    213         void Mail() { mMailbox = sMailId; } 
    214         bool Mailed() const { return mMailbox == sMailId; } 
    215  
    216         void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 
    217         bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 
    218  
    219         int IncMail() { return ++ mMailbox - sMailId; } 
    220  
    221         static int sMailId; 
    222         //int mMailbox; 
    223         static int sReservedMailboxes; 
     208//      static void NewMail(const int reserve = 1) { 
     209//              sMailId += sReservedMailboxes; 
     210//              sReservedMailboxes = reserve; 
     211//      } 
     212         
     213//      void Mail() { mMailbox = sMailId; } 
     214//      bool Mailed() const { return mMailbox == sMailId; } 
     215 
     216//      void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 
     217//      bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 
     218 
     219//      int IncMail() { return ++ mMailbox - sMailId; } 
     220 
     221//      static int sMailId; 
     222//      //int mMailbox; 
     223//      static int sReservedMailboxes; 
    224224 
    225225 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r1757 r1761  
    14641464        RegisterOption("ViewCells.processOnlyValidViewCells", 
    14651465                                        optBool, 
    1466                                         "view_cells_process_only_valid_view_cells=", 
     1466                                        "view_cells_process_only_valid_view_cells", 
    14671467                                        "false"); 
    14681468 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r1736 r1761  
    2121 
    2222 
    23 KdNode::KdNode(KdInterior *parent):mParent(parent), mMailbox(0) 
     23KdNode::KdNode(KdInterior *parent):mParent(parent), mMailbox(0), mIntersectable(NULL) 
     24 
    2425{ 
    2526  if (parent) 
     
    14051406  if (node == NULL) 
    14061407        return NULL; 
    1407    
    1408   // search nodes 
    1409   std::map<KdNode *, KdIntersectable *>:: 
    1410         const_iterator it = mKdIntersectables.find(node); 
    1411    
    1412   if (it != mKdIntersectables.end())  
    1413         { 
    1414           return (*it).second; 
    1415         } 
    1416    
    1417   // not in map => create new entry 
    1418   KdIntersectable *kdObj = new KdIntersectable(node, GetBox(node)); 
    1419   mKdIntersectables[node] = kdObj; 
    1420    
    1421   return kdObj; 
     1408 
     1409  if (node->mIntersectable == NULL) { 
     1410        // not in map => create new entry 
     1411        node->mIntersectable = new KdIntersectable(node, GetBox(node)); 
     1412        mKdIntersectables.push_back(node->mIntersectable); 
     1413  } 
     1414 
     1415  return node->mIntersectable; 
    14221416} 
    14231417 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h

    r1633 r1761  
    101101  static int sReservedMailboxes; 
    102102  int mMailbox; 
     103 
     104  KdIntersectable *mIntersectable; 
    103105   
    104106  void Mail() { mMailbox = sMailId; } 
     
    596598public: 
    597599  /// stores the kd node intersectables used for pvs 
    598   KdIntersectableMap mKdIntersectables; 
    599  
     600  vector<KdIntersectable *> mKdIntersectables; 
     601   
    600602}; 
    601603 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Makefile

    r1757 r1761  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (2.00a) (Qt 4.1.2) on: Tue Nov 14 23:59:07 2006 
     3# Generated by qmake (2.00a) (Qt 4.1.2) on: Thu Nov 16 14:37:00 2006 
    44# Project:  preprocessor.pro 
    55# Template: app 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp

    r1737 r1761  
    525525        } 
    526526         
    527         mVssRays.PrintStatistics(mStats); 
    528         mViewCellsManager->PrintPvsStatistics(mStats); 
    529527           
    530528        // viewcells->UpdatePVS(newVssRays); 
     
    534532        mViewCellsManager->SetValidityPercentage(0, 1.0f);  
    535533        Debug<<"Valid viewcells after set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; 
    536          
     534 
     535        mVssRays.PrintStatistics(mStats); 
     536        mViewCellsManager->PrintPvsStatistics(mStats); 
     537 
    537538        ComputeRenderError(); 
    538539  } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp

    r1757 r1761  
    144144          } 
    145145           
    146            
     146          CLEAR_CONTAINER(vssRays); 
     147 
    147148          if (samples > mTotalSamples) 
    148149                break; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r1732 r1761  
    245245        } 
    246246 
     247  static bool GreaterOrEqualPvs(const ViewCell *a, const ViewCell *b) { 
     248        return !SmallerPvs(a, b); 
     249  } 
     250 
    247251        static bool SmallerRenderCost(const ViewCell *a, const ViewCell *b)  
    248252        { 
     
    267271        float GetMergeCost() const; 
    268272 
     273 
     274  float GetCachedPvsCost() const { 
     275        return mPvsCost; 
     276  } 
    269277 
    270278        ////////// 
     
    483491        */ 
    484492        float GetPvsCost(ViewCell *vc) const; 
     493   
    485494 
    486495        /** Returns number of entries associated with this view cell.  
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1760 r1761  
    3232 
    3333// $$JB HACK 
    34 #define USE_KD_PVS 0 
    35 #define KD_PVS_AREA (5*1e-4f) 
     34#define USE_KD_PVS 1 
     35#define KD_PVS_AREA (1e-4f) 
    3636 
    3737 
     
    8787{ 
    8888        // visualization stuff 
    89         Environment::GetSingleton()->GetBoolValue("ViewCells.Visualization.exportRays", mExportRays); 
     89        Environment::GetSingleton()->GetBoolValue("ViewCells.Visualization.exportRays", mExportRays); 
    9090        Environment::GetSingleton()->GetBoolValue("ViewCells.Visualization.exportGeometry", mExportGeometry); 
    9191        Environment::GetSingleton()->GetFloatValue("ViewCells.maxPvsRatio", mMaxPvsRatio); 
     
    317317ViewCellsManager::GetIntersectable(const VssRay &ray, const bool isTermination) const 
    318318{ 
     319#if USE_KD_PVS 
     320  float area = GetPreprocessor()->mKdTree->GetBox().SurfaceArea()*KD_PVS_AREA; 
     321  KdNode *node = GetPreprocessor()->mKdTree->GetNode(isTermination ? 
     322                                                                                                         ray.mTermination : ray.mOrigin, 
     323                                                                                                         area); 
     324  return  
     325        GetPreprocessor()->mKdTree-> 
     326        GetOrCreateKdIntersectable(node); 
     327#else 
    319328  return isTermination ? ray.mTerminationObject : ray.mOriginObject; 
     329#endif 
    320330} 
    321331 
     
    794804                stream << "<BoundingBoxes>" << endl; 
    795805#if USE_KD_PVS  
    796         KdIntersectableMap::const_iterator kit, kit_end = GetPreprocessor()->mKdTree->mKdIntersectables.end(); 
     806                vector<KdIntersectable *>::iterator kit, kit_end = GetPreprocessor()->mKdTree->mKdIntersectables.end(); 
    797807 
    798808                int id = 0; 
    799809                for (kit = GetPreprocessor()->mKdTree->mKdIntersectables.begin(); kit != kit_end; ++ kit, ++ id) 
    800810                { 
    801                         Intersectable *obj = (*kit).second; 
    802                         const AxisAlignedBox3 box = obj->GetBox(); 
    803                  
    804                         obj->SetId(id); 
    805  
    806                         stream << "<BoundingBox" << " id=\"" << id << "\"" 
    807                                    << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 
    808                                    << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 
     811                  Intersectable *obj = *kit; 
     812                  const AxisAlignedBox3 box = obj->GetBox(); 
     813                   
     814                  obj->SetId(id); 
     815                   
     816                  stream << "<BoundingBox" << " id=\"" << id << "\"" 
     817                                 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 
     818                                 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 
    809819                } 
    810820#else 
    811         ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    812  
     821                ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     822                 
    813823                for (oit = objects.begin(); oit != oit_end; ++ oit) 
    814824                { 
     
    955965                                                                          float &contribution) const 
    956966{ 
    957         if (!obj) return false; 
    958  
     967        if (!obj) 
     968          return false; 
     969         
    959970        // potentially visible objects 
    960971        return vc->AddPvsSample(obj, pdf, contribution); 
     
    14011412                                                                                ) 
    14021413{ 
    1403         sort(mViewCells.begin(), mViewCells.end(), ViewCell::SmallerPvs); 
    1404  
    1405         int start = (int)(mViewCells.size() * minValid); 
    1406         int end = (int)(mViewCells.size() * maxValid); 
    1407  
    1408         for (int i = 0; i < (int)mViewCells.size(); ++ i) 
    1409         { 
    1410                 mViewCells[i]->SetValid(i >= start && i <= end); 
     1414  ObjectPvs dummyPvs; 
     1415  // update pvs sizes 
     1416  for (int i = 0; i < (int)mViewCells.size(); ++ i) { 
     1417        UpdatePvsForEvaluation(mViewCells[i], dummyPvs); 
     1418  } 
     1419   
     1420  sort(mViewCells.begin(), mViewCells.end(), ViewCell::SmallerPvs); 
     1421   
     1422  int start = (int)(mViewCells.size() * minValid); 
     1423  int end = (int)(mViewCells.size() * maxValid); 
     1424   
     1425  for (int i = 0; i < (int)mViewCells.size(); ++ i) 
     1426        { 
     1427          //      cout<<"pvs:"<<mViewCells[i]->GetCachedPvsCost()<<endl; 
     1428          mViewCells[i]->SetValid(i >= start && i <= end); 
    14111429        } 
    14121430} 
     
    18211839  stat.avgFilteredPvs = 0.0f; 
    18221840  stat.avgFilterContribution = 0.0f; 
     1841  stat.avgFilterRadius = 0; 
     1842  stat.avgFilterRatio = 0; 
    18231843   
    18241844  for (; it != mViewCells.end(); ++ it)  
    18251845        { 
    18261846          ViewCell *viewcell = *it; 
    1827            
    1828           const float pvsCost = mViewCellsTree->GetPvsCost(viewcell); 
    1829            
    1830           if (pvsCost < stat.minPvs) 
    1831                 stat.minPvs = pvsCost; 
    1832           if (pvsCost > stat.maxPvs) 
    1833                 stat.maxPvs = pvsCost; 
    1834            
    1835           stat.avgPvs += pvsCost; 
    1836  
    1837           const bool evaluateFilter = true; 
    1838            
    1839           if (evaluateFilter) { 
    1840                 ObjectPvs filteredPvs = viewcell->GetPvs(); 
    1841                 ApplyFilter2(viewcell, false, 1.0f, filteredPvs); 
    1842                 float filteredCost = filteredPvs.EvalPvsCost(); 
    1843                 stat.avgFilteredPvs += filteredCost; 
    1844                 stat.avgFilterContribution += filteredCost - pvsCost; 
    1845           } else { 
    1846                 stat.avgFilteredPvs += pvsCost; 
    1847                 stat.avgFilterContribution += 0; 
     1847          if (viewcell->GetValid()) { 
     1848                const float pvsCost = mViewCellsTree->GetPvsCost(viewcell); 
     1849                 
     1850                if (pvsCost < stat.minPvs) 
     1851                  stat.minPvs = pvsCost; 
     1852                if (pvsCost > stat.maxPvs) 
     1853                  stat.maxPvs = pvsCost; 
     1854                 
     1855                stat.avgPvs += pvsCost; 
     1856                 
     1857                const bool evaluateFilter = true; 
     1858                 
     1859                if (evaluateFilter) { 
     1860                  ObjectPvs filteredPvs = viewcell->GetPvs(); 
     1861                  PvsFilterStatistics fstat = ApplyFilter2(viewcell, false, 1.0f, filteredPvs); 
     1862                   
     1863                  float filteredCost = filteredPvs.EvalPvsCost(); 
     1864                  stat.avgFilteredPvs += filteredCost; 
     1865                  stat.avgFilterContribution += filteredCost - pvsCost; 
     1866 
     1867                  stat.avgFilterRadius += fstat.mAvgFilterRadius; 
     1868                  stat.avgFilterRatio += fstat.mLocalFilterCount / (float) fstat.mGlobalFilterCount; 
     1869                   
     1870                   
     1871                } else { 
     1872                  stat.avgFilteredPvs += pvsCost; 
     1873                  stat.avgFilterContribution += 0; 
     1874                } 
     1875                 
     1876                ++ stat.viewcells; 
    18481877          } 
    1849            
    1850           ++ stat.viewcells; 
    18511878        } 
    18521879   
     
    18551882        stat.avgFilteredPvs/=stat.viewcells; 
    18561883        stat.avgFilterContribution/=stat.viewcells; 
     1884        stat.avgFilterRadius/=stat.viewcells; 
     1885        stat.avgFilterRatio/=stat.viewcells; 
    18571886  } 
    18581887} 
     
    18671896  s<<"#AVG_FILTERED_PVS\n"<<pvsStat.avgFilteredPvs<<endl; 
    18681897  s<<"#AVG_FILTER_CONTRIBUTION\n"<<pvsStat.avgFilterContribution<<endl; 
     1898  s<<"#AVG_FILTER_RADIUS\n"<<pvsStat.avgFilterRadius<<endl; 
     1899  s<<"#AVG_FILTER_RATIO\n"<<pvsStat.avgFilterRatio<<endl; 
    18691900  s<<"#MAX_PVS\n"<<pvsStat.maxPvs<<endl; 
    18701901  s<<"#MIN_PVS\n"<<pvsStat.minPvs<<endl; 
     
    19852016        return; 
    19862017   
    1987 #if USE_KD_PVS 
    1988   float area = GetPreprocessor()->mKdTree->GetBox().SurfaceArea()*KD_PVS_AREA; 
    1989   KdNode *node = GetPreprocessor()->mKdTree->GetNode(ray.mTermination, area); 
    1990   Intersectable *obj = 
    1991         GetPreprocessor()->mKdTree-> 
    1992         GetOrCreateKdIntersectable(node); 
    1993 #else 
    1994   Intersectable *obj = ray.mTerminationObject; 
    1995 #endif 
     2018  Intersectable *obj = GetIntersectable(ray, true); 
    19962019   
    19972020  for (it = viewcells->begin(); it != viewcells->end(); ++it) { 
     
    20372060                ray.mViewCells = viewcells; 
    20382061        } 
    2039  
    2040 #if USE_KD_PVS 
    2041         float area = GetPreprocessor()->mKdTree->GetBox().SurfaceArea()*KD_PVS_AREA; 
    2042         KdNode *node = GetPreprocessor()->mKdTree->GetNode(ray.mTermination, area); 
    2043         Intersectable *obj = 
    2044           GetPreprocessor()->mKdTree-> 
    2045           GetOrCreateKdIntersectable(node); 
    2046 #else 
    2047         Intersectable *obj = ray.mTerminationObject; 
    2048 #endif 
     2062         
     2063        Intersectable *obj = GetIntersectable(ray, true); 
    20492064         
    20502065         
     
    25902605 
    25912606 
    2592 void 
     2607PvsFilterStatistics 
    25932608ViewCellsManager::ApplyFilter2(ViewCell *viewCell, 
    25942609                                                           const bool useViewSpaceFilter, 
     
    25972612                                                           ) 
    25982613{ 
     2614  PvsFilterStatistics stats; 
     2615 
    25992616  AxisAlignedBox3 vbox = GetViewCellBox(viewCell); 
    26002617  Vector3 center = vbox.Center(); 
    2601    
    26022618  // COpy the PVS 
    26032619  ObjectPvs basePvs = viewCell->GetPvs(); 
     
    26062622  ObjectPvsIterator pit = basePvs.GetIterator(); 
    26072623 
     2624#if !USE_KD_PVS 
    26082625  // first mark all object from this pvs 
    26092626  while (pit.HasMoreEntries()) {                 
     
    26132630        object->Mail(); 
    26142631  } 
    2615  
     2632#endif 
    26162633 
    26172634  int pvsSize = 0; 
    26182635  int nPvsSize = 0; 
    2619   float samples = (float)pvs.GetSamples(); 
    2620  
    2621   //  cout<<"#s"<<samples<<endl; 
    2622   //  cout<<"pvs size = "<<pvs.GetSize() <<endl; 
     2636  float samples = (float)basePvs.GetSamples(); 
     2637   
     2638  cout<<"f #s="<<samples<<"pvs size = "<<basePvs.GetSize(); 
    26232639  //  cout<<"Filter size = "<<filterSize<<endl; 
    26242640  //  cout<<"vbox = "<<vbox<<endl; 
     
    26352651#define MIN_LOCAL_SAMPLES 5 
    26362652 
    2637   float globalC = 2.0f*filterSize/sqrt(samples); 
    26382653  float viewCellRadius = 0.5f*Magnitude(vbox.Diagonal()); 
    26392654   
     
    26592674        // update samples and globalC 
    26602675        samples = (float)pvs.GetSamples(); 
    2661         globalC = 2.0f*filterSize/sqrt(samples); 
    26622676        //      cout<<"neighboring viewcells = "<<i-1<<endl; 
    26632677        //      cout<<"Samples' = "<<samples<<endl; 
    26642678  } 
     2679 
     2680  // Minimal number of samples so that filtering takes place 
     2681#define MIN_SAMPLES  100 
     2682  if (samples > MIN_SAMPLES) { 
     2683        float globalC = 2.0f*filterSize/sqrt(samples); 
     2684         
     2685        pit = basePvs.GetIterator(); 
     2686         
     2687        ObjectContainer objects; 
     2688         
     2689        while (pit.HasMoreEntries()) 
     2690          {              
     2691                ObjectPvsEntry entry = pit.Next(); 
     2692                 
     2693                Intersectable *object = entry.mObject; 
     2694                // compute filter size based on the distance and the numebr of samples 
     2695                AxisAlignedBox3 box = object->GetBox(); 
     2696                 
     2697                float distance = Distance(center, box.Center()); 
     2698                float globalRadius = distance*globalC; 
     2699                 
     2700                int objectSamples = (int)entry.mData.mSumPdf; 
     2701                float localRadius = MAX_FLOAT; 
     2702                if (objectSamples > MIN_LOCAL_SAMPLES) 
     2703                  localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 
     2704                        sqrt((float)objectSamples); 
     2705                 
     2706                //      cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 
     2707                 
     2708                // now compute the filter size 
     2709                float radius; 
     2710 
     2711                if (localRadius < globalRadius) { 
     2712                  radius = localRadius; 
     2713                  stats.mLocalFilterCount++; 
     2714                } else { 
     2715                  radius = globalRadius; 
     2716                  stats.mGlobalFilterCount++; 
     2717                } 
     2718 
     2719                stats.mAvgFilterRadius += radius; 
     2720                 
     2721                // cout<<"box = "<<box<<endl; 
     2722                //      cout<<"distance = "<<distance<<endl; 
     2723                //      cout<<"radiues = "<<radius<<endl; 
     2724                 
     2725                box.Enlarge(Vector3(radius)); 
     2726                 
     2727                objects.clear(); 
     2728                // $$ warning collect objects takes only unmailed ones! 
     2729                CollectObjects(box, objects); 
     2730                //      cout<<"collected objects="<<objects.size()<<endl; 
     2731                ObjectContainer::const_iterator noi = objects.begin(); 
     2732                for (; noi != objects.end(); ++ noi) { 
     2733                  Intersectable *o = *noi; 
     2734                  // $$ JB warning: pdfs are not correct at this point!    
     2735                  pvs.AddSampleDirty(o, Limits::Small); 
     2736                } 
     2737          } 
     2738        stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 
     2739  } 
    26652740   
    2666   pit = basePvs.GetIterator(); 
    2667  
    2668   ObjectContainer objects; 
    2669  
    2670   while (pit.HasMoreEntries()) 
    2671   {              
    2672         ObjectPvsEntry entry = pit.Next(); 
    2673  
    2674         Intersectable *object = entry.mObject; 
    2675         // compute filter size based on the distance and the numebr of samples 
    2676         AxisAlignedBox3 box = object->GetBox(); 
    2677          
    2678         float distance = Distance(center, box.Center()); 
    2679         float globalRadius = distance*globalC; 
    2680          
    2681         int objectSamples = (int)entry.mData.mSumPdf; 
    2682         float localRadius = MAX_FLOAT; 
    2683         if (objectSamples > MIN_LOCAL_SAMPLES) 
    2684           localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 
    2685                 sqrt((float)objectSamples); 
    2686          
    2687         //      cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 
    2688          
    2689         // now compute the filter size 
    2690         float radius = Min(localRadius, globalRadius); 
    2691          
    2692         // cout<<"box = "<<box<<endl; 
    2693         //      cout<<"distance = "<<distance<<endl; 
    2694         //      cout<<"radiues = "<<radius<<endl; 
    2695          
    2696         box.Enlarge(Vector3(radius)); 
    2697          
    2698         objects.clear(); 
    2699         // $$ warning collect objects takes only unmailed ones! 
    2700         CollectObjects(box, objects); 
    2701         //      cout<<"collected objects="<<objects.size()<<endl; 
    2702         ObjectContainer::const_iterator noi = objects.begin(); 
    2703         for (; noi != objects.end(); ++ noi) { 
    2704           Intersectable *o = *noi; 
    2705           // $$ JB warning: pdfs are not correct at this point!    
    2706           pvs.AddSampleDirty(o, Limits::Small); 
    2707         } 
    2708   } 
    2709  
    2710   //  cout<<"nPvs size = "<<pvs.GetSize()<<endl; 
    2711  
     2741  cout<<" nPvs size = "<<pvs.GetSize()<<endl; 
     2742 
     2743#if !USE_KD_PVS 
    27122744  // copy the base pvs to the new pvs 
    27132745  pit = basePvs.GetIterator(); 
     
    27162748        pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf); 
    27172749  } 
     2750#endif 
    27182751   
    27192752  Intersectable::NewMail(); 
     2753  return stats; 
    27202754} 
    27212755   
     
    50965130VspOspViewCellsManager::GetIntersectable(const VssRay &ray, const bool isTermination) const 
    50975131{ 
     5132#if USE_KD_PVS 
     5133  return ViewCellsManager::GetIntersectable(ray, isTermination); 
     5134#else 
    50985135  return mHierarchyManager->GetIntersectable(ray, isTermination); 
     5136#endif 
    50995137} 
    51005138 
     
    58535891        ViewCellContainer::const_iterator it = viewcells.begin(); 
    58545892 
     5893        Intersectable *terminationObj = GetIntersectable(ray, true); 
     5894        Intersectable *originObj = GetIntersectable(ray, false); 
     5895           
    58555896        for (; it != viewcells.end(); ++ it)  
    58565897        { 
     
    58615902                        float contribution; 
    58625903 
    5863                         if (ray.mTerminationObject)  
     5904                        if (terminationObj)  
    58645905                        { 
    58655906                                // todo: maybe not correct for kd node pvs 
    5866                                 Intersectable *obj = mHierarchyManager->GetIntersectable(ray, true); 
    5867  
    5868                                 if (viewcell->GetPvs().GetSampleContribution(obj, 
    5869                                         ray.mPdf,  
    5870                                         contribution)) 
     5907                           
     5908                          if (viewcell->GetPvs().GetSampleContribution(terminationObj, 
     5909                                                                                                                   ray.mPdf,  
     5910                                                                                                                   contribution)) 
    58715911                                { 
    5872                                         ++ ray.mPvsContribution; 
     5912                                  ++ ray.mPvsContribution; 
    58735913                                } 
    5874  
    5875                                 ray.mRelativePvsContribution += contribution; 
     5914                           
     5915                          ray.mRelativePvsContribution += contribution; 
    58765916                        } 
    5877  
     5917                         
    58785918                        //////////////// 
    58795919                        //-- for directional sampling it is important to count only contributions  
     
    58815921                        //-- the other contributions of this sample will be counted for the opposite ray! 
    58825922#if SAMPLE_ORIGIN_OBJECTS 
    5883                         if (ray.mOriginObject &&  
    5884                                 viewcell->GetPvs().GetSampleContribution(ray.mOriginObject, 
    5885                                 ray.mPdf, 
    5886                                 contribution)) 
    5887                         { 
     5923                        if (originObj &&  
     5924                                viewcell->GetPvs().GetSampleContribution(originObj, 
     5925                                                                                                                 ray.mPdf, 
     5926                                                                                                                 contribution)) 
     5927                          { 
    58885928                                ++ ray.mPvsContribution; 
    58895929                                ray.mRelativePvsContribution += contribution; 
    5890                         } 
     5930                          } 
    58915931#endif 
    58925932                } 
     
    59065946                        break; 
    59075947 
     5948                //$$JB hack 
     5949#if !USE_KD_PVS 
    59085950                AddSampleToPvs( 
    5909                         ray.mTerminationObject,  
    5910                         ray.mTermination,  
    5911                         viewCell,  
    5912                         ray.mPdf,  
    5913                         ray.mRelativePvsContribution); 
    5914  
     5951                                           terminationObj,  
     5952                                           ray.mTermination,  
     5953                                           viewCell,  
     5954                                           ray.mPdf,  
     5955                                           ray.mRelativePvsContribution); 
     5956#else 
     5957                viewCell->GetPvs().AddSample(terminationObj, ray.mPdf); 
     5958#endif 
     5959                 
    59155960#if SAMPLE_ORIGIN_OBJECTS 
    5916  
    59175961                AddSampleToPvs( 
    5918                         ray.mOriginObject,  
    5919                         ray.mOrigin,  
    5920                         viewCell,  
    5921                         ray.mPdf,  
    5922                         ray.mRelativePvsContribution); 
     5962                                           originObj,  
     5963                                           ray.mOrigin,  
     5964                                           viewCell,  
     5965                                           ray.mPdf,  
     5966                                           ray.mRelativePvsContribution); 
    59235967#endif                   
    59245968        } 
    5925  
     5969         
    59265970         
    59275971 
     
    59375981                                                                                        float &contribution) const 
    59385982{ 
    5939         // The hierarchy manager decides about the type of sample cast 
    5940         return mHierarchyManager->AddSampleToPvs(obj, hitPoint, vc, pdf, contribution); 
     5983  // The hierarchy manager decides about the type of sample cast 
     5984  return mHierarchyManager->AddSampleToPvs(obj, hitPoint, vc, pdf, contribution); 
    59415985} 
    59425986 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1760 r1761  
    4242struct BspRay; 
    4343 
    44  
     44  struct PvsFilterStatistics { 
     45        PvsFilterStatistics(): mAvgFilterRadius(0.0f), mLocalFilterCount(0), mGlobalFilterCount(0) {} 
     46        float mAvgFilterRadius; 
     47        int mLocalFilterCount; 
     48        int mGlobalFilterCount; 
     49         
     50  }; 
     51   
    4552/** Probably Visible Set  
    4653*/ 
     
    6976          float avgFilteredPvs; 
    7077          float avgFilterContribution; 
     78          float avgFilterRadius; 
     79          float avgFilterRatio; 
    7180          int viewcells; 
     81           
    7282        }; 
    7383 
     
    466476 
    467477        // TODO: write own visibiltiy filter class 
    468         void ApplyFilter(KdTree *kdTree, 
     478  void ApplyFilter(KdTree *kdTree, 
    469479                                         const float viewSpaceFilterSize, 
    470480                                         const float spatialFilterSize); 
    471481 
    472482  // new adaptive version of the filter 
    473   void 
     483  PvsFilterStatistics  
    474484  ApplyFilter2(ViewCell *viewCell, 
    475485                           const bool useViewSpaceFilter, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/default.env

    r1757 r1761  
    8181RssPreprocessor { 
    8282        samplesPerPass 1000 
    83         initialSamples 2000000 
     83        initialSamples 3000000 
    8484        vssSamples 50000000 
    8585#       vssSamples 1000000 
     
    205205        maxPvsRatio 1.0 
    206206                 
    207         processOnlyValidViewCells false 
     207        processOnlyValidViewCells true 
    208208 
    209209        #stats viewCellStats.log 
Note: See TracChangeset for help on using the changeset viewer.