]> git.mxchange.org Git - flightgear.git/blob - DEM/dem.hxx
44e91a8b011cb14a2921e7b84afd909f6b6d4e9a
[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/bucketutils.h>
39
40 //#include <zlib/zlib.h>
41 #include <Misc/fgstream.hxx>
42
43
44 #define DEM_SIZE 1200
45 #define DEM_SIZE_1 1201
46
47
48 class fgDEM {
49     // file pointer for input
50     // gzFile fd;
51     fg_gzifstream *in;
52
53     // coordinates (in arc seconds) of south west corner
54     double originx, originy;
55     
56     // number of columns and rows
57     int cols, rows;
58     
59     // Distance between column and row data points (in arc seconds)
60     double col_step, row_step;
61     
62     // pointers to the actual mesh data allocated here
63     float (*dem_data)[DEM_SIZE_1];
64     float (*output_data)[DEM_SIZE_1];
65
66     // Current "A" Record Information
67     char dem_description[80], dem_quadrangle[80];
68     double dem_x1, dem_y1, dem_x2, dem_y2, dem_x3, dem_y3, dem_x4, dem_y4;
69     double dem_z1, dem_z2;
70     int dem_resolution, dem_num_profiles;
71   
72     // Current "B" Record Information
73     int prof_col, prof_row;
74     int prof_num_cols, prof_num_rows;
75     double prof_x1, prof_y1;
76     int prof_data;
77
78     // temporary values for the class to use
79     char option_name[32];
80     int do_data;
81     int cur_col, cur_row;
82
83     // return next token from input stream
84     string next_token();
85
86     // return next integer from input stream
87     int next_int();
88
89     // return next double from input stream
90     double next_double();
91
92     // return next exponential num from input stream
93     double next_exp();
94
95 public:
96
97     // Constructor
98     fgDEM( void );
99     fgDEM( const string& file );
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     // Informational methods
117     double get_originx( void ) { return originx; }
118     double get_originy( void ) { return originy; }
119     int get_cols( void ) { return cols; }
120     int get_rows( void ) { return rows; }
121     double get_col_step( void ) { return col_step; }
122     double get_row_step( void ) { return row_step; }
123
124     // return the current altitude based on mesh data.  We should
125     // rewrite this to interpolate exact values, but for now this is
126     // good enough
127     double interpolate_altitude( double lon, double lat );
128
129     // Use least squares to fit a simpler data set to dem data
130     void fit( double error, fgBUCKET *p );
131
132     // Initialize output mesh structure
133     void outputmesh_init( void );
134
135     // Get the value of a mesh node
136     double outputmesh_get_pt( int i, int j );
137
138     // Set the value of a mesh node
139     void outputmesh_set_pt( int i, int j, double value );
140
141     // Write out a node file that can be used by the "triangle" program
142     void outputmesh_output_nodes( const string& fg_root, fgBUCKET *p );
143
144     // Destructor
145     ~fgDEM( void );
146 };
147
148
149 #endif // _DEM_H
150
151
152 // $Log$
153 // Revision 1.10  1999/03/10 01:09:13  curt
154 // Tweaks to go along with scenery tools overhaul.
155 // Added a new constructor that accepts the file name.
156 //
157 // Revision 1.9  1998/10/16 19:08:14  curt
158 // Portability updates from Bernie Bright.
159 //
160 // Revision 1.8  1998/09/19 17:59:46  curt
161 // Use c++ streams (fg_gzifstream).  Also converted many character arrays to
162 // the string class.
163 //
164 // Revision 1.7  1998/07/04 00:47:19  curt
165 // typedef'd struct fgBUCKET.
166 //
167 // Revision 1.6  1998/06/05 18:14:40  curt
168 // Abort out early when reading the "A" record if it doesn't look like
169 // a proper DEM file.
170 //
171 // Revision 1.5  1998/04/22 13:14:46  curt
172 // Fixed a bug in zlib usage.
173 //
174 // Revision 1.4  1998/04/21 17:03:41  curt
175 // Prepairing for C++ integration.
176 //
177 // Revision 1.3  1998/04/18 03:53:06  curt
178 // Added zlib support.
179 //
180 // Revision 1.2  1998/04/14 02:43:28  curt
181 // Used "new" to auto-allocate large DEM parsing arrays in class constructor.
182 //
183 // Revision 1.1  1998/04/08 22:57:23  curt
184 // Adopted Gnu automake/autoconf system.
185 //
186 // Revision 1.2  1998/03/23 20:35:42  curt
187 // Updated to use FG_EPSILON
188 //
189 // Revision 1.1  1998/03/19 02:54:47  curt
190 // Reorganized into a class lib called fgDEM.
191 //
192 // Revision 1.1  1998/03/19 01:46:29  curt
193 // Initial revision.
194 //