1998-03-19 02:54:46 +00:00
|
|
|
// -*- Mode: C++ -*-
|
|
|
|
//
|
|
|
|
// dem.c -- DEM management class
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started March 1998.
|
|
|
|
//
|
|
|
|
// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
|
|
|
|
//
|
|
|
|
// 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$
|
|
|
|
// (Log is kept at end of this file)
|
|
|
|
|
|
|
|
|
1998-07-13 15:29:49 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
1999-01-19 20:56:56 +00:00
|
|
|
#include <Include/compiler.h>
|
|
|
|
|
1998-03-19 02:54:46 +00:00
|
|
|
#include <ctype.h> // isspace()
|
1998-07-13 20:58:02 +00:00
|
|
|
#include <stdlib.h> // atoi()
|
1998-03-19 02:54:46 +00:00
|
|
|
#include <math.h> // rint()
|
|
|
|
#include <stdio.h>
|
1998-04-06 21:09:37 +00:00
|
|
|
#include <string.h>
|
1999-01-19 20:56:56 +00:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
# include <sys/stat.h> // stat()
|
|
|
|
#endif
|
|
|
|
#ifdef FG_HAVE_STD_INCLUDES
|
|
|
|
# include <cerrno>
|
|
|
|
#else
|
|
|
|
# include <errno.h>
|
|
|
|
#endif
|
1998-10-16 19:08:12 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h> // stat()
|
|
|
|
#endif
|
1998-09-19 17:59:45 +00:00
|
|
|
#include <string>
|
|
|
|
|
1999-01-19 20:56:56 +00:00
|
|
|
#include STL_IOSTREAM
|
|
|
|
|
1998-09-19 17:59:45 +00:00
|
|
|
// #include <zlib/zlib.h>
|
|
|
|
#include <Misc/fgstream.hxx>
|
|
|
|
#include <Misc/strutils.hxx>
|
1998-10-16 19:08:12 +00:00
|
|
|
#include <Include/compiler.h>
|
|
|
|
FG_USING_NAMESPACE(std);
|
1998-04-18 03:53:05 +00:00
|
|
|
|
1998-04-08 22:54:56 +00:00
|
|
|
#include "dem.hxx"
|
|
|
|
#include "leastsqs.hxx"
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1998-03-23 20:35:41 +00:00
|
|
|
#include <Include/fg_constants.h>
|
|
|
|
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1998-07-20 12:46:11 +00:00
|
|
|
#define MAX_EX_NODES 10000
|
|
|
|
|
1998-10-28 19:38:20 +00:00
|
|
|
#if 0
|
1998-04-06 21:09:37 +00:00
|
|
|
#ifdef WIN32
|
1998-10-16 19:08:12 +00:00
|
|
|
# ifdef __BORLANDC__
|
|
|
|
# include <dir.h>
|
|
|
|
# define MKDIR(a) mkdir(a)
|
|
|
|
# else
|
|
|
|
# define MKDIR(a) mkdir(a,S_IRWXU) // I am just guessing at this flag (NHV)
|
|
|
|
# endif // __BORLANDC__
|
1998-04-06 21:09:37 +00:00
|
|
|
#endif // WIN32
|
1998-10-28 19:38:20 +00:00
|
|
|
#endif //0
|
1998-04-06 21:09:37 +00:00
|
|
|
|
|
|
|
|
1998-03-19 02:54:46 +00:00
|
|
|
fgDEM::fgDEM( void ) {
|
|
|
|
// printf("class fgDEM CONstructor called.\n");
|
1998-04-14 02:43:27 +00:00
|
|
|
dem_data = new float[DEM_SIZE_1][DEM_SIZE_1];
|
|
|
|
output_data = new float[DEM_SIZE_1][DEM_SIZE_1];
|
1998-03-19 02:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-10-28 19:38:20 +00:00
|
|
|
#if 0
|
1998-04-06 21:09:37 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
|
|
|
|
// return the file path name ( foo/bar/file.ext = foo/bar )
|
1998-10-16 19:08:12 +00:00
|
|
|
static void extract_path ( const char *in, char *base) {
|
1998-04-06 21:09:37 +00:00
|
|
|
int len, i;
|
|
|
|
|
|
|
|
len = strlen (in);
|
|
|
|
strcpy (base, in);
|
|
|
|
|
|
|
|
i = len - 1;
|
|
|
|
while ( (i >= 0) && (in[i] != '/') ) {
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
|
|
|
|
base[i] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Make a subdirectory
|
1998-10-16 19:08:12 +00:00
|
|
|
static int my_mkdir (const char *dir) {
|
1998-04-06 21:09:37 +00:00
|
|
|
struct stat stat_buf;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
printf ("mk_dir() ");
|
|
|
|
|
|
|
|
result = stat (dir, &stat_buf);
|
|
|
|
|
|
|
|
if (result != 0) {
|
|
|
|
MKDIR (dir);
|
|
|
|
result = stat (dir, &stat_buf);
|
|
|
|
if (result != 0) {
|
|
|
|
printf ("problem creating %s\n", dir);
|
|
|
|
} else {
|
|
|
|
printf ("%s created\n", dir);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf ("%s already exists\n", dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // WIN32
|
1998-10-28 19:38:20 +00:00
|
|
|
#endif //0
|
1998-04-06 21:09:37 +00:00
|
|
|
|
|
|
|
|
1998-03-19 02:54:46 +00:00
|
|
|
// open a DEM file
|
1998-09-19 17:59:45 +00:00
|
|
|
int fgDEM::open ( const string& file ) {
|
1998-03-19 02:54:46 +00:00
|
|
|
// open input file (or read from stdin)
|
1998-09-19 17:59:45 +00:00
|
|
|
if ( file == "-" ) {
|
1998-03-19 02:54:46 +00:00
|
|
|
printf("Loading DEM data file: stdin\n");
|
1998-04-18 03:53:05 +00:00
|
|
|
// fd = stdin;
|
1998-09-19 17:59:45 +00:00
|
|
|
// fd = gzdopen(STDIN_FILENO, "r");
|
|
|
|
printf("Not yet ported ...\n");
|
|
|
|
return 0;
|
1998-03-19 02:54:46 +00:00
|
|
|
} else {
|
1998-09-19 17:59:45 +00:00
|
|
|
in = new fg_gzifstream( file );
|
1998-10-16 19:08:12 +00:00
|
|
|
if ( !(*in) ) {
|
|
|
|
cout << "Cannot open " << file << endl;
|
1998-09-19 17:59:45 +00:00
|
|
|
return 0;
|
1998-03-19 02:54:46 +00:00
|
|
|
}
|
1998-10-16 19:08:12 +00:00
|
|
|
cout << "Loading DEM data file: " << file << endl;
|
1998-03-19 02:54:46 +00:00
|
|
|
}
|
|
|
|
|
1998-09-19 17:59:45 +00:00
|
|
|
return 1;
|
1998-03-19 02:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// close a DEM file
|
1998-09-19 17:59:45 +00:00
|
|
|
int fgDEM::close () {
|
|
|
|
// the fg_gzifstream doesn't seem to have a close()
|
|
|
|
|
1998-10-16 19:08:12 +00:00
|
|
|
delete in;
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1998-09-19 17:59:45 +00:00
|
|
|
return 1;
|
1998-03-19 02:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// return next token from input stream
|
1998-09-19 17:59:45 +00:00
|
|
|
string fgDEM::next_token() {
|
|
|
|
string token;
|
1998-04-18 03:53:05 +00:00
|
|
|
|
1998-11-06 14:04:32 +00:00
|
|
|
*in >> token;
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1998-09-21 20:53:59 +00:00
|
|
|
// cout << " returning " + token + "\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1998-09-19 17:59:45 +00:00
|
|
|
return token;
|
1998-03-19 02:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// return next integer from input stream
|
1998-09-19 17:59:45 +00:00
|
|
|
int fgDEM::next_int() {
|
|
|
|
int result;
|
1998-11-06 14:04:32 +00:00
|
|
|
|
|
|
|
*in >> result;
|
1998-09-19 17:59:45 +00:00
|
|
|
|
|
|
|
return result;
|
1998-03-19 02:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// return next double from input stream
|
1998-09-19 17:59:45 +00:00
|
|
|
double fgDEM::next_double() {
|
|
|
|
double result;
|
|
|
|
|
1998-11-06 14:04:32 +00:00
|
|
|
*in >> result;
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1998-09-19 17:59:45 +00:00
|
|
|
return result;
|
1998-03-19 02:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// return next exponential num from input stream
|
1998-10-16 19:08:12 +00:00
|
|
|
double fgDEM::next_exp() {
|
1998-09-19 17:59:45 +00:00
|
|
|
string token;
|
1998-03-19 02:54:46 +00:00
|
|
|
double mantissa;
|
|
|
|
int exp, acc;
|
|
|
|
int i;
|
|
|
|
|
1998-09-19 17:59:45 +00:00
|
|
|
token = next_token();
|
1998-04-18 03:53:05 +00:00
|
|
|
|
1998-10-16 19:08:12 +00:00
|
|
|
#if 1
|
|
|
|
const char* p = token.c_str();
|
|
|
|
char buf[64];
|
|
|
|
char* bp = buf;
|
|
|
|
|
|
|
|
for ( ; *p != 0; ++p )
|
|
|
|
{
|
|
|
|
if ( *p == 'D' )
|
|
|
|
*bp++ = 'E';
|
|
|
|
else
|
|
|
|
*bp++ = *p;
|
|
|
|
}
|
|
|
|
*bp = 0;
|
|
|
|
return ::atof( buf );
|
|
|
|
#else
|
1998-09-19 17:59:45 +00:00
|
|
|
sscanf(token.c_str(), "%lfD%d", &mantissa, &exp);
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1998-09-21 20:53:59 +00:00
|
|
|
// cout << " Mantissa = " << mantissa << " Exp = " << exp << "\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
acc = 1;
|
|
|
|
if ( exp > 0 ) {
|
|
|
|
for ( i = 1; i <= exp; i++ ) {
|
|
|
|
acc *= 10;
|
|
|
|
}
|
|
|
|
} else if ( exp < 0 ) {
|
|
|
|
for ( i = -1; i >= exp; i-- ) {
|
|
|
|
acc /= 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return( (int)rint(mantissa * (double)acc) );
|
1998-10-16 19:08:12 +00:00
|
|
|
#endif
|
1998-03-19 02:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// read and parse DEM "A" record
|
1998-09-19 17:59:45 +00:00
|
|
|
int fgDEM::read_a_record() {
|
1998-03-19 02:54:46 +00:00
|
|
|
int i, inum;
|
|
|
|
double dnum;
|
1998-09-19 17:59:45 +00:00
|
|
|
string name, token;
|
|
|
|
char c;
|
1998-03-19 02:54:46 +00:00
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
// get the name field (144 characters)
|
|
|
|
for ( i = 0; i < 144; i++ ) {
|
1998-09-19 17:59:45 +00:00
|
|
|
in->get(c);
|
|
|
|
name += c;
|
1998-03-19 02:54:46 +00:00
|
|
|
}
|
1998-09-19 17:59:45 +00:00
|
|
|
|
|
|
|
// clean off the trailing whitespace
|
1998-10-18 01:17:09 +00:00
|
|
|
name = trim(name);
|
1998-10-16 19:08:12 +00:00
|
|
|
cout << " Quad name field: " << name << endl;
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// DEM level code, 3 reflects processing by DMA
|
1998-09-19 17:59:45 +00:00
|
|
|
inum = next_int();
|
|
|
|
cout << " DEM level code = " << inum << "\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1998-06-05 18:14:39 +00:00
|
|
|
if ( inum > 3 ) {
|
1998-09-19 17:59:45 +00:00
|
|
|
return 0;
|
1998-06-05 18:14:39 +00:00
|
|
|
}
|
|
|
|
|
1998-03-19 02:54:46 +00:00
|
|
|
// Pattern code, 1 indicates a regular elevation pattern
|
1998-09-19 17:59:45 +00:00
|
|
|
inum = next_int();
|
|
|
|
cout << " Pattern code = " << inum << "\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// Planimetric reference system code, 0 indicates geographic
|
|
|
|
// coordinate system.
|
1998-09-19 17:59:45 +00:00
|
|
|
inum = next_int();
|
|
|
|
cout << " Planimetric reference code = " << inum << "\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// Zone code
|
1998-09-19 17:59:45 +00:00
|
|
|
inum = next_int();
|
|
|
|
cout << " Zone code = " << inum << "\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// Map projection parameters (ignored)
|
|
|
|
for ( i = 0; i < 15; i++ ) {
|
1998-10-22 21:59:19 +00:00
|
|
|
dnum = next_exp();
|
1998-03-19 02:54:46 +00:00
|
|
|
// printf("%d: %f\n",i,dnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Units code, 3 represents arc-seconds as the unit of measure for
|
|
|
|
// ground planimetric coordinates throughout the file.
|
1998-09-19 17:59:45 +00:00
|
|
|
inum = next_int();
|
1998-03-19 02:54:46 +00:00
|
|
|
if ( inum != 3 ) {
|
1998-09-19 17:59:45 +00:00
|
|
|
cout << " Unknown (X,Y) units code = " << inum << "!\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Units code; 2 represents meters as the unit of measure for
|
|
|
|
// elevation coordinates throughout the file.
|
1998-09-19 17:59:45 +00:00
|
|
|
inum = next_int();
|
1998-03-19 02:54:46 +00:00
|
|
|
if ( inum != 2 ) {
|
1998-09-19 17:59:45 +00:00
|
|
|
cout << " Unknown (Z) units code = " << inum << "!\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Number (n) of sides in the polygon which defines the coverage of
|
|
|
|
// the DEM file (usually equal to 4).
|
1998-09-19 17:59:45 +00:00
|
|
|
inum = next_int();
|
1998-03-19 02:54:46 +00:00
|
|
|
if ( inum != 4 ) {
|
1998-09-19 17:59:45 +00:00
|
|
|
cout << " Unknown polygon dimension = " << inum << "!\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ground coordinates of bounding box in arc-seconds
|
1998-09-19 17:59:45 +00:00
|
|
|
dem_x1 = originx = next_exp();
|
|
|
|
dem_y1 = originy = next_exp();
|
|
|
|
cout << " Origin = (" << originx << "," << originy << ")\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1998-09-19 17:59:45 +00:00
|
|
|
dem_x2 = next_exp();
|
|
|
|
dem_y2 = next_exp();
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1998-09-19 17:59:45 +00:00
|
|
|
dem_x3 = next_exp();
|
|
|
|
dem_y3 = next_exp();
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1998-09-19 17:59:45 +00:00
|
|
|
dem_x4 = next_exp();
|
|
|
|
dem_y4 = next_exp();
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// Minimum/maximum elevations in meters
|
1998-09-19 17:59:45 +00:00
|
|
|
dem_z1 = next_exp();
|
|
|
|
dem_z2 = next_exp();
|
1998-09-21 20:53:59 +00:00
|
|
|
cout << " Elevation range " << dem_z1 << " to " << dem_z2 << "\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// Counterclockwise angle from the primary axis of ground
|
|
|
|
// planimetric referenced to the primary axis of the DEM local
|
|
|
|
// reference system.
|
1998-09-19 17:59:45 +00:00
|
|
|
token = next_token();
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// Accuracy code; 0 indicates that a record of accuracy does not
|
|
|
|
// exist and that no record type C will follow.
|
|
|
|
|
|
|
|
// DEM spacial resolution. Usually (3,3,1) (3,6,1) or (3,9,1)
|
|
|
|
// depending on latitude
|
|
|
|
|
|
|
|
// I will eventually have to do something with this for data at
|
|
|
|
// higher latitudes */
|
1998-09-19 17:59:45 +00:00
|
|
|
token = next_token();
|
1998-10-16 19:08:12 +00:00
|
|
|
cout << " accuracy & spacial resolution string = " << token << endl;
|
1998-09-19 17:59:45 +00:00
|
|
|
i = token.length();
|
|
|
|
cout << " length = " << i << "\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1998-10-16 19:08:12 +00:00
|
|
|
#if 1
|
1998-10-22 21:59:19 +00:00
|
|
|
inum = atoi( token.substr( 0, i - 36 ) );
|
|
|
|
row_step = atof( token.substr( i - 36, 12 ) );
|
|
|
|
col_step = atof( token.substr( i - 24, 12 ) );
|
1998-10-16 19:08:12 +00:00
|
|
|
//token.substr( 25, 12 )
|
|
|
|
#else
|
1998-09-19 17:59:45 +00:00
|
|
|
ptr = token.c_str() + i - 12;
|
|
|
|
cout << " last field = " << ptr << " = " << atof(ptr) << "\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
ptr[0] = '\0';
|
|
|
|
|
|
|
|
ptr = ptr - 12;
|
|
|
|
col_step = atof(ptr);
|
1998-09-19 17:59:45 +00:00
|
|
|
cout << " last field = " << ptr << " = " << col_step << "\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
ptr[0] = '\0';
|
|
|
|
|
|
|
|
ptr = ptr - 12;
|
|
|
|
row_step = atof(ptr);
|
1998-09-19 17:59:45 +00:00
|
|
|
cout << " last field = " << ptr << " = " << row_step << "\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
ptr[0] = '\0';
|
|
|
|
|
|
|
|
// accuracy code = atod(token)
|
1998-09-19 17:59:45 +00:00
|
|
|
ptr = ptr - 12;
|
|
|
|
inum = atoi(ptr);
|
1998-10-16 19:08:12 +00:00
|
|
|
#endif
|
1998-09-19 17:59:45 +00:00
|
|
|
cout << " Accuracy code = " << inum << "\n";
|
|
|
|
|
|
|
|
cout << " column step = " << col_step <<
|
|
|
|
" row step = " << row_step << "\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// dimension of arrays to follow (1)
|
1998-09-19 17:59:45 +00:00
|
|
|
token = next_token();
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// number of profiles
|
1998-09-19 17:59:45 +00:00
|
|
|
dem_num_profiles = cols = next_int();
|
|
|
|
cout << " Expecting " << dem_num_profiles << " profiles\n";
|
1998-06-05 18:14:39 +00:00
|
|
|
|
1998-09-19 17:59:45 +00:00
|
|
|
return 1;
|
1998-03-19 02:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// read and parse DEM "B" record
|
1998-09-19 17:59:45 +00:00
|
|
|
void fgDEM::read_b_record( ) {
|
|
|
|
string token;
|
1998-03-19 02:54:46 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
// row / column id of this profile
|
1998-09-19 17:59:45 +00:00
|
|
|
prof_row = next_int();
|
|
|
|
prof_col = next_int();
|
1998-03-19 02:54:46 +00:00
|
|
|
// printf("col id = %d row id = %d\n", prof_col, prof_row);
|
|
|
|
|
|
|
|
// Number of columns and rows (elevations) in this profile
|
1998-09-19 17:59:45 +00:00
|
|
|
prof_num_rows = rows = next_int();
|
|
|
|
prof_num_cols = next_int();
|
1998-04-06 21:09:37 +00:00
|
|
|
// printf(" profile num rows = %d\n", prof_num_rows);
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// Ground planimetric coordinates (arc-seconds) of the first
|
|
|
|
// elevation in the profile
|
1998-09-19 17:59:45 +00:00
|
|
|
prof_x1 = next_exp();
|
|
|
|
prof_y1 = next_exp();
|
1998-03-19 02:54:46 +00:00
|
|
|
// printf(" Starting at %.2f %.2f\n", prof_x1, prof_y1);
|
|
|
|
|
|
|
|
// Elevation of local datum for the profile. Always zero for
|
|
|
|
// 1-degree DEM, the reference is mean sea level.
|
1998-09-19 17:59:45 +00:00
|
|
|
token = next_token();
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// Minimum and maximum elevations for the profile.
|
1998-09-19 17:59:45 +00:00
|
|
|
token = next_token();
|
|
|
|
token = next_token();
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// One (usually) dimensional array (prof_num_cols,1) of elevations
|
1998-04-06 21:09:37 +00:00
|
|
|
for ( i = 0; i < prof_num_rows; i++ ) {
|
1998-09-19 17:59:45 +00:00
|
|
|
prof_data = next_int();
|
1998-04-06 21:09:37 +00:00
|
|
|
dem_data[cur_col][i] = (float)prof_data;
|
1998-03-19 02:54:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// parse dem file
|
1998-09-19 17:59:45 +00:00
|
|
|
int fgDEM::parse( ) {
|
1998-03-19 02:54:46 +00:00
|
|
|
int i;
|
|
|
|
|
1998-05-02 01:49:21 +00:00
|
|
|
cur_col = 0;
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1998-06-05 18:14:39 +00:00
|
|
|
if ( !read_a_record() ) {
|
|
|
|
return(0);
|
|
|
|
}
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
for ( i = 0; i < dem_num_profiles; i++ ) {
|
1998-04-14 02:43:27 +00:00
|
|
|
// printf("Ready to read next b record\n");
|
|
|
|
read_b_record();
|
1998-04-06 21:09:37 +00:00
|
|
|
cur_col++;
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1998-04-06 21:09:37 +00:00
|
|
|
if ( cur_col % 100 == 0 ) {
|
1998-09-21 20:53:59 +00:00
|
|
|
cout << " loaded " << cur_col << " profiles of data\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-19 17:59:45 +00:00
|
|
|
cout << " Done parsing\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1998-09-19 17:59:45 +00:00
|
|
|
return 1;
|
1998-03-19 02:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// return the current altitude based on mesh data. We should rewrite
|
|
|
|
// this to interpolate exact values, but for now this is good enough
|
1998-04-14 02:43:27 +00:00
|
|
|
double fgDEM::interpolate_altitude( double lon, double lat ) {
|
1998-03-19 02:54:46 +00:00
|
|
|
// we expect incoming (lon,lat) to be in arcsec for now
|
|
|
|
|
|
|
|
double xlocal, ylocal, dx, dy, zA, zB, elev;
|
|
|
|
int x1, x2, x3, y1, y2, y3;
|
|
|
|
float z1, z2, z3;
|
|
|
|
int xindex, yindex;
|
|
|
|
|
|
|
|
/* determine if we are in the lower triangle or the upper triangle
|
|
|
|
______
|
|
|
|
| /|
|
|
|
|
| / |
|
|
|
|
| / |
|
|
|
|
|/ |
|
|
|
|
------
|
|
|
|
|
|
|
|
then calculate our end points
|
|
|
|
*/
|
|
|
|
|
|
|
|
xlocal = (lon - originx) / col_step;
|
|
|
|
ylocal = (lat - originy) / row_step;
|
|
|
|
|
|
|
|
xindex = (int)(xlocal);
|
|
|
|
yindex = (int)(ylocal);
|
|
|
|
|
|
|
|
// printf("xindex = %d yindex = %d\n", xindex, yindex);
|
|
|
|
|
|
|
|
if ( xindex + 1 == cols ) {
|
|
|
|
xindex--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( yindex + 1 == rows ) {
|
|
|
|
yindex--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (xindex < 0) || (xindex + 1 >= cols) ||
|
|
|
|
(yindex < 0) || (yindex + 1 >= rows) ) {
|
|
|
|
return(-9999);
|
|
|
|
}
|
|
|
|
|
|
|
|
dx = xlocal - xindex;
|
|
|
|
dy = ylocal - yindex;
|
|
|
|
|
|
|
|
if ( dx > dy ) {
|
|
|
|
// lower triangle
|
|
|
|
// printf(" Lower triangle\n");
|
|
|
|
|
|
|
|
x1 = xindex;
|
|
|
|
y1 = yindex;
|
|
|
|
z1 = dem_data[x1][y1];
|
|
|
|
|
|
|
|
x2 = xindex + 1;
|
|
|
|
y2 = yindex;
|
|
|
|
z2 = dem_data[x2][y2];
|
|
|
|
|
|
|
|
x3 = xindex + 1;
|
|
|
|
y3 = yindex + 1;
|
|
|
|
z3 = dem_data[x3][y3];
|
|
|
|
|
|
|
|
// printf(" dx = %.2f dy = %.2f\n", dx, dy);
|
|
|
|
// printf(" (x1,y1,z1) = (%d,%d,%d)\n", x1, y1, z1);
|
|
|
|
// printf(" (x2,y2,z2) = (%d,%d,%d)\n", x2, y2, z2);
|
|
|
|
// printf(" (x3,y3,z3) = (%d,%d,%d)\n", x3, y3, z3);
|
|
|
|
|
|
|
|
zA = dx * (z2 - z1) + z1;
|
|
|
|
zB = dx * (z3 - z1) + z1;
|
|
|
|
|
|
|
|
// printf(" zA = %.2f zB = %.2f\n", zA, zB);
|
|
|
|
|
1998-03-23 20:35:41 +00:00
|
|
|
if ( dx > FG_EPSILON ) {
|
1998-03-19 02:54:46 +00:00
|
|
|
elev = dy * (zB - zA) / dx + zA;
|
|
|
|
} else {
|
|
|
|
elev = zA;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// upper triangle
|
|
|
|
// printf(" Upper triangle\n");
|
|
|
|
|
|
|
|
x1 = xindex;
|
|
|
|
y1 = yindex;
|
|
|
|
z1 = dem_data[x1][y1];
|
|
|
|
|
|
|
|
x2 = xindex;
|
|
|
|
y2 = yindex + 1;
|
|
|
|
z2 = dem_data[x2][y2];
|
|
|
|
|
|
|
|
x3 = xindex + 1;
|
|
|
|
y3 = yindex + 1;
|
|
|
|
z3 = dem_data[x3][y3];
|
|
|
|
|
|
|
|
// printf(" dx = %.2f dy = %.2f\n", dx, dy);
|
|
|
|
// printf(" (x1,y1,z1) = (%d,%d,%d)\n", x1, y1, z1);
|
|
|
|
// printf(" (x2,y2,z2) = (%d,%d,%d)\n", x2, y2, z2);
|
|
|
|
// printf(" (x3,y3,z3) = (%d,%d,%d)\n", x3, y3, z3);
|
|
|
|
|
|
|
|
zA = dy * (z2 - z1) + z1;
|
|
|
|
zB = dy * (z3 - z1) + z1;
|
|
|
|
|
|
|
|
// printf(" zA = %.2f zB = %.2f\n", zA, zB );
|
|
|
|
// printf(" xB - xA = %.2f\n", col_step * dy / row_step);
|
|
|
|
|
1998-03-23 20:35:41 +00:00
|
|
|
if ( dy > FG_EPSILON ) {
|
1998-03-19 02:54:46 +00:00
|
|
|
elev = dx * (zB - zA) / dy + zA;
|
|
|
|
} else {
|
|
|
|
elev = zA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(elev);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Use least squares to fit a simpler data set to dem data
|
1998-07-04 00:47:18 +00:00
|
|
|
void fgDEM::fit( double error, fgBUCKET *p ) {
|
1998-03-19 02:54:46 +00:00
|
|
|
double x[DEM_SIZE_1], y[DEM_SIZE_1];
|
|
|
|
double m, b, ave_error, max_error;
|
|
|
|
double cury, lasty;
|
1998-09-21 20:53:59 +00:00
|
|
|
int n, row, start, end;
|
1998-03-19 02:54:46 +00:00
|
|
|
int colmin, colmax, rowmin, rowmax;
|
1998-09-21 20:53:59 +00:00
|
|
|
bool good_fit;
|
1998-03-19 02:54:46 +00:00
|
|
|
// FILE *dem, *fit, *fit1;
|
|
|
|
|
|
|
|
printf("Initializing output mesh structure\n");
|
1998-04-14 02:43:27 +00:00
|
|
|
outputmesh_init();
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// determine dimensions
|
|
|
|
colmin = p->x * ( (cols - 1) / 8);
|
|
|
|
colmax = colmin + ( (cols - 1) / 8);
|
|
|
|
rowmin = p->y * ( (rows - 1) / 8);
|
|
|
|
rowmax = rowmin + ( (rows - 1) / 8);
|
|
|
|
printf("Fitting region = %d,%d to %d,%d\n", colmin, rowmin, colmax, rowmax);
|
|
|
|
|
|
|
|
// include the corners explicitly
|
1998-04-14 02:43:27 +00:00
|
|
|
outputmesh_set_pt(colmin, rowmin, dem_data[colmin][rowmin]);
|
|
|
|
outputmesh_set_pt(colmin, rowmax, dem_data[colmin][rowmax]);
|
|
|
|
outputmesh_set_pt(colmax, rowmax, dem_data[colmax][rowmax]);
|
|
|
|
outputmesh_set_pt(colmax, rowmin, dem_data[colmax][rowmin]);
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
printf("Beginning best fit procedure\n");
|
|
|
|
|
|
|
|
for ( row = rowmin; row <= rowmax; row++ ) {
|
|
|
|
// fit = fopen("fit.dat", "w");
|
|
|
|
// fit1 = fopen("fit1.dat", "w");
|
|
|
|
|
|
|
|
start = colmin;
|
|
|
|
|
|
|
|
// printf(" fitting row = %d\n", row);
|
|
|
|
|
|
|
|
while ( start < colmax ) {
|
|
|
|
end = start + 1;
|
1998-09-21 20:53:59 +00:00
|
|
|
good_fit = true;
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
x[(end - start) - 1] = 0.0 + ( start * col_step );
|
|
|
|
y[(end - start) - 1] = dem_data[start][row];
|
|
|
|
|
|
|
|
while ( (end <= colmax) && good_fit ) {
|
|
|
|
n = (end - start) + 1;
|
|
|
|
// printf("Least square of first %d points\n", n);
|
|
|
|
x[end - start] = 0.0 + ( end * col_step );
|
|
|
|
y[end - start] = dem_data[end][row];
|
|
|
|
least_squares(x, y, n, &m, &b);
|
|
|
|
ave_error = least_squares_error(x, y, n, m, b);
|
|
|
|
max_error = least_squares_max_error(x, y, n, m, b);
|
|
|
|
|
|
|
|
/*
|
|
|
|
printf("%d - %d ave error = %.2f max error = %.2f y = %.2f*x + %.2f\n",
|
|
|
|
start, end, ave_error, max_error, m, b);
|
|
|
|
|
|
|
|
f = fopen("gnuplot.dat", "w");
|
|
|
|
for ( j = 0; j <= end; j++) {
|
|
|
|
fprintf(f, "%.2f %.2f\n", 0.0 + ( j * col_step ),
|
|
|
|
dem_data[row][j]);
|
|
|
|
}
|
|
|
|
for ( j = start; j <= end; j++) {
|
|
|
|
fprintf(f, "%.2f %.2f\n", 0.0 + ( j * col_step ),
|
|
|
|
dem_data[row][j]);
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
printf("Please hit return: "); gets(junk);
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ( max_error > error ) {
|
1998-09-21 20:53:59 +00:00
|
|
|
good_fit = false;
|
1998-03-19 02:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
end++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !good_fit ) {
|
|
|
|
// error exceeded the threshold, back up
|
|
|
|
end -= 2; // back "end" up to the last good enough fit
|
|
|
|
n--; // back "n" up appropriately too
|
|
|
|
} else {
|
|
|
|
// we popped out of the above loop while still within
|
|
|
|
// the error threshold, so we must be at the end of
|
|
|
|
// the data set
|
|
|
|
end--;
|
|
|
|
}
|
|
|
|
|
|
|
|
least_squares(x, y, n, &m, &b);
|
|
|
|
ave_error = least_squares_error(x, y, n, m, b);
|
|
|
|
max_error = least_squares_max_error(x, y, n, m, b);
|
|
|
|
|
|
|
|
/*
|
|
|
|
printf("\n");
|
|
|
|
printf("%d - %d ave error = %.2f max error = %.2f y = %.2f*x + %.2f\n",
|
|
|
|
start, end, ave_error, max_error, m, b);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
fprintf(fit1, "%.2f %.2f\n", x[0], m * x[0] + b);
|
|
|
|
fprintf(fit1, "%.2f %.2f\n", x[end-start], m * x[end-start] + b);
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ( start > colmin ) {
|
|
|
|
// skip this for the first line segment
|
|
|
|
cury = m * x[0] + b;
|
1998-04-14 02:43:27 +00:00
|
|
|
outputmesh_set_pt(start, row, (lasty + cury) / 2);
|
1998-03-19 02:54:46 +00:00
|
|
|
// fprintf(fit, "%.2f %.2f\n", x[0], (lasty + cury) / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
lasty = m * x[end-start] + b;
|
|
|
|
start = end;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
fclose(fit);
|
|
|
|
fclose(fit1);
|
|
|
|
|
|
|
|
dem = fopen("gnuplot.dat", "w");
|
|
|
|
for ( j = 0; j < DEM_SIZE_1; j++) {
|
|
|
|
fprintf(dem, "%.2f %.2f\n", 0.0 + ( j * col_step ),
|
|
|
|
dem_data[j][row]);
|
|
|
|
}
|
|
|
|
fclose(dem);
|
|
|
|
*/
|
|
|
|
|
|
|
|
// NOTICE, this is for testing only. This instance of
|
|
|
|
// output_nodes should be removed. It should be called only
|
|
|
|
// once at the end once all the nodes have been generated.
|
|
|
|
// newmesh_output_nodes(&nm, "mesh.node");
|
|
|
|
// printf("Please hit return: "); gets(junk);
|
|
|
|
}
|
|
|
|
|
1998-07-04 00:47:18 +00:00
|
|
|
// outputmesh_output_nodes(fg_root, p);
|
1998-03-19 02:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize output mesh structure
|
1998-04-14 02:43:27 +00:00
|
|
|
void fgDEM::outputmesh_init( void ) {
|
1998-03-19 02:54:46 +00:00
|
|
|
int i, j;
|
1998-04-06 21:09:37 +00:00
|
|
|
|
|
|
|
for ( j = 0; j < DEM_SIZE_1; j++ ) {
|
|
|
|
for ( i = 0; i < DEM_SIZE_1; i++ ) {
|
1998-03-19 02:54:46 +00:00
|
|
|
output_data[i][j] = -9999.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the value of a mesh node
|
1998-04-14 02:43:27 +00:00
|
|
|
double fgDEM::outputmesh_get_pt( int i, int j ) {
|
1998-03-19 02:54:46 +00:00
|
|
|
return ( output_data[i][j] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set the value of a mesh node
|
1998-04-14 02:43:27 +00:00
|
|
|
void fgDEM::outputmesh_set_pt( int i, int j, double value ) {
|
1998-03-19 02:54:46 +00:00
|
|
|
// printf("Setting data[%d][%d] = %.2f\n", i, j, value);
|
|
|
|
output_data[i][j] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-20 12:46:11 +00:00
|
|
|
// Write out a node file that can be used by the "triangle" program.
|
|
|
|
// Check for an optional "index.node.ex" file in case there is a .poly
|
|
|
|
// file to go along with this node file. Include these nodes first
|
|
|
|
// since they are referenced by position from the .poly file.
|
1998-09-19 17:59:45 +00:00
|
|
|
void fgDEM::outputmesh_output_nodes( const string& fg_root, fgBUCKET *p ) {
|
1998-07-20 12:46:11 +00:00
|
|
|
double exnodes[MAX_EX_NODES][3];
|
1998-03-19 02:54:46 +00:00
|
|
|
struct stat stat_buf;
|
1998-09-19 17:59:45 +00:00
|
|
|
string dir;
|
|
|
|
char base_path[256], file[256], exfile[256];
|
1998-04-06 21:09:37 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
char tmp_path[256];
|
|
|
|
#endif
|
1998-09-19 17:59:45 +00:00
|
|
|
string command;
|
1998-03-19 02:54:46 +00:00
|
|
|
FILE *fd;
|
|
|
|
long int index;
|
|
|
|
int colmin, colmax, rowmin, rowmax;
|
1998-07-20 12:46:11 +00:00
|
|
|
int i, j, count, excount, result;
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// determine dimensions
|
|
|
|
colmin = p->x * ( (cols - 1) / 8);
|
|
|
|
colmax = colmin + ( (cols - 1) / 8);
|
|
|
|
rowmin = p->y * ( (rows - 1) / 8);
|
|
|
|
rowmax = rowmin + ( (rows - 1) / 8);
|
1998-09-19 17:59:45 +00:00
|
|
|
cout << " dumping region = " << colmin << "," << rowmin << " to " <<
|
|
|
|
colmax << "," << rowmax << "\n";
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// generate the base directory
|
|
|
|
fgBucketGenBasePath(p, base_path);
|
1998-10-16 19:08:12 +00:00
|
|
|
cout << "fg_root = " << fg_root << " Base Path = " << base_path << endl;
|
1998-09-19 17:59:45 +00:00
|
|
|
dir = fg_root + "/Scenery/" + base_path;
|
1998-10-16 19:08:12 +00:00
|
|
|
cout << "Dir = " << dir << endl;
|
1998-03-19 02:54:46 +00:00
|
|
|
|
|
|
|
// stat() directory and create if needed
|
1998-10-16 19:08:12 +00:00
|
|
|
errno = 0;
|
1998-09-19 17:59:45 +00:00
|
|
|
result = stat(dir.c_str(), &stat_buf);
|
1998-10-16 19:08:12 +00:00
|
|
|
if ( result != 0 && errno == ENOENT ) {
|
|
|
|
cout << "Creating directory\n";
|
1998-04-06 21:09:37 +00:00
|
|
|
|
1998-10-28 19:38:20 +00:00
|
|
|
// #ifndef WIN32
|
1998-04-06 21:09:37 +00:00
|
|
|
|
1998-09-19 17:59:45 +00:00
|
|
|
command = "mkdir -p " + dir + "\n";
|
|
|
|
system( command.c_str() );
|
1998-04-06 21:09:37 +00:00
|
|
|
|
1998-10-28 19:38:20 +00:00
|
|
|
#if 0
|
|
|
|
// #else // WIN32
|
1998-04-06 21:09:37 +00:00
|
|
|
|
|
|
|
// Cygwin crashes when trying to output to node file
|
|
|
|
// explicitly making directory structure seems OK on Win95
|
|
|
|
|
|
|
|
extract_path (base_path, tmp_path);
|
|
|
|
|
1998-09-19 17:59:45 +00:00
|
|
|
dir = fg_root + "/Scenery";
|
|
|
|
if (my_mkdir ( dir.c_str() )) { exit (-1); }
|
1998-04-06 21:09:37 +00:00
|
|
|
|
1998-10-02 21:41:39 +00:00
|
|
|
dir = fg_root + "/Scenery/" + tmp_path;
|
1998-09-19 17:59:45 +00:00
|
|
|
if (my_mkdir ( dir.c_str() )) { exit (-1); }
|
1998-04-06 21:09:37 +00:00
|
|
|
|
1998-10-02 21:41:39 +00:00
|
|
|
dir = fg_root + "/Scenery/" + base_path;
|
1998-09-19 17:59:45 +00:00
|
|
|
if (my_mkdir ( dir.c_str() )) { exit (-1); }
|
1998-04-06 21:09:37 +00:00
|
|
|
|
1998-10-28 19:38:20 +00:00
|
|
|
// #endif // WIN32
|
|
|
|
#endif //0
|
1998-04-06 21:09:37 +00:00
|
|
|
|
1998-03-19 02:54:46 +00:00
|
|
|
} else {
|
|
|
|
// assume directory exists
|
|
|
|
}
|
|
|
|
|
|
|
|
// get index and generate output file name
|
|
|
|
index = fgBucketGenIndex(p);
|
1998-09-19 17:59:45 +00:00
|
|
|
sprintf(file, "%s/%ld.node", dir.c_str(), index);
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1998-07-20 12:46:11 +00:00
|
|
|
// get (optional) extra node file name (in case there is matching
|
|
|
|
// .poly file.
|
|
|
|
strcpy(exfile, file);
|
|
|
|
strcat(exfile, ".ex");
|
|
|
|
|
|
|
|
// load extra nodes if they exist
|
|
|
|
excount = 0;
|
|
|
|
if ( (fd = fopen(exfile, "r")) != NULL ) {
|
1998-10-16 19:08:12 +00:00
|
|
|
int junki;
|
|
|
|
fscanf(fd, "%d %d %d %d", &excount, &junki, &junki, &junki);
|
1998-07-20 12:46:11 +00:00
|
|
|
|
|
|
|
if ( excount > MAX_EX_NODES - 1 ) {
|
|
|
|
printf("Error, too many 'extra' nodes, increase array size\n");
|
|
|
|
exit(-1);
|
|
|
|
} else {
|
|
|
|
printf(" Expecting %d 'extra' nodes\n", excount);
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = 1; i <= excount; i++ ) {
|
1998-10-16 19:08:12 +00:00
|
|
|
fscanf(fd, "%d %lf %lf %lf\n", &junki,
|
1998-07-20 12:46:11 +00:00
|
|
|
&exnodes[i][0], &exnodes[i][1], &exnodes[i][2]);
|
|
|
|
printf("(extra) %d %.2f %.2f %.2f\n",
|
|
|
|
i, exnodes[i][0], exnodes[i][1], exnodes[i][2]);
|
|
|
|
}
|
1998-09-09 16:24:04 +00:00
|
|
|
fclose(fd);
|
1998-07-20 12:46:11 +00:00
|
|
|
}
|
|
|
|
|
1998-03-19 02:54:46 +00:00
|
|
|
printf("Creating node file: %s\n", file);
|
|
|
|
fd = fopen(file, "w");
|
|
|
|
|
1998-07-20 12:46:11 +00:00
|
|
|
// first count regular nodes to generate header
|
1998-03-19 02:54:46 +00:00
|
|
|
count = 0;
|
|
|
|
for ( j = rowmin; j <= rowmax; j++ ) {
|
|
|
|
for ( i = colmin; i <= colmax; i++ ) {
|
|
|
|
if ( output_data[i][j] > -9000.0 ) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// printf(" count = %d\n", count);
|
|
|
|
}
|
1998-07-20 12:46:11 +00:00
|
|
|
fprintf(fd, "%d 2 1 0\n", count + excount);
|
1998-03-19 02:54:46 +00:00
|
|
|
|
1998-07-20 12:46:11 +00:00
|
|
|
// now write out extra node data
|
|
|
|
for ( i = 1; i <= excount; i++ ) {
|
|
|
|
fprintf(fd, "%d %.2f %.2f %.2f\n",
|
|
|
|
i, exnodes[i][0], exnodes[i][1], exnodes[i][2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// write out actual node data
|
|
|
|
count = excount + 1;
|
1998-03-19 02:54:46 +00:00
|
|
|
for ( j = rowmin; j <= rowmax; j++ ) {
|
|
|
|
for ( i = colmin; i <= colmax; i++ ) {
|
|
|
|
if ( output_data[i][j] > -9000.0 ) {
|
|
|
|
fprintf(fd, "%d %.2f %.2f %.2f\n",
|
|
|
|
count++,
|
|
|
|
originx + (double)i * col_step,
|
|
|
|
originy + (double)j * row_step,
|
|
|
|
output_data[i][j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// printf(" count = %d\n", count);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fgDEM::~fgDEM( void ) {
|
|
|
|
// printf("class fgDEM DEstructor called.\n");
|
1998-10-16 19:08:12 +00:00
|
|
|
delete [] dem_data;
|
|
|
|
delete [] output_data;
|
1998-03-19 02:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// $Log$
|
1999-01-19 20:56:56 +00:00
|
|
|
// Revision 1.22 1999/01/19 20:56:56 curt
|
|
|
|
// MacOS portability changes contributed by "Robert Puyol" <puyol@abvent.fr>
|
|
|
|
//
|
1998-11-06 14:04:32 +00:00
|
|
|
// Revision 1.21 1998/11/06 14:04:32 curt
|
|
|
|
// Changes due to updates in fgstream.
|
|
|
|
//
|
1998-10-28 19:38:20 +00:00
|
|
|
// Revision 1.20 1998/10/28 19:38:20 curt
|
|
|
|
// Elliminate some unnecessary win32 specific stuff (by Norman Vine)
|
|
|
|
//
|
1998-10-22 21:59:19 +00:00
|
|
|
// Revision 1.19 1998/10/22 21:59:19 curt
|
|
|
|
// Fixed a couple subtle bugs that resulted from some of my c++ conversions.
|
|
|
|
// One bug could cause a segfault on certain input, and the other bug could
|
|
|
|
// cause the whole procedure to go balistic and generate huge files (also only
|
|
|
|
// on rare input combinations.)
|
|
|
|
//
|
1998-10-18 01:17:09 +00:00
|
|
|
// Revision 1.18 1998/10/18 01:17:09 curt
|
|
|
|
// Point3D tweaks.
|
|
|
|
//
|
1998-10-16 19:08:12 +00:00
|
|
|
// Revision 1.17 1998/10/16 19:08:12 curt
|
|
|
|
// Portability updates from Bernie Bright.
|
|
|
|
//
|
1998-10-02 21:41:39 +00:00
|
|
|
// Revision 1.16 1998/10/02 21:41:39 curt
|
|
|
|
// Fixes for win32.
|
|
|
|
//
|
1998-09-21 20:53:59 +00:00
|
|
|
// Revision 1.15 1998/09/21 20:53:59 curt
|
|
|
|
// minor tweaks to clean a few additional things up after the rewrite.
|
|
|
|
//
|
1998-09-19 17:59:45 +00:00
|
|
|
// Revision 1.14 1998/09/19 17:59:45 curt
|
|
|
|
// Use c++ streams (fg_gzifstream). Also converted many character arrays to
|
|
|
|
// the string class.
|
|
|
|
//
|
1998-09-09 16:24:04 +00:00
|
|
|
// Revision 1.13 1998/09/09 16:24:04 curt
|
|
|
|
// Fixed a bug in the handling of exclude files which was causing
|
|
|
|
// a crash by calling fclose() on an invalid file handle.
|
|
|
|
//
|
1998-08-24 20:03:31 +00:00
|
|
|
// Revision 1.12 1998/08/24 20:03:31 curt
|
|
|
|
// Eliminated a possible memory overrun error.
|
|
|
|
// Use the proper free() rather than the incorrect delete().
|
|
|
|
//
|
1998-07-20 12:46:11 +00:00
|
|
|
// Revision 1.11 1998/07/20 12:46:11 curt
|
|
|
|
// When outputing to a .node file, first check for an optional
|
|
|
|
// "index.node.ex" file in case there is a .poly file to go along with this
|
|
|
|
// node file. Include these nodes first since they are referenced by position
|
|
|
|
// from the .poly file. This is my first pass at adding an area "cutout"
|
|
|
|
// feature to the terrain generation pipeline.
|
|
|
|
//
|
1998-07-13 20:58:02 +00:00
|
|
|
// Revision 1.10 1998/07/13 20:58:02 curt
|
|
|
|
// .
|
|
|
|
//
|
1998-07-13 15:29:49 +00:00
|
|
|
// Revision 1.9 1998/07/13 15:29:49 curt
|
|
|
|
// Added #ifdef HAVE_CONFIG_H
|
|
|
|
//
|
1998-07-04 00:47:18 +00:00
|
|
|
// Revision 1.8 1998/07/04 00:47:18 curt
|
|
|
|
// typedef'd struct fgBUCKET.
|
|
|
|
//
|
1998-06-05 18:14:39 +00:00
|
|
|
// Revision 1.7 1998/06/05 18:14:39 curt
|
|
|
|
// Abort out early when reading the "A" record if it doesn't look like
|
|
|
|
// a proper DEM file.
|
|
|
|
//
|
1998-05-02 01:49:21 +00:00
|
|
|
// Revision 1.6 1998/05/02 01:49:21 curt
|
|
|
|
// Fixed a bug where the wrong variable was being initialized.
|
|
|
|
//
|
1998-04-25 15:00:32 +00:00
|
|
|
// Revision 1.5 1998/04/25 15:00:32 curt
|
|
|
|
// Changed "r" to "rb" in gzopen() options. This fixes bad behavior in win32.
|
|
|
|
//
|
1998-04-22 13:14:46 +00:00
|
|
|
// Revision 1.4 1998/04/22 13:14:46 curt
|
|
|
|
// Fixed a bug in zlib usage.
|
|
|
|
//
|
1998-04-18 03:53:05 +00:00
|
|
|
// Revision 1.3 1998/04/18 03:53:05 curt
|
|
|
|
// Added zlib support.
|
|
|
|
//
|
1998-04-14 02:43:27 +00:00
|
|
|
// Revision 1.2 1998/04/14 02:43:27 curt
|
|
|
|
// Used "new" to auto-allocate large DEM parsing arrays in class constructor.
|
|
|
|
//
|
1998-04-08 22:54:56 +00:00
|
|
|
// Revision 1.1 1998/04/08 22:57:22 curt
|
|
|
|
// Adopted Gnu automake/autoconf system.
|
|
|
|
//
|
1998-04-06 21:09:37 +00:00
|
|
|
// Revision 1.3 1998/04/06 21:09:41 curt
|
|
|
|
// Additional win32 support.
|
|
|
|
// Fixed a bad bug in dem file parsing that was causing the output to be
|
|
|
|
// flipped about x = y.
|
|
|
|
//
|
1998-03-23 20:35:41 +00:00
|
|
|
// Revision 1.2 1998/03/23 20:35:41 curt
|
|
|
|
// Updated to use FG_EPSILON
|
|
|
|
//
|
1998-03-19 02:54:46 +00:00
|
|
|
// Revision 1.1 1998/03/19 02:54:47 curt
|
|
|
|
// Reorganized into a class lib called fgDEM.
|
|
|
|
//
|
|
|
|
// Revision 1.1 1998/03/19 01:46:28 curt
|
|
|
|
// Initial revision.
|
|
|
|
//
|