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;
|
|
|
19 |
|
|
|
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 |
{
|
|
|
59 |
static CVar<string> line_direction("display.curvature_lines.direction", "min");
|
|
|
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 |
{
|
|
|
80 |
static CVar<float> smoothing("display.gaussian_curvature_renderer.smoothing",2);
|
|
|
81 |
vector<double> scalars;
|
|
|
82 |
gaussian_curvature_angle_defects(mani, scalars, smoothing);
|
|
|
83 |
double max_G = 0;
|
409 |
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 |
{
|
|
|
91 |
static CVar<float> smoothing("display.mean_curvature_renderer.smoothing",2);
|
|
|
92 |
vector<double> scalars;
|
|
|
93 |
mean_curvatures(mani, scalars, smoothing);
|
|
|
94 |
double max_G = 0;
|
409 |
jrf |
95 |
for(unsigned int i=0;i<scalars.size(); ++i)
|
403 |
jab |
96 |
max_G = max(abs(scalars[i]), max_G);
|
|
|
97 |
renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G);
|
|
|
98 |
|
|
|
99 |
}
|
406 |
jab |
100 |
else if(short_name == "amb")
|
|
|
101 |
{
|
|
|
102 |
static CVar<float> smoothing("display.ambient_occlusion_renderer.smoothing",1);
|
|
|
103 |
vector<double> scalars;
|
|
|
104 |
mean_curvatures(mani, scalars, smoothing);
|
|
|
105 |
double max_G = 0;
|
409 |
jrf |
106 |
for(unsigned int i=0;i<scalars.size(); ++i)
|
406 |
jab |
107 |
max_G = max(abs(scalars[i]), max_G);
|
|
|
108 |
renderer = new AmbientOcclusionRenderer(mani, smooth, scalars, max_G);
|
|
|
109 |
|
|
|
110 |
}
|
|
|
111 |
else if(short_name == "cop")
|
|
|
112 |
{
|
|
|
113 |
static CVar<float> smoothing("display.patina_renderer.smoothing",1);
|
|
|
114 |
vector<double> scalars;
|
|
|
115 |
mean_curvatures(mani, scalars, smoothing);
|
|
|
116 |
double max_G = 0;
|
409 |
jrf |
117 |
for(unsigned int i=0;i<scalars.size(); ++i)
|
406 |
jab |
118 |
max_G = max(abs(scalars[i]), max_G);
|
|
|
119 |
renderer = new CopperRenderer(mani, smooth, scalars, max_G,bsphere_radius);
|
|
|
120 |
|
|
|
121 |
}
|
401 |
jab |
122 |
else
|
399 |
jab |
123 |
renderer = new NormalRenderer(mani,smooth);
|
|
|
124 |
|
|
|
125 |
}
|
|
|
126 |
view_ctrl.set_gl_modelview();
|
|
|
127 |
renderer->draw();
|
|
|
128 |
}
|