Subversion Repositories gelsvn

Rev

Rev 663 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 663 Rev 666
1
/* ----------------------------------------------------------------------- *
1
/* ----------------------------------------------------------------------- *
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
3
 * Copyright (C) the authors and DTU Informatics
3
 * Copyright (C) the authors and DTU Informatics
4
 * For license and list of authors, see ../../doc/intro.pdf
4
 * For license and list of authors, see ../../doc/intro.pdf
5
 * ----------------------------------------------------------------------- */
5
 * ----------------------------------------------------------------------- */
6
/**
6
/**
7
 * @file ManifoldRenderer.h
7
 * @file ManifoldRenderer.h
8
 * @brief Tool for rendering a HMesh Manifold.
8
 * @brief Tool for rendering a HMesh Manifold.
9
 */
9
 */
10
 
10
 
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 "../HMesh/harmonics.h"
17
#include "../GLGraphics/draw.h"
17
#include "../GLGraphics/draw.h"
18
#include "../GLGraphics/Console.h"
18
#include "../GLGraphics/Console.h"
19
#include "../GLGraphics/IDBufferWireFrameRenderer.h"
19
#include "../GLGraphics/IDBufferWireFrameRenderer.h"
20
#include "../CGLA/Vec4d.h"
20
#include "../CGLA/Vec4d.h"
21
 
21
 
22
namespace HMesh
22
namespace HMesh
23
{
23
{
24
    template<typename ITEM>
24
    template<typename ITEM>
25
    class VertexAttributeVector;
25
    class VertexAttributeVector;
26
}
26
}
27
 
27
 
28
namespace GLGraphics {
28
namespace GLGraphics {
29
    
29
    
30
    /** 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
31
     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
32
     of the RAII "resource acquisition is initialization" idiom */
32
     of the RAII "resource acquisition is initialization" idiom */
33
    class ManifoldRenderer
33
    class ManifoldRenderer
34
	{
34
	{
35
	protected:
35
	protected:
36
		GLuint display_list;
36
		GLuint display_list;
37
	public:
37
	public:
38
		ManifoldRenderer(): display_list(glGenLists(1))	{}
38
		ManifoldRenderer(): display_list(glGenLists(1))	{}
39
		virtual ~ManifoldRenderer()
39
		virtual ~ManifoldRenderer()
40
		{
40
		{
41
			glDeleteLists(display_list, 1);
41
			glDeleteLists(display_list, 1);
42
		}
42
		}
43
        /// Produce a display list containing geometry and normals (which may be smooth or per face).
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) {}
44
		virtual void compile_display_list(const HMesh::Manifold& m, bool smooth) {}
45
 
45
 
46
		virtual void draw()
46
		virtual void draw()
47
		{
47
		{
48
			glCallList(display_list);
48
			glCallList(display_list);
49
		}
49
		}
50
	};
50
	};
51
    
51
    
52
    
52
    
53
    /** 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
54
     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.
55
     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. */
56
    class WireframeRenderer: public ManifoldRenderer
56
    class WireframeRenderer: public ManifoldRenderer
57
	{
57
	{
58
		GLGraphics::IDBufferWireframeRenderer* idbuff_renderer;
58
		GLGraphics::IDBufferWireframeRenderer* idbuff_renderer;
59
		
59
		
60
		int maximum_face_valency(const HMesh::Manifold& m);
60
		int maximum_face_valency(const HMesh::Manifold& m);
61
		
61
		
62
	public:
62
	public:
63
		~WireframeRenderer()
63
		~WireframeRenderer()
64
		{
64
		{
65
			delete idbuff_renderer;
65
			delete idbuff_renderer;
66
		}
66
		}
67
		
67
		
68
		WireframeRenderer(HMesh::Manifold& m, bool flat);
68
		WireframeRenderer(HMesh::Manifold& m, bool flat);
69
		
69
		
70
		void draw();
70
		void draw();
71
	};
71
	};
72
    
72
    
73
    /** 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.
74
     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
75
     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.
76
     
76
     
77
     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
78
     geometry shader.
78
     geometry shader.
79
     
79
     
80
     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
81
     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
82
     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.
83
     
83
     
84
     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
85
     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
86
     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
87
     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.
88
     */
88
     */
89
    class SimpleShaderRenderer: public ManifoldRenderer
89
    class SimpleShaderRenderer: public ManifoldRenderer
90
	{
90
	{
91
		/// 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.
92
		void init_shaders(const std::string& vss,
92
		void init_shaders(const std::string& vss,
93
						  const std::string& fss);
93
						  const std::string& fss);
94
		
94
		
95
        
95
        
96
	protected:
96
	protected:
97
        
97
        
98
		GLuint prog,vs,fs;
98
		GLuint prog,vs,fs;
99
        
99
        
100
	public:
100
	public:
101
				
101
				
102
		/** 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.
103
         Use if you shader has extra attributes. */
103
         Use if you shader has extra attributes. */
104
		SimpleShaderRenderer(const std::string& vss,
104
		SimpleShaderRenderer(const std::string& vss,
105
							 const std::string& fss) {init_shaders(vss,fss);}
105
							 const std::string& fss) {init_shaders(vss,fss);}
106
		
106
		
107
		/// Produce a display list containing geometry and normals (which may be smooth or per face).
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);
108
		virtual void compile_display_list(const HMesh::Manifold& m, bool smooth);
109
 
109
 
110
		/// Releases the program and shaders.
110
		/// Releases the program and shaders.
111
		~SimpleShaderRenderer()
111
		~SimpleShaderRenderer()
112
		{
112
		{
113
			glDeleteProgram(prog);
113
			glDeleteProgram(prog);
114
			glDeleteShader(vs);
114
			glDeleteShader(vs);
115
			glDeleteShader(fs);
115
			glDeleteShader(fs);
116
		}
116
		}
117
		
117
		
118
		/// 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.
119
		virtual void draw();
119
		virtual void draw();
120
        
120
        
121
	};
121
	};
