(#805) Added category legend and mapper

This commit is contained in:
Magne Sjaastad
2016-08-02 10:25:55 +02:00
parent 3abd849230
commit 1101db5787
12 changed files with 1119 additions and 29 deletions

View File

@@ -944,12 +944,7 @@ void RimEclipseView::updateLegends()
this->cellEdgeResult()->legendConfig->setAutomaticRanges(globalMin, globalMax, globalMin, globalMax);
m_viewer->addColorLegendToBottomLeftCorner(this->cellEdgeResult()->legendConfig->legend());
cvf::OverlayScalarMapperLegend* scalarMapperLegend = dynamic_cast<cvf::OverlayScalarMapperLegend*>(this->cellEdgeResult()->legendConfig->legend());
if (scalarMapperLegend)
{
scalarMapperLegend->setTitle(cvfqt::Utils::toString(QString("Edge Results: \n") + this->cellEdgeResult()->resultVariable));
}
this->cellEdgeResult()->legendConfig->setTitle(cvfqt::Utils::toString(QString("Edge Results: \n") + this->cellEdgeResult()->resultVariable));
}
else
{
@@ -991,13 +986,15 @@ void RimEclipseView::updateMinMaxValuesAndAddLegendToView(QString legendLabel, R
resultColors->legendConfig()->setClosestToZeroValues(globalPosClosestToZero, globalNegClosestToZero, localPosClosestToZero, localNegClosestToZero);
resultColors->legendConfig()->setAutomaticRanges(globalMin, globalMax, localMin, localMax);
m_viewer->addColorLegendToBottomLeftCorner(resultColors->legendConfig()->legend());
cvf::OverlayScalarMapperLegend* scalarMapperLegend = dynamic_cast<cvf::OverlayScalarMapperLegend*>(resultColors->legendConfig()->legend());
if (scalarMapperLegend)
if (resultColors->hasCategoryResult())
{
scalarMapperLegend->setTitle(cvfqt::Utils::toString(legendLabel + resultColors->resultVariable()));
size_t adjustedTimeStep = m_currentTimeStep;
if (resultColors->hasStaticResult()) adjustedTimeStep = 0;
resultColors->legendConfig()->setCategories(cellResultsData->uniqueCellScalarValues(resultColors->scalarResultIndex()), cellResultsData->uniqueCellScalarValues(resultColors->scalarResultIndex(), adjustedTimeStep));
}
m_viewer->addColorLegendToBottomLeftCorner(resultColors->legendConfig()->legend());
resultColors->legendConfig()->setTitle(cvfqt::Utils::toString(legendLabel + resultColors->resultVariable()));
}

View File

@@ -435,11 +435,7 @@ void RimGeoMechView::updateLegends()
legendTitle += " [Bar]";
}
cvf::OverlayScalarMapperLegend* scalarMapperLegend = dynamic_cast<cvf::OverlayScalarMapperLegend*>(cellResult()->legendConfig->legend());
if (scalarMapperLegend)
{
scalarMapperLegend->setTitle(legendTitle);
}
cellResult()->legendConfig->setTitle(legendTitle);
}
//--------------------------------------------------------------------------------------------------

View File

