Changeset 1932 for GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
- Timestamp:
- 01/03/07 01:36:35 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1931 r1932 34 34 #define AVG_RAY_CONTRIBUTIONS 1 35 35 #define CONTRIBUTION_RELATIVE_TO_PVS_SIZE 1 36 #define PVS_ADD_DIRTY 1 36 37 37 38 namespace GtpVisibilityPreprocessor { … … 82 83 83 84 84 int ViewCellsManager::CastPassSamples2(const int samplesPerPass, VssRayContainer &passSamples) const 85 int ViewCellsManager::CastPassSamples2(const int samplesPerPass, 86 VssRayContainer &passSamples) const 85 87 { 86 88 long startTime = GetTime(); … … 2153 2155 2154 2156 2155 2156 #define PVS_ADD_DIRTY 1 2157 inline 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 2174 void 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 2157 2226 2158 2227 float … … 2164 2233 ray.mRelativePvsContribution = 0.0f; 2165 2234 2166 if ( ray.mTerminationObject==NULL)2235 if (!ray.mTerminationObject) 2167 2236 return 0.0f; 2168 2237 2169 ViewCellContainer view cells;2238 ViewCellContainer viewCells; 2170 2239 2171 2240 static Ray hray; … … 2183 2252 2184 2253 // traverse the view space subdivision 2185 CastLineSegment(origin, termination, view cells);2254 CastLineSegment(origin, termination, viewCells); 2186 2255 2187 2256 if (storeViewCells) 2188 2257 { 2189 2258 // 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) 2196 2264 Intersectable *terminationObj = GetIntersectable(ray, true); 2197 2265 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); 2257 2275 } 2258 2276 2259 2277 #if AVG_RAY_CONTRIBUTIONS 2260 ray.mRelativePvsContribution /= viewcells.size();2278 ray.mRelativePvsContribution /= (float)viewCells.size(); 2261 2279 #endif 2262 2280 #if USE_RAY_LENGTH_AS_CONTRIBUTION 2263 2264 if (terminationObj)2265 c = ray.Length();2266 2267 2281 float c = 0.0f; 2282 if (obj) 2283 c = ray.Length(); 2284 ray.mRelativePvsContribution = ray.mPvsContribution = c; 2285 return c; 2268 2286 #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; 2271 2289 #endif 2272 2290 } 2273 2274 2291 2275 2292 … … 3544 3561 if (p < raysOut) 3545 3562 { 3546 if ( (*rit)->mFlags & VssRay::BorderSample)3563 if (0 && (*rit)->mFlags & VssRay::BorderSample) 3547 3564 { 3548 cout << "b";3549 3565 vcRays.push_back(*rit); 3550 3566 } 3551 3567 else if ((*rit)->mFlags & VssRay::ReverseSample) 3552 3568 { 3569 cout << "l"; 3553 3570 vcRays2.push_back(*rit); 3554 cout << "r";3555 3571 } 3556 else 3572 else if(0) 3557 3573 { 3558 cout << "n";3559 3574 vcRays3.push_back(*rit); 3560 3575 } … … 5448 5463 5449 5464 if (0) 5450 { // real meshes are constructed at this stage 5465 { 5466 // real meshes are constructed at this stage 5451 5467 cout << "finalizing view cells ... "; 5452 5468 FinalizeViewCells(true); 5453 5469 cout << "finished" << endl; 5454 5470 }
Note: See TracChangeset
for help on using the changeset viewer.