Axis.h 3.39 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2008 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8

9
#include "MantidAPI/DllConfig.h"
10
#include "MantidGeometry/IDTypes.h"
11

12
#include <boost/shared_ptr.hpp>
13
14
#include <string>

15
namespace Mantid {
16
17
18
namespace Kernel {
class Unit;
}
19
namespace API {
20
21
22
//----------------------------------------------------------------------
// Forward declaration
//----------------------------------------------------------------------
23
class MatrixWorkspace;
24
25
26
27
28
29

/** Class to represent the axis of a workspace.

    @author Russell Taylor, Tessella Support Services plc
    @date 16/05/2008
*/
30
class MANTID_API_DLL Axis {
31
public:
32
  Axis();
33
  virtual ~Axis() = default;
34

35
  /// Virtual constructor
36
  virtual Axis *clone(const MatrixWorkspace *const parentWorkspace) = 0;
37
  /// Virtual constructor for axis of different length
38
39
  virtual Axis *clone(const std::size_t length,
                      const MatrixWorkspace *const parentWorkspace) = 0;
40

41
42
  const std::string &title() const;
  std::string &title();
43

44
45
  const boost::shared_ptr<Kernel::Unit> &unit() const;
  boost::shared_ptr<Kernel::Unit> &unit();
46

47
  /// Set the unit on the Axis
48
49
  virtual const boost::shared_ptr<Kernel::Unit> &
  setUnit(const std::string &unitName);
50

Nick Draper's avatar
re #100    
Nick Draper committed
51
  /// Returns true is the axis is a Spectra axis
52
  virtual bool isSpectra() const { return false; }
Nick Draper's avatar
re #100    
Nick Draper committed
53
  /// Returns true if the axis is numeric
54
  virtual bool isNumeric() const { return false; }
55
  /// Returns true if the axis is Text
56
  virtual bool isText() const { return false; }
57

Nick Draper's avatar
re #100    
Nick Draper committed
58
  /// Returns the value at a specified index
59
60
  /// @param index :: the index
  /// @param verticalIndex :: The verticalIndex
61
62
63
64
65
66
  virtual double operator()(const std::size_t &index,
                            const std::size_t &verticalIndex = 0) const = 0;
  /// Gets the value at the specified index. Just calls operator() but is easier
  /// to use with Axis pointers
  double getValue(const std::size_t &index,
                  const std::size_t &verticalIndex = 0) const;
67
  /// returns min value defined on axis
68
  virtual double getMin() const = 0;
69
  /// returns max value defined on axis
70
  virtual double getMax() const = 0;
Nick Draper's avatar
re #100    
Nick Draper committed
71
  /// Sets the value at the specified index
72
73
  /// @param index :: The index
  /// @param value :: The new value
74
  virtual void setValue(const std::size_t &index, const double &value) = 0;
75
76
77
  /// Find the index of the given double value
  virtual size_t indexOfValue(const double value) const = 0;

78
79
  /// Get the spectrum number
  virtual specnum_t spectraNo(const std::size_t &index) const;
80

81
  /// Get the length of the axis
Peterson, Peter's avatar
Peterson, Peter committed
82
  virtual std::size_t length() const = 0;
83

84
85
86
  /// Check whether two axis are the same, i.e same length and same
  /// spectra_values for all elements in the axis
  virtual bool operator==(const Axis &) const = 0;
Laurent Chapon's avatar
re#316    
Laurent Chapon committed
87

Roman Tolchenov's avatar
Roman Tolchenov committed
88
  /// Returns a text label of for a value
89
  virtual std::string label(const std::size_t &index) const = 0;
Roman Tolchenov's avatar
Roman Tolchenov committed
90

91
protected:
Hahn, Steven's avatar
Hahn, Steven committed
92
  Axis(const Axis &) = default;
93

94
95
private:
  /// Private, undefined copy assignment operator
96
  const Axis &operator=(const Axis &) = delete;
97

98
99
100
  /// The user-defined title for this axis
  std::string m_title;
  /// The unit for this axis
101
  boost::shared_ptr<Kernel::Unit> m_unit;
102
103
104
105
};

} // namespace API
} // namespace Mantid