#780 A major step towards a flexible assignment of curve appearance based on the properties of the curve data

This commit is contained in:
Jacob Støren
2016-08-08 15:14:34 +02:00
parent 5088ae90d9
commit 10d5da6ef5
6 changed files with 386 additions and 53 deletions

View File

@@ -87,6 +87,7 @@ ${CEE_CURRENT_LIST_DIR}RimGridSummaryCase.cpp
${CEE_CURRENT_LIST_DIR}RimFileSummaryCase.cpp ${CEE_CURRENT_LIST_DIR}RimFileSummaryCase.cpp
${CEE_CURRENT_LIST_DIR}RimSummaryCaseCollection.h ${CEE_CURRENT_LIST_DIR}RimSummaryCaseCollection.h
${CEE_CURRENT_LIST_DIR}RimPlotCurve.h ${CEE_CURRENT_LIST_DIR}RimPlotCurve.h
${CEE_CURRENT_LIST_DIR}RimCurveAppearanceCalculator.h
${CEE_CURRENT_LIST_DIR}RimEclipseInputCaseOpm.h ${CEE_CURRENT_LIST_DIR}RimEclipseInputCaseOpm.h
) )
@@ -173,6 +174,7 @@ ${CEE_CURRENT_LIST_DIR}RimGridSummaryCase.cpp
${CEE_CURRENT_LIST_DIR}RimFileSummaryCase.cpp ${CEE_CURRENT_LIST_DIR}RimFileSummaryCase.cpp
${CEE_CURRENT_LIST_DIR}RimSummaryCaseCollection.cpp ${CEE_CURRENT_LIST_DIR}RimSummaryCaseCollection.cpp
${CEE_CURRENT_LIST_DIR}RimPlotCurve.cpp ${CEE_CURRENT_LIST_DIR}RimPlotCurve.cpp
${CEE_CURRENT_LIST_DIR}RimCurveAppearanceCalculator.cpp
${CEE_CURRENT_LIST_DIR}RimEclipseInputCaseOpm.cpp ${CEE_CURRENT_LIST_DIR}RimEclipseInputCaseOpm.cpp
) )

View File

