Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ApplicationLibCode/Commands/CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicCreateContourMapPolygonFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCreateContourMapPolygonAdvancedFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCreateContourMapPolygonTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RicComputeContourMapPeaksFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicPolygonFromImageDialog.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCreateSummaryEnsembleFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicImportGridAndSummaryEnsembleDialog.cpp
Expand Down
69 changes: 69 additions & 0 deletions ApplicationLibCode/Commands/RicComputeContourMapPeaksFeature.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////

#include "RicComputeContourMapPeaksFeature.h"

#include "RicExportContourMapToTextFeature.h"

#include "ContourMap/RimContourMapPeaksCollection.h"
#include "ContourMap/RimContourMapProjection.h"
#include "ContourMap/RimEclipseContourMapView.h"
#include "RimGeoMechContourMapView.h"

#include <QAction>

CAF_CMD_SOURCE_INIT( RicComputeContourMapPeaksFeature, "RicComputeContourMapPeaksFeature" );

//--------------------------------------------------------------------------------------------------
/// Enabled for all contour map view types (Eclipse, GeoMech and ensemble statistics).
//--------------------------------------------------------------------------------------------------
bool RicComputeContourMapPeaksFeature::isCommandEnabled() const
{
auto [existingEclipseContourMap, existingGeoMechContourMap] = RicExportContourMapToTextFeature::findContourMapView();

return existingEclipseContourMap || existingGeoMechContourMap;
}

//--------------------------------------------------------------------------------------------------
/// Computes peaks using the peaks collection's current (default, unless previously edited) peakCount and
/// minDistance field values. Use the "Contour Map Peaks" object's own property panel to customize and
/// recompute.
//--------------------------------------------------------------------------------------------------
void RicComputeContourMapPeaksFeature::onActionTriggered( bool isChecked )
{
auto [existingEclipseContourMap, existingGeoMechContourMap] = RicExportContourMapToTextFeature::findContourMapView();

RimContourMapProjection* contourMapProjection = nullptr;
if ( existingEclipseContourMap ) contourMapProjection = existingEclipseContourMap->contourMapProjection();
if ( existingGeoMechContourMap ) contourMapProjection = existingGeoMechContourMap->contourMapProjection();
if ( !contourMapProjection ) return;

auto* peaksCollection = contourMapProjection->peaksCollection();
if ( !peaksCollection ) return;

peaksCollection->computePeaks();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicComputeContourMapPeaksFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setIcon( QIcon( ":/WellTargetPoint16x16.png" ) );
actionToSetup->setText( "Compute Contour Map Peaks" );
}
38 changes: 38 additions & 0 deletions ApplicationLibCode/Commands/RicComputeContourMapPeaksFeature.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "cafCmdFeature.h"

//==================================================================================================
/// Compute the N most significant peaks (local maxima) in the current contour map, and create a marker
/// (single-point polygon) for each in the project tree.
///
/// Available for Eclipse and GeoMech contour maps, including ensemble statistics contour maps
/// (RimStatisticsContourMapView derives from RimEclipseContourMapView).
//==================================================================================================
class RicComputeContourMapPeaksFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;

protected:
bool isCommandEnabled() const override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};
19 changes: 1 addition & 18 deletions ApplicationLibCode/Commands/RicCreateContourMapPolygonTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,7 @@ void createPolygonObjects( const std::vector<std::vector<cvf::Vec3d>>& polygons
newPolygon->coordinatesChanged.send();
}

polygonCollection->updateAllRequiredEditors();

// Update polygon collections in all views so new polygons become visible
if ( auto project = RimProject::current() )
{
for ( auto* view : project->allViews() )
{
if ( auto* gridView = dynamic_cast<RimGridView*>( view ) )
{
if ( auto* polyCollection = gridView->polygonInViewCollection() )
{
polyCollection->updateFromPolygonCollection();
polyCollection->updateConnectedEditors();
}
gridView->scheduleCreateDisplayModelAndRedraw();
}
}
}
polygonCollection->updateViewsAfterPolygonsChanged();
}

} // namespace internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ void RimPolygonFilter::defineUiOrdering( QString uiConfigName, caf::PdmUiOrderin
auto group1 = uiOrdering.addNewGroup( "Polygon Selection" );
group1->add( &m_polyFilterMode );

bool isPolygonClosed = m_cellFilterPolygon() ? m_cellFilterPolygon->isClosed() : false;
if ( isPolygonClosed )
const bool isClosed = isPolygonClosed();
if ( isClosed )
{
group1->add( &m_polyIncludeType );
}
Expand All @@ -291,7 +291,7 @@ void RimPolygonFilter::defineUiOrdering( QString uiConfigName, caf::PdmUiOrderin
objField->uiCapability()->setUiReadOnly( readOnlyState );
}

