-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmap_defs.cpp
305 lines (243 loc) · 5.82 KB
/
map_defs.cpp
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
#include "map_defs.h"
#include <QPolygonF>
#include <QPointF>
#include <cmath>
namespace map {
void Tile::setIndex(const TileIndex &index)
{
index_ = index;
}
void Tile::setCreationTime(const QDateTime &val)
{
creationTime_ = val;
}
void Tile::setRequestLastTime(const QDateTime &val)
{
requestLastTime_ = val;
}
void Tile::setVertices(const QVector<QVector3D> &vertices)
{
vertices_ = vertices;
}
TileInfo Tile::getOriginTileInfo() const
{
return originInfo_;
}
TileInfo Tile::getModifiedTileInfo() const
{
return modifiedInfo_;
}
Tile::State Tile::getState() const
{
return state_;
}
bool Tile::getInUse() const
{
return inUse_;
}
bool Tile::getIsCopied() const
{
return copied_;
}
QImage Tile::getImage() const
{
return image_;
}
QImage& Tile::getImageRef()
{
return image_;
}
bool Tile::getImageIsNull() const
{
return image_.isNull();
}
GLuint Tile::getTextureId() const
{
return textureId_;
}
TileIndex Tile::getIndex() const
{
return index_;
}
QDateTime Tile::getCreationTime() const
{
return creationTime_;
}
QDateTime Tile::getRequestLastTime() const
{
return requestLastTime_;
}
LLARef Tile::getUsedLlaRef() const
{
return usedLlaRef_;
}
const QVector<QVector3D>& Tile::getVerticesRef() const
{
return vertices_;
}
bool Tile::operator==(const Tile &other) const
{
return index_ == other.index_;
}
bool Tile::operator!=(const Tile &other) const
{
return !(*this == other);
}
bool Tile::operator<(const Tile &other) const
{
if (index_ != other.index_) {
return index_ < other.index_;
}
return false;
}
Tile::Tile(TileIndex index) :
state_(State::kNone),
inUse_(false),
copied_(false),
textureId_(0),
index_(index),
creationTime_(QDateTime::currentDateTimeUtc())
{
}
void Tile::updateVertices(const LLARef& llaRef, bool isPerspective)
{
auto ref = llaRef;
if (llaRef.isInit) {
LLA lla1(modifiedInfo_.bounds.south, modifiedInfo_.bounds.west, 0.0f); // 4 <--- 3
NED ned1(&lla1, &ref, isPerspective); // |
LLA lla2(modifiedInfo_.bounds.north, modifiedInfo_.bounds.west, 0.0f); // |
NED ned2(&lla2, &ref, isPerspective); // 1 ---> 2
LLA lla3(modifiedInfo_.bounds.north, modifiedInfo_.bounds.east, 0.0f);
NED ned3(&lla3, &ref, isPerspective);
LLA lla4(modifiedInfo_.bounds.south, modifiedInfo_.bounds.east, 0.0f);
NED ned4(&lla4, &ref, isPerspective);
vertices_ = {
QVector3D(ned1.n, ned1.e, 0.0f),
QVector3D(ned2.n, ned2.e, 0.0f),
QVector3D(ned3.n, ned3.e, 0.0f),
QVector3D(ned4.n, ned4.e, 0.0f)
};
usedLlaRef_ = ref;
}
}
bool Tile::isValid() const
{
if (index_ != TileIndex()) {
return true;
}
return false;
}
void Tile::setOriginTileInfo(const TileInfo &info)
{
originInfo_ = info;
}
void Tile::setModifiedTileInfo(const TileInfo &info)
{
modifiedInfo_ = info;
}
void Tile::setState(State state)
{
state_ = state;
}
void Tile::setInUse(bool val)
{
inUse_ = val;
}
void Tile::setIsCopied(bool val)
{
copied_ = val;
}
void Tile::setImage(const QImage &image)
{
image_ = image;
}
void Tile::setTextureId(GLuint textureId)
{
textureId_ = textureId;
}
TileIndex::TileIndex() :
x_(-1),
y_(-1),
z_(-1),
providerId_(-1)
{
}
TileIndex::TileIndex(int32_t x, int32_t y, int32_t z, int32_t providerId) :
x_(x),
y_(y),
z_(z),
providerId_(providerId)
{
}
bool TileIndex::isValid() const
{
return !(x_ == -1 || y_ == -1 || z_ == -1 || providerId_ == -1);
}
std::pair<TileIndex, bool> TileIndex::getParent(int depth) const
{
if (depth < 0) {
depth = 0;
}
int targetZ = z_ - depth;
if (targetZ < 1) {
return {*this, false};
}
int shift = depth;
TileIndex parent{
x_ >> shift,
y_ >> shift,
targetZ,
providerId_
};
return { parent, true };
}
std::pair<std::vector<TileIndex>, bool> TileIndex::getChilds(int depth) const
{
if (depth < 1) {
depth = 1;
}
int targetZ = z_ + depth;
if (targetZ > 21) {
return {{}, false};
}
std::vector<TileIndex> childs = {
TileIndex{x_ * 2, y_ * 2, z_ + 1, providerId_},
TileIndex{x_ * 2 + 1, y_ * 2, z_ + 1, providerId_},
TileIndex{x_ * 2, y_ * 2 + 1, z_ + 1, providerId_},
TileIndex{x_ * 2 + 1, y_ * 2 + 1, z_ + 1, providerId_}
};
for (int currentDepth = 2; currentDepth <= depth; ++currentDepth) {
std::vector<TileIndex> nextGeneration;
for (const auto& child : childs) {
nextGeneration.push_back(TileIndex{child.x_ * 2, child.y_ * 2, child.z_ + 1, providerId_});
nextGeneration.push_back(TileIndex{child.x_ * 2 + 1, child.y_ * 2, child.z_ + 1, providerId_});
nextGeneration.push_back(TileIndex{child.x_ * 2, child.y_ * 2 + 1, child.z_ + 1, providerId_});
nextGeneration.push_back(TileIndex{child.x_ * 2 + 1, child.y_ * 2 + 1, child.z_ + 1, providerId_});
}
childs = std::move(nextGeneration);
}
return { childs, true };
}
bool TileIndex::operator==(const TileIndex &other) const
{
return x_ == other.x_ &&
y_ == other.y_ &&
z_ == other.z_ &&
providerId_ == other.providerId_;
}
bool TileIndex::operator!=(const TileIndex &other) const
{
return !(*this == other);
}
bool TileIndex::operator<(const TileIndex &other) const
{
if (z_ != other.z_) return z_ < other.z_;
if (x_ != other.x_) return x_ < other.x_;
if (y_ != other.y_) return y_ < other.y_;
return providerId_ < other.providerId_;
}
bool Tile::getHasValidImage() const
{
return (!image_.isNull() && !copied_);
}
} // namespace map