2000-02-15 17:13:45 +00:00
|
|
|
/*
|
|
|
|
WARNING - Do not remove this header.
|
|
|
|
|
|
|
|
This code is a templated version of the 'magic-software' spherical
|
|
|
|
interpolation code by Dave Eberly. The original (un-hacked) code can be
|
|
|
|
obtained from here: http://www.magic-software.com/gr_appr.htm
|
|
|
|
This code is derived from linintp2.h/cpp and sphrintp.h/cpp.
|
|
|
|
|
|
|
|
Dave Eberly says that the conditions for use are:
|
|
|
|
|
|
|
|
* You may distribute the original source code to others at no charge.
|
|
|
|
|
|
|
|
* You may modify the original source code and distribute it to others at
|
|
|
|
no charge. The modified code must be documented to indicate that it is
|
|
|
|
not part of the original package.
|
|
|
|
|
|
|
|
* You may use this code for non-commercial purposes. You may also
|
|
|
|
incorporate this code into commercial packages. However, you may not
|
|
|
|
sell any of your source code which contains my original and/or modified
|
|
|
|
source code. In such a case, you need to factor out my code and freely
|
|
|
|
distribute it.
|
|
|
|
|
|
|
|
* The original code comes with absolutely no warranty and no guarantee is
|
|
|
|
made that the code is bug-free.
|
|
|
|
|
|
|
|
This does not seem incompatible with GPL - so this modified version
|
|
|
|
is hereby placed under GPL along with the rest of FlightGear.
|
|
|
|
|
|
|
|
Christian Mayer
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SPHRINTP_H
|
|
|
|
#define SPHRINTP_H
|
|
|
|
|
2002-03-16 20:31:27 +00:00
|
|
|
#include <simgear/compiler.h>
|
2002-03-20 13:59:34 +00:00
|
|
|
#include STL_IOSTREAM
|
2002-03-16 20:31:27 +00:00
|
|
|
|
2000-02-15 17:13:45 +00:00
|
|
|
#include "linintp2.h"
|
|
|
|
#include <plib/sg.h>
|
|
|
|
|
2002-03-20 13:59:34 +00:00
|
|
|
#ifndef SG_HAVE_NATIVE_SGI_COMPILERS
|
2002-03-16 20:31:27 +00:00
|
|
|
SG_USING_NAMESPACE(std);
|
|
|
|
SG_USING_STD(cout);
|
2002-03-20 13:59:34 +00:00
|
|
|
#endif
|
2002-03-16 20:31:27 +00:00
|
|
|
|
|
|
|
|
2000-02-15 17:13:45 +00:00
|
|
|
class SphereInterpolate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SphereInterpolate (int n, const double* x, const double* y,
|
2002-03-16 20:31:27 +00:00
|
|
|
const double* z, const unsigned int* f);
|
|
|
|
SphereInterpolate (int n, const sgVec2* p, const unsigned int* f);
|
2000-02-15 17:13:45 +00:00
|
|
|
|
|
|
|
~SphereInterpolate ();
|
|
|
|
|
|
|
|
void GetSphericalCoords (const double x, const double y, const double z,
|
|
|
|
double& thetaAngle, double& phiAngle) const;
|
|
|
|
|
2002-03-16 20:31:27 +00:00
|
|
|
int Evaluate (const double x, const double y, const double z, EvaluateData& f) const;
|
|
|
|
int Evaluate (const double thetaAngle, const double phiAngle, EvaluateData& f) const;
|
2000-02-15 17:13:45 +00:00
|
|
|
|
2000-09-10 00:04:50 +00:00
|
|
|
#ifndef macintosh
|
2000-04-27 21:57:08 +00:00
|
|
|
// CodeWarrior doesn't know the differece between sgVec2 and
|
|
|
|
// sgVec3, so I commented this out for Mac builds. This change is
|
|
|
|
// related to a similar change in FGLocalWeatherDatabase module.
|
|
|
|
|
2002-03-16 20:31:27 +00:00
|
|
|
EvaluateData Evaluate(const sgVec2& p) const
|
2000-02-15 17:13:45 +00:00
|
|
|
{
|
2002-03-16 20:31:27 +00:00
|
|
|
EvaluateData retval;
|
2000-02-15 17:13:45 +00:00
|
|
|
Evaluate(p[1], p[0], retval);
|
|
|
|
return retval;
|
|
|
|
}
|
2000-04-27 21:57:08 +00:00
|
|
|
#endif
|
|
|
|
|
2000-02-15 17:13:45 +00:00
|
|
|
|
2002-03-16 20:31:27 +00:00
|
|
|
EvaluateData Evaluate(const sgVec3& p) const
|
2000-02-15 17:13:45 +00:00
|
|
|
{
|
2002-03-16 20:31:27 +00:00
|
|
|
EvaluateData retval;
|
|
|
|
if (!Evaluate(p[1], p[0], retval))
|
|
|
|
{
|
|
|
|
cout << "Error during spherical interpolation. Point ("
|
|
|
|
<< p[0] << "/" << p[1] << "/" << p[2] << ") was in no triangle\n";
|
|
|
|
retval.index[0] = 0; //fake something
|
|
|
|
retval.index[1] = 0;
|
|
|
|
retval.index[2] = 0;
|
|
|
|
retval.percentage[0] = 1.0;
|
|
|
|
retval.percentage[1] = 0.0;
|
|
|
|
retval.percentage[2] = 0.0;
|
|
|
|
}
|
2000-02-15 17:13:45 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int numPoints;
|
|
|
|
double* theta;
|
|
|
|
double* phi;
|
2002-03-16 20:31:27 +00:00
|
|
|
unsigned int* func;
|
|
|
|
mgcLinInterp2D* pInterp;
|
2000-02-15 17:13:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|