if ( !isPolygonClosed )
if ( !isClosed )
{
m_polyFilterMode = RimPolygonFilter::PolygonFilterModeType::INDEX_K;
m_polyFilterMode.uiCapability()->setUiReadOnly( true );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RimContourMapInView.cpp
${CMAKE_CURRENT_LIST_DIR}/RimContourMapInViewCollection.cpp
${CMAKE_CURRENT_LIST_DIR}/RimContourMapProjection.cpp
${CMAKE_CURRENT_LIST_DIR}/RimContourMapPeak.cpp
${CMAKE_CURRENT_LIST_DIR}/RimContourMapPeaksCollection.cpp
${CMAKE_CURRENT_LIST_DIR}/RimEclipseContourMapProjection.cpp
${CMAKE_CURRENT_LIST_DIR}/RimEclipseContourMapView.cpp
${CMAKE_CURRENT_LIST_DIR}/RimEclipseContourMapViewCollection.cpp
Expand Down
145 changes: 145 additions & 0 deletions ApplicationLibCode/ProjectDataModel/ContourMap/RimContourMapPeak.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////

#include "RimContourMapPeak.h"

#include "Polygons/RimPolygon.h"
#include "Polygons/RimPolygonCollection.h"

CAF_PDM_SOURCE_INIT( RimContourMapPeak, "RimContourMapPeak" );

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimContourMapPeak::RimContourMapPeak()
{
CAF_PDM_InitObject( "Peak", ":/WellTargetPoint16x16.png" );

CAF_PDM_InitField( &m_rank, "Rank", 0, "Rank" );
m_rank.uiCapability()->setUiReadOnly( true );

CAF_PDM_InitField( &m_value, "Value", 0.0, "Value" );
m_value.uiCapability()->setUiReadOnly( true );

CAF_PDM_InitField( &m_prominence, "Prominence", 0.0, "Prominence" );
m_prominence.uiCapability()->setUiReadOnly( true );

CAF_PDM_InitField( &m_position, "Position", cvf::Vec3d::ZERO, "Position" );
m_position.uiCapability()->setUiReadOnly( true );

CAF_PDM_InitFieldNoDefault( &m_markerPolygon, "MarkerPolygon", "Marker Polygon" );
m_markerPolygon.uiCapability()->setUiHidden( true );
}

//--------------------------------------------------------------------------------------------------
/// Delete the marker polygon along with this object, so no orphaned polygons are left behind in the
/// project-wide polygon collection when a peak is removed (e.g. via the generic delete-item command).
//--------------------------------------------------------------------------------------------------
RimContourMapPeak::~RimContourMapPeak()
{
deleteMarkerPolygon();
}

//--------------------------------------------------------------------------------------------------
/// Only the marker polygon and its direct parent field are accessed, no project-wide lookups, so this is
/// safe during project teardown. If the polygon collection is destroyed first, the pointer field is
/// already null. The polygon is removed from whichever container owns it, also if the user moved it into
/// a sub-folder. The project tree and views are refreshed later from the event loop, as this is also
/// called when a whole contour map view is deleted.
//--------------------------------------------------------------------------------------------------
void RimContourMapPeak::deleteMarkerPolygon()
{
RimPolygon* polygon = m_markerPolygon();
if ( !polygon ) return;

m_markerPolygon = nullptr;

if ( auto* parentField = polygon->parentField() ) parentField->removeChild( polygon );
delete polygon;

RimPolygonCollection::scheduleUpdateViewsAfterPolygonsChanged();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimContourMapPeak::setValues( int rank, double value, double prominence, const cvf::Vec3d& domainPosition )
{
m_rank = rank;
m_value = value;
m_prominence = prominence;
m_position = domainPosition;

setName( QString( "Peak %1 (%2)" ).arg( rank ).arg( value, 0, 'g', 6 ) );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimContourMapPeak::setMarkerPolygon( RimPolygon* markerPolygon )
{
m_markerPolygon = markerPolygon;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimContourMapPeak::releaseMarkerPolygon()
{
m_markerPolygon = nullptr;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RimContourMapPeak::rank() const
{
return m_rank();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RimContourMapPeak::value() const
{
return m_value();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RimContourMapPeak::prominence() const
{
return m_prominence();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Vec3d RimContourMapPeak::position() const
{
return m_position();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPolygon* RimContourMapPeak::markerPolygon() const
{
return m_markerPolygon();
}
68 changes: 68 additions & 0 deletions ApplicationLibCode/ProjectDataModel/ContourMap/RimContourMapPeak.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RimNamedObject.h"

#include "cafPdmField.h"
#include "cafPdmPtrField.h"

#include "cvfVector3.h"

class RimPolygon;

//==================================================================================================
/// A single computed "peak" (local maximum) in a contour map, as produced by RigContourMapPeakFinder.
///
/// Stores the result value, prominence and rank for inspection/sorting in the project tree, and
/// references a small marker RimPolygon (owned by the global polygon collection, so it can be
/// mirrored and rendered by the existing polygon-in-view machinery) used to visualize the peak's
/// position in 3d views. The marker polygon is deleted together with this object, unless it has been
/// detached with releaseMarkerPolygon().
//==================================================================================================
class RimContourMapPeak : public RimNamedObject
{
CAF_PDM_HEADER_INIT;

public:
RimContourMapPeak();
~RimContourMapPeak() override;

void setValues( int rank, double value, double prominence, const cvf::Vec3d& domainPosition );
void setMarkerPolygon( RimPolygon* markerPolygon );

// Stop referencing the marker polygon without deleting it
void releaseMarkerPolygon();

int rank() const;
double value() const;
double prominence() const;
cvf::Vec3d position() const;
RimPolygon* markerPolygon() const;

private:
void deleteMarkerPolygon();

private:
caf::PdmField<int> m_rank;
caf::PdmField<double> m_value;
caf::PdmField<double> m_prominence;
caf::PdmField<cvf::Vec3d> m_position;
caf::PdmPtrField<RimPolygon*> m_markerPolygon;
Comment thread
magnesj marked this conversation as resolved.
};
Loading
Loading