Go to the documentation of this file.00001 
00002 #ifndef vgl_sphere_3d_h
00003 #define vgl_sphere_3d_h
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 
00008 
00009 
00010 
00011 
00012 #include <vcl_iosfwd.h>
00013 #include <vgl/vgl_fwd.h> 
00014 #include <vgl/vgl_point_3d.h>
00015 
00016 
00017 template <class Type>
00018 class vgl_sphere_3d
00019 {
00020   vgl_point_3d<Type> c_; 
00021   Type r_;               
00022  public:
00023 
00024   
00025 
00026   
00027    inline vgl_sphere_3d (): c_(0.0, 0.0, 0.0), r_(-1) {}
00028 
00029   
00030   inline vgl_sphere_3d(Type px, Type py, Type pz, Type rad) : c_(px, py, pz), r_(rad) {}
00031 
00032   
00033   inline vgl_sphere_3d (const Type v[4]): c_(v[0], v[1], v[2]), r_(v[3]) {}
00034 
00035   
00036   vgl_sphere_3d (vgl_point_3d<Type> const& cntr, Type rad): c_(cntr), r_(rad) {}
00037 
00038   
00039   inline bool operator==(const vgl_sphere_3d<Type> &s) const { return this==&s || (c_==s.c_ && r_==s.r_); }
00040   
00041   inline bool operator!=(vgl_sphere_3d<Type>const& s) const { return !operator==(s); }
00042 
00043   
00044 
00045   inline const vgl_point_3d<Type> & centre() const {return c_;}
00046   inline Type radius() const {return r_;}
00047 
00048   
00049   inline bool is_empty() const {
00050     return r_ < 0.0;
00051   }
00052 
00053   
00054   bool contains(vgl_point_3d<Type> const& p) const;
00055 
00056   
00057   void set_empty() {c_.set(0,0,0); r_=-1;}
00058 
00059   
00060   inline void set_radius(Type r) { r_=r; }
00061   
00062   inline void set_centre(const vgl_point_3d<Type> & c) { c_=c; }
00063 
00064   
00065   bool clip(const vgl_line_3d_2_points<Type> & line,
00066             vgl_point_3d<Type> &p1, vgl_point_3d<Type> &p2) const;
00067   
00068   
00069   vcl_ostream& print(vcl_ostream& os) const;
00070 
00071   
00072   
00073   
00074   
00075   vcl_istream& read(vcl_istream& is);
00076 };
00077 
00078 
00079 
00080 template <class Type>
00081 vcl_ostream& operator<<(vcl_ostream& os, const vgl_sphere_3d<Type>& sph);
00082 
00083 
00084 
00085 
00086 
00087 template <class Type>
00088 vcl_istream& operator>>(vcl_istream& is, vgl_sphere_3d<Type>& sph);
00089 
00090 
00091 #define VGL_SPHERE_3D_INSTANTIATE(T) extern "please include vgl/vgl_sphere_3d.txx first"
00092 
00093 #endif // vgl_sphere_3d_h