Subversion Repositories gelsvn

Rev

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

Rev 630 Rev 631
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(harmonics);
77
        
77
        
78
		else if(short_name == "iso")
78
		else if(short_name == "iso")
79
			renderer = new IsophoteLineRenderer(mani, smooth);
79
			renderer = new IsophoteLineRenderer(mani, smooth);
80
        
80
        
81
		else if(short_name == "ref")
81
		else if(short_name == "ref")
82
			renderer = new ReflectionLineRenderer(mani, smooth);
82
			renderer = new ReflectionLineRenderer(mani, smooth);
83
        
83
        
84
		else if(short_name == "gla")
84
		else if(short_name == "gla")
85
			renderer = new GlazedRenderer(mani, smooth, bsphere_radius);
85
			renderer = new GlazedRenderer(mani, smooth, bsphere_radius);
86
        
86
        
87
		else if(short_name == "too")
87
		else if(short_name == "too")
88
			renderer = new ToonRenderer(mani, smooth);
88
			renderer = new ToonRenderer(mani, smooth);
89
        
89
        
90
		else if(short_name == "cur"){
90
		else if(short_name == "cur"){
91
            static Console::variable<string> line_direction("min");
91
            static Console::variable<string> line_direction("min");
92
            static Console::variable<string> method("tensors");
92
            static Console::variable<string> method("tensors");
93
            static Console::variable<int> smoothing_iter(1);
93
            static Console::variable<int> smoothing_iter(1);
94
            
94
            
95
            line_direction.reg(cs,"display.curvature_lines.direction", "");
95
            line_direction.reg(cs,"display.curvature_lines.direction", "");
96
            method.reg(cs, "display.curvature_lines.method", "");
96
            method.reg(cs, "display.curvature_lines.method", "");
97
            smoothing_iter.reg(cs, "display.curvature_lines.smoothing_iter", "");
97
            smoothing_iter.reg(cs, "display.curvature_lines.smoothing_iter", "");
98
			
98
			
99
			VertexAttributeVector<Mat3x3d> curvature_tensors(mani.allocated_vertices());
99
			VertexAttributeVector<Mat3x3d> curvature_tensors(mani.allocated_vertices());
100
			VertexAttributeVector<Vec3d> min_curv_direction(mani.allocated_vertices());
100
			VertexAttributeVector<Vec3d> min_curv_direction(mani.allocated_vertices());
101
			VertexAttributeVector<Vec3d> max_curv_direction(mani.allocated_vertices());
101
			VertexAttributeVector<Vec3d> max_curv_direction(mani.allocated_vertices());
102
			string _line_direction = line_direction;
102
			string _line_direction = line_direction;
103
			VertexAttributeVector<Vec3d>& lines = (_line_direction == "min") ? min_curv_direction : max_curv_direction;
103
			VertexAttributeVector<Vec3d>& lines = (_line_direction == "min") ? min_curv_direction : max_curv_direction;
104
			VertexAttributeVector<double> curvature(mani.allocated_vertices());
104
			VertexAttributeVector<double> curvature(mani.allocated_vertices());
105
			
105
			
106
            if(string(method) == "tensors")
106
            if(string(method) == "tensors")
107
            {
107
            {
108
                curvature_tensors_from_edges(mani, curvature_tensors);
108
                curvature_tensors_from_edges(mani, curvature_tensors);
109
                for(int i=0;i<smoothing_iter; ++i)
109
                for(int i=0;i<smoothing_iter; ++i)
110
                    smooth_curvature_tensors(mani,curvature_tensors);
110
                    smooth_curvature_tensors(mani,curvature_tensors);
111
                
111
                
112
                curvature_from_tensors(mani, curvature_tensors,
112
                curvature_from_tensors(mani, curvature_tensors,
113
                                       min_curv_direction,
113
                                       min_curv_direction,
114
                                       max_curv_direction,
114
                                       max_curv_direction,
115
                                       curvature);
115
                                       curvature);
116
            }
116
            }
117
            else
117
            else
118
                curvature_paraboloids(mani,
118
                curvature_paraboloids(mani,
119
                                      min_curv_direction,
119
                                      min_curv_direction,
120
                                      max_curv_direction,
120
                                      max_curv_direction,
121
                                      curvature);
121
                                      curvature);
122
			renderer = new LineFieldRenderer(mani, smooth, lines, r);
122
			renderer = new LineFieldRenderer(mani, smooth, lines, r);
123
		}
123
		}
