Changeset 2117


Ignore:
Timestamp:
02/15/07 13:19:17 (17 years ago)
Author:
mattausch
Message:

implemented bit pvs (warnin: only worjs for preprocessing)

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

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/BitVectorPvs.h

    r2116 r2117  
    1313typedef vector<bool> bit_vector; 
    1414 
     15 
    1516/** Iterator over a bitvector pvs. 
    1617*/ 
    17 #if 0 
    1818template<typename T, typename S> 
    1919class BitVectorPvsIterator 
     
    2121public: 
    2222         
    23         HashPvsIterator<T, S>() {} 
    24  
    25         HashPvsIterator<T, S>(const typename HASH_SET::const_iterator &itCurrent, 
    26                                                   const typename HASH_SET::const_iterator &itEnd): 
    27         mItCurrent(itCurrent), mItEnd(itEnd) 
     23        BitVectorPvsIterator<T, S>(const typename bit_vector::const_iterator &itBegin, 
     24                                                           const typename bit_vector::const_iterator &itEnd 
     25                                                           //,const int lastElement 
     26                                                           ): 
     27        mItCurrent(itBegin), mItEnd(itEnd), mDistance(0)//, mLastElement 
    2828        { 
    2929        } 
     
    3131        bool HasMoreEntries() const  
    3232        { 
    33                 return (mItCurrent != mItEnd); 
    34         } 
    35  
    36         PvsEntry<T, S> Next() 
     33                // find next element in bit vector 
     34                // warning: has to do traversal each time 
     35                typename bit_vector::const_iterator itNext = mItCurrent; 
     36 
     37                for (;(itNext != mItEnd) && !(*itNext); ++ itNext); 
     38 
     39                return (itNext != mItEnd); 
     40        } 
     41 
     42        T Next(S &pdf) 
     43        { 
     44                return Next(); 
     45        } 
     46         
     47        T Next() 
    3748        { 
    3849                // hack: create new pvs entry 
    39                 return PvsEntry<T, S>(*(mItCurrent) ++, S(0.0)); 
    40         } 
    41          
     50                for (; !(*mItCurrent); ++ mItCurrent, ++ mDistance); 
     51 
     52                T sample = sObjects[mDistance]; 
     53 
     54                ++ mDistance; 
     55                ++ mItCurrent; 
     56 
     57                return sample; 
     58        } 
     59 
     60         
     61        // vector of objects corresponding to pvs entries 
     62        static vector<T> sObjects; 
     63 
    4264private: 
    43         typename HASH_SET::const_iterator mItCurrent; 
    44         typename HASH_SET::const_iterator mItEnd; 
     65 
     66        typename bit_vector::const_iterator mItCurrent; 
     67        //typename bit_vector::const_iterator mItNext; 
     68        typename bit_vector::const_iterator mItEnd; 
     69         
     70        // note: store distance explicitly because I  
     71        // don't know how efficient 
     72        // std::distance is on specialisation of vector<bool> 
     73        int mDistance; 
    4574}; 
    46 #endif 
    47  
    48 #if 0 
     75 
     76 
    4977/** Pvs implemented as bitvector 
    5078*/ 
     
    5684public: 
    5785 
    58         //HashPvs(): mEntries((Intersectable *)100) {}; 
    59         HashPvs() {}; 
     86        BitVectorPvs(); 
    6087        //virtual ~HashPvs() {}; 
    6188 
     
    92119 
    93120        /** Finds sample in PVS. 
    94                 @param checkDirty if dirty part of the pvs should be checked for entry  
    95                 (warning: linear runtime in dirty part) 
    96                 @returns iterator on the sample if found, else the place where  
    97                 it would be added in the sorted vector. 
    98         */ 
    99         bool Find(T sample, typename HASH_SET::iterator &it); 
    100  
    101         typename HashPvsIterator<T, S> GetIterator() const; 
     121        */ 
     122        bool Find(T sample); 
     123 
     124        typename BitVectorPvsIterator<T, S> GetIterator() const; 
    102125 
    103126        /** Compute continuous PVS difference  
    104127        */ 
    105         float GetPvsHomogenity(HashPvs<T, S> &pvs); 
    106  
    107         static void Merge(HashPvs<T, S> &mergedPvs,  
    108                                           const HashPvs<T, S> &a,  
    109                                           const HashPvs<T, S> &b); 
     128        float GetPvsHomogenity(BitVectorPvs<T, S> &pvs); 
     129 
     130        static void Merge(BitVectorPvs<T, S> &mergedPvs,  
     131                                          const BitVectorPvs<T, S> &a,  
     132                                          const BitVectorPvs<T, S> &b); 
    110133 
    111134        static int GetEntrySizeByte();  
     
    121144        } 
    122145 
    123         void MergeInPlace(const HashPvs<T, S> &a) 
     146        void MergeInPlace(const BitVectorPvs<T, S> &a) 
    124147        { 
    125148                cerr << "not implemented yet" << endl; 
     
    133156        void Reserve(const int n)  
    134157        {  
     158                mEntries.reserve(n); 
     159        } 
     160 
     161        /** Sort pvs entries assume that the pvs contains unique entries 
     162        */ 
     163        void SimpleSort() 
     164        { 
    135165                // not necessary 
    136166        } 
    137167 
    138         /** Sort pvs entries assume that the pvs contains unique entries 
    139         */ 
    140         void SimpleSort() 
    141         { 
    142                 // not necessary 
    143         } 
    144  
    145         int SubtractPvs(const HashPvs<T, S> &pvs) 
     168        int SubtractPvs(const BitVectorPvs<T, S> &pvs) 
    146169        { 
    147170                cerr << "not yet implemented" << endl; 
     
    151174        /** Compute continuous PVS difference  
    152175        */ 
    153         void ComputeContinuousPvsDifference(HashPvs<T, S> &pvs,  
     176        void ComputeContinuousPvsDifference(BitVectorPvs<T, S> &pvs,  
    154177                                                                                float &pvsReduction, 
    155178                                                                                float &pvsEnlargement) 
     
    157180                cerr << "not yet implemented" << endl; 
    158181        } 
     182 
     183 
     184        static void SetPvsSize(const int pvsSize) { sPvsSize = pvsSize; }; 
     185         
    159186protected: 
    160187 
    161188        /// hash table of PVS entries 
    162         HASH_SET mEntries;  
     189        bit_vector mEntries;  
    163190 
    164191        /// Number of samples used to create the PVS 
    165192        int mSamples; 
     193 
     194public: 
     195        static int sPvsSize; 
    166196}; 
    167197 
    168198 
    169199template <typename T, typename S> 
    170 bool HashPvs<T, S>::Find(T sample, typename HASH_SET::iterator &it) 
    171 { 
    172         it = mEntries.find(sample); 
    173  
    174         // already in map 
    175         return (it != mEntries.end()); 
    176 } 
    177  
    178  
    179 template <typename T, typename S> 
    180 int HashPvs<T, S>::GetSize() const 
    181 { 
    182         return (int)mEntries.size(); 
    183 } 
    184  
    185  
    186 template <typename T, typename S> 
    187 bool HashPvs<T, S>::Empty() const 
    188 { 
    189         return mEntries.empty(); 
    190 } 
    191  
    192  
    193 template <typename T, typename S> 
    194 float HashPvs<T, S>::AddSample(T sample, const float pdf) 
    195 { 
    196         HASH_SET::iterator it; 
    197  
    198         if (Find(sample, it)) 
     200BitVectorPvs<T, S>::BitVectorPvs() 
     201{ 
     202        // initialize bit vector 
     203        mEntries.reserve(sPvsSize); 
     204        mEntries.resize(sPvsSize); 
     205 
     206        // set pvs entries to false 
     207        Clear(); 
     208} 
     209 
     210 
     211template <typename T, typename S> 
     212bool BitVectorPvs<T, S>::Find(T sample) 
     213{ 
     214        return mEntries[sample->GetId()]; 
     215} 
     216 
     217 
     218template <typename T, typename S> 
     219int BitVectorPvs<T, S>::GetSize() const 
     220{ 
     221        int size = 0; 
     222        bit_vector::const_iterator bit, bit_end = mEntries.end(); 
     223 
     224        for (bit = mEntries.begin(); bit != bit_end; ++ bit) 
     225        { 
     226                if (*bit) ++ size; 
     227        } 
     228 
     229        return size; 
     230} 
     231 
     232 
     233template <typename T, typename S> 
     234bool BitVectorPvs<T, S>::Empty() const 
     235{ 
     236        bit_vector::const_iterator bit, bit_end = mEntries.end(); 
     237 
     238        for (bit = mEntries.begin(); bit != bit_end; ++ bit) 
     239        { 
     240                if (*bit) return false; 
     241        } 
     242 
     243        return true; 
     244} 
     245 
     246 
     247template <typename T, typename S> 
     248float BitVectorPvs<T, S>::AddSample(T sample, const float pdf) 
     249{ 
     250        if (Find(sample)) 
    199251                return 0.0f; 
    200252         
    201         mEntries.insert(sample); 
     253        mEntries[sample->GetId()] = true; 
     254 
    202255        return 1.0f; 
    203256} 
     
    205258 
    206259template <typename T, typename S> 
    207 void HashPvs<T, S>::AddSampleDirty(T sample, const float pdf) 
    208 { 
    209         HASH_SET::iterator it; 
    210  
    211         // not yet in map 
    212         if (!Find(sample, it)) 
    213         { 
    214                 mEntries.insert(sample);         
    215         } 
    216 } 
    217  
    218  
    219 template <typename T, typename S> 
    220 bool HashPvs<T, S>::AddSampleDirtyCheck(T sample,  
     260void BitVectorPvs<T, S>::AddSampleDirty(T sample, const float pdf) 
     261{ 
     262        if (!Find(sample)) 
     263        { 
     264                mEntries[sample->GetId()] = true; 
     265        } 
     266} 
     267 
     268 
     269template <typename T, typename S> 
     270bool BitVectorPvs<T, S>::AddSampleDirtyCheck(T sample,  
    221271                                                                                const float pdf) 
    222272{ 
    223         HASH_SET::iterator it; 
    224  
    225         // already in map 
    226         if (Find(sample, it)) 
     273        if (Find(sample)) 
    227274                return false; 
    228275         
    229         mEntries.insert(sample); 
     276        mEntries[sample->GetId()] = true; 
    230277        return true; 
    231278} 
     
    233280 
    234281template <typename T, typename S> 
    235 void HashPvs<T, S>::Sort() 
    236 { 
    237 } 
    238  
    239  
    240 template <typename T, typename S> 
    241 void HashPvs<T, S>::Clear(const bool trim = true) 
    242 { 
    243         mEntries.clear(); 
    244 } 
    245  
    246  
    247 template <typename T, typename S> 
    248 bool HashPvs<T, S>::IsDirty() const 
     282void BitVectorPvs<T, S>::Sort() 
     283{ 
     284} 
     285 
     286 
     287template <typename T, typename S> 
     288void BitVectorPvs<T, S>::Clear(const bool trim = true) 
     289{ 
     290        bit_vector::iterator bit, bit_end = mEntries.end(); 
     291        for (bit = mEntries.begin(); bit != bit_end; ++ bit) 
     292        { 
     293                (*bit) = false; 
     294        } 
     295} 
     296 
     297 
     298template <typename T, typename S> 
     299bool BitVectorPvs<T, S>::IsDirty() const 
    249300{ 
    250301        return false; 
     
    253304 
    254305template <typename T, typename S> 
    255 bool HashPvs<T, S>::RequiresResort() const 
     306bool BitVectorPvs<T, S>::RequiresResort() const 
    256307{ 
    257308        return false; 
     
    260311 
    261312template <typename T, typename S> 
    262 typename HashPvsIterator<T, S> HashPvs<T, S>::GetIterator() const 
    263 { 
    264         HashPvsIterator<T, S> pit(mEntries.begin(), mEntries.end()); 
     313typename BitVectorPvsIterator<T, S> BitVectorPvs<T, S>::GetIterator() const 
     314{ 
     315        BitVectorPvsIterator<T, S> pit(mEntries.begin(), mEntries.end()); 
    265316 
    266317        return pit; 
     
    269320 
    270321template <typename T, typename S> 
    271 float HashPvs<T, S>::GetEntrySize() 
    272 { 
    273         return (float)(sizeof(T)) / float(1024 * 1024); 
    274 } 
    275  
    276  
    277 template <typename T, typename S> 
    278 int HashPvs<T, S>::GetEntrySizeByte() 
    279 { 
    280         return sizeof(T); 
    281 } 
    282  
    283  
    284 template <typename T, typename S> 
    285 float HashPvs<T, S>::GetPvsHomogenity(HashPvs<T, S> &pvs)  
     322float BitVectorPvs<T, S>::GetEntrySize() 
     323{ 
     324        return (float)(sizeof(bool)) / float(1024 * 1024); 
     325} 
     326 
     327 
     328template <typename T, typename S> 
     329int BitVectorPvs<T, S>::GetEntrySizeByte() 
     330{ 
     331        return sizeof(bool); 
     332} 
     333 
     334 
     335template <typename T, typename S> 
     336float BitVectorPvs<T, S>::GetPvsHomogenity(BitVectorPvs<T, S> &pvs)  
    286337{ 
    287338        float pvsReduction, pvsEnlargement; 
     
    294345 
    295346template <typename T, typename S> 
    296 bool HashPvs<T, S>::GetSampleContribution(T sample, 
     347bool BitVectorPvs<T, S>::GetSampleContribution(T sample, 
    297348                                                                          const float pdf, 
    298349                                                                          float &contribution)  
    299350{ 
    300         HASH_SET::iterator it; 
    301         const bool entryFound = Find(sample, it); 
     351        const bool entryFound = Find(sample); 
    302352 
    303353        if (entryFound)   
     
    315365 
    316366template <typename T, typename S> 
    317 void HashPvs<T, S>::Merge(HashPvs<T, S> &mergedPvs,  
    318                                                   const HashPvs<T, S> &a,  
    319                                                   const HashPvs<T, S> &b) 
    320 { 
     367void BitVectorPvs<T, S>::Merge(BitVectorPvs<T, S> &mergedPvs,  
     368                                                           const BitVectorPvs<T, S> &a,  
     369                                                           const BitVectorPvs<T, S> &b) 
     370{ 
     371        bit_vector::iterator bit, bit_end = mergedPvs.mEntries.end(); 
     372        bit_vector::const_iterator bitA =  a.mEntries.begin(), bitB = b.mEntries.begin(); 
     373 
     374        for (bit = mergedPvs.mEntries.begin(); bit != bit_end; ++ bit, ++ bitA, ++ bitB) 
     375        { 
     376        (*bit) = (*bitA) | (*bitB); 
     377        } 
     378} 
     379 
     380 
     381template<typename T, typename S> 
     382int BitVectorPvs<T, S>::sPvsSize = 0; 
     383 
     384template<typename T, typename S> 
     385vector<T> BitVectorPvsIterator<T, S>::sObjects; 
     386 
    321387} 
    322388 
    323389#endif 
    324390 
    325 } 
    326  
    327 #endif 
    328  
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp

    r2116 r2117  
    678678                return; 
    679679 
    680         /*ObjectPvsIterator pit = vc->GetPvs().GetIterator(); 
    681  
    682         // output PVS of view cell 
    683         while (pit.HasMoreEntries()) 
    684         {                
    685                 ObjectPvsEntry entry = pit.Next(); 
    686  
    687                 Intersectable *intersect = entry.mObject; 
    688                  
    689                 if (intersect->Mailed()) 
    690                         continue; 
    691                  
    692                 intersect->Mail(); 
    693                 //m.mDiffuseColor = RgbColor(1, 0, 0); 
    694                 m = RandomMaterial(); 
    695                 exporter->SetForcedMaterial(m); 
    696  
    697                 exporter->ExportIntersectable(intersect); 
    698         }*/ 
    699680        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    700681 
     
    10281009        while (pit.HasMoreEntries()) 
    10291010        {                
    1030                 ObjectPvsEntry entry = pit.Next(); 
    1031  
    1032                 Intersectable *intersect = entry.mObject; 
    1033          
     1011                Intersectable *intersect = pit.Next(); 
     1012 
    10341013                BvhLeaf *bv = intersect->mBvhLeaf; 
    10351014 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HashPvs.h

    r2116 r2117  
    7070        } 
    7171 
    72         PvsEntry<T, S> Next() 
     72        T Next(S &pdf) 
    7373        { 
    7474                // hack: create new pvs entry 
    75                 return PvsEntry<T, S>(*(mItCurrent) ++, S(0.0)); 
     75                return *(mItCurrent) ++; 
     76        } 
     77 
     78        T Next() 
     79        { 
     80                // hack: create new pvs entry 
     81                return *(mItCurrent) ++; 
    7682        } 
    7783         
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r2094 r2117  
    18771877        while (pit.HasMoreEntries()) 
    18781878        { 
    1879                 const ObjectPvsEntry &entry = pit.Next(); 
    1880  
    1881                 if (entry.mObject->Type() != Intersectable::BVH_INTERSECTABLE) 
    1882                         cout << "error " << entry.mObject->Type() << endl; 
    1883  
    1884                 BvhNode *intersect = static_cast<BvhNode *>(entry.mObject); 
     1879                Intersectable *obj = pit.Next(); 
     1880 
     1881                if (obj->Type() != Intersectable::BVH_INTERSECTABLE) 
     1882                        cout << "error " << obj->Type() << endl; 
     1883 
     1884                BvhNode *intersect = static_cast<BvhNode *>(obj); 
    18851885                BvhNode *activeNode; 
    18861886 
     
    19371937                        while (pit.HasMoreEntries()) 
    19381938                        {                
    1939                                 const ObjectPvsEntry &entry = pit.Next(); 
    1940  
    1941                                 Intersectable *object = entry.mObject; 
     1939                                Intersectable *object = pit.Next(); 
     1940 
    19421941                                if (!object->Mailed()) 
    19431942                                { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r2116 r2117  
    14641464        { 
    14651465                // not in map => create new entry 
    1466                 node->mIntersectable = new KdIntersectable(node, GetBox(node)); 
    1467                 mKdIntersectables.push_back(node->mIntersectable); 
    1468                 node->mIntersectable->SetId((int)mKdIntersectables.size()); 
     1466                const int id = (int)mKdIntersectables.size(); 
     1467                KdIntersectable *kdObj = new KdIntersectable(node, GetBox(node));; 
     1468                node->mIntersectable = kdObj; 
     1469                 
     1470                mKdIntersectables.push_back(kdObj); 
     1471                kdObj->SetId(id); 
     1472 
     1473#ifdef USE_BIT_PVS 
     1474                // hack: for kd pvs the kd intersecables are the pvs objects 
     1475                ObjectPvsIterator::sObjects.push_back(kdObj); 
     1476#endif 
    14691477        } 
    14701478 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h

    r2116 r2117  
    202202  } 
    203203 
    204   /** \sa KdNode::IsLeaf() */ 
     204  /** \sa KdNode::IsLeaf()  
     205  */ 
    205206  virtual bool IsLeaf() const { return true; } 
    206207 
    207208 
    208   /** pointers to occluders contained in this node */ 
     209  /// pointers to occluders contained in this node 
    209210  ObjectContainer mObjects; 
    210211 
    211   /** Ray set description of the rays passing through this node */ 
     212  /// Ray set description of the rays passing through this node 
    212213  PassingRaySet mPassingRays; 
    213214         
    214   /** PVS consisting of visible KdTree nodes */ 
     215  /// PVS consisting of visible KdTree nodes 
    215216  //KdPvs mKdPvs; 
    216217 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ObjectPvs.h

    r2116 r2117  
    3131                while (pit.HasMoreEntries()) 
    3232                {                
    33                         const ObjectPvsEntry &entry = pit.Next(); 
    34                         Intersectable *obj = entry.mObject; 
    35  
     33                        Intersectable *obj = pit.Next(); 
    3634                        cout << obj << " "; 
    3735                } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r2115 r2117  
    729729        char buf[100]; 
    730730 
    731         if (mLoadViewCells) 
     731    if (mLoadViewCells) 
    732732        {        
     733                 
     734#ifdef USE_BIT_PVS 
     735                // HACK: for kd pvs, set pvs size to maximal number of kd nodes 
     736                vector<KdLeaf *> leaves; 
     737                preprocessor->mKdTree->CollectLeaves(leaves); 
     738 
     739                ObjectPvs::SetPvsSize((int)leaves.size()); 
     740#endif 
     741 
    733742        Environment::GetSingleton()->GetStringValue("ViewCells.filename", buf); 
    734743                 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj

    r2116 r2117  
    2121                                Optimization="0" 
    2222                                AdditionalIncludeDirectories="..\include;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost;Timer" 
    23                                 PreprocessorDefinitions="WIN32;_DEBUG;_LIB;USE_HASH_PVS" 
     23                                PreprocessorDefinitions="WIN32;_DEBUG;_LIB;USE_BIT_PVS" 
    2424                                MinimalRebuild="TRUE" 
    2525                                BasicRuntimeChecks="3" 
     
    7272                                OptimizeForWindowsApplication="TRUE" 
    7373                                AdditionalIncludeDirectories="..\include;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost;Timer" 
    74                                 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;USE_HASH_PVS" 
     74                                PreprocessorDefinitions="WIN32;NDEBUG;_LIB;USE_BIT_PVS" 
    7575                                ExceptionHandling="TRUE" 
    7676                                RuntimeLibrary="2" 
     
    383383                        </File> 
    384384                        <File 
     385                                RelativePath=".\BitVectorPvs.cpp"> 
     386                        </File> 
     387                        <File 
    385388                                RelativePath=".\BitVectorPvs.h"> 
    386389                        </File> 
     
    588591                        <File 
    589592                                RelativePath=".\ObjectPvs.h"> 
     593                        </File> 
     594                        <File 
     595                                RelativePath=".\ObjectsParser.cpp"> 
     596                        </File> 
     597                        <File 
     598                                RelativePath=".\ObjectsParser.h"> 
    590599                        </File> 
    591600                        <File 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h

    r2116 r2117  
    2929        } 
    3030 
    31         const PvsEntry<T, S> &Next() 
    32         { 
    33                 return *(mItCurrent ++); 
     31        T Next(S &pdf) 
     32        { 
     33                pdf = (*mItCurrent).mData; 
     34                return (*(mItCurrent ++)).mObject; 
     35        } 
     36 
     37        T Next() 
     38        { 
     39                return (*(mItCurrent ++)).mObject; 
    3440        } 
    3541 
  • GTP/trunk/Lib/Vis/Preprocessing/src/PvsBase.h

    r2116 r2117  
    1919public: 
    2020 
    21         PvsEntry() {} 
    22  
     21        PvsEntry(): mObject(NULL), mData(0) {} 
     22        PvsEntry(T sample): mObject(sample), mData(0) {} 
    2323        PvsEntry(T sample, const S &data): mObject(sample), mData(data) {} 
    2424 
  • GTP/trunk/Lib/Vis/Preprocessing/src/PvsDefinitions.h

    r2116 r2117  
    1212#include "HashPvs.h" 
    1313 
    14 #define HASH_PVS 1 
     14#define PVS_TYPE 0 
    1515 
    1616namespace GtpVisibilityPreprocessor { 
     
    1919} 
    2020 
    21 #else 
     21#endif 
     22 
     23#ifdef USE_VERBOSE_PVS 
    2224 
    2325#include "Pvs.h" 
    2426 
    25 #define HASH_PVS 0 
     27#define PVS_TYPE 1 
    2628 
    2729namespace GtpVisibilityPreprocessor { 
     
    2931typedef PvsIterator<Intersectable *, PvsData> ObjectPvsIterator; 
    3032} 
     33#endif 
     34 
     35 
     36#ifdef USE_BIT_PVS 
     37 
     38#include "BitVectorPvs.h" 
     39 
     40#define PVS_TYPE 2 
     41 
     42namespace GtpVisibilityPreprocessor { 
     43typedef BitVectorPvs<Intersectable *, PvsData> DefaultPvs; 
     44typedef BitVectorPvsIterator<Intersectable *, PvsData> ObjectPvsIterator; 
     45} 
     46 
    3147#endif 
    3248 
  • GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj

    r2116 r2117  
    2121                                Optimization="0" 
    2222                                AdditionalIncludeDirectories="..\include;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost" 
    23                                 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;NO_QT;USE_HASH_PVS" 
     23                                PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;NO_QT;USE_BIT_PVS" 
    2424                                MinimalRebuild="TRUE" 
    2525                                BasicRuntimeChecks="3" 
     
    8181                                OptimizeForWindowsApplication="TRUE" 
    8282                                AdditionalIncludeDirectories="..\include;..\..\..\..\..\..\NonGTP\Boost;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\MultiLevelRayTracing;Timer" 
    83                                 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;NO_QT;USE_HASH_PVS" 
     83                                PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;NO_QT;USE_BIT_PVS" 
    8484                                RuntimeLibrary="2" 
    8585                                EnableEnhancedInstructionSet="2" 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r2100 r2117  
    6565        while (pit.HasMoreEntries()) 
    6666        { 
    67                 ObjectPvsEntry entry = pit.Next(); 
    68  
    69                 if (!entry.mObject->Mailed()) 
    70                 { 
    71                         entry.mObject->Mail(); 
     67                Intersectable *obj = pit.Next(); 
     68 
     69                if (!obj->Mailed()) 
     70                { 
     71                        obj->Mail(); 
    7272                        ++ count; 
    7373                } 
     
    9292        while (pit.HasMoreEntries()) 
    9393        { 
    94                 ObjectPvsEntry entry = pit.Next(); 
    95                 entry.mObject->Mail(); 
     94                pit.Next()->Mail(); 
    9695        } 
    9796 
     
    10099        while (pit.HasMoreEntries()) 
    101100        { 
    102                 ObjectPvsEntry entry = pit.Next(); 
    103  
    104                 Intersectable *obj = entry.mObject; 
    105                 if (!obj->Mailed()) 
     101                if (!pit.Next()->Mailed()) 
    106102                        ++ pvs; 
    107103        } 
     
    847843        while (pit.HasMoreEntries()) 
    848844        { 
    849                 ObjectPvsEntry entry = pit.Next(); 
    850  
    851                 Intersectable *obj = entry.mObject; 
     845                Intersectable *obj = pit.Next(); 
    852846 
    853847                obj->Mail(); 
     
    859853        while (pit2.HasMoreEntries()) 
    860854        { 
    861                 ObjectPvsEntry entry = pit2.Next(); 
    862                 Intersectable *obj = entry.mObject; 
    863  
     855                Intersectable *obj = pit2.Next(); 
     856                 
    864857                // test if object already considered     
    865858                if (!obj->Mailed()) 
     
    16811674                while (pit.HasMoreEntries()) 
    16821675                {                
    1683                         const ObjectPvsEntry &entry = pit.Next(); 
    1684                         Intersectable *obj = entry.mObject; 
    1685                         obj->Mail(); 
     1676                        pit.Next()->Mail(); 
    16861677                } 
    16871678        } 
     
    16951686                while (pit.HasMoreEntries()) 
    16961687                {                
    1697                         const ObjectPvsEntry &entry = pit.Next(); 
    1698                         Intersectable *obj = entry.mObject; 
    1699  
    1700                         obj->IncMail(); 
     1688                        pit.Next()->IncMail(); 
    17011689                } 
    17021690        } 
     
    17051693    interior->GetPvs().Clear(false); 
    17061694                 
     1695        PvsData pvsData; 
     1696 
    17071697        // only the objects which are present in all leaf pvs  
    17081698        // should remain in the parent pvs 
     
    17161706                while (pit.HasMoreEntries()) 
    17171707                {                
    1718                         ObjectPvsEntry entry = pit.Next(); 
    1719  
    1720                         if (entry.mObject->Mailed(mail)) 
     1708                        Intersectable *obj = pit.Next(pvsData); 
     1709 
     1710                        if (obj->Mailed(mail)) 
    17211711                        {        
    1722                                 interior->GetPvs().AddSample(entry.mObject, entry.mData.mSumPdf); 
     1712                                interior->GetPvs().AddSample(obj, pvsData.mSumPdf); 
    17231713                        } 
    17241714                } 
     
    17331723 
    17341724                ObjectPvs newPvs; 
    1735  
     1725                 
    17361726                while (pit.HasMoreEntries()) 
    17371727                {                
    1738                         const ObjectPvsEntry &entry = pit.Next(); 
    1739                         Intersectable *obj = entry.mObject; 
    1740  
    1741                         /*if (obj->Mailed(mail)) 
    1742                         { 
    1743                                 vc->GetPvs().RemoveSample(entry.mObject, Limits::Infinity)) 
    1744                         }*/ 
     1728                        Intersectable *obj = pit.Next(pvsData); 
     1729 
    17451730                        if (!obj->Mailed(mail)) 
    17461731                        { 
    1747                                 newPvs.AddSampleDirty(obj, entry.mData.mSumPdf); 
     1732                                newPvs.AddSampleDirty(obj, pvsData.mSumPdf); 
    17481733                        } 
    17491734                } 
     
    18721857                while (oit.HasMoreEntries()) 
    18731858                { 
    1874                         ObjectPvsEntry entry = oit.Next(); 
    1875                         Intersectable *intersect = entry.mObject; 
     1859                        Intersectable *intersect = oit.Next(); 
    18761860 
    18771861                        if (!intersect->Mailed()) 
     
    23902374        while (it.HasMoreEntries()) 
    23912375        { 
    2392                 ObjectPvsEntry entry = it.Next(); 
    2393                 Intersectable *obj = entry.mObject; 
     2376                Intersectable *obj = it.Next(); 
    23942377 
    23952378                // hack: just output full pvs 
     
    24082391                else 
    24092392                { 
    2410                         stream << entry.mObject->GetId() << " "; 
     2393                        stream << obj->GetId() << " "; 
    24112394                } 
    24122395        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r2116 r2117  
    283283                return mPvsCost; 
    284284        } 
    285  
    286285 
    287286        int GetFilteredPvsSize() const  
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r2116 r2117  
    681681        if (mUseKdPvs) 
    682682        { 
    683           KdNode *node = GetPreprocessor()->mKdTree->GetPvsNode(isTermination ? 
    684                                                                                                                         ray.mTermination : ray.mOrigin); 
     683                KdNode *node = GetPreprocessor()-> 
     684                        mKdTree->GetPvsNode(isTermination ?     ray.mTermination : ray.mOrigin); 
    685685          return GetPreprocessor()->mKdTree->GetOrCreateKdIntersectable(node); 
    686686        } 
     
    12781278 
    12791279        ViewCellContainer viewCells; 
    1280          
     1280 
     1281        cout << "objects size: " << ObjectPvsIterator::sObjects.size() << endl; 
     1282        cout << "pvs size: " <<  ObjectPvs::sPvsSize << endl; 
     1283 
    12811284        // $$ JB hack - the collect best viewcells does not work? 
    12821285#if 0 
     
    26122615 
    26132616 
    2614 void 
    2615 ViewCellsManager::SortViewCellPvs() 
    2616 { 
    2617  
    2618   ViewCellContainer::iterator it, it_end = mViewCells.end(); 
    2619   for (it = mViewCells.begin(); it != it_end; ++ it) { 
    2620         ObjectPvs &pvs = (*it)->GetPvs(); 
    2621         if (pvs.RequiresResortLog()) 
    2622           pvs.SimpleSort(); 
    2623   } 
    2624 } 
     2617void ViewCellsManager::SortViewCellPvs() 
     2618{ 
     2619        ViewCellContainer::iterator it, it_end = mViewCells.end(); 
     2620         
     2621        for (it = mViewCells.begin(); it != it_end; ++ it)  
     2622        { 
     2623                ObjectPvs &pvs = (*it)->GetPvs(); 
     2624                if (pvs.RequiresResortLog()) 
     2625                        pvs.SimpleSort(); 
     2626        } 
     2627} 
     2628 
    26252629 
    26262630void ViewCellsManager::ComputeViewCellContribution(ViewCell *viewCell, 
     
    26302634                                                                                                   const bool addSamplesToPvs) 
    26312635{ 
    2632   // check if we are outside of view space 
    2633   // $$JB tmp commented to speedup up computations 
     2636        // check if we are outside of view space 
     2637        // $$JB tmp commented to speedup up computations 
    26342638#if 0 
    2635   if (!obj || !viewCell->GetValid()) 
    2636         return; 
     2639        if (!obj || !viewCell->GetValid()) 
     2640                return; 
    26372641#endif 
    2638    
    2639    
    2640   // if ray not outside of view space 
    2641   float relContribution = 0.0f; 
    2642   float absContribution = 0.0f; 
    2643   bool hasAbsContribution; 
    2644    
    2645   // todo: maybe not correct for kd node pvs 
    2646   if (addSamplesToPvs) { 
    2647         hasAbsContribution = viewCell->GetPvs().AddSampleDirtyCheck(obj, 
    2648                                                                                                                                 ray.mPdf); 
    2649         //hasAbsContribution = viewCell->GetPvs().AddSample(obj,ray.mPdf); 
    2650   } 
    2651   else { 
    2652         hasAbsContribution = viewCell->GetPvs().GetSampleContribution( 
    2653                                                                                                                                   obj, 
    2654                                                                                                                                   ray.mPdf, 
    2655                                                                                                                                   relContribution); 
    2656   } 
    2657    
    2658   // $$ clear the relative contribution as it is currently not correct anyway 
    2659   //  relContribution = 0.0f; 
    2660    
    2661   if (hasAbsContribution)  { 
    2662         ++ ray.mPvsContribution; 
    2663         absContribution = relContribution = 1.0f; 
    2664         if (viewCell->GetPvs().RequiresResort())  
    2665                 viewCell->GetPvs().SimpleSort(); 
     2642 
     2643        // if ray not outside of view space 
     2644        float relContribution = 0.0f; 
     2645        float absContribution = 0.0f; 
     2646        bool hasAbsContribution; 
     2647 
     2648        // todo: maybe not correct for kd node pvs 
     2649        if (addSamplesToPvs)  
     2650        { 
     2651                hasAbsContribution = viewCell->GetPvs(). 
     2652                        AddSampleDirtyCheck(obj, ray.mPdf); 
     2653                //hasAbsContribution = viewCell->GetPvs().AddSample(obj,ray.mPdf); 
     2654        } 
     2655        else  
     2656        { 
     2657                hasAbsContribution =  
     2658                        viewCell->GetPvs().GetSampleContribution(obj, 
     2659                        ray.mPdf, 
     2660                        relContribution); 
     2661        } 
     2662 
     2663        // $$ clear the relative contribution as it is currently not correct anyway 
     2664        //  relContribution = 0.0f; 
     2665 
     2666        if (hasAbsContribution)   
     2667        { 
     2668                ++ ray.mPvsContribution; 
     2669                absContribution = relContribution = 1.0f; 
     2670 
     2671                if (viewCell->GetPvs().RequiresResort())  
     2672                        viewCell->GetPvs().SimpleSort(); 
    26662673 
    26672674#if CONTRIBUTION_RELATIVE_TO_PVS_SIZE 
    2668         relContribution /= viewcell->GetPvs().GetSize(); 
     2675                relContribution /= viewcell->GetPvs().GetSize(); 
    26692676#endif 
    2670          
     2677 
    26712678#if DIST_WEIGHTED_CONTRIBUTION  
    2672         // recalculate the contribution - weight the 1.0f contribution by the sqr distance to the 
    2673         // object-> a new contribution in the proximity of the viewcell has a larger weight! 
    2674         relContribution /= SqrDistance(GetViewCellBox(viewcell).Center(), 
    2675                                                                   ray.mTermination); 
    2676          
     2679                // recalculate the contribution - weight the 1.0f contribution by the sqr distance to the 
     2680                // object-> a new contribution in the proximity of the viewcell has a larger weight! 
     2681                relContribution /=  
     2682                        SqrDistance(GetViewCellBox(viewcell).Center(), ray.mTermination); 
     2683 
    26772684#endif 
    26782685        } 
    2679    
     2686 
    26802687#if SUM_RAY_CONTRIBUTIONS || AVG_RAY_CONTRIBUTIONS 
    2681   ray.mRelativePvsContribution += relContribution; 
     2688        ray.mRelativePvsContribution += relContribution; 
    26822689#else 
    2683   // recalculate relative contribution - use max of Rel Contribution 
    2684   if (ray.mRelativePvsContribution < relContribution) 
    2685         ray.mRelativePvsContribution = relContribution; 
     2690        // recalculate relative contribution - use max of Rel Contribution 
     2691        if (ray.mRelativePvsContribution < relContribution) 
     2692                ray.mRelativePvsContribution = relContribution; 
    26862693#endif 
    26872694} 
     
    32873294  while (pit.HasMoreEntries()) 
    32883295  {              
    3289           ObjectPvsEntry entry = pit.Next(); 
    3290    
    3291           Intersectable *object = entry.mObject; 
    3292       object->Mail(); 
     3296      pit.Next()->Mail(); 
    32933297  } 
    32943298 
     
    33013305  {              
    33023306          // now go through the pvs again 
    3303           ObjectPvsEntry entry = pit2.Next(); 
    3304           Intersectable *object = entry.mObject; 
     3307          Intersectable *object = pit2.Next(); 
    33053308 
    33063309          //    Vector3 center = object->GetBox().Center(); 
     
    33853388          while (pit.HasMoreEntries())   
    33863389          { 
    3387                   ObjectPvsEntry entry = pit.Next(); 
    3388                   Intersectable *object = entry.mObject; 
    3389                   object->Mail(); 
     3390                  pit.Next()->Mail(); 
    33903391          } 
    33913392  } 
     
    34473448        ObjectContainer objects; 
    34483449         
     3450        PvsData pvsData; 
     3451 
    34493452        while (pit.HasMoreEntries()) {           
    3450           ObjectPvsEntry entry = pit.Next(); 
     3453          Intersectable *object = pit.Next(pvsData); 
    34513454           
    3452           Intersectable *object = entry.mObject; 
    34533455          // compute filter size based on the distance and the numebr of samples 
    34543456          AxisAlignedBox3 box = object->GetBox(); 
     
    34573459          float globalRadius = distance*globalC; 
    34583460           
    3459           int objectSamples = (int)entry.mData.mSumPdf; 
     3461          int objectSamples = (int)pvsData.mSumPdf; 
    34603462          float localRadius = MAX_FLOAT; 
    34613463           
     
    35253527  if (!mUseKdPvs) 
    35263528  { 
     3529          PvsData pvsData; 
     3530 
    35273531          // copy the base pvs to the new pvs 
    35283532          pit = basePvs.GetIterator(); 
    35293533          while (pit.HasMoreEntries())  
    35303534          {              
    3531                   ObjectPvsEntry entry = pit.Next(); 
    3532                   pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf); 
     3535                  Intersectable *obj = pit.Next(pvsData); 
     3536                  pvs.AddSampleDirty(obj, pvsData.mSumPdf); 
    35333537          } 
    35343538  } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r2116 r2117  
    382382 
    383383 
    384   // resort pvss after a pass of the algorithm 
    385   void 
    386   SortViewCellPvs(); 
    387  
    388   // map the ray intersection objects from triangles to high level objects... 
    389   void 
    390   DeterminePvsObjects( 
    391                                           VssRayContainer &rays, 
    392                                           const bool useHitObjects = false); 
     384        // resort pvss after a pass of the algorithm 
     385        void  SortViewCellPvs(); 
     386 
     387        // map the ray intersection objects from triangles to high level objects... 
     388        void DeterminePvsObjects(VssRayContainer &rays, 
     389                                                         const bool useHitObjects = false); 
    393390         
    394391        /** Sets validity of view cell 
     
    404401 
    405402 
    406         /** set valid viewcells in the range of pvs. sorts the viewcells 
    407           according to the pvs and then pickups those in the ranges  
    408           */ 
     403        /** Set valid viewcells in the range of pvs. sorts the viewcells 
     404                according to the pvs and then pickups those in the ranges  
     405        */ 
    409406        void SetValidityPercentage(const float minValid, const float maxValid); 
    410407 
     
    420417        */ 
    421418        int GetMinPvsSize() const; 
     419 
    422420        /** Returns maximal ratio. i.e., currentPVs / maxPvs, 
    423421                where pvs is still considered valid. 
    424422        */ 
    425423        float GetMaxPvsRatio() const; 
     424 
    426425        /** Exports view cell geometry. 
    427426        */ 
    428         virtual void ExportViewCellGeometry( 
    429                 Exporter *exporter, 
    430                 ViewCell *vc, 
    431                 const AxisAlignedBox3 *box, 
    432                 const AxisAlignedPlane *clipPlane = NULL 
    433                 ) const = 0; 
     427        virtual void ExportViewCellGeometry(Exporter *exporter, 
     428                                                                                ViewCell *vc, 
     429                                                                                const AxisAlignedBox3 *box, 
     430                                                                                const AxisAlignedPlane *clipPlane = NULL 
     431                                                                                ) const = 0; 
    434432 
    435433        /** Brings the view cells into their final state, computes meshes and volume. 
     
    446444                                                                  float &avgRenderCost); 
    447445 
    448  
    449446        /** Returns hierarchy of the view cells. 
    450447        */ 
     
    488485        /** Evaluautes histogram for a given number of view cells. 
    489486        */ 
    490         void EvalViewCellHistogramForPvsSize(const string filename, const int nViewCells); 
     487        void EvalViewCellHistogramForPvsSize(const string filename,  
     488                                                                                 const int nViewCells); 
    491489 
    492490        void EvalViewCellHistogramForPvsSize(const string filename,  
     
    500498                of the hierarchy. 
    501499        */ 
    502         void UpdateScalarPvsSize(ViewCell *vc, const float pvsCost, const int entriesInPvs) const; 
     500        void UpdateScalarPvsSize(ViewCell *vc,  
     501                                                         const float pvsCost,  
     502                                                         const int entriesInPvs) const; 
    503503 
    504504        /** Returns bounding box of a view cell. 
     
    508508        /** Exports bounding boxes of objects to file. 
    509509        */ 
    510         bool ExportBoundingBoxes(const string filename, const ObjectContainer &objects) const; 
     510        bool ExportBoundingBoxes(const string filename,  
     511                                                         const ObjectContainer &objects) const; 
    511512     
    512513        /** Load the bounding boxes into the container. 
    513514        */ 
    514         bool LoadBoundingBoxes(const string filename, IndexedBoundingBoxContainer &boxes) const; 
     515        bool LoadBoundingBoxes(const string filename,  
     516                                                  IndexedBoundingBoxContainer &boxes) const; 
    515517 
    516518        /** Returns true if pvs should be exported together with the view cells. 
     
    523525                                                                  const ViewCellContainer &viewCells) const; 
    524526 
     527        /** Compress the view cells. 
     528        */ 
    525529        virtual void CompressViewCells(); 
    526530 
     
    616620        /** Returns the bounding box of filter width. 
    617621        */ 
    618         AxisAlignedBox3 GetFilterBBox(const Vector3 &viewPoint, const float width) const; 
     622        AxisAlignedBox3 GetFilterBBox(const Vector3 &viewPoint,  
     623                                                                  const float width) const; 
    619624 
    620625        ////////////////////////////////////////////////////////////////// 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r2116 r2117  
    218218        } 
    219219 
    220  
    221         if (HASH_PVS) 
    222                 Debug << "using hash pvs" << endl; 
    223         else 
    224                 Debug << "using verbose pvs" << endl; 
     220        Debug << "using pvs type " << PVS_TYPE << endl; 
    225221 
    226222        ///////////// 
Note: See TracChangeset for help on using the changeset viewer.