Welcome to mirror list, hosted at ThFree Co, Russian Federation.

draw_processor.hpp « map - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7419ff9e7183c6fbe0f702319765f4c185ba826e (plain)
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
#pragma once

#include "draw_info.hpp"
#include "events.hpp"

#include "../indexer/drawing_rule_def.hpp"
#include "../indexer/feature.hpp"
#include "../indexer/cell_id.hpp" // CoordPointT
#include "../indexer/data_header.hpp"
#include "../indexer/feature_data.hpp"

#include "../geometry/point2d.hpp"
#include "../geometry/rect2d.hpp"

#include "../std/list.hpp"
#include "../std/limits.hpp"

#include "../yg/glyph_cache.hpp"

class ScreenBase;

namespace get_pts
{
  /// @name Base class policies (use by inheritance) for points processing.
  /// Containt next functions:\n
  /// - make_point - convert from Feature point to Screen point
  /// - convert_point - convert point to screen coordinates;\n
  /// - m_rect - clip rect;\n

  //@{
  class base
  {
  protected:
    ScreenBase const * m_convertor;

    static m2::PointD make_point(CoordPointT const & p)
    {
      return m2::PointD(p.first, p.second);
    }
    m2::PointD g2p(m2::PointD const & pt) const;

    struct params
    {
      ScreenBase const * m_convertor;
      params() : m_convertor()
      {}
    };

    base(params const & p) : m_convertor(p.m_convertor)
    {
    }
  };

  /// in global coordinates
  class base_global : public base
  {
  protected:
    m2::RectD const * m_rect;

    m2::PointD convert_point(m2::PointD const & pt) const
    {
      return g2p(pt);
    }

    struct params : base::params
    {
      m2::RectD const * m_rect;
      params() : m_rect(0){}
    };

    base_global(params const & p)
      : base(p), m_rect(p.m_rect)
    {
    }
  };

  /// in screen coordinates
  class base_screen : public base
  {
  protected:

    m2::RectD m_rect;

    m2::PointD convert_point(m2::PointD const & pt) const
    {
      return pt;
    }

    struct params : base::params
    {
      m2::RectD const * m_rect;
      params() : m_rect(0)
      {}
    };

    base_screen(params const & p);
  };

  //@}

  template <typename TBase>
  class calc_length : public TBase
  {
    bool m_exist;
    m2::PointD m_prevPt;
  public:
    double m_length;

    typedef typename TBase::params params;

    calc_length(params const & p) :
      TBase(p), m_exist(false), m_length(0)
    {}

    void operator() (CoordPointT const & p)
    {
      m2::PointD pt(this->convert_point(this->make_point(p)));
      if (m_exist)
        m_length += pt.Length(m_prevPt);

      m_exist = true;
      m_prevPt = pt;
    }

    bool IsExist() const {return m_exist;}
  };

  class one_point : public base_global
  {
    bool m_exist;

  public:
    m2::PointD m_point;

    typedef base_global::params params;

    one_point(params const & p)
      : base_global(p), m_exist(false)
    {
    }

    void operator() (CoordPointT const & p);

    bool IsExist() const { return m_exist; }
  };

  template <class TInfo, class TBase> class geometry_base : public TBase
  {
  public:
    list<TInfo> m_points;

    typedef typename TBase::params params;

    geometry_base(params const & p)
      : TBase(p)
    {
    }

    bool IsExist() const
    {
      return !m_points.empty();
    }

    void push_point(m2::PointD const & pt)
    {
      m_points.back().push_back(this->convert_point(pt));
    }
  };

  class path_points : public geometry_base<di::PathInfo, base_screen>
  {
    typedef geometry_base<di::PathInfo, base_screen> base_type;

    bool m_newPL, m_hasPrevPt;
    m2::PointD m_prev;

    double m_length;
    double m_startLength;
    double m_endLength;

    double m_fontSize;

    void StartPL(m2::PointD const & pt);
    void EndPL();

