area.
Moved leastsqs.* to Lib/Math/
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
-// -*- 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
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;
}
*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
}
double dnum;
string name, token;
char c;
- char *ptr;
// get the name field (144 characters)
for ( i = 0; i < 144; i++ ) {
|| ( 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
string command = "gzip --best -f " + demfile;
system( command.c_str() );
}
+
+ return 1;
}
// $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.
-// -*- 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
// (Log is kept at end of this file)
-#ifndef _DEM_H
-#define _DEM_H
+#ifndef _DEM_HXX
+#define _DEM_HXX
#ifndef __cplusplus
#endif
-#include <stdio.h>
-
#include <Bucket/newbucket.hxx>
#include <Misc/fgstream.hxx>
};
-#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.
+++ /dev/null
-// 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.
-//
+++ /dev/null
-// 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.
-//