Changeset 1903


Ignore:
Timestamp:
12/16/06 19:05:53 (17 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
6 edited

Legend:

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

    r1899 r1903  
    18261826 
    18271827                if (onlyMailedRays && !ray->Mailed()) 
    1828                 {//if (onlyMailedRays)cout << "u"; 
     1828                { 
    18291829                        continue; 
    1830                 }//else if (onlyMailedRays) cout << "z"; 
    1831  
    1832                 //ray->Mail(); 
     1830                } 
     1831 
    18331832                ++ numRays; 
    18341833 
     
    18461845                        if (!useMailBoxing || !vc->Mailed()) 
    18471846                        { 
    1848                                 if (useMailBoxing) 
     1847                                if (useMailBoxing) // => view cell not mailed 
    18491848                                { 
    18501849                                        vc->Mail(); 
     
    18541853                                        } 
    18551854                                } 
     1855 
    18561856                                viewCells.push_back(vc); 
    18571857                        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1877 r1903  
    800800                                                 ViewCellContainer &viewCells, 
    801801                                                 const bool setCounter, 
    802                                                  const bool onlyUnmailedRays) const; 
     802                                                 const bool onlyMailedRays) const; 
    803803 
    804804        /** Counts the view cells of this object. note: only 
     
    817817                                                 const bool useMailBoxing, 
    818818                                                 const bool setCounter, 
    819                                                  const bool onlyUnmailedRays) const; 
     819                                                 const bool onlyMailedRays) const; 
    820820 
    821821        /** Evaluates increase in pvs size. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1902 r1903  
    7979 
    8080 
     81int ViewCellsManager::CastPassSamples2(const int samplesPerPass, VssRayContainer &passSamples) const 
     82{ 
     83        long startTime = GetTime(); 
     84 
     85        SimpleRayContainer simpleRays; 
     86         
     87        simpleRays.reserve(samplesPerPass); 
     88        passSamples.reserve(samplesPerPass * 2); // always creates double rays 
     89 
     90        // create one third of each type 
     91        int castRays = 0; 
     92 
     93        mMixtureDistribution->GenerateSamples(mSamplesPerPass, simpleRays); 
     94 
     95        cout << "generated " << simpleRays.size() << " samples in "  
     96                 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     97 
     98        startTime = GetTime(); 
     99 
     100        // shoot simple ray and add it to importance samples 
     101        mPreprocessor->CastRays(simpleRays, passSamples, true); 
     102 
     103    cout << "cast " <<  samplesPerPass << " samples in "  
     104                 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     105 
     106        mMixtureDistribution->ComputeContributions(passSamples); 
     107 
     108        return (int)passSamples.size(); 
     109} 
     110 
     111 
    81112void ViewCellsManager::ParseEnvironment() 
    82113{ 
     
    123154                mStrategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION); 
    124155        } 
    125         else 
    126         { 
    127                 mStrategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION); 
    128                 //mStrategies.push_back(SamplingStrategy::VIEWSPACE_BORDER_BASED_DISTRIBUTION); 
    129                 mStrategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION); 
    130                 //mStrategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION); 
    131                 //mStrategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION); 
    132         } 
    133  
     156         
    134157         
    135158    Debug << "casting strategies: "; 
     
    137160                Debug << mStrategies[i] << " "; 
    138161        Debug << endl; 
     162 
     163        // now decode distribution string 
     164        char buff[1024]; 
     165        Environment::GetSingleton()->GetStringValue("RssPreprocessor.distributions", buff); 
     166 
     167        mMixtureDistribution = new MixtureDistribution(*mPreprocessor); 
     168        mMixtureDistribution->Construct(buff); 
     169 
    139170 
    140171        // sampling type for view cells construction samples 
     
    278309                DEL_PTR(mViewCellsTree); 
    279310        } 
    280 } 
     311 
     312        DEL_PTR(mMixtureDistribution); 
     313} 
     314 
    281315 
    282316Intersectable * 
     
    20282062                                                                                        const bool storeViewCells) 
    20292063{ 
    2030   ray.mPvsContribution = 0; 
    2031   ray.mRelativePvsContribution = 0.0f; 
    2032    
    2033   if (ray.mTerminationObject==NULL) 
    2034         return 0.0f; 
    2035    
    2036   ViewCellContainer viewcells; 
    2037    
    2038   static Ray hray; 
    2039   hray.Init(ray); 
    2040  
    2041   float tmin = 0, tmax = 1.0; 
    2042    
    2043   if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 
    2044         return 0; 
    2045    
    2046   Vector3 origin = hray.Extrap(tmin); 
    2047   Vector3 termination = hray.Extrap(tmax); 
    2048    
    2049   ViewCell::NewMail(); 
    2050    
    2051   // traverse the view space subdivision 
    2052   CastLineSegment(origin, termination, viewcells); 
    2053    
    2054   if (storeViewCells) 
     2064        ray.mPvsContribution = 0; 
     2065        ray.mRelativePvsContribution = 0.0f; 
     2066 
     2067        if (ray.mTerminationObject==NULL) 
     2068                return 0.0f; 
     2069 
     2070        ViewCellContainer viewcells; 
     2071 
     2072        static Ray hray; 
     2073        hray.Init(ray); 
     2074 
     2075        float tmin = 0, tmax = 1.0; 
     2076 
     2077        if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 
     2078                return 0; 
     2079 
     2080        Vector3 origin = hray.Extrap(tmin); 
     2081        Vector3 termination = hray.Extrap(tmax); 
     2082 
     2083        ViewCell::NewMail(); 
     2084 
     2085        // traverse the view space subdivision 
     2086        CastLineSegment(origin, termination, viewcells); 
     2087 
     2088        if (storeViewCells) 
    20552089        {        
    2056           // copy viewcells memory efficiently 
    2057           ray.mViewCells.reserve(viewcells.size()); 
    2058           ray.mViewCells = viewcells; 
    2059         } 
    2060    
    2061   ViewCellContainer::const_iterator it = viewcells.begin(); 
    2062    
    2063   Intersectable *terminationObj = GetIntersectable(ray, true); 
    2064    
    2065    
    2066   for (; it != viewcells.end(); ++ it)  
    2067         { 
    2068           ViewCell *viewcell = *it; 
    2069            
    2070           if (viewcell->GetValid()) 
    2071                 {       // if ray not outside of view space 
    2072                   float contribution; 
    2073                    
    2074                   if (terminationObj)  
     2090                // copy viewcells memory efficiently 
     2091                ray.mViewCells.reserve(viewcells.size()); 
     2092                ray.mViewCells = viewcells; 
     2093        } 
     2094 
     2095        ViewCellContainer::const_iterator it = viewcells.begin(); 
     2096 
     2097        Intersectable *terminationObj = GetIntersectable(ray, true); 
     2098 
     2099 
     2100        for (; it != viewcells.end(); ++ it)  
     2101        { 
     2102                ViewCell *viewcell = *it; 
     2103 
     2104                if (viewcell->GetValid()) 
     2105                {        
     2106                        // if ray not outside of view space 
     2107                        float contribution; 
     2108 
     2109                        if (terminationObj)  
    20752110                        { 
    2076                           // todo: maybe not correct for kd node pvs 
    2077                           bool absContribution = viewcell->GetPvs().GetSampleContribution( 
    2078                                                                                                                                                           terminationObj, 
    2079                                                                                                                                                           ray.mPdf, 
    2080                                                                                                                                                           contribution); 
     2111                                // todo: maybe not correct for kd node pvs 
     2112                                bool absContribution =  
     2113                                        viewcell->GetPvs().GetSampleContribution( 
     2114                                                                                                                        terminationObj, 
     2115                                                                                                                        ray.mPdf, 
     2116                                                                                                                        contribution); 
    20812117#if DIST_WEIGHTED_CONTRIBUTION 
    2082                           // clear the relative contribution 
    2083                           contribution = 0.0f; 
     2118                                // clear the relative contribution 
     2119                                contribution = 0.0f; 
    20842120#endif 
    2085                           if (absContribution) 
     2121                                if (absContribution) 
    20862122                                { 
    2087                                   ++ ray.mPvsContribution; 
    2088                                   if (addRays) { 
     2123                                        ++ ray.mPvsContribution; 
     2124                                        if (addRays) { 
    20892125#if PVS_ADD_DIRTY 
    2090                                         viewcell->GetPvs().AddSampleDirtyCheck(terminationObj, ray.mPdf); 
    2091                                         if (viewcell->GetPvs().RequiresResort()) { 
    2092                                           viewcell->GetPvs().SimpleSort(); 
     2126                                                viewcell->GetPvs().AddSampleDirtyCheck(terminationObj, ray.mPdf); 
     2127                                                if (viewcell->GetPvs().RequiresResort()) { 
     2128                                                        viewcell->GetPvs().SimpleSort(); 
     2129                                                } 
     2130#else 
     2131                                                viewcell->GetPvs().AddSample(terminationObj, ray.mPdf); 
     2132#endif 
    20932133                                        } 
    2094 #else 
    2095                                         viewcell->GetPvs().AddSample(terminationObj, ray.mPdf); 
    2096 #endif 
    2097                                   } 
    20982134#if DIST_WEIGHTED_CONTRIBUTION  
    2099                                   // recalculate the contribution - weight the 1.0f contribution by the sqr distance to the 
    2100                                   // object-> a new contribution in the proximity of the viewcell has a larger weight! 
    2101                                   contribution = 1.0f/SqrDistance(GetViewCellBox(viewcell).Center(), 
    2102                                                                                                   ray.mTermination); 
     2135                                        // recalculate the contribution - weight the 1.0f contribution by the sqr distance to the 
     2136                                        // object-> a new contribution in the proximity of the viewcell has a larger weight! 
     2137                                        contribution = 1.0f/SqrDistance(GetViewCellBox(viewcell).Center(), 
     2138                                                ray.mTermination); 
    21032139#endif 
    21042140                                } 
    2105                            
    2106                           ray.mRelativePvsContribution += contribution; 
     2141 
     2142                                ray.mRelativePvsContribution += contribution; 
    21072143                        } 
    21082144                } 
     
    60166052                evalStrats.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION); 
    60176053        } 
    6018         else 
    6019         { 
    6020                 //evalStrats.push_back(SamplingStrategy::VIEWSPACE_BORDER_BASED_DISTRIBUTION); 
    6021                 evalStrats.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION); 
    6022                 evalStrats.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION); 
    6023                 //evalStrats.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION); 
    6024                 //evalStrats.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION); 
    6025         } 
    6026          
     6054                 
    60276055    Debug << "casting eval strategies: "; 
    60286056        for (int i = 0; i < (int)evalStrats.size(); ++ i) 
     
    60486076                Debug << "casting " << samplesPerPass << " samples ... "; 
    60496077         
    6050                 CastPassSamples(samplesPerPass, evalStrats, evaluationSamples); 
    6051                 //CastPassSamples(samplesPerPass, mStrategies, evaluationSamples); 
    6052                  
     6078                if (1) 
     6079                { 
     6080                        CastPassSamples(samplesPerPass, evalStrats, evaluationSamples); 
     6081                } 
     6082                else 
     6083                { 
     6084                        // use mixed distributions 
     6085                        CastPassSamples2(samplesPerPass, evaluationSamples); 
     6086                } 
     6087 
    60536088                castSamples += samplesPerPass; 
    60546089 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1902 r1903  
    3939class ViewCellsTree; 
    4040class ViewCell; 
    41  
     41class MixtureDistribution; 
    4242struct AxisAlignedPlane; 
    4343struct BspRay; 
     44 
    4445 
    4546  struct PvsFilterStatistics { 
     
    596597                                                VssRayContainer &vssRays) const; 
    597598 
     599        int CastPassSamples2(const int samplesPerPass,  
     600                                                 VssRayContainer &passSamples) const; 
     601 
    598602        /** Parse the options from the environment file. 
    599603        */ 
     
    756760 
    757761        bool mUseKdPvs; 
     762 
     763        MixtureDistribution *mMixtureDistribution; 
    758764 
    759765        ////////////////// 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1899 r1903  
    14511451        // get subset of rays 
    14521452        RayInfoContainer randomRays; 
    1453         randomRays.reserve(mMaxTests); 
     1453        randomRays.reserve(min(mMaxTests, (int)tData.mRays->size())); 
    14541454 
    14551455        RayInfoContainer *usedRays; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r1892 r1903  
    265265        //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor); 
    266266        PreprocessorThread *pt; 
    267 cout << "here8"<<endl; 
    268267 
    269268#if USE_QT 
Note: See TracChangeset for help on using the changeset viewer.