#6517 Fudge the maximimum and minimum contour levels inwards

* Unify with logaritmic contour levels.
* Ensure the labels in the contour map show less precision.

Fudge in the opposite direction and unify with logarithmic
This commit is contained in:
Gaute Lindkvist 2020-09-28 14:22:07 +02:00 committed by Magne Sjaastad
parent f967cfcb65
commit ec40673119
2 changed files with 18 additions and 16 deletions

View File

@ -25,10 +25,12 @@
#include "cvfPrimitiveSetIndexedUInt.h" #include "cvfPrimitiveSetIndexedUInt.h"
#include "cvfRay.h" #include "cvfRay.h"
#include "cvfScalarMapper.h" #include "cvfScalarMapper.h"
#include "cvfqtUtils.h"
#include <cmath> #include <cmath>
#include <QDebug> #include <QDebug>
#include <QString>
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -267,7 +269,9 @@ std::vector<std::vector<cvf::ref<cvf::Drawable>>>
{ {
if ( m_contourLinePolygons[i][j].vertices.empty() ) continue; if ( m_contourLinePolygons[i][j].vertices.empty() ) continue;
cvf::String labelText( m_contourLinePolygons[i][j].value ); // cvf::String::number does not allow precision on 'g' formats, so use Qt.
QString qLabelText = QString::number( m_contourLinePolygons[i][j].value, 'g', 2 );
cvf::String labelText = cvfqt::Utils::toString( qLabelText );
size_t nVertices = m_contourLinePolygons[i][j].vertices.size(); size_t nVertices = m_contourLinePolygons[i][j].vertices.size();
@ -402,7 +406,9 @@ std::vector<cvf::ref<cvf::Drawable>>
{ {
if ( m_contourLinePolygons[i][j].vertices.empty() ) continue; if ( m_contourLinePolygons[i][j].vertices.empty() ) continue;
cvf::String labelText( m_contourLinePolygons[i][j].value ); // cvf::String::number does not allow precision on 'g' formats, so use Qt.
QString qLabelText = QString::number( m_contourLinePolygons[i][j].value, 'g', 2 );
cvf::String labelText = cvfqt::Utils::toString( qLabelText );
size_t nVertices = m_contourLinePolygons[i][j].vertices.size(); size_t nVertices = m_contourLinePolygons[i][j].vertices.size();
size_t nLabels = nVertices; size_t nLabels = nVertices;

View File

@ -976,11 +976,11 @@ void RimContourMapProjection::generateTrianglesWithVertexValues()
std::vector<cvf::Vec3d> clippedTriangle; std::vector<cvf::Vec3d> clippedTriangle;
if ( v == clippedPolygon.size() - 1 ) if ( v == clippedPolygon.size() - 1 )
{ {
clippedTriangle = { clippedPolygon[v], clippedPolygon[0], baryCenter }; clippedTriangle = {clippedPolygon[v], clippedPolygon[0], baryCenter};
} }
else else
{ {
clippedTriangle = { clippedPolygon[v], clippedPolygon[v + 1], baryCenter }; clippedTriangle = {clippedPolygon[v], clippedPolygon[v + 1], baryCenter};
} }
polygonTriangles.push_back( clippedTriangle ); polygonTriangles.push_back( clippedTriangle );
} }
@ -1103,18 +1103,14 @@ void RimContourMapProjection::generateContourPolygons()
{ {
if ( nContourLevels > 2 ) if ( nContourLevels > 2 )
{ {
if ( legendConfig()->mappingMode() == RimRegularLegendConfig::MappingType::LINEAR_DISCRETE || const size_t N = contourLevels.size();
legendConfig()->mappingMode() == RimRegularLegendConfig::MappingType::LINEAR_CONTINUOUS ) // Adjust contour levels slightly to avoid weird visual artifacts due to numerical error.
{ double fudgeFactor = 1.0e-3;
const int fudgeFactor = 0.01; double fudgeAmountMin = fudgeFactor * ( contourLevels[1] - contourLevels[0] );
// Adjust contour levels slightly to avoid weird visual artifacts due to numerical error. double fudgeAmountMax = fudgeFactor * ( contourLevels[N - 1u] - contourLevels[N - 2u] );
contourLevels.front() -= fudgeFactor * ( contourLevels.back() - contourLevels.front() );
contourLevels.back() += fudgeFactor * ( contourLevels.back() - contourLevels.front() ); contourLevels.front() += fudgeAmountMin;
} contourLevels.back() -= fudgeAmountMax;
else
{
contourLevels.front() *= 0.5;
}
double simplifyEpsilon = m_smoothContourLines() ? 5.0e-2 * sampleSpacing() : 1.0e-3 * sampleSpacing(); double simplifyEpsilon = m_smoothContourLines() ? 5.0e-2 * sampleSpacing() : 1.0e-3 * sampleSpacing();