#1222 Interpolate category colors and assign well color based on sorted order

This commit is contained in:
Magne Sjaastad 2017-02-15 13:26:59 +01:00
parent 4fc0839a33
commit 9a7f187765
4 changed files with 59 additions and 20 deletions

View File

@ -1125,14 +1125,16 @@ void RimEclipseView::syncronizeWellsWithResults()
// Set the new wells into the field. // Set the new wells into the field.
this->wellCollection()->wells().insert(0, newWells); 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) if (isAnyWellCreated)
{ {
this->wellCollection()->assignDefaultWellColors(); this->wellCollection()->assignDefaultWellColors();
} }
// Make sure all the wells have their reservoirView ptr setup correctly
this->wellCollection()->setReservoirView(this);
this->wellCollection()->sortWellsByName();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -25,7 +25,6 @@
#include "RiaPreferences.h" #include "RiaPreferences.h"
#include "RigEclipseCaseData.h" #include "RigEclipseCaseData.h"
#include "RigSingleWellResultsData.h"
#include "RimEclipseCase.h" #include "RimEclipseCase.h"
#include "RimEclipseView.h" #include "RimEclipseView.h"
@ -453,24 +452,16 @@ void RimEclipseWellCollection::fieldChangedByUi(const caf::PdmFieldHandle* chang
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimEclipseWellCollection::assignDefaultWellColors() 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<RigSingleWellResultsData> wellResults = rimEclipseCase->reservoirData()->wellResults();
const caf::ColorTable& colorTable = RiaColorTables::wellsPaletteColors(); 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) if (well)
{ {
cvf::Color3f col = colorTable.cycledColor3f(wIdx); cvf::Color3f col = cvf::Color3f(interpolatedCatColors[wIdx]);
well->wellPipeColor = col; well->wellPipeColor = col;
well->updateConnectedEditors(); well->updateConnectedEditors();

View File

@ -112,4 +112,50 @@ cvf::Color3ub ColorTable::fromQColor(const QColor& color)
return cvf::Color3ub(color.red(), color.green(), color.blue()); 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<double>(outputColorsMaxIdx));
const size_t inputLevelIndex = static_cast<size_t>(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<int>(c1.r() + t*(c2.r() - c1.r()) + 0.5);
int g = static_cast<int>(c1.g() + t*(c2.g() - c1.g()) + 0.5);
int b = static_cast<int>(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 } // namespace caf

View File

@ -65,8 +65,8 @@ public:
cvf::Color3ubArray color3ubArray() const; cvf::Color3ubArray color3ubArray() const;
cvf::Color3fArray color3fArray() 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: private:
const std::vector<cvf::Color3ub> m_colors; const std::vector<cvf::Color3ub> m_colors;
}; };