<commit_before>// ======================================================================== //
// Copyright 2009-2013 Intel Corporation                                    //
//                                                                          //
// Licensed under the Apache License, Version 2.0 (the "License");          //
// you may not use this file except in compliance with the License.         //
// You may obtain a copy of the License at                                  //
//                                                                          //
//     http://www.apache.org/licenses/LICENSE-2.0                           //
//                                                                          //
// Unless required by applicable law or agreed to in writing, software      //
// distributed under the License is distributed on an "AS IS" BASIS,        //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and      //
// limitations under the License.                                           //
// ======================================================================== //

#include "acceln.h"

namespace embree
{
  AccelN::AccelN () : N(0) { 
    memset(accels,0,sizeof(accels));
  }

  AccelN::~AccelN() 
  {
    for (size_t i=0; i<N; i++)
      delete accels[i];
  }

  void AccelN::add(Accel* accel) 
  {
    assert(N<16);
    assert(accel);
    if (N<16) accels[N++] = accel;
  }
  
  void AccelN::intersect (void* ptr, RTCRay& ray) 
  {
    AccelN* This = (AccelN*)ptr;
    for (size_t i=0; i<This->N; i++)
      This->accels[i]->intersect(ray);
  }

  void AccelN::intersect4 (const void* valid, void* ptr, RTCRay4& ray) 
  {
    AccelN* This = (AccelN*)ptr;
    for (size_t i=0; i<This->N; i++)
      This->accels[i]->intersect4(valid,ray);
  }

  void AccelN::intersect8 (const void* valid, void* ptr, RTCRay8& ray) 
  {
    AccelN* This = (AccelN*)ptr;
    for (size_t i=0; i<This->N; i++)
      This->accels[i]->intersect8(valid,ray);
  }

  void AccelN::intersect16 (const void* valid, void* ptr, RTCRay16& ray) 
  {
    AccelN* This = (AccelN*)ptr;
    for (size_t i=0; i<This->N; i++)
      This->accels[i]->intersect16(valid,ray);
  }

  void AccelN::occluded (void* ptr, RTCRay& ray) 
  {
    AccelN* This = (AccelN*)ptr;
    for (size_t i=0; i<This->N; i++)
      This->accels[i]->occluded(ray); // FIXME: terminate loop if hit found
  }

  void AccelN::occluded4 (const void* valid, void* ptr, RTCRay4& ray) 
  {
    AccelN* This = (AccelN*)ptr;
    for (size_t i=0; i<This->N; i++)
      This->accels[i]->occluded4(valid,ray);
  }

  void AccelN::occluded8 (const void* valid, void* ptr, RTCRay8& ray) 
  {
    AccelN* This = (AccelN*)ptr;
    for (size_t i=0; i<This->N; i++)
      This->accels[i]->occluded8(valid,ray);
  }

  void AccelN::occluded16 (const void* valid, void* ptr, RTCRay16& ray) 
  {
    AccelN* This = (AccelN*)ptr;
    for (size_t i=0; i<This->N; i++)
      This->accels[i]->occluded16(valid,ray);
  }

  void AccelN::print(size_t ident)
  {
    for (size_t i=0; i<N; i++)
    {
      for (size_t j=0; j<ident; j++) std::cout << " "; 
      std::cout << "accels[" << i << "]" << std::endl;
      accels[i]->intersectors.print(ident+2);
    }
  }

  void AccelN::immutable()
  {
    for (size_t i=0; i<N; i++)
      accels[i]->immutable();
  }

