Changeset 1786


Ignore:
Timestamp:
11/24/06 00:24:41 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
14 edited

Legend:

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

    r1785 r1786  
    5252BvhNode::BvhNode():  
    5353mParent(NULL),  
    54 mTimeStamp(0) 
     54mTimeStamp(0), 
     55mRenderCost(-1) 
     56 
    5557{ 
    5658         
     
    6062mParent(NULL),  
    6163mBoundingBox(bbox),  
    62 mTimeStamp(0) 
     64mTimeStamp(0), 
     65mRenderCost(-1) 
    6366{ 
    6467} 
     
    6871mBoundingBox(bbox),  
    6972mParent(parent),  
    70 mTimeStamp(0) 
     73mTimeStamp(0), 
     74mRenderCost(-1) 
    7175{ 
    7276} 
     
    301305        Environment::GetSingleton()->GetIntValue("BvHierarchy.maxTests", mMaxTests); 
    302306        //      Environment::GetSingleton()->GetBoolValue("BvHierarchy.Construction.useInitialSubdivision", mApplyInitialPartition); 
    303          
    304         mInitialObjectsSize = 50; 
     307        Environment::GetSingleton()->GetIntValue("BvHierarchy.Construction.Initial.minObjects", mInitialMinObjects); 
     308        Environment::GetSingleton()->GetFloatValue("BvHierarchy.Construction.Initial.maxAreaRatio", mInitialMaxAreaRatio); 
     309        Environment::GetSingleton()->GetFloatValue("BvHierarchy.Construction.Initial.minArea", mInitialMinArea); 
    305310 
    306311        //mMemoryConst = (float)(sizeof(VspLeaf) + sizeof(VspViewCell)); 
     
    334339        Debug << "bvh mem const: " << mMemoryConst << endl; 
    335340        Debug << "apply initial partition: " << mApplyInitialPartition << endl; 
     341        Debug << "min objects: " << mInitialMinObjects << endl; 
     342        Debug << "max area ratio: " << mInitialMaxAreaRatio << endl; 
     343        Debug << "min area: " << mInitialMinArea << endl; 
     344 
    336345        Debug << endl; 
    337346} 
     
    496505                BvhSubdivisionCandidate *backCandidate =  
    497506                                new BvhSubdivisionCandidate(tBackData); 
    498  
     507                 
    499508                EvalSubdivisionCandidate(*frontCandidate); 
    500509                EvalSubdivisionCandidate(*backCandidate); 
     
    21502159         
    21512160        if (mApplyInitialPartition) 
    2152         { 
    2153                 cout << "§§§§§§§§here41 "<<oSubdivisionCandidate->mParentData.mSortedObjects[3]->size()<<endl; 
     2161        {cout << "here29"<<endl; 
    21542162                ApplyInitialSubdivision(oSubdivisionCandidate, tQueue);          
    21552163        } 
     
    21582166                tQueue.Push(oSubdivisionCandidate); 
    21592167        } 
     2168        cout << "!!size: " << GetStatistics().Leaves() << endl; 
    21602169} 
    21612170 
     
    25102519        {cout << "here2"<<endl; 
    25112520                SubdivisionCandidate *candidate = tempQueue.Top(); 
    2512                 tQueue.Pop(); 
     2521                tempQueue.Pop(); 
    25132522 
    25142523                BvhSubdivisionCandidate *bsc =  
    25152524                        dynamic_cast<BvhSubdivisionCandidate *>(candidate); 
    2516                 cout << "§§§§§§§§here49 "<< bsc->mParentData.mSortedObjects[3]->size()<<endl; 
    2517 cout << "here87 "<<((BvhSubdivisionCandidate *)firstCandidate)->mParentData.mNode->mObjects.size()<<endl; 
    2518                 const bool globalCriteriaMet =  
    2519                         GlobalTerminationCriteriaMet(bsc->mParentData); 
    2520 cout << "here5"<<endl; 
     2525                cout << "§§§§§§§§here49 "<< bsc->mParentData.mSortedObjects[3]->size() << " " << mInitialMinObjects << endl; 
     2526 
     2527                const bool globalCriteriaMet = GlobalTerminationCriteriaMet(bsc->mParentData); 
     2528 
    25212529                if (!InitialTerminationCriteriaMet(bsc->mParentData)) 
    2522                 {cout << "here9"<<bsc->mParentData.mNode->mObjects.size()<<endl; 
     2530                { 
     2531                        cout << "here12"<<endl; 
     2532                        cout << "here9"<<bsc->mParentData.mNode->mObjects.size()<<endl; 
    25232533                        BvhNode *node = Subdivide(tempQueue, bsc, globalCriteriaMet); 
    2524 cout << "here12"<<endl; 
     2534 
    25252535                        // not needed anymore 
    25262536                        delete bsc; 
    25272537                } 
    25282538                else // initial preprocessing  finished for this candidate 
    2529                 {cout << "here15"<<endl; 
     2539                {cout << "here14"<<endl; 
     2540                        // add to "real" traversal queue 
    25302541                        tQueue.Push(bsc); 
    25312542                } 
     
    25442555 
    25452556        ObjectContainer::const_iterator oit, oit_end = objects->end(); 
    2546     cout<<"$$$$$$$$$$$$$$$$$$$"<<endl; 
     2557    cout<<"here104"<<endl; 
    25472558        for (oit = objects->begin(); oit != objects->end(); ++ oit) 
    25482559        { 
    25492560                //cout << (*oit)->GetBox().SurfaceArea() << " "; 
    25502561        } 
    2551 cout<<"$$$$$$$$$$$$$$$$$$$"<<endl; 
    2552         float maxAreaDiff = 0.0f; 
     2562 
     2563        float maxAreaDiff = -1.0f; 
    25532564 
    25542565        ObjectContainer::const_iterator backObjectsStart = objects->begin(); 
    25552566 
    25562567    for (oit = objects->begin(); oit != (objects->end() - 1); ++ oit) 
    2557         { 
     2568        {//cout << "h"; 
    25582569                Intersectable *objS = *oit; 
    25592570                Intersectable *objL = *(oit + 1); 
    25602571                 
    25612572                const float areaDiff =  
    2562                         fabs(objS->GetBox().SurfaceArea() - objL->GetBox().SurfaceArea()); 
     2573                                objL->GetBox().SurfaceArea() - objS->GetBox().SurfaceArea(); 
    25632574 
    25642575                if (areaDiff > maxAreaDiff) 
    25652576                { 
     2577                        //cout << "here5 " << areaDiff << " " << maxAreaDiff << endl; 
    25662578                        maxAreaDiff = areaDiff; 
    25672579                        backObjectsStart = oit + 1; 
     
    25832595 
    25842596 
     2597inline static float AreaRatio(Intersectable *smallObj, Intersectable *largeObj) 
     2598{ 
     2599        const float areaSmall = smallObj->GetBox().SurfaceArea(); 
     2600        const float areaLarge = largeObj->GetBox().SurfaceArea(); 
     2601 
     2602        return areaSmall / (areaLarge - areaSmall + Limits::Small); 
     2603} 
     2604 
     2605 
    25852606bool BvHierarchy::InitialTerminationCriteriaMet(const BvhTraversalData &tData) const 
    25862607{ 
    25872608        return (0 
    2588                     || ((int)tData.mNode->mObjects.size() < mInitialObjectsSize) 
    2589                         || (tData.mNode->mObjects.back()->GetBox().SurfaceArea() < mMinInitialSurfaceArea) 
     2609                    || ((int)tData.mNode->mObjects.size() < mInitialMinObjects) 
     2610                        || (tData.mNode->mObjects.back()->GetBox().SurfaceArea() < mInitialMinArea) 
     2611                        || (AreaRatio(tData.mNode->mObjects.front(), tData.mNode->mObjects.back()) > mInitialMaxAreaRatio) 
    25902612                        ); 
    25912613} 
    25922614 
    25932615 
    2594 } 
     2616// HACK 
     2617float BvHierarchy::GetRenderCostIncrementially(BvhNode *node) const 
     2618{ 
     2619        if (node->mRenderCost < 0) 
     2620        { 
     2621                //cout <<"p"; 
     2622                if (node->IsLeaf()) 
     2623                { 
     2624                        BvhLeaf *leaf = dynamic_cast<BvhLeaf *>(node); 
     2625                        node->mRenderCost = EvalAbsCost(leaf->mObjects); 
     2626                } 
     2627                else 
     2628                { 
     2629                        BvhInterior *interior = dynamic_cast<BvhInterior *>(node); 
     2630                 
     2631                        node->mRenderCost = GetRenderCostIncrementially(interior->GetFront()) +  
     2632                                                                GetRenderCostIncrementially(interior->GetBack()); 
     2633                } 
     2634        } 
     2635 
     2636        return node->mRenderCost; 
     2637} 
     2638 
     2639 
     2640} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1785 r1786  
    207207        inline void SetTimeStamp(const int timeStamp) { mTimeStamp = timeStamp; }; 
    208208 
    209         ///////////////////////////////////// 
    210         //-- mailing options 
    211          
    212 //      static void NewMail(const int reserve = 1) { 
    213 //              sMailId += sReservedMailboxes; 
    214 //              sReservedMailboxes = reserve; 
    215 //      } 
    216          
    217 //      void Mail() { mMailbox = sMailId; } 
    218 //      bool Mailed() const { return mMailbox == sMailId; } 
    219  
    220 //      void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 
    221 //      bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 
    222  
    223 //      int IncMail() { return ++ mMailbox - sMailId; } 
    224  
    225 //      static int sMailId; 
    226 //      //int mMailbox; 
    227 //      static int sReservedMailboxes; 
    228  
    229  
    230  
    231         ///////////////////////////////////////////// 
     209 
     210        //////////////////////// 
    232211        //-- inherited functions from Intersectable 
    233212 
     
    266245 
    267246        /////////////////////////////////// 
     247 
     248        float mRenderCost; 
    268249 
    269250protected: 
     
    644625        void CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects); 
    645626 
     627        float GetRenderCostIncrementially(BvhNode *node) const; 
     628 
     629 
    646630protected: 
    647631 
     
    911895        bool InitialTerminationCriteriaMet(const BvhTraversalData &tData) const; 
    912896 
    913         float mMinInitialSurfaceArea; 
    914         int mInitialObjectsSize; 
    915897 
    916898protected: 
     
    1007989        float mMemoryConst; 
    1008990 
     991        int mMaxTests; 
     992 
    1009993        bool mIsInitialSubdivision; 
    1010994 
    1011995        bool mApplyInitialPartition; 
    1012  
    1013         int mMaxTests; 
     996         
     997        int mInitialMinObjects; 
     998        float mInitialMaxAreaRatio; 
     999        float mInitialMinArea; 
    10141000}; 
    10151001 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r1785 r1786  
    25052505                                        "false"); 
    25062506 
     2507        RegisterOption("BvHierarchy.Construction.Initial.minObjects", 
     2508                                        optInt, 
     2509                                        "bvh_construction_use_initial_min_objects=", 
     2510                                        "100000"); 
     2511 
     2512        RegisterOption("BvHierarchy.Construction.Initial.minArea", 
     2513                                        optFloat, 
     2514                                        "bvh_construction_use_initial_min_area=", 
     2515                                        "0.0001"); 
     2516 
     2517        RegisterOption("BvHierarchy.Construction.Initial.maxAreaRatio", 
     2518                                        optFloat, 
     2519                                        "bvh_construction_use_initial_max_area_ratio=", 
     2520                                        "0.1"); 
     2521 
    25072522        RegisterOption("BvHierarchy.minRaysForVisibility", 
    25082523                                        optInt, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1784 r1786  
    2929#define USE_FIXEDPOINT_T 0 
    3030 
    31  
     31#define STUPID_METHOD 0 
    3232 
    3333/*******************************************************************/ 
     
    17871787                // hack for choosing which node to account for 
    17881788                if (intersect->IsLeaf()) 
     1789                { 
    17891790                        activeNode = dynamic_cast<BvhLeaf *>(intersect)->GetActiveNode(); 
     1791                } 
    17901792                else 
     1793                { 
    17911794                        activeNode = intersect; 
     1795                } 
    17921796 
    17931797                if (!activeNode->Mailed()) 
     
    17951799                        activeNode->Mail(); 
    17961800 
     1801#if STUPID_METHOD 
     1802 
    17971803                        ObjectContainer objects; 
    1798                         activeNode->CollectObjects(objects); 
    1799  
     1804            activeNode->CollectObjects(objects); 
     1805                        rc += mBvHierarchy->EvalAbsCost(objects); 
     1806#else 
     1807                        rc += mBvHierarchy->GetRenderCostIncrementially(activeNode); 
     1808#endif 
    18001809                        ++ pvsEntries; 
    1801                         rc += mBvHierarchy->EvalAbsCost(objects); 
    18021810                } 
    18031811        } 
     
    18101818        //////////////// 
    18111819        //-- pvs is not stored with the interiors => reconstruct 
    1812         ViewCell *root = vc; 
    18131820         
    18141821        // add pvs from leaves 
     
    18241831                if (!vc->GetPvs().Empty()) 
    18251832                { 
     1833                        if (vc->IsLeaf()) cout << " l " << pvs.GetSize(); 
     1834                        else cout << " i " << pvs.GetSize(); 
    18261835                        pvs.MergeInPlace(vc->GetPvs()); 
    18271836                } 
    18281837                else if (!vc->IsLeaf()) // interior cells: go down to leaf level 
    18291838                { 
     1839                        cout <<" t"; 
    18301840                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
    18311841                        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     
    18361846                        }                
    18371847                } 
    1838         } 
    1839 } 
     1848                else cout <<"k"; 
     1849        } 
     1850} 
     1851 
     1852 
     1853// TODO matt: implement this function for different storing methods 
     1854void HierarchyManager::PullUpPvsIncrementally(ViewCell *viewCell) const 
     1855{ 
     1856        //////////////// 
     1857        //-- pvs is not stored with the interiors => reconstruct 
     1858         
     1859        // early exit: pvs is already pulled up to this view cell 
     1860        if (!viewCell->GetPvs().Empty()) 
     1861                return; 
     1862 
     1863        // add pvs from leaves 
     1864        stack<ViewCell *> tstack; 
     1865        tstack.push(viewCell); 
     1866 
     1867        ViewCell *vc = viewCell; 
     1868 
     1869        while (!tstack.empty()) 
     1870        { 
     1871                vc = tstack.top(); 
     1872                tstack.pop(); 
     1873         
     1874                // add newly found pvs to merged pvs: break here even for interior 
     1875                if (!vc->GetPvs().Empty()) 
     1876                { 
     1877                        /*if (vc->IsLeaf())  
     1878                                cout << " l " << viewCell->GetPvs().GetSize(); 
     1879                        else cout << " i " << viewCell->GetPvs().GetSize(); 
     1880                        */ 
     1881                                viewCell->GetPvs().MergeInPlace(vc->GetPvs()); 
     1882                } 
     1883                else if (!vc->IsLeaf()) // interior cells: go down to leaf level 
     1884                { 
     1885                        //cout <<" t"; 
     1886                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
     1887                        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     1888 
     1889                        for (it = interior->mChildren.begin(); it != it_end; ++ it) 
     1890                        { 
     1891                                tstack.push(*it); 
     1892                        }                
     1893                } 
     1894        } 
     1895} 
     1896 
     1897 
     1898 
     1899// TODO matt: implement this function for different storing methods 
     1900void HierarchyManager::GetPvsRecursive(ViewCell *vc, ObjectPvs &pvs) const 
     1901{ 
     1902        //////////////// 
     1903        //-- pvs is not stored with the interiors => reconstruct 
     1904        if (vc->IsLeaf() || !vc->GetPvs().Empty()) 
     1905        { 
     1906                pvs = vc->GetPvs(); 
     1907        } 
     1908        else 
     1909        { 
     1910                ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
     1911#if 0 
     1912                ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     1913                const int childPvsSize = (int)interior->mChildren.size(); 
     1914                vector<ObjectPvs> childPvs; 
     1915                childPvs.resize((int)interior->mChildren.size()); 
     1916 
     1917                int i = 0; 
     1918                for (it = interior->mChildren.begin(); it != it_end; ++ it, ++ i) 
     1919                { 
     1920                        GetPvsRecursive(*it, childPvs[i]); 
     1921                        pvs.MergeInPlace(childPvs[i]); 
     1922                } 
     1923#else 
     1924 
     1925                ObjectPvs leftPvs, rightPvs; 
     1926 
     1927                GetPvsRecursive(interior->mChildren[0], leftPvs); 
     1928                GetPvsRecursive(interior->mChildren[1], rightPvs); 
     1929 
     1930                ObjectPvs::Merge(pvs, leftPvs, rightPvs); 
     1931#endif 
     1932        } 
     1933} 
     1934 
    18401935 
    18411936int HierarchyManager::ExtractStatistics(const int maxSplits, 
     
    18681963        ViewCell::NewMail(); 
    18691964 
     1965        cout << "\n**************viewcells: " << viewCells.size() << endl; 
    18701966        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    18711967        { 
    18721968                ViewCell *vc = *vit; 
    18731969 
     1970                //cout << "\nhere5: "; 
    18741971                float rc = 0; 
    1875         ObjectPvs pvs; 
    1876                  
    1877                 //mVspTree->mViewCellsTree->GetPvs(vc, pvs); 
     1972         
     1973#if STUPID_METHOD        
     1974                ObjectPvs pvs; 
    18781975                GetPvsIncrementally(vc, pvs); 
    1879                  
    18801976                vc->SetPvs(pvs); 
     1977#else 
     1978                //PullUpPvsIncrementally(vc); 
     1979                ObjectPvs pvs; 
     1980                GetPvsRecursive(vc, pvs); 
     1981                vc->SetPvs(pvs); 
     1982#endif 
    18811983 
    18821984                vc->Mail(); 
     
    18841986                if (useFilter) 
    18851987                { 
     1988                        const long startT = GetTime(); 
    18861989                        ObjectPvs filteredPvs; 
    18871990                        mVspTree->mViewCellsManager->ApplyFilter2(vc, false, 1.0f, filteredPvs); 
     1991                        const long endT = GetTime(); 
     1992 
     1993                        cout << "filter computed in " << TimeDiff(startT, endT) * 1e-3f << " secs" << endl; 
    18881994                        ComputePvs(filteredPvs, rc, pvsEntries); 
    18891995                } 
    18901996                else 
    18911997                { 
    1892                         ComputePvs(pvs, rc, pvsEntries); 
     1998                        ComputePvs(vc->GetPvs(), rc, pvsEntries); 
    18931999                } 
    18942000 
     
    19152021        } 
    19162022 
     2023        // store current level 
    19172024        mOldViewCells = viewCells; 
    19182025 
     
    20982205        vector<HierarchySubdivisionStats> subStatsContainer; 
    20992206 
    2100         int splits = (1 + mHierarchyStats.Leaves() / splitsStepSize) * splitsStepSize; 
     2207        int splits = (1 + (mHierarchyStats.Leaves() - 1) / splitsStepSize) * splitsStepSize; 
    21012208        cout << "splits: " << splits << endl; 
    21022209 
     
    21332240                 
    21342241                if (splits == 0) 
     2242                { 
    21352243                        break; 
    2136  
     2244                } 
    21372245                splits -= splitsStepSize; 
    21382246 
    2139                 cout << subStats.mNumSplits << " "; 
     2247                cout << "splits: " << subStats.mNumSplits << " "; 
    21402248        } 
    21412249 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1779 r1786  
    524524        void ComputePvs(const ObjectPvs &pvs, float &rc, int &pvsEntries); 
    525525        void GetPvsIncrementally(ViewCell *vc, ObjectPvs &pvs) const; 
     526        void PullUpPvsIncrementally(ViewCell *viewCell) const; 
     527        void GetPvsRecursive(ViewCell *vc, ObjectPvs &pvs) const; 
    526528protected: 
    527529 
     
    636638 
    637639        ViewCellContainer mOldViewCells; 
     640 
     641        ObjectPvs mOldPvs; 
    638642}; 
    639643 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp

    r1757 r1786  
    5555 
    5656        if (hittriangle != -1 ) { 
    57                 if (hittriangle >= mPreprocessor.mFaceParents.size()) 
    58                         cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 
    59                 else { 
    60                         hitA.mObject = mPreprocessor.mFaceParents[hittriangle].mObject; 
     57                Intersectable *intersect = mPreprocessor.GetParentObject(hittriangle); 
     58                 
     59                if (intersect) 
     60                { 
     61                        hitA.mObject = intersect; 
    6162                        hitA.mNormal = Vector3(normal[0], normal[1], normal[2]); 
    6263                        // Get the normal of that face 
     
    7778                        dist); 
    7879 
    79                 if (hittriangle != -1 ) { 
    80                         if (hittriangle >= mPreprocessor.mFaceParents.size()) 
    81                                 cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 
    82                         else  
    83                         { 
    84                                 hitB.mObject = mPreprocessor.mFaceParents[hittriangle].mObject; 
    85                                 hitB.mNormal = Vector3(normal[0], normal[1], normal[2]); 
    86                                 // Get the normal of that face 
    87                                 //              Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 
    88                                 //              normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
    89                                 //-rays[index+i].mDirection; // $$ temporary 
    90                                 hitB.mPoint = simpleRay.Extrap(dist); 
    91                         } 
     80                Intersectable *intersect = mPreprocessor.GetParentObject(hittriangle); 
     81                 
     82                if (intersect) 
     83                { 
     84                        hitB.mObject = intersect; 
     85                        hitB.mNormal = Vector3(normal[0], normal[1], normal[2]); 
     86                        // Get the normal of that face 
     87                        //              Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 
     88                        //              normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
     89                        //-rays[index+i].mDirection; // $$ temporary 
     90                        hitB.mPoint = simpleRay.Extrap(dist); 
    9291                } 
    9392        } 
     
    170169 
    171170        for (i=0; i < num; i++)  
    172           { 
     171        { 
    173172                Intersection hitA(rays[i].mOrigin), hitB(rays[i].mOrigin); 
    174173 
    175174#if DEBUG_RAYCAST 
    176           Debug<<"FH\n"<<flush; 
    177 #endif 
    178                  
    179                 if (forward_hit_triangles[i] != -1 ) { 
    180                   if (forward_hit_triangles[i] >= mPreprocessor.mFaceParents.size()) 
    181                         cerr<<"Warning: triangle index out of range! "<<forward_hit_triangles[i]<<endl; 
    182                   else {  
    183                         hitA.mObject = mPreprocessor.mFaceParents[forward_hit_triangles[i]].mObject; 
     175                Debug<<"FH\n"<<flush; 
     176#endif 
     177                Intersectable *intersect = mPreprocessor.GetParentObject(forward_hit_triangles[i]); 
     178 
     179                if (intersect) 
     180                { 
     181                        hitA.mObject = intersect; 
    184182                        // Get the normal of that face 
    185                         hitA.mNormal = hitA.mObject->GetNormal(mPreprocessor.mFaceParents[forward_hit_triangles[i]].mFaceIndex); 
     183                        hitA.mNormal = mPreprocessor.GetParentNormal(forward_hit_triangles[i]); 
     184 
    186185                        //-rays[index+i].mDirection; // $$ temporary 
    187186                        hitA.mPoint = rays[index+i].Extrap(forward_dist[i]); 
     187                } 
     188         
     189#if DEBUG_RAYCAST 
     190                Debug<<"BH\n"<<flush; 
     191#endif 
     192 
     193                if (castDoubleRay)  
     194                { 
     195                        Intersectable *intersect = mPreprocessor.GetParentObject(backward_hit_triangles[i]); 
     196 
     197                        if (intersect) 
     198                        {  
     199                                hitB.mObject = intersect; 
     200                                hitB.mNormal = mPreprocessor.GetParentNormal(backward_hit_triangles[i]); 
     201 
     202                                // normalB = rays[index+i].mDirection; // $$ temporary 
     203                                hitB.mPoint = rays[index+i].Extrap(-backward_dist[i]); 
    188204                        } 
    189           } 
    190 #if DEBUG_RAYCAST 
    191           Debug<<"BH\n"<<flush; 
    192 #endif 
    193            
    194           if (castDoubleRay && (backward_hit_triangles[i] != -1)) { 
    195                 if (backward_hit_triangles[i] >= mPreprocessor.mFaceParents.size()) 
    196                   cerr<<"Warning: triangle  index out of range! "<<backward_hit_triangles[i]<<endl; 
    197                 else {  
    198                   hitB.mObject = mPreprocessor.mFaceParents[backward_hit_triangles[i]].mObject; 
    199                   hitB.mNormal = hitB.mObject->GetNormal(mPreprocessor.mFaceParents[backward_hit_triangles[i]].mFaceIndex); 
    200                    
    201                   // normalB = rays[index+i].mDirection; // $$ temporary 
    202                   hitB.mPoint = rays[index+i].Extrap(-backward_dist[i]); 
    203                 } 
    204           } 
    205            
    206 #if DEBUG_RAYCAST 
    207           Debug<<"PR\n"<<flush; 
    208 #endif 
    209            
    210           ProcessRay( 
    211                                  rays[index + i], 
    212                                  hitA, 
    213                                  hitB, 
    214                                  vssRays, 
    215                                  sbox, 
    216                                  castDoubleRay, 
    217                                  pruneInvalidRays 
    218                                  ); 
    219         } 
    220          
     205                } 
     206 
     207#if DEBUG_RAYCAST 
     208                Debug<<"PR\n"<<flush; 
     209#endif 
     210 
     211                ProcessRay(rays[index + i], 
     212                                   hitA, 
     213                                   hitB, 
     214                                   vssRays, 
     215                                   sbox, 
     216                                   castDoubleRay, 
     217                                   pruneInvalidRays 
     218                                   ); 
     219        } 
     220 
    221221#if DEBUG_RAYCAST 
    222222        Debug<<"C16F\n"<<flush; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp

    r1765 r1786  
    5656        return mItem.GetNormal(); 
    5757} 
     58 
    5859 
    5960int 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Parser.h

    r1379 r1786  
    2222                                                 const bool loadMeshes = true, 
    2323                                                 std::vector<FaceParentInfo> *parents = NULL)  
    24   {return false;}; 
     24  {return false;} 
    2525         
    2626}; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1785 r1786  
    247247        FaceContainer faces; 
    248248 
     249        if (parents) 
     250                cout << "using face parents" << endl; 
     251        else 
     252                cout << "not using face parents" << endl; 
     253 
    249254        while (1) 
    250255        { 
     
    370375        } 
    371376        return result; 
     377} 
     378 
     379 
     380Intersectable *Preprocessor::GetParentObject(const int index) const 
     381{ 
     382        if (index == -1) 
     383                return NULL; 
     384         
     385        if (!mFaceParents.empty()) 
     386        { 
     387                if (index >= (int)mFaceParents.size()) 
     388                { 
     389                        cerr<<"Warning: triangle  index out of range! "<<index<<endl; 
     390                        return NULL; 
     391                } 
     392                else 
     393                { 
     394                        return mFaceParents[index].mObject; 
     395                } 
     396        } 
     397        else 
     398        { 
     399                if (index >= (int)mObjects.size()) 
     400                { 
     401                        cerr<<"Warning: triangle  index out of range! "<<index<<endl; 
     402                        return NULL; 
     403                } 
     404                else 
     405                { 
     406                        return mObjects[index]; 
     407                } 
     408        } 
     409} 
     410 
     411 
     412Vector3 Preprocessor::GetParentNormal(const int index) const 
     413{ 
     414        if (!mFaceParents.empty()) 
     415        { 
     416                return mFaceParents[index].mObject->GetNormal(mFaceParents[index].mFaceIndex); 
     417        }        
     418        else 
     419        { 
     420                return mObjects[index]->GetNormal(0); 
     421        } 
    372422} 
    373423 
     
    392442        int rayCastMethod; 
    393443        Environment::GetSingleton()->GetIntValue("Preprocessor.rayCastMethod", rayCastMethod); 
    394         vector<FaceParentInfo> *fi = (rayCastMethod == RayCaster::INTEL_RAYCASTER) ? 
     444        vector<FaceParentInfo> *fi = ((rayCastMethod == RayCaster::INTEL_RAYCASTER) || (!mLoadMeshes)) ? 
    395445                &mFaceParents : NULL; 
    396446 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1785 r1786  
    121121        bool ExportKdTree(const string filename); 
    122122 
    123   virtual int 
    124   GenerateRays(const int number, 
    125                            const SamplingStrategy &strategy, 
    126                            SimpleRayContainer &rays); 
    127    
    128   virtual int GenerateRays(const int number, 
    129                                                    const int raysType, 
    130                                                    SimpleRayContainer &rays); 
    131    
    132   bool GenerateRayBundle(SimpleRayContainer &rayBundle, 
    133                                                  const SimpleRay &mainRay, 
    134                                                  const int number, 
    135                                                  const int shuffleType) const; 
    136    
    137   virtual void CastRays(SimpleRayContainer &rays, 
    138                                                 VssRayContainer &vssRays, 
    139                                                 const bool castDoubleRays, 
    140                                                 const bool pruneInvalidRays = true); 
    141    
     123        virtual int 
     124                GenerateRays(const int number, 
     125                const SamplingStrategy &strategy, 
     126                SimpleRayContainer &rays); 
     127 
     128        virtual int GenerateRays(const int number, 
     129                const int raysType, 
     130                SimpleRayContainer &rays); 
     131 
     132        bool GenerateRayBundle(SimpleRayContainer &rayBundle, 
     133                const SimpleRay &mainRay, 
     134                const int number, 
     135                const int shuffleType) const; 
     136 
     137        virtual void CastRays(SimpleRayContainer &rays, 
     138                VssRayContainer &vssRays, 
     139                const bool castDoubleRays, 
     140                const bool pruneInvalidRays = true); 
     141 
    142142        /** Returns a view cells manager of the given name. 
    143143        */ 
     
    148148        bool InitRayCast(const string externKdTree, const string internKdTree); 
    149149 
    150 bool ExportObj(const string filename, const ObjectContainer &objects); 
    151  
     150        bool ExportObj(const string filename, const ObjectContainer &objects); 
     151 
     152        Intersectable *GetParentObject(const int index) const; 
     153Vector3 GetParentNormal(const int index) const; 
    152154        //////////////////////////////////////////////// 
    153155 
     
    202204        bool mExportObj; 
    203205 
    204   ofstream mStats; 
     206        ofstream mStats; 
    205207 
    206208  GlRendererBuffer *renderer; 
     
    214216        bool ExportBinaryObj(const string filename, SceneGraphNode *root); 
    215217 
    216  
    217218        void SetupRay(Ray &ray, const Vector3 &point, const Vector3 &direction) const; 
    218219 
    219220        void EvalPvsStat(); 
    220221 
    221   virtual void 
    222   EvalViewCellHistogram(); 
     222        virtual void EvalViewCellHistogram(); 
    223223 
    224224        ///////////////////////// 
     
    229229        /// samples used for construction of the VSP OSP tree. 
    230230        int mVspOspConstructionSamples; 
    231         /** Simulates rendering of the scene. 
    232         */ 
     231        /// Simulates rendering of the scene. 
    233232        RenderSimulator *mRenderSimulator; 
    234233 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h

    r1764 r1786  
    407407void Pvs<T, S>::MergeInPlace(const Pvs<T, S> &a) 
    408408{ 
     409        // early exit 
     410        if (a.Empty()) 
     411        { 
     412                return; 
     413        } 
     414        else if (Empty()) 
     415        { 
     416                mEntries.reserve(a.GetSize()); 
     417                mEntries = a.mEntries; 
     418                mSamples = a.mSamples; 
     419                return; 
     420        } 
     421 
    409422        ObjectPvs interPvs; 
    410423         
     
    467480        mEntries.clear(); 
    468481        mSamples = 0; 
    469         vector<PvsEntry<T,S> >().swap(mEntries); 
     482 
     483        if (trim) 
     484        { 
     485                vector<PvsEntry<T,S> >().swap(mEntries); 
     486        } 
    470487} 
    471488 
     
    473490template <typename T, typename S> void Pvs<T, S>::Trim() 
    474491{ 
    475         vector<PvsEntry<T,S> >(mEntries).swap(mEntries);//trim vi 
     492        vector<PvsEntry<T,S> >(mEntries).swap(mEntries); 
    476493} 
    477494 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1772 r1786  
    529529        float totalRenderCost = 0; 
    530530 
     531        ////////////////// 
    531532        //-- compute statistics values of initial view cells 
     533 
    532534        mViewCellsManager->EvaluateRenderStatistics(totalRenderCost, 
    533535                                                                                                mExpectedCost, 
     
    537539                                                                                                mAvgRenderCost); 
    538540 
    539  
     541        ///////////// 
    540542        //-- fill merge queue 
    541543        vector<MergeCandidate> candidates; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1785 r1786  
    25912591 
    25922592 
     2593void ViewCellsManager::MergeViewCellsEfficient(ObjectPvs &pvs, const ViewCellContainer &viewCells) const 
     2594{ 
     2595        LocalMergeTree mergeTree(viewCells); 
     2596        mergeTree.Merge(pvs); 
     2597} 
     2598 
     2599#if 1 
    25932600PvsFilterStatistics 
    25942601ViewCellsManager::ApplyFilter2(ViewCell *viewCell, 
     
    26022609  AxisAlignedBox3 vbox = GetViewCellBox(viewCell); 
    26032610  Vector3 center = vbox.Center(); 
    2604   // COpy the PVS 
     2611  // copy the PVS 
    26052612  ObjectPvs basePvs = viewCell->GetPvs(); 
    26062613  Intersectable::NewMail(); 
     
    27402747  return stats; 
    27412748} 
     2749#else 
     2750PvsFilterStatistics 
     2751ViewCellsManager::ApplyFilter2(ViewCell *viewCell, 
     2752                                                           const bool useViewSpaceFilter, 
     2753                                                           const float filterSize, 
     2754                                                           ObjectPvs &pvs 
     2755                                                           ) 
     2756{cout << "x"; 
     2757  PvsFilterStatistics stats; 
     2758 
     2759  AxisAlignedBox3 vbox = GetViewCellBox(viewCell); 
     2760  Vector3 center = vbox.Center(); 
     2761  // copy the PVS 
     2762  ObjectPvs basePvs = viewCell->GetPvs(); 
     2763  Intersectable::NewMail(); 
     2764 
     2765  ObjectPvsIterator pit = basePvs.GetIterator(); 
     2766 
     2767#if !USE_KD_PVS 
     2768  // first mark all object from this pvs 
     2769  while (pit.HasMoreEntries()) {                 
     2770        ObjectPvsEntry entry = pit.Next(); 
     2771         
     2772        Intersectable *object = entry.mObject; 
     2773        object->Mail(); 
     2774  } 
     2775#endif 
     2776 
     2777  int pvsSize = 0; 
     2778  int nPvsSize = 0; 
     2779  float samples = (float)basePvs.GetSamples(); 
    27422780   
     2781  Debug<<"f #s="<<samples<<"pvs size = "<<basePvs.GetSize(); 
     2782  //  cout<<"Filter size = "<<filterSize<<endl; 
     2783  //  cout<<"vbox = "<<vbox<<endl; 
     2784  //  cout<<"center = "<<center<<endl; 
     2785 
     2786 
     2787   // Minimal number of local samples to take into account 
     2788   // the local sampling density. 
     2789   // The size of the filter is a minimum of the conservative 
     2790   // local sampling density estimate (#rays intersecting teh viewcell and 
     2791   // the object) 
     2792   // and gobal estimate for the view cell 
     2793   // (total #rays intersecting the viewcell) 
     2794#define MIN_LOCAL_SAMPLES 5 
     2795 
     2796  float viewCellRadius = 0.5f*Magnitude(vbox.Diagonal()); 
    27432797   
     2798  // now compute the filter box around the current viewCell 
     2799   
     2800  if (useViewSpaceFilter) { 
     2801        //      float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 
     2802        float radius = viewCellRadius/100.0f; 
     2803        vbox.Enlarge(radius); 
     2804        cout<<"vbox = "<<vbox<<endl; 
     2805        ViewCellContainer viewCells; 
     2806        ComputeBoxIntersections(vbox, viewCells); 
     2807        ObjectPvs pvs; 
     2808        MergeViewCellsEfficient(pvs, viewCells); 
     2809        basePvs = pvs; 
     2810                 
     2811        // update samples and globalC 
     2812        samples = (float)pvs.GetSamples(); 
     2813        //      cout<<"neighboring viewcells = "<<i-1<<endl; 
     2814        //      cout<<"Samples' = "<<samples<<endl; 
     2815  } 
     2816 
     2817  // Minimal number of samples so that filtering takes place 
     2818#define MIN_SAMPLES  100 
     2819  if (samples > MIN_SAMPLES) { 
     2820        float globalC = 2.0f*filterSize/sqrt(samples); 
     2821         
     2822        pit = basePvs.GetIterator(); 
     2823         
     2824        ObjectContainer objects; 
     2825         
     2826        while (pit.HasMoreEntries()) 
     2827          {              
     2828                ObjectPvsEntry entry = pit.Next(); 
     2829                 
     2830                Intersectable *object = entry.mObject; 
     2831                // compute filter size based on the distance and the numebr of samples 
     2832                AxisAlignedBox3 box = object->GetBox(); 
     2833                 
     2834                float distance = Distance(center, box.Center()); 
     2835                float globalRadius = distance*globalC; 
     2836                 
     2837                int objectSamples = (int)entry.mData.mSumPdf; 
     2838                float localRadius = MAX_FLOAT; 
     2839                if (objectSamples > MIN_LOCAL_SAMPLES) 
     2840                  localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 
     2841                        sqrt((float)objectSamples); 
     2842                 
     2843                //      cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 
     2844                 
     2845                // now compute the filter size 
     2846                float radius; 
     2847 
     2848                if (localRadius < globalRadius) { 
     2849                  radius = localRadius; 
     2850                  stats.mLocalFilterCount++; 
     2851                } else { 
     2852                  radius = globalRadius; 
     2853                  stats.mGlobalFilterCount++; 
     2854                } 
     2855 
     2856                stats.mAvgFilterRadius += radius; 
     2857                 
     2858                // cout<<"box = "<<box<<endl; 
     2859                //      cout<<"distance = "<<distance<<endl; 
     2860                //      cout<<"radiues = "<<radius<<endl; 
     2861                 
     2862                box.Enlarge(Vector3(radius)); 
     2863                 
     2864                objects.clear(); 
     2865                // $$ warning collect objects takes only unmailed ones! 
     2866                CollectObjects(box, objects); 
     2867                //      cout<<"collected objects="<<objects.size()<<endl; 
     2868                ObjectContainer::const_iterator noi = objects.begin(); 
     2869                for (; noi != objects.end(); ++ noi) { 
     2870                  Intersectable *o = *noi; 
     2871                  // $$ JB warning: pdfs are not correct at this point!    
     2872                  pvs.AddSampleDirty(o, Limits::Small); 
     2873                } 
     2874          } 
     2875        stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 
     2876  } 
     2877   
     2878  Debug<<" nPvs size = "<<pvs.GetSize()<<endl; 
     2879 
     2880#if !USE_KD_PVS 
     2881  // copy the base pvs to the new pvs 
     2882  pit = basePvs.GetIterator(); 
     2883  while (pit.HasMoreEntries()) {                 
     2884        ObjectPvsEntry entry = pit.Next(); 
     2885        pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf); 
     2886  } 
     2887#endif 
     2888  viewCell->SetFilteredPvsSize(pvs.GetSize()); 
     2889   
     2890  Intersectable::NewMail(); 
     2891  return stats; 
     2892} 
     2893#endif 
    27442894 
    27452895   
     
    60316181                //dummyStrat.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION); 
    60326182 
    6033                 CastPassSamples(samplesPerPass, mStrategies, evaluationSamples); 
     6183                CastPassSamples(samplesPerPass, dummyStrat, evaluationSamples); 
     6184                //CastPassSamples(samplesPerPass, mStrategies, evaluationSamples); 
    60346185                 
    60356186                castSamples += samplesPerPass; 
     
    61186269} 
    61196270#endif 
    6120 } 
     6271 
     6272 
     6273LocalMergeTree::LocalMergeTree(const ViewCellContainer &viewCells): 
     6274mViewCells(viewCells) 
     6275{ 
     6276        mRoot = Subdivide(0, (int)mViewCells.size()); 
     6277} 
     6278 
     6279 
     6280void LocalMergeTree::Merge(ObjectPvs &mergedPvs) 
     6281{ 
     6282        Merge(mRoot, mergedPvs); 
     6283} 
     6284 
     6285 
     6286void LocalMergeTree::Merge(LocalMergeNode *node, ObjectPvs &mergedPvs) 
     6287{ 
     6288        //////////////// 
     6289        //-- pvs is not stored with the interiors => reconstruct 
     6290        if (node->IsLeaf()) 
     6291        { 
     6292                LocalMergeLeaf *leaf = dynamic_cast<LocalMergeLeaf *>(node); 
     6293        mergedPvs = leaf->mViewCell->GetPvs(); 
     6294        } 
     6295        else 
     6296        { 
     6297                LocalMergeInterior *interior = dynamic_cast<LocalMergeInterior *>(node); 
     6298 
     6299                ObjectPvs leftPvs, rightPvs; 
     6300 
     6301                Merge(interior->mLeft, leftPvs); 
     6302                Merge(interior->mRight, rightPvs); 
     6303 
     6304                ObjectPvs::Merge(mergedPvs, leftPvs, rightPvs); 
     6305        }        
     6306} 
     6307 
     6308 
     6309LocalMergeNode *LocalMergeTree::Subdivide(const int leftIdx, const int rightIdx) 
     6310{ 
     6311        if (leftIdx == rightIdx) 
     6312        { 
     6313                return new LocalMergeLeaf(mViewCells[leftIdx]); 
     6314        } 
     6315 
     6316        LocalMergeInterior *interior = new LocalMergeInterior(); 
     6317 
     6318        const int midSplit = (leftIdx + rightIdx) / 2; 
     6319 
     6320        interior->mLeft = Subdivide(leftIdx, midSplit); 
     6321        interior->mRight = Subdivide(midSplit,  rightIdx); 
     6322 
     6323        return interior; 
     6324} 
     6325 
     6326 
     6327 
     6328} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1773 r1786  
    3838class BvHierarchy; 
    3939class ViewCellsTree; 
     40class ViewCell; 
    4041 
    4142struct AxisAlignedPlane; 
     
    6465  // some characteristic values could be stored as well 
    6566}; 
     67 
     68 
     69class LocalMergeNode 
     70{ 
     71public: 
     72        virtual ~LocalMergeNode() {}; 
     73        virtual bool IsLeaf() const = 0; 
     74}; 
     75 
     76 
     77class LocalMergeLeaf: public LocalMergeNode 
     78{ 
     79public: 
     80        LocalMergeLeaf(ViewCell *vc): mViewCell(vc) {}; 
     81        virtual ~LocalMergeLeaf() {}; 
     82        virtual bool IsLeaf() const { return true; } 
     83 
     84        ViewCell *mViewCell; 
     85}; 
     86 
     87 
     88class LocalMergeInterior: public LocalMergeNode 
     89{ 
     90public: 
     91         
     92        virtual ~LocalMergeInterior() {DEL_PTR(mLeft); DEL_PTR(mRight);} 
     93        virtual bool IsLeaf() const { return false; } 
     94 
     95        LocalMergeNode *mLeft; 
     96        LocalMergeNode *mRight; 
     97}; 
     98 
     99 
     100class LocalMergeTree 
     101{ 
     102public: 
     103 
     104        LocalMergeTree(const ViewCellContainer &viewCells); 
     105         
     106        void Merge(ObjectPvs &mergedPvs); 
     107 
     108protected: 
     109 
     110        void Merge(LocalMergeNode *node, ObjectPvs &mergedPvs); 
     111        LocalMergeNode *Subdivide(const int leftIdx, const int rightIdx); 
     112 
     113        LocalMergeNode *mRoot; 
     114        const ViewCellContainer &mViewCells; 
     115}; 
     116 
    66117 
    67118/**     Manages different higher order operations on the view cells. 
     
    452503        bool GetExportPvs() const; 
    453504 
     505        /** Efficiently merges the view cells in the container. 
     506        */ 
     507        void MergeViewCellsEfficient(ObjectPvs &pvs, const ViewCellContainer &viewCells) const; 
     508 
     509 
    454510        ///////////////////////////// 
    455511        // static members 
Note: See TracChangeset for help on using the changeset viewer.