2 #ifndef vgl_convex_hxx_ 3 #define vgl_convex_hxx_ 11 # include <vcl_msvc_warnings.h> 25 double eps = std::sqrt(current.x() * current.x() + current.y() * current.y())
26 * std::numeric_limits<T>::epsilon();
30 if (
v.length() <= eps)
return (T)2.0;
38 if (points.empty())
return hull;
40 typedef typename std::list<vgl_point_2d<T> >::iterator ITER;
43 std::list<vgl_point_2d<T> > pts(points.begin(), points.end());
46 ITER start = pts.begin();
47 for (ITER i=pts.begin(); i != pts.end(); ++i)
48 if (i->x() < start->x()) start=i;
55 bool not_starting =
false;
60 if (pts.empty())
return hull;
63 double nc_angle_to_first = get_nc_angle(last_dir, current, first);
67 if (not_starting && nc_angle_to_first > 1.5)
return hull;
70 double best_nc_angle = 1.5;
73 for (ITER i=pts.begin(); i != pts.end(); ++i)
75 double nc_angle = get_nc_angle(last_dir, current, *i);
76 if (nc_angle < best_nc_angle)
78 best_nc_angle = nc_angle;
84 if (nc_angle_to_first <= best_nc_angle)
return hull;
89 last_dir=*best - current;
95 #undef VGL_CONVEX_INSTANTIATE 96 #define VGL_CONVEX_INSTANTIATE(T) \ 97 template vgl_polygon<T > vgl_convex_hull(const std::vector<vgl_point_2d<T > >&) 100 #endif // vgl_convex_hxx_ Direction vector in Euclidean 2D space, templated by type of element.
vgl_polygon< T > vgl_convex_hull(std::vector< vgl_point_2d< T > > const &points)
Return a single-sheet polygon which is the smallest one containing all given points.
Functions such as convex hull, convex union, convexify polygon, ...
void push_back(T x, T y)
Add a new point to the last sheet.
double cos_angle(v const &a, v const &b)
cosine of the angle between two vectors.