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

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

#ifndef USE_DRAPE
#include "drawer.hpp"
#endif // USE_DRAPE

#include "indexer/feature_impl.hpp"
#include "indexer/feature_algo.hpp"


namespace fwork
{
#ifndef USE_DRAPE
  namespace
  {
    template <class TSrc> void assign_point(di::FeatureInfo & p, TSrc & src)
    {
      p.m_point = src.m_point;
    }

    template <class TSrc> void assign_path(di::FeatureInfo & p, TSrc & src)
    {
      p.m_pathes.swap(src.m_points);
    }

    template <class TSrc> void assign_area(di::FeatureInfo & p, TSrc & src)
    {
      p.m_areas.swap(src.m_points);

      ASSERT ( !p.m_areas.empty(), () );
      p.m_areas.back().SetCenter(src.GetCenter());
    }
  }

  FeatureProcessor::FeatureProcessor(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()->GetGlyphCache())
  {
    GetDrawer()->SetScale(m_zoom);
  }

  bool FeatureProcessor::operator() (FeatureType const & f)
  {
    if (m_paintEvent->isCancelled())
      throw redraw_operation_cancelled();

    Drawer * pDrawer = GetDrawer();
    di::FeatureInfo fi(f, m_zoom, pDrawer->VisualScale(), m_glyphCache, &m_convertor, &m_rect);

    if (fi.m_styler.IsEmpty())
      return true;

    // Draw coastlines features only once.
    if (fi.m_styler.m_isCoastline)
    {
      if (!m_coasts.insert(fi.m_styler.m_primaryText).second)
        return true;
    }
    else
      m_hasNonCoast = true;

    using namespace gp;

    bool isExist = false;

    switch (fi.m_styler.m_geometryType)
    {
    case feature::GEOM_POINT:
    {
      typedef gp::one_point functor_t;

      functor_t::params p;
      p.m_convertor = &m_convertor;
      p.m_rect = &m_rect;

      functor_t fun(p);
      f.ForEachPointRef(fun, m_zoom);
      if (fun.IsExist())
      {
        isExist = true;
        assign_point(fi, fun);
      }

      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);
      f.ForEachTriangleExRef(fun, m_zoom);

      if (fi.m_styler.m_hasPointStyles)
        fun.SetCenter(feature::GetCenter(f, m_zoom));

      if (fun.IsExist())
      {
        isExist = true;
        assign_area(fi, fun);
      }

      // continue rendering as line if feature has linear styles too
      if (!fi.m_styler.m_hasLineStyles)
        break;
    }

    case feature::GEOM_LINE:
      {
        if (fi.m_styler.m_hasPathText)
        {
          typedef filter_screenpts_adapter<cut_path_intervals> functor_t;

          functor_t::params p;

          p.m_convertor = &m_convertor;
          p.m_rect = &m_rect;
          p.m_intervals = &fi.m_styler.m_intervals;

          functor_t fun(p);

          f.ForEachPointRef(fun, m_zoom);
          if (fun.IsExist())
          {
            isExist = true;
            assign_path(fi, fun);

#ifdef DEBUG
            if (fi.m_pathes.size() == 1)
            {
              double const offset = fi.m_pathes.front().GetOffset();
              for (size_t i = 0; i < fi.m_styler.m_offsets.size(); ++i)
                ASSERT_LESS_OR_EQUAL(offset, fi.m_styler.m_offsets[i], ());
            }
#endif
          }
        }
        else
        {
          typedef filter_screenpts_adapter<path_points> functor_t;

          functor_t::params p;

          p.m_convertor = &m_convertor;
          p.m_rect = &m_rect;

          functor_t fun(p);

          f.ForEachPointRef(fun, m_zoom);

          if (fun.IsExist())
          {
            isExist = true;
            assign_path(fi, fun);
          }
        }
        break;
      }
    }

    if (isExist)
      pDrawer->Draw(fi);

    return true;
  }

  bool FeatureProcessor::IsEmptyDrawing() const
  {
    return (m_zoom >= feature::g_arrCountryScales[0] && !m_hasNonCoast);
  }
#endif // USE_DRAPE
}