Subversion Repositories gelsvn

Rev

Rev 631 | Rev 663 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 631 Rev 647
Line 11... Line 11...
11
#ifndef __MESHEDIT_RENDERER_H__
11
#ifndef __MESHEDIT_RENDERER_H__
12
#define __MESHEDIT_RENDERER_H__
12
#define __MESHEDIT_RENDERER_H__
13
 
13
 
14
#include "../CGLA/Vec2d.h"
14
#include "../CGLA/Vec2d.h"
15
#include "../GL/glew.h"
15
#include "../GL/glew.h"
-
 
16
#include "../HMesh/harmonics.h"
16
#include "../GLGraphics/draw.h"
17
#include "../GLGraphics/draw.h"
-
 
18
#include "../GLGraphics/Console.h"
17
#include "../GLGraphics/IDBufferWireFrameRenderer.h"
19
#include "../GLGraphics/IDBufferWireFrameRenderer.h"
18
#include "../CGLA/Vec4d.h"
20
#include "../CGLA/Vec4d.h"
19
 
21
 
20
namespace HMesh
22
namespace HMesh
21
{
23
{
22
    template<typename ITEM>
24
    template<typename ITEM>
23
    class VertexAttributeVector;
25
    class VertexAttributeVector;
24
}
26
}
25
 
27
 
