mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Discrete legend: Fix of discrete texture and end colors
Added changes from ChList 2078-2081
This commit is contained in:
parent
8c12c8bcf7
commit
7a2640b52f
@ -375,16 +375,16 @@ ref<Color3ubArray> ScalarMapper::interpolateColorArray(const Color3ubArray& colo
|
|||||||
ref<Color3ubArray> colors = new Color3ubArray;
|
ref<Color3ubArray> colors = new Color3ubArray;
|
||||||
colors->reserve(targetColorCount);
|
colors->reserve(targetColorCount);
|
||||||
|
|
||||||
const uint inputLevelCount = inputColorCount - 1;
|
const uint inputColorsMaxIdx = inputColorCount - 1;
|
||||||
const uint outputLevelCount = targetColorCount - 1;
|
const uint outputColorsMaxIdx = targetColorCount - 1;
|
||||||
|
|
||||||
uint outputLevelIdx;
|
uint outputLevelIdx;
|
||||||
for (outputLevelIdx = 0; outputLevelIdx < outputLevelCount; outputLevelIdx++)
|
for (outputLevelIdx = 0; outputLevelIdx < outputColorsMaxIdx; outputLevelIdx++)
|
||||||
{
|
{
|
||||||
double dblInputLevelIndex = inputLevelCount * (outputLevelIdx / static_cast<double>(outputLevelCount));
|
double dblInputLevelIndex = inputColorsMaxIdx * (outputLevelIdx / static_cast<double>(outputColorsMaxIdx));
|
||||||
|
|
||||||
const uint inputLevelIndex = static_cast<uint>(dblInputLevelIndex);
|
const uint inputLevelIndex = static_cast<uint>(dblInputLevelIndex);
|
||||||
CVF_ASSERT(inputLevelIndex < inputLevelCount);
|
CVF_ASSERT(inputLevelIndex < inputColorsMaxIdx);
|
||||||
|
|
||||||
double t = dblInputLevelIndex - inputLevelIndex;
|
double t = dblInputLevelIndex - inputLevelIndex;
|
||||||
CVF_ASSERT(t >= 0 && t <= 1.0);
|
CVF_ASSERT(t >= 0 && t <= 1.0);
|
||||||
|
@ -54,38 +54,37 @@ ScalarMapperDiscreteLinear::ScalarMapperDiscreteLinear()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
Vec2f ScalarMapperDiscreteLinear::mapToTextureCoord(double scalarValue) const
|
|
||||||
{
|
|
||||||
double discVal = discretize(scalarValue, m_sortedLevels);
|
|
||||||
return ScalarMapperRangeBased::mapToTextureCoord(discVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
Color3ub ScalarMapperDiscreteLinear::mapToColor(double scalarValue) const
|
Color3ub ScalarMapperDiscreteLinear::mapToColor(double scalarValue) const
|
||||||
{
|
{
|
||||||
double discVal = discretize(scalarValue, m_sortedLevels);
|
double discVal = ScalarMapperDiscreteLinear::discretizeToLevelBelow(scalarValue, m_sortedLevels);
|
||||||
return ScalarMapperRangeBased::mapToColor(discVal);
|
std::set<double>::reverse_iterator it = m_sortedLevels.rbegin();
|
||||||
|
it++;
|
||||||
|
double levelUnderMax = *it;
|
||||||
|
double normDiscVal = normalizedValue(discVal);
|
||||||
|
double normSemiMaxVal = normalizedValue(levelUnderMax);
|
||||||
|
double adjustedNormVal = 0;
|
||||||
|
if (normSemiMaxVal != 0) adjustedNormVal = cvf::Math::clamp(normDiscVal/normSemiMaxVal, 0.0, 1.0);
|
||||||
|
|
||||||
|
return colorFromUserColorGradient(adjustedNormVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
double ScalarMapperDiscreteLinear::discretize(double scalarValue, const std::set<double>& sortedLevels)
|
double ScalarMapperDiscreteLinear::discretizeToLevelBelow(double scalarValue, const std::set<double>& sortedLevels)
|
||||||
{
|
{
|
||||||
std::set<double>::iterator it;
|
std::set<double>::iterator it;
|
||||||
|
|
||||||
it = sortedLevels.upper_bound(scalarValue);
|
it = sortedLevels.upper_bound(scalarValue);
|
||||||
if (it == sortedLevels.begin()) return (*it);
|
if (it == sortedLevels.begin()) return (*it);
|
||||||
if (it == sortedLevels.end()) return (*sortedLevels.rbegin());
|
if (it == sortedLevels.end()) return (*sortedLevels.rbegin());
|
||||||
double upperValue = *it;
|
|
||||||
it--;
|
it--;
|
||||||
double lowerValue = *it;
|
double lowerValue = *it;
|
||||||
return 0.5 * (upperValue + lowerValue);
|
|
||||||
|
return lowerValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -55,13 +55,12 @@ public:
|
|||||||
|
|
||||||
// Scalarmapper interface implementation
|
// Scalarmapper interface implementation
|
||||||
|
|
||||||
virtual Vec2f mapToTextureCoord(double scalarValue) const;
|
|
||||||
virtual Color3ub mapToColor(double scalarValue) const;
|
virtual Color3ub mapToColor(double scalarValue) const;
|
||||||
virtual double normalizedValue( double domainValue ) const;
|
virtual double normalizedValue( double domainValue ) const;
|
||||||
virtual double domainValue( double normalizedPosition ) const;
|
virtual double domainValue( double normalizedPosition ) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static double discretize(double scalarValue, const std::set<double>& sortedLevels);
|
static double discretizeToLevelBelow(double scalarValue, const std::set<double>& sortedLevels);
|
||||||
friend class ScalarMapperDiscreteLog;
|
friend class ScalarMapperDiscreteLog;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -58,24 +58,25 @@ ScalarMapperDiscreteLog::ScalarMapperDiscreteLog()
|
|||||||
m_decadeLevelCount = 2;
|
m_decadeLevelCount = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
Vec2f ScalarMapperDiscreteLog::mapToTextureCoord(double scalarValue) const
|
|
||||||
{
|
|
||||||
double discVal = ScalarMapperDiscreteLinear::discretize(scalarValue, m_sortedLevels);
|
|
||||||
return ScalarMapperRangeBased::mapToTextureCoord(discVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
Color3ub ScalarMapperDiscreteLog::mapToColor(double scalarValue) const
|
Color3ub ScalarMapperDiscreteLog::mapToColor(double scalarValue) const
|
||||||
{
|
{
|
||||||
double discVal = ScalarMapperDiscreteLinear::discretize(scalarValue, m_sortedLevels);
|
double discVal = ScalarMapperDiscreteLinear::discretizeToLevelBelow(scalarValue, m_sortedLevels);
|
||||||
return ScalarMapperRangeBased::mapToColor(discVal);
|
std::set<double>::reverse_iterator it = m_sortedLevels.rbegin();
|
||||||
|
it++;
|
||||||
|
double levelUnderMax = *it;
|
||||||
|
double normDiscVal = normalizedValue(discVal);
|
||||||
|
double normSemiMaxVal = normalizedValue(levelUnderMax);
|
||||||
|
double adjustedNormVal = 0;
|
||||||
|
if (normSemiMaxVal != 0) adjustedNormVal = normDiscVal/normSemiMaxVal;
|
||||||
|
|
||||||
|
return colorFromUserColorGradient(adjustedNormVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -53,7 +53,7 @@ public:
|
|||||||
ScalarMapperDiscreteLog();
|
ScalarMapperDiscreteLog();
|
||||||
|
|
||||||
// Implementing the Scalarmapper interface
|
// Implementing the Scalarmapper interface
|
||||||
virtual Vec2f mapToTextureCoord(double scalarValue) const;
|
|
||||||
virtual Color3ub mapToColor(double scalarValue) const;
|
virtual Color3ub mapToColor(double scalarValue) const;
|
||||||
virtual double normalizedValue( double domainValue ) const;
|
virtual double normalizedValue( double domainValue ) const;
|
||||||
virtual double domainValue( double normalizedPosition ) const;
|
virtual double domainValue( double normalizedPosition ) const;
|
||||||
|
@ -58,9 +58,9 @@ ScalarMapperRangeBased::ScalarMapperRangeBased()
|
|||||||
m_textureSize(2048), // Large enough, I guess and a power of two
|
m_textureSize(2048), // Large enough, I guess and a power of two
|
||||||
m_adjustLevels(true)
|
m_adjustLevels(true)
|
||||||
{
|
{
|
||||||
m_colors.resize(m_textureSize);
|
m_interpolatedUserGradientColors.resize(m_textureSize);
|
||||||
m_colors.setAll(Color3ub::WHITE);
|
m_interpolatedUserGradientColors.setAll(Color3ub::WHITE);
|
||||||
setColors(ScalarMapper::NORMAL);
|
setColors(*normalColorTableArray(13));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ void ScalarMapperRangeBased::setRange(double min, double max)
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void ScalarMapperRangeBased::setColors(const Color3ubArray& colorArray)
|
void ScalarMapperRangeBased::setColors(const Color3ubArray& colorArray)
|
||||||
{
|
{
|
||||||
m_colors = *interpolateColorArray(colorArray, m_textureSize);
|
m_interpolatedUserGradientColors = *interpolateColorArray(colorArray, m_textureSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -137,10 +137,7 @@ Vec2f ScalarMapperRangeBased::mapToTextureCoord(double scalarValue) const
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
Color3ub ScalarMapperRangeBased::mapToColor(double scalarValue) const
|
Color3ub ScalarMapperRangeBased::mapToColor(double scalarValue) const
|
||||||
{
|
{
|
||||||
size_t colorIdx = static_cast<size_t>(normalizedValue(scalarValue) * (m_textureSize - 1));
|
return colorFromUserColorGradient(normalizedValue(scalarValue));
|
||||||
|
|
||||||
CVF_TIGHT_ASSERT(colorIdx < m_colors.size());
|
|
||||||
return m_colors[colorIdx];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -170,7 +167,7 @@ bool ScalarMapperRangeBased::updateTexture(TextureImage* image) const
|
|||||||
uint ic;
|
uint ic;
|
||||||
for (ic = 0; ic < m_textureSize; ic++)
|
for (ic = 0; ic < m_textureSize; ic++)
|
||||||
{
|
{
|
||||||
const Color4ub clr(m_colors[ic], 255);
|
const Color4ub clr(mapToColor(domainValue(((double)ic)/(m_textureSize-1))), 255);
|
||||||
image->setPixel(ic, 0, clr);
|
image->setPixel(ic, 0, clr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,5 +276,18 @@ void ScalarMapperRangeBased::majorTickValues( std::vector<double>* domainValues)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
cvf::Color3ub ScalarMapperRangeBased::colorFromUserColorGradient(double normalizedValue) const
|
||||||
|
{
|
||||||
|
CVF_TIGHT_ASSERT(0.0 <= normalizedValue && normalizedValue <= 1.0);
|
||||||
|
|
||||||
|
size_t colorIdx = static_cast<size_t>(normalizedValue * (m_textureSize - 1));
|
||||||
|
|
||||||
|
CVF_TIGHT_ASSERT(colorIdx < m_interpolatedUserGradientColors.size());
|
||||||
|
return m_interpolatedUserGradientColors[colorIdx];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace cvf
|
} // namespace cvf
|
||||||
|
@ -67,6 +67,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void rangeUpdated() {}; //< Called when the range is changed. Subclasses can reimplment to recalculate cached values
|
virtual void rangeUpdated() {}; //< Called when the range is changed. Subclasses can reimplment to recalculate cached values
|
||||||
|
Color3ub colorFromUserColorGradient(double normalizedValue) const;
|
||||||
|
|
||||||
double m_rangeMin;
|
double m_rangeMin;
|
||||||
double m_rangeMax;
|
double m_rangeMax;
|
||||||
@ -81,7 +82,7 @@ private:
|
|||||||
bool m_adjustLevels; //< Toggles wether to round tick positions to nice numbers
|
bool m_adjustLevels; //< Toggles wether to round tick positions to nice numbers
|
||||||
std::set<double> m_userDefinedLevelValues;
|
std::set<double> m_userDefinedLevelValues;
|
||||||
|
|
||||||
Color3ubArray m_colors;
|
Color3ubArray m_interpolatedUserGradientColors; //< Table of smooth interpolated colors as a result of the users color request
|
||||||
uint m_textureSize; // The size of texture that updateTexture() will produce.
|
uint m_textureSize; // The size of texture that updateTexture() will produce.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user