libosmscout  1.1.1
MapPainter.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_MAP_MAPPAINTER_H
2 #define OSMSCOUT_MAP_MAPPAINTER_H
3 
4 /*
5  This source is part of the libosmscout-map library
6  Copyright (C) 2009 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 <list>
24 #include <string>
25 
27 
28 #include <osmscout/ObjectRef.h>
29 
30 #include <osmscout/TypeFeatures.h>
31 
32 #include <osmscout/Node.h>
33 #include <osmscout/Area.h>
34 #include <osmscout/Way.h>
35 
36 #include <osmscout/StyleConfig.h>
37 
38 #include <osmscout/GroundTile.h>
39 
40 #include <osmscout/MapData.h>
41 
42 #include <osmscout/util/Breaker.h>
43 #include <osmscout/util/Geometry.h>
46 
48 
49 #include <osmscout/LabelLayouter.h>
50 #include <osmscout/MapParameter.h>
51 
52 namespace osmscout {
53 
54  enum RenderSteps : size_t
55  {
56  FirstStep = 0,
57  Initialize = 0,
60  Prerender = 3,
64  DrawAreas = 7,
65  DrawWays = 8,
75  DrawLabels = 18,
76  Postrender = 19,
77  LastStep = 19
78  };
79 
88  {
89  private:
90  using StepMethod = void (MapPainter::*)(const Projection &, const MapParameter &, const MapData &);
91 
92  public:
93 
98  {
100  size_t objectCount=0;
101  size_t nodeCount=0;
102  size_t wayCount=0;
103  size_t areaCount=0;
104  size_t coordCount=0;
105  size_t labelCount=0;
106  size_t iconCount=0;
107 
108  DataStatistic() = default;
109  };
110 
115  {
116  const FeatureValueBuffer *buffer;
117  int8_t layer;
119  Color color;
120  size_t wayPriority;
121  CoordBufferRange coordRange;
122  double lineWidth;
124  bool endIsClosed;
125 
139  bool operator<(const WayData& other) const
140  {
141  if (layer!=other.layer)
142  {
143  return layer<other.layer;
144  }
145 
146  if (lineStyle->GetZIndex()!=other.lineStyle->GetZIndex()) {
147  return lineStyle->GetZIndex()<other.lineStyle->GetZIndex();
148  }
149 
150  if (lineStyle->GetPriority()!=other.lineStyle->GetPriority()) {
151  return lineStyle->GetPriority()<other.lineStyle->GetPriority();
152  }
153 
154  return wayPriority>other.wayPriority;
155  }
156  };
157 
163  {
165  const FeatureValueBuffer *buffer;
166  CoordBufferRange coordRange;
167  double mainSlotWidth;
168  };
169 
171  {
172  size_t transStart;
173  size_t transEnd;
174  };
175 
180  {
181  ObjectFileRef ref;
183  const FeatureValueBuffer *buffer;
186  GeoBox boundingBox;
187  bool isOuter;
188  CoordBufferRange coordRange;
189  std::list<PolyData> clippings;
190  };
191 
192  using WayPathDataIt=std::list<WayPathData>::iterator;
193 
198  {
200  std::map<PathTextStyleRef,std::set<std::string>> labels;
201  };
202 
203  protected:
208  TransBuffer transBuffer;
209  CoordBuffer coordBuffer;
210 
211 
213 
220  FeatureValueBuffer coastlineSegmentAttributes;
222 
223  private:
224  std::vector<StepMethod> stepMethods;
225  double errorTolerancePixel;
226 
227  std::list<AreaData> areaData;
228  std::list<WayData> wayData;
229  std::list<WayPathData> wayPathData;
230  // std::list<RouteData> routeData;
231  std::list<RouteLabelData> routeLabelData;
232 
233  std::vector<TextStyleRef> textStyles;
234  std::vector<LineStyleRef> lineStyles;
235 
240  double standardFontSize;
241  double areaMinDimension;
243 
244  protected:
246 
260 
261 
266  std::vector<double> emptyDash;
267  std::vector<double> tunnelDash;
273 
274 
275  private:
280  void DumpDataStatistics(const Projection& projection,
281  const MapParameter& parameter,
282  const MapData& data);
284 
289  void PrepareNode(const StyleConfig& styleConfig,
290  const Projection& projection,
291  const MapParameter& parameter,
292  const NodeRef& node);
293 
294  void PrepareNodes(const StyleConfig& styleConfig,
295  const Projection& projection,
296  const MapParameter& parameter,
297  const MapData& data);
298 
299  void TransformPathData(const Projection& projection,
300  const MapParameter& parameter,
301  const Way& way,
302  WayPathData &pathData);
303 
304  void CalculatePaths(const StyleConfig& styleConfig,
305  const Projection& projection,
306  const MapParameter& parameter,
307  const Way& way);
308 
309  void PrepareWays(const StyleConfig& styleConfig,
310  const Projection& projection,
311  const MapParameter& parameter,
312  const MapData& data);
313 
314  void PrepareRoutes(const StyleConfig& styleConfig,
315  const Projection& projection,
316  const MapParameter& parameter,
317  const MapData& data);
318 
319  void PrepareArea(const StyleConfig& styleConfig,
320  const Projection& projection,
321  const MapParameter& parameter,
322  const AreaRef &area);
323 
324  void PrepareAreaLabel(const StyleConfig& styleConfig,
325  const Projection& projection,
326  const MapParameter& parameter,
327  const AreaData& areaData);
328 
329  void PrepareAreas(const StyleConfig& styleConfig,
330  const Projection& projection,
331  const MapParameter& parameter,
332  const MapData& data);
333 
334  void RegisterPointWayLabel(const Projection& projection,
335  const MapParameter& parameter,
336  const PathShieldStyleRef& style,
337  const std::string& text,
338  const std::vector<Point>& nodes);
339 
340  void LayoutPointLabels(const Projection& projection,
341  const MapParameter& parameter,
342  const FeatureValueBuffer& buffer,
343  const IconStyleRef& iconStyle,
344  const std::vector<TextStyleRef>& textStyles,
345  double x, double y,
346  double objectWidth=0,
347  double objectHeight=0);
348 
349  bool DrawWayDecoration(const StyleConfig& styleConfig,
350  const Projection& projection,
351  const MapParameter& parameter,
352  const WayPathData& data);
353 
354  bool CalculateWayShieldLabels(const StyleConfig& styleConfig,
355  const Projection& projection,
356  const MapParameter& parameter,
357  const Way& data);
358 
359  bool DrawWayContourLabel(const StyleConfig& styleConfig,
360  const Projection& projection,
361  const MapParameter& parameter,
362  const WayPathData& data);
363 
364  bool DrawWayContourLabel(const Projection& projection,
365  const MapParameter& parameter,
366  const WayPathData& data,
367  const PathTextStyleRef &pathTextStyle,
368  const std::string &textLabel);
369 
370  bool DrawAreaBorderLabel(const StyleConfig& styleConfig,
371  const Projection& projection,
372  const MapParameter& parameter,
373  const AreaData& areaData);
374 
375  bool DrawAreaBorderSymbol(const StyleConfig& styleConfig,
376  const Projection& projection,
377  const MapParameter& parameter,
378  const AreaData& areaData);
379 
380  void DrawOSMTileGrid(const Projection& projection,
381  const MapParameter& parameter,
382  const Magnification& magnification,
383  const LineStyleRef& osmTileLine);
384 
385  void DrawGroundTiles(const Projection& projection,
386  const MapParameter& parameter,
387  const std::list<GroundTile> &groundTiles);
388 
390 
395  void InitializeRender(const Projection& projection,
396  const MapParameter& parameter,
397  const MapData& data);
398 
399  void DumpStatistics(const Projection& projection,
400  const MapParameter& parameter,
401  const MapData& data);
402 
403  void PreprocessData(const Projection& projection,
404  const MapParameter& parameter,
405  const MapData& data);
406 
407  void Prerender(const Projection& projection,
408  const MapParameter& parameter,
409  const MapData& data);
410 
411  void DrawBaseMapTiles(const Projection& projection,
412  const MapParameter& parameter,
413  const MapData& data);
414 
415  void DrawGroundTiles(const Projection& projection,
416  const MapParameter& parameter,
417  const MapData& data);
418 
419  void DrawOSMTileGrids(const Projection& projection,
420  const MapParameter& parameter,
421  const MapData& data);
422 
423  void DrawAreas(const Projection& projection,
424  const MapParameter& parameter,
425  const MapData& data);
426 
427  void DrawWays(const Projection& projection,
428  const MapParameter& parameter,
429  const MapData& data);
430 
431  void DrawWayDecorations(const Projection& projection,
432  const MapParameter& parameter,
433  const MapData& data);
434 
435  void DrawWayContourLabels(const Projection& projection,
436  const MapParameter& parameter,
437  const MapData& data);
438 
439  void PrepareAreaLabels(const Projection& projection,
440  const MapParameter& parameter,
441  const MapData& data);
442 
443  void DrawAreaBorderLabels(const Projection& projection,
444  const MapParameter& parameter,
445  const MapData& data);
446 
447  void DrawAreaBorderSymbols(const Projection& projection,
448  const MapParameter& parameter,
449  const MapData& data);
450 
451  void PrepareNodeLabels(const Projection& projection,
452  const MapParameter& parameter,
453  const MapData& data);
454 
455  void PrepareRouteLabels(const Projection& projection,
456  const MapParameter& parameter,
457  const MapData& data);
458 
459  void Postrender(const Projection& projection,
460  const MapParameter& parameter,
461  const MapData& data);
462  //@]
463 
464  protected:
469  bool IsVisibleArea(const Projection& projection,
470  const GeoBox& boundingBox,
471  double pixelOffset) const;
472 
473  bool IsVisibleWay(const Projection& projection,
474  const GeoBox& boundingBox,
475  double pixelOffset) const;
476 
477  void Transform(const Projection& projection,
478  const MapParameter& parameter,
479  const GeoCoord& coord,
480  double& x,
481  double& y);
482 
483  double GetProjectedWidth(const Projection& projection,
484  double minPixel,
485  double width) const;
486 
487  double GetProjectedWidth(const Projection& projection,
488  double width) const
489  {
490  return width/projection.GetPixelSize();
491  }
493 
494  const std::list<WayData>& GetWayData() const
495  {
496  return wayData;
497  }
498 
499  const std::list<AreaData>& GetAreaData() const
500  {
501  return areaData;
502  }
503 
509 
514  virtual void AfterPreprocessing(const StyleConfig& styleConfig,
515  const Projection& projection,
516  const MapParameter& parameter,
517  const MapData& data);
518  virtual void BeforeDrawing(const StyleConfig& styleConfig,
519  const Projection& projection,
520  const MapParameter& parameter,
521  const MapData& data);
522  virtual void AfterDrawing(const StyleConfig& styleConfig,
523  const Projection& projection,
524  const MapParameter& parameter,
525  const MapData& data);
527 
535  virtual bool HasIcon(const StyleConfig& styleConfig,
536  const Projection& projection,
537  const MapParameter& parameter,
538  IconStyle& style)= 0;
539 
543  virtual double GetFontHeight(const Projection& projection,
544  const MapParameter& parameter,
545  double fontSize) = 0;
546 
552  virtual void DrawGround(const Projection& projection,
553  const MapParameter& parameter,
554  const FillStyle& style) = 0;
555 
560  virtual void RegisterRegularLabel(const Projection &projection,
561  const MapParameter &parameter,
562  const std::vector<LabelData> &labels,
563  const Vertex2D &position,
564  double objectWidth) = 0;
565 
569  virtual void RegisterContourLabel(const Projection &projection,
570  const MapParameter &parameter,
571  const PathLabelData &label,
572  const LabelPath &labelPath) = 0;
573 
574  virtual void DrawLabels(const Projection& projection,
575  const MapParameter& parameter,
576  const MapData& data) = 0;
577 
578  virtual void DrawContourLines(const Projection& projection,
579  const MapParameter& parameter,
580  const MapData& data);
581 
582  virtual void DrawHillShading(const Projection& projection,
583  const MapParameter& parameter,
584  const MapData& data);
585 
589  virtual void DrawIcon(const IconStyle* style,
590  double centerX, double centerY,
591  double width, double height) = 0;
592 
596  virtual void DrawSymbol(const Projection& projection,
597  const MapParameter& parameter,
598  const Symbol& symbol,
599  double x, double y) = 0;
600 
605  virtual void DrawPath(const Projection& projection,
606  const MapParameter& parameter,
607  const Color& color,
608  double width,
609  const std::vector<double>& dash,
610  LineStyle::CapStyle startCap,
611  LineStyle::CapStyle endCap,
612  size_t transStart, size_t transEnd) = 0;
613 
618  virtual void DrawContourSymbol(const Projection& projection,
619  const MapParameter& parameter,
620  const Symbol& symbol,
621  double space,
622  size_t transStart, size_t transEnd) = 0;
623 
628  virtual void DrawArea(const Projection& projection,
629  const MapParameter& parameter,
630  const AreaData& area) = 0;
632 
637  virtual double GetProposedLabelWidth(const MapParameter& parameter,
638  double averageCharWidth,
639  double objectWidth,
640  size_t stringLength);
641 
642  virtual void DrawWay(const StyleConfig& styleConfig,
643  const Projection& projection,
644  const MapParameter& parameter,
645  const WayData& data);
646 
648 
649  std::vector<OffsetRel> ParseLaneTurns(const LanesFeatureValue&);
650 
651  public:
652  MapPainter(const StyleConfigRef& styleConfig);
653  virtual ~MapPainter();
654 
655  bool Draw(const Projection& projection,
656  const MapParameter& parameter,
657  const MapData& data,
658  RenderSteps startStep,
659  RenderSteps endStep);
660 
661  bool Draw(const Projection& projection,
662  const MapParameter& parameter,
663  const MapData& data);
664  };
665 
672  template <class PainterType>
674  protected:
675  std::vector<MapDataRef> data;
676  std::vector<PainterType> painters;
677 
678  protected:
679 
688  bool batchPaintInternal(const Projection& projection,
689  const MapParameter& parameter)
690  {
691  bool success=true;
692  for (size_t step=osmscout::RenderSteps::FirstStep;
694  step++){
695 
696  for (size_t i=0;i<data.size(); i++){
697  const MapData &d=*(data[i]);
698  success &= painters[i]->Draw(projection,
699  parameter,
700  d,
701  (RenderSteps)step,
702  (RenderSteps)step);
703  }
704  }
705  return success;
706  }
707 
708  public:
709  explicit MapPainterBatch(size_t expectedCount)
710  {
711  data.reserve(expectedCount);
712  painters.reserve(expectedCount);
713  }
714 
715  virtual ~MapPainterBatch() = default;
716 
717  void addData(const MapDataRef &d, PainterType &painter)
718  {
719  data.push_back(d);
720  painters.push_back(painter);
721  }
722  };
723 
729 }
730 
731 #endif
AddressFeatureValueReader addressReader
Value reader for the &#39;address&#39; feature.
Definition: MapPainter.h:256
double lineWidth
Line width.
Definition: MapPainter.h:122
WayPathDataIt wayData
Definition: MapPainter.h:199
std::vector< MapDataRef > data
Definition: MapPainter.h:675
void addData(const MapDataRef &d, PainterType &painter)
Definition: MapPainter.h:717
Definition: MapPainter.h:74
bool operator<(const WayData &other) const
Definition: MapPainter.h:139
std::shared_ptr< FillStyle > FillStyleRef
Definition: Styles.h:349
Definition: Styles.h:884
Definition: MapPainter.h:65
WidthFeatureValueReader widthReader
Value reader for the &#39;width&#39; feature.
Definition: MapPainter.h:255
double GetProjectedWidth(const Projection &projection, double width) const
Definition: MapPainter.h:487
size_t transEnd
End of coordinates in transformation buffer (inclusive)
Definition: MapPainter.h:173
std::shared_ptr< Node > NodeRef
Definition: Node.h:124
Definition: MapPainter.h:72
double GetPixelSize() const
Definition: Projection.h:251
Index selectors by type and level.
Definition: StyleConfig.h:553
std::list< PolyData > clippings
Clipping polygons to be used during drawing of this area.
Definition: MapPainter.h:189
MapPainterBatch(size_t expectedCount)
Definition: MapPainter.h:709
Implementation specific final step.
Definition: MapPainter.h:76
Definition: MapPainter.h:170
std::shared_ptr< LineStyle > LineStyleRef
Definition: Styles.h:273
Definition: MapPainter.h:71
CoordBuffer coordBuffer
Coordinate buffer.
Definition: MapPainter.h:209
Definition: LabelLayouter.h:87
RefFeatureValueReader refReader
Value reader for the &#39;ref&#39; feature.
Definition: MapPainter.h:253
double contourLabelOffset
Same value as in MapParameter but converted to pixel.
Definition: MapPainter.h:269
RenderSteps
Definition: MapPainter.h:54
Convert geographical coordinates of object points to screen coordinates,.
Definition: MapPainter.h:59
FillStyleRef landFill
Definition: MapPainter.h:218
Definition: MapPainter.h:73
Prints details for debugging, if debug flag (performance, data) is set in renderer parameter...
Definition: MapPainter.h:58
FillStyleRef seaFill
Definition: MapPainter.h:219
ObjectFileRef ref
Definition: MapPainter.h:181
AccessFeatureValueReader accessReader
Value reader for the &#39;lanes&#39; feature.
Definition: MapPainter.h:258
int8_t layer
Layer this way is in.
Definition: MapPainter.h:117
double shieldGridSizeHoriz
Width of a cell for shield label placement.
Definition: MapPainter.h:271
std::shared_ptr< BorderStyle > BorderStyleRef
Definition: Styles.h:458
std::shared_ptr< MapData > MapDataRef
Definition: MapData.h:63
Definition: MapPainter.h:77
Definition: MapPainter.h:673
double mainSlotWidth
Width of main slot, used for relative positioning.
Definition: MapPainter.h:167
NameAltFeatureValueReader nameAltReader
Value reader for the &#39;alternative name&#39; feature.
Definition: MapPainter.h:252
Color color
Line color.
Definition: MapPainter.h:119
FillStyleRef fillStyle
Fill style.
Definition: MapPainter.h:184
NameFeatureValueReader nameReader
Value reader for the &#39;name&#39; feature.
Definition: MapPainter.h:251
Definition: Projection.h:43
Definition: MapPainter.h:75
std::shared_ptr< PathTextStyle > PathTextStyleRef
Definition: Styles.h:877
If special style exists, renders grid corresponding to OSM tiles.
Definition: MapPainter.h:63
Definition: Area.h:38
Definition: MapPainter.h:66
bool endIsClosed
The end of the way is closed, it does not lead to another way or area.
Definition: MapPainter.h:124
Definition: MapPainter.h:97
std::vector< double > emptyDash
Empty dash array.
Definition: MapPainter.h:266
size_t transStart
Start of coordinates in transformation buffer.
Definition: MapPainter.h:172
Definition: Styles.h:1135
Implementation specific preparison.
Definition: MapPainter.h:60
TransBuffer transBuffer
Internal buffer for coordinate transformation from geo coordinates to display coordinates.
Definition: MapPainter.h:208
StyleConfigRef styleConfig
Reference to the style configuration to be used.
Definition: MapPainter.h:245
const FeatureValueBuffer * buffer
Features of the line segment. Not owned pointer.
Definition: MapPainter.h:165
size_t wayPriority
Priority of way (from style sheet)
Definition: MapPainter.h:120
FillStyle areaMarkStyle
Marker fill style for internal debugging.
Definition: MapPainter.h:268
Definition: MapPainter.h:70
std::shared_ptr< Area > AreaRef
Definition: Area.h:358
std::shared_ptr< PathShieldStyle > PathShieldStyleRef
Definition: Styles.h:791
Setup internal state of renderer for executing next steps with current projection and parameters...
Definition: MapPainter.h:57
const FeatureValueBuffer * buffer
Features of the line segment, can be NULL in case of border only areas.
Definition: MapPainter.h:183
Definition: LabelPath.h:42
#define OSMSCOUT_MAP_API
Definition: MapImportExport.h:45
CoordBufferRange coordRange
Range of coordinates in transformation buffer.
Definition: MapPainter.h:188
TypeInfoRef type
Type.
Definition: MapPainter.h:99
std::shared_ptr< StyleConfig > StyleConfigRef
Definition: StyleConfig.h:849
FileOffset ref
Definition: MapPainter.h:164
bool isOuter
flag if this area is outer ring of some relation
Definition: MapPainter.h:187
TypeInfoRef type
Definition: MapPainter.h:182
Definition: MapPainter.h:87
std::vector< PainterType > painters
Definition: MapPainter.h:676
std::vector< double > tunnelDash
Dash array for drawing tunnel border.
Definition: MapPainter.h:267
Definition: MapPainter.h:68
Definition: MapPainter.h:67
Definition: MapPainter.h:114
bool batchPaintInternal(const Projection &projection, const MapParameter &parameter)
Definition: MapPainter.h:688
Definition: Styles.h:280
Definition: MapPainter.h:162
const std::list< WayData > & GetWayData() const
Definition: MapPainter.h:494
LineStyleRef lineStyle
Line style.
Definition: MapPainter.h:118
std::shared_ptr< TypeInfo > TypeInfoRef
Definition: TypeConfig.h:58
GeoBox boundingBox
Bounding box of the area.
Definition: MapPainter.h:186
uint64_t FileOffset
Definition: OSMScoutTypes.h:47
double shieldGridSizeVert
Height of a cell for shield label placement.
Definition: MapPainter.h:272
double contourLabelSpace
Same value as in MapParameter but converted to pixel.
Definition: MapPainter.h:270
std::map< PathTextStyleRef, std::set< std::string > > labels
Definition: MapPainter.h:200
const FeatureValueBuffer * buffer
Features of the line segment.
Definition: MapPainter.h:116
std::list< WayPathData >::iterator WayPathDataIt
Definition: MapPainter.h:192
codepoint(*)(const character *, int context) Transform
functor implements desired transformation of the character It has 2 arguments:
Definition: utf8helper.h:49
CoordBufferRange coordRange
Range of coordinates in transformation buffer.
Definition: MapPainter.h:166
CoordBufferRange coordRange
Range of coordinates in transformation buffer.
Definition: MapPainter.h:121
LanesFeatureValueReader lanesReader
Value reader for the &#39;lanes&#39; feature.
Definition: MapPainter.h:257
const std::list< AreaData > & GetAreaData() const
Definition: MapPainter.h:499
Definition: MapPainter.h:69
bool startIsClosed
The end of the way is closed, it does not lead to another way or area.
Definition: MapPainter.h:123
BorderStyleRef borderStyle
Border style.
Definition: MapPainter.h:185
Definition: MapPainter.h:56
FeatureValueBuffer coastlineSegmentAttributes
Definition: MapPainter.h:220
Definition: MapPainter.h:179
LayerFeatureValueReader layerReader
Value reader for the &#39;layer&#39; feature.
Definition: MapPainter.h:254
virtual ~MapPainterBatch()=default
TextStyleRef debugLabel
Definition: MapPainter.h:212
Draw unknown/sea/land tiles and tiles with "coastlines" from base map.
Definition: MapPainter.h:61
Same as previous, but from main database.
Definition: MapPainter.h:62
Definition: TypeFeatures.h:1859
Definition: MapPainter.h:64
std::shared_ptr< IconStyle > IconStyleRef
Definition: Styles.h:975
std::shared_ptr< TextStyle > TextStyleRef
Definition: Styles.h:622
Definition: MapPainter.h:197
ColorFeatureValueReader colorReader
Value reader for the &#39;color&#39; feature.
Definition: MapPainter.h:259
CapStyle
Definition: Styles.h:69