DP3
Axis.h
Go to the documentation of this file.
1 // Axis.h: Classes representing a regular or irregular axis.
2 //
3 // Copyright (C) 2020 ASTRON (Netherlands Institute for Radio Astronomy)
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 
9 
10 #ifndef LOFAR_PARMDB_AXIS_H
11 #define LOFAR_PARMDB_AXIS_H
12 
13 #include <cstdint>
14 #include <memory>
15 #include <utility>
16 #include <vector>
17 
18 namespace dp3 {
19 namespace parmdb {
20 
23 
25 
27 class Axis {
28  public:
30  typedef std::shared_ptr<Axis> ShPtr;
31 
33  Axis();
34  virtual ~Axis() {}
35 
37  virtual Axis::ShPtr clone() const = 0;
38 
41  bool operator==(const Axis& that) const;
42  bool operator!=(const Axis& that) const { return !operator==(that); }
44 
46  unsigned int getId() const { return itsId; }
47 
50  double center(size_t n) const { return itsCenter[n]; }
51  double width(size_t n) const { return itsWidth[n]; }
52  double upper(size_t n) const { return itsUpper[n]; }
53  double lower(size_t n) const { return itsLower[n]; }
55 
58  const std::vector<double>& centers() const { return itsCenter; }
59  const std::vector<double>& widths() const { return itsWidth; }
60  const std::vector<double>& uppers() const { return itsUpper; }
61  const std::vector<double>& lowers() const { return itsLower; }
63 
65  bool isRegular() const { return itsIsRegular; }
66 
68  size_t size() const { return itsCenter.size(); }
69 
72  double start() const { return itsLower[0]; }
73  double end() const { return itsUpper[itsUpper.size() - 1]; }
75 
77  std::pair<double, double> range() const {
78  return std::make_pair(start(), end());
79  }
80 
88  std::pair<size_t, bool> find(double x, bool biasRight = true,
89  size_t start = 0) const;
90 
92  size_t locate(double x, bool biasRight = true, size_t start = 0) const {
93  std::pair<size_t, bool> res = find(x, biasRight, start);
94  if (!res.second) throwNotFound(x);
95  return res.first;
96  }
97 
99  bool checkIntervals(const Axis& that) const;
100 
104  Axis::ShPtr subset(double start, double end, size_t& index) const;
105  Axis::ShPtr subset(double start, double end) const;
107 
109  Axis::ShPtr subset(size_t start, size_t end) const {
110  return doSubset(start, end);
111  }
112 
114  virtual Axis::ShPtr compress(size_t factor) const = 0;
115 
124  Axis::ShPtr combine(const Axis& that, int& s1, int& e1, int& s2,
125  int& e2) const;
126 
132  static Axis::ShPtr makeAxis(const std::vector<double>& low,
133  const std::vector<double>& high);
134 
135  private:
137  Axis::ShPtr add(const Axis& that) const;
138 
139  virtual Axis::ShPtr doSubset(size_t start, size_t end) const = 0;
140 
142  void throwNotFound(double x) const;
143 
144  protected:
146  void setup(double start, double width, unsigned int count);
148  void setup(const std::vector<double>& v1, const std::vector<double>& v2,
149  bool asStartEnd);
150 
152  static unsigned int theirId;
153 
154  unsigned int itsId;
156  std::vector<double> itsCenter;
157  std::vector<double> itsWidth;
158  std::vector<double> itsLower;
159  std::vector<double> itsUpper;
160 };
161 
163 class RegularAxis : public Axis {
164  public:
167 
169  RegularAxis(double begin, double cellWidth, unsigned int count,
170  bool asStartEnd = false);
171 
172  ~RegularAxis() override;
173 
175  Axis::ShPtr clone() const override;
176 
177  Axis::ShPtr doSubset(size_t start, size_t end) const override;
178  Axis::ShPtr compress(size_t factor) const override;
179 
180  private:
181  double itsStart;
182  double itsWidth;
183  uint32_t itsCount;
184 };
185 
189 class OrderedAxis : public Axis {
190  public:
193 
198  OrderedAxis(const std::vector<double>& v1, const std::vector<double>& v2,
199  bool asStartEnd = false);
200 
201  ~OrderedAxis() override;
202 
204  Axis::ShPtr clone() const override;
205 
206  Axis::ShPtr doSubset(size_t start, size_t end) const override;
207  Axis::ShPtr compress(size_t factor) const override;
208 };
209 
211 
212 } // namespace parmdb
213 } // namespace dp3
214 
215 #endif
Classes representing a regular or irregular axis.
Definition: Axis.h:27
std::vector< double > itsCenter
Definition: Axis.h:156
void setup(const std::vector< double > &v1, const std::vector< double > &v2, bool asStartEnd)
Set up the object for an irregular axis.
std::shared_ptr< Axis > ShPtr
Define a shared_ptr for this class.
Definition: Axis.h:30
Axis::ShPtr combine(const Axis &that, int &s1, int &e1, int &s2, int &e2) const
Axis::ShPtr subset(size_t start, size_t end) const
Make a subset of the axis for the given start/end index.
Definition: Axis.h:109
double upper(size_t n) const
Definition: Axis.h:52
Axis::ShPtr subset(double start, double end, size_t &index) const
Axis()
The constructor sets the unique id.
double center(size_t n) const
Definition: Axis.h:50
static unsigned int theirId
Unique seqnr of an Axis object. Used in class AxisMapping.
Definition: Axis.h:152
const std::vector< double > & centers() const
Definition: Axis.h:58
virtual ~Axis()
Definition: Axis.h:34
const std::vector< double > & uppers() const
Definition: Axis.h:60
bool operator==(const Axis &that) const
unsigned int itsId
Definition: Axis.h:154
double start() const
Definition: Axis.h:72
size_t size() const
Get nr of cells.
Definition: Axis.h:68
std::pair< double, double > range() const
Get the total range of the axis.
Definition: Axis.h:77
Axis::ShPtr subset(double start, double end) const
virtual Axis::ShPtr clone() const =0
Clone the object.
virtual Axis::ShPtr compress(size_t factor) const =0
Compress the axis.
unsigned int getId() const
Get the unique axis id.
Definition: Axis.h:46
std::vector< double > itsUpper
Definition: Axis.h:159
std::vector< double > itsWidth
Definition: Axis.h:157
static Axis::ShPtr makeAxis(const std::vector< double > &low, const std::vector< double > &high)
bool isRegular() const
Is the axis regular?
Definition: Axis.h:65
double lower(size_t n) const
Definition: Axis.h:53
bool operator!=(const Axis &that) const
Definition: Axis.h:42
bool checkIntervals(const Axis &that) const
Check if the corresponding intervals in this and that axis are the same.
double end() const
Definition: Axis.h:73
const std::vector< double > & widths() const
Definition: Axis.h:59
double width(size_t n) const
Definition: Axis.h:51
std::vector< double > itsLower
Definition: Axis.h:158
bool itsIsRegular
Definition: Axis.h:155
const std::vector< double > & lowers() const
Definition: Axis.h:61
void setup(double start, double width, unsigned int count)
Set up the object for a regular axis.
size_t locate(double x, bool biasRight=true, size_t start=0) const
Get the cellnr as above, but throw an exception if not found.
Definition: Axis.h:92
std::pair< size_t, bool > find(double x, bool biasRight=true, size_t start=0) const
Ordered irregularly strided cell centered axis. The cells are ordered and disjoint,...
Definition: Axis.h:189
OrderedAxis()
Default constructor creates one cell from -1e30 till 1e30.
OrderedAxis(const std::vector< double > &v1, const std::vector< double > &v2, bool asStartEnd=false)
Axis::ShPtr doSubset(size_t start, size_t end) const override
Axis::ShPtr clone() const override
Clone the object.
Axis::ShPtr compress(size_t factor) const override
Compress the axis.
Regularly strided cell centered axis.
Definition: Axis.h:163
Axis::ShPtr compress(size_t factor) const override
Compress the axis.
Axis::ShPtr clone() const override
Clone the object.
RegularAxis(double begin, double cellWidth, unsigned int count, bool asStartEnd=false)
Construct giving the beginning of the axis and the width of each cell.
RegularAxis()
Default constructor creates one cell from -1e30 till 1e30.
Axis::ShPtr doSubset(size_t start, size_t end) const override
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53