vgl_orient_box_3d.h
Go to the documentation of this file.
1 // This is core/vgl/algo/vgl_orient_box_3d.h
2 #ifndef vgl_orient_box_3d_h
3 #define vgl_orient_box_3d_h
4 //:
5 // \file
6 // \brief A bounding oriented box
7 //
8 // This class mimics the properties of an oriented
9 // box by keeping a regular axis aligned box and a
10 // rotation direction. It keeps a bounding box of
11 // the rotated box which is an axis aligned box.
12 //
13 // \verbatim
14 // Modifications
15 // 2010-01-18 Peter Vanroose - added constructor from 4 corner points
16 // \endverbatim
17 
18 #include <vector>
19 #include <iosfwd>
20 #include <vgl/vgl_box_3d.h>
21 #include <vgl/vgl_point_3d.h>
22 #include <vnl/vnl_quaternion.h>
23 #ifdef _MSC_VER
24 # include <vcl_msvc_warnings.h>
25 #endif
26 
27 template <class Type>
29 {
30  public:
31  vgl_orient_box_3d() = default;
32 
33  //: constructor with only box definition, the direction will be set to (0,0,1) with no rotation
35  : box_(box), orient_(vnl_quaternion<double>(vnl_vector_fixed<double,3>(0.0,0.0,1.0), 0.0)) {}
36 
37  //: constructor with box and the orientation
38  vgl_orient_box_3d(vgl_box_3d<Type> const& box, vnl_quaternion<double> const& orient)
39  : box_(box), orient_(orient) {}
40 
41 
42  //: constructor from four corner points.
43  // The three directions from the first of these to the three other points must be mutually orthogonal.
45 
46  virtual ~vgl_orient_box_3d(void) = default;
47 
48  inline bool operator==(vgl_orient_box_3d<Type> const& obb) const {
49  return obb.box_ == this->box_ && obb.orient_ == this->orient_;
50  }
51 
52  // dimension related Data access
53  Type width() const { return box_.width(); }
54  Type height() const { return box_.height(); }
55  Type depth() const { return box_.depth(); }
56  inline Type volume() const { return box_.width()*box_.height()*box_.depth(); }
57  std::vector<vgl_point_3d<Type> > corners() const;
58  vgl_point_3d<Type> centroid() {return box_.centroid(); }
59  vgl_box_3d<Type> const box() {return box_; }
60 
61  //: The axis-aligned box that encloses the oriented box
63 
64  //: Return true if \a (x,y,z) is inside this box
65  bool contains(Type const& x, Type const& y, Type const& z) const;
66 
67  //: Return true if point is inside this box
68  bool contains(vgl_point_3d<Type> const& p) const {return contains(p.x(), p.y(), p.z());}
69 
70  std::ostream& print(std::ostream& s) const;
71 
72  std::istream& read(std::istream& s);
73 
74  //private:
75  //: regular AABB(axis-aligned bounding box)
77 
78  //: orientation of the box as a quaternion
79  vnl_quaternion<double> orient_;
80 };
81 
82 //: Write box to stream
83 // \relatesalso vgl_box_3d
84 template <class Type>
85 std::ostream& operator<<(std::ostream& s, vgl_orient_box_3d<Type> const& p);
86 
87 //: Read box from stream
88 // \relatesalso vgl_box_3d
89 template <class Type>
90 std::istream& operator>>(std::istream& is, vgl_orient_box_3d<Type>& p);
91 
92 #define VGL_ORIENT_BOX_3D_INSTANTIATE(T) extern "Please #include <vgl/vgl_orient_box_3d.hxx> instead"
93 
94 #endif // vgl_orient_box_3d_h
vgl_orient_box_3d()=default
vgl_point_3d< Type > centroid()
bool contains(Type const &x, Type const &y, Type const &z) const
Return true if (x,y,z) is inside this box.
vgl_orient_box_3d(vgl_box_3d< Type > const &box, vnl_quaternion< double > const &orient)
constructor with box and the orientation.
vgl_box_3d< Type > box_
regular AABB(axis-aligned bounding box).
Contains class to represent a cartesian 3D bounding box.
Represents a cartesian 3D point.
Definition: vgl_fwd.h:11
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
vgl_orient_box_3d(vgl_box_3d< Type > const &box)
constructor with only box definition, the direction will be set to (0,0,1) with no rotation.
Type & z()
Definition: vgl_point_3d.h:73
virtual ~vgl_orient_box_3d(void)=default
std::vector< vgl_point_3d< Type > > corners() const
returns the 8 corner points of the box.
vnl_quaternion< double > orient_
orientation of the box as a quaternion.
a point in 3D nonhomogeneous space
std::istream & read(std::istream &s)
bool operator==(vgl_orient_box_3d< Type > const &obb) const
Type & x()
Definition: vgl_point_3d.h:71
vgl_box_3d< Type > enclosing_box() const
The axis-aligned box that encloses the oriented box.
std::istream & operator>>(std::istream &is, vgl_orient_box_3d< Type > &p)
Read box from stream.
bool contains(vgl_point_3d< Type > const &p) const
Return true if point is inside this box.
std::ostream & print(std::ostream &s) const
Represents a cartesian 3D box.
Definition: vgl_box_3d.h:65
Type & y()
Definition: vgl_point_3d.h:72
vgl_box_3d< Type > const box()