mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Merge pull request #5081 from OPM/move-error-bar-curve
Curve Error Bars : Move to RimPlotCurve
This commit is contained in:
@@ -18,7 +18,9 @@
|
||||
|
||||
#include "RimPlotCurve.h"
|
||||
|
||||
#include "RiaCurveDataTools.h"
|
||||
#include "RiaGuiApplication.h"
|
||||
|
||||
#include "RimEnsembleCurveSet.h"
|
||||
#include "RimEnsembleCurveSetCollection.h"
|
||||
#include "RimNameConfig.h"
|
||||
@@ -35,12 +37,16 @@
|
||||
|
||||
#include "cvfAssert.h"
|
||||
|
||||
#include "qwt_date.h"
|
||||
#include "qwt_interval_symbol.h"
|
||||
#include "qwt_plot.h"
|
||||
#include "qwt_symbol.h"
|
||||
|
||||
// NB! Special macro for pure virtual class
|
||||
CAF_PDM_XML_ABSTRACT_SOURCE_INIT( RimPlotCurve, "PlotCurve" );
|
||||
|
||||
#define DOUBLE_INF std::numeric_limits<double>::infinity()
|
||||
|
||||
namespace caf
|
||||
{
|
||||
template <>
|
||||
@@ -147,7 +153,12 @@ RimPlotCurve::RimPlotCurve()
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_symbolLabelPosition, "SymbolLabelPosition", "Symbol Label Position", "", "", "" );
|
||||
|
||||
m_qwtPlotCurve = new RiuRimQwtPlotCurve( this );
|
||||
m_qwtPlotCurve = new RiuRimQwtPlotCurve( this );
|
||||
m_qwtCurveErrorBars = new QwtPlotIntervalCurve();
|
||||
m_qwtCurveErrorBars->setStyle( QwtPlotIntervalCurve::CurveStyle::NoCurve );
|
||||
m_qwtCurveErrorBars->setSymbol( new QwtIntervalSymbol( QwtIntervalSymbol::Bar ) );
|
||||
m_qwtCurveErrorBars->setItemAttribute( QwtPlotItem::Legend, false );
|
||||
m_qwtCurveErrorBars->setZ( RiuQwtPlotCurve::Z_ERROR_BARS );
|
||||
|
||||
m_parentQwtPlot = nullptr;
|
||||
}
|
||||
@@ -164,6 +175,13 @@ RimPlotCurve::~RimPlotCurve()
|
||||
m_qwtPlotCurve = nullptr;
|
||||
}
|
||||
|
||||
if ( m_qwtCurveErrorBars )
|
||||
{
|
||||
m_qwtCurveErrorBars->detach();
|
||||
delete m_qwtCurveErrorBars;
|
||||
m_qwtCurveErrorBars = nullptr;
|
||||
}
|
||||
|
||||
if ( m_parentQwtPlot )
|
||||
{
|
||||
m_parentQwtPlot->replot();
|
||||
@@ -220,7 +238,6 @@ void RimPlotCurve::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
|
||||
}
|
||||
else if ( changedField == &m_showErrorBars )
|
||||
{
|
||||
m_qwtPlotCurve->showErrorBars( m_showErrorBars );
|
||||
updateCurveAppearance();
|
||||
}
|
||||
RiuPlotMainWindowTools::refreshToolbars();
|
||||
@@ -271,11 +288,12 @@ void RimPlotCurve::updateCurveVisibility( bool updateParentPlot )
|
||||
{
|
||||
if ( canCurveBeAttached() )
|
||||
{
|
||||
m_qwtPlotCurve->attach( m_parentQwtPlot );
|
||||
attachCurveAndErrorBars();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_qwtPlotCurve->detach();
|
||||
m_qwtCurveErrorBars->detach();
|
||||
}
|
||||
|
||||
if ( updateParentPlot )
|
||||
@@ -323,7 +341,8 @@ void RimPlotCurve::setParentQwtPlotAndReplot( QwtPlot* plot )
|
||||
m_parentQwtPlot = plot;
|
||||
if ( canCurveBeAttached() )
|
||||
{
|
||||
m_qwtPlotCurve->attach( m_parentQwtPlot );
|
||||
attachCurveAndErrorBars();
|
||||
|
||||
m_parentQwtPlot->replot();
|
||||
}
|
||||
}
|
||||
@@ -336,11 +355,12 @@ void RimPlotCurve::setParentQwtPlotNoReplot( QwtPlot* plot )
|
||||
m_parentQwtPlot = plot;
|
||||
if ( canCurveBeAttached() )
|
||||
{
|
||||
m_qwtPlotCurve->attach( m_parentQwtPlot );
|
||||
attachCurveAndErrorBars();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_qwtPlotCurve->detach();
|
||||
m_qwtCurveErrorBars->detach();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,6 +386,7 @@ void RimPlotCurve::setColor( const cvf::Color3f& color )
|
||||
void RimPlotCurve::detachQwtCurve()
|
||||
{
|
||||
m_qwtPlotCurve->detach();
|
||||
m_qwtCurveErrorBars->detach();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -376,7 +397,7 @@ void RimPlotCurve::reattachQwtCurve()
|
||||
detachQwtCurve();
|
||||
if ( canCurveBeAttached() )
|
||||
{
|
||||
m_qwtPlotCurve->attach( m_parentQwtPlot );
|
||||
attachCurveAndErrorBars();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -486,6 +507,75 @@ void RimPlotCurve::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& u
|
||||
throw std::logic_error( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPlotCurve::setSamplesFromXYErrorValues(
|
||||
const std::vector<double>& xValues,
|
||||
const std::vector<double>& yValues,
|
||||
const std::vector<double>& errorValues,
|
||||
bool keepOnlyPositiveValues,
|
||||
RiaCurveDataTools::ErrorAxis errorAxis /*= RiuQwtPlotCurve::ERROR_ALONG_Y_AXIS */ )
|
||||
{
|
||||
CVF_ASSERT( xValues.size() == yValues.size() );
|
||||
CVF_ASSERT( xValues.size() == errorValues.size() );
|
||||
|
||||
auto intervalsOfValidValues = RiaCurveDataTools::calculateIntervalsOfValidValues( yValues, keepOnlyPositiveValues );
|
||||
std::vector<double> filteredYValues;
|
||||
std::vector<double> filteredXValues;
|
||||
|
||||
RiaCurveDataTools::getValuesByIntervals( yValues, intervalsOfValidValues, &filteredYValues );
|
||||
RiaCurveDataTools::getValuesByIntervals( xValues, intervalsOfValidValues, &filteredXValues );
|
||||
|
||||
std::vector<double> filteredErrorValues;
|
||||
RiaCurveDataTools::getValuesByIntervals( errorValues, intervalsOfValidValues, &filteredErrorValues );
|
||||
|
||||
QVector<QwtIntervalSample> errorIntervals;
|
||||
|
||||
errorIntervals.reserve( static_cast<int>( filteredXValues.size() ) );
|
||||
|
||||
for ( size_t i = 0; i < filteredXValues.size(); i++ )
|
||||
{
|
||||
if ( filteredYValues[i] != DOUBLE_INF && filteredErrorValues[i] != DOUBLE_INF )
|
||||
{
|
||||
if ( errorAxis == RiaCurveDataTools::ERROR_ALONG_Y_AXIS )
|
||||
{
|
||||
errorIntervals << QwtIntervalSample( filteredXValues[i],
|
||||
filteredYValues[i] - filteredErrorValues[i],
|
||||
filteredYValues[i] + filteredErrorValues[i] );
|
||||
}
|
||||
else
|
||||
{
|
||||
errorIntervals << QwtIntervalSample( filteredYValues[i],
|
||||
filteredXValues[i] - filteredErrorValues[i],
|
||||
filteredXValues[i] + filteredErrorValues[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_qwtPlotCurve )
|
||||
{
|
||||
m_qwtPlotCurve->setSamples( filteredXValues.data(),
|
||||
filteredYValues.data(),
|
||||
static_cast<int>( filteredXValues.size() ) );
|
||||
|
||||
m_qwtPlotCurve->setLineSegmentStartStopIndices( intervalsOfValidValues );
|
||||
}
|
||||
|
||||
if ( m_qwtCurveErrorBars )
|
||||
{
|
||||
m_qwtCurveErrorBars->setSamples( errorIntervals );
|
||||
if ( errorAxis == RiaCurveDataTools::ERROR_ALONG_Y_AXIS )
|
||||
{
|
||||
m_qwtCurveErrorBars->setOrientation( Qt::Vertical );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_qwtCurveErrorBars->setOrientation( Qt::Horizontal );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -557,6 +647,19 @@ bool RimPlotCurve::canCurveBeAttached() const
|
||||
return isVisibleInPossibleParent;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPlotCurve::attachCurveAndErrorBars()
|
||||
{
|
||||
m_qwtPlotCurve->attach( m_parentQwtPlot );
|
||||
|
||||
if ( m_showErrorBars )
|
||||
{
|
||||
m_qwtCurveErrorBars->attach( m_parentQwtPlot );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -585,7 +688,11 @@ void RimPlotCurve::updateCurveAppearance()
|
||||
m_qwtPlotCurve->setSymbol( symbol );
|
||||
m_qwtPlotCurve->setSymbolSkipPixelDistance( m_symbolSkipPixelDistance() );
|
||||
|
||||
m_qwtPlotCurve->setErrorBarsColor( curveColor );
|
||||
{
|
||||
QwtIntervalSymbol* newSymbol = new QwtIntervalSymbol( QwtIntervalSymbol::Bar );
|
||||
newSymbol->setPen( QPen( curveColor ) );
|
||||
m_qwtCurveErrorBars->setSymbol( newSymbol );
|
||||
}
|
||||
|
||||
// Make sure the legend lines are long enough to distinguish between line types.
|
||||
// Standard width in Qwt is 8 which is too short.
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "RifEclipseSummaryAddress.h"
|
||||
|
||||
#include "RiaCurveDataTools.h"
|
||||
|
||||
#include "RiuQwtPlotCurve.h"
|
||||
#include "RiuQwtSymbol.h"
|
||||
|
||||
@@ -29,6 +32,7 @@
|
||||
|
||||
class QwtPlot;
|
||||
class QwtPlotCurve;
|
||||
class QwtPlotIntervalCurve;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
@@ -120,6 +124,12 @@ protected:
|
||||
virtual void updateLegendsInPlot();
|
||||
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
|
||||
|
||||
void setSamplesFromXYErrorValues( const std::vector<double>& xValues,
|
||||
const std::vector<double>& yValues,
|
||||
const std::vector<double>& errorValues,
|
||||
bool keepOnlyPositiveValues,
|
||||
RiaCurveDataTools::ErrorAxis errorAxis = RiaCurveDataTools::ERROR_ALONG_Y_AXIS );
|
||||
|
||||
protected:
|
||||
// Overridden PDM methods
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField,
|
||||
@@ -134,10 +144,13 @@ protected:
|
||||
|
||||
private:
|
||||
bool canCurveBeAttached() const;
|
||||
void attachCurveAndErrorBars();
|
||||
|
||||
protected:
|
||||
QPointer<QwtPlot> m_parentQwtPlot;
|
||||
RiuQwtPlotCurve* m_qwtPlotCurve;
|
||||
|
||||
RiuQwtPlotCurve* m_qwtPlotCurve;
|
||||
QwtPlotIntervalCurve* m_qwtCurveErrorBars;
|
||||
|
||||
caf::PdmField<bool> m_showCurve;
|
||||
caf::PdmField<QString> m_curveName;
|
||||
|
||||
@@ -47,7 +47,7 @@ RimWellLogCurve::RimWellLogCurve()
|
||||
CAF_PDM_InitObject( "WellLogCurve", ":/WellLogCurve16x16.png", "", "" );
|
||||
|
||||
m_qwtPlotCurve->setXAxis( QwtPlot::xTop );
|
||||
m_qwtPlotCurve->setErrorBarsXAxis( QwtPlot::xTop );
|
||||
m_qwtCurveErrorBars->setXAxis( QwtPlot::xTop );
|
||||
m_qwtPlotCurve->setYAxis( QwtPlot::yLeft );
|
||||
|
||||
m_curveData = new RigWellLogCurveData;
|
||||
|
||||
@@ -378,6 +378,7 @@ void RimWellLogRftCurve::onLoadDataAndUpdate( bool updateParentPlot )
|
||||
|
||||
RimWellRftPlot* rftPlot = dynamic_cast<RimWellRftPlot*>( wellLogPlot );
|
||||
bool showErrorBarsInObservedData = rftPlot ? rftPlot->showErrorBarsForObservedData() : false;
|
||||
m_showErrorBars = showErrorBarsInObservedData;
|
||||
|
||||
std::vector<double> measuredDepthVector = measuredDepthValues();
|
||||
std::vector<double> tvDepthVector = tvDepthValues();
|
||||
@@ -447,14 +448,24 @@ void RimWellLogRftCurve::onLoadDataAndUpdate( bool updateParentPlot )
|
||||
|
||||
if ( wellLogPlot->depthType() == RiaDefines::MEASURED_DEPTH )
|
||||
{
|
||||
m_qwtPlotCurve->showErrorBars( showErrorBarsInObservedData );
|
||||
m_qwtPlotCurve->setPerPointLabels( perPointLabels );
|
||||
m_qwtPlotCurve->setSamplesFromXValuesAndYValues( this->curveData()->xPlotValues(),
|
||||
this->curveData()->depthPlotValues( RiaDefines::MEASURED_DEPTH,
|
||||
displayUnit ),
|
||||
errors,
|
||||
false,
|
||||
RiuQwtPlotCurve::ERROR_ALONG_X_AXIS );
|
||||
|
||||
auto xValues = this->curveData()->xPlotValues();
|
||||
auto yValues = this->curveData()->depthPlotValues( RiaDefines::MEASURED_DEPTH, displayUnit );
|
||||
bool keepOnlyPositiveValues = false;
|
||||
|
||||
if ( !errors.empty() )
|
||||
{
|
||||
this->setSamplesFromXYErrorValues( xValues,
|
||||
yValues,
|
||||
errors,
|
||||
keepOnlyPositiveValues,
|
||||
RiaCurveDataTools::ERROR_ALONG_X_AXIS );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_qwtPlotCurve->setSamplesFromXValuesAndYValues( xValues, yValues, keepOnlyPositiveValues );
|
||||
}
|
||||
|
||||
RimWellLogTrack* wellLogTrack;
|
||||
firstAncestorOrThisOfType( wellLogTrack );
|
||||
@@ -483,14 +494,24 @@ void RimWellLogRftCurve::onLoadDataAndUpdate( bool updateParentPlot )
|
||||
}
|
||||
else
|
||||
{
|
||||
m_qwtPlotCurve->showErrorBars( showErrorBarsInObservedData );
|
||||
m_qwtPlotCurve->setPerPointLabels( perPointLabels );
|
||||
m_qwtPlotCurve->setSamplesFromXValuesAndYValues( this->curveData()->xPlotValues(),
|
||||
this->curveData()->depthPlotValues( RiaDefines::TRUE_VERTICAL_DEPTH,
|
||||
displayUnit ),
|
||||
errors,
|
||||
false,
|
||||
RiuQwtPlotCurve::ERROR_ALONG_X_AXIS );
|
||||
|
||||
auto xValues = this->curveData()->xPlotValues();
|
||||
auto yValues = this->curveData()->depthPlotValues( RiaDefines::TRUE_VERTICAL_DEPTH, displayUnit );
|
||||
bool isLogCurve = false;
|
||||
|
||||
if ( !errors.empty() )
|
||||
{
|
||||
this->setSamplesFromXYErrorValues( xValues,
|
||||
yValues,
|
||||
errors,
|
||||
isLogCurve,
|
||||
RiaCurveDataTools::ERROR_ALONG_X_AXIS );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_qwtPlotCurve->setSamplesFromXValuesAndYValues( xValues, yValues, isLogCurve );
|
||||
}
|
||||
}
|
||||
|
||||
m_qwtPlotCurve->setLineSegmentStartStopIndices( this->curveData()->polylineStartStopIndices() );
|
||||
|
||||
@@ -151,7 +151,7 @@ void RimSummaryCurve::setSummaryCaseY( RimSummaryCase* sumCase )
|
||||
{
|
||||
if ( m_yValuesSummaryCase != sumCase )
|
||||
{
|
||||
m_qwtPlotCurve->clearErrorBars();
|
||||
m_qwtCurveErrorBars->setSamples( nullptr );
|
||||
}
|
||||
|
||||
m_yValuesSummaryCase = sumCase;
|
||||
@@ -208,7 +208,7 @@ void RimSummaryCurve::setSummaryAddressY( const RifEclipseSummaryAddress& addres
|
||||
{
|
||||
if ( m_yValuesSummaryAddress->address() != address )
|
||||
{
|
||||
m_qwtPlotCurve->clearErrorBars();
|
||||
m_qwtCurveErrorBars->setSamples( nullptr );
|
||||
}
|
||||
|
||||
m_yValuesSummaryAddress->setAddress( address );
|
||||
@@ -520,10 +520,17 @@ void RimSummaryCurve::onLoadDataAndUpdate( bool updateParentPlot )
|
||||
{
|
||||
std::vector<double> errValues;
|
||||
reader->values( errAddress, &errValues );
|
||||
m_qwtPlotCurve->setSamplesFromTimeTAndYValues( curveTimeStepsY,
|
||||
curveValuesY,
|
||||
errValues,
|
||||
isLogCurve );
|
||||
|
||||
auto timeSteps = RiuQwtPlotCurve::fromTime_t( curveTimeStepsY );
|
||||
|
||||
if ( !errValues.empty() )
|
||||
{
|
||||
this->setSamplesFromXYErrorValues( timeSteps, curveValuesY, errValues, isLogCurve );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_qwtPlotCurve->setSamplesFromXValuesAndYValues( timeSteps, curveValuesY, isLogCurve );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -564,8 +571,6 @@ void RimSummaryCurve::onLoadDataAndUpdate( bool updateParentPlot )
|
||||
updateZoomInParentPlot();
|
||||
m_parentQwtPlot->replot();
|
||||
}
|
||||
|
||||
m_qwtPlotCurve->showErrorBars( m_showErrorBars );
|
||||
}
|
||||
|
||||
if ( updateParentPlot ) updateQwtPlotAxis();
|
||||
|
||||
Reference in New Issue
Block a user