Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/segments.h
Parent Directory
|
Revision Log
Revision 89 -
(show 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 | /*************************************** |
2 | $Header: /home/amb/CVS/routino/src/segments.h,v 1.19 2009-01-28 18:46:55 amb Exp $ |
3 | |
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 | #include "nodes.h" |
21 | #include "ways.h" |
22 | #include "profiles.h" |
23 | |
24 | |
25 | /* Constants */ |
26 | |
27 | |
28 | /*+ The number of bins for segments - expect ~8,000,000 segments and use 4*sqrt(N) bins. +*/ |
29 | #define NBINS_SEGMENTS 8192 |
30 | |
31 | /*+ The array size increment for segments - expect ~8,000,000 segments. +*/ |
32 | #define INCREMENT_SEGMENTS 1024*1024 |
33 | |
34 | |
35 | /* Simple Types */ |
36 | |
37 | /*+ A long distance, measured in metres. +*/ |
38 | typedef uint32_t distance_t; |
39 | |
40 | /*+ A duration, measured in 1/10th seconds. +*/ |
41 | typedef uint32_t duration_t; |
42 | |
43 | |
44 | /*+ A flag to mark a distance as only applying for the other direction. +*/ |
45 | #define ONEWAY_OPPOSITE (distance_t)(0x80000000) |
46 | |
47 | /*+ The real distance ignoring the ONEWAY_OPPOSITE flag. +*/ |
48 | #define DISTANCE(xx) (distance_t)((xx)&(~ONEWAY_OPPOSITE)) |
49 | |
50 | |
51 | /*+ 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 | #define duration_to_minutes(xx) ((double)(xx)/600.0) |
59 | |
60 | /*+ Conversion from duration_t to hours. +*/ |
61 | #define duration_to_hours(xx) ((double)(xx)/36000.0) |
62 | |
63 | /*+ Conversion from hours to duration_t. +*/ |
64 | #define hours_to_duration(xx) ((duration_t)((double)(xx)*36000.0)) |
65 | |
66 | /*+ 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 | |
69 | |
70 | /* Data structures */ |
71 | |
72 | |
73 | /*+ A structure containing a single segment. +*/ |
74 | typedef struct _Segment |
75 | { |
76 | 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 | } |
81 | Segment; |
82 | |
83 | /*+ 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 | int super; /*+ A marker for super segments. +*/ |
89 | |
90 | Segment segment; /*+ The real segment data. +*/ |
91 | } |
92 | SegmentEx; |
93 | |
94 | /*+ A structure containing a set of segments (mmap format). +*/ |
95 | typedef struct _Segments |
96 | { |
97 | uint32_t number; /*+ How many entries are used in total? +*/ |
98 | |
99 | Segment *segments; /*+ An array of segments. +*/ |
100 | |
101 | void *data; /*+ The memory mapped data. +*/ |
102 | } |
103 | Segments; |
104 | |
105 | /*+ A structure containing a set of segments (memory format). +*/ |
106 | typedef struct _SegmentsMem |
107 | { |
108 | uint32_t sorted; /*+ Is the data sorted and therefore searchable? +*/ |
109 | uint32_t alloced; /*+ How many entries are allocated? +*/ |
110 | uint32_t number; /*+ How many entries are used? +*/ |
111 | |
112 | SegmentEx *xdata; /*+ The extended segment data. +*/ |
113 | } |
114 | SegmentsMem; |
115 | |
116 | |
117 | /* Functions in segments.c */ |
118 | |
119 | |
120 | SegmentsMem *NewSegmentList(void); |
121 | |
122 | Segments *LoadSegmentList(const char *filename); |
123 | void SaveSegmentList(SegmentsMem *segmentsmem,const char *filename); |
124 | |
125 | SegmentEx *FindFirstSegment(SegmentsMem* segmentsem,node_t node); |
126 | SegmentEx *FindNextSegment(SegmentsMem* segmentsem,SegmentEx *segmentex); |
127 | |
128 | Segment *NextSegment(Segments *segments,Segment *segment); |
129 | |
130 | SegmentEx *AppendSegment(SegmentsMem *segmentsmem,node_t node1,node_t node2,uint32_t wayindex); |
131 | |
132 | void SortSegmentList(SegmentsMem *segmentsmem); |
133 | |
134 | void RemoveBadSegments(SegmentsMem *segmentsmem); |
135 | |
136 | void MeasureSegments(SegmentsMem *segmentsmem,NodesMem *nodesmem); |
137 | void FixupSegments(SegmentsMem *segmentsmem,NodesMem *nodesmem); |
138 | |
139 | distance_t Distance(Node *node1,Node *node2); |
140 | |
141 | duration_t Duration(Segment *segment,Way *way,Profile *profile); |
142 | |
143 | #define LookupSegment(xxx,yyy) (&(xxx)->segments[yyy]) |
144 | |
145 | #define LookupSegmentEx(xxx,yyy) (&(xxx)->xdata[yyy]) |
146 | |
147 | #define IndexSegment(xxx,yyy) ((yyy)-&(xxx)->segments[0]) |
148 | |
149 | #define IndexSegmentEx(xxx,yyy) ((yyy)-&(xxx)->xdata[0]) |
150 | |
151 | |
152 | #endif /* SEGMENTS_H */ |
Properties
Name | Value |
---|---|
cvs:description | Header file for segments. |