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