Subversion Repositories gelsvn

Rev

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

Rev 387 Rev 388
1
/*
1
/*
2
 *  MeshEdit is a small application which allows you to load and edit a mesh.
2
 *  MeshEdit is a small application which allows you to load and edit a mesh.
3
 *  The mesh will be stored in GEL's half edge based Manifold data structure.
3
 *  The mesh will be stored in GEL's half edge based Manifold data structure.
4
 *  A number of editing operations are supported. Most of these are accessible from the 
4
 *  A number of editing operations are supported. Most of these are accessible from the 
5
 *  console that pops up when you hit 'esc'.
5
 *  console that pops up when you hit 'esc'.
6
 *
6
 *
7
 *  Created by J. Andreas Bærentzen on 15/08/08.
7
 *  Created by J. Andreas Bærentzen on 15/08/08.
8
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
8
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
9
 *
9
 *
10
 */
10
 */
11
#include <iostream>
11
#include <iostream>
12
#include <CGLA/eigensolution.h>
12
#include <CGLA/eigensolution.h>
13
#include <CGLA/Vec2d.h>
13
#include <CGLA/Vec2d.h>
14
#include <CGLA/Vec3d.h>
14
#include <CGLA/Vec3d.h>
15
#include <CGLA/Mat3x3d.h>
15
#include <CGLA/Mat3x3d.h>
16
#include <CGLA/Mat2x2d.h>
16
#include <CGLA/Mat2x2d.h>
17
#include <CGLA/Mat2x3d.h>
17
#include <CGLA/Mat2x3d.h>
18
 
18
 
19
#include <LinAlg/Matrix.h>
19
#include <LinAlg/Matrix.h>
20
#include <LinAlg/Vector.h>
20
#include <LinAlg/Vector.h>
21
#include <LinAlg/LapackFunc.h>
21
#include <LinAlg/LapackFunc.h>
22
 
22
 
23
#include <Util/Timer.h>
23
#include <Util/Timer.h>
24
#include <Util/ArgExtracter.h>
24
#include <Util/ArgExtracter.h>
25
 
25
 
26
#include <GL/glew.h>
26
#include <GL/glew.h>
27
#include <GLGraphics/gel_glut.h>
27
#include <GLGraphics/gel_glut.h>
28
#include <GLGraphics/draw.h>
28
#include <GLGraphics/draw.h>
29
#include <GLGraphics/glsl_shader.h>
29
#include <GLGraphics/glsl_shader.h>
30
#include <GLGraphics/GLViewController.h>
30
#include <GLGraphics/GLViewController.h>
31
 
31
 
32
#include <HMesh/Manifold.h>
32
#include <HMesh/Manifold.h>
33
#include <HMesh/VertexCirculator.h>
33
#include <HMesh/VertexCirculator.h>
34
#include <HMesh/FaceCirculator.h>
34
#include <HMesh/FaceCirculator.h>
35
#include <HMesh/build_manifold.h>
35
#include <HMesh/build_manifold.h>
36
#include <HMesh/mesh_optimization.h>
36
#include <HMesh/mesh_optimization.h>
37
#include <HMesh/triangulate.h>
37
#include <HMesh/triangulate.h>
38
#include <HMesh/load.h>
38
#include <HMesh/load.h>
39
#include <HMesh/quadric_simplify.h>
39
#include <HMesh/quadric_simplify.h>
40
#include <HMesh/smooth.h>
40
#include <HMesh/smooth.h>
41
#include <HMesh/x3d_save.h>
41
#include <HMesh/x3d_save.h>
-
 
42
#include <HMesh/obj_save.h>
42
#include <HMesh/mesh_optimization.h>
43
#include <HMesh/mesh_optimization.h>
-
 
44
#include <HMesh/triangulate.h>
-
 
45
#include <HMesh/close_holes.h>
-
 
46
#include <HMesh/caps_and_needles.h>
-
 
47
#include <HMesh/refine_edges.h>
-
 
48
#include <HMesh/subdivision.h>
43
 
49
 
44
#include <GLConsole/GLConsole.h>
50
#include <GLConsole/GLConsole.h>
45
 
51
 
46
#include "harmonics.h"
52
#include "harmonics.h"
47
#include "wireframe.h"
53
#include "wireframe.h"
48
 
54
 
49
 
55
 
50
// Single global instance so glut can get access
56
// Single global instance so glut can get access
51
GLConsole theConsole;
57
GLConsole theConsole;
52
 
58
 
