Ignore:
Timestamp:
08/30/06 04:39:53 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r1294 r1297  
    2626static float debugVol = 0; 
    2727 
    28 int BvhNode::sMailId = 2147483647; 
     28int BvhNode::sMailId = 10000;//2147483647; 
    2929int BvhNode::sReservedMailboxes = 1; 
    3030 
     
    4444/***************************************************************/ 
    4545 
    46 BvhNode::BvhNode(): mParent(NULL) 
     46BvhNode::BvhNode(): mParent(NULL), mMailbox(0) 
    4747{ 
    4848} 
    4949 
    5050BvhNode::BvhNode(const AxisAlignedBox3 &bbox): 
    51 mParent(NULL), mBoundingBox(bbox) 
     51mParent(NULL), mBoundingBox(bbox), mMailbox(0) 
    5252{ 
    5353} 
     
    5555 
    5656BvhNode::BvhNode(const AxisAlignedBox3 &bbox, BvhInterior *parent): 
    57 mBoundingBox(bbox), mParent(parent) 
     57mBoundingBox(bbox), mParent(parent), mMailbox(0) 
    5858{ 
    5959} 
     
    217217 
    218218        //-- factors for bsp tree split plane heuristics 
    219         Environment::GetSingleton()->GetFloatValue("BvHierarchy.Termination.ct_div_ci", mCtDivCi); 
    220  
    221         //-- partition criteria 
    222         Environment::GetSingleton()->GetFloatValue("BvHierarchy.Construction.epsilon", mEpsilon); 
    223219 
    224220        // if only the driving axis is used for axis aligned split 
     
    227223        Environment::GetSingleton()->GetBoolValue("BvHierarchy.useCostHeuristics", mUseCostHeuristics); 
    228224 
    229  
    230225        char subdivisionStatsLog[100]; 
    231226        Environment::GetSingleton()->GetStringValue("BvHierarchy.subdivisionStats", subdivisionStatsLog); 
    232227        mSubdivisionStats.open(subdivisionStatsLog); 
    233228 
    234         Environment::GetSingleton()->GetFloatValue("BvHierarchy.Construction.splitBorder", mSplitBorder); 
    235229        Environment::GetSingleton()->GetFloatValue( 
    236230                "BvHierarchy.Construction.renderCostDecreaseWeight", mRenderCostDecreaseWeight); 
     
    240234 
    241235        Debug << "******* Bvh hierarchy options ******** " << endl; 
    242  
    243236    Debug << "max depth: " << mTermMaxDepth << endl; 
    244237        Debug << "min probabiliy: " << mTermMinProbability<< endl; 
     
    247240        Debug << "miss tolerance: " << mTermMissTolerance << endl; 
    248241        Debug << "max leaves: " << mTermMaxLeaves << endl; 
    249  
    250242        Debug << "randomize: " << randomize << endl; 
    251  
    252243        Debug << "min global cost ratio: " << mTermMinGlobalCostRatio << endl; 
    253244        Debug << "global cost miss tolerance: " << mTermGlobalCostMissTolerance << endl; 
     
    387378                EvalSubdivisionCandidate(*frontCandidate); 
    388379                EvalSubdivisionCandidate(*backCandidate); 
     380         
     381                // cross reference 
     382                tFrontData.mNode->SetSubdivisionCandidate(frontCandidate);  
     383                tBackData.mNode->SetSubdivisionCandidate(backCandidate); 
    389384 
    390385                tQueue.Push(frontCandidate); 
     
    397392 
    398393        //-- terminate traversal 
    399         if (newNode->IsLeaf()) 
    400         { 
     394    if (newNode->IsLeaf()) 
     395        { 
     396                //-- store additional info 
    401397                EvaluateLeafStats(tData); 
    402398         
    403                 const bool mStoreRays= true; 
    404  
    405                 //-- store additional info 
     399                const bool mStoreRays = true; 
    406400                if (mStoreRays) 
    407401                { 
     
    429423 
    430424        // cost ratio violated? 
    431         const bool maxCostRatioViolated = ratio < mTermMaxCostRatio; 
     425        const bool maxCostRatioViolated = mTermMaxCostRatio < ratio; 
    432426 
    433427        splitCandidate.mMaxCostMisses = maxCostRatioViolated ?  
    434                 splitCandidate.mParentData.mMaxCostMisses :  
    435                 splitCandidate.mParentData.mMaxCostMisses + 1; 
     428                splitCandidate.mParentData.mMaxCostMisses + 1 : 
     429                splitCandidate.mParentData.mMaxCostMisses; 
    436430 
    437431        const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
     
    451445        splitCandidate.SetRenderCostDecrease(renderCostDecr); 
    452446 
    453 #if 1 
     447#if 0 
    454448        const float priority = (float)-splitCandidate.mParentData.mDepth; 
    455449#else    
     
    520514 
    521515 
     516#if 0 
    522517float BvHierarchy::EvalLocalObjectPartition(const BvhTraversalData &tData, 
    523518                                                                                        const int axis, 
     
    535530        { 
    536531                Intersectable *obj = *oit; 
    537                 AxisAlignedBox3 box = obj->GetBox(); 
     532                const AxisAlignedBox3 box = obj->GetBox(); 
    538533 
    539534                const float objMid = (box.Max(axis) + box.Min(axis)) * 0.5f; 
     
    553548        return ratio; 
    554549} 
     550 
     551#else 
     552 
     553float BvHierarchy::EvalLocalObjectPartition(const BvhTraversalData &tData, 
     554                                                                                        const int axis, 
     555                                                                                        ObjectContainer &objectsFront, 
     556                                                                                        ObjectContainer &objectsBack) 
     557{ 
     558        SortSubdivisionCandidates(tData, axis); 
     559         
     560        vector<SortableEntry>::const_iterator cit, cit_end = mSubdivisionCandidates->end(); 
     561 
     562        int i = 0; 
     563        const int border = (int)tData.mNode->mObjects.size() / 2; 
     564 
     565    for (cit = mSubdivisionCandidates->begin(); cit != cit_end; ++ cit, ++ i) 
     566        { 
     567                Intersectable *obj = (*cit).mObject; 
     568 
     569                // object mailed => belongs to back objects 
     570                if (i < border)  
     571                        objectsBack.push_back(obj); 
     572                else 
     573                        objectsFront.push_back(obj); 
     574        } 
     575 
     576        const float oldRenderCost = tData.mProbability * (float)tData.mNode->mObjects.size(); 
     577        const float newRenderCost =  
     578                EvalRenderCost(tData, objectsFront, objectsBack); 
     579 
     580        const float ratio = newRenderCost / oldRenderCost; 
     581        return ratio; 
     582} 
     583#endif 
    555584 
    556585 
     
    719748        // mail view cells on the left side 
    720749        ViewCell::NewMail(); 
    721          
    722750        // mail the objects on the left side 
    723751        Intersectable::NewMail(); 
     
    762790                        // => add volume to left node 
    763791                        volLeft += vol; 
    764                         //volRight -= vol; 
    765792                } 
    766793 
     
    815842                { 
    816843                        if (mUseCostHeuristics) 
    817                         { 
     844                        {cout << "h"; 
    818845                                //-- partition objects using heuristics 
    819846                                nCostRatio[axis] = 
     
    825852                        } 
    826853                        else 
    827                         { 
     854                        {cout << "m"; 
    828855                                nCostRatio[axis] = 
    829856                                        EvalLocalObjectPartition( 
     
    10721099        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    10731100 
     1101        Debug << "collecting " << (int)viewCells.size() << " dirty candidates" << endl; 
    10741102        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    10751103        { 
    10761104                VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit); 
    1077  
    10781105                VspLeaf *leaf = vc->mLeaf; 
     1106                SubdivisionCandidate *candidate = leaf->GetSubdivisionCandidate(); 
     1107                 
    10791108                dirtyList.push_back(leaf->GetSubdivisionCandidate()); 
    10801109        } 
     
    11081137{ 
    11091138        // rather use the simple version 
    1110         if (object->mBvhLeaf) 
    1111         { 
    1112                 return object->mBvhLeaf; 
    1113         } 
    1114  
     1139        if (!object) return NULL; 
     1140        return object->mBvhLeaf; 
     1141         
    11151142        /////////////////////////////////////// 
    11161143        // start from root of tree 
     1144         
    11171145        if (node == NULL) 
    1118         { 
    11191146                node = mRoot; 
    1120         } 
    1121  
     1147         
    11221148        vector<BvhLeaf *> leaves; 
    11231149 
     
    11821208 
    11831209 
    1184 /* 
    1185 int BvHierarchy::UpdateViewCellsPvs(BvhLeaf *leaf,  
    1186                                                                 const RayInfoContainer &rays) const 
    1187  
    1188 { 
    1189         MailablePvsData::NewMail(); 
    1190          
    1191         ViewCellContainer touchedViewCells; 
    1192         CollectTouchedViewCells(rays, touchedViewCells); 
    1193  
    1194         ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
    1195  
    1196         for (oit = leaf->mObjects.begin(); oit < oit_end; ++ oit) 
    1197         { 
    1198                 Intersectable *obj = *oit; 
    1199                 ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 
    1200  
    1201                 // traverse through view cells and classify them according 
    1202                 // to them being seen from to back / front / front and back node 
    1203                 for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 
    1204                 { 
    1205                         ViewCell *vc = *vit; 
    1206                         float contri; 
    1207                         AddViewCellToObjectPvs(obj, vc, contri, true); 
    1208                 } 
    1209         } 
    1210  
    1211         return 0; 
    1212 } 
    1213  
    1214  
    1215 int BvHierarchy::RemoveParentViewCellsPvs(BvhLeaf *leaf,  
    1216                                                                           const RayInfoContainer &rays 
    1217                                                                           ) const 
    1218  
    1219 { 
    1220         MailablePvsData::NewMail(); 
    1221          
    1222         ViewCellContainer touchedViewCells; 
    1223         CollectTouchedViewCells(rays, touchedViewCells); 
    1224  
    1225         ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
    1226  
    1227         for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
    1228         { 
    1229                 Intersectable *obj = *oit; 
    1230  
    1231                 // traverse through view cells and classify them according 
    1232                 // to them being seen from to back / front / front and back node 
    1233         ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 
    1234  
    1235                 for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 
    1236                 { 
    1237                         ViewCell *vc = *vit; 
    1238                          
    1239                         MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 
    1240  
    1241                         if (vdata && !vdata->Mailed()) 
    1242                         { 
    1243                                 vdata->Mail(); 
    1244                                 obj->mViewCellPvs.RemoveSample(vc, 1); 
    1245                         } 
    1246                 } 
    1247         } 
    1248  
    1249         return 0; 
    1250 } 
    1251 */ 
    1252  
    12531210bool BvHierarchy::Export(OUT_STREAM &stream) 
    12541211{ 
Note: See TracChangeset for help on using the changeset viewer.