86 mz_array->data.resize(spectrum->getMZArray()->data.size());
87 intensity_array->data.resize(spectrum->getMZArray()->data.size());
90 bool ret_val = filter(
91 spectrum->getMZArray()->data.begin(),
92 spectrum->getMZArray()->data.end(),
93 spectrum->getIntensityArray()->data.begin(),
94 mz_array->data.begin(), intensity_array->data.begin()
97 spectrum->setMZArray(mz_array);
98 spectrum->setIntensityArray(intensity_array);
110 rt_array->data.resize(chromatogram->getTimeArray()->data.size());
111 intensity_array->data.resize(chromatogram->getTimeArray()->data.size());
114 bool ret_val = filter(
115 chromatogram->getTimeArray()->data.begin(),
116 chromatogram->getTimeArray()->data.end(),
117 chromatogram->getIntensityArray()->data.begin(),
118 rt_array->data.begin(), intensity_array->data.begin()
121 chromatogram->setTimeArray(rt_array);
122 chromatogram->setIntensityArray(intensity_array);
131 template <
typename ConstIterT,
typename IterT>
133 ConstIterT mz_in_start,
134 ConstIterT mz_in_end,
135 ConstIterT int_in_start,
139 bool found_signal =
false;
141 ConstIterT mz_it = mz_in_start;
142 ConstIterT int_it = int_in_start;
143 for (; mz_it != mz_in_end; mz_it++, int_it++)
146 if (use_ppm_tolerance_)
148 initialize((*mz_it) * ppm_tolerance_ * 10e-6, spacing_, ppm_tolerance_, use_ppm_tolerance_ );
151 double new_int = integrate_(mz_it, int_it, mz_in_start, mz_in_end);
159 if (fabs(new_int) > 0) found_signal =
true;
164 void initialize(
double gaussian_width,
double spacing,
double ppm_tolerance,
bool use_ppm_tolerance);
180 template <
typename InputPeakIterator>
181 double integrate_(InputPeakIterator x , InputPeakIterator y , InputPeakIterator first, InputPeakIterator last)
186 Size middle = coeffs_.size();
188 double start_pos = (( (*x) - (middle * spacing_)) > (*first)) ? ((*x) - (middle * spacing_)) : (*first);
189 double end_pos = (( (*x) + (middle * spacing_)) < (*(last - 1))) ? ((*x) + (middle * spacing_)) : (*(last - 1));
191 InputPeakIterator help_x = x;
192 InputPeakIterator help_y = y;
193 #ifdef DEBUG_FILTERING
195 std::cout <<
"integrate from middle to start_pos " << *help_x <<
" until " << start_pos << std::endl;
199 while ((help_x != first) && (*(help_x - 1) > start_pos))
202 double distance_in_gaussian = fabs(*x - *help_x);
203 Size left_position = (
Size)floor(distance_in_gaussian / spacing_);
206 for (
int j = 0; ((j < 3) && (distance(first, help_x - j) >= 0)); ++j)
208 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
214 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
222 Size right_position = left_position + 1;
223 double d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
225 double coeffs_right = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
226 : coeffs_[left_position];
227 #ifdef DEBUG_FILTERING
229 std::cout <<
"distance_in_gaussian " << distance_in_gaussian << std::endl;
230 std::cout <<
" right_position " << right_position << std::endl;
231 std::cout <<
" left_position " << left_position << std::endl;
232 std::cout <<
"coeffs_ at left_position " << coeffs_[left_position] << std::endl;
233 std::cout <<
"coeffs_ at right_position " << coeffs_[right_position] << std::endl;
234 std::cout <<
"interpolated value left " << coeffs_right << std::endl;
239 distance_in_gaussian = fabs((*x) - (*(help_x - 1)));
240 left_position = (
Size)floor(distance_in_gaussian / spacing_);
243 for (
UInt j = 0; ((j < 3) && (distance(first, help_x - j) >= 0)); ++j)
245 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
251 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
259 right_position = left_position + 1;
260 d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
261 double coeffs_left = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
262 : coeffs_[left_position];
263 #ifdef DEBUG_FILTERING
265 std::cout <<
" help_x-1 " << *(help_x - 1) <<
" distance_in_gaussian " << distance_in_gaussian << std::endl;
266 std::cout <<
" right_position " << right_position << std::endl;
267 std::cout <<
" left_position " << left_position << std::endl;
268 std::cout <<
"coeffs_ at left_position " << coeffs_[left_position] << std::endl;
269 std::cout <<
"coeffs_ at right_position " << coeffs_[right_position] << std::endl;
270 std::cout <<
"interpolated value right " << coeffs_left << std::endl;
272 std::cout <<
" intensity " << fabs(*(help_x - 1) - (*help_x)) / 2. <<
" * " << *(help_y - 1) <<
" * " << coeffs_left <<
" + " << *help_y <<
"* " << coeffs_right
277 norm += fabs((*(help_x - 1)) - (*help_x)) / 2. * (coeffs_left + coeffs_right);
279 v += fabs((*(help_x - 1)) - (*help_x)) / 2. * (*(help_y - 1) * coeffs_left + (*help_y) * coeffs_right);
288 #ifdef DEBUG_FILTERING
290 std::cout <<
"integrate from middle to endpos " << *help_x <<
" until " << end_pos << std::endl;
293 while ((help_x != (last - 1)) && (*(help_x + 1) < end_pos))
296 double distance_in_gaussian = fabs((*x) - (*help_x));
297 int left_position = (
UInt)floor(distance_in_gaussian / spacing_);
300 for (
int j = 0; ((j < 3) && (distance(help_x + j, last - 1) >= 0)); ++j)
302 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
308 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
315 Size right_position = left_position + 1;
316 double d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
317 double coeffs_left = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
318 : coeffs_[left_position];
320 #ifdef DEBUG_FILTERING
322 std::cout <<
" help " << *help_x <<
" distance_in_gaussian " << distance_in_gaussian << std::endl;
323 std::cout <<
" left_position " << left_position << std::endl;
324 std::cout <<
"coeffs_ at right_position " << coeffs_[left_position] << std::endl;
325 std::cout <<
"coeffs_ at left_position " << coeffs_[right_position] << std::endl;
326 std::cout <<
"interpolated value left " << coeffs_left << std::endl;
330 distance_in_gaussian = fabs((*x) - (*(help_x + 1)));
331 left_position = (
UInt)floor(distance_in_gaussian / spacing_);
334 for (
int j = 0; ((j < 3) && (distance(help_x + j, last - 1) >= 0)); ++j)
336 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
342 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
350 right_position = left_position + 1;
351 d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
352 double coeffs_right = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
353 : coeffs_[left_position];
354 #ifdef DEBUG_FILTERING
356 std::cout <<
" (help + 1) " << *(help_x + 1) <<
" distance_in_gaussian " << distance_in_gaussian << std::endl;
357 std::cout <<
" left_position " << left_position << std::endl;
358 std::cout <<
"coeffs_ at right_position " << coeffs_[left_position] << std::endl;
359 std::cout <<
"coeffs_ at left_position " << coeffs_[right_position] << std::endl;
360 std::cout <<
"interpolated value right " << coeffs_right << std::endl;
362 std::cout <<
" intensity " << fabs(*help_x - *(help_x + 1)) / 2.
363 <<
" * " << *help_y <<
" * " << coeffs_left <<
" + " << *(help_y + 1)
364 <<
"* " << coeffs_right
367 norm += fabs((*help_x) - (*(help_x + 1)) ) / 2. * (coeffs_left + coeffs_right);
369 v += fabs((*help_x) - (*(help_x + 1)) ) / 2. * ((*help_y) * coeffs_left + (*(help_y + 1)) * coeffs_right);