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 (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}

◆ SelectionPolygon() [2/4]

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

Definition at line 31 of file selectionpolygon.cpp.

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

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

References computeMinMaxCoordinates(), and m_points.

◆ SelectionPolygon() [4/4]

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

Definition at line 91 of file selectionpolygon.cpp.

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

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

◆ ~SelectionPolygon()

pappso::SelectionPolygon::~SelectionPolygon ( )
virtual

Definition at line 113 of file selectionpolygon.cpp.

114{
115}

Member Function Documentation

◆ computeMinMaxCoordinates() [1/2]

bool pappso::SelectionPolygon::computeMinMaxCoordinates ( )

Definition at line 323 of file selectionpolygon.cpp.

324{
325 // Set the variable to starting values that allow easy value comparisons with
326 // std::min() and std::max() for checking the x|y values below.
327
328 m_minX = std::numeric_limits<double>::max();
329 m_minY = std::numeric_limits<double>::max();
330 m_maxX = std::numeric_limits<double>::min();
331 m_maxY = std::numeric_limits<double>::min();
332
333 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
334 {
335 m_minX = std::min(m_points.at(iter).x(), m_minX);
336 m_maxX = std::max(m_points.at(iter).x(), m_maxX);
337
338 m_minY = std::min(m_points.at(iter).y(), m_minY);
339 m_maxY = std::max(m_points.at(iter).y(), m_maxY);
340 }
341
342 return true;
343}

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 347 of file selectionpolygon.cpp.

351{
352 // Set the variable to starting values that allow easy value comparisons with
353 // std::min() and std::max() for checking the x|y values below.
354
355 min_x = std::numeric_limits<double>::max();
356 min_y = std::numeric_limits<double>::max();
357 max_x = std::numeric_limits<double>::min();
358 max_y = std::numeric_limits<double>::min();
359
360 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
361 {
362 min_x = std::min(m_points.at(iter).x(), min_x);
363 max_x = std::max(m_points.at(iter).x(), max_x);
364
365 min_y = std::min(m_points.at(iter).y(), min_y);
366 max_y = std::max(m_points.at(iter).y(), max_y);
367 }
368
369 // qDebug() << "min_x:" << min_x << "max_x:" << max_x << "min_y:" << min_y
370 //<< "max_y:" << max_y;
371
372 return true;
373}

References pappso::ENUM_LAST, and m_points.

◆ contains() [1/2]

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

Definition at line 489 of file selectionpolygon.cpp.

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

References isRectangle(), m_maxX, m_maxY, m_minX, m_minY, m_points, pappso::res, 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 574 of file selectionpolygon.cpp.

575{
576 // A polygon is inside another polygon if all its points are inside the
577 // polygon.
578
579 bool is_inside = true;
580
581 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
582 {
583 if(!contains(selection_polygon.getPoint(static_cast<PointSpec>(iter))))
584 is_inside = false;
585 }
586
587 return is_inside;
588}
bool contains(const QPointF &tested_point) const

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

◆ convertTo1D()

void pappso::SelectionPolygon::convertTo1D ( )

Definition at line 216 of file selectionpolygon.cpp.

217{
218 // When a 2D polygon is converted to a 1D polygon, the x axis range is
219 // unchanged, but the height is set to its maximum possible with the bottom
220 // line at y = min and the top line at y = max.
221
223
225}
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 138 of file selectionpolygon.cpp.

140{
141 QPointF src_point = getPoint(point_spec_src);
142 setPoint(point_spec_dest, src_point);
143
145}
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 842 of file selectionpolygon.cpp.

844{
845 bool is_point_inside = false;
846
847 QString debug_string;
848
849 is_point_inside = selection_polygon.contains(tested_point);
850 debug_string = QString("(%1,%2) is inside: %3")
851 .arg(tested_point.x(), 0, 'f', 10)
852 .arg(tested_point.y(), 0, 'f', 10)
853 .arg(is_point_inside ? "true" : "false");
854 qDebug().noquote() << debug_string;
855}

References contains().

◆ getBottomMostPoint()

QPointF pappso::SelectionPolygon::getBottomMostPoint ( ) const

Definition at line 289 of file selectionpolygon.cpp.

290{
291 // When we say topmost or bottommost , that means that we are implicitely
292 // interesed in y-axis coordinate of the points.
293
294 QPointF temp_point(0, std::numeric_limits<double>::max());
295
296 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
297 {
298 if(m_points[iter].y() < temp_point.y())
299 {
300 temp_point = m_points[iter];
301 }
302 }
303
304 return temp_point;
305}

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

◆ getLeftMostPoint()

QPointF pappso::SelectionPolygon::getLeftMostPoint ( ) const

Definition at line 229 of file selectionpolygon.cpp.

