]> git.mxchange.org Git - flightgear.git/commitdiff
Moved point interpolation and least squares fitting to contruction program
authorcurt <curt>
Sat, 13 Mar 1999 17:40:36 +0000 (17:40 +0000)
committercurt <curt>
Sat, 13 Mar 1999 17:40:36 +0000 (17:40 +0000)
area.
Moved leastsqs.* to Lib/Math/

DEM/Makefile.am
DEM/dem.cxx
DEM/dem.hxx
DEM/leastsqs.cxx [deleted file]
DEM/leastsqs.hxx [deleted file]

index ec72f2e384fd2da482073b52ed437bb405adc721..91bfd90d6cfc45eddb51b3b2b24e853ef3b4a476 100644 (file)
@@ -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
 
index 2e1ee279895d39d952c718f33323207b65dee509..b7fdbfc74a2ee9e575d2d3d680107698fc3cb56d 100644 (file)
@@ -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
 #include <math.h>     // rint()
 #include <stdio.h>
 #include <string.h>
+
 #ifdef HAVE_SYS_STAT_H
 #  include <sys/stat.h> // stat()
 #endif
+
 #ifdef FG_HAVE_STD_INCLUDES
 #  include <cerrno>
 #else
 #  include <errno.h>
 #endif
+
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>   // stat()
 #endif
-#include <string>
-
-#include STL_IOSTREAM
 
-// #include <zlib/zlib.h>
 #include <Misc/fgstream.hxx>
 #include <Misc/strutils.hxx>
-#include <Include/compiler.h>
-
-FG_USING_NAMESPACE(std);
+#include <Include/fg_constants.h>
 
 #include "dem.hxx"
-// #include "leastsqs.hxx"
-
-#include <Include/fg_constants.h>
 
 
 #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.
index 832a957ae528f0324c7564a704f822d7f4cb9245..46849e3a4ef8712786c1ea9679fa71ea2fa1d439 100644 (file)
@@ -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 <stdio.h>
-
 #include <Bucket/newbucket.hxx>
 #include <Misc/fgstream.hxx>
 
@@ -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 (file)
index a97581d..0000000
+++ /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 <stdio.h>
-
-#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 (file)
index 71760ba..0000000
+++ /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.
-//