#4117 Implement formation categorisation

This commit is contained in:
Gaute Lindkvist 2019-02-26 16:22:01 +01:00
parent aa5935d5db
commit 41b6cd55f2
3 changed files with 95 additions and 44 deletions

View File

@ -49,7 +49,7 @@ void RimGridCrossPlotCurve::determineColorAndSymbol(int curveSetIndex, int categ
{ {
if (contrastColors) if (contrastColors)
{ {
const caf::ColorTable& colors = RiaColorTables::contrastCategoryPaletteColors(); const caf::ColorTable& colors = RiaColorTables::categoryPaletteColors();
int colorIndex = categoryIndex + curveSetIndex; // Offset cycle for each curve set int colorIndex = categoryIndex + curveSetIndex; // Offset cycle for each curve set
setColor(colors.cycledColor3f(colorIndex)); setColor(colors.cycledColor3f(colorIndex));
int numColors = (int)colors.size(); int numColors = (int)colors.size();

View File

@ -23,6 +23,7 @@
#include "RigActiveCellInfo.h" #include "RigActiveCellInfo.h"
#include "RigActiveCellsResultAccessor.h" #include "RigActiveCellsResultAccessor.h"
#include "RigCaseCellResultCalculator.h" #include "RigCaseCellResultCalculator.h"
#include "RigFormationNames.h"
#include "RigMainGrid.h" #include "RigMainGrid.h"
#include "RimCase.h" #include "RimCase.h"
@ -37,6 +38,20 @@
CAF_PDM_SOURCE_INIT(RimGridCrossPlotCurveSet, "GridCrossPlotCurveSet"); CAF_PDM_SOURCE_INIT(RimGridCrossPlotCurveSet, "GridCrossPlotCurveSet");
namespace caf
{
template<>
void AppEnum<RimGridCrossPlotCurveSet::CurveCategorization>::setUp()
{
addItem(RimGridCrossPlotCurveSet::NO_CATEGORIZATION, "NONE", "None");
addItem(RimGridCrossPlotCurveSet::TIME_CATEGORIZATION, "TIME", "Time");
addItem(RimGridCrossPlotCurveSet::FORMATION_CATEGORIZATION, "FORMATION", "Formations");
setDefault(RimGridCrossPlotCurveSet::TIME_CATEGORIZATION);
}
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -49,6 +64,8 @@ RimGridCrossPlotCurveSet::RimGridCrossPlotCurveSet()
CAF_PDM_InitField(&m_timeStep, "TimeStep", -1, "Time Step", "", "", ""); CAF_PDM_InitField(&m_timeStep, "TimeStep", -1, "Time Step", "", "", "");
m_timeStep.uiCapability()->setUiEditorTypeName(caf::PdmUiComboBoxEditor::uiEditorTypeName()); m_timeStep.uiCapability()->setUiEditorTypeName(caf::PdmUiComboBoxEditor::uiEditorTypeName());
CAF_PDM_InitFieldNoDefault(&m_categorization, "Categorization", "Data Categorization", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_xAxisProperty, "XAxisProperty", "X-Axis Property", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_xAxisProperty, "XAxisProperty", "X-Axis Property", "", "", "");
m_xAxisProperty = new RimEclipseResultDefinition; m_xAxisProperty = new RimEclipseResultDefinition;
m_xAxisProperty.uiCapability()->setUiHidden(true); m_xAxisProperty.uiCapability()->setUiHidden(true);
@ -204,6 +221,7 @@ void RimGridCrossPlotCurveSet::onLoadDataAndUpdate(bool updateParentPlot)
if (m_case()) if (m_case())
{ {
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(m_case.value()); RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(m_case.value());
if (eclipseCase) if (eclipseCase)
{ {
if (!eclipseCase->ensureReservoirCaseIsOpen()) if (!eclipseCase->ensureReservoirCaseIsOpen())
@ -214,6 +232,7 @@ void RimGridCrossPlotCurveSet::onLoadDataAndUpdate(bool updateParentPlot)
} }
RigCaseCellResultsData* resultData = eclipseCase->results(RiaDefines::MATRIX_MODEL); RigCaseCellResultsData* resultData = eclipseCase->results(RiaDefines::MATRIX_MODEL);
RigFormationNames* activeFormationNames = resultData->activeFormationNames();
RigEclipseResultAddress xAddress(m_xAxisProperty->resultType(), m_xAxisProperty->resultVariable()); RigEclipseResultAddress xAddress(m_xAxisProperty->resultType(), m_xAxisProperty->resultVariable());
RigEclipseResultAddress yAddress(m_yAxisProperty->resultType(), m_yAxisProperty->resultVariable()); RigEclipseResultAddress yAddress(m_yAxisProperty->resultType(), m_yAxisProperty->resultVariable());
@ -252,47 +271,61 @@ void RimGridCrossPlotCurveSet::onLoadDataAndUpdate(bool updateParentPlot)
RigActiveCellsResultAccessor xAccessor(mainGrid, &xValuesForAllSteps[xIndex], activeCellInfo); RigActiveCellsResultAccessor xAccessor(mainGrid, &xValuesForAllSteps[xIndex], activeCellInfo);
RigActiveCellsResultAccessor yAccessor(mainGrid, &yValuesForAllSteps[yIndex], activeCellInfo); RigActiveCellsResultAccessor yAccessor(mainGrid, &yValuesForAllSteps[yIndex], activeCellInfo);
for (size_t j = 0; j < activeCellInfo->reservoirCellCount(); ++j) for (size_t globalCellIdx = 0; globalCellIdx < activeCellInfo->reservoirCellCount(); ++globalCellIdx)
{ {
double xValue = xAccessor.cellScalarGlobIdx(j); int category = 0;
double yValue = yAccessor.cellScalarGlobIdx(j); if (m_categorization() == TIME_CATEGORIZATION)
{
category = timeStep;
}
else if (m_categorization() == FORMATION_CATEGORIZATION && activeFormationNames)
{
size_t i(cvf::UNDEFINED_SIZE_T), j(cvf::UNDEFINED_SIZE_T), k(cvf::UNDEFINED_SIZE_T);
if (mainGrid->ijkFromCellIndex(globalCellIdx, &i, &j, &k))
{
category = activeFormationNames->formationIndexFromKLayerIdx(k);
}
}
double xValue = xAccessor.cellScalarGlobIdx(globalCellIdx);
double yValue = yAccessor.cellScalarGlobIdx(globalCellIdx);
if (xValue != HUGE_VAL && yValue != HUGE_VAL) if (xValue != HUGE_VAL && yValue != HUGE_VAL)
{ {
samples[timeStep].push_back(QPointF(xValue, yValue)); samples[category].push_back(QPointF(xValue, yValue));
}
}
} }
} }
} }
} }
QStringList timeStepNames; QStringList timeStepNames = m_case->timeStepStrings();
if (m_case)
{
timeStepNames = m_case->timeStepStrings();
}
int curveSetIndex = indexInPlot(); int curveSetIndex = indexInPlot();
for (const auto& sampleCategory : samples) for (const auto& sampleCategory : samples)
{ {
RimGridCrossPlotCurve* curve = new RimGridCrossPlotCurve(); RimGridCrossPlotCurve* curve = new RimGridCrossPlotCurve();
QString timeStepName = QString::number(sampleCategory.first); QString categoryName;
if (sampleCategory.first < timeStepNames.size()) if (m_categorization() == TIME_CATEGORIZATION)
{ {
timeStepName = timeStepNames[sampleCategory.first];
}
bool staticResultsOnly = staticResultsOnly = m_xAxisProperty->hasStaticResult() && m_yAxisProperty->hasStaticResult(); bool staticResultsOnly = staticResultsOnly = m_xAxisProperty->hasStaticResult() && m_yAxisProperty->hasStaticResult();
if (staticResultsOnly) if (!staticResultsOnly && sampleCategory.first < timeStepNames.size())
{
categoryName = timeStepNames[sampleCategory.first];
}
}
else if (m_categorization() == FORMATION_CATEGORIZATION && activeFormationNames)
{
categoryName = activeFormationNames->formationNameFromKLayerIdx(sampleCategory.first);
}
if (categoryName.isEmpty())
{ {
curve->setCustomName(createAutoName()); curve->setCustomName(createAutoName());
} }
else else
{ {
curve->setCustomName(QString("%1 : %2").arg(createAutoName()).arg(timeStepName)); curve->setCustomName(QString("%1 : %2").arg(createAutoName()).arg(categoryName));
} }
curve->determineColorAndSymbol(curveSetIndex, sampleCategory.first, (int) samples.size(), false); curve->determineColorAndSymbol(curveSetIndex, sampleCategory.first, (int)samples.size(), m_categorization() == FORMATION_CATEGORIZATION);
curve->setSamples(sampleCategory.second); curve->setSamples(sampleCategory.second);
curve->updateCurveAppearance(); curve->updateCurveAppearance();
curve->updateCurveNameAndUpdatePlotLegendAndTitle(); curve->updateCurveNameAndUpdatePlotLegendAndTitle();
@ -300,6 +333,8 @@ void RimGridCrossPlotCurveSet::onLoadDataAndUpdate(bool updateParentPlot)
m_crossPlotCurves.push_back(curve); m_crossPlotCurves.push_back(curve);
} }
}
}
if (updateParentPlot) if (updateParentPlot)
{ {
@ -316,6 +351,7 @@ void RimGridCrossPlotCurveSet::defineUiOrdering(QString uiConfigName, caf::PdmUi
if (m_case) if (m_case)
{ {
uiOrdering.add(&m_timeStep); uiOrdering.add(&m_timeStep);
uiOrdering.add(&m_categorization);
caf::PdmUiGroup* xAxisGroup = uiOrdering.addNewGroup("X-Axis Property"); caf::PdmUiGroup* xAxisGroup = uiOrdering.addNewGroup("X-Axis Property");
m_xAxisProperty->uiOrdering(uiConfigName, *xAxisGroup); m_xAxisProperty->uiOrdering(uiConfigName, *xAxisGroup);
@ -352,6 +388,10 @@ void RimGridCrossPlotCurveSet::fieldChangedByUi(const caf::PdmFieldHandle* chang
{ {
loadDataAndUpdate(true); loadDataAndUpdate(true);
} }
else if (changedField == &m_categorization)
{
loadDataAndUpdate(true);
}
else if (changedField == &m_isChecked) else if (changedField == &m_isChecked)
{ {
triggerReplotAndTreeRebuild(); triggerReplotAndTreeRebuild();

View File

@ -20,6 +20,7 @@
#include "RimCheckableNamedObject.h" #include "RimCheckableNamedObject.h"
#include "RimNameConfig.h" #include "RimNameConfig.h"
#include "cafAppEnum.h"
#include "cafPdmChildArrayField.h" #include "cafPdmChildArrayField.h"
#include "cafPdmChildField.h" #include "cafPdmChildField.h"
#include "cafPdmField.h" #include "cafPdmField.h"
@ -55,6 +56,15 @@ class RimGridCrossPlotCurveSet : public RimCheckableNamedObject, public RimNameC
{ {
CAF_PDM_HEADER_INIT; CAF_PDM_HEADER_INIT;
public:
enum CurveCategorization
{
NO_CATEGORIZATION,
TIME_CATEGORIZATION,
FORMATION_CATEGORIZATION
};
typedef caf::AppEnum<CurveCategorization> CurveCategorizationEnum;
public: public:
RimGridCrossPlotCurveSet(); RimGridCrossPlotCurveSet();
~RimGridCrossPlotCurveSet() = default; ~RimGridCrossPlotCurveSet() = default;
@ -84,6 +94,7 @@ private:
caf::PdmPtrField<RimCase*> m_case; caf::PdmPtrField<RimCase*> m_case;
caf::PdmField<int> m_timeStep; caf::PdmField<int> m_timeStep;
caf::PdmField<CurveCategorizationEnum> m_categorization;
caf::PdmChildField<RimEclipseResultDefinition*> m_xAxisProperty; caf::PdmChildField<RimEclipseResultDefinition*> m_xAxisProperty;
caf::PdmChildField<RimEclipseResultDefinition*> m_yAxisProperty; caf::PdmChildField<RimEclipseResultDefinition*> m_yAxisProperty;