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");
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:93
Linear Resampling of raw data.
Definition: LinearResampler.h:64
double spacing_
Spacing of the resampled data.
Definition: LinearResampler.h:160
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
Definition: LinearResampler.h:162
LinearResampler()
Constructor.
Definition: LinearResampler.h:69
~LinearResampler() override
Destructor.
Definition: LinearResampler.h:77
void rasterExperiment(PeakMap &exp)
Resamples the data in an MSExperiment.
Definition: LinearResampler.h:146
void raster(MSSpectrum &spectrum)
Applies the resampling algorithm to an MSSpectrum.
Definition: LinearResampler.h:84
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:80
Size size() const
Definition: MSExperiment.h:127
The representation of a 1D spectrum.
Definition: MSSpectrum.h:71
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47