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 89 -
(hide annotations)
(download)
(as text)
Wed Jan 28 18:46:55 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-chdr
File size: 4611 byte(s)
Wed Jan 28 18:46:55 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-chdr
File size: 4611 byte(s)
Intermediate version while transitioning data format for nodes and segments.
1 | amb | 24 | /*************************************** |
2 | amb | 89 | $Header: /home/amb/CVS/routino/src/segments.h,v 1.19 2009-01-28 18:46:55 amb Exp $ |
3 | amb | 24 | |
4 | A header file for the segments. | ||
5 | ******************/ /****************** | ||
6 | Written by Andrew M. Bishop | ||
7 | |||
8 | This file Copyright 2009 Andrew M. Bishop | ||
9 | It may be distributed under the GNU Public License, version 2, or | ||
10 | any higher version. See section COPYING of the GNU Public license | ||
11 | for conditions under which this file may be redistributed. | ||
12 | ***************************************/ | ||
13 | |||
14 | |||
15 | #ifndef SEGMENTS_H | ||
16 | #define SEGMENTS_H /*+ To stop multiple inclusions. +*/ | ||
17 | |||
18 | #include <stdint.h> | ||
19 | |||
20 | amb | 26 | #include "nodes.h" |
21 | #include "ways.h" | ||
22 | amb | 82 | #include "profiles.h" |
23 | amb | 24 | |
24 | amb | 26 | |
25 | amb | 24 | /* Constants */ |
26 | |||
27 | |||
28 | amb | 65 | /*+ The number of bins for segments - expect ~8,000,000 segments and use 4*sqrt(N) bins. +*/ |
29 | #define NBINS_SEGMENTS 8192 | ||
30 | amb | 24 | |
31 | amb | 65 | /*+ The array size increment for segments - expect ~8,000,000 segments. +*/ |
32 | amb | 27 | #define INCREMENT_SEGMENTS 1024*1024 |
33 | amb | 24 | |
34 | amb | 27 | |
35 | amb | 24 | /* Simple Types */ |
36 | |||
37 | /*+ A long distance, measured in metres. +*/ | ||
38 | typedef uint32_t distance_t; | ||
39 | |||
40 | amb | 39 | /*+ A duration, measured in 1/10th seconds. +*/ |
41 | typedef uint32_t duration_t; | ||
42 | |||
43 | |||
44 | amb | 69 | /*+ A flag to mark a distance as only applying for the other direction. +*/ |
45 | #define ONEWAY_OPPOSITE (distance_t)(0x80000000) | ||
46 | amb | 39 | |
47 | amb | 82 | /*+ The real distance ignoring the ONEWAY_OPPOSITE flag. +*/ |
48 | #define DISTANCE(xx) (distance_t)((xx)&(~ONEWAY_OPPOSITE)) | ||
49 | amb | 39 | |
50 | amb | 82 | |
51 | amb | 24 | /*+ Conversion from distance_t to kilometres. +*/ |
52 | #define distance_to_km(xx) ((double)(xx)/1000.0) | ||
53 | |||
54 | /*+ Conversion from metres to distance_t. +*/ | ||
55 | #define km_to_distance(xx) ((distance_t)((double)(xx)*1000.0)) | ||
56 | |||
57 | /*+ Conversion from duration_t to minutes. +*/ | ||
58 | amb | 31 | #define duration_to_minutes(xx) ((double)(xx)/600.0) |
59 | amb | 24 | |
60 | /*+ Conversion from duration_t to hours. +*/ | ||
61 | amb | 31 | #define duration_to_hours(xx) ((double)(xx)/36000.0) |
62 | amb | 24 | |
63 | /*+ Conversion from hours to duration_t. +*/ | ||
64 | amb | 31 | #define hours_to_duration(xx) ((duration_t)((double)(xx)*36000.0)) |
65 | amb | 24 | |
66 | amb | 86 | /*+ Conversion from distance_t and speed_t to duration_t. +*/ |
67 | #define distance_speed_to_duration(xx,yy) ((duration_t)(((double)(xx)/(double)(yy))*(36000.0/1000.0))) | ||
68 | amb | 24 | |
69 | amb | 86 | |
70 | amb | 24 | /* Data structures */ |
71 | |||
72 | |||
73 | /*+ A structure containing a single segment. +*/ | ||
74 | typedef struct _Segment | ||
75 | { | ||
76 | amb | 88 | uint32_t node1; /*+ The index of the starting node. +*/ |
77 | uint32_t node2; /*+ The index of the finishing node. +*/ | ||
78 | uint32_t wayindex; /*+ The index of the way associated with the segment. +*/ | ||
79 | distance_t distance; /*+ The distance between the nodes. +*/ | ||
80 | amb | 24 | } |
81 | Segment; | ||
82 | |||
83 | amb | 88 | /*+ An extended structure used for processing. +*/ |
84 | typedef struct _SegmentEx | ||
85 | { | ||
86 | node_t node1; /*+ The starting node. +*/ | ||
87 | node_t node2; /*+ The finishing node. +*/ | ||
88 | amb | 89 | int super; /*+ A marker for super segments. +*/ |
89 | amb | 88 | |
90 | Segment segment; /*+ The real segment data. +*/ | ||
91 | } | ||
92 | SegmentEx; | ||
93 | |||
94 | amb | 24 | /*+ A structure containing a set of segments (mmap format). +*/ |
95 | typedef struct _Segments | ||
96 | { | ||
97 | amb | 65 | uint32_t number; /*+ How many entries are used in total? +*/ |
98 | amb | 88 | |
99 | Segment *segments; /*+ An array of segments. +*/ | ||
100 | |||
101 | void *data; /*+ The memory mapped data. +*/ | ||
102 | amb | 24 | } |
103 | Segments; | ||
104 | |||
105 | /*+ A structure containing a set of segments (memory format). +*/ | ||
106 | typedef struct _SegmentsMem | ||
107 | { | ||
108 | amb | 88 | uint32_t sorted; /*+ Is the data sorted and therefore searchable? +*/ |
109 | amb | 24 | uint32_t alloced; /*+ How many entries are allocated? +*/ |
110 | uint32_t number; /*+ How many entries are used? +*/ | ||
111 | |||
112 | amb | 88 | SegmentEx *xdata; /*+ The extended segment data. +*/ |
113 | amb | 24 | } |
114 | SegmentsMem; | ||
115 | |||
116 | |||
117 | amb | 26 | /* Functions in segments.c */ |
118 | amb | 24 | |
119 | |||
120 | SegmentsMem *NewSegmentList(void); | ||
121 | |||
122 | Segments *LoadSegmentList(const char *filename); | ||
123 | amb | 89 | void SaveSegmentList(SegmentsMem *segmentsmem,const char *filename); |
124 | amb | 24 | |
125 | amb | 89 | SegmentEx *FindFirstSegment(SegmentsMem* segmentsem,node_t node); |
126 | SegmentEx *FindNextSegment(SegmentsMem* segmentsem,SegmentEx *segmentex); | ||
127 | amb | 24 | |
128 | amb | 88 | Segment *NextSegment(Segments *segments,Segment *segment); |
129 | amb | 24 | |
130 | amb | 89 | SegmentEx *AppendSegment(SegmentsMem *segmentsmem,node_t node1,node_t node2,uint32_t wayindex); |
131 | amb | 39 | |
132 | amb | 88 | void SortSegmentList(SegmentsMem *segmentsmem); |
133 | amb | 24 | |
134 | amb | 88 | void RemoveBadSegments(SegmentsMem *segmentsmem); |
135 | |||
136 | amb | 89 | void MeasureSegments(SegmentsMem *segmentsmem,NodesMem *nodesmem); |
137 | amb | 88 | void FixupSegments(SegmentsMem *segmentsmem,NodesMem *nodesmem); |
138 | |||
139 | amb | 24 | distance_t Distance(Node *node1,Node *node2); |
140 | |||
141 | amb | 82 | duration_t Duration(Segment *segment,Way *way,Profile *profile); |
142 | amb | 63 | |
143 | amb | 89 | #define LookupSegment(xxx,yyy) (&(xxx)->segments[yyy]) |
144 | amb | 24 | |
145 | amb | 89 | #define LookupSegmentEx(xxx,yyy) (&(xxx)->xdata[yyy]) |
146 | amb | 32 | |
147 | amb | 89 | #define IndexSegment(xxx,yyy) ((yyy)-&(xxx)->segments[0]) |
148 | |||
149 | #define IndexSegmentEx(xxx,yyy) ((yyy)-&(xxx)->xdata[0]) | ||
150 | |||
151 | |||
152 | amb | 24 | #endif /* SEGMENTS_H */ |
Properties
Name | Value |
---|---|
cvs:description | Header file for segments. |