3 #include <vnl/vnl_math.h> 12 for(
size_t is = 0; is<ns; ++is)
13 for(
size_t i = 0; i<poly[is].size(); ++i)
14 pts_.push_back(poly[is][i]);
20 T min_area = std::numeric_limits<T>::max();
21 size_t n = pts_.size();
23 std::cout <<
"insufficient number of points to fit obox " << n << std::endl;
28 T T_pi_2 = static_cast<T>(vnl_math::pi_over_2);
29 T low_theta = -T_pi_2, high_theta = T_pi_2;
33 low_theta = -theta_rad;
34 high_theta = -theta_rad;
37 for(T theta = low_theta; theta <= high_theta; theta += dtheta_){
38 T c = cos(theta), s = sin(theta);
40 for(
size_t j = 0; j<n; ++j){
52 T width = w, height = h;
57 pmaj0.
set(cent.
x(), cent.
y()-width/2.0); pmaj1.set(cent.
x(), cent.
y()+width/2.0);
60 c = cos(-theta); s = sin(-theta);
61 T pmaj0x = pmaj0.x(), pmaj0y = pmaj0.y();
62 T pmaj1x = pmaj1.x(), pmaj1y = pmaj1.y();
68 pmaj0r += offset; pmaj1r += offset;
72 obox_ = min_area_obox;
84 #undef VGL_FIT_ORIENTED_BOX_2D_INSTANTIATE 85 #define VGL_FIT_ORIENTED_BOX_2D_INSTANTIATE(T) \ 86 template class vgl_fit_oriented_box_2d<T > vgl_fit_oriented_box_2d()
default constructor.
Direction vector in Euclidean 2D space, templated by type of element.
Type width() const
Get width of this box (= x dimension).
void set(Type px, Type py)
Set x and y.
vgl_oriented_box_2d< T > fitted_box()
brute force search.
Contains class to represent a cartesian 2D bounding box.
vgl_point_2d< Type > centroid() const
Get the centroid point.
std::vector< vgl_point_2d< T > > pts_
void fit_obox(T theta_rad=T(0))
Type height() const
Get height of this box (= y dimension).
void add(vgl_point_2d< Type > const &p)
Add a point to this box.
Fit an oriented box to a set of 2d points.
unsigned int num_sheets() const
T vgl_area(vgl_polygon< T > const &poly)
The area of a polygon.