53
////////////////////////////////////////////////////////////////////////////////
59
////////////////////////////////////////////////////////////////////////////////
54
char* ConsoleHelp(std::vector<std::string> &args)
60
char* ConsoleHelp(std::vector<std::string> &args)
55
{
61
{
56
    theConsole.Printf("");
62
    theConsole.Printf("");
57
    theConsole.Printf("----------------- HELP -----------------");
63
    theConsole.Printf("----------------- HELP -----------------");
58
    theConsole.Printf("Press ~ key to open and close console");
64
    theConsole.Printf("Press ~ key to open and close console");
59
    theConsole.Printf("Press TAB to see the available commands and functions");
65
    theConsole.Printf("Press TAB to see the available commands and functions");
60
    theConsole.Printf("Functions are shown in green and variables in yellow");
66
    theConsole.Printf("Functions are shown in green and variables in yellow");
61
    theConsole.Printf("Setting a value: [command] = value");
67
    theConsole.Printf("Setting a value: [command] = value");
62
    theConsole.Printf("Getting a value: [command]");
68
    theConsole.Printf("Getting a value: [command]");
63
    theConsole.Printf("Functions: [function] [arg1] [arg2] ...");
69
    theConsole.Printf("Functions: [function] [arg1] [arg2] ...");
64
    theConsole.Printf("Entering just the function name will give a description.");
70
    theConsole.Printf("Entering just the function name will give a description.");
65
    theConsole.Printf("History: Up and Down arrow keys move through history.");
71
    theConsole.Printf("History: Up and Down arrow keys move through history.");
66
    theConsole.Printf("Tab Completion: TAB does tab completion and makes suggestions.");
72
    theConsole.Printf("Tab Completion: TAB does tab completion and makes suggestions.");
67
    theConsole.Printf("----------------- HELP -----------------");
73
    theConsole.Printf("----------------- HELP -----------------");
68
    theConsole.Printf("");
74
    theConsole.Printf("");
69
    return "";
75
    return "";
70
}
76
}
71
 
77
 
72
using namespace std;
78
using namespace std;
73
using namespace HMesh;
79
using namespace HMesh;
74
using namespace Geometry;
80
using namespace Geometry;
75
using namespace GLGraphics;
81
using namespace GLGraphics;
76
using namespace CGLA;
82
using namespace CGLA;
77
using namespace Util;
83
using namespace Util;
78
using namespace LinAlg;
84
using namespace LinAlg;
79
 
85
 
80
 
86
 
81
 
87
 
82
namespace 
88
namespace 
83
{
89
{
84
	GLViewController* view_ctrl;
90
	GLViewController* view_ctrl;
85
	int WINX=800, WINY=800;
91
	int WINX=800, WINY=800;
-
 
92
	string file;
86
	
93
	
87
	Manifold mani;	
94
	Manifold mani;	
88
	bool create_display_list = true;
95
	bool create_display_list = true;
89
}
96
}
90
 
97
 
-
 
98
char* console_save(std::vector<std::string> &args)
-
 
99
{
-
 
100
	string& file_name = args[0];
-
 
101
	if(args.size() == 1)
-
 
102
	{
-
 
103
		if(file_name.substr(file_name.length()-4,file_name.length())==".obj")
-
 
104
		{
-
 
105
			obj_save(file_name, mani);
-
 
106
			return "";
-
 
107
		}
-
 
108
		else if(file_name.substr(file_name.length()-4,file_name.length())==".x3d")
-
 
109
		{
-
 
110
			x3d_save(file_name, mani);
-
 
111
			return "";
-
 
112
		}
-
 
113
		return "unknown format";
-
 
114
	}
-
 
115
	return "usage: save <name.x3d|name.obj> ";
-
 
116
}
-
 
117
 
-
 
118
char* console_refine_edges(std::vector<std::string> &args)
-
 
119
{
-
 
120
	float thresh = 0.5;
-
 
121
	if(args.size()>0)
-
 
122
	{
-
 
123
		istringstream a0(args[0]);
-
 
124
		a0 >> thresh;
-
 
125
	}
-
 
126
	float avg_length = average_edge_length(mani);
-
 
127
	refine_edges(mani, thresh * avg_length);
-
 
128
	return "";
-
 
129
 
-
 
130
}
-
 
131
 
-
 
132
char* console_refine_faces(std::vector<std::string> &args)
-
 
133
{
-
 
134
	safe_triangulate(mani);
-
 
135
	return "";
-
 
136
 
-
 
137
}
-
 
138
 
-
 
139
char* console_cc_subdivide(std::vector<std::string> &args)
-
 
140
{
-
 
141
	cc_split(mani,mani);
-
 
142
	return "";
-
 
143
}
-
 
144
 
-
 
145
 
91
 
146
 
