libpappsomspp
Library for mass spectrometry
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
SelectionPolygonoperator= (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.

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

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.

32{
33 // First clear the default values points because we want to push_back
34 // new points and we want to only ever have 4 points.
35 m_points.clear();
36
37 // We get only two points that provide the horizontal range of the polygon.
38 // These two points show the x range of the polygon. We need to craft a
39 // polygon that has:
40 //
41 // that specified x range and
42 //
43 // the widest y range possible.
44
45 // In other words, we are crafting a 1D selection polygon.
46
47 // top left point
48 m_points.push_back(QPointF(top_left_point.x(), std::numeric_limits<double>::max()));
49
50 // top right point
51 m_points.push_back(QPointF(top_right_point.x(), std::numeric_limits<double>::max()));
52
53 // bottom right point
54 m_points.push_back(QPointF(top_right_point.x(), std::numeric_limits<double>::min()));
55
56 // bottom left point
57 m_points.push_back(QPointF(top_left_point.x(), std::numeric_limits<double>::min()));
58
59 // Compute the min|max x|y coordinates of the polygon that will be used to
60 // quickly check if a point is outside.
62}
std::vector< QPointF > m_points

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.

69{
70 // First clear the default values points.
71 m_points.clear();
72
73 // Attention, we need to push back the points starting top left and clockwise.
74
75 m_points.push_back(top_left_point);
76 m_points.push_back(top_right_point);
77 m_points.push_back(bottom_right_point);
78 m_points.push_back(bottom_left_point);
79
80 // Compute the min|max x|y coordinates of the polygon that will be used to
81 // quickly check if a point is outside.
83}

References computeMinMaxCoordinates(), and m_points.

◆ SelectionPolygon() [4/4]

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

Definition at line 86 of file selectionpolygon.cpp.

87{
88 if(other.m_points.size() != static_cast<int>(PointSpec::ENUM_LAST))
89 qFatal("The template selection polygon must have four points, no less, no more");
90
91 // First clear the default values points.
92 m_points.clear();
93
94 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
95 {
96 m_points.push_back(other.m_points[iter]);
97 }
98
99 m_minX = other.m_minX;
100 m_minY = other.m_minY;
101
102 m_maxX = other.m_maxX;
103 m_maxY = other.m_maxY;
104}

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.

108{
109}

Member Function Documentation

◆ computeMinMaxCoordinates() [1/2]

bool pappso::SelectionPolygon::computeMinMaxCoordinates ( )

Definition at line 313 of file selectionpolygon.cpp.

314{
315 // Set the variable to starting values that allow easy value comparisons with
316 // std::min() and std::max() for checking the x|y values below.
317
318 m_minX = std::numeric_limits<double>::max();
319 m_minY = std::numeric_limits<double>::max();
320 m_maxX = std::numeric_limits<double>::min();
321 m_maxY = std::numeric_limits<double>::min();
322
323 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
324 {
325 m_minX = std::min(m_points.at(iter).x(), m_minX);
326 m_maxX = std::max(m_points.at(iter).x(), m_maxX);
327
328 m_minY = std::min(m_points.at(iter).y(), m_minY);
329 m_maxY = std::max(m_points.at(iter).y(), m_maxY);
330 }
331
332 return true;
333}

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.

341{
342 // Set the variable to starting values that allow easy value comparisons with
343 // std::min() and std::max() for checking the x|y values below.
344
345 min_x = std::numeric_limits<double>::max();
346 min_y = std::numeric_limits<double>::max();
347 max_x = std::numeric_limits<double>::min();
348 max_y = std::numeric_limits<double>::min();
349
350 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
351 {
352 min_x = std::min(m_points.at(iter).x(), min_x);
353 max_x = std::max(m_points.at(iter).x(), max_x);
354
355 min_y = std::min(m_points.at(iter).y(), min_y);
356 max_y = std::max(m_points.at(iter).y(), max_y);
357 }
358
359 // qDebug() << "min_x:" << min_x << "max_x:" << max_x << "min_y:" << min_y
360 //<< "max_y:" << max_y;
361
362 return true;
363}

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.

477{
478 // Easy check: if the point lies outside of most external limits of the
479 // polygon, return false.
480
481 if(tested_point.x() < m_minX || tested_point.x() > m_maxX || tested_point.y() < m_minY ||
482 tested_point.y() > m_maxY)
483 {
484 // qDebug() << "Testing point:" << tested_point
485 //<< "aginst polygon:" << toString()
486 //<< "is out of x and y ranges.";
487 return false;
488 }
489
490 // There are two situations:
491 //
492 // 1. The selection polygon is a rectangle, we can check the tested_point very
493 // easily.
494 //
495 // 2. The selection polygon is a skewed rectangle, that is, it is a
496 // parallelogram, we need to really use the point-in-polygon algorithm.
497
498 if(isRectangle())
499 {
500 // qDebug() << "Selection polygon *is* rectangle.";
501
502 double x = tested_point.x();
503 double y = tested_point.y();
504
505 // return (x >= getPoint(PointSpecs::TOP_LEFT_POINT).x() &&
506 // x <= getPoint(PointSpecs::TOP_RIGHT_POINT).x() &&
507 // y >= getPoint(PointSpecs::BOTTOM_LEFT_POINT).y() &&
508 // y <= getPoint(PointSpecs::TOP_LEFT_POINT).y());
509
510 bool res = x >= m_minX && x <= m_maxX && y >= m_minY && y <= m_maxY;
511
512 // qDebug() << qSetRealNumberPrecision(10) << "Returning: " << res
513 //<< "for point:" << tested_point
514 //<< "and selection polygon:" << toString();
515
516 return res;
517 }
518
519 // qDebug() << "Testing point:" << tested_point
520 //<< "aginst polygon:" << toString()
521 //<< "is tested against a skewed selection polygon rectangle.";
522
523 // At this point, we know the selection polygon is not rectangle, we have to
524 // make the real check using the point-in-polygon algorithm.
525
526 // This code is inspired by the work described here:
527 // https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html
528
529 // int pnpoly(int vertex_count, float *vertx, float *verty, float testx,
530 // float testy)
531
532 int i = 0;
533 int j = 0;
534 bool is_inside = false;
535
536 int vertex_count = m_points.size();
537
538 for(i = 0, j = vertex_count - 1; i < vertex_count; j = i++)
539 {
540 if(((m_points.at(i).y() > tested_point.y()) != (m_points.at(j).y() > tested_point.y())) &&
541 (tested_point.x() < (m_points.at(j).x() - m_points.at(i).x()) *
542 (tested_point.y() - m_points.at(i).y()) /
543 (m_points.at(j).y() - m_points.at(i).y()) +
544 m_points.at(i).x()))
545 is_inside = !is_inside;
546 }
547
548 // if(is_inside)
549 // qDebug() << "Testing point:" << tested_point
550 //<< "aginst polygon:" << toString() << "turns out be in.";
551 // else
552 // qDebug() << "Testing point:" << tested_point
553 //<< "aginst polygon:" << toString() << "turns out be out.";
554
555 return is_inside;
556}

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.

561{
562 // A polygon is inside another polygon if all its points are inside the
563 // polygon.
564
565 bool is_inside = true;
566
567 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
568 {
569 if(!contains(selection_polygon.getPoint(static_cast<PointSpec>(iter))))
570 is_inside = false;
571 }
572
573 return is_inside;
574}
bool contains(const QPointF &tested_point) const

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

◆ convertTo1D()

void pappso::SelectionPolygon::convertTo1D ( )

Definition at line 206 of file selectionpolygon.cpp.

207{
208 // When a 2D polygon is converted to a 1D polygon, the x axis range is
209 // unchanged, but the height is set to its maximum possible with the bottom
210 // line at y = min and the top line at y = max.
211
213
215}
void set1D(double x_range_start, double x_range_end)

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.

133{
134 QPointF src_point = getPoint(point_spec_src);
135 setPoint(point_spec_dest, src_point);
136
138}
void setPoint(PointSpec point_spec, double x, double y)
QPointF getPoint(PointSpec point_spec) const

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.

815{
816 bool is_point_inside = false;
817
818 QString debug_string;
819
820 is_point_inside = selection_polygon.contains(tested_point);
821 debug_string = QString("(%1,%2) is inside: %3")
822 .arg(tested_point.x(), 0, 'f', 10)
823 .arg(tested_point.y(), 0, 'f', 10)
824 .arg(is_point_inside ? "true" : "false");
825 qDebug().noquote() << debug_string;
826}

References SelectionPolygon(), and contains().

◆ getBottomMostPoint()

QPointF pappso::SelectionPolygon::getBottomMostPoint ( ) const

Definition at line 279 of file selectionpolygon.cpp.

280{
281 // When we say topmost or bottommost , that means that we are implicitely
282 // interesed in y-axis coordinate of the points.
283
284 QPointF temp_point(0, std::numeric_limits<double>::max());
285
286 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
287 {
288 if(m_points[iter].y() < temp_point.y())
289 {
290 temp_point = m_points[iter];
291 }
292 }
293
294 return temp_point;
295}

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

◆ getLeftMostPoint()

QPointF pappso::SelectionPolygon::getLeftMostPoint ( ) const

Definition at line 219 of file selectionpolygon.cpp.

220{
221 // When we say leftmost, that means that we are implicitely interesed in
222 // x-axis coordinate of the points.
223
224 QPointF temp_point(std::numeric_limits<double>::max(), 0);
225
226 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
227 {
228 if(m_points[iter].x() < temp_point.x())
229 {
230 temp_point = m_points[iter];
231 }
232 }
233
234 return temp_point;
235}

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.

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

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.

300{
301 return m_points;
302}

References m_points.

◆ getRightMostPoint()

QPointF pappso::SelectionPolygon::getRightMostPoint ( ) const

Definition at line 239 of file selectionpolygon.cpp.

240{
241 // When we say rightmost, that means that we are implicitely interesed in
242 // x-axis coordinate of the points.
243
244 QPointF temp_point(std::numeric_limits<double>::min(), 0);
245
246 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
247 {
248 if(m_points[iter].x() > temp_point.x())
249 {
250 temp_point = m_points[iter];
251 }
252 }
253
254 return temp_point;
255}

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.

260{
261 // When we say topmost or bottommost , that means that we are implicitely
262 // interesed in y-axis coordinate of the points.
263
264 QPointF temp_point(0, std::numeric_limits<double>::min());
265
266 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
267 {
268 if(m_points[iter].y() > temp_point.y())
269 {
270 temp_point = m_points[iter];
271 }
272 }
273
274 return temp_point;
275}

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.

383{
384 double min_x;
385 double min_y;
386 double max_x;
387 double max_y;
388
389 computeMinMaxCoordinates(min_x, max_x, min_y, max_y);
390
391 ok = true;
392 return max_y - min_y;
393}

References computeMinMaxCoordinates().

Referenced by is1D(), and is2D().

◆ is1D()

bool pappso::SelectionPolygon::is1D ( ) const

Definition at line 616 of file selectionpolygon.cpp.

617{
618 // qDebug() << "Selection polygon:" << toString();
619
620 bool ok = false;
621
622 double width_value = width(ok);
623 if(!ok)
624 return false;
625
626 double height_value = height(ok);
627 if(!ok)
628 return false;
629
630 // qDebug() << "Width and height computations succeeded:"
631 //<< "width:" << width_value << "height:" << height_value;
632
633 // A polygon is mono-dimensional if it has both non-0 width and no (max-min)
634 // width AND if the height is 0 or (max-min).
635 return ((width_value > 0 &&
636 width_value < std::numeric_limits<double>::max() - std::numeric_limits<double>::min()) &&
637 (height_value == 0 || height_value == std::numeric_limits<double>::max() -
638 std::numeric_limits<double>::min()));
639}
double width(bool &ok) const
double height(bool &ok) const

References height(), and width().

Referenced by toShort4PointsString().

◆ is2D()

bool pappso::SelectionPolygon::is2D ( ) const

Definition at line 643 of file selectionpolygon.cpp.

644{
645 // A selection polygon can behave like a line segment if the bottom side
646 // confounds with the top side.
647
648 bool ok = false;
649
650 double width_value = width(ok);
651 if(!ok)
652 return false;
653
654 double height_value = height(ok);
655 if(!ok)
656 return false;
657
658 // A polygon is two-dimensional if it has both non-0 width and no (max-min)
659 // width AND same for height.
660 return ((width_value > 0 &&
661 width_value < std::numeric_limits<double>::max() - std::numeric_limits<double>::min()) &&
662 (height_value > 0 &&
663 height_value < std::numeric_limits<double>::max() - std::numeric_limits<double>::min()));
664}

References height(), and width().

◆ isRectangle()

bool pappso::SelectionPolygon::isRectangle ( ) const

Definition at line 668 of file selectionpolygon.cpp.

669{
670 // A skewed rectangle polygon has the following conditions verified:
671 //
672 // 1. If its left|right sides are vertical, then its top|bottom lines are
673 // *not* horizontal.
674 //
675 // 2 If its top|bottom lines are horizontal, then its left|right sides are
676 // *not* vertical.
677 //
678 // 3. Then, if a selection polygon is rectangle, its top|bottom lines are
679 // horizontal and its left|right lines are vertical.
680
681 // A line is vertical if its two defining points have the same X.
682 // A line is horizontal if its two defining points have the same Y.
683
684 // Try the horiontal top|bottom lines.
685
688 {
689 // We have horizontal top|bottom lines
690
691 // Try the vertical lines
692
695 {
696 // The top|bottom lines are vertical
697
698 return true;
699 }
700 }
701
702 return false;
703}

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.

579{
580 if(this == &other)
581 return *this;
582
583 if(other.m_points.size() != static_cast<int>(PointSpec::ENUM_LAST))
584 qFatal("Programming error.");
585
586 if(m_points.size() != static_cast<int>(PointSpec::ENUM_LAST))
587 qFatal("Programming error.");
588
589 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
590 m_points[iter] = other.m_points[iter];
591
592 m_minX = other.m_minX;
593 m_minY = other.m_minY;
594
595 m_maxX = other.m_maxX;
596 m_maxY = other.m_maxY;
597
598 return *this;
599}

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.

418{
419 if(axis == Enums::Axis::x)
420 return rangeX(range_start, range_end);
421 else if(axis == Enums::Axis::y)
422 return rangeY(range_start, range_end);
423
424 return false;
425}
bool rangeX(double &range_start, double &range_end) const
bool rangeY(double &range_start, double &range_end) const

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.

398{
399 double min_y = std::numeric_limits<double>::max();
400 double max_y = std::numeric_limits<double>::min();
401
402 return computeMinMaxCoordinates(range_start, range_end, min_y, max_y);
403}

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.

408{
409 double min_x = std::numeric_limits<double>::max();
410 double max_x = std::numeric_limits<double>::min();
411
412 return computeMinMaxCoordinates(min_x, max_x, range_start, range_end);
413}

References computeMinMaxCoordinates().

Referenced by range().

◆ resetPoints()

void pappso::SelectionPolygon::resetPoints ( )

Definition at line 603 of file selectionpolygon.cpp.

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

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.

143{
144 // We get only two points that provide the horizontal range of the polygon.
145 // These two points show the x range of the polygon. We need to craft a
146 // polygon that has:
147 //
148 // that specified x range and
149 //
150 // the widest y range possible.
151
152 resetPoints();
153
154 // top left point
155 setPoint(PointSpec::TOP_LEFT_POINT, QPointF(x_range_start, std::numeric_limits<double>::max()));
156
157 // top right point
158 setPoint(PointSpec::TOP_RIGHT_POINT, QPointF(x_range_end, std::numeric_limits<double>::max()));
159
160 // bottom right point
161 setPoint(PointSpec::BOTTOM_RIGHT_POINT, QPointF(x_range_end, std::numeric_limits<double>::min()));
162
163 // bottom left point
165 QPointF(x_range_start, std::numeric_limits<double>::min()));
166
167 // Compute the min|max x|y coordinates of the polygon that will be used to
168 // quickly check if a point is outside.
170}

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.

