Changeset 1740


Ignore:
Timestamp:
11/10/06 22:15:56 (18 years ago)
Author:
mattausch
Message:

exchanged pvs implementation: using vectors instead of maps

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

Legend:

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

    r1738 r1740  
    18451845                for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 
    18461846                { 
    1847                         BvhIntersectable *intersect = dynamic_cast<BvhIntersectable *>((*oit).first); 
     1847                        BvhIntersectable *intersect = dynamic_cast<BvhIntersectable *>((*oit).mObject); 
    18481848 
    18491849                        BvhLeaf *leaf = intersect->GetItem(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp

    r1736 r1740  
    21752175                        { 
    21762176                                ViewCell *vc = *vit; 
    2177                                 PvsData *vdata = vc->GetPvs().Find(obj); 
     2177                                /*PvsData *vdata = vc->GetPvs().Find(obj); 
    21782178 
    21792179                                if (!vdata) 
     
    21832183                                } 
    21842184 
    2185 /*                              MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 
     2185                                MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 
    21862186 
    21872187                                if (!vdata || !vdata->Mailed()) 
     
    22562256                { 
    22572257                        ViewCell *vc = *vit; 
    2258                         PvsData *vdata = vc->GetPvs().Find(obj); 
     2258                        /*PvsData *vdata = vc->GetPvs().Find(obj); 
    22592259 
    22602260                        if (!vdata) 
     
    22622262                                vc->GetPvs().AddSample(obj, 1); 
    22632263                                rc += vc->GetVolume(); 
    2264                                 //prop += vc->GetVolume(); 
    22652264                        } 
     2265                        */ 
    22662266                } 
    22672267        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1723 r1740  
    127127mBspTree(NULL), 
    128128mVspBspTree(NULL), 
    129 mHierarchyManager(NULL), 
    130129mViewCellsManager(NULL), 
    131130mRenderSimulator(NULL), 
     
    186185        cout << "Deleting kd tree...\n"; 
    187186        DEL_PTR(mKdTree); 
    188         cout << "done.\n"; 
    189  
    190         cout << "Deleting hierarchy manager...\n"; 
    191         DEL_PTR(mHierarchyManager); 
    192187        cout << "done.\n"; 
    193188 
     
    630625        if (mLoadViewCells) 
    631626        {        
    632           Environment::GetSingleton()->GetStringValue("ViewCells.filename", buf); 
    633           cout << "loading view cells from " << buf << endl<<flush; 
    634            
    635          mViewCellsManager = ViewCellsManager::LoadViewCells(buf, &mObjects, true, NULL); 
    636  
    637          cout << "view cells loaded." << endl<<flush; 
    638           
    639           if (!mViewCellsManager) 
    640           { 
    641                   return false; 
    642           } 
     627                Environment::GetSingleton()->GetStringValue("ViewCells.filename", buf); 
     628                cout << "loading view cells from " << buf << endl<<flush; 
     629 
     630                mViewCellsManager = ViewCellsManager::LoadViewCells(buf, &mObjects, true, NULL); 
     631 
     632                cout << "view cells loaded." << endl<<flush; 
     633 
     634                if (!mViewCellsManager) 
     635                { 
     636                        return false; 
     637                } 
    643638        } 
    644639        else 
     
    646641                // parse type of view cell container 
    647642                Environment::GetSingleton()->GetStringValue("ViewCells.type", buf);              
    648             mViewCellsManager = CreateViewCellsManager(buf); 
     643                mViewCellsManager = CreateViewCellsManager(buf); 
    649644 
    650645                // default view space is the extent of the scene 
    651646                AxisAlignedBox3 viewSpaceBox; 
    652                          
     647 
    653648                if (mUseViewSpaceBox) 
    654649                { 
     
    675670                char vcGeomFilename[100]; 
    676671                Environment::GetSingleton()->GetStringValue("ViewCells.geometryFilename", vcGeomFilename); 
    677                  
     672 
    678673                if (loadVcGeometry) 
    679674                { 
     
    691686                } 
    692687        } 
    693          
     688 
    694689        //////// 
    695690        //-- evaluation of render cost heuristics 
     
    699694        Environment::GetSingleton()->GetFloatValue("Simulation.vcOverhead", vcOverhead); 
    700695        Environment::GetSingleton()->GetFloatValue("Simulation.moveSpeed", moveSpeed); 
    701          
     696 
    702697        mRenderSimulator =  
    703698                new RenderSimulator(mViewCellsManager, objRenderCost, vcOverhead, moveSpeed); 
    704699 
    705700        mViewCellsManager->SetRenderer(mRenderSimulator); 
    706          
     701 
    707702        if (mUseGlRenderer || mUseGlDebugger) 
    708           { 
     703        { 
    709704                // NOTE: render texture should be power of 2 and square 
    710705                // renderer must be initialised 
     
    712707                //              renderer = new GlRendererBuffer(1024, 768, mSceneGraph, mViewCellsManager, mKdTree); 
    713708                //              renderer->makeCurrent(); 
    714                  
    715           } 
     709 
     710        } 
    716711 
    717712        mViewCellsManager->SetPreprocessor(this); 
     
    733728 
    734729 
    735 HierarchyManager *Preprocessor::CreateHierarchyManager(const char *name) 
    736 { 
    737         HierarchyManager *hierarchyManager; 
    738  
    739         if (strcmp(name, "osp") == 0) 
    740         { 
    741                 Debug << "hierarchy manager: osp" << endl; 
    742                 // HACK for testing if per kd evaluation works!! 
    743                 const bool ishack = false; 
    744                 if (ishack) 
    745                         hierarchyManager = new HierarchyManager(mKdTree); 
    746                 else 
    747                         hierarchyManager = new HierarchyManager(HierarchyManager::KD_BASED_OBJ_SUBDIV); 
    748         } 
    749         else if (strcmp(name, "bvh") == 0) 
    750         { 
    751                 Debug << "hierarchy manager: bvh" << endl; 
    752                 hierarchyManager = new HierarchyManager(HierarchyManager::BV_BASED_OBJ_SUBDIV); 
    753         } 
    754         else // only view space partition 
    755         { 
    756                 Debug << "hierarchy manager: obj" << endl; 
    757                 hierarchyManager = new HierarchyManager(HierarchyManager::NO_OBJ_SUBDIV); 
    758         } 
    759  
    760         return hierarchyManager; 
    761 } 
    762  
    763  
    764730ViewCellsManager *Preprocessor::CreateViewCellsManager(const char *name) 
    765731{ 
     
    790756                Environment::GetSingleton()->GetStringValue("Hierarchy.type", buf);      
    791757 
    792                 mHierarchyManager = CreateHierarchyManager(buf); 
    793                 mViewCellsManager = new VspOspViewCellsManager(vcTree, mHierarchyManager); 
     758                mViewCellsManager = new VspOspViewCellsManager(vcTree, buf); 
    794759        } 
    795760        else if (strcmp(name, "sceneDependent") == 0) //TODO 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1723 r1740  
    138138        */ 
    139139        ViewCellsManager *CreateViewCellsManager(const char *name); 
    140         /** Returns a hierarchy manager of the given name. 
    141         */ 
    142         HierarchyManager *CreateHierarchyManager(const char *name); 
    143140 
    144141        GlRendererBuffer *GetRenderer(); 
     
    160157        /// View space partition bsp tree 
    161158        VspBspTree *mVspBspTree; 
    162         /// Hierarchy manager handling view space and object space partition 
    163         HierarchyManager *mHierarchyManager; 
    164159        /// BSP tree representing the viewcells 
    165160        BspTree *mBspTree; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp

    r1738 r1740  
    143143        for (it = mEntries.begin(); it != it_end; ++ it) 
    144144        { 
    145                 Intersectable *obj = (*it).first; 
     145                Intersectable *obj = (*it).mObject; 
    146146         
    147147                switch (obj->Type()) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h

    r1739 r1740  
    1515 
    1616 
    17 template<typename T> 
    18 struct LtSample  
    19 { 
    20     bool operator()(const T a, const T b) const 
     17/** Information stored with a PVS entry. Consists of the number 
     18        the object was seen from the view cell. 
     19*/ 
     20template<typename T, typename S> 
     21class PvsEntry  
     22{ 
     23public: 
     24 
     25        PvsEntry(T sample, const S &data): mObject(sample), mData(data) {} 
     26 
     27        T mObject; 
     28        S mData; 
     29 
     30        template<typename T, typename S> 
     31        friend int operator< (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b); 
     32}; 
     33 
     34 
     35template<typename T, typename S> 
     36int operator< (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b) 
     37{ 
     38        return a.mObject < b.mObject; 
     39}  
     40 
     41 
     42template<typename T, typename S> 
     43struct LtSample 
     44{ 
     45    bool operator()(const PvsEntry<T, S> &a, const PvsEntry<T, S> &b) const 
    2146    { 
    22                 return a < b; 
     47                return a.mObject < b.mObject; 
    2348        }  
    2449}; 
     50 
    2551 
    2652/** Information stored with a PVS entry. Consists of the number 
     
    2955class PvsData { 
    3056public: 
     57        PvsData() {} 
     58        PvsData(const float sumPdf): 
     59        mSumPdf(sumPdf) {} 
     60         
     61        // $$JB in order to return meaningfull values 
     62        // it assumes that the sum pdf has been normalized somehow!!! 
     63        inline float GetVisibility()  
     64        {  
     65                return mSumPdf;  
     66        } 
     67 
    3168        /// sum of probability density of visible sample rays 
    3269        float mSumPdf; 
    33  
    34         PvsData() {} 
    35         PvsData(const float sumPdf): 
     70}; 
     71 
     72 
     73class MailablePvsData  
     74{ 
     75public: 
     76        // sum of probability density of visible sample rays 
     77        float mSumPdf; 
     78        int mCounter; 
     79 
     80        MailablePvsData() {} 
     81        MailablePvsData(const float sumPdf): 
    3682        mSumPdf(sumPdf) {} 
    3783 
     
    4288                return mSumPdf;  
    4389        } 
    44 }; 
    45  
    46  
    47 class MailablePvsData  
    48 { 
     90 
    4991        //////////////////////////// 
    5092        //  Mailing stuff 
    51 protected: 
    52         int mMailbox; 
    53  
    54 public: 
     93 
    5594        // last mail id -> warning not thread safe! 
    5695        // both mailId and mailbox should be unique for each thread!!! 
     
    5897        static int sReservedMailboxes; 
    5998 
    60  
    6199        static void NewMail(const int reserve = 1) { 
    62100                sMailId += sReservedMailboxes; 
     
    71109 
    72110        int IncMail() { return ++ mMailbox - sMailId; } 
     111         
    73112        ////////////////////////////////////////// 
    74113 
    75         // sum of probability density of visible sample rays 
    76         float mSumPdf; 
    77         int mCounter; 
    78  
    79         MailablePvsData() {} 
    80         MailablePvsData(const float sumPdf): 
    81         mSumPdf(sumPdf) {} 
    82  
    83         // $$JB in order to return meaningfull values 
    84         // it assumes that the sum pdf has been normalized somehow!!! 
    85         float GetVisibility()  
    86         {  
    87                 return mSumPdf;  
    88         } 
    89 }; 
     114protected: 
     115 
     116        int mMailbox; 
     117 
     118}; 
     119 
     120 
    90121template<typename T, typename S> 
    91         class Iterator 
    92         { 
    93                 //template<typename T, typename S> friend Pvs<T, S>; 
    94         private: 
    95                 std::vector<std::pair<T, S> >::iterator mIt; 
    96                 //vector<pair<T, S> >::iterator mItEnd; 
    97         }; 
     122class PvsIterator 
     123{ 
     124private: 
     125        typename vector<PvsEntry<T, S> >::iterator mItCurrent; 
     126        typename vector<PvsEntry<T, S> >::iterator mItEnd; 
     127}; 
     128 
     129 
    98130/** Template class representing the Potentially Visible Set (PVS)  
    99131        mainly from a view cell, but also e.g., from objects. 
     
    102134class Pvs 
    103135{ 
     136        template<typename T, typename S> 
     137        friend class PvsIterator; 
     138 
    104139public: 
    105 //vector<pair<T, S> >::iterator mItEnd; 
    106          
    107  
    108         template<typename T, typename S> 
    109         class ConstIterator 
    110         { 
    111         //      template<typename T, typename S> friend Pvs<T, S>; 
    112         private: 
    113                 //vector<pair<T, S> >::const_iterator mIt; 
    114                 //vector<pair<T, S> >::const_iteator mItEnd; 
    115         }; 
    116  
    117   Pvs(): mSamples(0), mEntries() {} 
    118    
    119  
     140 
     141        Pvs(): mSamples(0), mEntries() {} 
     142 
     143        Pvs(const vector<PvsEntry<T, S> > &samples); 
    120144        //virtual ~Pvs(); 
    121145 
     
    126150        bool Empty() const {return mEntries.empty();} 
    127151 
    128         /** Normalize the visibility of entries in order to get comparable 
    129                 results  
     152        /** Normalize the visibility of entries in order to get  
     153                comparable results. 
    130154        */ 
    131155        void NormalizeMaximum(); 
    132156 
    133157        /** Merges pvs of a into this pvs. 
    134         */ 
    135         void Merge(const Pvs<T, S> &a); 
     158                Warning: very slow! 
     159        */ 
     160        void MergeInPlace(const Pvs<T, S> &a); 
    136161 
    137162        /** Difference of pvs to pvs b. 
     
    141166 
    142167        /** Finds sample in PVS. 
    143                 @returns sample if found, NULL otherwise. 
    144         */ 
    145         S *Find(T sample); 
     168                @returns iterator on the sample. 
     169        */ 
     170        typename vector<PvsEntry<T, S> >::iterator Find(T sample); 
    146171 
    147172        bool GetSampleContribution(T sample, const float pdf, float &contribution); 
     
    157182        */ 
    158183        float AddSample(T sample, const float pdf); 
     184         
     185        /** Adds sample to PVS. 
     186                @returns contribution of sample (0 or 1) 
     187        */ 
     188        float AddSamples(const vector<PvsEntry<T, S> > &samples); 
    159189 
    160190        /** Adds sample to PVS. 
    161191                @returns PvsData 
    162192        */ 
    163         S *AddSample2(T sample, const float pdf); 
    164  
    165         /** Adds one pvs to another one. 
    166                 @returns new pvs size 
    167         */ 
    168         int AddPvs(const Pvs<T, S> &pvs); 
     193        typename std::vector<PvsEntry<T, S> >::iterator AddSample2(T sample, const float pdf); 
    169194 
    170195        /** Subtracts one pvs from another one. 
     
    173198        */ 
    174199        int SubtractPvs(const Pvs<T, S> &pvs); 
     200 
    175201        /** Returns PVS data, i.e., how often it was seen from the view cell,  
    176202                and the object itsef. 
     
    189215        /** Compute continuous PVS difference  
    190216        */ 
    191         void ComputeContinuousPvsDifference(Pvs<T, S> &pvs, 
    192                 float &pvsReduction, 
    193                 float &pvsEnlargement); 
    194  
     217        void ComputeContinuousPvsDifference(Pvs<T, S> &pvs,  
     218                                                                                float &pvsReduction, 
     219                                                                                float &pvsEnlargement); 
    195220 
    196221        /** Clears the pvs. 
     
    201226        static float GetEntrySize(); 
    202227 
    203         /** Compute continuous PVS difference */ 
    204         float GetPvsHomogenity(Pvs<T, S> &pvs) { 
    205                 float pvsReduction, pvsEnlargement; 
    206  
    207                 ComputeContinuousPvsDifference(pvs, 
    208                         pvsReduction, 
    209                         pvsEnlargement); 
    210  
    211                 return pvsReduction + pvsEnlargement; 
    212         } 
    213  
    214         int Size() { return mEntries.size(); } 
    215  
    216         //vector<pair<T, S> >::const_iterator &GetConstIterator() const { return mEntries.begin(); } 
    217         //vector<pair<T, S> >::iterator &GetIterator() { return mEntries.begin(); } 
     228        /** Compute continuous PVS difference  
     229        */ 
     230        float GetPvsHomogenity(Pvs<T, S> &pvs); 
     231 
     232        static void Merge(Pvs<T, S> &mergedPvs, const Pvs<T, S> &a, const Pvs<T, S> &b); 
    218233 
    219234//protected: 
    220235 
    221236        /// vector of PVS entries 
    222         vector<pair<T, S> > mEntries;  
     237        vector<PvsEntry<T, S> > mEntries;  
    223238         
    224239        /// Number of samples used to create the PVS 
     
    227242 
    228243 
     244template <typename T, typename S> 
     245Pvs<T, S>::Pvs(const vector<PvsEntry<T, S> > &samples) 
     246{ 
     247        mEntries.reserve(samples.size()); 
     248        mEntries = samples; 
     249} 
     250 
    229251 
    230252/** 
     
    236258void 
    237259Pvs<T, S>::ComputeContinuousPvsDifference(Pvs<T, S> &b, 
    238                                                                            float &pvsReduction, 
    239                                                                            float &pvsEnlargement) 
     260                                                                                  float &pvsReduction, 
     261                                                                                  float &pvsEnlargement) 
    240262{ 
    241263        pvsReduction = 0.0f; 
    242264        pvsEnlargement = 0.0f; 
     265 
    243266        // Uses sum of log differences, which corresponds to entropy 
    244         std::vector<pair<T, S> >::iterator it; 
     267        std::vector<PvsEntry<T, S> >::iterator it; 
    245268 
    246269        for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it)  
    247270        { 
    248                 float bSumPdf = (*it).second.mSumPdf; 
     271                float bSumPdf = (*it).mData.mSumPdf; 
    249272                float aSumPdf = 0.0f; 
    250                 S *data = Find((*it).first);             
    251  
    252                 if (data)  
     273 
     274                vector<PvsEntry<T, S> >::iterator oit = Find((*it).mObject);             
     275 
     276                const bool entryFound = (it != mEntries.end()) && ((*it).mObject == (*oit).mObject); 
     277 
     278                if (entryFound) 
    253279                { 
    254                         aSumPdf = data->mSumPdf; 
     280                        aSumPdf = (*it).mData.mSumPdf; 
     281 
    255282                        // mark this entry as processed to avoid double counting 
    256                         data->mSumPdf = -aSumPdf; 
     283                        (*it).mData.mSumPdf = -aSumPdf; 
    257284                } 
    258285 
    259286#if 0 
    260                 float diff = bSumPdf - aSumPdf; 
     287                const float diff = bSumPdf - aSumPdf; 
    261288 
    262289                if (diff > 0.0f) { 
     
    266293                } 
    267294#else 
    268                 if (!data) 
     295                if (!entryFound) 
    269296                        pvsEnlargement += 1.0f; 
    270297#endif 
    271298        } 
    272299 
    273         for (it = mEntries.begin(); it != mEntries.end(); ++ it) { 
    274                 float aSumPdf = (*it).second.mSumPdf; 
     300        for (it = mEntries.begin(); it != mEntries.end(); ++ it)  
     301        { 
     302                float aSumPdf = (*it).mData.mSumPdf; 
    275303                float bSumPdf = 0.0f; 
    276304                if (aSumPdf < 0.0f) { 
     305                 
    277306                        // this entry was already accounted for! 
    278307                        // just revert it back 
    279                         (*it).second.mSumPdf = -aSumPdf; 
     308                        (*it).mData.mSumPdf = -aSumPdf; 
    280309                } else { 
    281                         S *data = b.Find((*it).first); 
    282                         if (data) { 
    283                                 bSumPdf = data->mSumPdf; 
     310                        vector<PvsEntry<T, S> >::iterator oit = b.Find((*it).mObject); 
     311 
     312                        const bool entryFound = (it != mEntries.end()) && ((*it).mObject == (*oit).mObject); 
     313                         
     314                        if (entryFound) { 
     315                                bSumPdf = (*oit).mData.mSumPdf; 
    284316                        } 
    285317#if 0 
    286                         float diff = bSumPdf - aSumPdf; 
     318                        const float diff = bSumPdf - aSumPdf; 
    287319 
    288320                        if (diff > 0.0f) { 
     
    293325 
    294326#else 
    295                         if (!data)  
     327                        if (!entryFound)  
    296328                                pvsReduction += 1.0f; 
    297329#endif 
     
    306338        int dif = 0; 
    307339 
    308         std::vector<pair<T, S> >::const_iterator it; 
     340        std::vector<PvsEntry<T, S> >::const_iterator it; 
    309341 
    310342        for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it) 
    311343        { 
    312                 S data = Find((*it).first);              
    313                 if (!data) ++ dif; 
     344                std::vector<PvsEntry<T, S> >::const_iterator bit = Find((*it).first);            
     345                if (bit == mEntries.end()) ++ dif; 
    314346        } 
    315347 
     
    317349} 
    318350 
    319 template <typename T, typename S> void Pvs<T, S>::Merge(const Pvs<T, S> &a) 
    320 { 
    321 #if TODO 
     351 
     352template <typename T, typename S>  
     353void Pvs<T, S>::MergeInPlace(const Pvs<T, S> &a) 
     354{ 
     355    const int samples = mSamples + a.mSamples; 
     356 
     357        ObjectPvs interPvs; 
     358         
     359        Merge(interPvs, *this, a); 
     360         
     361        mEntries.reserve(interPvs.GetSize()); 
     362        mEntries = interPvs.mEntries; 
     363 
     364        mSamples = samples; 
     365} 
     366 
     367 
     368template <typename T, typename S> 
     369void Pvs<T, S>::Merge(Pvs<T, S> &mergedPvs, const Pvs<T, S> &a, const Pvs<T, S> &b) 
     370{ 
     371        std::vector<PvsEntry<T, S> >::const_iterator ait = a.mEntries.begin(), ait_end = a.mEntries.end(); 
     372        std::vector<PvsEntry<T, S> >::const_iterator bit = b.mEntries.begin(), bit_end = b.mEntries.end(); 
     373 
     374        while (1) 
     375        { 
     376                for (; (ait != ait_end) && ((*ait).mObject < (*bit).mObject); ++ ait) 
     377                { 
     378                        if ((*ait).mObject != (*bit).mObject) 
     379                                mergedPvs.mEntries.push_back(*ait); 
     380                } 
     381 
     382                for (; (bit != bit_end) && ((ait == ait_end) || ((*bit).mObject <= (*bit).mObject)); ++ bit) 
     383                { 
     384                        if ((*ait).mObject == (*bit).mObject) 
     385                        { 
     386                                PvsData newData((*ait).mData.mSumPdf + (*bit).mData.mSumPdf); 
     387                                PvsEntry<T, S> entry((*ait).mObject, newData); 
     388                                mergedPvs.mEntries.push_back(entry); 
     389                        } 
     390                        else 
     391                        { 
     392                                mergedPvs.mEntries.push_back(*bit); 
     393                        } 
     394                } 
     395        } 
     396} 
     397 
     398 
     399/*template <typename T, typename S> void Pvs<T, S>::QuickMerge(const Pvs<T, S> &a) 
     400{ 
    322401        const int samples = mSamples + a.mSamples; 
    323402 
    324         std::vector<pair<T, S>> >::const_iterator it; 
    325  
    326         for (it = a.mEntries.begin(); it != a.mEntries.end(); ++ it) 
    327         { 
    328                 AddSample((*it).first, (*it).second.mSumPdf); 
     403        std::vector<PvsEntry<T, S>> >::const_iterator it; 
     404 
     405        for (it = mEntries.begin(); it != mEntries.end(); ++ it) 
     406        { 
     407                it->first->Mail(); 
     408        } 
     409 
     410    for (it = a.mEntries.begin(); it != a.mEntries.end(); ++ it) 
     411        { 
     412                if (!it->first->Mailed()) 
     413                { 
     414                        mEntries.push_back(*it); 
     415                } 
    329416        } 
    330417 
    331418        mSamples = samples; 
    332 #endif 
    333 } 
     419}*/ 
    334420 
    335421 
     
    341427 
    342428template <typename T, typename S>  
    343 S *Pvs<T, S>::Find(T sample) 
    344 { 
    345 #if TODO 
    346   std::vector<pair<T, S>, LtSample<T> >::iterator i = mEntries.find(sample); 
    347  
    348   if (i != mEntries.end())  
    349   { 
    350           return &(*i).second; 
    351   }  
    352   else 
    353   { 
    354           return NULL; 
    355   } 
    356 #else 
    357 return NULL; 
    358 #endif 
    359 } 
    360  
    361 template <typename T, typename S> 
    362 void Pvs<T, S>::GetData(const int index, 
    363                                          T &entry, 
    364                                          S &data) 
    365 { 
    366         std::vector<pair<T, S> >::iterator i = mEntries.begin(); 
     429typename std::vector<PvsEntry<T, S> >::iterator Pvs<T, S>::Find(T sample) 
     430{ 
     431        PvsEntry<T, S> dummy(sample, PvsData()); 
     432        vector<PvsEntry<T, S> >::iterator it = lower_bound(mEntries.begin(), mEntries.end(), dummy); 
     433                                 
     434        return it; 
     435} 
     436 
     437 
     438template <typename T, typename S> 
     439void Pvs<T, S>::GetData(const int index, T &entry, S &data) 
     440{ 
     441        std::vector<PvsEntry<T, S> >::iterator i = mEntries.begin(); 
    367442        for (int k = 0; k != index && i != mEntries.end(); ++ i, ++ k); 
    368443 
     
    373448 
    374449template <typename T, typename S> 
    375 float 
    376 Pvs<T, S>::AddSample(T sample, const float pdf) 
    377 { 
    378 #if TODO 
     450float Pvs<T, S>::AddSample(T sample, const float pdf) 
     451{ 
    379452        ++ mSamples; 
    380         S *data = Find(sample); 
    381  
    382         if (data)   
    383         { 
     453        std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
     454 
     455        if ((it != mEntries.end()) && ((*it).mObject == sample)) 
     456        { 
     457                S &data = (*it).mData; 
     458                data.mSumPdf += pdf; 
     459 
     460                return data.mSumPdf; 
     461        } 
     462        else  
     463        { 
     464                PvsEntry<T, S> entry(sample, pdf); 
     465                 
     466                mEntries.insert(it, entry); 
     467                return pdf; 
     468        } 
     469} 
     470 
     471 
     472template <typename T, typename S> 
     473typename vector< PvsEntry<T, S> >::iterator Pvs<T, S>::AddSample2(T sample, const float pdf) 
     474{ 
     475        ++ mSamples; 
     476        std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
     477 
     478        if ((it != mEntries.end()) && ((*it).first == T)) 
     479        { 
     480                S &data = (*it).second; 
    384481                data->mSumPdf += pdf; 
    385                 return data->mSumPdf; 
    386482        } 
    387483        else  
    388484        { 
    389                 mEntries[sample] = S(pdf); 
    390                 return pdf; 
    391         } 
    392 #else 
    393 return 0; 
    394 #endif 
    395 } 
    396  
    397  
    398 template <typename T, typename S> 
    399 S * Pvs<T, S>::AddSample2(T sample, const float pdf) 
    400 { 
    401   mSamples++; 
    402   S *data = Find(sample); 
    403    
    404   if (data)   
    405         { 
    406           data->mSumPdf += pdf; 
    407         } 
    408   else  
    409         { 
    410           mEntries[sample] = S(pdf); 
    411           data = Find(sample); 
    412         } 
    413    
    414   return data; 
    415 } 
     485                PvsEntry<T, S> entry(sample, pdf); 
     486                mEntries.insert(it, entry); 
     487        } 
     488 
     489        return it; 
     490} 
     491 
    416492 
    417493template <typename T, typename S>  
    418494bool Pvs<T, S>::AddSample(T sample, 
    419                                   const float pdf, 
    420                                   float &contribution) 
     495                                                  const float pdf, 
     496                                                  float &contribution) 
    421497{ 
    422498        ++ mSamples; 
    423     S *data = Find(sample); 
    424 #if TODO 
    425         if (data)   
    426         { 
    427                 data->mSumPdf += pdf; 
    428                 contribution = pdf / data->mSumPdf; 
     499 
     500        std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
     501 
     502        if ((it != mEntries.end()) && ((*it).mObject == sample)) 
     503        { 
     504                S &data = (*it).mData; 
     505 
     506                data.mSumPdf += pdf; 
     507                contribution = pdf / data.mSumPdf; 
     508 
    429509                return false; 
    430510        } 
    431         else { 
    432                 mEntries[sample] = S(pdf); 
     511        else  
     512        { 
     513                PvsEntry<T, S> entry(sample, pdf); 
     514 
     515                mEntries.insert(it, entry); 
     516                contribution = 1.0f; 
     517 
     518                return true; 
     519        } 
     520} 
     521 
     522 
     523template <typename T, typename S> 
     524bool Pvs<T, S>::GetSampleContribution(T sample, 
     525                                                                          const float pdf, 
     526                                                                          float &contribution)  
     527{ 
     528        std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
     529 
     530        if (it != mEntries.end() && ((*it).mObject == sample))   
     531        { 
     532                S &data = (*it).mData; 
     533                contribution = pdf / (data.mSumPdf + pdf); 
     534                return false; 
     535        } 
     536        else  
     537        { 
    433538                contribution = 1.0f; 
    434539                return true; 
    435540        } 
    436 #else 
     541} 
     542 
     543 
     544template <typename T, typename S> 
     545bool Pvs<T, S>::RemoveSample(T sample, const float pdf) 
     546{ 
     547        -- mSamples; 
     548 
     549        std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
     550 
     551        if (it == mEntries.end()) 
     552                return false; 
     553 
     554        S &data = (*it).mData; 
     555 
     556        data.mSumPdf -= pdf; 
     557 
     558        if (data.mSumPdf <= 0.0f) 
     559        { 
     560                mEntries.erase(it); 
     561        } 
     562 
    437563        return true; 
    438 #endif 
    439 } 
    440  
    441 template <typename T, typename S> 
    442 bool 
    443 Pvs<T, S>::GetSampleContribution(T sample, 
    444                                                                  const float pdf, 
    445                                                                  float &contribution)  
    446 { 
    447   S *data = Find(sample); 
    448    
    449   if (data)  { 
    450         contribution = pdf / (data->mSumPdf + pdf); 
    451         return false; 
    452   } 
    453   else { 
    454         contribution = 1.0f; 
    455         return true; 
    456   } 
    457 } 
    458  
    459 template <typename T, typename S> 
    460 bool Pvs<T, S>::RemoveSample(T sample, 
    461                                                          const float pdf) 
    462 { 
    463   -- mSamples; 
    464 #if TODO 
    465   std::vector<pair<T, S> >::iterator it = mEntries.find(sample); 
    466    
    467   if (it == mEntries.end()) 
    468         return false; 
    469    
    470   S *data = &(*it).second; 
    471    
    472   data->mSumPdf -= pdf; 
    473  
    474   if (data->mSumPdf <= 0.0f) 
    475   { 
    476           mEntries.erase(it); 
    477   } 
    478 #endif 
    479   return true; 
    480 } 
    481  
    482 template <typename T, typename S> 
    483 int Pvs<T, S>::AddPvs(const Pvs<T, S> &pvs) 
    484 { 
    485   int samples = mSamples + pvs.mSamples; 
    486   std::vector<pair<T, S> >:: 
    487         const_iterator it, it_end = pvs.mEntries.end(); 
    488    
    489   float contri; 
    490   // output PVS of view cell 
    491   for (it = pvs.mEntries.begin(); it != it_end; ++ it) 
    492   {      
    493           AddSample((*it).first, (*it).second.mSumPdf, contri); 
    494   } 
    495  
    496   mSamples = samples; 
    497  
    498   return GetSize(); 
    499 } 
    500   
     564} 
     565 
     566 
    501567template <typename T, typename S> 
    502568int Pvs<T, S>::SubtractPvs(const Pvs<T, S> &pvs) 
    503569{ 
    504570        const int samples = mSamples - pvs.mSamples; 
    505 #if TODO 
    506         std::vector<pair<T, S> >:: 
     571 
     572        std::vector<PvsEntry<T, S> >:: 
    507573                const_iterator it, it_end = pvs.mEntries.end(); 
    508574 
    509575        // output PVS of view cell 
    510576        for (it = pvs.mEntries.begin(); it != it_end; ++ it)  
    511                 RemoveSample((*it).first, (*it).second.mSumPdf); 
     577                RemoveSample((*it).mObject, (*it).mData.mSumPdf); 
    512578 
    513579        mSamples = samples; 
    514 #endif 
     580 
    515581        return GetSize(); 
    516582} 
    517583 
     584 
    518585template <typename T, typename S> 
    519586void Pvs<T, S>::CollectEntries(std::vector<T> &entries) 
    520587{ 
    521         std::vector<pair<T, S> >:: 
     588        std::vector<PvsEntry<T, S> >:: 
    522589                const_iterator it, it_end = mEntries.end(); 
    523590 
     
    527594} 
    528595 
     596 
    529597template <typename T, typename S> 
    530598void Pvs<T, S>::NormalizeMaximum() 
    531599{ 
    532   std::vector<pair<T, S> >:: 
    533         const_iterator it, it_end = mEntries.end(); 
    534  
    535   float maxPdfSum = -1.0f; 
    536  
    537   // output PVS of view cell 
    538   for (it = mEntries.begin(); it != it_end; ++ it) { 
    539         float sum = (*it)->second.sumPdf; 
    540         if (sum > maxSum) 
    541           maxSum = sum; 
    542   } 
    543  
    544   maxSum = 1.0f / maxSum; 
    545  
    546   for (it = mEntries.begin(); it != it_end; ++ it) { 
    547         (*it)->second.sumPdf *= maxSum; 
    548   } 
    549    
     600        std::vector<PvsEntry<T, S> >:: 
     601                const_iterator it, it_end = mEntries.end(); 
     602 
     603        float maxPdfSum = -1.0f; 
     604 
     605        // output PVS of view cell 
     606        for (it = mEntries.begin(); it != it_end; ++ it) { 
     607                float sum = (*it)->second.sumPdf; 
     608                if (sum > maxSum) 
     609                        maxSum = sum; 
     610        } 
     611 
     612        maxSum = 1.0f / maxSum; 
     613 
     614        for (it = mEntries.begin(); it != it_end; ++ it) { 
     615                (*it)->second.sumPdf *= maxSum; 
     616        } 
     617 
    550618} 
    551619 
     
    562630{ 
    563631        return sizeof(T) + sizeof(S); 
     632} 
     633 
     634 
     635template <typename T, typename S> 
     636float Pvs<T, S>::GetPvsHomogenity(Pvs<T, S> &pvs)  
     637{ 
     638        float pvsReduction, pvsEnlargement; 
     639 
     640        ComputeContinuousPvsDifference(pvs,     pvsReduction, pvsEnlargement); 
     641 
     642        return pvsReduction + pvsEnlargement; 
    564643} 
    565644 
     
    590669//-- typedefs 
    591670 
    592 //typedef std::map<KdNode *, PvsData, LtSample<KdNode *> > KdPvsMap; 
    593 //typedef std::map<Intersectable *, PvsData, LtSample<Intersectable *> > ObjectPvsEntries; 
    594 //typedef std::map<ViewCell *, MailablePvsData, LtSample<ViewCell *> > ViewCellPvsEntries; 
    595  
    596  
    597 typedef std::vector<pair<Intersectable *, PvsData> > ObjectPvsEntries; 
    598  
     671typedef std::vector<PvsEntry<Intersectable *, PvsData> > ObjectPvsEntries; 
    599672typedef Pvs<ViewCell *, MailablePvsData> ViewCellPvs; 
    600673 
  • GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj

    r1733 r1740  
    206206                                Name="VCLinkerTool" 
    207207                                AdditionalDependencies="xerces-c_2.lib glew32.lib zdll.lib zziplib.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib Preprocessor.lib RTScene.lib RTWorld.lib QtCore4.lib qtmain.lib QtOpenGL4.lib Qt3Support4.lib QtTest4.lib QtGui4.lib QtGlRenderer.lib" 
    208                                 OutputFile="../bin/release/Preprocessor2.exe" 
     208                                OutputFile="../bin/release/Preprocessor.exe" 
    209209                                LinkIncremental="1" 
    210210                                AdditionalLibraryDirectories="..\src\GL;..\lib\release;..\..\Preprocessing\lib\release;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib;..\MultiLevelRayTracing\RTScene\Release;..\MultiLevelRayTracing\RTWorld\Release;&quot;$(QTDIR)\lib&quot;;.\QtGlRenderer\Release" 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1738 r1740  
    6464        for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 
    6565        { 
    66                 if (!(*it).first->Mailed()) 
    67                 { 
    68                         (*it).first->Mail(); 
     66                if (!(*it).mObject->Mailed()) 
     67                { 
     68                        (*it).mObject->Mail(); 
    6969                        ++ count; 
    7070                } 
     
    8888        for (it = pvs1.mEntries.begin(); it != it_end; ++ it) 
    8989        { 
    90                 (*it).first->Mail(); 
     90                (*it).mObject->Mail(); 
    9191        } 
    9292 
     
    9696        for (it = pvs2.mEntries.begin(); it != it_end; ++ it) 
    9797        { 
    98                 Intersectable *obj = (*it).first; 
     98                Intersectable *obj = (*it).mObject; 
    9999                if (!obj->Mailed()) 
    100100                        ++ pvs; 
     
    837837        for (it = pvs1.mEntries.begin(); it != it_end; ++ it) 
    838838        { 
    839                 Intersectable *obj = (*it).first; 
     839                Intersectable *obj = (*it).mObject; 
    840840 
    841841                obj->Mail(); 
     
    848848        for (it = pvs2.mEntries.begin(); it != it_end; ++ it) 
    849849        { 
    850                 Intersectable *obj = (*it).first; 
     850                Intersectable *obj = (*it).mObject; 
    851851 
    852852                // test if object already considered     
     
    11521152inline int AddedPvsSize(ObjectPvs pvs1, const ObjectPvs &pvs2) 
    11531153{ 
    1154         return pvs1.AddPvs(pvs2); 
     1154        ObjectPvs interPvs; 
     1155        ObjectPvs::Merge(interPvs, pvs1, pvs2); 
     1156 
     1157        return (int)interPvs.GetSize(); 
    11551158} 
    11561159 
     
    12421245        // TODO change 
    12431246        vc1->GetPvs().SubtractPvs(leaf->GetPvs()); 
    1244         vc2->GetPvs().AddPvs(leaf->GetPvs()); 
    1245          
     1247         
     1248        ObjectPvs interPvs; 
     1249        ObjectPvs::Merge(interPvs, vc2->GetPvs(), leaf->GetPvs()); 
     1250        vc2->SetPvs(interPvs); 
     1251 
    12461252        if (mUseAreaForPvs) 
    12471253        { 
     
    16511657                for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
    16521658                { 
    1653                         Intersectable *obj = (*oit).first; 
     1659                        Intersectable *obj = (*oit).mObject; 
    16541660                        if ((cit == interior->mChildren.begin()) && !obj->Mailed()) 
    16551661                                obj->Mail(); 
     
    16731679                for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
    16741680                {                
    1675                         if ((*oit).first->Mailed((int)interior->mChildren.size())) 
     1681                        if ((*oit).mObject->Mailed((int)interior->mChildren.size())) 
    16761682                        {        
    1677                                 interior->GetPvs().AddSample((*oit).first, (*oit).second.mSumPdf); 
     1683                                interior->GetPvs().AddSample((*oit).mObject, (*oit).mData.mSumPdf); 
    16781684                        } 
    16791685                } 
     
    16881694                for (cit = interior->mChildren.begin(); cit != cit_end; ++ cit) 
    16891695                { 
    1690                         if (!(*cit)->GetPvs().RemoveSample((*oit).first, Limits::Infinity)) 
     1696                        if (!(*cit)->GetPvs().RemoveSample((*oit).mObject, Limits::Infinity)) 
    16911697                        { 
    16921698                                Debug << "should not come here!" << endl; 
     
    17171723        { 
    17181724                root = root->GetParent(); 
    1719                 pvs.AddPvs(root->GetPvs()); 
     1725                pvs.MergeInPlace(root->GetPvs()); 
    17201726        } 
    17211727 
     
    17301736 
    17311737                // add newly found pvs to merged pvs 
    1732                 pvs.AddPvs(vc->GetPvs()); 
     1738                ObjectPvs interPvs; 
     1739                pvs.MergeInPlace(vc->GetPvs()); 
    17331740 
    17341741                if (!vc->IsLeaf()) // interior cells: go down to leaf level 
     
    17791786                for (oit = (*it)->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
    17801787                { 
    1781                         Intersectable *intersect = (*oit).first; 
     1788                        Intersectable *intersect = (*oit).mObject; 
    17821789 
    17831790                        if (!intersect->Mailed()) 
    17841791                        { 
    17851792                                intersect->Mail(); 
    1786                                 newPvs.AddSample(intersect, (*oit).second.mSumPdf); 
     1793                                newPvs.AddSample(intersect, (*oit).mData.mSumPdf); 
    17871794                        } 
    17881795                } 
     
    18291836                for (oit = (*it)->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
    18301837                { 
    1831                         Intersectable *intersect = (*oit).first; 
     1838                        Intersectable *intersect = (*oit).mObject; 
    18321839 
    18331840                        if (!intersect->Mailed()) 
     
    20502057 
    20512058 
    2052 void ViewCellsTree::PropagatePvs(ViewCell *vc) 
     2059void ViewCellsTree::PropagatePvs(ViewCell *root) 
    20532060{        
    2054         ViewCell *viewCell = vc; 
     2061        ViewCell *viewCell = root; 
    20552062 
    20562063        // propagate pvs up 
    20572064        while (viewCell->GetParent()) 
    20582065        { 
    2059                 viewCell->GetParent()->GetPvs().Merge(vc->GetPvs()); 
     2066                ObjectPvs mergedPvs; 
     2067                viewCell->GetParent()->GetPvs().MergeInPlace(root->GetPvs()); 
     2068 
    20602069                viewCell = viewCell->GetParent(); 
    20612070        } 
    20622071 
    2063         if (vc->IsLeaf()) 
     2072        if (root->IsLeaf()) 
    20642073                return; 
    20652074 
    20662075        // propagate pvs to the leaves 
    20672076        stack<ViewCell *> tstack; 
    2068         tstack.push(vc); 
     2077        tstack.push(root); 
    20692078 
    20702079        while (!tstack.empty()) 
     
    20732082                tstack.pop(); 
    20742083 
    2075                 if (viewCell != vc) 
    2076                 { 
    2077                         viewCell->GetPvs().Merge(vc->GetPvs()); 
     2084                if (viewCell != root) 
     2085                { 
     2086                        viewCell->GetPvs().MergeInPlace(root->GetPvs()); 
    20782087                } 
    20792088 
     
    21052114                tqueue.pop(); 
    21062115 
    2107                 // save the view cells if it is a leaf or if enough view cells have already been traversed 
    2108                 // because of the priority queue, this will be the optimal set of v 
     2116                // save the view cells if it is a leaf or if enough view cells  
     2117                // have already been traversed because of the priority queue,  
     2118                // this will be the optimal set of v 
    21092119                if (!vc->IsLeaf())  
    21102120                {        
     
    23432353        for (it = viewCell->GetPvs().mEntries.begin(); it != it_end; ++ it) 
    23442354        { 
    2345                 Intersectable *obj = (*it).first; 
     2355                Intersectable *obj = (*it).mObject; 
    23462356                // hack: just output full pvs 
    23472357                if (obj->Type() == Intersectable::BVH_INTERSECTABLE) 
     
    23592369                else 
    23602370                { 
    2361                         stream << (*it).first->GetId() << " "; 
     2371                        stream << (*it).mObject->GetId() << " "; 
    23622372                } 
    23632373        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1738 r1740  
    16471647 
    16481648        vc->GetPvs().Clear(); 
    1649         vc->GetPvs() = left->GetPvs(); 
    1650  
    1651         // merge pvs of right cell 
    1652         vc->GetPvs().Merge(right->GetPvs()); 
     1649        ObjectPvs::Merge(vc->GetPvs(), left->GetPvs(), right->GetPvs()); 
    16531650 
    16541651        // set only links to child (not from child to parent, maybe not wished!!) 
     
    16661663{ 
    16671664        ViewCellInterior *vc = new ViewCellInterior(); 
    1668  
    16691665        ViewCellContainer::const_iterator it, it_end = children.end(); 
    16701666 
    16711667        for (it = children.begin(); it != it_end; ++ it) 
    16721668        { 
    1673                 // merge pvs 
    1674                 vc->GetPvs().Merge((*it)->GetPvs()); 
     1669                vc->GetPvs().MergeInPlace((*it)->GetPvs()); 
     1670         
    16751671                vc->mChildren.push_back(*it); 
    16761672        } 
     
    23992395                        ViewCellContainer::const_iterator it = viewCells.begin(), it_end = viewCells.end(); 
    24002396 
    2401                         int i; 
    2402                         for (i=0; it != it_end; ++ it, ++ i) { 
     2397                        for (; it != it_end; ++ it)  
     2398                        { 
     2399                                ObjectPvs interPvs; 
    24032400                                //cout<<"v"<<i<<" pvs="<<(*it)->GetPvs().mEntries.size()<<endl; 
    2404                                 pvs.Merge((*it)->GetPvs()); 
     2401                                ObjectPvs::Merge(interPvs, pvs, (*it)->GetPvs()); 
     2402 
     2403                                pvs = interPvs; 
    24052404                        } 
    2406                 } else { 
     2405                } else  
     2406                { 
    24072407                        PrVs prvs; 
    24082408                        AxisAlignedBox3 box = GetViewCellBox(viewCell); 
     
    24132413                        DeleteLocalMergeTree(prvs.mViewCell); 
    24142414                } 
    2415         } else 
     2415        }  
     2416        else 
     2417        { 
    24162418                pvs = viewCell->GetPvs(); 
     2419        } 
    24172420 
    24182421        if (spatialFilterSize >=0.0f) 
     
    24792482  for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++ oi)  
    24802483        { 
    2481           Intersectable *object = (*oi).first; 
     2484          Intersectable *object = (*oi).mObject; 
    24822485      object->Mail(); 
    24832486        } 
     
    24872490  // now go through the pvs again 
    24882491  for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++oi) { 
    2489         Intersectable *object = (*oi).first; 
     2492        Intersectable *object = (*oi).mObject; 
    24902493 
    24912494        //      Vector3 center = object->GetBox().Center(); 
     
    25112514  } 
    25122515  //  cout<<"nPvs size = "<<nPvsSize<<endl; 
    2513   pvs.Merge(nPvs); 
     2516 
     2517  pvs.MergeInPlace(nPvs); 
    25142518} 
    25152519 
     
    25302534  // first mark all object from this pvs 
    25312535  for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++ oi) { 
    2532         Intersectable *object = (*oi).first; 
     2536        Intersectable *object = (*oi).mObject; 
    25332537        object->Mail(); 
    25342538  } 
     
    25512555  float sumRadius = 0.0f; 
    25522556  for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++oi, pvsSize++) { 
    2553         Intersectable *object = (*oi).first; 
     2557        Intersectable *object = (*oi).mObject; 
    25542558        // compute filter size based on the distance and the numebr of samples 
    25552559        AxisAlignedBox3 box = object->GetBox(); 
     
    25582562        float globalRadius = distance*globalC; 
    25592563 
    2560         int objectSamples = (int)(*oi).second.mSumPdf; 
     2564        int objectSamples = (int)(*oi).mData.mSumPdf; 
    25612565        float localRadius = MAX_FLOAT; 
    25622566         
     
    25912595          if ((*it) != viewCell) { 
    25922596                //cout<<"v"<<i<<" pvs="<<(*it)->GetPvs().mEntries.size()<<endl; 
    2593                 pvs.Merge((*it)->GetPvs()); 
     2597                  pvs.MergeInPlace((*it)->GetPvs()); 
    25942598          } 
    25952599 
     
    26022606   
    26032607  for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++oi) { 
    2604         Intersectable *object = (*oi).first; 
     2608        Intersectable *object = (*oi).mObject; 
    26052609        // compute filter size based on the distance and the numebr of samples 
    26062610        AxisAlignedBox3 box = object->GetBox(); 
     
    26102614 
    26112615         
    2612         int objectSamples = (int)(*oi).second.mSumPdf; 
     2616        int objectSamples = (int)(*oi).mData.mSumPdf; 
    26132617        float localRadius = MAX_FLOAT; 
    26142618        if (objectSamples > MIN_LOCAL_SAMPLES) 
     
    26392643  } 
    26402644  cout<<"nPvs size = "<<nPvsSize<<endl; 
    2641   pvs.Merge(nPvs); 
     2645   
     2646  pvs.MergeInPlace(nPvs); 
     2647 
    26422648  Intersectable::NewMail(); 
    26432649} 
     
    27842790                for (pit = (*oit).mEntries.begin(); pit != pit_end; ++ pit) 
    27852791                { 
    2786                         Intersectable *intersect = (*pit).first; 
     2792                        Intersectable *intersect = (*pit).mObject; 
    27872793 
    27882794                        if (!intersect->Mailed()) 
    27892795                        { 
    2790                                 pvs.AddSample(intersect, (*pit).second.mSumPdf); 
     2796                                pvs.AddSample(intersect, (*pit).mData.mSumPdf); 
    27912797                                intersect->Mail(); 
    27922798                        } 
     
    32733279                        for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 
    32743280                        {                
    3275                                 Intersectable *intersect = (*oit).first; 
     3281                                Intersectable *intersect = (*oit).mObject; 
    32763282                                 
    32773283                                if (!intersect->Mailed()) 
     
    37733779                        for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 
    37743780                        { 
    3775                                 Intersectable *intersect = (*it).first; 
     3781                                Intersectable *intersect = (*it).mObject; 
    37763782                                if (!intersect->Mailed()) 
    37773783                                { 
     
    46224628                        for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 
    46234629                        {                
    4624                                 Intersectable *intersect = (*oit).first; 
     4630                                Intersectable *intersect = (*oit).mObject; 
    46254631                                 
    46264632                                if (!intersect->Mailed()) 
     
    47454751                else 
    47464752                { 
    4747                         (*it).second.Merge(sample.mPvs); 
     4753                        (*it).second.MergeInPlace(sample.mPvs); 
    47484754                } 
    47494755        } 
     
    49804986 
    49814987 
     4988VspOspViewCellsManager::VspOspViewCellsManager(ViewCellsTree *vcTree, const string &hierarchyType) 
     4989: ViewCellsManager(vcTree) 
     4990{ 
     4991        Environment::GetSingleton()->GetIntValue("Hierarchy.Construction.samples", mInitialSamples); 
     4992 
     4993        mHierarchyManager = CreateHierarchyManager(hierarchyType); 
     4994        mHierarchyManager->SetViewCellsManager(this); 
     4995        mHierarchyManager->SetViewCellsTree(mViewCellsTree); 
     4996} 
     4997 
     4998 
    49824999VspOspViewCellsManager::VspOspViewCellsManager(ViewCellsTree *vcTree, HierarchyManager *hm) 
    49835000: ViewCellsManager(vcTree), mHierarchyManager(hm) 
     
    49905007 
    49915008 
     5009HierarchyManager *VspOspViewCellsManager::CreateHierarchyManager(const string &hierarchyType) 
     5010{ 
     5011        HierarchyManager *hierarchyManager; 
     5012 
     5013        if (strcmp(hierarchyType.c_str(), "osp") == 0) 
     5014        { 
     5015                Debug << "hierarchy manager: osp" << endl; 
     5016                hierarchyManager = new HierarchyManager(HierarchyManager::KD_BASED_OBJ_SUBDIV); 
     5017        } 
     5018        else if (strcmp(hierarchyType.c_str(), "bvh") == 0) 
     5019        { 
     5020                Debug << "hierarchy manager: bvh" << endl; 
     5021                hierarchyManager = new HierarchyManager(HierarchyManager::BV_BASED_OBJ_SUBDIV); 
     5022        } 
     5023        else // only view space partition 
     5024        { 
     5025                Debug << "hierarchy manager: obj" << endl; 
     5026                hierarchyManager = new HierarchyManager(HierarchyManager::NO_OBJ_SUBDIV); 
     5027        } 
     5028 
     5029        return hierarchyManager; 
     5030} 
     5031 
     5032 
    49925033VspOspViewCellsManager::~VspOspViewCellsManager() 
    49935034{ 
     5035        DEL_PTR(mHierarchyManager); 
    49945036} 
    49955037 
     
    54535495                        for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 
    54545496                        {                
    5455                                 Intersectable *intersect = (*oit).first; 
     5497                                Intersectable *intersect = (*oit).mObject; 
    54565498                                if (!intersect->Mailed()) 
    54575499                                { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1737 r1740  
    10471047class VspOspViewCellsManager: public ViewCellsManager 
    10481048{ 
    1049  
     1049        friend class ViewCellsParseHandlers; 
    10501050public: 
    10511051 
    1052         VspOspViewCellsManager(ViewCellsTree *vcTree, HierarchyManager *hm); 
     1052        VspOspViewCellsManager(ViewCellsTree *vcTree, const string &hierarchyType); 
    10531053         
    10541054        ~VspOspViewCellsManager(); 
     
    11201120protected: 
    11211121 
     1122        VspOspViewCellsManager(ViewCellsTree *vcTree, HierarchyManager *hm); 
     1123         
    11221124#if 1//TEST_EVALUATION 
    11231125        virtual void EvalViewCellPartition(); 
     
    11481150        void ExportPvs(const ObjectContainer &objects, const VssRayContainer &rays); 
    11491151 
     1152        /** Returns a hierarchy manager of the given name. 
     1153        */ 
     1154        static HierarchyManager *CreateHierarchyManager(const string &name); 
     1155 
    11501156        //void ExportStats(const string &mergeStats); 
    11511157 
Note: See TracChangeset for help on using the changeset viewer.