Changeset 1942 for GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
- Timestamp:
- 01/05/07 16:29:54 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1935 r1942 31 31 #define USE_RAY_LENGTH_AS_CONTRIBUTION 0 32 32 #define DIST_WEIGHTED_CONTRIBUTION 0 33 #define SUM_RAY_CONTRIBUTIONS 034 #define AVG_RAY_CONTRIBUTIONS 135 #define CONTRIBUTION_RELATIVE_TO_PVS_SIZE 133 #define SUM_RAY_CONTRIBUTIONS 1 34 #define AVG_RAY_CONTRIBUTIONS 0 35 #define CONTRIBUTION_RELATIVE_TO_PVS_SIZE 0 36 36 #define PVS_ADD_DIRTY 1 37 37 … … 1996 1996 stat.avgFilterRadius = 0; 1997 1997 stat.avgFilterRatio = 0; 1998 stat.avgRelPvsIncrease = 0.0f; 1999 stat.devRelPvsIncrease = 0.0f; 1998 2000 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++) 2000 2014 { 2001 2015 ViewCell *viewcell = *it; … … 2010 2024 stat.avgPvs += pvsCost; 2011 2025 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 2014 2035 2015 2036 … … 2040 2061 } 2041 2062 } 2063 2064 2042 2065 2043 2066 if (stat.viewcells) { … … 2046 2069 stat.avgFilterContribution/=stat.viewcells; 2047 2070 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); 2049 2080 } 2081 2050 2082 } 2051 2083 … … 2063 2095 s<<"#MAX_PVS\n"<<pvsStat.maxPvs<<endl; 2064 2096 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; 2065 2099 } 2066 2100 … … 2178 2212 const bool addRays) 2179 2213 { 2180 2214 // check if we are outside of view space 2181 2215 if (!obj || !viewCell->GetValid()) 2182 2216 return; 2183 2217 2184 2218 // if ray not outside of view space 2185 2219 float relContribution = 0.0f; 2186 2220 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 2209 2251 #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 2214 2257 #endif 2215 }2216 2258 } 2259 2217 2260 #if SUM_RAY_CONTRIBUTIONS || AVG_RAY_CONTRIBUTIONS 2218 ray.mRelativePvsContribution += relContribution;2261 ray.mRelativePvsContribution += relContribution; 2219 2262 #else 2220 // recalculate relative contribution - use max of AbsContribution2221 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; 2223 2266 #endif 2267 } 2268 2224 2269 } 2225 2270 … … 2243 2288 float tmin = 0, tmax = 1.0; 2244 2289 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 } 2247 2294 2248 2295 Vector3 origin = hray.Extrap(tmin); … … 2254 2301 CastLineSegment(origin, termination, viewCells); 2255 2302 2303 2256 2304 if (storeViewCells) 2257 2305 { 2258 2259 2260 2306 // copy viewcells memory efficiently 2307 ray.mViewCells.reserve(viewCells.size()); 2308 ray.mViewCells = viewCells; 2261 2309 } 2262 2310 … … 2280 2328 #if USE_RAY_LENGTH_AS_CONTRIBUTION 2281 2329 float c = 0.0f; 2282 if ( obj)2283 2330 if (terminationObj) 2331 c = ray.Length(); 2284 2332 ray.mRelativePvsContribution = ray.mPvsContribution = c; 2285 2333 return c; 2286 2334 #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; 2289 2337 #endif 2290 2338 } … … 2897 2945 sqrt((float)objectSamples); 2898 2946 2899 // cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl;2947 // cout<<"os="<<objectSamples<<" lr="<<localRadius<<" gr="<<globalRadius<<endl; 2900 2948 2901 2949 // now compute the filter size
Note: See TracChangeset
for help on using the changeset viewer.