-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain4.cpp
More file actions
93 lines (82 loc) · 4.39 KB
/
main4.cpp
File metadata and controls
93 lines (82 loc) · 4.39 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
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <Util/cmdLineParser.h>
#include <Ray/scene.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>
using namespace std;
using namespace Ray;
using namespace Util;
CmdLineParameter< string > InputRayFile( "in" );
CmdLineParameter< int > ParameterType( "parameter" , RotationParameters::TRIVIAL+1 );
CmdLineParameter< int > InterpolantType( "interpolant" , Interpolation::NEAREST+1 );
CmdLineParameter< int > WindowWidth( "width" , 640 );
CmdLineParameter< int > WindowHeight( "height" , 480 );
CmdLineParameter< int > Complexity( "cplx" , 10 );
CmdLineReadable* params[] =
{
&InputRayFile , &WindowWidth , &WindowHeight , &Complexity , &ParameterType , &InterpolantType ,
NULL
};
void ShowUsage( const string &ex )
{
cout << "Usage " << ex << ":" << endl;
cout << "\t --" << InputRayFile.name << " <input ray File>" << endl;
cout << "\t[--" << ParameterType.name << " <matrix representation>=" << ParameterType.value << "]" << endl;
for( int i=0 ; i<RotationParameters::COUNT ; i++ ) cout << "\t\t" << (i+1) << "] " << RotationParameters::Names[i] << endl;
cout << "\t[--" << InterpolantType.name << " <interpolation type>=" << InterpolantType.value << "]" << endl;
for( int i=0 ; i<Interpolation::COUNT ; i++ ) cout << "\t\t" << (i+1) << "] " << Interpolation::Names[i] << 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;
}
int main( int argc , char *argv[] )
{
CmdLineParse( argc-1 , argv+1 , params );
if( !InputRayFile.set ){ ShowUsage( argv[0] ) ; return EXIT_FAILURE; }
Scene scene;
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 >();
ShapeList::ShapeFactories[ DynamicAffineShape::Directive() ] = new DerivedFactory< Shape , DynamicAffineShape >();
GlobalSceneData::LightFactories[ DirectionalLight::Directive() ] = new DerivedFactory< Light , DirectionalLight >();
GlobalSceneData::LightFactories[ PointLight ::Directive() ] = new DerivedFactory< Light , PointLight >();
GlobalSceneData::LightFactories[ SpotLight ::Directive() ] = new DerivedFactory< Light , SpotLight >();
Shape::OpenGLTessellationComplexity = Complexity.value;
Window::interpolationType = InterpolantType.value-1;
Window::parametrizationType = ParameterType.value-1;
ifstream istream;
istream.open( InputRayFile.value );
if( !istream ) THROW( "Failed to open file for reading: %s\n" , InputRayFile.value.c_str() );
istream >> scene;
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;
}