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")
|
399 |
jab |
76 |
renderer = new HarmonicsRenderer(harmonics);
|
596 |
jab |
77 |
|
401 |
jab |
78 |
else if(short_name == "iso")
|
403 |
jab |
79 |
renderer = new IsophoteLineRenderer(mani, smooth);
|
596 |
jab |
80 |
|
401 |
jab |
81 |
else if(short_name == "ref")
|
403 |
jab |
82 |
renderer = new ReflectionLineRenderer(mani, smooth);
|
596 |
jab |
83 |
|
401 |
jab |
84 |
else if(short_name == "gla")
|
403 |
jab |
85 |
renderer = new GlazedRenderer(mani, smooth, bsphere_radius);
|
596 |
jab |
86 |
|
403 |
jab |
87 |
else if(short_name == "too")
|
|
|
88 |
renderer = new ToonRenderer(mani, smooth);
|
596 |
jab |
89 |
|
|
|
90 |
else if(short_name == "cur"){
|
|
|
91 |
static Console::variable<string> line_direction("min");
|
|
|
92 |
static Console::variable<string> method("tensors");
|
|
|
93 |
static Console::variable<int> smoothing_iter(1);
|
|
|
94 |
|
|
|
95 |
line_direction.reg(cs,"display.curvature_lines.direction", "");
|
|
|
96 |
method.reg(cs, "display.curvature_lines.method", "");
|
|
|
97 |
smoothing_iter.reg(cs, "display.curvature_lines.smoothing_iter", "");
|
403 |
jab |
98 |
|
596 |
jab |
99 |
VertexAttributeVector<Mat3x3d> curvature_tensors(mani.allocated_vertices());
|
|
|
100 |
VertexAttributeVector<Vec3d> min_curv_direction(mani.allocated_vertices());
|
|
|
101 |
VertexAttributeVector<Vec3d> max_curv_direction(mani.allocated_vertices());
|
403 |
jab |
102 |
string _line_direction = line_direction;
|
596 |
jab |
103 |
VertexAttributeVector<Vec3d>& lines = (_line_direction == "min") ? min_curv_direction : max_curv_direction;
|
|
|
104 |
VertexAttributeVector<double> curvature(mani.allocated_vertices());
|
403 |
jab |
105 |
|
596 |
jab |
106 |
if(string(method) == "tensors")
|
|
|
107 |
{
|
|
|
108 |
curvature_tensors_from_edges(mani, curvature_tensors);
|
|
|
109 |
for(int i=0;i<smoothing_iter; ++i)
|
|
|
110 |
smooth_curvature_tensors(mani,curvature_tensors);
|
|
|
111 |
|
|
|
112 |
curvature_from_tensors(mani, curvature_tensors,
|
|
|
113 |
min_curv_direction,
|
|
|
114 |
max_curv_direction,
|
|
|
115 |
curvature);
|
|
|
116 |
}
|
|
|
117 |
else
|
|
|
118 |
curvature_paraboloids(mani,
|
|
|
119 |
min_curv_direction,
|
|
|
120 |
max_curv_direction,
|
618 |
jab |
121 |
curvature);
|
|
|
122 |
renderer = new LineFieldRenderer(mani, smooth, lines, r);
|
403 |
jab |
123 |
}
|
596 |
jab |
124 |
else if(short_name == "gau"){
|
|
|
125 |
static Console::variable<float> smoothing(2.0f);
|
|
|
126 |
smoothing.reg(cs, "display.gaussian_curvature_renderer.smoothing", "");
|
|
|
127 |
VertexAttributeVector<double> scalars(mani.allocated_vertices());
|
403 |
jab |
128 |
gaussian_curvature_angle_defects(mani, scalars, smoothing);
|
|
|
129 |
double max_G = 0;
|
596 |
jab |
130 |
|
|
|
131 |
for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
|
|
|
132 |
max_G = max(abs(scalars[*v]), max_G);
|
|
|
133 |
|
|
|
134 |
renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G, gamma);
|
403 |
jab |
135 |
|
|
|
136 |
}
|
596 |
jab |
137 |
else if(short_name == "mea"){
|
|
|
138 |
static Console::variable<int> smoothing(2);
|
|
|
139 |
smoothing.reg(cs, "display.mean_curvature_renderer.smoothing", "");
|
|
|
140 |
|
|
|
141 |
VertexAttributeVector<double> scalars(mani.allocated_vertices());
|
403 |
jab |
142 |
mean_curvatures(mani, scalars, smoothing);
|
|
|
143 |
double max_G = 0;
|
412 |
jab |
144 |
double mean = 0;
|
596 |
jab |
145 |
|
|
|
146 |
for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v){
|
|
|
147 |
max_G = max(abs(scalars[*v]), max_G);
|
|
|
148 |
mean += scalars[*v];
|
412 |
jab |
149 |
}
|
596 |
jab |
150 |
|
|
|
151 |
renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G, gamma);
|
403 |
jab |
152 |
}
|
596 |
jab |
153 |
else if(short_name == "amb"){
|
|
|
154 |
static Console::variable<int> smoothing(2);
|
|
|
155 |
smoothing.reg(cs, "display.ambient_occlusion_renderer.smoothing", "");
|
|
|
156 |
|
|
|
157 |
VertexAttributeVector<double> scalars(mani.allocated_vertices());
|
406 |
jab |
158 |
mean_curvatures(mani, scalars, smoothing);
|
|
|
159 |
double max_G = 0;
|
596 |
jab |
160 |
|
|
|
161 |
for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
|
|
|
162 |
max_G = max(abs(scalars[*v]), max_G);
|
|
|
163 |
|
406 |
jab |
164 |
renderer = new AmbientOcclusionRenderer(mani, smooth, scalars, max_G);
|
|
|
165 |
|
631 |
janba |
166 |
}
|
|
|
167 |
else if(short_name == "pol")
|
|
|
168 |
{
|
|
|
169 |
double vmin, vmax;
|
|
|
170 |
VertexAttributeVector<double> fun;
|
|
|
171 |
VertexAttributeVector<Vec2d> par;
|
|
|
172 |
make_height_fun(mani, fun, vmin, vmax);
|
|
|
173 |
polarize_mesh(mani, fun, vmin, vmax, 15, par);
|
|
|
174 |
renderer = new CircleFieldRenderer(mani, smooth, par, gamma);
|
|
|
175 |
|
|
|
176 |
}
|
|
|
177 |
else
|
596 |
jab |
178 |
renderer = new NormalRenderer(mani, smooth);
|
399 |
jab |
179 |
|
|
|
180 |
}
|
|
|
181 |
view_ctrl.set_gl_modelview();
|
|
|
182 |
renderer->draw();
|
|
|
183 |
}
|