BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
axisitems.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/model/mvvm/standarditems/axisitems.h
6 //! @brief Defines class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_MVVM_MODEL_MVVM_STANDARDITEMS_AXISITEMS_H
16 #define BORNAGAIN_MVVM_MODEL_MVVM_STANDARDITEMS_AXISITEMS_H
17 
18 //! @file mvvm/model/mvvm/standarditems/axisitems.h
19 //! Collection of axis items for 1D and 2D data/plotting support.
20 
22 #include <memory>
23 #include <vector>
24 
25 namespace ModelView {
26 
27 //! Base class for all axes items. Has min, max defined, but nothing else.
28 
29 class MVVM_MODEL_EXPORT BasicAxisItem : public CompoundItem {
30 public:
31  static inline const std::string P_MIN = "P_MIN";
32  static inline const std::string P_MAX = "P_MAX";
33 
34  explicit BasicAxisItem(const std::string& model_type);
35 
36 protected:
37  void register_min_max();
38 };
39 
40 //! Item to represent viewport axis.
41 //! Serves as a counterpart of QCPAxis from QCustomPlot. Intended to cary title, fonts etc.
42 
43 class MVVM_MODEL_EXPORT ViewportAxisItem : public BasicAxisItem {
44 public:
45  static inline const std::string P_TITLE = "P_TITLE";
46  static inline const std::string P_IS_LOG = "P_IS_LOG";
47  explicit ViewportAxisItem(const std::string& model_type = Constants::ViewportAxisItemType);
48 
49  std::pair<double, double> range() const;
50 
51  void set_range(double lower, double upper);
52 
53  bool is_in_log() const;
54 };
55 
56 //! Item to represent an axis with arbitrary binning.
57 //! Base class to define an axis with specific binning (fixed, variable). Used in Data1DItem and
58 //! Data2Ditem to store 1d and 2d data. Doesn't carry any appearance info (e.g. axis title, label
59 //! size, etc) and thus not intended for direct plotting.
60 
61 class MVVM_MODEL_EXPORT BinnedAxisItem : public BasicAxisItem {
62 public:
63  explicit BinnedAxisItem(const std::string& model_type);
64 
65  virtual std::pair<double, double> range() const = 0;
66 
67  virtual int size() const = 0;
68 
69  virtual std::vector<double> binCenters() const = 0;
70 };
71 
72 //! Item to represent fixed bin axis.
73 //! Defines an axis with equidistant binning.
74 
75 class MVVM_MODEL_EXPORT FixedBinAxisItem : public BinnedAxisItem {
76 public:
77  static inline const std::string P_NBINS = "P_NBINS";
79 
80  void setParameters(int nbins, double xmin, double xmax);
81 
82  static std::unique_ptr<FixedBinAxisItem> create(int nbins, double xmin, double xmax);
83 
84  std::pair<double, double> range() const override;
85 
86  int size() const override;
87 
88  std::vector<double> binCenters() const override;
89 };
90 
91 //! Item to represent pointwise axis.
92 //! Defines an axis via array of points representing point coordinates.
93 
94 class MVVM_MODEL_EXPORT PointwiseAxisItem : public BinnedAxisItem {
95 public:
97 
98  void setParameters(const std::vector<double>& data);
99 
100  static std::unique_ptr<PointwiseAxisItem> create(const std::vector<double>& data);
101 
102  std::pair<double, double> range() const override;
103 
104  int size() const override;
105 
106  std::vector<double> binCenters() const override;
107 };
108 
109 } // namespace ModelView
110 
111 #endif // BORNAGAIN_MVVM_MODEL_MVVM_STANDARDITEMS_AXISITEMS_H
Base class for all axes items. Has min, max defined, but nothing else.
Definition: axisitems.h:29
Item to represent an axis with arbitrary binning.
Definition: axisitems.h:61
virtual int size() const =0
virtual std::vector< double > binCenters() const =0
virtual std::pair< double, double > range() const =0
Complex item holding mixed SessionItem types (single properties and other CompountItems).
Definition: compounditem.h:28
Item to represent fixed bin axis.
Definition: axisitems.h:75
Item to represent pointwise axis.
Definition: axisitems.h:94
Item to represent viewport axis.
Definition: axisitems.h:43
Defines class CLASS?
const model_type FixedBinAxisItemType
Definition: mvvm_types.h:52
const model_type ViewportAxisItemType
Definition: mvvm_types.h:62
const model_type PointwiseAxisItemType
Definition: mvvm_types.h:58
materialitems.h Collection of materials to populate MaterialModel.
std::string model_type
Definition: types.h:23
std::vector< double > binCenters(const QCPGraph *graph)
Returns vector representing bin centers on QCPgraph.