Subversion Repositories gelsvn

Rev

Rev 631 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 631 Rev 643
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
#include "polarize.h"
11
#include "polarize.h"
12
 
12
 
13
#include <GLGraphics/Console.h>
13
#include <GLGraphics/Console.h>
14
#include <HMesh/Manifold.h>
14
#include <HMesh/Manifold.h>
15
#include <HMesh/AttributeVector.h>
15
#include <HMesh/AttributeVector.h>
16
#include <HMesh/load.h>
16
#include <HMesh/load.h>
17
#include <HMesh/curvature.h>
17
#include <HMesh/curvature.h>
18
 
18
 
19
#include <CGLA/Mat3x3d.h>
19
#include <CGLA/Mat3x3d.h>
20
#include <CGLA/Vec3d.h>
20
#include <CGLA/Vec3d.h>
21
#include <CGLA/Vec4d.h>
21
#include <CGLA/Vec4d.h>
22
 
22
 
23
using namespace std;
23
using namespace std;
24
using namespace CGLA;
24
using namespace CGLA;
25
using namespace HMesh;
25
using namespace HMesh;
26
using namespace GLGraphics;
26
using namespace GLGraphics;
27
 
27
 
28
int WINX=800, WINY=800;
28
int WINX=800, WINY=800;
29
 
29
 
30
void VisObj::refit()
30
void VisObj::refit()
31
{
31
{
32
	bsphere(mani, bsphere_center, bsphere_radius);
32
	bsphere(mani, bsphere_center, bsphere_radius);
33
    
33
    
34
	view_ctrl.set_centre(Vec3f(bsphere_center));
34
	view_ctrl.set_centre(Vec3f(bsphere_center));
35
	view_ctrl.set_eye_dist(2*bsphere_radius);
35
	view_ctrl.set_eye_dist(2*bsphere_radius);
36
}
36
}
37
 
37
 
38
bool VisObj::reload(string _file)
38
bool VisObj::reload(string _file)
39
{
39
{
40
	if(_file != "") file = _file;
40
	if(_file != "") file = _file;
41
	mani.clear();
41
	mani.clear();
42
	if(!load(file, mani))
42
	if(!load(file, mani))
43
		return false;
43
		return false;
44
    refit();
44
    refit();
45
	return true;
45
	return true;
46
}
46
}
47
 
47
 
48
bool VisObj::add_mesh(string file)
48
bool VisObj::add_mesh(string file)
49
{
49
{
50
	if(!load(file, mani))
50
	if(!load(file, mani))
51
		return false;
51
		return false;
52
	bsphere(mani, bsphere_center, bsphere_radius);
52
	bsphere(mani, bsphere_center, bsphere_radius);
53
	view_ctrl.set_centre(Vec3f(bsphere_center));
53
	view_ctrl.set_centre(Vec3f(bsphere_center));
54
	view_ctrl.set_eye_dist(2*bsphere_radius);
54
	view_ctrl.set_eye_dist(2*bsphere_radius);
55
	return true;
55
	return true;
56
}
56
}
57
 
57
 
58
 
58
 
59
 
59
 
