Subversion Repositories gelsvn

Rev

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

Rev 411 Rev 412
Line 47... Line 47...
47
#include <HMesh/subdivision.h>
47
#include <HMesh/subdivision.h>
48
 
48
 
49
#include <GLConsole/GLConsole.h>
49
#include <GLConsole/GLConsole.h>
50
#include <Util/Timer.h>
50
#include <Util/Timer.h>
51
#include "harmonics.h"
51
#include "harmonics.h"
-
 
52
#include "curvature.h"
52
#include "Renderer.h"
53
#include "Renderer.h"
53
#include "VisObj.h"
54
#include "VisObj.h"
54
 
55
 
55
using namespace std;
56
using namespace std;
56
using namespace HMesh;
57
using namespace HMesh;
57
using namespace Geometry;
58
using namespace Geometry;
58
using namespace GLGraphics;
59
using namespace GLGraphics;
59
using namespace CGLA;
60
using namespace CGLA;
60
using namespace Util;
61
using namespace Util;
61
using namespace LinAlg;
62
using namespace LinAlg;
62
 
-
 
63
template<typename T>
63
using namespace CVarUtils;
64
T& get_CVar_ref(const std::string& s)
-
 
65
{
-
 
66
	return *reinterpret_cast<T*> (GetCVarData(s));
-
 
67
}
-
 
68
 
64
 
69
inline VisObj& get_vis_obj(int i)
65
inline VisObj& get_vis_obj(int i)
70
{
66
{
71
	static VisObj vo[9];
67
	static VisObj vo[9];
72
	return vo[i];
68
	return vo[i];
73
}
69
}
74
 
70
 
75
inline VisObj& avo()
71
inline VisObj& avo()
76
{
72
{
77
	static CVar<int> active("active_mesh",0);
73
	static int& active = CreateCVar("active_mesh",0);
78
	return get_vis_obj(active);
74
	return get_vis_obj(active);
79
}
75
}
80
 
76
 
81
inline Manifold& active_mesh()
77
inline Manifold& active_mesh()
82
{
78
{
Line 87... Line 83...
87
{
83
{
88
	return avo().view_control();
84
	return avo().view_control();
89
}
85
}
90
 
86
 
91
// Single global instance so glut can get access
87
// Single global instance so glut can get access
-
 
88
Trie CVarTrie;
92
GLConsole theConsole;
89
GLConsole theConsole;
93
 
90
 
94
////////////////////////////////////////////////////////////////////////////////
91
////////////////////////////////////////////////////////////////////////////////
95
char* ConsoleHelp(std::vector<std::string> &args)
92
char* ConsoleHelp(std::vector<std::string> &args)
96
{
93
{
Line 197... Line 194...
197
		return "unknown format";
194
		return "unknown format";
198
	}
195
	}
199
	return "usage: save <name.x3d|name.obj> ";
196
	return "usage: save <name.x3d|name.obj> ";
200
}
197
}
201
 
198
 
-
 
199
char* console_save_history(std::vector<std::string> &args)
-
 
200
{
-
 
201
	if(wantshelp(args)) 
-
 
202
	{
-
 
203
		theConsole.Printf("usage: save_history <file> ... writes history to file");
-
 
204
		return "";
-
 
205
	}
-
 
206
	if(args.size()>0)
-
 
207
	{
-
 
208
		string& file_name = args[0];
-
 
209
		theConsole.SaveHistoryScript(file_name.c_str());
-
 
210
		return "";
-
 
211
	}
-
 
212
	return "must supply file name\n";
-
 
213
}
-
 
214
 
-
 
215
char* console_exec_script(std::vector<std::string> &args)
-
 
216
{
-
 
217
	if(wantshelp(args)) 
-
 
218
	{
-
 
219
		theConsole.Printf("usage: source <file> ... runs script");
-
 
220
		return "";
-
 
221
	}
-
 
222
	if(args.size()>0)
-
 
223
	{
-
 
224
		string& file_name = args[0];
-
 
225
		theConsole.ExecuteScript(file_name.c_str());
-
 
226
		return "";
-
 
227
	}
-
 
228
	return "must supply file name\n";
-
 
229
}
-
 
