71template <
typename GetSpectrum>
73 double mz,
double tolerance_ppm,
74 const std::vector<Size>& pixel_indices,
76 GetSpectrum&& get_spectrum)
78 if (!std::isfinite(mz) || !std::isfinite(tolerance_ppm) || mz < 0.0 || tolerance_ppm < 0.0)
81 "mz and tolerance_ppm must be finite and non-negative",
85 const double dm = mz * tolerance_ppm * 1e-6;
86 const double mz_lo = mz - dm;
87 const double mz_hi = mz + dm;
93 for (
Size i : pixel_indices)
95 const auto& p = pixels[i];
96 if (p.spectrum_index >= n_spectra)
99 "Pixel references missing spectrum",
105 const auto& spec = get_spectrum(p.spectrum_index);
107 for (
auto it = spec.MZBegin(mz_lo); it != spec.MZEnd(mz_hi); ++it)
109 sum +=
static_cast<double>(it->getIntensity());
Invalid value exception.
Definition Exception.h:306
Dense W x H grid of ion intensities with a per-pixel mask.
Definition IonImage.h:31
void setMzRange(const RangeMZ &range)
Records the m/z window the image was extracted from.
void setIntensity(UInt x, UInt y, double intensity)
Stores intensity at (x, y) and marks the cell valid.
Pixel grid metadata and (x, y) -> spectrum_index lookup for MSI data.
Definition MSImagingGeometry.h:33
const std::vector< Pixel > & getPixels() const
Pixels in insertion order.
UInt getWidth() const
Image width.
UInt getHeight() const
Image height.
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
static double sum(IteratorType begin, IteratorType end)
Calculates the sum of a range of values.
Definition StatisticFunctions.h:103
IonImage extractIonImage(const MSImagingGeometry &geom, double mz, double tolerance_ppm, const std::vector< Size > &pixel_indices, Size n_spectra, GetSpectrum &&get_spectrum)
Build an IonImage by summing peak intensities in an m/z window over a pixel subset.
Definition IonImageExtraction.h:72
std::string toStr(int i)
Definition StringUtils.h:101
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Definition RangeManager.h:358