178{
179 resetPoints();
180
181 // top left point
183 // qDebug() << "PointSpecs::TOP_LEFT_POINT:" << top_left;
184
185 // top right point
187 // qDebug() << "PointSpecs::TOP_RIGHT_POINT:" << top_right;
188
189 // bottom right point
191 // qDebug() << "PointSpecs::BOTTOM_RIGHT_POINT:" << bottom_right;
192
193 // bottom left point
195 // qDebug() << "PointSpecs::BOTTOM_LEFT_POINT:" << bottom_left;
196
197 // Compute the min|max x|y coordinates of the polygon that will be used to
198 // quickly check if a point is outside.
200
201 // qDebug() << toString();
202}

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.

114{
115 m_points[static_cast<int>(point_spec)].setX(x);
116 m_points[static_cast<int>(point_spec)].setY(y);
117
119}

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.

124{
125 setPoint(point_spec, point.x(), point.y());
126
128}

References computeMinMaxCoordinates(), and setPoint().

◆ toShort4PointsString()

QString pappso::SelectionPolygon::toShort4PointsString ( ) const

Definition at line 762 of file selectionpolygon.cpp.

763{
764 // By essence, a selection polygon is designed to always have 4 points.
765
766 if(m_points.size() != static_cast<int>(PointSpec::ENUM_LAST))
767 qFatal("Programming error.");
768
769 // qDebug() << "size:" << m_points.size();
770
771 QString text = "[";
772
773 QString x_string = "NOT_SET";
774 QString y_string = "NOT_SET";
775
776 // There are two situations:
777 //
778 // 1. The selection polygon is 1D, we only need to provide two points
779 //
780 // 2. The selection polygon is 2D, we need to provide four points.
781
782 if(is1D())
783 {
784 text += QString("(%1,%2)").arg(getLeftMostPoint().x()).arg("NOT_SET");
785 text += QString("(%1,%2)").arg(getRightMostPoint().x()).arg("NOT_SET");
786 }
787 else
788 {
789 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
790 {
791 QPointF iter_point = m_points[iter];
792
793
794 if(iter_point.x() != std::numeric_limits<double>::min() &&
795 iter_point.x() != std::numeric_limits<double>::max())
796 x_string = QString("%1").arg(iter_point.x(), 0, 'f', 3);
797
798 if(iter_point.y() != std::numeric_limits<double>::min() &&
799 iter_point.y() != std::numeric_limits<double>::max())
800 y_string = QString("%1").arg(iter_point.y(), 0, 'f', 3);
801
802 text += QString("(%1,%2)").arg(x_string).arg(y_string);
803 }
804 }
805
806 text += "]";
807
808 return text;
809}

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.

