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

geometry_processors.hpp « software_renderer - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 59b657747ec755d32192a109990fc99fd09f1388 (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
#pragma once

#include "area_info.hpp"
#include "path_info.hpp"

#include "indexer/cell_id.hpp" // CoordPointT

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

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

#include "base/buffer_vector.hpp"

class ScreenBase;

namespace software_renderer
{

/// @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

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

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

  ScreenBase const * m_convertor;

  m2::PointD g2p(m2::PointD const & pt) const
  {
    return m_convertor->GtoP(pt);
  }
};

/// in global coordinates
struct base_global : public base
{
  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){}
  };

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

/// in screen coordinates
struct base_screen : public base
{
  m2::RectD m_rect;

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

  explicit base_screen(params const & p);

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

//@}

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

  typedef typename TBase::params params;

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

  void operator() (m2::PointD const & p)
  {
    m2::PointD const pt(this->convert_point(p));

    if (m_exist)
      m_length += pt.Length(m_prevPt);

    m_exist = true;
    m_prevPt = pt;
  }

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

struct one_point : public base_global
{
  bool m_exist;
  m2::PointD m_point;

  typedef base_global::params params;

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

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

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

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

  typedef typename TBase::params params;

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

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

  void push_point(m2::PointD const & pt)
  {
    /// @todo Filter for equal points.
    m_points.back().push_back(this->convert_point(pt));
  }
};

struct interval_params : public geometry_base<PathInfo, base_screen>
{
  typedef geometry_base<PathInfo, base_screen> base_t;

  buffer_vector<double, 16> * m_intervals;

  m2::PointD m_prev;
  double m_length;
  bool m_hasPrevPt;

  struct params : base_t::params
  {
    buffer_vector<double, 16> * m_intervals;
    params() : m_intervals(0) {}
  };

  explicit interval_params(params const & p);
};

struct get_path_intervals : public interval_params
{
  explicit get_path_intervals(params const & p) : interval_params(p) {}

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

  bool IsExist() const;
};

struct cut_path_intervals : public interval_params
{
  size_t m_pos;

  explicit cut_path_intervals(params const & p) : interval_params(p), m_pos(0) {}

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

  bool IsExist();
};

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

  bool m_newPL, m_hasPrevPt;
  m2::PointD m_prev;

  double m_length;
  double m_startLength;
  double m_endLength;

  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)
    {}
  };

  explicit 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<AreaInfo, base_screen>
{
  typedef geometry_base<AreaInfo, base_screen> base_type;

public:

  typedef base_type::params params;

  explicit 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;

  explicit 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
{
  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;

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

  void operator() (m2::PointD const & p)
  {
    m2::PointD const pt = this->g2p(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]);

    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; }
  void SetCenter(m2::PointD const & p) { m_center = this->g2p(p); }
};

}