-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathResolutionCtrl.cc
244 lines (196 loc) · 4.44 KB
/
ResolutionCtrl.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
//############################################################
//
// ResolutionCtrl.cc
//
// Kari Pulli
// Fri Jul 3 11:52:55 PDT 1998
//
//############################################################
#include "ResolutionCtrl.h"
#include "plvGlobals.h"
#include "plvScene.h"
void
ResolutionCtrl::split_name(void)
{
basename = name;
crope::const_iterator it = basename.end()-1;
// Special case - gzipped scans
if ((basename.size() > 3) &&
(*(it-2) == '.') &&
(*(it-1) == 'g') &&
(*(it ) == 'z'))
it -= 3;
// Search for a dot
while (*it != '.' && it != basename.begin()) it--;
if (it == basename.begin()) it = basename.end();
ending = basename.substr(it+1, basename.end());
basename = basename.substr (basename.begin(), it);
}
void
ResolutionCtrl::set_name(const char *n)
{
name = crope(n);
// remove trailing slash, if a directory name
if (name.back() == '/' || name.back() == '\\') name.pop_back();
split_name();
}
void
ResolutionCtrl::set_name(const crope &n)
{
name = n;
// remove trailing slash, if a directory name
if (name.back() == '/' || name.back() == '\\') name.pop_back();
split_name();
}
crope
ResolutionCtrl::get_name(void)
{
return name;
}
crope
ResolutionCtrl::get_basename(void)
{
return basename;
}
crope
ResolutionCtrl::get_nameending(void)
{
return ending;
}
bool
ResolutionCtrl::has_ending(const char *end)
{
if (end[0] == '.') return ending == crope(end+1);
else return ending == crope(end);
}
bool
ResolutionCtrl::select_finest(void)
{
if (!resolutions.size()) return false;
return switchToResLevel (0);
}
bool
ResolutionCtrl::select_coarsest(void)
{
if (!resolutions.size()) return false;
return switchToResLevel (resolutions.size()-1);
}
bool
ResolutionCtrl::select_finer(void)
{
if (!resolutions.size()) return false;
if (curr_res == 0) return false;
if (switchToResLevel (curr_res - 1)) return true;
return false;
//return select_finest();
}
bool
ResolutionCtrl::select_coarser(void)
{
if (!resolutions.size()) return false;
if (curr_res == resolutions.size()-1) return false;
if (switchToResLevel (curr_res + 1)) return true;
return false;
//return select_coarsest();
}
bool
ResolutionCtrl::select_by_count(int n)
{
return switchToResLevel (findLevelForRes (n));
}
int
ResolutionCtrl::create_resolution_absolute(int budget, Decimator dec)
{ return 0; }
bool
ResolutionCtrl::delete_resolution (int abs_res)
{ return false; }
void
ResolutionCtrl::insert_resolution (int abs, crope filename,
bool in_mem, bool desired_mem)
{
res_info res;
res.abs_resolution = abs;
res.filename = filename;
res.in_memory = in_mem;
res.desired_in_mem = desired_mem;
int n = resolutions.size();
resolutions.push_back (res);
// STL Update
inplace_merge (resolutions.begin(), resolutions.begin() + n, resolutions.end());
}
bool
ResolutionCtrl::set_load_desired (int res, bool desired)
{
int i = findLevelForRes (res);
if (i >= 0) {
resolutions[i].desired_in_mem = desired;
return true;
}
return false;
}
void
ResolutionCtrl::existing_resolutions(vector<res_info> &res)
{ res = resolutions; }
ResolutionCtrl::res_info
ResolutionCtrl::current_resolution(void)
{
if (curr_res < 0 || curr_res >= resolutions.size())
{
static res_info bogus;
memset (&bogus, 0, sizeof(bogus));
return bogus;
}
return resolutions[curr_res];
}
bool
ResolutionCtrl::load_resolution(int i)
{ return 0; }
bool
ResolutionCtrl::release_resolution(int nPolys)
{
cerr << "Warning: no memory was actually freed" << endl;
return 0;
}
bool
ResolutionCtrl::switchToResLevel (int iRes)
{
if (iRes < 0 || iRes >= resolutions.size())
return false;
if (!resolutions[iRes].in_memory) {
if (!load_resolution (iRes))
return false;
}
curr_res = iRes;
return true;
}
int
ResolutionCtrl::current_resolution_index (void)
{
int globalRes = theScene->getMeshResolution();
switch (globalRes) {
case Scene::resTempHigh:
return 0;
case Scene::resTempLow:
return resolutions.size() - 1;
case Scene::resDefault:
default:
assert (curr_res >= 0 && curr_res < resolutions.size());
return curr_res;
}
}
int
ResolutionCtrl::findLevelForRes (int n)
{
for (int i=0; i<resolutions.size(); i++) {
if (n == resolutions[i].abs_resolution) {
return i;
}
}
return -1;
}
int
ResolutionCtrl::findResForLevel (int n)
{
assert (n >= 0 && n < resolutions.size());
return resolutions[n].abs_resolution;
}