///////////////////////////////////////////////////////////////////////////////// // // 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 // 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& xValues, const std::vector& yValues ) { setSamplesInPlot( xValues, yValues ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiuPlotCurve::setSamplesFromXValuesAndYValues( const std::vector& xValues, const std::vector& yValues, bool useLogarithmicScale ) { computeValidIntervalsAndSetCurveData( xValues, yValues, useLogarithmicScale ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiuPlotCurve::setSamplesFromDatesAndYValues( const std::vector& dateTimes, const std::vector& yValues, bool useLogarithmicScale ) { auto xValues = RiuPlotCurve::fromQDateTime( dateTimes ); computeValidIntervalsAndSetCurveData( xValues, yValues, useLogarithmicScale ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiuPlotCurve::setSamplesFromTimeTAndYValues( const std::vector& dateTimes, const std::vector& yValues, bool useLogarithmicScale ) { auto xValues = RiuPlotCurve::fromTime_t( dateTimes ); computeValidIntervalsAndSetCurveData( xValues, yValues, useLogarithmicScale ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiuPlotCurve::setLineSegmentStartStopIndices( const std::vector>& lineSegmentStartStopIndices ) { m_polyLineStartStopIndices = lineSegmentStartStopIndices; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiuPlotCurve::setSymbolSkipPixelDistance( float distance ) { m_symbolSkipPixelDistance = distance >= 0.0f ? distance : 0.0f; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiuPlotCurve::setPerPointLabels( const std::vector& labels ) { m_perPointLabels = labels; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiuPlotCurve::setBlackAndWhiteLegendIcon( bool blackAndWhite ) { m_blackAndWhiteLegendIcon = blackAndWhite; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiuPlotCurve::computeValidIntervalsAndSetCurveData( const std::vector& xValues, const std::vector& yValues, bool useLogarithmicScale ) { auto intervalsOfValidValues = RiaCurveDataTools::calculateIntervalsOfValidValues( yValues, useLogarithmicScale ); std::vector validYValues; std::vector validXValues; RiaCurveDataTools::getValuesByIntervals( yValues, intervalsOfValidValues, &validYValues ); RiaCurveDataTools::getValuesByIntervals( xValues, intervalsOfValidValues, &validXValues ); setSamplesInPlot( validXValues, validYValues ); setLineSegmentStartStopIndices( RiaCurveDataTools::computePolyLineStartStopIndices( intervalsOfValidValues ) ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::vector RiuPlotCurve::fromQDateTime( const std::vector& dateTimes ) { std::vector 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 RiuPlotCurve::fromTime_t( const std::vector& timeSteps ) { std::vector 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& xValues, const std::vector& yValues, const std::vector& errorValues, bool useLogarithmicScale, RiaCurveDataTools::ErrorAxis errorAxis ) { } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RimPlotCurve* RiuPlotCurve::ownerRimCurve() { return m_ownerRimCurve; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- const RimPlotCurve* RiuPlotCurve::ownerRimCurve() const { return m_ownerRimCurve; }