libosmscout 1.1.1
Loading...
Searching...
No Matches
Area.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_AREA_H
2#define OSMSCOUT_AREA_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2013 Tim Teulings
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/
22
23#include <memory>
24#include <optional>
25
26#include <osmscout/GeoCoord.h>
27#include <osmscout/Point.h>
28
29#include <osmscout/TypeConfig.h>
30
36
38
39namespace osmscout {
88 {
89 public:
90 static const uint8_t masterRingId;
91 static const uint8_t outerRingId;
92
93 public:
95 {
96 private:
97 FeatureValueBuffer featureValueBuffer;
98 uint8_t ring=0;
99
100 public:
107 std::vector<Point> nodes;
108 std::vector<SegmentGeoBox> segments;
110 std::optional<GeoCoord> center;
112
113 public:
114 Ring() = default;
115
117 {
118 return featureValueBuffer.GetType();
119 }
120
121 size_t GetFeatureCount() const
122 {
123 return featureValueBuffer.GetType()->GetFeatureCount();
124 }
125
126 bool HasFeature(size_t idx) const
127 {
128 return featureValueBuffer.HasFeature(idx);
129 }
130
131 bool HasAnyFeaturesSet() const;
132
133 const FeatureInstance& GetFeature(size_t idx) const
134 {
135 return featureValueBuffer.GetType()->GetFeature(idx);
136 }
137
138 void UnsetFeature(size_t idx)
139 {
140 featureValueBuffer.FreeValue(idx);
141 }
142
144 {
145 return featureValueBuffer;
146 }
147
148 bool IsMaster() const
149 {
150 return ring==masterRingId;
151 }
152
153 // top level outer ring
154 bool IsTopOuter() const
155 {
156 return ring==outerRingId;
157 }
158
159 // ring level is odd, it is some outer ring
160 bool IsOuter() const
161 {
162 return (ring & outerRingId) == outerRingId;
163 }
164
165 uint8_t GetRing() const
166 {
167 return ring;
168 }
169
170 Id GetSerial(size_t index) const
171 {
172 return nodes[index].GetSerial();
173 }
174
175 Id GetId(size_t index) const
176 {
177 return nodes[index].GetId();
178 }
179
181 {
182 return nodes.front().GetId();
183 }
184
185 Id GetBackId() const
186 {
187 return nodes.back().GetId();
188 }
189
191 size_t& index) const;
192
193 const GeoCoord& GetCoord(size_t index) const
194 {
195 return nodes[index].GetCoord();
196 }
197
199
201
203 {
204 featureValueBuffer.SetType(type);
205 }
206
208 {
209 featureValueBuffer.Set(buffer);
210 }
211
213 {
214 featureValueBuffer.CopyMissingValues(buffer);
215 }
216
218 {
219 ring=masterRingId;
220 }
221
223 {
224 ring=outerRingId;
225 }
226
227 void SetRing(uint8_t ring)
228 {
229 this->ring=ring;
230 }
231
232 friend class Area;
233 };
234
235 using RingVisitor = std::function<bool(size_t i, const Ring&, const TypeInfoRef&)>;
236
237 private:
238 FileOffset fileOffset=0;
239 FileOffset nextFileOffset=0;
240
241 public:
242 std::vector<Ring> rings;
243
244 public:
245 Area() = default;
246
248 {
249 return fileOffset;
250 }
251
253 {
254 return nextFileOffset;
255 }
256
258 {
259 return {fileOffset,refArea};
260 }
261
263 {
264 return rings.front().GetType();
265 }
266
267 TypeInfoRef GetRingType(const Ring &ring) const
268 {
269 if (ring.IsTopOuter() ||
270 (ring.IsOuter() && ring.GetType()->GetIgnore())) {
271 return GetType();
272 }
273
274 return ring.GetType();
275
276 }
277
279 {
280 return rings.front().GetFeatureValueBuffer();
281 }
282
283 bool IsSimple() const
284 {
285 return rings.size()==1;
286 }
287
288 bool GetCenter(GeoCoord& center) const;
289
291
301 bool Intersects(const GeoBox& boundingBox) const
302 {
303 return GetBoundingBox().Intersects(boundingBox);
304 }
305
309 void Read(const TypeConfig& typeConfig,
310 FileScanner& scanner);
311
315 void ReadImport(const TypeConfig& typeConfig,
316 FileScanner& scanner);
317
321 void ReadOptimized(const TypeConfig& typeConfig,
322 FileScanner& scanner);
323
328 void Write(const TypeConfig& typeConfig,
329 FileWriter& writer) const;
330
336 void WriteImport(const TypeConfig& typeConfig,
337 FileWriter& writer) const;
338
343 void WriteOptimized(const TypeConfig& typeConfig,
344 FileWriter& writer) const;
345
351 void VisitRings(const RingVisitor& visitor) const;
352
357 void VisitClippingRings(size_t index, const RingVisitor& visitor) const;
358 };
359
360 using AreaRef = std::shared_ptr<Area>;
361}
362
363#endif
#define OSMSCOUT_API
Definition CoreImportExport.h:45
Definition Area.h:95
bool IsTopOuter() const
Definition Area.h:154
void UnsetFeature(size_t idx)
Definition Area.h:138
friend class Area
Definition Area.h:232
std::optional< GeoCoord > center
Definition Area.h:110
void MarkAsMasterRing()
Definition Area.h:217
void SetRing(uint8_t ring)
Definition Area.h:227
bool GetCenter(GeoCoord &center) const
std::vector< SegmentGeoBox > segments
Precomputed (cache) segment bounding boxes for optimisation.
Definition Area.h:108
const GeoCoord & GetCoord(size_t index) const
Definition Area.h:193
void SetFeatures(const FeatureValueBuffer &buffer)
Definition Area.h:207
bool IsOuter() const
Definition Area.h:160
const FeatureInstance & GetFeature(size_t idx) const
Definition Area.h:133
Id GetFrontId() const
Definition Area.h:180
Id GetSerial(size_t index) const
Definition Area.h:170
bool GetNodeIndexByNodeId(Id id, size_t &index) const
GeoBox GetBoundingBox() const
size_t GetFeatureCount() const
Definition Area.h:121
GeoBox bbox
Precomputed (cache) bounding box.
Definition Area.h:109
Id GetId(size_t index) const
Definition Area.h:175
uint8_t GetRing() const
Definition Area.h:165
void MarkAsOuterRing()
Definition Area.h:222
TypeInfoRef GetType() const
Definition Area.h:116
void SetType(const TypeInfoRef &type)
Definition Area.h:202
bool IsMaster() const
Definition Area.h:148
bool HasFeature(size_t idx) const
Definition Area.h:126
Id GetBackId() const
Definition Area.h:185
void CopyMissingValues(const FeatureValueBuffer &buffer)
Definition Area.h:212
const FeatureValueBuffer & GetFeatureValueBuffer() const
Definition Area.h:143
std::vector< Point > nodes
The array of coordinates.
Definition Area.h:107
void ReadImport(const TypeConfig &typeConfig, FileScanner &scanner)
TypeInfoRef GetType() const
Definition Area.h:262
void WriteOptimized(const TypeConfig &typeConfig, FileWriter &writer) const
void WriteImport(const TypeConfig &typeConfig, FileWriter &writer) const
TypeInfoRef GetRingType(const Ring &ring) const
Definition Area.h:267
static const uint8_t masterRingId
Definition Area.h:90
void VisitRings(const RingVisitor &visitor) const
bool Intersects(const GeoBox &boundingBox) const
Definition Area.h:301
std::vector< Ring > rings
Definition Area.h:242
void Write(const TypeConfig &typeConfig, FileWriter &writer) const
GeoBox GetBoundingBox() const
bool GetCenter(GeoCoord &center) const
FileOffset GetFileOffset() const
Definition Area.h:247
ObjectFileRef GetObjectFileRef() const
Definition Area.h:257
FileOffset GetNextFileOffset() const
Definition Area.h:252
const FeatureValueBuffer & GetFeatureValueBuffer() const
Definition Area.h:278
Type type
The type of the cell.
Definition GroundTile.h:92
void ReadOptimized(const TypeConfig &typeConfig, FileScanner &scanner)
bool IsSimple() const
Definition Area.h:283
Vertex2D * buffer
Definition Transformation.h:343
static const uint8_t outerRingId
Definition Area.h:91
FeatureValueBuffer()=default
void VisitClippingRings(size_t index, const RingVisitor &visitor) const
std::function< bool(size_t i, const Ring &, const TypeInfoRef &)> RingVisitor
Definition Area.h:235
void Read(const TypeConfig &typeConfig, FileScanner &scanner)
uint64_t Id
Definition OSMScoutTypes.h:40
uint64_t FileOffset
Definition OSMScoutTypes.h:46
Definition Area.h:39
std::shared_ptr< Area > AreaRef
Definition Area.h:360
@ refArea
Definition ObjectRef.h:142
std::shared_ptr< TypeInfo > TypeInfoRef
Definition TypeConfig.h:61
Definition LaneAgent.h:61