]> git.mxchange.org Git - flightgear.git/blob - DemChop/demchop.cxx
Initial revision.
[flightgear.git] / DemChop / demchop.cxx
1 // demchop.cxx -- chop up a dem file into it's corresponding pieces and stuff
2 //                them into the workspace directory
3 //
4 // Written by Curtis Olson, started March 1999.
5 //
6 // Copyright (C) 1997  Curtis L. Olson  - curt@flightgear.org
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 // $Id$
23 // (Log is kept at end of this file)
24
25
26 #include <Include/compiler.h>
27
28 #include STL_STRING
29
30 #include <Debug/logstream.hxx>
31 #include <Bucket/newbucket.hxx>
32 #include <DEM/dem.hxx>
33
34 FG_USING_STD(string);
35
36
37 int main(int argc, char **argv) {
38     /*
39     fgDEM dem;
40     FGBucket p;
41     string fg_root;
42     string filename;
43     double error;
44     int i, j;
45     */
46
47     fglog().setLogLevels( FG_ALL, FG_DEBUG );
48
49     if ( argc != 4 ) {
50         FG_LOG( FG_GENERAL, FG_ALERT, 
51                 "Usage " << argv[0] << " <dem_file> <work_dir>" );
52         exit(-1);
53     }
54
55     string dem_name = argv[1];
56     string work_dir = argv[2];
57     string command = "mkdir -p " + work_dir;
58     system( command.c_str() );
59
60     fgDEM dem(dem_name);
61     dem.parse();
62     dem.close();
63
64     point2d min, max;
65     min.x = dem.get_originx() / 3600.0;
66     min.y = dem.get_originy() / 3600.0;
67     FGBucket b_min( min.x, min.y );
68
69     max.x = min.x + ( dem.get_cols() * dem.get_col_step() ) / 3600.0;
70     max.y = min.y + ( dem.get_rows() * dem.get_row_step() ) / 3600.0;
71     FGBucket b_max( max.x, max.y );
72
73     if ( b_min == b_max ) {
74         dem.write_area( b_min );
75     } else {
76         FGBucket b_cur;
77         int dx, dy, i, j;
78
79         fgBucketDiff(b_min, b_max, &dx, &dy);
80         cout << "DEM file spans tile boundaries" << endl;
81         cout << "  dx = " << dx << "  dy = " << dy << endl;
82
83         if ( (dx > 20) || (dy > 20) ) {
84             cout << "somethings really wrong!!!!" << endl;
85             exit(-1);
86         }
87
88         for ( j = 0; j <= dy; j++ ) {
89             for ( i = 0; i <= dx; i++ ) {
90                 b_cur = fgBucketOffset(min.x, min.y, i, j);
91                 if ( b_cur == b ) {
92                     dem.write_area( b_cur );
93                 } else {
94                     dem.write_area( b_cur );
95                 }
96             }
97         }
98     }
99
100     return 0;
101 }
102
103
104 // $Log$
105 // Revision 1.1  1999/03/10 01:02:54  curt
106 // Initial revision.
107 //