mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-31 09:14:11 -05:00
Union-find sweep from highest to lowest value computes the prominence of each peak. Peaks are filtered on prominence and edge contact, ranked by prominence or value, and thinned by minimum distance. Flat shoulders and plateaus are rejected, and prominence is measured against the minimum of each connected data region.
66 lines
2.7 KiB
C++
66 lines
2.7 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2026- Equinor ASA
|
|
//
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
//
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
// for more details.
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma once
|
|
|
|
#include <vector>
|
|
|
|
//==================================================================================================
|
|
/// Find the N most significant peaks in a gridded surface / contour map, with a minimum distance
|
|
/// between accepted peaks.
|
|
///
|
|
/// Grid layout: row-major, index = i + j * nx. Undefined cells may be NaN or +/-inf.
|
|
/// Distances are computed in world units via cell sizes dx, dy (rotation does not affect distance).
|
|
//==================================================================================================
|
|
namespace RigContourMapPeakFinder
|
|
{
|
|
struct Peak
|
|
{
|
|
int i = 0;
|
|
int j = 0;
|
|
double x = 0.0;
|
|
double y = 0.0;
|
|
double z = 0.0;
|
|
double prominence = 0.0;
|
|
};
|
|
|
|
struct Settings
|
|
{
|
|
int maxPeaks = 10;
|
|
double minDistance = 0.0; // world units
|
|
double minProminence = 0.0; // z units, filters noise / shoulders
|
|
bool rankByProminence = true; // false: rank by z (after prominence filter)
|
|
bool excludeEdgePeaks = false; // drop peaks touching grid border or undefined cells
|
|
};
|
|
|
|
// Returns prominence per cell: NaN for non-peak cells, >= 0 for peaks.
|
|
// Union-find sweep from highest to lowest value (8-connectivity). O(M log M).
|
|
std::vector<double> computeProminence( const std::vector<double>& z, int nx, int ny );
|
|
|
|
// Find the top N peaks, ranked and filtered according to settings.
|
|
std::vector<Peak> findPeaks( const std::vector<double>& z,
|
|
int nx,
|
|
int ny,
|
|
double dx,
|
|
double dy,
|
|
const Settings& settings,
|
|
double originX = 0.0,
|
|
double originY = 0.0 );
|
|
|
|
} // namespace RigContourMapPeakFinder
|