<commit_before>#include "Rayforce.h"

#include <stdio.h>
#include <stdlib.h>

#include <rfut/CullMode.h>
#include <rfut/ModelType.h>
#include <rfut/Target.h>

#include <rfut/Buffer.t>
#include <rfut/Context.h>
#include <rfut/Device.t>
#include <rfut/Model.h>
#include <rfut/Object.h>
#include <rfut/Scene.t>
#include <rfut/TraceFcn.t>

#include "rfStruct.h"

#include "Interface/RayPacket.h"
#include "Interface/Primitive.h"
#include "Interface/TexCoordMapper.h"
#include "Core/Color/Color.h"
#include "Core/Geometry/BBox.h"
#include "Model/Materials/Lambertian.h"
#include "Model/Groups/Mesh.h"
#include "Model/Groups/Group.h"

using namespace Manta;

extern rfPipeline rfRays;

Rayforce::Rayforce() :
  context(0),
  object(0),
  model(0),
  scene(0),
  device(0),
  traceFcn(0),
  inited(false),
  currMesh(0)
{
  /*no-op*/
}

Rayforce::~Rayforce()
{
  cleanup();
}

bool Rayforce::buildFromFile(const std::string &fileName)
{
  fprintf(stderr, "buildFromFile()\n");

  initialize();

  model = new rfut::Model(*scene, ModelType::Triangles, 255, 255);
  model->setData(fileName);

  object->attach(*model);
  scene->acquire();

  traceFcn = new rfut::TraceFcn<Target::System>(*scene, rfRays);

  inited = true;

  // Finished loading the graph cache, return success
  return true;
}

bool Rayforce::saveToFile(const string &fileName)
{
  fprintf(stderr, "saveToFile()\n");

  if(model)
  {
    model->saveCacheFile(fileName);
    return true;
  }

  return false;
}

void Rayforce::intersect(const RenderContext& context, RayPacket& rays) const
{
  //fprintf(stderr, "intersect()\n");

  for(int i = rays.begin(); i < rays.end(); ++i)
  {
    rfRaySingle ray;

    ray.origin[0] = rays.getRay(i).origin().x();
    ray.origin[1] = rays.getRay(i).origin().y();
    ray.origin[2] = rays.getRay(i).origin().z();

    ray.vector[0] = rays.getRay(i).direction().x();
    ray.vector[1] = rays.getRay(i).direction().y();
    ray.vector[2] = rays.getRay(i).direction().z();

    ray.root = scene->resolve(ray.origin);

    rfRayData rayData;

    (*traceFcn)(ray, rayData);
<commit_msg>optimization to the tracing loop in Rayforce::intersect()<commit_after>#include "Rayforce.h"

#include <stdio.h>
#include <stdlib.h>

#include <rfut/CullMode.h>
#include <rfut/ModelType.h>
#include <rfut/Target.h>

#include <rfut/Buffer.t>
#include <rfut/Context.h>
#include <rfut/Device.t>
#include <rfut/Model.h>
#include <rfut/Object.h>
#include <rfut/Scene.t>
#include <rfut/TraceFcn.t>

#include "rfStruct.h"

#include "Interface/RayPacket.h"
#include "Interface/Primitive.h"
#include "Interface/TexCoordMapper.h"
#include "Core/Color/Color.h"
#include "Core/Geometry/BBox.h"
#include "Model/Materials/Lambertian.h"
#include "Model/Groups/Mesh.h"
#include "Model/Groups/Group.h"

using namespace Manta;

extern rfPipeline rfRays;

Rayforce::Rayforce() :
  context(0),
  object(0),
  model(0),
  scene(0),
  device(0),
  traceFcn(0),
  inited(false),
  currMesh(0)
{
  /*no-op*/
}

Rayforce::~Rayforce()
{
  cleanup();
}

bool Rayforce::buildFromFile(const std::string &fileName)
{
  fprintf(stderr, "buildFromFile()\n");

  initialize();

  model = new rfut::Model(*scene, ModelType::Triangles, 255, 255);
  model->setData(fileName);

  object->attach(*model);
  scene->acquire();

  traceFcn = new rfut::TraceFcn<Target::System>(*scene, rfRays);

  inited = true;

  // Finished loading the graph cache, return success
  return true;
}

bool Rayforce::saveToFile(const string &fileName)
{
  fprintf(stderr, "saveToFile()\n");

  if(model)
  {
    model->saveCacheFile(fileName);
    return true;
  }

  return false;
}

void Rayforce::intersect(const RenderContext& context, RayPacket& rays) const
{
  //fprintf(stderr, "intersect()\n");

  for(int i = rays.begin(); i < rays.end(); ++i)
  {
    rfRaySingle ray;

    Manta::Ray mray = rays.getRay(i);

    ray.origin[0] = mray.origin().x();
    ray.origin[1] = mray.origin().y();
    ray.origin[2] = mray.origin().z();

    ray.vector[0] = mray.direction().x();
    ray.vector[1] = mray.direction().y();
    ray.vector[2] = mray.direction().z();

    ray.root = scene->resolve(ray.origin);

    rfRayData rayData;

    (*traceFcn)(ray, rayData);

{'fraction_non_alphanumeric': 0.18479560124312694, 'fraction_numerical': 0.009084389194358116, 'mean_word_length': 4.370988446726573, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 39, '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': '6591776', 'n_tokens_mistral': 1647, 'n_tokens_neox': 1594, 'n_words': 289}