Regression Curves: Use a contrast color for the regression curves

Use a list of predefined colors, and select the color with the larges RGB difference to the source curve. This will ensure that we avoid ending up with fully white or fully black curves, unable to see.
This commit is contained in:
Magne Sjaastad 2023-10-17 11:35:36 +02:00
parent 2fe290bbce
commit f763f73ba3
3 changed files with 40 additions and 6 deletions

View File

@ -136,6 +136,30 @@ cvf::Color3f RiaColorTools::fromQColorTo3f( QColor color )
return cvf::Color3f( color.redF(), color.greenF(), color.blueF() ); return cvf::Color3f( color.redF(), color.greenF(), color.blueF() );
} }
//--------------------------------------------------------------------------------------------------
/// Find the color with larges distance to the given color based on RGB distance
//--------------------------------------------------------------------------------------------------
cvf::Color3f RiaColorTools::selectContrastColorFromCandiates( cvf::Color3f color, const cvf::Color3fArray& candidates )
{
if ( candidates.size() == 0 ) return color;
float maxDiff = 0.0f;
cvf::Color3f selectedColor = color;
for ( const auto& candidate : candidates )
{
const auto diff = std::fabs( color.r() - candidate.r() ) + std::fabs( color.g() - candidate.g() ) +
std::fabs( color.b() - candidate.b() );
if ( diff > maxDiff )
{
maxDiff = diff;
selectedColor = candidate;
}
}
return selectedColor;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -42,6 +42,8 @@ public:
static QColor toQColor( cvf::Color4f color ); static QColor toQColor( cvf::Color4f color );
static cvf::Color3f fromQColorTo3f( QColor ); static cvf::Color3f fromQColorTo3f( QColor );
static cvf::Color3f selectContrastColorFromCandiates( cvf::Color3f color, const cvf::Color3fArray& candidates );
static QColor textColor(); static QColor textColor();
static cvf::Color3f textColor3f(); static cvf::Color3f textColor3f();

View File

@ -18,6 +18,7 @@
#include "RicCreateRegressionAnalysisCurveFeature.h" #include "RicCreateRegressionAnalysisCurveFeature.h"
#include "RiaColorTables.h"
#include "RiaColorTools.h" #include "RiaColorTools.h"
#include "RiaSummaryTools.h" #include "RiaSummaryTools.h"
@ -84,12 +85,15 @@ void RicCreateRegressionAnalysisCurveFeature::setupActionLook( QAction* actionTo
RimSummaryRegressionAnalysisCurve* RimSummaryRegressionAnalysisCurve*
RicCreateRegressionAnalysisCurveFeature::createRegressionAnalysisCurveAndAddToPlot( RimSummaryCurve* sourceCurve ) RicCreateRegressionAnalysisCurveFeature::createRegressionAnalysisCurveAndAddToPlot( RimSummaryCurve* sourceCurve )
{ {
RimSummaryPlot* summaryPlot = caf::firstAncestorOfTypeFromSelectedObject<RimSummaryPlot>(); auto* summaryPlot = caf::firstAncestorOfTypeFromSelectedObject<RimSummaryPlot>();
auto newCurve = new RimSummaryRegressionAnalysisCurve(); auto newCurve = new RimSummaryRegressionAnalysisCurve();
RiaSummaryTools::copyCurveDataSources( *newCurve, *sourceCurve ); RiaSummaryTools::copyCurveDataSources( *newCurve, *sourceCurve );
newCurve->setColor( sourceCurve->color() ); auto candidates = RiaColorTables::summaryCurveDefaultPaletteColors();
auto contrastColor = RiaColorTools::selectContrastColorFromCandiates( sourceCurve->color(), candidates.color3fArray() );
newCurve->setColor( contrastColor );
newCurve->setSymbol( RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_RECT ); newCurve->setSymbol( RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_RECT );
newCurve->setSymbolSkipDistance( 50 ); newCurve->setSymbolSkipDistance( 50 );
@ -100,7 +104,7 @@ RimSummaryRegressionAnalysisCurve*
newCurve->loadDataAndUpdate( true ); newCurve->loadDataAndUpdate( true );
newCurve->updateConnectedEditors(); newCurve->updateConnectedEditors();
RimSummaryMultiPlot* summaryMultiPlot = summaryPlot->firstAncestorOrThisOfType<RimSummaryMultiPlot>(); auto* summaryMultiPlot = summaryPlot->firstAncestorOrThisOfType<RimSummaryMultiPlot>();
if ( summaryMultiPlot ) if ( summaryMultiPlot )
{ {
summaryMultiPlot->updatePlotTitles(); summaryMultiPlot->updatePlotTitles();
@ -121,14 +125,18 @@ RimSummaryRegressionAnalysisCurve*
RimSummaryRegressionAnalysisCurve* RimSummaryRegressionAnalysisCurve*
RicCreateRegressionAnalysisCurveFeature::createRegressionAnalysisCurveAndAddToPlot( RimEnsembleCurveSet* sourceCurveSet ) RicCreateRegressionAnalysisCurveFeature::createRegressionAnalysisCurveAndAddToPlot( RimEnsembleCurveSet* sourceCurveSet )
{ {
RimSummaryPlot* summaryPlot = caf::firstAncestorOfTypeFromSelectedObject<RimSummaryPlot>(); auto* summaryPlot = caf::firstAncestorOfTypeFromSelectedObject<RimSummaryPlot>();
auto newCurve = new RimSummaryRegressionAnalysisCurve(); auto newCurve = new RimSummaryRegressionAnalysisCurve();
newCurve->setEnsembleCurveSet( sourceCurveSet ); newCurve->setEnsembleCurveSet( sourceCurveSet );
auto color = RiaColorTools::fromQColorTo3f( sourceCurveSet->mainEnsembleColor() ); auto color = RiaColorTools::fromQColorTo3f( sourceCurveSet->mainEnsembleColor() );
newCurve->setColor( color );
auto candidates = RiaColorTables::summaryCurveDefaultPaletteColors();
auto contrastColor = RiaColorTools::selectContrastColorFromCandiates( color, candidates.color3fArray() );
newCurve->setColor( contrastColor );
newCurve->setSymbol( RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_RECT ); newCurve->setSymbol( RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_RECT );
newCurve->setSymbolSkipDistance( 50 ); newCurve->setSymbolSkipDistance( 50 );
@ -141,7 +149,7 @@ RimSummaryRegressionAnalysisCurve*
newCurve->loadDataAndUpdate( true ); newCurve->loadDataAndUpdate( true );
newCurve->updateConnectedEditors(); newCurve->updateConnectedEditors();
RimSummaryMultiPlot* summaryMultiPlot = summaryPlot->firstAncestorOrThisOfType<RimSummaryMultiPlot>(); auto* summaryMultiPlot = summaryPlot->firstAncestorOrThisOfType<RimSummaryMultiPlot>();
if ( summaryMultiPlot ) if ( summaryMultiPlot )
{ {
summaryMultiPlot->updatePlotTitles(); summaryMultiPlot->updatePlotTitles();