]> git.mxchange.org Git - flightgear.git/blob - DEM/dem.hxx
Dynamically update "error" until the resulting tile data scales within
[flightgear.git] / DEM / dem.hxx
1 // dem.hxx -- DEM management class
2 //
3 // Written by Curtis Olson, started March 1998.
4 //
5 // Copyright (C) 1998  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 #ifndef _DEM_HXX
26 #define _DEM_HXX
27
28
29 #ifndef __cplusplus                                                          
30 # error This library requires C++
31 #endif                                   
32
33
34 #include <Bucket/newbucket.hxx>
35 #include <Misc/fgstream.hxx>
36
37
38 #define DEM_SIZE 1200
39 #define DEM_SIZE_1 1201
40
41
42 class FGDem {
43
44 private:
45
46     // file pointer for input
47     // gzFile fd;
48     fg_gzifstream *in;
49
50     // coordinates (in arc seconds) of south west corner
51     double originx, originy;
52     
53     // number of columns and rows
54     int cols, rows;
55     
56     // Distance between column and row data points (in arc seconds)
57     double col_step, row_step;
58     
59     // pointers to the actual grid data allocated here
60     float (*dem_data)[DEM_SIZE_1];
61     float (*output_data)[DEM_SIZE_1];
62
63     // Current "A" Record Information
64     char dem_description[80], dem_quadrangle[80];
65     double dem_x1, dem_y1, dem_x2, dem_y2, dem_x3, dem_y3, dem_x4, dem_y4;
66     double dem_z1, dem_z2;
67     int dem_resolution, dem_num_profiles;
68   
69     // Current "B" Record Information
70     int prof_col, prof_row;
71     int prof_num_cols, prof_num_rows;
72     double prof_x1, prof_y1;
73     int prof_data;
74
75     // temporary values for the class to use
76     char option_name[32];
77     int do_data;
78     int cur_col, cur_row;
79
80     // return next token from input stream
81     string next_token();
82
83     // return next integer from input stream
84     int next_int();
85
86     // return next double from input stream
87     double next_double();
88
89     // return next exponential num from input stream
90     double next_exp();
91
92 public:
93
94     // Constructor
95     FGDem( void );
96     FGDem( const string& file );
97
98     // Destructor
99     ~FGDem( void );
100
101     // open a DEM file (use "-" if input is coming from stdin)
102     int open ( const string& file );
103
104     // close a DEM file
105     int close();
106
107     // parse a DEM file
108     int parse();
109
110     // read and parse DEM "A" record
111     int read_a_record();
112
113     // read and parse DEM "B" record
114     void read_b_record();
115
116     // write out the area of data covered by the specified bucket.
117     // Data is written out column by column starting at the lower left
118     // hand corner.
119     int write_area( const string& root, FGBucket& b, bool compress );
120
121 #if 0
122     // return the current altitude based on grid data.  We should
123     // rewrite this to interpolate exact values, but for now this is
124     // good enough
125     double interpolate_altitude( double lon, double lat );
126
127     // Use least squares to fit a simpler data set to dem data
128     void fit( double error, FGBucket& p );
129
130     // Initialize output mesh structure
131     void outputmesh_init( void );
132
133     // Get the value of a mesh node
134     double outputmesh_get_pt( int i, int j );
135
136     // Set the value of a mesh node
137     void outputmesh_set_pt( int i, int j, double value );
138
139     // Write out a node file that can be used by the "triangle" program
140     void outputmesh_output_nodes( const string& fg_root, FGBucket& p );
141 #endif
142
143     // Informational methods
144     inline double get_originx() const { return originx; }
145     inline double get_originy() const { return originy; }
146     inline int get_cols() const { return cols; }
147     inline int get_rows() const { return rows; }
148     inline double get_col_step() const { return col_step; }
149     inline double get_row_step() const { return row_step; }
150 };
151
152
153 #endif // _DEM_HXX
154
155
156 // $Log$
157 // Revision 1.13  1999/03/13 17:40:39  curt
158 // Moved point interpolation and least squares fitting to contruction program
159 // area.
160 // Moved leastsqs.* to Lib/Math/
161 //
162 // Revision 1.12  1999/03/12 22:53:09  curt
163 // Added a routine to dump out the portion of the dem data covered by a
164 // specified bucket.  Other changes related to needs of scenery tools overhaul.
165 //
166 // Revision 1.11  1999/03/11 23:31:57  curt
167 // Tweaks to use newbucket.hxx
168 //
169 // Revision 1.10  1999/03/10 01:09:13  curt
170 // Tweaks to go along with scenery tools overhaul.
171 // Added a new constructor that accepts the file name.
172 //
173 // Revision 1.9  1998/10/16 19:08:14  curt
174 // Portability updates from Bernie Bright.
175 //
176 // Revision 1.8  1998/09/19 17:59:46  curt
177 // Use c++ streams (fg_gzifstream).  Also converted many character arrays to
178 // the string class.
179 //
180 // Revision 1.7  1998/07/04 00:47:19  curt
181 // typedef'd struct fgBUCKET.
182 //
183 // Revision 1.6  1998/06/05 18:14:40  curt
184 // Abort out early when reading the "A" record if it doesn't look like
185 // a proper DEM file.
186 //
187 // Revision 1.5  1998/04/22 13:14:46  curt
188 // Fixed a bug in zlib usage.
189 //
190 // Revision 1.4  1998/04/21 17:03:41  curt
191 // Prepairing for C++ integration.
192 //
193 // Revision 1.3  1998/04/18 03:53:06  curt
194 // Added zlib support.
195 //
196 // Revision 1.2  1998/04/14 02:43:28  curt
197 // Used "new" to auto-allocate large DEM parsing arrays in class constructor.
198 //
199 // Revision 1.1  1998/04/08 22:57:23  curt
200 // Adopted Gnu automake/autoconf system.
201 //
202 // Revision 1.2  1998/03/23 20:35:42  curt
203 // Updated to use FG_EPSILON
204 //
205 // Revision 1.1  1998/03/19 02:54:47  curt
206 // Reorganized into a class lib called fgDEM.
207 //
208 // Revision 1.1  1998/03/19 01:46:29  curt
209 // Initial revision.
210 //