From 9884d531bb3141e123c17d44fd336d916e03e14c Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 18 Nov 2020 15:06:24 +0100 Subject: [PATCH] Color Legend : Make sure there are at least two color items (#7006) * #7004 Color Legend : Make sure there are at least two color items The interpolation methods require minimum two items --- ApplicationCode/ProjectDataModel/RimColorLegend.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ApplicationCode/ProjectDataModel/RimColorLegend.cpp b/ApplicationCode/ProjectDataModel/RimColorLegend.cpp index b0d29956f8..6bdf7b8089 100644 --- a/ApplicationCode/ProjectDataModel/RimColorLegend.cpp +++ b/ApplicationCode/ProjectDataModel/RimColorLegend.cpp @@ -25,6 +25,8 @@ #include "cafPdmFieldReorderCapability.h" +#include + CAF_PDM_SOURCE_INIT( RimColorLegend, "ColorLegend" ); //-------------------------------------------------------------------------------------------------- @@ -94,6 +96,7 @@ void RimColorLegend::addReorderCapability() void RimColorLegend::appendColorLegendItem( RimColorLegendItem* colorLegendItem ) { m_colorLegendItems.push_back( colorLegendItem ); + onColorLegendItemHasChanged(); } //-------------------------------------------------------------------------------------------------- @@ -143,11 +146,18 @@ void RimColorLegend::orderChanged( const caf::SignalEmitter* emitter ) cvf::Color3ubArray RimColorLegend::colorArray() const { std::vector legendItems = colorLegendItems(); - cvf::Color3ubArray colorArray( legendItems.size() ); + + // The interpolation algorithm requires minimum two levels + size_t colorCount = std::max( size_t( 2 ), legendItems.size() ); + + cvf::Color3ubArray colorArray( colorCount ); + colorArray.setAll( cvf::Color3ub::GRAY ); + for ( size_t i = 0; i < legendItems.size(); i++ ) { colorArray.set( i, cvf::Color3ub( legendItems[i]->color() ) ); } + return colorArray; }