<commit_before>// This file is distributed under the MIT license.
// See the LICENSE file for details.

#include <exception>
#include <iostream>
#include <memory>
#include <ostream>

#include <GL/glew.h>

#include <visionaray/detail/platform.h>

#include <visionaray/math/math.h>

#include <visionaray/texture/texture.h>

#include <visionaray/cpu_buffer_rt.h>
#include <visionaray/phase_function.h>
#include <visionaray/pinhole_camera.h>
#include <visionaray/random_generator.h>
#include <visionaray/sampling.h>
#include <visionaray/scheduler.h>

#include <common/manip/arcball_manipulator.h>
#include <common/manip/pan_manipulator.h>
#include <common/manip/translate_manipulator.h>
#include <common/manip/zoom_manipulator.h>
#include <common/viewer_glut.h>

using namespace visionaray;

using viewer_type   = viewer_glut;


//-------------------------------------------------------------------------------------------------
// Procedural volumes
// Using the same as in "Ray Tracing Inhomogeneous Volumes" by <NAME> (Ray Tracing Gems 1)
//

template <int Mode>
struct volume
{
    // Extinction (absorption+scattering)
    float sigma_t(vec3 const& pos) const
    {
        if (Mode == 0) // spiral
        {
            const float r = 0.5f * (0.5f - fabsf (pos.y));
            const float a = (float)(M_PI * 8.0) * pos.y;
            const float dx = (cosf(a) * r - pos.x) * 2.0f;
            const float dy = (sinf(a) * r - pos.z) * 2.0f;
            return powf (fmaxf((1.0f - dx * dx - dy * dy), 0.0f), 8.0f) * sigma_();
        }
        else // menger sponge
        {
            vec3 ppos = pos + vec3(0.5f, 0.5f, 0.5f);
            const unsigned int steps = 3;
            for (unsigned int i = 0; i < steps; ++i)
            {
                ppos *= 3.0f;

                const int s = ((int)ppos.x & 1) + ((int)ppos.y & 1) + ((int)ppos.z & 1);

                if (s >= 2)
                {
                    return 0.0f;
                }
            }
            return sigma_();
        }
    }

    float sigma_a(vec3 const& pos) const
    {
        // Model extinction as 1:1 absorption and out-scattering
        return sigma_t(pos) / 2.0f;
    }

    // Majorant
    float sigma_() const
    {
        return 50.0f;
    }

    // Emission
    vec3 Le(vec3 const& pos) const
    {
        return vec3(0.0f);

        if (pos.x > 0.16f && pos.y > 0.16f && pos.z > 0.16f)
         //&& pos.x < 0.33f && pos.y < 0.33f && pos.z < 0.33f)
        {
            return vec3(4.0f, 2.0f, 1.5f);
            //return vec3(120.0f, 60.0f, 45.0f);
        }
        else
        {
            return vec3(0.0f);
        }
    }
};


//-------------------------------------------------------------------------------------------------
//
//

enum collision_type
{
    Scattering,
    Emission,
    Boundary,
};

namespace delta_tracking
{

template <int Mode>
collision_type sample_interaction(ray& r, ::volume<Mode> const& vol, vec3& Le, float& Tr,float d, random_generator<float>& gen)
{
    collision_type result;

    float t = 0.0f;
    vec3 pos;

    Le = vec3(0.0f);

    while (true)
    {
        t -= log(1.0f - gen.next()) / vol.sigma_();

        pos = r.ori + r.dir * t;
        if (t >= d)
        {
            result = Boundary;
            break;
        }

        float u2 = gen.next();
        if (u2 < vol.sigma_a(pos) / vol.sigma_t(pos))
        {
            Le = vol.Le(pos);
            result = Emission;
            break;
        }
        else if (vol.sigma_t(pos) >= u2 * vol.sigma_())
        {
            result = Scattering;
            break;
        }
    }

    Tr = result == Boundary ? 1.0f : 0.0f;
    r.ori = pos;

    return result;
}

}


//-------------------------------------------------------------------------------------------------
// struct with state variables
//

struct renderer : viewer_type
{
    using host_ray_type = basic_ray<float>;

    using model_manipulators = std::vector<std::shared_ptr<model_manipulator>>;

    renderer()
        : viewer_type(512, 512, "Visionaray Residual Ratio Tracking Example")
        , bbox({ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f })
        , host_sched(8)
    {
        model_manips.emplace_back( std::make_shared<translate_manipulator>(
                cam,
                sphere_transform,
                vec3(1.0f),
                mouse::Left
                ) );
    }

