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

geometry_processors.cpp « software_renderer - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 82985fd999bf303a71562214dba41615a890920f (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
#include "software_renderer/geometry_processors.hpp"

#include "base/assert.hpp"
#include "base/math.hpp"

#include <functional>

namespace software_renderer
{
base_screen::base_screen(params const & p)
  : base_policy(p)
{
  m_convertor->GtoP(*p.m_rect, m_rect);
}

void one_point::operator() (m2::PointD const & pt)
{
  ASSERT ( !m_exist, ("point feature should have only one point") );

  if (m_rect->IsPointInside(pt))
  {
    m_exist = true;
    m_point = convert_point(pt);
  }
  else
    m_exist = false;
}

interval_params::interval_params(params const & p)
  : base_t(p),
    m_intervals(p.m_intervals),
    m_length(0.0),
    m_hasPrevPt(false)
{
}

void get_path_intervals::operator()(m2::PointD const & pt)
{
  if (m_hasPrevPt)
  {
    m2::PointD prev = m_prev;
    m2::PointD cur = pt;

    double const segLen = cur.Length(prev);

    if (m2::Intersect(base_t::m_rect, prev, cur))
    {
      double clipStart = prev.Length(m_prev) + m_length;
      double clipEnd = cur.Length(m_prev) + m_length;

      if (m_intervals->empty())
      {
        m_intervals->push_back(clipStart);
        m_intervals->push_back(clipEnd);
      }
      else
      {
        if (base::AlmostEqualULPs(m_intervals->back(), clipStart))
          m_intervals->back() = clipEnd;
        else
        {
          m_intervals->push_back(clipStart);
          m_intervals->push_back(clipEnd);
        }
      }
    }

    m_prev = pt;
    m_length += segLen;
  }
  else
  {
    m_prev = pt;
    m_hasPrevPt = true;
  }
}

bool get_path_intervals::IsExist() const
{
  return !m_intervals->empty();
}

void cut_path_intervals::operator()(m2::PointD const & pt)
{
  if (m_hasPrevPt)
  {
    double const segLen = pt.Length(m_prev);

    for (; m_pos != m_intervals->size(); m_pos += 2)
    {
      double const start = (*m_intervals)[m_pos];
      if (start >= m_length + segLen)
        break;

      m2::PointD const dir = (pt - m_prev) / segLen;

      if (start >= m_length)
      {
        m_points.push_back(PathInfo(start));
        push_point(m_prev + dir * (start - m_length));
      }

      double const end = (*m_intervals)[m_pos+1];
      if (end >= m_length + segLen)
      {
        push_point(pt);
        break;
      }

      if (end < m_length + segLen)
      {
        push_point(m_prev + dir * (end - m_length));
#ifdef DEBUG
        double const len = m_points.back().GetLength();
        ASSERT_LESS_OR_EQUAL ( fabs(len - (end - start)), 1.0E-4, (len, end - start) );
#endif
      }
    }

    m_prev = pt;
    m_length += segLen;
  }
  else
  {
    m_hasPrevPt = true;
    m_prev = pt;
  }
}

bool cut_path_intervals::IsExist()
{
  // finally, assign whole length to every cutted path
  for_each(m_points.begin(), m_points.end(),
           std::bind(&PathInfo::SetFullLength, std::placeholders::_1, m_length));

  return !m_points.empty();
}

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(),
           std::bind(&PathInfo::SetFullLength, std::placeholders::_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 software_renderer