NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
LinearBoundaryChecker.hpp
1 //LinearBoundaryChecker.hpp
2 // Created on: May 29, 2015
3 // Author: Hafez Farazi <farazi@ais.uni-bonn.de>
4 #pragma once
5 
6 #include <vision_module/Tools/LineSegment.hpp>
7 #include <vision_module/Tools/LinearInterpolator.hpp>
8 #include <math.h>
9 
16 {
17 private:
18  LineSegment LLow, LHigh;
19 public:
20  inline bool checkValidity()
21  {
22  Point2d tmp;
23  return !LLow.Intersect(LHigh, tmp);
24  }
25 
26  inline LinearBoundaryChecker(LineSegment _LLow, LineSegment _LHigh) :
27  LLow(_LLow), LHigh(_LHigh)
28  {
29  if (!checkValidity())
30  {
31  HAF_ERROR_THROTTLE(1,
32  "Conflict in input for LinearBoundaryChecker");
33  }
34  }
35 
36  inline LinearBoundaryChecker(double nearDistance, double nearMin,
37  double nearMax, double farDistance, double farMin, double farMax)
38  {
39  LLow.P1 = Point2d(nearDistance, nearMin);
40  LLow.P2 = Point2d(farDistance, farMin);
41 
42  LHigh.P1 = Point2d(nearDistance, nearMax);
43  LHigh.P2 = Point2d(farDistance, farMax);
44  if (!checkValidity())
45  {
46  HAF_ERROR_THROTTLE(1,
47  "Conflict in input for LinearBoundaryChecker");
48  }
49  }
50 
51  inline bool CheckExtrapolation(double distance,
52  double value)
53  {
54  LineSegment verLine(Point2d(distance, -10),
55  Point2d(distance, 10));
56  Point2d resLowerBand, resUpperBand;
57  if (LLow.IntersectLineForm(verLine, resLowerBand)
58  && LHigh.IntersectLineForm(verLine, resUpperBand))
59  {
60  if (value >= resLowerBand.y && value <= resUpperBand.y)
61  {
62  return true;
63  }
64  }
65  else
66  {
67  ROS_ERROR("Error in programming %f", distance);
68  }
69 
70  return false;
71  }
72 
73 
74  inline bool GetExtrapolation(double distance,
75  double &min, double &max)
76  {
77  LineSegment verLine(Point2d(distance, -10),
78  Point2d(distance, 10));
79  Point2d resLowerBand, resUpperBand;
80 
81  if (LLow.IntersectLineForm(verLine, resLowerBand)
82  && LHigh.IntersectLineForm(verLine, resUpperBand))
83  {
84  if (resUpperBand.y > resLowerBand.y)
85  {
86  min = resLowerBand.y;
87  max = resUpperBand.y;
88  return true;
89  }
90  }
91  else
92  {
93  ROS_ERROR("Error in programming %f", distance);
94  }
95  return false;
96  }
97 
98  inline bool CheckInside(double distance, double value)
99  {
100 
101  double max_y = std::max(LLow.P1.y,
102  std::max(LLow.P2.y, std::max(LHigh.P1.y, LHigh.P2.y)));
103  LineSegment verLine(Point2d(distance, 0), Point2d(distance, max_y));
104  Point2d resLowerBand, resUpperBand;
105  if (LLow.Intersect(verLine, resLowerBand)
106  && LHigh.Intersect(verLine, resUpperBand))
107  {
108  if (value >= resLowerBand.y && value <= resUpperBand.y)
109  {
110  return true;
111  }
112  }
113  return false;
114  }
115 
116  inline virtual ~LinearBoundaryChecker()
117  {
118 
119  }
120 };
121 
A class representing line segments.
Definition: LineSegment.hpp:17
A class for check if a point is between two given line segments.
Definition: LinearBoundaryChecker.hpp:15