92
char* console_minimize_curvature(std::vector<std::string> &args)
147
char* console_minimize_curvature(std::vector<std::string> &args)
93
{
148
{
94
	bool anneal=false;
149
	bool anneal=false;
95
	if(args.size()>0)
150
	if(args.size()>0)
96
	{
151
	{
97
		istringstream a0(args[0]);
152
		istringstream a0(args[0]);
98
		a0 >> anneal;
153
		a0 >> anneal;
99
	}
154
	}
100
 
155
 
101
	minimize_curvature(mani, anneal);
156
	minimize_curvature(mani, anneal);
-
 
157
	create_display_list = true;
102
	return "";
158
	return "";
103
}
159
}
104
 
160
 
105
char* console_minimize_dihedral(std::vector<std::string> &args)
161
char* console_minimize_dihedral(std::vector<std::string> &args)
106
{
162
{
107
	int iter = 1000;
163
	int iter = 1000;
108
	if(args.size()>0)
164
	if(args.size()>0)
109
	{
165
	{
110
		istringstream a0(args[0]);
166
		istringstream a0(args[0]);
111
		a0 >> iter;
167
		a0 >> iter;
112
	}
168
	}
113
 
169
 
114
	bool anneal = false;
170
	bool anneal = false;
115
	if(args.size()>1)
171
	if(args.size()>1)
116
	{
172
	{
117
		istringstream a0(args[0]);
173
		istringstream a0(args[0]);
118
		a0 >> anneal;
174
		a0 >> anneal;
119
	}
175
	}
120
 
176
 
121
	bool use_alpha = true;
177
	bool use_alpha = true;
122
	if(args.size()>22)
178
	if(args.size()>2)
123
	{
179
	{
124
		istringstream a0(args[0]);
180
		istringstream a0(args[0]);
125
		a0 >> use_alpha;
181
		a0 >> use_alpha;
126
	}
182
	}
127
 
183
 
128
	float gamma = 4.0;
184
	float gamma = 4.0;
129
	if(args.size()>3)
185
	if(args.size()>3)
130
	{
186
	{
131
		istringstream a0(args[0]);
187
		istringstream a0(args[0]);
132
		a0 >> gamma;
188
		a0 >> gamma;
133
	}
189
	}
134
	
190
	
135
	
191
	
136
	minimize_dihedral_angle(mani, iter, anneal, use_alpha, gamma);
192
	minimize_dihedral_angle(mani, iter, anneal, use_alpha, gamma);
137
	return "";
193
	return "";
138
}
194
}
139
 
195
 
-
 
196
char* console_maximize_min_angle(std::vector<std::string> &args)
-
 
197
{
-
 
198
	float thresh=0.0;
-
 
199
	if(args.size()>0)
-
 
200
	{
-
 
201
		istringstream a0(args[0]);
-
 
202
		a0 >> thresh;
-
 
203
	}
-
 
204
	bool anneal=false;
-
 
205
	if(args.size()>1)
-
 
206
	{
-
 
207
		istringstream a0(args[0]);
-
 
208
		a0 >> anneal;
-
 
209
	}
-
 
210
	maximize_min_angle(mani,thresh,anneal);
-
 
211
	return "";
-
 
212
}
-
 
213
 
-
 
214
 
140
char* console_optimize_valency(std::vector<std::string> &args)
215
char* console_optimize_valency(std::vector<std::string> &args)
141
{
216
{
142
	bool anneal=false;
217
	bool anneal=false;
143
	if(args.size()>0)
218
	if(args.size()>0)
144
	{
219
	{
145
		istringstream a0(args[0]);
220
		istringstream a0(args[0]);
146
		a0 >> anneal;
221
		a0 >> anneal;
147
	}
222
	}
148
	optimize_valency(mani, anneal);
223
	optimize_valency(mani, anneal);
149
	return "";
224
	return "";
150
}
225
}
151
 
226
 
-
 
227
char* console_analyze(std::vector<std::string> &args)
-
 
228
{
-
 
229
	analyze_mesh(mani);
-
 
230
	return "";
-
 
231
}
-
 
232
 
-
 
233
 
152
char* console_partial_reconstruct(std::vector<std::string> &args)
234
char* console_partial_reconstruct(std::vector<std::string> &args)
153
{
235
{
154
	int E0,E1;
236
	int E0,E1;
155
	float scale;
237
	float scale;
156
	istringstream a0(args[0]);
238
	istringstream a0(args[0]);
157
	a0 >> E0;
239
	a0 >> E0;
158
	istringstream a1(args[1]);
240
	istringstream a1(args[1]);
159
	a1 >> E1;
241
	a1 >> E1;
160
	istringstream a2(args[2]);
242
	istringstream a2(args[2]);
161
	a2 >> scale;
243
	a2 >> scale;
162
	partial_reconstruct(mani, E0,E1,scale);
244
	partial_reconstruct(mani, E0,E1,scale);
163
	return "";
245
	return "";
164
}
246
}
165
 
