Subversion Repositories gelsvn

Rev

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

Rev 596 Rev 618
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()
-
 
31
{
-
 
32
	bsphere(mani, bsphere_center, bsphere_radius);
-
 
33
    
-
 
34
	view_ctrl.set_centre(Vec3f(bsphere_center));
-
 
35
	view_ctrl.set_eye_dist(2*bsphere_radius);
-
 
36
}
30
 
37
 
31
bool VisObj::reload(string _file)
38
bool VisObj::reload(string _file)
32
{
39
{
33
	if(_file != "") file = _file;
40
	if(_file != "") file = _file;
34
	mani.clear();
41
	mani.clear();
35
	if(!load(file, mani))
42
	if(!load(file, mani))
36
		return false;
43
		return false;
37
	bsphere(mani, bsphere_center, bsphere_radius);
-
 
38
    
44
    refit();
39
	view_ctrl.set_centre(Vec3f(bsphere_center));
-
 
40
	view_ctrl.set_eye_dist(2*bsphere_radius);
-
 
41
	return true;
45
	return true;
42
}
46
}
43
 
47
 
44
bool VisObj::add_mesh(string file)
48
bool VisObj::add_mesh(string file)
45
{
49
{
46
	if(!load(file, mani))
50
	if(!load(file, mani))
47
		return false;
51
		return false;
48
	bsphere(mani, bsphere_center, bsphere_radius);
52
	bsphere(mani, bsphere_center, bsphere_radius);
49
	view_ctrl.set_centre(Vec3f(bsphere_center));
53
	view_ctrl.set_centre(Vec3f(bsphere_center));
50
	view_ctrl.set_eye_dist(2*bsphere_radius);
54
	view_ctrl.set_eye_dist(2*bsphere_radius);
51
	return true;
55
	return true;
52
}
56
}
53
 
57
 
54
 
58
 
55
 
59
 