    aabb                                        bbox;
    pinhole_camera                              cam;
    cpu_buffer_rt<PF_RGBA32F, PF_UNSPECIFIED>   host_rt;
    tiled_sched<host_ray_type>                  host_sched;
<commit_msg>Change window title<commit_after>// This file is distributed under the MIT license.
// See the LICENSE file for details.

#include <exception>
#include <iostream>
#include <memory>
#include <ostream>

#include <GL/glew.h>

#include <visionaray/detail/platform.h>

#include <visionaray/math/math.h>

#include <visionaray/texture/texture.h>

#include <visionaray/cpu_buffer_rt.h>
#include <visionaray/phase_function.h>
#include <visionaray/pinhole_camera.h>
#include <visionaray/random_generator.h>
#include <visionaray/sampling.h>
#include <visionaray/scheduler.h>

#include <common/manip/arcball_manipulator.h>
#include <common/manip/pan_manipulator.h>
#include <common/manip/translate_manipulator.h>
#include <common/manip/zoom_manipulator.h>
#include <common/viewer_glut.h>

using namespace visionaray;

using viewer_type   = viewer_glut;


//-------------------------------------------------------------------------------------------------
// Procedural volumes
// Using the same as in "Ray Tracing Inhomogeneous Volumes" by <NAME> (Ray Tracing Gems 1)
//

template <int Mode>
struct volume
{
    // Extinction (absorption+scattering)
    float sigma_t(vec3 const& pos) const
    {
        if (Mode == 0) // spiral
        {
            const float r = 0.5f * (0.5f - fabsf (pos.y));
            const float a = (float)(M_PI * 8.0) * pos.y;
            const float dx = (cosf(a) * r - pos.x) * 2.0f;
            const float dy = (sinf(a) * r - pos.z) * 2.0f;
            return powf (fmaxf((1.0f - dx * dx - dy * dy), 0.0f), 8.0f) * sigma_();
        }
        else // menger sponge
        {
            vec3 ppos = pos + vec3(0.5f, 0.5f, 0.5f);
            const unsigned int steps = 3;
            for (unsigned int i = 0; i < steps; ++i)
            {
                ppos *= 3.0f;

                const int s = ((int)ppos.x & 1) + ((int)ppos.y & 1) + ((int)ppos.z & 1);

                if (s >= 2)
                {
                    return 0.0f;
                }
            }
            return sigma_();
        }
    }

    float sigma_a(vec3 const& pos) const
    {
        // Model extinction as 1:1 absorption and out-scattering
        return sigma_t(pos) / 2.0f;
    }

    // Majorant
    float sigma_() const
    {
        return 50.0f;
    }

    // Emission
    vec3 Le(vec3 const& pos) const
    {
        return vec3(0.0f);

        if (pos.x > 0.16f && pos.y > 0.16f && pos.z > 0.16f)
         //&& pos.x < 0.33f && pos.y < 0.33f && pos.z < 0.33f)
        {
            return vec3(4.0f, 2.0f, 1.5f);
            //return vec3(120.0f, 60.0f, 45.0f);
        }
        else
        {
            return vec3(0.0f);
        }
    }
};


//-------------------------------------------------------------------------------------------------
//
//

enum collision_type
{
    Scattering,
    Emission,
    Boundary,
};

namespace delta_tracking
{

template <int Mode>
collision_type sample_interaction(ray& r, ::volume<Mode> const& vol, vec3& Le, float& Tr,float d, random_generator<float>& gen)
{
    collision_type result;

    float t = 0.0f;
    vec3 pos;

    Le = vec3(0.0f);

    while (true)
    {
        t -= log(1.0f - gen.next()) / vol.sigma_();

        pos = r.ori + r.dir * t;
        if (t >= d)
        {
            result = Boundary;
            break;
        }

        float u2 = gen.next();
        if (u2 < vol.sigma_a(pos) / vol.sigma_t(pos))
        {
            Le = vol.Le(pos);
            result = Emission;
            break;
        }
        else if (vol.sigma_t(pos) >= u2 * vol.sigma_())
        {
            result = Scattering;
            break;
        }
    }

    Tr = result == Boundary ? 1.0f : 0.0f;
    r.ori = pos;

    return result;
}

}


//-------------------------------------------------------------------------------------------------
// struct with state variables
//

struct renderer : viewer_type
{
    using host_ray_type = basic_ray<float>;

    using model_manipulators = std::vector<std::shared_ptr<model_manipulator>>;

    renderer()
        : viewer_type(512, 512, "Visionaray Volumetric Pathtracer Example")
        , bbox({ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f })
        , host_sched(8)
    {
        model_manips.emplace_back( std::make_shared<translate_manipulator>(
                cam,
                sphere_transform,
                vec3(1.0f),
                mouse::Left
                ) );
    }

    aabb                                        bbox;
    pinhole_camera                              cam;
    cpu_buffer_rt<PF_RGBA32F, PF_UNSPECIFIED>   host_rt;
    tiled_sched<host_ray_type>                  host_sched;

{'fraction_non_alphanumeric': 0.1875, 'fraction_numerical': 0.027897923875432527, 'mean_word_length': 1.4326670173592846, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5314941', 'n_tokens_mistral': 3277, 'n_tokens_neox': 3052, 'n_words': 687}