122
    
122
    
123
    /** 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. */
124
    class NormalRenderer: public SimpleShaderRenderer
124
    class NormalRenderer: public SimpleShaderRenderer
125
    {
125
    {
126
        const static std::string vss;
126
        const static std::string vss;
127
        const static std::string fss;
127
        const static std::string fss;
128
        
128
        
129
    public:
129
    public:
130
        NormalRenderer():
130
        NormalRenderer():
131
        SimpleShaderRenderer(vss, fss) {}
131
        SimpleShaderRenderer(vss, fss) {}
132
    };
132
    };
133
    
133
    
134
    /** Debug renderer. Color code faces and show vertices as balls.*/
134
    /** Debug renderer. Color code faces and show vertices as balls.*/
135
    class DebugRenderer: public SimpleShaderRenderer
135
    class DebugRenderer: public SimpleShaderRenderer
136
    {
136
    {
137
        const static std::string vss;
137
        const static std::string vss;
138
        const static std::string fss;
138
        const static std::string fss;
139
        
139
        
140
    public:
140
    public:
141
        static HMesh::VertexAttributeVector<CGLA::Vec3f> vertex_colors;
141
        static HMesh::VertexAttributeVector<CGLA::Vec3f> vertex_colors;
142
        static HMesh::FaceAttributeVector<CGLA::Vec3f> face_colors;
142
        static HMesh::FaceAttributeVector<CGLA::Vec3f> face_colors;
143
        static HMesh::HalfEdgeAttributeVector<CGLA::Vec3f> edge_colors;
143
        static HMesh::HalfEdgeAttributeVector<CGLA::Vec3f> edge_colors;
144
    public:
144
    public:
145
        DebugRenderer(): SimpleShaderRenderer(vss, fss) {}
145
        DebugRenderer(): SimpleShaderRenderer(vss, fss) {}
146
        void compile_display_list(const HMesh::Manifold& m, bool smooth);
146
        void compile_display_list(const HMesh::Manifold& m, bool smooth, float rad);
147
        
147
        
148
    };
148
    };
149
    
149
    
150
    /** 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
151
     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
152
     want to see whether the surface is smooth or has kinks. */
152
     want to see whether the surface is smooth or has kinks. */
153
    class ReflectionLineRenderer: public SimpleShaderRenderer
153
    class ReflectionLineRenderer: public SimpleShaderRenderer
154
	{
154
	{
155
		const static std::string vss;
155
		const static std::string vss;
156
		const static std::string fss;
156
		const static std::string fss;
157
	public:
157
	public:
158
		ReflectionLineRenderer(): SimpleShaderRenderer(vss, fss) {}
158
		ReflectionLineRenderer(): SimpleShaderRenderer(vss, fss) {}
159
 
159
 
160
	};
160
	};
161
    
161
    
