Subversion Repositories gelsvn

Rev

Rev 630 | Rev 647 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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

Generated by GNU Enscript 1.6.6.
264

Generated by GNU Enscript 1.6.6.
251
 
265
 
252
 
266
 
253
 
267