Subversion Repositories gelsvn

Rev

Rev 456 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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