Subversion Repositories gelsvn

Rev

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