Euclid
Geometry Processing and Shape Analysis in C++
Euclid::RayTracer Class Reference

A simple ray tracer. More...

#include <RayTracer.h>

Public Member Functions

 RayTracer (int threads=0)
 Create a ray tracer. More...
 
void attach_geometry_buffers (const std::vector< float > &positions, const std::vector< unsigned > &indices)
 Attach shared geoemtry buffers to the ray tracer. More...
 
void attach_color_buffer (const std::vector< float > *colors, bool vertex_color=false)
 Attach a shared color buffer to the ray tracer. More...
 
void attach_face_mask_buffer (const std::vector< uint8_t > *mask)
 Attach a face maks buffer to the ray tracer. More...
 
void release_buffers ()
 Release all associated buffers.
 
void set_material (const Material &material)
 Change the material of the model.
 
void set_background (const Eigen::Ref< const Eigen::Array3f > &color)
 Change the color of background.
 
void set_background (float r, float g, float b)
 Change the color of background.
 
void enable_light (bool on)
 Enable or diable lighting.
 
void render_shaded (std::vector< uint8_t > &pixels, const RayCamera &camera, int width, int height, bool interleaved=true)
 Render the mesh into a shaded image. More...
 
void render_shaded (std::vector< uint8_t > &pixels, const RayCamera &camera, int width, int height, int samples, bool interleaved=true)
 Render the mesh into a shaded image. More...
 
void render_depth (std::vector< uint8_t > &pixels, const RayCamera &camera, int width, int height)
 Render the mesh into a depth image. More...
 
void render_depth (std::vector< float > &values, const RayCamera &camera, int width, int height)
 Render the mesh into a depth image. More...
 
void render_silhouette (std::vector< uint8_t > &pixels, const RayCamera &camera, int width, int height)
 Render the mesh into a silhouette image. More...
 
void render_index (std::vector< uint8_t > &pixels, const RayCamera &camera, int width, int height, bool interleaved=true)
 Render the mesh based on face index. More...
 
void render_index (std::vector< uint32_t > &indices, const RayCamera &camera, int width, int height)
 Render the mesh based on face index. More...
 

Detailed Description

This ray tracer could render several types of images of a triangle mesh.

Constructor & Destructor Documentation

Euclid::RayTracer::RayTracer ( int  threads = 0)
inlineexplicit
Parameters
threadsSet to 0 to use number of hardware threads.

Member Function Documentation

void Euclid::RayTracer::attach_color_buffer ( const std::vector< float > *  colors,
bool  vertex_color = false 
)
inline

Attach a color buffer storing either per-face colors or per-vertex colors. This buffer is mapped directly by the RayTracer so their lifetime should outlive the end of rendering. Attach another buffer will automatically release the previously attached one.

Note

The user is responsible of padding the positions buffer with one more float for Embree's SSE instructions to work correctly, if you are in vertex color mode. Otherwise the padding will not be necessary.

Parameters
colorsA color array storing [r,g,b,r,g,b...] values of each elements. The values range in [0 1]. Set colors to nullptr to disable color buffering and fall back to the material.
vertex_colorTrue for vertex color and false for face color. Default to false.
void Euclid::RayTracer::attach_face_mask_buffer ( const std::vector< uint8_t > *  mask)
inline

This mask is used to filter out specified faces.

Parameters
maskThe size of the array pointed by mask should be equal to the number of faces of the attached geometry. Set (*mask)[i] to 1 to enable face i in intersection, otherwise it will be ignored. Set mask to nullptr to disable masking.
void Euclid::RayTracer::attach_geometry_buffers ( const std::vector< float > &  positions,
const std::vector< unsigned > &  indices 
)
inline

Attach both the positions and indices buffer. These buffers are mapped directly by the RayTracer so their lifetime should outlive the end of rendering. This class can only render one mesh at a time, so attaching another geometry will automatically release the previously attached geometry and all associated buffers.

Note

The user is responsible of padding the positions buffer with one more float for Embree's SSE instructions to work correctly.

Parameters
positionsThe geometry's positions buffer.
indicesThe geometry's indices buffer.
void Euclid::RayTracer::render_depth ( std::vector< uint8_t > &  pixels,
const RayCamera camera,
int  width,
int  height 
)
inline

The minimum depth value is mapped to 255 in image, and the maximum depth value is mapped to 0.

Parameters
pixelsOutput pixels.
cameraCamera.
widthImage width.
heightImage height.
void Euclid::RayTracer::render_depth ( std::vector< float > &  values,
const RayCamera camera,
int  width,
int  height 
)
inline

The depth values are returned as they are, while the depth of the background is set to negative.

Parameters
valuesOutput depth values.
cameraCamera.
widthImage width.
heightImage height.
void Euclid::RayTracer::render_index ( std::vector< uint8_t > &  pixels,
const RayCamera camera,
int  width,
int  height,
bool  interleaved = true 
)
inline

Color each face base on its index, following

face_index = r + g << 8 + b << 16 - 1;

The background is set to 0, and the primitive index starts from 1. Due to bit width limitations, only 2^24 number of faces could be uniquely colored.

Parameters
pixelsOutput pixels.
cameraCamera.
widthImage width.
heightImage height.
interleavedIf true, pixels are stored like [RGBRGBRGB...], otherwise pixels are stored like [RRR...GGG...BBB...].
void Euclid::RayTracer::render_index ( std::vector< uint32_t > &  indices,
const RayCamera camera,
int  width,
int  height 
)
inline

Each index is stored as a uint32_t value. The background is set to 0, and the primitive index starts from 1. Due to bit width limitations, the maximum number of indices supported is 2^32.

Parameters
indicesThe face indices of each pixel.
cameraCamera.
widthImage width.
heightImage height.
void Euclid::RayTracer::render_shaded ( std::vector< uint8_t > &  pixels,
const RayCamera camera,
int  width,
int  height,
bool  interleaved = true 
)
inline

This function renders the mesh with simple lambertian shading, using a point light located at the camera position.

Parameters
pixelsOutput pixels
cameraCamera.
widthImage width.
heightImage height.
interleavedIf true, pixels are stored like [RGBRGBRGB...], otherwise pixels are stored like [RRR...GGG...BBB...].
void Euclid::RayTracer::render_shaded ( std::vector< uint8_t > &  pixels,
const RayCamera camera,
int  width,
int  height,
int  samples,
bool  interleaved = true 
)
inline

This function renders the mesh with simple lambertian shading, using a point light located at the camera position. Random multisampling is enabled.

Parameters
pixelsOutput pixels
cameraCamera.
widthImage width.
heightImage height.
samplesNumber of samples per pixel.
interleavedIf true, pixels are stored like [RGBRGBRGB...], otherwise pixels are stored like [RRR...GGG...BBB...].
void Euclid::RayTracer::render_silhouette ( std::vector< uint8_t > &  pixels,
const RayCamera camera,
int  width,
int  height 
)
inline
Parameters
pixelsOutput pixels.
cameraCamera.
widthImage width.
heightImage height.

The documentation for this class was generated from the following files: