Add Depth Surface

Add Depth surface and initialize the location of the surface based on the first available grid model. Add feature to create Depth surface.
This commit is contained in:
Magne Sjaastad 2024-07-24 10:25:42 +02:00
parent 337584025c
commit 736bfd9a96
10 changed files with 432 additions and 13 deletions

View File

@ -6,6 +6,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicExportKLayerToPtlFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicExportSurfaceToTsurfFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicNewSurfaceCollectionFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicNewDepthSurfaceFeature.h
)
set(SOURCE_GROUP_SOURCE_FILES
@ -16,6 +17,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicExportKLayerToPtlFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicExportSurfaceToTsurfFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicNewSurfaceCollectionFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicNewDepthSurfaceFeature.cpp
)
list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})

View File

@ -0,0 +1,77 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024 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 "RicNewDepthSurfaceFeature.h"
#include "RimCase.h"
#include "RimDepthSurface.h"
#include "RimProject.h"
#include "RimSurface.h"
#include "RimSurfaceCollection.h"
#include "Riu3DMainWindowTools.h"
#include "cafSelectionManagerTools.h"
#include "cvfBoundingBox.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicNewDepthSurfaceFeature, "RicNewDepthSurfaceFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewDepthSurfaceFeature::onActionTriggered( bool isChecked )
{
auto colls = caf::selectedObjectsByTypeStrict<RimSurfaceCollection*>();
if ( colls.empty() ) return;
auto surface = new RimDepthSurface;
auto allCases = RimProject::current()->allGridCases();
if ( !allCases.empty() )
{
auto sourceCase = allCases.front();
auto bb = sourceCase->activeCellsBoundingBox();
surface->setPlaneExtent( bb.min().x(), bb.min().y(), bb.max().x(), bb.max().y() );
surface->setDepth( -bb.center().z() );
bb.expand( 0.1 * bb.extent().z() );
auto lowerDepthLimit = -bb.max().z();
auto upperDepthLimit = -bb.min().z();
surface->setDepthSliderLimits( lowerDepthLimit, upperDepthLimit );
}
surface->loadDataIfRequired();
auto surfColl = colls.front();
surfColl->addSurfacesAtIndex( -1, { surface } );
surfColl->updateConnectedEditors();
Riu3DMainWindowTools::selectAsCurrentItem( surface );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewDepthSurfaceFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setIcon( QIcon( ":/ReservoirSurfaces16x16.png" ) );
actionToSetup->setText( "Create Depth Surface" );
}

View File

@ -0,0 +1,33 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024 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"
//==================================================================================================
///
//==================================================================================================
class RicNewDepthSurfaceFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@ -146,7 +146,6 @@
#include "RimSummaryTableCollection.h"
#include "RimSummaryTimeAxisProperties.h"
#include "RimSurface.h"
#include "RimSurfaceCollection.h"
#include "RimValveTemplate.h"
#include "RimValveTemplateCollection.h"
#include "RimViewController.h"
@ -1023,15 +1022,6 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
{
menuBuilder << "RicNewElasticPropertyScalingFeature";
}
else if ( dynamic_cast<RimSurfaceCollection*>( firstUiItem ) )
{
menuBuilder << "RicImportSurfacesFeature";
menuBuilder << "RicNewGridSurfaceFeature";
menuBuilder << "RicImportEnsembleSurfaceFeature";
menuBuilder << "RicCreateEnsembleSurfaceFeature";
menuBuilder.addSeparator();
menuBuilder << "RicNewSurfaceCollectionFeature";
}
else if ( dynamic_cast<RimSurface*>( firstUiItem ) )
{
if ( dynamic_cast<RimGridCaseSurface*>( firstUiItem ) )

View File

@ -8,6 +8,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RimSurfaceResultDefinition.h
${CMAKE_CURRENT_LIST_DIR}/RimEnsembleSurface.h
${CMAKE_CURRENT_LIST_DIR}/RimEnsembleStatisticsSurface.h
${CMAKE_CURRENT_LIST_DIR}/RimDepthSurface.h
)
set(SOURCE_GROUP_SOURCE_FILES
@ -20,6 +21,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RimSurfaceResultDefinition.cpp
${CMAKE_CURRENT_LIST_DIR}/RimEnsembleSurface.cpp
${CMAKE_CURRENT_LIST_DIR}/RimEnsembleStatisticsSurface.cpp
${CMAKE_CURRENT_LIST_DIR}/RimDepthSurface.cpp
)
list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})

