1 // main.cxx -- sample use of the clipper lib
3 // Written by Curtis Olson, started February 1999.
5 // Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
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.
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.
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.
22 // (Log is kept at end of this file)
26 #include <Debug/logstream.hxx>
27 #include <Bucket/newbucket.hxx>
29 #include "clipper.hxx"
32 int main( int argc, char **argv ) {
33 point2d global_min, global_max;
35 fglog().setLogLevels( FG_ALL, FG_DEBUG );
37 global_min.x = global_min.y = 200;
38 global_max.y = global_max.x = -200;
44 FG_LOG( FG_CLIPPER, FG_ALERT, "Usage: " << argv[0]
45 << " file1 file2 ..." );
49 // process all specified polygon files
50 for ( int i = 1; i < argc; i++ ) {
51 string full_path = argv[i];
53 // determine bucket for this polygon
54 int pos = full_path.rfind("/");
55 string file_name = full_path.substr(pos + 1);
56 cout << "file name = " << file_name << endl;
58 pos = file_name.find(".");
59 string base_name = file_name.substr(0, pos);
60 cout << "base_name = " << base_name << endl;
63 sscanf( base_name.c_str(), "%ld", &index);
65 cout << "bucket = " << b << endl;
67 // calculate bucket dimensions
70 c.x = b.get_center_lon();
71 c.y = b.get_center_lat();
72 double span = bucket_span(c.y);
74 if ( (c.y >= -89.0) && (c.y < 89.0) ) {
75 min.x = c.x - span / 2.0;
76 max.x = c.x + span / 2.0;
77 min.y = c.y - FG_HALF_BUCKET_SPAN;
78 max.y = c.y + FG_HALF_BUCKET_SPAN;
79 } else if ( c.y < -89.0) {
84 } else if ( c.y >= 89.0) {
90 FG_LOG ( FG_GENERAL, FG_ALERT,
91 "Out of range latitude in clip_and_write_poly() = "
95 if ( min.x < global_min.x ) global_min.x = min.x;
96 if ( min.y < global_min.y ) global_min.y = min.y;
97 if ( max.x > global_max.x ) global_max.x = max.x;
98 if ( max.y > global_max.y ) global_max.y = max.y;
100 // finally, load the polygon(s) from this file
101 clipper.load_polys( full_path );
105 clipper.clip_all(global_min, global_max);
107 FG_LOG( FG_CLIPPER, FG_INFO, "finished main" );
113 // Revision 1.1 1999/03/13 23:51:36 curt
114 // Renamed main.cxx to testclipper.cxx
115 // Converted clipper routines to a class FGClipper.
117 // Revision 1.1 1999/03/01 15:39:39 curt