#2883, #2890 Fix color assignment and stability for ensemble curve sets

This commit is contained in:
Jacob Støren 2018-05-11 08:01:10 +02:00
parent 6270dd3bc9
commit bb033eb561
12 changed files with 41 additions and 73 deletions

View File

@ -19,6 +19,7 @@
#include "RicNewSummaryEnsembleCurveSetFeature.h" #include "RicNewSummaryEnsembleCurveSetFeature.h"
#include "RiaApplication.h" #include "RiaApplication.h"
#include "RiaColorTables.h"
#include "RimMainPlotCollection.h" #include "RimMainPlotCollection.h"
#include "RimOilField.h" #include "RimOilField.h"
@ -30,6 +31,7 @@
#include "RimSummaryPlotCollection.h" #include "RimSummaryPlotCollection.h"
#include "RimEnsembleCurveSet.h" #include "RimEnsembleCurveSet.h"
#include "RimEnsembleCurveSetCollection.h" #include "RimEnsembleCurveSetCollection.h"
#include "RimEnsembleCurveSetColorManager.h"
#include "RiuPlotMainWindow.h" #include "RiuPlotMainWindow.h"
@ -65,6 +67,10 @@ void RicNewSummaryEnsembleCurveSetFeature::onActionTriggered(bool isChecked)
{ {
RimEnsembleCurveSet* curveSet = new RimEnsembleCurveSet(); RimEnsembleCurveSet* curveSet = new RimEnsembleCurveSet();
size_t colorIndex = plot->ensembleCurveSets()->curveSetCount();
curveSet->setColor(RiaColorTables::summaryCurveDefaultPaletteColors().cycledColor3f(colorIndex));
curveSet->legendConfig()->setColorRange(RimEnsembleCurveSetColorManager::cycledEnsembleColorRange(static_cast<int>(colorIndex)));
if (!project->summaryGroups().empty()) if (!project->summaryGroups().empty())
{ {
curveSet->setSummaryCaseCollection(project->summaryGroups().back()); curveSet->setSummaryCaseCollection(project->summaryGroups().back());

View File

@ -209,7 +209,7 @@ void RimEclipseCellColors::updateLegendCategorySettings()
if (this->hasCategoryResult()) if (this->hasCategoryResult())
{ {
legendConfig()->setMappingMode(RimRegularLegendConfig::CATEGORY_INTEGER); legendConfig()->setMappingMode(RimRegularLegendConfig::CATEGORY_INTEGER);
legendConfig()->setColorRangeMode(RimRegularLegendConfig::CATEGORY); legendConfig()->setColorRange(RimRegularLegendConfig::CATEGORY);
} }
else else
{ {
@ -218,9 +218,9 @@ void RimEclipseCellColors::updateLegendCategorySettings()
legendConfig()->setMappingMode(RimRegularLegendConfig::LINEAR_CONTINUOUS); legendConfig()->setMappingMode(RimRegularLegendConfig::LINEAR_CONTINUOUS);
} }
if (legendConfig()->colorRangeMode() == RimRegularLegendConfig::CATEGORY) if (legendConfig()->colorRange() == RimRegularLegendConfig::CATEGORY)
{ {
legendConfig()->setColorRangeMode(RimRegularLegendConfig::NORMAL); legendConfig()->setColorRange(RimRegularLegendConfig::NORMAL);
} }
} }
} }

View File

@ -151,7 +151,7 @@ RimEclipseView::RimEclipseView()
this->cellResult()->setReservoirView(this); this->cellResult()->setReservoirView(this);
this->cellEdgeResult()->setReservoirView(this); this->cellEdgeResult()->setReservoirView(this);
this->cellEdgeResult()->legendConfig()->setColorRangeMode(RimRegularLegendConfig::PINK_WHITE); this->cellEdgeResult()->legendConfig()->setColorRange(RimRegularLegendConfig::PINK_WHITE);
this->faultResultSettings()->setReservoirView(this); this->faultResultSettings()->setReservoirView(this);

View File

@ -88,7 +88,7 @@ void RimGeoMechCellColors::updateLegendCategorySettings()
if(this->hasCategoryResult()) if(this->hasCategoryResult())
{ {
legendConfig->setMappingMode(RimRegularLegendConfig::CATEGORY_INTEGER); legendConfig->setMappingMode(RimRegularLegendConfig::CATEGORY_INTEGER);
legendConfig->setColorRangeMode(RimRegularLegendConfig::CATEGORY); legendConfig->setColorRange(RimRegularLegendConfig::CATEGORY);
} }
else else
{ {
@ -97,9 +97,9 @@ void RimGeoMechCellColors::updateLegendCategorySettings()
legendConfig->setMappingMode(RimRegularLegendConfig::LINEAR_CONTINUOUS); legendConfig->setMappingMode(RimRegularLegendConfig::LINEAR_CONTINUOUS);
} }
if(legendConfig->colorRangeMode() == RimRegularLegendConfig::CATEGORY) if(legendConfig->colorRange() == RimRegularLegendConfig::CATEGORY)
{ {
legendConfig->setColorRangeMode(RimRegularLegendConfig::NORMAL); legendConfig->setColorRange(RimRegularLegendConfig::NORMAL);
} }
} }
} }

