Changeset 177


Ignore:
Timestamp:
07/18/05 11:27:52 (19 years ago)
Author:
bittner
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
6 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/preprocessor.pro

    r65 r177  
    44TARGET = preprocessor 
    55 
    6 INCLUDEPATH += ../include 
     6INCLUDEPATH += ../src  
    77 
    88# debuc config 
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp

    r162 r177  
    15081508 
    15091509 
     1510int 
     1511AxisAlignedBox3::Side(const Plane3 &plane) const 
     1512{ 
     1513  Vector3 v; 
     1514  int i, m=3, M=-3, s; 
     1515   
     1516  for (i=0;i<8;i++) { 
     1517    GetVertex(i, v); 
     1518    if((s = plane.Side(v)) < m) 
     1519      m=s; 
     1520    if(s > M) 
     1521      M=s; 
     1522    if (m && m==-M) 
     1523      return 0; 
     1524  } 
     1525   
     1526  return (m == M) ? m : m + M; 
     1527} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h

    r170 r177  
    104104 
    105105   
     106  int 
     107  Side(const Plane3 &plane) const; 
    106108 
    107109  // Overlap returns 1 if the two axis-aligned boxes overlap .. even weakly 
     
    123125 
    124126  virtual int IsInside(const Vector3 &v) const; 
    125  
     127   
    126128  // Test if the box is really sensefull 
    127129  virtual bool IsCorrect(); 
     
    167169  //    1 ... the cube contains fully the box 
    168170  int MutualPositionWithCube(const Vector3 &center, float halfSize) const; 
     171 
     172 
     173  Vector3 GetRandomPoint() { 
     174    Vector3 size = Size(); 
     175    return mMin + Vector3(RandomValue(0, size.x), 
     176                          RandomValue(0, size.y), 
     177                          RandomValue(0, size.z));  
     178  } 
    169179   
    170180  // Returns the smallest axis-aligned box that includes all points 
     
    181191                                          const Matrix4x4 &tform); 
    182192 
     193   
    183194  // returns true when two boxes are completely equal 
    184195  friend inline int operator== (const AxisAlignedBox3 &A, const AxisAlignedBox3 &B); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r170 r177  
    11411141                 "0.1"); 
    11421142 
     1143  RegisterOption("Sampling.totalSamples", 
     1144                 optInt, 
     1145                 "-total_samples=", 
     1146                 "1000000"); 
     1147 
     1148  RegisterOption("Sampling.samplesPerPass", 
     1149                 optInt, 
     1150                 "-total_samples=", 
     1151                 "10"); 
     1152 
    11431153   
    11441154} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp

    r176 r177  
    77 
    88 
    9  
    10  
    11 KdNode::KdNode(KdInterior *parent):mParent(parent) 
     9int KdNode::mailID = 1; 
     10 
     11 
     12KdNode::KdNode(KdInterior *parent):mParent(parent), mailbox(0) 
    1213{ 
    1314  if (parent) 
     
    633634  } 
    634635} 
     636 
     637// Find random neighbor which was not mailed 
     638KdNode * 
     639KdTree::FindRandomNeighbor(KdNode *n, 
     640                           bool onlyUnmailed 
     641                           ) 
     642{ 
     643  stack<KdNode *> nodeStack; 
     644   
     645  nodeStack.push(mRoot); 
     646 
     647  AxisAlignedBox3 box = GetBox(n); 
     648  int mask = rand(); 
     649 
     650  while (!nodeStack.empty()) { 
     651    KdNode *node = nodeStack.top(); 
     652    nodeStack.pop(); 
     653    if (node->IsLeaf()) { 
     654      if ( node != n && (!onlyUnmailed || !node->Mailed()) ) 
     655        return node; 
     656    } else { 
     657      KdInterior *interior = (KdInterior *)node; 
     658      if (interior->mPosition > box.Max(interior->mAxis)) 
     659        nodeStack.push(interior->mBack); 
     660      else 
     661        if (interior->mPosition < box.Min(interior->mAxis)) 
     662          nodeStack.push(interior->mFront); 
     663        else { 
     664          // random decision 
     665          if (mask&1) 
     666            nodeStack.push(interior->mBack); 
     667          else 
     668            nodeStack.push(interior->mFront); 
     669          mask = mask>>1; 
     670        } 
     671    } 
     672  } 
     673   
     674  return NULL; 
     675} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.h

    r176 r177  
    8686class KdNode { 
    8787public: 
     88  static int mailID; 
     89  int mailbox; 
     90   
     91  void Mail() { mailbox = mailID; } 
     92  static void NewMail() { mailID++; } 
     93  bool Mailed() const { return mailbox == mailID; } 
     94 
     95 
    8896  KdNode(KdInterior *parent); 
    8997 
     
    277285  } 
    278286 
     287  KdNode * 
     288  FindRandomNeighbor(KdNode *n, 
     289                     bool onlyUnmailed 
     290                     ); 
     291 
     292  int 
     293  FindNeighbors(KdNode *n, 
     294                vector<KdNode *> &neighbors, 
     295                bool onlyUnmailed 
     296                ); 
     297   
    279298protected: 
    280299 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h

    r162 r177  
    2323  } 
    2424 
     25  float Distance(const Vector3 &v) const { 
     26    return DotProd(v, mNormal) + mD; 
     27  } 
     28 
     29  int Side(const Vector3 &v, const float threshold = 1e-6) const { 
     30    return signum(Distance(v), threshold); 
     31  } 
     32   
    2533  friend ostream &operator<<(ostream &s, const Plane3 p) { 
    2634    s<<p.mNormal<<" "<<p.mD; 
  • 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; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/default.env

    r176 r177  
    88#       filename glasgow1.x3d 
    99#       filename vienna.x3d 
    10 #       filename atlanta2.x3d 
    11         filename soda.dat 
     10        filename atlanta2.x3d 
     11#       filename soda.dat 
    1212 
    1313} 
     
    5252 
    5353 
    54 SamplingPreprocessor { 
    55  
    56  
     54Sampling { 
     55        totalSamples    500000 
     56        samplesPerPass  2 
    5757} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro

    r176 r177  
    88INCLUDEPATH += ../src ../support/xerces/include  ../support/zlib/include ../support/boost 
    99 
    10 win32:LIBPATH += ../support/expat/lib ../support/xerces/lib 
     10win32:LIBPATH += ../support/xerces/lib 
    1111 
    1212#win32:LIBPATH += c:/STLport-4.6.2/lib 
Note: See TracChangeset for help on using the changeset viewer.