From 6d9985d2ef92b835071cf6c63b8b94432edb839e Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 4 May 2020 15:00:14 +0200 Subject: [PATCH] #5865 Fault and NNC performance : Build NNC geometry when needed --- .../ModelVisualization/RivFaultPartMgr.cpp | 172 +++++++++++------- .../ModelVisualization/RivFaultPartMgr.h | 10 + 2 files changed, 120 insertions(+), 62 deletions(-) diff --git a/ApplicationCode/ModelVisualization/RivFaultPartMgr.cpp b/ApplicationCode/ModelVisualization/RivFaultPartMgr.cpp index aca436e0f7..4099e96b4c 100644 --- a/ApplicationCode/ModelVisualization/RivFaultPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivFaultPartMgr.cpp @@ -64,6 +64,11 @@ RivFaultPartMgr::RivFaultPartMgr( const RigGridBase* grid, , m_rimFault( rimFault ) , m_opacityLevel( 1.0f ) , m_defaultColor( cvf::Color3::WHITE ) + , m_isNativeFaultsGenerated( false ) + , m_isOppositeFaultsGenerated( false ) + , m_isNativeNncsGenerated( false ) + , m_isAllNncsGenerated( false ) + { CVF_ASSERT( rimFault->faultGeometry() ); cvf::ref> connIdxes = new cvf::Array; @@ -100,7 +105,7 @@ void RivFaultPartMgr::setCellVisibility( cvf::UByteArray* cellVisibilities ) m_NNCGenerator->setCellVisibility( cellVisibilities, m_grid.p() ); m_allenNNCGenerator->setCellVisibility( cellVisibilities, m_grid.p() ); - generatePartGeometry(); + clearFlags(); } //-------------------------------------------------------------------------------------------------- @@ -379,73 +384,96 @@ void RivFaultPartMgr::generatePartGeometry() } } - { - cvf::ref geo = m_NNCGenerator->generateSurface(); - if ( geo.notNull() ) - { - geo->computeNormals(); - - if ( useBufferObjects ) - { - geo->setRenderMode( cvf::DrawableGeo::BUFFER_OBJECT ); - } - - cvf::ref part = new cvf::Part; - part->setName( "NNC in Fault. Grid " + cvf::String( static_cast( m_grid->gridIndex() ) ) ); - part->setDrawable( geo.p() ); - - // Set mapping from triangle face index to cell index - cvf::ref si = new RivSourceInfo( m_rimFault, m_grid->gridIndex() ); - si->m_NNCIndices = m_NNCGenerator->triangleToNNCIndex().p(); - part->setSourceInfo( si.p() ); - - part->updateBoundingBox(); - part->setEnableMask( faultBit ); - part->setPriority( RivPartPriority::PartType::Nnc ); - - cvf::ref eff = new cvf::Effect; - part->setEffect( eff.p() ); - - m_NNCFaces = part; - } - } - - { - cvf::ref geo = m_allenNNCGenerator->generateSurface(); - if ( geo.notNull() ) - { - geo->computeNormals(); - - if ( useBufferObjects ) - { - geo->setRenderMode( cvf::DrawableGeo::BUFFER_OBJECT ); - } - - cvf::ref part = new cvf::Part; - part->setName( "Allen NNC in Fault. Grid " + cvf::String( static_cast( m_grid->gridIndex() ) ) ); - part->setDrawable( geo.p() ); - - // Set mapping from triangle face index to cell index - cvf::ref si = new RivSourceInfo( m_rimFault, m_grid->gridIndex() ); - si->m_NNCIndices = m_allenNNCGenerator->triangleToNNCIndex().p(); - part->setSourceInfo( si.p() ); - - part->updateBoundingBox(); - part->setEnableMask( faultBit ); - part->setPriority( RivPartPriority::PartType::Nnc ); - - cvf::ref eff = new cvf::Effect; - part->setEffect( eff.p() ); - - m_allenNNCFaces = part; - } - } + m_isNativeFaultsGenerated = true; + m_isOppositeFaultsGenerated = true; createLabelWithAnchorLine( m_nativeFaultFaces.p() ); updatePartEffect(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RivFaultPartMgr::generateNativeNncPartGeometry() +{ + cvf::ref geo = m_NNCGenerator->generateSurface(); + if ( geo.notNull() ) + { + geo->computeNormals(); + geo->setRenderMode( cvf::DrawableGeo::BUFFER_OBJECT ); + + cvf::ref part = new cvf::Part; + part->setName( "NNC in Fault. Grid " + cvf::String( static_cast( m_grid->gridIndex() ) ) ); + part->setDrawable( geo.p() ); + + // Set mapping from triangle face index to cell index + cvf::ref si = new RivSourceInfo( m_rimFault, m_grid->gridIndex() ); + si->m_NNCIndices = m_NNCGenerator->triangleToNNCIndex().p(); + part->setSourceInfo( si.p() ); + + part->updateBoundingBox(); + part->setEnableMask( faultBit ); + part->setPriority( RivPartPriority::PartType::Nnc ); + + cvf::ref eff = new cvf::Effect; + part->setEffect( eff.p() ); + + m_NNCFaces = part; + + updatePartEffect(); + } + + m_isNativeNncsGenerated = true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RivFaultPartMgr::generateAllNncPartGeometry() +{ + cvf::ref geo = m_allenNNCGenerator->generateSurface(); + if ( geo.notNull() ) + { + geo->computeNormals(); + + geo->setRenderMode( cvf::DrawableGeo::BUFFER_OBJECT ); + + cvf::ref part = new cvf::Part; + part->setName( "Allen NNC in Fault. Grid " + cvf::String( static_cast( m_grid->gridIndex() ) ) ); + part->setDrawable( geo.p() ); + + // Set mapping from triangle face index to cell index + cvf::ref si = new RivSourceInfo( m_rimFault, m_grid->gridIndex() ); + si->m_NNCIndices = m_allenNNCGenerator->triangleToNNCIndex().p(); + part->setSourceInfo( si.p() ); + + part->updateBoundingBox(); + part->setEnableMask( faultBit ); + part->setPriority( RivPartPriority::PartType::Nnc ); + + cvf::ref eff = new cvf::Effect; + part->setEffect( eff.p() ); + + m_allenNNCFaces = part; + + updatePartEffect(); + } + + m_isAllNncsGenerated = true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RivFaultPartMgr::clearFlags() +{ + m_isNativeFaultsGenerated = false; + m_isOppositeFaultsGenerated = false; + m_isNativeNncsGenerated = false; + m_isAllNncsGenerated = false; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -651,6 +679,11 @@ cvf::Vec3f RivFaultPartMgr::findClosestVertex( const cvf::Vec3f& point, const cv //-------------------------------------------------------------------------------------------------- void RivFaultPartMgr::appendNativeFaultFacesToModel( cvf::ModelBasicList* model ) { + if ( !m_isNativeFaultsGenerated ) + { + generatePartGeometry(); + } + if ( m_nativeFaultFaces.notNull() ) { model->addPart( m_nativeFaultFaces.p() ); @@ -662,6 +695,11 @@ void RivFaultPartMgr::appendNativeFaultFacesToModel( cvf::ModelBasicList* model //-------------------------------------------------------------------------------------------------- void RivFaultPartMgr::appendOppositeFaultFacesToModel( cvf::ModelBasicList* model ) { + if ( !m_isOppositeFaultsGenerated ) + { + generatePartGeometry(); + } + if ( m_oppositeFaultFaces.notNull() ) { model->addPart( m_oppositeFaultFaces.p() ); @@ -691,6 +729,11 @@ void RivFaultPartMgr::appendMeshLinePartsToModel( cvf::ModelBasicList* model ) //-------------------------------------------------------------------------------------------------- void RivFaultPartMgr::appendCompleteNNCFacesToModel( cvf::ModelBasicList* model ) { + if ( !m_isAllNncsGenerated ) + { + generateAllNncPartGeometry(); + } + if ( m_allenNNCFaces.notNull() ) model->addPart( m_allenNNCFaces.p() ); } @@ -699,6 +742,11 @@ void RivFaultPartMgr::appendCompleteNNCFacesToModel( cvf::ModelBasicList* model //-------------------------------------------------------------------------------------------------- void RivFaultPartMgr::appendNativeNNCFacesToModel( cvf::ModelBasicList* model ) { + if ( !m_isNativeNncsGenerated ) + { + generateNativeNncPartGeometry(); + } + if ( m_NNCFaces.notNull() ) model->addPart( m_NNCFaces.p() ); } diff --git a/ApplicationCode/ModelVisualization/RivFaultPartMgr.h b/ApplicationCode/ModelVisualization/RivFaultPartMgr.h index a8115a0b4d..bb755a053d 100644 --- a/ApplicationCode/ModelVisualization/RivFaultPartMgr.h +++ b/ApplicationCode/ModelVisualization/RivFaultPartMgr.h @@ -71,6 +71,12 @@ public: private: void generatePartGeometry(); + + void generateNativeNncPartGeometry(); + void generateAllNncPartGeometry(); + + void clearFlags(); + void updatePartEffect(); void updateNNCColors( size_t timeStepIndex, RimEclipseCellColors* cellResultColors ); @@ -91,20 +97,24 @@ private: cvf::ref m_cellVisibility; + bool m_isNativeFaultsGenerated; cvf::ref m_nativeFaultGenerator; cvf::ref m_nativeFaultFaces; cvf::ref m_nativeFaultGridLines; cvf::ref m_nativeFaultFacesTextureCoords; + bool m_isOppositeFaultsGenerated; cvf::ref m_oppositeFaultGenerator; cvf::ref m_oppositeFaultFaces; cvf::ref m_oppositeFaultGridLines; cvf::ref m_oppositeFaultFacesTextureCoords; + bool m_isNativeNncsGenerated; cvf::ref m_NNCGenerator; cvf::ref m_NNCFaces; cvf::ref m_NNCTextureCoords; + bool m_isAllNncsGenerated; cvf::ref m_allenNNCGenerator; cvf::ref m_allenNNCFaces; cvf::ref m_allenNNCTextureCoords;