Loading...
Searching...
No Matches
pappso::SelectionPolygon Class Reference

`#include <selectionpolygon.h>`

## Public Member Functions

| 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 Public Member Functions

static void | debugAlgorithm (const SelectionPolygon &selection_polygon, const QPointF &tested_point)

## Protected Attributes

std::vector< QPointF > | m_points
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()

## Detailed Description

Definition at line 43 of file selectionpolygon.h.

## Constructor & Destructor Documentation

## SelectionPolygon() [1/4]

pappso::SelectionPolygon::SelectionPolygon | ( |  | ) |

Definition at line 21 of file selectionpolygon.cpp.

{
// When we create a polygon, we create it as immense as possible, so that
// if this polygon is not modified, any other polygon created on the basis
// of experimental data will fit inside it.
// See the definition of the points in the header file.
}

Referenced by SelectionPolygon(), contains(), debugAlgorithm(), operator=(), and transpose().

## SelectionPolygon() [2/4]

pappso::SelectionPolygon::SelectionPolygon | ( | QPointF | top_left_point,
|  | QPointF | top_right_point )

Definition at line 31 of file selectionpolygon.cpp.

{
// First clear the default values points because we want to push_back
// new points and we want to only ever have 4 points.
m_points.clear();
// We get only two points that provide the horizontal range of the polygon.
// These two points show the x range of the polygon. We need to craft a
// polygon that has:
//
// that specified x range and
//
// the widest y range possible.
// In other words, we are crafting a 1D selection polygon.
// top left point
m_points.push_back(QPointF(top_left_point.x(), std::numeric_limits<double>::max()));
// top right point
m_points.push_back(QPointF(top_right_point.x(), std::numeric_limits<double>::max()));
// bottom right point
m_points.push_back(QPointF(top_right_point.x(), std::numeric_limits<double>::min()));
// bottom left point
m_points.push_back(QPointF(top_left_point.x(), std::numeric_limits<double>::min()));
// Compute the min|max x|y coordinates of the polygon that will be used to
// quickly check if a point is outside.
computeMinMaxCoordinates();
}
pappso::SelectionPolygon::computeMinMaxCoordinates
bool computeMinMaxCoordinates()
Definition selectionpolygon.cpp:313
pappso::SelectionPolygon::m_points
std::vector< QPointF > m_points
Definition selectionpolygon.h:122

References computeMinMaxCoordinates(), and m_points.

## SelectionPolygon() [3/4]

pappso::SelectionPolygon::SelectionPolygon | ( | QPointF | top_left_point,
|  | QPointF | top_right_point,
|  | QPointF | bottom_right_point,
|  | QPointF | bottom_left_point )

Definition at line 65 of file selectionpolygon.cpp.

{
// First clear the default values points.
m_points.clear();
// Attention, we need to push back the points starting top left and clockwise.
m_points.push_back(top_left_point);
m_points.push_back(top_right_point);
m_points.push_back(bottom_right_point);
m_points.push_back(bottom_left_point);
// Compute the min|max x|y coordinates of the polygon that will be used to
// quickly check if a point is outside.
computeMinMaxCoordinates();
}

References computeMinMaxCoordinates(), and m_points.

## SelectionPolygon() [4/4]

pappso::SelectionPolygon::SelectionPolygon | ( | const SelectionPolygon & | other | ) |

Definition at line 86 of file selectionpolygon.cpp.

{
if(other.m_points.size() != static_cast<int>(PointSpec::ENUM_LAST))
qFatal("The template selection polygon must have four points, no less, no more");
// First clear the default values points.
m_points.clear();
for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
{
m_points.push_back(other.m_points[iter]);
}
m_minX = other.m_minX;
m_minY = other.m_minY;
m_maxX = other.m_maxX;
m_maxY = other.m_maxY;
}
pappso::SelectionPolygon::m_maxY
double m_maxY
Definition selectionpolygon.h:135
pappso::SelectionPolygon::m_minY
double m_minY
Definition selectionpolygon.h:132
pappso::SelectionPolygon::m_maxX
double m_maxX
Definition selectionpolygon.h:134
pappso::SelectionPolygon::m_minX
double m_minX
Definition selectionpolygon.h:131
pappso::PointSpec::ENUM_LAST
@ ENUM_LAST
Definition selectionpolygon.h:30

References SelectionPolygon(), pappso::ENUM_LAST, m_maxX, m_maxY, m_minX, m_minY, and m_points.