247
 
166
char* console_reset_shape(std::vector<std::string> &args)
248
char* console_reset_shape(std::vector<std::string> &args)
167
{
249
{
168
	reset_shape(mani);
250
	reset_shape(mani);
169
	return "";
251
	return "";
170
}
252
}
171
 
253
 
172
void reshape(int W, int H)
254
void reshape(int W, int H)
173
{
255
{
174
	view_ctrl->reshape(W,H);
256
	view_ctrl->reshape(W,H);
175
}
257
}
176
 
258
 
-
 
259
char* console_close_holes(std::vector<std::string> &args)
-
 
260
{
-
 
261
	close_holes(mani);
-
 
262
	return "";
-
 
263
}
-
 
264
 
-
 
265
char* console_reload(std::vector<std::string> &args)
-
 
266
{
-
 
267
	if(args.size()>0)
-
 
268
		file = args[0];
-
 
269
	mani.clear();
-
 
270
	load(file, mani); 
-
 
271
	Vec3f c(0,0,0);
-
 
272
	float r = 5;
-
 
273
	mani.get_bsphere(c,r);
-
 
274
	delete view_ctrl;
-
 
275
	view_ctrl = new GLViewController(WINX,WINY, c,r*2);
-
 
276
	return "";
-
 
277
}
-
 
278
 
177
 
279
 
178
char* console_simplify(std::vector<std::string> &args)
280
char* console_simplify(std::vector<std::string> &args)
179
{
281
{
180
	float keep_fraction;
282
	float keep_fraction;
181
	if(args.size()==0) return "you must specify fraction of vertices to keep";
283
	if(args.size()==0) return "you must specify fraction of vertices to keep";
182
	istringstream a0(args[0]);
284
	istringstream a0(args[0]);
183
	a0 >> keep_fraction;
285
	a0 >> keep_fraction;
184
 
286
 
185
	Vec3f p0, p7;
287
	Vec3f p0, p7;
186
	mani.get_bbox(p0, p7);
288
	mani.get_bbox(p0, p7);
187
	Vec3f d = p7-p0;
289
	Vec3f d = p7-p0;
188
	float s = 1.0/d.max_coord();
290
	float s = 1.0/d.max_coord();
189
	Vec3f pcentre = (p7+p0)/2.0;
291
	Vec3f pcentre = (p7+p0)/2.0;
190
	for(VertexIter vi = mani.vertices_begin(); vi != mani.vertices_end(); ++vi)
292
	for(VertexIter vi = mani.vertices_begin(); vi != mani.vertices_end(); ++vi)
191
		vi->pos = (vi->pos - pcentre) * s;
293
		vi->pos = (vi->pos - pcentre) * s;
192
	quadric_simplify(mani,keep_fraction,0.0001f,true);
294
	quadric_simplify(mani,keep_fraction,0.0001f,true);
193
	for(VertexIter vi = mani.vertices_begin(); vi != mani.vertices_end(); ++vi)
295
	for(VertexIter vi = mani.vertices_begin(); vi != mani.vertices_end(); ++vi)
194
		vi->pos = vi->pos*d.max_coord() + pcentre;
296
		vi->pos = vi->pos*d.max_coord() + pcentre;
195
	return "";
297
	return "";
196
}
298
}
197
 
299
 
198
char* console_laplacian_smooth(std::vector<std::string> &args)
300
char* console_laplacian_smooth(std::vector<std::string> &args)
199
{
301
{
200
	float t=1.0;
302
	float t=1.0;
201
	if(args.size()>0)
303
	if(args.size()>0)
202
	{
304
	{
203
		istringstream a0(args[0]);
305
		istringstream a0(args[0]);
204
		a0 >> t;
306
		a0 >> t;
205
	}
307
	}
206
	/// Simple laplacian smoothing with an optional weight.
308
	/// Simple laplacian smoothing with an optional weight.
207
	laplacian_smooth(mani, t);
309
	laplacian_smooth(mani, t);
208
	return "";
310
	return "";
209
}
311
}
210
 
312
 
211
char* console_taubin_smooth(std::vector<std::string> &args)
313
char* console_taubin_smooth(std::vector<std::string> &args)
212
{
314
{
213
	int iter=1;
315
	int iter=1;
214
	if(args.size()>0)
316
	if(args.size()>0)
215
	{
317
	{
216
		istringstream a0(args[0]);
318
		istringstream a0(args[0]);
217
		a0 >> iter;
319
		a0 >> iter;
218
	}
320
	}
219
	
321
	
220
	/// Taubin smoothing is similar to laplacian smoothing but reduces shrinkage
322
	/// Taubin smoothing is similar to laplacian smoothing but reduces shrinkage
221
	taubin_smooth(mani,  iter);
323
	taubin_smooth(mani,  iter);
222
	return "";
324
	return "";
223
}
325
}
224
 
