46 defaults_.setValue(
"spacing", 0.05,
"Spacing of the resampled output peaks.");
61 if (spectrum.empty())
return;
63 typename MSSpectrum::iterator first = spectrum.begin();
64 typename MSSpectrum::iterator last = spectrum.end();
66 double end_pos = (last - 1)->getMZ();
67 double start_pos = first->getMZ();
68 int number_raw_points =
static_cast<int>(spectrum.size());
69 int number_resampled_points =
static_cast<int>(ceil((end_pos - start_pos) / spacing_ + 1));
71 std::vector<Peak1D> resampled_peak_container;
72 resampled_peak_container.resize(number_resampled_points);
75 std::vector<Peak1D>::iterator it = resampled_peak_container.begin();
76 for (
int i = 0; i < number_resampled_points; ++i)
78 it->setMZ(start_pos + i * spacing_);
84 double distance_left = 0.;
85 double distance_right = 0.;
89 it = resampled_peak_container.begin();
90 for (
int i = 0; i < number_raw_points; ++i)
92 int help =
static_cast<int>(floor(((first + i)->getMZ() - start_pos) / spacing_));
93 left_index = (help < 0) ? 0 : help;
94 help = distance(first, last) - 1;
95 right_index = (left_index >= help) ? help : left_index + 1;
98 distance_left = fabs((first + i)->getMZ() - (it + left_index)->getMZ()) / spacing_;
101 distance_right = fabs((first + i)->getMZ() - (it + right_index)->getMZ());
106 double intensity =
static_cast<double>((it + left_index)->getIntensity());
107 intensity +=
static_cast<double>((first + i)->getIntensity()) * distance_right / spacing_;
108 (it + left_index)->setIntensity(intensity);
109 intensity =
static_cast<double>((it + right_index)->getIntensity());
110 intensity +=
static_cast<double>((first + i)->getIntensity()) * distance_left;
111 (it + right_index)->setIntensity(intensity);
114 spectrum.
swap(resampled_peak_container);
122 startProgress(0, exp.
size(),
"resampling of data");
123 for (
Size i = 0; i < exp.
size(); ++i)
138 spacing_ = param_.getValue(
"spacing");
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
Linear Resampling of raw data.
Definition: LinearResampler.h:38
double spacing_
Spacing of the resampled data.
Definition: LinearResampler.h:134
void raster(MSSpectrum &spectrum) const
Applies the resampling algorithm to an MSSpectrum, without alignment between spectra.
Definition: LinearResampler.h:58
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
Definition: LinearResampler.h:136
LinearResampler()
Constructor.
Definition: LinearResampler.h:43
~LinearResampler() override
Destructor.
Definition: LinearResampler.h:51
void rasterExperiment(PeakMap &exp)
Resamples the data in an MSExperiment, without alignment between spectra.
Definition: LinearResampler.h:120
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
Size size() const noexcept
The number of spectra.
Definition: MSExperiment.h:121
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:27
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19