162
    /** 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
163
     want to see whether the surface is smooth or has kinks. */
163
     want to see whether the surface is smooth or has kinks. */
164
    class IsophoteLineRenderer: public SimpleShaderRenderer
164
    class IsophoteLineRenderer: public SimpleShaderRenderer
165
	{
165
	{
166
		const static std::string vss;
166
		const static std::string vss;
167
		const static std::string fss;
167
		const static std::string fss;
168
	public:
168
	public:
169
		IsophoteLineRenderer(): SimpleShaderRenderer(vss, fss) {}
169
		IsophoteLineRenderer(): SimpleShaderRenderer(vss, fss) {}
170
		
170
		
171
	};
171
	};
172
    
172
    
173
    /** 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
174
     with a fat black silhouette. */
174
     with a fat black silhouette. */
175
    
175
    
176
    class ToonRenderer: public SimpleShaderRenderer
176
    class ToonRenderer: public SimpleShaderRenderer
177
	{
177
	{
178
		const static std::string vss;
178
		const static std::string vss;
179
		const static std::string fss;
179
		const static std::string fss;
180
	public:
180
	public:
181
		ToonRenderer(): SimpleShaderRenderer(vss, fss) {}
181
		ToonRenderer(): SimpleShaderRenderer(vss, fss) {}
182
		
182
		
183
	};
183
	};
184
    
184
    
185
    /** 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. */
186
    class GlazedRenderer: public SimpleShaderRenderer
186
    class GlazedRenderer: public SimpleShaderRenderer
187
	{
187
	{
188
		float bsphere_rad;
188
		float bsphere_rad;
189
		const static std::string vss;
189
		const static std::string vss;
190
		const static std::string fss;
190
		const static std::string fss;
191
	public:
191
	public:
192
		GlazedRenderer(): SimpleShaderRenderer(vss, fss) {}
192
		GlazedRenderer(): SimpleShaderRenderer(vss, fss) {}
193
        void compile_display_list(const HMesh::Manifold& m, bool smooth);
193
        void compile_display_list(const HMesh::Manifold& m, bool smooth);
194
	};
194
	};
195
    
195
    
196
    /** 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.
197
     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
198
     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
199
     produce a good result. */
199
     produce a good result. */
200
    class ScalarFieldRenderer: public SimpleShaderRenderer
200
    class ScalarFieldRenderer: public SimpleShaderRenderer
201
	{
201
	{
202
		const static std::string vss;
202
		const static std::string vss;
203
		const static std::string fss;
203
		const static std::string fss;
204
	public:
204
	public:
205
		ScalarFieldRenderer(): SimpleShaderRenderer(vss, fss) {}
205
		ScalarFieldRenderer(): SimpleShaderRenderer(vss, fss) {}
206
        void compile_display_list(const HMesh::Manifold& m, bool smooth,
206
        void compile_display_list(const HMesh::Manifold& m, bool smooth,
207
                                  HMesh::VertexAttributeVector<double>& field, double max_val, float gamma = 2.2);
207
                                  HMesh::VertexAttributeVector<double>& field, double max_val, float gamma = 2.2);
208
	};
208
	};
209
    
209
    
210
    /** Render a checkerboard pattern based on input texture map */
210
    /** Render a checkerboard pattern based on input texture map */
211
    class CheckerBoardRenderer: public SimpleShaderRenderer
211
    class CheckerBoardRenderer: public SimpleShaderRenderer
212
	{
212
	{
213
		const static std::string vss;
213
		const static std::string vss;
214
		const static std::string fss;
214
		const static std::string fss;
215
	public:
215
	public:
216
        static HMesh::VertexAttributeVector<CGLA::Vec2f> param;
216
        static HMesh::VertexAttributeVector<CGLA::Vec2f> param;
217
		CheckerBoardRenderer(): SimpleShaderRenderer(vss, fss) {}
217
		CheckerBoardRenderer(): SimpleShaderRenderer(vss, fss) {}
218
        void compile_display_list(const HMesh::Manifold& m, bool smooth);
218
        void compile_display_list(const HMesh::Manifold& m, bool smooth);
219
	};
219
	};
220
 
220
 
221
    
221
    
222
    
222
    
223
    /** Ambient occlusion renderer. Very similar to ScalarFieldRender. Simply assumes that the input values are
223
    /** Ambient occlusion renderer. Very similar to ScalarFieldRender. Simply assumes that the input values are
224
     mean curvatures which in some sense indicate how concave the surface is.*/