326
 
225
char* console_fvm_smooth(std::vector<std::string> &args)
327
char* console_fvm_smooth(std::vector<std::string> &args)
226
{	
328
{	
227
	int iter=1;
329
	int iter=1;
228
	if(args.size()>0)
330
	if(args.size()>0)
229
	{
331
	{
230
		istringstream a0(args[0]);
332
		istringstream a0(args[0]);
231
		a0 >> iter;
333
		a0 >> iter;
232
	}
334
	}
233
	/** Fuzzy vector median smoothing is effective when it comes to
335
	/** Fuzzy vector median smoothing is effective when it comes to
234
	 preserving sharp edges. */
336
	 preserving sharp edges. */
235
	fvm_smooth(mani,  iter);
337
	fvm_smooth(mani,  iter);
236
	return "";
338
	return "";
237
 
339
 
238
}
340
}
239
 
341
 
-
 
342
char* console_triangulate(std::vector<std::string> &args)
-
 
343
{	
-
 
344
	shortest_edge_triangulate(mani);
-
 
345
	return "";
-
 
346
}
-
 
347
 
-
 
348
 
-
 
349
char* console_remove_caps(std::vector<std::string> &args)
-
 
350
{	
-
 
351
	remove_caps_from_trimesh(mani, static_cast<float>(M_PI) * 0.85f);
-
 
352
	return "";
-
 
353
}
-
 
354
 
-
 
355
char* console_remove_needles(std::vector<std::string> &args)
-
 
356
{	
-
 
357
	float thresh = 0.1;
-
 
358
	if(args.size()>0)
-
 
359
	{
-
 
360
		istringstream a0(args[0]);
-
 
361
		a0 >> thresh;
-
 
362
	}
-
 
363
	float avg_length = average_edge_length(mani);
-
 
364
	remove_needles_from_trimesh(mani, thresh * avg_length);
-
 
365
	return "";
-
 
366
}
-
 
367
 
240
void display() 
368
void display() 
241
{
369
{
242
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
370
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
243
	
371
	
244
	static CVar<int> do_wireframe("display.wireframe",0);
372
	static CVar<int> display_wireframe("display.wireframe",0);
-
 
373
	static CVar<int> display_eigenmodes("display.eigenmodes",0);
-
 
374
	static CVar<int> display_flat("display.flatshading",0);
245
	
375
	
246
	glPushMatrix();
376
	glPushMatrix();
247
	
377
	
248
	view_ctrl->set_gl_modelview();
378
	view_ctrl->set_gl_modelview();
249
	
379
	
250
	if(create_display_list)
380
	if(create_display_list)
251
	{
381
	{
252
		create_display_list = false;
382
		create_display_list = false;
253
		
383
		
254
		glNewList(1,GL_COMPILE);
384
		glNewList(1,GL_COMPILE);
255
		if(do_wireframe)
385
		if(display_wireframe)
256
			{
386
			{
257
				enable_wireframe();
387
				enable_wireframe();
258
				draw(mani);
388
				draw(mani);
-
 
389
				glUseProgram(0);	
259
			}
390
			}
260
		else
391
		else if(display_eigenmodes)
261
			draw_eigenvalues(mani);
392
			draw_eigenvalues(mani);
-
 
393
		else 
-
 
394
			draw(mani,!display_flat);
262
		glEndList();
395
		glEndList();
263
	}
396
	}
264
	glCallList(1);
397
	glCallList(1);
265
	
398
	
266
	glPopMatrix();
399
	glPopMatrix();
267
	
400
	
268
	glUseProgram(0);
401
	glUseProgram(0);
269
	theConsole.RenderConsole();
402
	theConsole.RenderConsole();
270
	
403
	
271
	glutSwapBuffers();
404
	glutSwapBuffers();
272
}
405
}
273
 
406
 
274
void animate() 
407
void animate() 
275
{	
408
{	
276
	usleep( (int)1e4 );
409
	usleep( (int)1e4 );
277
	view_ctrl->try_spin();
410
	view_ctrl->try_spin();
278
	glutPostRedisplay();
411
	glutPostRedisplay();
279
}
412
}
280
 
413
 
281
 
414
 
