<commit_before>/*++

Copyright (c) 2018 <NAME>

Module Name:

    sample_tracer.c

Abstract:

    Implements physx sample tracer.

--*/

#include <stdalign.h>

#include "iris_physx_toolkit/sample_tracer.h"

//
// Types
//

typedef struct _PHYSX_SAMPLE_TRACER {
    PINTEGRATOR integrator;
    PSHAPE_RAY_TRACER_TRACE_ROUTINE trace_routine;
    const void *trace_context;
    PLIGHT_SAMPLER_SAMPLE_LIGHTS_ROUTINE sample_lights_routine;
    const void* sample_lights_context;
    PCOLOR_MATCHER color_matcher;
} PHYSX_SAMPLE_TRACER, *PPHYSX_SAMPLE_TRACER;

typedef const PHYSX_SAMPLE_TRACER *PCPHYSX_SAMPLE_TRACER;

//
// Static Functions
//

static
ISTATUS
PhysxSampleTracerTraceRay(
    _In_opt_ void *context,
    _In_ PCRAY ray,
    _In_ PRANDOM rng,
    _In_ float_t epsilon
    )
{
    PPHYSX_SAMPLE_TRACER physx_sample_tracer = (PPHYSX_SAMPLE_TRACER)context;

    ISTATUS status = 
        IntegratorIntegrate(physx_sample_tracer->integrator,
                            physx_sample_tracer->trace_routine,
                            physx_sample_tracer->trace_context,
                            physx_sample_tracer->sample_lights_routine,
                            physx_sample_tracer->sample_lights_context,
                            *ray,
                            rng,
                            epsilon,
                            physx_sample_tracer->color_matcher);

    return status;
}

static
ISTATUS
PhysxSampleTracerColorMatch(
    _In_opt_ void *context,
    _Out_ PCOLOR3 color
    )
{
    PPHYSX_SAMPLE_TRACER physx_sample_tracer = (PPHYSX_SAMPLE_TRACER)context;

    ISTATUS status =
        ColorMatcherComputeColor(physx_sample_tracer->color_matcher, color);

    if (status != ISTATUS_SUCCESS)
    {
        return status;
    }

    status = ColorMatcherClear(physx_sample_tracer->color_matcher);

    return status;
}

static
void
PhysxSampleTracerFree(
    _In_opt_ _Post_invalid_ void *context
    )
{
    PPHYSX_SAMPLE_TRACER physx_sample_tracer = (PPHYSX_SAMPLE_TRACER)context;

    IntegratorFree(physx_sample_tracer->integrator);
    ColorMatcherFree(physx_sample_tracer->color_matcher);
}

//
// Static Data
//

static const SAMPLE_TRACER_VTABLE sample_tracer_vtable = {
    PhysxSampleTracerTraceRay,
    PhysxSampleTracerColorMatch,
    NULL, // TODO
    PhysxSampleTracerFree
};

//
// Functions
//<commit_msg>Implement PhysxSampleTracerDuplicate<commit_after>/*++

Copyright (c) 2018 <NAME>

Module Name:

    sample_tracer.c

Abstract:

    Implements physx sample tracer.

--*/

#include <stdalign.h>

#include "iris_physx_toolkit/sample_tracer.h"

//
// Types
//

typedef struct _PHYSX_SAMPLE_TRACER {
    PINTEGRATOR integrator;
    PSHAPE_RAY_TRACER_TRACE_ROUTINE trace_routine;
    const void *trace_context;
    PLIGHT_SAMPLER_SAMPLE_LIGHTS_ROUTINE sample_lights_routine;
    const void* sample_lights_context;
    PCOLOR_MATCHER color_matcher;
} PHYSX_SAMPLE_TRACER, *PPHYSX_SAMPLE_TRACER;

typedef const PHYSX_SAMPLE_TRACER *PCPHYSX_SAMPLE_TRACER;

//
// Static Functions
//

static
ISTATUS
PhysxSampleTracerTraceRay(
    _In_opt_ void *context,
    _In_ PCRAY ray,
    _In_ PRANDOM rng,
    _In_ float_t epsilon
    )
{
    PPHYSX_SAMPLE_TRACER physx_sample_tracer = (PPHYSX_SAMPLE_TRACER)context;

    ISTATUS status = 
        IntegratorIntegrate(physx_sample_tracer->integrator,
                            physx_sample_tracer->trace_routine,
                            physx_sample_tracer->trace_context,
                            physx_sample_tracer->sample_lights_routine,
                            physx_sample_tracer->sample_lights_context,
                            *ray,
                            rng,
                            epsilon,
                            physx_sample_tracer->color_matcher);

    return status;
}

static
ISTATUS
PhysxSampleTracerColorMatch(
    _In_opt_ void *context,
    _Out_ PCOLOR3 color
    )
{
    PPHYSX_SAMPLE_TRACER physx_sample_tracer = (PPHYSX_SAMPLE_TRACER)context;

    ISTATUS status =
        ColorMatcherComputeColor(physx_sample_tracer->color_matcher, color);

    if (status != ISTATUS_SUCCESS)
    {
        return status;
    }

    status = ColorMatcherClear(physx_sample_tracer->color_matcher);

    return status;
}

static
ISTATUS
PhysxSampleTracerDuplicate(
    _In_opt_ const void *context,
    _Out_ PSAMPLE_TRACER *duplicate
    )
{
    PCPHYSX_SAMPLE_TRACER physx_sample_tracer = (PCPHYSX_SAMPLE_TRACER)context;

    PINTEGRATOR integrator;
    ISTATUS status = IntegratorDuplicate(physx_sample_tracer->integrator,
                                         &integrator);

    if (status != ISTATUS_SUCCESS)
    {
        return status;
    }

    PCOLOR_MATCHER color_matcher;
    status = ColorMatcherReplicate(physx_sample_tracer->color_matcher,
                                   &color_matcher);

    if (status != ISTATUS_SUCCESS)
    {
        IntegratorFree(integrator);
        return status;
    }

    status =
        PhysxSampleTracerAllocate(integrator,
                                  physx_sample_tracer->trace_routine,
                                  physx_sample_tracer->trace_context,
                                  physx_sample_tracer->sample_lights_routine,
                                  physx_sample_tracer->sample_lights_context,
                                  color_matcher,
                                  duplicate);

    if (status != ISTATUS_SUCCESS)
    {
        IntegratorFree(integrator);
        ColorMatcherFree(color_matcher);
    }

    return status;
}

static
void
PhysxSampleTracerFree(
    _In_opt_ _Post_invalid_ void *context
    )
{
    PPHYSX_SAMPLE_TRACER physx_sample_tracer = (PPHYSX_SAMPLE_TRACER)context;

    IntegratorFree(physx_sample_tracer->integrator);
    ColorMatcherFree(physx_sample_tracer->color_matcher);
}

//
// Static Data
//

static const SAMPLE_TRACER_VTABLE sample_tracer_vtable = {
    PhysxSampleTracerTraceRay,
    PhysxSampleTracerColorMatch,
    PhysxSampleTracerDuplicate,
    PhysxSampleTracerFree
};

//
// Functions
//
{'fraction_non_alphanumeric': 0.06666666666666667, 'fraction_numerical': 0.0016542597187758478, 'mean_word_length': 2.519208381839348, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4719671', 'n_tokens_mistral': 2082, 'n_tokens_neox': 2017, 'n_words': 296}