libosmscout  1.1.1
SimpleRoutingService.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_SIMPLEROUTINGSERVICE_H
2 #define OSMSCOUT_SIMPLEROUTINGSERVICE_H
3 
4 /*
5  This source is part of the libosmscout library
6  Copyright (C) 2012 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 <atomic>
24 #include <functional>
25 #include <list>
26 #include <memory>
27 #include <set>
28 #include <unordered_map>
29 #include <unordered_set>
30 
31 #include <osmscout/CoreFeatures.h>
32 
33 #include <osmscout/Point.h>
34 
35 #include <osmscout/TypeConfig.h>
36 
38 
39 // Datafiles
40 #include <osmscout/DataFile.h>
41 #include <osmscout/Database.h>
43 
44 // Routing
45 #include <osmscout/Intersection.h>
52 
53 #include <osmscout/util/Breaker.h>
54 #include <osmscout/util/Cache.h>
55 
57 
58 namespace osmscout {
59 
60  class SimpleRoutingService;
61 
63  {
64  private:
65  ObjectFileRef object;
66  Distance distance;
67  WayRef way;
68  AreaRef area;
69  std::string name;
70 
71  public:
73 
74  ObjectFileRef GetObject() const
75  {
76  return object;
77  }
78 
79  Distance GetDistance() const
80  {
81  return distance;
82  }
83 
84  WayRef GetWay() const
85  {
86  return way;
87  }
88 
89  AreaRef GetArea() const
90  {
91  return area;
92  }
93 
94  std::string GetName() const
95  {
96  return name;
97  }
98  };
99 
113  {
114 
115  private:
116  DatabaseRef database;
117  std::string filenamebase;
118  AccessFeatureValueReader accessReader;
119  bool isOpen;
120 
121  std::string path;
122 
123  RoutingDatabase routingDatabase;
124 
125  private:
126  bool HasNodeWithId(const std::vector<Point>& nodes) const;
127 
128  protected:
129  Vehicle GetVehicle(const RoutingProfile& profile) override;
130 
131  bool CanUse(const RoutingProfile& profile,
132  DatabaseId database,
133  const RouteNode& routeNode,
134  size_t pathIndex) override;
135 
136  bool CanUseForward(const RoutingProfile& profile,
137  const DatabaseId& database,
138  const WayRef& way) override;
139 
140  bool CanUseBackward(const RoutingProfile& profile,
141  const DatabaseId& database,
142  const WayRef& way) override;
143 
144  double GetCosts(const RoutingProfile& profile,
145  DatabaseId database,
146  const RouteNode& routeNode,
147  size_t inPathIndex,
148  size_t outPathIndex) override;
149 
150  double GetCosts(const RoutingProfile& profile,
151  DatabaseId database,
152  const WayRef &way,
153  const Distance &wayLength) override;
154 
155  double GetEstimateCosts(const RoutingProfile& profile,
156  DatabaseId database,
157  const Distance &targetDistance) override;
158 
159  double GetCostLimit(const RoutingProfile& profile,
160  DatabaseId database,
161  const Distance &targetDistance) override;
162 
163  std::string GetCostString(const RoutingProfile& profile,
164  DatabaseId database,
165  double cost) const override;
166 
167  bool GetRouteNodes(const std::set<DBId> &routeNodeIds,
168  std::unordered_map<DBId,RouteNodeRef> &routeNodeMap) override;
169 
170  bool GetRouteNode(const DBId &id,
171  RouteNodeRef &node) override;
172 
173  bool GetWayByOffset(const DBFileOffset &offset,
174  WayRef &way) override;
175 
176  bool GetWaysByOffset(const std::set<DBFileOffset> &wayOffsets,
177  std::unordered_map<DBFileOffset,WayRef> &wayMap) override;
178 
179  bool GetAreaByOffset(const DBFileOffset &offset,
180  AreaRef &area) override;
181 
182  bool GetAreasByOffset(const std::set<DBFileOffset> &areaOffsets,
183  std::unordered_map<DBFileOffset,AreaRef> &areaMap) override;
184 
185  bool ResolveRouteDataJunctions(RouteData& route) override;
186 
187  std::vector<DBId> GetNodeTwins(const RoutingProfile& state,
188  DatabaseId database,
189  Id id) override;
190 
191  public:
192  SimpleRoutingService(const DatabaseRef& database,
193  const RouterParameter& parameter,
194  const std::string& filenamebase);
195  ~SimpleRoutingService() override;
196 
197  bool Open();
198  bool IsOpen() const;
199  void Close();
200 
201  TypeConfigRef GetTypeConfig() const;
202 
203  RoutingResult CalculateRouteViaCoords(RoutingProfile& profile,
204  const std::vector<GeoCoord>& via,
205  const Distance &radius,
206  const RoutingParameter& parameter);
207 
208  RoutePositionResult GetClosestRoutableNode(const GeoCoord& coord,
209  const RoutingProfile& profile,
210  const Distance &radius) const;
211 
212  ClosestRoutableObjectResult GetClosestRoutableObject(const GeoCoord& location,
213  Vehicle vehicle,
214  const Distance &maxRadius);
215 
216  std::map<DatabaseId, std::string> GetDatabaseMapping() const override;
217 
218  void DumpStatistics();
219  };
220 
223  using SimpleRoutingServiceRef = std::shared_ptr<SimpleRoutingService>;
224 
229 }
230 
231 #endif
friend SimpleRoutingService
Definition: SimpleRoutingService.h:72
AreaRef GetArea() const
Definition: SimpleRoutingService.h:89
Definition: SimpleRoutingService.h:62
uint64_t Id
Definition: OSMScoutTypes.h:41
std::string GetName() const
Definition: SimpleRoutingService.h:94
Prints details for debugging, if debug flag (performance, data) is set in renderer parameter...
Definition: MapPainter.h:58
Vehicle
Definition: OSMScoutTypes.h:55
Distance GetDistance() const
Definition: SimpleRoutingService.h:79
std::shared_ptr< Way > WayRef
Definition: Way.h:202
ObjectFileRef GetObject() const
Definition: SimpleRoutingService.h:74
std::shared_ptr< Database > DatabaseRef
Reference counted reference to an Database instance.
Definition: Database.h:555
Definition: RouteData.h:35
Definition: Area.h:38
std::shared_ptr< SimpleRoutingService > SimpleRoutingServiceRef
Definition: SimpleRoutingService.h:223
Definition: RoutingProfile.h:117
std::shared_ptr< Area > AreaRef
Definition: Area.h:358
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
Definition: AbstractRoutingService.h:175
std::shared_ptr< RouteNode > RouteNodeRef
Definition: RouteNode.h:160
WayRef GetWay() const
Definition: SimpleRoutingService.h:84
Definition: SimpleRoutingService.h:112
Definition: DBFileOffset.h:38
Definition: DBFileOffset.h:92
std::shared_ptr< TypeConfig > TypeConfigRef
Definition: TypeConfig.h:1227
Definition: RouteNode.h:61
uint32_t DatabaseId
Definition: DBFileOffset.h:30