BALL 1.5.0
spectrum.h
Go to the documentation of this file.
1// -*- Mode: C++; tab-width: 2; -*-
2// vi: set ts=2:
3//
4// $Id: spectrum.h,v 1.14.18.6 2007-04-12 13:53:57 anne Exp $
5//
6
7#ifndef BALL_NMR_SPECTRUM_H
8#define BALL_NMR_SPECTRUM_H
9
10#ifndef BALL_NMR_PEAKLIST_H
11# include<BALL/NMR/peakList.h>
12#endif
13
14#ifndef BALL_DATATYPE_REGULARDATA1D_H
16#endif
17
18#ifndef BALL_DATATYPE_REGULARDATA2D_H
20#endif
21
22#ifndef BALL_DATATYPE_REGULARDATA3D_H
24#endif
25
26#ifdef BALL_HAS_FFTW
27# include <BALL/MATHS/complex.h>
28#ifndef BALL_MATHS_FFT1D_H
29# include <BALL/MATHS/FFT1D.h>
30#endif
31#ifndef BALL_MATHS_FFT2D_H
32# include <BALL/MATHS/FFT2D.h>
33#endif
34#endif
35
36
37namespace BALL
38{
45 template <typename DataT, typename PeakT, typename PositionT = typename PeakT::Position>
47 {
48 public:
49
54 typedef DataT DataType;
56 typedef PositionT PositionType;
58 typedef PeakT PeakType;
60 typedef typename DataT::Iterator Iterator;
62 typedef typename DataT::ConstIterator ConstIterator;
64
68 // ?????
70 : data_(),
71 sticks_(),
72 spacing_(),
73 min_(),
74 max_()
75 {}
76
77 Spectrum(const DataType& data)
78 : data_(data),
79 sticks_(),
80 spacing_(),
81 min_(),
82 max_()
83 {}
84
85 Spectrum(const std::vector<PeakType>& peaks, const PositionType& origin, const PositionType& dimension, const PositionType& spacing)
86 {}
87
90 virtual ~Spectrum() {}
92
97 const DataType& getData() const;
100
101 const std::vector<float>& getHuInvariants() const;
102
103 std::vector<float>& getHuInvariants();
104
106
107 virtual void clear();
108 virtual void clearSticks();
109 virtual double difference(const Spectrum<DataT, PeakT, PositionT>& spectrum) const;
111 virtual double earthMoversDistance(const Spectrum<DataT,PeakT, PositionT>& spectrum) const;
112
113 virtual void convertToGaussian();
114 virtual void convertToLorentzian();
115 virtual void computeAllMoments(int moment_number);
116
117 virtual void setSpacing(const PositionType& spacing);
118 virtual PositionType getSpacing() const;
119
120 virtual void setSticks(std::vector<PeakType> sticks) {sticks_ = sticks;};
121 virtual std::vector<PeakType> getSticks() const {return sticks_;};
122
123
124 // computes the integral over the fabs() of the spectrum
125 virtual double getAbsIntegral() const;
126 virtual void computeHuInvariants();
127 virtual std::vector<float> computeHuInvariantsDifferences(std::vector<Spectrum<DataT, PeakT, PositionT> >& spectra);
128
135 virtual double getFourierDifference(const Spectrum<DataT,PeakT, PositionT>& spectrum, float min_freq = 1e6, float max_freq = -1e6);
136
140 virtual double getNormalMomentsDifference(Spectrum<DataT,PeakT, PositionT>& spectrum, int moment_number);
141 virtual double getCentralMomentsDifference(Spectrum<DataT,PeakT, PositionT>& spectrum, int moment_number);
142 virtual double getStandardizedMomentsDifference(Spectrum<DataT,PeakT, PositionT>& spectrum, int moment_number);
143
145 std::vector<float> normal_moments;
147 std::vector<float> central_moments;
149 std::vector<float> standardized_moments;
150
152 void binaryWrite(const String& filename);
153
155 void binaryRead(const String& filename);
156
157 protected:
159 std::vector<PeakType> sticks_;
160 PositionType spacing_; // rausschmeissen , wie auch immer
161 PositionType min_; // rausschmeissen , wie auch immer
162 PositionType max_; // rausschmeissen , wie auch immer
163 std::vector<float> Hu_invariants_;
164 };
165
169 template <typename DataT, typename PeakT, typename PositionT>
171 {
172 data_.clear();
173 sticks_.clear();
174 }
175
176 template <typename DataT, typename PeakT, typename PositionT>
178 {
179 sticks_.clear();
180 }
181
182
183 // TODO: muss die hier stehen???
186 template <typename DataT, typename PeakT, typename PositionT>
188 {
189 // ?????
190 return 0.0;
191 }
192
195 template <typename DataT, typename PeakT, typename PositionT>
197 {
198 return spacing_;
199 }
200
203 template <typename DataT, typename PeakT, typename PositionT>
205 {
206 spacing_ = spacing;
207 }
208
212 template <typename DataT, typename PeakT, typename PositionT>
214 {
215 return s1.difference(s2);
216 }
217
218 template <typename DataT, typename PeakT, typename PositionT>
220 {
221 if (normal_moments.size() != (Size)moment_number)
222 computeAllMoments(moment_number);
223 if (spectrum.normal_moments.size() != (Size)moment_number)
224 spectrum.computeAllMoments(moment_number);
225
226 double diff = 0.;
227 for (int current_moment=0; current_moment<moment_number; current_moment++)
228 diff += fabs(normal_moments[current_moment] - spectrum.normal_moments[current_moment]);
229
230 return diff;
231 }
232
233 template <typename DataT, typename PeakT, typename PositionT>
235 {
236 if (central_moments.size() != (Size)moment_number)
237 computeAllMoments(moment_number);
238 if (spectrum.central_moments.size() != (Size)moment_number)
239 spectrum.computeAllMoments(moment_number);
240
241 double diff = 0.;
242 for (int current_moment=0; current_moment<moment_number; current_moment++)
243 diff += fabs(central_moments[current_moment] - spectrum.central_moments[current_moment]);
244
245 return diff;
246 }
247
248 template <typename DataT, typename PeakT, typename PositionT>
250 {
251 if (standardized_moments.size() != (Size)moment_number)
252 computeAllMoments(moment_number);
253 if (spectrum.standardized_moments.size() != (Size)moment_number)
254 spectrum.computeAllMoments(moment_number);
255
256 double diff = 0.;
257 for (int current_moment=0; current_moment<moment_number; current_moment++)
258 diff += fabs(standardized_moments[current_moment] - spectrum.standardized_moments[current_moment]);
259
260 return diff;
261 }
262
263 template <typename DataT, typename PeakT, typename PositionT>
265 {
266 return data_;
267 }
268
269 template <typename DataT, typename PeakT, typename PositionT>
271 {
272 return data_;
273 }
274/*
275 const vector<float>& getHuInvariants();
276*/
277
278 template <typename DataT, typename PeakT, typename PositionT>
280 {
281 return Hu_invariants_;
282 }
283
284 template <typename DataT, typename PeakT, typename PositionT>
286 {
287 return Hu_invariants_;
288 }
289
290
291
292 template <typename DataT, typename PeakT, typename PositionT>
294 {
295 Log.error()<< "computeHuInvariants() only implemented in 2D" << std::endl;
296 return;
297 }
298
299 template <typename DataT, typename PeakT, typename PositionT>
301 {
302 Log.error()<< "computeHuInvariantsDifferences() only implemented in 2D" << std::endl;
303 std::vector<float> result;
304 return result;
305 }
306
307 template <typename DataT, typename PeakT, typename PositionT>
309 {
310 Log.error() << "getFourierDifference only implemented in 1D and 2D" << std::endl;
311 return 0.;
312 }
313
320
323
327
328 template <typename DataT, typename PeakT, typename PositionT>
329 std::ostream& operator << (std::ostream& os, const Spectrum<DataT, PeakT, PositionT>& spectrum);
330
331 template <typename DataT, typename PeakT, typename PositionT>
332 std::istream& operator >> (std::istream& is, Spectrum<DataT, PeakT, PositionT>& spectrum);
333
334# ifndef BALL_NO_INLINE_FUNCTIONS
335# include <BALL/NMR/spectrum.iC>
336# endif
337} // namespace BALL
338
339
340#endif // BALL_NMR_SPECTRUM_H
BALL_EXPORT std::ostream & operator<<(std::ostream &os, const Exception::GeneralException &e)
Spectrum< RegularData1D, Peak1D > Spectrum1D
One-dimensional spectrum.
Definition: spectrum.h:319
Definition: constants.h:13
Spectrum< RegularData3D, Peak3D > Spectrum3D
Three-dimensional spectrum.
Definition: spectrum.h:325
BALL_EXPORT LogStream Log
std::istream & operator>>(std::istream &is, TRegularData1D< ValueType > &grid)
Input operator.
Spectrum< RegularData2D, Peak2D > Spectrum2D
Two-dimensional spectrum.
Definition: spectrum.h:322
BALL_INLINE TAngle< T > operator-(const T &val, const TAngle< T > &angle)
Definition: angle.h:724
LogStream & error(int n=0)
void binaryRead(const String &filename)
This function requires that DataT has a binaryRead method.
DataT DataType
The datatype used to store the spectrum.
Definition: spectrum.h:54
virtual void convertToLorentzian()
std::vector< float > central_moments
precomputed central moments
Definition: spectrum.h:147
DataT::Iterator Iterator
An iterator.
Definition: spectrum.h:60
virtual PositionType getSpacing() const
Definition: spectrum.h:196
virtual double difference(const Spectrum< DataT, PeakT, PositionT > &spectrum) const
Definition: spectrum.h:187
virtual std::vector< PeakType > getSticks() const
Definition: spectrum.h:121
virtual double earthMoversDistance(const Spectrum< DataT, PeakT, PositionT > &spectrum) const
PeakT PeakType
The peak type.
Definition: spectrum.h:58
Spectrum(const std::vector< PeakType > &peaks, const PositionType &origin, const PositionType &dimension, const PositionType &spacing)
Definition: spectrum.h:85
virtual void setSpacing(const PositionType &spacing)
Definition: spectrum.h:204
virtual double getAbsIntegral() const
PositionType spacing_
Definition: spectrum.h:160
const std::vector< float > & getHuInvariants() const
Definition: spectrum.h:279
PositionType min_
Definition: spectrum.h:161
virtual double getStandardizedMomentsDifference(Spectrum< DataT, PeakT, PositionT > &spectrum, int moment_number)
Definition: spectrum.h:249
virtual void convertToGaussian()
virtual void clearSticks()
Definition: spectrum.h:177
std::vector< PeakType > sticks_
Definition: spectrum.h:159
Spectrum(const DataType &data)
Definition: spectrum.h:77
PositionT PositionType
the data type used to store a position (for peaks and data)
Definition: spectrum.h:56
virtual void computeHuInvariants()
Definition: spectrum.h:293
virtual void clear()
Definition: spectrum.h:170
virtual double getNormalMomentsDifference(Spectrum< DataT, PeakT, PositionT > &spectrum, int moment_number)
Definition: spectrum.h:219
std::vector< float > normal_moments
precomputed normal moments
Definition: spectrum.h:145
std::vector< float > Hu_invariants_
Definition: spectrum.h:163
DataT::ConstIterator ConstIterator
A constant iterator.
Definition: spectrum.h:62
virtual ~Spectrum()
Definition: spectrum.h:90
DataType data_
Definition: spectrum.h:158
virtual std::vector< float > computeHuInvariantsDifferences(std::vector< Spectrum< DataT, PeakT, PositionT > > &spectra)
Definition: spectrum.h:300
virtual Spectrum< DataT, PeakT, PositionT > differenceSpectrum(const Spectrum< DataT, PeakT, PositionT > &spectrum)
virtual double getCentralMomentsDifference(Spectrum< DataT, PeakT, PositionT > &spectrum, int moment_number)
Definition: spectrum.h:234
PositionType max_
Definition: spectrum.h:162
virtual void computeAllMoments(int moment_number)
void binaryWrite(const String &filename)
This function requires that DataT has a binaryWrite method.
virtual void setSticks(std::vector< PeakType > sticks)
Definition: spectrum.h:120
std::vector< float > standardized_moments
precomputed standardized moments
Definition: spectrum.h:149
const DataType & getData() const
Definition: spectrum.h:264
virtual double getFourierDifference(const Spectrum< DataT, PeakT, PositionT > &spectrum, float min_freq=1e6, float max_freq=-1e6)
Definition: spectrum.h:308