Ignore:
Timestamp:
01/03/07 01:36:35 (17 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r1931 r1932  
    3434#define AVG_RAY_CONTRIBUTIONS 1 
    3535#define CONTRIBUTION_RELATIVE_TO_PVS_SIZE 1 
     36#define PVS_ADD_DIRTY 1 
    3637 
    3738namespace GtpVisibilityPreprocessor { 
     
    8283 
    8384 
    84 int ViewCellsManager::CastPassSamples2(const int samplesPerPass, VssRayContainer &passSamples) const 
     85int ViewCellsManager::CastPassSamples2(const int samplesPerPass,  
     86                                                                           VssRayContainer &passSamples) const 
    8587{ 
    8688        long startTime = GetTime(); 
     
    21532155 
    21542156 
    2155  
    2156 #define PVS_ADD_DIRTY 1 
     2157inline static void AddSampleToPvs(ObjectPvs &pvs,  
     2158                                                                  Intersectable *obj,  
     2159                                                                  const float pdf) 
     2160{ 
     2161#if PVS_ADD_DIRTY 
     2162        pvs.AddSampleDirtyCheck(obj, pdf); 
     2163 
     2164        if (pvs.RequiresResort())  
     2165        { 
     2166                pvs.SimpleSort(); 
     2167        } 
     2168#else 
     2169        pvs.AddSample(obj, pdf); 
     2170#endif 
     2171} 
     2172 
     2173 
     2174void ViewCellsManager::ComputeViewCellContribution(ViewCell *viewCell, 
     2175                                                                                                   VssRay &ray,  
     2176                                                                                                   Intersectable *obj, 
     2177                                                                                                   const Vector3 &pt, 
     2178                                                                                                   const bool addRays) 
     2179{ 
     2180        // check if we are outside of view space 
     2181        if (!obj || !viewCell->GetValid()) 
     2182                return; 
     2183 
     2184        // if ray not outside of view space 
     2185        float relContribution = 0.0f; 
     2186        float absContribution = 0.0f; 
     2187 
     2188        // todo: maybe not correct for kd node pvs 
     2189        if (viewCell->GetPvs().GetSampleContribution(obj, 
     2190                                                                                                 ray.mPdf, 
     2191                                                                                                 relContribution)) 
     2192        { 
     2193                absContribution = 1.0f; 
     2194        } 
     2195         
     2196        // $$ clear the relative contribution as it is currently not correct anyway 
     2197        relContribution = 0.0f; 
     2198 
     2199        if (absContribution == 1.0f) 
     2200        { 
     2201                ++ ray.mPvsContribution; 
     2202                relContribution = 1.0f; 
     2203 
     2204                if (addRays)  
     2205                { 
     2206                        AddSampleToPvs(viewCell->GetPvs(), obj, ray.mPdf); 
     2207                } 
     2208 
     2209#if DIST_WEIGHTED_CONTRIBUTION  
     2210                // recalculate the contribution - weight the 1.0f contribution by the sqr distance to the 
     2211                // object-> a new contribution in the proximity of the viewcell has a larger weight! 
     2212                relContribution /= SqrDistance(GetViewCellBox(viewcell).Center(), pt); 
     2213                                   
     2214#endif 
     2215        } 
     2216 
     2217#if SUM_RAY_CONTRIBUTIONS || AVG_RAY_CONTRIBUTIONS 
     2218        ray.mRelativePvsContribution += relContribution; 
     2219#else 
     2220        // recalculate relative contribution - use max of AbsContribution 
     2221        if (ray.mRelativePvsContribution < absContribution) 
     2222                ray.mRelativePvsContribution = absContribution; 
     2223#endif 
     2224} 
     2225 
    21572226 
    21582227float 
     
    21642233        ray.mRelativePvsContribution = 0.0f; 
    21652234 
    2166         if (ray.mTerminationObject==NULL) 
     2235        if (!ray.mTerminationObject) 
    21672236                return 0.0f; 
    21682237 
    2169         ViewCellContainer viewcells; 
     2238        ViewCellContainer viewCells; 
    21702239 
    21712240        static Ray hray; 
     
    21832252 
    21842253        // traverse the view space subdivision 
    2185         CastLineSegment(origin, termination, viewcells); 
     2254        CastLineSegment(origin, termination, viewCells); 
    21862255 
    21872256        if (storeViewCells) 
    21882257        {        
    21892258                // copy viewcells memory efficiently 
    2190                 ray.mViewCells.reserve(viewcells.size()); 
    2191                 ray.mViewCells = viewcells; 
    2192         } 
    2193  
    2194         ViewCellContainer::const_iterator it = viewcells.begin(); 
    2195  
     2259                ray.mViewCells.reserve(viewCells.size()); 
     2260                ray.mViewCells = viewCells; 
     2261        } 
     2262 
     2263        // optain pvs entry (can be different from hit object) 
    21962264        Intersectable *terminationObj = GetIntersectable(ray, true); 
    21972265 
    2198          
    2199         for (; it != viewcells.end(); ++ it)  
    2200         { 
    2201                 ViewCell *viewcell = *it; 
    2202  
    2203                 if (viewcell->GetValid()) 
    2204                 {        
    2205                         // if ray not outside of view space 
    2206                         float relContribution = 0.0f; 
    2207                         float absContribution = 0.0f; 
    2208                          
    2209                         if (terminationObj)  
    2210                         { 
    2211                                 // todo: maybe not correct for kd node pvs 
    2212                           if (viewcell->GetPvs().GetSampleContribution( 
    2213                                                                                                                    terminationObj, 
    2214                                                                                                                    ray.mPdf, 
    2215                                                                                                                    relContribution)) 
    2216                                 absContribution = 1.0f; 
    2217                            
    2218                           // $$ clear the relative contribution as it is currently not correct anyway 
    2219                           relContribution = 0.0f; 
    2220  
    2221                           if (absContribution == 1.0f) 
    2222                                 { 
    2223                                   ++ ray.mPvsContribution; 
    2224                                   relContribution = 1.0f; 
    2225                                   if (addRays) { 
    2226 #if PVS_ADD_DIRTY 
    2227                                         viewcell->GetPvs().AddSampleDirtyCheck(terminationObj, ray.mPdf); 
    2228                                         if (viewcell->GetPvs().RequiresResort()) { 
    2229                                           viewcell->GetPvs().SimpleSort(); 
    2230                                         } 
    2231 #else 
    2232                                         viewcell->GetPvs().AddSample(terminationObj, ray.mPdf); 
    2233 #endif 
    2234                                   } 
    2235  
    2236 #if CONTRIBUTION_RELATIVE_TO_PVS_SIZE 
    2237                                   relContribution /= viewcell->GetPvs().GetSize(); 
    2238 #endif 
    2239                                    
    2240 #if DIST_WEIGHTED_CONTRIBUTION  
    2241                                   // recalculate the contribution - weight the 1.0f contribution by the sqr distance to the 
    2242                                   // object-> a new contribution in the proximity of the viewcell has a larger weight! 
    2243                                   relContribution /= SqrDistance(GetViewCellBox(viewcell).Center(), 
    2244                                                                                                  ray.mTermination); 
    2245                                    
    2246 #endif 
    2247                                 } 
    2248 #if SUM_RAY_CONTRIBUTIONS || AVG_RAY_CONTRIBUTIONS 
    2249                           ray.mRelativePvsContribution += relContribution; 
    2250 #else 
    2251                           // recalculate relative contribution - use max of AbsContribution 
    2252                           if (ray.mRelativePvsContribution < absContribution) 
    2253                                 ray.mRelativePvsContribution = absContribution; 
    2254 #endif 
    2255                         } 
    2256                 } 
     2266        ViewCellContainer::const_iterator it = viewCells.begin(); 
     2267 
     2268        for (; it != viewCells.end(); ++ it)  
     2269        { 
     2270                ComputeViewCellContribution(*it,  
     2271                                                                        ray,  
     2272                                                                        terminationObj,  
     2273                                                                        ray.mTermination,  
     2274                                                                        addRays); 
    22572275        } 
    22582276 
    22592277#if AVG_RAY_CONTRIBUTIONS 
    2260         ray.mRelativePvsContribution /= viewcells.size(); 
     2278        ray.mRelativePvsContribution /= (float)viewCells.size(); 
    22612279#endif 
    22622280#if USE_RAY_LENGTH_AS_CONTRIBUTION 
    2263   float c = 0.0f; 
    2264   if (terminationObj)  
    2265         c = ray.Length(); 
    2266   ray.mRelativePvsContribution = ray.mPvsContribution = c; 
    2267   return c; 
     2281        float c = 0.0f; 
     2282        if (obj)  
     2283                c = ray.Length(); 
     2284        ray.mRelativePvsContribution = ray.mPvsContribution = c; 
     2285        return c; 
    22682286#else 
    2269   return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution + 
    2270         (1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution; 
     2287        return ABS_CONTRIBUTION_WEIGHT * ray.mPvsContribution + 
     2288                (1.0f - ABS_CONTRIBUTION_WEIGHT) * ray.mRelativePvsContribution; 
    22712289#endif 
    22722290} 
    2273  
    22742291 
    22752292 
     
    35443561                                if (p < raysOut) 
    35453562                                { 
    3546                                         if ((*rit)->mFlags & VssRay::BorderSample) 
     3563                                        if (0 && (*rit)->mFlags & VssRay::BorderSample) 
    35473564                                        { 
    3548                                                 cout << "b"; 
    35493565                                                vcRays.push_back(*rit); 
    35503566                                        } 
    35513567                                        else if ((*rit)->mFlags & VssRay::ReverseSample) 
    35523568                                        { 
     3569                                                cout << "l"; 
    35533570                                                vcRays2.push_back(*rit); 
    3554                                                 cout << "r"; 
    35553571                                        } 
    3556                                         else 
     3572                                        else if(0) 
    35573573                                        { 
    3558                                                 cout << "n"; 
    35593574                                                vcRays3.push_back(*rit); 
    35603575                                        }        
     
    54485463 
    54495464        if (0) 
    5450         {       // real meshes are constructed at this stage 
     5465        {        
     5466                // real meshes are constructed at this stage 
    54515467                cout << "finalizing view cells ... "; 
    5452                 FinalizeViewCells(true); 
     5468        FinalizeViewCells(true); 
    54535469                cout << "finished" << endl; 
    54545470        } 
Note: See TracChangeset for help on using the changeset viewer.