Game Accessibility Library logo SourceForge.net Logo
Game Accessibility Suite: CAT/CATCurveFit.h Source File

CATCurveFit.h

Go to the documentation of this file.
00001 /// \file CATCurveFit.h
00002 /// \brief Fit a curve to a set of points
00003 /// \ingroup CAT
00004 ///
00005 /// Copyright (c) 2002-2008 by Michael Ellison.
00006 /// See COPYING.txt for the \ref gaslicense License (MIT License).
00007 ///
00008 // $Author: mikeellison $
00009 // $Date: 2008-01-19 19:19:35 -0600 (Sat, 19 Jan 2008) $
00010 // $Revision:   $
00011 // $NoKeywords: $
00012 
00013 #ifndef _CATCURVEFIT_H_
00014 #define _CATCURVEFIT_H_
00015 
00016 #include "CATInternal.h"
00017 #include "CATPoint.h"
00018 #include "CATMatrix.h"
00019 
00020 /// \class CATCurveFit
00021 /// \brief  Fit a curve to a set of points
00022 /// \ingroup CAT
00023 ///
00024 /// Fits a curve of the specified degree to a set of data.
00025 /// Based off the algorithm presented in "Introduction to Algorithms" Second Edition,
00026 ///    by Cormen, Leiserson, Rivest, and Stein (MIT press)
00027 ///
00028 class CATCurveFit
00029 {
00030     public:     
00031         /// Pass in the number of coefficients you want to calculate.
00032         /// defaults to quadratic.  For line, use 2.
00033         CATCurveFit(CATUInt32 curveDegree = 3);
00034 
00035         virtual ~CATCurveFit();
00036 
00037         /// Add a point to the interpolation data
00038         bool        AddPoint( CATFloat64 x, CATFloat64 y);
00039 
00040         /// Clear out all current data
00041         bool        Clear();
00042         
00043         /// Get the polynomial degree
00044         bool        GetDegree(CATUInt32 &degree);
00045 
00046         /// Get a specific coefficient
00047         bool        GetCoefficient( CATUInt32 deg, CATFloat64& coef);
00048         
00049         /// Get the number of data points acquired
00050         CATUInt32   GetNumPoints();
00051 
00052         /// Get an individual data point
00053         bool        GetDataPoint( CATUInt32 n, CATFloat64& x, CATFloat64& y);
00054         
00055         /// Calculate the Y val from a specified x val
00056         bool        CalcYVal( CATFloat64 x, CATFloat64& y);
00057 
00058         /// Get error value
00059         bool        GetCurrentErr( CATFloat64& err);
00060 
00061         bool        GetMinMax( CATFloat64& minX, CATFloat64& minY, CATFloat64& maxX, CATFloat64& maxY);
00062 
00063         bool        LangrangianCalcY(CATFloat64 x, CATFloat64 &y);
00064     protected:      
00065         bool        CalcFit();  // Internal calc    
00066         
00067         std::vector <CATPoint> fPointList; ///< list of X points
00068         std::vector <CATFloat64> fCoef;    ///< list of coefficients (double's)     
00069         
00070         CATFloat64  fLastErr;              ///< last calculated err
00071 
00072         CATUInt32   fDegree;               ///< Degree of coefficient to calculate with fit
00073                 
00074         bool        fDirty;                ///< Are the coefficients dirty? (i.e. need to call CalcFit?)
00075 };
00076 
00077 #endif // _CATCURVEFIT_H_

Generated on Mon Feb 11 04:09:42 2008 for Game Accessibility Suite by doxygen 1.5.4