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

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

#include "drape_frontend/color_constants.hpp"
#include "drape_frontend/map_shape.hpp"
#include "drape_frontend/render_state_extension.hpp"
#include "drape_frontend/shape_view_params.hpp"

#include "drape/render_bucket.hpp"
#include "drape/utils/vertex_decl.hpp"
#include "drape/pointers.hpp"

#include "traffic/speed_groups.hpp"

#include "geometry/polyline2d.hpp"

#include <cmath>
#include <memory>
#include <vector>

namespace df
{
double const kArrowSize = 0.0008;

// Constants below depend on arrow texture.
double const kArrowTextureWidth = 74.0;
double const kArrowTextureHeight = 44.0;
double const kArrowBodyHeight = 24.0;
double const kArrowHeadTextureWidth = 32.0;
double const kArrowTailTextureWidth = 4.0;

double const kArrowHeadSize = kArrowHeadTextureWidth / kArrowTextureWidth;
float const kArrowHeadFactor = static_cast<float>(2.0 * kArrowHeadTextureWidth / kArrowTextureHeight);
double const kArrowTailSize = kArrowTailTextureWidth / kArrowTextureWidth;
float const kArrowTailFactor = static_cast<float>(2.0 * kArrowTailTextureWidth / kArrowTextureHeight);
double const kArrowHeightFactor = kArrowTextureHeight / kArrowBodyHeight;
double const kArrowAspect = kArrowTextureWidth / kArrowTextureHeight;

extern std::vector<float> const kRouteHalfWidthInPixelCar;
extern std::vector<float> const kRouteHalfWidthInPixelTransit;
extern std::vector<float> const kRouteHalfWidthInPixelOthers;

enum class RouteType : uint8_t
{
  Car,
  Pedestrian,
  Bicycle,
  Taxi,
  Transit
};

struct RoutePattern
{
  RoutePattern() = default;

  RoutePattern(double dashLength, double gapLength)
    : m_isDashed(true)
    , m_dashLength(dashLength)
    , m_gapLength(gapLength)
  {}

  bool operator == (RoutePattern const & pattern) const
  {
    double const kEps = 1e-5;
    return m_isDashed == pattern.m_isDashed &&
           std::fabs(m_dashLength - pattern.m_dashLength) < kEps &&
           std::fabs(m_gapLength - pattern.m_gapLength) < kEps;
  }

  bool m_isDashed = false;
  double m_dashLength = 0.0;
  double m_gapLength = 0.0;
};

enum class SubrouteStyleType
{
  Single = 0,
  Multiple
};

struct SubrouteStyle
{
  SubrouteStyle() = default;
  explicit SubrouteStyle(df::ColorConstant const & color)
    : m_color(color)
    , m_outlineColor(color)
  {}
  SubrouteStyle(df::ColorConstant const & color, df::ColorConstant const & outlineColor)
    : m_color(color)
    , m_outlineColor(outlineColor)
  {}
  SubrouteStyle(df::ColorConstant const & color, df::RoutePattern const & pattern)
    : m_color(color)
    , m_outlineColor(color)
    , m_pattern(pattern)
  {}
  SubrouteStyle(df::ColorConstant const & color, df::ColorConstant const & outlineColor,
                df::RoutePattern const & pattern)
    : m_color(color)
    , m_outlineColor(outlineColor)
    , m_pattern(pattern)
  {}

  bool operator==(SubrouteStyle const & style) const
  {
    return m_color == style.m_color && m_outlineColor == style.m_outlineColor &&
           m_pattern == style.m_pattern;
  }

  bool operator!=(SubrouteStyle const & style) const { return !operator==(style); }

  df::ColorConstant m_color;
  df::ColorConstant m_outlineColor;
  df::RoutePattern m_pattern;
  size_t m_startIndex = 0;
  size_t m_endIndex = 0;
};

// Colored circle on the subroute.
struct SubrouteMarker
{
  // Position in mercator.
  m2::PointD m_position = {};
  // Distance from the beginning of route.
  double m_distance = 0.0;
  // Array of colors in range [0;2].
  std::vector<df::ColorConstant> m_colors;
  // Color of inner circle.
  df::ColorConstant m_innerColor;
  // Normalized up vector to determine rotation of circle.
  m2::PointD m_up = m2::PointD(0.0, 1.0);
  // Scale (1.0 when the radius is equal to route line half-width).
  float m_scale = 1.0f;
};

struct Subroute
{
  void AddStyle(SubrouteStyle const & style);