## ~SelectionPolygon()

pappso::SelectionPolygon::~SelectionPolygon | ( |  | ) |

virtual

Definition at line 107 of file selectionpolygon.cpp.

{
}

## Member Function Documentation

## computeMinMaxCoordinates() [1/2]

bool pappso::SelectionPolygon::computeMinMaxCoordinates | ( |  | ) |

Definition at line 313 of file selectionpolygon.cpp.

{
// Set the variable to starting values that allow easy value comparisons with
// std::min() and std::max() for checking the x|y values below.
m_minX = std::numeric_limits<double>::max();
m_minY = std::numeric_limits<double>::max();
m_maxX = std::numeric_limits<double>::min();
m_maxY = std::numeric_limits<double>::min();
for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
{
m_minX = std::min(m_points.at(iter).x(), m_minX);
m_maxX = std::max(m_points.at(iter).x(), m_maxX);
m_minY = std::min(m_points.at(iter).y(), m_minY);
m_maxY = std::max(m_points.at(iter).y(), m_maxY);
}
return true;
}

References pappso::ENUM_LAST, m_maxX, m_maxY, m_minX, m_minY, and m_points.

Referenced by SelectionPolygon(), SelectionPolygon(), convertTo1D(), copyPoint(), height(), rangeX(), rangeY(), set1D(), set2D(), setPoint(), setPoint(), and width().

## computeMinMaxCoordinates() [2/2]

bool pappso::SelectionPolygon::computeMinMaxCoordinates | ( | double & | min_x,
|  | double & | max_x,
|  | double & | min_y,
|  | double & | max_y ) const

Definition at line 337 of file selectionpolygon.cpp.

{
// Set the variable to starting values that allow easy value comparisons with
// std::min() and std::max() for checking the x|y values below.
min_x = std::numeric_limits<double>::max();
min_y = std::numeric_limits<double>::max();
max_x = std::numeric_limits<double>::min();
max_y = std::numeric_limits<double>::min();
for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
{
min_x = std::min(m_points.at(iter).x(), min_x);
max_x = std::max(m_points.at(iter).x(), max_x);
min_y = std::min(m_points.at(iter).y(), min_y);
max_y = std::max(m_points.at(iter).y(), max_y);
}
// qDebug() << "min_x:" << min_x << "max_x:" << max_x << "min_y:" << min_y
//<< "max_y:" << max_y;
return true;
}

References pappso::ENUM_LAST, and m_points.

## contains() [1/2]

bool pappso::SelectionPolygon::contains | ( | const QPointF & | tested_point | ) | const

Definition at line 476 of file selectionpolygon.cpp.

{
// Easy check: if the point lies outside of most external limits of the
// polygon, return false.
if(tested_point.x() < m_minX || tested_point.x() > m_maxX || tested_point.y() < m_minY ||
tested_point.y() > m_maxY)
{
// qDebug() << "Testing point:" << tested_point
//<< "aginst polygon:" << toString()
//<< "is out of x and y ranges.";
return false;
}
// There are two situations:
//
// 1. The selection polygon is a rectangle, we can check the tested_point very
// easily.
//
// 2. The selection polygon is a skewed rectangle, that is, it is a
// parallelogram, we need to really use the point-in-polygon algorithm.
if(isRectangle())
{
// qDebug() << "Selection polygon *is* rectangle.";
double x = tested_point.x();
double y = tested_point.y();
// return (x >= getPoint(PointSpecs::TOP_LEFT_POINT).x() &&
// x <= getPoint(PointSpecs::TOP_RIGHT_POINT).x() &&
// y >= getPoint(PointSpecs::BOTTOM_LEFT_POINT).y() &&
// y <= getPoint(PointSpecs::TOP_LEFT_POINT).y());
bool res = x >= m_minX && x <= m_maxX && y >= m_minY && y <= m_maxY;
// qDebug() << qSetRealNumberPrecision(10) << "Returning: " << res
//<< "for point:" << tested_point
//<< "and selection polygon:" << toString();
return res;
}
// qDebug() << "Testing point:" << tested_point
//<< "aginst polygon:" << toString()
//<< "is tested against a skewed selection polygon rectangle.";
// At this point, we know the selection polygon is not rectangle, we have to
// make the real check using the point-in-polygon algorithm.
// This code is inspired by the work described here:
// https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html
// int pnpoly(int vertex_count, float *vertx, float *verty, float testx,
// float testy)
int i = 0;
int j = 0;
bool is_inside = false;
int vertex_count = m_points.size();
for(i = 0, j = vertex_count - 1; i < vertex_count; j = i++)
{
if(((m_points.at(i).y() > tested_point.y()) != (m_points.at(j).y() > tested_point.y())) &&
(tested_point.x() < (m_points.at(j).x() - m_points.at(i).x()) *
(tested_point.y() - m_points.at(i).y()) /
(m_points.at(j).y() - m_points.at(i).y()) +
m_points.at(i).x()))
is_inside = !is_inside;
}
// if(is_inside)
// qDebug() << "Testing point:" << tested_point
//<< "aginst polygon:" << toString() << "turns out be in.";
// else
// qDebug() << "Testing point:" << tested_point
//<< "aginst polygon:" << toString() << "turns out be out.";
return is_inside;
}
pappso::SelectionPolygon::isRectangle
bool isRectangle() const
Definition selectionpolygon.cpp:668
pappso::Enums::PrecisionUnit::res
@ res
Definition types.h:100
pappso::PeptideIonCter::y
@ y
Definition peptide.h:87
pappso::PeptideIonCter::x
@ x
Definition peptide.h:92

