ResInsight/ApplicationLibCode/UserInterface/RiuPlotCurve.cpp
Magne Sjaastad f8c5cf389f
clang-format: Set column width to 140
* Set column width to 140
* Use c++20
* Remove redundant virtual
2023-02-26 10:48:40 +01:00

203 lines
8.2 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2021- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiuPlotCurve.h"
#include "RiaCurveDataTools.h"
#include "RiaTimeTTools.h"
#include "RimPlotCurve.h"
#include "qwt_date.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuPlotCurve::RiuPlotCurve( RimPlotCurve* ownerRimCurve, const QString& title )
{
m_ownerRimCurve = ownerRimCurve;
m_symbolSkipPixelDistance = 10.0f;
m_blackAndWhiteLegendIcon = false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuPlotCurve::~RiuPlotCurve()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuPlotCurve::setSamplesValues( const std::vector<double>& xValues, const std::vector<double>& yValues )
{
setSamplesInPlot( xValues, yValues );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuPlotCurve::setSamplesFromXValuesAndYValues( const std::vector<double>& xValues, const std::vector<double>& yValues, bool useLogarithmicScale )
{
computeValidIntervalsAndSetCurveData( xValues, yValues, useLogarithmicScale );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuPlotCurve::setSamplesFromDatesAndYValues( const std::vector<QDateTime>& dateTimes,
const std::vector<double>& yValues,
bool useLogarithmicScale )
{
auto xValues = RiuPlotCurve::fromQDateTime( dateTimes );
computeValidIntervalsAndSetCurveData( xValues, yValues, useLogarithmicScale );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuPlotCurve::setSamplesFromTimeTAndYValues( const std::vector<time_t>& dateTimes, const std::vector<double>& yValues, bool useLogarithmicScale )
{
auto xValues = RiuPlotCurve::fromTime_t( dateTimes );
computeValidIntervalsAndSetCurveData( xValues, yValues, useLogarithmicScale );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuPlotCurve::setLineSegmentStartStopIndices( const std::vector<std::pair<size_t, size_t>>& lineSegmentStartStopIndices )
{
m_polyLineStartStopIndices = lineSegmentStartStopIndices;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuPlotCurve::setSymbolSkipPixelDistance( float distance )
{
m_symbolSkipPixelDistance = distance >= 0.0f ? distance : 0.0f;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuPlotCurve::setPerPointLabels( const std::vector<QString>& labels )
{
m_perPointLabels = labels;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuPlotCurve::setBlackAndWhiteLegendIcon( bool blackAndWhite )
{
m_blackAndWhiteLegendIcon = blackAndWhite;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuPlotCurve::computeValidIntervalsAndSetCurveData( const std::vector<double>& xValues,
const std::vector<double>& yValues,
bool useLogarithmicScale )
{
auto intervalsOfValidValues = RiaCurveDataTools::calculateIntervalsOfValidValues( yValues, useLogarithmicScale );
std::vector<double> validYValues;
std::vector<double> validXValues;
RiaCurveDataTools::getValuesByIntervals( yValues, intervalsOfValidValues, &validYValues );
RiaCurveDataTools::getValuesByIntervals( xValues, intervalsOfValidValues, &validXValues );
setSamplesInPlot( validXValues, validYValues );
setLineSegmentStartStopIndices( RiaCurveDataTools::computePolyLineStartStopIndices( intervalsOfValidValues ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<double> RiuPlotCurve::fromQDateTime( const std::vector<QDateTime>& dateTimes )
{
std::vector<double> doubleValues;
if ( !dateTimes.empty() )
{
doubleValues.reserve( dateTimes.size() );
for ( const auto& dt : dateTimes )
{
// TODO: remove Qwt usage here..
doubleValues.push_back( QwtDate::toDouble( dt ) );
}
}
return doubleValues;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<double> RiuPlotCurve::fromTime_t( const std::vector<time_t>& timeSteps )
{
std::vector<double> doubleValues;
if ( !timeSteps.empty() )
{
doubleValues.reserve( timeSteps.size() );
for ( const auto& time : timeSteps )
{
doubleValues.push_back( RiaTimeTTools::toDouble( time ) );
}
}
return doubleValues;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuPlotCurve::setSamplesFromXYErrorValues( const std::vector<double>& xValues,
const std::vector<double>& yValues,
const std::vector<double>& errorValues,
bool useLogarithmicScale,
RiaCurveDataTools::ErrorAxis errorAxis )
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPlotCurve* RiuPlotCurve::ownerRimCurve()
{
return m_ownerRimCurve;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const RimPlotCurve* RiuPlotCurve::ownerRimCurve() const
{
return m_ownerRimCurve;
}