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 (PointSpecs point_spec, double x, double y)
 
void setPoint (PointSpecs point_spec, QPointF point)
 
void copyPoint (PointSpecs point_spec_src, PointSpecs 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 (PointSpecs 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 60 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 any
24 // other polygon will fill inside it and *this polygon by necessity will
25 // contain another one based on experimental data. See the header file for the
26 // creation of the four points.
27}

◆ SelectionPolygon() [2/4]

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

Definition at line 30 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 // top left point
46 m_points.push_back(
47 QPointF(top_left_point.x(), std::numeric_limits<double>::max()));
48
49 // top right point
50 m_points.push_back(
51 QPointF(top_right_point.x(), std::numeric_limits<double>::max()));
52
53 // bottom right point
54 m_points.push_back(
55 QPointF(top_right_point.x(), std::numeric_limits<double>::min()));
56
57 // bottom left point
58 m_points.push_back(
59 QPointF(top_left_point.x(), std::numeric_limits<double>::min()));
60
61 // Compute the min|max x|y coordinates of the polygon that will be used to
62 // quickly check if a point is outside.
64}
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 67 of file selectionpolygon.cpp.

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

References computeMinMaxCoordinates(), and m_points.

◆ SelectionPolygon() [4/4]

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

Definition at line 88 of file selectionpolygon.cpp.

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

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

◆ ~SelectionPolygon()

pappso::SelectionPolygon::~SelectionPolygon ( )
virtual

Definition at line 110 of file selectionpolygon.cpp.

111{
112}

Member Function Documentation

◆ computeMinMaxCoordinates() [1/2]

bool pappso::SelectionPolygon::computeMinMaxCoordinates ( )

Definition at line 320 of file selectionpolygon.cpp.

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

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

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

References pappso::ENUM_LAST, and m_points.

◆ contains() [1/2]

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

Definition at line 486 of file selectionpolygon.cpp.

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

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

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

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

◆ convertTo1D()

void pappso::SelectionPolygon::convertTo1D ( )

Definition at line 213 of file selectionpolygon.cpp.

214{
215 // When a 2D polygon is converted to a 1D polygon, the x axis range is
216 // unchanged, but the height is set to its maximum possible with the bottom
217 // line at y = min and the top line at y = max.
218
220
222}
void set1D(double x_range_start, double x_range_end)

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

◆ copyPoint()

void pappso::SelectionPolygon::copyPoint ( PointSpecs  point_spec_src,
PointSpecs  point_spec_dest 
)

Definition at line 135 of file selectionpolygon.cpp.

