Ignore:
Timestamp:
07/18/05 11:27:52 (19 years ago)
Author:
bittner
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r176 r177  
    33#include "SamplingPreprocessor.h" 
    44#include "X3dExporter.h" 
    5  
     5#include "Environment.h" 
    66SamplingPreprocessor::SamplingPreprocessor() 
    77{ 
    88  // this should increase coherence of the samples 
    9   mSamplesPerPass = 1; 
    10   mTotalSamples = 1e8; 
    11   mKdPvsDepth = 10; 
     9  environment->GetIntValue("Sampling.samplesPerPass", mSamplesPerPass); 
     10  environment->GetIntValue("Sampling.totalSamples", mTotalSamples); 
     11  mKdPvsDepth = 100; 
    1212 
    1313} 
     
    7575     
    7676    for (i =0; i < objects.size(); i++) { 
     77      KdNode *nodeToSample = NULL; 
     78      Intersectable *object = objects[i]; 
     79 
     80      int pvsSize = object->mKdPvs.GetSize(); 
     81       
     82      if (0 && pvsSize) { 
     83        // mail all nodes from the pvs 
     84        Intersectable::NewMail(); 
     85        KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 
     86        for (; i != object->mKdPvs.mEntries.end(); i++) { 
     87          KdNode *node = (*i).first; 
     88          node->Mail(); 
     89        } 
     90        int maxTries = 2*pvsSize; 
     91        for (int tries = 0; tries < 10; tries++) { 
     92          int index = RandomValue(0, pvsSize - 1); 
     93          KdPvsData data; 
     94          KdNode *visibleNode; 
     95          object->mKdPvs.GetData(index, visibleNode, data); 
     96          nodeToSample = mKdTree->FindRandomNeighbor(visibleNode, true); 
     97          if (nodeToSample) 
     98            break; 
     99        } 
     100      } 
     101 
     102      if (pvsSize) { 
     103        // mail all nodes from the pvs 
     104        Intersectable::NewMail(); 
     105        KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 
     106        for (; i != object->mKdPvs.mEntries.end(); i++) { 
     107          KdNode *node = (*i).first; 
     108          node->Mail(); 
     109        } 
     110        vector<KdNode *> invisibleNeighbors; 
     111        // get all neighbors of all PVS nodes 
     112        KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 
     113        for (; i != object->mKdPvs.mEntries.end(); i++) { 
     114          KdNode *node = (*i).first; 
     115          mKdTree->FindNeighbors(visibleNode, invisibleNeighbors, true); 
     116        } 
     117 
     118        KdPvsData data; 
     119        KdNode *visibleNode; 
     120        object->mKdPvs.GetData(index, visibleNode, data); 
     121        nodeToSample = mKdTree->FindRandomNeighbor(visibleNode, true); 
     122        if (nodeToSample) 
     123          break; 
     124      } 
     125       
     126 
    77127      for (int k=0; k < mSamplesPerPass; k++) { 
    78         Intersectable *object = objects[i]; 
    79128        object->GetRandomSurfacePoint(point, normal); 
    80         direction = UniformRandomVector(normal); 
     129        if (nodeToSample) { 
     130          int maxTries = 5; 
     131          for (int tries = 0; tries < maxTries; tries++) { 
     132            direction = mKdTree->GetBox(nodeToSample).GetRandomPoint() - point; 
     133            if (DotProd(direction, normal) > Limits::Small) 
     134              break; 
     135          } 
     136          if (tries == maxTries) 
     137            direction = UniformRandomVector(normal); 
     138        } else 
     139          direction = UniformRandomVector(normal); 
     140         
    81141        // construct a ray 
    82142        SetupRay(ray, point, direction); 
     
    114174    for (i=0; i < objects.size(); i++) { 
    115175      Intersectable *object = objects[i]; 
    116       pvsSize += object->mKdPvs.mEntries.size(); 
     176      pvsSize += object->mKdPvs.GetSize(); 
    117177    } 
    118178     
     
    120180    cout<<"#totalSamples="<<totalSamples/1000<< 
    121181      "k   #sampleContributions="<<passSampleContributions<< 
    122       " ("<<100*passContributingSamples/passSamples<<"%)"<< 
    123       " avgPVS="<<pvsSize/(float)objects.size()<<endl; 
     182      " ("<<100*passContributingSamples/(float)passSamples<<"%)"<< 
     183      " avgPVS="<<pvsSize/(float)objects.size()<<endl<< 
     184      "avg ray contrib="<<passSampleContributions/(float)passContributingSamples<< 
     185      endl; 
    124186  } 
    125187  bool exportRays = false; 
Note: See TracChangeset for help on using the changeset viewer.