Subversion Repositories gelsvn

Rev

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

Rev 391 Rev 394
Line 46... Line 46...
46
#include <HMesh/caps_and_needles.h>
46
#include <HMesh/caps_and_needles.h>
47
#include <HMesh/refine_edges.h>
47
#include <HMesh/refine_edges.h>
48
#include <HMesh/subdivision.h>
48
#include <HMesh/subdivision.h>
49
 
49
 
50
#include <GLConsole/GLConsole.h>
50
#include <GLConsole/GLConsole.h>
51
 
-
 
-
 
51
#include <Util/Timer.h>
52
#include "harmonics.h"
52
#include "harmonics.h"
53
#include "wireframe.h"
53
#include "wireframe.h"
54
 
54
 
55
using namespace std;
55
using namespace std;
56
using namespace HMesh;
56
using namespace HMesh;
Line 95... Line 95...
95
	{
95
	{
96
	}
96
	}
97
	
97
	
98
	void display(bool wire, bool harm, bool flat)
98
	void display(bool wire, bool harm, bool flat)
99
	{
99
	{
-
 
100
/*		static Timer tim;
-
 
101
		tim.start();*/
100
		if(create_display_list)
102
		if(create_display_list)
101
		{
103
		{
102
			create_display_list = false;
104
			create_display_list = false;
103
			
105
			
104
			glNewList(display_list,GL_COMPILE);
106
			glNewList(display_list,GL_COMPILE);
105
			if(wire)
107
			if(wire)
106
			{
108
			{
107
				enable_wireframe();
109
				enable_wireframe();
108
				draw(mani);
110
				draw(mani,false);
109
				glUseProgram(0);	
111
				glUseProgram(0);	
110
			}
112
			}
111
			else if(harm)
113
			else if(harm)
112
				harmonics->draw();
114
				harmonics->draw();
113
			else 
115
			else 
114
				draw(mani,!flat);
116
				draw(mani,!flat);
115
			glEndList();
117
			glEndList();
116
		}
118
		}
117
		view_ctrl.reset_projection();
-
 
118
		view_ctrl.set_gl_modelview();
119
		view_ctrl.set_gl_modelview();
119
		glCallList(display_list);
120
		glCallList(display_list);
-
 
121
		// tim.get_secs();
120
	}
122
	}
121
	
123
	
122
	
124
	
123
	void post_create_display_list()
125
	void post_create_display_list()
124
	{
126
	{
Line 192... Line 194...
192
    theConsole.Printf("");
194
    theConsole.Printf("");
193
    theConsole.Printf("Keyboard commands (when console is not active):");
195
    theConsole.Printf("Keyboard commands (when console is not active):");
194
    theConsole.Printf("w   : toggle wireframe");
196
    theConsole.Printf("w   : toggle wireframe");
195
    theConsole.Printf("f   : toggle flatshading");
197
    theConsole.Printf("f   : toggle flatshading");
196
    theConsole.Printf("1-9 : switch between active meshes.");
198
    theConsole.Printf("1-9 : switch between active meshes.");
197
    theConsole.Printf("d   : (display.harmonics = 1) diffuse light on and off");
199
    theConsole.Printf("d   : (display.show_harmonics = 1) diffuse light on and off");
198
    theConsole.Printf("h   : (display.harmonics = 1) highlight on and off ");
200
    theConsole.Printf("h   : (display.show_harmonics = 1) highlight on and off ");
199
    theConsole.Printf("+/- : (display.harmonics = 1) which eigenvector to show");
201
    theConsole.Printf("+/- : (display.show_harmonics = 1) which eigenvector to show");
200
    theConsole.Printf("q   : quit program");
202
    theConsole.Printf("q   : quit program");
201
    theConsole.Printf("ESC : open console");
203
    theConsole.Printf("ESC : open console");
202
    theConsole.Printf("");
204
    theConsole.Printf("");
203
    theConsole.Printf("Mouse: Left button rotates, middle zooms, right pans");
205
    theConsole.Printf("Mouse: Left button rotates, middle zooms, right pans");
204
    theConsole.Printf("----------------- HELP -----------------");
206
    theConsole.Printf("----------------- HELP -----------------");
Line 322... Line 324...
322
		}
324
		}
323
	cc_split(active_mesh(),active_mesh());
325
	cc_split(active_mesh(),active_mesh());
324
	return "";
326
	return "";
325
}
327
}
326
 
328
 
-
 
329
char* console_dual(std::vector<std::string> &args)
-
 
