QGpCoreTools/Function2Search.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of QGpCoreTools.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
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 Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created : 2007-11-12
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (LGIT, Grenoble, France)
00025 **
00026 ***************************************************************************/
00027 
00028 #ifndef FUNCTIONSEARCH_H
00029 #define FUNCTIONSEARCH_H
00030 
00031 #include "QGpCoreToolsDLLExport.h"
00032 #include "AbstractFunction2.h"
00033 #include "Trace.h"
00034 #include "Point2D.h"
00035 
00036 namespace QGpCoreTools {
00037 
00038 class Function2SearchMaximum
00039 {
00040 public:
00041   Function2SearchMaximum(double value, const Point2D& pos) {
00042     _value=value;
00043     _pos=pos;
00044   }
00045   ~Function2SearchMaximum() {}
00046 
00047   bool operator<(const Function2SearchMaximum& o) const {return _value>o._value;}
00048   double value() const {return _value;}
00049   const Point2D& pos() const {return _pos;}
00050 private:
00051   double _value;
00052   Point2D _pos;
00053 };
00054 
00055 typedef QList<Function2SearchMaximum>::iterator Function2MaximaIterator;
00056 
00057 class QGPCORETOOLS_EXPORT Function2Search
00058 {
00059 public:
00060   Function2Search();
00061   ~Function2Search();
00062 
00063   void setFunction(AbstractFunction2 * f);
00064   AbstractFunction2 * takeFunction();
00065 
00066   double value(double x, double y) const {return _function->value(x,y);}
00067   double value(double x, double y, int index) const {return _function->value(x,y, index);}
00068 
00069   const Point2D& pos() const {return _pos;}
00070   Function2MaximaIterator localMax(int nMax, double absThres=0.0, double relThres=0.0);
00071   Function2MaximaIterator localMaxEnd() {return _localMaxima.end();}
00072 protected:
00073   static inline double lowLimit(int i, double * axis);
00074   static inline double highLimit(int i, double * axis, int nAxis);
00075 
00076   Point2D _pos;
00077   AbstractFunction2 * _function;
00078   bool _relative;
00079   QList<Function2SearchMaximum> _localMaxima;
00080 };
00081 
00082 inline double Function2Search::lowLimit(int i, double * axis)
00083 {
00084   TRACE;
00085   return i>0 ? axis[i-1] : axis[0];
00086 }
00087 
00088 inline double Function2Search::highLimit(int i, double * axis, int nAxis)
00089 {
00090   TRACE;
00091   return i<nAxis-1 ? axis[i+1] : axis[nAxis-1];
00092 }
00093 
00094 } // namespace QGpCoreTools
00095 
00096 #endif // FUNCTION2SEARCH.H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines