Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /trunk/src/nodes.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1312 - (show annotations) (download) (as text)
Sat May 11 11:12:56 2013 UTC (11 years, 10 months ago) by amb
File MIME type: text/x-chdr
File size: 5363 byte(s)
Add functions to destroy the node/segment/way/relation lists and don't call them
from the end of the router by default.

1 /***************************************
2 A header file for the nodes.
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2008-2013 Andrew M. Bishop
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program 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
16 GNU Affero General Public License for more details.
17
18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ***************************************/
21
22
23 #ifndef NODES_H
24 #define NODES_H /*+ To stop multiple inclusions. +*/
25
26 #include <stdint.h>
27 #include <sys/types.h>
28
29 #include "types.h"
30 #include "cache.h"
31
32 #include "files.h"
33 #include "profiles.h"
34
35
36 /* Data structures */
37
38
39 /*+ A structure containing a single node. +*/
40 struct _Node
41 {
42 index_t firstseg; /*+ The index of the first segment. +*/
43
44 ll_off_t latoffset; /*+ The node latitude offset within its bin. +*/
45 ll_off_t lonoffset; /*+ The node longitude offset within its bin. +*/
46
47 transports_t allow; /*+ The types of transport that are allowed through the node. +*/
48 nodeflags_t flags; /*+ Flags containing extra information (e.g. super-node, turn restriction). +*/
49 };
50
51
52 /*+ A structure containing the header from the file. +*/
53 typedef struct _NodesFile
54 {
55 index_t number; /*+ The number of nodes in total. +*/
56 index_t snumber; /*+ The number of super-nodes. +*/
57
58 ll_bin_t latbins; /*+ The number of bins containing latitude. +*/
59 ll_bin_t lonbins; /*+ The number of bins containing longitude. +*/
60
61 ll_bin_t latzero; /*+ The bin number of the furthest south bin. +*/
62 ll_bin_t lonzero; /*+ The bin number of the furthest west bin. +*/
63 }
64 NodesFile;
65
66
67 /*+ A structure containing a set of nodes. +*/
68 struct _Nodes
69 {
70 NodesFile file; /*+ The header data from the file. +*/
71
72 #if !SLIM
73
74 void *data; /*+ The memory mapped data in the file. +*/
75
76 index_t *offsets; /*+ A pointer to the array of offsets in the file. +*/
77
78 Node *nodes; /*+ A pointer to the array of nodes in the file. +*/
79
80 #else
81
82 int fd; /*+ The file descriptor for the file. +*/
83
84 index_t *offsets; /*+ An allocated array with a copy of the file offsets. +*/
85
86 off_t nodesoffset; /*+ The offset of the nodes within the file. +*/
87
88 Node cached[6]; /*+ Some cached nodes read from the file in slim mode. +*/
89
90 NodeCache *cache; /*+ A RAM cache of nodes read from the file. +*/
91
92 #endif
93 };
94
95
96 /* Functions in nodes.c */
97
98 Nodes *LoadNodeList(const char *filename);
99
100 void DestroyNodeList(Nodes *nodes);
101
102 index_t FindClosestNode(Nodes *nodes,Segments *segments,Ways *ways,double latitude,double longitude,
103 distance_t distance,Profile *profile,distance_t *bestdist);
104
105 index_t FindClosestSegment(Nodes *nodes,Segments *segments,Ways *ways,double latitude,double longitude,
106 distance_t distance,Profile *profile, distance_t *bestdist,
107 index_t *bestnode1,index_t *bestnode2,distance_t *bestdist1,distance_t *bestdist2);
108
109 void GetLatLong(Nodes *nodes,index_t index,Node *nodep,double *latitude,double *longitude);
110
111
112 /* Macros and inline functions */
113
114 /*+ Return true if this is a super-node. +*/
115 #define IsSuperNode(xxx) (((xxx)->flags)&NODE_SUPER)
116
117 /*+ Return true if this is a turn restricted node. +*/
118 #define IsTurnRestrictedNode(xxx) (((xxx)->flags)&NODE_TURNRSTRCT)
119
120 /*+ Return a Segment index given a Node pointer and a set of segments. +*/
121 #define FirstSegment(xxx,yyy,ppp) LookupSegment((xxx),(yyy)->firstseg,ppp)
122
123 /*+ Return the offset of a geographical region given a set of nodes. +*/
124 #define LookupNodeOffset(xxx,yyy) ((xxx)->offsets[yyy])
125
126
127 #if !SLIM
128
129 /*+ Return a Node pointer given a set of nodes and an index. +*/
130 #define LookupNode(xxx,yyy,ppp) (&(xxx)->nodes[yyy])
131
132 #else
133
134 /* Prototypes */
135
136 static inline Node *LookupNode(Nodes *nodes,index_t index,int position);
137
138 CACHE_NEWCACHE_PROTO(Node)
139 CACHE_DELETECACHE_PROTO(Node)
140 CACHE_FETCHCACHE_PROTO(Node)
141 CACHE_INVALIDATECACHE_PROTO(Node)
142
143
144 /* Inline functions */
145
146 CACHE_STRUCTURE(Node)
147 CACHE_NEWCACHE(Node)
148 CACHE_DELETECACHE(Node)
149 CACHE_FETCHCACHE(Node)
150 CACHE_INVALIDATECACHE(Node)
151
152
153 /*++++++++++++++++++++++++++++++++++++++
154 Find the Node information for a particular node.
155
156 Node *LookupNode Returns a pointer to the cached node information.
157
158 Nodes *nodes The set of nodes to use.
159
160 index_t index The index of the node.
161
162 int position The position in the cache to store the value.
163 ++++++++++++++++++++++++++++++++++++++*/
164
165 static inline Node *LookupNode(Nodes *nodes,index_t index,int position)
166 {
167 nodes->cached[position-1]=*FetchCachedNode(nodes->cache,index,nodes->fd,nodes->nodesoffset);
168
169 return(&nodes->cached[position-1]);
170 }
171
172 #endif
173
174
175 #endif /* NODES_H */

Properties

Name Value
cvs:description Header file for nodes.