vgl_fit_oriented_box_2d.h
Go to the documentation of this file.
1 // This is core/vgl/vgl_fit_oriented_box_2d.h
2 #ifndef vgl_fit_oriented_box_2d_h_
3 #define vgl_fit_oriented_box_2d_h_
4 
5 #include <iostream>
6 #include <map>
7 #include <utility>
8 #include <vector>
11 #include <vgl/vgl_point_2d.h>
12 #include <vgl/vgl_polygon.h>
13 #include <vgl/vgl_tolerance.h>
14 //:
15 // \file
16 // \brief Fit an oriented box to a set of 2d points
17 // \author J.L. Mundy
18 // \date November 12, 2017
19 //
20 // a brute force algorithm: try all angles with granularity dtheta return obox with minimum area
21 #define default_dtheta 0.0174524 // one degree
22 template <class T>
24  public:
25  //:default constructor
27 
28  //: constructor with polygon
29  vgl_fit_oriented_box_2d(vgl_polygon<T> const& poly, double dtheta = default_dtheta);
30 
31  //: constructor with points
32  vgl_fit_oriented_box_2d(std::vector<vgl_point_2d<T> > pts, double dtheta = default_dtheta):
33  fixed_theta_(false), fit_valid_(false), dtheta_(dtheta), pts_(std::move(pts)){}
34 
35  //: brute force search
37 
38  //: fit box with specified oriention
39  // theta is defined ccw with respect to the x-axis
41  if(!fit_valid_){
42  fixed_theta_ = true;
43  fit_obox(theta_rad);
44  fit_valid_ = true;
45  }
46  return obox_;
47  }
48 
49  private:
51  void fit_obox(T theta_rad = T(0));
52  bool fit_valid_;
53  double dtheta_;
54  std::vector<vgl_point_2d<T> > pts_;
56 };
57 
58 #define VGL_FIT_ORIENTED_BOX_2D_INSTANTIATE(T) extern "please include vgl/algo/vgl_fit_oriented_box_2d.hxx first"
59 
60 #endif // vgl_fit_oriented_box_2d_h_
a point in 2D nonhomogeneous space
vgl_fit_oriented_box_2d()
default constructor.
vgl_oriented_box_2d< T > fitted_box(double theta_rad)
fit box with specified oriention.
vgl_oriented_box_2d< T > obox_
vgl_oriented_box_2d< T > fitted_box()
brute force search.
#define default_dtheta
std::vector< vgl_point_2d< T > > pts_
void fit_obox(T theta_rad=T(0))
vgl_fit_oriented_box_2d(std::vector< vgl_point_2d< T > > pts, double dtheta=default_dtheta)
constructor with points.
Store a polygon.
Definition: vgl_area.h:6
An orienteded box in 2-d.