mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-10 07:26:03 -06:00
Make curve drawing more robust (#8537)
* Janitor : Improve robustness * Guard nullptr access * Limit the curve points to incoming from/to curve point index range Co-authored-by: magnesj <magnesj@users.noreply.github.com>
This commit is contained in:
parent
6591de716b
commit
6c92206893
@ -178,6 +178,8 @@ std::vector<std::pair<FloatType, FloatType>>
|
||||
RiaDefines::DepthUnitType unitsIn,
|
||||
RiaDefines::DepthUnitType unitsOut )
|
||||
{
|
||||
if ( depthsIn.empty() ) return {};
|
||||
|
||||
std::vector<std::pair<FloatType, FloatType>> convertedDepths( depthsIn.size() );
|
||||
double factor = 1.0;
|
||||
if ( unitsOut == RiaDefines::DepthUnitType::UNIT_METER && unitsIn == RiaDefines::DepthUnitType::UNIT_FEET )
|
||||
@ -335,6 +337,8 @@ template <typename FloatType>
|
||||
std::vector<FloatType>
|
||||
RiaWellLogUnitTools<FloatType>::tvdRKBs( const std::vector<FloatType>& measuredDepths, const RigWellPath* wellPath )
|
||||
{
|
||||
if ( measuredDepths.empty() ) return {};
|
||||
|
||||
std::vector<double> tvdRKBs( measuredDepths.size(), 0.0 );
|
||||
for ( size_t i = 0; i < measuredDepths.size(); ++i )
|
||||
{
|
||||
@ -351,6 +355,8 @@ template <typename FloatType>
|
||||
std::vector<FloatType> RiaWellLogUnitTools<FloatType>::convertGpcm3ToBar( const std::vector<FloatType>& tvdRKBs,
|
||||
const std::vector<FloatType>& valuesInGpcm3 )
|
||||
{
|
||||
if ( tvdRKBs.empty() ) return {};
|
||||
|
||||
CAF_ASSERT( tvdRKBs.size() == valuesInGpcm3.size() );
|
||||
|
||||
std::vector<FloatType> valuesInBar( valuesInGpcm3.size(), 0.0 );
|
||||
@ -378,6 +384,8 @@ template <typename FloatType>
|
||||
std::vector<FloatType> RiaWellLogUnitTools<FloatType>::convertBarToGpcm3( const std::vector<FloatType>& tvdRKBs,
|
||||
const std::vector<FloatType>& valuesInBar )
|
||||
{
|
||||
if ( tvdRKBs.empty() ) return {};
|
||||
|
||||
CAF_ASSERT( tvdRKBs.size() == valuesInBar.size() );
|
||||
|
||||
std::vector<FloatType> valuesInGpcm3( valuesInBar.size(), 0.0 );
|
||||
@ -406,6 +414,8 @@ std::vector<FloatType>
|
||||
RiaWellLogUnitTools<FloatType>::convertNormalizedByPPToBar( const std::vector<FloatType>& tvdRKBs,
|
||||
const std::vector<FloatType>& normalizedValues )
|
||||
{
|
||||
if ( tvdRKBs.empty() ) return {};
|
||||
|
||||
CAF_ASSERT( tvdRKBs.size() == normalizedValues.size() );
|
||||
|
||||
std::vector<FloatType> valuesInBar( tvdRKBs.size(), 0.0 );
|
||||
@ -424,6 +434,8 @@ std::vector<FloatType>
|
||||
RiaWellLogUnitTools<FloatType>::convertBarToNormalizedByPP( const std::vector<FloatType>& tvdRKBs,
|
||||
const std::vector<FloatType>& valuesInBar )
|
||||
{
|
||||
if ( tvdRKBs.empty() ) return {};
|
||||
|
||||
CAF_ASSERT( tvdRKBs.size() == valuesInBar.size() );
|
||||
|
||||
std::vector<FloatType> normalizedValues( tvdRKBs.size(), 0.0 );
|
||||
@ -440,6 +452,8 @@ std::vector<FloatType>
|
||||
template <typename FloatType>
|
||||
std::vector<FloatType> RiaWellLogUnitTools<FloatType>::multiply( const std::vector<FloatType>& valuesIn, FloatType factor )
|
||||
{
|
||||
if ( valuesIn.empty() ) return {};
|
||||
|
||||
std::vector<FloatType> valuesOut( valuesIn.size(), std::numeric_limits<FloatType>::infinity() );
|
||||
for ( size_t i = 0; i < valuesIn.size(); ++i )
|
||||
{
|
||||
|
@ -388,7 +388,7 @@ void RimGridTimeHistoryCurve::onLoadDataAndUpdate( bool updateParentPlot )
|
||||
{
|
||||
this->RimPlotCurve::updateCurvePresentation( updateParentPlot );
|
||||
|
||||
if ( isCurveVisible() )
|
||||
if ( isCurveVisible() && m_plotCurve )
|
||||
{
|
||||
std::vector<double> values;
|
||||
|
||||
|
@ -93,9 +93,17 @@ void RiuQwtPlotCurve::drawCurve( QPainter* p,
|
||||
size_t intervalCount = m_polyLineStartStopIndices.size();
|
||||
if ( intervalCount > 0 )
|
||||
{
|
||||
for ( size_t intIdx = 0; intIdx < intervalCount; intIdx++ )
|
||||
for ( const auto& [segmentFromCandiate, segmentToCandidate] : m_polyLineStartStopIndices )
|
||||
{
|
||||
if ( m_polyLineStartStopIndices[intIdx].first == m_polyLineStartStopIndices[intIdx].second )
|
||||
// Skip segments outside the requested index range
|
||||
if ( static_cast<int>( segmentToCandidate ) < from ) continue;
|
||||
if ( static_cast<int>( segmentFromCandiate ) > to ) continue;
|
||||
|
||||
// Draw the curve points limited to incoming from/to indices
|
||||
auto actualFromIndex = std::max( from, static_cast<int>( segmentFromCandiate ) );
|
||||
auto actualToIndex = std::min( to, static_cast<int>( segmentToCandidate ) );
|
||||
|
||||
if ( actualFromIndex == actualToIndex )
|
||||
{
|
||||
// Use a symbol to draw a single value, as a single value will not be visible
|
||||
// when using QwtPlotCurve::drawCurve without symbols activated
|
||||
@ -103,23 +111,14 @@ void RiuQwtPlotCurve::drawCurve( QPainter* p,
|
||||
QwtSymbol symbol( QwtSymbol::XCross );
|
||||
symbol.setSize( 10, 10 );
|
||||
|
||||
QwtPlotCurve::drawSymbols( p,
|
||||
symbol,
|
||||
xMap,
|
||||
yMap,
|
||||
canvasRect,
|
||||
(int)m_polyLineStartStopIndices[intIdx].first,
|
||||
(int)m_polyLineStartStopIndices[intIdx].second );
|
||||
QwtPlotCurve::drawSymbols( p, symbol, xMap, yMap, canvasRect, actualFromIndex, actualToIndex );
|
||||
}
|
||||
else
|
||||
{
|
||||
QwtPlotCurve::drawCurve( p,
|
||||
style,
|
||||
xMap,
|
||||
yMap,
|
||||
canvasRect,
|
||||
(int)m_polyLineStartStopIndices[intIdx].first,
|
||||
(int)m_polyLineStartStopIndices[intIdx].second );
|
||||
if ( actualFromIndex < actualToIndex )
|
||||
{
|
||||
QwtPlotCurve::drawCurve( p, style, xMap, yMap, canvasRect, actualFromIndex, actualToIndex );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user