Skip to content

Commit

Permalink
add: doxygen documentation headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jabolol committed May 8, 2024
1 parent 1b5bc06 commit d35db6a
Show file tree
Hide file tree
Showing 30 changed files with 1,382 additions and 4 deletions.
33 changes: 30 additions & 3 deletions sources/config/Factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
#include "textures/Noise.hpp"
#include "textures/SolidColor.hpp"

/**
* @brief Factory map for textures.
*
* This map is used to create textures based on their name.
* The key is the name of the texture and the value is a lambda function that
* creates the texture.
*/
Raytracer::Config::FactoryMap<Raytracer::Interfaces::ITexture,
Raytracer::Config::ConfigTextures>
Raytracer::Config::Factory::textures = {
Expand Down Expand Up @@ -85,6 +92,13 @@ Raytracer::Config::FactoryMap<Raytracer::Interfaces::ITexture,
},
};

/**
* @brief Factory map for effects.
*
* This map is used to create effects based on their name.
* The key is the name of the effect and the value is a lambda function that
* creates the effect.
*/
Raytracer::Config::FactoryMap<Raytracer::Interfaces::IHittable,
Raytracer::Config::ConfigEffects>
Raytracer::Config::Factory::effects = {
Expand Down Expand Up @@ -153,8 +167,16 @@ Raytracer::Config::FactoryMap<Raytracer::Interfaces::IHittable,

return effect;
},
}};
},
};

/**
* @brief Factory map for materials.
*
* This map is used to create materials based on their name.
* The key is the name of the material and the value is a lambda function that
* creates the material.
*/
Raytracer::Config::FactoryMap<Raytracer::Interfaces::IMaterial,
Raytracer::Config::ConfigMaterials>
Raytracer::Config::Factory::materials = {
Expand Down Expand Up @@ -233,7 +255,6 @@ Raytracer::Config::FactoryMap<Raytracer::Interfaces::IMaterial,
std::make_shared<Raytracer::Materials::Isotropic>(
args->color());
} else {
// FIXME: No matching constructor for this call
material =
std::make_shared<Raytracer::Materials::Isotropic>(
args->texture());
Expand All @@ -256,6 +277,13 @@ Raytracer::Config::FactoryMap<Raytracer::Interfaces::IMaterial,
},
};

/**
* @brief Factory map for shapes.
*
* This map is used to create shapes based on their name.
* The key is the name of the shape and the value is a lambda function that
* creates the shape.
*/
Raytracer::Config::FactoryMap<Raytracer::Interfaces::IHittable,
Raytracer::Config::ConfigShapes>
Raytracer::Config::Factory::shapes = {
Expand Down Expand Up @@ -321,7 +349,6 @@ Raytracer::Config::FactoryMap<Raytracer::Interfaces::IHittable,
args->center(), args->centerTwo(), args->radius(),
args->material());
} else {
// FIXME: No matching constructor for this call
shape = std::make_shared<Raytracer::Shapes::Sphere>(
args->center(), args->radius(), args->material());
}
Expand Down
91 changes: 91 additions & 0 deletions sources/core/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
#include "utils/Color.hpp"
#include "utils/VecN.hpp"

/**
* @brief Set up the camera with the given parameters.
*
* This function calculates the image height based on the aspect ratio and the
* image width. It also calculates the viewport height and width based on the
* vertical field of view and the focus distance. The pixel sample scale is
* calculated based on the number of samples per pixel. The camera's center
* is set to the look from point. The camera's u, v, and w vectors are
* calculated based on the look from, look at, and v up points. The viewport
* u and v vectors are calculated based on the viewport width and height and
* the u and v vectors. The pixel delta u and v vectors are calculated based
* on the viewport u and v vectors and the image width and height. The pixel
* zero location is calculated based on the viewport upper left corner and
* the pixel delta u and v vectors. The defocus disk u and v vectors are
* calculated based on the defocus angle and the u and v vectors.
*
* @return void
*/
void Raytracer::Core::Camera::setup()
{
_imageHeight = static_cast<int>(_imageWidth / _aspectRatio);
Expand Down Expand Up @@ -38,6 +56,17 @@ void Raytracer::Core::Camera::setup()
_defocusDiskV = _v * defocusRadius;
}

