Subversion Repositories gelsvn

Rev

Rev 631 | Rev 662 | Go to most recent revision | Show entire file | Regard 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
{
Line 36... Line 38...
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
	};
Line 85... Line 90...
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
		
101
				
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
		{
-
 
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);
Line 129... Line 125...
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
		
159
 
150
	};
160
	};
151
 
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. */
Line 167... Line 176...
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):
192
		GlazedRenderer(): SimpleShaderRenderer(vss, fss) {}
185
		SimpleShaderRenderer(m, smooth, vss, fss), bsphere_rad(_bsphere_rad) {}
193
        void compile_display_list(const HMesh::Manifold& m, bool smooth);
186
		void draw();
-
 
187
	};
194
	};
188
 
195
    
189
/** 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.
190
	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
191
	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
Line 193... Line 200...
193
class ScalarFieldRenderer: public SimpleShaderRenderer
200
    class ScalarFieldRenderer: public SimpleShaderRenderer
194
	{
201
	{
195
		const static std::string vss;
202
		const static std::string vss;
196
		const static std::string fss;
203
		const static std::string fss;
197
	public:
204
	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 
-
 
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
205
		ScalarFieldRenderer(): SimpleShaderRenderer(vss, fss) {}
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
	};
-
 
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
206
        void compile_display_list(const HMesh::Manifold& m, bool smooth,
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);
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
	};
248
 
233
    
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
234
    class HarmonicsRenderer: public GLGraphics::ManifoldRenderer
252
	{
235
    {
253
		const static std::string vss;
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
        
254
		const static std::string gss;
241
        HMesh::Manifold* m;
255
		const static std::string fss;
242
        HMesh::Harmonics* h;
-
 
243
        
-
 
244
        /// Draw with eigenvalues
-
 
245
        void draw_adf();
-
 
246
        
256
	public:
247
    public:
257
		/// The constructor creates the wireframe shader program. It is static so the program is shared.
248
        HarmonicsRenderer(HMesh::Manifold& _m, HMesh::Harmonics* _h, GLGraphics::Console& cs);
-
 
249
        
258
		DualVertexRenderer(const HMesh::Manifold& m, HMesh::VertexAttributeVector<CGLA::Vec4d>& field);
250
        /// Parse keystrokes that would influence the interactive display
-
 
251
        void parse_key(unsigned char key);
-
 
252
        
259
	};
253
    };
-
 
254
 
-
 
255
    
260
}
256
}
261
 
257
 
262
#endif
258
#endif
263
 
259