Changeset 557


Ignore:
Timestamp:
01/19/06 23:36:01 (18 years ago)
Author:
mattausch
Message:

started implementing merge visualization !not working!!

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r555 r557  
    2929VssPreprocessor { 
    3030        samplesPerPass  100000 
    31         initialSamples 300000 
    32         vssSamples 1500000 
     31        initialSamples 1000000 
     32        vssSamples 0 
    3333        vssSamplesPerPass 500000 
    3434        useImportanceSampling true 
     
    5252        maxDepth        40 
    5353        minPvs          30 
    54         minRays         400 
     54        minRays         800 
    5555        minSize         0.001 
    5656        maxCostRatio    1.5 
     
    170170 
    171171ViewCells { 
    172         loadFromFile true 
    173         exportToFile false 
     172        loadFromFile false 
     173        exportToFile true 
    174174        #type kdTree 
    175175        #type vspKdTree 
     
    182182        maxViewCells 3000 
    183183        #percentage of total visible objects where pvs is considered invalid 
    184         maxPvsRatio 1.0 
    185                  
    186         delayedConstruction true 
     184        maxPvsRatio 0.9 
     185                 
     186        delayedConstruction false 
    187187                 
    188188                 
     
    259259VspBspTree { 
    260260        Construction { 
    261                 samples 900000 
     261                samples 500000 
    262262                epsilon 0.005 
    263263                randomize false 
     
    292292        Termination { 
    293293                # parameters used for autopartition 
    294                 minRays                 100 
     294                minRays                 300 
    295295                minPolygons             -1 
    296296                maxDepth                30 
     
    298298                #minProbability         0.0001 
    299299                minProbability          -1 
    300                 maxRayContribution      0.6 
    301                 maxCostRatio            0.99 
     300                maxRayContribution      0.1 
     301                maxCostRatio            0.9 
    302302                missTolerance           3 
    303303                #maxAccRayLength        100 
    304304                 
    305                 maxViewCells            3501 
     305                maxViewCells            1000 
    306306                 
    307307                # used for pvs criterium 
     
    323323        PostProcess { 
    324324                maxCostRatio 0.1 
    325                 minViewCells 200 
    326                 useRaysForMerge false 
     325                minViewCells 100 
     326                useRaysForMerge true 
    327327        } 
    328328} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp

    r547 r557  
    17591759} 
    17601760 
     1761 
    17611762bool AxisAlignedBox3::GetRaySegment(const Ray &ray,  
    17621763                                                                        float &minT,  
    17631764                                                                        float &maxT) const 
    17641765{ 
    1765         maxT = 1e6; 
     1766        maxT = 1e15; 
    17661767        minT = 0; 
    17671768         
    1768         // test with  bounding box 
     1769        // test with bounding box 
    17691770        if (!GetMinMaxT(ray, &minT, &maxT)) 
    17701771                return false; 
    17711772 
    1772         if (minT < 0) // start ray from origin 
     1773        if (minT < 0) 
    17731774                minT = 0; 
    17741775 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r556 r557  
    139139 
    140140 
     141float ViewCellsManager::GetViewSpaceVolume() 
     142{ 
     143        return mViewSpaceBox.GetVolume()*(2.0f*sqr(M_PI)); 
     144} 
     145 
     146 
    141147bool ViewCellsManager::ViewPointValid(const Vector3 &viewPoint) const 
    142148{ 
     
    428434        //hray.Init(ray.GetOrigin(), ray.GetDir(), Ray::LINE_SEGMENT); 
    429435        if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 
    430         return; 
     436                return; 
    431437 
    432438        Vector3 origin = hray.Extrap(tmin); 
     
    679685{ 
    680686        // compute view cell area as subsititute for probability 
    681 #if 0 
    682         return GetArea(viewCell) / GetViewSpaceBox().SurfaceArea(); 
     687#if 1 
     688        return GetVolume(viewCell) / GetViewSpaceBox().GetVolume(); 
    683689#else 
    684690        return GetArea(viewCell) / GetAccVcArea(); 
     
    835841                cout << "exporting view cells after merge ... "; 
    836842                Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 
     843 
    837844 
    838845                if (exporter) 
     
    18881895        VssRayContainer savedRays; 
    18891896 
    1890         Debug << "construction samples: " << mConstructionSamples << " rays: " << rays.size() << endl; 
     1897        Debug << "construction samples: " << mConstructionSamples << " rays: " << (int)rays.size() << endl; 
    18911898        GetRaySets(rays, mConstructionSamples, constructionRays, &savedRays); 
    18921899 
     
    21762183                                exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 
    21772184                        } 
    2178  
     2185                         
    21792186                        ExportViewCellsForViz(exporter); 
    21802187                        delete exporter; 
    21812188                } 
     2189        } 
     2190 
     2191        // export shuffled view cells 
     2192        if (1) 
     2193        { 
     2194                cout << "exporting shuffled view cells ..."; 
     2195 
     2196                Exporter *exporter = Exporter::GetExporter("shuffled_view_cells.x3d"); 
     2197                if (exporter) 
     2198                { 
     2199                        if (1) 
     2200                        { 
     2201                                exporter->SetWireframe(); 
     2202                                exporter->ExportBox(mViewSpaceBox); 
     2203                                exporter->SetFilled(); 
     2204                        } 
     2205 
     2206                        if (mExportGeometry) 
     2207                        { 
     2208                                exporter->ExportGeometry(objects); 
     2209                        } 
     2210 
     2211                        ViewCellContainer::const_iterator vit, vit_end = mViewCells.end(); 
     2212 
     2213                        Material vm, lm; 
     2214 
     2215                        for (vit = mViewCells.begin(); vit != mViewCells.end(); ++ vit) 
     2216                        { 
     2217                                BspViewCell *vc = dynamic_cast<BspViewCell *>(*vit); 
     2218 
     2219                                vm = RandomMaterial(); 
     2220 
     2221                                lm = vm; 
     2222                                         
     2223                                vm.mDiffuseColor.r -= 0.3f; 
     2224                                vm.mDiffuseColor.g -= 0.3f; 
     2225                                vm.mDiffuseColor.b -= 0.3f; 
     2226 
     2227                                vector<BspLeaf *>::const_iterator lit, lit_end = vc->mLeaves.end(); 
     2228 
     2229                                for (lit = vc->mLeaves.begin(); lit != lit_end; ++ lit) 
     2230                                { 
     2231                                        BspLeaf *leaf = *lit; 
     2232 
     2233                                        if (leaf->Mailed()) 
     2234                                                exporter->SetForcedMaterial(lm); 
     2235                                        else 
     2236                                                exporter->SetForcedMaterial(vm); 
     2237                                         
     2238                                        BspNodeGeometry geom; 
     2239                                        mVspBspTree->ConstructGeometry(leaf, geom); 
     2240                                        exporter->ExportPolygons(geom.mPolys); 
     2241                                } 
     2242                        } 
     2243                         
     2244                        delete exporter; 
     2245                } 
     2246 
    21822247 
    21832248                cout << "finished" << endl; 
     
    23752440                        importance = (float)bspVc->mLeaves.size() / 
    23762441                                (float)mViewCellsStats.maxLeaves; 
    2377  
    2378                         if (CheckValid(vc)) 
    2379                                 m.mDiffuseColor.b = 1.0f; 
    2380                         m.mDiffuseColor.r = importance; 
    2381                         m.mDiffuseColor.g = 1.0f - m.mDiffuseColor.r; 
    23822442                } 
    23832443                break; 
     
    23872447                                (float)(mVspBspTree->GetStatistics().maxDepth * 2); 
    23882448 
    2389                         if (CheckValid(vc)) 
    2390                                 m.mDiffuseColor.b = 1.0f; 
    2391                         m.mDiffuseColor.r = importance; 
    2392                         m.mDiffuseColor.g = 1.0f - m.mDiffuseColor.r; 
    23932449                } 
    23942450                break; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h

    r556 r557  
    301301 
    302302 
    303   virtual float GetViewSpaceVolume() { 
    304         return mViewSpaceBox.GetVolume()*(2.0f*sqr(M_PI)); 
    305   } 
     303        virtual float GetViewSpaceVolume(); 
     304         
    306305        /** Creates meshes from the view cells. 
    307306        */ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r556 r557  
    3838bool BspMergeCandidate::sUseArea = false; 
    3939 
     40 
    4041/********************************************************************/ 
    4142/*                  class VspBspTree implementation                 */ 
    4243/********************************************************************/ 
     44 
    4345 
    4446VspBspTree::VspBspTree(): 
     
    498500 
    499501                mStat.contributingSamples += conSamp; 
    500                 mStat.sampleContributions += sampCon; 
     502                mStat.sampleContributions +=(int) sampCon; 
    501503 
    502504                //-- store additional info 
     
    19151917typedef pair<BspNode *, BspNodeGeometry *> bspNodePair; 
    19161918 
     1919 
    19171920int VspBspTree::FindNeighbors(BspNode *n, vector<BspLeaf *> &neighbors, 
    19181921                                                   const bool onlyUnmailed) const 
     
    19251928        // split planes from the root to this node 
    19261929        // needed to verify that we found neighbor leaf 
     1930        // TODO: really needed? 
    19271931        vector<Plane3> halfSpaces; 
    19281932        ExtractHalfSpaces(n, halfSpaces); 
     
    19341938        nodeStack.push(bspNodePair(mRoot, rgeom)); 
    19351939 
     1940        Debug << "here77" << endl; 
    19361941 
    19371942        while (!nodeStack.empty()) 
     
    19421947                nodeStack.pop(); 
    19431948 
    1944                 bool isAdjacent = true; 
    1945  
    1946                  
     1949                if (node->IsLeaf()) 
     1950                {        
     1951                        Debug << "here22" << endl; 
     1952                        // test if this leaf is in valid view space 
     1953                        if (node->TreeValid() && 
     1954                                (node != n) &&  
     1955                                (!onlyUnmailed || !node->Mailed())) 
     1956                        { 
     1957                                Debug << "here" << endl; 
     1958                                bool isAdjacent = true; 
    19471959#if 1 
    1948                 // test all planes of current node if still adjacent 
    1949                 for (int i = 0; (i < halfSpaces.size()) && isAdjacent && (node != n); ++ i) 
    1950                 { 
    1951                         const int cf = 
    1952                                 Polygon3::ClassifyPlane(geom->mPolys, 
    1953                                                                                 halfSpaces[i], 
    1954                                                                                 mEpsilon); 
    1955  
    1956                         if (cf == Polygon3::BACK_SIDE) 
    1957                         { 
    1958                                 isAdjacent = false; 
    1959                         } 
    1960                 } 
    1961 #else 
    1962                 // test all planes of current node if still adjacent 
    1963                 for (int i = 0; i < nodeGeom.size()) && isAdjacent && (node != n); ++ i) 
    1964                 { 
    1965                         Polygon3 *poly = nodeGeom->mPolys[i]; 
    1966  
    1967                         const int cf = 
    1968                                 Polygon3::ClassifyPlane(geom->mPolys, 
    1969                                                                                 poly->GetSupportingPlane(), 
    1970                                                                                 mEpsilon); 
    1971  
    1972                         if (cf == Polygon3::BACK_SIDE) 
    1973                         { 
    1974                                 isAdjacent = false; 
    1975                         } 
    1976                 } 
     1960 
     1961                                // test all planes of current node if still adjacent 
     1962                                for (int i = 0; (i < halfSpaces.size()) && isAdjacent; ++ i) 
     1963                                { 
     1964                                        const int cf = 
     1965                                                Polygon3::ClassifyPlane(geom->mPolys, 
     1966                                                                                                halfSpaces[i], 
     1967                                                                                                mEpsilon); 
     1968 
     1969                                        if (cf == Polygon3::BACK_SIDE) 
     1970                                        { 
     1971                                                isAdjacent = false; 
     1972                                        } 
     1973                                } 
     1974#else // TODO: why is this wrong?? 
     1975                                // test all planes of current node if still adjacent 
     1976                                for (int i = 0; (i < (int)nodeGeom.mPolys.size()) && isAdjacent; ++ i) 
     1977                                { 
     1978                                        Debug << "here33" << endl; 
     1979                                        Polygon3 *poly = nodeGeom.mPolys[i]; 
     1980 
     1981                                        const int cf = 
     1982                                                Polygon3::ClassifyPlane(geom->mPolys, 
     1983                                                                                                poly->GetSupportingPlane(), 
     1984                                                                                                mEpsilon); 
     1985 
     1986                                        if (cf == Polygon3::BACK_SIDE) 
     1987                                        { 
     1988                                                isAdjacent = false; 
     1989                                        } 
     1990                                } 
    19771991#endif 
    1978                 if (isAdjacent) 
    1979                 { 
    1980                  
    1981                         if (node->IsLeaf()) 
    1982                         {        
    1983                                 // test if this leaf is in valid view space 
    1984                                 if (node->TreeValid() && 
    1985                                         node != n &&  
    1986                                         (!onlyUnmailed || !node->Mailed())) 
    1987                                 { 
    1988                                         // neighbor was found 
     1992                                Debug << "here2" << endl; 
     1993                                // neighbor was found 
     1994                                if (isAdjacent) 
    19891995                                        neighbors.push_back(dynamic_cast<BspLeaf *>(node)); 
    1990                                 } 
    19911996                        } 
    19921997                        else 
     
    25052510 
    25062511 
    2507 bool VspBspTree::MergeViewCells(BspLeaf *l1, BspLeaf *l2) const 
     2512bool VspBspTree::MergeViewCells(BspLeaf *l1, BspLeaf *l2) //const 
    25082513{ 
    25092514        //-- change pointer to view cells of all leaves associated 
     
    25452550 
    25462551        // clean up old view cells 
    2547         DEL_PTR(fVc); 
    2548         DEL_PTR(bVc); 
     2552        if (0) 
     2553        { 
     2554                DEL_PTR(fVc); 
     2555                DEL_PTR(bVc); 
     2556        } 
     2557        else // throw them into old view cells container 
     2558        { 
     2559                fVc->mMailbox = -1; 
     2560                bVc->mMailbox = -1; 
     2561 
     2562                mOldViewCells.push_back(fVc); 
     2563                mOldViewCells.push_back(bVc); 
     2564 
     2565                mNewViewCells.push_back(vc); 
     2566        } 
    25492567 
    25502568        return true; 
     
    27642782        BspMergeCandidate::sUseArea = mUseAreaForPvs; 
    27652783 
     2784        // the current view cells are kept in this container 
     2785        ViewCellContainer viewCells; 
     2786        ViewCell::NewMail(); 
     2787        CollectViewCells(mRoot, true, viewCells, true); 
     2788        ViewCell::NewMail(); 
     2789 
    27662790        MergeStatistics mergeStats; 
    27672791        mergeStats.Start(); 
    27682792        // TODO: REMOVE LATER for performance! 
    2769         const bool showMergeStats = false; 
     2793        const bool showMergeStats = true; 
    27702794        //BspMergeCandidate::sOverallCost = mBox.SurfaceArea() * mStat.maxPvs; 
    27712795        long startTime = GetTime(); 
     
    28462870 
    28472871                                        cout << "exporting view cells ... "; 
    2848                                         ViewCellContainer viewCells;     
    2849                                         CollectViewCells(mRoot, false, viewCells); 
    2850                          
    2851                                          
     2872                                                                 
     2873                                 
     2874                                        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     2875 
     2876                                        Debug << "here2111 " << viewCells.size() << endl; 
     2877                                        for (int i = 0; i < viewCells.size(); ++ i) 
     2878                                        { 
     2879                                                while (!viewCells.empty() && (viewCells.back()->mMailbox == -1)) 
     2880                                                { 
     2881                                                        Debug << "here244" << endl; 
     2882                                                        viewCells.pop_back(); 
     2883                                                } 
     2884 
     2885                                                // already merged view cell, put it to end of vector 
     2886                                                if ((i < viewCells.size()) && (viewCells[i]->mMailbox == -1)) 
     2887                                                { 
     2888                                                        Debug << "here2" << endl; 
     2889                                                        swap(viewCells[i], viewCells.back()); 
     2890                                                } 
     2891                                        } 
     2892                                 
     2893                                        cout << "finished" << endl; 
     2894                                        // not part of any leaf 
     2895                                        CLEAR_CONTAINER(mOldViewCells); 
     2896 
     2897                                        int newVcSize = (int)mNewViewCells.size(); 
     2898                                        // add new view cells to container 
     2899                                        while (!mNewViewCells.empty()) 
     2900                                        { 
     2901                                                viewCells.push_back(mNewViewCells.back()); 
     2902                                                mNewViewCells.pop_back(); 
     2903                                        } 
     2904 
    28522905                                        char s[64]; 
    28532906                                        sprintf(s, "merged_viewcells%07d.x3d", nViewCells); 
     
    28602913                                                ViewCellContainer::const_iterator it, it_end = viewCells.end(); 
    28612914                 
     2915                                                int i = (int)viewCells.size(); 
    28622916                                                for (it = viewCells.begin(); it != it_end; ++ it) 
    28632917                                                { 
     2918                                                        Material m = RandomMaterial(); 
     2919                                                        if (i-- == newVcSize) 
     2920                                                        { 
     2921                                                                m.mDiffuseColor.r = 1; 
     2922                                                                m.mDiffuseColor.g = 0; 
     2923                                                                m.mDiffuseColor.b = 0; 
     2924                                                        } 
     2925                                                        exporter->SetForcedMaterial(m); 
    28642926                                                        mViewCellsManager->ExportVcGeometry(exporter, *it); 
    28652927                                                } 
     
    28822944                } 
    28832945        } 
     2946 
     2947 
    28842948        cout << "finished merge" << endl; 
    28852949        mergeStats.mergeTime = TimeDiff(startTime, GetTime()); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h

    r556 r557  
    275275        /** Merge view cells of leaves l1 and l2. 
    276276        */ 
    277         bool MergeViewCells(BspLeaf *l1, BspLeaf *l2) const; 
     277        bool MergeViewCells(BspLeaf *l1, BspLeaf *l2); //const; 
    278278 
    279279        /** Returns true if this view point is in a valid view space, 
     
    721721private: 
    722722         
     723        ViewCellContainer mOldViewCells; 
     724        ViewCellContainer mNewViewCells; 
     725 
    723726        static const float sLeastRaySplitsTable[5]; 
    724727        /** Evaluates split plane classification with respect to the plane's  
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp

    r556 r557  
    678678   
    679679  // cast view cell samples 
    680   while (1) { 
     680  while (samples < mVssSamples)  
     681  { 
     682         
    681683        int num = mVssSamplesPerPass; 
    682684        SimpleRayContainer rays; 
     
    720722 
    721723                // test if we really have enough rays 
    722                 //if (constructionRays.size() >= nSamples) 
     724                //if (constructionRays.size() >= nSamples)  
    723725                mViewCellsManager->Construct(mObjects, constructionRays); 
    724726        } 
     
    743745        cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 
    744746        cout<<"*****************************\n"; 
    745         if (samples >= mVssSamples) 
    746           break; 
    747         pass++; 
     747//      if (samples >= mVssSamples) break; 
     748        pass ++; 
    748749  } 
    749750 
Note: See TracChangeset for help on using the changeset viewer.