MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / findClosestDataPoint

Method findClosestDataPoint

src/openms_gui/source/VISUAL/LayerData1DPeak.cpp:54–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52 }
53
54 PeakIndex LayerData1DPeak::findClosestDataPoint(const RangeAllType& area) const
55 {
56 Peak1D peak_lt(area.getMinMZ(), area.getMinIntensity()), peak_rb(area.getMaxMZ(), area.getMaxIntensity());
57 // reference to the current data
58 const auto& spectrum = getCurrentSpectrum();
59 const Size spectrum_index = getCurrentIndex();
60
61 // get iterator on first peak with lower position than interval_start
62 auto left_it = lower_bound(spectrum.begin(), spectrum.end(), peak_lt, PeakType::PositionLess());
63
64 // get iterator on first peak with higher position than interval_end
65 auto right_it = lower_bound(left_it, spectrum.end(), peak_rb, PeakType::PositionLess());
66
67 if (left_it == right_it) // both are equal => no peak falls into this interval
68 {
69 return PeakIndex();
70 }
71
72 if (left_it == right_it - 1)
73 {
74 return PeakIndex(spectrum_index, left_it - spectrum.begin());
75 }
76
77 auto nearest_it = left_it;
78 const auto center_intensity = (peak_lt.getIntensity() + peak_rb.getIntensity()) * 0.5;
79 for (auto it = left_it; it != right_it; ++it)
80 {
81 if (abs(center_intensity - it->getIntensity()) < abs(center_intensity - nearest_it->getIntensity()))
82 {
83 nearest_it = it;
84 }
85 }
86 return PeakIndex(spectrum_index, nearest_it - spectrum.begin());
87 }
88
89 std::unique_ptr<Painter1DBase> LayerData1DPeak::getPainter1D() const
90 {

Callers 1

findPeakAtPosition_Method · 0.45

Calls 10

getCurrentIndexFunction · 0.85
getMinMZMethod · 0.80
getMinIntensityMethod · 0.80
getMaxMZMethod · 0.80
PositionLessClass · 0.50
PeakIndexClass · 0.50
getMaxIntensityMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
getIntensityMethod · 0.45

Tested by

no test coverage detected