/**
* @brief Render the scene with the given camera.
*
* This function sets up the camera and prints the PPM header. It then loops
* through each pixel in the image and calculates the pixel color based on the
* number of samples per pixel. The pixel color is then written to the output
* stream.
*
* @param world The world to render.
* @return void
*/
void Raytracer::Core::Camera::render(const Interfaces::IHittable &world)
{
setup();
Expand All @@ -61,6 +90,19 @@ void Raytracer::Core::Camera::render(const Interfaces::IHittable &world)
}
}

/**
* @brief Get the ray for the given pixel.
*
* This function calculates the sample location based on the pixel location
* and the pixel delta u and v vectors. The origin is set to the center of the
* camera if the defocus angle is less than or equal to 0. Otherwise, the
* origin is set to a point on the defocus disk. The direction is set to the
* sample location minus the origin. The time is set to a random double.
*
* @param i The x coordinate of the pixel.
* @param j The y coordinate of the pixel.
* @return The ray for the given pixel.
*/
Raytracer::Core::Ray Raytracer::Core::Camera::getRay(double i, double j) const
{
Utils::Vec3 offset = sampleSquare();
Expand All @@ -75,24 +117,62 @@ Raytracer::Core::Ray Raytracer::Core::Camera::getRay(double i, double j) const
return Ray(origin, direction, time);
}

/**
* @brief Sample a square.
*
* This function returns a random point in a square centered at the origin
* with a side length of 1.
*
* @return A random point in a square.
*/
Raytracer::Utils::Vec3 Raytracer::Core::Camera::sampleSquare() const
{
return Utils::Vec3(
Utils::randomDouble() - 0.5, Utils::randomDouble() - 0.5, 0);
}

/**
* @brief Sample a disk.
*
* This function returns a random point in a disk centered at the origin with
* a radius of 1.
*
* @param radius The radius of the disk.
* @return A random point in a disk.
*/
Raytracer::Utils::Vec3 Raytracer::Core::Camera::sampleDisk(double radius) const
{
return radius * Utils::randomInUnitDisk<double, 3>();
}

/**
* @brief Sample the defocus disk.
*
* This function returns a random point in the defocus disk.
*
* @return A random point in the defocus disk.
*/
Raytracer::Utils::Vec3 Raytracer::Core::Camera::sampleDefocusDisk() const
{
Utils::Vec3 p = Utils::randomInUnitDisk<double, 3>();

return _center + (p.x() * _defocusDiskU) + (p.y() * _defocusDiskV);
}