References isRectangle(), m_maxX, m_maxY, m_minX, m_minY, m_points, pappso::x, and pappso::y.

Referenced by contains(), and debugAlgorithm().

## contains() [2/2]

bool pappso::SelectionPolygon::contains | ( | const SelectionPolygon & | selection_polygon | ) | const

Definition at line 560 of file selectionpolygon.cpp.

{
// A polygon is inside another polygon if all its points are inside the
// polygon.
bool is_inside = true;
for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
{
if(!contains(selection_polygon.getPoint(static_cast<PointSpec>(iter))))
is_inside = false;
}
return is_inside;
}
pappso::SelectionPolygon::contains
bool contains(const QPointF &tested_point) const
Definition selectionpolygon.cpp:476
pappso::PointSpec
PointSpec
Definition selectionpolygon.h:24

References SelectionPolygon(), contains(), pappso::ENUM_LAST, and getPoint().

## convertTo1D()

void pappso::SelectionPolygon::convertTo1D | ( |  | ) |

Definition at line 206 of file selectionpolygon.cpp.

{
// When a 2D polygon is converted to a 1D polygon, the x axis range is
// unchanged, but the height is set to its maximum possible with the bottom
// line at y = min and the top line at y = max.
computeMinMaxCoordinates();
set1D(m_minX, m_maxX);
}
pappso::SelectionPolygon::set1D
void set1D(double x_range_start, double x_range_end)
Definition selectionpolygon.cpp:142

References computeMinMaxCoordinates(), m_maxX, m_minX, and set1D().

## copyPoint()

void pappso::SelectionPolygon::copyPoint | ( | PointSpec | point_spec_src,
|  | PointSpec | point_spec_dest )

Definition at line 132 of file selectionpolygon.cpp.

{
QPointF src_point = getPoint(point_spec_src);
setPoint(point_spec_dest, src_point);
computeMinMaxCoordinates();
}
pappso::SelectionPolygon::setPoint
void setPoint(PointSpec point_spec, double x, double y)
Definition selectionpolygon.cpp:113
pappso::SelectionPolygon::getPoint
QPointF getPoint(PointSpec point_spec) const
Definition selectionpolygon.cpp:306

References computeMinMaxCoordinates(), getPoint(), and setPoint().

## debugAlgorithm()

void pappso::SelectionPolygon::debugAlgorithm | ( | const SelectionPolygon & | selection_polygon,
|  | const QPointF & | tested_point )

static

Definition at line 813 of file selectionpolygon.cpp.

{
bool is_point_inside = false;
QString debug_string;
is_point_inside = selection_polygon.contains(tested_point);
debug_string = QString("(%1,%2) is inside: %3")
.arg(tested_point.x(), 0, 'f', 10)
.arg(tested_point.y(), 0, 'f', 10)
.arg(is_point_inside ? "true" : "false");
qDebug().noquote() << debug_string;
}

References SelectionPolygon(), and contains().

## getBottomMostPoint()

QPointF pappso::SelectionPolygon::getBottomMostPoint | ( |  | ) | const

Definition at line 279 of file selectionpolygon.cpp.