60
void VisObj::display(const std::string& display_method , Console& cs, bool smooth, float gamma)
60
void VisObj::display(const std::string& display_method , Console& cs, bool smooth, float gamma)
61
{
61
{
62
	if(create_display_list){
62
	if(create_display_list){
63
		create_display_list = false;
63
		create_display_list = false;
64
        
64
        
65
		delete renderer;
65
		delete renderer;
66
        static Console::variable<float> r(-1);
66
        static Console::variable<float> r(-1);
67
        r.reg(cs,"display.bsphere_radius","Radius of the bounding sphere of present object");
67
        r.reg(cs,"display.bsphere_radius","Radius of the bounding sphere of present object");
68
        if(r<=0)
68
        if(r<=0)
69
            r = bsphere_radius;
69
            r = bsphere_radius;
70
        
70
        
71
		string short_name = display_method.substr(0,3);
71
		string short_name = display_method.substr(0,3);
72
		if(short_name== "wir")
72
		if(short_name== "wir")
73
			renderer = new WireframeRenderer(mani, smooth);
73
			renderer = new WireframeRenderer(mani, smooth);
74
        
74
        
75
		else if(short_name == "har")
75
		else if(short_name == "har")
76
			renderer = new HarmonicsRenderer(harmonics);
76
			renderer = new HarmonicsRenderer(mani, *harmonics, cs);
77
        
77
        
78
		else if(short_name == "iso")
78
		else if(short_name == "iso") {
79
			renderer = new IsophoteLineRenderer(mani, smooth);
79
			renderer = new IsophoteLineRenderer();
-
 
80
            renderer->compile_display_list(mani,smooth);
80
        
81
        }
81
		else if(short_name == "ref")
82
		else if(short_name == "ref") {
82
			renderer = new ReflectionLineRenderer(mani, smooth);
83
			renderer = new ReflectionLineRenderer();
-
 
84
            renderer->compile_display_list(mani,smooth);
83
        
85
        }
84
		else if(short_name == "gla")
86
		else if(short_name == "gla") {
85
			renderer = new GlazedRenderer(mani, smooth, bsphere_radius);
87
			renderer = new GlazedRenderer();
-
 
88
            dynamic_cast<GlazedRenderer*>(renderer)->compile_display_list(mani,smooth, r);
-
 
89
        }
-
 
90
 
86
        
91
        
87
		else if(short_name == "too")
92
		else if(short_name == "too") {
88
			renderer = new ToonRenderer(mani, smooth);
93
			renderer = new ToonRenderer();
-
 
94
            renderer->compile_display_list(mani,smooth);
-
 
95
        }
-
 
96
 
89
        
97
        
90
		else if(short_name == "cur"){
98
		else if(short_name == "cur"){
91
            static Console::variable<string> line_direction("min");
99
            static Console::variable<string> line_direction("min");
92
            static Console::variable<string> method("tensors");
100
            static Console::variable<string> method("tensors");
93
            static Console::variable<int> smoothing_iter(1);
101
            static Console::variable<int> smoothing_iter(1);
94
            
102
            
95
            line_direction.reg(cs,"display.curvature_lines.direction", "");
103
            line_direction.reg(cs,"display.curvature_lines.direction", "");
96
            method.reg(cs, "display.curvature_lines.method", "");
104
            method.reg(cs, "display.curvature_lines.method", "");
97
            smoothing_iter.reg(cs, "display.curvature_lines.smoothing_iter", "");
105
            smoothing_iter.reg(cs, "display.curvature_lines.smoothing_iter", "");
98
			
106
			
99
			VertexAttributeVector<Mat3x3d> curvature_tensors(mani.allocated_vertices());
107
			VertexAttributeVector<Mat3x3d> curvature_tensors(mani.allocated_vertices());
100
			VertexAttributeVector<Vec3d> min_curv_direction(mani.allocated_vertices());
108
			VertexAttributeVector<Vec3d> min_curv_direction(mani.allocated_vertices());
101
			VertexAttributeVector<Vec3d> max_curv_direction(mani.allocated_vertices());
109
			VertexAttributeVector<Vec3d> max_curv_direction(mani.allocated_vertices());
102
			string _line_direction = line_direction;
110
			string _line_direction = line_direction;
103
			VertexAttributeVector<Vec3d>& lines = (_line_direction == "min") ? min_curv_direction : max_curv_direction;
111
			VertexAttributeVector<Vec3d>& lines = (_line_direction == "min") ? min_curv_direction : max_curv_direction;
104
			VertexAttributeVector<double> curvature(mani.allocated_vertices());
112
			VertexAttributeVector<double> curvature(mani.allocated_vertices());
105
			
113
			
106
            if(string(method) == "tensors")
114
            if(string(method) == "tensors")
107
            {
115
            {
108
                curvature_tensors_from_edges(mani, curvature_tensors);
116
                curvature_tensors_from_edges(mani, curvature_tensors);
109
                for(int i=0;i<smoothing_iter; ++i)
117
                for(int i=0;i<smoothing_iter; ++i)
110
                    smooth_curvature_tensors(mani,curvature_tensors);
118
                    smooth_curvature_tensors(mani,curvature_tensors);
111
                
119
                
112
                curvature_from_tensors(mani, curvature_tensors,
120
                curvature_from_tensors(mani, curvature_tensors,
113
                                       min_curv_direction,
121
                                       min_curv_direction,
114
                                       max_curv_direction,
122
                                       max_curv_direction,
115
                                       curvature);
123
                                       curvature);
116
            }
124
            }
117
            else
125
            else
118
                curvature_paraboloids(mani,
126
                curvature_paraboloids(mani,
119
                                      min_curv_direction,
127
                                      min_curv_direction,
120
                                      max_curv_direction,
128
                                      max_curv_direction,
121
                                      curvature);
129
                                      curvature);
122
			renderer = new LineFieldRenderer(mani, smooth, lines, r);
130
            renderer = new LineFieldRenderer();
-
 
131
            dynamic_cast<LineFieldRenderer*>(renderer)->compile_display_list(mani, lines, r);
123
		}
132
		}
124
		else if(short_name == "gau"){
133
		else if(short_name == "gau"){
125
            static Console::variable<float> smoothing(2.0f);
134
            static Console::variable<float> smoothing(2.0f);
126
            smoothing.reg(cs, "display.gaussian_curvature_renderer.smoothing", "");
135
            smoothing.reg(cs, "display.gaussian_curvature_renderer.smoothing", "");
127
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
136
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
128
			gaussian_curvature_angle_defects(mani, scalars, smoothing);
137
			gaussian_curvature_angle_defects(mani, scalars, smoothing);
129
			double max_G = 0;
138
			double max_G = 0;
130
            
139
            
131
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
140
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
132
				max_G = max(abs(scalars[*v]), max_G);
141
				max_G = max(abs(scalars[*v]), max_G);
133
            
142
            
-
 
143
            renderer = new ScalarFieldRenderer();
134
			renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G, gamma);
144
            dynamic_cast<ScalarFieldRenderer*>(renderer)->compile_display_list(mani, smooth, scalars, max_G, gamma);
135
			
145
			
136
		}
146
		}
137
		else if(short_name == "mea"){
147
		else if(short_name == "mea"){
138
            static Console::variable<int> smoothing(2);
148
            static Console::variable<int> smoothing(2);
139
            smoothing.reg(cs, "display.mean_curvature_renderer.smoothing", "");
149
            smoothing.reg(cs, "display.mean_curvature_renderer.smoothing", "");
140
            
150
            
141
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
151
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
142
			mean_curvatures(mani, scalars, smoothing);
152
			mean_curvatures(mani, scalars, smoothing);
143
			double max_G = 0;
153
			double max_G = 0;
144
			double mean = 0;
154
			double mean = 0;
145
            
155
            
146
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v){
156
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v){
147
				max_G = max(abs(scalars[*v]), max_G);
157
				max_G = max(abs(scalars[*v]), max_G);
148
				mean += scalars[*v];
158
				mean += scalars[*v];
149
			}
159
			}
150
            
160
            
-
 
161
            renderer = new ScalarFieldRenderer();
151
			renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G, gamma);
162
            dynamic_cast<ScalarFieldRenderer*>(renderer)->compile_display_list(mani, smooth, scalars, max_G, gamma);
152
		}
163
		}