/**
* @brief Get the color of the ray.
*
* This function returns the color of the ray based on the depth and the world.
* If the depth is less than or equal to 0, the function returns black. If the
* ray does not hit anything in the world, the function returns the background
* color. If the ray scatters, the function returns the emission color plus the
* scatter color.
*
* @param ray The ray to get the color of.
* @param depth The depth of the ray.
* @param world The world to get the color from.
* @return The color of the ray.
*/
Raytracer::Utils::Color Raytracer::Core::Camera::rayColor(
const Ray ray, int depth, const Interfaces::IHittable &world) const
{
Expand Down Expand Up @@ -122,6 +202,17 @@ Raytracer::Utils::Color Raytracer::Core::Camera::rayColor(
return emissionColor + scatterColor;
}

/**
* @brief Print the progress of the rendering.
*
* This function prints the progress of the rendering to the standard error
* stream. The progress is printed as a percentage and the time elapsed is
* printed in seconds.
*
* @param start The start time of the rendering.
* @param j The y coordinate of the pixel.
* @return void
*/
void Raytracer::Core::Camera::progress(
const std::chrono::steady_clock::time_point &start, int j) const
{
Expand Down
13 changes: 13 additions & 0 deletions sources/core/Payload.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#include "core/Payload.hpp"

/**
* @brief Set the face normal based on the ray and the outward normal.
*
* This function sets the face normal based on the ray and the outward normal.
* If the ray is outside the object, the face normal is the outward normal. If
* the ray is inside the object, the face normal is the negative of the outward
* normal.
*
* @param ray The ray to set the face normal from.
* @param outwardNormal The outward normal to set the face normal from.
*
* @return void
*/
void Raytracer::Core::Payload::setFaceNormal(
const Core::Ray &ray, const Utils::Vec3 &outwardNormal)
{
Expand Down
19 changes: 19 additions & 0 deletions sources/core/Ray.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
#include "core/Ray.hpp"

/**
* @brief Construct a new Ray object.
*
* This function constructs a new Ray object with the given origin, direction,
* and time.
*
* @param origin The origin of the ray.
* @param direction The direction of the ray.
* @param time The time of the ray.
*
* @return A new Ray object.
*/
Raytracer::Core::Ray::Ray(const Raytracer::Utils::Point3 &origin,
const Raytracer::Utils::Vec3 &direction, double time)
: _origin(origin), _direction(direction), _time(time)
{
}

/**
* @brief Get the origin of the ray.
*
* This function returns the origin of the ray.
*
* @return The origin of the ray.
*/
Raytracer::Utils::Point3 Raytracer::Core::Ray::at(double t) const
{
return _origin + t * _direction;
Expand Down
53 changes: 53 additions & 0 deletions sources/core/Scene.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,67 @@
#include "core/Scene.hpp"

/**
* @brief Construct a new Scene object.
*
* This function constructs a new Scene object with the given object.
* The object is added to the list of objects in the scene.
* The bounding box of the scene is updated with the bounding box of the
* object.
*
* @param object The object to add to the scene.
*
* @return A new Scene object.
*/
Raytracer::Core::Scene::Scene(std::shared_ptr<Interfaces::IHittable> object)
{
add(object);
}

/**
* @brief Clear the scene.
*
* This function clears the list of objects in the scene.
* The bounding box of the scene is reset to the default value.
* The scene is empty after this function is called.
*
* @return void
*/
void Raytracer::Core::Scene::clear()
{
_objects.clear();
}

/**
* @brief Add an object to the scene.
*
* This function adds an object to the list of objects in the scene.
* The bounding box of the scene is updated with the bounding box of the
* object.
*
* @param object The object to add to the scene.
*
* @return void
*/
void Raytracer::Core::Scene::add(std::shared_ptr<Interfaces::IHittable> object)
{
_objects.push_back(object);
_bbox = Utils::AxisAlignedBBox(_bbox, object->boundingBox());
}

/**
* @brief Check if the ray hits anything in the scene.
*
* This function checks if the ray hits anything in the scene.
* The function returns true if the ray hits anything in the scene.
* The function returns false if the ray does not hit anything in the scene.
* The function updates the payload with the hit information.
*
* @param ray The ray to check for hits.
* @param interval The interval to check for hits.
* @param payload The payload to update with the hit information.
*
* @return true if the ray hits anything in the scene, false otherwise.
*/
bool Raytracer::Core::Scene::hit(
const Ray &ray, Utils::Interval interval, Payload &payload) const
{
Expand All @@ -35,6 +81,13 @@ bool Raytracer::Core::Scene::hit(
return hitAnything;
}

/**
* @brief Get the bounding box of the scene.
*
* This function returns the bounding box of the scene.
*
* @return The bounding box of the scene.
*/
Raytracer::Utils::AxisAlignedBBox Raytracer::Core::Scene::boundingBox() const
{
return _bbox;
Expand Down
Loading

0 comments on commit d35db6a

Please sign in to comment.