diff --git a/openpgl/directional/vmm/VMMChiSquareComponentSplitter.h b/openpgl/directional/vmm/VMMChiSquareComponentSplitter.h index ef12ddb..dabfaa5 100644 --- a/openpgl/directional/vmm/VMMChiSquareComponentSplitter.h +++ b/openpgl/directional/vmm/VMMChiSquareComponentSplitter.h @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -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); @@ -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; @@ -503,7 +504,7 @@ void VonMisesFisherChiSquareComponentSplitter::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 @@ -1056,7 +1057,7 @@ void VonMisesFisherChiSquareComponentSplitter::ComponentSplitStatis Vector2 meanDirection2DItoK = Map3DTo2D(inv_transformK * meanDirectionI3D); Vector2 meanDirection2DJtoK = Map3DTo2D(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]; @@ -1065,14 +1066,14 @@ void VonMisesFisherChiSquareComponentSplitter::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);