Performance: Recompute legend only when required

This commit is contained in:
Magne Sjaastad 2013-09-30 13:29:29 +02:00
parent 15eab9b261
commit e02d2f2300
2 changed files with 72 additions and 17 deletions

View File

@ -416,13 +416,45 @@ void RimLegendConfig::updateLegend()
//--------------------------------------------------------------------------------------------------
void RimLegendConfig::setAutomaticRanges(double globalMin, double globalMax, double localMin, double localMax)
{
m_globalAutoMin = roundToNumSignificantDigits(globalMin, m_precision);
m_globalAutoMax = roundToNumSignificantDigits(globalMax, m_precision);
double candidateGlobalAutoMin = roundToNumSignificantDigits(globalMin, m_precision);
double candidateGlobalAutoMax = roundToNumSignificantDigits(globalMax, m_precision);
m_localAutoMin = roundToNumSignificantDigits(localMin, m_precision);
m_localAutoMax = roundToNumSignificantDigits(localMax, m_precision);
double candidateLocalAutoMin = roundToNumSignificantDigits(localMin, m_precision);
double candidateLocalAutoMax = roundToNumSignificantDigits(localMax, m_precision);
updateLegend();
bool needsUpdate = false;
const double epsilon = std::numeric_limits<double>::epsilon();
if (cvf::Math::abs(candidateGlobalAutoMax - m_globalAutoMax) > epsilon)
{
needsUpdate = true;
}
if (cvf::Math::abs(candidateGlobalAutoMin - m_globalAutoMin) > epsilon)
{
needsUpdate = true;
}
if (cvf::Math::abs(candidateLocalAutoMax - m_localAutoMax) > epsilon)
{
needsUpdate = true;
}
if (cvf::Math::abs(candidateLocalAutoMin - m_localAutoMin) > epsilon)
{
needsUpdate = true;
}
if (needsUpdate)
{
m_globalAutoMin = candidateGlobalAutoMin;
m_globalAutoMax = candidateGlobalAutoMax;
m_localAutoMin = candidateLocalAutoMin;
m_localAutoMax = candidateLocalAutoMax;
updateLegend();
}
}
//--------------------------------------------------------------------------------------------------
@ -562,17 +594,40 @@ double RimLegendConfig::roundToNumSignificantDigits(double domainValue, double n
//--------------------------------------------------------------------------------------------------
void RimLegendConfig::setClosestToZeroValues(double globalPosClosestToZero, double globalNegClosestToZero, double localPosClosestToZero, double localNegClosestToZero)
{
m_globalAutoPosClosestToZero = globalPosClosestToZero;
m_globalAutoNegClosestToZero = globalNegClosestToZero;
m_localAutoPosClosestToZero = localPosClosestToZero;
m_localAutoNegClosestToZero = localNegClosestToZero;
bool needsUpdate = false;
const double epsilon = std::numeric_limits<double>::epsilon();
if (m_globalAutoPosClosestToZero == HUGE_VAL) m_globalAutoPosClosestToZero = 0;
if (m_globalAutoNegClosestToZero == -HUGE_VAL) m_globalAutoNegClosestToZero = 0;
if (m_localAutoPosClosestToZero == HUGE_VAL) m_localAutoPosClosestToZero = 0;
if (m_localAutoNegClosestToZero == -HUGE_VAL) m_localAutoNegClosestToZero = 0;
if (cvf::Math::abs(globalPosClosestToZero - m_globalAutoPosClosestToZero) > epsilon)
{
needsUpdate = true;
}
if (cvf::Math::abs(globalNegClosestToZero - m_globalAutoNegClosestToZero) > epsilon)
{
needsUpdate = true;
}
if (cvf::Math::abs(localPosClosestToZero - m_localAutoPosClosestToZero) > epsilon)
{
needsUpdate = true;
}
if (cvf::Math::abs(localNegClosestToZero - m_localAutoNegClosestToZero) > epsilon)
{
needsUpdate = true;
}
updateLegend();
if (needsUpdate)
{
m_globalAutoPosClosestToZero = globalPosClosestToZero;
m_globalAutoNegClosestToZero = globalNegClosestToZero;
m_localAutoPosClosestToZero = localPosClosestToZero;
m_localAutoNegClosestToZero = localNegClosestToZero;
if (m_globalAutoPosClosestToZero == HUGE_VAL) m_globalAutoPosClosestToZero = 0;
if (m_globalAutoNegClosestToZero == -HUGE_VAL) m_globalAutoNegClosestToZero = 0;
if (m_localAutoPosClosestToZero == HUGE_VAL) m_localAutoPosClosestToZero = 0;
if (m_localAutoNegClosestToZero == -HUGE_VAL) m_localAutoNegClosestToZero = 0;
updateLegend();
}
}
//--------------------------------------------------------------------------------------------------

View File

@ -92,14 +92,14 @@ public:
void setPosition(cvf::Vec2ui position);
cvf::ScalarMapper* scalarMapper() { return m_currentScalarMapper.p(); }
cvf::OverlayScalarMapperLegend* legend() { return m_legend.p(); }
void updateLegend();
cvf::OverlayScalarMapperLegend* legend() { return m_legend.p(); }
protected:
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
virtual void initAfterRead();
virtual void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering );
private:
void updateLegend();
void updateFieldVisibility();
cvf::ref<cvf::Color3ubArray> interpolateColorArray(const cvf::Color3ubArray& colorArray, cvf::uint targetColorCount);
double roundToNumSignificantDigits(double value, double precision);
@ -115,7 +115,7 @@ private:
cvf::ref<cvf::ScalarMapperContinuousLinear> m_linSmoothScalarMapper;
cvf::ref<cvf::ScalarMapper> m_currentScalarMapper;
cvf::ref<cvf::OverlayScalarMapperLegend> m_legend;
cvf::ref<cvf::OverlayScalarMapperLegend> m_legend;
double m_globalAutoMax;
double m_globalAutoMin;