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> const& box)
00032   : box_(box), orient_(vnl_quaternion<double>(vnl_vector_fixed<double,3>(0.0,0.0,1.0), 0.0)) {}
00033 
00034   //: constructor with box and the orientation
00035   vgl_orient_box_3d(vgl_box_3d<Type> const& box, vnl_quaternion<double> const& orient)
00036   : box_(box), orient_(orient) {}
00037 
00038 
00039   //: constructor from four corner points.
00040   //  The three directions from the first of these to the three other points must be mutually orthogonal.
00041   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);
00042 
00043   virtual ~vgl_orient_box_3d(void) {}
00044 
00045   inline bool operator==(vgl_orient_box_3d<Type> const& obb) const {
00046     return obb.box_ == this->box_ && obb.orient_ == this->orient_;
00047   }
00048 
00049   // dimension related Data access
00050   Type width() const { return box_.width(); }
00051   Type height() const { return box_.height(); }
00052   Type depth() const { return box_.depth(); }
00053   inline Type volume() const { return box_.width()*box_.height()*box_.depth(); }
00054   vcl_vector<vgl_point_3d<Type> > corners();
00055 
00056   //: Return true if \a (x,y,z) is inside this box
00057   bool contains(Type const& x, Type const& y, Type const& z) const;
00058 
00059   //: Return true if point is inside this box
00060   bool contains(vgl_point_3d<Type> const& p) const {return contains(p.x(), p.y(), p.z());}
00061 
00062   vcl_ostream& print(vcl_ostream& s) const;
00063 
00064   vcl_istream& read(vcl_istream& s);
00065 
00066  private:
00067   //: regular AABB(axis-aligned bounding box)
00068   vgl_box_3d<Type> box_;
00069 
00070   //: orientation of the box as a quaternion
00071   vnl_quaternion<double> orient_;
00072 };
00073 
00074 //: Write box to stream
00075 // \relatesalso vgl_box_3d
00076 template <class Type>
00077 vcl_ostream&  operator<<(vcl_ostream& s, vgl_orient_box_3d<Type> const& p);
00078 
00079 //: Read box from stream
00080 // \relatesalso vgl_box_3d
00081 template <class Type>
00082 vcl_istream&  operator>>(vcl_istream& is,  vgl_orient_box_3d<Type>& p);
00083 
00084 #define VGL_ORIENT_BOX_3D_INSTANTIATE(T) extern "Please #include <vgl/vgl_orient_box_3d.txx> instead"
00085 
00086 #endif // vgl_orient_box_3d_h