Subversion Repositories gelsvn

Rev

Rev 417 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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