Changeset 1184


Ignore:
Timestamp:
08/07/06 10:40:43 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/Preprocessor.vcproj

    r1163 r1184  
    459459                        </File> 
    460460                        <File 
    461                                 RelativePath="..\src\VssRay.cpp"> 
    462                         </File> 
    463                         <File 
    464461                                RelativePath="..\src\VssRay.h"> 
    465462                        </File> 
     
    538535                        <File 
    539536                                RelativePath="..\src\Renderer.h"> 
     537                        </File> 
     538                        <File 
     539                                RelativePath="..\src\VssRay.cpp"> 
    540540                        </File> 
    541541                </Filter> 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BoostPreprocessorThread.cpp

    r1166 r1184  
    2929                // camera.LookAtBox(mPreprocessor->mKdTree->GetBox()); 
    3030                //      camera.LookInBox(mPreprocessor->mKdTree->GetBox()); 
    31                 camera.SetPosition(Vector3(3473, 6.778, -1699)); 
    32                 camera.SetDirection(Vector3(-0.2432, 0, 0.97)); 
     31                camera.SetPosition(Vector3(3473, 6.778f, -1699.0f)); 
     32                camera.SetDirection(Vector3(-0.2432f, 0, 0.97f)); 
    3333                //      camera.SetPosition(Vector3(991.7, 187.8, -271)); 
    3434                //      camera.SetDirection(Vector3(0.9, 0, -0.4)); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Containers.h

    r1072 r1184  
    1717class Ray; 
    1818class Mesh; 
     19class KdLeaf; 
    1920 
    2021struct IndexedBoundingBox; 
     
    5556typedef vector<IndexedBoundingBox> IndexedBoundingBoxContainer; 
    5657 
     58/** Container for ViewCell pointers primarily for the use within the kDTree and 
     59    BSP hierarchies */ 
     60 
     61typedef vector<KdLeaf *> KdLeafContainer; 
     62 
     63 
    5764typedef std::map<int, Intersectable *> ObjectMap; 
    5865 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h

    r1176 r1184  
    55#include "Pvs.h" 
    66#include <set> 
     7#include "VssRay.h" 
    78 
    89namespace GtpVisibilityPreprocessor { 
     
    3334  /// kd leaves that this intersectable belongs to 
    3435  //set<KdLeaf *> mKdLeaves; 
    35  
     36VssRayContainer mVssRays; 
    3637  /// # of object references 
    3738  int mReferences; 
     
    5051        int GetId() { return mId; } 
    5152         
     53//////////////////////////////////////////////// 
     54//      Mailing stuff 
    5255 
    5356        static void NewMail(const int reserve = 1) { 
     
    6467        int IncMail() { return ++ mMailbox - sMailId; } 
    6568 
    66  
     69//////////////////////////////////////////////////// 
    6770    virtual AxisAlignedBox3 GetBox() const = 0; 
    6871        virtual int CastRay(GtpVisibilityPreprocessor::Ray &ray) = 0; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r1176 r1184  
    370370    rayRefs/(double)Leaves() << "\n"; 
    371371 
    372   app << "#N_MAXOBJECTREFS  ( Max number of rayRefs / leaf )\n" << 
     372  app << "#N_MAXOBJECTREFS  ( Max number of object refs / leaf )\n" << 
    373373    maxObjectRefs << "\n"; 
    374374 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h

    r1176 r1184  
    1010#include "Pvs.h" 
    1111#include "Viewcell.h" 
     12#include "VssRay.h" 
     13 
    1214 
    1315namespace GtpVisibilityPreprocessor { 
     
    216218  KdViewCell *mViewCell; 
    217219 
     220  VssRayContainer mVssRays; 
     221 
    218222   /// Objects that are referenced in more than one leaf. 
    219223  ObjectContainer mMultipleObjects; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp

    r1176 r1184  
    4747 
    4848                                // already processed node (= objects in pvs)? 
    49                                 if (!node->Mailed()) 
     49                                if (0 ||!node->Mailed()) 
    5050                                { 
    5151                                        node->Mail(); 
     
    5454                                        { 
    5555                                                KdLeaf *leaf = dynamic_cast<KdLeaf *>(node); 
    56                          
     56#if 1                         
    5757                                                // add #objects exclusivly in this node 
    5858                                                pvs += (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size()); 
     
    7272                                                        } 
    7373                                                } 
     74#else    
     75                                                ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     76                                                 
     77                                                for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
     78                                                { 
     79                                                        Intersectable *object = *oit;                                            
     80                             
     81                                                        if (!object->Mailed()) 
     82                                                        { 
     83                                                                object->Mail(); 
     84                                                                ++ pvs; 
     85                                                        } 
     86                                                } 
     87#endif 
    7488                                        } 
    7589                                        else // traverse tree 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h

    r1168 r1184  
    2828template<typename T>  
    2929struct PvsData { 
    30   //  int mVisibleSamples; 
     30//////////////////////////// 
     31//  Mailing stuff 
     32protected: 
     33        int mMailbox; 
     34 
     35public: 
     36  // last mail id -> warning not thread safe! 
     37  // both mailId and mailbox should be unique for each thread!!! 
     38  static int sMailId; 
     39  static int sReservedMailboxes; 
     40   
     41   
     42        static void NewMail(const int reserve = 1) { 
     43                sMailId += sReservedMailboxes; 
     44                sReservedMailboxes = reserve; 
     45        } 
     46         
     47        void Mail() { mMailbox = sMailId; } 
     48        bool Mailed() const { return mMailbox == sMailId; } 
     49 
     50        void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 
     51        bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 
     52 
     53        int IncMail() { return ++ mMailbox - sMailId; } 
     54////////////////////////////////////////// 
     55 
    3156  // sum of probability density of visible sample rays 
    3257  float mSumPdf; 
     58 
    3359  PvsData<T>() {} 
    3460  PvsData<T>(const float sumPdf): 
     
    3763  // $$JB in order to return meaningfull values 
    3864  // it assumes that the sum pdf has been normalized somehow!!! 
    39   float GetVisibility() { return mSumPdf; } 
     65  float GetVisibility()  
     66  {  
     67          return mSumPdf;  
     68  } 
    4069}; 
     70 
     71template<typename T> int PvsData<T>::sMailId = 1; 
     72template<typename T> int PvsData<T>::sReservedMailboxes = 1; 
    4173 
    4274/** Template class representing the Potentially Visible Set (PVS)  
     
    89121  float AddSample(T sample, const float pdf); 
    90122   
     123  /** Adds sample to PVS. 
     124          @returns PvsData 
     125  */ 
     126  PvsData<T> *AddSample2(T sample, const float pdf); 
     127 
    91128  /** Adds one pvs to another one. 
    92129          @returns new pvs size 
     
    291328 
    292329template <typename T> 
     330PvsData<T> * 
     331Pvs<T>::AddSample2(T sample, const float pdf) 
     332{ 
     333  PvsData<T> *data = Find(sample); 
     334   
     335  if (data)  { 
     336        data->mSumPdf += pdf; 
     337  } 
     338  else { 
     339        mEntries[sample] = PvsData<T>(pdf); 
     340        data = Find(sample); 
     341  } 
     342  return data; 
     343} 
     344 
     345template <typename T> 
    293346bool 
    294347Pvs<T>::AddSample(T sample, 
     
    437490typedef PvsData<KdNode *> KdPvsData; 
    438491 
    439 //typedef Pvs<Intersectable *> ObjectPvs; 
    440492typedef Pvs<ViewCell *> ViewCellPvs; 
     493typedef PvsData<ViewCell *> ViewCellPvsData; 
     494 
    441495} 
    442496 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1180 r1184  
    18891889                                                                                                                   ray.mPdf, 
    18901890                                                                                                                   contribution)) 
     1891                          { 
    18911892                                ++ ray.mPvsContribution; 
    1892                           ray.mRelativePvsContribution += contribution; 
     1893                                  ray.mRelativePvsContribution += contribution; 
     1894                          } 
    18931895                        } 
    18941896                        // for directional sampling it is important to count only contributions 
     
    48104812        mOspTree->SetViewCellsManager(this); 
    48114813 
    4812         mVspTree->mViewCellsTree = mViewCellsTree; 
     4814        mVspTree->SetViewCellsTree(mViewCellsTree); 
    48134815} 
    48144816 
     
    57265728} 
    57275729 
    5728 #if 1 
     5730#if TEST_EVALUATION 
    57295731void VspOspViewCellsManager::EvalViewCellPartition() 
    57305732{ 
    5731         int samplesPerPass; 
    5732         int numSamples; 
    57335733        int castSamples = (int)storedRays.size(); 
    57345734 
     
    57465746                 
    57475747        const bool startFromZero = true; 
     5748 
    57485749 
    57495750        // reset pvs and start over from zero 
     
    57875788        string fileName = string(statsPrefix) + string(s); 
    57885789 
     5790        ViewCellContainer leaves; 
     5791 
     5792        mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves); 
     5793float rc = 0; 
     5794        ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 
     5795        for (vit = leaves.begin(); vit != vit_end; ++ vit) 
     5796        { 
     5797                ViewCell *vc = *vit; 
     5798 
     5799                int pvs = vc->GetPvs().CountObjectsInPvs(); 
     5800                float vol = vc->GetVolume(); 
     5801                rc += pvs * vol; 
     5802 
     5803        } 
     5804         
     5805        Debug << "here295 " << rc / mVspTree->GetBoundingBox().GetVolume(); 
     5806 
    57895807        mViewCellsTree->ExportStats(fileName); 
    57905808         
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1180 r1184  
    954954}; 
    955955 
     956#define TEST_EVALUATION 1 
    956957 
    957958/** 
     
    10121013protected: 
    10131014 
    1014 #if 1 
     1015#if TEST_EVALUATION 
    10151016        virtual void EvalViewCellPartition(); 
    10161017#endif 
     
    10371038        /** Exports visualization of the PVS. 
    10381039        */ 
    1039         void ExportPvs(const ObjectContainer &objects, 
     1040        void ExportPvs( 
     1041                const ObjectContainer &objects, 
    10401042                const VssRayContainer &rays); 
    10411043 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp

    r1181 r1184  
    102102        //app << "#N_PVS: " << pvs << endl; 
    103103 
     104        //app << "#N_MAXOBJECTREFS  ( Max number of object refs / leaf )\n" << maxObjectRefs << "\n"; 
     105 
    104106        app << "========== END OF VspTree statistics ==========\n"; 
    105107} 
     
    134136                << minPvsNodes * 100 / (double)Leaves() << endl; 
    135137 
    136         //app << "#N_PMINRAYSLEAVES  ( Percentage of leaves with minimal number of rays)\n"  
    137         //      << minRaysNodes * 100 / (double)Leaves() << endl; 
     138        //app << "#N_PMINOBJECTREFLEAVES  ( Percentage of leaves with minimal number of object ref)\n"  
     139                //<< minObjectNodes * 100 / (double)Leaves() << endl; 
    138140 
    139141        app << "#N_MAXCOSTNODES  ( Percentage of leaves with terminated because of max cost ratio )\n" 
     
    143145                << minProbabilityNodes * 100 / (double)Leaves() << endl; 
    144146 
    145 //      app << "#N_PMAXRAYCONTRIBLEAVES  ( Percentage of leaves with maximal ray contribution )\n"  
    146 //              <<      maxRayContribNodes * 100 / (double)Leaves() << endl; 
    147  
    148147        app << "#N_PMAXDEPTH ( Maximal reached depth )\n" << maxDepth << endl; 
    149148 
     
    153152 
    154153        app << "#N_INVALIDLEAVES (number of invalid leaves )\n" << invalidLeaves << endl; 
     154 
     155        app << "#N_MAXOBJECTREFS  ( Max number of object refs / leaf )\n" << 
     156                 maxObjectRefs << "\n"; 
    155157 
    156158//      app << "#N_RAYS (number of rays / leaf)\n" << AvgRays() << endl; 
     
    632634        } 
    633635                 
    634         // 
     636        // set view cell values 
    635637        viewCell->mLeaf = leaf; 
    636638 
     
    734736                        { 
    735737                                (*it).mRay->Ref();                       
    736                                 dynamic_cast<VspLeaf *>(newNode)->mVssRays.push_back((*it).mRay); 
     738                                leaf->mVssRays.push_back((*it).mRay); 
    737739                        } 
    738740                } 
     
    933935bool VspTree::AddKdLeafToPvs(KdLeaf *leaf,  
    934936                                                         ViewCell *vc,  
    935                                                          float &pdf,  
     937                                                         const float pdf,  
    936938                                                         float &contribution) 
    937939{ 
     
    948950#else // add all objects of kd node 
    949951 
    950         pdf = 0; 
    951952        contribution = 0; 
    952953 
     
    957958                Intersectable *object = *it;                                             
    958959 
    959                 float newpdf; 
    960960                float newcontri; 
    961961                                                 
    962                 if (vc->AddPvsSample(object, newpdf, newcontri)) 
     962                if (vc->AddPvsSample(object, pdf, newcontri)) 
    963963                { 
    964964                        contri = true; 
    965965                } 
    966966 
    967                 pdf += newPdf; 
     967                //pdf += newPdf; 
    968968                newContri += contribution; 
    969969        } 
     
    23792379        stack<LineTraversalData> tStack; 
    23802380 
    2381         Intersectable::NewMail(); 
     2381        //Intersectable::NewMail(); 
    23822382        //ViewCell::NewMail(); 
    23832383 
     
    29132913void VspTree::GetViewCells(const VssRay &ray, ViewCellContainer &viewCells) 
    29142914{ 
     2915        static Ray hray; 
     2916        hray.Init(ray); 
     2917        //hray.mFlags |= Ray::CULL_BACKFACES; 
     2918        //Ray hray(ray); 
     2919 
     2920        float tmin = 0, tmax = 1.0; 
     2921 
     2922        if (!mBoundingBox.GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 
     2923                return; 
     2924 
     2925        const Vector3 origin = hray.Extrap(tmin); 
     2926        const Vector3 termination = hray.Extrap(tmax); 
     2927 
    29152928        // if no precomputation of view cells 
    2916         CastLineSegment(ray.mOrigin, ray.mTermination, viewCells); 
     2929        CastLineSegment(origin, termination, viewCells); 
    29172930} 
    29182931 
     
    31173130 
    31183131        //-- classify objects 
     3132 
    31193133        int objectsBack = 0; 
    31203134        int objectsFront = 0; 
    31213135 
    3122         ObjectContainer::const_iterator mi, mi_end = leaf->mObjects.end(); 
     3136    ObjectContainer::const_iterator mi, mi_end = leaf->mObjects.end(); 
    31233137 
    31243138        for ( mi = leaf->mObjects.begin(); mi != mi_end; ++ mi)  
     
    31273141                const AxisAlignedBox3 box = (*mi)->GetBox(); 
    31283142                 
    3129                 if (box.Max(axis) > position + mEpsilon)  
     3143                if (box.Max(axis) >= position)  
    31303144                        ++ objectsFront; 
    31313145     
    3132                 if (box.Min(axis) < position - mEpsilon) 
     3146                if (box.Min(axis) < position) 
    31333147                        ++ objectsBack; 
    31343148        } 
     3149 
    31353150 
    31363151        // TODO matt: compute pvs 
     
    31383153        backData.mPvs = objectsBack; 
    31393154 
     3155        //CheckViewCellsPvs(leaf, *tData.mRays); 
     3156        RemoveParentViewCellsPvs(leaf, *tData.mRays); 
     3157 
     3158 
    31403159        KdLeaf *back = new KdLeaf(node, objectsBack); 
    31413160        KdLeaf *front = new KdLeaf(node, objectsFront); 
    31423161 
     3162         
    31433163        ///////////// 
    31443164        //-- create front and back leaf 
     
    31613181 
    31623182        SplitObjects(leaf, splitPlane, leaf->mObjects, front->mObjects, back->mObjects); 
     3183 
     3184 
     3185        //-- eval view cells pvs 
     3186         
     3187        // remove parent pvs update pvs of left and right leaves 
     3188        // Note: It is necessary to update first left and then right pvs. 
     3189        // We need to store the view cells seen by each object, 
     3190        // but also if the view cells are seen as part of two different 
     3191        // kd leaves, which is stored in the pdf component of the pvs entry.  
     3192        // Because if an object is part of a view cell more than once, 
     3193        // it cannot be removed from the pvs by splitting a kd node where 
     3194        // the view cell sees only the other child of the node. 
     3195        // This is important during the subdivision 
     3196 
     3197//ViewCellPvsData::NewMail(); 
     3198        UpdateViewCellsPvs(front, *frontData.mRays); 
     3199        UpdateViewCellsPvs(back, *backData.mRays); 
     3200 
     3201        //////////////////////////////////// 
     3202 
    31633203 
    31643204        ProcessMultipleRefs(front); 
     
    32343274        { 
    32353275                EvaluateLeafStats(tData);                
     3276const bool mStoreRays= true; 
     3277                //-- store additional info 
     3278                if (mStoreRays) 
     3279                { 
     3280                        KdLeaf *leaf = dynamic_cast<KdLeaf *>(newNode); 
     3281 
     3282                        RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 
     3283 
     3284                        for (it = tData.mRays->begin(); it != it_end; ++ it) 
     3285                        { 
     3286                                (*it).mRay->Ref();                       
     3287                                leaf->mVssRays.push_back((*it).mRay); 
     3288                        } 
     3289                } 
    32363290        } 
    32373291         
     
    32503304        // compute locally best split plane 
    32513305        const bool success =  
    3252                 SelectSplitPlane(splitCandidate.mParentData, splitCandidate.mSplitPlane, frontProb, backProb); 
     3306                SelectSplitPlane(splitCandidate.mParentData,  
     3307                                                 splitCandidate.mSplitPlane,  
     3308                                                 frontProb,  
     3309                                                 backProb); 
    32533310 
    32543311        float oldRenderCost; 
     
    32753332 
    32763333        splitCandidate.mMaxCostMisses =  
    3277                 success ? splitCandidate.mParentData.mMaxCostMisses : splitCandidate.mParentData.mMaxCostMisses + 1; 
     3334                success ? splitCandidate.mParentData.mMaxCostMisses :  
     3335        splitCandidate.mParentData.mMaxCostMisses + 1; 
    32783336} 
    32793337 
     
    33053363        // the node became a leaf -> evaluate stats for leafs 
    33063364        KdLeaf *leaf = data.mNode; 
     3365         
     3366        ++ mCreatedLeaves; 
    33073367 
    33083368        if (data.mPvs > mOspStats.maxPvs) 
     
    33243384        } 
    33253385 
    3326 //      if (data.mPvs < mTermMinPvs) 
    3327 //              ++ mOspStats.minPvsNodes; 
    3328  
    33293386        if (data.mProbability <= mTermMinProbability) 
    33303387                ++ mOspStats.minProbabilityNodes; 
     
    33323389        // accumulate depth to compute average depth 
    33333390        mOspStats.accumDepth += data.mDepth; 
    3334  
    3335         ++ mCreatedLeaves; 
     3391  
     3392        //      if ((int)(leaf->mObjects.size()) < mTermMinCost) 
     3393        //     ++ mOspStats.minCostNodes; 
     3394  
     3395        if ((int)(leaf->mObjects.size()) > mOspStats.maxObjectRefs) 
     3396                mOspStats.maxObjectRefs = (int)leaf->mObjects.size(); 
    33363397 
    33373398#ifdef _DEBUG 
     
    35003561        //      << "\t pb=(" << volBack << ")\t pf=(" << volFront << ")" << endl; 
    35013562 
    3502         Debug << "\n§§§§ eval local cost §§§§" << endl 
     3563/*      Debug << "\n§§§§ eval local cost §§§§" << endl 
    35033564                  << "back pvs: " << pvsBack << " front pvs: " << pvsFront << " total pvs: " << totalPvs << endl  
    35043565                  << "back p: " << volBack / viewSpaceVol << " front p " << volFront / viewSpaceVol << " p: " << totalVol / viewSpaceVol << endl 
    35053566                  << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl 
    35063567                  << "render cost decrease: " << oldRenderCost / viewSpaceVol - newRenderCost / viewSpaceVol << endl; 
    3507  
     3568*/ 
    35083569        if (oldRenderCost < newRenderCost) 
    35093570                Debug << "\nwarning!!:\n" << "old rc: " << oldRenderCost * viewSpaceVol << " new rc: " << newRenderCost * viewSpaceVol << endl; 
     
    35523613 
    35533614                const bool positive = ray->HasPosDir(axis); 
    3554                  
     3615         
     3616                if (EndPointInsideNode(leaf, *ray, true)) 
     3617                { 
     3618                        pos = ray->mTermination[axis]; 
     3619 
     3620                        mSplitCandidates->push_back( 
     3621                                SortableEntry(SortableEntry::BOX_INTERSECT,  
     3622                                                          pos,  
     3623                                                          ray->mTerminationObject,  
     3624                                                          ray) 
     3625                                                          ); 
     3626                } 
     3627 
    35553628                // if hitpoint with object is inside this node 
    3556                 if (ray->mOriginObject && (GetLeaf(ray->mOrigin, ray->mOriginNode) == leaf)) 
     3629                if (EndPointInsideNode(leaf, *ray, false)) 
    35573630                { 
    35583631                        pos = ray->mOrigin[axis]; 
     
    35623635                                                          pos,  
    35633636                                                          ray->mOriginObject,  
    3564                                                           ray) 
    3565                                                           ); 
    3566                 } 
    3567  
    3568                 if (ray->mTerminationObject && (GetLeaf(ray->mTermination, ray->mTerminationNode) == leaf)) 
    3569                 { 
    3570                         pos = ray->mTermination[axis]; 
    3571  
    3572                         mSplitCandidates->push_back( 
    3573                                 SortableEntry(SortableEntry::BOX_INTERSECT,  
    3574                                                           pos,  
    3575                                                           ray->mTerminationObject,  
    35763637                                                          ray) 
    35773638                                                          ); 
     
    36703731                // if hitpoint with one of the objects is inside this node, we 
    36713732                // evaluate the volume of the view cells seen by this ray 
    3672                 if (ray->mOriginObject && (GetLeaf(ray->mOrigin, ray->mOriginNode) == leaf)) 
     3733                if (EndPointInsideNode(leaf, *ray, true)) 
    36733734                { 
    36743735            vol += PrepareHeuristics(*ray, newViewCells); 
     
    36773738 
    36783739                // count double if both hit points are within the kd node 
    3679                 if (ray->mTerminationObject && (GetLeaf(ray->mTermination, ray->mTerminationNode) == leaf)) 
     3740                if (EndPointInsideNode(leaf, *ray, false)) 
    36803741                { 
    36813742                        vol += PrepareHeuristics(*ray, newViewCells); 
     
    36843745        } 
    36853746 
    3686         //Debug << "vol: " << vol << endl; 
     3747         
    36873748        return vol; 
    36883749} 
     
    37163777                                // process ray if the hit point with termination / origin object  
    37173778                                // is inside this kd leaf 
    3718                                 if ((ray->mOriginObject && (GetLeaf(ray->mOrigin, ray->mOriginNode) == leaf)) || 
    3719                                         (ray->mTerminationObject && (GetLeaf(ray->mTermination, ray->mTerminationNode) == leaf))) 
     3779                                if (EndPointInsideNode(leaf, *ray, true) || 
     3780                                        EndPointInsideNode(leaf, *ray, false)) 
    37203781                                { 
    37213782                                        EvalVolumeContribution(*ray, volLeft, volRight); 
     
    38813942        if (isTermination) 
    38823943        { 
    3883                  return ray.mTerminationObject && (GetLeaf(ray.mTermination, ray.mOriginNode) == leaf); 
     3944                 return ray.mTerminationObject && (GetLeaf(ray.mTermination, ray.mTerminationNode) == leaf); 
    38843945        } 
    38853946        else 
     
    39454006 
    39464007 
     4008static bool ViewCellHasMultipleReferences(Intersectable *obj,  
     4009                                                                                  ViewCell *vc,  
     4010                                                                                  bool checkOnlyMailed) 
     4011{ 
     4012        ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc); 
     4013 
     4014        if (vdata) 
     4015        { 
     4016                //Debug << "sumpdf: " << vdata->mSumPdf << endl; 
     4017                // more than one view cell sees this object inside different kd cells 
     4018                if (!checkOnlyMailed || !vdata->Mailed()) 
     4019                { 
     4020                        vdata->Mail();//return true; 
     4021                        if (vdata->mSumPdf > 1.5f)  
     4022                                return true; 
     4023                } 
     4024        } 
     4025 
     4026        return false; 
     4027} 
     4028 
     4029 
    39474030float OspTree::EvalRenderCostDecrease(const AxisAlignedPlane &candidatePlane, 
    39484031                                                                          const OspTraversalData &tData, 
     
    39584041        float pFrontAndBack = 0; 
    39594042 
    3960  
    39614043        const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
    39624044 
    3963         //Intersectable::NewMail(); 
    3964         KdLeaf::NewMail(); 
    3965         ViewCell::NewMail(); 
    3966  
     4045        Intersectable::NewMail(3); 
     4046         
    39674047        KdLeaf *leaf = tData.mNode; 
    39684048        const int totalPvs = (int)leaf->mObjects.size(); 
     
    39834063                { 
    39844064                        ++ pvsFront; 
     4065                        obj->Mail();             
    39854066                } 
    39864067 
     
    39884069                { 
    39894070                        ++ pvsBack; 
    3990                 } 
    3991         } 
     4071 
     4072                        if (obj->Mailed()) 
     4073                                obj->Mail(2); 
     4074                        else  
     4075                                obj->Mail(1); 
     4076                } 
     4077 
     4078                //Debug << "here3 pt: " << obj << " mail: " << obj->mMailbox - Intersectable::sMailId << endl; 
     4079        } 
     4080 
     4081         
     4082        ViewCellContainer touchedViewCells; 
     4083        RayInfoContainer touchedRays; 
    39924084 
    39934085        // sum up volume seen from the objects of left and right children 
     
    39964088 
    39974089        RayInfoContainer::const_iterator rit, rit_end = tData.mRays->end(); 
    3998  
    3999         ViewCellContainer collectedViewCells; 
     4090        //map<Intersectable *, ViewCellContainer> objectsMap; 
    40004091 
    40014092        for (rit = tData.mRays->begin(); rit < rit_end; ++ rit) 
     
    40094100                if (originInside || terminationInside) 
    40104101                { 
     4102                        touchedRays.push_back(*rit); 
    40114103                        // add volume to volumes of left and / or right children 
    40124104                        // if one of the ray end points is inside 
     
    40264118                                // if not previously mailed 
    40274119                                if (!vc->Mailed() && !vc->Mailed(1) && !vc->Mailed(2)) 
    4028                                         collectedViewCells.push_back(vc); 
    4029  
    4030                                 // classify / mail the view cell 
    4031                                 MailViewCell(*vit, classification);      
    4032                         } 
    4033                 } 
    4034         } 
    4035  
    4036  
    4037         // evaluate view cells volume contribution with respect to the mail box classification 
    4038         ViewCellContainer::const_iterator vit, vit_end = collectedViewCells.end(); 
    4039  
    4040         for (vit = collectedViewCells.begin(); vit != vit_end; ++ vit) 
     4120                                { 
     4121                                        touchedViewCells.push_back(vc); 
     4122                                } 
     4123 
     4124                // classify / mail the view cell 
     4125                                MailViewCell(vc, classification);        
     4126 
     4127                                /*if (terminationInside) 
     4128                                        objectsMap[ray->mTerminationObject].push_back(vc); 
     4129                                if (originInside) 
     4130                                        objectsMap[ray->mOriginObject].push_back(vc);*/ 
     4131                        } 
     4132                } 
     4133        } 
     4134 
     4135        // evaluate view cells volume contribution  
     4136        // with respect to the mail box classification 
     4137        ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 
     4138 
     4139        for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 
    40414140        { 
    40424141                AddViewCellVolumeContri(*vit, pFront, pBack, pFrontAndBack); 
    40434142        } 
     4143 
     4144        ////////////////////////////////////////////// 
     4145        // 
     4146        // evaluate contribution of objects which are part of other kd nodes 
     4147        // which are seen by the same view cell 
     4148        // These contributions cannot be reduced by splitting, because 
     4149        // the object would still be part of the pvs 
     4150 
     4151        float additionalFrontRenderCost = 0; 
     4152        float additionalBackRenderCost = 0; 
     4153         
     4154        ViewCellPvsData::NewMail(); 
     4155 
     4156        for (rit = touchedRays.begin(); rit != touchedRays.end(); ++ rit) 
     4157        { 
     4158                VssRay *ray = (*rit).mRay; 
     4159 
     4160                ViewCellContainer viewCells; 
     4161                mVspTree->GetViewCells(*ray, viewCells); 
     4162 
     4163                ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     4164 
     4165                // traverse through view cells 
     4166                for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     4167                { 
     4168                        ViewCell *viewCell = *vit; 
     4169 
     4170                        // for a view cell: 
     4171                        // if object is also in the kd pvs entries from other kd leaves, 
     4172                        // render cost cannot be reduced for this view cell 
     4173                        // => the render cost was falsly reduced, add them again 
     4174 
     4175                        if (EndPointInsideNode(leaf, *ray, true)) 
     4176                        {        
     4177                                Intersectable *obj = ray->mTerminationObject; 
     4178                                 
     4179                                const bool renderCostWrong =  
     4180                                        ViewCellHasMultipleReferences(obj, viewCell, true); 
     4181                        //      if(!obj->Mailed()){ 
     4182                        //      Debug << "pt: " << obj << endl; 
     4183                        //      Debug << "vc mail: " << viewCell->mMailbox - ViewCell::sMailId << " obj mail: " << obj->mMailbox << " "<< Intersectable::sMailId << " " <<obj->mMailbox - Intersectable::sMailId << endl; 
     4184                        //      obj->Mail(); 
     4185                        //      } 
     4186                                // if there is already an entry of this object in the view cell pvs  
     4187                                if (renderCostWrong) 
     4188                                { 
     4189                                        // view cell was counted only for front or back => correct tjos 
     4190                                        if (viewCell->Mailed(1) && obj->Mailed()) 
     4191                                                additionalFrontRenderCost += viewCell->GetVolume(); 
     4192                                        else if (viewCell->Mailed() && obj->Mailed(1)) 
     4193                                                additionalBackRenderCost += viewCell->GetVolume(); 
     4194                                } 
     4195                        } 
     4196         
     4197                        if (EndPointInsideNode(leaf, *ray, false)) 
     4198                        { 
     4199                                Intersectable *obj = ray->mOriginObject; 
     4200 
     4201                                const bool renderCostWrong =  
     4202                                        ViewCellHasMultipleReferences(obj, viewCell, true); 
     4203                                // if there is already an entry of this object in the view cell pvs  
     4204                                if (renderCostWrong) 
     4205                                { 
     4206                                        if (viewCell->Mailed(1) && obj->Mailed()) 
     4207                                                additionalFrontRenderCost += viewCell->GetVolume(); 
     4208                                        else if (viewCell->Mailed() && obj->Mailed(1)) 
     4209                                                additionalBackRenderCost += viewCell->GetVolume(); 
     4210                                } 
     4211                        } 
     4212                } 
     4213        } 
     4214 
     4215        ///////////////////////////// 
    40444216 
    40454217 
     
    40574229        // b) the right node are weighted by the #right node objects 
    40584230        // c) both nodes are weighted by the #parent node objects 
    4059         const float newRenderCost = pvsFront * pFront + pvsBack * pBack + totalPvs * pFrontAndBack; 
     4231        const float newRenderCost = pvsFront * pFront + pvsBack * pBack + totalPvs * pFrontAndBack 
     4232                + additionalFrontRenderCost + additionalBackRenderCost; 
    40604233 
    40614234        // normalize volume with view space volume 
     
    40674240                  << " front and back p " << pFrontAndBack / viewSpaceVol << " p: " << tData.mProbability / viewSpaceVol << endl 
    40684241                  << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl 
    4069                   << "render cost decrease: " << renderCostDecrease << endl; 
    4070                    
     4242                  << "render cost decrease: " << renderCostDecrease << endl 
     4243                  << "additional front " << additionalFrontRenderCost / viewSpaceVol  
     4244                  << " additional back " << additionalBackRenderCost  / viewSpaceVol << endl; 
     4245 
     4246        if (oldRenderCost < newRenderCost * 0.99) 
     4247                Debug <<"error!!"<<endl; 
     4248 
    40714249        //if ((((pOverall - tData.mProbability) / viewSpaceVol) > 0.00001)) 
    40724250        //      Debug << "ERROR!!"<<endl; 
     
    43834561 
    43844562 
     4563int OspTree::SplitViewCells(const AxisAlignedPlane &candidatePlane, 
     4564                                                        const RayInfoContainer &rays, 
     4565                                                        KdLeaf *leaf,                                                    
     4566                                                        ViewCellContainer &frontViewCells, 
     4567                                                        ViewCellContainer &backViewCells, 
     4568                                                        ViewCellContainer &frontAndBackViewCells) const  
     4569{ 
     4570        ViewCellContainer touchedViewCells; 
     4571        RayInfoContainer touchedRays; 
     4572 
     4573        // sum up volume seen from the objects of left and right children 
     4574        // => the volume is the weight for the render cost equation 
     4575        ViewCell::NewMail(3); 
     4576 
     4577        RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
     4578 
     4579        for (rit = rays.begin(); rit < rit_end; ++ rit) 
     4580        { 
     4581                VssRay *ray = (*rit).mRay; 
     4582 
     4583                // test if intersection point with one of the objects is inside this node 
     4584                const bool originInside = EndPointInsideNode(leaf, *ray, false); 
     4585        const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 
     4586 
     4587                if (originInside || terminationInside) 
     4588                { 
     4589                        touchedRays.push_back(*rit); 
     4590                        // add volume to volumes of left and / or right children 
     4591                        // if one of the ray end points is inside 
     4592                        const int classification = ClassifyRay(ray, leaf, candidatePlane); 
     4593 
     4594                        ViewCellContainer viewCells; 
     4595                        mVspTree->GetViewCells(*ray, viewCells); 
     4596                         
     4597                        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     4598 
     4599                        // traverse through view cells and classify them according 
     4600                        // to them being seen from to back / front / front and back node 
     4601                        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     4602                        { 
     4603                                ViewCell *vc = *vit; 
     4604 
     4605                                // if not previously mailed 
     4606                                if (!vc->Mailed() && !vc->Mailed(1) && !vc->Mailed(2)) 
     4607                                { 
     4608                                        touchedViewCells.push_back(vc); 
     4609                                } 
     4610 
     4611                // classify / mail the view cell 
     4612                                MailViewCell(*vit, classification);      
     4613                        } 
     4614                } 
     4615        } 
     4616         
     4617        // the important view cells 
     4618        ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 
     4619 
     4620        for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 
     4621        { 
     4622                ViewCell *vc = *vit; 
     4623 
     4624                if (vc->Mailed()) 
     4625                        frontViewCells.push_back(vc); 
     4626                else if (vc->Mailed(1)) 
     4627                        backViewCells.push_back(vc); 
     4628                else if (vc->Mailed(2)) 
     4629                        frontAndBackViewCells.push_back(vc); 
     4630        } 
     4631 
     4632        return 0; 
     4633} 
     4634 
     4635 
     4636int OspTree::CheckViewCellsPvs(KdLeaf *leaf,  
     4637                                                           const RayInfoContainer &rays) const 
     4638{ 
     4639        RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
     4640 
     4641        Intersectable::NewMail(); 
     4642        ObjectContainer touchedObjects; 
     4643         
     4644 
     4645        for (rit = rays.begin(); rit < rit_end; ++ rit) 
     4646        { 
     4647                VssRay *ray = (*rit).mRay; 
     4648 
     4649                // test if intersection point with one of the objects is inside this node 
     4650                const bool originInside = EndPointInsideNode(leaf, *ray, false); 
     4651        const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 
     4652 
     4653                if (terminationInside) 
     4654                { 
     4655                        Intersectable *obj = ray->mTerminationObject; 
     4656 
     4657                        if (!obj->Mailed()) 
     4658                        { 
     4659                                obj->Mail(); 
     4660                                touchedObjects.push_back(obj); 
     4661                        } 
     4662                } 
     4663 
     4664                if (originInside) 
     4665                { 
     4666                        Intersectable *obj = ray->mOriginObject; 
     4667 
     4668                        if (!obj->Mailed()) 
     4669                        { 
     4670                                obj->Mail(); 
     4671                                touchedObjects.push_back(obj); 
     4672                        } 
     4673                } 
     4674        } 
     4675        Debug << "here65 " << touchedObjects.size() << endl; 
     4676        ObjectContainer::const_iterator it, it_end = touchedObjects.end(); 
     4677        for (it = touchedObjects.begin(); it != it_end; ++ it) 
     4678        { 
     4679                Debug << "\nhere94 obj: " << (*it) << " size: " << (*it)->mViewCellPvs.GetSize() << endl << endl; 
     4680                ViewCellPvsMap::const_iterator mit, mit_end = (*it)->mViewCellPvs.mEntries.end(); 
     4681 
     4682                for (mit = (*it)->mViewCellPvs.mEntries.begin(); mit != mit_end; ++ mit) 
     4683                { 
     4684                        Debug << "newsumpdf: " << (*mit).second.mSumPdf << endl; 
     4685                } 
     4686        } 
     4687 
     4688        return 0; 
     4689} 
     4690 
     4691 
     4692 
     4693 
    43854694KdIntersectable *OspTree::GetOrCreateKdIntersectable(KdNode *node) 
    43864695{ 
     
    44484757} 
    44494758*/ 
     4759 
     4760 
    44504761void OspTree::MailViewCell(ViewCell *vc, const int cf) const 
    44514762{ 
     
    45014812 
    45024813 
    4503 float OspTree::EvalViewCellsVolume(KdLeaf *leaf, const RayInfoContainer &rays) const 
     4814float OspTree::EvalViewCellsVolume(KdLeaf *leaf,  
     4815                                                                   const RayInfoContainer &rays) const 
    45044816{ 
    45054817        float vol = 0; 
     
    45144826                // process ray if the hit point with termination / origin object  
    45154827                // is inside this kd leaf 
    4516                 if (!((ray->mOriginObject && (GetLeaf(ray->mOrigin, ray->mOriginNode) == leaf)) || 
    4517                           (ray->mTerminationObject && (GetLeaf(ray->mTermination, ray->mTerminationNode) == leaf)))) 
     4828                if (!((EndPointInsideNode(leaf, *ray, true)) || 
     4829                          (EndPointInsideNode(leaf, *ray, false)))) 
    45184830                        continue; 
    45194831                 
     
    45364848 
    45374849        return vol; 
     4850} 
     4851 
     4852 
     4853bool OspTree::AddViewCellToObjectPvs(Intersectable *obj,  
     4854                                                                         ViewCell *vc,  
     4855                                                                         float &contribution, 
     4856                                                                         bool onlyMailed) const 
     4857{        
     4858        contribution = 0; // todo 
     4859 
     4860        ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc); 
     4861 
     4862        if (!vdata) 
     4863        { 
     4864                vdata = obj->mViewCellPvs.AddSample2(vc, 1); 
     4865        } 
     4866        else if (!onlyMailed || !vdata->Mailed()) 
     4867        { 
     4868                obj->mViewCellPvs.AddSample(vc, 1); 
     4869        } 
     4870         
     4871        vdata->Mail(); 
     4872 
     4873        return true; 
     4874} 
     4875 
     4876 
     4877int OspTree::UpdateViewCellsPvs(KdLeaf *leaf,  
     4878                                                                const RayInfoContainer &rays) const 
     4879 
     4880{ 
     4881        RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
     4882 
     4883        //ViewCell::NewMail(); Intersectable::NewMail(); 
     4884        ViewCellPvsData::NewMail(); 
     4885 
     4886        for (rit = rays.begin(); rit < rit_end; ++ rit) 
     4887        { 
     4888                VssRay *ray = (*rit).mRay; 
     4889 
     4890                // test if intersection point with one of the objects is inside this node 
     4891                const bool originInside = EndPointInsideNode(leaf, *ray, false); 
     4892        const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 
     4893 
     4894                if (originInside || terminationInside) 
     4895                { 
     4896                        ViewCellContainer viewCells; 
     4897                        mVspTree->GetViewCells(*ray, viewCells); 
     4898 
     4899                        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     4900 
     4901                        // traverse through view cells and classify them according 
     4902                        // to them being seen from to back / front / front and back node 
     4903                        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     4904                        { 
     4905                                ViewCell *vc = *vit; 
     4906 
     4907                                Intersectable *obj = ray->mTerminationObject; 
     4908                         
     4909                                if (obj) 
     4910                                { 
     4911                                        float contri; 
     4912                                        AddViewCellToObjectPvs(obj, vc, contri, true); 
     4913                                } 
     4914 
     4915                                obj = ray->mOriginObject; 
     4916                         
     4917                                if (obj) 
     4918                                { 
     4919                                        float contri; 
     4920                                        AddViewCellToObjectPvs(obj, vc, contri, true); 
     4921                                } 
     4922                        } 
     4923                } 
     4924        } 
     4925 
     4926        return 0; 
     4927} 
     4928 
     4929 
     4930int OspTree::RemoveParentViewCellsPvs(KdLeaf *leaf,  
     4931                                                                          const RayInfoContainer &rays 
     4932                                                                          ) const 
     4933 
     4934{ 
     4935        RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
     4936        //ViewCell::NewMail(); Intersectable::NewMail(); 
     4937        ViewCellPvsData::NewMail(); 
     4938 
     4939        for (rit = rays.begin(); rit < rit_end; ++ rit) 
     4940        { 
     4941                VssRay *ray = (*rit).mRay; 
     4942 
     4943                // test if intersection point with one of the objects is inside this node 
     4944                const bool originInside = EndPointInsideNode(leaf, *ray, false); 
     4945        const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 
     4946 
     4947                if (originInside || terminationInside) 
     4948                { 
     4949                        ViewCellContainer viewCells; 
     4950                        mVspTree->GetViewCells(*ray, viewCells); 
     4951 
     4952                        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     4953 
     4954                        // traverse through view cells and classify them according 
     4955                        // to them being seen from to back / front / front and back node 
     4956                        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     4957                        { 
     4958                                ViewCell *vc = *vit; 
     4959 
     4960                                Intersectable *obj = ray->mTerminationObject; 
     4961                                if (obj) 
     4962                                { 
     4963                                        ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc); 
     4964 
     4965                                        if (vdata && !vdata->Mailed()) 
     4966                                        { 
     4967                                                vdata->Mail(); 
     4968                                                obj->mViewCellPvs.RemoveSample(vc, 1); 
     4969                                        } 
     4970                                         
     4971                                } 
     4972 
     4973                                obj = ray->mOriginObject; 
     4974                                if (obj) 
     4975                                { 
     4976                                        ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc); 
     4977 
     4978                                        if (vdata && !vdata->Mailed()) 
     4979                                        { 
     4980                                                vdata->Mail(); 
     4981                                                obj->mViewCellPvs.RemoveSample(vc, 1); 
     4982                                        } 
     4983                                } 
     4984                        } 
     4985                } 
     4986        } 
     4987 
     4988        return 0; 
     4989} 
     4990 
     4991 
     4992float OspTree::EvalRenderCost() 
     4993{ 
     4994        float rc = 0; 
     4995float prop = mVspTree->GetBoundingBox().GetVolume();     
     4996        KdLeafContainer leaves; 
     4997        CollectLeaves(leaves); 
     4998 
     4999        KdLeafContainer::const_iterator kit, kit_end = leaves.end(); 
     5000        for (kit = leaves.begin(); kit != kit_end; ++ kit) 
     5001        { 
     5002                KdLeaf *leaf = *kit; 
     5003                float newCost = 0; 
     5004                float vol = 0; 
     5005 
     5006                ViewCell::NewMail(); 
     5007                VssRayContainer::const_iterator rit, rit_end = leaf->mVssRays.end(); 
     5008                ViewCellContainer touchedViewCells; 
     5009 
     5010                for (rit = leaf->mVssRays.begin(); rit != rit_end; ++ rit) 
     5011                { 
     5012                        VssRay *ray = *rit; 
     5013                         
     5014                        // test if intersection point with one of the objects is inside this node 
     5015                        const bool originInside = EndPointInsideNode(leaf, *ray, false); 
     5016                        const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 
     5017 
     5018                        if (originInside || terminationInside) 
     5019                        { 
     5020                                ViewCellContainer viewCells; 
     5021                                mVspTree->GetViewCells(*ray, viewCells); 
     5022                         
     5023                                ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     5024 
     5025                                for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     5026                                { 
     5027                                        ViewCell *vc = *vit; 
     5028 
     5029                                        // if not previously mailed 
     5030                                        if (!vc->Mailed()) 
     5031                                        { 
     5032                                                vc->Mail(); 
     5033                                                vc->GetPvs().Clear(); 
     5034                                                touchedViewCells.push_back(vc); 
     5035                                        } 
     5036 
     5037                        } 
     5038                        } 
     5039                } 
     5040                 
     5041                //ViewCellPvsData::NewMail(); 
     5042                ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     5043 
     5044                for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
     5045                { 
     5046                        Intersectable *obj = *oit; 
     5047                        ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 
     5048 
     5049                        for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 
     5050                        { 
     5051                                ViewCell *vc = *vit; 
     5052                                ObjectPvsData *vdata = vc->GetPvs().Find(obj); 
     5053 
     5054                                if (!vdata) 
     5055                                { 
     5056                                        vc->GetPvs().AddSample(obj, 1); 
     5057                                        newCost += vc->GetVolume(); 
     5058                                        //prop += vc->GetVolume(); 
     5059                                } 
     5060                        } 
     5061                } 
     5062 
     5063                rc += newCost; 
     5064        } 
     5065 
     5066        return rc / prop; 
    45385067} 
    45395068 
     
    46575186        mOspTree.mRoot = kdleaf; 
    46585187         
     5188        // probabilty is voume of all "seen" view cells 
     5189#if 1 
    46595190        const float prop = mOspTree.EvalViewCellsVolume(kdleaf, rays); 
    4660  
    4661         //-- add first candidate for view space partition 
    4662  
    4663         // first osp traversal data 
     5191#else 
     5192        const float prop = mVspTree.GetBoundingBox().GetVolume(); 
     5193#endif 
     5194 
     5195        //-- add first candidate for object space partition 
     5196 
     5197        // create osp traversal data 
    46645198        OspTree::OspTraversalData oData(kdleaf, 
    46655199                                                                        0, 
     
    46705204 
    46715205                 
    4672         // compute first split candidate 
     5206        // first split candidate 
    46735207        OspTree::OspSplitCandidate *oSplitCandidate =  
    46745208                new OspTree::OspSplitCandidate(oData); 
     
    46765210        mOspTree.EvalSplitCandidate(*oSplitCandidate); 
    46775211 
    4678         mOspTree.mTotalCost = (float)objects.size() * prop / mVspTree.GetBoundingBox().GetVolume(); 
     5212        mOspTree.mTotalCost = (float)objects.size() * prop /  
     5213                mVspTree.GetBoundingBox().GetVolume(); 
     5214 
    46795215        mOspTree.EvalSubdivisionStats(*oSplitCandidate); 
    46805216 
     
    47935329                        ++ mGlobalCostMisses; 
    47945330         
    4795                 Debug << "\n**********" << endl 
     5331                /*Debug << "\n**********" << endl 
    47965332                          << "total cost: " << mTotalCost << " render cost decr: "  
    47975333                          << splitCandidate->GetRenderCostDecrease()  
    4798                           << " cost ratio: " << costRatio << endl << endl; 
     5334                          << " cost ratio: " << costRatio << endl << endl;*/ 
    47995335 
    48005336                //-- subdivide leaf node 
     
    48765412        cout << "starting osp contruction ... " << endl; 
    48775413 
     5414        // start with one big kd cell - all objects can be seen from everywhere 
     5415        // note: only true for view space = object space 
     5416 
    48785417        // compute first candidate 
    48795418        OspTree::OspSplitCandidate *osc = 
    48805419                PrepareOsp(sampleRays, objects, forcedViewSpace, *objectSpaceRays); 
    48815420 
     5421        Debug << "reseting cost, new total cost: " << mTotalCost << endl; 
     5422        mTotalCost = mOspTree.mTotalCost; 
     5423 
    48825424    mTQueue.Push(osc); 
    48835425 
     
    48865428 
    48875429        startTime = GetTime(); 
    4888  
    4889         // reset cost 
    4890         // start with one big kd cell - all objects can be seen from everywhere 
    4891         // note: only true for view space = object space 
    4892         mTotalCost = (float)osc->mParentData.mNode->mObjects.size();//(float)sc->mParentData.mPvs; 
    4893          
    4894         Debug << "reseting cost, new total cost: " << mTotalCost << endl; 
    4895  
     5430         
    48965431        // process object space candidates 
    48975432        RunConstruction(repairQueue); 
     
    49015436        mOspTree.mOspStats.Stop(); 
    49025437 
     5438        float rc = mOspTree.EvalRenderCost(); 
     5439 
     5440        Debug << "My render cost evalulation: " << rc << endl; 
     5441 
     5442         
     5443 
     5444 
     5445ViewCellContainer leaves; 
     5446 
     5447mVspTree.CollectViewCells(leaves, false); 
     5448float rc2 = 0; 
     5449        ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 
     5450        for (vit = leaves.begin(); vit != vit_end; ++ vit) 
     5451        { 
     5452                ViewCell *vc = *vit; 
     5453 
     5454                int pvs = vc->GetPvs().CountObjectsInPvs(); 
     5455                float vol = vc->GetVolume(); 
     5456                rc2 += (float)pvs * vol; 
     5457 
     5458        } 
     5459         
     5460        Debug << "here225 " << rc2 / mVspTree.GetBoundingBox().GetVolume()<<endl; 
    49035461#if 0 
    49045462        // reset parameters 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h

    r1181 r1184  
    180180                invalidLeaves = 0; 
    181181                accumRays = 0; 
     182                maxObjectRefs = 0; 
    182183        } 
    183184 
     
    272273                invalidLeaves = 0; 
    273274                objectRefs = 0; 
     275 
     276                maxObjectRefs = 0; 
    274277        } 
    275278 
     
    778781 
    779782 
    780         /// pointer to the hierarchy of view cells 
    781         ViewCellsTree *mViewCellsTree; 
    782  
    783         OspTree *mOspTree; 
     783        ViewCellsTree *GetViewCellsTree() const { return mViewCellsTree; } 
     784 
     785        void SetViewCellsTree(ViewCellsTree *vt) { mViewCellsTree = vt; } 
     786 
    784787 
    785788protected: 
     
    10201023        bool AddKdLeafToPvs(KdLeaf *leaf,  
    10211024                                                ViewCell *vc,  
    1022                                                 float &pvs,  
     1025                                                const float pvs,  
    10231026                                                float &contribution); 
    10241027 
     
    10621065 
    10631066 
     1067 
    10641068protected: 
    10651069 
     1070 
     1071        /// pointer to the hierarchy of view cells 
     1072        ViewCellsTree *mViewCellsTree; 
     1073 
     1074        OspTree *mOspTree; 
    10661075 
    10671076        bool mUseKdPvsForHeuristics; 
     
    14131422        void SetViewCellsTree(ViewCellsTree *vt) { mViewCellsTree = vt; } 
    14141423 
     1424        float EvalRenderCost(); 
    14151425 
    14161426protected: 
     
    15711581        */ 
    15721582        int SplitRays(const AxisAlignedPlane &plane, 
    1573                                   RayInfoContainer &rays,  
    1574                               RayInfoContainer &frontRays,  
    1575                                   RayInfoContainer &backRays) const; 
     1583                RayInfoContainer &rays,  
     1584                RayInfoContainer &frontRays,  
     1585                RayInfoContainer &backRays) const; 
     1586 
     1587        int SplitViewCells( 
     1588                const AxisAlignedPlane &candidatePlane, 
     1589                const RayInfoContainer &rays, 
     1590                KdLeaf *leaf, 
     1591                ViewCellContainer &frontViewCells, 
     1592                ViewCellContainer &backViewCells, 
     1593                ViewCellContainer &frontAndBackViewCells) const; 
    15761594 
    15771595        /** Adds the object to the pvs of the front and back leaf with a given classification. 
     
    16251643                                                                        float &volRight); 
    16261644 
    1627 /** Evaluates the influence on the pvs of the event. 
     1645        /** Evaluates the influence on the pvs of the event. 
    16281646                @param ve the visibility event 
    16291647                @param pvsLeft updates the left pvs 
     
    16981716 
    16991717        float EvalViewCellsVolume(KdLeaf *leaf, const RayInfoContainer &rays) const; 
    1700  
     1718         
     1719        int RemoveParentViewCellsPvs(KdLeaf *leaf,  
     1720                                                                          const RayInfoContainer &rays 
     1721                                                                          ) const; 
     1722 
     1723        int UpdateViewCellsPvs(KdLeaf *leaf, const RayInfoContainer &rays) const; 
     1724int OspTree::CheckViewCellsPvs(KdLeaf *leaf,  
     1725                                                           const RayInfoContainer &rays) const; 
     1726        bool AddViewCellToObjectPvs( 
     1727                Intersectable *obj, 
     1728                ViewCell *vc,  
     1729                float &contribution, 
     1730                bool onlyMailed) const; 
    17011731 
    17021732protected: 
    17031733 
     1734         
    17041735        /// pointer to the hierarchy of view cells 
    17051736        ViewCellsTree *mViewCellsTree; 
Note: See TracChangeset for help on using the changeset viewer.