core/vgl/algo/vgl_ellipsoid_3d.h
Go to the documentation of this file.
00001 // This is core/vgl/algo/vgl_ellipsoid_3d.h
00002 #ifndef vgl_ellipsoid_3d_h_
00003 #define vgl_ellipsoid_3d_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Ellipsoid in 3D, defined by centre point, rotation, 3 axis halflengths
00010 //
00011 // Consider this ellipsoid as being constructed from the unit sphere by first
00012 // extruding along the X, Y and Z axes by the extrusion factors x_halflength(),
00013 // y_halflength() and z_halflength(), then rotating around the origin by the
00014 // given vgl_rotation_3d, and finally translating such that the point (0,0,0)
00015 // moves to the given centre point.
00016 //
00017 // \author Peter Vanroose, Leuven, Belgium
00018 // \date   12 June 2009
00019 //
00020 // \verbatim
00021 //  Modifications
00022 //   Jun 2009 created
00023 // \endverbatim
00024 
00025 #include <vgl/vgl_point_3d.h>
00026 #include <vgl/algo/vgl_rotation_3d.h>
00027 #include <vcl_iosfwd.h>
00028 
00029 template <class T>
00030 class vgl_ellipsoid_3d
00031 {
00032   vgl_point_3d<T> center_;
00033   T x_halflength_;
00034   T y_halflength_;
00035   T z_halflength_;
00036   vgl_rotation_3d<T> orientation_;
00037 
00038  public:
00039   //: Default constructor: no initialisations
00040   vgl_ellipsoid_3d() {}
00041 
00042   //: Construct from a center point, three extrusion factors, and optionally a rotation
00043   vgl_ellipsoid_3d(vgl_point_3d<T> const& cntr,
00044                    T x_halflen,
00045                    T y_halflen,
00046                    T z_halflen,
00047                    vgl_rotation_3d<T> const& orient = vgl_rotation_3d<T>())
00048   : center_(cntr), x_halflength_(x_halflen), y_halflength_(y_halflen), z_halflength_(z_halflen), orientation_(orient) {}
00049 
00050   //: returns the symmetry point (centre) of the ellipsoid
00051   vgl_point_3d<T> center() const { return center_; }
00052   //: returns the scaling factor along the first principal axis
00053   T x_halflength() const { return x_halflength_; }
00054   //: returns the scaling factor along the second principal axis
00055   T y_halflength() const { return y_halflength_; }
00056   //: returns the scaling factor along the third principal axis
00057   T z_halflength() const { return z_halflength_; }
00058   //: returns the rotation that created this ellipsoid from an axes-aligned one
00059   vgl_rotation_3d<T> orientation() const { return orientation_; }
00060 
00061   //: shifts (translates) the ellipsoid by setting its symmetry point (centre)
00062   void set_center(vgl_point_3d<T> const& cntr) { center_ = cntr; }
00063   //: sets the rotation that would create this ellipsoid from an axes-aligned one
00064   void set_orientation(vgl_rotation_3d<T> orient) { orientation_ = orient; }
00065   //: sets the scalings along the three principal axes
00066   void set_halflengths(T x, T y, T z) { x_halflength_ = x; y_halflength_ = y; z_halflength_ = z; }
00067 
00068   //: comparison operator
00069   bool operator==(vgl_ellipsoid_3d<T> const& e) const;
00070 
00071   //: Writes "<vgl_ellipsoid_3d center=(x0,y0,z0), orientation, size=(x_hl,y_hl,z_hl)" to stream
00072   vcl_ostream& print(vcl_ostream& s) const;
00073 };
00074 
00075 //: Writes "<vgl_ellipsoid_3d center=(x0,y0,z0), orientation, size=(x_hl,y_hl,z_hl)" to stream
00076 template <class T>
00077 vcl_ostream& operator<<(vcl_ostream& os, vgl_ellipsoid_3d<T> const& e) { e.print(os); return os; }
00078 
00079 #define VGL_ELLIPSOID_3D_INSTANTIATE(T) extern "please include vgl/vgl_ellipsoid_3d.txx first"
00080 
00081 #endif // vgl_ellipsoid_3d_h_