282
void mouse(int button, int state, int x, int y) 
415
void mouse(int button, int state, int x, int y) 
283
{
416
{
284
	Vec2i pos(x,y);
417
	Vec2i pos(x,y);
285
	if (state==GLUT_DOWN) 
418
	if (state==GLUT_DOWN) 
286
	{
419
	{
287
		if (button==GLUT_LEFT_BUTTON) 
420
		if (button==GLUT_LEFT_BUTTON) 
288
			view_ctrl->grab_ball(ROTATE_ACTION,pos);
421
			view_ctrl->grab_ball(ROTATE_ACTION,pos);
289
		else if (button==GLUT_MIDDLE_BUTTON) 
422
		else if (button==GLUT_MIDDLE_BUTTON) 
290
			view_ctrl->grab_ball(ZOOM_ACTION,pos);
423
			view_ctrl->grab_ball(ZOOM_ACTION,pos);
291
		else if (button==GLUT_RIGHT_BUTTON) 
424
		else if (button==GLUT_RIGHT_BUTTON) 
292
			view_ctrl->grab_ball(PAN_ACTION,pos);
425
			view_ctrl->grab_ball(PAN_ACTION,pos);
293
	}
426
	}
294
	else if (state==GLUT_UP)
427
	else if (state==GLUT_UP)
295
		view_ctrl->release_ball();
428
		view_ctrl->release_ball();
296
}
429
}
297
 
430
 
298
void motion(int x, int y) {
431
void motion(int x, int y) {
299
	Vec2i pos(x,y);
432
	Vec2i pos(x,y);
300
	view_ctrl->roll_ball(Vec2i(x,y));
433
	view_ctrl->roll_ball(Vec2i(x,y));
301
}
434
}
302
 
435
 
303
void keyboard_spec(int key, int x, int y)
436
void keyboard_spec(int key, int x, int y)
304
{
437
{
305
   int mod = glutGetModifiers();
438
   int mod = glutGetModifiers();
306
 
-
 
307
    if( theConsole.isOpen() ) {
439
   if( theConsole.isOpen() ) {
308
        // If shift held, scroll the console
440
        // If shift held, scroll the console
309
        if( mod == GLUT_ACTIVE_SHIFT ) {
441
        if( mod == GLUT_ACTIVE_SHIFT ) {
310
            switch (key){
442
            switch (key){
311
                case GLUT_KEY_UP:
443
                case GLUT_KEY_UP:
312
                    theConsole.ScrollDownLine();
444
                    theConsole.ScrollDownLine();
313
                    break;
445
                    break;
314
                case GLUT_KEY_DOWN: 
446
                case GLUT_KEY_DOWN: 
315
                    theConsole.ScrollUpLine();
447
                    theConsole.ScrollUpLine();
316
                    break;
448
                    break;
317
            }
449
            }
318
        } else {
450
        } else {
319
            theConsole.StandardKeyBindings( key );
451
            theConsole.StandardKeyBindings( key );
320
        }
452
        }
321
    }
453
    }
322
}
454
}
323
 
455
 
324
template<typename T>
456
template<typename T>
325
T& get_CVar_ref(const std::string& s)
457
T& get_CVar_ref(const std::string& s)
326
{
458
{
327
	return *reinterpret_cast<T*> (GetCVarData(s));
459
	return *reinterpret_cast<T*> (GetCVarData(s));
328
}
460
}
329
 
461
 
