Changeset 2198


Ignore:
Timestamp:
03/06/07 17:37:28 (17 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
13 edited

Legend:

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

    r2187 r2198  
    366366        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    367367 
     368        // warning: not exact number (there can be rays counted twice) 
     369        // otherwise we would have to traverse trough all rays 
    368370        for (oit = objects.begin(); oit != oit_end; ++ oit) 
    369371        { 
     
    373375        return nRays; 
    374376} 
     377 
    375378                                                                         
    376379float BvHierarchy::GetViewSpaceVolume() const 
     
    384387                                                                                BvhTraversalData &backData) 
    385388{  
     389        // fill view cells cache 
    386390        mNodeTimer.Entry(); 
     391 
     392#if STORE_VIEWCELLS_WITH_BVH 
     393        AssociateViewCellsWithObjects(sc.mFrontObjects); 
     394        AssociateViewCellsWithObjects(sc.mBackObjects); 
     395#endif   
    387396        const BvhTraversalData &tData = sc.mParentData; 
    388397        BvhLeaf *leaf = tData.mNode; 
     
    400409        // add the new nodes to the tree 
    401410        BvhInterior *node = new BvhInterior(parentBox, leaf->GetParent()); 
    402          
     411 
    403412 
    404413        ////////////////// 
     
    480489                AssignSortedObjects(sc, frontData, backData); 
    481490        } 
    482          
     491 
     492#if STORE_VIEWCELLS_WITH_BVH 
     493        ReleaseViewCells(sc.mFrontObjects); 
     494        ReleaseViewCells(sc.mBackObjects); 
     495#endif 
     496 
    483497        mNodeTimer.Exit(); 
    484498 
     
    615629                                                                                   bool computeSplitPlane) 
    616630{ 
    617         mEvalTimer.Entry(); 
     631        mPlaneTimer.Entry(); 
     632 
     633#if STORE_VIEWCELLS_WITH_BVH 
     634        // fill view cells cache 
     635        AssociateViewCellsWithObjects(*splitCandidate.mParentData.mSortedObjects[3]); 
     636#endif 
     637 
    618638        if (computeSplitPlane) 
    619639        { 
     
    640660                                                                                previousMisses + 1 : previousMisses); 
    641661        } 
    642  
     662        mPlaneTimer.Exit(); 
     663 
     664        mEvalTimer.Entry(); 
    643665 
    644666        const BvhTraversalData &tData = splitCandidate.mParentData; 
     
    705727        // compute global decrease in render cost 
    706728        splitCandidate.SetPriority(priority); 
     729 
     730#if STORE_VIEWCELLS_WITH_BVH 
     731        ReleaseViewCells(*splitCandidate.mParentData.mSortedObjects[3]); 
     732#endif 
     733 
    707734        mEvalTimer.Exit(); 
    708735} 
     
    710737 
    711738int BvHierarchy::EvalPvsEntriesIncr(BvhSubdivisionCandidate &splitCandidate,  
    712                                                                         const float avgRayContri) const 
     739                                                                        const float avgRayContri) //const 
    713740{ 
    714741        const float oldPvsSize = (float)CountViewCells(splitCandidate.mParentData.mNode->mObjects); 
     
    9911018 
    9921019        SortableEntryContainer::reverse_iterator rcit =  
    993                 mSubdivisionCandidates->rbegin(), rcit_end =  
    994                 mSubdivisionCandidates->rend(); 
     1020                mSubdivisionCandidates->rbegin(), rcit_end = mSubdivisionCandidates->rend(); 
    9951021 
    9961022        vector<float>::reverse_iterator rbit = bordersRight.rbegin(); 
     
    14061432void BvHierarchy::PrepareLocalSubdivisionCandidates(const BvhTraversalData &tData, 
    14071433                                                                                                        const int axis)                                                                                  
    1408 { 
     1434{mSort2Timer.Entry(); 
    14091435        //-- insert object queries 
    14101436        ObjectContainer *objects = mUseGlobalSorting ?  
     
    14121438 
    14131439        CreateLocalSubdivisionCandidates(*objects, &mSubdivisionCandidates, !mUseGlobalSorting, axis); 
     1440                mSort2Timer.Exit(); 
    14141441} 
    14151442 
     
    14721499        ViewCellContainer viewCells; 
    14731500 
    1474         const int numRays = CollectViewCells(tData.mNode->mObjects, viewCells, true, true); 
     1501        const bool setCounter = true; 
     1502        const bool onlyUnmailed = true; 
     1503 
     1504        const int numRays = CollectViewCells(tData.mNode->mObjects,  
     1505                                                                                 viewCells,  
     1506                                                                                 setCounter,  
     1507                                                                                 onlyUnmailed); 
     1508 
    14751509        //cout << "number of rays: " << numRays << endl; 
    14761510 
     
    17811815 
    17821816 
    1783 float BvHierarchy::EvalRenderCost(const ObjectContainer &objects) const 
     1817float BvHierarchy::EvalRenderCost(const ObjectContainer &objects)// const 
    17841818{        
    17851819        /////////////// 
     
    17931827         
    17941828        return objRenderCost * p; 
    1795 } 
    1796  
    1797  
    1798 float BvHierarchy::EvalProb(const ObjectContainer &objects) const 
    1799 {        
    1800         /////////////// 
    1801         //-- render cost heuristics 
    1802  
    1803         const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 
    1804  
    1805         // probability that view point lies in a view cell which sees this node 
    1806         return EvalViewCellsVolume(objects) / viewSpaceVol; 
    18071829} 
    18081830 
     
    18901912                                                                  ViewCellContainer &viewCells, 
    18911913                                                                  const bool setCounter, 
    1892                                                                   const bool onlyUnmailedRays) const 
     1914                                                                  const bool onlyUnmailedRays)// const 
    18931915{ 
    18941916        ViewCell::NewMail(); 
     1917 
    18951918        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     1919 
     1920        // use mailing to avoid dublicates 
     1921        const bool useMailBoxing = true; 
    18961922 
    18971923        int numRays = 0; 
     
    18991925        for (oit = objects.begin(); oit != oit_end; ++ oit) 
    19001926        { 
    1901                 // always use only mailed objects 
    1902                 numRays += CollectViewCells(*oit, viewCells, true, setCounter, onlyUnmailedRays); 
     1927                // use mailing to avoid duplicates 
     1928                numRays += CollectViewCells(*oit, viewCells, useMailBoxing, setCounter, onlyUnmailedRays); 
    19031929        } 
    19041930 
    19051931        return numRays; 
     1932} 
     1933 
     1934 
     1935#if STORE_VIEWCELLS_WITH_BVH 
     1936 
     1937 
     1938void BvHierarchy::ReleaseViewCells(const ObjectContainer &objects) 
     1939{ 
     1940        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     1941 
     1942        for (oit = objects.begin(); oit != oit_end; ++ oit) 
     1943        { 
     1944                (*oit)->DelViewCells(); 
     1945        } 
     1946} 
     1947 
     1948 
     1949void BvHierarchy::AssociateViewCellsWithObjects(const ObjectContainer &objects) const 
     1950{ 
     1951        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     1952 
     1953        const bool useMailBoxing = true; 
     1954        for (oit = objects.begin(); oit != oit_end; ++ oit) 
     1955        { 
     1956                ViewCell::NewMail(); 
     1957                // use mailing to avoid duplicates 
     1958                AssociateViewCellsWithObject(*oit, useMailBoxing); 
     1959        } 
     1960} 
     1961 
     1962 
     1963int BvHierarchy::AssociateViewCellsWithObject(Intersectable *obj, const bool useMailBoxing) const 
     1964{ 
     1965        if (!obj->GetOrCreateViewCells()->empty()) 
     1966        { 
     1967                cerr << "AssociateViewCellsWithObject: view cells cache not working" << endl; 
     1968        } 
     1969 
     1970        ViewCellContainer *objViewCells = obj->GetOrCreateViewCells(); 
     1971        VssRayContainer *vssRays = obj->GetOrCreateRays(); 
     1972 
     1973        VssRayContainer::const_iterator rit, rit_end = vssRays->end(); 
     1974 
     1975        // fill cache 
     1976        for (rit = vssRays->begin(); rit < rit_end; ++ rit) 
     1977        { 
     1978                VssRay *ray = (*rit); 
     1979 
     1980                //      if (onlyUnmailedRays && ray->Mailed()) 
     1981                //              continue; 
     1982                mHierarchyManager->mVspTree->GetViewCells(*ray, *objViewCells); 
     1983        } 
     1984 
     1985        return (int)vssRays->size(); 
     1986} 
     1987 
     1988 
     1989 
     1990int BvHierarchy::CountViewCells(Intersectable *obj) //const 
     1991{ 
     1992        ViewCellContainer *viewCells = obj->GetOrCreateViewCells(); 
     1993 
     1994        if (obj->GetOrCreateViewCells()->empty()) 
     1995        { 
     1996                //cerr << "h";//CountViewCells: view cells empty, view cells cache not working" << endl; 
     1997                return CountViewCellsFromRays(obj); 
     1998        } 
     1999         
     2000        int result = 0; 
     2001 
     2002        ViewCellContainer::const_iterator vit, vit_end = viewCells->end(); 
     2003         
     2004        for (vit = viewCells->begin(); vit != vit_end; ++ vit) 
     2005        { 
     2006                ViewCell *vc = *vit; 
     2007 
     2008                // store view cells 
     2009                if (!vc->Mailed()) 
     2010                { 
     2011                        vc->Mail(); 
     2012                        ++ result; 
     2013                } 
     2014        } 
     2015 
     2016        return result; 
    19062017} 
    19072018 
     
    19112022                                                                  const bool useMailBoxing, 
    19122023                                                                  const bool setCounter, 
    1913                                                                   const bool onlyUnmailedRays) const 
    1914 { 
     2024                                                                  const bool onlyUnmailedRays)// const 
     2025{ 
     2026        if (obj->GetOrCreateViewCells()->empty()) 
     2027        { 
     2028                //cerr << "g";//CollectViewCells: view cells empty, view cells cache not working" << endl; 
     2029                return CollectViewCellsFromRays(obj, viewCells, useMailBoxing, setCounter, onlyUnmailedRays); 
     2030        } 
     2031 
     2032        mCollectTimer.Entry(); 
     2033 
     2034        ViewCellContainer *objViewCells = obj->GetOrCreateViewCells(); 
     2035 
     2036        /////////// 
     2037        //-- use view cells cache 
     2038 
     2039        // fastest way: just copy to the end 
     2040        //if (!useMailBoxing)   viewCells.insert(viewCells.end(), objViewCells->begin(), objViewCells->end()); 
     2041 
     2042        // loop through view cells 
     2043        // matt: probably slow to insert  view cells one by one 
     2044        ViewCellContainer::const_iterator vit, vit_end = objViewCells->end(); 
     2045 
     2046        for (vit = objViewCells->begin(); vit != vit_end; ++ vit) 
     2047        { 
     2048                ViewCell *vc = *vit; 
     2049 
     2050                // store view cells 
     2051                if (!useMailBoxing || !vc->Mailed()) 
     2052                { 
     2053                        if (useMailBoxing)  
     2054                        { 
     2055                                // view cell not mailed 
     2056                                vc->Mail(); 
     2057                                 
     2058                                if (setCounter) 
     2059                                        vc->mCounter = 0; 
     2060                                //viewCells.push_back(vc); 
     2061                        } 
     2062 
     2063                        viewCells.push_back(vc); 
     2064                } 
     2065 
     2066                if (setCounter) 
     2067                        ++ vc->mCounter; 
     2068        } 
     2069 
     2070        mCollectTimer.Exit(); 
     2071 
     2072        return (int)objViewCells->size(); 
     2073} 
     2074 
     2075 
     2076int BvHierarchy::CollectViewCellsFromRays(Intersectable *obj,  
     2077                                                                                  ViewCellContainer &viewCells, 
     2078                                                                                  const bool useMailBoxing, 
     2079                                                                                  const bool setCounter, 
     2080                                                                                  const bool onlyUnmailedRays) 
     2081{ 
     2082        mCollectTimer.Entry(); 
    19152083        VssRayContainer::const_iterator rit, rit_end = obj->GetOrCreateRays()->end(); 
    19162084 
     
    19222090 
    19232091                if (onlyUnmailedRays && ray->Mailed()) 
    1924                 { 
    19252092                        continue; 
    1926                 } 
    1927  
     2093                 
    19282094                ++ numRays; 
    19292095 
     
    19452111                                        vc->Mail(); 
    19462112                                        if (setCounter) 
    1947                                         { 
    19482113                                                vc->mCounter = 0; 
    1949                                         } 
    19502114                                } 
    19512115 
     
    19542118                         
    19552119                        if (setCounter) 
    1956                         { 
    19572120                                ++ vc->mCounter; 
    1958                         } 
    1959                 } 
    1960         } 
    1961  
     2121                } 
     2122        } 
     2123 
     2124        mCollectTimer.Exit(); 
    19622125        return numRays; 
    19632126} 
    19642127 
    19652128 
    1966 int BvHierarchy::CountViewCells(Intersectable *obj) const 
     2129int BvHierarchy::CountViewCellsFromRays(Intersectable *obj) //const 
    19672130{ 
    19682131        int result = 0; 
     
    19942157} 
    19952158 
    1996  
    1997 int BvHierarchy::CountViewCells(const ObjectContainer &objects) const 
     2159#else 
     2160 
     2161int BvHierarchy::CountViewCells(Intersectable *obj) //const 
     2162{ 
     2163        int result = 0; 
     2164         
     2165        VssRayContainer::const_iterator rit, rit_end = obj->GetOrCreateRays()->end(); 
     2166 
     2167        for (rit = obj->GetOrCreateRays()->begin(); rit < rit_end; ++ rit) 
     2168        { 
     2169                VssRay *ray = (*rit); 
     2170                ViewCellContainer tmpViewCells; 
     2171         
     2172                mHierarchyManager->mVspTree->GetViewCells(*ray, tmpViewCells); 
     2173                 
     2174                ViewCellContainer::const_iterator vit, vit_end = tmpViewCells.end(); 
     2175                for (vit = tmpViewCells.begin(); vit != vit_end; ++ vit) 
     2176                { 
     2177                        ViewCell *vc = *vit; 
     2178 
     2179                        // store view cells 
     2180                        if (!vc->Mailed()) 
     2181                        { 
     2182                                vc->Mail(); 
     2183                                ++ result; 
     2184                        } 
     2185                } 
     2186        } 
     2187 
     2188        return result; 
     2189} 
     2190 
     2191 
     2192int BvHierarchy::CollectViewCells(Intersectable *obj,  
     2193                                                                  ViewCellContainer &viewCells, 
     2194                                                                  const bool useMailBoxing, 
     2195                                                                  const bool setCounter, 
     2196                                                                  const bool onlyUnmailedRays) 
     2197{ 
     2198        mCollectTimer.Entry(); 
     2199        VssRayContainer::const_iterator rit, rit_end = obj->GetOrCreateRays()->end(); 
     2200 
     2201        int numRays = 0; 
     2202 
     2203        for (rit = obj->GetOrCreateRays()->begin(); rit < rit_end; ++ rit) 
     2204        { 
     2205                VssRay *ray = (*rit); 
     2206 
     2207                if (onlyUnmailedRays && ray->Mailed()) 
     2208                        continue; 
     2209                 
     2210                ++ numRays; 
     2211 
     2212                ViewCellContainer tmpViewCells; 
     2213                mHierarchyManager->mVspTree->GetViewCells(*ray, tmpViewCells); 
     2214 
     2215                // matt: probably slow to allocate memory for view cells every time 
     2216                ViewCellContainer::const_iterator vit, vit_end = tmpViewCells.end(); 
     2217 
     2218                for (vit = tmpViewCells.begin(); vit != vit_end; ++ vit) 
     2219                { 
     2220                        ViewCell *vc = *vit; 
     2221 
     2222                        // store view cells 
     2223                        if (!useMailBoxing || !vc->Mailed()) 
     2224                        { 
     2225                                if (useMailBoxing) // => view cell not mailed 
     2226                                { 
     2227                                        vc->Mail(); 
     2228                                        if (setCounter) 
     2229                                                vc->mCounter = 0; 
     2230                                } 
     2231 
     2232                                viewCells.push_back(vc); 
     2233                        } 
     2234                         
     2235                        if (setCounter) 
     2236                                ++ vc->mCounter; 
     2237                } 
     2238        } 
     2239 
     2240        mCollectTimer.Exit(); 
     2241        return numRays; 
     2242} 
     2243#endif 
     2244 
     2245 
     2246int BvHierarchy::CountViewCells(const ObjectContainer &objects)// const 
    19982247{ 
    19992248        int nViewCells = 0; 
    2000         ViewCell::NewMail(); 
     2249 
     2250        //ViewCell::NewMail(); 
    20012251        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    20022252 
     
    21792429 
    21802430 
    2181 float BvHierarchy::EvalViewCellsVolume(const ObjectContainer &objects) const 
     2431float BvHierarchy::EvalViewCellsVolume(const ObjectContainer &objects)// const 
    21822432{ 
    21832433        float vol = 0; 
     
    22572507        //cout << "using " << nRays << " of " << (int)sampleRays.size() << " rays" << endl; 
    22582508         
     2509#if STORE_VIEWCELLS_WITH_BVH 
     2510        AssociateViewCellsWithObjects(objects); 
     2511#endif 
     2512 
    22592513        // probability that volume is "seen" from the view cells 
    22602514        const float prop = EvalViewCellsVolume(objects) / GetViewSpaceVolume(); 
     
    22832537        bvhLeaf->SetSubdivisionCandidate(oSubdivisionCandidate); 
    22842538 
     2539#if STORE_VIEWCELLS_WITH_BVH 
     2540        ReleaseViewCells(objects); 
     2541#endif 
     2542 
    22852543        if (mApplyInitialPartition) 
    22862544        { 
     
    23252583                                                                                                const ObjectContainer &objects) 
    23262584{ 
    2327         mSortTimer.Entry(); 
    2328  
    23292585        const bool doSort = true; 
    23302586 
     
    23622618        stable_sort(tData.mSortedObjects[3]->begin(), tData.mSortedObjects[3]->end(), smallerSize); 
    23632619        //sort(tData.mSortedObjects[3]->begin(), tData.mSortedObjects[3]->end(), smallerSize); 
    2364  
    2365         mSortTimer.Exit(); 
    23662620} 
    23672621 
     
    24122666                                                const ObjectContainer &objects) 
    24132667{ 
     2668 
    24142669        // reset stats 
    24152670        mBvhStats.Reset(); 
     
    24242679        mRoot = bvhleaf; 
    24252680         
     2681#if STORE_VIEWCELLS_WITH_BVH 
     2682        AssociateViewCellsWithObjects(objects); 
     2683#endif 
     2684 
    24262685        //mTermMinProbability *= mVspTree->GetBoundingBox().GetVolume(); 
    24272686        // probability that volume is "seen" from the view cells 
     
    24382697                AssignInitialSortedObjectList(oData, objects); 
    24392698         
    2440  
     2699#if STORE_VIEWCELLS_WITH_BVH 
     2700        ReleaseViewCells(objects); 
     2701#endif 
    24412702        /////////////////// 
    24422703        //-- add first candidate for object space partition      
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r2187 r2198  
    3535class BvhTree; 
    3636class VspTree; 
    37 class ViewCellsContainer; 
    3837class HierarchyManager; 
    3938 
     
    649648        static float EvalAbsCost(const ObjectContainer &objects); 
    650649 
    651         float EvalProb(const ObjectContainer &objects) const; 
    652  
    653650        void CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects); 
    654651 
     
    658655        void CreateUniqueObjectIds(); 
    659656 
    660         PerfTimer mSortTimer; 
    661657        PerfTimer mNodeTimer; 
    662658        PerfTimer mSubdivTimer; 
    663659        PerfTimer mEvalTimer; 
    664660        PerfTimer mSplitTimer; 
     661        PerfTimer mPlaneTimer; 
     662        PerfTimer mSort2Timer; 
     663        PerfTimer mCollectTimer; 
    665664 
    666665protected: 
     
    710709        /** Evaluates render cost of the bv induced by these objects 
    711710        */ 
    712         float EvalRenderCost(const ObjectContainer &objects) const; 
     711        float EvalRenderCost(const ObjectContainer &objects);// const; 
    713712 
    714713        /** Evaluates tree stats in the BSP tree leafs. 
     
    759758        static void AssociateObjectsWithLeaf(BvhLeaf *leaf); 
    760759 
    761  
     760         
    762761        ///////////////////////////// 
    763762        // Helper functions for local cost heuristics 
     
    834833                                                 ViewCellContainer &viewCells, 
    835834                                                 const bool setCounter, 
    836                                                  const bool onlyUnmailedRays) const; 
     835                                                 const bool onlyUnmailedRays);// const; 
    837836 
    838837        /** Collects view cells which see an object. 
     
    846845                                                 const bool useMailBoxing, 
    847846                                                 const bool setCounter, 
    848                                                  const bool onlyUnmailedRays) const; 
     847                                                 const bool onlyUnmailedRays);// const; 
    849848 
    850849        /** Counts the view cells of this object. note: only 
    851850                counts unmailed objects. 
    852851        */ 
    853         int CountViewCells(Intersectable *obj) const; 
     852        int CountViewCells(Intersectable *obj);// const; 
    854853 
    855854        /** Counts the view cells seen by this bvh leaf 
    856855        */ 
    857         int CountViewCells(const ObjectContainer &objects) const; 
     856        int CountViewCells(const ObjectContainer &objects);// const; 
     857 
     858#if STORE_VIEWCELLS_WITH_BVH 
     859 
     860        int AssociateViewCellsWithObject(Intersectable *obj, const bool useMailBoxing) const; 
     861 
     862        void AssociateViewCellsWithObjects(const ObjectContainer &objects) const; 
     863 
     864        void ReleaseViewCells(const ObjectContainer &objects); 
     865 
     866        int CollectViewCellsFromRays(Intersectable *obj,  
     867                                                                 ViewCellContainer &viewCells, 
     868                                                                 const bool useMailBoxing, 
     869                                                                 const bool setCounter, 
     870                                                                 const bool onlyUnmailedRays); 
     871 
     872        int CountViewCellsFromRays(Intersectable *obj); 
     873#endif 
    858874 
    859875        /** Evaluates increase in pvs size. 
    860876        */ 
    861         int EvalPvsEntriesIncr(BvhSubdivisionCandidate &splitCandidate, const float avgRayContri) const; 
     877        int EvalPvsEntriesIncr(BvhSubdivisionCandidate &splitCandidate,  
     878                                                   const float avgRayContri);// const; 
    862879 
    863880        /** Rays will be clipped to the bounding box. 
     
    901918        /** Evaluates volume of view cells that see the objects. 
    902919        */ 
    903         float EvalViewCellsVolume(const ObjectContainer &objects) const; 
     920        float EvalViewCellsVolume(const ObjectContainer &objects);// const; 
    904921 
    905922        /** Assigns or newly creates initial list of sorted objects. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r2187 r2198  
    282282        // split was not reevaluated before => do it now 
    283283        if (splitCandidate->IsDirty()) 
     284        { 
    284285                splitCandidate->EvalCandidate(); 
     286        } 
    285287 
    286288        return splitCandidate; 
     
    411413void HierarchyManager::PrintTimings(const bool lastSplitWasOsp) 
    412414{ 
    413         double sortTime, evalTime, nodeTime, splitTime, subdTime; 
    414  
    415         sortTime = mBvHierarchy->mSortTimer.TotalTime(); 
     415        double sortTime, evalTime, nodeTime, splitTime, subdTime, planeTime, collectTime, viewCellsTime; 
     416 
     417        sortTime = mBvHierarchy->mSort2Timer.TotalTime(); 
    416418        evalTime = mBvHierarchy->mEvalTimer.TotalTime(); 
    417419        nodeTime = mBvHierarchy->mNodeTimer.TotalTime(); 
    418420        splitTime = mBvHierarchy->mSplitTimer.TotalTime(); 
    419421        subdTime = mBvHierarchy->mSubdivTimer.TotalTime(); 
     422        planeTime = mBvHierarchy->mPlaneTimer.TotalTime(); 
     423        collectTime = mBvHierarchy->mCollectTimer.TotalTime(); 
    420424 
    421425        cout << "bvh times" 
     
    424428                 << " node : " << nodeTime 
    425429                 << " split: " << splitTime 
    426                  << " subd : " << subdTime << endl; 
     430                 << " subd : " << subdTime  
     431                 << " plane: " << planeTime  
     432                 << " colct: " << collectTime 
     433                 << endl; 
    427434 
    428435        Debug << "bvh times" 
     
    431438                 << " node : " << nodeTime 
    432439                 << " split: " << splitTime 
    433                  << " subd : " << subdTime << endl; 
     440                 << " subd : " << subdTime 
     441                 << " plane: " << planeTime  
     442                 << " colct: " << collectTime 
     443                 << endl; 
    434444 
    435445        sortTime = mVspTree->mSortTimer.TotalTime(); 
     
    438448        splitTime = mVspTree->mSplitTimer.TotalTime(); 
    439449        subdTime = mVspTree->mSubdivTimer.TotalTime(); 
     450        planeTime = mVspTree->mPlaneTimer.TotalTime(); 
     451        viewCellsTime = mVspTree->mViewCellsTimer.TotalTime(); 
    440452 
    441453        cout << "vsp times" 
     
    444456                 << " node : " << nodeTime 
    445457                 << " split: " << splitTime 
    446                  << " subd : " << subdTime << endl; 
     458                 << " subd : " << subdTime 
     459                 << " plane: " << planeTime  
     460                 << " viewc: " << viewCellsTime  
     461                 << endl; 
    447462 
    448463        Debug << "vsp times" 
    449                 << " sort : " << sortTime 
    450                  << " eval : " << evalTime 
    451                  << " node : " << nodeTime 
    452                  << " split: " << splitTime 
    453                  << " subd : " << subdTime << endl; 
     464                  << " sort : " << sortTime 
     465                  << " eval : " << evalTime 
     466                  << " node : " << nodeTime 
     467                  << " split: " << splitTime 
     468                  << " subd : " << subdTime 
     469                  << " plane: " << planeTime  
     470                  << " viewc: " << viewCellsTime  
     471                  << endl; 
     472 
    454473        cout << endl; 
    455474        Debug << endl; 
     
    854873        } 
    855874 
    856         //cout << "priority: " << sc->GetPriority() << " rc decr: " << sc->GetRenderCostDecrease() << " | "; 
     875         
    857876        /////////////// 
    858877        //-- split was successful => update stats and queue 
     
    877896        const int pvsEntriesIncr = sc->GetPvsEntriesIncr(); 
    878897        mHierarchyStats.mPvsEntries += pvsEntriesIncr; 
    879         //cout << "pvs entries: " << pvsEntriesIncr << " " << mHierarchyStats.pvsEntries << endl; 
     898        //cout << "pvs entries: " << pvsEntriesIncr << " " << mHierarchyStats.mPvsEntries << endl; 
    880899 
    881900        // memory size in byte 
     
    11561175                        mHierarchyStats.mTotalCost = mBvHierarchy->mTotalCost; 
    11571176                         
     1177 
    11581178                        //mHierarchyStats.mPvsEntries -= mBvHierarchy->mPvsEntries + 1; 
    11591179                        mHierarchyStats.mPvsEntries = mBvHierarchy->CountViewCells(objects); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.cpp

    r2176 r2198  
    1111mBvhLeaf(0),  
    1212mVssRays(NULL)  
     13#if STORE_VIEWCELLS_WITH_BVH 
     14, mViewCells(NULL) 
     15#endif 
    1316{} 
    1417 
     
    6265} 
    6366 
     67#if STORE_VIEWCELLS_WITH_BVH 
     68 
     69ViewCellContainer *Intersectable::GetOrCreateViewCells()  
     70{  
     71        if (!mViewCells) 
     72                mViewCells = new ViewCellContainer(); 
     73 
     74        return mViewCells; 
     75} 
     76 
     77 
     78void Intersectable::DelViewCells() 
     79{ 
     80        DEL_PTR(mViewCells); 
     81} 
     82 
     83#endif 
     84 
    6485 
    6586void Intersectable::DelRayRefs() 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h

    r2176 r2198  
    22#define __INTERSECTABLE_H 
    33 
     4 
    45#include "AxisAlignedBox3.h" 
    5 #include <set> 
    6 //#include "VssRay.h" 
    76#include "Mailable.h" 
     7 
     8#define STORE_VIEWCELLS_WITH_BVH 0 
    89 
    910namespace GtpVisibilityPreprocessor { 
     
    137138   static bool GreaterCounter(const Intersectable *a, 
    138139                                                          const Intersectable *b); 
    139  
    140   /** Returns the name of the type of this intersectable 
    141   */ 
    142   static std::string GetTypeName(Intersectable *obj); 
     140    
     141   /** Returns the name of the type of this intersectable 
     142   */ 
     143   static std::string GetTypeName(Intersectable *obj); 
    143144 
    144145   /** Returns normal from the face with the specified index. 
     
    155156   void DelRayRefs(); 
    156157 
     158 
    157159protected: 
    158  
    159160        /// some rays piercing this intersectable 
    160161        VssRayContainer *mVssRays; 
     162 
     163#if STORE_VIEWCELLS_WITH_BVH 
     164public: 
     165   /** Returns rays stored with this intersectable. 
     166   */ 
     167   ViewCellContainer *GetOrCreateViewCells(); 
     168 
     169   void DelViewCells(); 
     170 
     171protected: 
     172   ViewCellContainer *mViewCells; 
     173#endif 
    161174}; 
    162175 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r2187 r2198  
    11891189        const long t1 = GetTime(); 
    11901190         
    1191         if (1 && (rays.size() > 10000)) 
     1191        if (rays.size() > 10000) 
    11921192        { 
    11931193         
    11941194                mRayCaster->SortRays(rays); 
    11951195                cout<<"Rays sorted in "<<TimeDiff(t1, GetTime())<<" ms."<<endl; 
    1196  
    1197                 if (0) { 
    1198                         VssRayContainer tmpRays; 
    1199                         int m = 890000; 
    1200  
    1201                         for (int i=m; i < m+20; i++) { 
    1202                                 tmpRays.push_back(new VssRay(rays[i].mOrigin, 
    1203                                         rays[i].mOrigin + 100.0f*rays[i].mDirection, 
    1204                                         NULL, 
    1205                                         NULL 
    1206                                         ) 
    1207                                         ); 
    1208  
    1209                         } 
    1210                         ExportRays("sorted_rays.x3d", tmpRays, 200); 
    1211                 } 
    12121196        } 
    12131197 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp

    r2187 r2198  
    250250         
    251251        // old method: always allocate 
    252         if (1) return new VssRay(origin, termination, originObject, terminationObject, pass, pdf); 
     252        if (0) return new VssRay(origin, termination, originObject, terminationObject, pass, pdf); 
    253253 
    254254        VssRay *vssRay = mVssRayPool.Alloc(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Statistics.h

    r2003 r2198  
    1717  static inline double TimeDiff(long time1, long time2) // in s 
    1818  { 
    19     const double clk = 1.0E-6; // ticks per second 
     19    const double clk = 1.0E-3; // ticks per second 
    2020    long t = time2 - time1; 
    2121                 
  • GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj

    r2187 r2198  
    281281                                LinkIncremental="1" 
    282282                                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" 
    283                                 GenerateDebugInformation="FALSE" 
     283                                GenerateDebugInformation="TRUE" 
    284284                                SubSystem="1" 
    285285                                LargeAddressAware="0" 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r2187 r2198  
    27912791         
    27922792        // check if last ray was not same ray with reverse direction 
    2793         if (lastVssRay == NULL || 
     2793        if (!lastVssRay || 
    27942794                !(ray.mOrigin == lastVssRay->mTermination) || 
    27952795                !(ray.mTermination == lastVssRay->mOrigin))  
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r2187 r2198  
    775775                                                                           bool computeSplitPlane) 
    776776{ 
    777         mEvalTimer.Entry(); 
     777        mPlaneTimer.Entry(); 
    778778 
    779779        if (computeSplitPlane) 
     
    796796        } 
    797797         
     798        mPlaneTimer.Exit(); 
     799 
     800        mEvalTimer.Entry(); 
     801 
    798802        VspLeaf *leaf = static_cast<VspLeaf *>(splitCandidate.mParentData.mNode); 
    799803 
     
    11121116        } 
    11131117 
    1114         stable_sort(mLocalSubdivisionCandidates->begin(), mLocalSubdivisionCandidates->end()); 
    1115         //sort(mLocalSubdivisionCandidates->begin(), mLocalSubdivisionCandidates->end()); 
     1118        if (1) 
     1119                stable_sort(mLocalSubdivisionCandidates->begin(), mLocalSubdivisionCandidates->end()); 
     1120        else 
     1121                sort(mLocalSubdivisionCandidates->begin(), mLocalSubdivisionCandidates->end()); 
    11161122 
    11171123        mSortTimer.Exit(); 
     
    25522558ViewCell *VspTree::GetViewCell(const Vector3 &point, const bool active) 
    25532559{ 
    2554         if (mRoot == NULL) 
     2560        if (!mRoot) 
    25552561                return NULL; 
    25562562 
     
    25902596        } 
    25912597   
     2598        // return active or leaf view cell 
    25922599        if (active) 
    25932600        { 
     
    27852792                const AxisAlignedBox3 bbox = GetBoundingBox(node); 
    27862793 
    2787                 if (Overlap(bbox, box)) { 
    2788                   if (node->IsLeaf()) 
    2789                         { 
    2790                           VspLeaf *leaf = static_cast<VspLeaf *>(node); 
    2791                            
    2792                           if (!leaf->GetViewCell()->Mailed() && leaf->TreeValid()) 
     2794                if (Overlap(bbox, box))  
     2795                { 
     2796                        if (node->IsLeaf()) 
     2797                        { 
     2798                                VspLeaf *leaf = static_cast<VspLeaf *>(node); 
     2799 
     2800                                if (!leaf->GetViewCell()->Mailed() && leaf->TreeValid()) 
    27932801                                { 
    2794                                   leaf->GetViewCell()->Mail(); 
    2795                                   viewCells.push_back(leaf->GetViewCell()); 
     2802                                        leaf->GetViewCell()->Mail(); 
     2803                                        viewCells.push_back(leaf->GetViewCell()); 
    27962804                                } 
    27972805                        } 
    2798                   else  
    2799                         { 
    2800                           VspInterior *interior = static_cast<VspInterior *>(node); 
    2801                            
    2802                           VspNode *first = interior->GetFront(); 
    2803                           VspNode *second = interior->GetBack(); 
    2804                            
    2805                           nodeStack.push(first); 
    2806                           nodeStack.push(second); 
     2806                        else  
     2807                        { 
     2808                                VspInterior *interior = static_cast<VspInterior *>(node); 
     2809 
     2810                                VspNode *first = interior->GetFront(); 
     2811                                VspNode *second = interior->GetBack(); 
     2812 
     2813                                nodeStack.push(first); 
     2814                                nodeStack.push(second); 
    28072815                        } 
    28082816                } 
     
    28522860void VspTree::GetViewCells(const VssRay &ray, ViewCellContainer &viewCells) 
    28532861{ 
     2862        mViewCellsTimer.Entry(); 
     2863         
    28542864        static Ray hray; 
    28552865        hray.Init(ray); 
     
    28632873        const Vector3 termination = hray.Extrap(tmax); 
    28642874 
    2865         // view cells were not precomputed 
    2866         // don't mail because we need mailboxing for something else 
     2875        // view cells were not precomputed and are extracted on the fly 
     2876        // don't mail because the same view cells can be found for different rays 
    28672877        CastLineSegment(origin, termination, viewCells, false); 
     2878 
     2879        mViewCellsTimer.Exit(); 
    28682880} 
    28692881 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h

    r2187 r2198  
    728728        PerfTimer mSubdivTimer; 
    729729        PerfTimer mEvalTimer; 
     730        PerfTimer mPlaneTimer; 
     731        PerfTimer mViewCellsTimer; 
    730732 
    731733protected: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp

    r2187 r2198  
    624624{ 
    625625        // store higher order object 
    626         mViewCellsManager->DeterminePvsObjects(rays, false); 
    627 } 
    628  
    629  
    630 } 
     626        mViewCellsManager->DeterminePvsObjects(rays, !mViewCellsManager->ViewCellsConstructed()); 
     627} 
     628 
     629 
     630} 
Note: See TracChangeset for help on using the changeset viewer.