libosmscout 1.1.1
Loading...
Searching...
No Matches
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
28
30#include <osmscout/log/Logger.h>
31
34
35namespace osmscout {
36
47 {
48 bool draw;
49 double x;
50 double y;
51 };
52
58 class OSMSCOUT_API TransBuffer CLASS_FINAL
59 {
60 private:
61 size_t pointsSize=0;
62 size_t length=0;
63 size_t start=0;
64 size_t end=0;
65
66 public:
67 TransPoint* points=nullptr;
68
69 private:
70 void Reserve(size_t size);
71
72 public:
73 TransBuffer() = default;
75
80 bool IsEmpty() const
81 {
82 return length==0;
83 }
84
89 size_t GetLength() const
90 {
91 return length;
92 }
93
98 size_t GetStart() const
99 {
100 return start;
101 }
102
107 size_t GetEnd() const
108 {
109 return end;
110 }
111
115 void Reset();
116
121 void CalcSize();
122
133 template<typename C>
134 void TransformGeoToPixel(const Projection& projection,
135 const C& nodes)
136 {
137 Projection::BatchTransformer batchTransformer(projection);
138
139 if (!nodes.empty()) {
140 Reserve(nodes.size());
141
142 start=0;
143 length=nodes.size();
144 end=length-1;
145
146 for (size_t i=start; i<=end; i++) {
147 batchTransformer.GeoToPixel(nodes[i],
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 {
188 };
189
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
314 // Forward declaration for CoordBuffer
315 class CoordBufferRange;
316
333 class OSMSCOUT_API CoordBuffer CLASS_FINAL
334 {
335 private:
336 size_t bufferSize=131072;
337 size_t usedPoints=0;
338
339 public:
341
342 public:
343 Vertex2D *buffer{new Vertex2D[bufferSize]()};
344
345 public:
346 CoordBuffer() = default;
348
349 CoordBuffer(const CoordBuffer& other) = delete;
350 CoordBuffer& operator=(const CoordBuffer& other) = delete;
351
352 void Reset();
353
361 size_t PushCoord(const Vertex2D& coord);
362
375 double offset);
376 };
377
383 class OSMSCOUT_API CoordBufferRange CLASS_FINAL
384 {
385 private:
386 CoordBuffer* coordBuffer=&CoordBuffer::emptyCoordBuffer;
387 size_t start=std::numeric_limits<size_t>::max();
388 size_t end=std::numeric_limits<size_t>::max();
389 mutable double length=-1;
390
391 public:
392 CoordBufferRange() = default;
393 CoordBufferRange(const CoordBufferRange& other) = default;
394
395 CoordBufferRange(CoordBuffer& coordBuffer, size_t start, size_t end)
396 : coordBuffer(&coordBuffer),
397 start(start),
398 end(end)
399 {
400 }
401
403 {
404 if (this!=&other) {
405 this->coordBuffer=other.coordBuffer;
406 this->start=other.start;
407 this->end=other.end;
408 }
409
410 return *this;
411 }
412
418 {
419 return coordBuffer->buffer[start];
420 }
421
427 {
428 return coordBuffer->buffer[end];
429 }
430
435 size_t GetStart() const
436 {
437 return start;
438 }
439
445 Vertex2D Get(size_t index) const
446 {
447 return coordBuffer->buffer[index];
448 }
449
454 size_t GetEnd() const
455 {
456 return end;
457 }
458
463 size_t GetSize() const
464 {
465 return end-start+1;
466 }
467
472 double GetLength() const
473 {
474 if (length<0.0) {
475 Vertex2D lastCoord=GetFirst();
476
477 length=0.0;
478 for (size_t j = start+1; j <= end; j++) {
479 Vertex2D currentCoord=Get(j);
480 length += sqrt(pow(currentCoord.GetX() - lastCoord.GetX(), 2) +
481 pow(currentCoord.GetY() - lastCoord.GetY(), 2));
482
483 lastCoord=currentCoord;
484 }
485 }
486
487 return length;
488 }
489
490 bool IsValid() const {
491 return start!=std::numeric_limits<size_t>::max();
492 }
493 };
494
495 extern OSMSCOUT_API CoordBufferRange CopyPolygonToCoordBuffer(const TransBuffer& transBuffer,
496 CoordBuffer& coordBuffer);
497
517 template<typename C>
518 CoordBufferRange TransformArea(const C& nodes,
519 TransBuffer& transBuffer,
520 CoordBuffer& coordBuffer,
521 const Projection& projection,
522 TransPolygon::OptimizeMethod optimize,
523 double optimizeErrorTolerance)
524 {
525 TransformArea(nodes,
526 transBuffer,
527 projection,
528 optimize,
529 optimizeErrorTolerance);
530
531 assert(!transBuffer.IsEmpty());
532
533 return CopyPolygonToCoordBuffer(transBuffer,
534 coordBuffer);
535 }
536
556 template<typename C>
557 CoordBufferRange TransformWay(const C& nodes,
558 TransBuffer& transBuffer,
559 CoordBuffer& coordBuffer,
560 const Projection& projection,
561 TransPolygon::OptimizeMethod optimize,
562 double optimizeErrorTolerance)
563 {
564 TransformWay(nodes,
565 transBuffer,
566 projection,
567 optimize,
568 optimizeErrorTolerance);
569
570 assert(!transBuffer.IsEmpty());
571
572 return CopyPolygonToCoordBuffer(transBuffer,
573 coordBuffer);
574 }
575
595 extern OSMSCOUT_API CoordBufferRange TransformBoundingBox(const GeoBox& boundingBox,
596 TransBuffer& buffer,
597 CoordBuffer& coordBuffer,
598 const Projection& projection,
599 TransPolygon::OptimizeMethod optimize,
600 double optimizeErrorTolerance);
601}
602
603#endif
#define OSMSCOUT_API
Definition CoreImportExport.h:45
Definition Area.h:88
CoordBufferRange()=default
const GeoCoord coord
Definition RouteStateAgent.h:49
std::vector< Point > nodes
List of nodes.
Definition Way.h:57
CoordBuffer(const CoordBuffer &other)=delete
bool Get(Id id, RouteNodeRef &node) const
static CoordBuffer emptyCoordBuffer
Definition Transformation.h:340
CoordBufferRange(CoordBuffer &coordBuffer, size_t start, size_t end)
Definition Transformation.h:395
OptimizeMethod
Definition Transformation.h:184
@ none
Definition Transformation.h:185
@ quality
Definition Transformation.h:187
@ fast
Definition Transformation.h:186
size_t PushCoord(const Vertex2D &coord)
size_t GetSize() const
Definition Transformation.h:463
size_t GetEnd() const
Definition Transformation.h:107
size_t GetLength() const
Definition Transformation.h:89
bool IsValid() const
Definition Transformation.h:490
Vertex2D Get(size_t index) const
Definition Transformation.h:445
Vertex2D GetLast() const
Definition Transformation.h:426
Vertex2D GetFirst() const
Definition Transformation.h:417
CoordBufferRange GenerateParallelWay(const CoordBufferRange &org, double offset)
void TransformGeoToPixel(const Projection &projection, const C &nodes)
Definition Transformation.h:134
CoordBufferRange(const CoordBufferRange &other)=default
double GetLength() const
Definition Transformation.h:472
uint32_t x
Definition Pixel.h:48
CoordBuffer & operator=(const CoordBuffer &other)=delete
uint32_t y
Definition Pixel.h:49
bool IsEmpty() const
Definition Transformation.h:80
CoordBufferRange & operator=(const CoordBufferRange &other)
Definition Transformation.h:402
Vertex2D * buffer
Definition Transformation.h:343
size_t GetStart() const
Definition Transformation.h:98
bool GetBoundingBox(double &xmin, double &ymin, double &xmax, double &ymax) const
OutputConstraint
Definition Transformation.h:191
@ simple
Definition Transformation.h:193
@ noConstraint
Definition Transformation.h:192
Definition Projection.h:46
friend class BatchTransformer
Definition Projection.h:341
Definition Area.h:39
OSMSCOUT_API void TransformBoundingBox(const GeoBox &boundingBox, TransBuffer &buffer, const Projection &projection, TransPolygon::OptimizeMethod optimize, double optimizeErrorTolerance, TransPolygon::OutputConstraint constraint=TransPolygon::noConstraint)
OSMSCOUT_API void OptimizeArea(TransBuffer &buffer, TransPolygon::OptimizeMethod optimize, double optimizeErrorTolerance, TransPolygon::OutputConstraint constraint)
void TransformWay(const C &nodes, TransBuffer &buffer, const Projection &projection, TransPolygon::OptimizeMethod optimize, double optimizeErrorTolerance, TransPolygon::OutputConstraint constraint=TransPolygon::noConstraint)
Definition Transformation.h:267
OSMSCOUT_API void OptimizeWay(TransBuffer &buffer, TransPolygon::OptimizeMethod optimize, double optimizeErrorTolerance, TransPolygon::OutputConstraint constraint)
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 CoordBufferRange CopyPolygonToCoordBuffer(const TransBuffer &transBuffer, CoordBuffer &coordBuffer)
Definition Transformation.h:47
bool draw
Definition Transformation.h:48
double x
Definition Transformation.h:49
double y
Definition Transformation.h:50