159 double integrate_(InputPeakIterator x , InputPeakIterator y , InputPeakIterator first, InputPeakIterator last)
164 Size middle = coeffs_.size();
166 double start_pos = (( (*x) - (middle * spacing_)) > (*first)) ? ((*x) - (middle * spacing_)) : (*first);
167 double end_pos = (( (*x) + (middle * spacing_)) < (*(last - 1))) ? ((*x) + (middle * spacing_)) : (*(last - 1));
169 InputPeakIterator help_x = x;
170 InputPeakIterator help_y = y;
171#ifdef DEBUG_FILTERING
173 std::cout <<
"integrate from middle to start_pos " << *help_x <<
" until " << start_pos << std::endl;
177 while ((help_x != first) && (*(help_x - 1) > start_pos))
180 double distance_in_gaussian = fabs(*x - *help_x);
181 Size left_position = (
Size)floor(distance_in_gaussian / spacing_);
184 for (
int j = 0; ((j < 3) && (distance(first, help_x - j) >= 0)); ++j)
186 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
192 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
200 Size right_position = left_position + 1;
201 double d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
203 double coeffs_right = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
204 : coeffs_[left_position];
205#ifdef DEBUG_FILTERING
207 std::cout <<
"distance_in_gaussian " << distance_in_gaussian << std::endl;
208 std::cout <<
" right_position " << right_position << std::endl;
209 std::cout <<
" left_position " << left_position << std::endl;
210 std::cout <<
"coeffs_ at left_position " << coeffs_[left_position] << std::endl;
211 std::cout <<
"coeffs_ at right_position " << coeffs_[right_position] << std::endl;
212 std::cout <<
"interpolated value left " << coeffs_right << std::endl;
217 distance_in_gaussian = fabs((*x) - (*(help_x - 1)));
218 left_position = (
Size)floor(distance_in_gaussian / spacing_);
221 for (
UInt j = 0; ((j < 3) && (distance(first, help_x - j) >= 0)); ++j)
223 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
229 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
237 right_position = left_position + 1;
238 d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
239 double coeffs_left = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
240 : coeffs_[left_position];
241#ifdef DEBUG_FILTERING
243 std::cout <<
" help_x-1 " << *(help_x - 1) <<
" distance_in_gaussian " << distance_in_gaussian << std::endl;
244 std::cout <<
" right_position " << right_position << std::endl;
245 std::cout <<
" left_position " << left_position << std::endl;
246 std::cout <<
"coeffs_ at left_position " << coeffs_[left_position] << std::endl;
247 std::cout <<
"coeffs_ at right_position " << coeffs_[right_position] << std::endl;
248 std::cout <<
"interpolated value right " << coeffs_left << std::endl;
250 std::cout <<
" intensity " << fabs(*(help_x - 1) - (*help_x)) / 2. <<
" * " << *(help_y - 1) <<
" * " << coeffs_left <<
" + " << *help_y <<
"* " << coeffs_right
255 norm += fabs((*(help_x - 1)) - (*help_x)) / 2. * (coeffs_left + coeffs_right);
257 v += fabs((*(help_x - 1)) - (*help_x)) / 2. * (*(help_y - 1) * coeffs_left + (*help_y) * coeffs_right);
266#ifdef DEBUG_FILTERING
268 std::cout <<
"integrate from middle to endpos " << *help_x <<
" until " << end_pos << std::endl;
271 while ((help_x != (last - 1)) && (*(help_x + 1) < end_pos))
274 double distance_in_gaussian = fabs((*x) - (*help_x));
275 int left_position = (
UInt)floor(distance_in_gaussian / spacing_);
278 for (
int j = 0; ((j < 3) && (distance(help_x + j, last - 1) >= 0)); ++j)
280 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
286 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
293 Size right_position = left_position + 1;
294 double d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
295 double coeffs_left = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
296 : coeffs_[left_position];
298#ifdef DEBUG_FILTERING
300 std::cout <<
" help " << *help_x <<
" distance_in_gaussian " << distance_in_gaussian << std::endl;
301 std::cout <<
" left_position " << left_position << std::endl;
302 std::cout <<
"coeffs_ at right_position " << coeffs_[left_position] << std::endl;
303 std::cout <<
"coeffs_ at left_position " << coeffs_[right_position] << std::endl;
304 std::cout <<
"interpolated value left " << coeffs_left << std::endl;
308 distance_in_gaussian = fabs((*x) - (*(help_x + 1)));
309 left_position = (
UInt)floor(distance_in_gaussian / spacing_);
312 for (
int j = 0; ((j < 3) && (distance(help_x + j, last - 1) >= 0)); ++j)
314 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
320 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
328 right_position = left_position + 1;
329 d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
330 double coeffs_right = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
331 : coeffs_[left_position];
332#ifdef DEBUG_FILTERING
334 std::cout <<
" (help + 1) " << *(help_x + 1) <<
" distance_in_gaussian " << distance_in_gaussian << std::endl;
335 std::cout <<
" left_position " << left_position << std::endl;
336 std::cout <<
"coeffs_ at right_position " << coeffs_[left_position] << std::endl;
337 std::cout <<
"coeffs_ at left_position " << coeffs_[right_position] << std::endl;
338 std::cout <<
"interpolated value right " << coeffs_right << std::endl;
340 std::cout <<
" intensity " << fabs(*help_x - *(help_x + 1)) / 2.
341 <<
" * " << *help_y <<
" * " << coeffs_left <<
" + " << *(help_y + 1)
342 <<
"* " << coeffs_right
345 norm += fabs((*help_x) - (*(help_x + 1)) ) / 2. * (coeffs_left + coeffs_right);
347 v += fabs((*help_x) - (*(help_x + 1)) ) / 2. * ((*help_y) * coeffs_left + (*(help_y + 1)) * coeffs_right);