{
// When we say topmost or bottommost , that means that we are implicitely
// interesed in y-axis coordinate of the points.
QPointF temp_point(0, std::numeric_limits<double>::max());
for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
{
if(m_points[iter].y() < temp_point.y())
{
temp_point = m_points[iter];
}
}
return temp_point;
}

References pappso::ENUM_LAST, m_points, and pappso::y.

## getLeftMostPoint()

QPointF pappso::SelectionPolygon::getLeftMostPoint | ( |  | ) | const

Definition at line 219 of file selectionpolygon.cpp.

{
// When we say leftmost, that means that we are implicitely interesed in
// x-axis coordinate of the points.
QPointF temp_point(std::numeric_limits<double>::max(), 0);
for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
{
if(m_points[iter].x() < temp_point.x())
{
temp_point = m_points[iter];
}
}
return temp_point;
}

References pappso::ENUM_LAST, m_points, and pappso::x.

Referenced by toShort4PointsString().

## getPoint()

QPointF pappso::SelectionPolygon::getPoint | ( | PointSpec | point_spec | ) | const

Definition at line 306 of file selectionpolygon.cpp.

{
return m_points[static_cast<int>(point_spec)];
}

References m_points.

Referenced by contains(), copyPoint(), isRectangle(), and transpose().

## getPoints()

const std::vector< QPointF > & pappso::SelectionPolygon::getPoints | ( |  | ) | const

Definition at line 299 of file selectionpolygon.cpp.

{
return m_points;
}

References m_points.

## getRightMostPoint()

QPointF pappso::SelectionPolygon::getRightMostPoint | ( |  | ) | const

Definition at line 239 of file selectionpolygon.cpp.

{
// When we say rightmost, that means that we are implicitely interesed in
// x-axis coordinate of the points.
QPointF temp_point(std::numeric_limits<double>::min(), 0);
for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
{
if(m_points[iter].x() > temp_point.x())
{
temp_point = m_points[iter];
}
}
return temp_point;
}

References pappso::ENUM_LAST, m_points, and pappso::x.

Referenced by toShort4PointsString().

## getTopMostPoint()

QPointF pappso::SelectionPolygon::getTopMostPoint | ( |  | ) | const

Definition at line 259 of file selectionpolygon.cpp.

{
// When we say topmost or bottommost , that means that we are implicitely
// interesed in y-axis coordinate of the points.
QPointF temp_point(0, std::numeric_limits<double>::min());
for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
{
if(m_points[iter].y() > temp_point.y())
{
temp_point = m_points[iter];
}
}
return temp_point;
}

References pappso::ENUM_LAST, m_points, and pappso::y.

## height()

double pappso::SelectionPolygon::height | ( | bool & | ok | ) | const

Definition at line 382 of file selectionpolygon.cpp.

{
double min_x;
double min_y;
double max_x;
double max_y;
computeMinMaxCoordinates(min_x, max_x, min_y, max_y);
ok = true;
return max_y - min_y;
}

References computeMinMaxCoordinates().

Referenced by is1D(), and is2D().

## is1D()

bool pappso::SelectionPolygon::is1D | ( |  | ) | const

Definition at line 616 of file selectionpolygon.cpp.

{
// qDebug() << "Selection polygon:" << toString();
bool ok = false;
double width_value = width(ok);
if(!ok)
return false;
double height_value = height(ok);
if(!ok)
return false;
// qDebug() << "Width and height computations succeeded:"
//<< "width:" << width_value << "height:" << height_value;
// A polygon is mono-dimensional if it has both non-0 width and no (max-min)
// width AND if the height is 0 or (max-min).
return ((width_value > 0 &&
width_value < std::numeric_limits<double>::max() - std::numeric_limits<double>::min()) &&
(height_value == 0 || height_value == std::numeric_limits<double>::max() -
std::numeric_limits<double>::min()));
}
pappso::SelectionPolygon::width
double width(bool &ok) const
Definition selectionpolygon.cpp:367
pappso::SelectionPolygon::height
double height(bool &ok) const
Definition selectionpolygon.cpp:382

References height(), and width().

Referenced by toShort4PointsString().

## is2D()

bool pappso::SelectionPolygon::is2D | ( |  | ) | const

Definition at line 643 of file selectionpolygon.cpp.

{
// A selection polygon can behave like a line segment if the bottom side
// confounds with the top side.
bool ok = false;
double width_value = width(ok);
if(!ok)
return false;
double height_value = height(ok);
if(!ok)
return false;
// A polygon is two-dimensional if it has both non-0 width and no (max-min)
// width AND same for height.
return ((width_value > 0 &&
width_value < std::numeric_limits<double>::max() - std::numeric_limits<double>::min()) &&
(height_value > 0 &&
height_value < std::numeric_limits<double>::max() - std::numeric_limits<double>::min()));
}

