Changeset 2548


Ignore:
Timestamp:
08/22/07 17:35:10 (17 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
6 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} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/DifferenceSampling.h

    r2546 r2548  
    22#define _DifferenceSampling_H__ 
    33 
    4 #include <vector> 
    5 // 
     4#include "common.h" 
     5//#include "ObjectPvs.h" 
    66 
    7 #include "common.h" 
    8 #include "Halton.h" 
     7class SimpleRay; 
    98 
    109namespace GtpVisibilityPreprocessor { 
     
    3534private: 
    3635 
    37   virtual bool GenerateSample(SimpleRay &ray); 
    38    
     36        virtual bool GenerateSample(SimpleRay &ray); 
     37 
     38        //ObjectPvs mDifferencePvs; 
     39        ObjectContainer mPvsDifference; 
     40 
     41        ViewCell *mCurrentViewCell; 
     42        int mNumSamples; 
    3943}; 
    4044 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h

    r2530 r2548  
    591591 
    592592template <typename T, typename S> 
    593 typename vector< PvsEntry<T, S> >::iterator VerbosePvs<T, S>::AddSample2(T sample,  
    594                                                                                                                                   const float pdf) 
     593typename vector< PvsEntry<T, S> >::iterator  
     594VerbosePvs<T, S>::AddSample2(T sample, const float pdf) 
    595595{ 
    596596        ++ mSamples; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp

    r2353 r2548  
    88#include "Mutation.h" 
    99#include "Timer/PerfTimer.h" 
     10#include "DifferenceSampling.h" 
     11 
    1012 
    1113 
     
    711713                                         mDistributions.push_back(new MutationBasedDistribution(mPreprocessor)); 
    712714                                        } 
     715                                        else if (strcmp(curr, "difference")==0) { 
     716                                         mDistributions.push_back(new DifferenceSampling(mPreprocessor)); 
     717                                        } 
    713718         
    714719         
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h

    r2176 r2548  
    4747                MUTATION_BASED_DISTRIBUTION, 
    4848                HW_GLOBAL_LINES_DISTRIBUTION, 
    49                 VIEWCELL_BASED_DISTRIBUTION 
     49                VIEWCELL_BASED_DISTRIBUTION, 
     50                DIFFERENCE_SAMPLING_BASED_DISTRIBUTION, 
    5051        }; 
    5152 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r2547 r2548  
    34563456        float samples = (float)basePvs.GetSamples(); 
    34573457 
     3458 
    34583459        ////////// 
    34593460        //-- now compute the filter box around the current viewCell 
     
    35993600        viewCell->SetFilteredPvsSize(pvs.GetSize()); 
    36003601 
    3601         //cout << "pvssize: " << pvs.GetSize() << endl; 
    36023602        // warning: not thread-safe! 
    36033603        if (!mUseKdPvs) 
Note: See TracChangeset for help on using the changeset viewer.