330
void keyboard(unsigned char key, int x, int y) 
462
void keyboard(unsigned char key, int x, int y) 
331
{	
463
{	
332
	if(theConsole.isOpen())
464
	if(theConsole.isOpen())
-
 
465
		{
333
		switch(key) {
466
		switch(key) {
334
			case '\033': 
467
			case '\033': 
335
				theConsole.ToggleConsole();
468
				theConsole.ToggleConsole();
336
			default:      
469
			default:      
337
				//send keystroke to console
470
				//send keystroke to console
338
				if( theConsole.isOpen() ){
471
				if( theConsole.isOpen() ){
339
					theConsole.EnterCommandCharacter(key);
472
					theConsole.EnterCommandCharacter(key);
340
				}
473
				}
341
				break;
474
				break;
-
 
475
		}
-
 
476
		if(key == 13)	create_display_list = true;
-
 
477
 
342
		}	
478
		}	
343
	else {
479
	else {
344
		int& display_eigenvalue = get_CVar_ref<int>("display.eigenvalue");
480
		int& display_eigenvalue = get_CVar_ref<int>("display.harmonics.eigenvalue");
345
		int& display_wireframe = get_CVar_ref<int>("display.wireframe");
481
		int& display_wireframe = get_CVar_ref<int>("display.wireframe");
346
		int& display_diffuse = get_CVar_ref<int>("display.diffuse");
482
		int& display_diffuse = get_CVar_ref<int>("display.harmonics.diffuse");
347
		int& display_highlight = get_CVar_ref<int>("display.highlight");
483
		int& display_highlight = get_CVar_ref<int>("display.harmonics.highlight");
-
 
484
		int& display_flat = get_CVar_ref<int>("display.flatshading");
348
		
485
		
349
		switch(key) {
486
		switch(key) {
350
			case 'q': exit(0);
487
			case 'q': exit(0);
351
			case '\033':
488
			case '\033':
352
				theConsole.ToggleConsole();
489
				theConsole.ToggleConsole();
353
				break;
490
				break;
-
 
491
			case 'f': display_flat = !display_flat;
354
			case '+': 
492
			case '+': 
355
				display_eigenvalue = min(display_eigenvalue+1, MAX_E); 
493
				display_eigenvalue = min(display_eigenvalue+1, MAX_E); 
356
				break;
494
				break;
357
			case '-': 
495
			case '-': 
358
				display_eigenvalue = max(display_eigenvalue-1, 0); 
496
				display_eigenvalue = max(display_eigenvalue-1, 0); 
359
				break;
497
				break;
360
			case '1': E = 1; reconstruct(mani,E); 
498
			case '1': E = 1; reconstruct(mani,E); 
361
				break;
499
				break;
362
			case '>': if(E < MAX_E) partial_reconstruct(mani,E,++E); 
500
			case '>': if(E < MAX_E) partial_reconstruct(mani,E,++E); 
363
				break;
501
				break;
364
			case '<': E = max(E-1, 0); reconstruct(mani,E); 
502
			case '<': E = max(E-1, 0); reconstruct(mani,E); 
365
				break;
503
				break;
366
			case 'd':	
504
			case 'd':	
367
				display_diffuse = !display_diffuse; 
505
				display_diffuse = !display_diffuse; 
368
				break;
506
				break;
369
			case 'h':
507
			case 'h':
370
				display_highlight = !display_highlight;
508
				display_highlight = !display_highlight;
371
				break;			
509
				break;			
372
			case 'w':
510
			case 'w':
373
				display_wireframe = !display_wireframe;
511
				display_wireframe = !display_wireframe;
374
				break;
512
				break;
375
		}
513
		}
-
 
514
		create_display_list = true;
-
 
515
 
376
	}
516
	}
377
	create_display_list = true;
-
 
378
}
517
}
379
 
518
 
380
void init_glut(int argc, char** argv)
519
void init_glut(int argc, char** argv)
381
{
520
{
382
	glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH);
521
	glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH);
383
	glutInitWindowSize(WINX, WINY);
522
	glutInitWindowSize(WINX, WINY);
384
	glutInit(&argc, argv);
523
	glutInit(&argc, argv);
385
	glutCreateWindow("Shape Harmonics");
524
	glutCreateWindow("Shape Harmonics");
386
	glutDisplayFunc(display);
525
	glutDisplayFunc(display);
387
	glutKeyboardFunc(keyboard);
526
	glutKeyboardFunc(keyboard);
388
	glutSpecialFunc(keyboard_spec);
527
	glutSpecialFunc(keyboard_spec);
389
	glutReshapeFunc(reshape);
528
	glutReshapeFunc(reshape);
390
	glutMouseFunc(mouse);
529
	glutMouseFunc(mouse);
391
	glutMotionFunc(motion);
530
	glutMotionFunc(motion);
392
	glutIdleFunc(animate);
531
	glutIdleFunc(animate);
393
}
532
}
394
 
533
 
