<commit_before>
//
// This source file is part of appleseed.
// Visit http://appleseedhq.net/ for additional information and resources.
//
// This software is released under the MIT license.
//
// Copyright (c) 2015 <NAME>, The appleseedhq Organization
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

// appleseed.renderer headers.
#include "renderer/kernel/shading/shadingpoint.h"
#include "renderer/kernel/shading/shadingpointbuilder.h"
#include "renderer/modeling/bssrdf/betterdipolebssrdf.h"
#include "renderer/modeling/bssrdf/bssrdf.h"
#include "renderer/modeling/bssrdf/directionaldipolebssrdf.h"
#ifdef APPLESEED_WITH_NORMALIZED_DIFFUSION_BSSRDF
#include "renderer/modeling/bssrdf/normalizeddiffusionbssrdf.h"
#endif
#include "renderer/modeling/bssrdf/sss.h"
#include "renderer/modeling/bssrdf/standarddipolebssrdf.h"
#include "renderer/utility/paramarray.h"

// appleseed.foundation headers.
#include "foundation/image/color.h"
#include "foundation/math/rng/distribution.h"
#include "foundation/math/rng/mersennetwister.h"
#include "foundation/math/sampling/mappings.h"
#include "foundation/math/basis.h"
#include "foundation/math/fresnel.h"
#include "foundation/math/scalar.h"
#include "foundation/utility/autoreleaseptr.h"
#include "foundation/utility/gnuplotfile.h"
#ifdef APPLESEED_WITH_PARTIO
#include "foundation/utility/partiofile.h"
#endif
#include "foundation/utility/string.h"
#include "foundation/utility/test.h"

// Standard headers.
#include <algorithm>
#include <cstddef>
#include <vector>

using namespace foundation;
using namespace renderer;
using namespace std;

