Go to the documentation of this file.00001
00002 #ifndef vgl_ray_3d_h_
00003 #define vgl_ray_3d_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <vcl_iosfwd.h>
00018 #include <vgl/vgl_vector_3d.h>
00019 #include <vgl/vgl_point_3d.h>
00020 #include <vgl/vgl_line_segment_3d.h>
00021 #include <vgl/vgl_line_3d_2_points.h>
00022
00023
00024
00025
00026 template <class Type>
00027 class vgl_ray_3d
00028 {
00029 vgl_point_3d<Type> p0_;
00030 vgl_vector_3d<Type> t_;
00031 public:
00032
00033 inline vgl_ray_3d() {}
00034
00035
00036 inline vgl_ray_3d(vgl_ray_3d<Type> const& l)
00037 : p0_(l.origin()), t_(l.direction()) {}
00038
00039
00040 inline vgl_ray_3d(vgl_point_3d<Type> const& p0,
00041 vgl_vector_3d<Type> const& direction)
00042 : p0_(p0), t_(direction) {t_ = t_/static_cast<Type>(t_.length());}
00043
00044
00045 inline vgl_ray_3d(vgl_point_3d<Type> const& origin,
00046 vgl_point_3d<Type> const& p)
00047 : p0_(origin), t_(p-origin) {t_ = t_/static_cast<Type>(t_.length());}
00048
00049 inline vgl_ray_3d(vgl_line_segment_3d<Type> const& ls)
00050 {
00051 p0_ = ls.point1(); t_ = ls.point2()-p0_;
00052 t_ = t_/static_cast<Type>(t_.length());
00053 }
00054
00055
00056 inline vgl_ray_3d(vgl_line_3d_2_points<Type> const& ls)
00057 {
00058 p0_ = ls.point1(); t_ = ls.point2()-p0_;
00059 t_ = t_/static_cast<Type>(t_.length());
00060 }
00061
00062
00063 inline ~vgl_ray_3d() {}
00064
00065
00066 inline vgl_point_3d<Type> origin() const { return p0_; }
00067
00068 inline vgl_vector_3d<Type> direction() const
00069 { return t_/static_cast<Type>(t_.length()); }
00070
00071
00072 inline bool operator==(vgl_ray_3d<Type> const& r) const
00073 { return (this==&r)||(direction()==r.direction() && origin()==r.origin());}
00074
00075 inline bool operator!=(vgl_ray_3d<Type>const& other) const
00076 { return !operator==(other); }
00077
00078
00079 inline void set(vgl_point_3d<Type> const& p0, vgl_vector_3d<Type> const& direction)
00080 {
00081 p0_ = p0; t_ = direction;
00082 t_=t_/static_cast<Type>(t_.length());
00083 }
00084
00085
00086 bool contains(const vgl_point_3d<Type>& p ) const;
00087
00088 };
00089
00090
00091
00092 template <class Type>
00093 vcl_ostream& operator<<(vcl_ostream& s, const vgl_ray_3d<Type>& p);
00094
00095
00096
00097 template <class Type>
00098 vcl_istream& operator>>(vcl_istream& is, vgl_ray_3d<Type>& p);
00099
00100 template <class Type>
00101
00102 double angle(vgl_ray_3d<Type> const& r0, vgl_ray_3d<Type> const& r1)
00103 {
00104 return angle(r0.direction(), r1.direction());
00105 }
00106 #define VGL_RAY_3D_INSTANTIATE(T) extern "please include vgl/vgl_ray_3d.txx first"
00107
00108 #endif // vgl_ray_3d_h_