<commit_before>// Copyright (c) 2016 <NAME> <<EMAIL>>
//
// 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.

#pragma once

#include "amber/rendering/bidirectional_path_sampling.h"

namespace amber {
namespace rendering {

/** Buffer object for the purpose of efficient calculation of MIS weight.
 */
template <typename Radiant>
class UnifiedPathSamplingBuffer
: public BidirectionalPathSamplingBuffer<Radiant>
{
public:
  using typename BidirectionalPathSamplingBuffer<Radiant>::SubpathConstIterator;

  /** Constructor.
   */
  UnifiedPathSamplingBuffer() noexcept;

  /** Buffers full path information.
   */
  void
  Buffer(
    const Scene<Radiant>& scene,
    const Sensor& sensor,
    SubpathConstIterator light_first,
    SubpathConstIterator light_last,
    SubpathConstIterator eye_first,
    SubpathConstIterator eye_last,
    real_type kernel,
    bool did_virtual_perturbation
  );

private:
  using BidirectionalPathSamplingBuffer<Radiant>::geometry_factor_;
  using BidirectionalPathSamplingBuffer<Radiant>::p_light_;
  using BidirectionalPathSamplingBuffer<Radiant>::p_importance_;
  using BidirectionalPathSamplingBuffer<Radiant>::p_technique_;

  void
  ExtendTechniqueProbability(
    const Scene<Radiant>& scene,
    const Sensor& sensor,
    SubpathConstIterator light_first,
    SubpathConstIterator light_last,
    SubpathConstIterator eye_first,
    SubpathConstIterator eye_last,
    real_type kernel,
    bool did_virtual_perturbation
  );
};





template <typename Radiant>
UnifiedPathSamplingBuffer<Radiant>::UnifiedPathSamplingBuffer() noexcept
: BidirectionalPathSamplingBuffer<Radiant>()
{}

template <typename Radiant>
void
UnifiedPathSamplingBuffer<Radiant>::Buffer(
  const Scene<Radiant>& scene,
  const Sensor& sensor,
  SubpathConstIterator light_first,
  SubpathConstIterator light_last,
  SubpathConstIterator eye_first,
  SubpathConstIterator eye_last,
  real_type kernel,
  bool did_virtual_perturbation
)
{
  if (!did_virtual_perturbation) {
    light_last--;
  }

  BidirectionalPathSamplingBuffer<Radiant>::BufferGeometryFactor(
    scene, sensor, light_first, light_last, eye_first, eye_last);
  BidirectionalPathSamplingBuffer<Radiant>::BufferLightProbability(
    scene, sensor, light_first, light_last, eye_first, eye_last);
  BidirectionalPathSamplingBuffer<Radiant>::BufferImportanceProbability(
    scene, sensor, light_first, light_last, eye_first, eye_last);
  BidirectionalPathSamplingBuffer<Radiant>::BufferTechniqueProbability(
    scene, sensor, light_first, light_last, eye_first, eye_last);

  ExtendTechniqueProbability(
    scene,
    sensor,
    light_first,
    light_last,
    eye_first,
    eye_last,
    kernel,
    did_virtual_perturbation
  );
}
<commit_msg>Refactor UnifiedPathSamplingBuffer<commit_after>// Copyright (c) 2016 <NAME> <<EMAIL>>
//
// 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.

#pragma once

#include "amber/rendering/bidirectional_path_sampling.h"

namespace amber {
namespace rendering {

/** Buffer object for the purpose of efficient calculation of MIS weight.
 */
template <typename Radiant>
class UnifiedPathSamplingBuffer
: private BidirectionalPathSamplingBuffer<Radiant>
{
public:
  using typename BidirectionalPathSamplingBuffer<Radiant>::SubpathConstIterator;

  /** Constructor.
   */
  UnifiedPathSamplingBuffer() noexcept;

  /** Buffers full path information.
   */
  void
  Buffer(
    const Scene<Radiant>& scene,
    const Sensor& sensor,
    SubpathConstIterator light_first,
    SubpathConstIterator light_last,
    SubpathConstIterator eye_first,
    SubpathConstIterator eye_last,
    real_type kernel,
    bool did_virtual_perturbation
  );

  /** Calculates MIS weight for the current buffer.
   */
  const real_type MISWeight(const MIS& mis) const noexcept;

private:
  using BidirectionalPathSamplingBuffer<Radiant>::geometry_factor_;
  using BidirectionalPathSamplingBuffer<Radiant>::p_light_;
  using BidirectionalPathSamplingBuffer<Radiant>::p_importance_;
  using BidirectionalPathSamplingBuffer<Radiant>::p_technique_;

  void
  ExtendTechniqueProbability(
    const Scene<Radiant>& scene,
    const Sensor& sensor,
    SubpathConstIterator light_first,
    SubpathConstIterator light_last,
    SubpathConstIterator eye_first,
    SubpathConstIterator eye_last,
    real_type kernel,
    bool did_virtual_perturbation
  );
};





template <typename Radiant>
UnifiedPathSamplingBuffer<Radiant>::UnifiedPathSamplingBuffer() noexcept
: BidirectionalPathSamplingBuffer<Radiant>()
{}

template <typename Radiant>
void
UnifiedPathSamplingBuffer<Radiant>::Buffer(
  const Scene<Radiant>& scene,
  const Sensor& sensor,
  SubpathConstIterator light_first,
  SubpathConstIterator light_last,
  SubpathConstIterator eye_first,
  SubpathConstIterator eye_last,
  real_type kernel,
  bool did_virtual_perturbation
)
{
  if (!did_virtual_perturbation) {
    light_last--;
  }

  BidirectionalPathSamplingBuffer<Radiant>::BufferGeometryFactor(
    scene, sensor, light_first, light_last, eye_first, eye_last);
  BidirectionalPathSamplingBuffer<Radiant>::BufferLightProbability(
    scene, sensor, light_first, light_last, eye_first, eye_last);
  BidirectionalPathSamplingBuffer<Radiant>::BufferImportanceProbability(
    scene, sensor, light_first, light_last, eye_first, eye_last);
  BidirectionalPathSamplingBuffer<Radiant>::BufferTechniqueProbability(
    scene, sensor, light_first, light_last, eye_first, eye_last);

  ExtendTechniqueProbability(
    scene,
    sensor,
    light_first,
    light_last,
    eye_first,
    eye_last,
    kernel,
    did_virtual_perturbation
  );
}

template <typename Radiant>
const real_type
UnifiedPathSamplingBuffer<Radiant>::MISWeight(const MIS& mis) const noexcept
{
  return BidirectionalPathSamplingBuffer<Radiant>::MISWeight(mis);
}

{'fraction_non_alphanumeric': 0.07434849259070005, 'fraction_numerical': 0.001021972406745018, 'mean_word_length': 5.11640625, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 50, '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': '3426390', 'n_tokens_mistral': 2297, 'n_tokens_neox': 2175, 'n_words': 673}