1999-03-13 17:40:36 +00:00
|
|
|
// dem.hxx -- DEM management class
|
1998-03-19 02:54:46 +00:00
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started March 1998.
|
|
|
|
//
|
1999-03-13 17:40:36 +00:00
|
|
|
// Copyright (C) 1998 Curtis L. Olson - curt@flightgear.org
|
1998-03-19 02:54:46 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
1999-03-13 17:40:36 +00:00
|
|
|
#ifndef _DEM_HXX
|
|
|
|
#define _DEM_HXX
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
|
1998-04-21 17:03:41 +00:00
|
|
|
#ifndef __cplusplus
|
|
|
|
# error This library requires C++
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1999-03-11 23:31:56 +00:00
|
|
|
#include <Bucket/newbucket.hxx>
|
1998-09-19 17:59:45 +00:00
|
|
|
#include <Misc/fgstream.hxx>
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define DEM_SIZE 1200
|
|
|
|
#define DEM_SIZE_1 1201
|
|
|
|
|
|
|
|
|
1999-03-12 22:53:07 +00:00
|
|
|
class FGDem {
|
1999-03-11 23:31:56 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
1998-03-19 02:54:46 +00:00
|
|
|
// file pointer for input
|
1998-09-19 17:59:45 +00:00
|
|
|
// gzFile fd;
|
|
|
|
fg_gzifstream *in;
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// coordinates (in arc seconds) of south west corner
|
|
|
|
double originx, originy;
|
|
|
|
|
|
|
|
// number of columns and rows
|
|
|
|
int cols, rows;
|
|
|
|
|
|
|
|
// Distance between column and row data points (in arc seconds)
|
|
|
|
double col_step, row_step;
|
|
|
|
|
1999-03-12 22:53:07 +00:00
|
|
|
// pointers to the actual grid data allocated here
|
1998-04-14 02:43:27 +00:00
|
|
|
float (*dem_data)[DEM_SIZE_1];
|
|
|
|
float (*output_data)[DEM_SIZE_1];
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// Current "A" Record Information
|
|
|
|
char dem_description[80], dem_quadrangle[80];
|
|
|
|
double dem_x1, dem_y1, dem_x2, dem_y2, dem_x3, dem_y3, dem_x4, dem_y4;
|
|
|
|
double dem_z1, dem_z2;
|
|
|
|
int dem_resolution, dem_num_profiles;
|
|
|
|
|
|
|
|
// Current "B" Record Information
|
|
|
|
int prof_col, prof_row;
|
|
|
|
int prof_num_cols, prof_num_rows;
|
|
|
|
double prof_x1, prof_y1;
|
|
|
|
int prof_data;
|
|
|
|
|
|
|
|
// temporary values for the class to use
|
|
|
|
char option_name[32];
|
|
|
|
int do_data;
|
|
|
|
int cur_col, cur_row;
|
|
|
|
|
1998-09-19 17:59:45 +00:00
|
|
|
// return next token from input stream
|
|
|
|
string next_token();
|
|
|
|
|
|
|
|
// return next integer from input stream
|
|
|
|
int next_int();
|
|
|
|
|
|
|
|
// return next double from input stream
|
|
|
|
double next_double();
|
|
|
|
|
|
|
|
// return next exponential num from input stream
|
1998-10-16 19:08:12 +00:00
|
|
|
double next_exp();
|
1998-09-19 17:59:45 +00:00
|
|
|
|
1998-03-19 02:54:46 +00:00
|
|
|
public:
|
|
|
|
|
1998-04-22 13:14:46 +00:00
|
|
|
// Constructor
|
1999-03-12 22:53:07 +00:00
|
|
|
FGDem( void );
|
|
|
|
FGDem( const string& file );
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1999-03-11 23:31:56 +00:00
|
|
|
// Destructor
|
1999-03-12 22:53:07 +00:00
|
|
|
~FGDem( void );
|
1999-03-11 23:31:56 +00:00
|
|
|
|
1998-03-19 02:54:46 +00:00
|
|
|
// open a DEM file (use "-" if input is coming from stdin)
|
1998-09-19 17:59:45 +00:00
|
|
|
int open ( const string& file );
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// close a DEM file
|
1999-03-11 23:31:56 +00:00
|
|
|
int close();
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// parse a DEM file
|
1998-09-19 17:59:45 +00:00
|
|
|
int parse();
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// read and parse DEM "A" record
|
1998-09-19 17:59:45 +00:00
|
|
|
int read_a_record();
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// read and parse DEM "B" record
|
1998-09-19 17:59:45 +00:00
|
|
|
void read_b_record();
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1999-03-12 22:53:07 +00:00
|
|
|
// write out the area of data covered by the specified bucket.
|
|
|
|
// Data is written out column by column starting at the lower left
|
|
|
|
// hand corner.
|
|
|
|
int write_area( const string& root, FGBucket& b, bool compress );
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// return the current altitude based on grid data. We should
|
1998-03-19 02:54:46 +00:00
|
|
|
// rewrite this to interpolate exact values, but for now this is
|
|
|
|
// good enough
|
1998-04-14 02:43:27 +00:00
|
|
|
double interpolate_altitude( double lon, double lat );
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// Use least squares to fit a simpler data set to dem data
|
1999-03-12 22:53:07 +00:00
|
|
|
void fit( double error, FGBucket& p );
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// Initialize output mesh structure
|
1998-04-14 02:43:27 +00:00
|
|
|
void outputmesh_init( void );
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// Get the value of a mesh node
|
1998-04-14 02:43:27 +00:00
|
|
|
double outputmesh_get_pt( int i, int j );
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// Set the value of a mesh node
|
1998-04-14 02:43:27 +00:00
|
|
|
void outputmesh_set_pt( int i, int j, double value );
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// Write out a node file that can be used by the "triangle" program
|
1999-03-12 22:53:07 +00:00
|
|
|
void outputmesh_output_nodes( const string& fg_root, FGBucket& p );
|
|
|
|
#endif
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1999-03-11 23:31:56 +00:00
|
|
|
// Informational methods
|
|
|
|
inline double get_originx() const { return originx; }
|
|
|
|
inline double get_originy() const { return originy; }
|
|
|
|
inline int get_cols() const { return cols; }
|
|
|
|
inline int get_rows() const { return rows; }
|
|
|
|
inline double get_col_step() const { return col_step; }
|
|
|
|
inline double get_row_step() const { return row_step; }
|
1998-03-19 02:54:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-03-13 17:40:36 +00:00
|
|
|
#endif // _DEM_HXX
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
|