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 <Util/geometry.h>
8#include <Util/factory.h>
9#include <GL/glew.h>
10#pragma warning( disable : 4290 )
11#ifdef __APPLE__
12#include <GLUT/glut.h>
13#else // !__APPLE__
14#include <GL/glut.h>
15#endif // __APPLE__
16#include <Util/exceptions.h>
17#include "GLSLProgram.h"
18
19#ifdef VERBOSE_MESSAGING
20inline void AssertOpenGLState( std::string fileName , int line , std::string functionName )
21{
22 GLenum errorCode;
23 if( ( errorCode=glGetError() )!=GL_NO_ERROR )
24 {
25 std::cerr << Util::MakeMessageString( "[OPEN_GL ERROR]" , fileName , line , functionName , gluErrorString( errorCode ) , " (" , errorCode , ")" ) << std::endl;
26 exit( 0 );
27 }
28}
29#ifndef ASSERT_OPEN_GL_STATE
30#define ASSERT_OPEN_GL_STATE( ... ) AssertOpenGLState( __FILE__ , __LINE__ , __FUNCTION__ )
31#endif // ASSERT_OPEN_GL_STATE
32#else // !VERBOSE_MESSAGING
33inline void AssertOpenGLState( std::string functionName )
34{
35 GLenum errorCode;
36 if( ( errorCode=glGetError() )!=GL_NO_ERROR )
37 {
38 std::cerr << Util::MakeMessageString( "[OPEN_GL ERROR]" , functionName , gluErrorString( errorCode ) , " (" , errorCode , ")" ) << std::endl;
39 exit( 0 );
40 }
41}
42#ifndef ASSERT_OPEN_GL_STATE
43#define ASSERT_OPEN_GL_STATE( ... ) AssertOpenGLState( __FUNCTION__ )
44#endif // ASSERT_OPEN_GL_STATE
45#endif // VERBOSE_MESSAGING
46
47
48namespace Ray
49{
50 /*** This is a simple class defining globally accessible variables. (Feel free to add more as needed.) */
52 {
53 static bool DebugFlag;
54 };
55
58 {
59 static std::atomic< size_t > _RayNum;
60 static std::atomic< size_t > _RayPrimitiveIntersectionNum;
61 static std::atomic< size_t > _RayBoundingBoxIntersectionNum;
62 static std::atomic< size_t > _ConeBoundingBoxIntersectionNum;
63 public:
64
65 static void Reset( void );
66 static void IncrementRayNum( unsigned int count=1 );
67 static void IncrementRayPrimitiveIntersectionNum( unsigned int count=1 );
68 static void IncrementRayBoundingBoxIntersectionNum( unsigned int count=1 );
69 static void IncrementConeBoundingBoxIntersectionNum( unsigned int count=1 );
70 static size_t RayNum( void );
71 static size_t RayPrimitiveIntersectionNum( void );
72 static size_t RayBoundingBoxIntersectionNum( void );
73 static size_t ConeBoundingBoxIntersectionNum( void );
74 };
75
78 {
82 ShapeBoundingBox &operator = ( const ShapeBoundingBox &bBox ){ Util::BoundingBox3D::operator = ( bBox ) ; return *this; }
83 ShapeBoundingBox &operator = ( const Util::BoundingBox3D &bBox ){ Util::BoundingBox3D::operator = ( bBox ) ; return *this; }
84 Util::BoundingBox1D intersect( const Util::Ray3D &ray ) const;
85 };
86
88 class Shape
89 {
90 friend std::ostream &operator << ( std::ostream & , const Shape & );
91 friend std::istream &operator >> ( std::istream & , Shape & );
92
94 virtual void _write( std::ostream &stream ) const = 0;
95
97 virtual void _read( std::istream &stream ) = 0;
98 protected:
101
104
105 public:
107 static unsigned int OpenGLTessellationComplexity;
108
110 static unsigned int WriteInsetSize;
111
113 static void WriteInset( std::ostream &stream );
114
116 virtual ~Shape( void ){}
117
119 ShapeBoundingBox boundingBox( void ) const;
120
122 virtual void init( const class LocalSceneData& data ) = 0;
123
125 virtual void initOpenGL( void ) = 0;
126
128 virtual void updateBoundingBox( void ) = 0;
129
131 virtual std::string name( void ) const = 0;
132
135 virtual bool isInside( Util::Point3D p ) const = 0;
136
138 virtual void drawOpenGL( GLSLProgram *glslProgram ) const=0;
139
141 virtual void addTrianglesOpenGL( std::vector< class TriangleIndex > &triangles ) {}
142
144 size_t primitiveNum( void ) const;
145
147 {
148 ShapeProcessingInfo( void );
151 const class Material *material;
152
154 {
158 };
159 };
160
161 typedef std::function< ShapeProcessingInfo::ProcessingType ( const ShapeProcessingInfo & , const Shape & ) > Filter;
162 typedef std::function< void ( const ShapeProcessingInfo & , const Shape & ) > Kernel;
163 typedef std::function< bool ( double ) > RayIntersectionFilter;
164 typedef std::function< void ( const ShapeProcessingInfo & , const class RayShapeIntersectionInfo & ) > RayIntersectionKernel;
165
169 virtual void processOverlapping( const Filter &filter , const Kernel &kernel , ShapeProcessingInfo spInfo ) const;
170
173 virtual bool processFirstIntersection( const Util::Ray3D &ray , const Util::BoundingBox1D &range , const RayIntersectionFilter &rFilter , const RayIntersectionKernel &rKernel , ShapeProcessingInfo spInfo , unsigned int tIdx ) const = 0;
174
178 virtual int processAllIntersections( const Util::Ray3D &ray , const Util::BoundingBox1D &range , const RayIntersectionFilter &rFilter , const RayIntersectionKernel &rKernel , ShapeProcessingInfo spInfo , unsigned int tIdx ) const = 0;
179 };
180
182 inline std::ostream &operator << ( std::ostream &stream , const Shape &shape ){ shape._write( stream ) ; return stream; }
183
185 inline std::istream &operator >> ( std::istream &stream , Shape &shape ){ shape._read( stream ) ; return stream; }
186}
187#endif // SHAPE_INCLUDED
Definition: GLSLProgram.h:33
Definition: scene.h:62
Definition: scene.h:249
Definition: scene.h:223
Definition: shape.h:89
std::function< void(const ShapeProcessingInfo &, const Shape &) > Kernel
Definition: shape.h:162
size_t primitiveNum(void) const
Definition: shape.cpp:32
ShapeBoundingBox boundingBox(void) const
Definition: shape.cpp:30
ShapeBoundingBox _bBox
Definition: shape.h:100
virtual void initOpenGL(void)=0
virtual void init(const class LocalSceneData &data)=0
std::function< bool(double) > RayIntersectionFilter
Definition: shape.h:163
virtual std::string name(void) const =0
virtual void _write(std::ostream &stream) const =0
friend std::istream & operator>>(std::istream &, Shape &)
Definition: shape.h:185
friend std::ostream & operator<<(std::ostream &, const Shape &)
Definition: shape.h:182
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:110
virtual void _read(std::istream &stream)=0
virtual void drawOpenGL(GLSLProgram *glslProgram) const =0
virtual void updateBoundingBox(void)=0
std::function< ShapeProcessingInfo::ProcessingType(const ShapeProcessingInfo &, const Shape &) > Filter
Definition: shape.h:161
virtual bool processFirstIntersection(const Util::Ray3D &ray, const Util::BoundingBox1D &range, const RayIntersectionFilter &rFilter, const RayIntersectionKernel &rKernel, ShapeProcessingInfo spInfo, unsigned int tIdx) const =0
virtual void addTrianglesOpenGL(std::vector< class TriangleIndex > &triangles)
Definition: shape.h:141
std::function< void(const ShapeProcessingInfo &, const class RayShapeIntersectionInfo &) > RayIntersectionKernel
Definition: shape.h:164
virtual ~Shape(void)
Definition: shape.h:116
virtual void processOverlapping(const Filter &filter, const Kernel &kernel, ShapeProcessingInfo spInfo) const
Definition: shape.cpp:41
size_t _primitiveNum
Definition: shape.h:103
static unsigned int OpenGLTessellationComplexity
Definition: shape.h:107
Definition: geometry.h:345
Definition: geometry.h:168
Definition: geometry.h:299
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
BoundingBox< 3 > BoundingBox3D
Definition: geometry.h:577
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:33
Definition: shape.h:52
static bool DebugFlag
Definition: shape.h:53
Definition: shape.h:58
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:59
static void IncrementRayNum(unsigned int count=1)
Definition: shape.cpp:55
static std::atomic< size_t > _ConeBoundingBoxIntersectionNum
Definition: shape.h:62
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:60
static size_t RayPrimitiveIntersectionNum(void)
Definition: shape.cpp:61
static std::atomic< size_t > _RayBoundingBoxIntersectionNum
Definition: shape.h:61
static void IncrementRayBoundingBoxIntersectionNum(unsigned int count=1)
Definition: shape.cpp:57
static size_t ConeBoundingBoxIntersectionNum(void)
Definition: shape.cpp:63
Definition: shape.h:147
Util::Matrix4D localToGlobal
Definition: shape.h:149
ShapeProcessingInfo(void)
Definition: shape.cpp:34
Util::Matrix4D globalToLocal
Definition: shape.h:149
Util::Matrix3D normalLocalToGlobal
Definition: shape.h:150
const class Material * material
Definition: shape.h:151
ProcessingType
Definition: shape.h:154
@ NONE
Definition: shape.h:155
@ PROPAGATE
Definition: shape.h:156
@ TERMINATE
Definition: shape.h:157
Util::Matrix3D directionGlobalToLocal
Definition: shape.h:150
Definition: shape.h:78
ShapeBoundingBox(void)
Definition: shape.h:79
Util::BoundingBox1D intersect(const Util::Ray3D &ray) const
Definition: shape.cpp:15
ShapeBoundingBox(const ShapeBoundingBox &bBox)
Definition: shape.h:80
ShapeBoundingBox & operator=(const ShapeBoundingBox &bBox)
Definition: shape.h:82
ShapeBoundingBox(const Util::BoundingBox3D &bBox)
Definition: shape.h:81