References height(), and width().

## isRectangle()

bool pappso::SelectionPolygon::isRectangle | ( |  | ) | const

Definition at line 668 of file selectionpolygon.cpp.

{
// A skewed rectangle polygon has the following conditions verified:
//
// 1. If its left|right sides are vertical, then its top|bottom lines are
// *not* horizontal.
//
// 2 If its top|bottom lines are horizontal, then its left|right sides are
// *not* vertical.
//
// 3. Then, if a selection polygon is rectangle, its top|bottom lines are
// horizontal and its left|right lines are vertical.
// A line is vertical if its two defining points have the same X.
// A line is horizontal if its two defining points have the same Y.
// Try the horiontal top|bottom lines.
if(getPoint(PointSpec::TOP_LEFT_POINT).y() == getPoint(PointSpec::TOP_RIGHT_POINT).y() &&
getPoint(PointSpec::BOTTOM_LEFT_POINT).y() == getPoint(PointSpec::BOTTOM_RIGHT_POINT).y())
{
// We have horizontal top|bottom lines
// Try the vertical lines
if(getPoint(PointSpec::TOP_LEFT_POINT).x() == getPoint(PointSpec::BOTTOM_LEFT_POINT).x() &&
getPoint(PointSpec::TOP_RIGHT_POINT).x() == getPoint(PointSpec::BOTTOM_RIGHT_POINT).x())
{
// The top|bottom lines are vertical
return true;
}
}
return false;
}
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::TOP_RIGHT_POINT
@ TOP_RIGHT_POINT
Definition selectionpolygon.h:27

References pappso::BOTTOM_LEFT_POINT, pappso::BOTTOM_RIGHT_POINT, getPoint(), pappso::TOP_LEFT_POINT, pappso::TOP_RIGHT_POINT, pappso::x, and pappso::y.

Referenced by contains().

## operator=()

SelectionPolygon & pappso::SelectionPolygon::operator= | ( | const SelectionPolygon & | other | ) |

Definition at line 578 of file selectionpolygon.cpp.

{
if(this == &other)
return *this;
if(other.m_points.size() != static_cast<int>(PointSpec::ENUM_LAST))
qFatal("Programming error.");
if(m_points.size() != static_cast<int>(PointSpec::ENUM_LAST))
qFatal("Programming error.");
for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
m_points[iter] = other.m_points[iter];
m_minX = other.m_minX;
m_minY = other.m_minY;
m_maxX = other.m_maxX;
m_maxY = other.m_maxY;
return *this;
}

References SelectionPolygon(), pappso::ENUM_LAST, m_maxX, m_maxY, m_minX, m_minY, and m_points.

## range()

bool pappso::SelectionPolygon::range | ( | Enums::Axis | axis,
|  | double & | range_start,
|  | double & | range_end ) const

Definition at line 417 of file selectionpolygon.cpp.

{
if(axis == Enums::Axis::x)
return rangeX(range_start, range_end);
else if(axis == Enums::Axis::y)
return rangeY(range_start, range_end);
return false;
}
pappso::SelectionPolygon::rangeX
bool rangeX(double &range_start, double &range_end) const
Definition selectionpolygon.cpp:397
pappso::SelectionPolygon::rangeY
bool rangeY(double &range_start, double &range_end) const
Definition selectionpolygon.cpp:407
pappso::Enums::Axis::y
@ y
Definition types.h:261
pappso::Enums::Axis::x
@ x
Definition types.h:260

References rangeX(), rangeY(), pappso::Enums::x, and pappso::Enums::y.

## rangeX()

bool pappso::SelectionPolygon::rangeX | ( | double & | range_start,
|  | double & | range_end ) const

Definition at line 397 of file selectionpolygon.cpp.

{
double min_y = std::numeric_limits<double>::max();
double max_y = std::numeric_limits<double>::min();
return computeMinMaxCoordinates(range_start, range_end, min_y, max_y);
}

References computeMinMaxCoordinates().

Referenced by range().

## rangeY()

bool pappso::SelectionPolygon::rangeY | ( | double & | range_start,
|  | double & | range_end ) const

Definition at line 407 of file selectionpolygon.cpp.

