ConvexHull.h
Go to the documentation of this file.
1 /**
2  * @file ConvexHull.h
3  *
4  * @brief Implements a ConvexHull for use in clustering
5  *
6  * @author usher@slac.stanford.edu
7  *
8  */
9 #ifndef ConvexHull_h
10 #define ConvexHull_h
11 
12 // Algorithm includes
14 
15 // std includes
16 #include <list>
17 #include <tuple>
18 #include <utility>
19 
20 //------------------------------------------------------------------------------------------------------------------------------------------
21 
22 namespace lar_cluster3d
23 {
24 /**
25  * @brief ConvexHull class definiton
26  */
28 {
29 public:
30  /**
31  * @brief Definitions used by the ConvexHull algorithm
32  */
33  using Point = std::tuple<float,float,const reco::ClusterHit3D*>; ///< projected x,y position and 3D hit
34  using PointList = std::list<Point>; ///< The list of the projected points
35  using PointPair = std::pair<Point,Point>;
36  using MinMaxPointPair = std::pair<PointPair,PointPair>;
37 
38  /**
39  * @brief Constructor
40  *
41  * @param pset
42  */
43  ConvexHull(const PointList&, float = 0.85, float = 0.35);
44 
45  /**
46  * @brief Destructor
47  */
48  ~ConvexHull();
49 
50  /**
51  * @brief recover the list of points used to build convex hull
52  */
53  const PointList& getPointsList() {return fPoints;}
54 
55  /**
56  * @brief recover the list of convex hull vertices
57  */
58  const PointList& getConvexHull() const {return fConvexHull;}
59 
60  /**
61  * @brief find the ends of the convex hull (along its x axis)
62  */
64 
65  /**
66  * @brief Find the two points on the hull which are furthest apart
67  */
68  const PointList& getExtremePoints();
69 
70  /**
71  * @brief Find the points with the largest angles
72  */
74 
75  /**
76  * @brief recover the area of the convex hull
77  */
78  float getConvexHullArea() const {return fConvexHullArea;}
79 
80  /**
81  * @brief Given an input Point, find the nearest edge
82  */
83  PointPair findNearestEdge(const Point&, float&) const;
84 
85  /**
86  * @brief Given an input point, find the distance to the nearest edge/point
87  */
88  float findNearestDistance(const Point&) const;
89 
90 private:
91 
92  /**
93  * @brief Given an input set of 2D points build a convex hull around them
94  *
95  * @param PointList The input list of 2D points to build hull around
96  */
97  void getConvexHull(const PointList&);
98 
99  /**
100  * @brief Gets the cross product of line from p0 to p1 and p0 to p2
101  */
102  float crossProduct(const Point& p0, const Point& p1, const Point& p2) const;
103 
104  /**
105  * @brief Computes the area of the enclosed convext hull
106  */
107  float Area() const;
108 
109  /**
110  * @brief Determines whether a point is to the left, right or on line specifiec by p0 and p1
111  */
112  bool isLeft(const Point& p0, const Point& p1, const Point& pCheck) const;
113 
114  float fKinkAngle;
116 
123 };
124 
125 } // namespace lar_cluster3d
126 #endif
const PointList & getPointsList()
recover the list of points used to build convex hull
Definition: ConvexHull.h:53
std::pair< PointPair, PointPair > MinMaxPointPair
Definition: ConvexHull.h:36
MinMaxPointPair fMinMaxPointPair
Definition: ConvexHull.h:119
std::list< Point > PointList
The list of the projected points.
Definition: ConvexHull.h:34
float crossProduct(const Point &p0, const Point &p1, const Point &p2) const
Gets the cross product of line from p0 to p1 and p0 to p2.
Definition: ConvexHull.cxx:58
std::pair< Point, Point > PointPair
Definition: ConvexHull.h:35
const MinMaxPointPair & getMinMaxPointPair() const
find the ends of the convex hull (along its x axis)
Definition: ConvexHull.h:63
float Area() const
Computes the area of the enclosed convext hull.
Definition: ConvexHull.cxx:71
PointPair findNearestEdge(const Point &, float &) const
Given an input Point, find the nearest edge.
Definition: ConvexHull.cxx:331
float findNearestDistance(const Point &) const
Given an input point, find the distance to the nearest edge/point.
Definition: ConvexHull.cxx:392
const reco::ConvexHullKinkTupleList & getKinkPoints()
Find the points with the largest angles.
Definition: ConvexHull.cxx:276
std::list< ConvexHullKinkTuple > ConvexHullKinkTupleList
Definition: Cluster3D.h:355
float getConvexHullArea() const
recover the area of the convex hull
Definition: ConvexHull.h:78
const PointList & getConvexHull() const
recover the list of convex hull vertices
Definition: ConvexHull.h:58
ConvexHull class definiton.
Definition: ConvexHull.h:27
reco::ConvexHullKinkTupleList fKinkPoints
Definition: ConvexHull.h:122
const PointList & getExtremePoints()
Find the two points on the hull which are furthest apart.
Definition: ConvexHull.cxx:207
bool isLeft(const Point &p0, const Point &p1, const Point &pCheck) const
Determines whether a point is to the left, right or on line specifiec by p0 and p1.
Definition: ConvexHull.cxx:49
ConvexHull(const PointList &, float=0.85, float=0.35)
Constructor.
Definition: ConvexHull.cxx:29
const PointList & fPoints
Definition: ConvexHull.h:117
~ConvexHull()
Destructor.
Definition: ConvexHull.cxx:43