///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2017 Statoil 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. // ///////////////////////////////////////////////////////////////////////////////// #pragma once #include "RiaCurveDataTools.h" #include template class XValueComparator { public: bool operator()( const XValueType& lhs, const XValueType& rhs ) const; static bool equals( const XValueType& lhs, const XValueType& rhs ); static double diff( const XValueType& lhs, const XValueType& rhs ); }; //================================================================================================== /// //================================================================================================== template class RiaCurveMerger { public: using XComparator = XValueComparator; RiaCurveMerger(); void addCurveData( const std::vector& xValues, const std::vector& yValues ); size_t curveCount() const; void computeInterpolatedValues( bool includeValuesFromPartialCurves = true ); RiaCurveDataTools::CurveIntervals validIntervalsForAllXValues() const; const std::vector& allXValues() const; const std::vector& interpolatedYValuesForAllXValues( size_t curveIdx ) const; // Non-const access is not required by any clients, but the expression parser has no available const interface // for specifying a data source for an expression variable. Allow non-const access to avoid copy of the contained // values, interpolated for all time steps // // See ExpressionParserImpl::assignVector() std::vector& interpolatedYValuesForAllXValues( size_t curveIdx ); static void removeValuesForPartialCurves( std::set& unionOfXValues, const std::vector>& originalXBounds ); public: // Helper methods, available as public to be able to access from unit tests static double interpolatedYValue( const XValueType& xValue, const std::vector& curveXValues, const std::vector& curveYValues ); private: void computeUnionOfXValues( bool includeValuesFromPartialCurves ); private: std::vector, std::vector>> m_originalValues; RiaCurveDataTools::CurveIntervals m_validIntervalsForAllXValues; std::vector m_allXValues; std::vector> m_interpolatedValuesForAllCurves; }; using RiaTimeHistoryCurveMerger = RiaCurveMerger; template <> bool XValueComparator::equals( const double& lhs, const double& rhs ); template <> double XValueComparator::diff( const time_t& lhs, const time_t& rhs ); #include "RiaCurveMerger.inl"