| 246 | #define INTEGER_SAMPLE_STATS_BOUND_SCALE (1.0f + 2.f / INTEGER_BINS) |
| 247 | |
| 248 | struct IntegerSampleStatistics |
| 249 | { |
| 250 | Point3i mean{0}; |
| 251 | Vector3i variance{0}; |
| 252 | uint32_t numSamples{0}; |
| 253 | // measured sample bound in the discretized integer domain |
| 254 | BBoxi intSampleBounds{openpgl::Vector3i(std::numeric_limits<int>::max()), openpgl::Vector3i(-std::numeric_limits<int>::max())}; |
| 255 | // actual measured sample bound (float) |
| 256 | BBox sampleBounds{openpgl::Vector3(std::numeric_limits<float>::max()), openpgl::Vector3(-std::numeric_limits<float>::max())}; |
| 257 | Vector3 sampleBoundsMin{0}; |
| 258 | Vector3 sampleBoundsMax{0}; |
| 259 | |
| 260 | // sample bound stats to center the collected samples before discretization |
| 261 | Vector3 sampleBoundsCenter{0}; |
| 262 | Vector3 sampleBoundsHalfExtend{0}; |
| 263 | Vector3 invSampleBoundsHalfExtend{0}; |
| 264 | |
| 265 | IntegerSampleStatistics() |
| 266 | { |
| 267 | mean = Point3i(0); |
| 268 | variance = Vector3i(0); |
| 269 | numSamples = 0; |
| 270 | intSampleBounds = BBoxi(openpgl::Vector3i(std::numeric_limits<int>::max()), openpgl::Vector3i(-std::numeric_limits<int>::max())); |
| 271 | sampleBounds = BBox(openpgl::Vector3(std::numeric_limits<float>::max()), openpgl::Vector3(-std::numeric_limits<float>::max())); |
| 272 | sampleBoundsMin = Vector3(0); |
| 273 | sampleBoundsMax = Vector3(0); |
| 274 | sampleBoundsCenter = Vector3(0); |
| 275 | sampleBoundsHalfExtend = Vector3(0); |
| 276 | invSampleBoundsHalfExtend = Vector3(0); |
| 277 | } |
| 278 | |
| 279 | IntegerSampleStatistics(const BBox &bounds) |
| 280 | { |
| 281 | mean = Point3i(0); |
| 282 | variance = Vector3i(0); |
| 283 | numSamples = 0; |
| 284 | intSampleBounds = BBoxi(openpgl::Vector3i(std::numeric_limits<int>::max()), openpgl::Vector3i(-std::numeric_limits<int>::max())); |
| 285 | sampleBounds = BBox(openpgl::Vector3(std::numeric_limits<float>::max()), openpgl::Vector3(-std::numeric_limits<float>::max())); |
| 286 | |
| 287 | // scaling the boundary of the samples to avoid discretization problems at the boundaries |
| 288 | BBox scaledBounds = bounds; |
| 289 | Vector3 center = scaledBounds.center(); |
| 290 | scaledBounds.lower = center + INTEGER_SAMPLE_STATS_BOUND_SCALE * (scaledBounds.lower - center); |
| 291 | scaledBounds.upper = center + INTEGER_SAMPLE_STATS_BOUND_SCALE * (scaledBounds.upper - center); |
| 292 | |
| 293 | sampleBoundsMin = scaledBounds.lower; |
| 294 | sampleBoundsMax = scaledBounds.upper; |
| 295 | sampleBoundsHalfExtend = (scaledBounds.upper - scaledBounds.lower) * 0.5f; |
| 296 | |
| 297 | // Checking and compenstaing for sampled bounds with dimensions of zero extend (e.g. plane) |
| 298 | invSampleBoundsHalfExtend.x = sampleBoundsHalfExtend.x > 0.f ? 1.0f / sampleBoundsHalfExtend.x : 0.f; |
| 299 | invSampleBoundsHalfExtend.y = sampleBoundsHalfExtend.y > 0.f ? 1.0f / sampleBoundsHalfExtend.y : 0.f; |
| 300 | invSampleBoundsHalfExtend.z = sampleBoundsHalfExtend.z > 0.f ? 1.0f / sampleBoundsHalfExtend.z : 0.f; |
| 301 | sampleBoundsCenter = sampleBoundsMin + sampleBoundsHalfExtend; |
| 302 | |
| 303 | OPENPGL_ASSERT(embree::isvalid(invSampleBoundsHalfExtend.x)); |
| 304 | OPENPGL_ASSERT(embree::isvalid(invSampleBoundsHalfExtend.y)); |
| 305 | OPENPGL_ASSERT(embree::isvalid(invSampleBoundsHalfExtend.z)); |
no test coverage detected