{
double min_x = std::numeric_limits<double>::max();
double max_x = std::numeric_limits<double>::min();
return computeMinMaxCoordinates(min_x, max_x, range_start, range_end);
}

References computeMinMaxCoordinates().

Referenced by range().

## resetPoints()

void pappso::SelectionPolygon::resetPoints | ( |  | ) |

Definition at line 603 of file selectionpolygon.cpp.

{
// Reset the points exactly as they were set upon construction of an empty
// polygon.
m_points[0] = QPointF(std::numeric_limits<double>::min(), std::numeric_limits<double>::max());
m_points[0] = QPointF(std::numeric_limits<double>::max(), std::numeric_limits<double>::max());
m_points[0] = QPointF(std::numeric_limits<double>::max(), std::numeric_limits<double>::min());
m_points[0] = QPointF(std::numeric_limits<double>::min(), std::numeric_limits<double>::max());
}

References m_points.

Referenced by set1D(), and set2D().

## set1D()

void pappso::SelectionPolygon::set1D | ( | double | x_range_start,
|  | double | x_range_end )

Definition at line 142 of file selectionpolygon.cpp.

{
// We get only two points that provide the horizontal range of the polygon.
// These two points show the x range of the polygon. We need to craft a
// polygon that has:
//
// that specified x range and
//
// the widest y range possible.
resetPoints();
// top left point
setPoint(PointSpec::TOP_LEFT_POINT, QPointF(x_range_start, std::numeric_limits<double>::max()));
// top right point
setPoint(PointSpec::TOP_RIGHT_POINT, QPointF(x_range_end, std::numeric_limits<double>::max()));
// bottom right point
setPoint(PointSpec::BOTTOM_RIGHT_POINT, QPointF(x_range_end, std::numeric_limits<double>::min()));
// bottom left point
setPoint(PointSpec::BOTTOM_LEFT_POINT,
QPointF(x_range_start, std::numeric_limits<double>::min()));
// Compute the min|max x|y coordinates of the polygon that will be used to
// quickly check if a point is outside.
computeMinMaxCoordinates();
}
pappso::SelectionPolygon::resetPoints
void resetPoints()
Definition selectionpolygon.cpp:603

References pappso::BOTTOM_LEFT_POINT, pappso::BOTTOM_RIGHT_POINT, computeMinMaxCoordinates(), resetPoints(), setPoint(), pappso::TOP_LEFT_POINT, and pappso::TOP_RIGHT_POINT.

Referenced by convertTo1D().

## set2D()

void pappso::SelectionPolygon::set2D | ( | QPointF | top_left,
|  | QPointF | top_right,
|  | QPointF | bottom_right,
|  | QPointF | bottom_left )

Definition at line 174 of file selectionpolygon.cpp.

{
resetPoints();
// top left point
setPoint(PointSpec::TOP_LEFT_POINT, top_left);
// qDebug() << "PointSpecs::TOP_LEFT_POINT:" << top_left;
// top right point
setPoint(PointSpec::TOP_RIGHT_POINT, top_right);
// qDebug() << "PointSpecs::TOP_RIGHT_POINT:" << top_right;
// bottom right point
setPoint(PointSpec::BOTTOM_RIGHT_POINT, bottom_right);
// qDebug() << "PointSpecs::BOTTOM_RIGHT_POINT:" << bottom_right;
// bottom left point
setPoint(PointSpec::BOTTOM_LEFT_POINT, bottom_left);
// qDebug() << "PointSpecs::BOTTOM_LEFT_POINT:" << bottom_left;
// Compute the min|max x|y coordinates of the polygon that will be used to
// quickly check if a point is outside.
computeMinMaxCoordinates();
// qDebug() << toString();
}

References pappso::BOTTOM_LEFT_POINT, pappso::BOTTOM_RIGHT_POINT, computeMinMaxCoordinates(), resetPoints(), setPoint(), pappso::TOP_LEFT_POINT, and pappso::TOP_RIGHT_POINT.

## setPoint() [1/2]

void pappso::SelectionPolygon::setPoint | ( | PointSpec | point_spec,
|  | double | x,
|  | double | y )

Definition at line 113 of file selectionpolygon.cpp.

{
m_points[static_cast<int>(point_spec)].setX(x);
m_points[static_cast<int>(point_spec)].setY(y);
computeMinMaxCoordinates();
}

References computeMinMaxCoordinates(), m_points, pappso::x, and pappso::y.

