libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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
19namespace pappso
20{
21
22
23enum class PointSpec
24{
25 // Starting top left and then clockwise
30 ENUM_LAST = 4,
31};
32
33
34enum class DataDimension
35{
36 NOT_SET = 0,
39};
40
41
42
44{
45 public:
46 // Constructor with no arguments
48
49 SelectionPolygon(QPointF top_left_point, QPointF top_right_point);
50
51 SelectionPolygon(QPointF top_left_point,
52 QPointF top_right_point,
53 QPointF bottom_right_point,
54 QPointF bottom_left_point);
55
57
58 virtual ~SelectionPolygon();
59
60
61 void setPoint(PointSpec point_spec, double x, double y);
62 void setPoint(PointSpec point_spec, QPointF point);
63 void copyPoint(PointSpec point_spec_src, PointSpec point_spec_dest);
64
65 void set1D(double x_range_start, double x_range_end);
66 void set2D(QPointF top_left,
67 QPointF top_right,
68 QPointF bottom_right,
69 QPointF bottom_left);
70 void convertTo1D();
71
72 const std::vector<QPointF> &getPoints() const;
73
74 QPointF getLeftMostPoint() const;
75 QPointF getRightMostPoint() const;
76 QPointF getTopMostPoint() const;
77 QPointF getBottomMostPoint() const;
78
79 QPointF getPoint(PointSpec point_spec) const;
80
81 bool computeMinMaxCoordinates();
82 bool computeMinMaxCoordinates(double &min_x,
83 double &max_x,
84 double &min_y,
85 double &max_y) const;
86
87 double width(bool &ok) const;
88 double height(bool &ok) const;
89
90 bool rangeX(double &range_start, double &range_end) const;
91 bool rangeY(double &range_start, double &range_end) const;
92 bool range(Axis axis, double &range_start, double &range_end) const;
93
94 SelectionPolygon transpose() const;
95
96 bool contains(const QPointF &tested_point) const;
97 bool contains(const SelectionPolygon &selection_polygon) const;
98
99 SelectionPolygon &operator=(const SelectionPolygon &other);
100
101 void resetPoints();
102
103 bool is1D() const;
104 bool is2D() const;
105 bool isRectangle() const;
106
107 QString toShort4PointsString() const;
108 QString toString() const;
109
110
111 static void debugAlgorithm(const SelectionPolygon &selection_polygon,
112 const QPointF &tested_point);
113
114 protected:
115 // The PointSpec enum and the setPoint function ensure that there are no more
116 // than four points in the vector.
117
118 // We want to create a largest polygon possible, by settting the first point,
119 // top_left on the lowest_x and highest_y, the top_right on the highest_x and
120 // highest_y, the bottom_right on the highest_x and lowest_y, the bottom_left
121 // at the lowest_x and lowest_y.
122 std::vector<QPointF> m_points = {QPointF(std::numeric_limits<double>::min(),
123 std::numeric_limits<double>::max()),
124 QPointF(std::numeric_limits<double>::max(),
125 std::numeric_limits<double>::max()),
126 QPointF(std::numeric_limits<double>::max(),
127 std::numeric_limits<double>::min()),
128 QPointF(std::numeric_limits<double>::min(),
129 std::numeric_limits<double>::min())};
130
131 double m_minX = std::numeric_limits<double>::min();
132 double m_minY = std::numeric_limits<double>::min();
133
134 double m_maxX = std::numeric_limits<double>::max();
135 double m_maxY = std::numeric_limits<double>::max();
136};
137
138
140{
141
143 DataKind dataKind = DataKind::unset;
144
145 // NO specification of the axis because it is implicit that MZ is Y and the
146 // checked value is either DT or RT depending on dataKind.
147
149
150 SelectionPolygonSpec(const SelectionPolygon &selection_polygon,
151 DataKind data_kind)
152 : selectionPolygon(selection_polygon), dataKind(data_kind)
153 {
154 }
155
157 : selectionPolygon(other.selectionPolygon), dataKind(other.dataKind)
158 {
159 }
160
163 {
164 if(this == &other)
165 return *this;
166
167 selectionPolygon = other.selectionPolygon;
168 dataKind = other.dataKind;
169
170 return *this;
171 }
172
173
174 QString
175 toString() const
176 {
177 QString text = "Selection polygon spec:";
178 text += selectionPolygon.toString();
179
180 text += " - data kind: ";
181
182 if(dataKind == DataKind::dt)
183 text += "dt.";
184 else if(dataKind == DataKind::mz)
185 text += "m/z.";
186 else if(dataKind == DataKind::rt)
187 text += "rt.";
188 else
189 text += "unset.";
190
191 return text;
192 }
193};
194
195
196} // namespace pappso
#define PMSPP_LIB_DECL
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
DataKind
Definition types.h:211
SelectionPolygonSpec(const SelectionPolygonSpec &other)
SelectionPolygonSpec & operator=(const SelectionPolygonSpec &other)
SelectionPolygonSpec(const SelectionPolygon &selection_polygon, DataKind data_kind)