224
     mean curvatures which in some sense indicate how concave the surface is.*/
225
    class AmbientOcclusionRenderer: public SimpleShaderRenderer
225
    class AmbientOcclusionRenderer: public SimpleShaderRenderer
226
	{
226
	{
227
		const static std::string vss;
227
		const static std::string vss;
228
		const static std::string fss;
228
		const static std::string fss;
229
	public:
229
	public:
230
		AmbientOcclusionRenderer(): SimpleShaderRenderer(vss, fss) {}
230
		AmbientOcclusionRenderer(): SimpleShaderRenderer(vss, fss) {}
231
        void compile_display_list(const HMesh::Manifold& m, HMesh::VertexAttributeVector<double>& field, double max_val);
231
        void compile_display_list(const HMesh::Manifold& m, HMesh::VertexAttributeVector<double>& field, double max_val);
232
	};
232
	};
233
    
233
    
234
    
234
    
235
    /** Line fields are rendered by convolving a noise function in the direction of the line.
235
    /** Line fields are rendered by convolving a noise function in the direction of the line.
236
     This is useful, for instance, for curvature rendering. */
236
     This is useful, for instance, for curvature rendering. */
237
    class LineFieldRenderer: public SimpleShaderRenderer
237
    class LineFieldRenderer: public SimpleShaderRenderer
238
	{
238
	{
239
		const static std::string vss;
239
		const static std::string vss;
240
		const static std::string fss;
240
		const static std::string fss;
241
	public:
241
	public:
242
		LineFieldRenderer(): SimpleShaderRenderer(vss, fss) {}
242
		LineFieldRenderer(): SimpleShaderRenderer(vss, fss) {}
243
        void compile_display_list(const HMesh::Manifold& m,HMesh::VertexAttributeVector<CGLA::Vec3d>& lines);
243
        void compile_display_list(const HMesh::Manifold& m,HMesh::VertexAttributeVector<CGLA::Vec3d>& lines);
244
	};
244
	};
245
    
245
    
246
    class HarmonicsRenderer: public GLGraphics::ManifoldRenderer
246
    class HarmonicsRenderer: public GLGraphics::ManifoldRenderer
247
    {
247
    {
248
        static GLuint prog_P0;
248
        static GLuint prog_P0;
249
        static GLGraphics::Console::variable<float> display_harmonics_time;
249
        static GLGraphics::Console::variable<float> display_harmonics_time;
250
        static GLGraphics::Console::variable<int> display_harmonics_diffuse;
250
        static GLGraphics::Console::variable<int> display_harmonics_diffuse;
251
        static GLGraphics::Console::variable<int> display_harmonics_highlight;
251
        static GLGraphics::Console::variable<int> display_harmonics_highlight;
252
        static GLGraphics::Console::variable<int> display_harmonics_e0;
252
        static GLGraphics::Console::variable<int> display_harmonics_e0;
253
        static GLGraphics::Console::variable<int> display_harmonics_e1;
253
        static GLGraphics::Console::variable<int> display_harmonics_e1;
254
        
254
        
255
        HMesh::Manifold* m;
255
        HMesh::Manifold* m;
256
        HMesh::Harmonics* h;
256
        HMesh::Harmonics* h;
257
        
257
        
258
        /// Draw with eigenvalues
258
        /// Draw with eigenvalues
259
        void draw_adf();
259
        void draw_adf();
260
        void draw_esum();
260
        void draw_esum();
261
        
261
        
262
    public:
262
    public:
263
        HarmonicsRenderer(HMesh::Manifold& _m, HMesh::Harmonics* _h, GLGraphics::Console& cs);
263
        HarmonicsRenderer(HMesh::Manifold& _m, HMesh::Harmonics* _h, GLGraphics::Console& cs);
264
        
264
        
265
        /// Parse keystrokes that would influence the interactive display
265
        /// Parse keystrokes that would influence the interactive display
266
        void parse_key(unsigned char key);
266
        void parse_key(unsigned char key);
267
        
267
        
268
    };
268
    };
269
 
269
 
270
    
270
    
271
}
271
}
272
 
272
 
273
#endif
273
#endif
274
 
274
 
275

Generated by GNU Enscript 1.6.6.
275

Generated by GNU Enscript 1.6.6.
276
 
276
 
277
 
277
 
278
 
278