From 007bac3720e694fddde672b5ecbe2645ab2d1f2b Mon Sep 17 00:00:00 2001 From: curt <curt> Date: Mon, 5 Apr 1999 02:15:23 +0000 Subject: [PATCH] Make dem fitting more robust in cases when no dem file available. --- Array/array.cxx | 77 ++++++++++++++++++++++++++++++++++----------- Array/array.hxx | 10 ++++-- Array/testarray.cxx | 2 +- 3 files changed, 67 insertions(+), 22 deletions(-) diff --git a/Array/array.cxx b/Array/array.cxx index af1e32f7d..2b7d2a625 100644 --- a/Array/array.cxx +++ b/Array/array.cxx @@ -107,24 +107,55 @@ FGArray::close() { } -// parse Array file +// parse Array file, pass in the bucket so we can make up values when +// the file wasn't found. int -FGArray::parse() { - *in >> originx >> originy; - *in >> cols >> col_step; - *in >> rows >> row_step; +FGArray::parse( FGBucket& b ) { + if ( in->is_open() ) { + // file open, parse + *in >> originx >> originy; + *in >> cols >> col_step; + *in >> rows >> row_step; - cout << " origin = " << originx << " " << originy << endl; - cout << " cols = " << cols << " rows = " << rows << endl; - cout << " col_step = " << col_step << " row_step = " << row_step <<endl; + cout << " origin = " << originx << " " << originy << endl; + cout << " cols = " << cols << " rows = " << rows << endl; + cout << " col_step = " << col_step + << " row_step = " << row_step <<endl; - for ( int i = 0; i < cols; i++ ) { - for ( int j = 0; j < rows; j++ ) { - *in >> in_data[i][j]; + for ( int i = 0; i < cols; i++ ) { + for ( int j = 0; j < rows; j++ ) { + *in >> in_data[i][j]; + } } - } - cout << " Done parsing\n"; + cout << " Done parsing\n"; + } else { + // file not open (not found?), fill with zero'd data + + originx = ( b.get_center_lon() - 0.5 * b.get_width() ) * 3600.0; + originy = ( b.get_center_lat() - 0.5 * b.get_height() ) * 3600.0; + + double max_x = ( b.get_center_lon() + 0.5 * b.get_width() ) * 3600.0; + double max_y = ( b.get_center_lat() + 0.5 * b.get_height() ) * 3600.0; + + cols = 3; + col_step = (max_x - originx) / (cols - 1); + rows = 3; + row_step = (max_y - originy) / (rows - 1); + + cout << " origin = " << originx << " " << originy << endl; + cout << " cols = " << cols << " rows = " << rows << endl; + cout << " col_step = " << col_step + << " row_step = " << row_step <<endl; + + for ( int i = 0; i < cols; i++ ) { + for ( int j = 0; j < rows; j++ ) { + in_data[i][j] = 0.0; + } + } + + cout << " File not open, so using zero'd data" << endl; + } return 1; } @@ -132,9 +163,11 @@ FGArray::parse() { // add a node to the output corner node list void FGArray::add_corner_node( int i, int j, double val ) { + double x = (originx + i * col_step) / 3600.0; double y = (originy + j * row_step) / 3600.0; - // cout << Point3D(x, y, val) << endl; + // cout << "originx = " << originx << " originy = " << originy << endl; + // cout << "corner = " << Point3D(x, y, val) << endl; corner_list.push_back( Point3D(x, y, val) ); } @@ -148,8 +181,9 @@ void FGArray::add_fit_node( int i, int j, double val ) { } -// Use least squares to fit a simpler data set to dem data -void FGArray::fit( double error ) { +// Use least squares to fit a simpler data set to dem data. Return +// the number of fitted nodes +int FGArray::fit( double error ) { double x[ARRAY_SIZE_1], y[ARRAY_SIZE_1]; double m, b, max_error, error_sq; double x1, y1; @@ -162,8 +196,9 @@ void FGArray::fit( double error ) { error_sq = error * error; - cout << " Initializing output mesh structure" << endl; - // outputmesh_init(); + cout << " Initializing fitted node list" << endl; + corner_list.clear(); + node_list.clear(); // determine dimensions colmin = 0; @@ -297,6 +332,9 @@ void FGArray::fit( double error ) { } // outputmesh_output_nodes(fg_root, p); + + // return fit nodes + 4 corners + return node_list.size() + 4; } @@ -539,6 +577,9 @@ FGArray::~FGArray( void ) { // $Log$ +// Revision 1.8 1999/04/05 02:15:23 curt +// Make dem fitting more robust in cases when no dem file available. +// // Revision 1.7 1999/03/27 14:05:10 curt // More sensible handling of the case where no dem file for this tile exists // (or has been generated). diff --git a/Array/array.hxx b/Array/array.hxx index 601d0fb56..2ec9e2a51 100644 --- a/Array/array.hxx +++ b/Array/array.hxx @@ -89,10 +89,11 @@ public: int close(); // parse a Array file - int parse(); + int parse( FGBucket& b ); - // Use least squares to fit a simpler data set to dem data - void fit( double error ); + // Use least squares to fit a simpler data set to dem data. + // Return the number of fitted nodes + int fit( double error ); // add a node to the output corner node list void add_corner_node( int i, int j, double val ); @@ -122,6 +123,9 @@ public: // $Log$ +// Revision 1.6 1999/04/05 02:15:24 curt +// Make dem fitting more robust in cases when no dem file available. +// // Revision 1.5 1999/03/29 13:11:02 curt // Shuffled stl type names a bit. // Began adding support for tri-fanning (or maybe other arrangments too.) diff --git a/Array/testarray.cxx b/Array/testarray.cxx index 74012eb93..1a0a4d55c 100644 --- a/Array/testarray.cxx +++ b/Array/testarray.cxx @@ -23,7 +23,7 @@ main(int argc, char **argv) { cout << "arrayfile = " << arrayfile << endl; FGArray a(arrayfile); - a.parse(); + a.parse( b ); lon *= 3600; lat *= 3600;