TEST_SUITE(Renderer_Modeling_BSSRDF_SSS)
{
    //
    // Utilities.
    //

    template <typename BSSRDFFactory>
    class DipoleBSSRDFEvaluator
    {
      public:
        DipoleBSSRDFEvaluator()
          : m_bssrdf(BSSRDFFactory().create("bssrdf", ParamArray()))
        {
            ShadingPointBuilder outgoing_builder(m_outgoing_point);
            outgoing_builder.set_primitive_type(ShadingPoint::PrimitiveTriangle);
            outgoing_builder.set_shading_basis(Basis3d(Vector3d(0.0, 1.0, 0.0)));
            outgoing_builder.set_point(Vector3d(0.0, 0.0, 0.0));
        }

        void set_values_from_sigmas(
            const double    sigma_a,
            const double    sigma_s,
            const double    eta,
            const double    g)
        {
            m_values.m_weight = 1.0;
            m_values.m_sigma_a = Color3f(static_cast<float>(sigma_a));
            m_values.m_sigma_s = Color3f(static_cast<float>(sigma_s));
            m_values.m_anisotropy = g;
            m_values.m_outside_ior = 1.0;
            m_values.m_inside_ior = eta;

            effective_extinction_coefficient(
                m_values.m_sigma_a,
                m_values.m_sigma_s,
                m_values.m_anisotropy,
                m_values.m_sigma_tr);
        }

        void set_values_from_rd_dmfp(
            const double    rd,
            const double    dmfp,
            const double    eta,
            const double    g)
        {
            m_values.m_weight = 1.0;
            m_values.m_reflectance.set(static_cast<float>(rd));
            m_values.m_reflectance_multiplier = 1.0;
            m_values.m_dmfp = dmfp;
            m_values.m_dmfp_multiplier = 1.0;
            m_values.m_anisotropy = g;
            m_values.m_outside_ior = 1.0;
            m_values.m_inside_ior = eta;

            m_bssrdf->prepare_inputs(&m_values);
        }

        const double get_sigma_tr() const
        {
            return static_cast<double>(m_values.m_sigma_tr[0]);
        }

        double evaluate(const double r, const Vector3d& incoming_dir) const<commit_msg>Fix SSS unit test<commit_after>
//
// This source file is part of appleseed.
// Visit http://appleseedhq.net/ for additional information and resources.
//
// This software is released under the MIT license.
//
// Copyright (c) 2015 <NAME>, The appleseedhq Organization
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

// appleseed.renderer headers.
#include "renderer/kernel/shading/shadingpoint.h"
#include "renderer/kernel/shading/shadingpointbuilder.h"
#include "renderer/modeling/bssrdf/betterdipolebssrdf.h"
#include "renderer/modeling/bssrdf/bssrdf.h"
#include "renderer/modeling/bssrdf/directionaldipolebssrdf.h"
#ifdef APPLESEED_WITH_NORMALIZED_DIFFUSION_BSSRDF
#include "renderer/modeling/bssrdf/normalizeddiffusionbssrdf.h"
#endif
#include "renderer/modeling/bssrdf/sss.h"
#include "renderer/modeling/bssrdf/standarddipolebssrdf.h"
#include "renderer/modeling/input/inputarray.h"
#include "renderer/modeling/input/scalarsource.h"
#include "renderer/utility/paramarray.h"

// appleseed.foundation headers.
#include "foundation/image/color.h"
#include "foundation/math/rng/distribution.h"
#include "foundation/math/rng/mersennetwister.h"
#include "foundation/math/sampling/mappings.h"
#include "foundation/math/basis.h"
#include "foundation/math/fresnel.h"
#include "foundation/math/scalar.h"
#include "foundation/utility/autoreleaseptr.h"
#include "foundation/utility/gnuplotfile.h"
#ifdef APPLESEED_WITH_PARTIO
#include "foundation/utility/partiofile.h"
#endif
#include "foundation/utility/string.h"
#include "foundation/utility/test.h"

// Standard headers.
#include <algorithm>
#include <cstddef>
#include <vector>

using namespace foundation;
using namespace renderer;
using namespace std;

TEST_SUITE(Renderer_Modeling_BSSRDF_SSS)
{
    //
    // Utilities.
    //

    template <typename BSSRDFFactory>
    class DipoleBSSRDFEvaluator
    {
      public:
        DipoleBSSRDFEvaluator()
          : m_bssrdf(BSSRDFFactory().create("bssrdf", ParamArray()))
        {
            ShadingPointBuilder outgoing_builder(m_outgoing_point);
            outgoing_builder.set_primitive_type(ShadingPoint::PrimitiveTriangle);
            outgoing_builder.set_shading_basis(Basis3d(Vector3d(0.0, 1.0, 0.0)));
            outgoing_builder.set_point(Vector3d(0.0, 0.0, 0.0));
        }

        void set_values_from_sigmas(
            const double    sigma_a,
            const double    sigma_s,
            const double    eta,
            const double    g)
        {
            m_values.m_weight = 1.0;
            m_values.m_anisotropy = g;
            m_values.m_outside_ior = 1.0;
            m_values.m_inside_ior = eta;

            m_bssrdf->get_inputs().find("sigma_a").bind(new ScalarSource(sigma_a));
            m_bssrdf->get_inputs().find("sigma_a").source()->evaluate_uniform(m_values.m_sigma_a);

            m_bssrdf->get_inputs().find("sigma_s").bind(new ScalarSource(sigma_s));
            m_bssrdf->get_inputs().find("sigma_s").source()->evaluate_uniform(m_values.m_sigma_s);

            m_bssrdf->prepare_inputs(&m_values);
        }

        void set_values_from_rd_dmfp(
            const double    rd,
            const double    dmfp,
            const double    eta,
            const double    g)
        {
            m_values.m_weight = 1.0;
            m_values.m_reflectance.set(static_cast<float>(rd));
            m_values.m_reflectance_multiplier = 1.0;
            m_values.m_dmfp = dmfp;
            m_values.m_dmfp_multiplier = 1.0;
            m_values.m_anisotropy = g;
            m_values.m_outside_ior = 1.0;
            m_values.m_inside_ior = eta;

            m_bssrdf->prepare_inputs(&m_values);
        }

        const double get_sigma_tr() const
        {
            return static_cast<double>(m_values.m_sigma_tr[0]);
        }

        double evaluate(const double r, const Vector3d& incoming_dir) const
{'fraction_non_alphanumeric': 0.09791666666666667, 'fraction_numerical': 0.007083333333333333, 'mean_word_length': 3.0425263157894737, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4661269', 'n_tokens_mistral': 3113, 'n_tokens_neox': 3036, 'n_words': 716}