libosmscout  1.1.1
Transformation.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_UTIL_TRANSFORMATION_H
2 #define OSMSCOUT_UTIL_TRANSFORMATION_H
3 
4 /*
5  This source is part of the libosmscout library
6  Copyright (C) 2011 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 <vector>
24 
26 
27 #include <osmscout/util/Geometry.h>
28 #include <osmscout/util/Logger.h>
30 
31 #include <osmscout/system/Assert.h>
32 #include <osmscout/system/Math.h>
33 
34 namespace osmscout {
35 
46  {
47  bool draw;
48  double x;
49  double y;
50  };
51 
57  class OSMSCOUT_API TransBuffer CLASS_FINAL
58  {
59  private:
60  size_t pointsSize=0;
61  size_t length=0;
62  size_t start=0;
63  size_t end=0;
64 
65  public:
66  TransPoint* points=nullptr;
67 
68  private:
69  void Reserve(size_t size);
70 
71  public:
72  TransBuffer() = default;
73  ~TransBuffer();
74 
79  bool IsEmpty() const
80  {
81  return length==0;
82  }
83 
88  size_t GetLength() const
89  {
90  return length;
91  }
92 
97  size_t GetStart() const
98  {
99  return start;
100  }
101 
106  size_t GetEnd() const
107  {
108  return end;
109  }
110 
114  void Reset();
115 
120  void CalcSize();
121 
132  template<typename C>
133  void TransformGeoToPixel(const Projection& projection,
134  const C& nodes)
135  {
136  Projection::BatchTransformer batchTransformer(projection);
137 
138  if (!nodes.empty()) {
139  Reserve(nodes.size());
140 
141  start=0;
142  length=nodes.size();
143  end=length-1;
144 
145  for (size_t i=start; i<=end; i++) {
146  batchTransformer.GeoToPixel(nodes[i].GetLon(),
147  nodes[i].GetLat(),
148  points[i].x,
149  points[i].y);
150  points[i].draw=true;
151  }
152  }
153  }
154 
164  bool GetBoundingBox(double& xmin, double& ymin,
165  double& xmax, double& ymax) const;
166  };
167 
180  class OSMSCOUT_API TransPolygon CLASS_FINAL
181  {
182  public:
184  {
185  none =0,
186  fast =1,
187  quality=2
188  };
189 
191  {
192  noConstraint=0,
193  simple =1
194  };
195  };
196 
200  extern OSMSCOUT_API void OptimizeArea(TransBuffer& buffer,
201  TransPolygon::OptimizeMethod optimize,
202  double optimizeErrorTolerance,
203  TransPolygon::OutputConstraint constraint);
204 
208  extern OSMSCOUT_API void OptimizeWay(TransBuffer& buffer,
209  TransPolygon::OptimizeMethod optimize,
210  double optimizeErrorTolerance,
211  TransPolygon::OutputConstraint constraint);
212 
227  template<typename C>
228  void TransformArea(const C& nodes,
229  TransBuffer& buffer,
230  const Projection& projection,
231  TransPolygon::OptimizeMethod optimize,
232  double optimizeErrorTolerance,
233  TransPolygon::OutputConstraint constraint=TransPolygon::noConstraint)
234  {
235  buffer.Reset();
236 
237  if (nodes.size()<2) {
238  return;
239  }
240 
241  buffer.TransformGeoToPixel(projection,
242  nodes);
243 
244  if (optimize!=TransPolygon::none) {
245  OptimizeArea(buffer,
246  optimize,
247  optimizeErrorTolerance,
248  constraint);
249  }
250  }
251 
266  template<typename C>
267  void TransformWay(const C& nodes,
268  TransBuffer& buffer,
269  const Projection& projection,
270  TransPolygon::OptimizeMethod optimize,
271  double optimizeErrorTolerance,
272  TransPolygon::OutputConstraint constraint=TransPolygon::noConstraint)
273  {
274  buffer.Reset();
275 
276  if (nodes.empty()) {
277  return;
278  }
279 
280  buffer.TransformGeoToPixel(projection,
281  nodes);
282 
283  if (optimize!=TransPolygon::none) {
284  OptimizeWay(buffer,
285  optimize,
286  optimizeErrorTolerance,
287  constraint);
288  }
289  }
290 
291 
307  extern OSMSCOUT_API void TransformBoundingBox(const GeoBox& boundingBox,
308  TransBuffer& buffer,
309  const Projection& projection,
310  TransPolygon::OptimizeMethod optimize,
311  double optimizeErrorTolerance,
312  TransPolygon::OutputConstraint constraint=TransPolygon::noConstraint);
313 
319  class OSMSCOUT_API CoordBufferRange CLASS_FINAL
320  {
321  private:
322  size_t start=std::numeric_limits<size_t>::max();
323  size_t end=std::numeric_limits<size_t>::max();
324 
325  public:
326  CoordBufferRange() = default;
327  CoordBufferRange(const CoordBufferRange& other) = default;
328 
329  CoordBufferRange(size_t start, size_t end)
330  : start(start),
331  end(end)
332  {
333  }
334 
335  size_t GetStart() const
336  {
337  return start;
338  }
339 
340  size_t GetEnd() const
341  {
342  return end;
343  }
344  };
345 
362  class OSMSCOUT_API CoordBuffer CLASS_FINAL
363  {
364  private:
365  size_t bufferSize;
366  size_t usedPoints;
367 
368  public:
369  Vertex2D *buffer;
370 
371  public:
372  CoordBuffer();
373  CoordBuffer(const CoordBuffer& other) = delete;
374  ~CoordBuffer();
375 
376  void Reset();
377 
386  size_t PushCoord(double x, double y);
387 
399  CoordBufferRange GenerateParallelWay(const CoordBufferRange& org,
400  double offset);
401  };
402 
403  extern OSMSCOUT_API CoordBufferRange CopyPolygonToCoordBuffer(const TransBuffer& transBuffer,
404  CoordBuffer& coordBuffer);
405 
425  template<typename C>
426  CoordBufferRange TransformArea(const C& nodes,
427  TransBuffer& transBuffer,
428  CoordBuffer& coordBuffer,
429  const Projection& projection,
430  TransPolygon::OptimizeMethod optimize,
431  double optimizeErrorTolerance)
432  {
433  TransformArea(nodes,
434  transBuffer,
435  projection,
436  optimize,
437  optimizeErrorTolerance);
438 
439  assert(!transBuffer.IsEmpty());
440 
441  return CopyPolygonToCoordBuffer(transBuffer,
442  coordBuffer);
443  }
444 
464  template<typename C>
465  CoordBufferRange TransformWay(const C& nodes,
466  TransBuffer& transBuffer,
467  CoordBuffer& coordBuffer,
468  const Projection& projection,
469  TransPolygon::OptimizeMethod optimize,
470  double optimizeErrorTolerance)
471  {
472  TransformWay(nodes,
473  transBuffer,
474  projection,
475  optimize,
476  optimizeErrorTolerance);
477 
478  assert(!transBuffer.IsEmpty());
479 
480  return CopyPolygonToCoordBuffer(transBuffer,
481  coordBuffer);
482  }
483 
503  extern OSMSCOUT_API CoordBufferRange TransformBoundingBox(const GeoBox& boundingBox,
504  TransBuffer& buffer,
505  CoordBuffer& coordBuffer,
506  const Projection& projection,
507  TransPolygon::OptimizeMethod optimize,
508  double optimizeErrorTolerance);
509 }
510 
511 #endif
size_t GetLength() const
Definition: Transformation.h:88
OSMSCOUT_API void OptimizeArea(TransBuffer &buffer, TransPolygon::OptimizeMethod optimize, double optimizeErrorTolerance, TransPolygon::OutputConstraint constraint)
Definition: Transformation.h:45
OSMSCOUT_API CoordBufferRange CopyPolygonToCoordBuffer(const TransBuffer &transBuffer, CoordBuffer &coordBuffer)
size_t GetEnd() const
Definition: Transformation.h:106
Definition: Area.h:86
Vertex2D * buffer
Definition: Transformation.h:369
void GetBoundingBox(const std::vector< N > &nodes, double &minLon, double &maxLon, double &minLat, double &maxLat)
Definition: Geometry.h:107
void TransformArea(const C &nodes, TransBuffer &buffer, const Projection &projection, TransPolygon::OptimizeMethod optimize, double optimizeErrorTolerance, TransPolygon::OutputConstraint constraint=TransPolygon::noConstraint)
Definition: Transformation.h:228
OSMSCOUT_API void OptimizeWay(TransBuffer &buffer, TransPolygon::OptimizeMethod optimize, double optimizeErrorTolerance, TransPolygon::OutputConstraint constraint)
Definition: Projection.h:43
Definition: Projection.h:68
Definition: Area.h:38
void TransformWay(const C &nodes, TransBuffer &buffer, const Projection &projection, TransPolygon::OptimizeMethod optimize, double optimizeErrorTolerance, TransPolygon::OutputConstraint constraint=TransPolygon::noConstraint)
Definition: Transformation.h:267
double x
Definition: Transformation.h:48
bool draw
Definition: Transformation.h:47
#define CLASS_FINAL
Definition: Compiler.h:26
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
OSMSCOUT_API void TransformBoundingBox(const GeoBox &boundingBox, TransBuffer &buffer, const Projection &projection, TransPolygon::OptimizeMethod optimize, double optimizeErrorTolerance, TransPolygon::OutputConstraint constraint=TransPolygon::noConstraint)
CoordBufferRange(size_t start, size_t end)
Definition: Transformation.h:329
bool IsEmpty() const
Definition: Transformation.h:79
double y
Definition: Transformation.h:49
void TransformGeoToPixel(const Projection &projection, const C &nodes)
Definition: Transformation.h:133
size_t GetStart() const
Definition: Transformation.h:97
OptimizeMethod
Definition: Transformation.h:183
void GeoToPixel(double lon, double lat, double &x, double &y)
Definition: Projection.h:96
OutputConstraint
Definition: Transformation.h:190