Subversion Repositories gelsvn

Rev

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

Rev 417 Rev 456
1
/*
1
/*
2
 *  VisObj.cpp
2
 *  VisObj.cpp
3
 *  GEL
3
 *  GEL
4
 *
4
 *
5
 *  Created by J. Andreas Bærentzen on 20/09/08.
5
 *  Created by J. Andreas Bærentzen on 20/09/08.
6
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
6
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
7
 *
7
 *
8
 */
8
 */
9
 
9
 
10
#include "VisObj.h"
10
#include "VisObj.h"
11
 
11
 
12
#include <GLConsole/GLConsole.h>
12
#include <GLConsole/GLConsole.h>
13
#include <HMesh/load.h>
13
#include <HMesh/load.h>
14
#include "curvature.h"
14
#include "curvature.h"
15
 
15
 
16
using namespace std;
16
using namespace std;
17
using namespace CGLA;
17
using namespace CGLA;
18
using namespace HMesh;
18
using namespace HMesh;
19
using namespace CVarUtils;
19
using namespace CVarUtils;
20
 
20
 
21
int WINX=800, WINY=800;
21
int WINX=800, WINY=800;
22
 
22
 
23
 
23
 
24
bool VisObj::reload(string _file)
24
bool VisObj::reload(string _file)
25
{
25
{
26
	if(_file != "") file = _file;
26
	if(_file != "") file = _file;
27
	mani.clear();
27
	mani.clear();
28
	if(!load(file, mani))
28
	if(!load(file, mani))
29
		return false;
29
		return false;
30
	mani.get_bsphere(bsphere_center,bsphere_radius);
30
	mani.get_bsphere(bsphere_center,bsphere_radius);
31
	view_ctrl.set_centre(bsphere_center);
31
	view_ctrl.set_centre(bsphere_center);
32
	view_ctrl.set_eye_dist(2*bsphere_radius);
32
	view_ctrl.set_eye_dist(2*bsphere_radius);
33
	return true;
33
	return true;
34
}
34
}
35
 
35
 
36
 
36
 
37
void VisObj::display(const std::string& display_method , bool smooth)
37
void VisObj::display(const std::string& display_method , bool smooth)
38
{
38
{
39
	if(create_display_list)
39
	if(create_display_list)
40
	{
40
	{
41
		create_display_list = false;
41
		create_display_list = false;
42
		delete renderer;
42
		delete renderer;
43
		
43
		
44
		string short_name = display_method.substr(0,3);
44
		string short_name = display_method.substr(0,3);
45
		if(short_name== "wir")
45
		if(short_name== "wir")
46
			renderer = new WireframeRenderer(mani, smooth);
46
			renderer = new WireframeRenderer(mani, smooth);
47
		else if(short_name == "har")
47
		else if(short_name == "har")
48
			renderer = new HarmonicsRenderer(harmonics);
48
			renderer = new HarmonicsRenderer(harmonics);
49
		else if(short_name == "iso")
49
		else if(short_name == "iso")
50
			renderer = new IsophoteLineRenderer(mani, smooth);
50
			renderer = new IsophoteLineRenderer(mani, smooth);
51
		else if(short_name == "ref")
51
		else if(short_name == "ref")
52
			renderer = new ReflectionLineRenderer(mani, smooth);
52
			renderer = new ReflectionLineRenderer(mani, smooth);
53
		else if(short_name == "gla")
53
		else if(short_name == "gla")
54
			renderer = new GlazedRenderer(mani, smooth, bsphere_radius);
54
			renderer = new GlazedRenderer(mani, smooth, bsphere_radius);
55
		else if(short_name == "too")
55
		else if(short_name == "too")
56
			renderer = new ToonRenderer(mani, smooth);
56
			renderer = new ToonRenderer(mani, smooth);
57
		else if(short_name == "cur")
57
		else if(short_name == "cur")
58
		{
58
		{
59
			static string& line_direction = CreateCVar<string>("display.curvature_lines.direction", "min");
59
			static string& line_direction = CreateCVar<string>("display.curvature_lines.direction", "min");
60
			
60
			
61
			std::vector<CGLA::Mat3x3d> curvature_tensors;
61
			std::vector<CGLA::Mat3x3d> curvature_tensors;
62
			curvature_tensors_from_edges(mani, curvature_tensors);
62
			curvature_tensors_from_edges(mani, curvature_tensors);
63
			smooth_curvature_tensors(mani,curvature_tensors);
63
			smooth_curvature_tensors(mani,curvature_tensors);
64
			smooth_curvature_tensors(mani,curvature_tensors);
64
			smooth_curvature_tensors(mani,curvature_tensors);
65
			std::vector<CGLA::Vec3d> min_curv_direction;
65
			std::vector<CGLA::Vec3d> min_curv_direction;
66
			std::vector<CGLA::Vec3d> max_curv_direction;
66
			std::vector<CGLA::Vec3d> max_curv_direction;
67
			string _line_direction = line_direction;
67
			string _line_direction = line_direction;
68
			vector<Vec3d>& lines = (_line_direction == "min")?min_curv_direction:max_curv_direction;
68
			vector<Vec3d>& lines = (_line_direction == "min")?min_curv_direction:max_curv_direction;
69
			
69
			
70
			std::vector<double> curvature;
70
			std::vector<double> curvature;
71
			curvature_from_tensors(mani, curvature_tensors,
71
			curvature_from_tensors(mani, curvature_tensors,
72
								   min_curv_direction,
72
								   min_curv_direction,
73
								   max_curv_direction,
73
								   max_curv_direction,
74
								   curvature);
74
								   curvature);
75
			
75
			
76
			renderer = new LineFieldRenderer(mani, smooth, lines, bsphere_radius);
76
			renderer = new LineFieldRenderer(mani, smooth, lines, bsphere_radius);
77
		}
77
		}
78
		else if(short_name == "gau")
78
		else if(short_name == "gau")
79
		{
79
		{
80
			static float& smoothing = CreateCVar("display.gaussian_curvature_renderer.smoothing",2.0f);
80
			static float& smoothing = CreateCVar("display.gaussian_curvature_renderer.smoothing",2.0f);
81
			vector<double> scalars;
81
			vector<double> scalars;
82
			gaussian_curvature_angle_defects(mani, scalars, smoothing);
82
			gaussian_curvature_angle_defects(mani, scalars, smoothing);
83
			double max_G = 0;
83
			double max_G = 0;
84
			for(unsigned int i=0;i<scalars.size(); ++i)
84
			for(unsigned int i=0;i<scalars.size(); ++i)
85
				max_G = max(abs(scalars[i]), max_G);
85
				max_G = max(abs(scalars[i]), max_G);
86
			renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G);
86
			renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G);
87
			
87
			
88
		}
88
		}
89
		else if(short_name == "mea")
89
		else if(short_name == "mea")
90
		{
90
		{
91
			static int& smoothing = CreateCVar("display.mean_curvature_renderer.smoothing",2);
91
			static int& smoothing = CreateCVar("display.mean_curvature_renderer.smoothing",2);
92
			vector<double> scalars;
92
			vector<double> scalars;
93
			mean_curvatures(mani, scalars, smoothing);
93
			mean_curvatures(mani, scalars, smoothing);
94
			double max_G = 0;
94
			double max_G = 0;
95
			double mean = 0;
95
			double mean = 0;
96
			for(unsigned int i=0;i<scalars.size(); ++i)
96
			for(unsigned int i=0;i<scalars.size(); ++i)
97
			{
97
			{
98
				max_G = max(abs(scalars[i]), max_G);
98
				max_G = max(abs(scalars[i]), max_G);
99
				mean += scalars[i];
99
				mean += scalars[i];
100
			}
100
			}
101
			renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G);
101
			renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G);
102
		}
102
		}
