BALL  1.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
37 using namespace std;
38 
39 namespace BALL
40 {
47  template <typename DataT, typename PeakT, typename PositionT = typename PeakT::Position>
48  class Spectrum
49  {
50  public:
51 
55 
56  typedef DataT DataType;
58  typedef PositionT PositionType;
60  typedef PeakT PeakType;
62  typedef typename DataT::Iterator Iterator;
64  typedef typename DataT::ConstIterator ConstIterator;
66 
70  // ?????
72  : data_(),
73  sticks_(),
74  spacing_(),
75  min_(),
76  max_()
77  {}
78 
79  Spectrum(const DataType& data)
80  : data_(data),
81  sticks_(),
82  spacing_(),
83  min_(),
84  max_()
85  {}
86 
87  Spectrum(const std::vector<PeakType>& peaks, const PositionType& origin, const PositionType& dimension, const PositionType& spacing)
88  {}
89 
92  virtual ~Spectrum() {}
94 
98 
99  const DataType& getData() const;
101  DataType& getData();
102 
103  const vector<float>& getHuInvariants() const;
104 
105  vector<float>& getHuInvariants();
106 
108 
109  virtual void clear();
110  virtual void clearSticks();
111  virtual double difference(const Spectrum<DataT, PeakT, PositionT>& spectrum) const;
112  virtual Spectrum<DataT, PeakT, PositionT> differenceSpectrum(const Spectrum<DataT, PeakT, PositionT>& spectrum);
113  virtual double earthMoversDistance(const Spectrum<DataT,PeakT, PositionT>& spectrum) const;
114 
115  virtual void convertToGaussian();
116  virtual void convertToLorentzian();
117  virtual void computeAllMoments(int moment_number);
118 
119  virtual void setSpacing(const PositionType& spacing);
120  virtual PositionType getSpacing() const;
121 
122  virtual void setSticks(std::vector<PeakType> sticks) {sticks_ = sticks;};
123  virtual std::vector<PeakType> getSticks() const {return sticks_;};
124 
125 
126  // computes the integral over the fabs() of the spectrum
127  virtual double getAbsIntegral() const;
128  virtual void computeHuInvariants();
129  virtual vector<float> computeHuInvariantsDifferences(vector<Spectrum<DataT, PeakT, PositionT> >& spectra);
130 
137  virtual double getFourierDifference(const Spectrum<DataT,PeakT, PositionT>& spectrum, float min_freq = 1e6, float max_freq = -1e6);
138 
142  virtual double getNormalMomentsDifference(Spectrum<DataT,PeakT, PositionT>& spectrum, int moment_number);
143  virtual double getCentralMomentsDifference(Spectrum<DataT,PeakT, PositionT>& spectrum, int moment_number);
144  virtual double getStandardizedMomentsDifference(Spectrum<DataT,PeakT, PositionT>& spectrum, int moment_number);
145 
147  std::vector<float> normal_moments;
149  std::vector<float> central_moments;
151  std::vector<float> standardized_moments;
152 
154  void binaryWrite(const String& filename);
155 
157  void binaryRead(const String& filename);
158 
159  protected:
161  std::vector<PeakType> sticks_;
162  PositionType spacing_; // rausschmeissen , wie auch immer
163  PositionType min_; // rausschmeissen , wie auch immer
164  PositionType max_; // rausschmeissen , wie auch immer
165  std::vector<float> Hu_invariants_;
166  };
167 
171  template <typename DataT, typename PeakT, typename PositionT>
173  {
174  data_.clear();
175  sticks_.clear();
176  }
177 
178  template <typename DataT, typename PeakT, typename PositionT>
180  {
181  sticks_.clear();
182  }
183 
184 
185  // TODO: muss die hier stehen???
188  template <typename DataT, typename PeakT, typename PositionT>
190  {
191  // ?????
192  return 0.0;
193  }
194 
197  template <typename DataT, typename PeakT, typename PositionT>
199  {
200  return spacing_;
201  }
202 
205  template <typename DataT, typename PeakT, typename PositionT>
207  {
208  spacing_ = spacing;
209  }
210 
214  template <typename DataT, typename PeakT, typename PositionT>
216  {
217  return s1.difference(s2);
218  }
219 
220  template <typename DataT, typename PeakT, typename PositionT>
222  {
223  if (normal_moments.size() != (Size)moment_number)
224  computeAllMoments(moment_number);
225  if (spectrum.normal_moments.size() != (Size)moment_number)
226  spectrum.computeAllMoments(moment_number);
227 
228  double diff = 0.;
229  for (int current_moment=0; current_moment<moment_number; current_moment++)
230  diff += fabs(normal_moments[current_moment] - spectrum.normal_moments[current_moment]);
231 
232  return diff;
233  }
234 
235  template <typename DataT, typename PeakT, typename PositionT>
237  {
238  if (central_moments.size() != (Size)moment_number)
239  computeAllMoments(moment_number);
240  if (spectrum.central_moments.size() != (Size)moment_number)
241  spectrum.computeAllMoments(moment_number);
242 
243  double diff = 0.;
244  for (int current_moment=0; current_moment<moment_number; current_moment++)
245  diff += fabs(central_moments[current_moment] - spectrum.central_moments[current_moment]);
246 
247  return diff;
248  }
249 
250  template <typename DataT, typename PeakT, typename PositionT>
252  {
253  if (standardized_moments.size() != (Size)moment_number)
254  computeAllMoments(moment_number);
255  if (spectrum.standardized_moments.size() != (Size)moment_number)
256  spectrum.computeAllMoments(moment_number);
257 
258  double diff = 0.;
259  for (int current_moment=0; current_moment<moment_number; current_moment++)
260  diff += fabs(standardized_moments[current_moment] - spectrum.standardized_moments[current_moment]);
261 
262  return diff;
263  }
264 
265  template <typename DataT, typename PeakT, typename PositionT>
267  {
268  return data_;
269  }
270 
271  template <typename DataT, typename PeakT, typename PositionT>
273  {
274  return data_;
275  }
276 /*
277  const vector<float>& getHuInvariants();
278 */
279 
280  template <typename DataT, typename PeakT, typename PositionT>
282  {
283  return Hu_invariants_;
284  }
285 
286  template <typename DataT, typename PeakT, typename PositionT>
288  {
289  return Hu_invariants_;
290  }
291 
292 
293 
294  template <typename DataT, typename PeakT, typename PositionT>
296  {
297  Log.error()<< "computeHuInvariants() only implemented in 2D" << std::endl;
298  return;
299  }
300 
301  template <typename DataT, typename PeakT, typename PositionT>
303  {
304  Log.error()<< "computeHuInvariantsDifferences() only implemented in 2D" << std::endl;
305  std::vector<float> result;
306  return result;
307  }
308 
309  template <typename DataT, typename PeakT, typename PositionT>
311  {
312  Log.error() << "getFourierDifference only implemented in 1D and 2D" << std::endl;
313  return 0.;
314  }
315 
320 
322 
325 
329 
330  template <typename DataT, typename PeakT, typename PositionT>
331  std::ostream& operator << (std::ostream& os, const Spectrum<DataT, PeakT, PositionT>& spectrum);
332 
333  template <typename DataT, typename PeakT, typename PositionT>
334  std::istream& operator >> (std::istream& is, Spectrum<DataT, PeakT, PositionT>& spectrum);
335 
336 # ifndef BALL_NO_INLINE_FUNCTIONS
337 # include <BALL/NMR/spectrum.iC>
338 # endif
339 } // namespace BALL
340 
341 
342 #endif // BALL_NMR_SPECTRUM_H