core/vgl/algo/vgl_orient_box_3d.h
Go to the documentation of this file.
00001 // This is core/vgl/algo/vgl_orient_box_3d.h
00002 #ifndef vgl_orient_box_3d_h
00003 #define vgl_orient_box_3d_h
00004 //:
00005 // \file
00006 // \brief A bounding oriented box
00007 //
00008 //  This class mimics the properties of an oriented
00009 //  box by keeping a regular axis aligned box and a
00010 //  rotation direction. It keeps a bounding box of
00011 //  the rotated box which is an axis aligned box.
00012 //
00013 // \verbatim
00014 //  Modifications
00015 //   2010-01-18 Peter Vanroose - added constructor from 4 corner points
00016 // \endverbatim
00017 
00018 #include <vgl/vgl_box_3d.h>
00019 #include <vgl/vgl_point_3d.h>
00020 #include <vnl/vnl_quaternion.h>
00021 #include <vcl_vector.h>
00022 #include <vcl_iosfwd.h>
00023 
00024 template <class Type>
00025 class vgl_orient_box_3d
00026 {
00027  public:
00028   vgl_orient_box_3d() {}
00029 
00030   //: constructor with only box definition, the direction will be set to (0,0,1) with no rotation
00031   vgl_orient_box_3d(vgl_box_3d<Type> box);
00032 
00033   //: constructor with box and the orientation
00034   vgl_orient_box_3d(vgl_box_3d<Type> box, vnl_quaternion<double> orient);
00035 
00036   //: constructor from four corner points.
00037   //  The three directions from the first of these to the three other points must be mutually orthogonal.
00038   vgl_orient_box_3d(vgl_point_3d<Type> const& p0, vgl_point_3d<Type> const& px, vgl_point_3d<Type> const& py, vgl_point_3d<Type> const& pz);
00039 
00040   virtual ~vgl_orient_box_3d(void) {}
00041 
00042   inline bool operator==(vgl_orient_box_3d<Type> const& obb) const {
00043     return obb.box_ == this->box_ && obb.orient_ == this->orient_;
00044   }
00045 
00046   // dimension related Data access
00047   Type width() const { return box_.width(); }
00048   Type height() const { return box_.height(); }
00049   Type depth() const { return box_.depth(); }
00050   inline Type volume() const { return box_.width()*box_.height()*box_.depth(); }
00051   vcl_vector<vgl_point_3d<Type> > corners();
00052 
00053   //: Return true if \a (x,y,z) is inside this box
00054   bool contains(Type const& x, Type const& y, Type const& z) const;
00055 
00056   //: Return true if point is inside this box
00057   bool contains(vgl_point_3d<Type> const& p) const
00058     {return contains(p.x(), p.y(), p.z());}
00059 
00060   vcl_ostream& print(vcl_ostream& s) const;
00061 
00062   vcl_istream& read(vcl_istream& s);
00063 
00064  private:
00065   //: regular AABB(axis-aligned bounding box)
00066   vgl_box_3d<Type> box_;
00067 
00068   //: orientation of the box as a quaternion
00069   vnl_quaternion<double> orient_;
00070 };
00071 
00072 //: Write box to stream
00073 // \relatesalso vgl_box_3d
00074 template <class Type>
00075 vcl_ostream&  operator<<(vcl_ostream& s, vgl_orient_box_3d<Type> const& p);
00076 
00077 //: Read box from stream
00078 // \relatesalso vgl_box_3d
00079 template <class Type>
00080 vcl_istream&  operator>>(vcl_istream& is,  vgl_orient_box_3d<Type>& p);
00081 
00082 #define VGL_ORIENT_BOX_3D_INSTANTIATE(T) extern "Please #include <vgl/vgl_orient_box_3d.txx> instead"
00083 
00084 #endif // vgl_orient_box_3d_h