View File

@ -0,0 +1,239 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024 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 "RimDepthSurface.h"
#include "RigSurface.h"
#include "RimSurfaceCollection.h"
#include "cafPdmObjectScriptingCapability.h"
#include "cafPdmUiDoubleSliderEditor.h"
#include "cafPdmUiDoubleValueEditor.h"
#include "cvfVector3.h"
CAF_PDM_SOURCE_INIT( RimDepthSurface, "RimDepthSurface" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimDepthSurface::RimDepthSurface()
{
CAF_PDM_InitScriptableObject( "DepthSurface", ":/ReservoirSurface16x16.png" );
CAF_PDM_InitField( &m_minX, "MinX", 0.0, "Min X" );
CAF_PDM_InitField( &m_maxX, "MaxX", 0.0, "Max X" );
CAF_PDM_InitField( &m_minY, "MinY", 0.0, "Min Y" );
CAF_PDM_InitField( &m_maxY, "MaxY", 0.0, "Min Y" );
CAF_PDM_InitField( &m_depth, "Depth", 0.0, "Depth" );
CAF_PDM_InitField( &m_depthLowerLimit, "DepthLowerLimit", 0.0, "Lower Limit" );
m_depthLowerLimit.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleValueEditor::uiEditorTypeName() );
CAF_PDM_InitField( &m_depthUpperLimit, "DepthUpperLimit", 100000.0, "Upper Limit" );
m_depthUpperLimit.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleValueEditor::uiEditorTypeName() );
m_minX.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleValueEditor::uiEditorTypeName() );
m_maxX.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleValueEditor::uiEditorTypeName() );
m_minY.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleValueEditor::uiEditorTypeName() );
m_maxY.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleValueEditor::uiEditorTypeName() );
m_depth.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleSliderEditor::uiEditorTypeName() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimDepthSurface::~RimDepthSurface()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimDepthSurface::onLoadData()
{
return updateSurfaceData();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurface* RimDepthSurface::createCopy()
{
return copyObject<RimDepthSurface>();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimDepthSurface::setPlaneExtent( double minX, double minY, double maxX, double maxY )
{
m_minX = minX;
m_minY = minY;
m_maxX = maxX;
m_maxY = maxY;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimDepthSurface::setDepth( double depth )
{
m_depth = depth;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimDepthSurface::setDepthSliderLimits( double lower, double upper )
{
m_depthLowerLimit = lower;
m_depthUpperLimit = upper;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimDepthSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
{
RimSurface::fieldChangedByUi( changedField, oldValue, newValue );
clearCachedNativeData();
updateSurfaceData();
auto surfColl = firstAncestorOrThisOfTypeAsserted<RimSurfaceCollection>();
surfColl->updateViews( { this } );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimDepthSurface::defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute )
{
caf::PdmUiDoubleValueEditorAttribute::testAndSetFixedWithTwoDecimals( attribute );
if ( field == &m_depth )
{
if ( auto attr = dynamic_cast<caf::PdmUiDoubleSliderEditorAttribute*>( attribute ) )
{
attr->m_minimum = m_depthLowerLimit;
attr->m_maximum = m_depthUpperLimit;
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimDepthSurface::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
uiOrdering.add( &m_depth );
{
auto group = uiOrdering.addNewGroup( "Depth Limits" );
group->setCollapsedByDefault();
group->add( &m_depthLowerLimit );
group->add( &m_depthUpperLimit );
}
{
auto group = uiOrdering.addNewGroup( "Extent" );
group->add( &m_minX );
group->add( &m_maxX );
group->add( &m_minY );
group->add( &m_maxY );
}
{
// Fields from RimSurface
auto group = uiOrdering.addNewGroup( "Appearance" );
group->add( &m_userDescription );
group->add( &m_color );
}
uiOrdering.skipRemainingFields();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimDepthSurface::clearCachedNativeData()
{
m_vertices.clear();
m_triangleIndices.clear();
}
//--------------------------------------------------------------------------------------------------
/// Returns false for fatal failure
//--------------------------------------------------------------------------------------------------
bool RimDepthSurface::updateSurfaceData()
{
auto displayZ = -m_depth;
cvf::Vec3d a( m_minX, m_minY, displayZ );
cvf::Vec3d b( m_maxX, m_minY, displayZ );
cvf::Vec3d c( m_maxX, m_maxY, displayZ );
cvf::Vec3d d( m_minX, m_maxY, displayZ );
m_vertices.push_back( a );
m_vertices.push_back( b );
m_vertices.push_back( c );
m_vertices.push_back( d );
m_triangleIndices.push_back( 0 );
m_triangleIndices.push_back( 1 );
m_triangleIndices.push_back( 2 );
m_triangleIndices.push_back( 0 );
m_triangleIndices.push_back( 2 );
m_triangleIndices.push_back( 3 );
if ( !m_triangleIndices.empty() )
{
std::vector<unsigned> tringleIndices{ m_triangleIndices };
std::vector<cvf::Vec3d> vertices{ m_vertices };
cvf::Vec3d offset;
offset.z() += depthOffset();
RimSurface::applyDepthOffset( offset, &vertices );
auto surfaceData = new RigSurface;
surfaceData->setTriangleData( tringleIndices, vertices );
setSurfaceData( surfaceData );
}
else
{
setSurfaceData( nullptr );
}
return true;
}
//--------------------------------------------------------------------------------------------------
/// Return the name to show in the project tree
//--------------------------------------------------------------------------------------------------
QString RimDepthSurface::fullName() const
{
QString retval = RimSurface::fullName();
if ( !retval.isEmpty() ) retval += " - ";
retval += "Depth: ";
retval += QString::number( m_depth );
return retval;
}

View File

@ -0,0 +1,59 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024 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 "RimSurface.h"
class RimDepthSurface : public RimSurface
{
CAF_PDM_HEADER_INIT;
public:
RimDepthSurface();
~RimDepthSurface() override;
bool onLoadData() override;
RimSurface* createCopy() override;
void setPlaneExtent( double minX, double minY, double maxX, double maxY );
void setDepth( double depth );
void setDepthSliderLimits( double lower, double upper );
private:
bool updateSurfaceData() override;
void clearCachedNativeData() override;
QString fullName() const override;
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override;
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
private:
caf::PdmField<double> m_minX;
caf::PdmField<double> m_maxX;
caf::PdmField<double> m_minY;
caf::PdmField<double> m_maxY;
caf::PdmField<double> m_depth;
caf::PdmField<double> m_depthLowerLimit;
caf::PdmField<double> m_depthUpperLimit;
std::vector<unsigned> m_triangleIndices;
std::vector<cvf::Vec3d> m_vertices;
};

View File

@ -80,11 +80,12 @@ protected:
virtual void clearCachedNativeData() = 0;
protected:
caf::PdmField<QString> m_userDescription;
caf::PdmField<cvf::Color3f> m_color;
cvf::ref<RigSurface> m_surfaceData;
private:
caf::PdmField<QString> m_userDescription;
caf::PdmField<cvf::Color3f> m_color;
caf::PdmField<double> m_depthOffset;
caf::PdmProxyValueField<QString> m_nameProxy;
caf::PdmField<double> m_depthOffset;
};

View File

@ -37,6 +37,7 @@
#include "cafPdmFieldReorderCapability.h"
#include "cafCmdFeatureMenuBuilder.h"
#include "cafPdmFieldScriptingCapability.h"
#include "cafPdmObjectScriptingCapability.h"
@ -274,6 +275,20 @@ std::vector<RimSurfaceCollection*> RimSurfaceCollection::subCollections() const
return m_subCollections.childrenByType();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceCollection::appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const
{
menuBuilder << "RicImportSurfacesFeature";
menuBuilder << "RicNewGridSurfaceFeature";
menuBuilder << "RicNewDepthSurfaceFeature";
menuBuilder << "RicImportEnsembleSurfaceFeature";
menuBuilder << "RicCreateEnsembleSurfaceFeature";
menuBuilder.addSeparator();
menuBuilder << "RicNewSurfaceCollectionFeature";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -71,6 +71,7 @@ public:
protected:
caf::PdmFieldHandle* userDescriptionField() override;
void appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const override;
private:
void orderChanged( const caf::SignalEmitter* emitter );