72 defaults_.setValue(
"spacing", 0.05,
"Spacing of the resampled output peaks.");
87 if (spectrum.empty())
return;
89 typename MSSpectrum::iterator first = spectrum.begin();
90 typename MSSpectrum::iterator last = spectrum.end();
92 double end_pos = (last - 1)->getMZ();
93 double start_pos = first->getMZ();
94 int number_raw_points = static_cast<int>(spectrum.size());
95 int number_resampled_points = static_cast<int>(ceil((end_pos - start_pos) / spacing_ + 1));
97 std::vector<Peak1D> resampled_peak_container;
98 resampled_peak_container.resize(number_resampled_points);
101 std::vector<Peak1D>::iterator it = resampled_peak_container.begin();
102 for (
int i = 0; i < number_resampled_points; ++i)
104 it->setMZ(start_pos + i * spacing_);
110 double distance_left = 0.;
111 double distance_right = 0.;
115 it = resampled_peak_container.begin();
116 for (
int i = 0; i < number_raw_points; ++i)
118 int help = static_cast<int>(floor(((first + i)->getMZ() - start_pos) / spacing_));
119 left_index = (help < 0) ? 0 : help;
120 help = distance(first, last) - 1;
121 right_index = (left_index >= help) ? help : left_index + 1;
124 distance_left = fabs((first + i)->getMZ() - (it + left_index)->getMZ()) / spacing_;
127 distance_right = fabs((first + i)->getMZ() - (it + right_index)->getMZ());
132 double intensity = static_cast<double>((it + left_index)->getIntensity());
133 intensity += static_cast<double>((first + i)->getIntensity()) * distance_right / spacing_;
134 (it + left_index)->setIntensity(intensity);
135 intensity = static_cast<double>((it + right_index)->getIntensity());
136 intensity += static_cast<double>((first + i)->getIntensity()) * distance_left;
137 (it + right_index)->setIntensity(intensity);
140 spectrum.swap(resampled_peak_container);
148 startProgress(0, exp.
size(),
"resampling of data");
149 for (
Size i = 0; i < exp.
size(); ++i)
164 spacing_ = param_.getValue(
"spacing");