3 // dem.h -- DEM management class
5 // Written by Curtis Olson, started March 1998.
7 // Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 // (Log is kept at end of this file)
32 # error This library requires C++
38 #include <Bucket/newbucket.hxx>
39 #include <Misc/fgstream.hxx>
43 #define DEM_SIZE_1 1201
50 // file pointer for input
54 // coordinates (in arc seconds) of south west corner
55 double originx, originy;
57 // number of columns and rows
60 // Distance between column and row data points (in arc seconds)
61 double col_step, row_step;
63 // pointers to the actual grid data allocated here
64 float (*dem_data)[DEM_SIZE_1];
65 float (*output_data)[DEM_SIZE_1];
67 // Current "A" Record Information
68 char dem_description[80], dem_quadrangle[80];
69 double dem_x1, dem_y1, dem_x2, dem_y2, dem_x3, dem_y3, dem_x4, dem_y4;
70 double dem_z1, dem_z2;
71 int dem_resolution, dem_num_profiles;
73 // Current "B" Record Information
74 int prof_col, prof_row;
75 int prof_num_cols, prof_num_rows;
76 double prof_x1, prof_y1;
79 // temporary values for the class to use
84 // return next token from input stream
87 // return next integer from input stream
90 // return next double from input stream
93 // return next exponential num from input stream
100 FGDem( const string& file );
105 // open a DEM file (use "-" if input is coming from stdin)
106 int open ( const string& file );
114 // read and parse DEM "A" record
117 // read and parse DEM "B" record
118 void read_b_record();
120 // write out the area of data covered by the specified bucket.
121 // Data is written out column by column starting at the lower left
123 int write_area( const string& root, FGBucket& b, bool compress );
126 // return the current altitude based on grid data. We should
127 // rewrite this to interpolate exact values, but for now this is
129 double interpolate_altitude( double lon, double lat );
131 // Use least squares to fit a simpler data set to dem data
132 void fit( double error, FGBucket& p );
134 // Initialize output mesh structure
135 void outputmesh_init( void );
137 // Get the value of a mesh node
138 double outputmesh_get_pt( int i, int j );
140 // Set the value of a mesh node
141 void outputmesh_set_pt( int i, int j, double value );
143 // Write out a node file that can be used by the "triangle" program
144 void outputmesh_output_nodes( const string& fg_root, FGBucket& p );
147 // Informational methods
148 inline double get_originx() const { return originx; }
149 inline double get_originy() const { return originy; }
150 inline int get_cols() const { return cols; }
151 inline int get_rows() const { return rows; }
152 inline double get_col_step() const { return col_step; }
153 inline double get_row_step() const { return row_step; }
161 // Revision 1.12 1999/03/12 22:53:09 curt
162 // Added a routine to dump out the portion of the dem data covered by a
163 // specified bucket. Other changes related to needs of scenery tools overhaul.
165 // Revision 1.11 1999/03/11 23:31:57 curt
166 // Tweaks to use newbucket.hxx
168 // Revision 1.10 1999/03/10 01:09:13 curt
169 // Tweaks to go along with scenery tools overhaul.
170 // Added a new constructor that accepts the file name.
172 // Revision 1.9 1998/10/16 19:08:14 curt
173 // Portability updates from Bernie Bright.
175 // Revision 1.8 1998/09/19 17:59:46 curt
176 // Use c++ streams (fg_gzifstream). Also converted many character arrays to
179 // Revision 1.7 1998/07/04 00:47:19 curt
180 // typedef'd struct fgBUCKET.
182 // Revision 1.6 1998/06/05 18:14:40 curt
183 // Abort out early when reading the "A" record if it doesn't look like
184 // a proper DEM file.
186 // Revision 1.5 1998/04/22 13:14:46 curt
187 // Fixed a bug in zlib usage.
189 // Revision 1.4 1998/04/21 17:03:41 curt
190 // Prepairing for C++ integration.
192 // Revision 1.3 1998/04/18 03:53:06 curt
193 // Added zlib support.
195 // Revision 1.2 1998/04/14 02:43:28 curt
196 // Used "new" to auto-allocate large DEM parsing arrays in class constructor.
198 // Revision 1.1 1998/04/08 22:57:23 curt
199 // Adopted Gnu automake/autoconf system.
201 // Revision 1.2 1998/03/23 20:35:42 curt
202 // Updated to use FG_EPSILON
204 // Revision 1.1 1998/03/19 02:54:47 curt
205 // Reorganized into a class lib called fgDEM.
207 // Revision 1.1 1998/03/19 01:46:29 curt