mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
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:
@@ -136,6 +136,30 @@ cvf::Color3f RiaColorTools::fromQColorTo3f( QColor color )
|
||||
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;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -42,6 +42,8 @@ public:
|
||||
static QColor toQColor( cvf::Color4f color );
|
||||
static cvf::Color3f fromQColorTo3f( QColor );
|
||||
|
||||
static cvf::Color3f selectContrastColorFromCandiates( cvf::Color3f color, const cvf::Color3fArray& candidates );
|
||||
|
||||
static QColor textColor();
|
||||
static cvf::Color3f textColor3f();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user