395
void init_gl()
534
void init_gl()
396
{
535
{
397
	glewInit();
536
	glewInit();
398
	glEnable(GL_LIGHTING);
537
	glEnable(GL_LIGHTING);
399
	glEnable(GL_LIGHT0);
538
	glEnable(GL_LIGHT0);
-
 
539
	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
400
	Vec3f c(0,0,0);
540
	Vec3f c(0,0,0);
401
	float r = 5;
541
	float r = 5;
402
	mani.get_bsphere(c,r);
542
	mani.get_bsphere(c,r);
403
	view_ctrl = new GLViewController(WINX,WINY, c,r*2);
543
	view_ctrl = new GLViewController(WINX,WINY, c,r*2);
404
	
544
	
405
	initialize_wireframe_shaders();
545
	initialize_wireframe_shaders();
406
	
546
	
407
	
547
	
408
	// Set the value of a uniform
548
	// Set the value of a uniform
409
	//glUniform2f(glGetUniformLocation(prog_P0,"WIN_SCALE"), win_size_x/2.0, win_size_y/2.0);
549
	//glUniform2f(glGetUniformLocation(prog_P0,"WIN_SCALE"), win_size_x/2.0, win_size_y/2.0);
410
	
550
	
411
	glMatrixMode(GL_MODELVIEW);
551
	glMatrixMode(GL_MODELVIEW);
412
	glLoadIdentity();
552
	glLoadIdentity();
413
	glClearColor(0.50f, 0.50f, 0.50f, 0.f);
553
	glClearColor(0.50f, 0.50f, 0.50f, 0.f);
414
	glColor4f(1.0f, 1.0f, 1.0f, 0.f);
554
	glColor4f(1.0f, 1.0f, 1.0f, 0.f);
415
	glEnable(GL_DEPTH_TEST);
555
	glEnable(GL_DEPTH_TEST);
416
	
556
	
417
	static CVar<ConsoleFunc> help( "help", ConsoleHelp );
557
	static CVar<ConsoleFunc> help( "help", ConsoleHelp );
418
	static CVar<ConsoleFunc> rs("reset_shape", console_reset_shape);
558
	static CVar<ConsoleFunc> rs("harmonics_reset_shape", console_reset_shape);
-
 
559
	static CVar<ConsoleFunc> ha("harmonics_analyze", console_analyze);
419
	static CVar<ConsoleFunc> pr("partial_reconstruct", console_partial_reconstruct);
560
	static CVar<ConsoleFunc> pr("harmonics_partial_reconstruct", console_partial_reconstruct);
420
	static CVar<ConsoleFunc> simpl("simplify", console_simplify);
561
	static CVar<ConsoleFunc> simpl("simplify", console_simplify);
421
	static CVar<ConsoleFunc> lsmooth("laplacian_smooth", console_laplacian_smooth);
562
	static CVar<ConsoleFunc> lsmooth("laplacian_smooth", console_laplacian_smooth);
422
	static CVar<ConsoleFunc> tsmooth("taubin_smooth", console_taubin_smooth);
563
	static CVar<ConsoleFunc> tsmooth("taubin_smooth", console_taubin_smooth);
423
	static CVar<ConsoleFunc> fsmooth("fvm_smooth", console_fvm_smooth);
564
	static CVar<ConsoleFunc> fsmooth("fvm_smooth", console_fvm_smooth);
424
 
565
 
425
	static CVar<ConsoleFunc> opt_val("optimize_valency", console_optimize_valency);
566
	static CVar<ConsoleFunc> opt_val("optimize_valency", console_optimize_valency);
426
	static CVar<ConsoleFunc> min_dih("minimize_dihedral", console_minimize_dihedral);
567
	static CVar<ConsoleFunc> min_dih("minimize_dihedral", console_minimize_dihedral);
427
	static CVar<ConsoleFunc> min_curv("minimize_curvature", console_minimize_curvature);
568
	static CVar<ConsoleFunc> min_curv("minimize_curvature", console_minimize_curvature);
-
 
569
	static CVar<ConsoleFunc> max_min_angle("maximize_min_angle", console_maximize_min_angle);
-
 
570
	static CVar<ConsoleFunc> close_holes_fun("close_holes", console_close_holes);
-
 
571
	static CVar<ConsoleFunc> reload_fun("reload", console_reload);
-
 
572
 
-
 
573
	static CVar<ConsoleFunc> rem_caps_fun("remove_caps", console_remove_caps);
-
 
574
	static CVar<ConsoleFunc> rem_needles_fun("remove_needles", console_remove_needles);
-
 
575
	static CVar<ConsoleFunc> triangulate_fun("triangulate", console_triangulate);
-
 
576
	static CVar<ConsoleFunc> refine_fun("refine_edges", console_refine_edges);
-
 
577
	static CVar<ConsoleFunc> refine_face_fun("refine_faces", console_refine_faces);
-
 
578
	static CVar<ConsoleFunc> subd_fun("refine_catmull_clark", console_cc_subdivide);
-
 
579
	static CVar<ConsoleFunc> save_fun("save", console_save);
428
	
580
	
429
	
581
	
430
}
582
}
431
 
583
 
432
int main(int argc, char** argv)
584
int main(int argc, char** argv)
433
{
585
{
434
	ArgExtracter ae(argc, argv);
586
	ArgExtracter ae(argc, argv);
435
	ae.extract("-E", E);
587
	ae.extract("-E", E);
436
    if(argc>1)
588
    if(argc>1)
437
	{		
589
	{		
438
		string file = ae.get_last_arg();
590
		 file = ae.get_last_arg();
439
		load(file, mani);
591
		load(file, mani);
440
	}
592
	}
441
 
593
 
442
	
594
	
443
	init_glut(argc,argv);
595
	init_glut(argc,argv);
444
	init_gl();
596
	init_gl();
445
	init_harmonics(mani);
597
	init_harmonics();
446
 
598
 
447
	glutMainLoop();
599
	glutMainLoop();
448
}
600
}
449
 
601
 
450
 
602
 
451
 
603