Ignore:
Timestamp:
01/05/07 16:29:54 (17 years ago)
Author:
bittner
Message:

tmp commit

File:
1 edited

Legend:

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

    r1935 r1942  
    3131#define USE_RAY_LENGTH_AS_CONTRIBUTION 0 
    3232#define DIST_WEIGHTED_CONTRIBUTION 0 
    33 #define SUM_RAY_CONTRIBUTIONS 0 
    34 #define AVG_RAY_CONTRIBUTIONS 1 
    35 #define CONTRIBUTION_RELATIVE_TO_PVS_SIZE 1 
     33#define SUM_RAY_CONTRIBUTIONS 1 
     34#define AVG_RAY_CONTRIBUTIONS 0 
     35#define CONTRIBUTION_RELATIVE_TO_PVS_SIZE 0 
    3636#define PVS_ADD_DIRTY 1 
    3737 
     
    19961996  stat.avgFilterRadius = 0; 
    19971997  stat.avgFilterRatio = 0; 
     1998  stat.avgRelPvsIncrease = 0.0f; 
     1999  stat.devRelPvsIncrease = 0.0f; 
    19982000   
    1999   for (; it != mViewCells.end(); ++ it)  
     2001  if (mPerViewCellStat.size() != mViewCells.size()) { 
     2002        // reset the pvs size array after the first call to this routine 
     2003        mPerViewCellStat.resize(mViewCells.size()); 
     2004        for (int i=0; i < mPerViewCellStat.size(); i++) { 
     2005          mPerViewCellStat[i].pvsSize = 0.0f; 
     2006          mPerViewCellStat[i].relPvsIncrease = 0.0f; 
     2007        } 
     2008  } 
     2009  int i; 
     2010  bool evaluateFilter; 
     2011  Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluateFilter", evaluateFilter); 
     2012 
     2013  for (i=0; it != mViewCells.end(); ++ it, i++)  
    20002014        { 
    20012015          ViewCell *viewcell = *it; 
     
    20102024                stat.avgPvs += pvsCost; 
    20112025 
    2012                 bool evaluateFilter; 
    2013                 Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluateFilter", evaluateFilter); 
     2026 
     2027                if (mPerViewCellStat[i].pvsSize > 0.0f) 
     2028                  mPerViewCellStat[i].relPvsIncrease = (pvsCost - mPerViewCellStat[i].pvsSize)/mPerViewCellStat[i].pvsSize; 
     2029                 
     2030                stat.avgRelPvsIncrease += mPerViewCellStat[i].relPvsIncrease; 
     2031                 
     2032                // update the pvs size 
     2033                mPerViewCellStat[i].pvsSize = pvsCost; 
     2034                 
    20142035                 
    20152036                 
     
    20402061          } 
    20412062        } 
     2063 
     2064   
    20422065   
    20432066  if (stat.viewcells) { 
     
    20462069        stat.avgFilterContribution/=stat.viewcells; 
    20472070        stat.avgFilterRadius/=stat.viewcells; 
    2048         stat.avgFilterRatio/=stat.viewcells; 
     2071        stat.avgFilterRatio/=stat.viewcells;  
     2072        stat.avgRelPvsIncrease/=stat.viewcells; 
     2073 
     2074        // evaluate std deviation of relPvsIncrease 
     2075        float sum=0.0f; 
     2076        for (i=0; i < stat.viewcells; i++) { 
     2077          sum += sqr(mPerViewCellStat[i].relPvsIncrease - stat.avgRelPvsIncrease); 
     2078        } 
     2079        stat.devRelPvsIncrease = sqrt(sum/stat.viewcells); 
    20492080  } 
     2081   
    20502082} 
    20512083 
     
    20632095  s<<"#MAX_PVS\n"<<pvsStat.maxPvs<<endl; 
    20642096  s<<"#MIN_PVS\n"<<pvsStat.minPvs<<endl; 
     2097  s<<"#AVG_REL_PVS_INCREASE\n"<<pvsStat.avgRelPvsIncrease<<endl; 
     2098  s<<"#DEV_REL_PVS_INCREASE\n"<<pvsStat.devRelPvsIncrease<<endl; 
    20652099} 
    20662100 
     
    21782212                                                                                                   const bool addRays) 
    21792213{ 
    2180         // check if we are outside of view space 
     2214  // check if we are outside of view space 
    21812215        if (!obj || !viewCell->GetValid()) 
    21822216                return; 
    2183  
     2217         
    21842218        // if ray not outside of view space 
    21852219        float relContribution = 0.0f; 
    21862220        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  
     2221         
     2222        if (obj)  
     2223          { 
     2224                // todo: maybe not correct for kd node pvs 
     2225                if (addRays) { 
     2226                  float pdf = viewCell->GetPvs().AddSampleDirtyCheck(obj, ray.mPdf); 
     2227                  if (pdf == ray.mPdf) { 
     2228                        absContribution = 1.0f; 
     2229                        if (viewCell->GetPvs().RequiresResort())  
     2230                          viewCell->GetPvs().SimpleSort(); 
     2231                  } 
     2232                          } else { 
     2233                                if (viewCell->GetPvs().GetSampleContribution( 
     2234                                                                                                                         obj, 
     2235                                                                                                                         ray.mPdf, 
     2236                                                                                                                         relContribution)) 
     2237                                  absContribution = 1.0f; 
     2238                          } 
     2239                // $$ clear the relative contribution as it is currently not correct anyway 
     2240                relContribution = 0.0f; 
     2241                 
     2242                if (absContribution == 1.0f) { 
     2243                  ++ ray.mPvsContribution; 
     2244                  relContribution = 1.0f; 
     2245                   
     2246                   
     2247#if CONTRIBUTION_RELATIVE_TO_PVS_SIZE 
     2248                  relContribution /= viewcell->GetPvs().GetSize(); 
     2249#endif 
     2250                   
    22092251#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                                    
     2252                  // recalculate the contribution - weight the 1.0f contribution by the sqr distance to the 
     2253                  // object-> a new contribution in the proximity of the viewcell has a larger weight! 
     2254                  relContribution /= SqrDistance(GetViewCellBox(viewcell).Center(), 
     2255                                                                                 ray.mTermination); 
     2256                   
    22142257#endif 
    2215         } 
    2216  
     2258                } 
     2259                 
    22172260#if SUM_RAY_CONTRIBUTIONS || AVG_RAY_CONTRIBUTIONS 
    2218         ray.mRelativePvsContribution += relContribution; 
     2261                ray.mRelativePvsContribution += relContribution; 
    22192262#else 
    2220         // recalculate relative contribution - use max of AbsContribution 
    2221         if (ray.mRelativePvsContribution < absContribution) 
    2222                 ray.mRelativePvsContribution = absContribution; 
     2263                // recalculate relative contribution - use max of Rel Contribution 
     2264                if (ray.mRelativePvsContribution < relContribution) 
     2265                  ray.mRelativePvsContribution = relContribution; 
    22232266#endif 
     2267          } 
     2268         
    22242269} 
    22252270 
     
    22432288        float tmin = 0, tmax = 1.0; 
    22442289 
    2245         if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 
    2246                 return 0; 
     2290        if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) { 
     2291          //      cerr<<"ray outside view space box\n"; 
     2292          return 0; 
     2293        } 
    22472294 
    22482295        Vector3 origin = hray.Extrap(tmin); 
     
    22542301        CastLineSegment(origin, termination, viewCells); 
    22552302 
     2303         
    22562304        if (storeViewCells) 
    22572305        {        
    2258                 // copy viewcells memory efficiently 
    2259                 ray.mViewCells.reserve(viewCells.size()); 
    2260                 ray.mViewCells = viewCells; 
     2306          // copy viewcells memory efficiently 
     2307          ray.mViewCells.reserve(viewCells.size()); 
     2308          ray.mViewCells = viewCells; 
    22612309        } 
    22622310 
     
    22802328#if USE_RAY_LENGTH_AS_CONTRIBUTION 
    22812329        float c = 0.0f; 
    2282         if (obj)  
    2283                 c = ray.Length(); 
     2330        if (terminationObj)  
     2331          c = ray.Length(); 
    22842332        ray.mRelativePvsContribution = ray.mPvsContribution = c; 
    22852333        return c; 
    22862334#else 
    2287         return ABS_CONTRIBUTION_WEIGHT * ray.mPvsContribution + 
    2288                 (1.0f - ABS_CONTRIBUTION_WEIGHT) * ray.mRelativePvsContribution; 
     2335        return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution + 
     2336          (1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution; 
    22892337#endif 
    22902338} 
     
    28972945                sqrt((float)objectSamples); 
    28982946           
    2899           //    cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 
     2947          //      cout<<"os="<<objectSamples<<" lr="<<localRadius<<" gr="<<globalRadius<<endl; 
    29002948           
    29012949          // now compute the filter size 
Note: See TracChangeset for help on using the changeset viewer.