-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain3.cpp
More file actions
97 lines (87 loc) · 3.88 KB
/
Copy pathmain3.cpp
File metadata and controls
97 lines (87 loc) · 3.88 KB
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
92
93
94
95
96
97
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <Util/cmdLineParser.h>
#include <Ray/window.h>
#include <Ray/box.h>
#include <Ray/cone.h>
#include <Ray/cylinder.h>
#include <Ray/sphere.h>
#include <Ray/torus.h>
#include <Ray/triangle.h>
#include <Ray/fileInstance.h>
#include <Ray/directionalLight.h>
#include <Ray/pointLight.h>
#include <Ray/spotLight.h>
#include <Ray/sphereLight.h>
using namespace std;
using namespace Ray;
using namespace Util;
CmdLineParameter<string> InputRayFile("in");
CmdLineParameter<int> WindowWidth("width", 640);
CmdLineParameter<int> WindowHeight("height", 480);
CmdLineParameter<int> Complexity("cplx", 10);
CmdLineParameter<int> Antialiasing("aa", 8);
CmdLineReadable* params[] =
{
&InputRayFile, &WindowWidth, &WindowHeight, &Complexity, &Antialiasing,
nullptr
};
void ShowUsage(const string& ex) {
cout << "Usage " << ex << ":" << endl;
cout << "\t --" << InputRayFile.name << " <input ray File>" << endl;
cout << "\t[--" << WindowWidth.name << " <window width>=" << WindowWidth.value << "]" << endl;
cout << "\t[--" << WindowHeight.name << " <window height>=" << WindowHeight.value << "]" << endl;
cout << "\t[--" << Complexity.name << " <tessellation complexity>=" << Complexity.value << "]" << endl;
cout << "\t[--" << Antialiasing.name << " <anti-aliasing samples>=" << Antialiasing.value << "]" << endl;
}
int main(int argc, char* argv[]) {
CmdLineParse(argc - 1, argv + 1, params);
if (!InputRayFile.set) {
ShowUsage(argv[0]);
return EXIT_FAILURE;
}
if (Antialiasing.value != 1 && Antialiasing.value != 2 && Antialiasing.value != 4 && Antialiasing.value != 8 &&
Antialiasing.value != 16) {
cout << "Anti-aliasing samples must be <1, 2, 4, 8, 16>. Set 1 to disable." << '\n';
ShowUsage(argv[0]);
return EXIT_FAILURE;
}
try {
ShapeList::ShapeFactories[Box::Directive()] = new DerivedFactory<Shape, Box>();
ShapeList::ShapeFactories[Cone::Directive()] = new DerivedFactory<Shape, Cone>();
ShapeList::ShapeFactories[Cylinder::Directive()] = new DerivedFactory<Shape, Cylinder>();
ShapeList::ShapeFactories[Sphere::Directive()] = new DerivedFactory<Shape, Sphere>();
ShapeList::ShapeFactories[Torus::Directive()] = new DerivedFactory<Shape, Torus>();
ShapeList::ShapeFactories[Triangle::Directive()] = new DerivedFactory<Shape, Triangle>();
ShapeList::ShapeFactories[FileInstance::Directive()] = new DerivedFactory<Shape, FileInstance>();
ShapeList::ShapeFactories[ShapeList::Directive()] = new DerivedFactory<Shape, ShapeList>();
ShapeList::ShapeFactories[TriangleList::Directive()] = new DerivedFactory<Shape, TriangleList>();
ShapeList::ShapeFactories[StaticAffineShape::Directive()] = new DerivedFactory<Shape, StaticAffineShape>();
GlobalSceneData::LightFactories[DirectionalLight::Directive()] = new DerivedFactory<Light, DirectionalLight>();
GlobalSceneData::LightFactories[PointLight::Directive()] = new DerivedFactory<Light, PointLight>();
GlobalSceneData::LightFactories[SpotLight::Directive()] = new DerivedFactory<Light, SpotLight>();
GlobalSceneData::LightFactories[SphereLight::Directive()] = new DerivedFactory<Light, SphereLight>();
Scene::BaseDir = GetFileDirectory(InputRayFile.value);
Scene::aa_samples = Antialiasing.value;
Scene scene;
ifstream istream;
istream.open(InputRayFile.value);
if (!istream)
THROW("Failed to open file for reading: %s\n", InputRayFile.value.c_str());
istream >> scene;
Shape::OpenGLTessellationComplexity = Complexity.value;
Window::View(scene, WindowWidth.value, WindowHeight.value);
}
catch (const exception& e) {
cerr << e.what() << endl;
return EXIT_FAILURE;
}
for (auto iter = ShapeList::ShapeFactories.begin(); iter != ShapeList::ShapeFactories.end(); ++iter)
delete iter->
second;
for (auto iter = GlobalSceneData::LightFactories.begin(); iter != GlobalSceneData::LightFactories.end(); ++iter)
delete iter->second;
return EXIT_SUCCESS;
}