Routino SVN Repository Browser

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

ViewVC logotype

Annotation of /trunk/src/segments.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 95 - (hide annotations) (download) (as text)
Sat Jan 31 14:53:29 2009 UTC (16 years, 1 month ago) by amb
File MIME type: text/x-chdr
File size: 4760 byte(s)
Intermediate checkin, routing now working.

1 amb 24 /***************************************
2 amb 95 $Header: /home/amb/CVS/routino/src/segments.h,v 1.21 2009-01-31 14:53:29 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 array size increment for segments - expect ~8,000,000 segments. +*/
29 amb 27 #define INCREMENT_SEGMENTS 1024*1024
30 amb 24
31 amb 90 /*+ A flag to mark super-segments. +*/
32     #define SUPER_SEGMENT 0x80000000
33 amb 27
34 amb 90
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    
89     Segment segment; /*+ The real segment data. +*/
90     }
91     SegmentEx;
92    
93 amb 24 /*+ A structure containing a set of segments (mmap format). +*/
94     typedef struct _Segments
95     {
96 amb 65 uint32_t number; /*+ How many entries are used in total? +*/
97 amb 88
98     Segment *segments; /*+ An array of segments. +*/
99    
100     void *data; /*+ The memory mapped data. +*/
101 amb 24 }
102     Segments;
103    
104     /*+ A structure containing a set of segments (memory format). +*/
105     typedef struct _SegmentsMem
106     {
107 amb 88 uint32_t sorted; /*+ Is the data sorted and therefore searchable? +*/
108 amb 24 uint32_t alloced; /*+ How many entries are allocated? +*/
109     uint32_t number; /*+ How many entries are used? +*/
110    
111 amb 88 SegmentEx *xdata; /*+ The extended segment data. +*/
112 amb 24 }
113     SegmentsMem;
114    
115    
116 amb 26 /* Functions in segments.c */
117 amb 24
118    
119     SegmentsMem *NewSegmentList(void);
120 amb 90 void FreeSegmentList(SegmentsMem *segmentsmem);
121 amb 24
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 90 void FixupSegments(SegmentsMem* segmentsmem,NodesMem *nodesmem,SegmentsMem* supersegmentsmem);
138 amb 88
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 amb 95 #define IsNormalSegment(xxx) (((xxx)->node1)&SUPER_SEGMENT)
152 amb 89
153 amb 95 #define IsSuperSegment(xxx) (((xxx)->node2)&SUPER_SEGMENT)
154    
155     #define SEGMENT(xxx) ((xxx)&(~SUPER_SEGMENT))
156    
157    
158 amb 24 #endif /* SEGMENTS_H */

Properties

Name Value
cvs:description Header file for segments.