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/visualiser.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 219 - (hide annotations) (download) (as text)
Thu Jul 9 17:31:56 2009 UTC (15 years, 8 months ago) by amb
File MIME type: text/x-csrc
File size: 15992 byte(s)
Change from float to double for latitude and longitude.
Store latitude and longitude as an integer type rather than float (higher precision).

1 amb 184 /***************************************
2 amb 219 $Header: /home/amb/CVS/routino/src/visualiser.c,v 1.6 2009-07-09 17:31:56 amb Exp $
3 amb 184
4     Extract data from Routino.
5    
6     Part of the Routino routing software.
7     ******************/ /******************
8     This file Copyright 2008,2009 Andrew M. Bishop
9    
10     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     ***************************************/
23    
24    
25     #include <stdio.h>
26     #include <stdlib.h>
27     #include <string.h>
28    
29     #include "types.h"
30     #include "visualiser.h"
31     #include "nodes.h"
32     #include "segments.h"
33     #include "ways.h"
34    
35    
36     #define SPEED_LIMIT 1
37     #define WEIGHT_LIMIT 2
38     #define HEIGHT_LIMIT 3
39     #define WIDTH_LIMIT 4
40     #define LENGTH_LIMIT 5
41    
42     /* Local types */
43    
44 amb 219 typedef void (*callback_t)(index_t node,double latitude,double longitude);
45 amb 184
46     /* Local variables */
47    
48     static Nodes *OSMNodes;
49     static Segments *OSMSegments;
50     static Ways *OSMWays;
51    
52 amb 219 static double LatMin;
53     static double LatMax;
54     static double LonMin;
55     static double LonMax;
56 amb 217
57 amb 184 static int limit_type=0;
58    
59     /* Local functions */
60    
61 amb 217 static void find_all_nodes(Nodes *nodes,callback_t callback);
62 amb 219 static void output_junctions(index_t node,double latitude,double longitude);
63     static void output_super(index_t node,double latitude,double longitude);
64     static void output_oneway(index_t node,double latitude,double longitude);
65     static void output_limits(index_t node,double latitude,double longitude);
66 amb 184
67    
68     /*++++++++++++++++++++++++++++++++++++++
69     Output the data for junctions.
70    
71     Nodes *nodes The set of nodes to use.
72    
73     Segments *segments The set of segments to use.
74    
75     Ways *ways The set of ways to use.
76    
77 amb 219 double latmin The minimum latitude.
78 amb 184
79 amb 219 double latmax The maximum latitude.
80 amb 184
81 amb 219 double lonmin The minimum longitude.
82 amb 184
83 amb 219 double lonmax The maximum longitude.
84 amb 184 ++++++++++++++++++++++++++++++++++++++*/
85    
86 amb 219 void OutputJunctions(Nodes *nodes,Segments *segments,Ways *ways,double latmin,double latmax,double lonmin,double lonmax)
87 amb 184 {
88     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
89    
90     OSMNodes=nodes;
91     OSMSegments=segments;
92     OSMWays=ways;
93    
94 amb 217 LatMin=latmin;
95     LatMax=latmax;
96     LonMin=lonmin;
97     LonMax=lonmax;
98    
99 amb 184 /* Iterate through the nodes and process them */
100    
101 amb 217 find_all_nodes(nodes,(callback_t)output_junctions);
102 amb 184 }
103    
104    
105     /*++++++++++++++++++++++++++++++++++++++
106     Process a single node (called as a callback).
107    
108     index_t node The node to output.
109    
110 amb 219 double latitude The latitude of the node.
111 amb 184
112 amb 219 double longitude The longitude of the node.
113 amb 184 ++++++++++++++++++++++++++++++++++++++*/
114    
115 amb 219 static void output_junctions(index_t node,double latitude,double longitude)
116 amb 184 {
117     Segment *segment;
118     Way *firstway;
119     int count=0,difference=0;
120    
121     segment=FirstSegment(OSMSegments,OSMNodes,node);
122     firstway=LookupWay(OSMWays,segment->way);
123    
124     do
125     {
126     Way *way=LookupWay(OSMWays,segment->way);
127    
128     if(IsNormalSegment(segment))
129     count++;
130    
131 amb 201 if(WaysCompare(firstway,way))
132 amb 184 difference=1;
133    
134     segment=NextSegment(OSMSegments,segment,node);
135     }
136     while(segment);
137    
138     if(count!=2 || difference)
139 amb 198 printf("%.6f %.6f %d\n",radians_to_degrees(latitude),radians_to_degrees(longitude),count);
140 amb 184 }
141    
142    
143     /*++++++++++++++++++++++++++++++++++++++
144     Output the data for super-nodes and super-segments.
145    
146     Nodes *nodes The set of nodes to use.
147    
148     Segments *segments The set of segments to use.
149    
150     Ways *ways The set of ways to use.
151    
152 amb 219 double latmin The minimum latitude.
153 amb 184
154 amb 219 double latmax The maximum latitude.
155 amb 184
156 amb 219 double lonmin The minimum longitude.
157 amb 184
158 amb 219 double lonmax The maximum longitude.
159 amb 184 ++++++++++++++++++++++++++++++++++++++*/
160    
161 amb 219 void OutputSuper(Nodes *nodes,Segments *segments,Ways *ways,double latmin,double latmax,double lonmin,double lonmax)
162 amb 184 {
163     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
164    
165     OSMNodes=nodes;
166     OSMSegments=segments;
167     OSMWays=ways;
168    
169 amb 217 LatMin=latmin;
170     LatMax=latmax;
171     LonMin=lonmin;
172     LonMax=lonmax;
173    
174 amb 184 /* Iterate through the nodes and process them */
175    
176 amb 217 find_all_nodes(nodes,(callback_t)output_super);
177 amb 184 }
178    
179    
180     /*++++++++++++++++++++++++++++++++++++++
181     Process a single node (called as a callback).
182    
183     index_t node The node to output.
184    
185 amb 219 double latitude The latitude of the node.
186 amb 184
187 amb 219 double longitude The longitude of the node.
188 amb 184 ++++++++++++++++++++++++++++++++++++++*/
189    
190 amb 219 static void output_super(index_t node,double latitude,double longitude)
191 amb 184 {
192     Segment *segment;
193    
194     if(!IsSuperNode(OSMNodes,node))
195     return;
196    
197 amb 198 printf("%.6f %.6f n\n",radians_to_degrees(latitude),radians_to_degrees(longitude));
198 amb 188
199 amb 184 segment=FirstSegment(OSMSegments,OSMNodes,node);
200    
201     do
202     {
203     if(IsSuperSegment(segment))
204     {
205     index_t othernode=OtherNode(segment,node);
206 amb 219 double lat,lon;
207 amb 184
208 amb 217 GetLatLong(OSMNodes,othernode,&lat,&lon);
209 amb 184
210 amb 217 if(node>othernode || (lat<LatMin || lat>LatMax || lon<LonMin || lon>LonMax))
211 amb 198 printf("%.6f %.6f s\n",radians_to_degrees(lat),radians_to_degrees(lon));
212 amb 184 }
213    
214     segment=NextSegment(OSMSegments,segment,node);
215     }
216     while(segment);
217     }
218    
219    
220     /*++++++++++++++++++++++++++++++++++++++
221     Output the data for one-way segments.
222    
223     Nodes *nodes The set of nodes to use.
224    
225     Segments *segments The set of segments to use.
226    
227     Ways *ways The set of ways to use.
228    
229 amb 219 double latmin The minimum latitude.
230 amb 184
231 amb 219 double latmax The maximum latitude.
232 amb 184
233 amb 219 double lonmin The minimum longitude.
234 amb 184
235 amb 219 double lonmax The maximum longitude.
236 amb 184 ++++++++++++++++++++++++++++++++++++++*/
237    
238 amb 219 void OutputOneway(Nodes *nodes,Segments *segments,Ways *ways,double latmin,double latmax,double lonmin,double lonmax)
239 amb 184 {
240     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
241    
242     OSMNodes=nodes;
243     OSMSegments=segments;
244     OSMWays=ways;
245    
246 amb 217 LatMin=latmin;
247     LatMax=latmax;
248     LonMin=lonmin;
249     LonMax=lonmax;
250    
251 amb 184 /* Iterate through the nodes and process them */
252    
253 amb 217 find_all_nodes(nodes,(callback_t)output_oneway);
254 amb 184 }
255    
256    
257     /*++++++++++++++++++++++++++++++++++++++
258     Process a single node (called as a callback).
259    
260     index_t node The node to output.
261    
262 amb 219 double latitude The latitude of the node.
263 amb 184
264 amb 219 double longitude The longitude of the node.
265 amb 184 ++++++++++++++++++++++++++++++++++++++*/
266    
267 amb 219 static void output_oneway(index_t node,double latitude,double longitude)
268 amb 184 {
269     Segment *segment;
270    
271     segment=FirstSegment(OSMSegments,OSMNodes,node);
272    
273     do
274     {
275     if(IsNormalSegment(segment))
276     {
277     index_t othernode=OtherNode(segment,node);
278    
279     if(node>othernode)
280     {
281 amb 219 double lat,lon;
282 amb 184
283     GetLatLong(OSMNodes,othernode,&lat,&lon);
284    
285     if(IsOnewayFrom(segment,node))
286 amb 198 printf("%.6f %.6f %.6f %.6f\n",radians_to_degrees(latitude),radians_to_degrees(longitude),radians_to_degrees(lat),radians_to_degrees(lon));
287 amb 184 else if(IsOnewayFrom(segment,othernode))
288 amb 198 printf("%.6f %.6f %.6f %.6f\n",radians_to_degrees(lat),radians_to_degrees(lon),radians_to_degrees(latitude),radians_to_degrees(longitude));
289 amb 184 }
290     }
291    
292     segment=NextSegment(OSMSegments,segment,node);
293     }
294     while(segment);
295     }
296    
297    
298     /*++++++++++++++++++++++++++++++++++++++
299     Output the data for speed limits.
300    
301     Nodes *nodes The set of nodes to use.
302    
303     Segments *segments The set of segments to use.
304    
305     Ways *ways The set of ways to use.
306    
307 amb 219 double latmin The minimum latitude.
308 amb 184
309 amb 219 double latmax The maximum latitude.
310 amb 184
311 amb 219 double lonmin The minimum longitude.
312 amb 184
313 amb 219 double lonmax The maximum longitude.
314 amb 184 ++++++++++++++++++++++++++++++++++++++*/
315    
316 amb 219 void OutputSpeedLimits(Nodes *nodes,Segments *segments,Ways *ways,double latmin,double latmax,double lonmin,double lonmax)
317 amb 184 {
318     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
319    
320     OSMNodes=nodes;
321     OSMSegments=segments;
322     OSMWays=ways;
323    
324 amb 217 LatMin=latmin;
325     LatMax=latmax;
326     LonMin=lonmin;
327     LonMax=lonmax;
328    
329 amb 184 /* Iterate through the nodes and process them */
330    
331     limit_type=SPEED_LIMIT;
332    
333 amb 217 find_all_nodes(nodes,(callback_t)output_limits);
334 amb 184 }
335    
336    
337     /*++++++++++++++++++++++++++++++++++++++
338     Output the data for weight limits.
339    
340     Nodes *nodes The set of nodes to use.
341    
342     Segments *segments The set of segments to use.
343    
344     Ways *ways The set of ways to use.
345    
346 amb 219 double latmin The minimum latitude.
347 amb 184
348 amb 219 double latmax The maximum latitude.
349 amb 184
350 amb 219 double lonmin The minimum longitude.
351 amb 184
352 amb 219 double lonmax The maximum longitude.
353 amb 184 ++++++++++++++++++++++++++++++++++++++*/
354    
355 amb 219 void OutputWeightLimits(Nodes *nodes,Segments *segments,Ways *ways,double latmin,double latmax,double lonmin,double lonmax)
356 amb 184 {
357     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
358    
359     OSMNodes=nodes;
360     OSMSegments=segments;
361     OSMWays=ways;
362    
363 amb 217 LatMin=latmin;
364     LatMax=latmax;
365     LonMin=lonmin;
366     LonMax=lonmax;
367    
368 amb 184 /* Iterate through the nodes and process them */
369    
370     limit_type=WEIGHT_LIMIT;
371    
372 amb 217 find_all_nodes(nodes,(callback_t)output_limits);
373 amb 184 }
374    
375    
376     /*++++++++++++++++++++++++++++++++++++++
377     Output the data for height limits.
378    
379     Nodes *nodes The set of nodes to use.
380    
381     Segments *segments The set of segments to use.
382    
383     Ways *ways The set of ways to use.
384    
385 amb 219 double latmin The minimum latitude.
386 amb 184
387 amb 219 double latmax The maximum latitude.
388 amb 184
389 amb 219 double lonmin The minimum longitude.
390 amb 184
391 amb 219 double lonmax The maximum longitude.
392 amb 184 ++++++++++++++++++++++++++++++++++++++*/
393    
394 amb 219 void OutputHeightLimits(Nodes *nodes,Segments *segments,Ways *ways,double latmin,double latmax,double lonmin,double lonmax)
395 amb 184 {
396     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
397    
398     OSMNodes=nodes;
399     OSMSegments=segments;
400     OSMWays=ways;
401    
402 amb 217 LatMin=latmin;
403     LatMax=latmax;
404     LonMin=lonmin;
405     LonMax=lonmax;
406    
407 amb 184 /* Iterate through the nodes and process them */
408    
409     limit_type=HEIGHT_LIMIT;
410    
411 amb 217 find_all_nodes(nodes,(callback_t)output_limits);
412 amb 184 }
413    
414    
415     /*++++++++++++++++++++++++++++++++++++++
416     Output the data for width limits.
417    
418     Nodes *nodes The set of nodes to use.
419    
420     Segments *segments The set of segments to use.
421    
422     Ways *ways The set of ways to use.
423    
424 amb 219 double latmin The minimum latitude.
425 amb 184
426 amb 219 double latmax The maximum latitude.
427 amb 184
428 amb 219 double lonmin The minimum longitude.
429 amb 184
430 amb 219 double lonmax The maximum longitude.
431 amb 184 ++++++++++++++++++++++++++++++++++++++*/
432    
433 amb 219 void OutputWidthLimits(Nodes *nodes,Segments *segments,Ways *ways,double latmin,double latmax,double lonmin,double lonmax)
434 amb 184 {
435     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
436    
437     OSMNodes=nodes;
438     OSMSegments=segments;
439     OSMWays=ways;
440    
441 amb 217 LatMin=latmin;
442     LatMax=latmax;
443     LonMin=lonmin;
444     LonMax=lonmax;
445    
446 amb 184 /* Iterate through the nodes and process them */
447    
448     limit_type=WIDTH_LIMIT;
449    
450 amb 217 find_all_nodes(nodes,(callback_t)output_limits);
451 amb 184 }
452    
453    
454     /*++++++++++++++++++++++++++++++++++++++
455     Output the data for length limits.
456    
457     Nodes *nodes The set of nodes to use.
458    
459     Segments *segments The set of segments to use.
460    
461     Ways *ways The set of ways to use.
462    
463 amb 219 double latmin The minimum latitude.
464 amb 184
465 amb 219 double latmax The maximum latitude.
466 amb 184
467 amb 219 double lonmin The minimum longitude.
468 amb 184
469 amb 219 double lonmax The maximum longitude.
470 amb 184 ++++++++++++++++++++++++++++++++++++++*/
471    
472 amb 219 void OutputLengthLimits(Nodes *nodes,Segments *segments,Ways *ways,double latmin,double latmax,double lonmin,double lonmax)
473 amb 184 {
474     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
475    
476     OSMNodes=nodes;
477     OSMSegments=segments;
478     OSMWays=ways;
479    
480 amb 217 LatMin=latmin;
481     LatMax=latmax;
482     LonMin=lonmin;
483     LonMax=lonmax;
484    
485 amb 184 /* Iterate through the nodes and process them */
486    
487     limit_type=LENGTH_LIMIT;
488    
489 amb 217 find_all_nodes(nodes,(callback_t)output_limits);
490 amb 184 }
491    
492    
493     /*++++++++++++++++++++++++++++++++++++++
494     Process a single node (called as a callback).
495    
496     index_t node The node to output.
497    
498 amb 219 double latitude The latitude of the node.
499 amb 184
500 amb 219 double longitude The longitude of the node.
501 amb 184 ++++++++++++++++++++++++++++++++++++++*/
502    
503 amb 219 static void output_limits(index_t node,double latitude,double longitude)
504 amb 184 {
505     Segment *segment,*segments[16];
506     Way *ways[16];
507     int limits[16];
508     int count=0;
509     int i,j,same=0;
510    
511     segment=FirstSegment(OSMSegments,OSMNodes,node);
512    
513     do
514     {
515     if(IsNormalSegment(segment) && count<16)
516     {
517     ways [count]=LookupWay(OSMWays,segment->way);
518     segments[count]=segment;
519    
520     switch(limit_type)
521     {
522     case SPEED_LIMIT: limits[count]=ways[count]->speed; break;
523     case WEIGHT_LIMIT: limits[count]=ways[count]->weight; break;
524     case HEIGHT_LIMIT: limits[count]=ways[count]->height; break;
525     case WIDTH_LIMIT: limits[count]=ways[count]->width; break;
526     case LENGTH_LIMIT: limits[count]=ways[count]->length; break;
527     }
528    
529 amb 217 if(limits[count] || ways[count]->type<Way_Track)
530     count++;
531 amb 184 }
532    
533     segment=NextSegment(OSMSegments,segment,node);
534     }
535     while(segment);
536    
537     /* Nodes with only one limit are not interesting */
538    
539     if(count==1)
540     return;
541    
542     /* Nodes with all segments the same limit is not interesting */
543    
544     same=0;
545     for(j=0;j<count;j++)
546     if(limits[0]==limits[j])
547     same++;
548    
549     if(same==count)
550     return;
551    
552     /* Display the interesting speed limits */
553    
554 amb 198 printf("%.6f %.6f\n",radians_to_degrees(latitude),radians_to_degrees(longitude));
555 amb 184
556     for(i=0;i<count;i++)
557     {
558     same=0;
559     for(j=0;j<count;j++)
560     if(limits[i]==limits[j])
561     same++;
562    
563     if(count==2 || same!=(count-1))
564     {
565 amb 219 double lat,lon;
566 amb 184
567     GetLatLong(OSMNodes,OtherNode(segments[i],node),&lat,&lon);
568    
569     switch(limit_type)
570     {
571     case SPEED_LIMIT:
572 amb 219 printf("%.6f %.6f %d\n",radians_to_degrees(lat),radians_to_degrees(lon),speed_to_kph(limits[i]));
573 amb 184 break;
574     case WEIGHT_LIMIT:
575 amb 198 printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),weight_to_tonnes(limits[i]));
576 amb 184 break;
577     case HEIGHT_LIMIT:
578 amb 198 printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),height_to_metres(limits[i]));
579 amb 184 break;
580     case WIDTH_LIMIT:
581 amb 198 printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),width_to_metres(limits[i]));
582 amb 184 break;
583     case LENGTH_LIMIT:
584 amb 198 printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),length_to_metres(limits[i]));
585 amb 184 break;
586     }
587     }
588     }
589     }
590    
591    
592     /*++++++++++++++++++++++++++++++++++++++
593     A function to iterate through all nodes and call a callback function for each one.
594    
595     Nodes *nodes The list of nodes to process.
596    
597     callback_t callback The callback function for each node.
598     ++++++++++++++++++++++++++++++++++++++*/
599    
600 amb 217 static void find_all_nodes(Nodes *nodes,callback_t callback)
601 amb 184 {
602 amb 219 int32_t latminbin=latlong_to_bin(radians_to_latlong(LatMin))-nodes->xlatzero;
603     int32_t latmaxbin=latlong_to_bin(radians_to_latlong(LatMax))-nodes->xlatzero;
604     int32_t lonminbin=latlong_to_bin(radians_to_latlong(LonMin))-nodes->xlonzero;
605     int32_t lonmaxbin=latlong_to_bin(radians_to_latlong(LonMax))-nodes->xlonzero;
606 amb 184 int latb,lonb,llbin;
607     index_t node;
608    
609     /* Loop through all of the nodes. */
610    
611     for(latb=latminbin;latb<=latmaxbin;latb++)
612     for(lonb=lonminbin;lonb<=lonmaxbin;lonb++)
613     {
614     llbin=lonb*nodes->latbins+latb;
615    
616     if(llbin<0 || llbin>(nodes->latbins*nodes->lonbins))
617     continue;
618    
619     for(node=nodes->offsets[llbin];node<nodes->offsets[llbin+1];node++)
620     {
621 amb 219 double lat=latlong_to_radians(bin_to_latlong(nodes->xlatzero+latb)+off_to_latlong(nodes->nodes[node].latoffset));
622     double lon=latlong_to_radians(bin_to_latlong(nodes->xlonzero+lonb)+off_to_latlong(nodes->nodes[node].lonoffset));
623 amb 184
624 amb 217 if(lat>LatMin && lat<LatMax && lon>LonMin && lon<LonMax)
625 amb 184 (*callback)(node,lat,lon);
626     }
627     }
628     }

Properties

Name Value
cvs:description Functions for data visualisation.