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