Skip to content
Snippets Groups Projects
Interpolation.h 3.17 KiB
Newer Older
#ifndef MANTID_KERNEL_INTERPOLATION_H_
#define MANTID_KERNEL_INTERPOLATION_H_

//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidKernel/DllConfig.h"
#include "MantidKernel/Unit.h"
#include <cstdlib>
#include <string>
namespace Mantid {
namespace Kernel {
/**
 Provide interpolation over a series of points.
 @author Anders Markvardsen, ISIS, RAL
 @date 9/3/2010

 Copyright &copy; 2007-2010 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
 National Laboratory & European Spallation Source

 This file is part of Mantid.

 Mantid 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.

 Mantid 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 for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 File change history is stored at: <https://github.com/mantidproject/mantid>.
 Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_KERNEL_DLL Interpolation {
  /// internal storage of x values
  /// internal storage of y values
  std::vector<double> m_y;

  /// method used for doing the interpolation
  std::string m_method;
protected:
  size_t findIndexOfNextLargerValue(const std::vector<double> &data,
                                    double key) const;
  /// Constructor default to linear interpolation and x-unit set to TOF
  Interpolation();
  virtual ~Interpolation() = default;
  void addPoint(const double &xx, const double &yy);

  /// get interpolated value at location at
  double value(const double &at) const;
  void setMethod(const std::string &method) { m_method = method; }
  std::string getMethod() const { return m_method; };
  void setXUnit(const std::string &unit);
  void setYUnit(const std::string &unit);
  Unit_sptr getXUnit() const { return m_xUnit; };

  /// get y-axis unit
  Unit_sptr getYUnit() const { return m_yUnit; };
  bool containData() const { return !m_x.empty() ? true : false; }
  void printSelf(std::ostream &os) const;
  /// Clear interpolation values
  void resetData();
MANTID_KERNEL_DLL std::ostream &operator<<(std::ostream &,
                                           const Interpolation &);
MANTID_KERNEL_DLL std::istream &operator>>(std::istream &, Interpolation &);
} // namespace Kernel
} // namespace Mantid

#endif /*MANTID_KERNEL_INTERPOLATION_H_*/