-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parse.h
91 lines (65 loc) · 3 KB
/
Parse.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Json
#include <json/json.h>
#include<iostream>
#include<string>
#include <typeinfo>
using namespace std;
vector<double> populate(string key, Json::Value metadata){
vector<double> arguments;
arguments.reserve(metadata[key].size());
transform(metadata[key].begin(), metadata[key].end(), back_inserter(arguments), [](const auto& e) { return e.asDouble(); });
return arguments;
}
pair< map<string,vector<double>>, map<string,map<string,vector<double>>> > parse_args(string input_file){
map<string,vector<double>> args;
map<string,map<string,vector<double>>> objects;
// Read json
Json::Reader reader;
Json::Value metadata;
std::ifstream metadata_file(input_file, std::ifstream::binary);
metadata_file >> metadata;
args["Camera_Position"] = populate("Camera_Position", metadata);
args["Lookup_Position"] = populate("Lookup_Position", metadata);
vector<double> scene_properties{
metadata["Height"].asInt(),
metadata["Width"].asInt(),
metadata["anti_aliasing"].asInt(),
metadata["threshold"].asDouble(),
metadata["ambientlight"].asDouble(),
metadata["accuracy"].asDouble(),
};
args["scene_properties"] = scene_properties;
map<string,vector<double>> sphere;
sphere["Location"] =populate("Location", metadata["objects"]["Sphere"]);
sphere["Radius"] =populate("Radius", metadata["objects"]["Sphere"]);
sphere["Color"] =populate("Color", metadata["objects"]["Sphere"]);
sphere["Show"] =populate("Show", metadata["objects"]["Sphere"]);
map<string,vector<double>> triangle;
triangle["Location"] =populate("Location", metadata["objects"]["Triangle"]);
triangle["Color"] =populate("Color", metadata["objects"]["Triangle"]);
triangle["Show"] =populate("Show", metadata["objects"]["Triangle"]);
map<string,vector<double>> quadric;
quadric["Location"] =populate("Location", metadata["objects"]["Quadric"]);
quadric["Radius"] =populate("Radius", metadata["objects"]["Quadric"]);
quadric["Height"] =populate("Height", metadata["objects"]["Quadric"]);
quadric["Color"] =populate("Color", metadata["objects"]["Quadric"]);
quadric["Show"] =populate("Show", metadata["objects"]["Quadric"]);
map<string,vector<double>> plane;
plane["Normal"] =populate("Normal", metadata["objects"]["Plane"]);
plane["Distance"] =populate("Distance", metadata["objects"]["Plane"]);
plane["Color"] =populate("Color", metadata["objects"]["Plane"]);
plane["Show"] =populate("Show", metadata["objects"]["Plane"]);
map<string,vector<double>> cuboid;
cuboid["Location"] =populate("Location", metadata["objects"]["Cuboid"]);
cuboid["Color"] =populate("Color", metadata["objects"]["Cuboid"]);
cuboid["Show"] =populate("Show", metadata["objects"]["Cuboid"]);
objects["Sphere"] = sphere;
objects["Triangle"] = triangle;
objects["Quadric"] = quadric;
objects["Plane"] = plane;
objects["Cuboid"] = cuboid;
// Light
args["Light_Source"]=populate("Light_Source", metadata);
cout<<metadata<<endl; //This will print the entire json object.
return make_pair(args, objects);
}