QGpCoreWave/ModalStorage.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of QGpCoreWave.
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 : 2006-09-25
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (LGIT, Grenoble, France)
00025 **
00026 ***************************************************************************/
00027 
00028 #ifndef MODALSTORAGE_H
00029 #define MODALSTORAGE_H
00030 
00031 #include <QGpCoreTools.h>
00032 #include "ModalRefine.h"
00033 #include "QGpCoreWaveDLLExport.h"
00034 
00035 namespace QGpCoreWave {
00036 
00037 class QGPCOREWAVE_EXPORT ModalStorage
00038 {
00039 public:
00040   ModalStorage();
00041   ModalStorage(int nModes, const QVector<double> * x) {set(nModes, x);}
00042   ~ModalStorage() {delete [] _values;}
00043 
00044   void set(int nModes, const QVector<double> * x);
00045   ModalStorage& operator=(const ModalStorage& o);
00046 
00047   void log10();
00048   void exp10();
00049   void abs();
00050 
00051   int xCount() const {return _nX;}
00052   int modeCount() const {return _nModes;}
00053   const QVector<double> * x() const {return _x;}
00054   double x(int ix) const {return _x->at(ix);}
00055   RealValue * mode(int index) {return _values+index*_nX;}
00056   const RealValue * mode(int index) const {return _values+index*_nX;}
00057 
00058   int refineCount() const {return _refines.count();}
00059   ModalRefine& refineAdd(double x) {
00060     _refines.append(ModalRefine(_nModes, x));
00061     _refines.last().setValid(false);
00062     return _refines.last();
00063   }
00064   void refineClear() {_refines.clear();}
00065   void refineSort() {qSort(_refines);}
00066   ModalRefine& lastRefine() {return _refines.last();}
00067   RefineIterator refineBegin() const {return _refines.begin();}
00068   RefineIterator refineEnd() const {return _refines.end();}
00069 
00070   void toStream(QTextStream& s, int modeIndex =-1) const;
00071   Curve<Point2D> curve(int iMode) const;
00072 
00073   void writeReport(QDataStream& s) const;
00074 
00075   class Iterator {
00076   public:
00077     inline Iterator(const ModalStorage * s, int iMode);
00078     inline bool atEnd() const;
00079     inline Iterator &operator++();
00080     inline double x() const;
00081     inline const RealValue& value();
00082   private:
00083     const ModalStorage * _storage;
00084     double _nextFixed, _nextRefine;
00085     int _fixedIterator;
00086     RefineIterator _refineIterator;
00087     int _iMode;
00088     const RealValue * _values;
00089   };
00090 
00091 private:
00092   int _nX, _nModes;
00093   const QVector<double> * _x;
00094   RealValue * _values;
00095   RefineList _refines;
00096 };
00097 
00098 inline ModalStorage::Iterator::Iterator(const ModalStorage * s, int iMode)
00099 {
00100   TRACE;
00101   _storage=s;
00102   _nextFixed=_storage->x(0);
00103   _fixedIterator=0;
00104   _refineIterator=_storage->refineBegin();
00105   if(_refineIterator!=_storage->refineEnd()) {
00106     _nextRefine=_refineIterator->x();
00107   } else {
00108     _nextRefine=1e99;
00109   }
00110   _iMode=iMode;
00111   _values=_storage->mode(_iMode);
00112 }
00113 
00114 inline ModalStorage::Iterator& ModalStorage::Iterator::operator++()
00115 {
00116   if(_nextFixed < _nextRefine) {
00117     _fixedIterator++;
00118     if(_fixedIterator < _storage->xCount())
00119       _nextFixed=_storage->x(_fixedIterator);
00120     else {
00121       _nextFixed=1e99;
00122     }
00123   } else {
00124     ++_refineIterator;
00125     if(_refineIterator!=_storage->refineEnd())
00126       _nextRefine=_refineIterator->x();
00127     else {
00128       _nextRefine=1e99;
00129     }
00130   }
00131   return *this;
00132 }
00133 
00134 inline bool ModalStorage::Iterator::atEnd() const
00135 {
00136   TRACE;
00137   return _fixedIterator==_storage->xCount() && _refineIterator==_storage->refineEnd();
00138 }
00139 
00140 inline double ModalStorage::Iterator::x() const
00141 {
00142   TRACE;
00143   if(_nextFixed < _nextRefine) {
00144     return _nextFixed;
00145   } else {
00146     return _nextRefine;
00147   }
00148 }
00149 
00150 inline const RealValue& ModalStorage::Iterator::value()
00151 {
00152   if(_nextFixed < _nextRefine) {
00153     return _values[_fixedIterator] ;
00154   } else {
00155     return _refineIterator->value(_iMode) ;
00156   }
00157 }
00158 
00159 } // namespace QGpCoreWave
00160 
00161 #endif // MODALSTORAGE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines