Ignore:
Timestamp:
07/10/06 01:57:41 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r1101 r1106  
    2222 
    2323#define USE_FIXEDPOINT_T 0 
    24  
     24#define COUNT_OBJECTS 1 
    2525 
    2626//-- static members 
    27  
    28 int VspTree::sFrontId = 0; 
    29 int VspTree::sBackId = 0; 
    30 int VspTree::sFrontAndBackId = 0; 
    3127 
    3228VspTree *VspTree::VspSplitCandidate::sVspTree = NULL; 
     
    379375 
    380376        Debug << "******* VSP options ******** " << endl; 
     377 
    381378    Debug << "max depth: " << mTermMaxDepth << endl; 
    382379        Debug << "min PVS: " << mTermMinPvs << endl; 
     
    399396        Debug << "minband: " << mMinBand << endl; 
    400397        Debug << "maxband: " << mMaxBand << endl; 
    401         Debug << "pvs count method: " << mPvsCountMethod << endl; 
    402  
     398 
     399        if (mPvsCountMethod == 0) 
     400                Debug << "pvs count method: per object" << endl; 
     401        else 
     402                Debug << "pvs count method: per kd node" << endl; 
    403403 
    404404        mSplitCandidates = new vector<SortableEntry>; 
     
    504504bool VspTree::LocalTerminationCriteriaMet(const VspTraversalData &data) const 
    505505{ 
    506         return 
    507 #if TODO 
    508                 (((int)data.mRays->size() <= mTermMinRays) || 
    509                  (data.mPvs <= mTermMinPvs)   || 
    510                  (data.mProbability <= mTermMinProbability) || 
    511                  (data.GetAvgRayContribution() > mTermMaxRayContribution) || 
    512                  (data.mDepth >= mTermMaxDepth)); 
    513 #else 
    514                 false; 
    515 #endif 
     506        return( 
     507                ((int)data.mRays->size() <= mTermMinRays) || 
     508                (data.mPvs <= mTermMinPvs)   || 
     509                (data.mProbability <= mTermMinProbability) || 
     510                (data.GetAvgRayContribution() > mTermMaxRayContribution) || 
     511                (data.mDepth >= mTermMaxDepth) 
     512                ); 
     513                 
    516514} 
    517515 
     
    519517bool VspTree::GlobalTerminationCriteriaMet(const VspTraversalData &data) const 
    520518{ 
    521         return 
    522 #if TODO 
    523                 (mOutOfMemory ||  
     519        return ( 
     520//              mOutOfMemory ||  
    524521                (mVspStats.Leaves() >= mMaxViewCells) ||  
    525                 (mGlobalCostMisses >= mTermGlobalCostMissTolerance)); 
    526 #else 
    527                 (mVspStats.Leaves() >= mMaxViewCells) ;          
    528 #endif 
     522        (mGlobalCostMisses >= mTermGlobalCostMissTolerance)  
     523                );               
    529524} 
    530525 
     
    729724        // and setup child links 
    730725        interior->SetupChildLinks(new VspLeaf(interior), new VspLeaf(interior)); 
     726         
    731727        // add bounding box 
    732728        interior->SetBoundingBox(tData.mBoundingBox); 
     729 
     730        // set front and back leaf 
     731        frontData.mNode = interior->GetFront(); 
     732        backData.mNode = interior->GetBack(); 
    733733 
    734734        interior->mTimeStamp = mTimeStamp ++; 
     
    915915                        node->mCounter = 1; 
    916916 
    917                         //Debug << "here5 "<<(int)node->mObjects.size() <<" "<< node->mMultipleObjects.size()<< " " <<(int)node->mObjects.size() - node->mMultipleObjects.size()<<endl; 
    918917                        // add objects without the objects which are in several kd leaves 
    919918                        pvsSize += (int)(node->mObjects.size() - node->mMultipleObjects.size()); 
     
    933932                        if (!object->Mailed()) 
    934933                        { 
    935                                 //Debug << "here233: " << object->mKdLeaves.size() << endl; 
    936934                                object->Mail(); 
    937935                                object->mCounter = 1; 
     
    13221320                sAxis = box.Size().DrivingAxis(); 
    13231321        } 
    1324         //sAxis = 2; 
     1322         
    13251323        for (int axis = 0; axis < 3; ++ axis) 
    13261324        { 
    13271325                if (!useSpecialAxis || (axis == sAxis)) 
    13281326                { 
    1329                         //-- place split plane using heuristics 
    1330  
    13311327                        if (mUseCostHeuristics) 
    13321328                        { 
     1329                                //-- place split plane using heuristics 
    13331330                                nCostRatio[axis] = 
    13341331                                        EvalLocalCostHeuristics(*tData.mRays, 
     
    13381335                                                                                        nPosition[axis]);                        
    13391336                        } 
    1340                         else //-- split plane position is spatial median 
    1341                         { 
     1337                        else 
     1338                        { 
     1339                                //-- split plane position is spatial median 
     1340 
    13421341                                nPosition[axis] = (box.Min()[axis] + box.Max()[axis]) * 0.5f; 
    13431342 
     
    25452544mTimeStamp(1) 
    25462545{ 
    2547 #if TODO 
     2546 
    25482547        bool randomize = false; 
    25492548        Environment::GetSingleton()->GetBoolValue("VspTree.Construction.randomize", randomize); 
     
    25522551 
    25532552        //-- termination criteria for autopartition 
    2554         Environment::GetSingleton()->GetIntValue("VspTree.Termination.maxDepth", mTermMaxDepth); 
    2555         Environment::GetSingleton()->GetIntValue("VspTree.Termination.minPvs", mTermMinPvs); 
    2556         Environment::GetSingleton()->GetIntValue("VspTree.Termination.minRays", mTermMinRays); 
    2557         Environment::GetSingleton()->GetFloatValue("VspTree.Termination.minProbability", mTermMinProbability); 
    2558         Environment::GetSingleton()->GetFloatValue("VspTree.Termination.maxRayContribution", mTermMaxRayContribution); 
    2559          
    2560         Environment::GetSingleton()->GetIntValue("VspTree.Termination.missTolerance", mTermMissTolerance); 
    2561         Environment::GetSingleton()->GetIntValue("VspTree.Termination.maxViewCells", mMaxViewCells); 
    2562  
     2553        Environment::GetSingleton()->GetIntValue("OspTree.Termination.maxDepth", mTermMaxDepth); 
     2554        Environment::GetSingleton()->GetIntValue("OspTree.Termination.maxLeaves", mTermMaxLeaves); 
     2555        Environment::GetSingleton()->GetIntValue("OspTree.Termination.minObjects", mTermMinObjects); 
     2556        Environment::GetSingleton()->GetFloatValue("OspTree.Termination.minProbability", mTermMinProbability); 
     2557         
     2558        Environment::GetSingleton()->GetIntValue("OspTree.Termination.missTolerance", mTermMissTolerance); 
     2559         
    25632560        //-- max cost ratio for early tree termination 
    2564         Environment::GetSingleton()->GetFloatValue("VspTree.Termination.maxCostRatio", mTermMaxCostRatio); 
    2565  
    2566         Environment::GetSingleton()->GetFloatValue("VspTree.Termination.minGlobalCostRatio", mTermMinGlobalCostRatio); 
    2567         Environment::GetSingleton()->GetIntValue("VspTree.Termination.globalCostMissTolerance", mTermGlobalCostMissTolerance); 
    2568  
    2569         // HACK//mTermMinPolygons = 25; 
     2561        Environment::GetSingleton()->GetFloatValue("OspTree.Termination.maxCostRatio", mTermMaxCostRatio); 
     2562 
     2563        Environment::GetSingleton()->GetFloatValue("OspTree.Termination.minGlobalCostRatio", mTermMinGlobalCostRatio); 
     2564        Environment::GetSingleton()->GetIntValue("OspTree.Termination.globalCostMissTolerance", mTermGlobalCostMissTolerance); 
     2565 
    25702566 
    25712567        //-- factors for bsp tree split plane heuristics 
    2572         Environment::GetSingleton()->GetFloatValue("VspTree.Termination.ct_div_ci", mCtDivCi); 
     2568        Environment::GetSingleton()->GetFloatValue("OspTree.Termination.ct_div_ci", mCtDivCi); 
    25732569 
    25742570        //-- partition criteria 
    2575         Environment::GetSingleton()->GetFloatValue("VspTree.Construction.epsilon", mEpsilon); 
     2571        Environment::GetSingleton()->GetFloatValue("OspTree.Construction.epsilon", mEpsilon); 
    25762572 
    25772573        // if only the driving axis is used for axis aligned split 
    2578         Environment::GetSingleton()->GetBoolValue("VspTree.splitUseOnlyDrivingAxis", mOnlyDrivingAxis); 
    2579          
    2580         //Environment::GetSingleton()->GetFloatValue("VspTree.maxTotalMemory", mMaxTotalMemory); 
    2581         Environment::GetSingleton()->GetFloatValue("VspTree.maxStaticMemory", mMaxMemory); 
    2582  
    2583         Environment::GetSingleton()->GetBoolValue("VspTree.useCostHeuristics", mUseCostHeuristics); 
    2584         Environment::GetSingleton()->GetBoolValue("VspTree.simulateOctree", mCirculatingAxis); 
     2574        Environment::GetSingleton()->GetBoolValue("OspTree.splitUseOnlyDrivingAxis", mOnlyDrivingAxis); 
     2575         
     2576        Environment::GetSingleton()->GetFloatValue("OspTree.maxStaticMemory", mMaxMemory); 
     2577 
     2578        Environment::GetSingleton()->GetBoolValue("OspTree.useCostHeuristics", mUseCostHeuristics); 
    25852579 
    25862580 
    25872581        char subdivisionStatsLog[100]; 
    2588         Environment::GetSingleton()->GetStringValue("VspTree.subdivisionStats", subdivisionStatsLog); 
     2582        Environment::GetSingleton()->GetStringValue("OspTree.subdivisionStats", subdivisionStatsLog); 
    25892583        mSubdivisionStats.open(subdivisionStatsLog); 
    25902584 
    2591         Environment::GetSingleton()->GetFloatValue("VspTree.Construction.minBand", mMinBand); 
    2592         Environment::GetSingleton()->GetFloatValue("VspTree.Construction.maxBand", mMaxBand); 
    2593          
    2594         mSplitBorder = 0.1f; 
     2585        Environment::GetSingleton()->GetFloatValue("OspTree.Construction.splitBorder", mSplitBorder); 
     2586        //mSplitBorder = 0.1f; 
    25952587 
    25962588 
     
    25982590 
    25992591        Debug << "******* OSP options ******** " << endl; 
     2592 
    26002593    Debug << "max depth: " << mTermMaxDepth << endl; 
    2601         Debug << "min PVS: " << mTermMinPvs << endl; 
    26022594        Debug << "min probabiliy: " << mTermMinProbability << endl; 
    2603         Debug << "min rays: " << mTermMinRays << endl; 
    2604         Debug << "max ray contri: " << mTermMaxRayContribution << endl; 
     2595        Debug << "min objects: " << mTermMinObjects << endl; 
    26052596        Debug << "max cost ratio: " << mTermMaxCostRatio << endl; 
    26062597        Debug << "miss tolerance: " << mTermMissTolerance << endl; 
    2607         Debug << "max view cells: " << mMaxViewCells << endl; 
     2598        Debug << "max leaves: " << mTermMaxLeaves << endl; 
     2599 
    26082600        Debug << "randomize: " << randomize << endl; 
    26092601 
     
    26152607        Debug << "subdivision stats log: " << subdivisionStatsLog << endl; 
    26162608         
    2617         Debug << "circulating axis: " << mCirculatingAxis << endl; 
    2618         Debug << "minband: " << mMinBand << endl; 
    2619         Debug << "maxband: " << mMaxBand << endl; 
    2620          
     2609        Debug << "split borders: " << mSplitBorder << endl; 
     2610 
    26212611 
    26222612        mSplitCandidates = new vector<SortableEntry>; 
    26232613 
    26242614        Debug << endl; 
    2625 #endif 
    26262615} 
    26272616 
     
    26302619void OspTree::SplitObjects(const AxisAlignedPlane & splitPlane, 
    26312620                                                   const ObjectContainer &objects, 
    2632                                                    ObjectContainer &back, 
    2633                                                    ObjectContainer &front) 
     2621                                                   ObjectContainer &front, 
     2622                                                   ObjectContainer &back) 
    26342623{ 
    26352624        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     
    26452634                if (box.Min(splitPlane.mAxis) < splitPlane.mPosition) 
    26462635                        back.push_back(*oit); 
    2647 #if TODO     
    2648                 mStat.objectRefs -= (int)objects.size(); 
    2649                 mStat.objectRefs += objectsBack + objectsFront; 
    2650 #endif 
    2651         } 
    2652 } 
    2653  
    2654  
    2655 KdInterior *OspTree::SubdivideNode(KdLeaf *leaf, 
     2636        } 
     2637 
     2638        mOspStats.objectRefs -= (int)objects.size(); 
     2639        mOspStats.objectRefs += (int)back.size() + (int)front.size(); 
     2640} 
     2641 
     2642 
     2643KdInterior *OspTree::SubdivideNode( 
     2644                                                                   KdLeaf *leaf, 
    26562645                                                                   const AxisAlignedPlane &splitPlane, 
    26572646                                                                   const AxisAlignedBox3 &box, 
    2658                                                                    AxisAlignedBox3 &backBBox, 
    2659                                                                    AxisAlignedBox3 &frontBBox) 
    2660 { 
    2661 #if TODO 
    2662     mSpatialStat.nodes += 2; 
    2663         mSpatialStat.splits[axis]; 
    2664 #endif 
     2647                                                                   OspTraversalData &frontData, 
     2648                                                                   OspTraversalData &backData 
     2649                                                                   ) 
     2650{ 
     2651    mOspStats.nodes += 2; 
    26652652 
    26662653        // add the new nodes to the tree 
     
    26742661        node->mBox = box; 
    26752662 
    2676     backBBox = box; 
    2677         frontBBox = box; 
     2663        backData.mBoundingBox = box; 
     2664        frontData.mBoundingBox = box; 
    26782665   
    26792666        // first count ray sides 
     
    26812668        int objectsFront = 0; 
    26822669   
    2683         backBBox.SetMax(axis, position); 
    2684         frontBBox.SetMin(axis, position); 
     2670        backData.mBoundingBox.SetMax(axis, position); 
     2671        frontData.mBoundingBox.SetMin(axis, position); 
    26852672 
    26862673        ObjectContainer::const_iterator mi, mi_end = leaf->mObjects.end(); 
     
    27012688        KdLeaf *front = new KdLeaf(node, objectsFront); 
    27022689 
     2690        ///////////// 
     2691        //-- create front and back leaf 
     2692 
     2693        KdInterior *parent = leaf->mParent; 
     2694 
    27032695        // replace a link from node's parent 
    2704         if (leaf->mParent) 
    2705                 leaf->mParent->ReplaceChildLink(leaf, node); 
     2696        if (parent) 
     2697        { 
     2698                parent->ReplaceChildLink(leaf, node); 
     2699                node->mParent = parent; 
     2700        } 
     2701        else // new root 
     2702        { 
     2703                mRoot = node; 
     2704        } 
    27062705 
    27072706        // and setup child links 
    27082707        node->SetupChildLinks(back, front); 
    27092708 
    2710         SplitObjects(splitPlane, leaf->mObjects, back->mObjects, front->mObjects); 
     2709        SplitObjects(splitPlane, leaf->mObjects, front->mObjects, back->mObjects); 
    27112710 
    27122711        ProcessLeafObjects(back, leaf); 
    27132712    ProcessLeafObjects(front, leaf); 
    27142713   
     2714        backData.mNode = back; 
     2715        frontData.mNode = front; 
     2716 
    27152717        //delete leaf; 
    27162718        return node; 
     
    27212723                                                   OspSplitCandidate &splitCandidate, 
    27222724                                                   const bool globalCriteriaMet) 
    2723 { 
     2725{Debug << "here11" << endl; 
    27242726        OspTraversalData &tData = splitCandidate.mParentData; 
    2725  
     2727Debug << "here993" << endl; 
    27262728        KdNode *newNode = tData.mNode; 
    27272729 
     2730Debug << "here996" << endl; 
    27282731        if (!LocalTerminationCriteriaMet(tData) && !globalCriteriaMet) 
    27292732        {        
    27302733                OspTraversalData tFrontData; 
    27312734                OspTraversalData tBackData; 
    2732  
     2735Debug << "here3" << endl; 
    27332736                //-- continue subdivision 
    27342737                 
     
    27392742                                                                splitPlane,  
    27402743                                                                tData.mBoundingBox,  
    2741                                                                 tFrontData.mBoundingBox,  
    2742                                                                 tBackData.mBoundingBox); 
     2744                                                                tFrontData,  
     2745                                                                tBackData); 
    27432746         
    27442747                const int maxCostMisses = splitCandidate.mMaxCostMisses; 
     
    27522755                OspSplitCandidate *backCandidate = new OspSplitCandidate(tBackData); 
    27532756 
     2757                Debug << "here 54 " << tFrontData.mNode << " " <<  tBackData.mNode << endl; 
     2758 
    27542759                EvalSplitCandidate(*frontCandidate); 
    27552760                EvalSplitCandidate(*backCandidate); 
     
    27662771        if (newNode->IsLeaf()) 
    27672772        { 
    2768                 //KdLeaf *leaf = dynamic_cast<KdLeaf *>(newNode); 
    27692773                EvaluateLeafStats(tData);                
    27702774        } 
    2771  
     2775        Debug << "here888 "<< endl; 
    27722776        //-- cleanup 
    27732777        tData.Clear(); 
    2774          
     2778        Debug << "here876"<< endl; 
    27752779        return newNode; 
    27762780} 
     
    27822786        float backProb; 
    27832787         
    2784         KdLeaf *leaf = dynamic_cast<KdLeaf *>(splitCandidate.mParentData.mNode); 
    2785  
    27862788        // compute locally best split plane 
    27872789        const bool success =  
    27882790                SelectSplitPlane(splitCandidate.mParentData, splitCandidate.mSplitPlane, frontProb, backProb); 
    27892791 
    2790         //TODO 
     2792        const float priority = EvalRenderCostDecrease(splitCandidate.mSplitPlane, splitCandidate.mParentData); 
    27912793        // compute global decrease in render cost 
    2792         splitCandidate.SetPriority(EvalRenderCostDecrease(splitCandidate.mSplitPlane, splitCandidate.mParentData)); 
    2793         splitCandidate.mMaxCostMisses = success ? splitCandidate.mParentData.mMaxCostMisses : splitCandidate.mParentData.mMaxCostMisses + 1; 
     2794        splitCandidate.SetPriority(priority); 
     2795 
     2796        splitCandidate.mMaxCostMisses =  
     2797                success ? splitCandidate.mParentData.mMaxCostMisses : splitCandidate.mParentData.mMaxCostMisses + 1; 
    27942798} 
    27952799 
     
    27982802{ 
    27992803        // matt: TODO 
    2800         return true; 
    2801     /*          (((int)data.mRays->size() <= mTermMinRays) || 
    2802                  (data.mPvs <= mTermMinPvs)   || 
    2803                  (data.mProbability <= mTermMinProbability) || 
    2804                  (data.GetAvgRayContribution() > mTermMaxRayContribution) || 
    2805                  (data.mDepth >= mTermMaxDepth));*/ 
     2804        return (  
     2805                //(data.mNode->mObjects.size() < mTermMinObjects) || 
     2806                //(data.mProbability <= mTermMinProbability) || 
     2807                (data.mDepth >= mTermMaxDepth) 
     2808                 ); 
    28062809} 
    28072810 
     
    28102813{ 
    28112814        // matt: TODO 
    2812         return true; 
    2813                 /*(mOutOfMemory ||  
    2814                 (mVspStats.Leaves() >= mMaxViewCells) ||  
    2815                 (mGlobalCostMisses >= mTermGlobalCostMissTolerance));*/ 
     2815        Debug << "here888 " << mTermMaxLeaves << " " << mOspStats.Leaves() << endl; 
     2816        return ( 
     2817                (mOspStats.Leaves() >= mTermMaxLeaves) 
     2818                //mOutOfMemory ||  
     2819                //(mGlobalCostMisses >= mTermGlobalCostMissTolerance) 
     2820                ); 
    28162821} 
    28172822 
     
    28192824void OspTree::EvaluateLeafStats(const OspTraversalData &data) 
    28202825{ 
    2821 #if TODO 
    28222826        // the node became a leaf -> evaluate stats for leafs 
    2823         VspLeaf *leaf = dynamic_cast<VspLeaf *>(data.mNode); 
    2824  
    2825         if (data.mPvs > mVspStats.maxPvs) 
    2826         { 
    2827                 mVspStats.maxPvs = data.mPvs; 
    2828         } 
    2829  
    2830         mVspStats.pvs += data.mPvs; 
    2831  
    2832         if (data.mDepth < mVspStats.minDepth) 
    2833         { 
    2834                 mVspStats.minDepth = data.mDepth; 
     2827        KdLeaf *leaf = data.mNode; 
     2828 
     2829        if (data.mPvs > mOspStats.maxPvs) 
     2830        { 
     2831                mOspStats.maxPvs = data.mPvs; 
     2832        } 
     2833 
     2834        mOspStats.pvs += data.mPvs; 
     2835 
     2836        if (data.mDepth < mOspStats.minDepth) 
     2837        { 
     2838                mOspStats.minDepth = data.mDepth; 
    28352839        } 
    28362840         
    28372841        if (data.mDepth >= mTermMaxDepth) 
    28382842        { 
    2839         ++ mVspStats.maxDepthNodes; 
     2843        ++ mOspStats.maxDepthNodes; 
    28402844                //Debug << "new max depth: " << mVspStats.maxDepthNodes << endl; 
    28412845        } 
    28422846 
    2843         // accumulate rays to compute rays /  leaf 
    2844         mVspStats.accumRays += (int)data.mRays->size(); 
    2845  
    2846         if (data.mPvs < mTermMinPvs) 
    2847                 ++ mVspStats.minPvsNodes; 
    2848  
    2849         if ((int)data.mRays->size() < mTermMinRays) 
    2850                 ++ mVspStats.minRaysNodes; 
    2851  
    2852         if (data.GetAvgRayContribution() > mTermMaxRayContribution) 
    2853                 ++ mVspStats.maxRayContribNodes; 
     2847//      if (data.mPvs < mTermMinPvs) 
     2848//              ++ mOspStats.minPvsNodes; 
    28542849 
    28552850        if (data.mProbability <= mTermMinProbability) 
    2856                 ++ mVspStats.minProbabilityNodes; 
     2851                ++ mOspStats.minProbabilityNodes; 
    28572852         
    28582853        // accumulate depth to compute average depth 
    2859         mVspStats.accumDepth += data.mDepth; 
    2860  
    2861         ++ mCreatedViewCells; 
     2854        mOspStats.accumDepth += data.mDepth; 
     2855 
     2856        ++ mCreatedLeaves; 
    28622857 
    28632858#ifdef _DEBUG 
    28642859        Debug << "BSP stats: " 
    28652860                  << "Depth: " << data.mDepth << " (max: " << mTermMaxDepth << "), " 
    2866                   << "PVS: " << data.mPvs << " (min: " << mTermMinPvs << "), " 
    2867                   << "Area: " << data.mProbability << " (min: " << mTermMinProbability << "), " 
    2868                   << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMinRays << "), " 
    2869                   << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "), " 
    2870                   << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 
    2871 #endif 
    2872  
     2861                 // << "PVS: " << data.mPvs << " (min: " << mTermMinPvs << "), " 
     2862                  << "Prob: " << data.mProbability << " (min: " << mTermMinProbability << "), " 
     2863                  << "#pvs: " << data.mPvs << ")\n"; 
    28732864#endif 
    28742865} 
     
    28792870                                                                           const int axis, 
    28802871                                                                           float &position, 
    2881                                                                            int &objectsBack, 
    2882                                                                            int &objectsFront) 
     2872                                                                           int &objectsFront, 
     2873                                                                           int &objectsBack) 
    28832874{ 
    28842875         
     
    28892880        // C = ct_div_ci  + (ol + or)/queries 
    28902881         
    2891         int pvsSize = PrepareHeuristics(node->mObjects);; 
     2882        int pvsSize = PrepareHeuristics(node->mObjects); 
    28922883        int pvsl = 0, pvsr = pvsSize; 
    28932884   
     
    30093000int OspTree::PrepareHeuristics(Intersectable *object) 
    30103001{ 
     3002#if COUNT_OBJECTS 
     3003        return 1; 
     3004#else 
    30113005        ViewCellPvsMap::const_iterator vit, vit_end = object->mViewCellPvs.mEntries.end(); 
    30123006         
     
    30303024 
    30313025        return pvsSize; 
     3026#endif 
    30323027} 
    30333028 
     
    30733068 
    30743069 
     3070void OspTree::SetViewCellsManager(ViewCellsManager *vcm) 
     3071{ 
     3072        mViewCellsManager = vcm; 
     3073} 
     3074 
     3075 
     3076AxisAlignedBox3 OspTree::GetBoundingBox() const 
     3077{ 
     3078        return mBoundingBox; 
     3079} 
     3080 
     3081 
    30753082void OspTree::RemoveContriFromPvs(Intersectable *object, int &pvs) const 
    30763083{ 
     3084#if COUNT_OBJECTS 
     3085        -- pvs; 
     3086#else 
    30773087        ViewCellPvsMap::const_iterator vit, vit_end = object->mViewCellPvs.mEntries.end(); 
    30783088         
     
    30863096                } 
    30873097        } 
     3098#endif 
    30883099} 
    30893100 
     
    30933104        ViewCellPvsMap::const_iterator vit, vit_end = object->mViewCellPvs.mEntries.end(); 
    30943105 
     3106#if COUNT_OBJECTS 
     3107        ++ pvs; 
     3108#else 
    30953109        for (vit = object->mViewCellPvs.mEntries.begin(); vit != vit_end; ++ vit) 
    30963110        { 
     
    31033117                } 
    31043118        } 
     3119#endif 
    31053120} 
    31063121 
     
    31273142        } 
    31283143 
    3129 /* 
    3130         //sAxis = 2; 
     3144        // -- evaluate split cost for all three axis 
    31313145        for (int axis = 0; axis < 3; ++ axis) 
    31323146        { 
    31333147                if (!mOnlyDrivingAxis || (axis == sAxis)) 
    31343148                { 
    3135                         //-- place split plane using heuristics 
    3136  
    3137                         if (mUseCostHeuristics) 
    3138                         { 
     3149                        if (1 || mUseCostHeuristics) 
     3150                        { 
     3151                                //-- place split plane using heuristics 
     3152                                int objectsFront, objectsBack; 
     3153 
    31393154                                nCostRatio[axis] = 
    3140                                         EvalLocalCostHeuristics(*tData.mRays, 
    3141                                                                                         box, 
    3142                                                                                         tData.mPvs, 
    3143                                                                                         axis, 
    3144                                                                                         nPosition[axis]);                        
    3145                         } 
    3146                         else //-- split plane position is spatial median 
    3147                         { 
     3155                                        EvalLocalCostHeuristics(tData.mNode, 
     3156                                                                           tData.mBoundingBox, 
     3157                                                                           axis, 
     3158                                                                           nPosition[axis], 
     3159                                                                           objectsFront, 
     3160                                                                           objectsBack);                         
     3161                        } 
     3162                        /*      else  
     3163                        { 
     3164                                //-- split plane position is spatial median 
     3165 
    31483166                                nPosition[axis] = (box.Min()[axis] + box.Max()[axis]) * 0.5f; 
    31493167 
     
    31543172                                                                                                          nProbFront[axis],  
    31553173                                                                                                          nProbBack[axis]); 
    3156                         } 
     3174                        }*/ 
    31573175                                                 
    31583176                        if (bestAxis == -1) 
     
    31673185        } 
    31683186 
    3169 */ 
    31703187        //-- assign values 
    3171          
     3188 
    31723189        plane.mAxis = bestAxis; 
    31733190        // split plane position 
     
    31843201float OspTree::EvalViewCellPvsIncr(Intersectable *object) const 
    31853202{ 
    3186         return 0; 
     3203        // TODO          
     3204        return 1; 
    31873205} 
    31883206 
     
    32063224 
    32073225        Intersectable::NewMail(); 
     3226        KdLeaf::NewMail(); 
    32083227        ViewCell::NewMail(); 
    32093228 
    3210         KdLeaf *leaf = dynamic_cast<KdLeaf *>(data.mNode); 
     3229        KdLeaf *leaf = data.mNode; 
    32113230        ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
    32123231 
     
    32523271 
    32533272        const float normalizedOldRenderCost = oldRenderCost / mBoundingBox.GetVolume(); 
     3273 
    32543274        return factor * renderCostDecrease + (1.0f - factor) * normalizedOldRenderCost; 
    32553275} 
     
    33153335 
    33163336 
    3317  
    3318 /*********************************************************************/ 
    3319 /*                class HierarchyManager implementation              */ 
    3320 /*********************************************************************/ 
     3337void OspTree::CollectLeaves(vector<KdLeaf *> &leaves) const 
     3338{ 
     3339        stack<KdNode *> nodeStack; 
     3340        nodeStack.push(mRoot); 
     3341 
     3342        while (!nodeStack.empty())  
     3343        { 
     3344                KdNode *node = nodeStack.top(); 
     3345                nodeStack.pop(); 
     3346                if (node->IsLeaf())  
     3347                { 
     3348                        KdLeaf *leaf = (KdLeaf *)node; 
     3349                        leaves.push_back(leaf); 
     3350                } 
     3351                else  
     3352                { 
     3353                        KdInterior *interior = (KdInterior *)node; 
     3354                        nodeStack.push(interior->mBack); 
     3355                        nodeStack.push(interior->mFront); 
     3356                } 
     3357        } 
     3358} 
     3359 
     3360 
     3361AxisAlignedBox3 OspTree::GetBBox(KdNode *node) const 
     3362{ 
     3363        if (!node->mParent) 
     3364                return mBoundingBox; 
     3365 
     3366        if (!node->IsLeaf()) 
     3367        { 
     3368                return (dynamic_cast<KdInterior *>(node))->mBox;                 
     3369        } 
     3370 
     3371        KdInterior *parent = dynamic_cast<KdInterior *>(node->mParent); 
     3372 
     3373        AxisAlignedBox3 box(parent->mBox); 
     3374 
     3375        if (parent->mFront == node) 
     3376                box.SetMin(parent->mAxis, parent->mPosition); 
     3377    else 
     3378                box.SetMax(parent->mAxis, parent->mPosition); 
     3379 
     3380        return box; 
     3381} 
     3382 
     3383 
     3384/********************************************************************/ 
     3385/*               class HierarchyManager implementation              */ 
     3386/********************************************************************/ 
    33213387 
    33223388 
     
    33303396SplitCandidate *HierarchyManager::NextSplitCandidate() 
    33313397{ 
    3332         SplitCandidate *splitCandidate = static_cast<SplitCandidate *>(mTQueue.Top()); 
    3333         //Debug << "priority: " << splitCandidate->GetPriority() << endl; 
     3398        SplitCandidate *splitCandidate = mTQueue.Top(); 
     3399 
     3400        Debug << "next candidate: " << splitCandidate->Type() 
     3401                << ", priority: " << splitCandidate->GetPriority() << endl; 
     3402 
    33343403        mTQueue.Pop(); 
    33353404 
     
    34153484 
    34163485        // first osp traversal data 
    3417         OspTree::OspTraversalData oData(mOspTree.mRoot, 
     3486        OspTree::OspTraversalData oData(leaf, 
    34183487                                                                        0, 
    3419                                                                         &rays, 
    34203488                                                                        pvsSize, 
    34213489                                                                        prop, 
     
    34553523 
    34563524void HierarchyManager::Construct2(const VssRayContainer &sampleRays, 
    3457                                                                  const ObjectContainer &objects, 
    3458                                                                  AxisAlignedBox3 *forcedViewSpace) 
     3525                                                                  const ObjectContainer &objects, 
     3526                                                                  AxisAlignedBox3 *forcedViewSpace) 
    34593527{ 
    34603528        RayInfoContainer *rays = new RayInfoContainer(); 
     
    34933561 
    34943562        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    3495  
    34963563 
    34973564        const int pvsSize = mVspTree.ComputePvsSize(*rays); 
     
    35493616 
    35503617        cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; 
    3551  
    35523618        mVspTree.mVspStats.Stop(); 
    3553  
    3554  
     3619         
     3620        Debug << "object space" << endl; 
    35553621 
    35563622        //-- object space partition 
     
    35663632 
    35673633        //-- first osp traversal data 
    3568         OspTree::OspTraversalData oData(mOspTree.mRoot, 
     3634        OspTree::OspTraversalData oData(leaf, 
    35693635                                                                        0, 
    3570                                                                         rays, 
    35713636                                                                        pvsSize, 
    35723637                                                                        prop, 
     
    35803645    mOspTree.EvalSplitCandidate(*oSplitCandidate); 
    35813646 
    3582         mTQueue.Push(splitCandidate); 
     3647        mTQueue.Push(oSplitCandidate); 
    35833648 
    35843649        i = 0; 
     
    35903655                        GlobalTerminationCriteriaMet(splitCandidate); 
    35913656 
    3592                 cout << "view cells: " << i ++ << endl; 
     3657                cout << "kd nodes: " << i ++ << endl; 
    35933658 
    35943659                // cost ratio of cost decrease / totalCost 
     
    36093674                DEL_PTR(splitCandidate); 
    36103675        } 
    3611  
     3676         
    36123677        cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; 
    36133678} 
Note: See TracChangeset for help on using the changeset viewer.