    static bool equal_glb_pts(m2::PointD const & p1, m2::PointD const & p2)
    {
      return p1.EqualDxDy(p2, 1.0E-12);
    }

    void simple_filtration(m2::PointD const & p);
    void best_filtration(m2::PointD const & p);

  public:

    struct params : base_type::params
    {
      double m_startLength;
      double m_endLength;
      params() : m_startLength(0), m_endLength(0)
      {}
    };

    path_points(params const & p)
      : base_type(p),
        m_newPL(true),
        m_hasPrevPt(false),
        m_length(0.0),
        m_startLength(p.m_startLength),
        m_endLength(p.m_endLength)
    {
    }

    void operator() (m2::PointD const & p);

    bool IsExist();
  };

  /// @name Policies for filling area.
  //@{
  class area_base : public geometry_base<di::AreaInfo, base_screen>
  {
    typedef geometry_base<di::AreaInfo, base_screen> base_type;

  public:

    typedef base_type::params params;

    area_base(params const & p)
      : base_type(p)
    {
    }
  };

  /// Used for triangle draw policy.
  class area_tess_points : public area_base
  {
  public:
    typedef area_base::params params;

    area_tess_points(params const & p)
      : area_base(p)
    {
    }

    void StartPrimitive(size_t ptsCount);
    void operator() (m2::PointD const & p1, m2::PointD const & p2, m2::PointD const & p3);
    void EndPrimitive();

    bool IsExist() const;
  };
  //@}

  /// Adapter for points filtering, before they will go for processing
  template <class TBase> class filter_screenpts_adapter : public TBase
  {
    size_t m_count;
    m2::PointD m_prev, m_center;

    static bool equal_scr_pts(m2::PointD const & p1, m2::PointD const & p2)
    {
      return p1.EqualDxDy(p2, 0.5);
    }
    static bool empty_scr_rect(m2::RectD const & r)
    {
      double const eps = 1.0;
      return (r.SizeX() < eps && r.SizeY() < eps);
    }

  public:

    typedef typename TBase::params params;

    filter_screenpts_adapter(params const & p)
      : TBase(p), m_count(0),
      m_prev(numeric_limits<CoordT>::min(), numeric_limits<CoordT>::min()), m_center(0, 0)
    {
    }

    void operator() (CoordPointT const & p)
    {
      m2::PointD pt = this->g2p(this->make_point(p));
      if (!equal_scr_pts(m_prev, pt))
      {
        TBase::operator()(pt);
        m_prev = pt;
      }
    }

    void operator() (m2::PointD const & p1, m2::PointD const & p2, m2::PointD const & p3)
    {
      m2::PointD arr[] = { this->g2p(p1), this->g2p(p2), this->g2p(p3) };

      m2::RectD r;
      for (int i = 0; i < 3; ++i)
      {
        r.Add(arr[i]);
        m_center += arr[i];
      }
      ++m_count;

      if (!empty_scr_rect(r) && r.IsIntersect(this->m_rect))
        TBase::operator()(arr[0], arr[1], arr[2]);
    }

    m2::PointD GetCenter() const { return m_center / (3*m_count); }
  };
}

namespace drule { class BaseRule; }
namespace di { class DrawInfo; }

class redraw_operation_cancelled {};

namespace fwork
{
  class DrawProcessor
  {
    m2::RectD m_rect;

    ScreenBase const & m_convertor;

    shared_ptr<PaintEvent> m_paintEvent;

    int m_zoom;
    yg::GlyphCache * m_glyphCache;

#ifdef PROFILER_DRAWING
    size_t m_drawCount;
#endif

    inline DrawerYG * GetDrawer() const { return m_paintEvent->drawer(); }

    void PreProcessKeys(vector<drule::Key> & keys) const;

    static const int reserve_rules_count = 16;

  public:

    DrawProcessor(m2::RectD const & r,
                  ScreenBase const & convertor,
                  shared_ptr<PaintEvent> const & paintEvent,
                  int scaleLevel);

    bool operator() (FeatureType const & f) const;
  };
}