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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
#include "draw_processor.hpp"
#include "drawer.hpp"
#include "feature_styler.hpp"
#include "../platform/preferred_languages.hpp"
#include "../geometry/screenbase.hpp"
#include "../geometry/rect_intersect.hpp"
#include "../indexer/feature_visibility.hpp"
#include "../indexer/drawing_rules.hpp"
#include "../indexer/feature_data.hpp"
#include "../indexer/feature_impl.hpp"
#include "../std/bind.hpp"
namespace get_pts {
using namespace di;
m2::PointD base::g2p(m2::PointD const & pt) const
{
return m_convertor->GtoP(pt);
}
base_screen::base_screen(params const & p)
: base(p)
{
m_convertor->GtoP(*p.m_rect, m_rect);
}
void one_point::operator() (CoordPointT const & p)
{
ASSERT ( !m_exist, ("point feature should have only one point") );
m2::PointD pt(make_point(p));
if (m_rect->IsPointInside(pt))
{
m_exist = true;
m_point = convert_point(pt);
}
else m_exist = false;
}
void path_points::StartPL(m2::PointD const & pt)
{
EndPL();
m_points.push_back(PathInfo(m_length + m_prev.Length(pt)));
push_point(pt);
m_newPL = false;
}
void path_points::EndPL()
{
if (!m_points.empty() && m_points.back().size() < 2)
m_points.pop_back();
}
void path_points::simple_filtration(m2::PointD const & pt)
{
if (m_hasPrevPt)
{
if (!m2::RectD(m_prev, pt).IsIntersect(m_rect))
m_newPL = true;
else
{
if (m_newPL)
StartPL(m_prev);
push_point(pt);
}
m_length += m_prev.Length(pt);
}
else
{
m_hasPrevPt = true;
m_length = 0.0;
}
m_prev = pt;
}
void path_points::best_filtration(m2::PointD const & pt)
{
if (m_hasPrevPt)
{
m2::PointD prev = m_prev;
m2::PointD curr = pt;
double const segLen = curr.Length(prev);
if ((m_startLength != 0) && (m_endLength != 0))
{
if ((m_startLength >= m_length) && (m_startLength < m_length + segLen))
m_startLength = m_length;
if ((m_endLength > m_length) && (m_endLength <= m_length + segLen))
m_endLength = m_length + segLen;
}
if ((m_length >= m_startLength) && (m_endLength >= m_length + segLen))
{
/// we're in the dead zone. add without clipping
if (m_newPL)
StartPL(prev);
push_point(curr);
}
else
{
if (!m2::Intersect(m_rect, prev, curr))
m_newPL = true;
else
{
if (!equal_glb_pts(prev, m_prev))
m_newPL = true;
if (m_newPL)
StartPL(prev);
push_point(curr);
if (!equal_glb_pts(curr, pt))
m_newPL = true;
}
}
m_length += segLen;
}
else
{
m_hasPrevPt = true;
m_length = 0.0;
}
m_prev = pt;
}
void path_points::operator() (m2::PointD const & p)
{
// Choose simple (fast) or best (slow) filtration
//simple_filtration(p);
best_filtration(p);
}
bool path_points::IsExist()
{
// finally, assign whole length to every cutted path
for_each(m_points.begin(), m_points.end(),
bind(&di::PathInfo::SetFullLength, _1, m_length));
EndPL();
return base_type::IsExist();
}
void area_tess_points::StartPrimitive(size_t ptsCount)
{
m_points.push_back(AreaInfo());
m_points.back().reserve(ptsCount);
}
void area_tess_points::operator() (m2::PointD const & p1, m2::PointD const & p2, m2::PointD const & p3)
{
push_point(p1);
push_point(p2);
push_point(p3);
}
void area_tess_points::EndPrimitive()
{
if (m_points.back().size() < 3)
m_points.pop_back();
}
bool area_tess_points::IsExist() const
{
return !m_points.empty();
}
}
namespace fwork
{
namespace
{
template <class TSrc> void assign_point(di::DrawInfo * p, TSrc & src)
{
p->m_point = src.m_point;
}
template <class TSrc> void assign_path(di::DrawInfo * p, TSrc & src)
{
p->m_pathes.swap(src.m_points);
}
template <class TSrc> void assign_area(di::DrawInfo * p, TSrc & src)
{
p->m_areas.swap(src.m_points);
ASSERT ( !p->m_areas.empty(), () );
p->m_areas.back().SetCenter(src.GetCenter());
}
}
DrawProcessor::DrawProcessor( m2::RectD const & r,
ScreenBase const & convertor,
shared_ptr<PaintEvent> const & e,
int scaleLevel)
: m_rect(r),
m_convertor(convertor),
m_paintEvent(e),
m_zoom(scaleLevel),
m_hasNonCoast(false),
m_glyphCache(e->drawer()->screen()->glyphCache())
#ifdef PROFILER_DRAWING
, m_drawCount(0)
#endif
{
GetDrawer()->SetScale(m_zoom);
}
#define GET_POINTS(f, for_each_fun, fun, assign_fun) \
{ \
f.for_each_fun(fun, m_zoom); \
if (fun.IsExist()) \
{ \
isExist = true; \
assign_fun(ptr.get(), fun); \
} \
}
bool DrawProcessor::operator() (FeatureType const & f)
{
if (m_paintEvent->isCancelled())
throw redraw_operation_cancelled();
feature::StylesContainer styles;
styles.GetStyles(f, m_zoom);
if (styles.empty())
return true;
// Draw coastlines features only once.
if (styles.m_isCoastline)
{
if (!m_coasts.insert(styles.m_primaryText).second)
return true;
}
else
m_hasNonCoast = true;
size_t count = styles.m_count;
#ifdef PROFILER_DRAWING
m_drawCount += count;
#endif
scoped_ptr<di::DrawInfo> ptr(new di::DrawInfo(
styles.m_primaryText,
styles.m_secondaryText,
styles.m_refText,
styles.m_popRank)); // FIXME
Drawer * pDrawer = GetDrawer();
using namespace get_pts;
bool isExist = false;
switch (styles.m_geometryType)
{
case feature::GEOM_POINT:
{
typedef get_pts::one_point functor_t;
functor_t::params p;
p.m_convertor = &m_convertor;
p.m_rect = &m_rect;
functor_t fun(p);
GET_POINTS(f, ForEachPointRef, fun, assign_point)
break;
}
case feature::GEOM_AREA:
{
typedef filter_screenpts_adapter<area_tess_points> functor_t;
functor_t::params p;
p.m_convertor = &m_convertor;
p.m_rect = &m_rect;
functor_t fun(p);
GET_POINTS(f, ForEachTriangleExRef, fun, assign_area)
{
// continue rendering as line if feature has linear styles too
if (!styles.m_hasLineStyles)
break;
}
}
case feature::GEOM_LINE:
{
typedef filter_screenpts_adapter<path_points> functor_t;
functor_t::params p;
p.m_convertor = &m_convertor;
p.m_rect = &m_rect;
if (styles.m_hasPathText)
{
uint8_t fontSize = 0;
for (size_t i = 0; i < count; i++)
{
if (!pDrawer->filter_text_size(styles.m_rules[i].m_rule))
fontSize = max(fontSize, pDrawer->get_text_font_size(styles.m_rules[i].m_rule));
}
if (fontSize != 0)
{
double textLength = m_glyphCache->getTextLength(fontSize, ptr->GetPathName());
typedef calc_length<base_global> functor_t;
functor_t::params p1;
p1.m_convertor = &m_convertor;
p1.m_rect = &m_rect;
functor_t fun(p1);
f.ForEachPointRef(fun, m_zoom);
textLength += 30;
if ((fun.IsExist()) && (fun.m_length > textLength))
{
p.m_startLength = (fun.m_length - textLength) / 2;
p.m_endLength = p.m_startLength + textLength;
}
}
}
functor_t fun(p);
GET_POINTS(f, ForEachPointRef, fun, assign_path)
break;
}
}
if (isExist)
pDrawer->Draw(ptr.get(), styles.m_rules.data(), count, f.GetID());
return true;
}
bool DrawProcessor::IsEmptyDrawing() const
{
return (m_zoom >= feature::g_arrCountryScales[0] && !m_hasNonCoast);
}
}
|