708{
709 // By essence, a selection polygon is designed to always have 4 points.
710
711 if(m_points.size() != static_cast<int>(PointSpec::ENUM_LAST))
712 qFatal("Programming error.");
713
714 // qDebug() << "size:" << m_points.size();
715
716 QString text = "Selection polygon points, from top left, clockwise\n";
717
718 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
719 {
720 QPointF iter_point = m_points[iter];
721
722 QString x_string = "NOT_SET";
723
724 if(iter_point.x() != std::numeric_limits<double>::min() &&
725 iter_point.x() != std::numeric_limits<double>::max())
726 x_string = QString("%1").arg(iter_point.x(), 0, 'f', 10);
727
728 QString y_string = "NOT_SET";
729
730 if(iter_point.y() != std::numeric_limits<double>::min() &&
731 iter_point.y() != std::numeric_limits<double>::max())
732 y_string = QString("%1").arg(iter_point.y(), 0, 'f', 10);
733
734 text += QString("(%1,%2)\n").arg(x_string).arg(y_string);
735 }
736
737 if(m_minX != std::numeric_limits<double>::min() && m_minX != std::numeric_limits<double>::max())
738 text += QString("minX: %1 - ").arg(m_minX, 0, 'f', 10);
739 else
740 text += QString("minX: NOT_SET - ");
741
742 if(m_maxX != std::numeric_limits<double>::min() && m_maxX != std::numeric_limits<double>::max())
743 text += QString("maxX: %1 - ").arg(m_maxX, 0, 'f', 10);
744 else
745 text += QString("maxX: NOT_SET - ");
746
747 if(m_minY != std::numeric_limits<double>::min() && m_minY != std::numeric_limits<double>::max())
748 text += QString("minY: %1 - ").arg(m_minY, 0, 'f', 10);
749 else
750 text += QString("minY: NOT_SET - ");
751
752 if(m_maxY != std::numeric_limits<double>::min() && m_maxY != std::numeric_limits<double>::max())
753 text += QString("maxY: %1 - ").arg(m_maxY, 0, 'f', 10);
754 else
755 text += QString("maxY: NOT_SET - ");
756
757 return text;
758}

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.

443{
444 SelectionPolygon selection_polygon;
445
446 // Make sure we do this for a polygon with four sides.
447
448 if(m_points.size() != static_cast<int>(PointSpec::ENUM_LAST))
449 qFatal("The polygon must have four points, no less, no more");
450
451 // The two invariant points, that is, the two points that do no change
452 // position in the polygon corners. Of course, x becomes y.
453 selection_polygon.setPoint(
456
457 selection_polygon.setPoint(PointSpec::BOTTOM_LEFT_POINT,
460
461 // The two other points.
462
463 selection_polygon.setPoint(
466
467 selection_polygon.setPoint(PointSpec::TOP_LEFT_POINT,
470
471 return selection_polygon;
472}

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.

368{
369 double min_x;
370 double min_y;
371 double max_x;
372 double max_y;
373
374 computeMinMaxCoordinates(min_x, max_x, min_y, max_y);
375
376 ok = true;
377 return max_x - min_x;
378}

References computeMinMaxCoordinates().

Referenced by is1D(), and is2D().

Member Data Documentation

◆ m_maxX

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

◆ m_maxY

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

◆ m_minX

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

◆ m_minY

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

◆ 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.

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

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: