Changeset 1758


Ignore:
Timestamp:
11/15/06 16:07:29 (18 years ago)
Author:
mattausch
Message:

bvhnode is now derived from Intersectable

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp

    r1757 r1758  
    4646BvhNode::BvhNode():  
    4747mParent(NULL),  
    48 mMailbox(0), 
    49 //mRenderCostDecr(0),  
    50 //mMemoryIncr(0), 
    51 //mPvsEntriesIncr(0), 
    5248mTimeStamp(0) 
    5349{ 
     
    5854mParent(NULL),  
    5955mBoundingBox(bbox),  
    60 mMailbox(0), 
    61 //mMemoryIncr(0), 
    62 //mRenderCostDecr(0),  
    63 //mPvsEntriesIncr(0), 
    6456mTimeStamp(0) 
    6557{ 
     
    7062mBoundingBox(bbox),  
    7163mParent(parent),  
    72 mMailbox(0), 
    73 //mMemoryIncr(0), 
    74 //mRenderCostDecr(0),  
    75 //mPvsEntriesIncr(0), 
    7664mTimeStamp(0) 
    7765{ 
     
    219207BvHierarchy::~BvHierarchy() 
    220208{ 
    221         // delete bvh intersectables 
    222         BvhIntersectableMap::iterator it, it_end = mBvhIntersectables.end(); 
    223  
    224         for (it = mBvhIntersectables.begin(); it != mBvhIntersectables.end(); ++ it) 
    225         { 
    226                 DEL_PTR((*it).second); 
    227         } 
    228  
    229209        // delete the local subdivision candidates 
    230210        DEL_PTR(mSubdivisionCandidates); 
     
    14021382        const bool useMailboxing = false; 
    14031383 
    1404         CollectViewCells(obj, viewCells, useMailboxing, true, true); 
     1384        CollectViewCells(obj, viewCells, useMailboxing, false, true); 
    14051385 
    14061386        // classify view cells and compute volume contri accordingly 
     
    18361816        ViewCellContainer viewCells; 
    18371817        ViewCell::NewMail(); 
    1838         int numRays = CollectViewCells(node->mObjects, viewCells, true, false); 
     1818        int numRays = CollectViewCells(node->mObjects, viewCells, false, false); 
    18391819 
    18401820        //cout << "here6 " << numRays << endl; 
     
    19431923 
    19441924 
    1945 BvhIntersectable *BvHierarchy::GetOrCreateBvhIntersectable(BvhLeaf *node) 
    1946 { 
    1947         // search nodes 
    1948         std::map<BvhLeaf *, BvhIntersectable *>::const_iterator  
    1949                 it = mBvhIntersectables.find(node); 
    1950  
    1951         if (it != mBvhIntersectables.end())  
    1952         { 
    1953                 return (*it).second; 
    1954         } 
    1955  
    1956         // not in map => create new entry 
    1957         BvhIntersectable *bvhObj = new BvhIntersectable(node); 
    1958         mBvhIntersectables[node] = bvhObj; 
    1959  
    1960         return bvhObj; 
    1961 } 
    1962  
    1963  
    19641925bool BvHierarchy::Export(OUT_STREAM &stream) 
    19651926{ 
     
    24242385 
    24252386 
    2426 void BvHierarchy::CollectObjects(const AxisAlignedBox3 &box, 
    2427                                                                  ObjectContainer &objects) 
     2387void BvHierarchy::CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects) 
    24282388{ 
    24292389  stack<BvhNode *> nodeStack; 
     
    24312391  nodeStack.push(mRoot); 
    24322392 
    2433   while (!nodeStack.empty()) { 
     2393  while (!nodeStack.empty())  
     2394        { 
    24342395        BvhNode *node = nodeStack.top(); 
    24352396         
    24362397        nodeStack.pop(); 
    24372398         
    2438         if (node->IsLeaf()) { 
     2399          if (node->IsLeaf())  
     2400                { 
    24392401          BvhLeaf *leaf = (BvhLeaf *)node; 
    24402402          if (Overlap(box, leaf->GetBoundingBox())) { 
    2441                 Intersectable *object = GetOrCreateBvhIntersectable(leaf); 
     2403                        Intersectable *object = leaf; 
    24422404                if (!object->Mailed()) { 
    24432405                  object->Mail(); 
     
    24462408          } 
    24472409        }  
    2448         else  { 
     2410          else  
     2411                { 
    24492412          BvhInterior *interior = (BvhInterior *)node; 
    24502413           
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1744 r1758  
    3232class BvhLeaf; 
    3333class BvhNode; 
    34 class BvhIntersectable; 
    3534class BvhTree; 
    3635class VspTree; 
     
    151150    VspNode abstract class serving for interior and leaf node implementation 
    152151*/ 
    153 class BvhNode 
     152class BvhNode: public Intersectable 
    154153{ 
    155154public: 
     
    204203        int mTimeStamp; 
    205204 
    206         //int mPvsEntriesIncr; 
    207         //float mMemoryIncr; 
    208         //float mRenderCostDecr; 
    209  
    210205        ///////////////////////////////////// 
    211206        //-- mailing options 
     
    225220 
    226221        static int sMailId; 
    227         int mMailbox; 
     222        //int mMailbox; 
    228223        static int sReservedMailboxes; 
     224 
     225 
     226 
     227        ///////////////////////////////////////////// 
     228        //-- inherited functions from Intersectable 
     229 
     230        AxisAlignedBox3 GetBox() const { return mBoundingBox; } 
     231         
     232        int CastRay(Ray &ray) { return 0; } 
     233         
     234        bool IsConvex() const { return true; } 
     235        bool IsWatertight() const { return true; } 
     236        float IntersectionComplexity() { return 1; } 
     237   
     238        int NumberOfFaces() const { return 6; }; 
     239         
     240        int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point,  
     241                                                          GtpVisibilityPreprocessor::Vector3 &normal) 
     242        { 
     243                // TODO 
     244                return 0; 
     245        } 
     246 
     247        int GetRandomVisibleSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point, 
     248                                                                         GtpVisibilityPreprocessor::Vector3 &normal, 
     249                                                                         const GtpVisibilityPreprocessor::Vector3 &viewpoint, 
     250                                                                         const int maxTries) 
     251        { 
     252                // TODO 
     253                return 0; 
     254        } 
     255   
     256        int Type() const 
     257        { 
     258                return Intersectable::BVH_INTERSECTABLE; 
     259        } 
     260 
     261        ostream &Describe(ostream &s) { return s; } 
    229262 
    230263        /////////////////////////////////// 
     
    341374        BvhNode *mActiveNode; 
    342375}; 
    343  
    344  
    345 typedef map<BvhLeaf *, BvhIntersectable *> BvhIntersectableMap; 
    346376 
    347377 
     
    568598        bool Export(OUT_STREAM &stream); 
    569599 
    570         /** Returns or creates a new intersectable for use in a bv based pvs. 
    571                 The hierarchy is responsible for destruction of the intersectable. 
    572         */ 
    573         BvhIntersectable *GetOrCreateBvhIntersectable(BvhLeaf *node); 
    574  
    575600        /** Collects rays associated with the objects. 
    576601        */ 
     
    943968        /// weight between render cost decrease and node render cost 
    944969        float mRenderCostDecreaseWeight; 
    945         /// stores the kd node intersectables used for pvs 
    946         BvhIntersectableMap mBvhIntersectables; 
     970 
    947971        /// if the objects should be sorted in one global step 
    948972        bool mUseGlobalSorting; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp

    r1723 r1758  
    184184        case Intersectable::BVH_INTERSECTABLE: 
    185185                { 
    186                         BvhNode *node = dynamic_cast<BvhIntersectable *>(object)->GetItem(); 
     186                        BvhNode *node = dynamic_cast<BvhNode *>(object); 
    187187                        if (node->IsLeaf()) 
    188188                                ExportGeometry(dynamic_cast<BvhLeaf *>(node)->mObjects, true); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp

    r1737 r1758  
    133133  case Intersectable::BVH_INTERSECTABLE: { 
    134134 
    135          
    136         BvhNode *node = (dynamic_cast<BvhIntersectable *>(object))->GetItem(); 
     135          BvhNode *node = dynamic_cast<BvhNode *>(object); 
    137136 
    138137        if (mRenderBoxes) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1750 r1758  
    14511451                { 
    14521452                        BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 
    1453                         BvhIntersectable *bvhObj = mBvHierarchy->GetOrCreateBvhIntersectable(leaf); 
    14541453                         
    1455                         return vc->AddPvsSample(bvhObj, pdf, contribution); 
     1454                        return vc->AddPvsSample(leaf, pdf, contribution); 
    14561455                } 
    14571456        default: 
     
    15221521                                                                                                  const Vector3 &point) const 
    15231522{ 
    1524    
    1525   if (!obj) 
    1526         return NULL; 
    1527    
    1528   switch (mObjectSpaceSubdivisionType) 
     1523 
     1524        if (!obj) 
     1525                return NULL; 
     1526 
     1527        switch (mObjectSpaceSubdivisionType) 
    15291528        { 
    15301529        case HierarchyManager::KD_BASED_OBJ_SUBDIV: 
    1531           { 
    1532                 KdLeaf *leaf = mOspTree->GetLeaf(point, NULL); 
    1533                 return mOspTree->GetOrCreateKdIntersectable(leaf); 
    1534           } 
     1530                { 
     1531                        KdLeaf *leaf = mOspTree->GetLeaf(point, NULL); 
     1532                        return mOspTree->GetOrCreateKdIntersectable(leaf); 
     1533                } 
    15351534        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
    1536           { 
    1537                 BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 
    1538                 return mBvHierarchy->GetOrCreateBvhIntersectable(leaf); 
    1539           } 
     1535                { 
     1536                        BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 
     1537                        return leaf; 
     1538                } 
    15401539        default: 
    1541           return obj; 
     1540                return obj; 
    15421541        } 
    15431542} 
     
    15461545                                                                                                  const bool isTermination) const 
    15471546{ 
    1548   Intersectable *obj = NULL; 
     1547        Intersectable *obj = NULL; 
    15491548        Vector3 pt; 
    15501549        KdNode *node; 
    15511550 
    15521551        ray.GetSampleData(isTermination, pt, &obj, &node); 
    1553          
     1552 
    15541553        if (!obj) 
    1555           return NULL; 
     1554                return NULL; 
    15561555 
    15571556        switch (mObjectSpaceSubdivisionType) 
     
    15591558        case HierarchyManager::KD_BASED_OBJ_SUBDIV: 
    15601559                { 
    1561                   KdLeaf *leaf = mOspTree->GetLeaf(pt, node); 
     1560                        KdLeaf *leaf = mOspTree->GetLeaf(pt, node); 
    15621561                        return mOspTree->GetOrCreateKdIntersectable(leaf); 
    15631562                } 
     
    15651564                { 
    15661565                        BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 
    1567                         return mBvHierarchy->GetOrCreateBvhIntersectable(leaf); 
     1566                        return leaf; 
    15681567                } 
    15691568        default: 
    1570           break; 
     1569                break; 
    15711570        } 
    15721571        return obj; 
     
    18391838                ObjectPvsEntry entry = pit.Next(); 
    18401839 
    1841                 BvhIntersectable *intersect = dynamic_cast<BvhIntersectable *>(entry.mObject); 
    1842  
    1843                 BvhLeaf *leaf = intersect->GetItem(); 
    1844                 BvhNode *activeNode = leaf->GetActiveNode(); 
     1840                BvhNode *activeNode; 
     1841                BvhNode *intersect = dynamic_cast<BvhNode *>(entry.mObject); 
     1842 
     1843                // hack for choosing which node to account for 
     1844                if (intersect->IsLeaf()) 
     1845                        activeNode = dynamic_cast<BvhLeaf *>(intersect)->GetActiveNode(); 
     1846                else 
     1847                        activeNode = intersect; 
    18451848 
    18461849                if (!activeNode->Mailed()) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp

    r1737 r1758  
    9797  mBox = box; 
    9898} 
    99  
    100 AxisAlignedBox3 BvhIntersectable::GetBox() const 
    101 { 
    102   return mItem->GetBoundingBox(); 
    10399} 
    104  
    105 } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h

    r1737 r1758  
    169169typedef map<KdNode *, KdIntersectable *> KdIntersectableMap; 
    170170 
    171 class BvhIntersectable: public IntersectableWrapper<BvhLeaf *> 
    172 { 
    173 public: 
    174         BvhIntersectable(BvhLeaf *item): 
    175         IntersectableWrapper<BvhLeaf *>(item) {} 
    176  
    177         int Type() const 
    178         { 
    179                 return Intersectable::BVH_INTERSECTABLE; 
    180         } 
    181  
    182         AxisAlignedBox3 GetBox() const; 
    183  
    184 }; 
    185  
    186171 
    187172class TriangleIntersectable: public IntersectableWrapper<Triangle3> 
  • GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h

    r1695 r1758  
    280280                float GetPriority() const 
    281281                { 
    282                         HierarchyManager *hm = sOspTree->mHierarchyManager; 
    283                         if (hm->ConsiderMemory()) 
    284                         { 
    285                                 const float rc = hm->GetHierarchyStats().mTotalCost - mRenderCostDecrease; 
    286                                 const float mc = hm->GetHierarchyStats().mMemory + 
    287                                                                  (float)mPvsEntriesIncr * ObjectPvs::GetEntrySizeByte(); 
    288  
    289                                 return - (rc * mc); 
    290                         } 
    291                         else 
    292                         { 
    293                                 return mPriority; 
    294                         } 
     282                        return mPriority; 
    295283                } 
    296284 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp

    r1740 r1758  
    7979        We eliminate already accounted bvh nodes and objects using mailboxing.  
    8080*/ 
    81 static float EvalBvhNodeContribution(BvhIntersectable *bvhobj) 
     81static float EvalBvhNodeContribution(BvhNode *bvhObj) 
    8282{ 
    83         BvhLeaf *leaf = bvhobj->GetItem(); 
    84         BvhNode *node = leaf->GetActiveNode(); 
     83        BvhNode *node; 
     84 
     85        // hack for choosing which node to account for 
     86        if (bvhObj->IsLeaf()) 
     87                node = dynamic_cast<BvhLeaf *>(bvhObj)->GetActiveNode(); 
     88        else 
     89                node = bvhObj; 
    8590 
    8691        // early exit 
    87         if (node == leaf)        
    88         { 
     92        if (node->IsLeaf())      
     93        {        
     94                BvhLeaf *leaf = dynamic_cast<BvhLeaf *>(node); 
    8995                // objects already accounted for 
    9096                if (leaf->Mailed()) 
     
    112118                        if (node->IsLeaf()) 
    113119                        { 
    114                                 leaf = dynamic_cast<BvhLeaf *>(node); 
     120                                BvhLeaf *leaf = dynamic_cast<BvhLeaf *>(node); 
    115121 
    116122                                // add #objects exclusivly in this node 
     
    156162                        case Intersectable::BVH_INTERSECTABLE: 
    157163                                { 
    158                                         BvhIntersectable *bvhObj = dynamic_cast<BvhIntersectable *>(obj); 
     164                                        BvhNode *bvhObj = dynamic_cast<BvhNode *>(obj); 
    159165                                        pvs += EvalBvhNodeContribution(bvhObj); 
    160166                                        break; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1750 r1758  
    23712371                { 
    23722372                        ObjectContainer objects;  
    2373                         BvhNode *node = dynamic_cast<BvhIntersectable *>(obj)->GetItem(); 
     2373                        BvhNode *node = dynamic_cast<BvhNode *>(obj); 
    23742374                        node->CollectObjects(objects); 
    23752375                 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1757 r1758  
    60296029                Debug << "finished in " << timeDiff * 1e-3 << " secs" << endl; 
    60306030 
    6031                 if ((castSamples >= samplesForStats + oldSamples) || (castSamples >= numSamples)) 
     6031                if ((castSamples >= samplesForStats + oldSamples) ||  
     6032                        (castSamples >= numSamples)) 
    60326033                { 
    60336034                        oldSamples += samplesForStats; 
Note: See TracChangeset for help on using the changeset viewer.