124
		else if(short_name == "gau"){
124
		else if(short_name == "gau"){
125
            static Console::variable<float> smoothing(2.0f);
125
            static Console::variable<float> smoothing(2.0f);
126
            smoothing.reg(cs, "display.gaussian_curvature_renderer.smoothing", "");
126
            smoothing.reg(cs, "display.gaussian_curvature_renderer.smoothing", "");
127
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
127
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
128
			gaussian_curvature_angle_defects(mani, scalars, smoothing);
128
			gaussian_curvature_angle_defects(mani, scalars, smoothing);
129
			double max_G = 0;
129
			double max_G = 0;
130
            
130
            
131
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
131
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
132
				max_G = max(abs(scalars[*v]), max_G);
132
				max_G = max(abs(scalars[*v]), max_G);
133
            
133
            
134
			renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G, gamma);
134
			renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G, gamma);
135
			
135
			
136
		}
136
		}
137
		else if(short_name == "mea"){
137
		else if(short_name == "mea"){
138
            static Console::variable<int> smoothing(2);
138
            static Console::variable<int> smoothing(2);
139
            smoothing.reg(cs, "display.mean_curvature_renderer.smoothing", "");
139
            smoothing.reg(cs, "display.mean_curvature_renderer.smoothing", "");
140
            
140
            
141
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
141
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
142
			mean_curvatures(mani, scalars, smoothing);
142
			mean_curvatures(mani, scalars, smoothing);
143
			double max_G = 0;
143
			double max_G = 0;
144
			double mean = 0;
144
			double mean = 0;
145
            
145
            
146
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v){
146
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v){
147
				max_G = max(abs(scalars[*v]), max_G);
147
				max_G = max(abs(scalars[*v]), max_G);
148
				mean += scalars[*v];
148
				mean += scalars[*v];
149
			}
149
			}
150
            
150
            
151
			renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G, gamma);
151
			renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G, gamma);
152
		}
152
		}
153
		else if(short_name == "amb"){
153
		else if(short_name == "amb"){
154
            static Console::variable<int> smoothing(2);
154
            static Console::variable<int> smoothing(2);
155
            smoothing.reg(cs, "display.ambient_occlusion_renderer.smoothing", "");
155
            smoothing.reg(cs, "display.ambient_occlusion_renderer.smoothing", "");
156
            
156
            
157
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
157
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
158
			mean_curvatures(mani, scalars, smoothing);
158
			mean_curvatures(mani, scalars, smoothing);
159
			double max_G = 0;
159
			double max_G = 0;
160
            
160
            
161
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
161
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
162
				max_G = max(abs(scalars[*v]), max_G);
162
				max_G = max(abs(scalars[*v]), max_G);
163
            
163
            
164
			renderer = new AmbientOcclusionRenderer(mani, smooth, scalars, max_G);
164
			renderer = new AmbientOcclusionRenderer(mani, smooth, scalars, max_G);
165
			
165
			
-
 
166
		}
-
 
167
        else if(short_name == "pol")
-
 
168
        {
-
 
169
            double vmin, vmax;
-
 
170
            VertexAttributeVector<double> fun;
-
 
171
            VertexAttributeVector<Vec2d> par;
-
 
172
            make_height_fun(mani, fun, vmin, vmax);
-
 
173
            polarize_mesh(mani, fun, vmin, vmax, 15, par);
-
 
174
			renderer = new CircleFieldRenderer(mani, smooth, par, gamma);
-
 
175
 
-
 
176
        }
166
		}		else
177
        else
167
			renderer = new NormalRenderer(mani, smooth);
178
			renderer = new NormalRenderer(mani, smooth);
168
		
179
		
169
	}
180
	}
170
	view_ctrl.set_gl_modelview();
181
	view_ctrl.set_gl_modelview();
171
	renderer->draw();
182
	renderer->draw();
172
}
183
}
173
 
184