Referenced by copyPoint(), set1D(), set2D(), setPoint(), and transpose().

## setPoint() [2/2]

void pappso::SelectionPolygon::setPoint | ( | PointSpec | point_spec,
|  | QPointF | point )

Definition at line 123 of file selectionpolygon.cpp.

{
setPoint(point_spec, point.x(), point.y());
computeMinMaxCoordinates();
}

References computeMinMaxCoordinates(), and setPoint().

## toShort4PointsString()

QString pappso::SelectionPolygon::toShort4PointsString | ( |  | ) | const

Definition at line 762 of file selectionpolygon.cpp.

{
// By essence, a selection polygon is designed to always have 4 points.
if(m_points.size() != static_cast<int>(PointSpec::ENUM_LAST))
qFatal("Programming error.");
// qDebug() << "size:" << m_points.size();
QString text = "[";
QString x_string = "NOT_SET";
QString y_string = "NOT_SET";
// There are two situations:
//
// 1. The selection polygon is 1D, we only need to provide two points
//
// 2. The selection polygon is 2D, we need to provide four points.
if(is1D())
{
text += QString("(%1,%2)").arg(getLeftMostPoint().x()).arg("NOT_SET");
text += QString("(%1,%2)").arg(getRightMostPoint().x()).arg("NOT_SET");
}
else
{
for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
{
QPointF iter_point = m_points[iter];
if(iter_point.x() != std::numeric_limits<double>::min() &&
iter_point.x() != std::numeric_limits<double>::max())
x_string = QString("%1").arg(iter_point.x(), 0, 'f', 3);
if(iter_point.y() != std::numeric_limits<double>::min() &&
iter_point.y() != std::numeric_limits<double>::max())
y_string = QString("%1").arg(iter_point.y(), 0, 'f', 3);
text += QString("(%1,%2)").arg(x_string).arg(y_string);
}
}
text += "]";
return text;
}
pappso::SelectionPolygon::is1D
bool is1D() const
Definition selectionpolygon.cpp:616
pappso::SelectionPolygon::getRightMostPoint
QPointF getRightMostPoint() const
Definition selectionpolygon.cpp:239
pappso::SelectionPolygon::getLeftMostPoint
QPointF getLeftMostPoint() const
Definition selectionpolygon.cpp:219

References pappso::ENUM_LAST, getLeftMostPoint(), getRightMostPoint(), is1D(), m_points, and pappso::x.

## toString()

QString pappso::SelectionPolygon::toString | ( |  | ) | const

Definition at line 707 of file selectionpolygon.cpp.

{
// By essence, a selection polygon is designed to always have 4 points.
if(m_points.size() != static_cast<int>(PointSpec::ENUM_LAST))
qFatal("Programming error.");
// qDebug() << "size:" << m_points.size();
QString text = "Selection polygon points, from top left, clockwise\n";
for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
{
QPointF iter_point = m_points[iter];
QString x_string = "NOT_SET";
if(iter_point.x() != std::numeric_limits<double>::min() &&
iter_point.x() != std::numeric_limits<double>::max())
x_string = QString("%1").arg(iter_point.x(), 0, 'f', 10);
QString y_string = "NOT_SET";
if(iter_point.y() != std::numeric_limits<double>::min() &&
iter_point.y() != std::numeric_limits<double>::max())
y_string = QString("%1").arg(iter_point.y(), 0, 'f', 10);
text += QString("(%1,%2)\n").arg(x_string).arg(y_string);
}
if(m_minX != std::numeric_limits<double>::min() && m_minX != std::numeric_limits<double>::max())
text += QString("minX: %1 - ").arg(m_minX, 0, 'f', 10);
else
text += QString("minX: NOT_SET - ");
if(m_maxX != std::numeric_limits<double>::min() && m_maxX != std::numeric_limits<double>::max())
text += QString("maxX: %1 - ").arg(m_maxX, 0, 'f', 10);
else
text += QString("maxX: NOT_SET - ");
if(m_minY != std::numeric_limits<double>::min() && m_minY != std::numeric_limits<double>::max())
text += QString("minY: %1 - ").arg(m_minY, 0, 'f', 10);
else
text += QString("minY: NOT_SET - ");
if(m_maxY != std::numeric_limits<double>::min() && m_maxY != std::numeric_limits<double>::max())
text += QString("maxY: %1 - ").arg(m_maxY, 0, 'f', 10);
else
text += QString("maxY: NOT_SET - ");
return text;
}

