#5002 Ensemble RFT curve sets with parameter coloring and separate legends

This commit is contained in:
Gaute Lindkvist
2019-12-02 15:26:24 +01:00
parent f56a34843a
commit 7fd4aa1ce9
16 changed files with 643 additions and 167 deletions

View File

@@ -37,7 +37,6 @@ ${CMAKE_CURRENT_LIST_DIR}/RimEnsembleStatisticsCase.h
${CMAKE_CURRENT_LIST_DIR}/RimDerivedEnsembleCase.h
${CMAKE_CURRENT_LIST_DIR}/RimDerivedEnsembleCaseCollection.h
${CMAKE_CURRENT_LIST_DIR}/RimSummaryPlotFilterTextCurveSetEditor.h
${CMAKE_CURRENT_LIST_DIR}/RimEnsembleParameterColorHandlerInterface.h
)
set (SOURCE_GROUP_SOURCE_FILES
@@ -78,7 +77,6 @@ ${CMAKE_CURRENT_LIST_DIR}/RimEnsembleStatisticsCase.cpp
${CMAKE_CURRENT_LIST_DIR}/RimDerivedEnsembleCase.cpp
${CMAKE_CURRENT_LIST_DIR}/RimDerivedEnsembleCaseCollection.cpp
${CMAKE_CURRENT_LIST_DIR}/RimSummaryPlotFilterTextCurveSetEditor.cpp
${CMAKE_CURRENT_LIST_DIR}/RimEnsembleParameterColorHandlerInterface.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@@ -766,11 +766,10 @@ QList<caf::PdmOptionItemInfo> RimEnsembleCurveSet::calculateValueOptions( const
auto singleColorOption = ColorModeEnum( ColorMode::SINGLE_COLOR );
auto byEnsParamOption = ColorModeEnum( ColorMode::BY_ENSEMBLE_PARAM );
options.push_back( caf::PdmOptionItemInfo::fromEnumClass( singleColorOption.uiText(), ColorMode::SINGLE_COLOR ) );
options.push_back( caf::PdmOptionItemInfo( singleColorOption.uiText(), ColorMode::SINGLE_COLOR ) );
if ( !ensembleParameters().empty() )
{
options.push_back(
caf::PdmOptionItemInfo::fromEnumClass( byEnsParamOption.uiText(), ColorMode::BY_ENSEMBLE_PARAM ) );
options.push_back( caf::PdmOptionItemInfo( byEnsParamOption.uiText(), ColorMode::BY_ENSEMBLE_PARAM ) );
}
}
else if ( fieldNeedingOptions == &m_ensembleParameter )
@@ -851,72 +850,18 @@ void RimEnsembleCurveSet::updateCurveColors()
if ( group && !parameterName.isEmpty() && !group->allSummaryCases().empty() )
{
auto ensembleParam = group->ensembleParameter( parameterName );
if ( ensembleParam.isText() )
if ( ensembleParam.isText() || ensembleParam.isNumeric() )
{
std::set<QString> categories;
for ( auto value : ensembleParam.values )
{
categories.insert( value.toString() );
}
std::vector<QString> categoryNames = std::vector<QString>( categories.begin(), categories.end() );
m_legendConfig->setNamedCategories( categoryNames );
m_legendConfig->setAutomaticRanges( 0, categoryNames.size() - 1, 0, categoryNames.size() - 1 );
RimEnsembleCurveSetColorManager::initializeLegendConfig( m_legendConfig, ensembleParam );
for ( auto& curve : m_curves )
{
if ( curve->summaryAddressY().category() == RifEclipseSummaryAddress::SUMMARY_ENSEMBLE_STATISTICS )
continue;
RimSummaryCase* rimCase = curve->summaryCaseY();
QString tValue = rimCase->hasCaseRealizationParameters()
? rimCase->caseRealizationParameters()->parameterValue( parameterName ).textValue()
: "";
double nValue = m_legendConfig->categoryValueFromCategoryName( tValue );
if ( nValue != DOUBLE_INF )
{
int iValue = static_cast<int>( nValue );
curve->setColor( cvf::Color3f( m_legendConfig->scalarMapper()->mapToColor( iValue ) ) );
}
else
{
curve->setColor( RiaColorTables::undefinedCellColor() );
}
curve->updateCurveAppearance();
}
}
else if ( ensembleParam.isNumeric() )
{
double minValue = DOUBLE_INF;
double maxValue = -DOUBLE_INF;
for ( auto value : ensembleParam.values )
{
double nValue = value.toDouble();
if ( nValue != DOUBLE_INF )
{
if ( nValue < minValue ) minValue = nValue;
if ( nValue > maxValue ) maxValue = nValue;
}
}
m_legendConfig->setAutomaticRanges( minValue, maxValue, minValue, maxValue );
for ( auto& curve : m_curves )
{
if ( curve->summaryAddressY().category() == RifEclipseSummaryAddress::SUMMARY_ENSEMBLE_STATISTICS )
continue;
RimSummaryCase* rimCase = curve->summaryCaseY();
double value = rimCase->hasCaseRealizationParameters()
? rimCase->caseRealizationParameters()->parameterValue( parameterName ).numericValue()
: DOUBLE_INF;
if ( value != DOUBLE_INF )
curve->setColor( cvf::Color3f( m_legendConfig->scalarMapper()->mapToColor( value ) ) );
else
curve->setColor( RiaColorTables::undefinedCellColor() );
RimSummaryCase* rimCase = curve->summaryCaseY();
cvf::Color3f curveColor = RimEnsembleCurveSetColorManager::caseColor( m_legendConfig,
rimCase,
ensembleParam );
curve->setColor( curveColor );
curve->updateCurveAppearance();
}
}
@@ -950,7 +895,7 @@ void RimEnsembleCurveSet::updateCurveColors()
}
else
{
if ( !m_legendOverlayFrame.isNull() )
if ( m_legendOverlayFrame )
{
plot->viewer()->removeOverlayFrame( m_legendOverlayFrame );
}

View File

@@ -19,10 +19,12 @@
#pragma once
#include "RifEclipseSummaryAddress.h"
#include "RifEclipseSummaryAddressQMetaType.h"
#include "RifSummaryReaderInterface.h"
#include "RiaDefines.h"
#include "RimEnsembleCurveSetColorManager.h"
#include "RimRegularLegendConfig.h"
#include "RimSummaryCase.h"
#include "RimSummaryCaseCollection.h"
@@ -36,8 +38,6 @@
#include "cafPdmPtrArrayField.h"
#include "cafPdmPtrField.h"
#include "RifEclipseSummaryAddressQMetaType.h"
#include "RimEnsembleParameterColorHandlerInterface.h"
#include "cafPdmProxyValueField.h"
#include <QPointer>
@@ -57,14 +57,21 @@ class RiuCvfOverlayItemWidget;
class QwtPlot;
class QwtPlotCurve;
class QKeyEvent;
class QFrame;
//==================================================================================================
///
//==================================================================================================
class RimEnsembleCurveSet : public caf::PdmObject, public RimEnsembleParameterColorHandlerInterface
class RimEnsembleCurveSet : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
using ColorMode = RimEnsembleCurveSetColorManager::ColorMode;
using ColorModeEnum = RimEnsembleCurveSetColorManager::ColorModeEnum;
using NameParameterPair = EnsembleParameter::NameParameterPair;
public:
RimEnsembleCurveSet();
~RimEnsembleCurveSet() override;
@@ -94,15 +101,16 @@ public:
RimEnsembleCurveFilterCollection* filterCollection() const;
ColorMode colorMode() const override;
void setColorMode( ColorMode mode ) override;
void setEnsembleParameter( const QString& parameterName ) override;
void updateEnsembleLegendItem() override;
RimRegularLegendConfig* legendConfig() override;
QFrame* legendFrame() const override;
ColorMode colorMode() const;
void setColorMode( ColorMode mode );
void setEnsembleParameter( const QString& parameterName );
EnsembleParameter::Type currentEnsembleParameterType() const;
RimRegularLegendConfig* legendConfig();
void updateEnsembleLegendItem();
QFrame* legendFrame() const;
void updateAllCurves();
void updateStatisticsCurves();

View File

@@ -17,8 +17,28 @@
/////////////////////////////////////////////////////////////////////////////////
#include "RimEnsembleCurveSetColorManager.h"
#include "RiaColorTables.h"
#include "RimEnsembleCurveSet.h"
#include "RimEnsembleCurveSetCollection.h"
#include "RimRegularLegendConfig.h"
#include "cvfScalarMapper.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
namespace caf
{
template <>
void AppEnum<RimEnsembleCurveSetColorManager::ColorMode>::setUp()
{
addItem( RimEnsembleCurveSetColorManager::ColorMode::SINGLE_COLOR, "SINGLE_COLOR", "Single Color" );
addItem( RimEnsembleCurveSetColorManager::ColorMode::BY_ENSEMBLE_PARAM, "BY_ENSEMBLE_PARAM", "By Ensemble Parameter" );
setDefault( RimEnsembleCurveSetColorManager::ColorMode::SINGLE_COLOR );
}
} // namespace caf
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -64,6 +84,76 @@ RimRegularLegendConfig::ColorRangesType RimEnsembleCurveSetColorManager::cycledE
return crIt->first;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEnsembleCurveSetColorManager::initializeLegendConfig( RimRegularLegendConfig* legendConfig,
const EnsembleParameter& ensembleParam )
{
if ( ensembleParam.isText() )
{
std::set<QString> categories;
for ( auto value : ensembleParam.values )
{
categories.insert( value.toString() );
}
std::vector<QString> categoryNames = std::vector<QString>( categories.begin(), categories.end() );
legendConfig->setNamedCategories( categoryNames );
legendConfig->setAutomaticRanges( 0, categoryNames.size() - 1, 0, categoryNames.size() - 1 );
}
else
{
double minValue = std::numeric_limits<double>::infinity();
double maxValue = -std::numeric_limits<double>::infinity();
for ( auto value : ensembleParam.values )
{
double nValue = value.toDouble();
if ( nValue != std::numeric_limits<double>::infinity() )
{
if ( nValue < minValue ) minValue = nValue;
if ( nValue > maxValue ) maxValue = nValue;
}
}
legendConfig->setAutomaticRanges( minValue, maxValue, minValue, maxValue );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Color3f RimEnsembleCurveSetColorManager::caseColor( const RimRegularLegendConfig* legendConfig,
const RimSummaryCase* summaryCase,
const EnsembleParameter& ensembleParam )
{
if ( ensembleParam.isText() )
{
QString tValue = summaryCase->hasCaseRealizationParameters()
? summaryCase->caseRealizationParameters()->parameterValue( ensembleParam.name ).textValue()
: "";
double nValue = legendConfig->categoryValueFromCategoryName( tValue );
if ( nValue != std::numeric_limits<double>::infinity() )
{
int iValue = static_cast<int>( nValue );
return cvf::Color3f( legendConfig->scalarMapper()->mapToColor( iValue ) );
}
}
else
{
double value = summaryCase->hasCaseRealizationParameters()
? summaryCase->caseRealizationParameters()->parameterValue( ensembleParam.name ).numericValue()
: std::numeric_limits<double>::infinity();
if ( value != std::numeric_limits<double>::infinity() )
{
return cvf::Color3f( legendConfig->scalarMapper()->mapToColor( value ) );
}
}
return RiaColorTables::undefinedCellColor();
}
std::map<RimEnsembleCurveSetCollection*, int> RimEnsembleCurveSetColorManager::m_nextColorIndexes;
std::map<RimEnsembleCurveSetCollection*, std::map<RimEnsembleCurveSet*, RimRegularLegendConfig::ColorRangesType>>

View File

@@ -20,11 +20,12 @@
#include "RiaDefines.h"
#include "RimEnsembleCurveSet.h"
#include "RimRegularLegendConfig.h"
#include "RimSummaryCaseCollection.h"
#include <map>
class RimEnsembleCurveSet;
class RimEnsembleCurveSetCollection;
//--------------------------------------------------------------------------------------------------
@@ -32,6 +33,15 @@ class RimEnsembleCurveSetCollection;
//--------------------------------------------------------------------------------------------------
class RimEnsembleCurveSetColorManager
{
public:
enum class ColorMode
{
SINGLE_COLOR,
BY_ENSEMBLE_PARAM
};
using ColorModeEnum = caf::AppEnum<ColorMode>;
using NameParameterPair = EnsembleParameter::NameParameterPair;
public:
static const std::map<RimRegularLegendConfig::ColorRangesType, cvf::Color3ubArray>& EnsembleColorRanges();
@@ -43,6 +53,11 @@ public:
return m_ensembleColorRanges.find( colorRange ) != m_ensembleColorRanges.end();
}
static void initializeLegendConfig( RimRegularLegendConfig* legendConfig, const EnsembleParameter& parameter );
static cvf::Color3f caseColor( const RimRegularLegendConfig* legendConfig,
const RimSummaryCase* summaryCase,
const EnsembleParameter& parameter );
private:
static const std::map<RimRegularLegendConfig::ColorRangesType, cvf::Color3ubArray> m_ensembleColorRanges;

View File

@@ -1,17 +0,0 @@
#include "RimEnsembleParameterColorHandlerInterface.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
namespace caf
{
template <>
void AppEnum<RimEnsembleParameterColorHandlerInterface::ColorMode>::setUp()
{
addItem( RimEnsembleParameterColorHandlerInterface::ColorMode::SINGLE_COLOR, "SINGLE_COLOR", "Single Color" );
addItem( RimEnsembleParameterColorHandlerInterface::ColorMode::BY_ENSEMBLE_PARAM,
"BY_ENSEMBLE_PARAM",
"By Ensemble Parameter" );
setDefault( RimEnsembleParameterColorHandlerInterface::ColorMode::SINGLE_COLOR );
}
} // namespace caf

View File

@@ -1,49 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Statoil 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 "RimSummaryCaseCollection.h"
#include "cafAppEnum.h"
#include <utility>
class RimRegularLegendConfig;
class RiuCvfOverlayItemWidget;
class QFrame;
class RimEnsembleParameterColorHandlerInterface
{
public:
enum class ColorMode
{
SINGLE_COLOR,
BY_ENSEMBLE_PARAM
};
using ColorModeEnum = caf::AppEnum<ColorMode>;
using NameParameterPair = EnsembleParameter::NameParameterPair;
public:
virtual ColorMode colorMode() const = 0;
virtual void setColorMode( ColorMode mode ) = 0;
virtual void setEnsembleParameter( const QString& parameterName ) = 0;
virtual void updateEnsembleLegendItem() = 0;
virtual RimRegularLegendConfig* legendConfig() = 0;
virtual QFrame* legendFrame() const = 0;
};