From 871a06428978559a9024adabed7d35a18018b8e6 Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Fri, 7 Mar 2025 13:21:25 +0100 Subject: [PATCH] #12211 Show mesh lines on fracture triangle geometry --- .../Surfaces/RivSurfacePartMgr.cpp | 68 +++++++++++++++++-- .../Surfaces/RivSurfacePartMgr.h | 3 + .../Surfaces/RimFractureSurface.cpp | 8 +++ .../Surfaces/RimFractureSurface.h | 1 + .../ProjectDataModel/Surfaces/RimSurface.cpp | 8 +++ .../ProjectDataModel/Surfaces/RimSurface.h | 3 + .../Surfaces/RimSurfaceInView.cpp | 20 +++++- .../Surfaces/RimSurfaceInView.h | 4 ++ .../Surfaces/RimSurfaceInViewCollection.cpp | 2 + 9 files changed, 110 insertions(+), 7 deletions(-) diff --git a/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfacePartMgr.cpp b/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfacePartMgr.cpp index c614c7ef90..53fc69da83 100644 --- a/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfacePartMgr.cpp +++ b/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfacePartMgr.cpp @@ -44,6 +44,7 @@ #include "cvfPart.h" #include "cvfPrimitiveSetIndexedUInt.h" #include "cvfRenderStateBlending.h" +#include "cvfVector3.h" #include @@ -91,6 +92,11 @@ void RivSurfacePartMgr::appendNativeGeometryPartsToModel( cvf::ModelBasicList* m model->addPart( m_nativeTrianglesPart.p() ); + if ( m_nativeMeshLinesPart.isNull() && m_surfaceInView->isMeshLinesEnabled() ) + { + generateNativeLinesPartGeometry(); + } + if ( m_nativeMeshLinesPart.notNull() ) { m_nativeMeshLinesPart->setTransform( scaleTransform ); @@ -400,7 +406,7 @@ void RivSurfacePartMgr::generatePartGeometry() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RivSurfacePartMgr::generateNativePartGeometry() +cvf::ref RivSurfacePartMgr::convertToDisplayOffsetVertices( const std::vector& vertices ) const { cvf::Vec3d displayModOffset( 0, 0, 0 ); @@ -411,17 +417,27 @@ void RivSurfacePartMgr::generateNativePartGeometry() if ( ownerCase ) displayModOffset = ownerCase->displayModelOffset(); } + cvf::ref cvfVertices = new cvf::Vec3fArray( vertices.size() ); + for ( size_t i = 0; i < vertices.size(); ++i ) + { + ( *cvfVertices )[i] = cvf::Vec3f( vertices[i] - displayModOffset ); + } + + return cvfVertices; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RivSurfacePartMgr::generateNativePartGeometry() +{ m_usedSurfaceData = m_surfaceInView->surface()->surfaceData(); if ( m_usedSurfaceData.isNull() ) return; const std::vector& vertices = m_usedSurfaceData->vertices(); if ( vertices.empty() ) return; - cvf::ref cvfVertices = new cvf::Vec3fArray( vertices.size() ); - for ( size_t i = 0; i < vertices.size(); ++i ) - { - ( *cvfVertices )[i] = cvf::Vec3f( vertices[i] - displayModOffset ); - } + cvf::ref cvfVertices = convertToDisplayOffsetVertices( vertices ); const std::vector& triangleIndices = m_usedSurfaceData->triangleIndices(); cvf::ref cvfIndices = new cvf::UIntArray( triangleIndices ); @@ -440,3 +456,43 @@ void RivSurfacePartMgr::generateNativePartGeometry() m_nativeTrianglesPart->setDrawable( drawGeo.p() ); m_nativeTrianglesPart->setSourceInfo( objectSourceInfo.p() ); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RivSurfacePartMgr::generateNativeLinesPartGeometry() +{ + m_usedSurfaceData = m_surfaceInView->surface()->surfaceData(); + if ( m_usedSurfaceData.isNull() ) return; + + const std::vector& vertices = m_usedSurfaceData->vertices(); + if ( vertices.empty() ) return; + + cvf::ref cvfVertices = convertToDisplayOffsetVertices( vertices ); + + const std::vector& triangleIndices = m_usedSurfaceData->triangleIndices(); + cvf::ref cvfIndices = new cvf::UIntArray( triangleIndices ); + + cvf::ref indexSet = new cvf::PrimitiveSetIndexedUInt( cvf::PT_LINE_STRIP ); + indexSet->setIndices( cvfIndices.p() ); + + cvf::ref drawGeo = new cvf::DrawableGeo; + drawGeo->addPrimitiveSet( indexSet.p() ); + drawGeo->setVertexArray( cvfVertices.p() ); + drawGeo->computeNormals(); + + m_nativeMeshLinesPart = new cvf::Part; + m_nativeMeshLinesPart->setName( "Mesh" ); + m_nativeMeshLinesPart->setDrawable( drawGeo.p() ); + + m_nativeMeshLinesPart->updateBoundingBox(); + m_nativeMeshLinesPart->setEnableMask( meshFaultBit ); + m_nativeMeshLinesPart->setPriority( RivPartPriority::PartType::MeshLines ); + + m_nativeMeshLinesPart->setSourceInfo( new RivMeshLinesSourceInfo( m_surfaceInView ) ); + + caf::MeshEffectGenerator lineEffGen( cvf::Color3::BLACK ); + lineEffGen.setLineWidth( 1.0f ); + cvf::ref eff = lineEffGen.generateCachedEffect(); + m_nativeMeshLinesPart->setEffect( eff.p() ); +} diff --git a/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfacePartMgr.h b/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfacePartMgr.h index 34ed50d3bd..05c6d148ab 100644 --- a/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfacePartMgr.h +++ b/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfacePartMgr.h @@ -59,6 +59,9 @@ private: void generatePartGeometry(); void generateNativePartGeometry(); + void generateNativeLinesPartGeometry(); + + cvf::ref convertToDisplayOffsetVertices( const std::vector& vertices ) const; bool m_useNativePartsOnly; diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp index d3d0ba108d..318690e53b 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp @@ -239,3 +239,11 @@ void RimFractureSurface::updateMinMaxValues( RimRegularLegendConfig* legendConfi legendConfig->setClosestToZeroValues( globalPosClosestToZero, globalNegClosestToZero, localPosClosestToZero, localNegClosestToZero ); legendConfig->setAutomaticRanges( globalMin, globalMax, localMin, localMax ); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimFractureSurface::isMeshLinesEnabledDefault() const +{ + return true; +} diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h index 1a6e8ad807..d8394318b9 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h @@ -41,6 +41,7 @@ public: std::vector> valuesForProperty( const QString& propertyName ) const; void updateMinMaxValues( RimRegularLegendConfig* legend, const QString& propertyName, int currentTimeStep ) const override; + bool isMeshLinesEnabledDefault() const override; protected: bool updateSurfaceData() override; diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.cpp index 9828cd3407..121315c84b 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.cpp @@ -347,3 +347,11 @@ void RimSurface::updateMinMaxValues( RimRegularLegendConfig* legend, const QStri legend->setAutomaticRanges( globalMin, globalMax, globalMin, globalMax ); } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimSurface::isMeshLinesEnabledDefault() const +{ + return false; +} diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.h b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.h index db9a615ec8..7f3393ab0e 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.h +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.h @@ -71,6 +71,8 @@ public: virtual void updateMinMaxValues( RimRegularLegendConfig* legend, const QString& propertyName, int currentTimeStep ) const; + virtual bool isMeshLinesEnabledDefault() const; + protected: void setSurfaceData( RigSurface* surface ); @@ -93,6 +95,7 @@ protected: caf::PdmField m_color; caf::PdmField m_enableOpacity; + caf::PdmField m_showMeshLines; caf::PdmField m_opacity; cvf::ref m_surfaceData; diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInView.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInView.cpp index d0b9dac1e1..eebb4faab8 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInView.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInView.cpp @@ -47,6 +47,8 @@ RimSurfaceInView::RimSurfaceInView() CAF_PDM_InitFieldNoDefault( &m_surface, "SurfaceRef", "Surface" ); m_surface.uiCapability()->setUiHidden( true ); + CAF_PDM_InitField( &m_showMeshLines, "ShowMeshLines", false, "Show Mesh Lines" ); + CAF_PDM_InitFieldNoDefault( &m_resultDefinition, "ResultDefinition", "Result Definition" ); m_resultDefinition.uiCapability()->setUiTreeChildrenHidden( true ); m_resultDefinition = new RimSurfaceResultDefinition; @@ -110,6 +112,22 @@ bool RimSurfaceInView::isNativeSurfaceResultsActive() const return m_resultDefinition->isChecked(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimSurfaceInView::isMeshLinesEnabled() const +{ + return m_showMeshLines(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSurfaceInView::setMeshLinesEnabled( bool meshLinesEnabled ) +{ + m_showMeshLines = meshLinesEnabled; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -223,7 +241,7 @@ void RimSurfaceInView::fieldChangedByUi( const caf::PdmFieldHandle* changedField scheduleRedraw = true; } - if ( changedField == &m_showInactiveCells ) + if ( changedField == &m_showInactiveCells || changedField == &m_showMeshLines ) { clearGeometry(); scheduleRedraw = true; diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInView.h b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInView.h index 93c4a6542d..51dd61d9ba 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInView.h +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInView.h @@ -60,6 +60,9 @@ public: void updateLegendRangesTextAndVisibility( RiuViewer* nativeOrOverrideViewer, bool isUsingOverrideViewer ); + void setMeshLinesEnabled( bool meshLinesEnabled ); + bool isMeshLinesEnabled() const; + protected: void initAfterRead() override; @@ -72,6 +75,7 @@ private: caf::PdmProxyValueField m_name; caf::PdmPtrField m_surface; + caf::PdmField m_showMeshLines; caf::PdmChildField m_resultDefinition; diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.cpp index 8fe41dbd40..3caf81e4a4 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.cpp @@ -215,6 +215,8 @@ void RimSurfaceInViewCollection::syncSurfacesWithView() newSurfInView->setActive( false ); } + newSurfInView->setMeshLinesEnabled( surf->isMeshLinesEnabledDefault() ); + orderedSurfs.push_back( newSurfInView ); } else