103
		else if(short_name == "amb")
103
		else if(short_name == "amb")
104
		{
104
		{
105
			static int& smoothing = CreateCVar("display.ambient_occlusion_renderer.smoothing",1);
105
			static int& smoothing = CreateCVar("display.ambient_occlusion_renderer.smoothing",1);
106
			vector<double> scalars;
106
			vector<double> scalars;
107
			mean_curvatures(mani, scalars, smoothing);
107
			mean_curvatures(mani, scalars, smoothing);
108
			double max_G = 0;
108
			double max_G = 0;
109
			for(unsigned int i=0;i<scalars.size(); ++i)
109
			for(unsigned int i=0;i<scalars.size(); ++i)
110
				max_G = max(abs(scalars[i]), max_G);
110
				max_G = max(abs(scalars[i]), max_G);
111
			renderer = new AmbientOcclusionRenderer(mani, smooth, scalars, max_G);
111
			renderer = new AmbientOcclusionRenderer(mani, smooth, scalars, max_G);
112
			
112
			
113
		}
113
		}
114
		else if(short_name == "cop")
114
		else if(short_name == "cop")
115
		{
115
		{
116
			static int& smoothing = CreateCVar("display.patina_renderer.smoothing",1);
116
			static int& smoothing = CreateCVar("display.patina_renderer.smoothing",1);
117
			vector<double> scalars;
117
			vector<double> scalars;
118
			mean_curvatures(mani, scalars, smoothing);
118
			mean_curvatures(mani, scalars, smoothing);
119
			double max_G = 0;
119
			double max_G = 0;
120
			for(unsigned int i=0;i<scalars.size(); ++i)
120
			for(unsigned int i=0;i<scalars.size(); ++i)
121
				max_G = max(abs(scalars[i]), max_G);
121
				max_G = max(abs(scalars[i]), max_G);
122
			renderer = new CopperRenderer(mani, smooth, scalars, max_G,bsphere_radius);
122
			renderer = new CopperRenderer(mani, smooth, scalars, max_G,bsphere_radius);
123
			
123
			
124
		}
124
		}
-
 
125
		else if(short_name == "dua")
-
 
126
		{
-
 
127
			vector<Vec4d> colors(mani.no_vertices());
-
 
128
			mani.enumerate_vertices();
-
 
129
			VertexIter v = mani.vertices_begin();
-
 
130
			Vec3f c;
-
 
131
			float r;
-
 
132
			mani.get_bsphere(c,r);
-
 
133
			for(unsigned int i=0;i<colors.size(); ++i,++v)
-
 
134
			{
-
 
135
				if(v->pos[2]<c[2])
-
 
136
					colors[i] = Vec4d(1,-1e10,c[2],v->pos[2]);
-
 
137
				else
-
 
138
					colors[i] = Vec4d(0,c[2],1e10,v->pos[2]);
-
 
139
			}
-
 
140
			renderer = new DualVertexRenderer(mani, colors);
-
 
141
		}
125
		else
142
		else
126
			renderer = new NormalRenderer(mani,smooth);
143
			renderer = new NormalRenderer(mani,smooth);
127
		
144
		
128
	}
145
	}
129
	view_ctrl.set_gl_modelview();
146
	view_ctrl.set_gl_modelview();
130
	renderer->draw();
147
	renderer->draw();
131
}
148
}
132
 
149