230{
231 // When we say leftmost, that means that we are implicitely interesed in
232 // x-axis coordinate of the points.
233
234 QPointF temp_point(std::numeric_limits<double>::max(), 0);
235
236 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
237 {
238 if(m_points[iter].x() < temp_point.x())
239 {
240 temp_point = m_points[iter];
241 }
242 }
243
244 return temp_point;
245}

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

Referenced by toShort4PointsString().

◆ getPoint()

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

Definition at line 316 of file selectionpolygon.cpp.

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

References m_points.

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

◆ getPoints()

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

Definition at line 309 of file selectionpolygon.cpp.

310{
311 return m_points;
312}

References m_points.

◆ getRightMostPoint()

QPointF pappso::SelectionPolygon::getRightMostPoint ( ) const

Definition at line 249 of file selectionpolygon.cpp.

250{
251 // When we say rightmost, that means that we are implicitely interesed in
252 // x-axis coordinate of the points.
253
254 QPointF temp_point(std::numeric_limits<double>::min(), 0);
255
256 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
257 {
258 if(m_points[iter].x() > temp_point.x())
259 {
260 temp_point = m_points[iter];
261 }
262 }
263
264 return temp_point;
265}

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

Referenced by toShort4PointsString().

◆ getTopMostPoint()

QPointF pappso::SelectionPolygon::getTopMostPoint ( ) const

Definition at line 269 of file selectionpolygon.cpp.

270{
271 // When we say topmost or bottommost , that means that we are implicitely
272 // interesed in y-axis coordinate of the points.
273
274 QPointF temp_point(0, std::numeric_limits<double>::min());
275
276 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
277 {
278 if(m_points[iter].y() > temp_point.y())
279 {
280 temp_point = m_points[iter];
281 }
282 }
283
284 return temp_point;
285}

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

◆ height()

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

Definition at line 392 of file selectionpolygon.cpp.

393{
394 double min_x;
395 double min_y;
396 double max_x;
397 double max_y;
398
399 computeMinMaxCoordinates(min_x, max_x, min_y, max_y);
400
401 ok = true;
402 return max_y - min_y;
403}

References computeMinMaxCoordinates().

Referenced by is1D(), and is2D().

◆ is1D()

bool pappso::SelectionPolygon::is1D ( ) const

Definition at line 634 of file selectionpolygon.cpp.

635{
636 // qDebug() << "Selection polygon:" << toString();
637
638 bool ok = false;
639
640 double width_value = width(ok);
641 if(!ok)
642 return false;
643
644 double height_value = height(ok);
645 if(!ok)
646 return false;
647
648 // qDebug() << "Width and height computations succeeded:"
649 //<< "width:" << width_value << "height:" << height_value;
650
651 // A polygon is mono-dimensional if it has both non-0 width and no (max-min)
652 // width AND if the height is 0 or (max-min).
653 return (
654 (width_value > 0 && width_value < std::numeric_limits<double>::max() -
655 std::numeric_limits<double>::min()) &&
656 (height_value == 0 ||
657 height_value == std::numeric_limits<double>::max() -
658 std::numeric_limits<double>::min()));
659}
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 663 of file selectionpolygon.cpp.

664{
665 // A selection polygon can behave like a line segment if the bottom side
666 // confounds with the top side.
667
668 bool ok = false;
669
670 double width_value = width(ok);
671 if(!ok)
672 return false;
673
674 double height_value = height(ok);
675 if(!ok)
676 return false;
677
678 // A polygon is two-dimensional if it has both non-0 width and no (max-min)
679 // width AND same for height.
680 return (
681 (width_value > 0 && width_value < std::numeric_limits<double>::max() -
682 std::numeric_limits<double>::min()) &&
683 (height_value > 0 && height_value < std::numeric_limits<double>::max() -
684 std::numeric_limits<double>::min()));
685}

References height(), and width().

◆ isRectangle()

bool pappso::SelectionPolygon::isRectangle ( ) const

Definition at line 689 of file selectionpolygon.cpp.

690{
691 // A skewed rectangle polygon has the following conditions verified:
692 //
693 // 1. If its left|right sides are vertical, then its top|bottom lines are
694 // *not* horizontal.
695 //
696 // 2 If its top|bottom lines are horizontal, then its left|right sides are
697 // *not* vertical.
698 //
699 // 3. Then, if a selection polygon is rectangle, its top|bottom lines are
700 // horizontal and its left|right lines are vertical.
701
702 // A line is vertical if its two defining points have the same X.
703 // A line is horizontal if its two defining points have the same Y.
704
705 // Try the horiontal top|bottom lines.
706
711 {
712 // We have horizontal top|bottom lines
713
714 // Try the vertical lines
715
720 {
721 // The top|bottom lines are vertical
722
723 return true;
724 }
725 }
726
727 return false;
728}

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 592 of file selectionpolygon.cpp.

