]> git.mxchange.org Git - flightgear.git/blob - Clipper/testclipper.cxx
Renamed main.cxx to testclipper.cxx
[flightgear.git] / Clipper / testclipper.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 <Debug/logstream.hxx>
27 #include <Bucket/newbucket.hxx>
28
29 #include "clipper.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     FGClipper clipper;
41     clipper.init();
42
43     if ( argc < 2 ) {
44         FG_LOG( FG_CLIPPER, FG_ALERT, "Usage: " << argv[0] 
45                 << " file1 file2 ..." );
46         exit(-1);
47     }
48
49     // process all specified polygon files
50     for ( int i = 1; i < argc; i++ ) {
51         string full_path = argv[i];
52
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;
57
58         pos = file_name.find(".");
59         string base_name = file_name.substr(0, pos);
60         cout << "base_name = " << base_name << endl;
61
62         long int index;
63         sscanf( base_name.c_str(), "%ld", &index);
64         FGBucket b(index);
65         cout << "bucket = " << b << endl;
66
67         // calculate bucket dimensions
68         point2d c, min, max;
69
70         c.x = b.get_center_lon();
71         c.y = b.get_center_lat();
72         double span = bucket_span(c.y);
73
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) {
80             min.x = -90.0;
81             max.x = -89.0;
82             min.y = -180.0;
83             max.y = 180.0;
84         } else if ( c.y >= 89.0) {
85             min.x = 89.0;
86             max.x = 90.0;
87             min.y = -180.0;
88             max.y = 180.0;
89         } else {
90             FG_LOG ( FG_GENERAL, FG_ALERT, 
91                      "Out of range latitude in clip_and_write_poly() = " 
92                      << c.y );
93         }
94
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;
99
100         // finally, load the polygon(s) from this file
101         clipper.load_polys( full_path );
102     }
103
104     // do the clipping
105     clipper.clip_all(global_min, global_max);
106
107     FG_LOG( FG_CLIPPER, FG_INFO, "finished main" );
108
109     return 0;
110 }
111
112 // $Log$
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.
116 //
117 // Revision 1.1  1999/03/01 15:39:39  curt
118 // Initial revision.
119 //