Ignore:
Timestamp:
11/24/06 00:24:41 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r1785 r1786  
    25912591 
    25922592 
     2593void ViewCellsManager::MergeViewCellsEfficient(ObjectPvs &pvs, const ViewCellContainer &viewCells) const 
     2594{ 
     2595        LocalMergeTree mergeTree(viewCells); 
     2596        mergeTree.Merge(pvs); 
     2597} 
     2598 
     2599#if 1 
    25932600PvsFilterStatistics 
    25942601ViewCellsManager::ApplyFilter2(ViewCell *viewCell, 
     
    26022609  AxisAlignedBox3 vbox = GetViewCellBox(viewCell); 
    26032610  Vector3 center = vbox.Center(); 
    2604   // COpy the PVS 
     2611  // copy the PVS 
    26052612  ObjectPvs basePvs = viewCell->GetPvs(); 
    26062613  Intersectable::NewMail(); 
     
    27402747  return stats; 
    27412748} 
     2749#else 
     2750PvsFilterStatistics 
     2751ViewCellsManager::ApplyFilter2(ViewCell *viewCell, 
     2752                                                           const bool useViewSpaceFilter, 
     2753                                                           const float filterSize, 
     2754                                                           ObjectPvs &pvs 
     2755                                                           ) 
     2756{cout << "x"; 
     2757  PvsFilterStatistics stats; 
     2758 
     2759  AxisAlignedBox3 vbox = GetViewCellBox(viewCell); 
     2760  Vector3 center = vbox.Center(); 
     2761  // copy the PVS 
     2762  ObjectPvs basePvs = viewCell->GetPvs(); 
     2763  Intersectable::NewMail(); 
     2764 
     2765  ObjectPvsIterator pit = basePvs.GetIterator(); 
     2766 
     2767#if !USE_KD_PVS 
     2768  // first mark all object from this pvs 
     2769  while (pit.HasMoreEntries()) {                 
     2770        ObjectPvsEntry entry = pit.Next(); 
     2771         
     2772        Intersectable *object = entry.mObject; 
     2773        object->Mail(); 
     2774  } 
     2775#endif 
     2776 
     2777  int pvsSize = 0; 
     2778  int nPvsSize = 0; 
     2779  float samples = (float)basePvs.GetSamples(); 
    27422780   
     2781  Debug<<"f #s="<<samples<<"pvs size = "<<basePvs.GetSize(); 
     2782  //  cout<<"Filter size = "<<filterSize<<endl; 
     2783  //  cout<<"vbox = "<<vbox<<endl; 
     2784  //  cout<<"center = "<<center<<endl; 
     2785 
     2786 
     2787   // Minimal number of local samples to take into account 
     2788   // the local sampling density. 
     2789   // The size of the filter is a minimum of the conservative 
     2790   // local sampling density estimate (#rays intersecting teh viewcell and 
     2791   // the object) 
     2792   // and gobal estimate for the view cell 
     2793   // (total #rays intersecting the viewcell) 
     2794#define MIN_LOCAL_SAMPLES 5 
     2795 
     2796  float viewCellRadius = 0.5f*Magnitude(vbox.Diagonal()); 
    27432797   
     2798  // now compute the filter box around the current viewCell 
     2799   
     2800  if (useViewSpaceFilter) { 
     2801        //      float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 
     2802        float radius = viewCellRadius/100.0f; 
     2803        vbox.Enlarge(radius); 
     2804        cout<<"vbox = "<<vbox<<endl; 
     2805        ViewCellContainer viewCells; 
     2806        ComputeBoxIntersections(vbox, viewCells); 
     2807        ObjectPvs pvs; 
     2808        MergeViewCellsEfficient(pvs, viewCells); 
     2809        basePvs = pvs; 
     2810                 
     2811        // update samples and globalC 
     2812        samples = (float)pvs.GetSamples(); 
     2813        //      cout<<"neighboring viewcells = "<<i-1<<endl; 
     2814        //      cout<<"Samples' = "<<samples<<endl; 
     2815  } 
     2816 
     2817  // Minimal number of samples so that filtering takes place 
     2818#define MIN_SAMPLES  100 
     2819  if (samples > MIN_SAMPLES) { 
     2820        float globalC = 2.0f*filterSize/sqrt(samples); 
     2821         
     2822        pit = basePvs.GetIterator(); 
     2823         
     2824        ObjectContainer objects; 
     2825         
     2826        while (pit.HasMoreEntries()) 
     2827          {              
     2828                ObjectPvsEntry entry = pit.Next(); 
     2829                 
     2830                Intersectable *object = entry.mObject; 
     2831                // compute filter size based on the distance and the numebr of samples 
     2832                AxisAlignedBox3 box = object->GetBox(); 
     2833                 
     2834                float distance = Distance(center, box.Center()); 
     2835                float globalRadius = distance*globalC; 
     2836                 
     2837                int objectSamples = (int)entry.mData.mSumPdf; 
     2838                float localRadius = MAX_FLOAT; 
     2839                if (objectSamples > MIN_LOCAL_SAMPLES) 
     2840                  localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 
     2841                        sqrt((float)objectSamples); 
     2842                 
     2843                //      cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 
     2844                 
     2845                // now compute the filter size 
     2846                float radius; 
     2847 
     2848                if (localRadius < globalRadius) { 
     2849                  radius = localRadius; 
     2850                  stats.mLocalFilterCount++; 
     2851                } else { 
     2852                  radius = globalRadius; 
     2853                  stats.mGlobalFilterCount++; 
     2854                } 
     2855 
     2856                stats.mAvgFilterRadius += radius; 
     2857                 
     2858                // cout<<"box = "<<box<<endl; 
     2859                //      cout<<"distance = "<<distance<<endl; 
     2860                //      cout<<"radiues = "<<radius<<endl; 
     2861                 
     2862                box.Enlarge(Vector3(radius)); 
     2863                 
     2864                objects.clear(); 
     2865                // $$ warning collect objects takes only unmailed ones! 
     2866                CollectObjects(box, objects); 
     2867                //      cout<<"collected objects="<<objects.size()<<endl; 
     2868                ObjectContainer::const_iterator noi = objects.begin(); 
     2869                for (; noi != objects.end(); ++ noi) { 
     2870                  Intersectable *o = *noi; 
     2871                  // $$ JB warning: pdfs are not correct at this point!    
     2872                  pvs.AddSampleDirty(o, Limits::Small); 
     2873                } 
     2874          } 
     2875        stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 
     2876  } 
     2877   
     2878  Debug<<" nPvs size = "<<pvs.GetSize()<<endl; 
     2879 
     2880#if !USE_KD_PVS 
     2881  // copy the base pvs to the new pvs 
     2882  pit = basePvs.GetIterator(); 
     2883  while (pit.HasMoreEntries()) {                 
     2884        ObjectPvsEntry entry = pit.Next(); 
     2885        pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf); 
     2886  } 
     2887#endif 
     2888  viewCell->SetFilteredPvsSize(pvs.GetSize()); 
     2889   
     2890  Intersectable::NewMail(); 
     2891  return stats; 
     2892} 
     2893#endif 
    27442894 
    27452895   
     
    60316181                //dummyStrat.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION); 
    60326182 
    6033                 CastPassSamples(samplesPerPass, mStrategies, evaluationSamples); 
     6183                CastPassSamples(samplesPerPass, dummyStrat, evaluationSamples); 
     6184                //CastPassSamples(samplesPerPass, mStrategies, evaluationSamples); 
    60346185                 
    60356186                castSamples += samplesPerPass; 
     
    61186269} 
    61196270#endif 
    6120 } 
     6271 
     6272 
     6273LocalMergeTree::LocalMergeTree(const ViewCellContainer &viewCells): 
     6274mViewCells(viewCells) 
     6275{ 
     6276        mRoot = Subdivide(0, (int)mViewCells.size()); 
     6277} 
     6278 
     6279 
     6280void LocalMergeTree::Merge(ObjectPvs &mergedPvs) 
     6281{ 
     6282        Merge(mRoot, mergedPvs); 
     6283} 
     6284 
     6285 
     6286void LocalMergeTree::Merge(LocalMergeNode *node, ObjectPvs &mergedPvs) 
     6287{ 
     6288        //////////////// 
     6289        //-- pvs is not stored with the interiors => reconstruct 
     6290        if (node->IsLeaf()) 
     6291        { 
     6292                LocalMergeLeaf *leaf = dynamic_cast<LocalMergeLeaf *>(node); 
     6293        mergedPvs = leaf->mViewCell->GetPvs(); 
     6294        } 
     6295        else 
     6296        { 
     6297                LocalMergeInterior *interior = dynamic_cast<LocalMergeInterior *>(node); 
     6298 
     6299                ObjectPvs leftPvs, rightPvs; 
     6300 
     6301                Merge(interior->mLeft, leftPvs); 
     6302                Merge(interior->mRight, rightPvs); 
     6303 
     6304                ObjectPvs::Merge(mergedPvs, leftPvs, rightPvs); 
     6305        }        
     6306} 
     6307 
     6308 
     6309LocalMergeNode *LocalMergeTree::Subdivide(const int leftIdx, const int rightIdx) 
     6310{ 
     6311        if (leftIdx == rightIdx) 
     6312        { 
     6313                return new LocalMergeLeaf(mViewCells[leftIdx]); 
     6314        } 
     6315 
     6316        LocalMergeInterior *interior = new LocalMergeInterior(); 
     6317 
     6318        const int midSplit = (leftIdx + rightIdx) / 2; 
     6319 
     6320        interior->mLeft = Subdivide(leftIdx, midSplit); 
     6321        interior->mRight = Subdivide(midSplit,  rightIdx); 
     6322 
     6323        return interior; 
     6324} 
     6325 
     6326 
     6327 
     6328} 
Note: See TracChangeset for help on using the changeset viewer.