Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/nodes.h
Parent Directory
|
Revision Log
Revision 707 -
(show annotations)
(download)
(as text)
Sun May 8 16:57:02 2011 UTC (13 years, 10 months ago) by amb
File MIME type: text/x-chdr
File size: 6295 byte(s)
Sun May 8 16:57:02 2011 UTC (13 years, 10 months ago) by amb
File MIME type: text/x-chdr
File size: 6295 byte(s)
The FirstSegment function now takes a cache position argument.
1 | /*************************************** |
2 | A header file for the nodes. |
3 | |
4 | Part of the Routino routing software. |
5 | ******************/ /****************** |
6 | This file Copyright 2008-2011 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 | |
28 | #include "types.h" |
29 | |
30 | #include "files.h" |
31 | #include "profiles.h" |
32 | |
33 | |
34 | /* Data structures */ |
35 | |
36 | |
37 | /*+ A structure containing a single node. +*/ |
38 | struct _Node |
39 | { |
40 | index_t firstseg; /*+ The index of the first segment. +*/ |
41 | |
42 | ll_off_t latoffset; /*+ The node latitude offset within its bin. +*/ |
43 | ll_off_t lonoffset; /*+ The node longitude offset within its bin. +*/ |
44 | |
45 | transports_t allow; /*+ The types of transport that are allowed through the node. +*/ |
46 | uint16_t flags; /*+ Flags containing extra information (e.g. super-node, turn restriction). +*/ |
47 | }; |
48 | |
49 | |
50 | /*+ A structure containing the header from the file. +*/ |
51 | typedef struct _NodesFile |
52 | { |
53 | index_t number; /*+ The number of nodes in total. +*/ |
54 | index_t snumber; /*+ The number of super-nodes. +*/ |
55 | |
56 | index_t latbins; /*+ The number of bins containing latitude. +*/ |
57 | index_t lonbins; /*+ The number of bins containing longitude. +*/ |
58 | |
59 | ll_bin_t latzero; /*+ The bin number of the furthest south bin. +*/ |
60 | ll_bin_t lonzero; /*+ The bin number of the furthest west bin. +*/ |
61 | } |
62 | NodesFile; |
63 | |
64 | |
65 | /*+ A structure containing a set of nodes. +*/ |
66 | struct _Nodes |
67 | { |
68 | NodesFile file; /*+ The header data from the file. +*/ |
69 | |
70 | #if !SLIM |
71 | |
72 | void *data; /*+ The memory mapped data in the file. +*/ |
73 | |
74 | index_t *offsets; /*+ A pointer to the array of offsets in the file. +*/ |
75 | |
76 | Node *nodes; /*+ A pointer to the array of nodes in the file. +*/ |
77 | |
78 | #else |
79 | |
80 | int fd; /*+ The file descriptor for the file. +*/ |
81 | off_t nodesoffset; /*+ The offset of the nodes within the file. +*/ |
82 | |
83 | Node cached[4]; /*+ Four cached nodes read from the file in slim mode. +*/ |
84 | index_t incache[4]; /*+ The indexes of the cached nodes. +*/ |
85 | |
86 | #endif |
87 | }; |
88 | |
89 | |
90 | /* Functions in nodes.c */ |
91 | |
92 | Nodes *LoadNodeList(const char *filename); |
93 | |
94 | index_t FindClosestNode(Nodes *nodes,Segments *segments,Ways *ways,double latitude,double longitude, |
95 | distance_t distance,Profile *profile,distance_t *bestdist); |
96 | |
97 | index_t FindClosestSegment(Nodes *nodes,Segments *segments,Ways *ways,double latitude,double longitude, |
98 | distance_t distance,Profile *profile, distance_t *bestdist, |
99 | index_t *bestnode1,index_t *bestnode2,distance_t *bestdist1,distance_t *bestdist2); |
100 | |
101 | void GetLatLong(Nodes *nodes,index_t index,double *latitude,double *longitude); |
102 | |
103 | |
104 | /* Macros and inline functions */ |
105 | |
106 | /*+ Return true if this is a super-node. +*/ |
107 | #define IsSuperNode(xxx) (((xxx)->flags)&NODE_SUPER) |
108 | |
109 | /*+ Return true if this is a turn restricted node. +*/ |
110 | #define IsTurnRestrictedNode(xxx) (((xxx)->flags)&NODE_TURNRSTRCT) |
111 | |
112 | |
113 | #if !SLIM |
114 | |
115 | /*+ Return a Node pointer given a set of nodes and an index. +*/ |
116 | #define LookupNode(xxx,yyy,ppp) (&(xxx)->nodes[yyy]) |
117 | |
118 | /*+ Return a Segment index given a Node pointer and a set of segments. +*/ |
119 | #define FirstSegment(xxx,yyy,zzz,ppp) LookupSegment((xxx),(yyy)->nodes[zzz].firstseg,1) |
120 | |
121 | /*+ Return the offset of a geographical region given a set of nodes. +*/ |
122 | #define LookupNodeOffset(xxx,yyy) ((xxx)->offsets[yyy]) |
123 | |
124 | #else |
125 | |
126 | static Node *LookupNode(Nodes *nodes,index_t index,int position); |
127 | |
128 | /*+ Return a Segment index given a Node pointer and a set of segments. +*/ |
129 | #define FirstSegment(xxx,yyy,zzz,ppp) LookupSegment((xxx),FirstSegment_internal(yyy,zzz),ppp) |
130 | |
131 | static index_t FirstSegment_internal(Nodes *nodes,index_t index); |
132 | |
133 | static index_t LookupNodeOffset(Nodes *nodes,index_t index); |
134 | |
135 | |
136 | /*++++++++++++++++++++++++++++++++++++++ |
137 | Find the Node information for a particular node. |
138 | |
139 | Node *LookupNode Returns a pointer to the cached node information. |
140 | |
141 | Nodes *nodes The set of nodes to use. |
142 | |
143 | index_t index The index of the node. |
144 | |
145 | int position The position in the cache to store the value. |
146 | ++++++++++++++++++++++++++++++++++++++*/ |
147 | |
148 | static inline Node *LookupNode(Nodes *nodes,index_t index,int position) |
149 | { |
150 | if(nodes->incache[position-1]!=index) |
151 | { |
152 | SeekFile(nodes->fd,nodes->nodesoffset+(off_t)index*sizeof(Node)); |
153 | |
154 | ReadFile(nodes->fd,&nodes->cached[position-1],sizeof(Node)); |
155 | |
156 | nodes->incache[position-1]=index; |
157 | } |
158 | |
159 | return(&nodes->cached[position-1]); |
160 | } |
161 | |
162 | |
163 | /*++++++++++++++++++++++++++++++++++++++ |
164 | Find the index of the first segment of a node (called by FirstSegment() macro). |
165 | |
166 | index_t FirstSegment_internal Returns the index of the first segment. |
167 | |
168 | Nodes *nodes The set of nodes to use. |
169 | |
170 | index_t index The index of the node. |
171 | ++++++++++++++++++++++++++++++++++++++*/ |
172 | |
173 | static inline index_t FirstSegment_internal(Nodes *nodes,index_t index) |
174 | { |
175 | Node *node; |
176 | |
177 | node=LookupNode(nodes,index,4); |
178 | |
179 | return(node->firstseg); |
180 | } |
181 | |
182 | |
183 | /*++++++++++++++++++++++++++++++++++++++ |
184 | Find the offset of nodes in a geographical region. |
185 | |
186 | index_t LookupNodeOffset Returns the index offset. |
187 | |
188 | Nodes *nodes The set of nodes to use. |
189 | |
190 | index_t index The index of the offset. |
191 | ++++++++++++++++++++++++++++++++++++++*/ |
192 | |
193 | static inline index_t LookupNodeOffset(Nodes *nodes,index_t index) |
194 | { |
195 | index_t offset; |
196 | |
197 | SeekFile(nodes->fd,sizeof(NodesFile)+(off_t)index*sizeof(index_t)); |
198 | |
199 | ReadFile(nodes->fd,&offset,sizeof(index_t)); |
200 | |
201 | return(offset); |
202 | } |
203 | |
204 | #endif |
205 | |
206 | |
207 | #endif /* NODES_H */ |
Properties
Name | Value |
---|---|
cvs:description | Header file for nodes. |