330
{
-
 
331
	if(wantshelp(args)) 
-
 
332
	{
-
 
333
		theConsole.Printf("usage: dual ");
-
 
334
		theConsole.Printf("Produces the dual by converting each face to a vertex placed at the barycenter.");
-
 
335
		return "";
-
 
336
	}
-
 
337
	
-
 
338
	Manifold& m = active_mesh();
-
 
339
	
-
 
340
	// make sure every face knows its number
-
 
341
	m.enumerate_faces();
-
 
342
	
-
 
343
	vector<Vec3f> vertices(m.no_faces());
-
 
344
	vector<int> faces(m.no_vertices());
-
 
345
	vector<int> indices;
-
 
346
	
-
 
347
	// Create new vertices. Each face becomes a vertex whose position
-
 
348
	// is the centre of the face
-
 
349
	int i=0;
-
 
350
	for(FaceIter f=m.faces_begin(); f!=m.faces_end(); ++f,++i)
-
 
351
		vertices[i] = centre(f);
-
 
352
	
-
 
353
	// Create new faces. Each vertex is a new face with N=valency of vertex
-
 
354
	// edges.
-
 
355
	i=0;
-
 
356
	for(VertexIter v=m.vertices_begin(); v!= m.vertices_end(); ++v,++i)
-
 
357
	{
-
 
358
		VertexCirculator vc(v);
-
 
359
		vector<int> index_tmp;
-
 
360
		for(; !vc.end(); ++vc)
-
 
361
			index_tmp.push_back(vc.get_face()->touched);
-
 
362
		
-
 
363
		// Push vertex indices for this face onto indices vector.
-
 
364
		// The circulator moves around the face in a clockwise fashion
-
 
365
		// so we just reverse the ordering.
-
 
366
		indices.insert(indices.end(), index_tmp.rbegin(), index_tmp.rend());
-
 
367
		
-
 
368
		// Insert face valency in the face vector.
-
 
369
		faces[i] = vc.no_steps();
-
 
370
	}
-
 
371
	
-
 
372
	// Clear the manifold before new geometry is inserted.
-
 
373
	m.clear();
-
 
374
	
-
 
375
	// And build
-
 
376
	build_manifold(m, vertices.size(), &vertices[0], faces.size(),
-
 
377
				   &faces[0],&indices[0]);
-
 
378
	
-
 
379
	return "";
-
 
380
}
327
 
381
 
328
 
382
 
329
char* console_minimize_curvature(std::vector<std::string> &args)
383
char* console_minimize_curvature(std::vector<std::string> &args)
330
{
384
{
331
	if(wantshelp(args)) 
385
	if(wantshelp(args)) 
Line 728... Line 782...
728
void display() 
782
void display() 
729
{
783
{
730
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
784
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
731
	
785
	
732
	static CVar<int> display_wireframe("display.wireframe",0);
786
	static CVar<int> display_wireframe("display.wireframe",0);
733
	static CVar<int> display_eigenmodes("display.harmonics",0);
787
	static CVar<int> display_eigenmodes("display.show_harmonics",0);
734
	static CVar<int> display_flat("display.flatshading",0);
788
	static CVar<int> display_flat("display.flatshading",0);
735
	
789
	
736
	glPushMatrix();
790
	glPushMatrix();
737
	
791
	
738
	avo().display(display_wireframe, display_eigenmodes, display_flat);
792
	avo().display(display_wireframe, display_eigenmodes, display_flat);
Line 745... Line 799...
745
	glutSwapBuffers();
799
	glutSwapBuffers();
746
}
800
}
747
 
801
 
748
void animate() 
802
void animate() 
749
{	
803
{	
750
	usleep( (int)1e4 );
804
	//usleep( (int)1e4 );
751
	active_view_control().try_spin();
805
	active_view_control().try_spin();
752
	glutPostRedisplay();
806
	glutPostRedisplay();
753
}
807
}
754
 
808
 
755
 
809
 
756
void mouse(int button, int state, int x, int y) 
810
void mouse(int button, int state, int x, int y) 
757
{
811
{
758
	cout << button << endl;
-
 
759
	Vec2i pos(x,y);
812
	Vec2i pos(x,y);
760
	if (state==GLUT_DOWN) 
813
	if (state==GLUT_DOWN) 
761
	{
814
	{
762
		if (button==GLUT_LEFT_BUTTON) 
815
		if (button==GLUT_LEFT_BUTTON) 
763
			active_view_control().grab_ball(ROTATE_ACTION,pos);
816
			active_view_control().grab_ball(ROTATE_ACTION,pos);
Line 843... Line 896...
843
			case 'w':
896
			case 'w':
844
				display_wireframe = !display_wireframe;
897
				display_wireframe = !display_wireframe;
845
				break;
898
				break;
846
		}
899
		}
847
		
900
		
848
		if(get_CVar_ref<int>("display.harmonics"))
901
		if(get_CVar_ref<int>("display.show_harmonics"))
849
			avo().harmonics_parse_key(key);
902
			avo().harmonics_parse_key(key);
850
		
903
		
851
		avo().post_create_display_list();		
904
		avo().post_create_display_list();		
852
	}
905
	}
853
}
906
}
Line 910... Line 963...
910
	static CVar<ConsoleFunc> subd_fun("refine.catmull_clark", console_cc_subdivide);
963
	static CVar<ConsoleFunc> subd_fun("refine.catmull_clark", console_cc_subdivide);
911
	static CVar<ConsoleFunc> save_fun("save", console_save);
964
	static CVar<ConsoleFunc> save_fun("save", console_save);
912
	static CVar<ConsoleFunc> noise_fun("noise.perturb_vertices", console_vertex_noise);
965
	static CVar<ConsoleFunc> noise_fun("noise.perturb_vertices", console_vertex_noise);
913
	static CVar<ConsoleFunc> noise_fun2("noise.perturb_topology", console_noisy_flips);
966
	static CVar<ConsoleFunc> noise_fun2("noise.perturb_topology", console_noisy_flips);
914
 
967
 
-
 
968
	static CVar<ConsoleFunc> dualize("dual", console_dual);
-
 
969
 
915
	static CVar<ConsoleFunc> align_fun("align", console_align);
970
	static CVar<ConsoleFunc> align_fun("align", console_align);
916
	
971
	
917
	
972
	
918
}
973
}
919
 
974