@@ -0,0 +1,201 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016 Statoil ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RimCurveAppearanceCalculator.h"
#include "RimSummaryCurve.h"
#include "cvfVector3.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimCurveLookCalculator::RimCurveLookCalculator(const std::set<std::pair<RimSummaryCase*, RifEclipseSummaryAddress> >& curveDefinitions)
{
for(const std::pair<RimSummaryCase*, RifEclipseSummaryAddress>& curveDef : curveDefinitions)
{
if(curveDef.first) m_caseToAppearanceIdxMap[curveDef.first] = -1;
if(!curveDef.second.quantityName().empty()) m_varToAppearanceIdxMap[curveDef.second.quantityName()] = -1;
if(!curveDef.second.wellName().empty()) m_welToAppearanceIdxMap[curveDef.second.wellName()] = -1;
if(!curveDef.second.wellGroupName().empty()) m_grpToAppearanceIdxMap[curveDef.second.wellGroupName()] = -1;
if(!(curveDef.second.regionNumber() == -1)) m_regToAppearanceIdxMap[curveDef.second.regionNumber()] = -1;
}
m_caseCount = m_caseToAppearanceIdxMap.size();
m_variableCount = m_varToAppearanceIdxMap .size();
m_wellCount = m_welToAppearanceIdxMap .size();
m_groupCount = m_grpToAppearanceIdxMap .size();
m_regionCount = m_regToAppearanceIdxMap .size();
// Select the appearance type for each data "dimension"
m_caseAppearanceType = SYMBOL;
m_varAppearanceType = COLOR;
m_wellAppearanceType = LINE_STYLE;
m_groupAppearanceType = NONE;
m_regionAppearanceType = NONE;
// Assign increasing indexes
{ int idx = 0; for(auto& pair : m_caseToAppearanceIdxMap) pair.second = idx++; }
{ int idx = 0; for(auto& pair : m_varToAppearanceIdxMap) pair.second = idx++; }
{ int idx = 0; for(auto& pair : m_welToAppearanceIdxMap) pair.second = idx++; }
{ int idx = 0; for(auto& pair : m_grpToAppearanceIdxMap) pair.second = idx++; }
{ int idx = 0; for(auto& pair : m_regToAppearanceIdxMap) pair.second = idx++; }
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCurveLookCalculator::setupCurveLook(RimSummaryCurve* curve)
{
m_currentCurveBaseColor = cvf::Color3f(0, 0, 0);
m_currentCurveGradient = 0.0f;
int caseAppearanceIdx = m_caseToAppearanceIdxMap[curve->summaryCase()];
int varAppearanceIdx = m_varToAppearanceIdxMap[curve->summaryAddress().quantityName()];
int welAppearanceIdx = m_welToAppearanceIdxMap[curve->summaryAddress().wellName()];
int grpAppearanceIdx = m_grpToAppearanceIdxMap[curve->summaryAddress().wellGroupName()];
int regAppearanceIdx = m_regToAppearanceIdxMap[curve->summaryAddress().regionNumber()];
setOneCurveAppearance(m_caseAppearanceType, m_caseCount, caseAppearanceIdx, curve);
setOneCurveAppearance(m_varAppearanceType, m_variableCount, varAppearanceIdx, curve);
setOneCurveAppearance(m_wellAppearanceType, m_wellCount, welAppearanceIdx, curve);
setOneCurveAppearance(m_groupAppearanceType, m_groupCount, grpAppearanceIdx, curve);
setOneCurveAppearance(m_regionAppearanceType, m_regionCount, regAppearanceIdx, curve);
curve->setColor(gradeColor(m_currentCurveBaseColor, m_currentCurveGradient));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Color3f RimCurveLookCalculator::cycledPaletteColor(int colorIndex)
{
static const int RI_LOGPLOT_CURVECOLORSCOUNT = 11;
static const cvf::ubyte RI_LOGPLOT_CURVECOLORS[][3] =
{
{ 202, 0, 0 },
{ 236, 118, 0 },
{ 236, 188, 0 },
{ 164, 193, 0 },
{ 78, 204, 0 },
{ 0, 205, 68 },
{ 0, 221, 221 },
{ 0, 143, 239 },
{ 56, 56, 255 },
{ 169, 2, 240 },
{ 248, 0, 170 }
};
int paletteIdx = colorIndex % RI_LOGPLOT_CURVECOLORSCOUNT;
cvf::Color3ub ubColor(RI_LOGPLOT_CURVECOLORS[paletteIdx][0], RI_LOGPLOT_CURVECOLORS[paletteIdx][1], RI_LOGPLOT_CURVECOLORS[paletteIdx][2]);
cvf::Color3f cvfColor(ubColor);
return cvfColor;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPlotCurve::LineStyleEnum RimCurveLookCalculator::cycledLineStyle(int index)
{
return caf::AppEnum<RimPlotCurve::LineStyleEnum>::fromIndex(1 + (index % (caf::AppEnum<RimPlotCurve::LineStyleEnum>::size() - 1)));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPlotCurve::PointSymbolEnum RimCurveLookCalculator::cycledSymbol(int index)
{
return caf::AppEnum<RimPlotCurve::PointSymbolEnum>::fromIndex(1 + (index % (caf::AppEnum<RimPlotCurve::PointSymbolEnum>::size() - 1)));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RimCurveLookCalculator::cycledLineThickness(int index)
{
static const int thicknessCount = 3;
static const int thicknesses[] ={ 1, 2, 4 };
return (thicknesses[(index) % 3]);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
float RimCurveLookCalculator::gradient(size_t totalCount, int index)
{
if(totalCount == 1) return 0.0f;
const float darkLimit = -1.0f;
const float lightLimit = 0.9f;
float totalSpan = lightLimit - darkLimit;
float step = totalSpan / (totalCount -1);
return darkLimit + (index * step);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCurveLookCalculator::setOneCurveAppearance(CurveAppearanceType appeaType, size_t totalCount, int appeaIdx, RimSummaryCurve* curve)
{
switch(appeaType)
{
case NONE:
break;
case COLOR:
m_currentCurveBaseColor = cycledPaletteColor(appeaIdx);
break;
case GRADIENT:
m_currentCurveGradient = gradient(totalCount, appeaIdx);
break;
case LINE_STYLE:
curve->setLineStyle(cycledLineStyle(appeaIdx));
break;
case SYMBOL:
curve->setSymbol(cycledSymbol(appeaIdx));
break;
case LINE_THICKNESS:
curve->setLineThickness(cycledLineThickness(appeaIdx));
break;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Color3f RimCurveLookCalculator::gradeColor(const cvf::Color3f& color, float factor)
{
CVF_ASSERT(-1.0 <= factor && factor <= 1.0);
cvf::Vec3f orgC(color.r(), color.g(), color.b());
cvf::Vec3f targetC;
if(factor < 0)
{
targetC = cvf::Vec3f(0, 0, 0);
}
else
{
targetC = cvf::Vec3f(1, 1, 1);
}
cvf::Vec3f newColor = fabs(factor) * (targetC - orgC) + orgC;
return cvf::Color3f(newColor[0], newColor[1], newColor[2]);
}

View File

@@ -0,0 +1,154 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016 Statoil ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfColor3.h"
#include <set>
#include "RifEclipseSummaryAddress.h"
#include "RimPlotCurve.h"
class RimSummaryCurve;
class RimSummaryCase;
class RimCurveLookCalculator
{
public:
#if 0
RimCurveLookCalculator(const std::set<std::pair<RimSummaryCase*, RifEclipseSummaryAddress> >& curveDefinitions)
{
std::set<RimSummaryCase*> casSet;
std::set<std::string> varSet;
std::set<std::string> welSet;
std::set<std::string> grpSet;
std::set<int> regSet;
for (const std::pair<RimSummaryCase*, RifEclipseSummaryAddress>& curveDef : curveDefinitions)
{
if (curveDef.first) casSet.insert(curveDef.first);
if (!curveDef.second.quantityName().empty()) varSet.insert(curveDef.second.quantityName());
if (!curveDef.second.wellName().empty()) welSet.insert(curveDef.second.wellName());
if (!curveDef.second.wellGroupName().empty()) grpSet.insert(curveDef.second.wellGroupName());
if (!(curveDef.second.regionNumber() == -1)) regSet.insert(curveDef.second.regionNumber());
}
m_caseCount = casSet.size();
m_variableCount = varSet.size();
m_wellCount = welSet.size();
m_groupCount = grpSet.size();
m_regionCount = regSet.size();
prevCase = nullptr;
colorIndex = 0;
lineStyleIdx = -1;
}
#endif
RimCurveLookCalculator(const std::set<std::pair<RimSummaryCase*, RifEclipseSummaryAddress> >& curveDefinitions);
#if 0
void setupCurveLook2(RimSummaryCurve* curve)
{
RimPlotCurve::LineStyleEnum lineStyle = RimPlotCurve::STYLE_SOLID;
if(curve->summaryCase() != prevCase)
{
prevCase = curve->summaryCase();
lineStyleIdx++;
}
lineStyle = caf::AppEnum<RimPlotCurve::LineStyleEnum>::fromIndex(lineStyleIdx%caf::AppEnum<RimPlotCurve::LineStyleEnum>::size());
if(lineStyle == RimPlotCurve::STYLE_NONE)
{
lineStyle = RimPlotCurve::STYLE_SOLID;
lineStyleIdx++;
}
cvf::Color3f curveColor = cycledPaletteColor(colorIndex);
colorIndex++;
curve->setColor(curveColor);
curve->setLineStyle(lineStyle);
}
#endif
void setupCurveLook(RimSummaryCurve* curve);
//--------------------------------------------------------------------------------------------------
/// Pick default curve color from an index based palette
//--------------------------------------------------------------------------------------------------
cvf::Color3f cycledPaletteColor(int colorIndex);
RimPlotCurve::LineStyleEnum cycledLineStyle(int index);
RimPlotCurve::PointSymbolEnum cycledSymbol(int index);
int cycledLineThickness(int index);
float gradient(size_t totalCount, int index);
private:
int colorIndex;
RimSummaryCase* prevCase;
int lineStyleIdx;
enum CurveAppearanceType
{
NONE,
COLOR,
GRADIENT,
LINE_STYLE,
SYMBOL,
LINE_THICKNESS
};
void setOneCurveAppearance(CurveAppearanceType appeaType, size_t totalCount, int appeaIdx, RimSummaryCurve* curve);
cvf::Color3f gradeColor(const cvf::Color3f& color , float factor);
cvf::Color3f m_currentCurveBaseColor;
float m_currentCurveGradient;
size_t m_caseCount;
size_t m_variableCount;
size_t m_wellCount;
size_t m_groupCount;
size_t m_regionCount;
CurveAppearanceType m_caseAppearanceType;
CurveAppearanceType m_varAppearanceType;
CurveAppearanceType m_wellAppearanceType;
CurveAppearanceType m_groupAppearanceType;
CurveAppearanceType m_regionAppearanceType;
std::map<RimSummaryCase*, int> m_caseToAppearanceIdxMap;
std::map<std::string , int> m_varToAppearanceIdxMap;
std::map<std::string , int> m_welToAppearanceIdxMap;
std::map<std::string , int> m_grpToAppearanceIdxMap;
std::map<int , int> m_regToAppearanceIdxMap;
#if 0
std::vector<cvf::Color3f> m_colorsPrCurveDimension;
std::vector<float> m_gradientPrCurveDimension;
std::vector<RimPlotCurve::LineStyleEnum> m_lineStylePrCurveDimension;
std::vector<RimPlotCurve::PointSymbolEnum> m_symbolPrCurveDimension;
std::vector<int> m_lineThicknessPrCurveDimension;
#endif
};

View File

@@ -78,7 +78,7 @@ RimPlotCurve::RimPlotCurve()
CAF_PDM_InitField(&m_curveColor, "Color", cvf::Color3f(cvf::Color3::BLACK), "Color", "", "", ""); CAF_PDM_InitField(&m_curveColor, "Color", cvf::Color3f(cvf::Color3::BLACK), "Color", "", "", "");
CAF_PDM_InitField(&m_curveThickness, "Thickness", 1.0f, "Thickness", "", "", ""); CAF_PDM_InitField(&m_curveThickness, "Thickness", 1, "Thickness", "", "", "");
m_curveThickness.uiCapability()->setUiEditorTypeName(caf::PdmUiComboBoxEditor::uiEditorTypeName()); m_curveThickness.uiCapability()->setUiEditorTypeName(caf::PdmUiComboBoxEditor::uiEditorTypeName());
caf::AppEnum< RimPlotCurve::LineStyleEnum > lineStyle = STYLE_SOLID; caf::AppEnum< RimPlotCurve::LineStyleEnum > lineStyle = STYLE_SOLID;
@@ -383,4 +383,19 @@ void RimPlotCurve::setLineStyle(LineStyleEnum lineStyle)
m_lineStyle = lineStyle; m_lineStyle = lineStyle;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setSymbol(PointSymbolEnum symbolStyle)
{
m_pointSymbol = symbolStyle;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setLineThickness(int thickness)
{
m_curveThickness = thickness;
}

View File

@@ -55,6 +55,7 @@ public:
SYMBOL_CROSS, SYMBOL_CROSS,
SYMBOL_XCROSS SYMBOL_XCROSS
}; };
public: public:
RimPlotCurve(); RimPlotCurve();
virtual ~RimPlotCurve(); virtual ~RimPlotCurve();
@@ -66,7 +67,11 @@ public:
QwtPlotCurve* qwtPlotCurve() const; QwtPlotCurve* qwtPlotCurve() const;
void setColor(const cvf::Color3f& color); void setColor(const cvf::Color3f& color);
cvf::Color3f color() const { return m_curveColor; }
void setLineStyle(LineStyleEnum lineStyle); void setLineStyle(LineStyleEnum lineStyle);
void setSymbol(PointSymbolEnum symbolStyle);
void setLineThickness(int thickness);
bool isCurveVisible() const; bool isCurveVisible() const;
void updateCurveName(); void updateCurveName();
@@ -103,7 +108,7 @@ protected:
caf::PdmField<bool> m_isUsingAutoName; caf::PdmField<bool> m_isUsingAutoName;
caf::PdmField<cvf::Color3f> m_curveColor; caf::PdmField<cvf::Color3f> m_curveColor;
caf::PdmField<float> m_curveThickness; caf::PdmField<int> m_curveThickness;
caf::PdmField<float> m_symbolSkipPixelDistance; caf::PdmField<float> m_symbolSkipPixelDistance;

View File

@@ -41,6 +41,7 @@
#include "cafPdmUiListEditor.h" #include "cafPdmUiListEditor.h"
#include "cafPdmUiPushButtonEditor.h" #include "cafPdmUiPushButtonEditor.h"
#include "cafPdmUiTreeOrdering.h" #include "cafPdmUiTreeOrdering.h"
#include "RimCurveAppearanceCalculator.h"
QTextStream& operator << (QTextStream& str, const std::vector<RifEclipseSummaryAddress>& sobj) QTextStream& operator << (QTextStream& str, const std::vector<RifEclipseSummaryAddress>& sobj)
@@ -250,37 +251,6 @@ RimSummaryCurve* RimSummaryCurveFilter::findRimCurveFromQwtCurve(const QwtPlotCu
static const int RI_LOGPLOT_CURVECOLORSCOUNT = 15;
static const int RI_LOGPLOT_CURVECOLORS[] =
{
Qt::black,
Qt::darkBlue,
Qt::darkRed,
Qt::darkGreen,
Qt::darkYellow,
Qt::darkMagenta,
Qt::darkCyan,
Qt::darkGray,
Qt::blue,
Qt::red,
Qt::green,
Qt::yellow,
Qt::magenta,
Qt::cyan,
Qt::gray
};
//--------------------------------------------------------------------------------------------------
/// Pick default curve color from an index based palette
//--------------------------------------------------------------------------------------------------
cvf::Color3f curveColorFromTable(int colorIndex)
{
QColor color = QColor(Qt::GlobalColor(RI_LOGPLOT_CURVECOLORS[colorIndex % RI_LOGPLOT_CURVECOLORSCOUNT]));
++colorIndex;
cvf::Color3f cvfColor(color.redF(), color.greenF(), color.blueF());
return cvfColor;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -411,6 +381,7 @@ void RimSummaryCurveFilter::createSetOfCasesAndResultAdresses(
} }
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -421,6 +392,7 @@ void RimSummaryCurveFilter::createCurvesFromCurveDefinitions(const std::set<std:
RimSummaryCase* prevCase = nullptr; RimSummaryCase* prevCase = nullptr;
RimPlotCurve::LineStyleEnum lineStyle = RimPlotCurve::STYLE_SOLID; RimPlotCurve::LineStyleEnum lineStyle = RimPlotCurve::STYLE_SOLID;
RimCurveLookCalculator curveLookCalc(curveDefinitions);
for (auto& caseAddrPair : curveDefinitions) for (auto& caseAddrPair : curveDefinitions)
{ {
@@ -430,30 +402,14 @@ void RimSummaryCurveFilter::createCurvesFromCurveDefinitions(const std::set<std:
curve->setParentQwtPlot(m_parentQwtPlot); curve->setParentQwtPlot(m_parentQwtPlot);
curve->setSummaryCase(currentCase); curve->setSummaryCase(currentCase);
curve->setSummaryAddress(caseAddrPair.second); curve->setSummaryAddress(caseAddrPair.second);
if (currentCase != prevCase)
{
prevCase = currentCase;
colorIndex = 2;
lineStyleIdx++;
lineStyle = caf::AppEnum<RimPlotCurve::LineStyleEnum>::fromIndex(lineStyleIdx%caf::AppEnum<RimPlotCurve::LineStyleEnum>::size());
if (lineStyle == RimPlotCurve::STYLE_NONE)
{
lineStyle = RimPlotCurve::STYLE_SOLID;
lineStyleIdx++;
}
}
cvf::Color3f curveColor = curveColorFromTable(colorIndex);
colorIndex++;
curve->setColor(curveColor);
curve->setLineStyle(lineStyle);
m_curves.push_back(curve); m_curves.push_back(curve);
curveLookCalc.setupCurveLook(curve);
} }
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------