137{
138 QPointF src_point = getPoint(point_spec_src);
139 setPoint(point_spec_dest, src_point);
140
142}
void setPoint(PointSpecs point_spec, double x, double y)
QPointF getPoint(PointSpecs 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 839 of file selectionpolygon.cpp.

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

References contains().

◆ getBottomMostPoint()

QPointF pappso::SelectionPolygon::getBottomMostPoint ( ) const

Definition at line 286 of file selectionpolygon.cpp.

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

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

Referenced by pappso::BasePlotWidget::drawYDeltaFeatures(), and pappso::BasePlotWidget::updateSelectionRectangle().

◆ getLeftMostPoint()

QPointF pappso::SelectionPolygon::getLeftMostPoint ( ) const

Definition at line 226 of file selectionpolygon.cpp.

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

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

Referenced by pappso::BasePlotWidget::drawXDeltaFeatures(), pappso::BasePlotWidget::drawYDeltaFeatures(), toShort4PointsString(), and pappso::BasePlotWidget::updateSelectionRectangle().

◆ getPoint()

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

◆ getPoints()

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

Definition at line 306 of file selectionpolygon.cpp.

307{
308 return m_points;
309}

References m_points.

◆ getRightMostPoint()

QPointF pappso::SelectionPolygon::getRightMostPoint ( ) const

Definition at line 246 of file selectionpolygon.cpp.

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

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

Referenced by pappso::BasePlotWidget::drawXDeltaFeatures(), pappso::BasePlotWidget::drawYDeltaFeatures(), toShort4PointsString(), and pappso::BasePlotWidget::updateSelectionRectangle().

◆ getTopMostPoint()

QPointF pappso::SelectionPolygon::getTopMostPoint ( ) const

Definition at line 266 of file selectionpolygon.cpp.

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

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

Referenced by pappso::BasePlotWidget::drawYDeltaFeatures(), and pappso::BasePlotWidget::updateSelectionRectangle().

◆ height()

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

Definition at line 389 of file selectionpolygon.cpp.

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

References computeMinMaxCoordinates().

Referenced by is1D(), and is2D().

◆ is1D()

bool pappso::SelectionPolygon::is1D ( ) const

Definition at line 631 of file selectionpolygon.cpp.

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

References height(), and width().

Referenced by pappso::BasePlotWidget::drawYDeltaFeatures(), and toShort4PointsString().

◆ is2D()

bool pappso::SelectionPolygon::is2D ( ) const

Definition at line 660 of file selectionpolygon.cpp.

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

References height(), and width().

◆ isRectangle()

bool pappso::SelectionPolygon::isRectangle ( ) const

Definition at line 686 of file selectionpolygon.cpp.

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

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

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

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

425{
426 if(axis == Axis::x)
427 return rangeX(range_start, range_end);
428 else if(axis == Axis::y)
429 return rangeY(range_start, range_end);
430
431 return false;
432}
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 404 of file selectionpolygon.cpp.

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

References computeMinMaxCoordinates().

Referenced by range().

◆ rangeY()

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

Definition at line 414 of file selectionpolygon.cpp.

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

References computeMinMaxCoordinates().

Referenced by range().

◆ resetPoints()

void pappso::SelectionPolygon::resetPoints ( )

Definition at line 614 of file selectionpolygon.cpp.

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

References m_points.

Referenced by pappso::BasePlotWidget::resetSelectionRectangle(), set1D(), set2D(), pappso::BasePlotWidget::update2DSelectionRectangleSkewed(), and pappso::BasePlotWidget::update2DSelectionRectangleSquare().

◆ set1D()

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

Definition at line 146 of file selectionpolygon.cpp.

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

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

Referenced by convertTo1D(), and pappso::BasePlotWidget::update1DSelectionRectangle().

◆ set2D()

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

Definition at line 181 of file selectionpolygon.cpp.

185{
186 resetPoints();
187
188 // top left point
190 // qDebug() << "PointSpecs::TOP_LEFT_POINT:" << top_left;
191
192 // top right point
194 // qDebug() << "PointSpecs::TOP_RIGHT_POINT:" << top_right;
195
196 // bottom right point
198 // qDebug() << "PointSpecs::BOTTOM_RIGHT_POINT:" << bottom_right;
199
200 // bottom left point
202 // qDebug() << "PointSpecs::BOTTOM_LEFT_POINT:" << bottom_left;
203
204 // Compute the min|max x|y coordinates of the polygon that will be used to
205 // quickly check if a point is outside.
207
208 // qDebug() << toString();
209}

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 ( PointSpecs  point_spec,
double  x,
double  y 
)

Definition at line 116 of file selectionpolygon.cpp.

117{
118 m_points[static_cast<int>(point_spec)].setX(x);
119 m_points[static_cast<int>(point_spec)].setY(y);
120
122}

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

Referenced by copyPoint(), set1D(), set2D(), setPoint(), transpose(), pappso::BasePlotWidget::update2DSelectionRectangleSkewed(), and pappso::BasePlotWidget::update2DSelectionRectangleSquare().

◆ setPoint() [2/2]

void pappso::SelectionPolygon::setPoint ( PointSpecs  point_spec,
QPointF  point 
)

Definition at line 126 of file selectionpolygon.cpp.

127{
128 setPoint(point_spec, point.x(), point.y());
129
131}

References computeMinMaxCoordinates(), and setPoint().

◆ toShort4PointsString()

QString pappso::SelectionPolygon::toShort4PointsString ( ) const

Definition at line 788 of file selectionpolygon.cpp.

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

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

◆ toString()

QString pappso::SelectionPolygon::toString ( ) const

Definition at line 729 of file selectionpolygon.cpp.

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

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

Referenced by pappso::SelectionPolygonSpec::toString(), and pappso::BasePlotContext::toString().

◆ transpose()

SelectionPolygon pappso::SelectionPolygon::transpose ( ) const

Definition at line 449 of file selectionpolygon.cpp.

450{
451 SelectionPolygon selection_polygon;
452
453 // Make sure we do this for a polygon with four sides.
454
455 if(m_points.size() != static_cast<int>(PointSpecs::ENUM_LAST))
456 qFatal("The polygon must have four points, no less, no more");
457
458 // The two invariant points, that is, the two points that do no change
459 // position in the polygon corners. Of course, x becomes y.
460 selection_polygon.setPoint(
464
465 selection_polygon.setPoint(
469
470 // The two other points.
471
472 selection_polygon.setPoint(PointSpecs::BOTTOM_RIGHT_POINT,
475
476 selection_polygon.setPoint(
480
481 return selection_polygon;
482}

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

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

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 139 of file selectionpolygon.h.

139 {QPointF(std::numeric_limits<double>::min(),
140 std::numeric_limits<double>::max()),
141 QPointF(std::numeric_limits<double>::max(),
142 std::numeric_limits<double>::max()),
143 QPointF(std::numeric_limits<double>::max(),
144 std::numeric_limits<double>::min()),
145 QPointF(std::numeric_limits<double>::min(),
146 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: