From bb033eb561c9fb2a55b996ffbe1a0634cf5658ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Fri, 11 May 2018 08:01:10 +0200 Subject: [PATCH] #2883, #2890 Fix color assignment and stability for ensemble curve sets --- .../RicNewSummaryEnsembleCurveSetFeature.cpp | 6 +++ .../ProjectDataModel/RimEclipseCellColors.cpp | 6 +-- .../ProjectDataModel/RimEclipseView.cpp | 2 +- .../ProjectDataModel/RimGeoMechCellColors.cpp | 6 +-- .../RimRegularLegendConfig.cpp | 15 ++---- .../ProjectDataModel/RimRegularLegendConfig.h | 6 +-- .../ProjectDataModel/RimStimPlanColors.cpp | 2 +- .../Summary/RimEnsembleCurveSet.cpp | 3 +- .../Summary/RimEnsembleCurveSetCollection.cpp | 14 ++++-- .../Summary/RimEnsembleCurveSetCollection.h | 1 + .../RimEnsembleCurveSetColorManager.cpp | 47 +++---------------- .../Summary/RimEnsembleCurveSetColorManager.h | 6 +-- 12 files changed, 41 insertions(+), 73 deletions(-) diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicNewSummaryEnsembleCurveSetFeature.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicNewSummaryEnsembleCurveSetFeature.cpp index c95f5e4261..5c85ead3bf 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicNewSummaryEnsembleCurveSetFeature.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicNewSummaryEnsembleCurveSetFeature.cpp @@ -19,6 +19,7 @@ #include "RicNewSummaryEnsembleCurveSetFeature.h" #include "RiaApplication.h" +#include "RiaColorTables.h" #include "RimMainPlotCollection.h" #include "RimOilField.h" @@ -30,6 +31,7 @@ #include "RimSummaryPlotCollection.h" #include "RimEnsembleCurveSet.h" #include "RimEnsembleCurveSetCollection.h" +#include "RimEnsembleCurveSetColorManager.h" #include "RiuPlotMainWindow.h" @@ -65,6 +67,10 @@ void RicNewSummaryEnsembleCurveSetFeature::onActionTriggered(bool isChecked) { RimEnsembleCurveSet* curveSet = new RimEnsembleCurveSet(); + size_t colorIndex = plot->ensembleCurveSets()->curveSetCount(); + curveSet->setColor(RiaColorTables::summaryCurveDefaultPaletteColors().cycledColor3f(colorIndex)); + curveSet->legendConfig()->setColorRange(RimEnsembleCurveSetColorManager::cycledEnsembleColorRange(static_cast(colorIndex))); + if (!project->summaryGroups().empty()) { curveSet->setSummaryCaseCollection(project->summaryGroups().back()); diff --git a/ApplicationCode/ProjectDataModel/RimEclipseCellColors.cpp b/ApplicationCode/ProjectDataModel/RimEclipseCellColors.cpp index 7c15f9065c..fe3d9148dd 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseCellColors.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseCellColors.cpp @@ -209,7 +209,7 @@ void RimEclipseCellColors::updateLegendCategorySettings() if (this->hasCategoryResult()) { legendConfig()->setMappingMode(RimRegularLegendConfig::CATEGORY_INTEGER); - legendConfig()->setColorRangeMode(RimRegularLegendConfig::CATEGORY); + legendConfig()->setColorRange(RimRegularLegendConfig::CATEGORY); } else { @@ -218,9 +218,9 @@ void RimEclipseCellColors::updateLegendCategorySettings() legendConfig()->setMappingMode(RimRegularLegendConfig::LINEAR_CONTINUOUS); } - if (legendConfig()->colorRangeMode() == RimRegularLegendConfig::CATEGORY) + if (legendConfig()->colorRange() == RimRegularLegendConfig::CATEGORY) { - legendConfig()->setColorRangeMode(RimRegularLegendConfig::NORMAL); + legendConfig()->setColorRange(RimRegularLegendConfig::NORMAL); } } } diff --git a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp index d4c1ce3499..d422703c6e 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp @@ -151,7 +151,7 @@ RimEclipseView::RimEclipseView() this->cellResult()->setReservoirView(this); this->cellEdgeResult()->setReservoirView(this); - this->cellEdgeResult()->legendConfig()->setColorRangeMode(RimRegularLegendConfig::PINK_WHITE); + this->cellEdgeResult()->legendConfig()->setColorRange(RimRegularLegendConfig::PINK_WHITE); this->faultResultSettings()->setReservoirView(this); diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechCellColors.cpp b/ApplicationCode/ProjectDataModel/RimGeoMechCellColors.cpp index 835d1fbdb4..98c9bdf542 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechCellColors.cpp +++ b/ApplicationCode/ProjectDataModel/RimGeoMechCellColors.cpp @@ -88,7 +88,7 @@ void RimGeoMechCellColors::updateLegendCategorySettings() if(this->hasCategoryResult()) { legendConfig->setMappingMode(RimRegularLegendConfig::CATEGORY_INTEGER); - legendConfig->setColorRangeMode(RimRegularLegendConfig::CATEGORY); + legendConfig->setColorRange(RimRegularLegendConfig::CATEGORY); } else { @@ -97,9 +97,9 @@ void RimGeoMechCellColors::updateLegendCategorySettings() legendConfig->setMappingMode(RimRegularLegendConfig::LINEAR_CONTINUOUS); } - if(legendConfig->colorRangeMode() == RimRegularLegendConfig::CATEGORY) + if(legendConfig->colorRange() == RimRegularLegendConfig::CATEGORY) { - legendConfig->setColorRangeMode(RimRegularLegendConfig::NORMAL); + legendConfig->setColorRange(RimRegularLegendConfig::NORMAL); } } } diff --git a/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.cpp b/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.cpp index 22e680a2bb..0513d231d6 100644 --- a/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.cpp +++ b/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.cpp @@ -513,7 +513,7 @@ void RimRegularLegendConfig::updateFieldVisibility() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimRegularLegendConfig::setColorRangeMode(ColorRangesType colorMode) +void RimRegularLegendConfig::setColorRange(ColorRangesType colorMode) { m_colorRangeMode = colorMode; 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(); break; default: - if (ColorManager::isEnsembleColorRange(colorType)) return ColorManager::ENSEMBLE_COLOR_RANGES.at(colorType); + if (ColorManager::isEnsembleColorRange(colorType)) return ColorManager::EnsembleColorRanges.at(colorType); break; } @@ -906,7 +897,7 @@ QList RimRegularLegendConfig::calculateValueOptions(cons } else { - for (const auto& col : ColorManager::ENSEMBLE_COLOR_RANGES) + for (const auto& col : ColorManager::EnsembleColorRanges) { rangeTypes.push_back(col.first); } diff --git a/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.h b/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.h index c7345561a3..8dafd2af15 100644 --- a/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.h +++ b/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.h @@ -99,8 +99,8 @@ public: typedef caf::AppEnum MappingEnum; void recreateLegend(); - void setColorRangeMode(ColorRangesType colorMode); - ColorRangesType colorRangeMode() { return m_colorRangeMode();} + void setColorRange(ColorRangesType colorMode); + ColorRangesType colorRange() { return m_colorRangeMode();} void setMappingMode(MappingType mappingType); MappingType mappingMode() { return m_mappingMode();} void disableAllTimeStepsRange(bool doDisable); @@ -125,8 +125,6 @@ public: const caf::TitledOverlayFrame* titledOverlayFrame() const override; caf::TitledOverlayFrame* titledOverlayFrame() override; - void initForEnsembleCurveSet(RimEnsembleCurveSet* curveSet); - private: void setNamedCategories(const std::vector& categoryNames, bool inverse); void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; diff --git a/ApplicationCode/ProjectDataModel/RimStimPlanColors.cpp b/ApplicationCode/ProjectDataModel/RimStimPlanColors.cpp index 2b7afe1325..a9850e13d4 100644 --- a/ApplicationCode/ProjectDataModel/RimStimPlanColors.cpp +++ b/ApplicationCode/ProjectDataModel/RimStimPlanColors.cpp @@ -152,7 +152,7 @@ void RimStimPlanColors::loadDataAndUpdate() RimRegularLegendConfig* legendConfig = new RimRegularLegendConfig(); legendConfig->resultVariableName = resultNameUnitString; legendConfig->setMappingMode(RimRegularLegendConfig::LINEAR_DISCRETE); - legendConfig->setColorRangeMode(RimRegularLegendConfig::STIMPLAN); + legendConfig->setColorRange(RimRegularLegendConfig::STIMPLAN); m_legendConfigurations.push_back(legendConfig); diff --git a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSet.cpp b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSet.cpp index 1855876272..3b97e9d3a5 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSet.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSet.cpp @@ -24,6 +24,7 @@ #include "RifReaderEclipseSummary.h" #include "RimEnsembleCurveSetCollection.h" +#include "RimEnsembleCurveSetColorManager.h" #include "RimProject.h" #include "RimRegularLegendConfig.h" #include "RimSummaryAddress.h" @@ -126,6 +127,7 @@ RimEnsembleCurveSet::RimEnsembleCurveSet() CAF_PDM_InitFieldNoDefault(&m_legendConfig, "LegendConfig", "", "", "", ""); 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", "", "", ""); @@ -186,7 +188,6 @@ void RimEnsembleCurveSet::loadDataAndUpdate(bool updateParentPlot) m_yValuesSelectedVariableDisplayField = QString::fromStdString(m_yValuesCurveVariable->address().uiText()); m_yValuesUiFilterResultSelection = m_yValuesCurveVariable->address(); - m_legendConfig->initForEnsembleCurveSet(this); updateAllCurves(); } diff --git a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSetCollection.cpp b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSetCollection.cpp index f3458f4d04..ac4a3c25f5 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSetCollection.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSetCollection.cpp @@ -140,15 +140,13 @@ RimEnsembleCurveSet* RimEnsembleCurveSetCollection::findRimCurveSetFromQwtCurve( //-------------------------------------------------------------------------------------------------- void RimEnsembleCurveSetCollection::addCurveSet(RimEnsembleCurveSet* curveSet) { - static int nextAutoColorIndex = 1; - static int numberOfColors = (int)RiaColorTables::summaryCurveDefaultPaletteColors().size(); if (curveSet) { - curveSet->setColor(RimSummaryCurveAppearanceCalculator::cycledPaletteColor(nextAutoColorIndex)); + m_curveSets.push_back(curveSet); - nextAutoColorIndex = (++nextAutoColorIndex) % numberOfColors; + } } @@ -193,6 +191,14 @@ std::vector RimEnsembleCurveSetCollection::visibleCurveSet return visible; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RimEnsembleCurveSetCollection::curveSetCount() const +{ + return m_curveSets.size(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSetCollection.h b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSetCollection.h index 2eb506aa84..6f80d235dc 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSetCollection.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSetCollection.h @@ -52,6 +52,7 @@ public: std::vector curveSets() const; std::vector visibleCurveSets() const; + size_t curveSetCount() const; void deleteAllCurveSets(); diff --git a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSetColorManager.cpp b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSetColorManager.cpp index cfeae62e06..8866abddc7 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSetColorManager.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSetColorManager.cpp @@ -22,7 +22,7 @@ //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -const std::map RimEnsembleCurveSetColorManager::ENSEMBLE_COLOR_RANGES( +const std::map RimEnsembleCurveSetColorManager::EnsembleColorRanges( { { 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) }) }, @@ -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; - curveSet->firstAncestorOrThisOfType(coll); + auto crIt = EnsembleColorRanges.begin(); + for (int i = 0; i < modIndex; ++i) ++crIt; - if (coll) - { - 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())); - 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; + return crIt->first; } std::map RimEnsembleCurveSetColorManager::m_nextColorIndexes; diff --git a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSetColorManager.h b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSetColorManager.h index 0149ff0de2..e3ff7e3768 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSetColorManager.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSetColorManager.h @@ -35,19 +35,19 @@ class RimEnsembleCurveSetCollection; class RimEnsembleCurveSetColorManager { public: - static const std::map ENSEMBLE_COLOR_RANGES; + static const std::map EnsembleColorRanges; static const RimRegularLegendConfig::ColorRangesType DEFAULT_ENSEMBLE_COLOR_RANGE; + static RimRegularLegendConfig::ColorRangesType cycledEnsembleColorRange(int index); 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); private: - static RimRegularLegendConfig::ColorRangesType colorRangeByIndex(int index); static std::map m_nextColorIndexes; static std::map> m_colorCache;