libosmscout  1.1.1
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 
25 #include <osmscout/GeoCoord.h>
26 #include <osmscout/Point.h>
27 
28 #include <osmscout/TypeConfig.h>
29 
32 #include <osmscout/util/GeoBox.h>
33 #include <osmscout/util/Progress.h>
34 #include <osmscout/util/Geometry.h>
35 
37 
38 namespace osmscout {
87  {
88  public:
89  static const uint8_t masterRingId;
90  static const uint8_t outerRingId;
91 
92  public:
94  {
95  private:
96  FeatureValueBuffer featureValueBuffer;
97  uint8_t ring=0;
98 
99  public:
106  std::vector<Point> nodes;
107  std::vector<SegmentGeoBox> segments;
108  GeoBox bbox;
109 
110  public:
111  Ring() = default;
112 
114  {
115  return featureValueBuffer.GetType();
116  }
117 
118  size_t GetFeatureCount() const
119  {
120  return featureValueBuffer.GetType()->GetFeatureCount();
121  }
122 
123  bool HasFeature(size_t idx) const
124  {
125  return featureValueBuffer.HasFeature(idx);
126  }
127 
128  bool HasAnyFeaturesSet() const;
129 
130  const FeatureInstance& GetFeature(size_t idx) const
131  {
132  return featureValueBuffer.GetType()->GetFeature(idx);
133  }
134 
135  void UnsetFeature(size_t idx)
136  {
137  featureValueBuffer.FreeValue(idx);
138  }
139 
140  const FeatureValueBuffer& GetFeatureValueBuffer() const
141  {
142  return featureValueBuffer;
143  }
144 
145  bool IsMaster() const
146  {
147  return ring==masterRingId;
148  }
149 
150  // top level outer ring
151  bool IsTopOuter() const
152  {
153  return ring==outerRingId;
154  }
155 
156  // ring level is odd, it is some outer ring
157  bool IsOuter() const
158  {
159  return (ring & outerRingId) == outerRingId;
160  }
161 
162  uint8_t GetRing() const
163  {
164  return ring;
165  }
166 
167  Id GetSerial(size_t index) const
168  {
169  return nodes[index].GetSerial();
170  }
171 
172  Id GetId(size_t index) const
173  {
174  return nodes[index].GetId();
175  }
176 
177  Id GetFrontId() const
178  {
179  return nodes.front().GetId();
180  }
181 
182  Id GetBackId() const
183  {
184  return nodes.back().GetId();
185  }
186 
187  bool GetNodeIndexByNodeId(Id id,
188  size_t& index) const;
189 
190  const GeoCoord& GetCoord(size_t index) const
191  {
192  return nodes[index].GetCoord();
193  }
194 
195  bool GetCenter(GeoCoord& center) const;
196 
197  void GetBoundingBox(GeoBox& boundingBox) const;
198  GeoBox GetBoundingBox() const;
199 
200  void SetType(const TypeInfoRef& type)
201  {
202  featureValueBuffer.SetType(type);
203  }
204 
205  void SetFeatures(const FeatureValueBuffer& buffer)
206  {
207  featureValueBuffer.Set(buffer);
208  }
209 
210  void CopyMissingValues(const FeatureValueBuffer& buffer)
211  {
212  featureValueBuffer.CopyMissingValues(buffer);
213  }
214 
216  {
217  ring=masterRingId;
218  }
219 
221  {
222  ring=outerRingId;
223  }
224 
225  void SetRing(uint8_t ring)
226  {
227  this->ring=ring;
228  }
229 
230  friend class Area;
231  };
232 
233  using RingVisitor = std::function<bool(size_t i, const Ring&, const TypeInfoRef&)>;
234 
235  private:
236  FileOffset fileOffset=0;
237  FileOffset nextFileOffset=0;
238 
239  public:
240  std::vector<Ring> rings;
241 
242  public:
243  Area() = default;
244 
246  {
247  return fileOffset;
248  }
249 
251  {
252  return nextFileOffset;
253  }
254 
255  ObjectFileRef GetObjectFileRef() const
256  {
257  return {fileOffset,refArea};
258  }
259 
261  {
262  return rings.front().GetType();
263  }
264 
265  TypeInfoRef GetRingType(const Ring &ring) const
266  {
267  if (ring.IsTopOuter() ||
268  (ring.IsOuter() && ring.GetType()->GetIgnore())) {
269  return GetType();
270  }
271 
272  return ring.GetType();
273 
274  }
275 
276  const FeatureValueBuffer& GetFeatureValueBuffer() const
277  {
278  return rings.front().GetFeatureValueBuffer();
279  }
280 
281  bool IsSimple() const
282  {
283  return rings.size()==1;
284  }
285 
286  bool GetCenter(GeoCoord& center) const;
287 
288  GeoBox GetBoundingBox() const;
289 
299  bool Intersects(const GeoBox& boundingBox) const
300  {
301  return GetBoundingBox().Intersects(boundingBox);
302  }
303 
307  void Read(const TypeConfig& typeConfig,
308  FileScanner& scanner);
309 
313  void ReadImport(const TypeConfig& typeConfig,
314  FileScanner& scanner);
315 
319  void ReadOptimized(const TypeConfig& typeConfig,
320  FileScanner& scanner);
321 
326  void Write(const TypeConfig& typeConfig,
327  FileWriter& writer) const;
328 
334  void WriteImport(const TypeConfig& typeConfig,
335  FileWriter& writer) const;
336 
341  void WriteOptimized(const TypeConfig& typeConfig,
342  FileWriter& writer) const;
343 
349  void VisitRings(const RingVisitor& visitor) const;
350 
355  void VisitClippingRings(size_t index, const RingVisitor& visitor) const;
356  };
357 
358  using AreaRef = std::shared_ptr<Area>;
359 }
360 
361 #endif
bool IsOuter() const
Definition: Area.h:157
FileOffset GetFileOffset() const
Definition: Area.h:245
bool Intersects(const GeoBox &boundingBox) const
Definition: Area.h:299
GeoBox bbox
Precomputed (cache) bounding box.
Definition: Area.h:108
void SetType(const TypeInfoRef &type)
Definition: Area.h:200
uint64_t Id
Definition: OSMScoutTypes.h:41
void UnsetFeature(size_t idx)
Definition: Area.h:135
const FeatureValueBuffer & GetFeatureValueBuffer() const
Definition: Area.h:276
void MarkAsMasterRing()
Definition: Area.h:215
const FeatureValueBuffer & GetFeatureValueBuffer() const
Definition: Area.h:140
uint8_t GetRing() const
Definition: Area.h:162
Id GetSerial(size_t index) const
Definition: Area.h:167
bool HasFeature(size_t idx) const
Definition: Area.h:123
ObjectFileRef GetObjectFileRef() const
Definition: Area.h:255
void MarkAsOuterRing()
Definition: Area.h:220
const FeatureInstance & GetFeature(size_t idx) const
Definition: Area.h:130
static const uint8_t outerRingId
Definition: Area.h:90
TypeInfoRef GetType() const
Definition: Area.h:113
TypeInfoRef GetType() const
Definition: Area.h:260
Definition: ObjectRef.h:135
void GetBoundingBox(const std::vector< N > &nodes, double &minLon, double &maxLon, double &minLat, double &maxLat)
Definition: Geometry.h:107
FileOffset GetNextFileOffset() const
Definition: Area.h:250
Id GetFrontId() const
Definition: Area.h:177
const GeoCoord & GetCoord(size_t index) const
Definition: Area.h:190
bool IsMaster() const
Definition: Area.h:145
Definition: Area.h:38
TypeInfoRef GetRingType(const Ring &ring) const
Definition: Area.h:265
size_t GetFeatureCount() const
Definition: Area.h:118
static const uint8_t masterRingId
Definition: Area.h:89
std::shared_ptr< Area > AreaRef
Definition: Area.h:358
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
Definition: LaneAgent.h:60
Id GetId(size_t index) const
Definition: Area.h:172
void CopyMissingValues(const FeatureValueBuffer &buffer)
Definition: Area.h:210
Definition: Area.h:93
bool IsSimple() const
Definition: Area.h:281
std::shared_ptr< TypeInfo > TypeInfoRef
Definition: TypeConfig.h:58
std::vector< Point > nodes
The array of coordinates.
Definition: Area.h:106
uint64_t FileOffset
Definition: OSMScoutTypes.h:47
std::vector< SegmentGeoBox > segments
Precomputed (cache) segment bounding boxes for optimisation.
Definition: Area.h:107
Id GetBackId() const
Definition: Area.h:182
void SetRing(uint8_t ring)
Definition: Area.h:225
void SetFeatures(const FeatureValueBuffer &buffer)
Definition: Area.h:205
std::function< bool(size_t i, const Ring &, const TypeInfoRef &)> RingVisitor
Definition: Area.h:233
bool IsTopOuter() const
Definition: Area.h:151
std::vector< Ring > rings
Definition: Area.h:240