Assignments Assignments

scene.h
Go to the documentation of this file.
1#ifndef SCENE_INCLUDED
2#define SCENE_INCLUDED
3#include <unordered_map>
4#include <vector>
5#include <Util/geometry.h>
6#include <Image/image.h>
7#include "shape.h"
8#include "light.h"
9#include "shapeList.h"
10#include "keyFrames.h"
11#include "camera.h"
12
13 namespace Ray
14{
15 class Material;
16 class Texture;
17 class File;
18 class KeyFrameFile;
19 class Shader;
20 class Vertex;
21
23 std::string ReadDirective( std::istream &stream );
24
26 void UnreadDirective( std::istream &stream , const std::string &directive );
27
29 Shape *ReadShape( std::istream &stream , const std::unordered_map< std::string , Util::BaseFactory< Shape > * > &shapeFactories );
30
32 class GlobalSceneData
33 {
34 public:
36 Camera camera;
37
39 std::vector< Light * > lights;
40
42 Shader *shader;
43
45 GlobalSceneData( void );
46
48 ~GlobalSceneData( void );
49
51 static std::unordered_map< std::string , Util::BaseFactory< Light > * > LightFactories;
52 };
53
55 std::ostream &operator << ( std::ostream &stream , const GlobalSceneData &data );
56
58 std::istream &operator >> ( std::istream &stream , GlobalSceneData &data );
59
61 class LocalSceneData
62 {
63 public:
65 std::vector< Vertex > vertices;
66
68 std::vector< Material > materials;
69
71 std::vector< Texture > textures;
72
74 std::vector< File > files;
75
77 KeyFrameFile *keyFrameFile;
78
80 template< typename ParameterType >
81 void setKeyFrameEvaluator( void );
82
84 void setCurrentTime( double t , int curveFit );
85
87 LocalSceneData( void );
88
90 ~LocalSceneData( void );
91 };
92
94 std::ostream &operator << ( std::ostream &stream , const LocalSceneData &data );
95
97 std::istream &operator >> ( std::istream &stream , LocalSceneData &data );
98
100 class SceneGeometry : public Shape
101 {
103 LocalSceneData _localData;
104
106 ShapeList _shapeList;
107
108 public:
110 void init( void );
111
113 template< typename ParameterType >
114 void setKeyFrameEvaluator( void );
115
117 void setCurrentTime( double t , int curveFit );
118
120 // Shape methods //
122 private:
123 void _write( std::ostream &stream ) const;
124 void _read( std::istream &stream );
125 public:
126 std::string name( void ) const { return "scene geometry"; }
127 void init( const LocalSceneData &sceneData );
128 void initOpenGL( void );
129 void updateBoundingBox( void );
130 bool processFirstIntersection( const Util::Ray3D &ray , const Util::BoundingBox1D &range , const RayIntersectionFilter &rFilter , const RayIntersectionKernel &rKernel , ShapeProcessingInfo spInfo , unsigned int tIdx ) const;
131 int processAllIntersections( const Util::Ray3D &ray , const Util::BoundingBox1D &range , const RayIntersectionFilter &rFilter , const RayIntersectionKernel &rKernel , ShapeProcessingInfo spInfo , unsigned int tIdx ) const;
132 void processOverlapping( const Filter &filter , const Kernel &kernel , ShapeProcessingInfo tInfo ) const;
133 bool isInside( Util::Point3D p ) const;
134 void drawOpenGL( GLSLProgram *glslProgram ) const;
135 };
136
138 class Scene : public SceneGeometry
139 {
140 friend class Window;
141 friend class FileInstance;
142 friend std::ostream &operator << ( std::ostream & , const Scene & );
143 friend std::istream &operator >> ( std::istream & , Scene & );
144
146 GlobalSceneData _globalData;
147
148 public:
150 static std::string BaseDir;
151
153 static Util::Point3D Reflect( Util::Point3D v , Util::Point3D n );
154
157 static bool Refract( Util::Point3D v , Util::Point3D n , double ir , Util::Point3D& refract );
158
162 Util::Point3D getColor( Util::Ray3D ray , int rDepth , Util::Point3D cLimit , unsigned int lightSamples , bool binaryShadows , unsigned int tIdx );
163
165 Image::Image32 rayTrace( int width , int height , int rLimit , double cLimit , unsigned int lightSamples , bool binaryShadows , bool showProgress );
166
168 void initOpenGL( void );
169
171 void drawOpenGL( void ) const;
172
174 bool processFirstIntersection( const Util::Ray3D &ray , const Util::BoundingBox1D &range , const RayIntersectionFilter &rFilter , const RayIntersectionKernel &rKernel , ShapeProcessingInfo spInfo , unsigned int tIdx ) const;
175 int processAllIntersections( const Util::Ray3D &ray , const Util::BoundingBox1D &range , const RayIntersectionFilter &rFilter , const RayIntersectionKernel &rKernel , ShapeProcessingInfo spInfo , unsigned int tIdx ) const;
176 };
177
179 std::ostream &operator << ( std::ostream &stream , const Scene &scene );
180
182 std::istream &operator >> ( std::istream &stream , Scene &scene );
183
185 class File : public SceneGeometry
186 {
187 friend std::istream &operator >> ( std::istream & , File & );
188 friend class FileInstance;
189 friend class Scene;
190 public:
192 std::string filename;
193 };
194
196 std::ostream &operator << ( std::ostream &stream , const File &file );
197
199 std::istream &operator >> ( std::istream &stream , File &file );
200
202 class Vertex
203 {
204 public:
206 Util::Point3D position;
207
209 Util::Point3D normal;
210
212 Util::Point2D texCoordinate;
213 };
214
216 std::ostream &operator << ( std::ostream &stream , const Vertex &vertex );
217
219 std::istream &operator >> ( std::istream &stream , Vertex &vertex );
220
222 class RayShapeIntersectionInfo
223 {
224 public:
226 RayShapeIntersectionInfo( void );
227
229 double t;
230
232 Util::Point3D position;
233
235 Util::Point3D normal;
236
238 Util::Point2D texture;
239
241 bool operator < ( const RayShapeIntersectionInfo &iInfo ) const;
242
244 bool operator < ( double t ) const;
245 };
246
248 class Material
249 {
250 friend SceneGeometry;
251 friend Scene;
252 friend class File;
253 friend std::ostream &operator << ( std::ostream & , const Material & );
254 friend std::istream &operator >> ( std::istream & , Material & );
255 friend std::istream &operator >> ( std::istream & , Scene & );
256
258 int _texIndex;
259 public:
261 Util::Point3D ambient;
262
264 Util::Point3D diffuse;
265
267 Util::Point3D specular;
268
270 Util::Point3D emissive;
271
273 Util::Point3D transparent;
274
276 double specularFallOff;
277
279 double ir;
280
282 const Texture *tex;
283
285 std::string foo;
286
288 Material( void );
289
291 void drawOpenGL( GLSLProgram * glslProgram ) const;
292 };
293
295 std::ostream &operator << ( std::ostream &stream , const Material &material );
296
298 std::istream &operator >> ( std::istream &stream , Material &material );
299
301 class Texture
302 {
303 friend Scene;
304 friend Material;
305 friend std::ostream &operator << ( std::ostream & , const Texture & );
306 friend std::istream &operator >> ( std::istream & , Texture & );
307
309 std::string _filename;
310
312 Image::Image32 _image;
313
315 GLuint _openGLHandle;
316 public:
318 void initOpenGL( void );
319 };
320
322 std::ostream &operator << ( std::ostream &stream , const Texture &texture );
323
325 std::istream &operator >> ( std::istream &stream , Texture &texture );
326
328 class Shader
329 {
330 public:
332 std::string vertexShaderFilename;
333
335 std::string fragmentShaderFilename;
336
338 GLSLProgram *glslProgram;
339
341 Shader( void );
342
344 ~Shader( void );
345 };
346
348 std::ostream &operator << ( std::ostream &stream , const Shader &shader );
349
351 std::istream &operator >> ( std::istream &stream , Shader &shader );
352
354 class KeyFrameFile
355 {
356 public:
358 std::string filename;
359
361 KeyFrameMatrices keyFrameMatrices;
362 };
363
365 std::ostream &operator << ( std::ostream &stream , const KeyFrameFile &keyFrameFile );
366
368 std::istream &operator >> ( std::istream &stream , KeyFrameFile &keyFrameFile );
369}
370
371#include "scene.inl"
372#endif // SCENE_INCLUDED
373
374
camera.h
GLSLProgram
Definition GLSLProgram.h:33
Image::Image32
Definition image.h:35
Ray::Camera
Definition camera.h:10
Ray::File
Definition scene.h:186
Ray::File::Scene
friend class Scene
Definition scene.h:189
Ray::File::FileInstance
friend class FileInstance
Definition scene.h:188
Ray::File::filename
std::string filename
Definition scene.h:192
Ray::File::operator>>
friend std::istream & operator>>(std::istream &, File &)
Ray::GlobalSceneData
Definition scene.h:33
Ray::GlobalSceneData::shader
Shader * shader
Definition scene.h:42
Ray::GlobalSceneData::~GlobalSceneData
~GlobalSceneData(void)
Definition scene.cpp:112
Ray::GlobalSceneData::camera
Camera camera
Definition scene.h:36
Ray::GlobalSceneData::lights
std::vector< Light * > lights
Definition scene.h:39
Ray::GlobalSceneData::GlobalSceneData
GlobalSceneData(void)
Definition scene.cpp:110
Ray::GlobalSceneData::LightFactories
static std::unordered_map< std::string, Util::BaseFactory< Light > * > LightFactories
Definition scene.h:51
Ray::KeyFrameFile
Definition scene.h:355
Ray::KeyFrameFile::filename
std::string filename
Definition scene.h:358
Ray::KeyFrameFile::keyFrameMatrices
KeyFrameMatrices keyFrameMatrices
Definition scene.h:361
Ray::LocalSceneData
Definition scene.h:62
Ray::LocalSceneData::keyFrameFile
KeyFrameFile * keyFrameFile
Definition scene.h:77
Ray::LocalSceneData::vertices
std::vector< Vertex > vertices
Definition scene.h:65
Ray::LocalSceneData::files
std::vector< File > files
Definition scene.h:74
Ray::LocalSceneData::LocalSceneData
LocalSceneData(void)
Definition scene.cpp:167
Ray::LocalSceneData::setCurrentTime
void setCurrentTime(double t, int curveFit)
Definition scene.cpp:171
Ray::LocalSceneData::materials
std::vector< Material > materials
Definition scene.h:68
Ray::LocalSceneData::textures
std::vector< Texture > textures
Definition scene.h:71
Ray::LocalSceneData::setKeyFrameEvaluator
void setKeyFrameEvaluator(void)
Definition scene.inl:7
Ray::LocalSceneData::~LocalSceneData
~LocalSceneData(void)
Definition scene.cpp:169
Ray::Material
Definition scene.h:249
Ray::Material::drawOpenGL
void drawOpenGL(GLSLProgram *glslProgram) const
Definition scene.todo.cpp:53
Ray::Material::tex
const Texture * tex
Definition scene.h:282
Ray::Material::ir
double ir
Definition scene.h:279
Ray::Material::ambient
Util::Point3D ambient
Definition scene.h:261
Ray::Material::File
friend class File
Definition scene.h:252
Ray::Material::SceneGeometry
friend SceneGeometry
Definition scene.h:250
Ray::Material::specularFallOff
double specularFallOff
Definition scene.h:276
Ray::Material::_texIndex
int _texIndex
Definition scene.h:258
Ray::Material::foo
std::string foo
Definition scene.h:285
Ray::Material::Material
Material(void)
Definition scene.cpp:256
Ray::Material::diffuse
Util::Point3D diffuse
Definition scene.h:264
Ray::Material::Scene
friend Scene
Definition scene.h:251
Ray::Material::operator>>
friend std::istream & operator>>(std::istream &, Material &)
Ray::Material::operator<<
friend std::ostream & operator<<(std::ostream &, const Material &)
Ray::Material::transparent
Util::Point3D transparent
Definition scene.h:273
Ray::Material::specular
Util::Point3D specular
Definition scene.h:267
Ray::Material::emissive
Util::Point3D emissive
Definition scene.h:270
Ray::RayShapeIntersectionInfo::t
double t
Definition scene.h:229
Ray::RayShapeIntersectionInfo::normal
Util::Point3D normal
Definition scene.h:235
Ray::RayShapeIntersectionInfo::RayShapeIntersectionInfo
RayShapeIntersectionInfo(void)
Definition scene.cpp:79
Ray::RayShapeIntersectionInfo::operator<
bool operator<(const RayShapeIntersectionInfo &iInfo) const
Definition scene.cpp:81
Ray::RayShapeIntersectionInfo::position
Util::Point3D position
Definition scene.h:232
Ray::RayShapeIntersectionInfo::texture
Util::Point2D texture
Definition scene.h:238
Ray::SceneGeometry
Definition scene.h:101
Ray::SceneGeometry::_write
void _write(std::ostream &stream) const
Definition scene.cpp:431
Ray::SceneGeometry::_localData
LocalSceneData _localData
Definition scene.h:103
Ray::SceneGeometry::updateBoundingBox
void updateBoundingBox(void)
Definition scene.cpp:407
Ray::SceneGeometry::initOpenGL
void initOpenGL(void)
Definition scene.cpp:414
Ray::SceneGeometry::processOverlapping
void processOverlapping(const Filter &filter, const Kernel &kernel, ShapeProcessingInfo tInfo) const
Definition scene.cpp:470
Ray::SceneGeometry::setKeyFrameEvaluator
void setKeyFrameEvaluator(void)
Definition scene.inl:16
Ray::SceneGeometry::processAllIntersections
int processAllIntersections(const Util::Ray3D &ray, const Util::BoundingBox1D &range, const RayIntersectionFilter &rFilter, const RayIntersectionKernel &rKernel, ShapeProcessingInfo spInfo, unsigned int tIdx) const
Definition scene.cpp:379
Ray::SceneGeometry::setCurrentTime
void setCurrentTime(double t, int curveFit)
Definition scene.cpp:425
Ray::SceneGeometry::name
std::string name(void) const
Definition scene.h:126
Ray::SceneGeometry::processFirstIntersection
bool processFirstIntersection(const Util::Ray3D &ray, const Util::BoundingBox1D &range, const RayIntersectionFilter &rFilter, const RayIntersectionKernel &rKernel, ShapeProcessingInfo spInfo, unsigned int tIdx) const
Definition scene.cpp:374
Ray::SceneGeometry::_shapeList
ShapeList _shapeList
Definition scene.h:106
Ray::SceneGeometry::init
void init(void)
Definition scene.cpp:384
Ray::SceneGeometry::drawOpenGL
void drawOpenGL(GLSLProgram *glslProgram) const
Definition scene.cpp:370
Ray::SceneGeometry::isInside
bool isInside(Util::Point3D p) const
Definition scene.cpp:372
Ray::SceneGeometry::_read
void _read(std::istream &stream)
Definition scene.cpp:437
Ray::Scene
Definition scene.h:139
Ray::Scene::Reflect
static Util::Point3D Reflect(Util::Point3D v, Util::Point3D n)
Definition scene.todo.cpp:11
Ray::Scene::FileInstance
friend class FileInstance
Definition scene.h:141
Ray::Scene::drawOpenGL
void drawOpenGL(void) const
Definition scene.cpp:505
Ray::Scene::operator<<
friend std::ostream & operator<<(std::ostream &, const Scene &)
Ray::Scene::Window
friend class Window
Definition scene.h:140
Ray::Scene::_globalData
GlobalSceneData _globalData
Definition scene.h:146
Ray::Scene::Refract
static bool Refract(Util::Point3D v, Util::Point3D n, double ir, Util::Point3D &refract)
Definition scene.todo.cpp:20
Ray::Scene::operator>>
friend std::istream & operator>>(std::istream &, Scene &)
Ray::Scene::processFirstIntersection
bool processFirstIntersection(const Util::Ray3D &ray, const Util::BoundingBox1D &range, const RayIntersectionFilter &rFilter, const RayIntersectionKernel &rKernel, ShapeProcessingInfo spInfo, unsigned int tIdx) const
Definition scene.cpp:555
Ray::Scene::BaseDir
static std::string BaseDir
Definition scene.h:150
Ray::Scene::initOpenGL
void initOpenGL(void)
Definition scene.cpp:477
Ray::Scene::getColor
Util::Point3D getColor(Util::Ray3D ray, int rDepth, Util::Point3D cLimit, unsigned int lightSamples, bool binaryShadows, unsigned int tIdx)
Definition scene.todo.cpp:29
Ray::Scene::processAllIntersections
int processAllIntersections(const Util::Ray3D &ray, const Util::BoundingBox1D &range, const RayIntersectionFilter &rFilter, const RayIntersectionKernel &rKernel, ShapeProcessingInfo spInfo, unsigned int tIdx) const
Definition scene.cpp:560
Ray::Scene::rayTrace
Image::Image32 rayTrace(int width, int height, int rLimit, double cLimit, unsigned int lightSamples, bool binaryShadows, bool showProgress)
Definition scene.cpp:520
Ray::Shader
Definition scene.h:329
Ray::Shader::glslProgram
GLSLProgram * glslProgram
Definition scene.h:338
Ray::Shader::~Shader
~Shader(void)
Definition scene.cpp:302
Ray::Shader::vertexShaderFilename
std::string vertexShaderFilename
Definition scene.h:332
Ray::Shader::fragmentShaderFilename
std::string fragmentShaderFilename
Definition scene.h:335
Ray::Shader::Shader
Shader(void)
Definition scene.cpp:300
Ray::Shape
Definition shape.h:90
Ray::Shape::Kernel
std::function< void(const ShapeProcessingInfo &, const Shape &) > Kernel
Definition shape.h:163
Ray::Shape::RayIntersectionFilter
std::function< bool(double) > RayIntersectionFilter
Definition shape.h:164
Ray::Shape::RayIntersectionKernel
std::function< bool(const ShapeProcessingInfo &, const class RayShapeIntersectionInfo &) > RayIntersectionKernel
Definition shape.h:165
Ray::Shape::Filter
std::function< ShapeProcessingInfo::ProcessingType(const ShapeProcessingInfo &, const Shape &) > Filter
Definition shape.h:162
Ray::ShapeList
Definition shapeList.h:168
Ray::Texture
Definition scene.h:302
Ray::Texture::operator<<
friend std::ostream & operator<<(std::ostream &, const Texture &)
Ray::Texture::initOpenGL
void initOpenGL(void)
Definition scene.todo.cpp:67
Ray::Texture::_filename
std::string _filename
Definition scene.h:309
Ray::Texture::operator>>
friend std::istream & operator>>(std::istream &, Texture &)
Ray::Texture::Scene
friend Scene
Definition scene.h:303
Ray::Texture::_image
Image::Image32 _image
Definition scene.h:312
Ray::Texture::_openGLHandle
GLuint _openGLHandle
Definition scene.h:315
Ray::Texture::Material
friend Material
Definition scene.h:304
Ray::Vertex
Definition scene.h:203
Ray::Vertex::position
Util::Point3D position
Definition scene.h:206
Ray::Vertex::texCoordinate
Util::Point2D texCoordinate
Definition scene.h:212
Ray::Vertex::normal
Util::Point3D normal
Definition scene.h:209
Util::BaseFactory
Definition factory.h:12
geometry.h
GLuint
unsigned int GLuint
Definition glew.h:280
image.h
data
JSAMPIMAGE data
Definition jpeglib.h:945
keyFrames.h
light.h
Ray
Definition box.h:7
Ray::ReadShape
Shape * ReadShape(std::istream &stream, const std::unordered_map< std::string, BaseFactory< Shape > * > &shapeFactories)
Definition scene.cpp:57
Ray::UnreadDirective
void UnreadDirective(istream &stream, const string &directive)
Definition scene.cpp:49
Ray::KeyFrameMatrices
KeyFrameData< Util::Matrix4D > KeyFrameMatrices
Definition keyFrames.h:79
Ray::ReadDirective
string ReadDirective(istream &stream)
Definition scene.cpp:20
Ray::operator>>
std::istream & operator>>(std::istream &stream, Camera &camera)
Definition camera.cpp:15
Ray::operator<<
std::ostream & operator<<(std::ostream &stream, const Camera &camera)
Definition camera.cpp:25
Util::Point3D
Point< 3 > Point3D
Definition geometry.h:526
Util::BoundingBox1D
BoundingBox< 1 > BoundingBox1D
Definition geometry.h:568
Util::Ray3D
Ray< 3 > Ray3D
Definition geometry.h:562
Util::Point2D
Point< 2 > Point2D
Definition geometry.h:523
scene.inl
shape.h
shapeList.h
Ray::Shape::ShapeProcessingInfo
Definition shape.h:148