Ignore:
Timestamp:
08/22/07 17:35:10 (17 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r2546 r2548  
    33#include "DifferenceSampling.h" 
    44#include "ViewCell.h" 
     5#include "ViewCellsManager.h" 
     6#include "Preprocessor.h" 
    57 
    68 
     
    1012 
    1113 
    12  
    1314namespace GtpVisibilityPreprocessor { 
    1415 
    1516 
     17/** Collects the pvs of the objects which are  
     18        in the first but not in the second pvs. 
     19*/ 
     20static void GetPvsDifference(const ObjectPvs &largerPvs,  
     21                                                         const ObjectPvs &smallerPvs,  
     22                                                         ObjectContainer &pvsDifference) 
     23{ 
     24        Intersectable::NewMail(); 
     25        Intersectable *obj; 
     26 
     27        ObjectPvsIterator bit = smallerPvs.GetIterator(); 
     28 
     29        // mail smaller pvs 
     30        while (bit.HasMoreEntries()) 
     31        { 
     32                obj = bit.Next(); 
     33                obj->Mail(); 
     34        } 
     35 
     36        ObjectPvsIterator ait = largerPvs.GetIterator(); 
     37 
     38        // write differece pvs 
     39        while (ait.HasMoreEntries()) 
     40        { 
     41                obj = ait.Next(); 
     42                pvsDifference.push_back(obj); 
     43 
     44                //if (!obj->Mailed()) 
     45                //      c.AddSampleDirty(obj, 0); 
     46        } 
     47} 
     48 
     49 
    1650DifferenceSampling::DifferenceSampling(Preprocessor &preprocessor): 
    17 SamplingStrategy(preprocessor) 
     51SamplingStrategy(preprocessor), mCurrentViewCell(0), mNumSamples(0) 
    1852{} 
    1953 
    2054 
    21 void DifferenceSampling::ComputeDifferenceSet(ViewCell *vc, ObjectContainer &differenceSet) 
     55void DifferenceSampling::ComputeDifferenceSet(ViewCell *vc,  
     56                                                                                          ObjectContainer &differenceSet) 
    2257{ 
     58        const ObjectPvs &pvs = vc->GetPvs(); 
     59        const float filterSize = 100; 
     60        ObjectPvs filteredPvs; 
     61 
     62    PvsFilterStatistics pvsStats = mPreprocessor. 
     63                mViewCellsManager->ApplyFilter2(vc,  
     64                                                false,  
     65                                                                                filterSize,  
     66                                                                                filteredPvs); 
     67 
     68        //mDifferencePvs.Clear(false); 
     69        //mDifferencePvs.Reserve(filteredPvs.GetSize()); 
     70        mPvsDifference.clear(); 
     71        mPvsDifference.reserve(filteredPvs.GetSize()); 
     72 
     73        GetPvsDifference(filteredPvs, pvs, mPvsDifference); 
    2374} 
    2475 
     76 
     77bool DifferenceSampling::GenerateSample(SimpleRay &ray) 
     78{ 
     79        if (mNumSamples -- <= 0) 
     80        { 
     81                ViewCellContainer &viewCells = mPreprocessor.mViewCellsManager->GetViewCells(); 
     82                const int vcIdx = (int)RandomValue(0, (float)viewCells.size() - 0.5f); 
     83 
     84                mCurrentViewCell = viewCells[vcIdx]; 
     85 
     86                ComputeDifferenceSet(mCurrentViewCell, mPvsDifference); 
     87 
     88                // n samples per object 
     89                const int n = 50; 
     90                mNumSamples = mPvsDifference.size() * n; 
     91        } 
     92 
     93        Vector3 origin, direction;  
     94        Vector3 point; 
     95        Vector3 normal, vcnormal; 
     96 
     97        // get a new object from the difference set 
     98        const int objIdx = (int)RandomValue(0, (float)mPvsDifference.size() - 0.5f); 
     99    Intersectable *object = mPvsDifference[objIdx]; 
     100 
     101        // cast a ray from the view cells border towards the object 
     102        object->GetRandomSurfacePoint(point, normal); 
     103        mCurrentViewCell->GetRandomEdgePoint(origin, vcnormal); 
     104 
     105        direction = point - origin; 
     106 
     107        // $$ jb the pdf is yet not correct for all sampling methods! 
     108        const float c = Magnitude(direction); 
     109 
     110        if ((c <= Limits::Small) /*|| (DotProd(direction, normal) < 0)*/) 
     111        { 
     112                return false; 
     113        } 
     114 
     115        // $$ jb the pdf is yet not correct for all sampling methods! 
     116        const float pdf = 1.0f; 
     117        //cout << "p: " << point << " "; 
     118        direction *= 1.0f / c; 
     119        ray = SimpleRay(origin, direction, DIFFERENCE_SAMPLING_BASED_DISTRIBUTION, pdf); 
     120 
     121        //cout << "ray: " << ray.mOrigin << " " << ray.mDirection << endl; 
     122 
     123        return true; 
    25124} 
     125 
     126 
     127} 
Note: See TracChangeset for help on using the changeset viewer.