593{
594 if(this == &other)
595 return *this;
596
597 if(other.m_points.size() != static_cast<int>(PointSpec::ENUM_LAST))
598 qFatal("Programming error.");
599
600 if(m_points.size() != static_cast<int>(PointSpec::ENUM_LAST))
601 qFatal("Programming error.");
602
603 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
604 m_points[iter] = other.m_points[iter];
605
606 m_minX = other.m_minX;
607 m_minY = other.m_minY;
608
609 m_maxX = other.m_maxX;
610 m_maxY = other.m_maxY;
611
612 return *this;
613}

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

◆ range()

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

Definition at line 427 of file selectionpolygon.cpp.

428{
429 if(axis == Axis::x)
430 return rangeX(range_start, range_end);
431 else if(axis == Axis::y)
432 return rangeY(range_start, range_end);
433
434 return false;
435}
bool rangeX(double &range_start, double &range_end) const
bool rangeY(double &range_start, double &range_end) const

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

◆ rangeX()

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

Definition at line 407 of file selectionpolygon.cpp.

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

References computeMinMaxCoordinates().

Referenced by range().

◆ rangeY()

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

Definition at line 417 of file selectionpolygon.cpp.

418{
419 double min_x = std::numeric_limits<double>::max();
420 double max_x = std::numeric_limits<double>::min();
421
422 return computeMinMaxCoordinates(min_x, max_x, range_start, range_end);
423}

References computeMinMaxCoordinates().

Referenced by range().

◆ resetPoints()

void pappso::SelectionPolygon::resetPoints ( )

Definition at line 617 of file selectionpolygon.cpp.

618{
619 // Reset the points exactly as they were set upon construction of an empty
620 // polygon.
621
622 m_points[0] = QPointF(std::numeric_limits<double>::min(),
623 std::numeric_limits<double>::max());
624 m_points[0] = QPointF(std::numeric_limits<double>::max(),
625 std::numeric_limits<double>::max());
626 m_points[0] = QPointF(std::numeric_limits<double>::max(),
627 std::numeric_limits<double>::min());
628 m_points[0] = QPointF(std::numeric_limits<double>::min(),
629 std::numeric_limits<double>::max());
630}

References m_points.

Referenced by set1D(), and set2D().

◆ set1D()

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

Definition at line 149 of file selectionpolygon.cpp.

150{
151 // We get only two points that provide the horizontal range of the polygon.
152 // These two points show the x range of the polygon. We need to craft a
153 // polygon that has:
154 //
155 // that specified x range and
156 //
157 // the widest y range possible.
158
159 resetPoints();
160
161 // top left point
163 QPointF(x_range_start, std::numeric_limits<double>::max()));
164
165 // top right point
167 QPointF(x_range_end, std::numeric_limits<double>::max()));
168
169 // bottom right point
171 QPointF(x_range_end, std::numeric_limits<double>::min()));
172
173 // bottom left point
175 QPointF(x_range_start, std::numeric_limits<double>::min()));
176
177 // Compute the min|max x|y coordinates of the polygon that will be used to
178 // quickly check if a point is outside.
180}

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 184 of file selectionpolygon.cpp.

188{
189 resetPoints();
190
191 // top left point
193 // qDebug() << "PointSpecs::TOP_LEFT_POINT:" << top_left;
194
195 // top right point
197 // qDebug() << "PointSpecs::TOP_RIGHT_POINT:" << top_right;
198
199 // bottom right point
201 // qDebug() << "PointSpecs::BOTTOM_RIGHT_POINT:" << bottom_right;
202
203 // bottom left point
205 // qDebug() << "PointSpecs::BOTTOM_LEFT_POINT:" << bottom_left;
206
207 // Compute the min|max x|y coordinates of the polygon that will be used to
208 // quickly check if a point is outside.
210
211 // qDebug() << toString();
212}

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 119 of file selectionpolygon.cpp.

120{
121 m_points[static_cast<int>(point_spec)].setX(x);
122 m_points[static_cast<int>(point_spec)].setY(y);
123
125}

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 129 of file selectionpolygon.cpp.

130{
131 setPoint(point_spec, point.x(), point.y());
132
134}

References computeMinMaxCoordinates(), and setPoint().

◆ toShort4PointsString()

QString pappso::SelectionPolygon::toShort4PointsString ( ) const

Definition at line 791 of file selectionpolygon.cpp.

