]> git.mxchange.org Git - flightgear.git/blob - Main/construct.cxx
Initial revision.
[flightgear.git] / Main / construct.cxx
1 // main.cxx -- top level construction routines
2 //
3 // Written by Curtis Olson, started March 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
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // 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 #include <sys/types.h>  // for directory reading
26 #include <dirent.h>     // for directory reading
27
28 #include <Bucket/newbucket.hxx>
29
30 #include <Array/array.hxx>
31 #include <Clipper/clipper.hxx>
32
33
34 // load regular grid of elevation data (dem based)
35 int load_dem(const string& work_base, FGBucket& b, FGArray& array) {
36     char tile_name[256];
37     string base = b.gen_base_path();
38     long int b_index = b.gen_index();
39     sprintf(tile_name, "%ld", b_index);
40
41     string dem_path = work_base + ".dem" + "/Scenery/" + base 
42         + "/" + tile_name + ".dem";
43     cout << "dem_path = " << dem_path << endl;
44
45     if ( ! array.open(dem_path) ) {
46         return 0;
47     }
48     array.parse();
49     array.fit( 100 );
50
51     return 1;
52 }
53
54
55 // load all 2d polygons matching the specified base path and clip
56 // against each other to resolve any overlaps
57 int load_polys( const string& work_base, FGBucket& b, FGClipper& clipper) {
58     char tile_char[256];
59     string base = b.gen_base_path();
60     long int b_index = b.gen_index();
61     sprintf(tile_char, "%ld", b_index);
62     string tile_str = tile_char;
63
64     string poly_path = work_base + ".shapes" + "/Scenery/" + base;
65     cout << "poly_path = " << poly_path << endl;
66
67     DIR *d;
68     struct dirent *de;
69
70     if ( (d = opendir( poly_path.c_str() )) == NULL ) {
71         cout << "cannot open directory " << poly_path << "\n";
72         return 0;
73     }
74
75     // initialize clipper
76     clipper.init();
77
78     // load all matching polygon files
79     string file, f_index, full_path;
80     int pos;
81     while ( (de = readdir(d)) != NULL ) {
82         file = de->d_name;
83         pos = file.find(".");
84         f_index = file.substr(0, pos);
85
86         if ( tile_str == f_index ) {
87             cout << file << "  " << f_index << endl;
88             full_path = poly_path + "/" + file;
89             clipper.load_polys( full_path );
90         }
91     }
92
93     point2d min, max;
94     min.x = b.get_center_lon() - 0.5 * b.get_width();
95     min.y = b.get_center_lat() - 0.5 * b.get_height();
96     max.x = b.get_center_lon() + 0.5 * b.get_width();
97     max.y = b.get_center_lat() + 0.5 * b.get_height();
98
99     // do clipping
100     clipper.clip_all(min, max);
101
102     return 1;
103 }
104
105
106 main(int argc, char **argv) {
107     double lon, lat;
108
109     if ( argc != 2 ) {
110         cout << "Usage: " << argv[0] << " work_base" << endl;
111         exit(-1);
112     }
113
114     string work_base = argv[1];
115    
116     lon = -146.248360; lat = 61.133950;  // PAVD (Valdez, AK)
117     // lon = -110.664244; lat = 33.352890;  // P13
118     FGBucket b( lon, lat );
119
120     // load and fit grid of elevation data
121     FGArray array;
122     load_dem( work_base, b, array );
123
124     // load and clip 2d polygon data
125     FGClipper clipper;
126     load_polys( work_base, b, clipper );
127 }
128
129
130 // $Log$
131 // Revision 1.1  1999/03/14 00:03:24  curt
132 // Initial revision.
133 //
134
135