15 #include <boost/range/adaptor/reversed.hpp> 59 float deltaX = std::get<0>(p1) - std::get<0>(p0);
60 float deltaY = std::get<1>(p1) - std::get<1>(p0);
61 float dCheckX = std::get<0>(p2) - std::get<0>(p0);
62 float dCheckY = std::get<1>(p2) - std::get<1>(p0);
64 return ((deltaX * dCheckY) - (deltaY * dCheckX));
79 Point center(0.,0.,0);
84 if (point != lastPoint) area += 0.5 *
crossProduct(center,lastPoint,point);
97 Point pMinMin = pointList.front();
100 PointList::const_iterator pMinMaxItr = std::find_if(pointList.begin(),pointList.end(),[pMinMin](
const auto& elem){
return std::get<0>(elem) != std::get<0>(pMinMin);});
102 Point pMinMax = *(--pMinMaxItr);
107 Point pMaxMax = pointList.back();
110 PointList::const_reverse_iterator pMaxMinItr = std::find_if(pointList.rbegin(),pointList.rend(),[pMaxMax](
const auto& elem){
return std::get<0>(elem) != std::get<0>(pMaxMax);});
112 Point pMaxMin = *(--pMaxMinItr);
120 lowerHullList.push_back(pMinMin);
123 for(
auto curPoint : pointList)
126 if (
isLeft(pMinMin,pMaxMin,curPoint))
continue;
133 while(lowerHullList.size() > 1)
135 Point lastPoint = lowerHullList.back();
137 lowerHullList.pop_back();
139 Point nextToLastPoint = lowerHullList.back();
141 if (
isLeft(nextToLastPoint,lastPoint,curPoint))
143 lowerHullList.push_back(lastPoint);
148 lowerHullList.push_back(curPoint);
154 upperHullList.push_back(pMaxMax);
156 for(
auto curPoint : boost::adaptors::reverse(pointList))
161 if (
isLeft(pMaxMax,pMinMax,curPoint))
continue;
164 while(upperHullList.size() > 1)
166 Point lastPoint = upperHullList.back();
168 upperHullList.pop_back();
170 Point nextToLastPoint = upperHullList.back();
172 if (
isLeft(nextToLastPoint,lastPoint,curPoint))
174 upperHullList.push_back(lastPoint);
179 upperHullList.push_back(curPoint);
183 std::copy(lowerHullList.begin(),lowerHullList.end(),std::back_inserter(
fConvexHull));
185 if (pMaxMin == pMaxMax) upperHullList.pop_front();
187 std::copy(upperHullList.begin(),upperHullList.end(),std::back_inserter(
fConvexHull));
189 if (pMinMin != pMinMax)
fConvexHull.push_back(pMinMin);
201 Point prevPoint = *curPointItr++;
202 Point curPoint = *curPointItr;
205 PointPair closestEdge(prevPoint,curPoint);
212 if (curPoint != prevPoint)
215 float xPrevToPoint = (std::get<0>(point) - std::get<0>(prevPoint));
216 float yPrevToPoint = (std::get<1>(point) - std::get<1>(prevPoint));
217 float xPrevToCur = (std::get<0>(curPoint) - std::get<0>(prevPoint));
218 float yPrevToCur = (std::get<1>(curPoint) - std::get<1>(prevPoint));
219 float edgeLength = std::sqrt(xPrevToCur * xPrevToCur + yPrevToCur * yPrevToCur);
222 float projection = ((xPrevToPoint * xPrevToCur) + (yPrevToPoint * yPrevToCur)) / edgeLength;
225 Point docaPoint(std::get<0>(prevPoint) + projection * xPrevToCur / edgeLength,
226 std::get<1>(prevPoint) + projection * yPrevToCur / edgeLength, 0);
228 if (projection > edgeLength) docaPoint = curPoint;
229 if (projection < 0) docaPoint = prevPoint;
231 float xDocaDist = std::get<0>(point) - std::get<0>(docaPoint);
232 float yDocaDist = std::get<1>(point) - std::get<1>(docaPoint);
233 float docaDist = xDocaDist * xDocaDist + yDocaDist * yDocaDist;
235 if (docaDist < closestDistance)
237 closestEdge =
PointPair(prevPoint,curPoint);
238 closestDistance = docaDist;
242 prevPoint = curPoint;
243 curPoint = *curPointItr++;
246 closestDistance = std::sqrt(closestDistance);
250 if (
isLeft(closestEdge.first,closestEdge.second,point)) closestDistance = -closestDistance;
257 float closestDistance;
261 return closestDistance;
MinMaxPointPair fMinMaxPointPair
std::list< Point > PointList
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.
std::pair< Point, Point > PointPair
Implements a ConvexHull for use in clustering.
float Area() const
Computes the area of the enclosed convext hull.
std::tuple< float, float, const reco::ClusterHit3D * > Point
Definitions used by the ConvexHull algorithm.
PointPair findNearestEdge(const Point &, float &) const
Given an input Point, find the nearest edge.
float findNearestDistance(const Point &) const
Given an input point, find the distance to the nearest edge/point.
const PointList & getConvexHull() const
recover the list of convex hull vertices
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.
const PointList & fPoints
ConvexHull(const PointList &)
Constructor.
virtual ~ConvexHull()
Destructor.