Loading...
Searching...
No Matches
selectionpolygon.h
Go to the documentation of this file.
// Copyright 2021 Filippo Rusconi
// GPLv3+
#pragma once
/////////////////////// StdLib includes
#include <vector>
#include <limits>
/////////////////////// Qt includes
#include <QString>
#include <QPointF>
/////////////////////// Local includes
#include "pappsomspp/export-import-config.h"
#include "../../types.h"
namespace pappso
{
enum class PointSpec
{
// Starting top left and then clockwise
TOP_LEFT_POINT = 0,
TOP_RIGHT_POINT = 1,
BOTTOM_RIGHT_POINT = 2,
BOTTOM_LEFT_POINT = 3,
ENUM_LAST = 4,
};
enum class DataDimension
{
NOT_SET = 0,
HORIZONTAL,
VERTICAL
};
class PMSPP_LIB_DECL SelectionPolygon
{
public:
// Constructor with no arguments
SelectionPolygon();
SelectionPolygon(QPointF top_left_point, QPointF top_right_point);
SelectionPolygon(QPointF top_left_point,
QPointF top_right_point,
QPointF bottom_right_point,
QPointF bottom_left_point);
SelectionPolygon(const SelectionPolygon &other);
virtual ~SelectionPolygon();
void setPoint(PointSpec point_spec, double x, double y);
void setPoint(PointSpec point_spec, QPointF point);
void copyPoint(PointSpec point_spec_src, PointSpec point_spec_dest);
void set1D(double x_range_start, double x_range_end);
void set2D(QPointF top_left,
QPointF top_right,
QPointF bottom_right,
QPointF bottom_left);
void convertTo1D();
const std::vector<QPointF> &getPoints() const;
QPointF getLeftMostPoint() const;
QPointF getRightMostPoint() const;
QPointF getTopMostPoint() const;
QPointF getBottomMostPoint() const;
QPointF getPoint(PointSpec point_spec) const;
bool computeMinMaxCoordinates();
bool computeMinMaxCoordinates(double &min_x,
double &max_x,
double &min_y,
double &max_y) const;
double width(bool &ok) const;
double height(bool &ok) const;
bool rangeX(double &range_start, double &range_end) const;
bool rangeY(double &range_start, double &range_end) const;
bool range(Enums::Axis axis, double &range_start, double &range_end) const;
SelectionPolygon transpose() const;
bool contains(const QPointF &tested_point) const;
bool contains(const SelectionPolygon &selection_polygon) const;
SelectionPolygon &operator=(const SelectionPolygon &other);
void resetPoints();
bool is1D() const;
bool is2D() const;
bool isRectangle() const;
QString toShort4PointsString() const;
QString toString() const;
static void debugAlgorithm(const SelectionPolygon &selection_polygon,
const QPointF &tested_point);
protected:
// The PointSpec enum and the setPoint function ensure that there are no more
// than four points in the vector.
// We want to create a largest polygon possible, by settting the first point,
// top_left on the lowest_x and highest_y, the top_right on the highest_x and
// highest_y, the bottom_right on the highest_x and lowest_y, the bottom_left
// at the lowest_x and lowest_y.
std::vector<QPointF> m_points = {QPointF(std::numeric_limits<double>::min(),
std::numeric_limits<double>::max()),
QPointF(std::numeric_limits<double>::max(),
std::numeric_limits<double>::max()),
QPointF(std::numeric_limits<double>::max(),
std::numeric_limits<double>::min()),
QPointF(std::numeric_limits<double>::min(),
std::numeric_limits<double>::min())};
double m_minX = std::numeric_limits<double>::min();
double m_minY = std::numeric_limits<double>::min();
double m_maxX = std::numeric_limits<double>::max();
double m_maxY = std::numeric_limits<double>::max();
};
struct PMSPP_LIB_DECL SelectionPolygonSpec
{
SelectionPolygon selectionPolygon;
Enums::DataKind dataKind = Enums::DataKind::unset;
// NO specification of the axis because it is implicit that MZ is Y and the
// checked value is either DT or RT depending on dataKind.
SelectionPolygonSpec();
SelectionPolygonSpec(const SelectionPolygon &selection_polygon,
Enums::DataKind data_kind)
: selectionPolygon(selection_polygon), dataKind(data_kind)
{
}
SelectionPolygonSpec(const SelectionPolygonSpec &other)
: selectionPolygon(other.selectionPolygon), dataKind(other.dataKind)
{
}
SelectionPolygonSpec &
operator=(const SelectionPolygonSpec &other)
{
if(this == &other)
return *this;
selectionPolygon = other.selectionPolygon;
dataKind = other.dataKind;
return *this;
}
QString
toString() const
{
QString text = "Selection polygon spec:";
text += selectionPolygon.toString();
text += " - data kind: ";
if(dataKind == Enums::DataKind::dt)
text += "dt.";
else if(dataKind == Enums::DataKind::mz)
text += "m/z.";
else if(dataKind == Enums::DataKind::rt)
text += "rt.";
else
text += "unset.";
return text;
}
};
} // namespace pappso
pappso::SelectionPolygon
Definition selectionpolygon.h:44
pappso::SelectionPolygon::range
bool range(Enums::Axis axis, double &range_start, double &range_end) const
Definition selectionpolygon.cpp:417
pappso::SelectionPolygon::rangeX
bool rangeX(double &range_start, double &range_end) const
Definition selectionpolygon.cpp:397
pappso::SelectionPolygon::m_maxY
double m_maxY
Definition selectionpolygon.h:135
pappso::SelectionPolygon::rangeY
bool rangeY(double &range_start, double &range_end) const
Definition selectionpolygon.cpp:407
pappso::SelectionPolygon::debugAlgorithm
static void debugAlgorithm(const SelectionPolygon &selection_polygon, const QPointF &tested_point)
Definition selectionpolygon.cpp:813
pappso::SelectionPolygon::is1D
bool is1D() const
Definition selectionpolygon.cpp:616
pappso::SelectionPolygon::transpose
SelectionPolygon transpose() const
Definition selectionpolygon.cpp:442
pappso::SelectionPolygon::toShort4PointsString
QString toShort4PointsString() const
Definition selectionpolygon.cpp:762
pappso::SelectionPolygon::setPoint
void setPoint(PointSpec point_spec, double x, double y)
Definition selectionpolygon.cpp:113
pappso::SelectionPolygon::m_minY
double m_minY
Definition selectionpolygon.h:132
pappso::SelectionPolygon::getTopMostPoint
QPointF getTopMostPoint() const
Definition selectionpolygon.cpp:259
pappso::SelectionPolygon::getRightMostPoint
QPointF getRightMostPoint() const
Definition selectionpolygon.cpp:239
pappso::SelectionPolygon::set2D
void set2D(QPointF top_left, QPointF top_right, QPointF bottom_right, QPointF bottom_left)
Definition selectionpolygon.cpp:174
pappso::SelectionPolygon::computeMinMaxCoordinates
bool computeMinMaxCoordinates()
Definition selectionpolygon.cpp:313
pappso::SelectionPolygon::m_maxX
double m_maxX
Definition selectionpolygon.h:134
pappso::SelectionPolygon::getPoints
const std::vector< QPointF > & getPoints() const
Definition selectionpolygon.cpp:299
pappso::SelectionPolygon::copyPoint
void copyPoint(PointSpec point_spec_src, PointSpec point_spec_dest)
Definition selectionpolygon.cpp:132
pappso::SelectionPolygon::m_minX
double m_minX
Definition selectionpolygon.h:131
pappso::SelectionPolygon::is2D
bool is2D() const
Definition selectionpolygon.cpp:643
pappso::SelectionPolygon::width
double width(bool &ok) const
Definition selectionpolygon.cpp:367
pappso::SelectionPolygon::getLeftMostPoint
QPointF getLeftMostPoint() const
Definition selectionpolygon.cpp:219
pappso::SelectionPolygon::operator=
SelectionPolygon & operator=(const SelectionPolygon &other)
Definition selectionpolygon.cpp:578
pappso::SelectionPolygon::getBottomMostPoint
QPointF getBottomMostPoint() const
Definition selectionpolygon.cpp:279
pappso::SelectionPolygon::set1D
void set1D(double x_range_start, double x_range_end)
Definition selectionpolygon.cpp:142
pappso::SelectionPolygon::convertTo1D
void convertTo1D()
Definition selectionpolygon.cpp:206
pappso::SelectionPolygon::isRectangle
bool isRectangle() const
Definition selectionpolygon.cpp:668
pappso::SelectionPolygon::resetPoints
void resetPoints()
Definition selectionpolygon.cpp:603
pappso::SelectionPolygon::getPoint
QPointF getPoint(PointSpec point_spec) const
Definition selectionpolygon.cpp:306
pappso::SelectionPolygon::height
double height(bool &ok) const
Definition selectionpolygon.cpp:382
pappso::SelectionPolygon::contains
bool contains(const QPointF &tested_point) const
Definition selectionpolygon.cpp:476
pappso::SelectionPolygon::SelectionPolygon
SelectionPolygon()
Definition selectionpolygon.cpp:21
pappso::SelectionPolygon::toString
QString toString() const
Definition selectionpolygon.cpp:707
pappso::SelectionPolygon::m_points
std::vector< QPointF > m_points
Definition selectionpolygon.h:122
export-import-config.h
PMSPP_LIB_DECL
#define PMSPP_LIB_DECL
Definition export-import-config.h:14
pappso::Enums::DataKind
DataKind
Definition types.h:249
pappso::Enums::DataKind::dt
@ dt
Drift time.
Definition types.h:252
pappso::Enums::DataKind::mz
@ mz
m/z
Definition types.h:253
pappso::Enums::DataKind::rt
@ rt
Retention time.
Definition types.h:251
pappso::Enums::DataKind::unset
@ unset
not set
Definition types.h:250
pappso::Enums::Axis
Axis
Definition types.h:258
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
pappso::PeptideIonCter::y
@ y
Definition peptide.h:87
pappso::PeptideIonCter::x
@ x
Definition peptide.h:92
pappso::DataDimension
DataDimension
Definition selectionpolygon.h:35
pappso::DataDimension::NOT_SET
@ NOT_SET
Definition selectionpolygon.h:36
pappso::DataDimension::VERTICAL
@ VERTICAL
Definition selectionpolygon.h:38
pappso::DataDimension::HORIZONTAL
@ HORIZONTAL
Definition selectionpolygon.h:37
pappso::PointSpec
PointSpec
Definition selectionpolygon.h:24
pappso::PointSpec::BOTTOM_RIGHT_POINT
@ BOTTOM_RIGHT_POINT
Definition selectionpolygon.h:28
pappso::PointSpec::TOP_LEFT_POINT
@ TOP_LEFT_POINT
Definition selectionpolygon.h:26
pappso::PointSpec::BOTTOM_LEFT_POINT
@ BOTTOM_LEFT_POINT
Definition selectionpolygon.h:29
pappso::PointSpec::ENUM_LAST
@ ENUM_LAST
Definition selectionpolygon.h:30
pappso::PointSpec::TOP_RIGHT_POINT
@ TOP_RIGHT_POINT
Definition selectionpolygon.h:27
pappso::SelectionPolygonSpec
Definition selectionpolygon.h:140
pappso::SelectionPolygonSpec::SelectionPolygonSpec
SelectionPolygonSpec(const SelectionPolygonSpec &other)
Definition selectionpolygon.h:156
pappso::SelectionPolygonSpec::operator=
SelectionPolygonSpec & operator=(const SelectionPolygonSpec &other)
Definition selectionpolygon.h:162
pappso::SelectionPolygonSpec::dataKind
Enums::DataKind dataKind
Definition selectionpolygon.h:143
pappso::SelectionPolygonSpec::SelectionPolygonSpec
SelectionPolygonSpec(const SelectionPolygon &selection_polygon, Enums::DataKind data_kind)
Definition selectionpolygon.h:150
pappso::SelectionPolygonSpec::selectionPolygon
SelectionPolygon selectionPolygon
Definition selectionpolygon.h:142
pappso::SelectionPolygonSpec::toString
QString toString() const
Definition selectionpolygon.h:175
pappso::SelectionPolygonSpec::SelectionPolygonSpec
SelectionPolygonSpec()
types.h