| 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 | { |
no test coverage detected