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

Method findClosestDataPoint

src/openms_gui/source/VISUAL/LayerData1DChrom.cpp:39–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37 }
38
39 PeakIndex LayerData1DChrom::findClosestDataPoint(const RangeAllType& area) const
40 {
41 ChromatogramPeak peak_lt {area.getMinRT(), area.getMinIntensity()}, peak_rb {area.getMaxRT(), area.getMaxIntensity()};
42 // reference to the current data
43 const auto& chrom = getCurrentChrom();
44 const Size index = getCurrentIndex();
45
46 // get iterator on first peak with lower position than interval_start
47 auto left_it = lower_bound(chrom.begin(), chrom.end(), peak_lt, ChromatogramPeak::PositionLess());
48
49 // get iterator on first peak with higher position than interval_end
50 auto right_it = lower_bound(left_it, chrom.end(), peak_rb, ChromatogramPeak::PositionLess());
51
52 if (left_it == right_it) // both are equal => no peak falls into this interval
53 {
54 return PeakIndex();
55 }
56
57 if (left_it == right_it - 1)
58 {
59 return PeakIndex(index, left_it - chrom.begin());
60 }
61
62 auto nearest_it = left_it;
63 const auto center_intensity = (peak_lt.getIntensity() + peak_rb.getIntensity()) * 0.5;
64 for (auto it = left_it; it != right_it; ++it)
65 {
66 if (abs(center_intensity - it->getIntensity()) < abs(center_intensity - nearest_it->getIntensity()))
67 {
68 nearest_it = it;
69 }
70 }
71 return PeakIndex(index, nearest_it - chrom.begin());
72 }
73
74 std::unique_ptr<Painter1DBase> LayerData1DChrom::getPainter1D() const
75 {

Callers

nothing calls this directly

Calls 10

getCurrentIndexFunction · 0.85
getMinRTMethod · 0.80
getMinIntensityMethod · 0.80
getMaxRTMethod · 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