QGpCompatibility/CompatDataPoint.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 : 2004-10-21
00021 **  Authors:
00022 **    Marc Wathelet
00023 **    Marc Wathelet (ULg, Liège, Belgium)
00024 **    Marc Wathelet (LGIT, Grenoble, France)
00025 **
00026 ***************************************************************************/
00027 
00028 #ifndef COMPATDataPoint_H
00029 #define COMPATDataPoint_H
00030 
00031 #include <QGpCoreTools.h>
00032 #include "QGpCompatibilityDLLExport.h"
00033 
00034 namespace QGpCompatibility {
00035 
00036 class QGPCOMPATIBILITY_EXPORT CompatDataPoint : public XMLClass
00037 {
00038 public:
00039   CompatDataPoint () {}
00040   inline CompatDataPoint (double mean, double stddev, double _weight);
00041 
00042   inline void operator=(const CompatDataPoint& o);
00043 
00044   double& mean() {return _mean;}
00045   double& stddev() {return _stddev;}
00046   double& weight() {return _weight;}
00047 
00048   const double& mean() const {return _mean;}
00049   const double& stddev() const {return _stddev;}
00050   const double& weight() const {return _weight;}
00051 
00052   inline double misfitOrder1(double value, double invalid);
00053 protected:
00054   double _mean;
00055   double _stddev;
00056   double _weight;
00057 protected:
00058   virtual const QString& xml_tagName() const {return xmlDataPointTag;}
00059   static const QString xmlDataPointTag;
00060   virtual void xml_writeProperties(XML_WRITEPROPERTIES_ARGS) const;
00061   virtual XMLMember xml_member(XML_MEMBER_ARGS);
00062   virtual bool xml_setProperty(XML_SETPROPERTY_ARGS);
00063 };
00064 
00065 class QGPCOMPATIBILITY_EXPORT CompatVDataPoint : public CompatDataPoint
00066 {
00067 public:
00068   CompatVDataPoint () {}
00069   inline CompatVDataPoint (double mean, double stddev, double _weight);
00070 
00071   inline void operator=(const CompatVDataPoint& o);
00072   inline void operator=(const CompatDataPoint& o);
00073 
00074   void setValue(double val) {_value=val;}
00075   const double& value() const {return _value;}
00076 
00077   inline double misfitOrder2(int& nMeans, int& nValues, double invalid);
00078 protected:
00079   double _value;
00080 };
00081 
00082 inline CompatDataPoint::CompatDataPoint(double mean, double stddev, double weight)
00083 {
00084   TRACE;
00085   _mean=mean;
00086   _stddev=stddev;
00087   _weight=weight;
00088 }
00089 
00090 inline void CompatDataPoint::operator=(const CompatDataPoint& o)
00091 {
00092   TRACE;
00093   _mean=o._mean;
00094   _stddev=o._stddev;
00095   _weight=o._weight;
00096 }
00097 
00098 inline double CompatDataPoint::misfitOrder1(double value, double invalid)
00099 {
00100   TRACE;
00101   if(value!=invalid) {
00102     double diff;
00103     if(_stddev)
00104       diff=(_mean - value)/_stddev;
00105     else
00106       diff=(_mean - value)/_mean;
00107     return (diff > 0) ? diff : -diff;
00108   }
00109   return 1e99;
00110 }
00111 
00112 inline CompatVDataPoint::CompatVDataPoint(double mean, double stddev, double weight)
00113     : CompatDataPoint(mean, stddev, weight)
00114 {
00115   TRACE;
00116   _value=mean;
00117 }
00118 
00119 inline void CompatVDataPoint::operator=(const CompatVDataPoint& o)
00120 {
00121   TRACE;
00122   _value=o._value;
00123   CompatDataPoint::operator=(o);
00124 }
00125 
00126 inline void CompatVDataPoint::operator=(const CompatDataPoint& o)
00127 {
00128   TRACE;
00129   CompatDataPoint::operator=(o);
00130   _value=_mean;
00131 }
00132 
00133 inline double CompatVDataPoint::misfitOrder2(int& nMeans, int& nValues, double invalid)
00134 {
00135   TRACE;
00136   if(_mean!=invalid) {
00137     if(_value!=invalid) {
00138       double diff;
00139       if(_stddev)
00140         diff=(_mean - _value)/_stddev;
00141       else
00142         diff=(_mean - _value)/_mean;
00143       return diff*diff;
00144     } else {
00145       nValues--;
00146       return 0.0;
00147     }
00148   } else {
00149     nMeans--;
00150     nValues--;
00151     return 0.0;
00152   }
00153 }
00154 
00155 QGPCOMPATIBILITY_EXPORT QDataStream& operator<< (QDataStream& s, const CompatDataPoint& p);
00156 QGPCOMPATIBILITY_EXPORT QDataStream& operator>> (QDataStream& s, CompatDataPoint& p);
00157 
00158 class QGPCOMPATIBILITY_EXPORT CompatDataPointVector : public QVector<CompatDataPoint>,
00159       public XMLClass
00160 {
00161 public:
00162   CompatDataPointVector() {}
00163   virtual ~CompatDataPointVector() {}
00164   QVector<double> * meanVector() const;
00165   QVector<double> * stddevVector() const;
00166   QVector<double> * weightVector() const;
00167 protected:
00168   virtual const QString& xml_tagName() const {return xmlDataPointVectorTag;}
00169   static const QString xmlDataPointVectorTag;
00170   virtual void xml_writeChildren(XML_WRITECHILDREN_ARGS) const;
00171   virtual XMLMember xml_member(XML_MEMBER_ARGS);
00172 };
00173 
00174 class QGPCOMPATIBILITY_EXPORT CompatVDataPointVector : public QVector<CompatVDataPoint>,
00175       public XMLClass
00176 {
00177 public:
00178   CompatVDataPointVector() {}
00179   virtual ~CompatVDataPointVector() {}
00180   QVector<double> * valueVector() const;
00181   QVector<double> * meanVector() const;
00182   QVector<double> * stddevVector() const;
00183   QVector<double> * weightVector() const;
00184 protected:
00185   virtual const QString& xml_tagName() const {return xmlVDataPointVectorTag;}
00186   static const QString xmlVDataPointVectorTag;
00187   virtual void xml_writeChildren(XML_WRITECHILDREN_ARGS) const;
00188   virtual XMLMember xml_member(XML_MEMBER_ARGS);
00189 };
00190 
00191 } // namespace QGpCompatibility
00192 
00193 #endif // COMPATDATAPOINT_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines