Subversion Repositories gelsvn

Rev

Rev 387 | Rev 391 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 387 Rev 388
Line 37... Line 37...
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"
Line 81... Line 87...
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)
Line 97... Line 152...
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
{
Line 117... Line 173...
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
 
Line 135... Line 191...
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
	{
Line 147... Line 222...
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]);
Line 172... Line 254...
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";
Line 235... Line 337...
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();
Line 301... Line 434...
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();
Line 328... Line 460...
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); 
Line 371... Line 509...
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);
Line 395... Line 534...
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
	
Line 413... Line 553...
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