792{
793 // By essence, a selection polygon is designed to always have 4 points.
794
795 if(m_points.size() != static_cast<int>(PointSpec::ENUM_LAST))
796 qFatal("Programming error.");
797
798 // qDebug() << "size:" << m_points.size();
799
800 QString text = "[";
801
802 QString x_string = "NOT_SET";
803 QString y_string = "NOT_SET";
804
805 // There are two situations:
806 //
807 // 1. The selection polygon is 1D, we only need to provide two points
808 //
809 // 2. The selection polygon is 2D, we need to provide four points.
810
811 if(is1D())
812 {
813 text += QString("(%1,%2)").arg(getLeftMostPoint().x()).arg("NOT_SET");
814 text += QString("(%1,%2)").arg(getRightMostPoint().x()).arg("NOT_SET");
815 }
816 else
817 {
818 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
819 {
820 QPointF iter_point = m_points[iter];
821
822
823 if(iter_point.x() != std::numeric_limits<double>::min() &&
824 iter_point.x() != std::numeric_limits<double>::max())
825 x_string = QString("%1").arg(iter_point.x(), 0, 'f', 3);
826
827 if(iter_point.y() != std::numeric_limits<double>::min() &&
828 iter_point.y() != std::numeric_limits<double>::max())
829 y_string = QString("%1").arg(iter_point.y(), 0, 'f', 3);
830
831 text += QString("(%1,%2)").arg(x_string).arg(y_string);
832 }
833 }
834
835 text += "]";
836
837 return text;
838}

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

◆ toString()

QString pappso::SelectionPolygon::toString ( ) const

Definition at line 732 of file selectionpolygon.cpp.

733{
734 // By essence, a selection polygon is designed to always have 4 points.
735
736 if(m_points.size() != static_cast<int>(PointSpec::ENUM_LAST))
737 qFatal("Programming error.");
738
739 // qDebug() << "size:" << m_points.size();
740
741 QString text = "Selection polygon points, from top left, clockwise\n";
742
743 for(int iter = 0; iter < static_cast<int>(PointSpec::ENUM_LAST); ++iter)
744 {
745 QPointF iter_point = m_points[iter];
746
747 QString x_string = "NOT_SET";
748
749 if(iter_point.x() != std::numeric_limits<double>::min() &&
750 iter_point.x() != std::numeric_limits<double>::max())
751 x_string = QString("%1").arg(iter_point.x(), 0, 'f', 10);
752
753 QString y_string = "NOT_SET";
754
755 if(iter_point.y() != std::numeric_limits<double>::min() &&
756 iter_point.y() != std::numeric_limits<double>::max())
757 y_string = QString("%1").arg(iter_point.y(), 0, 'f', 10);
758
759 text += QString("(%1,%2)\n").arg(x_string).arg(y_string);
760 }
761
762 if(m_minX != std::numeric_limits<double>::min() &&
763 m_minX != std::numeric_limits<double>::max())
764 text += QString("minX: %1 - ").arg(m_minX, 0, 'f', 10);
765 else
766 text += QString("minX: NOT_SET - ");
767
768 if(m_maxX != std::numeric_limits<double>::min() &&
769 m_maxX != std::numeric_limits<double>::max())
770 text += QString("maxX: %1 - ").arg(m_maxX, 0, 'f', 10);
771 else
772 text += QString("maxX: NOT_SET - ");
773
774 if(m_minY != std::numeric_limits<double>::min() &&
775 m_minY != std::numeric_limits<double>::max())
776 text += QString("minY: %1 - ").arg(m_minY, 0, 'f', 10);
777 else
778 text += QString("minY: NOT_SET - ");
779
780 if(m_maxY != std::numeric_limits<double>::min() &&
781 m_maxY != std::numeric_limits<double>::max())
782 text += QString("maxY: %1 - ").arg(m_maxY, 0, 'f', 10);
783 else
784 text += QString("maxY: NOT_SET - ");
785
786 return text;
787}

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

Referenced by pappso::SelectionPolygonSpec::toString().

◆ transpose()

SelectionPolygon pappso::SelectionPolygon::transpose ( ) const

Definition at line 452 of file selectionpolygon.cpp.

453{
454 SelectionPolygon selection_polygon;
455
456 // Make sure we do this for a polygon with four sides.
457
458 if(m_points.size() != static_cast<int>(PointSpec::ENUM_LAST))
459 qFatal("The polygon must have four points, no less, no more");
460
461 // The two invariant points, that is, the two points that do no change
462 // position in the polygon corners. Of course, x becomes y.
463 selection_polygon.setPoint(
467
468 selection_polygon.setPoint(
472
473 // The two other points.
474
475 selection_polygon.setPoint(PointSpec::BOTTOM_RIGHT_POINT,
478
479 selection_polygon.setPoint(
483
484 return selection_polygon;
485}

References 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 377 of file selectionpolygon.cpp.

378{
379 double min_x;
380 double min_y;
381 double max_x;
382 double max_y;
383
384 computeMinMaxCoordinates(min_x, max_x, min_y, max_y);
385
386 ok = true;
387 return max_x - min_x;
388}

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: