mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#5315 Category Cell Results: Use color legend values
This commit is contained in:
parent
5ae0e6a511
commit
22c098368d
@ -57,6 +57,7 @@
|
|||||||
#include "cafPdmUiComboBoxEditor.h"
|
#include "cafPdmUiComboBoxEditor.h"
|
||||||
#include "cafPdmUiLineEditor.h"
|
#include "cafPdmUiLineEditor.h"
|
||||||
|
|
||||||
|
#include "cvfMath.h"
|
||||||
#include "cvfScalarMapperContinuousLinear.h"
|
#include "cvfScalarMapperContinuousLinear.h"
|
||||||
#include "cvfScalarMapperContinuousLog.h"
|
#include "cvfScalarMapperContinuousLog.h"
|
||||||
#include "cvfScalarMapperDiscreteLinear.h"
|
#include "cvfScalarMapperDiscreteLinear.h"
|
||||||
@ -99,10 +100,7 @@ void RimRegularLegendConfig::ColorRangeEnum::setUp()
|
|||||||
addItem( RimRegularLegendConfig::ColorRangesType::UNDEFINED, "UNDEFINED", "Undefined" );
|
addItem( RimRegularLegendConfig::ColorRangesType::UNDEFINED, "UNDEFINED", "Undefined" );
|
||||||
setDefault( RimRegularLegendConfig::ColorRangesType::UNDEFINED );
|
setDefault( RimRegularLegendConfig::ColorRangesType::UNDEFINED );
|
||||||
}
|
}
|
||||||
} // namespace caf
|
|
||||||
|
|
||||||
namespace caf
|
|
||||||
{
|
|
||||||
template <>
|
template <>
|
||||||
void RimRegularLegendConfig::MappingEnum::setUp()
|
void RimRegularLegendConfig::MappingEnum::setUp()
|
||||||
{
|
{
|
||||||
@ -113,10 +111,7 @@ void RimRegularLegendConfig::MappingEnum::setUp()
|
|||||||
addItem( RimRegularLegendConfig::MappingType::CATEGORY_INTEGER, "Category", "Category" );
|
addItem( RimRegularLegendConfig::MappingType::CATEGORY_INTEGER, "Category", "Category" );
|
||||||
setDefault( RimRegularLegendConfig::MappingType::LINEAR_CONTINUOUS );
|
setDefault( RimRegularLegendConfig::MappingType::LINEAR_CONTINUOUS );
|
||||||
}
|
}
|
||||||
} // namespace caf
|
|
||||||
|
|
||||||
namespace caf
|
|
||||||
{
|
|
||||||
template <>
|
template <>
|
||||||
void AppEnum<RimRegularLegendConfig::NumberFormatType>::setUp()
|
void AppEnum<RimRegularLegendConfig::NumberFormatType>::setUp()
|
||||||
{
|
{
|
||||||
@ -125,6 +120,17 @@ void AppEnum<RimRegularLegendConfig::NumberFormatType>::setUp()
|
|||||||
addItem( RimRegularLegendConfig::NumberFormatType::SCIENTIFIC, "SCIENTIFIC", "Scientific notation" );
|
addItem( RimRegularLegendConfig::NumberFormatType::SCIENTIFIC, "SCIENTIFIC", "Scientific notation" );
|
||||||
setDefault( RimRegularLegendConfig::NumberFormatType::FIXED );
|
setDefault( RimRegularLegendConfig::NumberFormatType::FIXED );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
void AppEnum<RimRegularLegendConfig::CategoryColorModeType>::setUp()
|
||||||
|
{
|
||||||
|
addItem( RimRegularLegendConfig::CategoryColorModeType::INTERPOLATE, "INTERPOLATE", "Interpolate" );
|
||||||
|
addItem( RimRegularLegendConfig::CategoryColorModeType::COLOR_LEGEND_VALUES,
|
||||||
|
"COLOR_LEGEND_VALUES",
|
||||||
|
"Color Legend Values" );
|
||||||
|
setDefault( RimRegularLegendConfig::CategoryColorModeType::INTERPOLATE );
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace caf
|
} // namespace caf
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -190,6 +196,9 @@ RimRegularLegendConfig::RimRegularLegendConfig()
|
|||||||
"",
|
"",
|
||||||
"Min value of the legend (if mapping is logarithmic only positive values are valid)",
|
"Min value of the legend (if mapping is logarithmic only positive values are valid)",
|
||||||
"" );
|
"" );
|
||||||
|
|
||||||
|
CAF_PDM_InitFieldNoDefault( &m_categoryColorMode, "CategoryColorMode", "Category Mode", "", "", "" );
|
||||||
|
|
||||||
CAF_PDM_InitField( &resultVariableName, "ResultVariableUsage", QString( "" ), "", "", "", "" );
|
CAF_PDM_InitField( &resultVariableName, "ResultVariableUsage", QString( "" ), "", "", "", "" );
|
||||||
resultVariableName.uiCapability()->setUiHidden( true );
|
resultVariableName.uiCapability()->setUiHidden( true );
|
||||||
|
|
||||||
@ -436,16 +445,7 @@ void RimRegularLegendConfig::updateLegend()
|
|||||||
m_currentScalarMapper = m_logDiscreteScalarMapper.p();
|
m_currentScalarMapper = m_logDiscreteScalarMapper.p();
|
||||||
break;
|
break;
|
||||||
case MappingType::CATEGORY_INTEGER:
|
case MappingType::CATEGORY_INTEGER:
|
||||||
m_categoryMapper->setCategoriesWithNames( m_categories, m_categoryNames );
|
configureCategoryMapper();
|
||||||
|
|
||||||
if ( m_categoryColors.size() > 0 )
|
|
||||||
{
|
|
||||||
m_categoryMapper->setCycleColors( m_categoryColors );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_categoryMapper->setInterpolateColors( legendColors );
|
|
||||||
}
|
|
||||||
m_currentScalarMapper = m_categoryMapper.p();
|
m_currentScalarMapper = m_categoryMapper.p();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -617,6 +617,9 @@ void RimRegularLegendConfig::updateFieldVisibility()
|
|||||||
m_userDefinedMaxValue.uiCapability()->setUiHidden( true );
|
m_userDefinedMaxValue.uiCapability()->setUiHidden( true );
|
||||||
m_userDefinedMinValue.uiCapability()->setUiHidden( true );
|
m_userDefinedMinValue.uiCapability()->setUiHidden( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isCategoryMappingMode = ( m_mappingMode == MappingType::CATEGORY_INTEGER );
|
||||||
|
m_categoryColorMode.uiCapability()->setUiHidden( !isCategoryMappingMode );
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -709,6 +712,51 @@ void RimRegularLegendConfig::updateCategoryItems()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RimRegularLegendConfig::configureCategoryMapper()
|
||||||
|
{
|
||||||
|
if ( m_categoryColorMode() == CategoryColorModeType::COLOR_LEGEND_VALUES )
|
||||||
|
{
|
||||||
|
std::vector<RimColorLegendItem*> legendItems = m_colorLegend()->colorLegendItems();
|
||||||
|
cvf::Color3ubArray colorArray;
|
||||||
|
|
||||||
|
if ( !m_categories.empty() ) colorArray.resize( m_categories.size() );
|
||||||
|
|
||||||
|
colorArray.setAll( cvf::Color3ub( RiaColorTables::undefinedCellColor() ) );
|
||||||
|
|
||||||
|
for ( auto value : m_categories )
|
||||||
|
{
|
||||||
|
for ( auto legendItem : legendItems )
|
||||||
|
{
|
||||||
|
if ( legendItem->categoryValue() == value )
|
||||||
|
{
|
||||||
|
int zeroBasedIndex = cvf::Math::clamp( value - 1, 0, int( colorArray.size() - 1 ) );
|
||||||
|
colorArray.set( zeroBasedIndex, cvf::Color3ub( legendItem->color() ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_categoryMapper->setCategoriesValueNameColor( m_categories, m_categoryNames, colorArray );
|
||||||
|
}
|
||||||
|
else if ( m_categoryColorMode() == CategoryColorModeType::INTERPOLATE )
|
||||||
|
{
|
||||||
|
m_categoryMapper->setCategoriesWithNames( m_categories, m_categoryNames );
|
||||||
|
|
||||||
|
if ( m_categoryColors.size() > 0 )
|
||||||
|
{
|
||||||
|
m_categoryMapper->setCycleColors( m_categoryColors );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cvf::Color3ubArray legendColors = m_colorLegend()->colorArray();
|
||||||
|
|
||||||
|
m_categoryMapper->setInterpolateColors( legendColors );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -1018,6 +1066,7 @@ void RimRegularLegendConfig::defineUiOrdering( QString uiConfigName, caf::PdmUiO
|
|||||||
mappingGr->add( &m_rangeMode );
|
mappingGr->add( &m_rangeMode );
|
||||||
mappingGr->add( &m_userDefinedMaxValue );
|
mappingGr->add( &m_userDefinedMaxValue );
|
||||||
mappingGr->add( &m_userDefinedMinValue );
|
mappingGr->add( &m_userDefinedMinValue );
|
||||||
|
mappingGr->add( &m_categoryColorMode );
|
||||||
}
|
}
|
||||||
updateFieldVisibility();
|
updateFieldVisibility();
|
||||||
}
|
}
|
||||||
|
@ -109,9 +109,16 @@ public:
|
|||||||
SCIENTIFIC,
|
SCIENTIFIC,
|
||||||
FIXED
|
FIXED
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef caf::AppEnum<MappingType> MappingEnum;
|
typedef caf::AppEnum<MappingType> MappingEnum;
|
||||||
void onRecreateLegend();
|
|
||||||
|
enum class CategoryColorModeType
|
||||||
|
{
|
||||||
|
INTERPOLATE,
|
||||||
|
COLOR_LEGEND_VALUES
|
||||||
|
};
|
||||||
|
typedef caf::AppEnum<CategoryColorModeType> CategoryColorModeEnum;
|
||||||
|
|
||||||
|
void onRecreateLegend();
|
||||||
|
|
||||||
void setColorLegend( RimColorLegend* colorLegend );
|
void setColorLegend( RimColorLegend* colorLegend );
|
||||||
RimColorLegend* colorLegend() const;
|
RimColorLegend* colorLegend() const;
|
||||||
@ -166,6 +173,7 @@ private:
|
|||||||
double roundToNumSignificantDigits( double value, double precision );
|
double roundToNumSignificantDigits( double value, double precision );
|
||||||
|
|
||||||
void updateCategoryItems();
|
void updateCategoryItems();
|
||||||
|
void configureCategoryMapper();
|
||||||
|
|
||||||
friend class RimViewLinker;
|
friend class RimViewLinker;
|
||||||
|
|
||||||
@ -198,16 +206,18 @@ private:
|
|||||||
cvf::Color3ubArray m_categoryColors;
|
cvf::Color3ubArray m_categoryColors;
|
||||||
|
|
||||||
// Fields
|
// Fields
|
||||||
caf::PdmField<bool> m_showLegend;
|
caf::PdmField<bool> m_showLegend;
|
||||||
caf::PdmField<int> m_numLevels;
|
caf::PdmField<int> m_numLevels;
|
||||||
caf::PdmField<int> m_precision;
|
caf::PdmField<int> m_precision;
|
||||||
caf::PdmField<caf::AppEnum<NumberFormatType>> m_tickNumberFormat;
|
caf::PdmField<caf::AppEnum<NumberFormatType>> m_tickNumberFormat;
|
||||||
caf::PdmField<RangeModeEnum> m_rangeMode;
|
caf::PdmField<RangeModeEnum> m_rangeMode;
|
||||||
caf::PdmField<double> m_userDefinedMaxValue;
|
caf::PdmField<double> m_userDefinedMaxValue;
|
||||||
caf::PdmField<double> m_userDefinedMinValue;
|
caf::PdmField<double> m_userDefinedMinValue;
|
||||||
caf::PdmField<caf::AppEnum<ColorRangesType>> m_colorRangeMode_OBSOLETE;
|
caf::PdmField<caf::AppEnum<ColorRangesType>> m_colorRangeMode_OBSOLETE;
|
||||||
caf::PdmField<caf::AppEnum<MappingType>> m_mappingMode;
|
caf::PdmField<caf::AppEnum<MappingType>> m_mappingMode;
|
||||||
caf::PdmPtrField<RimColorLegend*> m_colorLegend;
|
caf::PdmField<caf::AppEnum<CategoryColorModeType>> m_categoryColorMode;
|
||||||
|
|
||||||
|
caf::PdmPtrField<RimColorLegend*> m_colorLegend;
|
||||||
|
|
||||||
QString m_title;
|
QString m_title;
|
||||||
int m_significantDigitsInData;
|
int m_significantDigitsInData;
|
||||||
|
@ -46,6 +46,20 @@ void CategoryMapper::setCategoriesWithNames( const std::vector<int>& cat
|
|||||||
setInterpolateColors( *( colorArr.p() ) );
|
setInterpolateColors( *( colorArr.p() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void CategoryMapper::setCategoriesValueNameColor( const std::vector<int>& categoryValues,
|
||||||
|
const std::vector<cvf::String>& categoryNames,
|
||||||
|
const cvf::Color3ubArray& colorArray )
|
||||||
|
{
|
||||||
|
m_categoryValues = categoryValues;
|
||||||
|
m_categoryNames = categoryNames;
|
||||||
|
m_colors = colorArray;
|
||||||
|
|
||||||
|
recomputeMaxTexCoord();
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -20,6 +20,10 @@ public:
|
|||||||
void setCategories( const std::vector<int>& categoryValues );
|
void setCategories( const std::vector<int>& categoryValues );
|
||||||
void setCategoriesWithNames( const std::vector<int>& categoryValues, const std::vector<cvf::String>& categoryNames );
|
void setCategoriesWithNames( const std::vector<int>& categoryValues, const std::vector<cvf::String>& categoryNames );
|
||||||
|
|
||||||
|
void setCategoriesValueNameColor( const std::vector<int>& categoryValues,
|
||||||
|
const std::vector<cvf::String>& categoryNames,
|
||||||
|
const cvf::Color3ubArray& colorArray );
|
||||||
|
|
||||||
// Colors in color array are cycled, if category count is larger than color count, colors are reused
|
// Colors in color array are cycled, if category count is larger than color count, colors are reused
|
||||||
void setCycleColors( const cvf::Color3ubArray& colorArray );
|
void setCycleColors( const cvf::Color3ubArray& colorArray );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user