From b67f546774ad67d131815ac3bebee575556c5d24 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Tue, 2 Jan 2024 23:23:59 -0600 Subject: [PATCH] Use parallel std::find_if to find radial at azimuth --- .../scwx/qt/view/level3_radial_view.cpp | 55 ++++++++++--------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/scwx-qt/source/scwx/qt/view/level3_radial_view.cpp b/scwx-qt/source/scwx/qt/view/level3_radial_view.cpp index 0875ac3c..aa6a322f 100644 --- a/scwx-qt/source/scwx/qt/view/level3_radial_view.cpp +++ b/scwx-qt/source/scwx/qt/view/level3_radial_view.cpp @@ -556,33 +556,38 @@ Level3RadialView::GetBinLevel(const common::Coordinate& coordinate) const // Find Radial const std::uint16_t numRadials = radialData->number_of_radials(); - std::uint16_t radial = numRadials; - double nextAngle = radialData->start_angle(0); - for (std::uint16_t i = 0; i < numRadials; ++i) - { - double startAngle = nextAngle; - nextAngle = radialData->start_angle((i + 1) % numRadials); + auto radials = boost::irange(0u, numRadials); - if (startAngle < nextAngle) + auto radial = std::find_if( // + std::execution::par_unseq, + radials.begin(), + radials.end(), + [&](std::uint32_t i) { - if (startAngle <= azi1 && azi1 < nextAngle) - { - radial = i; - break; - } - } - else - { - // If the bin crosses 0/360 degrees, special handling is needed - if (startAngle <= azi1 || azi1 < nextAngle) - { - radial = i; - break; - } - } - } + bool found = false; + double startAngle = radialData->start_angle(i); + double nextAngle = radialData->start_angle((i + 1) % numRadials); - if (radial == numRadials) + if (startAngle < nextAngle) + { + if (startAngle <= azi1 && azi1 < nextAngle) + { + found = true; + } + } + else + { + // If the bin crosses 0/360 degrees, special handling is needed + if (startAngle <= azi1 || azi1 < nextAngle) + { + found = true; + } + } + + return found; + }); + + if (radial == radials.end()) { // No radial was found (not likely to happen without a gap in data) return std::nullopt; @@ -590,7 +595,7 @@ Level3RadialView::GetBinLevel(const common::Coordinate& coordinate) const // Compute threshold at which to display an individual bin const std::uint16_t snrThreshold = descriptionBlock->threshold(); - const std::uint8_t level = radialData->level(radial).at(gate); + const std::uint8_t level = radialData->level(*radial).at(gate); if (level < snrThreshold && level != RANGE_FOLDED) {