From c89e1ecb726b5305574fb5a127ae06603c68e01f Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 27 Aug 2024 09:48:21 +0200 Subject: [PATCH] Improve visual appearance for depth surface - disable intersection geometry with cell property colors - allow opacity - set default color to blue, as most user use this plane for oil-water contact --- .../RicNewDepthSurfaceFeature.cpp | 4 ++ .../Surfaces/RivSurfacePartMgr.cpp | 27 ++++++++++-- .../Surfaces/RimDepthSurface.cpp | 14 +++++++ .../Surfaces/RimDepthSurface.h | 4 ++ .../ProjectDataModel/Surfaces/RimSurface.cpp | 41 +++++++++++++++++++ .../ProjectDataModel/Surfaces/RimSurface.h | 10 ++++- .../WellPath/RimWellPathTarget.h | 1 - 7 files changed, 96 insertions(+), 5 deletions(-) diff --git a/ApplicationLibCode/Commands/SurfaceCommands/RicNewDepthSurfaceFeature.cpp b/ApplicationLibCode/Commands/SurfaceCommands/RicNewDepthSurfaceFeature.cpp index 47ac3f718b..77d0f0e66a 100644 --- a/ApplicationLibCode/Commands/SurfaceCommands/RicNewDepthSurfaceFeature.cpp +++ b/ApplicationLibCode/Commands/SurfaceCommands/RicNewDepthSurfaceFeature.cpp @@ -44,6 +44,10 @@ void RicNewDepthSurfaceFeature::onActionTriggered( bool isChecked ) auto surface = new RimDepthSurface; + // As this surface is usually a oil-water contact, we set the color to blue + surface->setColor( cvf::Color3f::BLUE ); + surface->setOpacity( true, 0.6f ); + auto allCases = RimProject::current()->allGridCases(); if ( !allCases.empty() ) { diff --git a/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfacePartMgr.cpp b/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfacePartMgr.cpp index 42d72709e2..c614c7ef90 100644 --- a/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfacePartMgr.cpp +++ b/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfacePartMgr.cpp @@ -43,6 +43,7 @@ #include "cvfModelBasicList.h" #include "cvfPart.h" #include "cvfPrimitiveSetIndexedUInt.h" +#include "cvfRenderStateBlending.h" #include @@ -121,7 +122,8 @@ void RivSurfacePartMgr::updateCellResultColor( int timeStepIndex ) //-------------------------------------------------------------------------------------------------- void RivSurfacePartMgr::appendIntersectionGeometryPartsToModel( cvf::ModelBasicList* model, cvf::Transform* scaleTransform ) { - if ( !m_surfaceInView->surfaceResultDefinition()->isChecked() ) + if ( m_surfaceInView->surface() && m_surfaceInView->surface()->showIntersectionCellResults() && + !m_surfaceInView->surfaceResultDefinition()->isChecked() ) { if ( m_intersectionFaces.isNull() ) { @@ -162,6 +164,9 @@ void RivSurfacePartMgr::appendIntersectionGeometryPartsToModel( cvf::ModelBasicL //-------------------------------------------------------------------------------------------------- void RivSurfacePartMgr::updateNativeSurfaceColors() { + const auto [opacityEnabled, surfaceOpacityValue] = m_surfaceInView->surface()->opacity(); + const auto opacityValueToUse = opacityEnabled ? surfaceOpacityValue : 1.0f; + if ( m_surfaceInView->surfaceResultDefinition()->isChecked() ) { if ( m_usedSurfaceData.isNull() ) generateNativePartGeometry(); @@ -199,19 +204,35 @@ void RivSurfacePartMgr::updateNativeSurfaceColors() } else { - caf::SurfaceEffectGenerator surfaceGenBehind( cvf::Color4f( m_surfaceInView->surface()->color() ), caf::PO_POS_LARGE ); + const auto color = cvf::Color4f( m_surfaceInView->surface()->color(), opacityValueToUse ); + caf::SurfaceEffectGenerator surfaceGenBehind( color, caf::PO_POS_LARGE ); cvf::ref effBehind = surfaceGenBehind.generateCachedEffect(); if ( m_nativeTrianglesPart.notNull() ) { + if ( opacityEnabled ) + { + m_nativeTrianglesPart->setPriority( RivPartPriority::PartType::Transparent ); + cvf::ref blending = new cvf::RenderStateBlending; + blending->configureTransparencyBlending(); + effBehind->setRenderState( blending.p() ); + } + m_nativeTrianglesPart->setEffect( effBehind.p() ); } } if ( m_intersectionFaces.notNull() ) { - caf::SurfaceEffectGenerator surfaceGen( cvf::Color4f( m_surfaceInView->surface()->color() ), caf::PO_1 ); + caf::SurfaceEffectGenerator surfaceGen( cvf::Color4f( m_surfaceInView->surface()->color(), opacityValueToUse ), caf::PO_1 ); cvf::ref eff = surfaceGen.generateCachedEffect(); + if ( opacityEnabled ) + { + m_intersectionFaces->setPriority( RivPartPriority::PartType::Transparent ); + cvf::ref blending = new cvf::RenderStateBlending; + blending->configureTransparencyBlending(); + eff->setRenderState( blending.p() ); + } m_intersectionFaces->setEffect( eff.p() ); } diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimDepthSurface.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimDepthSurface.cpp index cfb0778c0c..95d33567d5 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimDepthSurface.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimDepthSurface.cpp @@ -81,6 +81,15 @@ RimSurface* RimDepthSurface::createCopy() return copyObject(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimDepthSurface::showIntersectionCellResults() +{ + // Avoid use of cell intersection results color for depth surfaces + return false; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -141,6 +150,8 @@ void RimDepthSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedField, //-------------------------------------------------------------------------------------------------- void RimDepthSurface::defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) { + RimSurface::defineEditorAttribute( field, uiConfigName, attribute ); + caf::PdmUiDoubleValueEditorAttribute::testAndSetFixedWithTwoDecimals( attribute ); if ( field == &m_depth ) @@ -199,6 +210,9 @@ void RimDepthSurface::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering auto group = uiOrdering.addNewGroup( "Appearance" ); group->add( &m_userDescription ); group->add( &m_color ); + + group->add( &m_enableOpacity ); + group->add( &m_opacity ); } uiOrdering.skipRemainingFields(); diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimDepthSurface.h b/ApplicationLibCode/ProjectDataModel/Surfaces/RimDepthSurface.h index 7b100ceead..e3ac532115 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimDepthSurface.h +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimDepthSurface.h @@ -20,6 +20,8 @@ #include "RimSurface.h" +#include "cafPdmCoreVec3d.h" + class RimDepthSurface : public RimSurface { CAF_PDM_HEADER_INIT; @@ -31,6 +33,8 @@ class RimDepthSurface : public RimSurface bool onLoadData() override; RimSurface* createCopy() override; + bool showIntersectionCellResults() override; + void setPlaneExtent( double minX, double minY, double maxX, double maxY ); void setDepth( double depth ); void setDepthSliderLimits( double lower, double upper ); diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.cpp index 4b4046ce90..d6bc2bcabd 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.cpp @@ -56,7 +56,11 @@ RimSurface::RimSurface() CAF_PDM_InitScriptableObject( "Surface", ":/ReservoirSurface16x16.png" ); CAF_PDM_InitScriptableFieldNoDefault( &m_userDescription, "SurfaceUserDecription", "Name" ); + CAF_PDM_InitField( &m_color, "SurfaceColor", cvf::Color3f( 0.5f, 0.3f, 0.2f ), "Color" ); + CAF_PDM_InitField( &m_enableOpacity, "EnableOpacity", false, "Enable Opacity" ); + CAF_PDM_InitField( &m_opacity, "Opacity", 0.6, "Opacity Value [0..1]" ); + m_opacity.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleSliderEditor::uiEditorTypeName() ); CAF_PDM_InitScriptableField( &m_depthOffset, "DepthOffset", 0.0, "Depth Offset" ); m_depthOffset.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleSliderEditor::uiEditorTypeName() ); @@ -94,6 +98,31 @@ cvf::Color3f RimSurface::color() const return m_color(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::pair RimSurface::opacity() const +{ + return std::make_pair( m_enableOpacity(), m_opacity() ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSurface::setOpacity( bool useOpacity, float opacity ) +{ + m_enableOpacity.setValue( useOpacity ); + m_opacity.setValue( opacity ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimSurface::showIntersectionCellResults() +{ + return true; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -162,6 +191,9 @@ double RimSurface::depthOffset() const return m_depthOffset; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- void RimSurface::setDepthOffset( double depthoffset ) { m_depthOffset.setValue( depthoffset ); @@ -273,4 +305,13 @@ void RimSurface::defineEditorAttribute( const caf::PdmFieldHandle* field, QStrin doubleSliderAttrib->m_maximum = minimumExtent; } } + + if ( field == &m_opacity ) + { + if ( auto attr = dynamic_cast( attribute ) ) + { + attr->m_minimum = 0.0; + attr->m_maximum = 1.0; + } + } } diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.h b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.h index 64e433769f..1177f402cf 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.h +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.h @@ -51,6 +51,11 @@ class RimSurface : public caf::PdmObject void setColor( const cvf::Color3f& color ); cvf::Color3f color() const; + std::pair opacity() const; + void setOpacity( bool useOpacity, float opacity ); + + virtual bool showIntersectionCellResults(); + RigSurface* surfaceData(); QString userDescription(); void setUserDescription( const QString& description ); @@ -80,8 +85,11 @@ class RimSurface : public caf::PdmObject virtual void clearCachedNativeData() = 0; protected: - caf::PdmField m_userDescription; + caf::PdmField m_userDescription; + caf::PdmField m_color; + caf::PdmField m_enableOpacity; + caf::PdmField m_opacity; cvf::ref m_surfaceData; diff --git a/ApplicationLibCode/ProjectDataModel/WellPath/RimWellPathTarget.h b/ApplicationLibCode/ProjectDataModel/WellPath/RimWellPathTarget.h index cfe4523eff..23079ed4b1 100644 --- a/ApplicationLibCode/ProjectDataModel/WellPath/RimWellPathTarget.h +++ b/ApplicationLibCode/ProjectDataModel/WellPath/RimWellPathTarget.h @@ -26,7 +26,6 @@ #include "cafPdmField.h" #include "cafPdmProxyValueField.h" #include "cafPdmPtrField.h" -#include "cvfVector3.h" class RimWellPathGeometryDef;