From d35db6a1d52f8a736d30ef19cd5e72082f1ecda7 Mon Sep 17 00:00:00 2001 From: Javier R Date: Wed, 8 May 2024 21:07:50 +0200 Subject: [PATCH] add: `doxygen` documentation headers --- sources/config/Factory.cpp | 33 ++++++++- sources/core/Camera.cpp | 91 ++++++++++++++++++++++++ sources/core/Payload.cpp | 13 ++++ sources/core/Ray.cpp | 19 +++++ sources/core/Scene.cpp | 53 ++++++++++++++ sources/effects/RotateX.cpp | 33 +++++++++ sources/effects/RotateY.cpp | 33 +++++++++ sources/effects/RotateZ.cpp | 30 ++++++++ sources/effects/Smoke.cpp | 48 +++++++++++++ sources/effects/Translate.cpp | 32 +++++++++ sources/materials/Dielectric.cpp | 58 +++++++++++++++ sources/materials/DiffuseLight.cpp | 46 ++++++++++++ sources/materials/Isotropic.cpp | 44 ++++++++++++ sources/materials/Lambertian.cpp | 46 ++++++++++++ sources/materials/Metal.cpp | 37 ++++++++++ sources/shapes/Cone.cpp | 34 +++++++++ sources/shapes/Cylinder.cpp | 34 +++++++++ sources/shapes/Plane.cpp | 33 +++++++++ sources/shapes/Quad.cpp | 65 +++++++++++++++++ sources/shapes/Sphere.cpp | 65 +++++++++++++++++ sources/textures/Checker.cpp | 36 ++++++++++ sources/textures/Image.cpp | 21 ++++++ sources/textures/Noise.cpp | 22 ++++++ sources/textures/SolidColor.cpp | 35 +++++++++ sources/utils/AxisAlignedBBox.cpp | 110 +++++++++++++++++++++++++++++ sources/utils/BVHNode.cpp | 103 ++++++++++++++++++++++++++- sources/utils/Color.cpp | 17 +++++ sources/utils/ImageHelper.cpp | 32 +++++++++ sources/utils/Interval.cpp | 103 +++++++++++++++++++++++++++ sources/utils/Perlin.cpp | 60 ++++++++++++++++ 30 files changed, 1382 insertions(+), 4 deletions(-) diff --git a/sources/config/Factory.cpp b/sources/config/Factory.cpp index c99fd33..e0027da 100644 --- a/sources/config/Factory.cpp +++ b/sources/config/Factory.cpp @@ -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::Config::Factory::textures = { @@ -85,6 +92,13 @@ Raytracer::Config::FactoryMap Raytracer::Config::Factory::effects = { @@ -153,8 +167,16 @@ Raytracer::Config::FactoryMap Raytracer::Config::Factory::materials = { @@ -233,7 +255,6 @@ Raytracer::Config::FactoryMap( args->color()); } else { - // FIXME: No matching constructor for this call material = std::make_shared( args->texture()); @@ -256,6 +277,13 @@ Raytracer::Config::FactoryMap Raytracer::Config::Factory::shapes = { @@ -321,7 +349,6 @@ Raytracer::Config::FactoryMapcenter(), args->centerTwo(), args->radius(), args->material()); } else { - // FIXME: No matching constructor for this call shape = std::make_shared( args->center(), args->radius(), args->material()); } diff --git a/sources/core/Camera.cpp b/sources/core/Camera.cpp index ccbe71e..fb1228d 100644 --- a/sources/core/Camera.cpp +++ b/sources/core/Camera.cpp @@ -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(_imageWidth / _aspectRatio); @@ -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(); @@ -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(); @@ -75,17 +117,41 @@ 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(); } +/** + * @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(); @@ -93,6 +159,20 @@ Raytracer::Utils::Vec3 Raytracer::Core::Camera::sampleDefocusDisk() const 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 { @@ -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 { diff --git a/sources/core/Payload.cpp b/sources/core/Payload.cpp index 83719d3..f2c6edc 100644 --- a/sources/core/Payload.cpp +++ b/sources/core/Payload.cpp @@ -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) { diff --git a/sources/core/Ray.cpp b/sources/core/Ray.cpp index 4940f6b..f9cbd7a 100644 --- a/sources/core/Ray.cpp +++ b/sources/core/Ray.cpp @@ -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; diff --git a/sources/core/Scene.cpp b/sources/core/Scene.cpp index 326f5f6..0590dc2 100644 --- a/sources/core/Scene.cpp +++ b/sources/core/Scene.cpp @@ -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 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 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 { @@ -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; diff --git a/sources/effects/RotateX.cpp b/sources/effects/RotateX.cpp index 46919e2..eeab197 100644 --- a/sources/effects/RotateX.cpp +++ b/sources/effects/RotateX.cpp @@ -1,5 +1,17 @@ #include "effects/RotateX.hpp" +/** + * @brief Construct a new RotateX object. + * + * This function constructs a new RotateX object with the given object and + * angle. The object is rotated around the x-axis by the given angle. The + * bounding box of the object is updated with the rotated bounding box. + * + * @param object The object to rotate. + * @param angle The angle to rotate the object by. + * + * @return A new RotateX object. + */ Raytracer::Effects::RotateX::RotateX( std::shared_ptr object, double angle) : _object(object) @@ -36,6 +48,20 @@ Raytracer::Effects::RotateX::RotateX( _bbox = Utils::AxisAlignedBBox(min, max); } +/** + * @brief Check if the ray hits the rotated object. + * + * This function checks if the ray hits the rotated object. The function + * returns true if the ray hits the rotated object. The function returns false + * if the ray does not hit the rotated object. 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 the rotated object, false otherwise. + */ bool Raytracer::Effects::RotateX::hit(const Core::Ray &ray, Utils::Interval interval, Core::Payload &payload) const { @@ -74,6 +100,13 @@ bool Raytracer::Effects::RotateX::hit(const Core::Ray &ray, return true; } +/** + * @brief Get the bounding box of the rotated object. + * + * This function returns the bounding box of the rotated object. + * + * @return The bounding box of the rotated object. + */ Raytracer::Utils::AxisAlignedBBox Raytracer::Effects::RotateX::boundingBox() const { diff --git a/sources/effects/RotateY.cpp b/sources/effects/RotateY.cpp index a3cc66c..b6a20af 100644 --- a/sources/effects/RotateY.cpp +++ b/sources/effects/RotateY.cpp @@ -1,5 +1,17 @@ #include "effects/RotateY.hpp" +/** + * @brief Construct a new RotateY object. + * + * This function constructs a new RotateY object with the given object and + * angle. The object is rotated around the y-axis by the given angle. The + * bounding box of the object is updated with the rotated bounding box. + * + * @param object The object to rotate. + * @param angle The angle to rotate the object by. + * + * @return A new RotateY object. + */ Raytracer::Effects::RotateY::RotateY( std::shared_ptr object, double angle) : _object(object) @@ -36,6 +48,20 @@ Raytracer::Effects::RotateY::RotateY( _bbox = Utils::AxisAlignedBBox(min, max); } +/** + * @brief Check if the ray hits the rotated object. + * + * This function checks if the ray hits the rotated object. The function + * returns true if the ray hits the rotated object. The function returns false + * if the ray does not hit the rotated object. 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 the rotated object, false otherwise. + */ bool Raytracer::Effects::RotateY::hit(const Core::Ray &ray, Utils::Interval interval, Core::Payload &payload) const { @@ -74,6 +100,13 @@ bool Raytracer::Effects::RotateY::hit(const Core::Ray &ray, return true; } +/** + * @brief Get the bounding box of the rotated object. + * + * This function returns the bounding box of the rotated object. + * + * @return The bounding box of the rotated object. + */ Raytracer::Utils::AxisAlignedBBox Raytracer::Effects::RotateY::boundingBox() const { diff --git a/sources/effects/RotateZ.cpp b/sources/effects/RotateZ.cpp index 3642e94..189bb40 100644 --- a/sources/effects/RotateZ.cpp +++ b/sources/effects/RotateZ.cpp @@ -1,5 +1,17 @@ #include "effects/RotateZ.hpp" +/** + * @brief Construct a new RotateZ object. + * + * This function constructs a new RotateZ object with the given object and + * angle. The object is rotated around the z-axis by the given angle. The + * bounding box of the object is updated with the rotated bounding box. + * + * @param object The object to rotate. + * @param angle The angle to rotate the object by. + * + * @return A new RotateZ object. + */ Raytracer::Effects::RotateZ::RotateZ( std::shared_ptr object, double angle) : _object(object) @@ -36,6 +48,17 @@ Raytracer::Effects::RotateZ::RotateZ( _bbox = Utils::AxisAlignedBBox(min, max); } +/** + * @brief Check if the ray hits the rotated object. + * + * This function checks if the ray hits the rotated object. The function + * returns true if the ray hits the rotated object. The function returns false + * if the ray does not hit the rotated object. 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. + */ bool Raytracer::Effects::RotateZ::hit(const Core::Ray &ray, Utils::Interval interval, Core::Payload &payload) const { @@ -74,6 +97,13 @@ bool Raytracer::Effects::RotateZ::hit(const Core::Ray &ray, return true; } +/** + * @brief Get the bounding box of the rotated object. + * + * This function returns the bounding box of the rotated object. + * + * @return The bounding box of the rotated object. + */ Raytracer::Utils::AxisAlignedBBox Raytracer::Effects::RotateZ::boundingBox() const { diff --git a/sources/effects/Smoke.cpp b/sources/effects/Smoke.cpp index 2a17da5..fd432cc 100644 --- a/sources/effects/Smoke.cpp +++ b/sources/effects/Smoke.cpp @@ -1,6 +1,20 @@ #include "effects/Smoke.hpp" #include "materials/Isotropic.hpp" +/** + * @brief Construct a new Smoke object. + * + * This function constructs a new Smoke object with the given boundary, + * density, and texture. The smoke is created within the boundary with the + * given density and texture. The phase function of the smoke is set to + * isotropic with the given texture. + * + * @param boundary The boundary to create the smoke within. + * @param density The density of the smoke. + * @param texture The texture of the smoke. + * + * @return A new Smoke object. + */ Raytracer::Effects::Smoke::Smoke( std::shared_ptr boundary, double density, std::shared_ptr texture) @@ -10,6 +24,20 @@ Raytracer::Effects::Smoke::Smoke( { } +/** + * @brief Construct a new Smoke object. + * + * This function constructs a new Smoke object with the given boundary, + * density, and albedo. The smoke is created within the boundary with the + * given density and albedo. The phase function of the smoke is set to + * isotropic with the given albedo. + * + * @param boundary The boundary to create the smoke within. + * @param density The density of the smoke. + * @param albedo The albedo of the smoke. + * + * @return A new Smoke object. + */ Raytracer::Effects::Smoke::Smoke( std::shared_ptr boundary, double density, const Utils::Color &albedo) @@ -19,6 +47,19 @@ Raytracer::Effects::Smoke::Smoke( { } +/** + * @brief Check if the ray hits the smoke. + * + * This function checks if the ray hits the smoke. The function returns true if + * the ray hits the smoke. The function returns false if the ray does not hit + * the smoke. 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 the smoke, false otherwise. + */ bool Raytracer::Effects::Smoke::hit(const Core::Ray &ray, Utils::Interval interval, Core::Payload &payload) const { @@ -65,6 +106,13 @@ bool Raytracer::Effects::Smoke::hit(const Core::Ray &ray, return true; } +/** + * @brief Get the bounding box of the smoke. + * + * This function returns the bounding box of the smoke. + * + * @return The bounding box of the smoke. + */ Raytracer::Utils::AxisAlignedBBox Raytracer::Effects::Smoke::boundingBox() const { diff --git a/sources/effects/Translate.cpp b/sources/effects/Translate.cpp index b306fca..1310b03 100644 --- a/sources/effects/Translate.cpp +++ b/sources/effects/Translate.cpp @@ -1,5 +1,16 @@ #include "effects/Translate.hpp" +/** + * @brief Construct a new Translate object. + * + * This function constructs a new Translate object with the given object and + * offset. The object is translated by the given offset. + * + * @param object The object to translate. + * @param offset The offset to translate the object by. + * + * @return A new Translate object. + */ Raytracer::Effects::Translate::Translate( std::shared_ptr object, const Utils::Vec3 &offset) : _object(object), _offset(offset) @@ -7,6 +18,20 @@ Raytracer::Effects::Translate::Translate( _bbox = object->boundingBox() + offset; } +/** + * @brief Check if the ray hits the translated object. + * + * This function checks if the ray hits the translated object. The function + * returns true if the ray hits the translated object. The function returns + * false if the ray does not hit the translated object. 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 the translated object, false otherwise. + */ bool Raytracer::Effects::Translate::hit(const Core::Ray &ray, Utils::Interval interval, Core::Payload &payload) const { @@ -22,6 +47,13 @@ bool Raytracer::Effects::Translate::hit(const Core::Ray &ray, return true; } +/** + * @brief Get the bounding box of the translated object. + * + * This function returns the bounding box of the translated object. + * + * @return The bounding box of the translated object. + */ Raytracer::Utils::AxisAlignedBBox Raytracer::Effects::Translate::boundingBox() const { diff --git a/sources/materials/Dielectric.cpp b/sources/materials/Dielectric.cpp index 60fed99..5f99e6e 100644 --- a/sources/materials/Dielectric.cpp +++ b/sources/materials/Dielectric.cpp @@ -3,17 +3,52 @@ #include "utils/Color.hpp" #include "utils/VecN.hpp" +/** + * @brief Construct a new Dielectric object. + * + * This function constructs a new Dielectric object with the given refraction + * index. + * + * @param refractionIndex The refraction index of the dielectric. + * + * @return A new Dielectric object. + */ Raytracer::Materials::Dielectric::Dielectric(double refractionIndex) : _refractionIndex(refractionIndex) { } +/** + * @brief Construct a new Dielectric object. + * + * This function constructs a new Dielectric object with the given refraction + * index and albedo. + * + * @param refractionIndex The refraction index of the dielectric. + * @param albedo The albedo of the dielectric. + * + * @return A new Dielectric object. + */ Raytracer::Materials::Dielectric::Dielectric( double refractionIndex, const Utils::Color &albedo) : _refractionIndex(refractionIndex), _albedo(albedo) { } +/** + * @brief Scatter the ray with the dielectric material. + * + * This function scatters the ray with the dielectric material. The function + * returns true if the ray is scattered. The function returns false if the ray + * is not scattered. The function updates the attenuation and scattered ray. + * + * @param ray The ray to scatter. + * @param payload The payload of the ray. + * @param attenuation The attenuation of the ray. + * @param scattered The scattered ray. + * + * @return true if the ray is scattered, false otherwise. + */ bool Raytracer::Materials::Dielectric::scatter(const Core::Ray &ray, const Core::Payload &payload, Utils::Color &attenuation, Core::Ray &scattered) const @@ -40,6 +75,17 @@ bool Raytracer::Materials::Dielectric::scatter(const Core::Ray &ray, return true; } +/** + * @brief Calculate the reflectance of the dielectric material. + * + * This function calculates the reflectance of the dielectric material. The + * function returns the reflectance of the dielectric material. + * + * @param cosine The cosine of the angle. + * @param index The refraction index. + * + * @return The reflectance of the dielectric material. + */ double Raytracer::Materials::Dielectric::reflectance( double cosine, double index) { @@ -49,6 +95,18 @@ double Raytracer::Materials::Dielectric::reflectance( return r0 + (1 - r0) * std::pow((1 - cosine), 5); } +/** + * @brief Calculate the refracted ray. + * + * This function calculates the refracted ray. The function returns the + * refracted ray. + * + * @param uv The unit vector. + * @param normal The normal vector. + * @param index The refraction index. + * + * @return The refracted ray. + */ Raytracer::Utils::Color Raytracer::Materials::Dielectric::emitted( double u, double v, const Utils::Point3 &point) const { diff --git a/sources/materials/DiffuseLight.cpp b/sources/materials/DiffuseLight.cpp index 6effcd7..6c23b9f 100644 --- a/sources/materials/DiffuseLight.cpp +++ b/sources/materials/DiffuseLight.cpp @@ -1,17 +1,51 @@ #include "materials/DiffuseLight.hpp" #include "textures/SolidColor.hpp" +/** + * @brief Construct a new DiffuseLight object. + * + * This function constructs a new DiffuseLight object with the given texture. + * The diffuse light material emits light with the given texture. + * + * @param texture The texture of the diffuse light. + * + * @return A new DiffuseLight object. + */ Raytracer::Materials::DiffuseLight::DiffuseLight( std::shared_ptr texture) : _texture(texture) { } +/** + * @brief Construct a new DiffuseLight object. + * + * This function constructs a new DiffuseLight object with the given color. The + * diffuse light material emits light with the given color. + * + * @param color The color of the diffuse light. + * + * @return A new DiffuseLight object. + */ Raytracer::Materials::DiffuseLight::DiffuseLight(const Utils::Color &color) : _texture(std::make_shared(color)) { } +/** + * @brief Scatter the ray with the diffuse light material. + * + * This function scatters the ray with the diffuse light material. The function + * returns true if the ray is scattered. The function returns false if the ray + * is not scattered. The function updates the attenuation and scattered ray. + * + * @param ray The ray to scatter. + * @param payload The payload of the ray. + * @param attenuation The attenuation of the ray. + * @param scattered The scattered ray. + * + * @return true if the ray is scattered, false otherwise. + */ bool Raytracer::Materials::DiffuseLight::scatter(const Core::Ray &ray, const Core::Payload &payload, Utils::Color &attenuation, Core::Ray &scattered) const @@ -19,6 +53,18 @@ bool Raytracer::Materials::DiffuseLight::scatter(const Core::Ray &ray, return false; } +/** + * @brief Emitted light of the diffuse light material. + * + * This function returns the emitted light of the diffuse light material. The + * function returns the emitted light of the material at the given point. + * + * @param u The u coordinate of the texture. + * @param v The v coordinate of the texture. + * @param point The point to get the emitted light from. + * + * @return The emitted light of the material. + */ Raytracer::Utils::Color Raytracer::Materials::DiffuseLight::emitted( double u, double v, const Utils::Point3 &point) const { diff --git a/sources/materials/Isotropic.cpp b/sources/materials/Isotropic.cpp index 5c22ba2..1d3f45c 100644 --- a/sources/materials/Isotropic.cpp +++ b/sources/materials/Isotropic.cpp @@ -2,17 +2,49 @@ #include "core/Payload.hpp" #include "textures/SolidColor.hpp" +/** + * @brief Construct a new Isotropic object. + * + * This function constructs a new Isotropic object with the given texture. + * + * @param texture The texture of the isotropic material. + * + * @return A new Isotropic object. + */ Raytracer::Materials::Isotropic::Isotropic( std::shared_ptr texture) : _texture(texture) { } +/** + * @brief Construct a new Isotropic object. + * + * This function constructs a new Isotropic object with the given color. + * + * @param color The color of the isotropic material. + * + * @return A new Isotropic object. + */ Raytracer::Materials::Isotropic::Isotropic(const Utils::Color &color) : _texture(std::make_shared(color)) { } +/** + * @brief Scatter the ray with the isotropic material. + * + * This function scatters the ray with the isotropic material. The function + * returns true if the ray is scattered. The function returns false if the ray + * is not scattered. The function updates the attenuation and scattered ray. + * + * @param ray The ray to scatter. + * @param payload The payload of the ray. + * @param attenuation The attenuation of the ray. + * @param scattered The scattered ray. + * + * @return true if the ray is scattered, false otherwise. + */ bool Raytracer::Materials::Isotropic::scatter(const Core::Ray &ray, const Core::Payload &payload, Utils::Color &attenuation, Core::Ray &scattered) const @@ -23,6 +55,18 @@ bool Raytracer::Materials::Isotropic::scatter(const Core::Ray &ray, return true; } +/** + * @brief Emitted light of the isotropic material. + * + * This function returns the emitted light of the isotropic material. The + * function returns the emitted light of the material at the given point. + * + * @param u The u texture coordinate. + * @param v The v texture coordinate. + * @param point The point to get the emitted light from. + * + * @return The emitted light of the isotropic material. + */ Raytracer::Utils::Color Raytracer::Materials::Isotropic::emitted( double u, double v, const Utils::Point3 &point) const { diff --git a/sources/materials/Lambertian.cpp b/sources/materials/Lambertian.cpp index 3884b5c..245cdaa 100644 --- a/sources/materials/Lambertian.cpp +++ b/sources/materials/Lambertian.cpp @@ -2,17 +2,51 @@ #include "core/Payload.hpp" #include "textures/SolidColor.hpp" +/** + * @brief Construct a new Lambertian object. + * + * This function constructs a new Lambertian object with the given albedo. The + * Lambertian material scatters light with the given albedo. + * + * @param albedo The albedo of the Lambertian material. + * + * @return A new Lambertian object. + */ Raytracer::Materials::Lambertian::Lambertian(const Utils::Color &albedo) : _texture(std::make_shared(albedo)) { } +/** + * @brief Construct a new Lambertian object. + * + * This function constructs a new Lambertian object with the given texture. The + * Lambertian material scatters light with the given texture. + * + * @param texture The texture of the Lambertian material. + * + * @return A new Lambertian object. + */ Raytracer::Materials::Lambertian::Lambertian( std::shared_ptr texture) : _texture(texture) { } +/** + * @brief Scatter the ray with the Lambertian material. + * + * This function scatters the ray with the Lambertian material. The function + * returns true if the ray is scattered. The function returns false if the ray + * is not scattered. The function updates the attenuation and scattered ray. + * + * @param ray The ray to scatter. + * @param payload The payload of the ray. + * @param attenuation The attenuation of the ray. + * @param scattered The scattered ray. + * + * @return true if the ray is scattered, false otherwise. + */ bool Raytracer::Materials::Lambertian::scatter(const Core::Ray &ray, const Core::Payload &payload, Utils::Color &attenuation, Core::Ray &scattered) const @@ -29,6 +63,18 @@ bool Raytracer::Materials::Lambertian::scatter(const Core::Ray &ray, return true; } +/** + * @brief Emitted light of the Lambertian material. + * + * This function returns the emitted light of the Lambertian material. The + * function returns the emitted light of the material at the given point. + * + * @param u The u coordinate of the texture. + * @param v The v coordinate of the texture. + * @param point The point to get the emitted light from. + * + * @return The emitted light of the material. + */ Raytracer::Utils::Color Raytracer::Materials::Lambertian::emitted( double u, double v, const Utils::Point3 &point) const { diff --git a/sources/materials/Metal.cpp b/sources/materials/Metal.cpp index 63fe95c..a30839a 100644 --- a/sources/materials/Metal.cpp +++ b/sources/materials/Metal.cpp @@ -1,11 +1,36 @@ #include "materials/Metal.hpp" #include "core/Payload.hpp" +/** + * @brief Construct a new Metal object. + * + * This function constructs a new Metal object with the given albedo and fuzz. + * The Metal material scatters light with the given albedo and fuzz. + * + * @param albedo The albedo of the Metal material. + * @param fuzz The fuzz of the Metal material. + * + * @return A new Metal object. + */ Raytracer::Materials::Metal::Metal(const Utils::Color &albedo, double fuzz) : _albedo(albedo), _fuzz(fuzz) { } +/** + * @brief Scatter the ray with the Metal material. + * + * This function scatters the ray with the Metal material. The function returns + * true if the ray is scattered. The function returns false if the ray is not + * scattered. The function updates the attenuation and scattered ray. + * + * @param ray The ray to scatter. + * @param payload The payload of the ray. + * @param attenuation The attenuation of the ray. + * @param scattered The scattered ray. + * + * @return true if the ray is scattered, false otherwise. + */ bool Raytracer::Materials::Metal::scatter(const Core::Ray &ray, const Core::Payload &payload, Utils::Color &attenuation, Core::Ray &scattered) const @@ -19,6 +44,18 @@ bool Raytracer::Materials::Metal::scatter(const Core::Ray &ray, return (dot(scattered.direction(), payload.normal()) > 0); } +/** + * @brief Emitted light of the Metal material. + * + * This function returns the emitted light of the Metal material. The function + * returns the emitted light of the material at the given point. + * + * @param u The u coordinate of the texture. + * @param v The v coordinate of the texture. + * @param point The point of intersection. + * + * @return The emitted light of the material. + */ Raytracer::Utils::Color Raytracer::Materials::Metal::emitted( double u, double v, const Utils::Point3 &point) const { diff --git a/sources/shapes/Cone.cpp b/sources/shapes/Cone.cpp index 09bd436..b3fdcf2 100644 --- a/sources/shapes/Cone.cpp +++ b/sources/shapes/Cone.cpp @@ -1,5 +1,19 @@ #include "shapes/Cone.hpp" +/** + * @brief Construct a new Cone object. + * + * This function constructs a new Cone object with the given center, radius, + * height, and material. The cone is centered at the given center with the + * given radius, height, and material. + * + * @param center The center of the cone. + * @param radius The radius of the cone. + * @param height The height of the cone. + * @param material The material of the cone. + * + * @return A new Cone object. + */ Raytracer::Shapes::Cone::Cone(const Utils::Point3 ¢er, double radius, double height, std::shared_ptr material) : _center(center), _radius(radius), _height(height), _material(material) @@ -9,6 +23,19 @@ Raytracer::Shapes::Cone::Cone(const Utils::Point3 ¢er, double radius, _bbox = Utils::AxisAlignedBBox(min, max); } +/** + * @brief Check if the ray hits the cone. + * + * This function checks if the ray hits the cone. The function returns true if + * the ray hits the cone. The function returns false if the ray does not hit + * the cone. 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 the cone, false otherwise. + */ bool Raytracer::Shapes::Cone::hit(const Core::Ray &ray, Utils::Interval interval, Core::Payload &payload) const { @@ -55,6 +82,13 @@ bool Raytracer::Shapes::Cone::hit(const Core::Ray &ray, return true; } +/** + * @brief Get the bounding box of the cone. + * + * This function returns the bounding box of the cone. + * + * @return The bounding box of the cone. + */ Raytracer::Utils::AxisAlignedBBox Raytracer::Shapes::Cone::boundingBox() const { return _bbox; diff --git a/sources/shapes/Cylinder.cpp b/sources/shapes/Cylinder.cpp index 259d237..1608cfc 100644 --- a/sources/shapes/Cylinder.cpp +++ b/sources/shapes/Cylinder.cpp @@ -1,5 +1,19 @@ #include "shapes/Cylinder.hpp" +/** + * @brief Construct a new Cylinder object. + * + * This function constructs a new Cylinder object with the given center, + * radius, height, and material. The cylinder is centered at the given center + * with the given radius, height, and material. + * + * @param center The center of the cylinder. + * @param radius The radius of the cylinder. + * @param height The height of the cylinder. + * @param material The material of the cylinder. + * + * @return A new Cylinder object. + */ Raytracer::Shapes::Cylinder::Cylinder(const Utils::Point3 ¢er, double radius, double height, std::shared_ptr material) @@ -10,6 +24,19 @@ Raytracer::Shapes::Cylinder::Cylinder(const Utils::Point3 ¢er, _center + Utils::Vec3(_radius, _height, _radius)); } +/** + * @brief Check if the ray hits the cylinder. + * + * This function checks if the ray hits the cylinder. The function returns true + * if the ray hits the cylinder. The function returns false if the ray does not + * hit the cylinder. 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 the cylinder, false otherwise. + */ bool Raytracer::Shapes::Cylinder::hit(const Core::Ray &ray, Utils::Interval interval, Core::Payload &payload) const { @@ -58,6 +85,13 @@ bool Raytracer::Shapes::Cylinder::hit(const Core::Ray &ray, return true; } +/** + * @brief Get the bounding box of the cylinder. + * + * This function returns the bounding box of the cylinder. + * + * @return The bounding box of the cylinder. + */ Raytracer::Utils::AxisAlignedBBox Raytracer::Shapes::Cylinder::boundingBox() const { diff --git a/sources/shapes/Plane.cpp b/sources/shapes/Plane.cpp index 9d2cf60..d7316be 100644 --- a/sources/shapes/Plane.cpp +++ b/sources/shapes/Plane.cpp @@ -1,5 +1,18 @@ #include "shapes/Plane.hpp" +/** + * @brief Construct a new Plane object. + * + * This function constructs a new Plane object with the given point, normal, + * and material. The plane is centered at the given point with the given normal + * and material. + * + * @param point The point of the plane. + * @param normal The normal of the plane. + * @param material The material of the plane. + * + * @return A new Plane object. + */ Raytracer::Shapes::Plane::Plane(const Utils::Point3 &point, const Utils::Vec3 &normal, std::shared_ptr material) : _point(point), _normal(normal), _material(material) @@ -7,6 +20,19 @@ Raytracer::Shapes::Plane::Plane(const Utils::Point3 &point, _bbox = Utils::AxisAlignedBBox(_point, _point); } +/** + * @brief Check if the ray hits the plane. + * + * This function checks if the ray hits the plane. The function returns true if + * the ray hits the plane. The function returns false if the ray does not hit + * the plane. 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 the plane, false otherwise. + */ bool Raytracer::Shapes::Plane::hit(const Core::Ray &ray, Utils::Interval interval, Core::Payload &payload) const { @@ -30,6 +56,13 @@ bool Raytracer::Shapes::Plane::hit(const Core::Ray &ray, return true; } +/** + * @brief Get the bounding box of the plane. + * + * This function returns the bounding box of the plane. + * + * @return The bounding box of the plane. + */ Raytracer::Utils::AxisAlignedBBox Raytracer::Shapes::Plane::boundingBox() const { return _bbox; diff --git a/sources/shapes/Quad.cpp b/sources/shapes/Quad.cpp index e9d1ea3..ce2adf7 100644 --- a/sources/shapes/Quad.cpp +++ b/sources/shapes/Quad.cpp @@ -1,6 +1,20 @@ #include "shapes/Quad.hpp" #include +/** + * @brief Construct a new Quad object. + * + * This function constructs a new Quad object with the given point, u, v, and + * material. The quad is centered at the given point with the given u, v, and + * material. + * + * @param Q The point of the quad. + * @param u The u vector of the quad. + * @param v The v vector of the quad. + * @param material The material of the quad. + * + * @return A new Quad object. + */ Raytracer::Shapes::Quad::Quad(const Utils::Point3 &Q, const Utils::Vec3 &u, const Utils::Vec3 &v, std::shared_ptr material) : _Q(Q), _u(u), _v(v), _material(material) @@ -13,6 +27,19 @@ Raytracer::Shapes::Quad::Quad(const Utils::Point3 &Q, const Utils::Vec3 &u, setBBox(); } +/** + * @brief Check if the ray hits the quad. + * + * This function checks if the ray hits the quad. The function returns true if + * the ray hits the quad. The function returns false if the ray does not hit + * the quad. 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 the quad, false otherwise. + */ bool Raytracer::Shapes::Quad::hit(const Core::Ray &ray, Utils::Interval interval, Core::Payload &payload) const { @@ -44,11 +71,23 @@ bool Raytracer::Shapes::Quad::hit(const Core::Ray &ray, return true; } +/** + * @brief Get the bounding box of the quad. + * + * This function returns the bounding box of the quad. + * + * @return The bounding box of the quad. + */ Raytracer::Utils::AxisAlignedBBox Raytracer::Shapes::Quad::boundingBox() const { return _bbox; } +/** + * @brief Set the bounding box of the quad. + * + * This function sets the bounding box of the quad. + */ void Raytracer::Shapes::Quad::setBBox() { Utils::AxisAlignedBBox diagOne = Utils::AxisAlignedBBox(_Q, _Q + _u + _v); @@ -57,6 +96,20 @@ void Raytracer::Shapes::Quad::setBBox() _bbox = Utils::AxisAlignedBBox(diagOne, diagTwo); } +/** + * @brief Check if the point is inside the quad. + * + * This function checks if the point is inside the quad. The function returns + * true if the point is inside the quad. The function returns false if the + * point is not inside the quad. The function updates the payload with the u + * and v values of the point. + * + * @param a The alpha value of the point. + * @param b The beta value of the point. + * @param payload The payload to update with the u and v values. + * + * @return True if the point is inside the quad, false otherwise. + */ bool Raytracer::Shapes::Quad::isInterior( double a, double b, Core::Payload &payload) const { @@ -72,6 +125,18 @@ bool Raytracer::Shapes::Quad::isInterior( return true; } +/** + * @brief Construct a box object. + * + * This function constructs a box object with the given a, b, and material. The + * box is centered at the given a and b with the given material. + * + * @param a The first point of the box. + * @param b The second point of the box. + * @param material The material of the box. + * + * @return A new box object. + */ std::shared_ptr Raytracer::Shapes::box( const Utils::Point3 &a, const Utils::Point3 &b, std::shared_ptr material) diff --git a/sources/shapes/Sphere.cpp b/sources/shapes/Sphere.cpp index d6fec0b..bb9124c 100644 --- a/sources/shapes/Sphere.cpp +++ b/sources/shapes/Sphere.cpp @@ -1,6 +1,19 @@ #include "shapes/Sphere.hpp" #include +/** + * @brief Construct a new Sphere object. + * + * This function constructs a new Sphere object with the given center, radius, + * and material. The sphere is centered at the given center with the given + * radius and material. + * + * @param center The center of the sphere. + * @param radius The radius of the sphere. + * @param material The material of the sphere. + * + * @return A new Sphere object. + */ Raytracer::Shapes::Sphere::Sphere(const Utils::Point3 ¢er, double radius, std::shared_ptr material) : _center(center), _radius(std::fmax(0, radius)), _material(material), @@ -10,6 +23,20 @@ Raytracer::Shapes::Sphere::Sphere(const Utils::Point3 ¢er, double radius, _bbox = Utils::AxisAlignedBBox(_center - rvec, _center + rvec); } +/** + * @brief Construct a new Sphere object. + * + * This function constructs a new Sphere object with the given centers, radius, + * and material. The sphere is centered at the given centers with the given + * radius and material. + * + * @param one The first center of the sphere. + * @param two The second center of the sphere. + * @param radius The radius of the sphere. + * @param material The material of the sphere. + * + * @return A new Sphere object. + */ Raytracer::Shapes::Sphere::Sphere(const Utils::Point3 &one, const Utils::Point3 &two, double radius, std::shared_ptr material) @@ -24,6 +51,19 @@ Raytracer::Shapes::Sphere::Sphere(const Utils::Point3 &one, _centerVec = two - one; } +/** + * @brief Check if the ray hits the sphere. + * + * This function checks if the ray hits the sphere. The function returns true + * if the ray hits the sphere. The function returns false if the ray does not + * hit the sphere. 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 the sphere, false otherwise. + */ bool Raytracer::Shapes::Sphere::hit(const Core::Ray &ray, Utils::Interval interval, Core::Payload &payload) const { @@ -60,18 +100,43 @@ bool Raytracer::Shapes::Sphere::hit(const Core::Ray &ray, return true; } +/** + * @brief Get the bounding box of the sphere. + * + * This function returns the bounding box of the sphere. + * + * @return The bounding box of the sphere. + */ Raytracer::Utils::AxisAlignedBBox Raytracer::Shapes::Sphere::boundingBox() const { return _bbox; } +/** + * @brief Get the center of the sphere at the given time. + * + * This function returns the center of the sphere at the given time. + * + * @param time The time to get the center of the sphere. + * + * @return The center of the sphere at the given time. + */ Raytracer::Utils::Point3 Raytracer::Shapes::Sphere::sphereCenter( double time) const { return _center + time * _centerVec; } +/** + * @brief Get the UV coordinates of the sphere. + * + * This function returns the UV coordinates of the sphere. + * + * @param point The point to get the UV coordinates. + * @param u The U coordinate of the UV coordinates. + * @param v The V coordinate of the UV coordinates. + */ void Raytracer::Shapes::Sphere::getSphereUV( const Utils::Point3 &point, double &u, double &v) { diff --git a/sources/textures/Checker.cpp b/sources/textures/Checker.cpp index ff701b6..28ca15f 100644 --- a/sources/textures/Checker.cpp +++ b/sources/textures/Checker.cpp @@ -1,6 +1,18 @@ #include "textures/Checker.hpp" #include "textures/SolidColor.hpp" +/** + * @brief Construct a new Checker object. + * + * This function constructs a new Checker object with the given scale, even + * texture, and odd texture. + * + * @param scale The scale of the checker texture. + * @param even The even texture of the checker texture. + * @param odd The odd texture of the checker texture. + * + * @return A new Checker object. + */ Raytracer::Textures::Checker::Checker(double scale, std::shared_ptr even, std::shared_ptr odd) @@ -8,6 +20,18 @@ Raytracer::Textures::Checker::Checker(double scale, { } +/** + * @brief Construct a new Checker object. + * + * This function constructs a new Checker object with the given scale, even + * color, and odd color. + * + * @param scale The scale of the checker texture. + * @param a The even color of the checker texture. + * @param b The odd color of the checker texture. + * + * @return A new Checker object. + */ Raytracer::Textures::Checker::Checker( double scale, const Utils::Color &a, const Utils::Color &b) : _odd(std::make_shared(b)), @@ -15,6 +39,18 @@ Raytracer::Textures::Checker::Checker( { } +/** + * @brief Get the value of the checker texture. + * + * This function returns the value of the checker texture at the given UV + * coordinates and point. + * + * @param u The U coordinate. + * @param v The V coordinate. + * @param point The point. + * + * @return The value of the checker texture. + */ Raytracer::Utils::Color Raytracer::Textures::Checker::value( double u, double v, const Utils::Point3 &point) const { diff --git a/sources/textures/Image.cpp b/sources/textures/Image.cpp index 9931dc0..fbca754 100644 --- a/sources/textures/Image.cpp +++ b/sources/textures/Image.cpp @@ -2,11 +2,32 @@ #include "utils/Color.hpp" #include "utils/Interval.hpp" +/** + * @brief Construct a new Image object. + * + * This function constructs a new Image object with the given filename. + * + * @param filename The filename of the image. + * + * @return A new Image object. + */ Raytracer::Textures::Image::Image(std::string filename) : _helper(filename.c_str()) { } +/** + * @brief Get the value of the image texture. + * + * This function returns the value of the image texture at the given UV + * coordinates and point. + * + * @param u The U coordinate. + * @param v The V coordinate. + * @param point The point. + * + * @return The value of the image texture. + */ Raytracer::Utils::Color Raytracer::Textures::Image::value( double u, double v, const Utils::Point3 &point) const { diff --git a/sources/textures/Noise.cpp b/sources/textures/Noise.cpp index bde2cbf..9e1adab 100644 --- a/sources/textures/Noise.cpp +++ b/sources/textures/Noise.cpp @@ -1,9 +1,31 @@ #include "textures/Noise.hpp" +/** + * @brief Construct a new Noise object. + * + * This function constructs a new Noise object with the given scale. + * The Noise texture is a texture that generates Perlin noise. + * + * @param scale The scale of the noise texture. + * + * @return A new Noise object. + */ Raytracer::Textures::Noise::Noise(double scale) : _scale(scale), _perlin() { } +/** + * @brief Get the value of the noise texture. + * + * This function returns the value of the noise texture at the given UV + * coordinates and point. + * + * @param u The U coordinate. + * @param v The V coordinate. + * @param point The point. + * + * @return The value of the noise texture. + */ Raytracer::Utils::Color Raytracer::Textures::Noise::value( double u, double v, const Raytracer::Utils::Point3 &point) const { diff --git a/sources/textures/SolidColor.cpp b/sources/textures/SolidColor.cpp index c842ba1..2540fe6 100644 --- a/sources/textures/SolidColor.cpp +++ b/sources/textures/SolidColor.cpp @@ -1,17 +1,52 @@ #include "textures/SolidColor.hpp" #include "utils/Color.hpp" +/** + * @brief Construct a new SolidColor object. + * + * This function constructs a new SolidColor object with the given albedo. + * The SolidColor texture is a texture that generates a solid color. + * + * @param albedo The albedo of the solid color texture. + * + * @return A new SolidColor object. + */ Raytracer::Textures::SolidColor::SolidColor(const Utils::Color &albedo) : _albedo(albedo) { } +/** + * @brief Construct a new SolidColor object. + * + * This function constructs a new SolidColor object with the given red, green, + * and blue values. + * The SolidColor texture is a texture that generates a solid color. + * + * @param red The red value of the solid color texture. + * @param green The green value of the solid color texture. + * @param blue The blue value of the solid color texture. + * + * @return A new SolidColor object. + */ Raytracer::Textures::SolidColor::SolidColor( double red, double green, double blue) : _albedo(red, green, blue) { } +/** + * @brief Get the value of the solid color texture. + * + * This function returns the value of the solid color texture at the given UV + * coordinates and point. + * + * @param u The U coordinate. + * @param v The V coordinate. + * @param point The point. + * + * @return The value of the solid color texture. + */ Raytracer::Utils::Color Raytracer::Textures::SolidColor::value( double u, double v, const Utils::Point3 &point) const { diff --git a/sources/utils/AxisAlignedBBox.cpp b/sources/utils/AxisAlignedBBox.cpp index 03eef6a..382edba 100644 --- a/sources/utils/AxisAlignedBBox.cpp +++ b/sources/utils/AxisAlignedBBox.cpp @@ -1,6 +1,20 @@ #include "utils/AxisAlignedBBox.hpp" #include "utils/Interval.hpp" +/** + * @brief Construct a new AxisAlignedBBox object. + * + * This function constructs a new AxisAlignedBBox object with the given x, y, + * and z intervals. The AxisAlignedBBox is an axis-aligned bounding box that + * represents a box in 3D space. The x, y, and z intervals represent the + * intervals of the box along the x, y, and z axes. + * + * @param x The interval along the x-axis. + * @param y The interval along the y-axis. + * @param z The interval along the z-axis. + * + * @return A new AxisAlignedBBox object. + */ Raytracer::Utils::AxisAlignedBBox::AxisAlignedBBox( const Interval &x, const Interval &y, const Interval &z) : _x(x), _y(y), _z(z) @@ -8,6 +22,18 @@ Raytracer::Utils::AxisAlignedBBox::AxisAlignedBBox( padToMinimum(); } +/** + * @brief Construct a new AxisAlignedBBox object. + * + * This function constructs a new AxisAlignedBBox object with the given points. + * The AxisAlignedBBox is an axis-aligned bounding box that represents a box in + * 3D space. The box is defined by the two points. + * + * @param a The first point of the box. + * @param b The second point of the box. + * + * @return A new AxisAlignedBBox object. + */ Raytracer::Utils::AxisAlignedBBox::AxisAlignedBBox( const Point3 &a, const Point3 &b) { @@ -18,6 +44,18 @@ Raytracer::Utils::AxisAlignedBBox::AxisAlignedBBox( padToMinimum(); } +/** + * @brief Construct a new AxisAlignedBBox object. + * + * This function constructs a new AxisAlignedBBox object by combining the given + * AxisAlignedBBoxes. The new AxisAlignedBBox is the smallest AxisAlignedBBox + * that contains both of the given AxisAlignedBBoxes. + * + * @param a The first AxisAlignedBBox. + * @param b The second AxisAlignedBBox. + * + * @return A new AxisAlignedBBox object. + */ Raytracer::Utils::AxisAlignedBBox::AxisAlignedBBox( const AxisAlignedBBox &a, const AxisAlignedBBox &b) { @@ -26,6 +64,15 @@ Raytracer::Utils::AxisAlignedBBox::AxisAlignedBBox( _z = Interval(a.z(), b.z()); } +/** + * @brief Get the interval along the x-axis. + * + * This function returns the interval along the x-axis. + * + * @param n The axis to get the interval for. + * + * @return The interval along the x-axis. + */ const Raytracer::Utils::Interval & Raytracer::Utils::AxisAlignedBBox::axisInterval(int n) const { @@ -38,6 +85,18 @@ Raytracer::Utils::AxisAlignedBBox::axisInterval(int n) const return _x; } +/** + * @brief Check if the ray hits the AxisAlignedBBox. + * + * This function checks if the ray hits the AxisAlignedBBox. The function + * returns true if the ray hits the AxisAlignedBBox. The function returns false + * if the ray does not hit the AxisAlignedBBox. + * + * @param ray The ray to check for hits. + * @param interval The interval to check for hits. + * + * @return True if the ray hits the AxisAlignedBBox, false otherwise. + */ bool Raytracer::Utils::AxisAlignedBBox::hit( const Core::Ray &ray, Interval interval) const { @@ -66,6 +125,16 @@ bool Raytracer::Utils::AxisAlignedBBox::hit( return true; } +/** + * @brief Get the longest axis of the AxisAlignedBBox. + * + * This function returns the index of the longest axis of the AxisAlignedBBox. + * The function returns 0 if the x-axis is the longest axis. The function + * returns 1 if the y-axis is the longest axis. The function returns 2 if the + * z-axis is the longest axis. + * + * @return The index of the longest axis of the AxisAlignedBBox. + */ int Raytracer::Utils::AxisAlignedBBox::longestAxis() const { double x = _x.size(); @@ -79,6 +148,15 @@ int Raytracer::Utils::AxisAlignedBBox::longestAxis() const } } +/** + * @brief Pad the AxisAlignedBBox to the minimum size. + * + * This function pads the AxisAlignedBBox to the minimum size. The function + * expands the intervals of the AxisAlignedBBox to the minimum size if the + * intervals are smaller than the minimum size. + * + * @return void + */ void Raytracer::Utils::AxisAlignedBBox::padToMinimum() { double delta = 0.0001; @@ -94,14 +172,35 @@ void Raytracer::Utils::AxisAlignedBBox::padToMinimum() } } +/** + * @brief Empty AxisAlignedBBox. + * + * This constant represents an empty AxisAlignedBBox. + */ const Raytracer::Utils::AxisAlignedBBox Raytracer::Utils::AxisAlignedBBox::Empty = AxisAlignedBBox(Interval::Empty, Interval::Empty, Interval::Empty); +/** + * @brief Universe AxisAlignedBBox. + * + * This constant represents the universe AxisAlignedBBox. + */ const Raytracer::Utils::AxisAlignedBBox Raytracer::Utils::AxisAlignedBBox::Universe = AxisAlignedBBox( Interval::Universe, Interval::Universe, Interval::Universe); +/** + * @brief Operator to add a Vec3 to an AxisAlignedBBox. + * + * This operator adds a Vec3 to an AxisAlignedBBox. The operator returns a new + * AxisAlignedBBox with the Vec3 added to the AxisAlignedBBox. + * + * @param value The AxisAlignedBBox to add the Vec3 to. + * @param offset The Vec3 to add to the AxisAlignedBBox. + * + * @return The AxisAlignedBBox with the Vec3 added to it. + */ Raytracer::Utils::AxisAlignedBBox Raytracer::Utils::operator+( const Raytracer::Utils::AxisAlignedBBox &value, Raytracer::Utils::Vec3 offset) @@ -110,6 +209,17 @@ Raytracer::Utils::AxisAlignedBBox Raytracer::Utils::operator+( value.y() + offset.y(), value.z() + offset.z()); } +/** + * @brief Operator to add an AxisAlignedBBox to a Vec3. + * + * This operator adds an AxisAlignedBBox to a Vec3. The operator returns a new + * AxisAlignedBBox with the Vec3 added to the AxisAlignedBBox. + * + * @param offset The Vec3 to add to the AxisAlignedBBox. + * @param value The AxisAlignedBBox to add the Vec3 to. + * + * @return The AxisAlignedBBox with the Vec3 added to it. + */ Raytracer::Utils::AxisAlignedBBox Raytracer::Utils::operator+( Raytracer::Utils::Vec3 offset, const Raytracer::Utils::AxisAlignedBBox &value) diff --git a/sources/utils/BVHNode.cpp b/sources/utils/BVHNode.cpp index c6a9160..ed5778b 100644 --- a/sources/utils/BVHNode.cpp +++ b/sources/utils/BVHNode.cpp @@ -1,12 +1,40 @@ -#include #include "utils/BVHNode.hpp" +#include #include "core/Scene.hpp" +/** + * @brief Construct a new BVHNode object. + * + * This function constructs a new BVHNode object with the given list of + * objects. The BVHNode is a bounding volume hierarchy node that represents + * a node in a BVH tree. The BVH tree is a binary tree that is used to + * accelerate ray tracing. The BVHNode is constructed from the given list of + * objects. + * + * @param list The list of objects. + * + * @return A new BVHNode object. + */ Raytracer::Utils::BVHNode::BVHNode(Raytracer::Core::Scene list) : Raytracer::Utils::BVHNode(list.objects(), 0, list.objects().size()) { } +/** + * @brief Construct a new BVHNode object. + * + * This function constructs a new BVHNode object with the given list of + * objects, start index, and end index. The BVHNode is a bounding volume + * hierarchy node that represents a node in a BVH tree. The BVH tree is a + * binary tree that is used to accelerate ray tracing. The BVHNode is + * constructed from the given list of objects, start index, and end index. + * + * @param objects The list of objects. + * @param start The start index. + * @param end The end index. + * + * @return A new BVHNode object. + */ Raytracer::Utils::BVHNode::BVHNode( std::vector> &objects, size_t start, size_t end) @@ -41,6 +69,19 @@ Raytracer::Utils::BVHNode::BVHNode( } } +/** + * @brief Check if the ray hits the BVHNode. + * + * This function checks if the ray hits the BVHNode. The function returns true + * if the ray hits the BVHNode. The function returns false if the ray does not + * hit the BVHNode. 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 the BVHNode, false otherwise. + */ bool Raytracer::Utils::BVHNode::hit(const Raytracer::Core::Ray &ray, Raytracer::Utils::Interval interval, Raytracer::Core::Payload &payload) const @@ -57,12 +98,33 @@ bool Raytracer::Utils::BVHNode::hit(const Raytracer::Core::Ray &ray, return hitLeft || hitRight; } +/** + * @brief Get the bounding box of the BVHNode. + * + * This function returns the bounding box of the BVHNode. + * + * @return The bounding box of the BVHNode. + */ Raytracer::Utils::AxisAlignedBBox Raytracer::Utils::BVHNode::boundingBox() const { return _bbox; } +/** + * @brief Compare two objects based on the given axis. + * + * This function compares two objects based on the given axis. The function + * returns true if the first object is less than the second object based on + * the given axis. The function returns false otherwise. + * + * @param a The first object. + * @param b The second object. + * @param axis The axis to compare the objects on. + * + * @return true if the first object is less than the second object based on the + * given axis, false otherwise. + */ bool Raytracer::Utils::BVHNode::boxCompare( const std::shared_ptr &a, const std::shared_ptr &b, int axis) @@ -73,6 +135,19 @@ bool Raytracer::Utils::BVHNode::boxCompare( return aInterval.min() < bInterval.min(); } +/** + * @brief Compare two objects based on the x-axis. + * + * This function compares two objects based on the x-axis. The function returns + * true if the first object is less than the second object based on the x-axis. + * The function returns false otherwise. + * + * @param a The first object. + * @param b The second object. + * + * @return true if the first object is less than the second object based on the + * x-axis, false otherwise. + */ bool Raytracer::Utils::BVHNode::boxXCompare( const std::shared_ptr &a, const std::shared_ptr &b) @@ -80,6 +155,19 @@ bool Raytracer::Utils::BVHNode::boxXCompare( return boxCompare(a, b, 0); } +/** + * @brief Compare two objects based on the y-axis. + * + * This function compares two objects based on the y-axis. The function returns + * true if the first object is less than the second object based on the y-axis. + * The function returns false otherwise. + * + * @param a The first object. + * @param b The second object. + * + * @return true if the first object is less than the second object based on the + * y-axis, false otherwise. + */ bool Raytracer::Utils::BVHNode::boxYCompare( const std::shared_ptr &a, const std::shared_ptr &b) @@ -87,6 +175,19 @@ bool Raytracer::Utils::BVHNode::boxYCompare( return boxCompare(a, b, 1); } +/** + * @brief Compare two objects based on the z-axis. + * + * This function compares two objects based on the z-axis. The function returns + * true if the first object is less than the second object based on the z-axis. + * The function returns false otherwise. + * + * @param a The first object. + * @param b The second object. + * + * @return true if the first object is less than the second object based on the + * z-axis, false otherwise. + */ bool Raytracer::Utils::BVHNode::boxZCompare( const std::shared_ptr &a, const std::shared_ptr &b) diff --git a/sources/utils/Color.cpp b/sources/utils/Color.cpp index a0c8e8d..dc2eaef 100644 --- a/sources/utils/Color.cpp +++ b/sources/utils/Color.cpp @@ -1,6 +1,15 @@ #include "utils/Color.hpp" #include "utils/Interval.hpp" +/** + * @brief Transform a linear color to a gamma color. + * + * This function transforms a linear color to a gamma color. + * + * @param linear The linear color. + * + * @return The gamma color. + */ double Raytracer::Utils::linearToGamma(double linear) { if (linear > 0) { @@ -10,6 +19,14 @@ double Raytracer::Utils::linearToGamma(double linear) return 0; } +/** + * @brief Write a color to an output stream. + * + * This function writes a color to an output stream. + * + * @param out The output stream. + * @param pixelColor The color. + */ void Raytracer::Utils::writeColor(std::ostream &out, const Color &pixelColor) { double r = pixelColor.x(); diff --git a/sources/utils/ImageHelper.cpp b/sources/utils/ImageHelper.cpp index af0f835..368bb9b 100644 --- a/sources/utils/ImageHelper.cpp +++ b/sources/utils/ImageHelper.cpp @@ -2,11 +2,32 @@ #include #include +/** + * @brief Construct a new ImageHelper object. + * + * This function constructs a new ImageHelper object with the given filename. + * The ImageHelper object is used to load and read PPM images. + * + * @param filename The filename of the image. + * + * @return A new ImageHelper object. + */ Raytracer::Utils::ImageHelper::ImageHelper(const char *filename) { load(filename); } +/** + * @brief Load the image from the given filename. + * + * This function loads the image from the given filename. The image must be in + * PPM format (P6). The function returns true if the image was successfully + * loaded, and false otherwise. + * + * @param filename The filename of the image. + * + * @return True if the image was successfully loaded, and false otherwise. + */ bool Raytracer::Utils::ImageHelper::load(const std::string &filename) { std::ifstream file(filename, std::ios::binary); @@ -43,6 +64,17 @@ bool Raytracer::Utils::ImageHelper::load(const std::string &filename) return true; } +/** + * @brief Get the pixel data at the given coordinates. + * + * This function returns the pixel data at the given coordinates. The function + * returns magenta if the coordinates are out of bounds. + * + * @param x The x-coordinate. + * @param y The y-coordinate. + * + * @return The pixel data at the given coordinates. + */ const unsigned char *Raytracer::Utils::ImageHelper::pixelData( int x, int y) const { diff --git a/sources/utils/Interval.cpp b/sources/utils/Interval.cpp index 0b92b78..82765c5 100644 --- a/sources/utils/Interval.cpp +++ b/sources/utils/Interval.cpp @@ -1,37 +1,107 @@ #include "utils/Interval.hpp" #include +/** + * @brief Construct a new Interval object. + * + * This function constructs a new Interval object with the given minimum and + * maximum values. + * + * @param min The minimum value. + * @param max The maximum value. + * + * @return A new Interval object. + */ Raytracer::Utils::Interval::Interval(double min, double max) : _min(min), _max(max) { } +/** + * @brief Construct a new Interval object. + * + * This function constructs a new Interval object by combining the given + * Intervals. The new Interval is the smallest Interval that contains both of + * the given Intervals. + * + * @param a The first Interval. + * @param b The second Interval. + * + * @return A new Interval object. + */ Raytracer::Utils::Interval::Interval(const Interval &a, const Interval &b) { _min = a.min() <= b.min() ? a.min() : b.min(); _max = a.max() >= b.max() ? a.max() : b.max(); } +/** + * @brief Get the minimum value of the interval. + * + * This function returns the minimum value of the interval. + * + * @return The minimum value of the interval. + */ double Raytracer::Utils::Interval::size() const { return _max - _min; } +/** + * @brief Check if the interval contains the given value. + * + * This function checks if the interval contains the given value. The function + * returns true if the interval contains the value, false otherwise. + * + * @param x The value to check. + * + * @return True if the interval contains the value, false otherwise. + */ bool Raytracer::Utils::Interval::contains(double x) const { return _min <= x && x <= _max; } +/** + * @brief Check if the interval surrounds the given value. + * + * This function checks if the interval surrounds the given value. The function + * returns true if the interval surrounds the value, false otherwise. + * + * @param x The value to check. + * + * @return True if the interval surrounds the value, false otherwise. + */ bool Raytracer::Utils::Interval::surrounds(double x) const { return _min < x && x < _max; } +/** + * @brief Clamp the value to the interval. + * + * This function clamps the value to the interval. The function returns the + * clamped value. + * + * @param x The value to clamp. + * + * @return The clamped value. + */ double Raytracer::Utils::Interval::clamp(double x) const { return std::min(std::max(x, _min), _max); } +/** + * @brief Expand the interval by the given value. + * + * This function expands the interval by the given value. The function returns + * the expanded interval. + * + * @param x The value to expand the interval by. + * + * @return The expanded interval. + */ Raytracer::Utils::Interval Raytracer::Utils::Interval::expand(double x) const { double padding = x / 2; @@ -39,13 +109,35 @@ Raytracer::Utils::Interval Raytracer::Utils::Interval::expand(double x) const return Interval(_min - padding, _max + padding); } +/** + * @brief A constant empty interval. + * + * This constant represents an empty interval. + */ const Raytracer::Utils::Interval Raytracer::Utils::Interval::Empty = Interval(+std::numeric_limits::infinity(), -std::numeric_limits::infinity()); + +/** + * @brief A constant universe interval. + * + * This constant represents the universe interval. + */ const Raytracer::Utils::Interval Raytracer::Utils::Interval::Universe = Interval(-std::numeric_limits::infinity(), +std::numeric_limits::infinity()); +/** + * @brief Operator to add a double to an Interval. + * + * This operator adds a double to an Interval. The operator returns a new + * Interval with the double added to the Interval. + * + * @param value The Interval to add the double to. + * @param offset The double to add to the Interval. + * + * @return The Interval with the double added to it. + */ Raytracer::Utils::Interval Raytracer::Utils::operator+( const Raytracer::Utils::Interval &value, double offset) { @@ -53,6 +145,17 @@ Raytracer::Utils::Interval Raytracer::Utils::operator+( value.min() + offset, value.max() + offset); } +/** + * @brief Operator to add a double to an Interval. + * + * This operator adds a double to an Interval. The operator returns a new + * Interval with the double added to the Interval. + * + * @param offset The double to add to the Interval. + * @param value The Interval to add the double to. + * + * @return The Interval with the double added to it. + */ Raytracer::Utils::Interval Raytracer::Utils::operator+( double offset, const Raytracer::Utils::Interval &value) { diff --git a/sources/utils/Perlin.cpp b/sources/utils/Perlin.cpp index 0109b7a..9134d79 100644 --- a/sources/utils/Perlin.cpp +++ b/sources/utils/Perlin.cpp @@ -1,5 +1,14 @@ #include "utils/Perlin.hpp" +/** + * @brief Construct a new Perlin object. + * + * This function constructs a new Perlin object. + * The Perlin object is a Perlin noise generator. + * The Perlin noise is a type of gradient noise. + * + * @return A new Perlin object. + */ Raytracer::Utils::Perlin::Perlin() { _randVec = new Utils::Vec3[pointCount]; @@ -12,6 +21,11 @@ Raytracer::Utils::Perlin::Perlin() _permZ = perlinGeneratePerm(); } +/** + * @brief Destroy the Perlin object. + * + * This function destroys the Perlin object. + */ Raytracer::Utils::Perlin::~Perlin() { delete[] _randVec; @@ -20,6 +34,15 @@ Raytracer::Utils::Perlin::~Perlin() delete[] _permZ; } +/** + * @brief Get the noise value at the given point. + * + * This function returns the noise value at the given point. + * + * @param point The point. + * + * @return The noise value. + */ double Raytracer::Utils::Perlin::noise(const Utils::Point3 &point) const { double u = point.x() - std::floor(point.x()); @@ -44,6 +67,16 @@ double Raytracer::Utils::Perlin::noise(const Utils::Point3 &point) const return perlinInterp(c, u, v, w); } +/** + * @brief Get the turbulence value at the given point. + * + * This function returns the turbulence value at the given point. + * + * @param point The point. + * @param depth The depth. + * + * @return The turbulence value. + */ double Raytracer::Utils::Perlin::turbulence( const Utils::Point3 &point, int depth) const { @@ -60,6 +93,13 @@ double Raytracer::Utils::Perlin::turbulence( return std::fabs(accum); } +/** + * @brief Generate the permutation table. + * + * This function generates the permutation table. + * + * @return The permutation table. + */ int *Raytracer::Utils::Perlin::perlinGeneratePerm() { int *perm = new int[pointCount]; @@ -71,6 +111,14 @@ int *Raytracer::Utils::Perlin::perlinGeneratePerm() return perm; } +/** + * @brief Permute the permutation table. + * + * This function permutes the permutation table. + * + * @param perm The permutation table. + * @param n The size of the permutation table. + */ void Raytracer::Utils::Perlin::permute(int *perm, int n) { for (int i = n - 1; i > 0; i--) { @@ -81,6 +129,18 @@ void Raytracer::Utils::Perlin::permute(int *perm, int n) } } +/** + * @brief Interpolate the noise value. + * + * This function interpolates the noise value. + * + * @param c The noise value. + * @param u The U coordinate. + * @param v The V coordinate. + * @param w The W coordinate. + * + * @return The interpolated noise value. + */ double Raytracer::Utils::Perlin::perlinInterp( const Utils::Vec3 c[2][2][2], double u, double v, double w) {