Ignore:
Timestamp:
11/03/05 19:31:56 (19 years ago)
Author:
bittner
Message:

vsspreprocessor kdtree meshkdtree optimization

Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h

    r372 r376  
    8484    if ( (value >=mMin[axis]) && (value <= mMax[axis]) ) 
    8585      if (right) 
    86        mMin[axis] = value; 
     86                                mMin[axis] = value; 
    8787      else 
    8888        mMax[axis] = value; 
    8989  } 
    90  
     90         
    9191  // the size of the box along all the axes 
    9292  Vector3 Size() const { return mMax - mMin; } 
     
    174174    Vector3 size = Size(); 
    175175    return mMin + Vector3(RandomValue(0, size.x), 
    176                           RandomValue(0, size.y), 
    177                           RandomValue(0, size.z));  
     176                                                                                                        RandomValue(0, size.y), 
     177                                                                                                        RandomValue(0, size.z));  
    178178  } 
    179179   
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r374 r376  
    11501150                 "10"); 
    11511151 
     1152        RegisterOption("VssPreprocessor.totalSamples", 
     1153                                                                 optInt, 
     1154                                                                 "-total_samples=", 
     1155                                                                 "1000000"); 
     1156         
     1157  RegisterOption("VssPreprocessor.samplesPerPass", 
     1158                                                                 optInt, 
     1159                                                                 "-samples_per_pass=", 
     1160                                                                 "100000"); 
     1161 
    11521162  RegisterOption("ViewCells.hierarchy", 
    11531163                 optString, 
  • trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp

    r374 r376  
    542542 
    543543      if (entp[axis] <= position) { 
    544         if (extp[axis] <= position) { 
    545           node = in->mBack; 
    546           // cases N1,N2,N3,P5,Z2,Z3 
    547           continue; 
    548         } else { 
    549           // case N4 
    550           node = in->mBack; 
    551           farChild = in->mFront; 
    552         } 
     544                                if (extp[axis] <= position) { 
     545                                        node = in->mBack; 
     546                                        // cases N1,N2,N3,P5,Z2,Z3 
     547                                        continue; 
     548                                } else { 
     549                                        // case N4 
     550                                        node = in->mBack; 
     551                                        farChild = in->mFront; 
     552                                } 
    553553      } 
    554554      else { 
    555         if (position <= extp[axis]) { 
    556           node = in->mFront; 
    557           // cases P1,P2,P3,N5,Z1 
    558           continue; 
    559         } else { 
    560           node = in->mFront; 
    561           farChild = in->mBack; 
    562           // case P4 
    563         } 
    564           } 
     555                                if (position <= extp[axis]) { 
     556                                        node = in->mFront; 
     557                                        // cases P1,P2,P3,N5,Z1 
     558                                        continue; 
     559                                } else { 
     560                                        node = in->mFront; 
     561                                        farChild = in->mBack; 
     562                                        // case P4 
     563                                } 
     564                        } 
    565565      // $$ modification 3.5.2004 - hints from Kamil Ghais 
    566566      // case N4 or P4 
     
    569569      extp = ray.GetLoc() + ray.GetDir()*tdist; 
    570570      maxt = tdist; 
    571         } else { 
    572                 // compute intersection with all objects in this leaf 
    573                 KdLeaf *leaf = (KdLeaf *) node; 
    574                 if (ray.mFlags & Ray::STORE_KDLEAVES) 
    575                         ray.kdLeaves.push_back(leaf); 
    576                  
    577                 ObjectContainer::const_iterator mi; 
    578                 for ( mi = leaf->mObjects.begin(); 
    579                                         mi != leaf->mObjects.end(); 
    580                                         mi++) { 
    581                         Intersectable *object = *mi; 
    582                         if (!object->Mailed() ) { 
    583                                 object->Mail(); 
    584                                 if (ray.mFlags & Ray::STORE_TESTED_OBJECTS) 
    585                                         ray.testedObjects.push_back(object); 
    586                                 hits += object->CastRay(ray); 
     571                } else { 
     572                        // compute intersection with all objects in this leaf 
     573                        KdLeaf *leaf = (KdLeaf *) node; 
     574                        if (ray.mFlags & Ray::STORE_KDLEAVES) 
     575                                ray.kdLeaves.push_back(leaf); 
     576                         
     577                        ObjectContainer::const_iterator mi; 
     578                        for ( mi = leaf->mObjects.begin(); 
     579                                                mi != leaf->mObjects.end(); 
     580                                                mi++) { 
     581                                Intersectable *object = *mi; 
     582                                if (!object->Mailed() ) { 
     583                                        object->Mail(); 
     584                                        if (ray.mFlags & Ray::STORE_TESTED_OBJECTS) 
     585                                                ray.testedObjects.push_back(object); 
     586                                        hits += object->CastRay(ray); 
     587                                } 
    587588                        } 
     589                         
     590                        if (hits && ray.GetType() == Ray::LOCAL_RAY) 
     591                                if (ray.intersections[0].mT <= maxt) 
     592                                        break; 
     593                         
     594                        // get the next node from the stack 
     595                        if (tStack.empty()) 
     596                                break; 
     597                         
     598                        entp = extp; 
     599                        mint = maxt; 
     600                        if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 
     601                                break; 
     602                         
     603                        RayTraversalData &s  = tStack.top(); 
     604                        node = s.mNode; 
     605                        extp = s.mExitPoint; 
     606                        maxt = s.mMaxT; 
     607                        tStack.pop(); 
    588608                } 
    589                  
    590                 if (hits && ray.GetType() == Ray::LOCAL_RAY) 
    591                         if (ray.intersections[0].mT <= maxt) 
    592                                 break; 
    593                  
    594                 // get the next node from the stack 
    595                 if (tStack.empty()) 
    596                         break; 
    597                  
    598                 entp = extp; 
    599                 mint = maxt; 
    600                 if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 
    601                         break; 
    602                  
    603                 RayTraversalData &s  = tStack.top(); 
    604                 node = s.mNode; 
    605                 extp = s.mExitPoint; 
    606                 maxt = s.mMaxT; 
    607                 tStack.pop(); 
    608         } 
    609   } 
    610    
    611    
     609  } 
    612610  return hits; 
    613611} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp

    r359 r376  
    100100    nearestT = ray.intersections[0].mT; 
    101101 
     102         
    102103  for ( ; 
    103104                                faceIndex < mFaces.size(); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/MeshKdTree.cpp

    r308 r376  
    291291int 
    292292MeshKdTree::CastRay( 
    293                     Ray &ray, 
    294                     MeshInstance *instance 
    295                     ) 
     293                                                                                Ray &ray, 
     294                                                                                MeshInstance *instance 
     295                                                                                ) 
    296296{ 
    297297  int hits = 0; 
     
    308308  if (mint < 0) 
    309309    mint = 0; 
    310    
     310 
     311 
     312        if (ray.GetType() == Ray::LOCAL_RAY && 
     313                        ray.intersections.size() && ray.intersections[0].mT < mint) { 
     314                return 0; 
     315        } 
     316 
    311317  maxt += Limits::Threshold; 
    312318   
     
    324330      position = in->mPosition; 
    325331      axis = in->mAxis; 
    326  
     332                         
    327333      if (entp[axis] <= position) { 
    328         if (extp[axis] <= position) { 
    329           node = in->mBack; 
    330           // cases N1,N2,N3,P5,Z2,Z3 
    331           continue; 
    332         } else { 
    333           // case N4 
    334           node = in->mBack; 
    335           farChild = in->mFront; 
    336         } 
     334                                if (extp[axis] <= position) { 
     335                                        node = in->mBack; 
     336                                        // cases N1,N2,N3,P5,Z2,Z3 
     337                                        continue; 
     338                                } else { 
     339                                        // case N4 
     340                                        node = in->mBack; 
     341                                        farChild = in->mFront; 
     342                                } 
    337343      } 
    338344      else { 
    339         if (position <= extp[axis]) { 
    340           node = in->mFront; 
    341           // cases P1,P2,P3,N5,Z1 
    342           continue; 
    343         } else { 
    344           node = in->mFront; 
    345           farChild = in->mBack; 
    346           // case P4 
    347         } 
     345                                if (position <= extp[axis]) { 
     346                                        node = in->mFront; 
     347                                        // cases P1,P2,P3,N5,Z1 
     348                                        continue; 
     349                                } else { 
     350                                        node = in->mFront; 
     351                                        farChild = in->mBack; 
     352                                        // case P4 
     353                                } 
    348354      } 
    349355      // $$ modification 3.5.2004 - hints from Kamil Ghais 
     
    359365      hits += instance->CastRay(ray, leaf->mFaces); 
    360366       
    361       if (hits && ray.GetType() == Ray::LOCAL_RAY) 
    362         if (ray.intersections[0].mT <= maxt) 
    363           break; 
     367      if (ray.GetType() == Ray::LOCAL_RAY && ray.intersections.size()) 
     368                                if (ray.intersections[0].mT <= maxt) { 
     369                                        break; 
     370                                } 
    364371       
    365372      // get the next node from the stack 
    366373      if (tStack.empty()) 
    367         break; 
     374                                break; 
    368375       
    369376      entp = extp; 
     
    371378 
    372379      if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 
    373         break; 
    374  
     380                                break; 
     381                         
    375382      RayTraversalData &s  = tStack.top(); 
    376383      node = s.mNode; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp

    r374 r376  
    77#include "Polygon3.h" 
    88#include "ViewCell.h" 
     9#include "VssRay.h" 
    910 
    1011VssPreprocessor::VssPreprocessor(): 
    1112        mPass(0), 
    12         mSampleRays(NULL) 
     13        mVssRays() 
    1314{ 
    1415  // this should increase coherence of the samples 
    15   environment->GetIntValue("Sampling.samplesPerPass", mSamplesPerPass); 
    16   environment->GetIntValue("Sampling.totalSamples", mTotalSamples); 
    17   mKdPvsDepth = 100; 
     16  environment->GetIntValue("VssPreprocessor.samplesPerPass", mSamplesPerPass); 
     17  environment->GetIntValue("VssPreprocessor.totalSamples", mTotalSamples); 
    1818  mStats.open("stats.log"); 
    19  
    2019} 
    2120 
    2221VssPreprocessor::~VssPreprocessor() 
    2322{ 
    24         CLEAR_CONTAINER(mSampleRays); 
     23        CLEAR_CONTAINER(mVssRays); 
    2524} 
    2625 
     
    3332  ray.intersections.clear(); 
    3433        // do not store anything else then intersections at the ray 
    35         ray.kdLeaves.clear(); 
    36         ray.mFlags = Ray::STORE_KDLEAVES; 
    37          
    38   //  cout<<point<<" "<<direction<<endl; 
    3934  ray.Init(point, direction, Ray::LOCAL_RAY); 
    4035} 
    4136 
    42 KdNode * 
    43 VssPreprocessor::GetNodeForPvs(KdLeaf *leaf) 
     37VssRay *  
     38VssPreprocessor::CastRay( 
     39                                                                                                 Vector3 &viewPoint, 
     40                                                                                                 Vector3 &direction 
     41                                                                                                 ) 
    4442{ 
    45   KdNode *node = leaf; 
    46   while (node->mParent && node->mDepth > mKdPvsDepth) 
    47     node = node->mParent; 
    48   return node; 
     43        static Ray ray; 
     44        AxisAlignedBox3 box = mKdTree->GetBox(); 
     45         
     46        SetupRay(ray, viewPoint, direction); 
     47        // cast ray to KD tree to find intersection with other objects 
     48        Intersectable *objectA, *objectB; 
     49        Vector3 pointA, pointB; 
     50 
     51        if (mKdTree->CastRay(ray)) { 
     52                objectA = ray.intersections[0].mObject; 
     53                pointA = ray.Extrap(ray.intersections[0].mT); 
     54        } else { 
     55                objectA = NULL; 
     56                // compute intersection with the scene bounding box 
     57                float tmin, tmax; 
     58                box.ComputeMinMaxT(ray, &tmin, &tmax); 
     59                pointA = ray.Extrap(tmax); 
     60        } 
     61         
     62        SetupRay(ray, viewPoint, -direction); 
     63         
     64        if (mKdTree->CastRay(ray)) { 
     65                objectB = ray.intersections[0].mObject; 
     66          pointB = ray.Extrap(ray.intersections[0].mT); 
     67        } else { 
     68                objectB = NULL; 
     69                float tmin, tmax; 
     70                box.ComputeMinMaxT(ray, &tmin, &tmax); 
     71                pointB = ray.Extrap(tmax); 
     72        } 
     73 
     74        VssRay *vssRay  = NULL; 
     75         
     76        if (objectA || objectB) { 
     77                vssRay = new VssRay(pointA, 
     78                                                                                                pointB, 
     79                                                                                                objectA, 
     80                                                                                                objectB); 
     81        } 
     82         
     83        return vssRay; 
    4984} 
    5085 
    5186 
    52 int 
    53 VssPreprocessor::AddNodeSamples(const Ray &ray, 
    54                                                                                                                                 Intersectable *sObject, 
    55                                                                                                                                 Intersectable *tObject 
    56                                                                                                                                 ) 
     87Vector3 
     88VssPreprocessor::GetViewpoint() 
    5789{ 
    58   int contributingSamples = 0; 
    59   int j; 
    60         int objects = 0; 
    61         if (sObject) 
    62                 objects++; 
    63         if (tObject) 
    64                 objects++; 
     90        AxisAlignedBox3 box = mKdTree->GetBox(); 
     91 
     92        // shrink the box in the y direction 
     93        Vector3 diff(0, -box.Size().y*0.4f, 0); 
     94        box.Enlarge(diff); 
    6595         
    66         if (objects) { 
    67                 for (j=0; j < ray.kdLeaves.size(); j++) { 
    68                         KdNode *node = GetNodeForPvs( ray.kdLeaves[j] ); 
    69                         if (sObject) 
    70                                 contributingSamples += sObject->mKdPvs.AddSample(node); 
    71                         if (tObject) 
    72                                 contributingSamples += tObject->mKdPvs.AddSample(node); 
    73                 } 
    74         } 
    75          
    76         for (j=1; j < ((int)ray.kdLeaves.size() - 1); j++) { 
    77                 ray.kdLeaves[j]->AddPassingRay2(ray, 
    78                                                                                                                                                 objects, 
    79                                                                                                                                                 ray.kdLeaves.size() 
    80                                                                                                                                                 ); 
    81   } 
    82    
    83   return contributingSamples; 
     96        return box.GetRandomPoint(); 
     97} 
     98 
     99Vector3 
     100VssPreprocessor::GetDirection(const Vector3 &viewpoint) 
     101{ 
     102        int i = RandomValue(0, mObjects.size()); 
     103        Intersectable *object = mObjects[i]; 
     104        Vector3 point, normal; 
     105        object->GetRandomSurfacePoint(point, normal); 
     106        return point - viewpoint; 
    84107} 
    85108 
    86109 
    87  
    88  
    89 int 
    90 VssPreprocessor::CastRay(Intersectable *object, 
    91                                                                                                  Ray &ray 
    92                                                                                                  ) 
    93 { 
    94         int sampleContributions = 0; 
    95  
    96         long t1 = GetRealTime(); 
    97         // cast ray to KD tree to find intersection with other objects 
    98         mKdTree->CastRay(ray); 
    99         long t2 = GetRealTime(); 
    100  
    101         if (0 && object && object->GetId() > 2197) { 
    102                 object->Describe(cout)<<endl; 
    103                 cout<<ray<<endl; 
    104         } 
    105  
    106         if (ray.kdLeaves.size()) { 
    107                 Intersectable *terminator = 
    108                         ray.intersections.size() ? ray.intersections[0].mObject: NULL; 
    109                  
    110                 sampleContributions += AddNodeSamples(ray, 
    111                                                                                                                                                                         object, 
    112                                                                                                                                                                         terminator); 
    113         } 
    114          
    115          
    116         return sampleContributions; 
    117 } 
    118  
    119  
    120 KdNode * 
    121 VssPreprocessor::GetNodeToSample(Intersectable *object) 
    122 { 
    123         int pvsSize = object->mKdPvs.GetSize(); 
    124         KdNode *nodeToSample = NULL; 
    125          
    126         // just pickup a random node 
    127         nodeToSample = mKdTree->GetRandomLeaf(); 
    128         return nodeToSample; 
    129 } 
    130110 
    131111bool 
     
    133113{ 
    134114   
    135   // pickup an object 
    136   ObjectContainer objects; 
    137    
    138   mSceneGraph->CollectObjects(&objects); 
    139  
    140   Vector3 point, normal, direction; 
    141   Ray ray; 
     115  mSceneGraph->CollectObjects(&mObjects); 
     116         
    142117 
    143118  long startTime = GetTime(); 
     
    146121  int totalSamples = 0; 
    147122 
    148   int pvsOut = Min((int)objects.size(), 10); 
    149  
    150   vector<Ray> rays[10]; 
    151123 
    152124  while (totalSamples < mTotalSamples) { 
     
    156128                int index = 0; 
    157129                 
    158                 int reverseSamples = 0; 
     130                int sampleContributions; 
    159131                 
     132                 
     133                for (int k=0; k < mSamplesPerPass; k++) { 
     134 
     135                        Vector3 viewpoint = GetViewpoint(); 
     136                        Vector3 direction = GetDirection(viewpoint); 
     137 
     138                        VssRay *vssRay = CastRay(viewpoint, direction); 
    160139                         
    161                 //cout << "totalSamples: "  << totalSamples << endl; 
    162  
    163                 for (i = 0; i < objects.size(); i++) { 
    164                                                  
    165                         KdNode *nodeToSample = NULL; 
    166                         Intersectable *object = objects[i]; 
    167                  
    168                         int pvsSize = 0; 
    169                         if (ViewCell::sHierarchy == ViewCell::KD) 
    170                                 pvsSize = object->mKdPvs.GetSize(); 
    171                                                  
     140                        if (vssRay) { 
     141                                sampleContributions = vssRay->HitCount(); 
     142                                mVssRays.push_back(vssRay); 
     143                        } 
    172144                         
    173                          
    174                         int faceIndex = object->GetRandomSurfacePoint(point, normal); 
    175                          
    176                         bool viewcellSample = true; 
    177                         int sampleContributions; 
    178                         bool debug = false; //(object->GetId() >= 2199); 
    179                         if (viewcellSample) { 
    180                                 //mKdTree->GetRandomLeaf(Plane3(normal, point)); 
    181  
    182                                 nodeToSample = GetNodeToSample(object); 
    183  
    184                                 for (int k=0; k < mSamplesPerPass; k++) { 
    185                                         bool reverseSample = false; 
    186                                          
    187  
    188                                         if (nodeToSample) { 
    189                                                 AxisAlignedBox3 box = mKdTree->GetBox(nodeToSample); 
    190                                                 Vector3 pointToSample = box.GetRandomPoint(); 
    191                                                 //                                              pointToSample.y = 0.9*box.Min().y + 0.1*box.Max().y; 
    192                                                 if (object->GetRandomVisibleSurfacePoint( point, normal, pointToSample, 3 )) { 
    193                                                         direction = pointToSample - point; 
    194                                                 } else { 
    195                                                         reverseSamples++; 
    196                                                         reverseSample = true; 
    197                                                         direction = point - pointToSample; 
    198                                                         point = pointToSample; 
    199                                                 } 
    200                                         } 
    201                                         else { 
    202                                                 direction = UniformRandomVector(normal); 
    203                                         } 
    204                                          
    205                                         // construct a ray 
    206                                         SetupRay(ray, point, direction); 
    207                                          
    208                                         sampleContributions = CastRay(reverseSample ? NULL : object, ray); 
    209                                          
    210                                         //-- CORR matt: put block inside loop 
    211                                         if (sampleContributions) { 
    212                                                 passContributingSamples ++; 
    213                                                 passSampleContributions += sampleContributions; 
    214                                         } 
    215  
    216                                         if ( i < pvsOut ) 
    217                                                 rays[i].push_back(ray); 
    218                  
    219                                         if (!ray.intersections.empty()) { 
    220                                                 // check whether we can add this to the rays 
    221                                                 for (int j = 0; j < pvsOut; j++) { 
    222                                                         if (objects[j] == ray.intersections[0].mObject) { 
    223                                                                 rays[j].push_back(ray); 
    224                                                         } 
    225                                                 } 
    226                                         } 
    227                                         //------------------- 
    228                                 } 
    229                         } else { 
    230                                 // edge samples 
    231                                 // get random visible mesh 
    232                                 //                              object->GetRandomVisibleMesh(Plane3(normal, point)); 
     145                        //-- CORR matt: put block inside loop 
     146                        if (sampleContributions) { 
     147                                passContributingSamples ++; 
     148                                passSampleContributions += sampleContributions; 
    233149                        } 
    234          
    235                         // CORR matt: must add all samples 
    236                         passSamples += mSamplesPerPass; 
     150                        passSamples++; 
     151                        totalSamples++; 
    237152                } 
    238          
    239                 totalSamples += passSamples;  
    240                  
    241                 //    if (pass>10) 
    242                 //      HoleSamplingPass(); 
    243153     
    244154                mPass++; 
    245155 
    246156                int pvsSize = 0; 
    247          
    248                 for (i=0; i < objects.size(); i++) { 
    249                         Intersectable *object = objects[i]; 
    250                         pvsSize += object->mKdPvs.GetSize(); 
    251                 } 
    252                  
    253                  
    254157                float avgRayContrib = (passContributingSamples > 0) ?  
    255158                        passSampleContributions/(float)passContributingSamples : 0; 
    256  
     159                 
    257160                cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    258161                cout << "#TotalSamples=" << totalSamples/1000  
    259162                                 << "k   #SampleContributions=" << passSampleContributions << " ("  
    260163                                 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 
    261                                  << pvsSize/(float)objects.size() << endl  
    262                                  << "avg ray contrib=" << avgRayContrib << endl 
    263                                  << "reverse samples [%]" << reverseSamples/(float)passSamples*100.0f << endl; 
    264  
     164                                 << pvsSize/(float)mObjects.size() << endl  
     165                                 << "avg ray contrib=" << avgRayContrib << endl; 
     166                 
    265167                mStats << 
    266168                        "#Pass\n" <<mPass<<endl<< 
     
    269171                        "#SampleContributions\n" << passSampleContributions << endl <<  
    270172                        "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 
    271                         "#AvgPVS\n"<< pvsSize/(float)objects.size() << endl << 
     173                        "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl << 
    272174                        "#AvgRayContrib\n" << avgRayContrib << endl; 
    273175        } 
    274176         
    275177        cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 
    276    
    277          
    278         if (0) { 
    279                 Exporter *exporter = Exporter::GetExporter("ray-density.x3d");  
    280                 exporter->SetExportRayDensity(true); 
    281                 exporter->ExportKdTree(*mKdTree); 
     178        cout << "#totalRayStackSize=" << mVssRays.size() << endl; 
    282179 
    283                 delete exporter; 
    284         } 
    285    
    286         bool exportRays = false; 
    287         if (exportRays) { 
    288                 Exporter *exporter = NULL; 
    289                 exporter = Exporter::GetExporter("sample-rays.x3d"); 
    290                 exporter->SetWireframe(); 
    291                 exporter->ExportKdTree(*mKdTree); 
    292  
    293                 for (i=0; i < pvsOut; i++)  
    294                 exporter->ExportRays(rays[i], 1000, RgbColor(1, 0, 0)); 
    295                 exporter->SetFilled(); 
    296                    
    297                 delete exporter; 
    298         } 
    299  
    300         //-- several visualizations and statistics 
    301         if (1) { 
    302                 for (int k=0; k < pvsOut; k++) { 
    303                         Intersectable *object = objects[k]; 
    304                         char s[64]; 
    305                         sprintf(s, "sample-pvs%04d.x3d", k); 
    306                         Exporter *exporter = Exporter::GetExporter(s); 
    307                         exporter->SetWireframe(); 
    308                          
    309                          
    310                         KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 
    311                         Intersectable::NewMail(); 
    312                          
    313                         // avoid adding the object to the list 
    314                         object->Mail(); 
    315                         ObjectContainer visibleObjects; 
    316                          
    317                         for (; i != object->mKdPvs.mEntries.end(); i++)  
    318                                 { 
    319                                         KdNode *node = (*i).first; 
    320                                         exporter->ExportBox(mKdTree->GetBox(node)); 
    321                                         mKdTree->CollectObjects(node, visibleObjects); 
    322                                 } 
    323                          
    324                         exporter->ExportRays(rays[k], 1000, RgbColor(0, 1, 0)); 
    325                         exporter->SetFilled(); 
    326                          
    327                         for (int j = 0; j < visibleObjects.size(); j++) 
    328                                 exporter->ExportIntersectable(visibleObjects[j]); 
    329                          
    330                          
    331                         Material m; 
    332                         m.mDiffuseColor = RgbColor(1, 0, 0); 
    333                         exporter->SetForcedMaterial(m); 
    334                         exporter->ExportIntersectable(object); 
    335                          
    336                         delete exporter; 
    337                 } 
    338   } 
    339    
    340180  return true; 
    341181} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h

    r374 r376  
    66 
    77#include "Preprocessor.h" 
    8  
     8#include "VssRay.h" 
    99 
    1010/** Sampling based visibility preprocessing. The implementation is based on heuristical 
     
    1313public: 
    1414        int mPass; 
    15  
    1615  int mSamplesPerPass; 
    1716  int mTotalSamples; 
    18   int mKdPvsDepth; 
    1917  ofstream mStats; 
     18         
    2019  ObjectContainer mObjects; 
    21   RayContainer mSampleRays; 
     20 
     21        // rays cast during the processing 
     22  VssRayContainer mVssRays; 
    2223         
    2324  VssPreprocessor(); 
    24  
    2525  ~VssPreprocessor(); 
    2626 
    2727  virtual bool ComputeVisibility(); 
    2828 
     29        Vector3 
     30        GetViewpoint(); 
     31 
     32        Vector3 
     33        GetDirection(const Vector3 &viewpoint); 
     34         
    2935  void 
    3036  SetupRay(Ray &ray,  
     
    3339                                         ); 
    3440 
    35   KdNode * 
    36   GetNodeForPvs(KdLeaf *leaf); 
    3741 
    38         int 
    39         AddNodeSamples(const Ray &ray, 
    40                                                                  Intersectable *sObject, 
    41                                                                  Intersectable *tObject 
    42                                                                  ); 
     42         
     43        VssRay *  
     44        CastRay( 
     45                                        Vector3 &viewPoint, 
     46                                        Vector3 &direction 
     47                                        ); 
     48                 
    4349 
    44         int 
    45         CastRay(Intersectable *object, 
    46                                         Ray &ray); 
    4750         
    48         KdNode * 
    49         GetNodeToSample(Intersectable *object); 
    50  
    5151        virtual bool BuildBspTree() { return false; } 
    5252 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h

    r372 r376  
    1 #ifndef __SIMPLE_RAY_H 
    2 #define __SIMPLE_RAY_H 
     1#ifndef __VSS_RAY_H 
     2#define __VSS_RAY_H 
    33 
    44#include <vector> 
     
    4444        ////////////////////////////// 
    4545        VssRay(const Vector3 &origin, 
    46                                                                 const Vector3 &termination, 
    47                                                                 Intersectable *originObject, 
    48                                                                 Intersectable *terminationObject): 
     46                                 const Vector3 &termination, 
     47                                 Intersectable *originObject, 
     48                                 Intersectable *terminationObject): 
    4949                mMailbox(-1), 
    5050    mOrigin(origin), 
     
    6060  void Precompute() { 
    6161    mFlags = 0; 
    62     if (GetDir().x>0.0f) mFlags |= FPosDirX; 
    63     if (GetDir().y>0.0f) mFlags |= FPosDirY; 
    64     if (GetDir().z>0.0f) mFlags |= FPosDirZ; 
     62                Vector3 dir = GetDir(); 
     63 
     64                if (dir.y < 0) { 
     65                        // swap objects and poits        
     66                        swap(mOriginObject, mTerminationObject); 
     67                        swap(mOrigin, mTermination); 
     68                        dir = -dir; 
     69                } 
     70                 
     71                if (dir.x > 0.0f) mFlags |= FPosDirX; 
     72    if (dir.y > 0.0f) mFlags |= FPosDirY; 
     73    if (dir.z > 0.0f) mFlags |= FPosDirZ; 
     74 
    6575    mInvSize = 1.0f/Magnitude(GetDir()); 
    6676  } 
     
    7484  } 
    7585 
    76          
     86        int HitCount() const { 
     87                if (mOriginObject && mTerminationObject) 
     88                        return 2; 
     89                if (mOriginObject || mTerminationObject) 
     90                        return 1; 
     91                return 0; 
     92        } 
    7793         
    7894        Vector3 GetOrigin() const { return mOrigin; } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp

    r374 r376  
    103103void 
    104104X3dParseHandlers::StartIndexedFaceSet( 
    105                                       AttributeList&  attributes) 
     105                                                                                                                                                        AttributeList&  attributes) 
    106106{ 
    107107  int len = attributes.getLength(); 
     
    195195void 
    196196X3dParseHandlers::startElement(const XMLCh* const name, 
    197                               AttributeList&  attributes) 
     197                                                                                                                        AttributeList&  attributes) 
    198198{ 
    199199  StrX lname(name); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/default.env

    r374 r376  
    88#       filename glasgow1.x3d 
    99#       filename vienna.x3d 
    10 #       filename ../data/vienna/vienna-simple.x3d 
    11 #       filename ../data/vienna/vienna-buildings.x3d 
     10# filename ../data/vienna/vienna-simple.x3d 
     11filename ../data/vienna/vienna-buildings.x3d 
    1212# filename ../data/vienna/viewcells-25-sel.x3d 
    1313# filename ../data/atlanta/atlanta2.x3d 
    14         filename ../data/soda/soda.dat 
     14#       filename ../data/soda/soda.dat 
    1515# filename ../data/soda/soda5.dat 
    1616} 
     
    1919#       type sampling 
    2020        type vss 
     21} 
     22 
     23VssPreprocessor { 
     24        totalSamples 1000000 
     25        samplesPerPass  100000 
    2126} 
    2227 
     
    3540        sahUseFaces true 
    3641        Termination { 
    37                 minCost 2 
     42                minCost 1 
    3843                maxDepth 18 
    3944                maxCostRatio 0.9 
     
    4853MeshKdTree { 
    4954        Termination { 
    50                 minCost 4 
     55                minCost 1 
    5156                maxDepth 18 
    5257                maxCostRatio 0.9 
Note: See TracChangeset for help on using the changeset viewer.