#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

@@ -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();
}

View File

@@ -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<RimEnsembleCurveSet*> RimEnsembleCurveSetCollection::visibleCurveSet
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*> visibleCurveSets() const;
size_t curveSetCount() const;
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::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<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;
return crIt->first;
}
std::map<RimEnsembleCurveSetCollection*, int> RimEnsembleCurveSetColorManager::m_nextColorIndexes;

View File

@@ -35,19 +35,19 @@ class RimEnsembleCurveSetCollection;
class RimEnsembleCurveSetColorManager
{
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 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<RimEnsembleCurveSetCollection*, int> m_nextColorIndexes;
static std::map<RimEnsembleCurveSetCollection*, std::map<RimEnsembleCurveSet*, RimRegularLegendConfig::ColorRangesType>> m_colorCache;