Subversion Repositories gelsvn

Rev

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