26
namespace GLGraphics {
28
namespace GLGraphics {
27
 
29
    
28
/** Ancestral class for Manifold rendering. Do not use directly. Its only purpose is to
30
    /** Ancestral class for Manifold rendering. Do not use directly. Its only purpose is to
29
	create a display list and remove it when the object is destroyed. This is an example
31
     create a display list and remove it when the object is destroyed. This is an example
30
	of the RAII "resource acquisition is initialization" idiom */
32
     of the RAII "resource acquisition is initialization" idiom */
31
class ManifoldRenderer
33
    class ManifoldRenderer
32
	{
34
	{
33
	protected:
35
	protected:
34
		GLuint display_list;
36
		GLuint display_list;
35
	public:
37
	public:
36
		ManifoldRenderer(): display_list(glGenLists(1))	{}
38
		ManifoldRenderer(): display_list(glGenLists(1))	{}
37
		virtual ~ManifoldRenderer()
39
		virtual ~ManifoldRenderer()
38
		{
40
		{
39
			glDeleteLists(display_list, 1);
41
			glDeleteLists(display_list, 1);
40
		}
42
		}
-
 
43
        /// Produce a display list containing geometry and normals (which may be smooth or per face).
-
 
44
		virtual void compile_display_list(const HMesh::Manifold& m, bool smooth) {}
-
 
45
 
41
		virtual void draw()
46
		virtual void draw()
42
		{
47
		{
43
			glCallList(display_list);
48
			glCallList(display_list);
44
		}
49
		}
45
	};
50
	};
46
 
51
    
47
 
52
    
48
/** Wireframe rendering. This is a nasty complex class that relies on other classes. The trouble
53
    /** Wireframe rendering. This is a nasty complex class that relies on other classes. The trouble
49
	is that for non-triangle meshes, we need to use another approach than for triangle meshes.
54
     is that for non-triangle meshes, we need to use another approach than for triangle meshes.
50
	This class is really a front end for a couple of other classes. */
55
     This class is really a front end for a couple of other classes. */
51
class WireframeRenderer: public ManifoldRenderer
56
    class WireframeRenderer: public ManifoldRenderer
52
	{
57
	{
53
		GLGraphics::IDBufferWireframeRenderer* idbuff_renderer;
58
		GLGraphics::IDBufferWireframeRenderer* idbuff_renderer;
54
		
59
		
55
		int maximum_face_valency(const HMesh::Manifold& m);
60
		int maximum_face_valency(const HMesh::Manifold& m);
56
		
61
		
Line 62... Line 67...
62
		
67
		
63
		WireframeRenderer(HMesh::Manifold& m, bool flat);
68
		WireframeRenderer(HMesh::Manifold& m, bool flat);
64
		
69
		
65
		void draw();
70
		void draw();
66
	};
71
	};
67
 
72
    
68
/** SimpleShaderRenderer is a very basic class for drawing a Manifold with shading.
73
    /** SimpleShaderRenderer is a very basic class for drawing a Manifold with shading.
69
	It is a convenient way to draw a surface using vertex and fragment shaders since it takes
74
     It is a convenient way to draw a surface using vertex and fragment shaders since it takes
70
	care of initializing the shaders and producing a display list for the geometry. 
75
     care of initializing the shaders and producing a display list for the geometry.
71
 
76
     
72
	Geometry shaders typically add more complexity and are left out of this class, so you cannot add a
77
     Geometry shaders typically add more complexity and are left out of this class, so you cannot add a
73
	geometry shader.
78
     geometry shader.
74
	
79
     
75
	While this class can be used directly, the normal procedure is to inherit from SimpleShaderRenderer
80
     While this class can be used directly, the normal procedure is to inherit from SimpleShaderRenderer
76
	and then pass the shaders to the constructor. The strings defining the shaders would fit
81
     and then pass the shaders to the constructor. The strings defining the shaders would fit
77
	nicely as static constant strings (see e.g. ToonRenderer or GlazedRenderer) in your inherited class.
82
     nicely as static constant strings (see e.g. ToonRenderer or GlazedRenderer) in your inherited class.
78
 
83
     
79
	If you need to define more attributes or uniforms, you need to take charge. Your inherited class's 
84
     If you need to define more attributes or uniforms, you need to take charge. Your inherited class's
80
	constructor should then use the default constructor of SimpleShaderRenderer. You can call init_shaders
85
     constructor should then use the default constructor of SimpleShaderRenderer. You can call init_shaders
81
	to initialize the shaders and then compile the display list yourself with the needed uniforms and
86
     to initialize the shaders and then compile the display list yourself with the needed uniforms and
82
	attributes - rather than calling compile_display_list which only puts vertices and normals in the list. 
87
     attributes - rather than calling compile_display_list which only puts vertices and normals in the list.
83
 */
88
     */
84
class SimpleShaderRenderer: public ManifoldRenderer
89
    class SimpleShaderRenderer: public ManifoldRenderer
85
	{
90
	{
86
		/// Compile the vertex and fragment shaders and link to form shader program.
91
		/// Compile the vertex and fragment shaders and link to form shader program.
87
		void init_shaders(const std::string& vss, 
92
		void init_shaders(const std::string& vss,
88
						  const std::string& fss);
93
						  const std::string& fss);
89
		
94
		
90
		/// Produce a display list containing geometry and normals (which may be smooth or per face).
-
 
91
		void compile_display_list(const HMesh::Manifold& m, bool smooth);
-
 
92
 
95
        
93
	protected:
96
	protected:
94
 
97
        
95
		GLuint prog,vs,fs;
98
		GLuint prog,vs,fs;
96
 
99
        
97
	public:
100
	public:
98
		
-
 
99
		/// This constructor simply calls init_shaders and then compile_display_list.
-
 
100
		SimpleShaderRenderer(const HMesh::Manifold& m, 
-
 
101
							bool smooth, 
-
 
102
							const std::string& vss, 
-
 
103
							const std::string& fss)
-
 
104
		{
101
				
105
			init_shaders(vss,fss);
-
 
106
			compile_display_list(m, smooth);
-
 
107
		}
-
 
108
		
-
 
109
		/** This constructor simply initializes the shaders. It does not create the display list.
102
		/** This constructor simply initializes the shaders. It does not create the display list.
110
			Use if you shader has extra attributes. */
103
         Use if you shader has extra attributes. */
111
		SimpleShaderRenderer(const std::string& vss, 
104
		SimpleShaderRenderer(const std::string& vss,
112
							 const std::string& fss) {init_shaders(vss,fss);}
105
							 const std::string& fss) {init_shaders(vss,fss);}
113
		
106
		
-
 
107
		/// Produce a display list containing geometry and normals (which may be smooth or per face).
-
 
108
		virtual void compile_display_list(const HMesh::Manifold& m, bool smooth);
-
 
109
 
114
		/// Releases the program and shaders.
110
		/// Releases the program and shaders.
115
		~SimpleShaderRenderer()
111
		~SimpleShaderRenderer()
116
		{
112
		{
117
			glDeleteProgram(prog);
113
			glDeleteProgram(prog);
118
			glDeleteShader(vs);
114
			glDeleteShader(vs);
119
			glDeleteShader(fs);
115
			glDeleteShader(fs);
120
		}
116
		}
121
		
117
		
122
		/// Do the actual drawing. Simply calls the display list if this function is not overloaded.
118
		/// Do the actual drawing. Simply calls the display list if this function is not overloaded.
123
		virtual void draw();
119
		virtual void draw();
124
	
120
        
125
	};
121
	};
126
 
122
    
127
/** Ugly basic gouraud rendering. This class uses OpenGL's fixed function pipeline. */
123
    /** Ugly basic gouraud rendering. This class uses OpenGL's fixed function pipeline. */
128
class NormalRenderer: public SimpleShaderRenderer
124
    class NormalRenderer: public SimpleShaderRenderer
129
{
125
    {
130
    const static std::string vss;
126
        const static std::string vss;
131
    const static std::string fss;
127
        const static std::string fss;
132
 
128
        
133
public:
129
    public:
134
    NormalRenderer(const HMesh::Manifold& m, bool smooth):
130
        NormalRenderer():
135
    SimpleShaderRenderer(m, smooth, vss, fss) {}
131
        SimpleShaderRenderer(vss, fss) {}
136
};
132
    };
137
 
133
    
-
 
134
    /** Debug renderer. Color code faces and show vertices as balls.*/
-
 
135
    class DebugRenderer: public SimpleShaderRenderer
-
 
136
    {
-
 
137
        const static std::string vss;
-
 
138
        const static std::string fss;
-
 
139
        
-
 
140
    public:
-
 
141
        static HMesh::VertexAttributeVector<CGLA::Vec3f> vertex_colors;
-
 
142
        static HMesh::FaceAttributeVector<CGLA::Vec3f> face_colors;
-
 
143
        static HMesh::HalfEdgeAttributeVector<CGLA::Vec3f> edge_colors;
-
 
144
    public:
-
 
145
        DebugRenderer(): SimpleShaderRenderer(vss, fss) {}
-
 
146
        void compile_display_list(const HMesh::Manifold& m, bool smooth);
-
 
147
        
-
 
148
    };
138
 
149
    
139
/** Render reflection lines. This class renders the object as if it is specular and inside
150
    /** Render reflection lines. This class renders the object as if it is specular and inside
140
	an infinitely long, vertical cylinder with white strips (also vertical). Useful if you
151
     an infinitely long, vertical cylinder with white strips (also vertical). Useful if you
141
	want to see whether the surface is smooth or has kinks. */
152
     want to see whether the surface is smooth or has kinks. */
142
class ReflectionLineRenderer: public SimpleShaderRenderer
153
    class ReflectionLineRenderer: public SimpleShaderRenderer
143
	{
154
	{
144
		const static std::string vss;
155
		const static std::string vss;
145
		const static std::string fss;
156
		const static std::string fss;
146
	public:
157
	public:
147
		ReflectionLineRenderer(const HMesh::Manifold& m, bool smooth):
158
		ReflectionLineRenderer(): SimpleShaderRenderer(vss, fss) {}
148
			SimpleShaderRenderer(m, smooth, vss, fss) {}
-
 
149
		
-
 
150
	};
-
 
151
 
159
 
-
 
160
	};
-
 
161
    
152
/** Render isophotes with respect to a lightsource in the eye. Useful if you
162
    /** Render isophotes with respect to a lightsource in the eye. Useful if you
153
 want to see whether the surface is smooth or has kinks. */
163
     want to see whether the surface is smooth or has kinks. */
154
class IsophoteLineRenderer: public SimpleShaderRenderer
164
    class IsophoteLineRenderer: public SimpleShaderRenderer
155
	{
165
	{
156
		const static std::string vss;
166
		const static std::string vss;
157
		const static std::string fss;
167
		const static std::string fss;
158
	public:
168
	public:
159
		IsophoteLineRenderer(const HMesh::Manifold& m, bool smooth):
169
		IsophoteLineRenderer(): SimpleShaderRenderer(vss, fss) {}
160
		SimpleShaderRenderer(m, smooth, vss, fss) {}
-
 
161
		
170
		
162
	};
171
	};
163
 
172
    
164
/** The toon renderer simply quantizes the shading to give a toonish appearance
173
    /** The toon renderer simply quantizes the shading to give a toonish appearance
165
	with a fat black silhouette. */
174
     with a fat black silhouette. */
166
 
175
    
167
class ToonRenderer: public SimpleShaderRenderer
176
    class ToonRenderer: public SimpleShaderRenderer
168
	{
177
	{
169
		const static std::string vss;
178
		const static std::string vss;
170
		const static std::string fss;
179
		const static std::string fss;
171
	public:
180
	public:
172
		ToonRenderer(const HMesh::Manifold& m, bool smooth):
-
 
173
		SimpleShaderRenderer(m, smooth, vss, fss) {}
181
		ToonRenderer(): SimpleShaderRenderer(vss, fss) {}
174
		
182
		
175
	};
183
	};
176
 
184
    
177
/** Render like glazed ceramics. Looks cool. I will add more to this. */
185
    /** Render like glazed ceramics. Looks cool. I will add more to this. */
178
class GlazedRenderer: public SimpleShaderRenderer
186
    class GlazedRenderer: public SimpleShaderRenderer
179
	{
187
	{
180
		float bsphere_rad;
188
		float bsphere_rad;
181
		const static std::string vss;
189
		const static std::string vss;
182
		const static std::string fss;
190
		const static std::string fss;
183
	public:
191
	public:
184
		GlazedRenderer(const HMesh::Manifold& m, bool smooth, float _bsphere_rad=1.0):
-
 
185
		SimpleShaderRenderer(m, smooth, vss, fss), bsphere_rad(_bsphere_rad) {}
-
 
186
		void draw();
-
 
187
	};
-
 
188
 
-
 
189
/** Render a scalar field. Positive scalars are mapped to blue and negative to red.
-
 
190
	This class also has controls for gamma correction which is highly useful if the 
-
 
191
	scalars are mostly small or large and simply scaling to the 0-1 range does not 
-
 
192
	produce a good result. */
-
 
193
class ScalarFieldRenderer: public SimpleShaderRenderer
192
		GlazedRenderer(): SimpleShaderRenderer(vss, fss) {}
194
	{
-
 
195
		const static std::string vss;
-
 
196
		const static std::string fss;
-
 
197
	public:
-
 
198
		ScalarFieldRenderer(const HMesh::Manifold& m, bool smooth, HMesh::VertexAttributeVector<double>& field, double max_val, float gamma = 2.2);
-
 
199
	};
-
 
200
 
-
 
201
    /** Render a scalar field. Positive scalars are mapped to blue and negative to red.
-
 
202
     This class also has controls for gamma correction which is highly useful if the 
193
        void compile_display_list(const HMesh::Manifold& m, bool smooth);
203
     scalars are mostly small or large and simply scaling to the 0-1 range does not 
-
 
204
     produce a good result. */
-
 
205
    class PeriodicScalarFieldRenderer: public SimpleShaderRenderer
-
 
206
	{
-
 
207
		const static std::string vss;
-
 
208
		const static std::string fss;
-
 
209
	public:
-
 
210
		PeriodicScalarFieldRenderer(const HMesh::Manifold& m, bool smooth, HMesh::VertexAttributeVector<double>& field, float gamma = 2.2);
-
 
211
	};
194
	};
212
 
195
    
213
    /** Render a scalar field. Positive scalars are mapped to blue and negative to red.
196
    /** Render a scalar field. Positive scalars are mapped to blue and negative to red.
214
     This class also has controls for gamma correction which is highly useful if the
197
     This class also has controls for gamma correction which is highly useful if the
215
     scalars are mostly small or large and simply scaling to the 0-1 range does not
198
     scalars are mostly small or large and simply scaling to the 0-1 range does not
216
     produce a good result. */
199
     produce a good result. */
217
    class CircleFieldRenderer: public SimpleShaderRenderer
200
    class ScalarFieldRenderer: public SimpleShaderRenderer
218
	{
201
	{
219
		const static std::string vss;
202
		const static std::string vss;
220
		const static std::string fss;
203
		const static std::string fss;
221
	public:
204
	public:
-
 
205
		ScalarFieldRenderer(): SimpleShaderRenderer(vss, fss) {}
-
 
206
        void compile_display_list(const HMesh::Manifold& m, bool smooth,
222
		CircleFieldRenderer(const HMesh::Manifold& m, bool smooth, HMesh::VertexAttributeVector<CGLA::Vec2d>& field, float gamma = 2.2);
207
                                  HMesh::VertexAttributeVector<double>& field, double max_val, float gamma = 2.2);
223
	};
208
	};
224
 
209
        
225
 
210
    
226
/** Ambient occlusion renderer. Very similar to ScalarFieldRender. Simply assumes that the input values are
211
    /** Ambient occlusion renderer. Very similar to ScalarFieldRender. Simply assumes that the input values are
227
	mean curvatures which in some sense indicate how concave the surface is.*/
212
     mean curvatures which in some sense indicate how concave the surface is.*/
228
class AmbientOcclusionRenderer: public SimpleShaderRenderer
213
    class AmbientOcclusionRenderer: public SimpleShaderRenderer
229
	{
214
	{
230
		const static std::string vss;
215
		const static std::string vss;
231
		const static std::string fss;
216
		const static std::string fss;
232
	public:
217
	public:
-
 
218
		AmbientOcclusionRenderer(): SimpleShaderRenderer(vss, fss) {}
233
		AmbientOcclusionRenderer(const HMesh::Manifold& m, bool smooth, HMesh::VertexAttributeVector<double>& field, double max_val);
219
        void compile_display_list(const HMesh::Manifold& m, HMesh::VertexAttributeVector<double>& field, double max_val);
234
	};
220
	};
235
 
221
    
236
 
222
    
237
/** Line fields are rendered by convolving a noise function in the direction of the line.
223
    /** Line fields are rendered by convolving a noise function in the direction of the line.
238
	This is useful, for instance, for curvature rendering. */
224
     This is useful, for instance, for curvature rendering. */
239
class LineFieldRenderer: public SimpleShaderRenderer
225
    class LineFieldRenderer: public SimpleShaderRenderer
240
	{
226
	{
241
		const static std::string vss;
227
		const static std::string vss;
242
		const static std::string fss;
228
		const static std::string fss;
243
		float r;
-
 
244
	public:
229
	public:
-
 
230
		LineFieldRenderer(): SimpleShaderRenderer(vss, fss) {}
245
		LineFieldRenderer(const HMesh::Manifold& m, bool smooth, HMesh::VertexAttributeVector<CGLA::Vec3d>& lines, float _r);
231
        void compile_display_list(const HMesh::Manifold& m,HMesh::VertexAttributeVector<CGLA::Vec3d>& lines);
246
		void draw();
-
 
247
	};
232
	};
-
 
233
    
-
 
234
    class HarmonicsRenderer: public GLGraphics::ManifoldRenderer
-
 
235
    {
-
 
236
        static GLuint prog_P0;
-
 
237
        static GLGraphics::Console::variable<float> display_harmonics_time;
-
 
238
        static GLGraphics::Console::variable<int> display_harmonics_diffuse;
-
 
239
        static GLGraphics::Console::variable<int> display_harmonics_highlight;
-
 
240
        
-
 
241
        HMesh::Manifold* m;
-
 
242
        HMesh::Harmonics* h;
-
 
243
        
-
 
244
        /// Draw with eigenvalues
-
 
245
        void draw_adf();
-
 
246
        
-
 
247
    public:
-
 
248
        HarmonicsRenderer(HMesh::Manifold& _m, HMesh::Harmonics* _h, GLGraphics::Console& cs);
-
 
249
        
-
 
250
        /// Parse keystrokes that would influence the interactive display
-
 
251
        void parse_key(unsigned char key);
-
 
252
        
-
 
253
    };
248
 
254
 
249
/** Class for wireframe rendering. Enable it will case all triangles to be drawn to be drawn as
-
 
250
 wireframe. Only triangles are supported, but it is fast. */
-
 
251
class DualVertexRenderer: public ManifoldRenderer
-
 
252
	{
-
 
253
		const static std::string vss;
-
 
254
		const static std::string gss;
-
 
255
		const static std::string fss;
-
 
256
	public:
-
 
257
		/// The constructor creates the wireframe shader program. It is static so the program is shared.
-
 
258
		DualVertexRenderer(const HMesh::Manifold& m, HMesh::VertexAttributeVector<CGLA::Vec4d>& field);
-
 
259
	};
255
    
260
}
256
}
261
 
257
 
262
#endif
258
#endif
263
 
259