Subversion Repositories gelsvn

Rev

Rev 393 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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