Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
BinnedSpectrum.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2017.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Mathias Walzer $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 //
35 #ifndef OPENMS_COMPARISON_SPECTRA_BINNEDSPECTRUM_H
36 #define OPENMS_COMPARISON_SPECTRA_BINNEDSPECTRUM_H
37 
42 
43 #include <cmath>
44 
45 namespace OpenMS
46 {
47 
65  class OPENMS_DLLAPI BinnedSpectrum
66  {
67 
68 private:
69 
71  float bin_size_;
76 
77 public:
78 
83  class OPENMS_DLLAPI NoSpectrumIntegrated :
85  {
86 public:
87  NoSpectrumIntegrated(const char* file, int line, const char* function, const char* message = "BinnedSpectrum hasn't got a PeakSpectrum to base on yet") throw();
88 
89  virtual ~NoSpectrumIntegrated() throw();
90  };
91 
94 
97 
99  BinnedSpectrum(float size, UInt spread, PeakSpectrum ps);
100 
102  BinnedSpectrum(const BinnedSpectrum& source);
103 
105  virtual ~BinnedSpectrum();
106 
109  {
110  if (&source != this)
111  {
112  setBinSize(source.getBinSize());
113  setBinSpread(source.getBinSpread());
114  bins_ = source.getBins();
115  raw_spec_ = source.raw_spec_;
116  }
117  return *this;
118  }
119 
122  {
123  if (raw_spec_ != source)
124  {
125  raw_spec_ = source;
126  setBinning();
127  }
128  return *this;
129  }
130 
132  bool operator==(const BinnedSpectrum& rhs) const
133  {
134 #pragma clang diagnostic push
135 #pragma clang diagnostic ignored "-Wfloat-equal"
136  return raw_spec_ == rhs.raw_spec_ &&
137  rhs.getBinSize() == this->bin_size_ &&
138  rhs.getBinSpread() == this->bin_spread_;
139 
140 #pragma clang diagnostic pop
141  }
142 
144  bool operator!=(const BinnedSpectrum& rhs) const
145  {
146  return !(operator==(rhs));
147  }
148 
150  bool operator==(const PeakSpectrum& rhs) const
151  {
152  return raw_spec_ == rhs;
153  }
154 
156  bool operator!=(const PeakSpectrum& rhs) const
157  {
158  return !(operator==(rhs));
159  }
160 
162  inline double getBinSize() const
163  {
164  return this->bin_size_;
165  }
166 
168  inline UInt getBinSpread() const
169  {
170  return this->bin_spread_;
171  }
172 
174  inline UInt getBinNumber() const
175  {
176  return (UInt) this->bins_.size();
177  }
178 
180  inline UInt getFilledBinNumber() const
181  {
182  return (UInt) this->bins_.nonzero_size();
183  }
184 
189  inline const SparseVector<float>& getBins() const
190  {
191  if (bins_.empty())
192  {
193  throw BinnedSpectrum::NoSpectrumIntegrated(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
194  }
195  return bins_;
196  }
197 
203  {
204  if (bins_.empty())
205  {
206  try
207  {
208  this->setBinning();
209  }
210  catch (...)
211  {
212  throw BinnedSpectrum::NoSpectrumIntegrated(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
213  }
214  }
215  return bins_;
216  }
217 
219  inline const_bin_iterator begin() const
220  {
221  return bins_.begin();
222  }
223 
225  inline const_bin_iterator end() const
226  {
227  return bins_.end();
228  }
229 
231  inline bin_iterator begin()
232  {
233  return bins_.begin();
234  }
235 
237  inline bin_iterator end()
238  {
239  return bins_.end();
240  }
241 
247  inline void setBinSize(double s)
248  {
249  if (this->bin_size_ != s)
250  {
251  this->bin_size_ = s;
252  try
253  {
254  this->setBinning();
255  }
256  catch (...)
257  {
258  throw BinnedSpectrum::NoSpectrumIntegrated(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
259  }
260  }
261  }
262 
268  inline void setBinSpread(UInt s)
269  {
270  if (this->bin_spread_ != s)
271  {
272  this->bin_spread_ = s;
273  try
274  {
275  this->setBinning();
276  }
277  catch (...)
278  {
279  throw BinnedSpectrum::NoSpectrumIntegrated(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
280  }
281  }
282  }
283 
288  void setBinning();
289 
291  bool checkCompliance(const BinnedSpectrum& bs) const;
292 
294  const PeakSpectrum& getRawSpectrum() const;
295  };
296 
297 }
298 #endif //OPENMS_COMPARISON_SPECTRA_BINNEDSPECTRUM_H
bool operator==(const BinnedSpectrum &rhs) const
equality operator
Definition: BinnedSpectrum.h:132
bool operator!=(const PeakSpectrum &rhs) const
inequality operator for PeakSpectra
Definition: BinnedSpectrum.h:156
SparseVector< float > bins_
The computed bins.
Definition: BinnedSpectrum.h:73
float bin_size_
Definition: BinnedSpectrum.h:71
PeakSpectrum raw_spec_
The original raw spectrum.
Definition: BinnedSpectrum.h:75
void setBinSize(double s)
Definition: BinnedSpectrum.h:247
unsigned int UInt
Unsigned integer type.
Definition: Types.h:95
const_bin_iterator begin() const
returns the const begin iterator of the container
Definition: BinnedSpectrum.h:219
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806
UInt bin_spread_
Definition: BinnedSpectrum.h:70
bool empty() const
true if the container is empty
Definition: SparseVector.h:188
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
SparseVector< float >::const_iterator const_bin_iterator
Definition: BinnedSpectrum.h:92
bin_iterator end()
returns the end iterator of the container
Definition: BinnedSpectrum.h:237
size_type nonzero_size() const
number of nonzero elements, i.e. the space actually used
Definition: SparseVector.h:176
BinnedSpectrum & operator=(const PeakSpectrum &source)
assignment operator for PeakSpectra
Definition: BinnedSpectrum.h:121
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
iterator end()
end iterator
Definition: SparseVector.h:401
bin_iterator begin()
returns the begin iterator of the container
Definition: BinnedSpectrum.h:231
UInt getBinNumber() const
get the BinNumber, number of Bins
Definition: BinnedSpectrum.h:174
BinnedSpectrum & operator=(const BinnedSpectrum &source)
assignment operator
Definition: BinnedSpectrum.h:108
iterator begin()
begin iterator
Definition: SparseVector.h:395
Exception base class.
Definition: Exception.h:90
void setBinSpread(UInt s)
Definition: BinnedSpectrum.h:268
This is a binned representation of a PeakSpectrum.
Definition: BinnedSpectrum.h:65
const_bin_iterator end() const
returns the const end iterator of the container
Definition: BinnedSpectrum.h:225
bool operator!=(const BinnedSpectrum &rhs) const
inequality operator
Definition: BinnedSpectrum.h:144
size_type size() const
size of the represented vector
Definition: SparseVector.h:182
double getBinSize() const
get the BinSize
Definition: BinnedSpectrum.h:162
SparseVector< float > & getBins()
Definition: BinnedSpectrum.h:202
UInt getBinSpread() const
get the BinSpread
Definition: BinnedSpectrum.h:168
const SparseVector< float > & getBins() const
Definition: BinnedSpectrum.h:189
bool operator==(const PeakSpectrum &rhs) const
equality operator for PeakSpectra
Definition: BinnedSpectrum.h:150
Exception which is thrown if BinnedSpectrum bins are accessed and no PeakSpektrum has been integrated...
Definition: BinnedSpectrum.h:83
SparseVector< float >::iterator bin_iterator
Definition: BinnedSpectrum.h:93
UInt getFilledBinNumber() const
get the FilledBinNumber, number of filled Bins
Definition: BinnedSpectrum.h:180

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:21:59 using doxygen 1.8.13