00001 /*************************************************************************** 00002 ** 00003 ** This file is part of GeopsyCore. 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 : 2009-04-11 00022 ** Authors : 00023 ** Marc Wathelet 00024 ** Marc Wathelet (LGIT, Grenoble, France) 00025 ** 00026 ***************************************************************************/ 00027 00028 #ifndef DFFTPACKCACHE_H 00029 #define DFFTPACKCACHE_H 00030 00031 #include <QGpCoreTools.h> 00032 00033 namespace GeopsyCore { 00034 00035 #ifndef NO_FFT 00036 00037 class DFFTPackKey : public AbstractNumericalKey 00038 { 00039 DECLARE_NUMERICALKEY(DFFTPackKey) 00040 public: 00041 enum Number {Real=0, Complex=1}; 00042 00043 DFFTPackKey(int nSamples, Number number) { 00044 _nSamples=nSamples; 00045 _number=number; 00046 } 00047 virtual bool operator==(const AbstractNumericalKey& o) { 00048 const DFFTPackKey& mo=static_cast<const DFFTPackKey&>(o); 00049 return _nSamples==mo._nSamples && _number==mo._number; 00050 } 00051 virtual int hash() const {return _nSamples*(_number*2-1);} 00052 inline virtual AbstractNumericalCache * createCache(); 00053 inline virtual int byteCount() const; 00054 00055 int nSamples() const {return _nSamples;} 00056 Number number() const {return _number;} 00057 private: 00058 int _nSamples; 00059 Number _number; 00060 }; 00061 00062 class DFFTPackCache : public AbstractNumericalCache 00063 { 00064 public: 00065 DFFTPackCache(DFFTPackKey * key); 00066 ~DFFTPackCache(); 00067 00068 static inline const DFFTPackCache * begin(int nSamples, DFFTPackKey::Number number); 00069 virtual void init(); 00070 00071 double * wsave() const {return _wsave;} 00072 private: 00073 double * _wsave; 00074 }; 00075 00076 inline const DFFTPackCache * DFFTPackCache::begin(int nSamples, DFFTPackKey::Number number) 00077 { 00078 return static_cast<const DFFTPackCache *>( 00079 AbstractNumericalCache::begin(new DFFTPackKey(nSamples, number) )); 00080 } 00081 00082 inline AbstractNumericalCache * DFFTPackKey::createCache( ) 00083 { 00084 return new DFFTPackCache(this); 00085 } 00086 00087 inline int DFFTPackKey::byteCount() const 00088 { 00089 switch (_number) { 00090 case Real: 00091 break; 00092 case Complex: 00093 return (2*_nSamples+15)*sizeof(double); 00094 } 00095 return (_nSamples+15)*sizeof(double); 00096 } 00097 00098 #endif // NO_FFT 00099 00100 } // namespace GeopsyCore 00101 00102 #endif // DFFTPACKCACHE_H