From f1c214c1d7e4ba05f123861e7c2db21328948816 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 7 Sep 2016 10:28:57 +0200 Subject: [PATCH] (#829) Use std::vector instead of std::set for categories. Added categoryNames to RimLegendConfig --- .../RimEclipsePropertyFilter.cpp | 7 +--- .../ProjectDataModel/RimEclipseView.cpp | 39 ++++++++++-------- .../ProjectDataModel/RimGeoMechView.cpp | 14 ++++--- .../ProjectDataModel/RimLegendConfig.cpp | 29 ++++++------- .../ProjectDataModel/RimLegendConfig.h | 7 ++-- .../RigCaseCellResultsData.cpp | 10 +---- .../RigCaseCellResultsData.h | 3 +- .../RigStatisticsDataCache.cpp | 41 ++++--------------- .../RigStatisticsDataCache.h | 10 ++--- 9 files changed, 65 insertions(+), 95 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimEclipsePropertyFilter.cpp b/ApplicationCode/ProjectDataModel/RimEclipsePropertyFilter.cpp index 9cb274e5aa..3f29a43368 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipsePropertyFilter.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipsePropertyFilter.cpp @@ -361,12 +361,7 @@ void RimEclipsePropertyFilter::computeResultValueRange() if (resultDefinition->hasCategoryResult()) { - std::set vals = results->cellResults()->uniqueCellScalarValues(scalarIndex); - - for (auto val : vals) - { - m_uniqueCellValues.push_back(val); - } + m_uniqueCellValues = results->cellResults()->uniqueCellScalarValues(scalarIndex); } } } diff --git a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp index f41f2bbf2d..f373e9ea80 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp @@ -948,16 +948,20 @@ void RimEclipseView::updateLegends() { if(cellEdgeResult()->singleVarEdgeResultColors()->resultType() != RimDefines::FORMATION_NAMES) { - cellEdgeResult()->legendConfig()->setCategories(results->uniqueCellScalarValues(cellEdgeResult()->singleVarEdgeResultColors()->scalarResultIndex()), - results->uniqueCellScalarValues(cellEdgeResult()->singleVarEdgeResultColors()->scalarResultIndex(), 0)); + cellEdgeResult()->legendConfig()->setCategories(results->uniqueCellScalarValues(cellEdgeResult()->singleVarEdgeResultColors()->scalarResultIndex())); } else { - const std::vector& fnVector = - eclipseCase->activeFormationNames()->formationNames(); - std::set nameIndices; - for(int i = 0; i < fnVector.size(); ++i) nameIndices.insert(i); - cellEdgeResult()->legendConfig()->setCategories(nameIndices, nameIndices); + const std::vector& fnVector = eclipseCase->activeFormationNames()->formationNames(); + std::vector nameIndices; + std::vector names; + for (int i = 0; i < fnVector.size(); ++i) + { + nameIndices.push_back(i); + names.push_back(cvfqt::Utils::toString(fnVector[i])); + } + + cellEdgeResult()->legendConfig()->setCategoriesWithNames(nameIndices, names); } } @@ -1006,21 +1010,22 @@ void RimEclipseView::updateMinMaxValuesAndAddLegendToView(QString legendLabel, R if (resultColors->hasCategoryResult()) { - size_t adjustedTimeStep = m_currentTimeStep; - if (resultColors->hasStaticResult()) adjustedTimeStep = 0; - if(resultColors->resultType() != RimDefines::FORMATION_NAMES) { - resultColors->legendConfig()->setCategories(cellResultsData->uniqueCellScalarValues(resultColors->scalarResultIndex()), - cellResultsData->uniqueCellScalarValues(resultColors->scalarResultIndex(), adjustedTimeStep)); + resultColors->legendConfig()->setCategories(cellResultsData->uniqueCellScalarValues(resultColors->scalarResultIndex())); } else { - const std::vector& fnVector = - eclipseCase()->reservoirData()->activeFormationNames()->formationNames(); - std::set nameIndices; - for(int i = 0; i < fnVector.size(); ++i) nameIndices.insert(i); - resultColors->legendConfig()->setCategories(nameIndices, nameIndices); + const std::vector& fnVector = eclipseCase()->reservoirData()->activeFormationNames()->formationNames(); + std::vector nameIndices; + std::vector names; + for (int i = 0; i < fnVector.size(); ++i) + { + nameIndices.push_back(i); + names.push_back(cvfqt::Utils::toString(fnVector[i])); + } + + resultColors->legendConfig()->setCategoriesWithNames(nameIndices, names); } } diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp b/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp index 8e95e6f028..2c5d0d2dae 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp +++ b/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp @@ -422,12 +422,16 @@ void RimGeoMechView::updateLegends() if (cellResult()->hasCategoryResult()) { - const std::vector& fnVector = - gmCase->femPartResults()->activeFormationNames()->formationNames(); - std::set nameIndices; - for (int i = 0; i < fnVector.size(); ++i) nameIndices.insert(i); + const std::vector& fnVector = gmCase->femPartResults()->activeFormationNames()->formationNames(); + std::vector nameIndices; + std::vector names; + for (int i = 0; i < fnVector.size(); ++i) + { + nameIndices.push_back(i); + names.push_back(cvfqt::Utils::toString(fnVector[i])); + } - cellResult()->legendConfig->setCategories(nameIndices, nameIndices); + cellResult()->legendConfig->setCategoriesWithNames(nameIndices, names); } m_viewer->addColorLegendToBottomLeftCorner(cellResult()->legendConfig->legend()); diff --git a/ApplicationCode/ProjectDataModel/RimLegendConfig.cpp b/ApplicationCode/ProjectDataModel/RimLegendConfig.cpp index 9e11592fc4..8734ad2707 100644 --- a/ApplicationCode/ProjectDataModel/RimLegendConfig.cpp +++ b/ApplicationCode/ProjectDataModel/RimLegendConfig.cpp @@ -201,8 +201,6 @@ void RimLegendConfig::updateLegend() posClosestToZero = m_globalAutoPosClosestToZero; negClosestToZero = m_globalAutoNegClosestToZero; - - m_categoryMapper->setCategories(m_globalCategories); } else if (m_rangeMode == AUTOMATIC_CURRENT_TIMESTEP) { @@ -211,8 +209,6 @@ void RimLegendConfig::updateLegend() posClosestToZero = m_localAutoPosClosestToZero; negClosestToZero = m_localAutoNegClosestToZero; - - m_categoryMapper->setCategories(m_localCategories); } else { @@ -381,7 +377,6 @@ void RimLegendConfig::updateLegend() m_logSmoothScalarMapper->setColors(legendColors); m_linSmoothScalarMapper->setColors(legendColors); - m_categoryMapper->setCycleColors(legendColors); m_linDiscreteScalarMapper->setLevelCount(m_numLevels, true); m_logDiscreteScalarMapper->setLevelCount(m_numLevels, true); @@ -403,6 +398,8 @@ void RimLegendConfig::updateLegend() m_currentScalarMapper = m_logDiscreteScalarMapper.p(); break; case CATEGORY_INTEGER: + m_categoryMapper->setCategoriesWithNames(m_categories, m_categoryNames); + m_categoryMapper->setCycleColors(legendColors); m_currentScalarMapper = m_categoryMapper.p(); break; default: @@ -694,17 +691,21 @@ void RimLegendConfig::setClosestToZeroValues(double globalPosClosestToZero, doub //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimLegendConfig::setCategories(const std::set& globalCategories, const std::set& localCategories) +void RimLegendConfig::setCategories(const std::vector& categories) { - for (auto val : globalCategories) - { - m_globalCategories.push_back(val); - } + m_categories = categories; + m_categoryNames.clear(); - for (auto val : localCategories) - { - m_localCategories.push_back(val); - } + updateLegend(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimLegendConfig::setCategoriesWithNames(const std::vector& categories, const std::vector& categoryNames) +{ + m_categories = categories; + m_categoryNames = categoryNames; updateLegend(); } diff --git a/ApplicationCode/ProjectDataModel/RimLegendConfig.h b/ApplicationCode/ProjectDataModel/RimLegendConfig.h index 47be6a39ff..832b698d01 100644 --- a/ApplicationCode/ProjectDataModel/RimLegendConfig.h +++ b/ApplicationCode/ProjectDataModel/RimLegendConfig.h @@ -105,7 +105,8 @@ public: 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& globalCategories, const std::set& localCategories); + void setCategories(const std::vector& categories); + void setCategoriesWithNames(const std::vector& categories, const std::vector& categoryNames); void setTitle(const cvf::String& title); @@ -149,8 +150,8 @@ private: double m_localAutoPosClosestToZero; double m_localAutoNegClosestToZero; - std::vector m_globalCategories; - std::vector m_localCategories; + std::vector m_categories; + std::vector m_categoryNames; // Fields caf::PdmField m_numLevels; diff --git a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp index 46cca0323f..e3555362ae 100644 --- a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp @@ -130,19 +130,11 @@ void RigCaseCellResultsData::meanCellScalarValues(size_t scalarResultIndex, size //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -const std::set& RigCaseCellResultsData::uniqueCellScalarValues(size_t scalarResultIndex) +const std::vector& RigCaseCellResultsData::uniqueCellScalarValues(size_t scalarResultIndex) { return m_statisticsDataCache[scalarResultIndex]->uniqueCellScalarValues(); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -const std::set& RigCaseCellResultsData::uniqueCellScalarValues(size_t scalarResultIndex, size_t timeStepIndex) -{ - return m_statisticsDataCache[scalarResultIndex]->uniqueCellScalarValues(timeStepIndex); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.h b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.h index 0c3b14cc5c..3d421c59b3 100644 --- a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.h +++ b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.h @@ -59,8 +59,7 @@ public: void p10p90CellScalarValues(size_t scalarResultIndex, size_t timeStepIndex, double& p10, double& p90); void meanCellScalarValues(size_t scalarResultIndex, double& meanValue); void meanCellScalarValues(size_t scalarResultIndex, size_t timeStepIndex, double& meanValue); - const std::set& uniqueCellScalarValues(size_t scalarResultIndex); - const std::set& uniqueCellScalarValues(size_t scalarResultIndex, size_t timeStepIndex); + const std::vector& uniqueCellScalarValues(size_t scalarResultIndex); void sumCellScalarValues(size_t scalarResultIndex, double& sumValue); void sumCellScalarValues(size_t scalarResultIndex, size_t timeStepIndex, double& sumValue); diff --git a/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.cpp b/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.cpp index 73e3dc8139..73cf73a540 100644 --- a/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.cpp +++ b/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.cpp @@ -258,21 +258,11 @@ const std::vector& RigStatisticsDataCache::cellScalarValuesHistogram(siz //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -const std::set& RigStatisticsDataCache::uniqueCellScalarValues() +const std::vector& RigStatisticsDataCache::uniqueCellScalarValues() { computeUniqueValuesIfNeeded(); - return m_statsAllTimesteps.m_uniqueValues; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -const std::set& RigStatisticsDataCache::uniqueCellScalarValues(size_t timeStepIndex) -{ - computeUniqueValuesIfNeeded(timeStepIndex); - - return m_statsPrTs[timeStepIndex].m_uniqueValues; + return m_uniqueValues; } //-------------------------------------------------------------------------------------------------- @@ -339,34 +329,19 @@ void RigStatisticsDataCache::computeHistogramStatisticsIfNeeded(size_t timeStepI } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigStatisticsDataCache::computeUniqueValuesIfNeeded(size_t timeStepIndex) -{ - if (timeStepIndex >= m_statsPrTs.size()) - { - m_statsPrTs.resize(timeStepIndex + 1); - } - - if (m_statsPrTs[timeStepIndex].m_uniqueValues.size() == 0) - { - m_statisticsCalculator->uniqueValues(timeStepIndex, m_statsPrTs[timeStepIndex].m_uniqueValues); - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RigStatisticsDataCache::computeUniqueValuesIfNeeded() { - if (m_statsAllTimesteps.m_uniqueValues.size() == 0) + if (m_uniqueValues.size() == 0) { - for (size_t tIdx = 0; tIdx < m_statisticsCalculator->timeStepCount(); tIdx++) - { - computeUniqueValuesIfNeeded(tIdx); + std::set setValues; + m_statisticsCalculator->uniqueValues(0, setValues); - m_statsAllTimesteps.m_uniqueValues.insert(m_statsPrTs[tIdx].m_uniqueValues.begin(), m_statsPrTs[tIdx].m_uniqueValues.end()); + for (auto val : setValues) + { + m_uniqueValues.push_back(val); } } } diff --git a/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.h b/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.h index 7167dfe13b..e35a60f578 100644 --- a/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.h +++ b/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.h @@ -55,15 +55,13 @@ public: const std::vector& cellScalarValuesHistogram(); const std::vector& cellScalarValuesHistogram(size_t timeStepIndex); - const std::set& uniqueCellScalarValues(); - const std::set& uniqueCellScalarValues(size_t timeStepIndex); + const std::vector& uniqueCellScalarValues(); private: void computeHistogramStatisticsIfNeeded(); void computeHistogramStatisticsIfNeeded(size_t timeStepIndex); void computeUniqueValuesIfNeeded(); - void computeUniqueValuesIfNeeded(size_t timeStepIndex); private: struct StatisticsValues @@ -102,11 +100,11 @@ private: bool m_isValueSumCalculated; std::vector m_histogram; - std::set m_uniqueValues; }; - StatisticsValues m_statsAllTimesteps; - std::vector m_statsPrTs; + StatisticsValues m_statsAllTimesteps; + std::vector m_statsPrTs; + std::vector m_uniqueValues; cvf::ref m_statisticsCalculator; };