From 9a7f18776545b7c377604db4ab3dcd8007ddc418 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 15 Feb 2017 13:26:59 +0100 Subject: [PATCH] #1222 Interpolate category colors and assign well color based on sorted order --- .../ProjectDataModel/RimEclipseView.cpp | 10 ++-- .../RimEclipseWellCollection.cpp | 19 ++------ Fwk/AppFwk/CommonCode/cafColorTable.cpp | 46 +++++++++++++++++++ Fwk/AppFwk/CommonCode/cafColorTable.h | 4 +- 4 files changed, 59 insertions(+), 20 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp index ffb9c3310f..b9c79c4a06 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp @@ -1125,14 +1125,16 @@ void RimEclipseView::syncronizeWellsWithResults() // Set the new wells into the field. this->wellCollection()->wells().insert(0, newWells); + // Make sure all the wells have their reservoirView ptr setup correctly + this->wellCollection()->setReservoirView(this); + + // Sort wells before assigning colors, as the colors are distributed based on sorting + this->wellCollection()->sortWellsByName(); + if (isAnyWellCreated) { this->wellCollection()->assignDefaultWellColors(); } - - // Make sure all the wells have their reservoirView ptr setup correctly - this->wellCollection()->setReservoirView(this); - this->wellCollection()->sortWellsByName(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimEclipseWellCollection.cpp b/ApplicationCode/ProjectDataModel/RimEclipseWellCollection.cpp index 1fe54e09d2..ebf2ec66cc 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseWellCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseWellCollection.cpp @@ -25,7 +25,6 @@ #include "RiaPreferences.h" #include "RigEclipseCaseData.h" -#include "RigSingleWellResultsData.h" #include "RimEclipseCase.h" #include "RimEclipseView.h" @@ -453,24 +452,16 @@ void RimEclipseWellCollection::fieldChangedByUi(const caf::PdmFieldHandle* chang //-------------------------------------------------------------------------------------------------- void RimEclipseWellCollection::assignDefaultWellColors() { - // The wells are sorted, use ordering of single well results data to assign colors - - RimEclipseCase* rimEclipseCase = nullptr; - this->firstAncestorOrThisOfType(rimEclipseCase); - if (!rimEclipseCase) return; - - if (!rimEclipseCase->reservoirData()) return; - - cvf::Collection wellResults = rimEclipseCase->reservoirData()->wellResults(); - const caf::ColorTable& colorTable = RiaColorTables::wellsPaletteColors(); + cvf::Color3ubArray catColors = colorTable.color3ubArray(); + cvf::Color3ubArray interpolatedCatColors = caf::ColorTable::interpolateColorArray(catColors, wells.size()); - for (size_t wIdx = 0; wIdx < wellResults.size(); ++wIdx) + for (size_t wIdx = 0; wIdx < wells.size(); ++wIdx) { - RimEclipseWell* well = this->findWell(wellResults[wIdx]->m_wellName); + RimEclipseWell* well = wells[wIdx]; if (well) { - cvf::Color3f col = colorTable.cycledColor3f(wIdx); + cvf::Color3f col = cvf::Color3f(interpolatedCatColors[wIdx]); well->wellPipeColor = col; well->updateConnectedEditors(); diff --git a/Fwk/AppFwk/CommonCode/cafColorTable.cpp b/Fwk/AppFwk/CommonCode/cafColorTable.cpp index 44d06f6c33..c75389a825 100644 --- a/Fwk/AppFwk/CommonCode/cafColorTable.cpp +++ b/Fwk/AppFwk/CommonCode/cafColorTable.cpp @@ -112,4 +112,50 @@ cvf::Color3ub ColorTable::fromQColor(const QColor& color) return cvf::Color3ub(color.red(), color.green(), color.blue()); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Color3ubArray ColorTable::interpolateColorArray(const cvf::Color3ubArray& colorArray, size_t targetColorCount) +{ + size_t inputColorCount = colorArray.size(); + CVF_ASSERT(inputColorCount > 1); + CVF_ASSERT(targetColorCount > 1); + + cvf::Color3ubArray colors; + colors.reserve(targetColorCount); + + const size_t inputColorsMaxIdx = inputColorCount - 1; + const size_t outputColorsMaxIdx = targetColorCount - 1; + + for (size_t outputLevelIdx = 0; outputLevelIdx < outputColorsMaxIdx; outputLevelIdx++) + { + double dblInputLevelIndex = inputColorsMaxIdx * (outputLevelIdx / static_cast(outputColorsMaxIdx)); + + const size_t inputLevelIndex = static_cast(dblInputLevelIndex); + CVF_ASSERT(inputLevelIndex < inputColorsMaxIdx); + + double t = dblInputLevelIndex - inputLevelIndex; + CVF_ASSERT(t >= 0 && t <= 1.0); + + cvf::Color3ub c1 = colorArray[inputLevelIndex]; + cvf::Color3ub c2 = colorArray[inputLevelIndex + 1]; + + int r = static_cast(c1.r() + t*(c2.r() - c1.r()) + 0.5); + int g = static_cast(c1.g() + t*(c2.g() - c1.g()) + 0.5); + int b = static_cast(c1.b() + t*(c2.b() - c1.b()) + 0.5); + + r = cvf::Math::clamp(r, 0, 255); + g = cvf::Math::clamp(g, 0, 255); + b = cvf::Math::clamp(b, 0, 255); + + cvf::Color3ub col((cvf::ubyte)r, (cvf::ubyte)g, (cvf::ubyte)b); + colors.add(col); + } + + colors.add(colorArray[colorArray.size() - 1]); + + return colors; + +} + } // namespace caf diff --git a/Fwk/AppFwk/CommonCode/cafColorTable.h b/Fwk/AppFwk/CommonCode/cafColorTable.h index f1391cb8e3..21720f189e 100644 --- a/Fwk/AppFwk/CommonCode/cafColorTable.h +++ b/Fwk/AppFwk/CommonCode/cafColorTable.h @@ -65,8 +65,8 @@ public: cvf::Color3ubArray color3ubArray() const; cvf::Color3fArray color3fArray() const; - static cvf::Color3ub fromQColor(const QColor& color); - + static cvf::Color3ub fromQColor(const QColor& color); + static cvf::Color3ubArray interpolateColorArray(const cvf::Color3ubArray& colorArray, size_t targetColorCount); private: const std::vector m_colors; };