Changeset 240


Ignore:
Timestamp:
08/16/05 02:08:07 (19 years ago)
Author:
mattausch
Message:

added dome bsp tree stuff

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

Legend:

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

    r191 r240  
    4242  data = (*i).second; 
    4343} 
     44 
     45BspPvsData *BspPvs::Find(BspNode *node) 
     46{ 
     47        BspPvsMap::iterator i = mEntries.find(node); 
     48         
     49        if (i != mEntries.end())  
     50        { 
     51                //    cout<<node<<" "<<(*i).first<<" "<<(*i).second.mVisibleSamples<<endl; 
     52                return &(*i).second; 
     53        }  
     54        else 
     55          return NULL; 
     56} 
     57 
     58// TODO: Get common ancestor for bsp and kd tree (HierarchyNode) 
     59int BspPvs::AddNodeSample(BspNode *node) 
     60{ 
     61  int result; 
     62   
     63  BspPvsData *data = Find(node); 
     64 
     65  if (data)  
     66  { 
     67          data->mVisibleSamples ++; 
     68          result = 0; 
     69  }  
     70  else  
     71  { 
     72          mEntries[node] = BspPvsData(1); 
     73          result = 1; 
     74  } 
     75 
     76  return  result; 
     77} 
     78 
     79 
     80void BspPvs::GetData(const int index, BspNode *&node, BspPvsData &data) 
     81{ 
     82        BspPvsMap::iterator i = mEntries.begin(); 
     83   
     84        for (int k = 0; k!=index && i != mEntries.end(); i++, k++); 
     85 
     86        node = (*i).first; 
     87        data = (*i).second; 
     88} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h

    r191 r240  
    55 
    66class KdNode; 
     7class BspNode; 
    78class Ray; 
    89 
     
    1718}; 
    1819 
     20/** Superclass for all types of PVS data. 
     21*/ 
     22class Pvs { 
     23public: 
     24        Pvs(): mSamples(0) {} 
     25        int mSamples; 
     26 
     27        virtual int Compress() = 0; 
     28        virtual int GetSize() = 0; 
     29}; 
     30 
    1931struct KdPvsData { 
    2032  int mVisibleSamples; 
     
    2638 
    2739 
    28 class KdPvs { 
     40class KdPvs: public Pvs { 
    2941public: 
    30   int mSamples; 
     42  
    3143  KdPvsMap mEntries; 
    3244   
    33   KdPvs():mSamples(0),mEntries() {} 
     45  KdPvs():mEntries() {} 
    3446   
    3547  KdPvsData *Find(KdNode *node); 
     
    4456}; 
    4557 
     58struct LtBspNode 
     59{ 
     60  bool operator()(const BspNode *a, 
     61                  const BspNode *b) const 
     62  { 
     63          return a < b; 
     64  } 
     65}; 
    4666 
     67struct BspPvsData { 
     68  int mVisibleSamples; 
     69  BspPvsData() {} 
     70  BspPvsData(const int samples): mVisibleSamples(samples) {} 
     71}; 
     72 
     73typedef std::map<BspNode *, BspPvsData, LtBspNode> BspPvsMap; 
     74 
     75class BspPvs: public Pvs  
     76{ 
     77public: 
     78        BspPvs(): mEntries() {} 
     79 
     80        BspPvsMap mEntries; 
     81  
     82        BspPvsData *Find(BspNode *node); 
     83        int AddNodeSample(BspNode *node); 
     84         
     85        int Compress() {return 0;} 
     86         
     87        int GetSize() {return mEntries.size();} 
     88         
     89        void GetData(const int index, 
     90                                 BspNode *&node, 
     91                                 BspPvsData &data); 
     92}; 
    4793 
    4894#endif 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r239 r240  
    1111#include <iomanip> 
    1212 
    13 #define INITIAL_TEST_VAL 999999// unreachable high initial value for heuristic evaluation 
     13#define INITIAL_COST 999999// unreachable high initial cost for heuristic evaluation 
    1414 
    1515int BspTree::sTermMaxPolygons = 10; 
     
    452452Plane3 BspTree::SelectPlaneHeuristics(PolygonContainer *polygons, int maxTests) const 
    453453{ 
    454         int bestValue = INITIAL_TEST_VAL; 
     454        int lowestCost = INITIAL_COST; 
    455455        Plane3 *bestPlane = NULL; 
    456456         
     
    463463                 
    464464                // evaluate current candidate 
    465                 int candidateValue = EvalSplitPlane(polygons, candidatePlane); 
     465                int candidateCost = EvalSplitPlane(polygons, candidatePlane); 
    466466                         
    467                 if (candidateValue < bestValue) 
     467                if (candidateCost < lowestCost) 
    468468                { 
    469469                        bestPlane = &candidatePlane; 
    470                         bestValue = candidateValue; 
    471                         //Debug << "new plane value " << bestValue << endl; 
     470                        lowestCost = candidateCost; 
     471                        //Debug << "new plane cost " << lowestCost << endl; 
    472472                } 
    473473        } 
     
    593593} 
    594594 
     595void BspTree::CollectLeaves(vector<BspLeaf *> &leaves) 
     596{ 
     597        stack<BspNode *> nodeStack; 
     598        nodeStack.push(mRoot); 
     599  
     600        while (!nodeStack.empty())  
     601        { 
     602                BspNode *node = nodeStack.top(); 
     603     
     604                nodeStack.pop(); 
     605     
     606                if (node->IsLeaf())  
     607                { 
     608                        BspLeaf *leaf = (BspLeaf *)node; 
     609                         
     610                        leaves.push_back(leaf); 
     611                } else  
     612                { 
     613                        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     614                        nodeStack.push(interior->GetBack()); 
     615                        nodeStack.push(interior->GetFront()); 
     616                } 
     617        } 
     618} 
     619 
     620int BspTree::CollectLeafPvs() 
     621{ 
     622        int totalPvsSize = 0; 
     623   
     624        stack<BspNode *> nodeStack; 
     625   
     626        nodeStack.push(mRoot); 
     627   
     628        while (!nodeStack.empty())  
     629        { 
     630                BspNode *node = nodeStack.top(); 
     631                 
     632                nodeStack.pop(); 
     633                 
     634                if (node->IsLeaf())  
     635                { 
     636                        BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
     637 
     638                        ViewCell *viewcell = leaf->GetViewCell(); 
     639                         
     640                        if (!viewcell->Mailed())  
     641                        { 
     642                                viewcell->Mail(); 
     643                                         
     644                                // add this node to pvs of all nodes it can see 
     645                                BspPvsMap::iterator ni;  
     646           
     647        /*                      for (ni = object->mBspPvs.mEntries.begin(); ni != object->mKdPvs.mEntries.end(); ni++)  
     648                                { 
     649                                        BspNode *node = (*ni).first; 
     650             
     651                                        // $$ JB TEMPORARY solution -> should add object PVS or explictly computed 
     652                                        // BSP tree PVS 
     653                                if (leaf->mBspPvs.AddNodeSample(node)) 
     654                                                totalPvsSize++; 
     655                                }*/ 
     656                        } 
     657                } else  
     658                { 
     659                        // traverse tree 
     660                        BspInterior *interior = (BspInterior *)node; 
     661       
     662                        nodeStack.push(interior->GetFront()); 
     663                        nodeStack.push(interior->GetBack()); 
     664                } 
     665        } 
     666 
     667        return totalPvsSize; 
     668} 
     669 
    595670void BspTree::EvaluateLeafStats(const BspTraversalData &data) 
    596671{ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r239 r240  
    230230        void Construct(const ObjectContainer &objects); 
    231231 
     232        int BspTree::CollectLeafPvs(); 
     233 
     234        void CollectLeaves(vector<BspLeaf *> &leaves); 
    232235 
    233236protected: 
Note: See TracChangeset for help on using the changeset viewer.