56
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)
57
{
61
{
58
	if(create_display_list){
62
	if(create_display_list){
59
		create_display_list = false;
63
		create_display_list = false;
60
        
64
        
61
		delete renderer;
65
		delete renderer;
-
 
66
        static Console::variable<float> r(-1);
-
 
67
        r.reg(cs,"display.bsphere_radius","Radius of the bounding sphere of present object");
-
 
68
        if(r<=0)
-
 
69
            r = bsphere_radius;
62
		
70
        
63
		string short_name = display_method.substr(0,3);
71
		string short_name = display_method.substr(0,3);
64
		if(short_name== "wir")
72
		if(short_name== "wir")
65
			renderer = new WireframeRenderer(mani, smooth);
73
			renderer = new WireframeRenderer(mani, smooth);
66
        
74
        
67
		else if(short_name == "har")
75
		else if(short_name == "har")
68
			renderer = new HarmonicsRenderer(harmonics);
76
			renderer = new HarmonicsRenderer(harmonics);
69
        
77
        
70
		else if(short_name == "iso")
78
		else if(short_name == "iso")
71
			renderer = new IsophoteLineRenderer(mani, smooth);
79
			renderer = new IsophoteLineRenderer(mani, smooth);
72
        
80
        
73
		else if(short_name == "ref")
81
		else if(short_name == "ref")
74
			renderer = new ReflectionLineRenderer(mani, smooth);
82
			renderer = new ReflectionLineRenderer(mani, smooth);
75
        
83
        
76
		else if(short_name == "gla")
84
		else if(short_name == "gla")
77
			renderer = new GlazedRenderer(mani, smooth, bsphere_radius);
85
			renderer = new GlazedRenderer(mani, smooth, bsphere_radius);
78
        
86
        
79
		else if(short_name == "too")
87
		else if(short_name == "too")
80
			renderer = new ToonRenderer(mani, smooth);
88
			renderer = new ToonRenderer(mani, smooth);
81
        
89
        
82
		else if(short_name == "cur"){
90
		else if(short_name == "cur"){
83
            static Console::variable<string> line_direction("min");
91
            static Console::variable<string> line_direction("min");
84
            static Console::variable<string> method("tensors");
92
            static Console::variable<string> method("tensors");
85
            static Console::variable<int> smoothing_iter(1);
93
            static Console::variable<int> smoothing_iter(1);
86
            
94
            
87
            line_direction.reg(cs,"display.curvature_lines.direction", "");
95
            line_direction.reg(cs,"display.curvature_lines.direction", "");
88
            method.reg(cs, "display.curvature_lines.method", "");
96
            method.reg(cs, "display.curvature_lines.method", "");
89
            smoothing_iter.reg(cs, "display.curvature_lines.smoothing_iter", "");
97
            smoothing_iter.reg(cs, "display.curvature_lines.smoothing_iter", "");
90
			
98
			
91
			VertexAttributeVector<Mat3x3d> curvature_tensors(mani.allocated_vertices());
99
			VertexAttributeVector<Mat3x3d> curvature_tensors(mani.allocated_vertices());
92
			VertexAttributeVector<Vec3d> min_curv_direction(mani.allocated_vertices());
100
			VertexAttributeVector<Vec3d> min_curv_direction(mani.allocated_vertices());
93
			VertexAttributeVector<Vec3d> max_curv_direction(mani.allocated_vertices());
101
			VertexAttributeVector<Vec3d> max_curv_direction(mani.allocated_vertices());
94
			string _line_direction = line_direction;
102
			string _line_direction = line_direction;
95
			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;
96
			VertexAttributeVector<double> curvature(mani.allocated_vertices());
104
			VertexAttributeVector<double> curvature(mani.allocated_vertices());
97
			
105
			
98
            if(string(method) == "tensors")
106
            if(string(method) == "tensors")
99
            {
107
            {
100
                curvature_tensors_from_edges(mani, curvature_tensors);
108
                curvature_tensors_from_edges(mani, curvature_tensors);
101
                for(int i=0;i<smoothing_iter; ++i)
109
                for(int i=0;i<smoothing_iter; ++i)
102
                    smooth_curvature_tensors(mani,curvature_tensors);
110
                    smooth_curvature_tensors(mani,curvature_tensors);
103
                
111
                
104
                curvature_from_tensors(mani, curvature_tensors,
112
                curvature_from_tensors(mani, curvature_tensors,
105
                                       min_curv_direction,
113
                                       min_curv_direction,
106
                                       max_curv_direction,
114
                                       max_curv_direction,
107
                                       curvature);
115
                                       curvature);
108
            }
116
            }
109
            else
117
            else
110
                curvature_paraboloids(mani,
118
                curvature_paraboloids(mani,
111
                                      min_curv_direction,
119
                                      min_curv_direction,
112
                                      max_curv_direction,
120
                                      max_curv_direction,
113
                                      curvature); 
121
                                      curvature);
114
			
-
 
115
			renderer = new LineFieldRenderer(mani, smooth, lines, bsphere_radius);
122
			renderer = new LineFieldRenderer(mani, smooth, lines, r);
116
		}
123
		}
117
		else if(short_name == "gau"){
124
		else if(short_name == "gau"){
118
            static Console::variable<float> smoothing(2.0f);
125
            static Console::variable<float> smoothing(2.0f);
119
            smoothing.reg(cs, "display.gaussian_curvature_renderer.smoothing", "");
126
            smoothing.reg(cs, "display.gaussian_curvature_renderer.smoothing", "");
120
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
127
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
121
			gaussian_curvature_angle_defects(mani, scalars, smoothing);
128
			gaussian_curvature_angle_defects(mani, scalars, smoothing);
122
			double max_G = 0;
129
			double max_G = 0;
123
            
130
            
124
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
131
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
125
				max_G = max(abs(scalars[*v]), max_G);
132
				max_G = max(abs(scalars[*v]), max_G);
126
            
133
            
127
			renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G, gamma);
134
			renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G, gamma);
128
			
135
			
129
		}
136
		}
130
		else if(short_name == "mea"){
137
		else if(short_name == "mea"){
131
            static Console::variable<int> smoothing(2);
138
            static Console::variable<int> smoothing(2);
132
            smoothing.reg(cs, "display.mean_curvature_renderer.smoothing", "");
139
            smoothing.reg(cs, "display.mean_curvature_renderer.smoothing", "");
133
            
140
            
134
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
141
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
135
			mean_curvatures(mani, scalars, smoothing);
142
			mean_curvatures(mani, scalars, smoothing);
136
			double max_G = 0;
143
			double max_G = 0;
137
			double mean = 0;
144
			double mean = 0;
138
            
145
            
139
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v){
146
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v){
140
				max_G = max(abs(scalars[*v]), max_G);
147
				max_G = max(abs(scalars[*v]), max_G);
141
				mean += scalars[*v];
148
				mean += scalars[*v];
142
			}
149
			}
143
            
150
            
144
			renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G, gamma);
151
			renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G, gamma);
145
		}
152
		}
146
		else if(short_name == "amb"){
153
		else if(short_name == "amb"){
147
            static Console::variable<int> smoothing(2);
154
            static Console::variable<int> smoothing(2);
148
            smoothing.reg(cs, "display.ambient_occlusion_renderer.smoothing", "");
155
            smoothing.reg(cs, "display.ambient_occlusion_renderer.smoothing", "");
149
            
156
            
150
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
157
			VertexAttributeVector<double> scalars(mani.allocated_vertices());
151
			mean_curvatures(mani, scalars, smoothing);
158
			mean_curvatures(mani, scalars, smoothing);
152
			double max_G = 0;
159
			double max_G = 0;
153
            
160
            
154
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
161
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
155
				max_G = max(abs(scalars[*v]), max_G);
162
				max_G = max(abs(scalars[*v]), max_G);
156
            
163
            
157
			renderer = new AmbientOcclusionRenderer(mani, smooth, scalars, max_G);
164
			renderer = new AmbientOcclusionRenderer(mani, smooth, scalars, max_G);
158
			
165
			
159
		}		else
166
		}		else
160
			renderer = new NormalRenderer(mani, smooth);
167
			renderer = new NormalRenderer(mani, smooth);
161
		
168
		
162
	}
169
	}
163
	view_ctrl.set_gl_modelview();
170
	view_ctrl.set_gl_modelview();
164
	renderer->draw();
171
	renderer->draw();
165
}
172
}
166
 
173