RayTracer 1.0
Ray tracing is a technique used to generate realistic digital images by simulating the inverse path of light. Our goal is to create a program able to generate an image from a file describing the scene.
 
Loading...
Searching...
No Matches
Config Namespace Reference

Classes

class  Camera
 
class  Directional
 
class  Plane
 
class  Point
 
class  Scene
 
class  Sphere
 

Functions

Scene parseScene (const std::string &path)
 

Function Documentation

◆ parseScene()

Config::Scene Config::parseScene ( const std::string & path)

Definition at line 10 of file ConfigParser.cpp.

11{
12 libconfig::Config cfg;
13 Config::Scene scene;
14 cfg.setAutoConvert(true);
15
16 try {
17 cfg.readFile(file.c_str());
18 } catch (const libconfig::FileIOException &fioex) {
19 throw RayTracerException("Error: Unable to read the configuration file");
20 } catch (const libconfig::ConfigException &cfgex) {
21 throw RayTracerException("Error: Invalid configuration file format");
22 }
23 try {
24 // Camera
25 // resolution
26 cfg.lookupValue("camera.resolution.width", scene.camera.width);
27 cfg.lookupValue("camera.resolution.height", scene.camera.height);
28 // position
29 cfg.lookupValue("camera.position.x", scene.camera.position.x);
30 cfg.lookupValue("camera.position.y", scene.camera.position.y);
31 cfg.lookupValue("camera.position.z", scene.camera.position.z);
32 // rotation
33 cfg.lookupValue("camera.rotation.x", scene.camera.rotation.x);
34 cfg.lookupValue("camera.rotation.y", scene.camera.rotation.y);
35 cfg.lookupValue("camera.rotation.z", scene.camera.rotation.z);
36 // fieldOfView
37 cfg.lookupValue("camera.fieldOfView", scene.camera.fieldOfView);
38
39 // Primitives
40 // Spheres
41 const libconfig::Setting &spheres = cfg.lookup("primitives.spheres");
42 for (int i = 0; i < spheres.getLength(); ++i) {
43 const libconfig::Setting &config_sphere = spheres[i];
44 Config::Sphere s;
45
46 // center
47 s.center.x = config_sphere.lookup("x");
48 s.center.y = config_sphere.lookup("y");
49 s.center.z = config_sphere.lookup("z");
50 // radius
51 s.radius = config_sphere.lookup("r");
52 // color
53 const libconfig::Setting &config_color = config_sphere.lookup("color");
54 s.color = Color(
55 config_color.lookup("r"),
56 config_color.lookup("g"),
57 config_color.lookup("b")
58 );
59
60 scene.spheres.push_back(s);
61 }
62
63 // Planes
64 const libconfig::Setting &planes = cfg.lookup("primitives.planes");
65 for (int i = 0; i < planes.getLength(); ++i) {
66 const libconfig::Setting &config_plane = planes[i];
67 Config::Plane p;
68
69 // axis
70 std::string ax;
71 config_plane.lookupValue("axis", ax);
72 p.axis = ax[0];
73 // position
74 p.position = config_plane.lookup("position");
75 // color
76 const libconfig::Setting &config_color = config_plane.lookup("color");
77 p.color = Color(
78 config_color.lookup("r"),
79 config_color.lookup("g"),
80 config_color.lookup("b")
81 );
82
83 scene.planes.push_back(p);
84 }
85
86 // Lights
87 // ambient
88 cfg.lookupValue("lights.ambient", scene.ambient);
89 // diffuse
90 cfg.lookupValue("lights.diffuse", scene.diffuse);
91 // point
92 const libconfig::Setting &points = cfg.lookup("lights.point");
93 for (int i = 0; i < points.getLength(); ++i) {
94 const libconfig::Setting &config_point = points[i];
95 Config::Point p;
96
97 // position
98 p.position.x = config_point.lookup("x");
99 p.position.y = config_point.lookup("y");
100 p.position.z = config_point.lookup("z");
101
102 scene.points.push_back(p);
103 }
104
105 // directional
106 const libconfig::Setting &directionals = cfg.lookup("lights.directional");
107 for (int i = 0; i < directionals.getLength(); ++i) {
108 const libconfig::Setting &config_directional = directionals[i];
109 Config::Directional d;
110
111 // direction
112 d.direction.x = config_directional.lookup("x");
113 d.direction.y = config_directional.lookup("y");
114 d.direction.z = config_directional.lookup("z");
115
116 scene.directionals.push_back(d);
117 }
118 } catch (const libconfig::SettingNotFoundException &nf) {
119 // si y a pas faut voir ce qu'on fait
120 }
121
122 return scene;
123}
Math::Point3D position
Math::Vector3D rotation
Math::Vector3D direction
Math::Point3D position
std::vector< Plane > planes
std::vector< Point > points
std::vector< Sphere > spheres
std::vector< Directional > directionals
Math::Point3D center

References Config::Scene::ambient, Config::Plane::axis, Config::Scene::camera, Config::Sphere::center, Config::Plane::color, Config::Sphere::color, Config::Scene::diffuse, Config::Directional::direction, Config::Scene::directionals, Config::Camera::fieldOfView, Config::Camera::height, Config::Scene::planes, Config::Scene::points, Config::Camera::position, Config::Plane::position, Config::Point::position, Config::Sphere::radius, Config::Camera::rotation, Config::Scene::spheres, Config::Camera::width, Math::Point3D::x, Math::Vector3D::x, Math::Point3D::y, Math::Vector3D::y, Math::Point3D::z, and Math::Vector3D::z.