153
		else if(short_name == "amb"){
164
		else if(short_name == "amb"){
154
            static Console::variable<int> smoothing(2);
165
            static Console::variable<int> smoothing(2);
155
            smoothing.reg(cs, "display.ambient_occlusion_renderer.smoothing", "");
166
            smoothing.reg(cs, "display.ambient_occlusion_renderer.smoothing", "");
156
            
167
            
157
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
168
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
158
			mean_curvatures(mani, scalars, smoothing);
169
			mean_curvatures(mani, scalars, smoothing);
159
			double max_G = 0;
170
			double max_G = 0;
160
            
171
            
161
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
172
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
162
				max_G = max(abs(scalars[*v]), max_G);
173
				max_G = max(abs(scalars[*v]), max_G);
163
            
174
            
164
			renderer = new AmbientOcclusionRenderer(mani, smooth, scalars, max_G);
175
            renderer = new AmbientOcclusionRenderer();
-
 
176
            dynamic_cast<AmbientOcclusionRenderer*>(renderer)->compile_display_list(mani, scalars, max_G);
165
			
177
			
166
		}
178
		}
167
        else if(short_name == "pol")
179
        else if(short_name == "deb")
168
        {
180
        {
169
            double vmin, vmax;
-
 
170
            VertexAttributeVector<double> fun;
-
 
171
            VertexAttributeVector<Vec2d> par;
181
            renderer = new DebugRenderer;
172
            make_height_fun(mani, fun, vmin, vmax);
182
            renderer->compile_display_list(mani, smooth);
173
            polarize_mesh(mani, fun, vmin, vmax, 15, par);
-
 
174
			renderer = new CircleFieldRenderer(mani, smooth, par, gamma);
-
 
175
 
-
 
176
        }
183
        }
177
        else
184
        else {
178
			renderer = new NormalRenderer(mani, smooth);
185
			renderer = new NormalRenderer();
-
 
186
            renderer->compile_display_list(mani, smooth);
-
 
187
        }
-
 
188
 
179
		
189
		
180
	}
190
	}
181
	view_ctrl.set_gl_modelview();
191
	view_ctrl.set_gl_modelview();
182
	renderer->draw();
192
	renderer->draw();
183
}
193
}
184
 
194