Assignments Assignments

shape.h
Go to the documentation of this file.
1#ifndef SHAPE_INCLUDED
2#define SHAPE_INCLUDED
3#include <vector>
4#include <stdexcept>
5#include <string>
6#include <functional>
7#include <atomic>
8#include <Util/geometry.h>
9#include <Util/factory.h>
10#include <GL/glew.h>
11#pragma warning( disable : 4290 )
12#ifdef __APPLE__
13#include <GLUT/glut.h>
14#else // !__APPLE__
15#include <GL/glut.h>
16#endif // __APPLE__
17#include <Util/exceptions.h>
18#include "GLSLProgram.h"
19
20#ifdef VERBOSE_MESSAGING
21 inline void AssertOpenGLState( std::string fileName , int line , std::string functionName )
22{
23 GLenum errorCode;
24 if( ( errorCode=glGetError() )!=GL_NO_ERROR )
25 {
26 std::cerr << Util::MakeMessageString( "[OPEN_GL ERROR]" , fileName , line , functionName , gluErrorString( errorCode ) , " (" , errorCode , ")" ) << std::endl;
27 exit( 0 );
28 }
29}
30#ifndef ASSERT_OPEN_GL_STATE
31#define ASSERT_OPEN_GL_STATE( ... ) AssertOpenGLState( __FILE__ , __LINE__ , __FUNCTION__ )
32#endif // ASSERT_OPEN_GL_STATE
33#else // !VERBOSE_MESSAGING
34 inline void AssertOpenGLState( std::string functionName )
35{
36 GLenum errorCode;
37 if( ( errorCode=glGetError() )!=GL_NO_ERROR )
38 {
39 std::cerr << Util::MakeMessageString( "[OPEN_GL ERROR]" , functionName , gluErrorString( errorCode ) , " (" , errorCode , ")" ) << std::endl;
40 exit( 0 );
41 }
42}
43#ifndef ASSERT_OPEN_GL_STATE
44#define ASSERT_OPEN_GL_STATE( ... ) AssertOpenGLState( __FUNCTION__ )
45#endif // ASSERT_OPEN_GL_STATE
46#endif // VERBOSE_MESSAGING
47
48
49 namespace Ray
50{
51 /*** This is a simple class defining globally accessible variables. (Feel free to add more as needed.) */
52 struct GlobalProperties
53 {
54 static bool DebugFlag;
55 };
56
58 struct RayTracingStats
59 {
60 static std::atomic< size_t > _RayNum;
61 static std::atomic< size_t > _RayPrimitiveIntersectionNum;
62 static std::atomic< size_t > _RayBoundingBoxIntersectionNum;
63 static std::atomic< size_t > _ConeBoundingBoxIntersectionNum;
64 public:
65
66 static void Reset( void );
67 static void IncrementRayNum( unsigned int count=1 );
68 static void IncrementRayPrimitiveIntersectionNum( unsigned int count=1 );
69 static void IncrementRayBoundingBoxIntersectionNum( unsigned int count=1 );
70 static void IncrementConeBoundingBoxIntersectionNum( unsigned int count=1 );
71 static size_t RayNum( void );
72 static size_t RayPrimitiveIntersectionNum( void );
73 static size_t RayBoundingBoxIntersectionNum( void );
74 static size_t ConeBoundingBoxIntersectionNum( void );
75 };
76
78 struct ShapeBoundingBox : public Util::BoundingBox3D
79 {
80 ShapeBoundingBox( void ) : Util::BoundingBox3D() {};
81 ShapeBoundingBox( const ShapeBoundingBox &bBox ) : Util::BoundingBox3D( bBox ) {}
82 ShapeBoundingBox( const Util::BoundingBox3D &bBox ) : Util::BoundingBox3D( bBox ) {}
83 ShapeBoundingBox &operator = ( const ShapeBoundingBox &bBox ){ Util::BoundingBox3D::operator = ( bBox ) ; return *this; }
84 ShapeBoundingBox &operator = ( const Util::BoundingBox3D &bBox ){ Util::BoundingBox3D::operator = ( bBox ) ; return *this; }
85 Util::BoundingBox1D intersect( const Util::Ray3D &ray ) const;
86 };
87
89 class Shape
90 {
91 friend std::ostream &operator << ( std::ostream & , const Shape & );
92 friend std::istream &operator >> ( std::istream & , Shape & );
93
95 virtual void _write( std::ostream &stream ) const = 0;
96
98 virtual void _read( std::istream &stream ) = 0;
99 protected:
101 ShapeBoundingBox _bBox;
102
104 size_t _primitiveNum;
105
106 public:
108 static unsigned int OpenGLTessellationComplexity;
109
111 static unsigned int WriteInsetSize;
112
114 static void WriteInset( std::ostream &stream );
115
117 virtual ~Shape( void ){}
118
120 ShapeBoundingBox boundingBox( void ) const;
121
123 virtual void init( const class LocalSceneData& data ) = 0;
124
126 virtual void initOpenGL( void ) = 0;
127
129 virtual void updateBoundingBox( void ) = 0;
130
132 virtual std::string name( void ) const = 0;
133
136 virtual bool isInside( Util::Point3D p ) const = 0;
137
139 virtual void drawOpenGL( GLSLProgram *glslProgram ) const=0;
140
142 virtual void addTrianglesOpenGL( std::vector< class TriangleIndex > &triangles ) {}
143
145 size_t primitiveNum( void ) const;
146
147 struct ShapeProcessingInfo
148 {
149 ShapeProcessingInfo( void );
150 Util::Matrix4D localToGlobal , globalToLocal;
151 Util::Matrix3D directionGlobalToLocal , normalLocalToGlobal;
152 const class Material *material;
153
154 enum ProcessingType
155 {
156 NONE ,
157 PROPAGATE ,
158 TERMINATE
159 };
160 };
161
162 typedef std::function< ShapeProcessingInfo::ProcessingType ( const ShapeProcessingInfo & , const Shape & ) > Filter;
163 typedef std::function< void ( const ShapeProcessingInfo & , const Shape & ) > Kernel;
164 typedef std::function< bool ( double ) > RayIntersectionFilter;
165 typedef std::function< bool ( const ShapeProcessingInfo & , const class RayShapeIntersectionInfo & ) > RayIntersectionKernel;
166
170 virtual void processOverlapping( const Filter &filter , const Kernel &kernel , ShapeProcessingInfo spInfo ) const;
171
174 virtual bool processFirstIntersection( const Util::Ray3D &ray , const Util::BoundingBox1D &range , const RayIntersectionFilter &rFilter , const RayIntersectionKernel &rKernel , ShapeProcessingInfo spInfo , unsigned int tIdx ) const = 0;
175
179 virtual int processAllIntersections( const Util::Ray3D &ray , const Util::BoundingBox1D &range , const RayIntersectionFilter &rFilter , const RayIntersectionKernel &rKernel , ShapeProcessingInfo spInfo , unsigned int tIdx ) const = 0;
180 };
181
183 inline std::ostream &operator << ( std::ostream &stream , const Shape &shape ){ shape._write( stream ) ; return stream; }
184
186 inline std::istream &operator >> ( std::istream &stream , Shape &shape ){ shape._read( stream ) ; return stream; }
187}
188#endif // SHAPE_INCLUDED
GLSLProgram.h
GLSLProgram
Definition GLSLProgram.h:33
Ray::LocalSceneData
Definition scene.h:62
Ray::Material
Definition scene.h:249
Ray::RayShapeIntersectionInfo
Definition scene.h:223
Ray::Shape
Definition shape.h:90
Ray::Shape::Kernel
std::function< void(const ShapeProcessingInfo &, const Shape &) > Kernel
Definition shape.h:163
Ray::Shape::primitiveNum
size_t primitiveNum(void) const
Definition shape.cpp:32
Ray::Shape::boundingBox
ShapeBoundingBox boundingBox(void) const
Definition shape.cpp:30
Ray::Shape::_bBox
ShapeBoundingBox _bBox
Definition shape.h:101
Ray::Shape::initOpenGL
virtual void initOpenGL(void)=0
Ray::Shape::init
virtual void init(const class LocalSceneData &data)=0
Ray::Shape::RayIntersectionFilter
std::function< bool(double) > RayIntersectionFilter
Definition shape.h:164
Ray::Shape::name
virtual std::string name(void) const =0
Ray::Shape::_write
virtual void _write(std::ostream &stream) const =0
Ray::Shape::processAllIntersections
virtual int processAllIntersections(const Util::Ray3D &ray, const Util::BoundingBox1D &range, const RayIntersectionFilter &rFilter, const RayIntersectionKernel &rKernel, ShapeProcessingInfo spInfo, unsigned int tIdx) const =0
Ray::Shape::isInside
virtual bool isInside(Util::Point3D p) const =0
Ray::Shape::WriteInset
static void WriteInset(std::ostream &stream)
Definition shape.cpp:28
Ray::Shape::WriteInsetSize
static unsigned int WriteInsetSize
Definition shape.h:111
Ray::Shape::RayIntersectionKernel
std::function< bool(const ShapeProcessingInfo &, const class RayShapeIntersectionInfo &) > RayIntersectionKernel
Definition shape.h:165
Ray::Shape::_read
virtual void _read(std::istream &stream)=0
Ray::Shape::drawOpenGL
virtual void drawOpenGL(GLSLProgram *glslProgram) const =0
Ray::Shape::operator>>
friend std::istream & operator>>(std::istream &, Shape &)
Definition shape.h:186
Ray::Shape::updateBoundingBox
virtual void updateBoundingBox(void)=0
Ray::Shape::Filter
std::function< ShapeProcessingInfo::ProcessingType(const ShapeProcessingInfo &, const Shape &) > Filter
Definition shape.h:162
Ray::Shape::processFirstIntersection
virtual bool processFirstIntersection(const Util::Ray3D &ray, const Util::BoundingBox1D &range, const RayIntersectionFilter &rFilter, const RayIntersectionKernel &rKernel, ShapeProcessingInfo spInfo, unsigned int tIdx) const =0
Ray::Shape::operator<<
friend std::ostream & operator<<(std::ostream &, const Shape &)
Definition shape.h:183
Ray::Shape::addTrianglesOpenGL
virtual void addTrianglesOpenGL(std::vector< class TriangleIndex > &triangles)
Definition shape.h:142
Ray::Shape::~Shape
virtual ~Shape(void)
Definition shape.h:117
Ray::Shape::processOverlapping
virtual void processOverlapping(const Filter &filter, const Kernel &kernel, ShapeProcessingInfo spInfo) const
Definition shape.cpp:41
Ray::Shape::_primitiveNum
size_t _primitiveNum
Definition shape.h:104
Ray::Shape::OpenGLTessellationComplexity
static unsigned int OpenGLTessellationComplexity
Definition shape.h:108
exceptions.h
factory.h
geometry.h
glew.h
GLenum
unsigned int GLenum
Definition glew.h:278
GL_NO_ERROR
#define GL_NO_ERROR
Definition glew.h:318
glGetError
GLAPI GLenum GLAPIENTRY glGetError(void)
glut.h
exit
void exit(int)
data
JSAMPIMAGE data
Definition jpeglib.h:945
Ray
Definition box.h:7
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
Definition algebra.h:7
Util::Matrix3D
Matrix< 3, 3 > Matrix3D
Definition geometry.h:541
Util::BoundingBox3D
BoundingBox< 3 > BoundingBox3D
Definition geometry.h:574
Util::Matrix4D
Matrix< 4, 4 > Matrix4D
Definition geometry.h:544
Util::MakeMessageString
std::string MakeMessageString(std::string header, std::string fileName, int line, std::string functionName, Arguments ... arguments)
Definition exceptions.h:60
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
AssertOpenGLState
void AssertOpenGLState(std::string functionName)
Definition shape.h:34
Ray::GlobalProperties
Definition shape.h:53
Ray::GlobalProperties::DebugFlag
static bool DebugFlag
Definition shape.h:54
Ray::RayTracingStats
Definition shape.h:59
Ray::RayTracingStats::RayNum
static size_t RayNum(void)
Definition shape.cpp:60
Ray::RayTracingStats::Reset
static void Reset(void)
Definition shape.cpp:54
Ray::RayTracingStats::_RayNum
static std::atomic< size_t > _RayNum
Definition shape.h:60
Ray::RayTracingStats::IncrementRayNum
static void IncrementRayNum(unsigned int count=1)
Definition shape.cpp:55
Ray::RayTracingStats::_ConeBoundingBoxIntersectionNum
static std::atomic< size_t > _ConeBoundingBoxIntersectionNum
Definition shape.h:63
Ray::RayTracingStats::RayBoundingBoxIntersectionNum
static size_t RayBoundingBoxIntersectionNum(void)
Definition shape.cpp:62
Ray::RayTracingStats::IncrementRayPrimitiveIntersectionNum
static void IncrementRayPrimitiveIntersectionNum(unsigned int count=1)
Definition shape.cpp:56
Ray::RayTracingStats::IncrementConeBoundingBoxIntersectionNum
static void IncrementConeBoundingBoxIntersectionNum(unsigned int count=1)
Definition shape.cpp:58
Ray::RayTracingStats::_RayPrimitiveIntersectionNum
static std::atomic< size_t > _RayPrimitiveIntersectionNum
Definition shape.h:61
Ray::RayTracingStats::RayPrimitiveIntersectionNum
static size_t RayPrimitiveIntersectionNum(void)
Definition shape.cpp:61
Ray::RayTracingStats::_RayBoundingBoxIntersectionNum
static std::atomic< size_t > _RayBoundingBoxIntersectionNum
Definition shape.h:62
Ray::RayTracingStats::IncrementRayBoundingBoxIntersectionNum
static void IncrementRayBoundingBoxIntersectionNum(unsigned int count=1)
Definition shape.cpp:57
Ray::RayTracingStats::ConeBoundingBoxIntersectionNum
static size_t ConeBoundingBoxIntersectionNum(void)
Definition shape.cpp:63
Ray::Shape::ShapeProcessingInfo
Definition shape.h:148
Ray::Shape::ShapeProcessingInfo::localToGlobal
Util::Matrix4D localToGlobal
Definition shape.h:150
Ray::Shape::ShapeProcessingInfo::ShapeProcessingInfo
ShapeProcessingInfo(void)
Definition shape.cpp:34
Ray::Shape::ShapeProcessingInfo::globalToLocal
Util::Matrix4D globalToLocal
Definition shape.h:150
Ray::Shape::ShapeProcessingInfo::normalLocalToGlobal
Util::Matrix3D normalLocalToGlobal
Definition shape.h:151
Ray::Shape::ShapeProcessingInfo::material
const class Material * material
Definition shape.h:152
Ray::Shape::ShapeProcessingInfo::ProcessingType
ProcessingType
Definition shape.h:155
Ray::Shape::ShapeProcessingInfo::NONE
@ NONE
Definition shape.h:156
Ray::Shape::ShapeProcessingInfo::PROPAGATE
@ PROPAGATE
Definition shape.h:157
Ray::Shape::ShapeProcessingInfo::TERMINATE
@ TERMINATE
Definition shape.h:158
Ray::Shape::ShapeProcessingInfo::directionGlobalToLocal
Util::Matrix3D directionGlobalToLocal
Definition shape.h:151
Ray::ShapeBoundingBox
Definition shape.h:79
Ray::ShapeBoundingBox::ShapeBoundingBox
ShapeBoundingBox(void)
Definition shape.h:80
Ray::ShapeBoundingBox::intersect
Util::BoundingBox1D intersect(const Util::Ray3D &ray) const
Definition shape.cpp:15
Ray::ShapeBoundingBox::ShapeBoundingBox
ShapeBoundingBox(const ShapeBoundingBox &bBox)
Definition shape.h:81
Ray::ShapeBoundingBox::operator=
ShapeBoundingBox & operator=(const ShapeBoundingBox &bBox)
Definition shape.h:83
Ray::ShapeBoundingBox::ShapeBoundingBox
ShapeBoundingBox(const Util::BoundingBox3D &bBox)
Definition shape.h:82