Changeset 374 for trunk


Ignore:
Timestamp:
11/03/05 16:43:51 (19 years ago)
Author:
bittner
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
1 added
11 edited

Legend:

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

    r370 r374  
    109109          exporter->ExportBox(tree->GetBox(ray->kdLeaves[i])); 
    110110        if (0) 
    111         for (i= 0; i < ray->meshes.size(); i++) 
    112           exporter->ExportIntersectable(ray->meshes[i]); 
     111                for (i= 0; i < ray->testedObjects.size(); i++) 
     112                        exporter->ExportIntersectable(ray->testedObjects[i]); 
    113113 
    114114      } 
     
    131131  ray.intersections.clear(); 
    132132  ray.kdLeaves.clear(); 
    133   ray.meshes.clear(); 
     133  ray.testedObjects.clear(); 
    134134  ray.bspIntersections.clear(); 
    135135 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r372 r374  
    12411241 
    12421242  RegisterOption("BspTree.splitPlaneStrategy", 
    1243                 optString, 
    1244                 "-bsp_split_method=", 
    1245                 "leastSplits"); 
     1243                                                                 optString, 
     1244                                                                 "-bsp_split_method=", 
     1245                                                                 "leastSplits"); 
    12461246 
    12471247  RegisterOption("BspTree.maxCandidates", 
     
    12591259          "-bsp_exportSplits", 
    12601260          "false"); 
     1261 
     1262  RegisterOption("Preprocessor.type", 
     1263                                                                 optString, 
     1264                                                                 "-preprocessor=", 
     1265                                                                 "sampling"); 
     1266         
    12611267} 
    12621268 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ExactPreprocessor.h

    r372 r374  
    99  public: 
    1010    virtual bool ComputeVisibility(); 
     11 
     12                virtual bool BuildBspTree() { return false; } 
     13 
    1114  }; 
    1215   
  • trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp

    r372 r374  
    476476      float sum; 
    477477      if (mSahUseFaces) 
    478         sum = intersectionsLeft*lbox.SurfaceArea() + intersectionsRight*rbox.SurfaceArea(); 
     478                                sum = intersectionsLeft*lbox.SurfaceArea() + intersectionsRight*rbox.SurfaceArea(); 
    479479      else 
    480         sum = objectsLeft*lbox.SurfaceArea() + objectsRight*rbox.SurfaceArea(); 
     480                                sum = objectsLeft*lbox.SurfaceArea() + objectsRight*rbox.SurfaceArea(); 
    481481       
    482482      //      cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl; 
     
    484484       
    485485      if (sum < minSum) { 
    486         minSum = sum; 
    487         position = (*ci).value; 
    488          
    489         objectsBack = objectsLeft; 
    490         objectsFront = objectsRight; 
     486                                minSum = sum; 
     487                                position = (*ci).value; 
     488                                 
     489                                objectsBack = objectsLeft; 
     490                                objectsFront = objectsRight; 
    491491      } 
    492492    } 
     
    507507int 
    508508KdTree::CastRay( 
    509                 Ray &ray 
    510                 ) 
     509                                                                Ray &ray 
     510                                                                ) 
    511511{ 
    512512  int hits = 0; 
     
    570570      maxt = tdist; 
    571571        } else { 
    572       // compute intersection with all objects in this leaf 
    573       KdLeaf *leaf = (KdLeaf *) node; 
    574       ray.kdLeaves.push_back(leaf); 
    575        
    576       ObjectContainer::const_iterator mi; 
    577       for ( mi = leaf->mObjects.begin(); 
    578             mi != leaf->mObjects.end(); 
    579             mi++) { 
    580         Intersectable *object = *mi; 
    581         if (!object->Mailed() ) { 
    582           object->Mail(); 
    583           //ray.meshes.push_back(mesh); 
    584           hits += object->CastRay(ray); 
     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                        } 
     588                } 
     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(); 
    585608        } 
    586       } 
    587  
    588       if (hits && ray.GetType() == Ray::LOCAL_RAY) 
    589         if (ray.intersections[0].mT <= maxt) 
    590           break; 
    591        
    592       // get the next node from the stack 
    593       if (tStack.empty()) 
    594         break; 
    595        
    596       entp = extp; 
    597       mint = maxt; 
    598       if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 
    599         break; 
    600        
    601       RayTraversalData &s  = tStack.top(); 
    602       node = s.mNode; 
    603       extp = s.mExitPoint; 
    604       maxt = s.mMaxT; 
    605       tStack.pop(); 
    606     } 
    607609  } 
    608610   
     
    624626      KdLeaf *leaf = (KdLeaf *)node; 
    625627      for (int j=0; j < leaf->mObjects.size(); j++) { 
    626         Intersectable *object = leaf->mObjects[j]; 
    627         if (!object->Mailed()) { 
    628           object->Mail(); 
    629           objects.push_back(object); 
    630         } 
     628                                Intersectable *object = leaf->mObjects[j]; 
     629                                if (!object->Mailed()) { 
     630                                        object->Mail(); 
     631                                        objects.push_back(object); 
     632                                } 
    631633      } 
    632634    } else { 
     
    699701      KdInterior *interior = (KdInterior *)node; 
    700702      if (interior->mPosition > box.Max(interior->mAxis)) 
    701         nodeStack.push(interior->mBack); 
     703                                nodeStack.push(interior->mBack); 
    702704      else 
    703         if (interior->mPosition < box.Min(interior->mAxis)) 
    704           nodeStack.push(interior->mFront); 
    705         else { 
    706           // random decision 
    707             nodeStack.push(interior->mBack); 
    708             nodeStack.push(interior->mFront); 
    709         } 
     705                                if (interior->mPosition < box.Min(interior->mAxis)) 
     706                                        nodeStack.push(interior->mFront); 
     707                                else { 
     708                                        // random decision 
     709                                        nodeStack.push(interior->mBack); 
     710                                        nodeStack.push(interior->mFront); 
     711                                } 
    710712    } 
    711713  } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h

    r370 r374  
    2929  /// front (back) to the back (front) 
    3030  enum {FRONT, BACK, BACK_FRONT, FRONT_BACK, COINCIDENT}; 
    31  
     31         
    3232  struct Intersection { 
    3333    // the point of intersection 
     
    6363 
    6464    BspIntersection(const float t, BspLeaf *l): 
    65         mT(t), mLeaf(l) {} 
    66  
     65                        mT(t), mLeaf(l) {} 
     66                 
    6767    BspIntersection() {} 
    68  
     68                 
    6969    bool operator<(const BspIntersection &b) const { 
    7070      return mT <b.mT; } 
     
    7979  vector<BspIntersection> bspIntersections; 
    8080  vector<KdLeaf *> kdLeaves; 
    81   vector<MeshInstance *> meshes; 
    82    
     81  vector<Intersectable *> testedObjects; 
     82 
     83        // various flags 
     84        enum {STORE_KDLEAVES=1, STORE_BSP_INTERSECTIONS=2, STORE_TESTED_OBJECTS=4}; 
     85        int mFlags; 
     86 
     87         
    8388  // constructors 
    8489  Ray(const Vector3 &wherefrom, 
    8590      const Vector3 &whichdir, 
    86       const int _type) { 
     91      const int _type):mFlags(0) { 
    8792    loc = wherefrom; 
    8893    if (_type == LINE_SEGMENT) 
     
    9297    mType = _type; 
    9398    depth = 0; 
    94     Init(); 
     99                Init(); 
    95100  } 
    96101  // dummy constructor 
    97102  Ray() {} 
    98  
     103         
    99104  Intersectable *GetIntersectionObject(const int i) const { 
    100105    return intersections[i].mObject; 
     
    236241  // to the number of bounces of the ray, also called the depth of the 
    237242  // ray (primary ray has its depth zero) 
    238   int      depth; 
    239    
    240    
     243  int depth; 
     244 
     245         
     246         
    241247  void Init(); 
    242248 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r373 r374  
    3333  ray.intersections.clear(); 
    3434  ray.kdLeaves.clear(); 
    35   ray.meshes.clear(); 
     35  ray.testedObjects.clear(); 
    3636  ray.bspIntersections.clear(); 
    37  
     37        ray.mFlags |= Ray::STORE_KDLEAVES | Ray::STORE_BSP_INTERSECTIONS; 
    3838  //  cout<<point<<" "<<direction<<endl; 
    3939  ray.Init(point, direction, type); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp

    r372 r374  
    2828VssPreprocessor::SetupRay(Ray &ray,  
    2929                                                                                                        const Vector3 &point,  
    30                                                                                                         const Vector3 &direction, 
    31                                                                                                         const int type) 
     30                                                                                                        const Vector3 &direction 
     31                                                                                                        ) 
    3232{ 
    3333  ray.intersections.clear(); 
    34   ray.kdLeaves.clear(); 
    35   ray.meshes.clear(); 
    36  
     34        // do not store anything else then intersections at the ray 
     35        ray.kdLeaves.clear(); 
     36        ray.mFlags = Ray::STORE_KDLEAVES; 
     37         
    3738  //  cout<<point<<" "<<direction<<endl; 
    38   ray.Init(point, direction, type); 
     39  ray.Init(point, direction, Ray::LOCAL_RAY); 
    3940} 
    4041 
     
    5152int 
    5253VssPreprocessor::AddNodeSamples(const Ray &ray, 
    53                                                                                                                                                  Intersectable *sObject, 
    54                                                                                                                                                  Intersectable *tObject 
    55                                                                                                                                                  ) 
     54                                                                                                                                Intersectable *sObject, 
     55                                                                                                                                Intersectable *tObject 
     56                                                                                                                                ) 
    5657{ 
    5758  int contributingSamples = 0; 
     
    6263        if (tObject) 
    6364                objects++; 
    64  
     65         
    6566        if (objects) { 
    6667                for (j=0; j < ray.kdLeaves.size(); j++) { 
     
    123124        KdNode *nodeToSample = NULL; 
    124125         
    125         bool samplePvsBoundary = false; 
    126         if (pvsSize && samplePvsBoundary) { 
    127                 // this samples the nodes from the boundary of the current PVS 
    128                 // mail all nodes from the pvs 
    129                 Intersectable::NewMail(); 
    130                 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 
    131                  
    132                 for (; i != object->mKdPvs.mEntries.end(); i++) { 
    133                         KdNode *node = (*i).first; 
    134                         node->Mail(); 
    135                 } 
    136                  
    137                 int maxTries = 2*pvsSize; 
    138                 Debug << "Finding random neighbour" << endl;     
    139                 for (int tries = 0; tries < 10; tries++) { 
    140                         int index = RandomValue(0, pvsSize - 1); 
    141                         KdPvsData data; 
    142                         KdNode *node; 
    143                         object->mKdPvs.GetData(index, node, data); 
    144                         nodeToSample = mKdTree->FindRandomNeighbor(node, true); 
    145                         if (nodeToSample) 
    146                                 break; 
    147                 } 
    148         } else { 
    149                 // just pickup a random node 
    150                 //              nodeToSample = mKdTree->GetRandomLeaf(Plane3(normal, point)); 
    151                 nodeToSample = mKdTree->GetRandomLeaf(); 
    152         } 
     126        // just pickup a random node 
     127        nodeToSample = mKdTree->GetRandomLeaf(); 
    153128        return nodeToSample; 
    154129} 
     
    229204                                         
    230205                                        // construct a ray 
    231                                         SetupRay(ray, point, direction, Ray::LOCAL_RAY); 
     206                                        SetupRay(ray, point, direction); 
    232207                                         
    233208                                        sampleContributions = CastRay(reverseSample ? NULL : object, ray); 
     
    298273        } 
    299274         
    300         if (ViewCell::sHierarchy == ViewCell::KD)        
    301                 cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 
    302    
    303          
    304   //  HoleSamplingPass(); 
     275        cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 
     276   
     277         
    305278        if (0) { 
    306279                Exporter *exporter = Exporter::GetExporter("ray-density.x3d");  
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h

    r372 r374  
    2929  void 
    3030  SetupRay(Ray &ray,  
    31                   const Vector3 &point,  
    32                    const Vector3 &direction, 
    33                    const int type); 
     31                                        const Vector3 &point,  
     32                                         const Vector3 &direction 
     33                                         ); 
    3434 
    3535  KdNode * 
     
    4949        GetNodeToSample(Intersectable *object); 
    5050 
     51        virtual bool BuildBspTree() { return false; } 
     52 
    5153}; 
    5254 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp

    r364 r374  
    458458void 
    459459X3dViewCellsParseHandlers::StartCoordinate( 
    460                                   AttributeList&  attributes) 
     460                                                                                                                                                                        AttributeList&  attributes) 
    461461{ 
    462462        int len = attributes.getLength(); 
     
    518518#ifdef _DEBUG 
    519519                Debug << "Viewcell: "  
    520                           << mesh->mVertices[0] << " " << mesh->mVertices[1] << " " << mesh->mVertices[2] << " "  
    521                           << mesh->mVertices[3] << " " << mesh->mVertices[4] << " " << mesh->mVertices[5] << "\n"; 
     520                                        << mesh->mVertices[0] << " " << mesh->mVertices[1] << " " << mesh->mVertices[2] << " "  
     521                                        << mesh->mVertices[3] << " " << mesh->mVertices[4] << " " << mesh->mVertices[5] << "\n"; 
    522522#endif 
    523         } 
     523                } 
    524524} 
    525525 
     
    527527void 
    528528X3dViewCellsParseHandlers::startElement(const XMLCh* const name, 
    529                                AttributeList&  attributes) 
     529                                                                                                                                                                AttributeList&  attributes) 
    530530{ 
    531531  StrX lname(name); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/default.env

    r370 r374  
    1212# filename ../data/vienna/viewcells-25-sel.x3d 
    1313# filename ../data/atlanta/atlanta2.x3d 
    14 #       filename ../data/soda/soda.dat 
    15 filename ../data/soda/soda5.dat 
     14        filename ../data/soda/soda.dat 
     15# filename ../data/soda/soda5.dat 
     16} 
     17 
     18Preprocessor { 
     19#       type sampling 
     20        type vss 
    1621} 
    1722 
     
    6166 
    6267ViewCells { 
    63         #hierarchy kdTree 
    64         hierarchy bspTree 
     68        hierarchy kdTree 
     69        #hierarchy bspTree 
    6570        # hierarchy sceneDependent 
    6671         
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r372 r374  
    11#include "SamplingPreprocessor.h" 
     2#include "VssPreprocessor.h" 
    23#include "ExactPreprocessor.h" 
    34#include "Parser.h" 
     
    2425  BspTree::ParseEnvironment(); 
    2526 
    26   Preprocessor *p = 
    27     new SamplingPreprocessor(); 
     27        char buff[128]; 
    2828 
    29   char buff[128]; 
     29        environment->GetStringValue("Preprocessor.type", buff); 
     30 
     31        string preprocessorType(buff); 
     32         
     33  Preprocessor *p; 
     34 
     35        if (preprocessorType == "vss") 
     36                p = new VssPreprocessor(); 
     37        else 
     38                if (preprocessorType == "exact") 
     39                        p = new ExactPreprocessor(); 
     40                else 
     41                        if (preprocessorType == "sampling") 
     42                                p = new SamplingPreprocessor(); 
     43                        else { 
     44                                cerr<<"Unknown preprocessor type"<<endl; 
     45                                Debug<<"Unknown preprocessor type"<<endl; 
     46                                exit(1); 
     47                        } 
     48         
     49 
    3050  environment->GetStringValue("Scene.filename", buff); 
    3151  string filename(buff); 
Note: See TracChangeset for help on using the changeset viewer.