Fix ensemble rft crash (#7160)

* #7138 Ensemble RFT Plot : Guard access to viewer when MDI window is closed

* #7138 Ensemble RFT Plot : Never insert empty vectors

* #7138 Ensemble RFT Plot : Remove cvf legend drawer

* #7138 Ensemble RFT Plot : Improve visibility of statistics curves

* #7138 Ensemble RFT Plot : Modernization

* Fixes by clang-format

Co-authored-by: magnesj <magnesj@users.noreply.github.com>
This commit is contained in:
Magne Sjaastad
2021-01-05 14:00:32 +01:00
committed by GitHub
parent 3209dcde6c
commit 5b9371c5f3
12 changed files with 39 additions and 238 deletions

View File

@@ -66,7 +66,10 @@ void RiaCurveMerger<XValueType>::addCurveData( const std::vector<XValueType>& xV
{
CVF_ASSERT( xValues.size() == yValues.size() );
m_originalValues.push_back( std::make_pair( xValues, yValues ) );
if ( !xValues.empty() )
{
m_originalValues.push_back( std::make_pair( xValues, yValues ) );
}
}
//--------------------------------------------------------------------------------------------------
@@ -181,6 +184,8 @@ void RiaCurveMerger<XValueType>::computeUnionOfXValues( bool includeValuesForPar
std::vector<std::pair<XValueType, XValueType>> originalXBounds;
for ( const auto& curveData : m_originalValues )
{
if ( curveData.first.empty() ) continue;
for ( const auto& x : curveData.first )
{
unionOfXValues.insert( x );

View File

@@ -212,8 +212,11 @@ void RifReaderEnsembleStatisticsRft::calculateStatistics( const RifEclipseRftAdd
std::vector<double> pressures;
reader->values( depthAddress, &depths );
reader->values( pressAddress, &pressures );
dataSetSizeCalc.addValueAndWeight( depths.size(), 1.0 );
curveMerger.addCurveData( depths, pressures );
if ( !depths.empty() && !pressures.empty() )
{
dataSetSizeCalc.addValueAndWeight( depths.size(), 1.0 );
curveMerger.addCurveData( depths, pressures );
}
}
}
curveMerger.computeInterpolatedValues( false );

View File

@@ -22,7 +22,6 @@
#include "RimSummaryCase.h"
#include "RimWellRftPlot.h"
#include "RiuCvfOverlayItemWidget.h"
#include "RiuQwtPlotWidget.h"
#include "cafPdmUiListEditor.h"

View File

@@ -54,7 +54,8 @@
#include "RimWellPlotTools.h"
#include "RimWellPltPlot.h"
#include "RiuCvfOverlayItemWidget.h"
#include "RiuAbstractLegendFrame.h"
#include "RiuAbstractOverlayContentFrame.h"
#include "RiuDraggableOverlayFrame.h"
#include "RiuQwtPlotWidget.h"
@@ -328,7 +329,7 @@ void RimWellRftPlot::updateEditorsFromPreviousSelection()
bool dummy = false;
auto dataSourceOptions = calculateValueOptions( &m_selectedSources, &dummy );
for ( auto dataSourceOption : dataSourceOptions )
for ( const auto& dataSourceOption : dataSourceOptions )
{
if ( dataSourceOption.level() == 1 )
{
@@ -343,7 +344,7 @@ void RimWellRftPlot::updateEditorsFromPreviousSelection()
// This has to happen after the m_selectedSources is filled
// because the available time steps is dependent on the selected sources.
auto timeStepOptions = calculateValueOptions( &m_selectedTimeSteps, &dummy );
for ( auto timeStepOption : timeStepOptions )
for ( const auto& timeStepOption : timeStepOptions )
{
QDateTime timeStep = timeStepOption.value().toDateTime();
if ( previousTimeSteps.count( timeStep ) )
@@ -584,6 +585,7 @@ void RimWellRftPlot::updateCurvesInPlot( const std::set<RiaRftPltCurveDefinition
QString label = uiText.replace( ": Pressure", "" );
label = RiaStatisticsTools::replacePercentileByPValueText( label );
curve->setSymbolLabel( label );
curve->setLineThickness( 3 );
}
}
}
@@ -1021,7 +1023,7 @@ std::map<QString, QStringList> RimWellRftPlot::findWellSources()
for ( RimSummaryCaseCollection* summaryCaseColl : rftEnsembles )
{
std::set<QString> wellsWithRftData = summaryCaseColl->wellsWithRftData();
for ( QString wellName : wellsWithRftData )
for ( const QString& wellName : wellsWithRftData )
{
wellNames[wellName].push_back( "Ensemble" );
}
@@ -1034,7 +1036,7 @@ std::map<QString, QStringList> RimWellRftPlot::findWellSources()
{
for ( RimObservedFmuRftData* rftFmuData : allRftFmuData )
{
for ( QString wellName : rftFmuData->wells() )
for ( const QString& wellName : rftFmuData->wells() )
{
wellNames[wellName].push_back( "Observed" );
}
@@ -1214,7 +1216,7 @@ cvf::Color3f RimWellRftPlot::findCurveColor( RimWellLogCurve* curve )
{
cvf::Color3f backgroundColor =
RiaColorTools::fromQColorTo3f( plotByIndex( 0 )->viewer()->canvasBackground().color() );
curveColor = RiaColorTools::blendCvfColors( backgroundColor, curveColor, 2, 1 );
curveColor = RiaColorTools::blendCvfColors( backgroundColor, curveColor, 1, 2 );
}
}
}
@@ -1235,12 +1237,15 @@ void RimWellRftPlot::defineCurveColorsAndSymbols( const std::set<RiaRftPltCurveD
m_timeStepSymbols.clear();
// Clear all ensemble legends
RimWellLogTrack* track = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) );
for ( auto ensembleLegendPair : m_ensembleLegendFrames )
RiuQwtPlotWidget* viewer = nullptr;
RimWellLogTrack* track = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) );
if ( track ) viewer = track->viewer();
for ( const auto& ensembleLegendPair : m_ensembleLegendFrames )
{
if ( track->viewer() && ensembleLegendPair.second )
if ( viewer && ensembleLegendPair.second )
{
track->viewer()->removeOverlayFrame( ensembleLegendPair.second );
viewer->removeOverlayFrame( ensembleLegendPair.second );
delete ensembleLegendPair.second;
}
}
@@ -1257,18 +1262,18 @@ void RimWellRftPlot::defineCurveColorsAndSymbols( const std::set<RiaRftPltCurveD
{
curveSet->initializeLegend();
if ( curveSet->legendConfig()->showLegend() && curveSet->colorMode() == ColorMode::BY_ENSEMBLE_PARAM &&
!curveSet->currentEnsembleParameter().isEmpty() )
if ( viewer && curveSet->legendConfig()->showLegend() &&
curveSet->colorMode() == ColorMode::BY_ENSEMBLE_PARAM && !curveSet->currentEnsembleParameter().isEmpty() )
{
if ( !m_ensembleLegendFrames[curveSet] )
{
m_ensembleLegendFrames[curveSet] =
new RiuCvfOverlayItemWidget( curveSet->legendConfig()->titledOverlayFrame(),
track->viewer()->canvas(),
track->viewer()->overlayMargins() );
auto m = new RiuDraggableOverlayFrame( viewer->canvas(), viewer->overlayMargins() );
m->setContentFrame( curveSet->legendConfig()->makeLegendFrame() );
m_ensembleLegendFrames[curveSet] = m;
}
track->viewer()->addOverlayFrame( m_ensembleLegendFrames[curveSet] );
viewer->addOverlayFrame( m_ensembleLegendFrames[curveSet] );
}
}
}
@@ -1289,8 +1294,8 @@ void RimWellRftPlot::defineCurveColorsAndSymbols( const std::set<RiaRftPltCurveD
auto colorTableIndex = m_dataSourceColors.size();
auto symbolTableIndex = m_timeStepSymbols.size();
RifDataSourceForRftPlt address = curveDefToAdd.address();
RifDataSourceForRftPlt colorAddress = address;
const RifDataSourceForRftPlt& address = curveDefToAdd.address();
RifDataSourceForRftPlt colorAddress = address;
if ( address.sourceType() == RifDataSourceForRftPlt::SUMMARY_RFT )
{
colorAddress = RifDataSourceForRftPlt( RifDataSourceForRftPlt::ENSEMBLE_RFT, address.ensemble() );

View File

@@ -32,7 +32,6 @@
#include "RigFormationNames.h"
#include "RigMainGrid.h"
#include "RiuCvfOverlayItemWidget.h"
#include "RiuGridCrossQwtPlot.h"
#include "RiuScalarMapperLegendFrame.h"

View File

@@ -286,7 +286,10 @@ bool RimSummaryCalculation::calculate()
std::vector<time_t> curveTimeSteps = RiaSummaryCurveDefinition::timeSteps( curveDef );
timeHistoryCurveMerger.addCurveData( curveTimeSteps, curveValues );
if ( !curveTimeSteps.empty() && !curveValues.empty() )
{
timeHistoryCurveMerger.addCurveData( curveTimeSteps, curveValues );
}
}
timeHistoryCurveMerger.computeInterpolatedValues();

View File

@@ -55,7 +55,6 @@
#include "RimTimeStepFilter.h"
#include "RiuAbstractLegendFrame.h"
#include "RiuCvfOverlayItemWidget.h"
#include "RiuDraggableOverlayFrame.h"
#include "RiuPlotMainWindow.h"
#include "RiuQwtPlotCurve.h"

View File

@@ -26,7 +26,6 @@ ${CMAKE_CURRENT_LIST_DIR}/RiuQwtCurvePointTracker.h
${CMAKE_CURRENT_LIST_DIR}/RiuQwtPlotWheelZoomer.h
${CMAKE_CURRENT_LIST_DIR}/RiuQwtPlotZoomer.h
${CMAKE_CURRENT_LIST_DIR}/RiuWidgetDragger.h
${CMAKE_CURRENT_LIST_DIR}/RiuCvfOverlayItemWidget.h
${CMAKE_CURRENT_LIST_DIR}/RiuRecentFileActionProvider.h
${CMAKE_CURRENT_LIST_DIR}/RiuRelativePermeabilityPlotPanel.h
${CMAKE_CURRENT_LIST_DIR}/RiuRelativePermeabilityPlotUpdater.h
@@ -123,7 +122,6 @@ ${CMAKE_CURRENT_LIST_DIR}/RiuQwtScalePicker.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuQwtCurvePointTracker.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuQwtPlotWheelZoomer.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuWidgetDragger.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuCvfOverlayItemWidget.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuRecentFileActionProvider.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuRelativePermeabilityPlotPanel.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuRelativePermeabilityPlotUpdater.cpp
@@ -246,7 +244,6 @@ ${CMAKE_CURRENT_LIST_DIR}/RiuTofAccumulatedPhaseFractionsPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuQwtScalePicker.h
${CMAKE_CURRENT_LIST_DIR}/RiuQwtPlotWheelZoomer.h
${CMAKE_CURRENT_LIST_DIR}/RiuWidgetDragger.h
${CMAKE_CURRENT_LIST_DIR}/RiuCvfOverlayItemWidget.h
${CMAKE_CURRENT_LIST_DIR}/RiuEditPerforationCollectionWidget.h
${CMAKE_CURRENT_LIST_DIR}/RiuAdvancedSnapshotExportWidget.h
${CMAKE_CURRENT_LIST_DIR}/RiuWellAllocationPlot.h

View File

@@ -1,150 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiuCvfOverlayItemWidget.h"
#include "RiaGuiApplication.h"
#include "cafAssert.h"
#include "cafTitledOverlayFrame.h"
#include "cafViewer.h"
#include "cvfCamera.h"
#include "cvfFramebufferObject.h"
#include "cvfRenderSequence.h"
#include "cvfRenderbufferObject.h"
#include "cvfRendering.h"
#include "cvfqtUtils.h"
#include <QLabel>
#include <QPainter>
#include <QPixmap>
#include <QPushButton>
#include <QResizeEvent>
#include "glew/GL/glew.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuCvfOverlayItemWidget::RiuCvfOverlayItemWidget( caf::TitledOverlayFrame* overlayItem,
QWidget* parent,
const int snapMargins,
const QColor& backgroundColor /*= QColor( 255, 255, 255, 100 ) */ )
: RiuDraggableOverlayFrame( parent, snapMargins, backgroundColor )
, m_overlayItem( overlayItem )
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuCvfOverlayItemWidget::~RiuCvfOverlayItemWidget()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize RiuCvfOverlayItemWidget::sizeHint() const
{
auto preferredSize = const_cast<caf::TitledOverlayFrame*>( m_overlayItem.p() )->preferredSize();
return QSize( preferredSize.x(), preferredSize.y() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuCvfOverlayItemWidget::renderTo( QPainter* painter, const QRect& paintRect, double scaleX, double scaleY )
{
unsigned int width = static_cast<unsigned int>( paintRect.width() );
unsigned int height = static_cast<unsigned int>( paintRect.height() );
m_overlayItem->setRenderSize( cvf::Vec2ui( width, height ) );
QGLFormat glFormat;
glFormat.setDirectRendering( RiaGuiApplication::instance()->useShaders() );
caf::Viewer* viewer = new caf::Viewer( glFormat, nullptr );
cvf::OpenGLContext* cvfOglContext = viewer->cvfOpenGLContext();
viewer->resize( width, height );
// Create a rendering
cvf::ref<cvf::Rendering> rendering = new cvf::Rendering;
m_overlayItem->setLayoutFixedPosition( { 0, 0 } );
rendering->addOverlayItem( m_overlayItem.p() );
rendering->camera()->setViewport( 0, 0, width, height );
rendering->camera()->viewport()->setClearColor( { 1, 1, 1, 0 } );
cvf::ref<cvf::RenderSequence> renderingSequence = new cvf::RenderSequence;
renderingSequence->addRendering( rendering.p() );
if ( RiaGuiApplication::instance()->useShaders() )
{
// Set up frame and render buffers
cvf::ref<cvf::FramebufferObject> fbo = new cvf::FramebufferObject;
cvf::ref<cvf::RenderbufferObject> rboColor =
new cvf::RenderbufferObject( cvf::RenderbufferObject::RGBA, width, height );
cvf::ref<cvf::RenderbufferObject> rboDepth =
new cvf::RenderbufferObject( cvf::RenderbufferObject::DEPTH_COMPONENT24, width, height );
fbo->attachDepthRenderbuffer( rboDepth.p() );
fbo->attachColorRenderbuffer( 0, rboColor.p() );
fbo->applyOpenGL( cvfOglContext );
rendering->setTargetFramebuffer( fbo.p() );
fbo->bind( cvfOglContext );
}
renderingSequence->render( cvfOglContext );
// Read data from frame buffer
cvf::UByteArray arr( 4 * width * height );
glReadPixels( 0, 0, static_cast<GLsizei>( width ), static_cast<GLsizei>( height ), GL_RGBA, GL_UNSIGNED_BYTE, arr.ptr() );
// Create a cvf texture image
cvf::ref<cvf::TextureImage> img = new cvf::TextureImage;
img->setData( arr.ptr(), width, height );
QImage image = cvfqt::Utils::toQImage( *img.p() );
// image.save("jjsLegendImageTest.png");
QPixmap pixmap = QPixmap::fromImage( image );
delete viewer;
painter->save();
painter->drawPixmap( paintRect.topLeft(), pixmap );
painter->restore();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuCvfOverlayItemWidget::paintEvent( QPaintEvent* e )
{
QRect paintRect = e->rect();
QPainter painter( this );
renderTo( &painter, paintRect, 1.0, 1.0 );
}

View File

@@ -1,57 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RiuDraggableOverlayFrame.h"
#include "cvfObject.h"
#include <QLabel>
#include <QSize>
#include <QWidget>
namespace caf
{
class TitledOverlayFrame;
}
//==================================================================================================
//
//
//
//==================================================================================================
class RiuCvfOverlayItemWidget : public RiuDraggableOverlayFrame
{
Q_OBJECT
public:
explicit RiuCvfOverlayItemWidget( caf::TitledOverlayFrame* overlayItem,
QWidget* parent,
const int snapMargins,
const QColor& backgroundColor = QColor( 255, 255, 255, 100 ) );
~RiuCvfOverlayItemWidget() override;
QSize sizeHint() const override;
void renderTo( QPainter* painter, const QRect& paintRect, double scaleX, double scaleY );
protected:
void paintEvent( QPaintEvent* e ) override;
private:
cvf::ref<caf::TitledOverlayFrame> m_overlayItem;
};

View File

@@ -27,7 +27,6 @@
#include "RimPlotAxisPropertiesInterface.h"
#include "RimRegularLegendConfig.h"
#include "RiuCvfOverlayItemWidget.h"
#include "RiuGuiTheme.h"
#include "RiuPlotAnnotationTool.h"
#include "RiuQwtCurvePointTracker.h"

View File

@@ -38,7 +38,6 @@
#include "RimSummaryPlot.h"
#include "RimSummaryPlotCollection.h"
#include "RiuCvfOverlayItemWidget.h"
#include "RiuPlotAnnotationTool.h"
#include "RiuQwtCurvePointTracker.h"
#include "RiuQwtPlotWheelZoomer.h"