From: curt Date: Sat, 13 Mar 1999 17:40:36 +0000 (+0000) Subject: Moved point interpolation and least squares fitting to contruction program X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5fe3a80ae34da61f1d2452b345c11b3eff3a82de;p=flightgear.git Moved point interpolation and least squares fitting to contruction program area. Moved leastsqs.* to Lib/Math/ --- diff --git a/DEM/Makefile.am b/DEM/Makefile.am index ec72f2e38..91bfd90d6 100644 --- a/DEM/Makefile.am +++ b/DEM/Makefile.am @@ -1,11 +1,11 @@ noinst_LIBRARIES = libDEM.a -libDEM_a_SOURCES = dem.cxx dem.hxx leastsqs.cxx leastsqs.hxx +libDEM_a_SOURCES = dem.cxx dem.hxx INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib # We can't build this with "-O2" (optimization) since this causes a seg fault # I haven't found a way to strip this out of the CXXFLAGS, so I'm just # setting it to "-g" -CXXFLAGS = -g +# CXXFLAGS = -g diff --git a/DEM/dem.cxx b/DEM/dem.cxx index 2e1ee2798..b7fdbfc74 100644 --- a/DEM/dem.cxx +++ b/DEM/dem.cxx @@ -1,10 +1,8 @@ -// -*- Mode: C++ -*- -// -// dem.c -- DEM management class +// dem.cxx -- DEM management class // // Written by Curtis Olson, started March 1998. // -// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu +// Copyright (C) 1998 Curtis L. Olson - curt@flightgear.org // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -35,32 +33,26 @@ #include // rint() #include #include + #ifdef HAVE_SYS_STAT_H # include // stat() #endif + #ifdef FG_HAVE_STD_INCLUDES # include #else # include #endif + #ifdef HAVE_UNISTD_H # include // stat() #endif -#include - -#include STL_IOSTREAM -// #include #include #include -#include - -FG_USING_NAMESPACE(std); +#include #include "dem.hxx" -// #include "leastsqs.hxx" - -#include #define MAX_EX_NODES 10000 @@ -166,13 +158,9 @@ FGDem::next_double() { double FGDem::next_exp() { string token; - double mantissa; - int exp, acc; - int i; token = next_token(); -#if 1 const char* p = token.c_str(); char buf[64]; char* bp = buf; @@ -186,24 +174,6 @@ FGDem::next_exp() { } *bp = 0; return ::atof( buf ); -#else - sscanf(token.c_str(), "%lfD%d", &mantissa, &exp); - - // cout << " Mantissa = " << mantissa << " Exp = " << exp << "\n"; - - 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) ); -#endif } @@ -214,7 +184,6 @@ FGDem::read_a_record() { double dnum; string name, token; char c; - char *ptr; // get the name field (144 characters) for ( i = 0; i < 144; i++ ) { @@ -434,7 +403,7 @@ FGDem::write_area( const string& root, FGBucket& b, bool compress ) { || ( max_y > originy + rows * row_step ) ) { cout << " ERROR: bucket at least partially outside DEM data range!" << endl; - return -1; + return 0; } // generate output file name @@ -470,6 +439,8 @@ FGDem::write_area( const string& root, FGBucket& b, bool compress ) { string command = "gzip --best -f " + demfile; system( command.c_str() ); } + + return 1; } @@ -898,6 +869,11 @@ FGDem::~FGDem( void ) { // $Log$ +// Revision 1.26 1999/03/13 17:40:37 curt +// Moved point interpolation and least squares fitting to contruction program +// area. +// Moved leastsqs.* to Lib/Math/ +// // Revision 1.25 1999/03/12 22:53:07 curt // Added a routine to dump out the portion of the dem data covered by a // specified bucket. Other changes related to needs of scenery tools overhaul. diff --git a/DEM/dem.hxx b/DEM/dem.hxx index 832a957ae..46849e3a4 100644 --- a/DEM/dem.hxx +++ b/DEM/dem.hxx @@ -1,10 +1,8 @@ -// -*- Mode: C++ -*- -// -// dem.h -- DEM management class +// dem.hxx -- DEM management class // // Written by Curtis Olson, started March 1998. // -// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu +// Copyright (C) 1998 Curtis L. Olson - curt@flightgear.org // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -24,8 +22,8 @@ // (Log is kept at end of this file) -#ifndef _DEM_H -#define _DEM_H +#ifndef _DEM_HXX +#define _DEM_HXX #ifndef __cplusplus @@ -33,8 +31,6 @@ #endif -#include - #include #include @@ -154,10 +150,15 @@ public: }; -#endif // _DEM_H +#endif // _DEM_HXX // $Log$ +// Revision 1.13 1999/03/13 17:40:39 curt +// Moved point interpolation and least squares fitting to contruction program +// area. +// Moved leastsqs.* to Lib/Math/ +// // Revision 1.12 1999/03/12 22:53:09 curt // Added a routine to dump out the portion of the dem data covered by a // specified bucket. Other changes related to needs of scenery tools overhaul. diff --git a/DEM/leastsqs.cxx b/DEM/leastsqs.cxx deleted file mode 100644 index a97581de4..000000000 --- a/DEM/leastsqs.cxx +++ /dev/null @@ -1,126 +0,0 @@ -// leastsqs.c -- Implements a simple linear least squares best fit routine -// -// Written by Curtis Olson, started September 1997. -// -// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com -// -// 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) -// - - -#include - -#include "leastsqs.hxx" - - -/* -Least squares fit: - -y = b0 + b1x - - n*sum(xi*yi) - (sum(xi)*sum(yi)) -b1 = -------------------------------- - n*sum(xi^2) - (sum(xi))^2 - - -b0 = sum(yi)/n - b1*(sum(xi)/n) -*/ - -void least_squares(double *x, double *y, int n, double *m, double *b) { - double sum_xi, sum_yi, sum_xi_2, sum_xi_yi; - int i; - - sum_xi = sum_yi = sum_xi_2 = sum_xi_yi = 0.0; - - for ( i = 0; i < n; i++ ) { - sum_xi += x[i]; - sum_yi += y[i]; - sum_xi_2 += x[i] * x[i]; - sum_xi_yi += x[i] * y[i]; - } - - /* printf("sum(xi)=%.2f sum(yi)=%.2f sum(xi^2)=%.2f sum(xi*yi)=%.2f\n", - sum_xi, sum_yi, sum_xi_2, sum_xi_yi); */ - - *m = ( (double)n * sum_xi_yi - sum_xi * sum_yi ) / - ( (double)n * sum_xi_2 - sum_xi * sum_xi ); - *b = (sum_yi / (double)n) - (*m) * (sum_xi / (double)n); - - /* printf("slope = %.2f intercept = %.2f\n", *m, *b); */ -} - - -/* - return the least squares error: - - (y[i] - y_hat[i])^2 - ------------------- - n - */ -double least_squares_error(double *x, double *y, int n, double m, double b) { - int i; - double error, sum; - - sum = 0.0; - - for ( i = 0; i < n; i++ ) { - error = y[i] - (m * x[i] + b); - sum += error * error; - // printf("%.2f %.2f\n", error, sum); - } - - return ( sum / (double)n ); -} - - -/* - return the maximum least squares error: - - (y[i] - y_hat[i])^2 - */ -double least_squares_max_error(double *x, double *y, int n, double m, double b){ - int i; - double error, max_error; - - max_error = 0.0; - - for ( i = 0; i < n; i++ ) { - error = y[i] - (m * x[i] + b); - error = error * error; - if ( error > max_error ) { - max_error = error; - } - } - - return ( max_error ); -} - - -// $Log$ -// Revision 1.2 1998/04/21 17:03:41 curt -// Prepairing for C++ integration. -// -// Revision 1.1 1998/04/08 22:57:24 curt -// Adopted Gnu automake/autoconf system. -// -// Revision 1.1 1998/03/19 02:54:47 curt -// Reorganized into a class lib called fgDEM. -// -// Revision 1.1 1997/10/13 17:02:35 curt -// Initial revision. -// diff --git a/DEM/leastsqs.hxx b/DEM/leastsqs.hxx deleted file mode 100644 index 71760ba70..000000000 --- a/DEM/leastsqs.hxx +++ /dev/null @@ -1,84 +0,0 @@ -// leastsqs.h -- Implements a simple linear least squares best fit routine -// -// Written by Curtis Olson, started September 1997. -// -// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com -// -// 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) -/// - - -#ifndef _LEASTSQS_H -#define _LEASTSQS_H - - -#ifndef __cplusplus -# error This library requires C++ -#endif - - -/* -Least squares fit: - -y = b0 + b1x - - n*sum(xi*yi) - (sum(xi)*sum(yi)) -b1 = -------------------------------- - n*sum(xi^2) - (sum(xi))^2 - - -b0 = sum(yi)/n - b1*(sum(xi)/n) -*/ - -void least_squares(double *x, double *y, int n, double *m, double *b); - - -/* - return the least squares error: - - (y[i] - y_hat[i])^2 - ------------------- - n -*/ -double least_squares_error(double *x, double *y, int n, double m, double b); - - -/* - return the maximum least squares error: - - (y[i] - y_hat[i])^2 -*/ -double least_squares_max_error(double *x, double *y, int n, double m, double b); - - -#endif // _LEASTSQS_H - - -// $Log$ -// Revision 1.2 1998/04/21 17:03:42 curt -// Prepairing for C++ integration. -// -// Revision 1.1 1998/04/08 22:57:25 curt -// Adopted Gnu automake/autoconf system. -// -// Revision 1.1 1998/03/19 02:54:48 curt -// Reorganized into a class lib called fgDEM. -// -// Revision 1.1 1997/10/13 17:02:35 curt -// Initial revision. -//