References pappso::ENUM_LAST, m_maxX, m_maxY, m_minX, m_minY, and m_points.

## transpose()

SelectionPolygon pappso::SelectionPolygon::transpose | ( |  | ) | const

Definition at line 442 of file selectionpolygon.cpp.

{
SelectionPolygon selection_polygon;
// Make sure we do this for a polygon with four sides.
if(m_points.size() != static_cast<int>(PointSpec::ENUM_LAST))
qFatal("The polygon must have four points, no less, no more");
// The two invariant points, that is, the two points that do no change
// position in the polygon corners. Of course, x becomes y.
selection_polygon.setPoint(
PointSpec::TOP_RIGHT_POINT,
QPointF(getPoint(PointSpec::TOP_RIGHT_POINT).y(), getPoint(PointSpec::TOP_RIGHT_POINT).x()));
selection_polygon.setPoint(PointSpec::BOTTOM_LEFT_POINT,
QPointF(getPoint(PointSpec::BOTTOM_LEFT_POINT).y(),
getPoint(PointSpec::BOTTOM_LEFT_POINT).x()));
// The two other points.
selection_polygon.setPoint(
PointSpec::BOTTOM_RIGHT_POINT,
QPointF(getPoint(PointSpec::TOP_LEFT_POINT).y(), getPoint(PointSpec::TOP_LEFT_POINT).x()));
selection_polygon.setPoint(PointSpec::TOP_LEFT_POINT,
QPointF(getPoint(PointSpec::BOTTOM_RIGHT_POINT).y(),
getPoint(PointSpec::BOTTOM_RIGHT_POINT).x()));
return selection_polygon;
}
pappso::SelectionPolygon::SelectionPolygon
SelectionPolygon()
Definition selectionpolygon.cpp:21

References SelectionPolygon(), pappso::BOTTOM_LEFT_POINT, pappso::BOTTOM_RIGHT_POINT, pappso::ENUM_LAST, getPoint(), m_points, setPoint(), pappso::TOP_LEFT_POINT, pappso::TOP_RIGHT_POINT, pappso::x, and pappso::y.

## width()

double pappso::SelectionPolygon::width | ( | bool & | ok | ) | const

Definition at line 367 of file selectionpolygon.cpp.

{
double min_x;
double min_y;
double max_x;
double max_y;
computeMinMaxCoordinates(min_x, max_x, min_y, max_y);
ok = true;
return max_x - min_x;
}

References computeMinMaxCoordinates().

Referenced by is1D(), and is2D().

## Member Data Documentation

## m_maxX

double pappso::SelectionPolygon::m_maxX = std::numeric_limits<double>::max()

protected

Definition at line 134 of file selectionpolygon.h.

Referenced by SelectionPolygon(), computeMinMaxCoordinates(), contains(), convertTo1D(), operator=(), and toString().

## m_maxY

double pappso::SelectionPolygon::m_maxY = std::numeric_limits<double>::max()

protected

Definition at line 135 of file selectionpolygon.h.

Referenced by SelectionPolygon(), computeMinMaxCoordinates(), contains(), operator=(), and toString().

## m_minX

double pappso::SelectionPolygon::m_minX = std::numeric_limits<double>::min()

protected

Definition at line 131 of file selectionpolygon.h.

Referenced by SelectionPolygon(), computeMinMaxCoordinates(), contains(), convertTo1D(), operator=(), and toString().

## m_minY

double pappso::SelectionPolygon::m_minY = std::numeric_limits<double>::min()

protected

Definition at line 132 of file selectionpolygon.h.

Referenced by SelectionPolygon(), computeMinMaxCoordinates(), contains(), operator=(), and toString().

## m_points

std::vector<QPointF> pappso::SelectionPolygon::m_points

protected

Initial value:
= {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())}

Definition at line 122 of file selectionpolygon.h.

{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())};

Referenced by SelectionPolygon(), SelectionPolygon(), SelectionPolygon(), computeMinMaxCoordinates(), computeMinMaxCoordinates(), contains(), getBottomMostPoint(), getLeftMostPoint(), getPoint(), getPoints(), getRightMostPoint(), getTopMostPoint(), operator=(), resetPoints(), setPoint(), toShort4PointsString(), toString(), and transpose().

The documentation for this class was generated from the following files:

- pappsomspp/core/processing/combiners/selectionpolygon.h
- pappsomspp/core/processing/combiners/selectionpolygon.cpp