ProteoWizard
breakspec.hpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Witold Wolski <wewolski@gmail.com>
6//
7// Copyright : ETH Zurich
8//
9// Licensed under the Apache License, Version 2.0 (the "License");
10// you may not use this file except in compliance with the License.
11// You may obtain a copy of the License at
12//
13// http://www.apache.org/licenses/LICENSE-2.0
14//
15// Unless required by applicable law or agreed to in writing, software
16// distributed under the License is distributed on an "AS IS" BASIS,
17// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18// See the License for the specific language governing permissions and
19// limitations under the License.
20//
21
22
23#ifndef BREAKSSPEC_H
24#define BREAKSSPEC_H
25
26#include <vector>
27
28namespace ralab
29{
30 namespace base
31 {
32 namespace resample{
33
34 /*! \brief Segment mass range according to Mass Compare functor
35 could be used to histogram a dataset or to compute minima for each segment
36 in order to perform baseline subtraction.
37
38 */
39 template<typename TMassComparator>
40 void breaks
41 (
42 double minMass,
43 double maxMass,
44 TMassComparator tmassComp,
45 std::vector<double> & breaks,
46 bool exact = false
47 )
48 {
49 double startMass;
50 double endMass = maxMass;
51 if(exact)
52 {
53 startMass = minMass;
54 }
55 else
56 {
57 startMass = minMass - tmassComp(minMass)/2.;
58 }
59
60 breaks.push_back(startMass);
61 do
62 {
63 startMass = startMass + tmassComp(startMass);
64 breaks.push_back(startMass );
65 }while( startMass < endMass);
66
67 if(exact)
68 {
69 breaks.back() = endMass;
70 }
71 }
72
73 /*\compute mids for breaks
74 */
75 template<
76 typename TInputIterator,
77 typename TOutputIterator
78 >
79 TOutputIterator getMids(TInputIterator breaksBeg,
80 TInputIterator breaksEnd,
81 TOutputIterator midsBeg
82 )
83 {
84 typedef typename std::iterator_traits<TInputIterator>::value_type TReal;
85 TReal oldval = *breaksBeg;
86 TReal divider = TReal(0.5);
87 ++breaksBeg;
88 for( ; breaksBeg != breaksEnd; ++breaksBeg, ++midsBeg )
89 {
90 TReal newval = *(breaksBeg);
91 *midsBeg = (oldval + newval)*divider;
92 oldval = newval;
93 }
94 return midsBeg;
95 }
96
97 /*!\brief Dummy version of getMids*/
98 inline void getMids(
99 const std::vector<double> &breaks,
100 std::vector<double> & mids
101 )
102 {
103 mids.resize(breaks.size()-1);
104 getMids(breaks.begin(), breaks.end(), mids.begin() );
105 }
106 }//end resample
107 }//end base
108}//end ralab
109
110
111#endif // BREAKSSPEC_H
TOutputIterator getMids(TInputIterator breaksBeg, TInputIterator breaksEnd, TOutputIterator midsBeg)
Definition breakspec.hpp:79
void breaks(double minMass, double maxMass, TMassComparator tmassComp, std::vector< double > &breaks, bool exact=false)
Segment mass range according to Mass Compare functor could be used to histogram a dataset or to compu...
Definition breakspec.hpp:41
EQUISPACEINTERPOL Interpolation on a equidistantly spaced grid.
Definition base.hpp:40