Skip to content

Commit

Permalink
Improve visual appearance for depth surface
Browse files Browse the repository at this point in the history
- disable intersection geometry with cell property colors
- allow opacity
- set default color to blue, as most user use this plane for oil-water contact
  • Loading branch information
magnesj committed Aug 27, 2024
1 parent 4d66bff commit c89e1ec
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "cvfModelBasicList.h"
#include "cvfPart.h"
#include "cvfPrimitiveSetIndexedUInt.h"
#include "cvfRenderStateBlending.h"

#include <limits>

Expand Down Expand Up @@ -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() )
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<cvf::Effect> effBehind = surfaceGenBehind.generateCachedEffect();
if ( m_nativeTrianglesPart.notNull() )
{
if ( opacityEnabled )
{
m_nativeTrianglesPart->setPriority( RivPartPriority::PartType::Transparent );
cvf::ref<cvf::RenderStateBlending> 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<cvf::Effect> eff = surfaceGen.generateCachedEffect();
if ( opacityEnabled )
{
m_intersectionFaces->setPriority( RivPartPriority::PartType::Transparent );
cvf::ref<cvf::RenderStateBlending> blending = new cvf::RenderStateBlending;
blending->configureTransparencyBlending();
eff->setRenderState( blending.p() );
}

m_intersectionFaces->setEffect( eff.p() );
}
Expand Down
14 changes: 14 additions & 0 deletions ApplicationLibCode/ProjectDataModel/Surfaces/RimDepthSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ RimSurface* RimDepthSurface::createCopy()
return copyObject<RimDepthSurface>();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimDepthSurface::showIntersectionCellResults()
{
// Avoid use of cell intersection results color for depth surfaces
return false;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "RimSurface.h"

#include "cafPdmCoreVec3d.h"

class RimDepthSurface : public RimSurface
{
CAF_PDM_HEADER_INIT;
Expand All @@ -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 );
Expand Down
41 changes: 41 additions & 0 deletions ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down Expand Up @@ -94,6 +98,31 @@ cvf::Color3f RimSurface::color() const
return m_color();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::pair<bool, float> 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;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -162,6 +191,9 @@ double RimSurface::depthOffset() const
return m_depthOffset;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurface::setDepthOffset( double depthoffset )
{
m_depthOffset.setValue( depthoffset );
Expand Down Expand Up @@ -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<caf::PdmUiDoubleSliderEditorAttribute*>( attribute ) )
{
attr->m_minimum = 0.0;
attr->m_maximum = 1.0;
}
}
}
10 changes: 9 additions & 1 deletion ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class RimSurface : public caf::PdmObject
void setColor( const cvf::Color3f& color );
cvf::Color3f color() const;

std::pair<bool, float> opacity() const;
void setOpacity( bool useOpacity, float opacity );

virtual bool showIntersectionCellResults();

RigSurface* surfaceData();
QString userDescription();
void setUserDescription( const QString& description );
Expand Down Expand Up @@ -80,8 +85,11 @@ class RimSurface : public caf::PdmObject
virtual void clearCachedNativeData() = 0;

protected:
caf::PdmField<QString> m_userDescription;
caf::PdmField<QString> m_userDescription;

caf::PdmField<cvf::Color3f> m_color;
caf::PdmField<bool> m_enableOpacity;
caf::PdmField<double> m_opacity;

cvf::ref<RigSurface> m_surfaceData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "cafPdmField.h"
#include "cafPdmProxyValueField.h"
#include "cafPdmPtrField.h"
#include "cvfVector3.h"

class RimWellPathGeometryDef;

Expand Down

0 comments on commit c89e1ec

Please sign in to comment.