  df::RouteType m_routeType;
  m2::PolylineD m_polyline;
  std::vector<double> m_turns;
  std::vector<traffic::SpeedGroup> m_traffic;
  double m_baseDistance = 0.0;
  double m_baseDepthIndex = 0.0;
  float m_maxPixelWidth = -1.0f;

  SubrouteStyleType m_styleType = SubrouteStyleType::Single;
  std::vector<SubrouteStyle> m_style;

  std::vector<SubrouteMarker> m_markers;
};

using SubrouteConstPtr = std::shared_ptr<Subroute const>;

struct RouteRenderProperty
{
  RouteRenderProperty()
    : m_state(CreateRenderState(gpu::Program::Route, DepthLayer::GeometryLayer))
  {}

  dp::RenderState m_state;
  std::vector<drape_ptr<dp::RenderBucket>> m_buckets;
  std::vector<m2::RectD> m_boundingBoxes;
};

struct BaseSubrouteData
{
  dp::DrapeID m_subrouteId = 0;
  m2::PointD m_pivot = m2::PointD(0.0, 0.0);
  int m_recacheId = -1;
  RouteRenderProperty m_renderProperty;
};

struct SubrouteData : public BaseSubrouteData
{
  SubrouteConstPtr m_subroute;
  size_t m_startPointIndex = 0;
  size_t m_endPointIndex = 0;
  size_t m_styleIndex = 0;
  double m_distanceOffset = 0.0;
};

struct SubrouteArrowsData : public BaseSubrouteData {};

struct SubrouteMarkersData : public BaseSubrouteData {};

struct ArrowBorders
{
  double m_startDistance = 0.0;
  double m_endDistance = 0.0;
  int m_groupIndex = 0;
};

class RouteShape
{
public:
  using RV = gpu::RouteVertex;
  using GeometryBuffer = buffer_vector<RV, 128>;
  using AV = gpu::SolidTexturingVertex;
  using ArrowGeometryBuffer = buffer_vector<AV, 128>;
  using MV = gpu::RouteMarkerVertex;
  using MarkersGeometryBuffer = buffer_vector<MV, 32>;

  static drape_ptr<df::SubrouteData> CacheRoute(ref_ptr<dp::GraphicsContext> context,
                                                dp::DrapeID subrouteId, SubrouteConstPtr subroute,
                                                size_t styleIndex, int recacheId,
                                                ref_ptr<dp::TextureManager> textures);

  static drape_ptr<df::SubrouteMarkersData> CacheMarkers(ref_ptr<dp::GraphicsContext> context,
                                                         dp::DrapeID subrouteId,
                                                         SubrouteConstPtr subroute, int recacheId,
                                                         ref_ptr<dp::TextureManager> textures);

  static void CacheRouteArrows(ref_ptr<dp::GraphicsContext> context,
                               ref_ptr<dp::TextureManager> mng, m2::PolylineD const & polyline,
                               std::vector<ArrowBorders> const & borders, double baseDepthIndex,
                               SubrouteArrowsData & routeArrowsData);

private:
  template<typename GeometryBufferType>
  struct GeometryBufferData
  {
    GeometryBufferData()
      : m_boundingBox(m2::RectD::GetEmptyRect())
    {}

    GeometryBufferType m_geometry;
    GeometryBufferType m_joinsGeometry;
    m2::RectD m_boundingBox;
  };
  static void PrepareGeometry(std::vector<m2::PointD> const & path, m2::PointD const & pivot,
                              std::vector<glsl::vec4> const & segmentsColors, float baseDepth,
                              std::vector<GeometryBufferData<GeometryBuffer>> & geometryBufferData);
  static void PrepareArrowGeometry(std::vector<m2::PointD> const & path, m2::PointD const & pivot,
                                   m2::RectF const & texRect, float depthStep, float depth,
                                   GeometryBufferData<ArrowGeometryBuffer> & geometryBufferData);
  static void PrepareMarkersGeometry(std::vector<SubrouteMarker> const & markers,
                                     m2::PointD const & pivot, float baseDepth,
                                     MarkersGeometryBuffer & geometry);

  static void BatchGeometry(ref_ptr<dp::GraphicsContext> context, dp::RenderState const & state,
                            ref_ptr<void> geometry, uint32_t geomSize, ref_ptr<void> joinsGeometry,
                            uint32_t joinsGeomSize, m2::RectD const & boundingBox,
                            dp::BindingInfo const & bindingInfo, RouteRenderProperty & property);
};
}  // namespace df