Fix geomech reload issues

This commit is contained in:
Jon Jenssen 2023-01-25 15:41:56 +01:00 committed by jonjenssen
parent 0cdaf5b62e
commit 42a9fef2d3
8 changed files with 58 additions and 42 deletions

View File

@ -332,3 +332,11 @@ void RivGeoMechVizLogic::calculateCurrentTotalCellVisibility( cvf::UByteArray* t
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivGeoMechVizLogic::resetPartMgrs()
{
m_partMgrCache = new RivGeoMechPartMgrCache;
}

View File

@ -49,6 +49,8 @@ public:
void scheduleGeometryRegen( RivCellSetEnum geometryType );
void scheduleGeometryRegenOfVisiblePartMgrs( int viewerStepIndex );
void calculateCurrentTotalCellVisibility( cvf::UByteArray* totalVisibility, int viewerStepIndex );
void resetPartMgrs();
std::vector<RivGeoMechPartMgrCache::Key> keysToVisiblePartMgrs( int viewerStepIndex ) const;
const cvf::ref<RivGeoMechPartMgrCache> partMgrCache() const;

View File

@ -136,7 +136,7 @@ void RivTensorResultPartMgr::appendDynamicGeometryPartsToModel( cvf::ModelBasicL
{
const RivGeoMechPartMgr* partMgr = partMgrCache->partMgr( partKey );
auto mgr = partMgr->femPartMgrs()[partIdx];
auto& mgr = partMgr->femPartMgrs()[partIdx];
{
const RivFemPartGeometryGenerator* surfaceGenerator = mgr->surfaceGenerator();
const std::vector<size_t>& quadVerticesToNodeIdxMapping = surfaceGenerator->quadVerticesToNodeIdxMapping();

View File

@ -234,8 +234,9 @@ void RimGeoMechCase::reloadDataAndUpdate()
{
RiaLogging::error( QString::fromStdString( errMsg ) );
}
for ( auto v : geoMechViews() )
for ( auto& v : geoMechViews() )
{
v->resetVizLogic();
v->loadDataAndUpdate();
v->setCurrentTimeStep( v->currentTimeStep() );
}

View File

@ -67,20 +67,17 @@ void RimGeoMechPartCollection::syncWithCase( RimGeoMechCase* geoCase )
{
const int count = geoCase->geoMechData()->femParts()->partCount();
if ( count != (int)m_parts.size() )
m_parts.deleteChildren();
for ( int i = 0; i < count; i++ )
{
m_parts.deleteChildren();
const auto& femPart = geoCase->geoMechData()->femParts()->part( i );
for ( int i = 0; i < count; i++ )
{
const auto& femPart = geoCase->geoMechData()->femParts()->part( i );
RimGeoMechPart* part = new RimGeoMechPart();
part->setPartId( i );
part->setName( QString( femPart->name().c_str() ) );
part->setCheckState( femPart->enabled() );
m_parts.push_back( part );
}
RimGeoMechPart* part = new RimGeoMechPart();
part->setPartId( i );
part->setName( QString( femPart->name().c_str() ) );
part->setCheckState( femPart->enabled() );
m_parts.push_back( part );
}
}
updateConnectedEditors();
@ -173,33 +170,25 @@ bool RimGeoMechPartCollection::isDisplacementsUsed() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimGeoMechPartCollection::shouldRebuildPartVisualization( int currentTimeStep, bool showDisplacement, double scaleFactor )
std::pair<bool, bool>
RimGeoMechPartCollection::needsReloadOrRebuildUpdate( int currentTimeStep, bool showDisplacement, double scaleFactor )
{
// if show flag has changed, we need to rebuild grid viz.
bool retVal = m_displacementsUsed != showDisplacement;
bool rebuild = m_displacementsUsed != showDisplacement || ( m_currentDisplacementTimeStep != currentTimeStep ) ||
( std::abs( m_currentScaleFactor - scaleFactor ) > 0.0001 );
bool reload = false;
// if scaling or timestep has changed, we need to rebuild grid if the displacement should be visible
if ( showDisplacement )
retVal = retVal || ( m_currentDisplacementTimeStep != currentTimeStep ) ||
( std::abs( m_currentScaleFactor - scaleFactor ) > 0.0001 );
return retVal;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimGeoMechPartCollection::shouldReloadDisplacements( int currentTimeStep, bool showDisplacement, double scaleFactor )
{
// no need to reload something we are not showing
if ( !showDisplacement ) return false;
// if we have no displacements at all, we need to reload.
for ( const auto& part : m_parts )
{
if ( part->displacements().size() == 0 ) return true;
bool missingDisplacement = false;
for ( const auto& part : m_parts )
{
missingDisplacement = missingDisplacement || ( part->displacements().size() == 0 );
}
rebuild = rebuild || missingDisplacement;
reload = ( m_currentDisplacementTimeStep != currentTimeStep ) || missingDisplacement;
}
// if timestep has changed we need to reload
return m_currentDisplacementTimeStep != currentTimeStep;
return std::make_pair( reload, rebuild );
}

View File

@ -23,6 +23,7 @@
#include "cvfVector3.h"
#include <utility>
#include <vector>
class RimGeoMechPart;
@ -38,8 +39,8 @@ public:
void syncWithCase( RimGeoMechCase* geoCase );
bool shouldRebuildPartVisualization( int currentTimeStep, bool showDisplacement, double scaleFactor );
bool shouldReloadDisplacements( int currentTimeStep, bool showDisplacement, double scaleFactor );
std::pair<bool, bool> needsReloadOrRebuildUpdate( int currentTimeStep, bool showDisplacement, double scaleFactor );
bool shouldBeVisibleInTree() const;
bool isPartEnabled( int partId ) const;

View File

@ -362,10 +362,12 @@ RimPropertyFilterCollection* RimGeoMechView::nativePropertyFilterCollection()
//--------------------------------------------------------------------------------------------------
void RimGeoMechView::updateElementDisplacements()
{
if ( !m_partsCollection->shouldRebuildPartVisualization( m_currentTimeStep, m_showDisplacement, m_displacementScaling ) )
return;
auto [reload, rebuild] =
m_partsCollection->needsReloadOrRebuildUpdate( m_currentTimeStep, m_showDisplacement, m_displacementScaling );
if ( m_partsCollection->shouldReloadDisplacements( m_currentTimeStep, m_showDisplacement, m_displacementScaling ) )
if ( !rebuild ) return;
if ( reload )
{
for ( auto part : m_partsCollection->parts() )
{
@ -1123,3 +1125,14 @@ void RimGeoMechView::setShowDisplacementsAndUpdate( bool show )
m_showDisplacement = show;
createDisplayModelAndRedraw();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGeoMechView::resetVizLogic()
{
if ( m_vizLogic.notNull() )
{
m_vizLogic->resetPartMgrs();
}
}

View File

@ -114,6 +114,8 @@ public:
std::pair<int, int> currentStepAndDataFrame() const;
void resetVizLogic();
protected:
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "" ) override;