libpappsomspp
Library for mass spectrometry
selectionpolygon.h
Go to the documentation of this file.
1 // Copyright 2021 Filippo Rusconi
2 // GPLv3+
3 
4 #pragma once
5 
6 /////////////////////// StdLib includes
7 #include <vector>
8 #include <limits>
9 
10 /////////////////////// Qt includes
11 #include <QString>
12 #include <QPointF>
13 
14 
15 /////////////////////// Local includes
16 #include "../../exportinmportconfig.h"
17 #include "../../types.h"
18 
19 namespace pappso
20 {
21 
22 
23 enum class PointSpecs
24 {
25  // Starting top left and then clockwise
26  TOP_LEFT_POINT = 0,
27  TOP_RIGHT_POINT = 1,
30  ENUM_LAST = 4,
31 };
32 
33 
34 enum class DataDimension
35 {
36  NOT_SET = 0,
37  HORIZONTAL,
38  VERTICAL
39 };
40 
41 
42 enum class PolygonType
43 {
44  NOT_SET = 0x0000,
45 
46  TOP_LINE = 1 << 0,
47  BOTTOM_LINE = 1 << 1,
48 
50 
51  RIGHT_LINE = 1 << 2,
52  LEFT_LINE = 1 << 3,
53 
55 
57 };
58 
59 
61 {
62  public:
63  // Constructor with no arguments
65 
66  SelectionPolygon(QPointF top_left_point, QPointF top_right_point);
67 
68  SelectionPolygon(QPointF top_left_point,
69  QPointF top_right_point,
70  QPointF bottom_right_point,
71  QPointF bottom_left_point);
72 
73  SelectionPolygon(const SelectionPolygon &other);
74 
75  virtual ~SelectionPolygon();
76 
77 
78  void setPoint(PointSpecs point_spec, double x, double y);
79  void setPoint(PointSpecs point_spec, QPointF point);
80  void copyPoint(PointSpecs point_spec_src, PointSpecs point_spec_dest);
81 
82  void set1D(double x_range_start, double x_range_end);
83  void set2D(QPointF top_left,
84  QPointF top_right,
85  QPointF bottom_right,
86  QPointF bottom_left);
87  void convertTo1D();
88 
89  const std::vector<QPointF> &getPoints() const;
90 
91  QPointF getLeftMostPoint() const;
92  QPointF getRightMostPoint() const;
93  QPointF getTopMostPoint() const;
94  QPointF getBottomMostPoint() const;
95 
96  QPointF getPoint(PointSpecs point_spec) const;
97 
98  bool computeMinMaxCoordinates();
99  bool computeMinMaxCoordinates(double &min_x,
100  double &max_x,
101  double &min_y,
102  double &max_y) const;
103 
104  double width(bool &ok) const;
105  double height(bool &ok) const;
106 
107  bool rangeX(double &range_start, double &range_end) const;
108  bool rangeY(double &range_start, double &range_end) const;
109  bool range(Axis axis, double &range_start, double &range_end) const;
110 
111  SelectionPolygon transpose() const;
112 
113  bool contains(const QPointF &tested_point) const;
114  bool contains(const SelectionPolygon &selection_polygon) const;
115 
116  SelectionPolygon &operator=(const SelectionPolygon &other);
117 
118  void resetPoints();
119 
120  bool is1D() const;
121  bool is2D() const;
122  bool isRectangle() const;
123 
124  QString toShort4PointsString() const;
125  QString toString() const;
126 
127 
128  static void debugAlgorithm(const SelectionPolygon &selection_polygon,
129  const QPointF &tested_point);
130 
131  protected:
132  // The PointSpecs enum and the setPoint function ensure that there are no more
133  // than four points in the vector.
134 
135  // We want to create a largest polygon possible, by settting the first point,
136  // top_left on the lowest_x and highest_y, the top_right on the highest_x and
137  // highest_y, the bottom_right on the highest_x and lowest_y, the bottom_left
138  // at the lowest_x and lowest_y.
139  std::vector<QPointF> m_points = {QPointF(std::numeric_limits<double>::min(),
140  std::numeric_limits<double>::max()),
141  QPointF(std::numeric_limits<double>::max(),
142  std::numeric_limits<double>::max()),
143  QPointF(std::numeric_limits<double>::max(),
144  std::numeric_limits<double>::min()),
145  QPointF(std::numeric_limits<double>::min(),
146  std::numeric_limits<double>::min())};
147 
148  double m_minX = std::numeric_limits<double>::min();
149  double m_minY = std::numeric_limits<double>::min();
150 
151  double m_maxX = std::numeric_limits<double>::max();
152  double m_maxY = std::numeric_limits<double>::max();
153 };
154 
155 
157 {
158 
161 
162  // NO specification of the axis because it is implicit that MZ is Y and the
163  // checked value is either DT or RT depending on dataKind.
164 
166 
167  SelectionPolygonSpec(const SelectionPolygon &selection_polygon,
168  DataKind data_kind)
169  : selectionPolygon(selection_polygon),
170  dataKind(data_kind)
171  {
172  }
173 
175  : selectionPolygon(other.selectionPolygon),
176  dataKind(other.dataKind)
177  {
178  }
179 
182  {
183  if(this == &other)
184  return *this;
185 
186  selectionPolygon = other.selectionPolygon;
187  dataKind = other.dataKind;
188 
189  return *this;
190  }
191 
192 
193  QString
194  toString() const
195  {
196  QString text = "Selection polygon spec:";
197  text += selectionPolygon.toString();
198 
199  text += " - data kind: ";
200 
201  if(dataKind == DataKind::dt)
202  text += "dt.";
203  else if(dataKind == DataKind::mz)
204  text += "m/z.";
205  else if(dataKind == DataKind::rt)
206  text += "rt.";
207  else
208  text += "unset.";
209 
210  return text;
211  }
212 };
213 
214 
215 } // namespace pappso
216 
#define PMSPP_LIB_DECL
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
Axis
Definition: types.h:181
DataKind
Definition: types.h:172
@ dt
Drift time.
@ rt
Retention time.
SelectionPolygonSpec & operator=(const SelectionPolygonSpec &other)
SelectionPolygonSpec(const SelectionPolygonSpec &other)
SelectionPolygonSpec(const SelectionPolygon &selection_polygon, DataKind data_kind)