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 184 - (hide annotations) (download) (as text)
Sun Jun 7 15:32:54 2009 UTC (15 years, 10 months ago) by amb
File MIME type: text/x-csrc
File size: 15380 byte(s)
Initial revision

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

Properties

Name Value
cvs:description Functions for data visualisation.