View File

@ -513,7 +513,7 @@ void RimRegularLegendConfig::updateFieldVisibility()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimRegularLegendConfig::setColorRangeMode(ColorRangesType colorMode) void RimRegularLegendConfig::setColorRange(ColorRangesType colorMode)
{ {
m_colorRangeMode = colorMode; m_colorRangeMode = colorMode;
updateLegend(); updateLegend();
@ -744,15 +744,6 @@ const caf::TitledOverlayFrame* RimRegularLegendConfig::titledOverlayFrame() cons
} }
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimRegularLegendConfig::initForEnsembleCurveSet(RimEnsembleCurveSet* curveSet)
{
// Set default color palette for ensemble curve sets
setColorRangeMode(ColorManager::nextColorRange(curveSet));
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -804,7 +795,7 @@ cvf::Color3ubArray RimRegularLegendConfig::colorArrayFromColorType(ColorRangesTy
return RiaColorTables::stimPlanPaletteColors().color3ubArray(); return RiaColorTables::stimPlanPaletteColors().color3ubArray();
break; break;
default: default:
if (ColorManager::isEnsembleColorRange(colorType)) return ColorManager::ENSEMBLE_COLOR_RANGES.at(colorType); if (ColorManager::isEnsembleColorRange(colorType)) return ColorManager::EnsembleColorRanges.at(colorType);
break; break;
} }
@ -906,7 +897,7 @@ QList<caf::PdmOptionItemInfo> RimRegularLegendConfig::calculateValueOptions(cons
} }
else else
{ {
for (const auto& col : ColorManager::ENSEMBLE_COLOR_RANGES) for (const auto& col : ColorManager::EnsembleColorRanges)
{ {
rangeTypes.push_back(col.first); rangeTypes.push_back(col.first);
} }

View File

@ -99,8 +99,8 @@ public:
typedef caf::AppEnum<MappingType> MappingEnum; typedef caf::AppEnum<MappingType> MappingEnum;
void recreateLegend(); void recreateLegend();
void setColorRangeMode(ColorRangesType colorMode); void setColorRange(ColorRangesType colorMode);
ColorRangesType colorRangeMode() { return m_colorRangeMode();} ColorRangesType colorRange() { return m_colorRangeMode();}
void setMappingMode(MappingType mappingType); void setMappingMode(MappingType mappingType);
MappingType mappingMode() { return m_mappingMode();} MappingType mappingMode() { return m_mappingMode();}
void disableAllTimeStepsRange(bool doDisable); void disableAllTimeStepsRange(bool doDisable);
@ -125,8 +125,6 @@ public:
const caf::TitledOverlayFrame* titledOverlayFrame() const override; const caf::TitledOverlayFrame* titledOverlayFrame() const override;
caf::TitledOverlayFrame* titledOverlayFrame() override; caf::TitledOverlayFrame* titledOverlayFrame() override;
void initForEnsembleCurveSet(RimEnsembleCurveSet* curveSet);
private: private:
void setNamedCategories(const std::vector<QString>& categoryNames, bool inverse); void setNamedCategories(const std::vector<QString>& categoryNames, bool inverse);
void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;

View File

@ -152,7 +152,7 @@ void RimStimPlanColors::loadDataAndUpdate()
RimRegularLegendConfig* legendConfig = new RimRegularLegendConfig(); RimRegularLegendConfig* legendConfig = new RimRegularLegendConfig();
legendConfig->resultVariableName = resultNameUnitString; legendConfig->resultVariableName = resultNameUnitString;
legendConfig->setMappingMode(RimRegularLegendConfig::LINEAR_DISCRETE); legendConfig->setMappingMode(RimRegularLegendConfig::LINEAR_DISCRETE);
legendConfig->setColorRangeMode(RimRegularLegendConfig::STIMPLAN); legendConfig->setColorRange(RimRegularLegendConfig::STIMPLAN);
m_legendConfigurations.push_back(legendConfig); m_legendConfigurations.push_back(legendConfig);

View File

@ -24,6 +24,7 @@
#include "RifReaderEclipseSummary.h" #include "RifReaderEclipseSummary.h"
#include "RimEnsembleCurveSetCollection.h" #include "RimEnsembleCurveSetCollection.h"
#include "RimEnsembleCurveSetColorManager.h"
#include "RimProject.h" #include "RimProject.h"
#include "RimRegularLegendConfig.h" #include "RimRegularLegendConfig.h"
#include "RimSummaryAddress.h" #include "RimSummaryAddress.h"
@ -126,6 +127,7 @@ RimEnsembleCurveSet::RimEnsembleCurveSet()
CAF_PDM_InitFieldNoDefault(&m_legendConfig, "LegendConfig", "", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_legendConfig, "LegendConfig", "", "", "", "");
m_legendConfig = new RimRegularLegendConfig(); m_legendConfig = new RimRegularLegendConfig();
m_legendConfig->setColorRange( RimEnsembleCurveSetColorManager::DEFAULT_ENSEMBLE_COLOR_RANGE );
CAF_PDM_InitField(&m_userDefinedName, "UserDefinedName", QString("Ensemble Curve Set"), "Curve Set Name", "", "", ""); CAF_PDM_InitField(&m_userDefinedName, "UserDefinedName", QString("Ensemble Curve Set"), "Curve Set Name", "", "", "");
@ -186,7 +188,6 @@ void RimEnsembleCurveSet::loadDataAndUpdate(bool updateParentPlot)
m_yValuesSelectedVariableDisplayField = QString::fromStdString(m_yValuesCurveVariable->address().uiText()); m_yValuesSelectedVariableDisplayField = QString::fromStdString(m_yValuesCurveVariable->address().uiText());
m_yValuesUiFilterResultSelection = m_yValuesCurveVariable->address(); m_yValuesUiFilterResultSelection = m_yValuesCurveVariable->address();
m_legendConfig->initForEnsembleCurveSet(this);
updateAllCurves(); updateAllCurves();
} }

