15 std::cout <<
"width must be greater than height!!!" << std::endl;
19 half_height_ = height/T(2);
20 T half_width = width/T(2);
21 T cx = center.
x(), cy = center.
y();
22 T c = cos(angle_in_rad), s = sin(angle_in_rad);
24 T p0x = - half_width, p1x = half_width;
25 T p0rx = c*p0x , p0ry = s*p0x ;
26 T p1rx = c*p1x , p1ry = s*p1x ;
28 p0rx += cx; p1rx += cx;
29 p0ry += cy; p1ry += cy;
31 major_axis_.set(p0r, p1r);
42 T width = w, height = h;
47 ang += T(3.1415926535897932384626433832795)/T(2);
55 T len_01 = v01.
length(), len_02 = v02.length();
58 half_height_ = len_02/T(2);
61 major_axis_.
set( p0p, p1p);
65 half_height_ = len_01/T(2);
68 major_axis_.
set( p0p, p2p);
79 assert(min_dir.
length()>T(0));
80 half_height_ = fabs(
dot_product(min_dir, perp))/T(2);
87 major_axis_.
set(maj_p1_c, maj_p2_c);
94 std::vector<vgl_point_2d<T> > corns = this->corners();
95 for(
typename std::vector<
vgl_point_2d<T> >::iterator cit = corns.begin();
96 cit != corns.end(); ++cit)
104 std::pair<T, T> ret(len, T(2)*half_height_);
122 std::vector<vgl_point_2d<T> > corns;
123 corns.push_back(p0); corns.push_back(p1);
124 corns.push_back(p2); corns.push_back(p3);
136 os <<
"major axis: " << obox.
major_axis() <<
" half_height: " << obox.
height()/T(2)<<
"\n";
143 T half_height = T(0);
146 is >> maj >> temp >> half_height;
147 obox.
set(maj, half_height);
156 T mag = (major_axis_.point2()-major_axis_.point1()).
length();
168 if(uv.
x()<-half || uv.
x()>half)
170 if(uv.
y()<-half || uv.
y()>half)
178 T ob_half_height = ob.
height()/T(2);
179 if(fabs(ob_half_height - half_height_) > tol)
202 return atan2(
v.y(),
v.x());
207 T c = cos(ang_rad), s = sin(ang_rad);
208 T vrx =
v.x()*c -
v.y()*s;
209 T vry =
v.x()*s +
v.y()*c;
217 rotate_point(rot_center, major_axis_.point1(), angle_rad);
219 rotate_point(rot_center, major_axis_.point2(), angle_rad);
230 #undef VGL_ORIENTED_BOX_2D_INSTANTIATE 231 #define VGL_ORIENTED_BOX_2D_INSTANTIATE(T) \ 232 template class vgl_oriented_box_2d<T >; \ 233 template std::ostream& operator<<(std::ostream&, const vgl_oriented_box_2d<T >&); \ 234 template std::istream& operator>>(std::istream&, vgl_oriented_box_2d<T >&)
T dot_product(v const &a, v const &b)
dot product or inner product of two vectors.
T angle_in_rad() const
: orientedation of major axis on the range +- pi (as returned by atan2).
vgl_oriented_box_2d()
default constructor.
Direction vector in Euclidean 2D space, templated by type of element.
vgl_oriented_box_2d< T > translate(T tx, T ty) const
translate by displacement (tx, ty).
vgl_point_2d< Type > point2() const
The other end-point of the line segment.
double length() const
Return the length of this vector.
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
void set(T vx, T vy)
Assignment.
Type width() const
Get width of this box (= x dimension).
double length(v const &a)
Return the length of a vector.
Set of closest-point functions.
std::pair< T, T > width_height() const
return width (first) and height (second).
vgl_box_2d< T > enclosing_box() const
axis-aligned bounding box for *this.
vgl_point_2d< T > vgl_closest_point(vgl_line_2d< T > const &l, vgl_point_2d< T > const &p)
Return the point on the given line closest to the given point.
void set(Type px, Type py)
Set x and y.
T height() const
height - length of minor axis.
bool contains(T const &x, T const &y) const
Return true if (x,y) is inside this box.
void set(vgl_line_segment_2d< T > const &major, T half_height)
direction vector in Euclidean 2D space
Contains class to represent a cartesian 2D bounding box.
vgl_point_2d< T > centroid() const
center (midpoint of major axis).
std::vector< vgl_point_2d< T > > corners() const
corners of the orienteded rectangle.
vgl_point_2d< Type > centroid() const
Get the centroid point.
std::istream & operator>>(std::istream &is, vgl_orient_box_3d< Type > &p)
Read box from stream.
vgl_line_segment_2d< T > major_axis() const
major axis.
Type height() const
Get height of this box (= y dimension).
void add(vgl_point_2d< Type > const &p)
Add a point to this box.
bool near_equal(vgl_oriented_box_2d< T > const &ob, T tol=vgl_tolerance< T >::position) const
vgl_point_2d< T > transform_to_obox(vgl_point_2d< T > const &p) const
map a point to the (u, v) coordinate system of the orienteded box.
An orienteded box in 2-d.
vgl_point_2d< Type > point1() const
One end-point of the line segment.
vgl_oriented_box_2d< T > rotate(vgl_point_2d< T > const &rot_center, T angle_rad) const
rotate by angle in radians.