Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
[FEAT]: init parse with libconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
bobis33 committed Apr 13, 2024
1 parent b9776b4 commit a8c5555
Show file tree
Hide file tree
Showing 14 changed files with 360 additions and 94 deletions.
22 changes: 22 additions & 0 deletions App/include/RayTracer/Abstraction/IShapes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
** EPITECH PROJECT, 2024
** Raytracer
** File description:
** IShapes.cpp
*/

#ifndef RAYTRACER_ISHAPES_HPP
#define RAYTRACER_ISHAPES_HPP

namespace RayTracer {

class IShapes {

public:
virtual ~IShapes() = default;

}; // IShapes

} // namespace RayTracer

#endif //RAYTRACER_ISHAPES_HPP
69 changes: 68 additions & 1 deletion App/include/RayTracer/Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,78 @@

#include <iostream>
#include <vector>
#include <tuple>

namespace RayTracer {

enum class PrimitiveType : u_int8_t {
SPHERE,
PLANE,
CYLINDER,
CONE,
NONE
};

struct Material_t {
std::string name;
std::tuple<u_int8_t, u_int8_t, u_int8_t> color{0, 0, 0};
};

struct Light_t {
std::tuple<u_int16_t, u_int16_t, u_int16_t> position{0, 0, 0};
u_int8_t intensity{0};
};

struct Plane_t {
std::string material;
std::tuple<u_int16_t, u_int16_t, u_int16_t> position{0, 0, 0};
};

struct Sphere_t {
std::string material;
std::tuple<u_int16_t, u_int16_t, u_int16_t> position{0, 0, 0};
u_int16_t radius{0};
};

struct Cylinder_t {
std::string material;
std::tuple<u_int16_t, u_int16_t, u_int16_t> position{0, 0, 0};
u_int8_t radius{0};
u_int16_t height;
};

struct Cone_t {
std::string material;
std::tuple<u_int16_t, u_int16_t, u_int16_t> position{0, 0, 0};
u_int8_t radius{0};
u_int16_t height;
};

struct Primitive_t {
Primitive_t() {}
~Primitive_t() {}
Material_t material;
PrimitiveType type{PrimitiveType::NONE};
union {
Sphere_t sphere;
Plane_t plane;
Cylinder_t cylinder;
Cone_t cone;
};
};

struct Camera_t {
std::tuple<u_int16_t, u_int16_t, u_int16_t> position{0, 0, 0};
u_int16_t fov{0};
};

struct Scene {
std::vector<std::string> config;
std::string fileName;
std::pair<u_int16_t, u_int16_t> resolution{1920, 1080};
Camera_t camera;
std::vector<Material_t> materials;
std::vector<Primitive_t> primitives;
std::vector<Light_t> lights;
};

class Parser {
Expand Down
18 changes: 9 additions & 9 deletions App/src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
*/

#include <filesystem>
#include <fstream>
#include <libconfig.h++>

#include "RayTracer/Parser.hpp"
#include "RayTracer/Constants.hpp"


RayTracer::Scene RayTracer::Parser::parseFile(const std::string &filePath)
{
libconfig::Config config;
Scene scene;
std::string line;
std::ifstream file(filePath);

while(std::getline(file, line)) {
scene.config.push_back(line);
}

if (scene.config.empty()) {
throw ParserException{"File is empty"};
try {
config.readFile(filePath.c_str());
} catch (const libconfig::FileIOException &e) {
throw ParserException{"Error while reading file"};
} catch (const libconfig::ParseException &e) {
throw ParserException{e.getError()};
}

return scene;
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ target_sources(${PROJECT_NAME} PRIVATE
)

target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE raytracer_interface)
target_link_libraries(${PROJECT_NAME} PRIVATE raytracer_interface config++)

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
target_compile_options(${PROJECT_NAME} PRIVATE ${WARNING_FLAGS})
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ $> ./build.sh build
### Launch RayTracer

```bash
$> ./raytracer .
$> ./raytracer <SCENE_FILE>
[...]
```

Expand Down
6 changes: 2 additions & 4 deletions cmake/modules/MakeDoc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ find_package(Doxygen)
if (DOXYGEN_FOUND)
set(DOXYGEN_GENERATE_LATEX YES)
set(DOXYGEN_QUIET YES)
set(DOXYGEN_STRIP_FROM_INC_PATH
Core/include
)
set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/.doxygen)
doxygen_add_docs(doc
Core/include
App/include
App/plugins/Renderer/include
ALL
)
add_custom_command(TARGET doc
Expand Down
Binary file added doc/RAYTRACER_SCENE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/RayTracer.pdf
Binary file not shown.
80 changes: 80 additions & 0 deletions scenes/colored_lights.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
camera:
{
origin = [5, 0, 0];
lookAt = [0, 0, 0];
up = [0, 1, 0];
vfov = 90;
aspectWidth = 16;
aspectHeight = 9;
};

renderer:
{
type = "ppmrenderer";
filename = "colored_lights.ppm";
width = 1280;
height = 720;
samplesPerPixel = 4;
};

materials = (
{ name = "redmat"; type = "flat_color"; color = [1.0, 0.255, 0.098]; },
{ name = "greenmat"; type = "flat_color"; color = [0.224, 1.0, 0.02]; },
{ name = "bluemat"; type = "flat_color"; color = [0.0, 0.886, 1.0]; },
{ name = "greymat"; type = "flat_color"; color = [0.4, 0.4, 0.4]; }
);

lights = (
{
type = "point_light";
position = [3, 3, 3];
color = [0, 1, 1];
intensity = 0.6;
shadowRayCount = 18;
shadowRayOffset = 1;
},
{
type = "point_light";
position = [-3, -3, -3];
color = [1, 1, 0];
intensity = 0.6;
shadowRayCount = 18;
shadowRayOffset = 1;
},
{
type = "point_light";
position = [3, -3, 3];
color = [1, 0, 1];
intensity = 0.6;
shadowRayCount = 18;
shadowRayOffset = 1;
},
{
type = "point_light";
position = [-3, 3, -3];
color = [1, 0, 0];
intensity = 0.6;
shadowRayCount = 18;
shadowRayOffset = 1;
},
{
type = "point_light";
position = [-3, 3, 3];
color = [0, 0, 1];
intensity = 0.6;
shadowRayCount = 18;
shadowRayOffset = 1;
},
{ type = "ambient_light"; color = [1, 1, 1]; intensity = 0.4; }
);

objects = (
{ type = "sphere"; position = [-1, -2, -2]; radius = 1; material = "redmat"; },
{ type = "sphere"; position = [-1, -2, 2]; radius = 1; material = "greenmat"; },
{ type = "sphere"; position = [-1, 2, 0]; radius = 1; material = "bluemat"; },
{ type = "plane"; position = [0, -5, 0]; normal = [0, 1, 0]; distance = [16, 0, 16]; material = "greymat"; },
{ type = "plane"; position = [0, 5, 0]; normal = [0, -1, 0]; distance = [16, 0, 16]; material = "greymat"; },
{ type = "plane"; position = [0, 0, -5]; normal = [0, 0, 1]; distance = [16, 16, 0]; material = "greymat"; },
{ type = "plane"; position = [0, 0, 5]; normal = [0, 0, -1]; distance = [16, 16, 0]; material = "greymat"; },
{ type = "plane"; position = [-5, 0, 0]; normal = [1, 0, 0]; distance = [0, 16, 16]; material = "greymat"; }
);
76 changes: 76 additions & 0 deletions scenes/colored_lights2.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
camera:
{
origin = [5, 0, 0];
lookAt = [0, 0, 0];
up = [0, 1, 0];
vfov = 90;
aspectWidth = 16;
aspectHeight = 9;
};

renderer:
{
type = "ppmrenderer";
filename = "colored_lights2.ppm";
width = 1280;
height = 720;
samplesPerPixel = 4;
};

materials = (
{ name = "whitemat"; type = "flat_color"; color = [1, 1, 1]; },
{ name = "greymat"; type = "flat_color"; color = [0.4, 0.4, 0.4]; }
);

lights = (
{
type = "point_light";
position = [3, 3, -3];
color = [0, 1, 1];
intensity = 0.6;
shadowRayCount = 18;
shadowRayOffset = 1;
},
{
type = "point_light";
position = [-3, -3, -3];
color = [1, 0, 1];
intensity = 0.6;
shadowRayCount = 18;
shadowRayOffset = 1;
},
{
type = "point_light";
position = [-3, -3, 3];
color = [1, 1, 0];
intensity = 0.6;
shadowRayCount = 18;
shadowRayOffset = 1;
},
{
type = "point_light";
position = [-3, 3, -3];
color = [0, 0, 1];
intensity = 0.6;
shadowRayCount = 18;
shadowRayOffset = 1;
},
{
type = "point_light";
position = [-3, 3, 3];
color = [1, 0, 0];
intensity = 0.6;
shadowRayCount = 18;
shadowRayOffset = 1;
},
{ type = "ambient_light"; color = [1, 1, 1]; intensity = 0.4; }
);

objects = (
{ type = "sphere"; position = [0, 0, 0]; radius = 1.5; material = "whitemat"; },
{ type = "plane"; position = [0, -5, 0]; normal = [0, 1, 0]; distance = [16, 0, 16]; material = "greymat"; },
{ type = "plane"; position = [0, 5, 0]; normal = [0, -1, 0]; distance = [16, 0, 16]; material = "greymat"; },
{ type = "plane"; position = [0, 0, -5]; normal = [0, 0, 1]; distance = [16, 16, 0]; material = "greymat"; },
{ type = "plane"; position = [0, 0, 5]; normal = [0, 0, -1]; distance = [16, 16, 0]; material = "greymat"; },
{ type = "plane"; position = [-5, 0, 0]; normal = [1, 0, 0]; distance = [0, 16, 16]; material = "greymat"; }
);
45 changes: 0 additions & 45 deletions scenes/cylender.cfg

This file was deleted.

Loading

0 comments on commit a8c5555

Please sign in to comment.