Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions openpgl/directional/vmm/VMMChiSquareComponentSplitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <embreeSrc/common/math/vec3.h>

#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <vector>
Expand Down Expand Up @@ -166,7 +167,7 @@ inline Vec2Type Map3DTo2D(const Vec3Type &vec3D)
OPENPGL_ASSERT(embree::isvalid(alpha));
ScalarType sinAlpha = embree::fastapprox::sin(alpha);
OPENPGL_ASSERT(embree::isvalid(sinAlpha));
ScalarType inv_sinc = sinAlpha != 0.f ? alpha / sinAlpha : 0.f;
ScalarType inv_sinc = std::fabs(sinAlpha) > FLT_EPSILON ? alpha / sinAlpha : 0.f;
OPENPGL_ASSERT(embree::isvalid(inv_sinc));

vec2D.x = embree::select(alpha > 0.0f, vec3D.x * inv_sinc, vec2D.x);
Expand All @@ -182,7 +183,7 @@ inline Vec3Type Map2DTo3D(const Vec2Type &vec2D)
{
Vec3Type vec3D = Vec3Type(0.0f);
ScalarType norm2 = vec2D.x * vec2D.x + vec2D.y * vec2D.y;
ScalarType length = norm2 > 0.f ? embree::sqrt(norm2) : 0.f;
ScalarType length = norm2 > FLT_EPSILON ? embree::sqrt(norm2) : 0.f;
OPENPGL_ASSERT(length < M_PI_F);
ScalarType sinc = length > FLT_EPSILON ? embree::fastapprox::sin(length) / length : 0.f;

Expand Down Expand Up @@ -503,7 +504,7 @@ void VonMisesFisherChiSquareComponentSplitter<TVMMFactory>::UpdateSplitStatistic
chiSquareEst += vmfPDF;
chiSquareEst /= samplePDF;

chiSquareEst = select(softAssign.assignments[k] > 0.f, chiSquareEst, zeros);
chiSquareEst = select(softAssign.assignments[k] > FLT_EPSILON, chiSquareEst, zeros);

splitStats.sumAssignedSamples[k] += softAssign.assignments[k];
// incremental updated of the MC chiSquare estimate
Expand Down Expand Up @@ -1056,7 +1057,7 @@ void VonMisesFisherChiSquareComponentSplitter<TVMMFactory>::ComponentSplitStatis
Vector2 meanDirection2DItoK = Map3DTo2D<Vector3, Vector2, float>(inv_transformK * meanDirectionI3D);
Vector2 meanDirection2DJtoK = Map3DTo2D<Vector3, Vector2, float>(inv_transformK * meanDirectionJ3D);

const float inv_weightK = (weightK > 0.f) ? embree::rcp(weightK) : 1.f;
const float inv_weightK = (weightK > FLT_EPSILON) ? embree::rcp(weightK) : 1.f;

const float sumWeightsI = sumWeights[tmpI.quot][tmpI.rem];
const float sumWeightsJ = sumWeights[tmpJ.quot][tmpJ.rem];
Expand All @@ -1065,14 +1066,14 @@ void VonMisesFisherChiSquareComponentSplitter<TVMMFactory>::ComponentSplitStatis
// std::cout << "\tsumWeightsI: " << sumWeightsI << "\tsumWeightsJ: " << sumWeightsJ << "\tsumWeightsK: " << sumWeightsK << std::endl;
// std::cout << "\tnumSamplesI: " << numSamples[tmpI.quot][tmpI.rem] << "\tsumWeightsJ: " << numSamples[tmpJ.quot][tmpJ.rem] << std::endl;

const Vector3 covarianceI = (sumWeightsI > 0.f) ? Vector3(splitWeightedSampleCovariances[tmpI.quot].x[tmpI.rem], splitWeightedSampleCovariances[tmpI.quot].y[tmpI.rem],
splitWeightedSampleCovariances[tmpI.quot].z[tmpI.rem]) *
embree::rcp(sumWeightsI)
: Vector3(0.f);
const Vector3 covarianceJ = (sumWeightsJ > 0.f) ? Vector3(splitWeightedSampleCovariances[tmpJ.quot].x[tmpJ.rem], splitWeightedSampleCovariances[tmpJ.quot].y[tmpJ.rem],
splitWeightedSampleCovariances[tmpJ.quot].z[tmpJ.rem]) *
embree::rcp(sumWeightsJ)
: Vector3(0.f);
const Vector3 covarianceI = (sumWeightsI > FLT_EPSILON) ? Vector3(splitWeightedSampleCovariances[tmpI.quot].x[tmpI.rem], splitWeightedSampleCovariances[tmpI.quot].y[tmpI.rem],
splitWeightedSampleCovariances[tmpI.quot].z[tmpI.rem]) *
embree::rcp(sumWeightsI)
: Vector3(0.f);
const Vector3 covarianceJ = (sumWeightsJ > FLT_EPSILON) ? Vector3(splitWeightedSampleCovariances[tmpJ.quot].x[tmpJ.rem], splitWeightedSampleCovariances[tmpJ.quot].y[tmpJ.rem],
splitWeightedSampleCovariances[tmpJ.quot].z[tmpJ.rem]) *
embree::rcp(sumWeightsJ)
: Vector3(0.f);

#ifdef OPENPGL_ZERO_MEAN
const Vector2 meanDirectionK2D(0.f);
Expand Down
Loading