/[zanavi_public1]/navit/navit/maptool/coastline.c
ZANavi

Contents of /navit/navit/maptool/coastline.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 37 - (hide annotations) (download)
Sat Mar 8 21:37:20 2014 UTC (10 years, 1 month ago) by zoff99
File MIME type: text/plain
File size: 19154 byte(s)
new market version, lots of new features
1 zoff99 8 /**
2 zoff99 37 * ZANavi, Zoff Android Navigation system.
3     * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
4     *
5     * This program is free software; you can redistribute it and/or
6     * modify it under the terms of the GNU General Public License
7     * version 2 as published by the Free Software Foundation.
8     *
9     * This program is distributed in the hope that it will be useful,
10     * but WITHOUT ANY WARRANTY; without even the implied warranty of
11     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12     * GNU General Public License for more details.
13     *
14     * You should have received a copy of the GNU General Public License
15     * along with this program; if not, write to the
16     * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     * Boston, MA 02110-1301, USA.
18     */
19    
20     /**
21 zoff99 8 * Navit, a modular navigation system.
22     * Copyright (C) 2005-2011 Navit Team
23     *
24     * This program is free software; you can redistribute it and/or
25     * modify it under the terms of the GNU General Public License
26     * version 2 as published by the Free Software Foundation.
27     *
28     * This program is distributed in the hope that it will be useful,
29     * but WITHOUT ANY WARRANTY; without even the implied warranty of
30     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31     * GNU General Public License for more details.
32     *
33     * You should have received a copy of the GNU General Public License
34     * along with this program; if not, write to the
35     * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36     * Boston, MA 02110-1301, USA.
37     */
38     #include "maptool.h"
39     #include "debug.h"
40    
41     static int distance_from_ll(struct coord *c, struct rect *bbox)
42     {
43 zoff99 37 int dist = 0;
44     if (c->x == bbox->l.x)
45     return dist + c->y - bbox->l.y;
46     dist += bbox->h.y - bbox->l.y;
47 zoff99 8 if (c->y == bbox->h.y)
48 zoff99 37 return dist + c->x - bbox->l.x;
49     dist += bbox->h.x - bbox->l.x;
50 zoff99 8 if (c->x == bbox->h.x)
51 zoff99 37 return dist + bbox->h.y - c->y;
52     dist += bbox->h.y - bbox->l.y;
53 zoff99 8 if (c->y == bbox->l.y)
54 zoff99 37 return dist + bbox->h.x - c->x;
55 zoff99 8 return -1;
56     }
57    
58     static struct geom_poly_segment *
59     find_next(struct rect *bbox, GList *segments, struct coord *c, int exclude, struct coord *ci)
60     {
61 zoff99 37 int min = INT_MAX, search = distance_from_ll(c, bbox) + (exclude ? 1 : 0);
62 zoff99 8 GList *curr;
63     int i;
64 zoff99 37 struct geom_poly_segment *ret = NULL;
65     int dbgl = 1;
66 zoff99 8
67 zoff99 37 for (i = 0; i < 2; i++)
68     {
69     curr = segments;
70     dbg(dbgl, "search distance %d\n", search);
71     while (curr)
72     {
73     struct geom_poly_segment *seg = curr->data;
74     int dist = distance_from_ll(seg->first, bbox);
75     dbg(dbgl, "0x%x 0x%x dist %d\n", seg->first->x, seg->first->y, dist);
76     if (dist != -1 && seg->first != seg->last && dist < min && (dist >= search))
77     {
78     min = dist;
79     ci[0] = *seg->first;
80     ci[1] = *seg->last;
81     ret = seg;
82 zoff99 8 }
83 zoff99 37 curr = g_list_next(curr);
84 zoff99 8 }
85     if (ret || !search)
86     break;
87 zoff99 37 search = 0;
88 zoff99 8 }
89     return ret;
90     }
91    
92 zoff99 37 static void close_polygon(struct item_bin *ib, struct coord *from, struct coord *to, int dir, struct rect *bbox, int *edges)
93 zoff99 8 {
94 zoff99 37 int i, e, dist, fromdist, todist;
95     int full = (bbox->h.x - bbox->l.x + bbox->h.y - bbox->l.y) * 2;
96     int corners = 0, first_corner = 0;
97 zoff99 8 struct coord c;
98 zoff99 37 if (dir > 0)
99     {
100     fromdist = distance_from_ll(from, bbox);
101     todist = distance_from_ll(to, bbox);
102 zoff99 8 }
103 zoff99 37 else
104     {
105     fromdist = distance_from_ll(to, bbox);
106     todist = distance_from_ll(from, bbox);
107     }
108 zoff99 8 #if 0
109     fprintf(stderr,"close_polygon fromdist %d todist %d full %d dir %d\n", fromdist, todist, full, dir);
110     #endif
111     if (fromdist > todist)
112 zoff99 37 todist += full;
113 zoff99 8 #if 0
114     fprintf(stderr,"close_polygon corrected fromdist %d todist %d full %d dir %d\n", fromdist, todist, full, dir);
115     #endif
116 zoff99 37 for (i = 0; i < 8; i++)
117     {
118 zoff99 8 if (dir > 0)
119 zoff99 37 e = i;
120 zoff99 8 else
121 zoff99 37 e = 7 - i;
122     switch (e % 4)
123     {
124     case 0:
125     c = bbox->l;
126     break;
127     case 1:
128     c.x = bbox->l.x;
129     c.y = bbox->h.y;
130     break;
131     case 2:
132     c = bbox->h;
133     break;
134     case 3:
135     c.x = bbox->h.x;
136     c.y = bbox->l.y;
137     break;
138 zoff99 8 }
139 zoff99 37 dist = distance_from_ll(&c, bbox);
140 zoff99 8 if (e & 4)
141 zoff99 37 dist += full;
142 zoff99 8 #if 0
143     fprintf(stderr,"dist %d %d\n",e,dist);
144     #endif
145 zoff99 37 if (dist > fromdist && dist < todist)
146     {
147 zoff99 8 item_bin_add_coord(ib, &c, 1);
148     #if 0
149     fprintf(stderr,"add\n");
150     #endif
151     }
152 zoff99 37 if (dist >= fromdist && dist <= todist)
153     {
154 zoff99 8 if (!corners)
155 zoff99 37 first_corner = e;
156 zoff99 8 corners++;
157     }
158     }
159 zoff99 37 while (corners >= 2)
160     {
161     *edges |= 1 << (first_corner % 4);
162 zoff99 8 first_corner++;
163     corners--;
164     }
165     }
166    
167 zoff99 37 struct coastline_tile_data
168     {
169 zoff99 8 struct item_bin_sink_func *sink;
170     GHashTable *tile_edges;
171     int level;
172     };
173    
174     static GList *
175     tile_data_to_segments(int *tile_data)
176     {
177 zoff99 37 int *end = tile_data + tile_data[0];
178     int *curr = tile_data + 1;
179     GList *segments = NULL;
180     int count = 0;
181 zoff99 8
182 zoff99 37 while (curr < end)
183     {
184     struct item_bin *ib = (struct item_bin *) curr;
185     segments = g_list_prepend(segments, item_bin_to_poly_segment(ib, geom_poly_segment_type_way_right_side));
186     curr += ib->len + 1;
187 zoff99 8 count++;
188     }
189     #if 0
190     fprintf(stderr,"%d segments\n",count);
191     #endif
192     return segments;
193     }
194    
195 zoff99 37 static void tile_collector_process_tile(char *tile, int *tile_data, struct coastline_tile_data *data)
196 zoff99 8 {
197 zoff99 37
198     //fprintf(stderr,"tile_collector_process_tile:Enter\n");
199    
200     int poly_start_valid, tile_start_valid, exclude, search = 0;
201 zoff99 8 struct rect bbox;
202 zoff99 37 struct coord cn[2], end, poly_start, tile_start;
203 zoff99 8 struct geom_poly_segment *first;
204 zoff99 37 struct item_bin *ib = NULL;
205     struct item_bin_sink *out = data->sink->priv_data[1];
206     int dbgl = 1;
207     int edges = 0, flags;
208     GList *sorted_segments, *curr;
209 zoff99 8 #if 0
210     if (strncmp(tile,"bcdbdcabddddba",7))
211 zoff99 37 return;
212 zoff99 8 #endif
213     #if 0
214     if (strncmp(tile,"bcdbdcaaaaddba",14))
215 zoff99 37 return;
216 zoff99 8 #endif
217     #if 0
218     fprintf(stderr,"tile %s of size %d\n", tile, *tile_data);
219     #endif
220     tile_bbox(tile, &bbox, 0);
221 zoff99 37 sorted_segments = geom_poly_segments_sort(tile_data_to_segments(tile_data), geom_poly_segment_type_way_right_side);
222 zoff99 8 #if 0
223 zoff99 37 {
224     GList *sort_segments=sorted_segments;
225     int count=0;
226     while (sort_segments)
227     {
228     struct geom_poly_segment *seg=sort_segments->data;
229     struct item_bin *ib=(struct item_bin *)buffer;
230     char *text=g_strdup_printf("segment %d type %d %p %s area "LONGLONG_FMT,count++,seg->type,sort_segments,coord_is_equal(*seg->first, *seg->last) ? "closed":"open",geom_poly_area(seg->first,seg->last-seg->first+1));
231     item_bin_init(ib, type_rg_segment);
232     item_bin_add_coord(ib, seg->first, seg->last-seg->first+1);
233     item_bin_add_attr_string(ib, attr_debug, text);
234     // fprintf(stderr,"%s\n",text);
235     g_free(text);
236     // item_bin_dump(ib, stderr);
237     item_bin_write_to_sink(ib, out, NULL);
238     sort_segments=g_list_next(sort_segments);
239     }
240 zoff99 8 }
241     #endif
242 zoff99 37 flags = 0;
243     curr = sorted_segments;
244     while (curr)
245     {
246     struct geom_poly_segment *seg = curr->data;
247     switch (seg->type)
248     {
249     case geom_poly_segment_type_way_inner:
250     flags |= 1;
251     break;
252     case geom_poly_segment_type_way_outer:
253     flags |= 2;
254     break;
255     default:
256     flags |= 4;
257     break;
258 zoff99 8 }
259 zoff99 37 curr = g_list_next(curr);
260 zoff99 8 }
261 zoff99 37
262     if (flags == 1)
263     {
264     //fprintf(stderr,"tile_collector_process_tile:poly, flags==1\n");
265    
266     ib = init_item(type_poly_water_tiled, 0);
267 zoff99 8 item_bin_bbox(ib, &bbox);
268     item_bin_write_to_sink(ib, out, NULL);
269 zoff99 37 g_hash_table_insert(data->tile_edges, g_strdup(tile), (void *) 15);
270 zoff99 8 return;
271     }
272 zoff99 37
273 zoff99 8 #if 1
274 zoff99 37 end = bbox.l;
275     tile_start_valid = 0;
276     poly_start_valid = 0;
277     exclude = 0;
278     poly_start.x = 0;
279     poly_start.y = 0;
280     tile_start.x = 0;
281     tile_start.y = 0;
282     for (;;)
283     {
284 zoff99 8 search++;
285     // item_bin_write_debug_point_to_sink(out, &end, "Search %d",search);
286 zoff99 37 dbg(dbgl, "searching next polygon from 0x%x 0x%x\n", end.x, end.y);
287     first = find_next(&bbox, sorted_segments, &end, exclude, cn);
288     exclude = 1;
289 zoff99 8 if (!first)
290     break;
291 zoff99 37 if (!tile_start_valid)
292     {
293     tile_start = cn[0];
294     tile_start_valid = 1;
295     }
296     else
297     {
298     if (cn[0].x == tile_start.x && cn[0].y == tile_start.y)
299     {
300     dbg(dbgl, "end of tile reached\n");
301 zoff99 8 break;
302     }
303     }
304 zoff99 37 if (first->type == geom_poly_segment_type_none)
305     {
306     end = cn[0];
307 zoff99 8 continue;
308     }
309 zoff99 37 poly_start_valid = 0;
310     dbg(dbgl, "start of polygon 0x%x 0x%x\n", cn[0].x, cn[0].y);
311     for (;;)
312     {
313     if (!poly_start_valid)
314     {
315     //fprintf(stderr,"tile_collector_process_tile:init item:poly_water_tiled\n");
316    
317     poly_start = cn[0];
318     poly_start_valid = 1;
319     ib = init_item(type_poly_water_tiled, 0);
320     }
321     else
322     {
323 zoff99 8 close_polygon(ib, &end, &cn[0], 1, &bbox, &edges);
324 zoff99 37 if (cn[0].x == poly_start.x && cn[0].y == poly_start.y)
325     {
326     dbg(dbgl, "poly end reached\n");
327 zoff99 8 item_bin_write_to_sink(ib, out, NULL);
328 zoff99 37 end = cn[0];
329 zoff99 8 break;
330     }
331     }
332     if (first->type == geom_poly_segment_type_none)
333     break;
334 zoff99 37 item_bin_add_coord(ib, first->first, first->last - first->first + 1);
335     first->type = geom_poly_segment_type_none;
336     end = cn[1];
337     if (distance_from_ll(&end, &bbox) == -1)
338     {
339     dbg(dbgl, "incomplete\n");
340 zoff99 8 break;
341     }
342 zoff99 37 first = find_next(&bbox, sorted_segments, &end, 1, cn);
343     dbg(dbgl, "next segment of polygon 0x%x 0x%x\n", cn[0].x, cn[0].y);
344 zoff99 8 }
345     if (search > 55)
346     break;
347     }
348     #endif
349    
350     #if 0
351     {
352     int *end=tile_data+tile_data[0];
353     int *curr=tile_data+1;
354 zoff99 37 while (curr < end)
355     {
356 zoff99 8 struct item_bin *ib=(struct item_bin *)curr;
357     // item_bin_dump(ib);
358     ib->type=type_rg_segment;
359     item_bin_write_to_sink(ib, out, NULL);
360     curr+=ib->len+1;
361     #if 0
362     {
363     struct coord *c[2];
364     int i;
365     char *s;
366     c[0]=(struct coord *)(ib+1);
367     c[1]=c[0]+ib->clen/2-1;
368 zoff99 37 for (i = 0; i < 2; i++)
369     {
370 zoff99 8 s=coord_to_str(c[i]);
371     item_bin_write_debug_point_to_sink(out, c[i], "%s",s);
372     g_free(s);
373     }
374 zoff99 37
375 zoff99 8 }
376     #endif
377     }
378     }
379     #endif
380 zoff99 37 g_hash_table_insert(data->tile_edges, g_strdup(tile), (void *) edges);
381 zoff99 8 #if 0
382     item_bin_init(ib, type_border_country);
383     item_bin_bbox(ib, &bbox);
384     item_bin_add_attr_string(ib, attr_debug, tile);
385     item_bin_write_to_sink(ib, out, NULL);
386     #endif
387     #if 0
388     c.x=(bbox.l.x+bbox.h.x)/2;
389     c.y=(bbox.l.y+bbox.h.y)/2;
390     item_bin_write_debug_point_to_sink(out, &c, "%s %d",tile,edges);
391     #endif
392     }
393    
394 zoff99 37 static void ocean_tile(GHashTable *hash, char *tile, char c, struct item_bin_sink *out)
395 zoff99 8 {
396 zoff99 37 int len = strlen(tile);
397     char *tile2 = g_alloca(sizeof(char) * (len + 1));
398 zoff99 8 struct rect bbox;
399     struct item_bin *ib;
400     struct coord co;
401    
402 zoff99 37 //fprintf(stderr,"ocean_tile:Enter\n");
403    
404 zoff99 8 strcpy(tile2, tile);
405 zoff99 37 tile2[len - 1] = c;
406    
407 zoff99 8 //fprintf(stderr,"Testing %s\n",tile2);
408 zoff99 37
409 zoff99 8 if (g_hash_table_lookup_extended(hash, tile2, NULL, NULL))
410 zoff99 37 {
411 zoff99 8 return;
412 zoff99 37 }
413    
414 zoff99 8 //fprintf(stderr,"%s ok\n",tile2);
415 zoff99 37
416 zoff99 8 tile_bbox(tile2, &bbox, 0);
417 zoff99 37 ib = init_item(type_poly_water_tiled, 0);
418 zoff99 8 item_bin_bbox(ib, &bbox);
419     item_bin_write_to_sink(ib, out, NULL);
420 zoff99 37 g_hash_table_insert(hash, g_strdup(tile2), (void *) 15);
421 zoff99 8 #if 0
422     item_bin_init(ib, type_border_country);
423     item_bin_bbox(ib, &bbox);
424     item_bin_add_attr_string(ib, attr_debug, tile2);
425     item_bin_write_to_sink(ib, out, NULL);
426     #endif
427 zoff99 37 co.x = (bbox.l.x + bbox.h.x) / 2;
428     co.y = (bbox.l.y + bbox.h.y) / 2;
429 zoff99 8 //item_bin_write_debug_point_to_sink(out, &co, "%s 15",tile2);
430 zoff99 37
431 zoff99 8 }
432    
433     /* ba */
434     /* dc */
435    
436 zoff99 37 static void tile_collector_add_siblings(char *tile, void *edgesp, struct coastline_tile_data *data)
437 zoff99 8 {
438 zoff99 37 int len = strlen(tile);
439     char t = tile[len - 1];
440     struct item_bin_sink *out = data->sink->priv_data[1];
441     int edges = (int) edgesp;
442     int debug = 0;
443 zoff99 8
444     if (len != data->level)
445     return;
446     #if 0
447     if (!strncmp(tile,"bcacccaadbdcd",10))
448 zoff99 37 debug=1;
449 zoff99 8 #endif
450     if (debug)
451 zoff99 37 fprintf(stderr, "%s (%c) has %d edges active\n", tile, t, edges);
452     if (t == 'a' && (edges & 1))
453 zoff99 8 ocean_tile(data->tile_edges, tile, 'b', out);
454 zoff99 37 if (t == 'a' && (edges & 8))
455 zoff99 8 ocean_tile(data->tile_edges, tile, 'c', out);
456 zoff99 37 if (t == 'b' && (edges & 4))
457 zoff99 8 ocean_tile(data->tile_edges, tile, 'a', out);
458 zoff99 37 if (t == 'b' && (edges & 8))
459 zoff99 8 ocean_tile(data->tile_edges, tile, 'd', out);
460 zoff99 37 if (t == 'c' && (edges & 1))
461 zoff99 8 ocean_tile(data->tile_edges, tile, 'd', out);
462 zoff99 37 if (t == 'c' && (edges & 2))
463 zoff99 8 ocean_tile(data->tile_edges, tile, 'a', out);
464 zoff99 37 if (t == 'd' && (edges & 4))
465 zoff99 8 ocean_tile(data->tile_edges, tile, 'c', out);
466 zoff99 37 if (t == 'd' && (edges & 2))
467 zoff99 8 ocean_tile(data->tile_edges, tile, 'b', out);
468     }
469    
470 zoff99 37 static int tile_sibling_edges(GHashTable *hash, char *tile, char c)
471 zoff99 8 {
472 zoff99 37 int len = strlen(tile);
473 zoff99 8 int ret;
474 zoff99 37 char *tile2 = g_alloca(sizeof(char) * (len + 1));
475 zoff99 8 void *data;
476     strcpy(tile2, tile);
477 zoff99 37 tile2[len - 1] = c;
478 zoff99 8 if (!g_hash_table_lookup_extended(hash, tile2, NULL, &data))
479 zoff99 37 ret = 15;
480 zoff99 8 else
481 zoff99 37 ret = (int) data;
482 zoff99 8 //fprintf(stderr,"checking '%s' with %d edges active\n",tile2,ret);
483    
484     return ret;
485     }
486    
487 zoff99 37 static void ocean_tile2(struct rect *r, int dx, int dy, int wf, int hf, struct item_bin_sink *out)
488 zoff99 8 {
489 zoff99 37 //fprintf(stderr,"ocean_tile2:Enter\n");
490    
491 zoff99 8 struct item_bin *ib;
492 zoff99 37 int w = r->h.x - r->l.x;
493     int h = r->h.y - r->l.y;
494 zoff99 8 char tile2[32];
495     struct rect bbox;
496     struct coord co;
497 zoff99 37 bbox.l.x = r->l.x + dx * w;
498     bbox.l.y = r->l.y + dy * h;
499     bbox.h.x = bbox.l.x + w * wf;
500     bbox.h.y = bbox.l.y + h * hf;
501 zoff99 8 //fprintf(stderr,"0x%x,0x%x-0x%x,0x%x -> 0x%x,0x%x-0x%x,0x%x\n",r->l.x,r->l.y,r->h.x,r->h.y,bbox.l.x,bbox.l.y,bbox.h.x,bbox.h.y);
502 zoff99 37 ib = init_item(type_poly_water_tiled, 0);
503 zoff99 8 item_bin_bbox(ib, &bbox);
504     item_bin_write_to_sink(ib, out, NULL);
505     #if 0
506     item_bin_init(ib, type_border_country);
507     item_bin_bbox(ib, &bbox);
508     item_bin_add_attr_string(ib, attr_debug, tile2);
509     item_bin_write_to_sink(ib, out, NULL);
510     #endif
511     tile(&bbox, NULL, tile2, 32, 0, NULL);
512 zoff99 37 co.x = (bbox.l.x + bbox.h.x) / 2;
513     co.y = (bbox.l.y + bbox.h.y) / 2;
514 zoff99 8 //item_bin_write_debug_point_to_sink(out, &co, "%s 15",tile2);
515     }
516    
517 zoff99 37 static void tile_collector_add_siblings2(char *tile, void *edgesp, struct coastline_tile_data *data)
518 zoff99 8 {
519 zoff99 37 int edges = (int) edgesp;
520     int pedges = 0;
521     int debug = 0;
522     int len = strlen(tile);
523     char *tile2 = g_alloca(sizeof(char) * (len + 1));
524     char t = tile[len - 1];
525 zoff99 8 strcpy(tile2, tile);
526 zoff99 37 tile2[len - 1] = '\0';
527 zoff99 8 #if 0
528     if (!strncmp(tile,"bcacccaadbdcd",10))
529 zoff99 37 debug=1;
530 zoff99 8 #endif
531 zoff99 37 if (debug)
532     fprintf(stderr, "len of %s %d vs %d\n", tile, len, data->level);
533 zoff99 8 if (len != data->level)
534     return;
535    
536     if (debug)
537 zoff99 37 fprintf(stderr, "checking siblings of '%s' with %d edges active\n", tile, edges);
538 zoff99 8 if (t == 'b' && (edges & 1) && (tile_sibling_edges(data->tile_edges, tile, 'd') & 1))
539 zoff99 37 pedges |= 1;
540 zoff99 8 if (t == 'd' && (edges & 2) && (tile_sibling_edges(data->tile_edges, tile, 'b') & 1))
541 zoff99 37 pedges |= 1;
542 zoff99 8 if (t == 'a' && (edges & 2) && (tile_sibling_edges(data->tile_edges, tile, 'b') & 2))
543 zoff99 37 pedges |= 2;
544 zoff99 8 if (t == 'b' && (edges & 2) && (tile_sibling_edges(data->tile_edges, tile, 'a') & 2))
545 zoff99 37 pedges |= 2;
546 zoff99 8 if (t == 'a' && (edges & 4) && (tile_sibling_edges(data->tile_edges, tile, 'c') & 4))
547 zoff99 37 pedges |= 4;
548 zoff99 8 if (t == 'c' && (edges & 4) && (tile_sibling_edges(data->tile_edges, tile, 'a') & 4))
549 zoff99 37 pedges |= 4;
550 zoff99 8 if (t == 'd' && (edges & 8) && (tile_sibling_edges(data->tile_edges, tile, 'c') & 8))
551 zoff99 37 pedges |= 8;
552 zoff99 8 if (t == 'c' && (edges & 8) && (tile_sibling_edges(data->tile_edges, tile, 'd') & 8))
553 zoff99 37 pedges |= 8;
554 zoff99 8 if (debug)
555 zoff99 37 fprintf(stderr, "result '%s' %d old %d\n", tile2, pedges, (int) g_hash_table_lookup(data->tile_edges, tile2));
556     g_hash_table_insert(data->tile_edges, g_strdup(tile2), (void *) ((int) g_hash_table_lookup(data->tile_edges, tile2) | pedges));
557 zoff99 8 }
558    
559 zoff99 37 static int tile_collector_finish(struct item_bin_sink_func *tile_collector)
560 zoff99 8 {
561     struct coastline_tile_data data;
562     int i;
563     GHashTable *hash;
564 zoff99 37 data.sink = tile_collector;
565     data.tile_edges = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
566     hash = tile_collector->priv_data[0];
567     if (verbose_mode) fprintf(stderr, "tile_collector_finish\n");
568 zoff99 8 g_hash_table_foreach(hash, (GHFunc) tile_collector_process_tile, &data);
569 zoff99 37 if (verbose_mode) fprintf(stderr, "tile_collector_finish foreach done\n");
570 zoff99 8 g_hash_table_destroy(hash);
571 zoff99 37 //fprintf(stderr,"tile_collector_finish destroy done\n");
572     for (i = 14; i > 0; i--)
573     {
574     if (verbose_mode) fprintf(stderr, "Level=%d\n", i);
575     data.level = i;
576 zoff99 8 g_hash_table_foreach(data.tile_edges, (GHFunc) tile_collector_add_siblings, &data);
577 zoff99 37 if (verbose_mode) fprintf(stderr, "*");
578 zoff99 8 g_hash_table_foreach(data.tile_edges, (GHFunc) tile_collector_add_siblings, &data);
579 zoff99 37 if (verbose_mode) fprintf(stderr, "*");
580 zoff99 8 g_hash_table_foreach(data.tile_edges, (GHFunc) tile_collector_add_siblings, &data);
581 zoff99 37 if (verbose_mode) fprintf(stderr, "*");
582 zoff99 8 g_hash_table_foreach(data.tile_edges, (GHFunc) tile_collector_add_siblings, &data);
583 zoff99 37 if (verbose_mode) fprintf(stderr, "*");
584 zoff99 8 g_hash_table_foreach(data.tile_edges, (GHFunc) tile_collector_add_siblings2, &data);
585 zoff99 37 if (verbose_mode) fprintf(stderr, "*\n");
586 zoff99 8 g_hash_table_foreach(data.tile_edges, (GHFunc) tile_collector_add_siblings2, &data);
587 zoff99 37 if (verbose_mode) fprintf(stderr, "*\n");
588 zoff99 8 g_hash_table_foreach(data.tile_edges, (GHFunc) tile_collector_add_siblings2, &data);
589 zoff99 37 if (verbose_mode) fprintf(stderr, "*\n");
590 zoff99 8 g_hash_table_foreach(data.tile_edges, (GHFunc) tile_collector_add_siblings2, &data);
591 zoff99 37 if (verbose_mode) fprintf(stderr, "*\n");
592 zoff99 8 }
593     #if 0
594     data.level=13;
595     g_hash_table_foreach(data.tile_edges, tile_collector_add_siblings, &data);
596     g_hash_table_foreach(data.tile_edges, tile_collector_add_siblings, &data);
597     g_hash_table_foreach(data.tile_edges, tile_collector_add_siblings2, &data);
598     data.level=12;
599     g_hash_table_foreach(data.tile_edges, tile_collector_add_siblings, &data);
600     g_hash_table_foreach(data.tile_edges, tile_collector_add_siblings, &data);
601     #endif
602     item_bin_sink_func_destroy(tile_collector);
603 zoff99 37 //fprintf(stderr,"tile_collector_finish done\n");
604 zoff99 8 return 0;
605     }
606    
607 zoff99 37 static int coastline_processor_process(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data)
608 zoff99 8 {
609     #if 0
610     int i;
611     struct coord *c=(struct coord *)(ib+1);
612 zoff99 37 for (i = 0; i < 19; i++)
613     {
614 zoff99 8 c[i]=c[i+420];
615     }
616     ib->clen=(i-1)*2;
617     #endif
618     item_bin_write_clipped(ib, func->priv_data[0], func->priv_data[1]);
619     return 0;
620     }
621    
622     static struct item_bin_sink_func *
623     coastline_processor_new(struct item_bin_sink *out)
624     {
625 zoff99 37 struct item_bin_sink_func *coastline_processor = item_bin_sink_func_new(coastline_processor_process);
626     struct item_bin_sink *tiles = item_bin_sink_new();
627     struct item_bin_sink_func *tile_collector = tile_collector_new(out);
628 zoff99 8 struct tile_parameter *param=g_new0(struct tile_parameter, 1);
629    
630 zoff99 37 //fprintf(stderr,"new:out=%p\n",out);
631     param->min = 14;
632     param->max = 14;
633     param->overlap = 0;
634 zoff99 8
635     item_bin_sink_add_func(tiles, tile_collector);
636 zoff99 37 coastline_processor->priv_data[0] = param;
637     coastline_processor->priv_data[1] = tiles;
638     coastline_processor->priv_data[2] = tile_collector;
639 zoff99 8 return coastline_processor;
640     }
641    
642 zoff99 37 static void coastline_processor_finish(struct item_bin_sink_func *coastline_processor)
643 zoff99 8 {
644 zoff99 37 struct tile_parameter *param = coastline_processor->priv_data[0];
645     struct item_bin_sink *tiles = coastline_processor->priv_data[1];
646     struct item_bin_sink_func *tile_collector = coastline_processor->priv_data[2];
647 zoff99 8 g_free(param);
648     tile_collector_finish(tile_collector);
649     item_bin_sink_destroy(tiles);
650     item_bin_sink_func_destroy(coastline_processor);
651     }
652    
653 zoff99 37 void process_coastlines(FILE *in, FILE *out)
654 zoff99 8 {
655 zoff99 37 struct item_bin_sink *reader = file_reader_new(in, 1000000, 0);
656     struct item_bin_sink_func *file_writer = file_writer_new(out);
657     struct item_bin_sink *result = item_bin_sink_new();
658     struct item_bin_sink_func *coastline_processor = coastline_processor_new(result);
659 zoff99 8 item_bin_sink_add_func(reader, coastline_processor);
660     item_bin_sink_add_func(result, file_writer);
661     file_reader_finish(reader);
662     coastline_processor_finish(coastline_processor);
663     file_writer_finish(file_writer);
664     item_bin_sink_destroy(result);
665     }
666 zoff99 37

   
Visit the ZANavi Wiki