View File

@ -140,15 +140,13 @@ RimEnsembleCurveSet* RimEnsembleCurveSetCollection::findRimCurveSetFromQwtCurve(
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimEnsembleCurveSetCollection::addCurveSet(RimEnsembleCurveSet* curveSet) void RimEnsembleCurveSetCollection::addCurveSet(RimEnsembleCurveSet* curveSet)
{ {
static int nextAutoColorIndex = 1;
static int numberOfColors = (int)RiaColorTables::summaryCurveDefaultPaletteColors().size();
if (curveSet) if (curveSet)
{ {
curveSet->setColor(RimSummaryCurveAppearanceCalculator::cycledPaletteColor(nextAutoColorIndex));
m_curveSets.push_back(curveSet); m_curveSets.push_back(curveSet);
nextAutoColorIndex = (++nextAutoColorIndex) % numberOfColors;
} }
} }
@ -193,6 +191,14 @@ std::vector<RimEnsembleCurveSet*> RimEnsembleCurveSetCollection::visibleCurveSet
return visible; return visible;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t RimEnsembleCurveSetCollection::curveSetCount() const
{
return m_curveSets.size();
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -52,6 +52,7 @@ public:
std::vector<RimEnsembleCurveSet*> curveSets() const; std::vector<RimEnsembleCurveSet*> curveSets() const;
std::vector<RimEnsembleCurveSet*> visibleCurveSets() const; std::vector<RimEnsembleCurveSet*> visibleCurveSets() const;
size_t curveSetCount() const;
void deleteAllCurveSets(); void deleteAllCurveSets();

View File

@ -22,7 +22,7 @@
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
const std::map<RimRegularLegendConfig::ColorRangesType, cvf::Color3ubArray> RimEnsembleCurveSetColorManager::ENSEMBLE_COLOR_RANGES( const std::map<RimRegularLegendConfig::ColorRangesType, cvf::Color3ubArray> RimEnsembleCurveSetColorManager::EnsembleColorRanges(
{ {
{ RimRegularLegendConfig::GREEN_RED, cvf::Color3ubArray({ cvf::Color3ub(0x00, 0xff, 0x00), cvf::Color3ub(0xff, 0x00, 0x00) }) }, { RimRegularLegendConfig::GREEN_RED, cvf::Color3ubArray({ cvf::Color3ub(0x00, 0xff, 0x00), cvf::Color3ub(0xff, 0x00, 0x00) }) },
{ RimRegularLegendConfig::BLUE_MAGENTA, cvf::Color3ubArray({ cvf::Color3ub(0x00, 0x00, 0xff), cvf::Color3ub(0xff, 0x00, 0xff) }) }, { RimRegularLegendConfig::BLUE_MAGENTA, cvf::Color3ubArray({ cvf::Color3ub(0x00, 0x00, 0xff), cvf::Color3ub(0xff, 0x00, 0xff) }) },
@ -39,49 +39,14 @@ const RimRegularLegendConfig::ColorRangesType RimEnsembleCurveSetColorManager::D
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RimRegularLegendConfig::ColorRangesType RimEnsembleCurveSetColorManager::nextColorRange(RimEnsembleCurveSet* curveSet) RimRegularLegendConfig::ColorRangesType RimEnsembleCurveSetColorManager::cycledEnsembleColorRange(int index)
{ {
CVF_ASSERT(curveSet); size_t modIndex = index % EnsembleColorRanges.size();
RimEnsembleCurveSetCollection* coll; auto crIt = EnsembleColorRanges.begin();
curveSet->firstAncestorOrThisOfType(coll); for (int i = 0; i < modIndex; ++i) ++crIt;
if (coll) return crIt->first;
{
if (m_colorCache.find(coll) != m_colorCache.end())
{
if (m_colorCache[coll].find(curveSet) != m_colorCache[coll].end())
{
// CurveSet found in cache, use same color range as last time
return m_colorCache[coll][curveSet];
}
}
else
{
m_colorCache.insert(std::make_pair(coll, std::map<RimEnsembleCurveSet*, RimRegularLegendConfig::ColorRangesType>()));
m_nextColorIndexes.insert(std::make_pair(coll, 0));
}
int currColorIndex = m_nextColorIndexes[coll];
RimRegularLegendConfig::ColorRangesType resultColorRange = colorRangeByIndex(currColorIndex);
m_nextColorIndexes[coll] = (currColorIndex < (int)ENSEMBLE_COLOR_RANGES.size() - 1) ? currColorIndex + 1 : 0;
m_colorCache[coll][curveSet] = resultColorRange;
return resultColorRange;
}
return DEFAULT_ENSEMBLE_COLOR_RANGE;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimRegularLegendConfig::ColorRangesType RimEnsembleCurveSetColorManager::colorRangeByIndex(int index)
{
int i = 0;
for (auto item : ENSEMBLE_COLOR_RANGES)
{
if (i++ == index) return item.first;
}
return DEFAULT_ENSEMBLE_COLOR_RANGE;
} }
std::map<RimEnsembleCurveSetCollection*, int> RimEnsembleCurveSetColorManager::m_nextColorIndexes; std::map<RimEnsembleCurveSetCollection*, int> RimEnsembleCurveSetColorManager::m_nextColorIndexes;

View File

@ -35,19 +35,19 @@ class RimEnsembleCurveSetCollection;
class RimEnsembleCurveSetColorManager class RimEnsembleCurveSetColorManager
{ {
public: public:
static const std::map<RimRegularLegendConfig::ColorRangesType, cvf::Color3ubArray> ENSEMBLE_COLOR_RANGES; static const std::map<RimRegularLegendConfig::ColorRangesType, cvf::Color3ubArray> EnsembleColorRanges;
static const RimRegularLegendConfig::ColorRangesType DEFAULT_ENSEMBLE_COLOR_RANGE; static const RimRegularLegendConfig::ColorRangesType DEFAULT_ENSEMBLE_COLOR_RANGE;
static RimRegularLegendConfig::ColorRangesType cycledEnsembleColorRange(int index);
static bool isEnsembleColorRange(RimRegularLegendConfig::ColorRangesType colorRange) static bool isEnsembleColorRange(RimRegularLegendConfig::ColorRangesType colorRange)
{ {
return ENSEMBLE_COLOR_RANGES.find(colorRange) != ENSEMBLE_COLOR_RANGES.end(); return EnsembleColorRanges.find(colorRange) != EnsembleColorRanges.end();
} }
static RimRegularLegendConfig::ColorRangesType nextColorRange(RimEnsembleCurveSet* curveSet); static RimRegularLegendConfig::ColorRangesType nextColorRange(RimEnsembleCurveSet* curveSet);
private: private:
static RimRegularLegendConfig::ColorRangesType colorRangeByIndex(int index);
static std::map<RimEnsembleCurveSetCollection*, int> m_nextColorIndexes; static std::map<RimEnsembleCurveSetCollection*, int> m_nextColorIndexes;
static std::map<RimEnsembleCurveSetCollection*, std::map<RimEnsembleCurveSet*, RimRegularLegendConfig::ColorRangesType>> m_colorCache; static std::map<RimEnsembleCurveSetCollection*, std::map<RimEnsembleCurveSet*, RimRegularLegendConfig::ColorRangesType>> m_colorCache;