raytracer
Parallel Ray Tracer written from scratch (no graphics API).
Loading...
Searching...
No Matches
raytracer::common Namespace Reference

Classes

class  Image
struct  Complex
struct  Point
struct  Vec3

Functions

double diff_images (const Image &img1, const Image &img2, unsigned short downsampling_factor=4)
void reportException (const std::exception &err) noexcept
void reportUnknownException () noexcept
 NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE (Point, x, y)
bool set_seed (unsigned new_seed)
bool remove_seed ()
Vec3 random_unit ()
std::mt19937 & get_generator ()
std::ostream & get_nullout ()
void clear_current_row (std::ostream &out)
void display_percentage (std::ostream &out, int current, int total, const std::string &qty, int width=20)
std::ostream & operator<< (std::ostream &os, Vec3 const &v)
std::byte doubleToColorByte (const double value, const int channels)
void write_n_bytes (std::vector< std::byte > &vec, const int n, const int data)

Variables

constexpr unsigned TEST_SEED = 123

Function Documentation

◆ clear_current_row()

void raytracer::common::clear_current_row ( std::ostream & out)

Writes an ANSI sequence to clear the current row from a terminal display.

Parameters
outThe std::ostream to write to.
Here is the caller graph for this function:

◆ diff_images()

double raytracer::common::diff_images ( const Image & img1,
const Image & img2,
unsigned short downsampling_factor = 4 )

Computes the average distance between the color vectors of each pixel in two images.

Exceptions
std::invalid_argumentIf the images don't have the same width and height, or if the factor is zero.
Parameters
img1The first image.
img2The second image.
downsampling_factorHow many pixels a side of the box has. Four means a 4x4 box filter is applied (colors are averaged over each 4x4 area).
Returns
A value between 0 and sqrt(3), equal to the average distance between the color vectors of each pixel in the two images.
Here is the call graph for this function:

◆ display_percentage()

void raytracer::common::display_percentage ( std::ostream & out,
int current,
int total,
const std::string & qty,
int width = 20 )

Write a progress bar to the terminal.

Parameters
outThe std::ostream to write to.
currentThe number of completed tasks.
totalThe total amount of tasks to complete.
qtyWhat the percentage is measured for (used as a label).
widthThe width of the progress bar in characters.
Here is the caller graph for this function:

◆ doubleToColorByte()

std::byte raytracer::common::doubleToColorByte ( const double value,
const int channels )
Here is the caller graph for this function:

◆ get_generator()

std::mt19937 & raytracer::common::get_generator ( )

Returns a reference to the thread-local RNG.

Returns
A reference to the thread-local RNG.
Here is the caller graph for this function:

◆ get_nullout()

std::ostream & raytracer::common::get_nullout ( )
inline

Returns a reference to a std::ostream that does nothing. Used for tests.

Returns
A reference to a std::ostream that does nothing.

◆ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE()

raytracer::common::NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE ( Point ,
x ,
y  )

◆ operator<<()

std::ostream & raytracer::common::operator<< ( std::ostream & os,
Vec3 const & v )
inline

◆ random_unit()

Vec3 raytracer::common::random_unit ( )

Returns a random 3D vector of length 1.

Returns
A random 3D vector of length 1.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_seed()

bool raytracer::common::remove_seed ( )

Resets the global seed so the generator will use a random device instead, if the seed is not frozen.

Returns
True if the generator has not been created yet (the seed is not frozen), false otherwise.

◆ reportException()

void raytracer::common::reportException ( const std::exception & err)
noexcept

Logs that an exception occurred.

Parameters
errThe exception to log.
Here is the caller graph for this function:

◆ reportUnknownException()

void raytracer::common::reportUnknownException ( )
noexcept

Logs that an unknown exception occurred.

Here is the caller graph for this function:

◆ set_seed()

bool raytracer::common::set_seed ( unsigned new_seed)

Sets the global RNG seed to the new value, if it is not frozen.

Parameters
new_seedThe new global seed.
Returns
True if the generator has not been created yet (the seed is not frozen), false otherwise.

◆ write_n_bytes()

void raytracer::common::write_n_bytes ( std::vector< std::byte > & vec,
const int n,
const int data )
Here is the caller graph for this function:

Variable Documentation

◆ TEST_SEED

unsigned raytracer::common::TEST_SEED = 123
constexpr