QGpCompatibility/CompatFunction.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of QGpCompatibility.
00004 **
00005 **  This file may be distributed and/or modified under the terms of the
00006 **  GNU General Public License version 2 or 3 as published by the Free
00007 **  Software Foundation and appearing in the file LICENSE.GPL included
00008 **  in the packaging of this file.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00013 **  more details.
00014 **
00015 **  You should have received a copy of the GNU General Public License
00016 **  along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 **
00018 **  See http://www.geopsy.org for more information.
00019 **
00020 **  Created : 2002-10-15
00021 **  Authors:
00022 **    Marc Wathelet
00023 **    Marc Wathelet (ULg, Liège, Belgium)
00024 **    Marc Wathelet (LGIT, Grenoble, France)
00025 **
00026 ***************************************************************************/
00027 
00028 #ifndef COMPATFunction_H
00029 #define COMPATFunction_H
00030 
00031 #include <QGpCoreTools.h>
00032 #include "CompatDataPoint.h"
00033 
00034 #include "QGpCompatibilityDLLExport.h"
00035 
00036 namespace QGpCompatibility {
00037 
00038 class QGPCOMPATIBILITY_EXPORT CompatFunctionPoint : public CompatDataPoint
00039 {
00040 public:
00041   CompatFunctionPoint(double x, double y, double yErr, double weight)
00042     : CompatDataPoint(y, yErr, weight), _x(x) {}
00043 
00044   bool operator<(const CompatFunctionPoint& o) const {return _x<o._x;}
00045   bool operator==(const CompatFunctionPoint& o) const {return _x==o._x;}
00046 
00047   double& x() {return _x;}
00048   const double& x() const {return _x;}
00049 private:
00050   double _x;
00051 };
00052 
00053 class QGPCOMPATIBILITY_EXPORT CompatFunction
00054 {
00055   TRANSLATIONS("CompatFunction");
00056 public:
00057   CompatFunction();
00058   CompatFunction(QVector<double> * x, QVector<double> * y, QVector<double> * dy);
00059   CompatFunction(QVector<Point>& f);
00060   ~CompatFunction();
00061 
00062   void line(double x1, double y1, double x2, double y2);
00063   int size() {return _x ? _x->size() : 0;}
00064   void setX(QVector<double> * x);
00065   void setY(QVector<double> * y);
00066   void setYErr(QVector<double> * dy);
00067   void setWeight(QVector<double> * w);
00068   void set(QVector<Point>& f);
00069   void addPoint(int atIndex, double x, double y, double z);
00070 QVector<double> * x() {return _x;}
00071   QVector<double> * y() {return _y;}
00072   QVector<double> * yErr() {return _yErr;}
00073   QVector<double> * weight() {return _weight;}
00074   double y(double x) {return interpole(x, find(x, _x), _x, _y);}
00075   void sort();
00076   void deleteVectors();
00077   void resample_ds(int n, double min, double max, bool isLog, bool isInv,
00078                     double valX, double valY);
00079   void resample(int n, double min, double max, bool isLog, bool isInv, double invalid_value=0);
00080   void resample(QVector<double> * xModel, double invalid_value, bool doInterpole);
00081   void resample(QVector<Point>& xModel, double invalid_value, bool doInterpole);
00082   void cut (double min, double max, bool isInv);
00083   void removeInvalidValues(double invalidValue);
00084   double minX();
00085   double maxX();
00086   int minYAt();
00087   int maxYAt();
00088   double minY();
00089   double maxY();
00090   void resize(int n, bool removeLast=true);
00091 
00092   void log10();
00093   void exp10();
00094   void inverseX();
00095   void inverseY(double invalidValue);
00096   void inverseYErr();
00097   void log10Y(double invalidValue);
00098   void log10YErr();
00099   double fitFactor(double x, double val);
00100   double fitFactor(int index, double val);
00101   void getModes(QVector<double>& mean, QVector<double>& stddev);
00102   int closestMax(int starti);
00103   void multiplyX(double value);
00104   void multiplyXbyY();
00105   // Apply to partition statistical functions
00106   double average();
00107   double stddev(double average);
00108 protected:
00109   QVector<double> * _x;
00110   QVector<double> * _y;
00111   QVector<double> * _yErr;
00112   QVector<double> * _weight;
00113   /*
00114      This flag is set to false whenever one of the three vector is changed 
00115      by set(). All operation on CompatFunction are blocked while this flag is false
00116      Call sort() to enable them
00117   */
00118   bool _isSorted;
00119   // Minimum power of 2 greater than the size of _x, otpimisation of find()
00120   int _n2;
00121   int find(double val, QVector<double> * inVector);
00122   double interpole(double val, int indexInVector,
00123                     QVector<double> * inVector,
00124                     QVector<double> * outVector);
00125 };
00126 
00127 } // namespace QGpCompatibility
00128 
00129 #endif // COMPATFUNCTION_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines