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