  void AccelN::build (size_t threadIndex, size_t threadCount) 
  {
    size_t validAccelIndex = 0;
    size_t validAccelCount = 0;
    
    /* build all acceleration structures */
    for (size_t i=0; i<N; i++) 
    {
      accels[i]->build(threadIndex,threadCount);<commit_msg>optimization in AccelN, exiting occluded loop if already found a hit<commit_after>// ======================================================================== //
// Copyright 2009-2013 Intel Corporation                                    //
//                                                                          //
// Licensed under the Apache License, Version 2.0 (the "License");          //
// you may not use this file except in compliance with the License.         //
// You may obtain a copy of the License at                                  //
//                                                                          //
//     http://www.apache.org/licenses/LICENSE-2.0                           //
//                                                                          //
// Unless required by applicable law or agreed to in writing, software      //
// distributed under the License is distributed on an "AS IS" BASIS,        //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and      //
// limitations under the License.                                           //
// ======================================================================== //

#include "acceln.h"
#include "embree2/rtcore_ray.h"

namespace embree
{
  AccelN::AccelN () : N(0) { 
    memset(accels,0,sizeof(accels));
  }

  AccelN::~AccelN() 
  {
    for (size_t i=0; i<N; i++)
      delete accels[i];
  }

  void AccelN::add(Accel* accel) 
  {
    assert(N<16);
    assert(accel);
    if (N<16) accels[N++] = accel;
  }
  
  void AccelN::intersect (void* ptr, RTCRay& ray) 
  {
    AccelN* This = (AccelN*)ptr;
    for (size_t i=0; i<This->N; i++)
      This->accels[i]->intersect(ray);
  }

  void AccelN::intersect4 (const void* valid, void* ptr, RTCRay4& ray) 
  {
    AccelN* This = (AccelN*)ptr;
    for (size_t i=0; i<This->N; i++)
      This->accels[i]->intersect4(valid,ray);
  }

  void AccelN::intersect8 (const void* valid, void* ptr, RTCRay8& ray) 
  {
    AccelN* This = (AccelN*)ptr;
    for (size_t i=0; i<This->N; i++)
      This->accels[i]->intersect8(valid,ray);
  }

  void AccelN::intersect16 (const void* valid, void* ptr, RTCRay16& ray) 
  {
    AccelN* This = (AccelN*)ptr;
    for (size_t i=0; i<This->N; i++)
      This->accels[i]->intersect16(valid,ray);
  }

  void AccelN::occluded (void* ptr, RTCRay& ray) 
  {
    AccelN* This = (AccelN*)ptr;
    for (size_t i=0; i<This->N; i++) {
      This->accels[i]->occluded(ray); 
      if (ray.geomID == 0) break;
    }
  }

  void AccelN::occluded4 (const void* valid, void* ptr, RTCRay4& ray) 
  {
    AccelN* This = (AccelN*)ptr;
    for (size_t i=0; i<This->N; i++) {
      This->accels[i]->occluded4(valid,ray);
      // FIXME: exit if already hit something
    }
  }

  void AccelN::occluded8 (const void* valid, void* ptr, RTCRay8& ray) 
  {
    AccelN* This = (AccelN*)ptr;
    for (size_t i=0; i<This->N; i++) {
      This->accels[i]->occluded8(valid,ray);
      // FIXME: exit if already hit something
    }
  }

  void AccelN::occluded16 (const void* valid, void* ptr, RTCRay16& ray) 
  {
    AccelN* This = (AccelN*)ptr;
    for (size_t i=0; i<This->N; i++) {
      This->accels[i]->occluded16(valid,ray);
      // FIXME: exit if already hit something
    }
  }

  void AccelN::print(size_t ident)
  {
    for (size_t i=0; i<N; i++)
    {
      for (size_t j=0; j<ident; j++) std::cout << " "; 
      std::cout << "accels[" << i << "]" << std::endl;
      accels[i]->intersectors.print(ident+2);
    }
  }

  void AccelN::immutable()
  {
    for (size_t i=0; i<N; i++)
      accels[i]->immutable();
  }

  void AccelN::build (size_t threadIndex, size_t threadCount) 
  {
    size_t validAccelIndex = 0;
    size_t validAccelCount = 0;
    
    /* build all acceleration structures */
    for (size_t i=0; i<N; i++) 
    {
      accels[i]->build(threadIndex,threadCount);
{'fraction_non_alphanumeric': 0.18627194131516897, 'fraction_numerical': 0.015457165313073094, 'mean_word_length': 2.058894230769231, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5276134', 'n_tokens_mistral': 2657, 'n_tokens_neox': 2540, 'n_words': 627}