Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/segments.h
Parent Directory
|
Revision Log
Revision 1164 -
(hide annotations)
(download)
(as text)
Tue Nov 20 15:24:30 2012 UTC (12 years, 3 months ago) by amb
File MIME type: text/x-chdr
File size: 7430 byte(s)
Tue Nov 20 15:24:30 2012 UTC (12 years, 3 months ago) by amb
File MIME type: text/x-chdr
File size: 7430 byte(s)
Replace the 32-bit combined distance and flags in the segment with 16 bits for each.
1 | amb | 24 | /*************************************** |
2 | amb | 564 | $Header: /home/amb/CVS/routino/src/segments.h,v 1.38 2010-12-21 17:18:41 amb Exp $ |
3 | amb | 24 | |
4 | A header file for the segments. | ||
5 | amb | 151 | |
6 | Part of the Routino routing software. | ||
7 | amb | 24 | ******************/ /****************** |
8 | amb | 964 | This file Copyright 2008-2012 Andrew M. Bishop |
9 | amb | 24 | |
10 | amb | 151 | This program is free software: you can redistribute it and/or modify |
11 | it under the terms of the GNU Affero General Public License as published by | ||
12 | the Free Software Foundation, either version 3 of the License, or | ||
13 | (at your option) any later version. | ||
14 | |||
15 | This program is distributed in the hope that it will be useful, | ||
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | GNU Affero General Public License for more details. | ||
19 | |||
20 | You should have received a copy of the GNU Affero General Public License | ||
21 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
22 | amb | 24 | ***************************************/ |
23 | |||
24 | |||
25 | #ifndef SEGMENTS_H | ||
26 | #define SEGMENTS_H /*+ To stop multiple inclusions. +*/ | ||
27 | |||
28 | #include <stdint.h> | ||
29 | |||
30 | amb | 96 | #include "types.h" |
31 | amb | 459 | |
32 | #include "files.h" | ||
33 | amb | 82 | #include "profiles.h" |
34 | amb | 24 | |
35 | amb | 26 | |
36 | amb | 24 | /* Data structures */ |
37 | |||
38 | |||
39 | amb | 109 | /*+ A structure containing a single segment. +*/ |
40 | struct _Segment | ||
41 | amb | 88 | { |
42 | amb | 109 | index_t node1; /*+ The index of the starting node. +*/ |
43 | index_t node2; /*+ The index of the finishing node. +*/ | ||
44 | amb | 88 | |
45 | amb | 109 | index_t next2; /*+ The index of the next segment sharing node2. +*/ |
46 | amb | 88 | |
47 | amb | 109 | index_t way; /*+ The index of the way associated with the segment. +*/ |
48 | |||
49 | amb | 1164 | segdist_t length; /*+ The length of the segment. +*/ |
50 | segflags_t flags; /*+ The flags for the segment. +*/ | ||
51 | amb | 109 | }; |
52 | |||
53 | |||
54 | amb | 459 | /*+ A structure containing the header from the file. +*/ |
55 | typedef struct _SegmentsFile | ||
56 | amb | 24 | { |
57 | amb | 680 | index_t number; /*+ The number of segments in total. +*/ |
58 | index_t snumber; /*+ The number of super-segments. +*/ | ||
59 | index_t nnumber; /*+ The number of normal segments. +*/ | ||
60 | amb | 459 | } |
61 | SegmentsFile; | ||
62 | amb | 88 | |
63 | |||
64 | amb | 459 | /*+ A structure containing a set of segments (and pointers to mmap file). +*/ |
65 | struct _Segments | ||
66 | { | ||
67 | SegmentsFile file; /*+ The header data from the file. +*/ | ||
68 | |||
69 | #if !SLIM | ||
70 | |||
71 | void *data; /*+ The memory mapped data. +*/ | ||
72 | |||
73 | Segment *segments; /*+ An array of segments. +*/ | ||
74 | |||
75 | #else | ||
76 | |||
77 | int fd; /*+ The file descriptor for the file. +*/ | ||
78 | |||
79 | amb | 680 | Segment cached[3]; /*+ Three cached segments read from the file in slim mode. +*/ |
80 | amb | 459 | index_t incache[3]; /*+ The indexes of the cached segments. +*/ |
81 | |||
82 | #endif | ||
83 | amb | 109 | }; |
84 | amb | 24 | |
85 | |||
86 | amb | 680 | /* Functions in segments.c */ |
87 | amb | 24 | |
88 | amb | 459 | Segments *LoadSegmentList(const char *filename); |
89 | amb | 24 | |
90 | amb | 681 | index_t FindClosestSegmentHeading(Nodes *nodes,Segments *segments,Ways *ways,index_t node1,double heading,Profile *profile); |
91 | amb | 675 | |
92 | amb | 459 | distance_t Distance(double lat1,double lon1,double lat2,double lon2); |
93 | amb | 303 | |
94 | amb | 1078 | duration_t Duration(Segment *segmentp,Way *wayp,Profile *profile); |
95 | amb | 459 | |
96 | amb | 1078 | double TurnAngle(Nodes *nodes,Segment *segment1p,Segment *segment2p,index_t node); |
97 | double BearingAngle(Nodes *nodes,Segment *segmentp,index_t node); | ||
98 | amb | 459 | |
99 | amb | 672 | |
100 | amb | 1078 | static inline Segment *NextSegment(Segments *segments,Segment *segmentp,index_t node); |
101 | amb | 708 | |
102 | |||
103 | amb | 459 | /* Macros and inline functions */ |
104 | |||
105 | amb | 109 | /*+ Return true if this is a normal segment. +*/ |
106 | amb | 1164 | #define IsNormalSegment(xxx) ((xxx)->flags&SEGMENT_NORMAL) |
107 | amb | 24 | |
108 | amb | 109 | /*+ Return true if this is a super-segment. +*/ |
109 | amb | 1164 | #define IsSuperSegment(xxx) ((xxx)->flags&SEGMENT_SUPER) |
110 | amb | 24 | |
111 | amb | 964 | /*+ Return true if the segment is oneway. +*/ |
112 | amb | 1164 | #define IsOneway(xxx) ((xxx)->flags&(ONEWAY_2TO1|ONEWAY_1TO2)) |
113 | amb | 964 | |
114 | amb | 109 | /*+ Return true if the segment is oneway towards the specified node. +*/ |
115 | amb | 1164 | #define IsOnewayTo(xxx,yyy) ((xxx)->node1==(yyy)?((xxx)->flags&ONEWAY_2TO1):((xxx)->flags&ONEWAY_1TO2)) |
116 | amb | 24 | |
117 | amb | 109 | /*+ Return true if the segment is oneway from the specified node. +*/ |
118 | amb | 1164 | #define IsOnewayFrom(xxx,yyy) ((xxx)->node2==(yyy)?((xxx)->flags&ONEWAY_2TO1):((xxx)->flags&ONEWAY_1TO2)) |
119 | amb | 97 | |
120 | amb | 109 | /*+ Return the other node in the segment that is not the specified node. +*/ |
121 | amb | 208 | #define OtherNode(xxx,yyy) ((xxx)->node1==(yyy)?(xxx)->node2:(xxx)->node1) |
122 | amb | 97 | |
123 | amb | 459 | #if !SLIM |
124 | amb | 39 | |
125 | amb | 459 | /*+ Return a segment pointer given a set of segments and an index. +*/ |
126 | amb | 708 | #define LookupSegment(xxx,yyy,ppp) (&(xxx)->segments[yyy]) |
127 | amb | 24 | |
128 | amb | 459 | /*+ Return a segment index given a set of segments and a pointer. +*/ |
129 | amb | 772 | #define IndexSegment(xxx,yyy) (index_t)((yyy)-&(xxx)->segments[0]) |
130 | amb | 88 | |
131 | amb | 708 | |
132 | /*++++++++++++++++++++++++++++++++++++++ | ||
133 | Find the next segment with a particular starting node. | ||
134 | |||
135 | Segment *NextSegment Returns a pointer to the next segment. | ||
136 | |||
137 | Segments *segments The set of segments to use. | ||
138 | |||
139 | amb | 1078 | Segment *segmentp The current segment. |
140 | amb | 708 | |
141 | index_t node The wanted node. | ||
142 | ++++++++++++++++++++++++++++++++++++++*/ | ||
143 | |||
144 | amb | 1078 | static inline Segment *NextSegment(Segments *segments,Segment *segmentp,index_t node) |
145 | amb | 708 | { |
146 | amb | 1078 | if(segmentp->node1==node) |
147 | amb | 708 | { |
148 | amb | 1078 | segmentp++; |
149 | amb | 708 | |
150 | amb | 1078 | if(IndexSegment(segments,segmentp)>=segments->file.number || segmentp->node1!=node) |
151 | amb | 708 | return(NULL); |
152 | else | ||
153 | amb | 1078 | return(segmentp); |
154 | amb | 708 | } |
155 | else | ||
156 | { | ||
157 | amb | 1078 | if(segmentp->next2==NO_SEGMENT) |
158 | amb | 708 | return(NULL); |
159 | else | ||
160 | amb | 1078 | return(LookupSegment(segments,segmentp->next2,1)); |
161 | amb | 708 | } |
162 | } | ||
163 | |||
164 | amb | 459 | #else |
165 | amb | 88 | |
166 | amb | 459 | static Segment *LookupSegment(Segments *segments,index_t index,int position); |
167 | amb | 99 | |
168 | amb | 1078 | static index_t IndexSegment(Segments *segments,Segment *segmentp); |
169 | amb | 63 | |
170 | amb | 32 | |
171 | amb | 459 | /*++++++++++++++++++++++++++++++++++++++ |
172 | Find the Segment information for a particular segment. | ||
173 | |||
174 | Segment *LookupSegment Returns a pointer to the cached segment information. | ||
175 | |||
176 | amb | 680 | Segments *segments The set of segments to use. |
177 | amb | 459 | |
178 | index_t index The index of the segment. | ||
179 | |||
180 | int position The position in the cache to store the value. | ||
181 | ++++++++++++++++++++++++++++++++++++++*/ | ||
182 | |||
183 | static inline Segment *LookupSegment(Segments *segments,index_t index,int position) | ||
184 | { | ||
185 | amb | 564 | if(segments->incache[position-1]!=index) |
186 | { | ||
187 | amb | 887 | SeekReadFile(segments->fd,&segments->cached[position-1],sizeof(Segment),sizeof(SegmentsFile)+(off_t)index*sizeof(Segment)); |
188 | amb | 459 | |
189 | amb | 564 | segments->incache[position-1]=index; |
190 | } | ||
191 | amb | 459 | |
192 | return(&segments->cached[position-1]); | ||
193 | } | ||
194 | |||
195 | |||
196 | /*++++++++++++++++++++++++++++++++++++++ | ||
197 | Find the segment index for a particular segment pointer. | ||
198 | |||
199 | index_t IndexSegment Returns the index of the segment in the list. | ||
200 | |||
201 | amb | 680 | Segments *segments The set of segments to use. |
202 | amb | 459 | |
203 | amb | 1078 | Segment *segmentp The segment whose index is to be found. |
204 | amb | 459 | ++++++++++++++++++++++++++++++++++++++*/ |
205 | |||
206 | amb | 1078 | static inline index_t IndexSegment(Segments *segments,Segment *segmentp) |
207 | amb | 459 | { |
208 | amb | 1078 | int position1=segmentp-&segments->cached[0]; |
209 | amb | 459 | |
210 | amb | 704 | return(segments->incache[position1]); |
211 | amb | 459 | } |
212 | |||
213 | amb | 708 | |
214 | /*++++++++++++++++++++++++++++++++++++++ | ||
215 | Find the next segment with a particular starting node. | ||
216 | |||
217 | Segment *NextSegment Returns a pointer to the next segment. | ||
218 | |||
219 | Segments *segments The set of segments to use. | ||
220 | |||
221 | amb | 1078 | Segment *segmentp The current segment. |
222 | amb | 708 | |
223 | index_t node The wanted node. | ||
224 | ++++++++++++++++++++++++++++++++++++++*/ | ||
225 | |||
226 | amb | 1078 | static inline Segment *NextSegment(Segments *segments,Segment *segmentp,index_t node) |
227 | amb | 708 | { |
228 | amb | 1078 | int position=segmentp-&segments->cached[-1]; |
229 | amb | 708 | |
230 | amb | 1078 | if(segmentp->node1==node) |
231 | amb | 708 | { |
232 | amb | 1078 | index_t index=IndexSegment(segments,segmentp); |
233 | amb | 708 | |
234 | index++; | ||
235 | |||
236 | if(index>=segments->file.number) | ||
237 | return(NULL); | ||
238 | |||
239 | amb | 1078 | segmentp=LookupSegment(segments,index,position); |
240 | amb | 708 | |
241 | amb | 1078 | if(segmentp->node1!=node) |
242 | amb | 708 | return(NULL); |
243 | else | ||
244 | amb | 1078 | return(segmentp); |
245 | amb | 708 | } |
246 | else | ||
247 | { | ||
248 | amb | 1078 | if(segmentp->next2==NO_SEGMENT) |
249 | amb | 708 | return(NULL); |
250 | else | ||
251 | amb | 1078 | return(LookupSegment(segments,segmentp->next2,position)); |
252 | amb | 708 | } |
253 | } | ||
254 | |||
255 | amb | 459 | #endif |
256 | |||
257 | |||
258 | amb | 24 | #endif /* SEGMENTS_H */ |
Properties
Name | Value |
---|---|
cvs:description | Header file for segments. |