@@ -22,8 +22,12 @@
#include "RiaApplication.h"
#include "RimEclipseCellColors.h"
#include "RimEclipseView.h"
#include "cafCategoryLegend.h"
#include "cafCategoryMapper.h"
#include "cafFactory.h"
#include "cafPdmFieldCvfColor.h"
#include "cafPdmFieldCvfMat4d.h"
@@ -60,10 +64,11 @@ namespace caf {
addItem(RimLegendConfig::OPPOSITE_NORMAL,"OPPOSITE_NORMAL", "Full color, Blue on top");
addItem(RimLegendConfig::WHITE_PINK, "WHITE_PIMK", "White to pink");
addItem(RimLegendConfig::PINK_WHITE, "PINK_WHITE", "Pink to white");
addItem(RimLegendConfig::BLUE_WHITE_RED, "BLUE_WHITE_RED", "Blue, white, red");
addItem(RimLegendConfig::RED_WHITE_BLUE, "RED_WHITE_BLUE", "Red, white, blue");
addItem(RimLegendConfig::BLUE_WHITE_RED, "BLUE_WHITE_RED", "Blue, white, red");
addItem(RimLegendConfig::RED_WHITE_BLUE, "RED_WHITE_BLUE", "Red, white, blue");
addItem(RimLegendConfig::WHITE_BLACK, "WHITE_BLACK", "White to black");
addItem(RimLegendConfig::BLACK_WHITE, "BLACK_WHITE", "Black to white");
addItem(RimLegendConfig::CATEGORY, "CATEGORY", "Category colors");
setDefault(RimLegendConfig::NORMAL);
}
}
@@ -76,6 +81,7 @@ namespace caf {
addItem(RimLegendConfig::LINEAR_CONTINUOUS, "LinearContinuous", "Continuous Linear");
addItem(RimLegendConfig::LOG10_CONTINUOUS, "Log10Continuous", "Continuous Logarithmic");
addItem(RimLegendConfig::LOG10_DISCRETE, "Log10Discrete", "Discrete Logarithmic");
addItem(RimLegendConfig::CATEGORY_INTEGER, "Category", "Category");
setDefault(RimLegendConfig::LINEAR_CONTINUOUS);
}
}
@@ -124,8 +130,11 @@ RimLegendConfig::RimLegendConfig()
m_currentScalarMapper = m_linDiscreteScalarMapper;
m_categoryMapper = new caf::CategoryMapper;
cvf::Font* standardFont = RiaApplication::instance()->standardFont();
m_scalarMapperLegend = new cvf::OverlayScalarMapperLegend(standardFont);
m_categoryLegend = new caf::CategoryLegend(standardFont, m_categoryMapper.p());
updateFieldVisibility();
updateLegend();
@@ -149,7 +158,8 @@ void RimLegendConfig::fieldChangedByUi(const caf::PdmFieldHandle* changedField,
int upperLimit = std::numeric_limits<int>::max();
m_numLevels = cvf::Math::clamp(m_numLevels.v(), 1, upperLimit);
}
else if (changedField == &m_rangeMode)
else if (changedField == &m_rangeMode ||
changedField == &m_mappingMode)
{
if (m_rangeMode == USER_DEFINED)
{
@@ -189,6 +199,8 @@ void RimLegendConfig::updateLegend()
posClosestToZero = m_globalAutoPosClosestToZero;
negClosestToZero = m_globalAutoNegClosestToZero;
m_categoryMapper->setCategories(m_globalCategories);
}
else if (m_rangeMode == AUTOMATIC_CURRENT_TIMESTEP)
{
@@ -197,6 +209,8 @@ void RimLegendConfig::updateLegend()
posClosestToZero = m_localAutoPosClosestToZero;
negClosestToZero = m_localAutoNegClosestToZero;
m_categoryMapper->setCategories(m_localCategories);
}
else
{
@@ -207,7 +221,6 @@ void RimLegendConfig::updateLegend()
negClosestToZero = m_globalAutoNegClosestToZero;
}
m_linDiscreteScalarMapper->setRange(adjustedMin, adjustedMax);
m_linSmoothScalarMapper->setRange(adjustedMin, adjustedMax);
@@ -329,6 +342,36 @@ void RimLegendConfig::updateLegend()
}
break;
case CATEGORY:
{
// Based on http://stackoverflow.com/questions/470690/how-to-automatically-generate-n-distinct-colors
// and Kelly Colors
legendColors.reserve(20);
legendColors.add(cvf::Color3ub(255, 179, 0)); // vivid_yellow
legendColors.add(cvf::Color3ub(128, 62, 117)); // strong_purple
legendColors.add(cvf::Color3ub(255, 104, 0)); // vivid_orange
legendColors.add(cvf::Color3ub(166, 189, 215)); // very_light_blue
legendColors.add(cvf::Color3ub(193, 0, 32)); // vivid_red
legendColors.add(cvf::Color3ub(206, 162, 98)); // grayish_yellow
legendColors.add(cvf::Color3ub(129, 112, 102)); // medium_gray
// these aren't good for people with defective color vision
legendColors.add(cvf::Color3ub( 0, 125, 52)); // vivid_green
legendColors.add(cvf::Color3ub(246, 118, 142)); //strong_purplish_pink
legendColors.add(cvf::Color3ub( 0, 83, 138)); //strong_blue
legendColors.add(cvf::Color3ub(255, 122, 92)); //strong_yellowish_pink
legendColors.add(cvf::Color3ub( 83, 55, 122)); //strong_violet
legendColors.add(cvf::Color3ub(255, 142, 0)); //vivid_orange_yellow
legendColors.add(cvf::Color3ub(179, 40, 81)); //strong_purplish_red
legendColors.add(cvf::Color3ub(244, 200, 0)); //vivid_greenish_yellow
legendColors.add(cvf::Color3ub(127, 24, 13)); //strong_reddish_brown
legendColors.add(cvf::Color3ub(147, 170, 0)); //vivid_yellowish_green
legendColors.add(cvf::Color3ub( 89, 51, 21)); //deep_yellowish_brown
legendColors.add(cvf::Color3ub(241, 58, 19)); //vivid_reddish_orange
legendColors.add(cvf::Color3ub( 35, 44, 22)); //dark_olive_green
}
break;
}
m_linDiscreteScalarMapper->setColors(legendColors);
@@ -336,6 +379,8 @@ void RimLegendConfig::updateLegend()
m_logSmoothScalarMapper->setColors(legendColors);
m_linSmoothScalarMapper->setColors(legendColors);
m_categoryMapper->setColors(legendColors);
m_linDiscreteScalarMapper->setLevelCount(m_numLevels, true);
m_logDiscreteScalarMapper->setLevelCount(m_numLevels, true);
m_logSmoothScalarMapper->setLevelCount(m_numLevels, true);
@@ -355,11 +400,17 @@ void RimLegendConfig::updateLegend()
case LOG10_DISCRETE:
m_currentScalarMapper = m_logDiscreteScalarMapper.p();
break;
case CATEGORY_INTEGER:
m_currentScalarMapper = m_categoryMapper.p();
break;
default:
break;
}
m_scalarMapperLegend->setScalarMapper(m_currentScalarMapper.p());
if (m_currentScalarMapper != m_categoryMapper.p())
{
m_scalarMapperLegend->setScalarMapper(m_currentScalarMapper.p());
}
double decadesInRange = 0;
if (m_mappingMode == LOG10_CONTINUOUS || m_mappingMode == LOG10_DISCRETE)
@@ -468,7 +519,14 @@ void RimLegendConfig::initAfterRead()
//--------------------------------------------------------------------------------------------------
void RimLegendConfig::updateFieldVisibility()
{
if (m_rangeMode == USER_DEFINED)
bool showRangeItems = m_mappingMode == CATEGORY_INTEGER ? false : true;
m_numLevels.uiCapability()->setUiHidden(!showRangeItems);
m_precision.uiCapability()->setUiHidden(!showRangeItems);
m_tickNumberFormat.uiCapability()->setUiHidden(!showRangeItems);
m_rangeMode.uiCapability()->setUiHidden(!showRangeItems);
if (showRangeItems && m_rangeMode == USER_DEFINED)
{
m_userDefinedMaxValue.uiCapability()->setUiHidden(false);
m_userDefinedMinValue.uiCapability()->setUiHidden(false);
@@ -537,6 +595,7 @@ cvf::ref<cvf::Color3ubArray> RimLegendConfig::interpolateColorArray(const cvf::C
}
*/
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -548,6 +607,7 @@ void RimLegendConfig::recreateLegend()
cvf::Font* standardFont = RiaApplication::instance()->standardFont();
m_scalarMapperLegend = new cvf::OverlayScalarMapperLegend(standardFont);
m_categoryLegend = new caf::CategoryLegend(standardFont, m_categoryMapper.p());
updateLegend();
}
@@ -620,12 +680,53 @@ void RimLegendConfig::setClosestToZeroValues(double globalPosClosestToZero, doub
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimLegendConfig::setCategories(const std::set<int>& globalCategories, const std::set<int>& localCategories)
{
m_globalCategories.resize(globalCategories.size());
m_localCategories.resize(localCategories.size());
{
size_t i = 0;
for (auto val : globalCategories)
{
m_globalCategories.set(i++, val);
}
}
{
size_t i = 0;
for (auto val : localCategories)
{
m_localCategories.set(i++, val);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimLegendConfig::setTitle(const cvf::String& title)
{
m_scalarMapperLegend->setTitle(title);
m_categoryLegend->setTitle(title);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::OverlayItem* RimLegendConfig::legend()
{
return m_scalarMapperLegend.p();
if (m_currentScalarMapper == m_categoryMapper)
{
return m_categoryLegend.p();
}
else
{
return m_scalarMapperLegend.p();
}
}
//--------------------------------------------------------------------------------------------------
@@ -648,3 +749,60 @@ void RimLegendConfig::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering&
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QList<caf::PdmOptionItemInfo> RimLegendConfig::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly)
{
QStringList optionTexts;
bool isCategoryResult = false;
RimEclipseCellColors* cellColors = NULL;
this->firstAnchestorOrThisOfType(cellColors);
if (cellColors && cellColors->hasCategoryResult())
{
isCategoryResult = true;
}
if (fieldNeedingOptions == &m_mappingMode)
{
// This is an app enum field, see cafInternalPdmFieldTypeSpecializations.h for the default specialization of this type
optionTexts << m_mappingMode.v().uiText(LINEAR_DISCRETE);
optionTexts << m_mappingMode.v().uiText(LINEAR_CONTINUOUS);
optionTexts << m_mappingMode.v().uiText(LOG10_CONTINUOUS);
optionTexts << m_mappingMode.v().uiText(LOG10_DISCRETE);
if (isCategoryResult)
{
optionTexts << m_mappingMode.v().uiText(CATEGORY_INTEGER);
}
}
else if (fieldNeedingOptions == &m_colorRangeMode)
{
// This is an app enum field, see cafInternalPdmFieldTypeSpecializations.h for the default specialization of this type
optionTexts << m_colorRangeMode.v().uiText(NORMAL);
optionTexts << m_colorRangeMode.v().uiText(OPPOSITE_NORMAL);
optionTexts << m_colorRangeMode.v().uiText(WHITE_PINK);
optionTexts << m_colorRangeMode.v().uiText(PINK_WHITE);
optionTexts << m_colorRangeMode.v().uiText(BLUE_WHITE_RED);
optionTexts << m_colorRangeMode.v().uiText(RED_WHITE_BLUE);
optionTexts << m_colorRangeMode.v().uiText(WHITE_BLACK);
optionTexts << m_colorRangeMode.v().uiText(BLACK_WHITE);
if (isCategoryResult)
{
optionTexts << m_colorRangeMode.v().uiText(CATEGORY);
}
}
QList<caf::PdmOptionItemInfo> optionList;
for (int i = 0; i < optionTexts.size(); ++i)
{
optionList.push_back(caf::PdmOptionItemInfo(optionTexts[i], static_cast<unsigned int>(i)));
}
return optionList;
}

View File

@@ -21,13 +21,10 @@
#pragma once
#include "cvfBase.h"
#include "cvfObject.h"
#include "cvfVector2.h"
#include "cvfArray.h"
#include "cafPdmObject.h"
#include "cafPdmField.h"
#include "cafPdmPointer.h"
#include "cafAppEnum.h"
namespace cvf
{
@@ -38,6 +35,13 @@ namespace cvf
class ScalarMapperDiscreteLinear;
class ScalarMapperDiscreteLog;
class ScalarMapper;
class String;
}
namespace caf
{
class CategoryLegend;
class CategoryMapper;
}
class RimView;
@@ -75,7 +79,8 @@ public:
WHITE_BLACK,
BLACK_WHITE,
BLUE_WHITE_RED,
RED_WHITE_BLUE
RED_WHITE_BLUE,
CATEGORY
};
typedef caf::AppEnum<ColorRangesType> ColorRangeEnum;
@@ -85,7 +90,8 @@ public:
LINEAR_DISCRETE,
LINEAR_CONTINUOUS,
LOG10_CONTINUOUS,
LOG10_DISCRETE
LOG10_DISCRETE,
CATEGORY_INTEGER
};
enum NumberFormatType { AUTO, SCIENTIFIC, FIXED};
@@ -94,6 +100,9 @@ public:
void setColorRangeMode(ColorRangesType colorMode);
void setAutomaticRanges(double globalMin, double globalMax, double localMin, double localMax);
void setClosestToZeroValues(double globalPosClosestToZero, double globalNegClosestToZero, double localPosClosestToZero, double localNegClosestToZero);
void setCategories(const std::set<int>& globalCategories, const std::set<int>& localCategories);
void setTitle(const cvf::String& title);
cvf::ScalarMapper* scalarMapper() { return m_currentScalarMapper.p(); }
cvf::OverlayItem* legend();
@@ -103,6 +112,8 @@ protected:
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
virtual void initAfterRead();
virtual void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering );
virtual QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly);
private:
void updateLegend();
void updateFieldVisibility();
@@ -120,6 +131,9 @@ private:
cvf::ref<cvf::ScalarMapper> m_currentScalarMapper;
cvf::ref<cvf::OverlayScalarMapperLegend> m_scalarMapperLegend;
cvf::ref<caf::CategoryMapper> m_categoryMapper;
cvf::ref<caf::CategoryLegend> m_categoryLegend;
double m_globalAutoMax;
double m_globalAutoMin;
@@ -131,6 +145,9 @@ private:
double m_localAutoPosClosestToZero;
double m_localAutoNegClosestToZero;
cvf::IntArray m_globalCategories;
cvf::IntArray m_localCategories;
// Fields
caf::PdmField<int> m_numLevels;
caf::PdmField<int> m_precision;
@@ -140,5 +157,4 @@ private:
caf::PdmField<double> m_userDefinedMinValue;
caf::PdmField<caf::AppEnum<ColorRangesType> > m_colorRangeMode;
caf::PdmField<caf::AppEnum<MappingType> > m_mappingMode;
};