]> git.mxchange.org Git - flightgear.git/blob - Clipper/main.cxx
Initial revision.
[flightgear.git] / Clipper / main.cxx
1 // main.cxx -- sample use of the clipper lib
2 //
3 // Written by Curtis Olson, started February 1999.
4 //
5 // Copyright (C) 1999  Curtis L. Olson  - curt@flightgear.org
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22 // (Log is kept at end of this file)
23  
24
25
26 #include "clipper.hxx"
27
28 #include <Debug/logstream.hxx>
29 #include <Bucket/newbucket.hxx>
30
31
32 int main( int argc, char **argv ) {
33     point2d global_min, global_max;
34
35     fglog().setLogLevels( FG_ALL, FG_DEBUG );
36
37     global_min.x = global_min.y = 200;
38     global_max.y = global_max.x = -200;
39
40     fgClipperInit();
41
42     if ( argc < 2 ) {
43         FG_LOG( FG_CLIPPER, FG_ALERT, "Usage: " << argv[0] 
44                 << " file1 file2 ..." );
45         exit(-1);
46     }
47
48     // process all specified polygon files
49     for ( int i = 1; i < argc; i++ ) {
50         string full_path = argv[i];
51
52         // determine bucket for this polygon
53         int pos = full_path.rfind("/");
54         string file_name = full_path.substr(pos + 1);
55         cout << "file name = " << file_name << endl;
56
57         pos = file_name.find(".");
58         string base_name = file_name.substr(0, pos);
59         cout << "base_name = " << base_name << endl;
60
61         long int index;
62         sscanf( base_name.c_str(), "%ld", &index);
63         FGBucket b(index);
64         cout << "bucket = " << b << endl;
65
66         // calculate bucket dimensions
67         point2d c, min, max;
68
69         c.x = b.get_center_lon();
70         c.y = b.get_center_lat();
71         double span = bucket_span(c.y);
72
73         if ( (c.y >= -89.0) && (c.y < 89.0) ) {
74             min.x = c.x - span / 2.0;
75             max.x = c.x + span / 2.0;
76             min.y = c.y - FG_HALF_BUCKET_SPAN;
77             max.y = c.y + FG_HALF_BUCKET_SPAN;
78         } else if ( c.y < -89.0) {
79             min.x = -90.0;
80             max.x = -89.0;
81             min.y = -180.0;
82             max.y = 180.0;
83         } else if ( c.y >= 89.0) {
84             min.x = 89.0;
85             max.x = 90.0;
86             min.y = -180.0;
87             max.y = 180.0;
88         } else {
89             FG_LOG ( FG_GENERAL, FG_ALERT, 
90                      "Out of range latitude in clip_and_write_poly() = " 
91                      << c.y );
92         }
93
94         if ( min.x < global_min.x ) global_min.x = min.x;
95         if ( min.y < global_min.y ) global_min.y = min.y;
96         if ( max.x > global_max.x ) global_max.x = max.x;
97         if ( max.y > global_max.y ) global_max.y = max.y;
98
99         // finally, load the polygon(s) from this file
100         fgClipperLoadPolygons( full_path );
101     }
102
103     // do the clipping
104     fgClipperMaster(global_min, global_max);
105
106     FG_LOG( FG_CLIPPER, FG_INFO, "finished main" );
107
108     return 0;
109 }
110
111 // $Log$
112 // Revision 1.1  1999/03/01 15:39:39  curt
113 // Initial revision.
114 //