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
21inline 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
34inline 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
49namespace Ray
50{
51 /*** This is a simple class defining globally accessible variables. (Feel free to add more as needed.) */
53 {
54 static bool DebugFlag;
55 };
56
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
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:
102
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
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
Definition GLSLProgram.h:33
Definition scene.h:62
Definition scene.h:249
Definition scene.h:223
Definition shape.h:90
std::function< void(const ShapeProcessingInfo &, const Shape &) > Kernel
Definition shape.h:163
size_t primitiveNum(void) const
Definition shape.cpp:32
ShapeBoundingBox boundingBox(void) const
Definition shape.cpp:30
ShapeBoundingBox _bBox
Definition shape.h:101
virtual void initOpenGL(void)=0
virtual void init(const class LocalSceneData &data)=0
std::function< bool(double) > RayIntersectionFilter
Definition shape.h:164
virtual std::string name(void) const =0
virtual void _write(std::ostream &stream) const =0
virtual int processAllIntersections(const Util::Ray3D &ray, const Util::BoundingBox1D &range, const RayIntersectionFilter &rFilter, const RayIntersectionKernel &rKernel, ShapeProcessingInfo spInfo, unsigned int tIdx) const =0
virtual bool isInside(Util::Point3D p) const =0
static void WriteInset(std::ostream &stream)
Definition shape.cpp:28
static unsigned int WriteInsetSize
Definition shape.h:111
std::function< bool(const ShapeProcessingInfo &, const class RayShapeIntersectionInfo &) > RayIntersectionKernel
Definition shape.h:165
virtual void _read(std::istream &stream)=0
virtual void drawOpenGL(GLSLProgram *glslProgram) const =0
friend std::istream & operator>>(std::istream &, Shape &)
Definition shape.h:186
virtual void updateBoundingBox(void)=0
std::function< ShapeProcessingInfo::ProcessingType(const ShapeProcessingInfo &, const Shape &) > Filter
Definition shape.h:162
virtual bool processFirstIntersection(const Util::Ray3D &ray, const Util::BoundingBox1D &range, const RayIntersectionFilter &rFilter, const RayIntersectionKernel &rKernel, ShapeProcessingInfo spInfo, unsigned int tIdx) const =0
friend std::ostream & operator<<(std::ostream &, const Shape &)
Definition shape.h:183
virtual void addTrianglesOpenGL(std::vector< class TriangleIndex > &triangles)
Definition shape.h:142
virtual ~Shape(void)
Definition shape.h:117
virtual void processOverlapping(const Filter &filter, const Kernel &kernel, ShapeProcessingInfo spInfo) const
Definition shape.cpp:41
size_t _primitiveNum
Definition shape.h:104
static unsigned int OpenGLTessellationComplexity
Definition shape.h:108
Definition geometry.h:345
Definition geometry.h:168
Definition geometry.h:299
unsigned int GLenum
Definition glew.h:278
#define GL_NO_ERROR
Definition glew.h:318
GLAPI GLenum GLAPIENTRY glGetError(void)
void exit(int)
JSAMPIMAGE data
Definition jpeglib.h:945
Definition box.h:7
std::istream & operator>>(std::istream &stream, Camera &camera)
Definition camera.cpp:15
std::ostream & operator<<(std::ostream &stream, const Camera &camera)
Definition camera.cpp:25
Definition algebra.h:7
std::string MakeMessageString(std::string header, std::string fileName, int line, std::string functionName, Arguments ... arguments)
Definition exceptions.h:60
void AssertOpenGLState(std::string functionName)
Definition shape.h:34
Definition shape.h:53
static bool DebugFlag
Definition shape.h:54
Definition shape.h:59
static size_t RayNum(void)
Definition shape.cpp:60
static void Reset(void)
Definition shape.cpp:54
static std::atomic< size_t > _RayNum
Definition shape.h:60
static void IncrementRayNum(unsigned int count=1)
Definition shape.cpp:55
static std::atomic< size_t > _ConeBoundingBoxIntersectionNum
Definition shape.h:63
static size_t RayBoundingBoxIntersectionNum(void)
Definition shape.cpp:62
static void IncrementRayPrimitiveIntersectionNum(unsigned int count=1)
Definition shape.cpp:56
static void IncrementConeBoundingBoxIntersectionNum(unsigned int count=1)
Definition shape.cpp:58
static std::atomic< size_t > _RayPrimitiveIntersectionNum
Definition shape.h:61
static size_t RayPrimitiveIntersectionNum(void)
Definition shape.cpp:61
static std::atomic< size_t > _RayBoundingBoxIntersectionNum
Definition shape.h:62
static void IncrementRayBoundingBoxIntersectionNum(unsigned int count=1)
Definition shape.cpp:57
static size_t ConeBoundingBoxIntersectionNum(void)
Definition shape.cpp:63
Definition shape.h:148
Util::Matrix4D localToGlobal
Definition shape.h:150
ShapeProcessingInfo(void)
Definition shape.cpp:34
Util::Matrix4D globalToLocal
Definition shape.h:150
Util::Matrix3D normalLocalToGlobal
Definition shape.h:151
const class Material * material
Definition shape.h:152
ProcessingType
Definition shape.h:155
@ NONE
Definition shape.h:156
@ PROPAGATE
Definition shape.h:157
@ TERMINATE
Definition shape.h:158
Util::Matrix3D directionGlobalToLocal
Definition shape.h:151
Definition shape.h:79
ShapeBoundingBox(void)
Definition shape.h:80
Util::BoundingBox1D intersect(const Util::Ray3D &ray) const
Definition shape.cpp:15
ShapeBoundingBox(const ShapeBoundingBox &bBox)
Definition shape.h:81
ShapeBoundingBox & operator=(const ShapeBoundingBox &bBox)
Definition shape.h:83
ShapeBoundingBox(const Util::BoundingBox3D &bBox)
Definition shape.h:82