forked from organicmaps/organicmaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapply_feature_functors.hpp
223 lines (179 loc) · 6.88 KB
/
apply_feature_functors.hpp
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
#pragma once
#include "drape_frontend/stylist.hpp"
#include "drape_frontend/tile_key.hpp"
#include "drape_frontend/shape_view_params.hpp"
#include "drape/drape_diagnostics.hpp"
#include "drape/pointers.hpp"
#include "indexer/ftypes_matcher.hpp"
#include "indexer/road_shields_parser.hpp"
#include "geometry/clipping.hpp"
#include "geometry/point2d.hpp"
#include "geometry/polyline2d.hpp"
#include "geometry/spline.hpp"
#include <functional>
#include <utility>
#include <vector>
class CaptionDefProto;
class ShieldRuleProto;
class SymbolRuleProto;
namespace dp
{
class TextureManager;
} // namespace dp
namespace df
{
struct TextViewParams;
class MapShape;
struct BuildingOutline;
using TInsertShapeFn = std::function<void(drape_ptr<MapShape> && shape)>;
class BaseApplyFeature
{
public:
BaseApplyFeature(TileKey const & tileKey, TInsertShapeFn const & insertShape,
FeatureID const & id, int minVisibleScale, uint8_t rank,
CaptionDescription const & captions);
virtual ~BaseApplyFeature() = default;
protected:
void ExtractCaptionParams(CaptionDefProto const * primaryProto,
CaptionDefProto const * secondaryProto,
float depth, TextViewParams & params) const;
std::string ExtractHotelInfo() const;
TInsertShapeFn m_insertShape;
FeatureID m_id;
CaptionDescription const & m_captions;
int m_minVisibleScale;
uint8_t m_rank;
TileKey const m_tileKey;
m2::RectD const m_tileRect;
};
class ApplyPointFeature : public BaseApplyFeature
{
using TBase = BaseApplyFeature;
public:
ApplyPointFeature(TileKey const & tileKey, TInsertShapeFn const & insertShape,
FeatureID const & id, int minVisibleScale, uint8_t rank,
CaptionDescription const & captions, float posZ,
DepthLayer depthLayer);
void operator()(m2::PointD const & point, bool hasArea);
void ProcessPointRule(Stylist::TRuleWrapper const & rule);
void Finish(ref_ptr<dp::TextureManager> texMng);
protected:
float const m_posZ;
private:
bool m_hasPoint;
bool m_hasArea;
bool m_createdByEditor;
bool m_obsoleteInEditor;
DepthLayer m_depthLayer;
double m_symbolDepth;
SymbolRuleProto const * m_symbolRule;
m2::PointF m_centerPoint;
std::vector<TextViewParams> m_textParams;
};
class ApplyAreaFeature : public ApplyPointFeature
{
using TBase = ApplyPointFeature;
public:
ApplyAreaFeature(TileKey const & tileKey, TInsertShapeFn const & insertShape,
FeatureID const & id, double currentScaleGtoP, bool isBuilding,
bool skipAreaGeometry, float minPosZ, float posZ, int minVisibleScale,
uint8_t rank, CaptionDescription const & captions, bool hatchingArea);
using TBase::operator ();
void operator()(m2::PointD const & p1, m2::PointD const & p2, m2::PointD const & p3);
void ProcessAreaRule(Stylist::TRuleWrapper const & rule);
struct Edge
{
Edge() = default;
Edge(int startIndex, int endIndex) : m_startIndex(startIndex), m_endIndex(endIndex) {}
bool operator==(Edge const & edge) const
{
return (m_startIndex == edge.m_startIndex && m_endIndex == edge.m_endIndex) ||
(m_startIndex == edge.m_endIndex && m_endIndex == edge.m_startIndex);
}
int m_startIndex = -1;
int m_endIndex = -1;
};
struct ExtendedEdge
{
ExtendedEdge() = default;
ExtendedEdge(Edge && edge, int internalVertexIndex, bool twoSide)
: m_edge(std::move(edge))
, m_internalVertexIndex(internalVertexIndex)
, m_twoSide(twoSide)
{}
Edge m_edge;
int m_internalVertexIndex = -1;
bool m_twoSide = false;
};
private:
void ProcessBuildingPolygon(m2::PointD const & p1, m2::PointD const & p2, m2::PointD const & p3);
void CalculateBuildingOutline(bool calculateNormals, BuildingOutline & outline);
int GetIndex(m2::PointD const & pt);
void BuildEdges(int vertexIndex1, int vertexIndex2, int vertexIndex3, bool twoSide);
bool IsDuplicatedEdge(Edge const & edge);
m2::PointD CalculateNormal(m2::PointD const & p1, m2::PointD const & p2, m2::PointD const & p3) const;
std::vector<m2::PointD> m_triangles;
buffer_vector<m2::PointD, kBuildingOutlineSize> m_points;
buffer_vector<ExtendedEdge, kBuildingOutlineSize> m_edges;
float const m_minPosZ;
bool const m_isBuilding;
bool const m_skipAreaGeometry;
bool const m_hatchingArea;
double const m_currentScaleGtoP;
};
class ApplyLineFeatureGeometry : public BaseApplyFeature
{
using TBase = BaseApplyFeature;
public:
ApplyLineFeatureGeometry(TileKey const & tileKey, TInsertShapeFn const & insertShape,
FeatureID const & id, double currentScaleGtoP, int minVisibleScale,
uint8_t rank, size_t pointsCount, bool smooth);
void operator() (m2::PointD const & point);
bool HasGeometry() const;
void ProcessLineRule(Stylist::TRuleWrapper const & rule);
void Finish();
std::vector<m2::SharedSpline> const & GetClippedSplines() const { return m_clippedSplines; }
private:
m2::SharedSpline m_spline;
std::vector<m2::SharedSpline> m_clippedSplines;
float m_currentScaleGtoP;
double m_sqrScale;
m2::PointD m_lastAddedPoint;
bool m_simplify;
bool m_smooth;
size_t m_initialPointsCount;
#ifdef LINES_GENERATION_CALC_FILTERED_POINTS
int m_readCount;
#endif
};
class ApplyLineFeatureAdditional : public BaseApplyFeature
{
using TBase = BaseApplyFeature;
public:
ApplyLineFeatureAdditional(TileKey const & tileKey, TInsertShapeFn const & insertShape,
FeatureID const & id, double currentScaleGtoP, int minVisibleScale,
uint8_t rank, CaptionDescription const & captions,
std::vector<m2::SharedSpline> const & clippedSplines);
void ProcessLineRule(Stylist::TRuleWrapper const & rule);
void Finish(ref_ptr<dp::TextureManager> texMng, std::set<ftypes::RoadShield> && roadShields,
GeneratedRoadShields & generatedRoadShields);
private:
void GetRoadShieldsViewParams(ref_ptr<dp::TextureManager> texMng,
ftypes::RoadShield const & shield,
uint8_t shieldIndex, uint8_t shieldCount,
TextViewParams & textParams,
ColoredSymbolViewParams & symbolParams,
PoiSymbolViewParams & poiParams,
m2::PointD & shieldPixelSize);
bool CheckShieldsNearby(m2::PointD const & shieldPos,
m2::PointD const & shieldPixelSize,
uint32_t minDistanceInPixels,
std::vector<m2::RectD> & shields);
std::vector<m2::SharedSpline> m_clippedSplines;
float m_currentScaleGtoP;
float m_depth;
CaptionDefProto const * m_captionRule;
ShieldRuleProto const * m_shieldRule;
};
extern dp::Color ToDrapeColor(uint32_t src);
} // namespace df