230
 
-
 
231
 
202
char* console_refine_edges(std::vector<std::string> &args)
232
char* console_refine_edges(std::vector<std::string> &args)
203
{
233
{
204
	if(wantshelp(args)) 
234
	if(wantshelp(args)) 
205
	{
235
	{
206
		theConsole.Printf("usage: refine.split_edges <length>");
236
		theConsole.Printf("usage: refine.split_edges <length>");
Line 489... Line 519...
489
 
519
 
490
char* console_reload(std::vector<std::string> &args)
520
char* console_reload(std::vector<std::string> &args)
491
{
521
{
492
	if(wantshelp(args)) 
522
	if(wantshelp(args)) 
493
	{
523
	{
494
		theConsole.Printf("usage:  reload <file>");
524
		theConsole.Printf("usage:  load <file>");
495
		theConsole.Printf("Reloads the current file if no argument is given, but");
525
		theConsole.Printf("(Re)loads the current file if no argument is given, but");
496
		theConsole.Printf("if an argument is given, then that becomes the current file");
526
		theConsole.Printf("if an argument is given, then that becomes the current file");
497
		return "";
527
		return "";
498
	}
528
	}
499
	if(!avo().reload(args.size()>0 ? args[0]:""))
529
	if(!avo().reload(args.size()>0 ? args[0]:""))
500
		return "failed to load";
530
		return "failed to load";
Line 564... Line 594...
564
		vi->pos += v;
594
		vi->pos += v;
565
	}		
595
	}		
566
	return "";
596
	return "";
567
}
597
}
568
 
598
 
-
 
599
char* console_perpendicular_vertex_noise(std::vector<std::string> &args)
-
 
600
{
-
 
601
	if(wantshelp(args)) 
-
 
602
	{
-
 
603
		theConsole.Printf("usage: noise.perturb_vertices_perpendicular <amplitude>");
-
 
604
		theConsole.Printf("adds the normal times a random scalar times amplitude times");
-
 
605
		theConsole.Printf("times average edge length to the vertex. (default amplitude=0.5)");
-
 
606
		return "";
-
 
607
	}
-
 
608
	float avg_length = average_edge_length(active_mesh());
-
 
609
	
-
 
610
	float noise_amplitude = 0.5;
-
 
611
	if(args.size()>0) 
-
 
612
	{
-
 
613
		istringstream a0(args[0]);
-
 
614
		a0 >> noise_amplitude;
-
 
615
	}
-
 
616
	
-
 
617
	vector<Vec3f> normals(active_mesh().no_vertices());
-
 
618
	int i=0;
-
 
619
	for(VertexIter vi = active_mesh().vertices_begin(); vi != active_mesh().vertices_end(); ++vi,++i)
-
 
620
		normals[i] = normal(vi);
-
 
621
	i=0;
-
 
622
	srandom(0);
-
 
623
	for(VertexIter vi = active_mesh().vertices_begin(); vi != active_mesh().vertices_end(); ++vi,++i)
-
 
624
	{
-
 
625
		float rval = 0.5-random()/float(RAND_MAX);
-
 
626
		vi->pos += normals[i]*rval*noise_amplitude*avg_length*2.0;
-
 
627
	}
-
 
628
	return "";
-
 
629
}
-
 
630
 
569
char* console_noisy_flips(std::vector<std::string> &args)
631
char* console_noisy_flips(std::vector<std::string> &args)
570
{
632
{
571
	if(wantshelp(args)) 
633
	if(wantshelp(args)) 
572
	{
634
	{
573
		theConsole.Printf("usage:  noise.perturb_topology <iter>");
635
		theConsole.Printf("usage:  noise.perturb_topology <iter>");
Line 588... Line 650...
588
 
650
 
589
char* console_laplacian_smooth(std::vector<std::string> &args)
651
char* console_laplacian_smooth(std::vector<std::string> &args)
590
{
652
{
591
	if(wantshelp(args)) 
653
	if(wantshelp(args)) 
592
	{
654
	{
593
		theConsole.Printf("usage:  smooth.laplacian <weight>");
655
		theConsole.Printf("usage:  smooth.laplacian <weight> <iter>");
594
		theConsole.Printf("Perform Laplacian smoothing. weight is the scaling factor for the Laplacian.");
656
		theConsole.Printf("Perform Laplacian smoothing. weight is the scaling factor for the Laplacian.");
-
 
657
		theConsole.Printf("default weight = 1.0. Default number of iterations = 1");
595
		return "";
658
		return "";
596
	}
659
	}
597
	float t=1.0;
660
	float t=1.0;
598
	if(args.size()>0)
661
	if(args.size()>0)
599
	{
662
	{
600
		istringstream a0(args[0]);
663
		istringstream a0(args[0]);
601
		a0 >> t;
664
		a0 >> t;
602
	}
665
	}
-
 
666
	int iter=1;
-
 
667
	if(args.size()>1)
-
 
668
	{
-
 
669
		istringstream a0(args[1]);
-
 
670
		a0 >> iter;
-
 
671
	}
-
 
672
	
603
	/// Simple laplacian smoothing with an optional weight.
673
	/// Simple laplacian smoothing with an optional weight.
604
	laplacian_smooth(active_mesh(), t);
674
	for(int i=0;i<iter;++i) laplacian_smooth(active_mesh(), t);
605
	return "";
675
	return "";
606
}
676
}
607
 
677
 
-
 
678
char* console_mean_curvature_smooth(std::vector<std::string> &args)
-
 
679
{
-
 
680
	if(wantshelp(args)) 
-
 
681
	{
-
 
682
		theConsole.Printf("usage:  smooth.mean_curvature <weight> <iter>");
-
 
683
		theConsole.Printf("Perform mean curvature smoothing. weight is the scaling factor for the");
-
 
684
		theConsole.Printf("mean curvature vector which has been normalized by dividing by edge lengths");
-
 
685
		theConsole.Printf("this allows for larger steps as suggested by Desbrun et al.");
-
 
686
		theConsole.Printf("default weight = 1.0. Default number of iterations = 1");
-
 
687
		return "";
-
 
688
	}
-
 
689
	float t=1.0;
-
 
690
	if(args.size()>0)
-
 
691
	{
-
 
692
		istringstream a0(args[0]);
-
 
693
		a0 >> t;
-
 
694
	}
-
 
695
	int iter=1;
-
 
696
	if(args.size()>1)
-
 
697
	{
-
 
698
		istringstream a0(args[1]);
-
 
699
		a0 >> iter;
-
 
700
	}	
-
 
701
	vector<Vec3d> new_pos(active_mesh().no_vertices());
-
 
702
	for(int j=0;j<iter;++j)
-
 
703
	{
-
 
704
		int i=0;
-
 
705
		for(VertexIter v = active_mesh().vertices_begin(); v != active_mesh().vertices_end(); ++v,++i) {
-
 
706
			Vec3d m;
-
 
707
			double w_sum;
-
 
708
			unnormalized_mean_curvature_normal(v, m, w_sum);
-
 
709
			new_pos[i] = Vec3d(v->pos)  - (t * m/w_sum);
-
 
710
		}
-
 
711
		i=0;
-
 
712
		for(VertexIter v = active_mesh().vertices_begin(); v != active_mesh().vertices_end(); ++v,++i)
-
 
713
			v->pos = Vec3f(new_pos[i]);
-
 
714
	}
-
 
715
	return "";
-
 
716
}
-
 
717
 
-
 
718
 
608
char* console_taubin_smooth(std::vector<std::string> &args)
719
char* console_taubin_smooth(std::vector<std::string> &args)
609
{
720
{
610
	if(wantshelp(args)) 
721
	if(wantshelp(args)) 
611
	{
722
	{
612
		theConsole.Printf("usage:  smooth.taubin <iter>");
723
		theConsole.Printf("usage:  smooth.taubin <iter>");
Line 709... Line 820...
709
 
820
 
710
void display() 
821
void display() 
711
{
822
{
712
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
823
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
713
	
824
	
714
	static CVar<string> display_render_mode("display.render_mode","");
825
	static string& display_render_mode = CreateCVar<string>("display.render_mode","");
715
	static CVar<int> display_smooth("display.smooth_shading",1);
826
	static int& display_smooth= CreateCVar<int>("display.smooth_shading",1);
716
	
827
	
717
	glPushMatrix();
828
	glPushMatrix();
718
	
829
	
719
	avo().display(display_render_mode, display_smooth);
830
	avo().display(display_render_mode, display_smooth);
720
	
831
	
Line 756... Line 867...
756
}
867
}
757
 
868
 
758
void keyboard_spec(int key, int x, int y)
869
void keyboard_spec(int key, int x, int y)
759
{
870
{
760
	int mod = glutGetModifiers();
871
	int mod = glutGetModifiers();
761
	if( theConsole.isOpen() ) {
872
	if( theConsole.IsOpen() ) {
762
		// If shift held, scroll the console
873
		// If shift held, scroll the console
763
		if( mod == GLUT_ACTIVE_SHIFT ) {
874
		if( mod == GLUT_ACTIVE_SHIFT ) {
764
			switch (key){
875
			switch (key){
765
				case GLUT_KEY_UP:
876
				case GLUT_KEY_UP:
766
					theConsole.ScrollDownLine();
877
					theConsole.ScrollDownLine();
Line 776... Line 887...
776
}
887
}
777
 
888
 
778
 
889
 
779
void keyboard(unsigned char key, int x, int y) 
890
void keyboard(unsigned char key, int x, int y) 
780
{	
891
{	
781
	if(theConsole.isOpen())
892
	if(theConsole.IsOpen())
782
	{
893
	{
783
		switch(key) {
894
		switch(key) {
784
			case '\033': 
895
			case '\033': 
785
				theConsole.ToggleConsole();
896
				theConsole.ToggleConsole();
786
			default:      
897
			default:
787
				//send keystroke to console
-
 
788
				if( theConsole.isOpen() ){
-
 
789
					theConsole.EnterCommandCharacter(key);
898
				theConsole.EnterCommandCharacter(key);
790
				}
-
 
791
				break;
899
			break;
792
		}
900
		}
793
		if(key == 13)	avo().post_create_display_list();
901
		if(key == 13)	avo().post_create_display_list();
794
		
902
		
795
	}	
903
	}	
796
	else {
904
	else {
797
		string& display_render_mode = get_CVar_ref<string>("display.render_mode");
905
		string& display_render_mode = GetCVarRef<string>("display.render_mode");
798
		int& display_smooth = get_CVar_ref<int>("display.smooth_shading");
906
		int& display_smooth = GetCVarRef<int>("display.smooth_shading");
799
		int& active  = get_CVar_ref<int>("active_mesh");
907
		int& active  = GetCVarRef<int>("active_mesh");
800
		
908
		
801
		
909
		
802
		switch(key) {
910
		switch(key) {
803
			case 'q': exit(0);
911
			case 'q': exit(0);
804
			case '\033':
912
			case '\033':
Line 879... Line 987...
879
	glColor4f(1.0f, 1.0f, 1.0f, 0.f);
987
	glColor4f(1.0f, 1.0f, 1.0f, 0.f);
880
	float material[4] = {1,1,1,1};
988
	float material[4] = {1,1,1,1};
881
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material);
989
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material);
882
	glEnable(GL_DEPTH_TEST);
990
	glEnable(GL_DEPTH_TEST);
883
	
991
	
884
	static CVar<ConsoleFunc> help( "help", ConsoleHelp );
992
	CreateCVar( "help", ConsoleHelp );
885
	static CVar<ConsoleFunc> rs("harmonics.reset_shape", console_reset_shape);
993
	CreateCVar("harmonics.reset_shape", console_reset_shape);
886
	static CVar<ConsoleFunc> ha("harmonics.analyze", console_analyze);
994
	CreateCVar("harmonics.analyze", console_analyze);
887
	static CVar<ConsoleFunc> pr("harmonics.partial_reconstruct", console_partial_reconstruct);
995
	CreateCVar("harmonics.partial_reconstruct", console_partial_reconstruct);
888
	static CVar<ConsoleFunc> simpl("simplify", console_simplify);
996
	CreateCVar("simplify", console_simplify);
-
 
997
	CreateCVar("smooth.mean_curvature", console_mean_curvature_smooth);
889
	static CVar<ConsoleFunc> lsmooth("smooth.laplacian", console_laplacian_smooth);
998
	CreateCVar("smooth.laplacian", console_laplacian_smooth);
890
	static CVar<ConsoleFunc> tsmooth("smooth.taubin", console_taubin_smooth);
999
	CreateCVar("smooth.taubin", console_taubin_smooth);
891
	static CVar<ConsoleFunc> fsmooth("smooth.fuzzy_vector_median", console_fvm_smooth);
1000
	CreateCVar("smooth.fuzzy_vector_median", console_fvm_smooth);
892
	
1001
	
893
	static CVar<ConsoleFunc> opt_val("optimize.valency", console_optimize_valency);
1002
	CreateCVar("optimize.valency", console_optimize_valency);
894
	static CVar<ConsoleFunc> min_dih("optimize.minimize_dihedral_angles", console_minimize_dihedral);
1003
	CreateCVar("optimize.minimize_dihedral_angles", console_minimize_dihedral);
895
	static CVar<ConsoleFunc> min_curv("optimize.minimize_curvature", console_minimize_curvature);
1004
	CreateCVar("optimize.minimize_curvature", console_minimize_curvature);
896
	static CVar<ConsoleFunc> max_min_angle("optimize.maximize_min_angle", console_maximize_min_angle);
1005
	CreateCVar("optimize.maximize_min_angle", console_maximize_min_angle);
897
	static CVar<ConsoleFunc> close_holes_fun("cleanup.close_holes", console_close_holes);
1006
	CreateCVar("cleanup.close_holes", console_close_holes);
898
	static CVar<ConsoleFunc> reload_fun("reload", console_reload);
1007
	CreateCVar("load", console_reload);
899
	
1008
	
900
	static CVar<ConsoleFunc> rem_caps_fun("cleanup.remove_caps", console_remove_caps);
1009
	CreateCVar("cleanup.remove_caps", console_remove_caps);
901
	static CVar<ConsoleFunc> rem_needles_fun("cleanup.remove_needles", console_remove_needles);
1010
	CreateCVar("cleanup.remove_needles", console_remove_needles);
902
	static CVar<ConsoleFunc> triangulate_fun("triangulate", console_triangulate);
1011
	CreateCVar("triangulate", console_triangulate);
903
	static CVar<ConsoleFunc> refine_fun("refine.split_edges", console_refine_edges);
1012
	CreateCVar("refine.split_edges", console_refine_edges);
904
	static CVar<ConsoleFunc> refine_face_fun("refine.split_faces", console_refine_faces);
1013
	CreateCVar("refine.split_faces", console_refine_faces);
905
	static CVar<ConsoleFunc> subd_fun("refine.catmull_clark", console_cc_subdivide);
1014
	CreateCVar("refine.catmull_clark", console_cc_subdivide);
906
	static CVar<ConsoleFunc> save_fun("save", console_save);
1015
	CreateCVar("save", console_save);
907
	static CVar<ConsoleFunc> noise_fun("noise.perturb_vertices", console_vertex_noise);
1016
	CreateCVar("noise.perturb_vertices", console_vertex_noise);
-
 
1017
	CreateCVar("noise.perturb_vertices_perpendicular", console_perpendicular_vertex_noise);
908
	static CVar<ConsoleFunc> noise_fun2("noise.perturb_topology", console_noisy_flips);
1018
	CreateCVar("noise.perturb_topology", console_noisy_flips);
909
	
1019
	
910
	static CVar<ConsoleFunc> dualize("dual", console_dual);
1020
	CreateCVar("dual", console_dual);
911
	
1021
	
912
	static CVar<ConsoleFunc> align_fun("align", console_align);
1022
	CreateCVar("align", console_align);
-
 
1023
	CreateCVar("save_history", console_save_history);
-
 
1024
	CreateCVar("source", console_exec_script);
913
	
1025
	
914
	
1026
	
915
}
1027
}
916
 
1028
 
917
int main(int argc, char** argv)
1029
int main(int argc, char** argv)