core/vgl/vgl_ray_3d.txx
Go to the documentation of this file.
00001 // This is core/vgl/vgl_ray_3d.txx
00002 #ifndef vgl_ray_3d_txx_
00003 #define vgl_ray_3d_txx_
00004 
00005 #include "vgl_ray_3d.h"
00006 #include <vcl_cassert.h>
00007 #include <vcl_algorithm.h>
00008 #include <vcl_iostream.h>
00009 #include <vcl_cmath.h> // for fabs
00010 #include <vgl/vgl_closest_point.h>
00011 #include <vgl/vgl_tolerance.h>
00012 template <class Type>
00013 bool vgl_ray_3d<Type>::contains(const vgl_point_3d<Type>& p ) const
00014 {
00015   vgl_point_3d<Type> pcls = vgl_closest_point(*this, p); 
00016   Type len = static_cast<Type>(length(pcls-p));
00017   if(len*len > static_cast<Type>(10) * vcl_max(vgl_tolerance<Type>::position, p.x()*p.x()+p.y()*p.y()+p.z()*p.z()) * vgl_tolerance<Type>::position)
00018     return false;
00019   Type dp = dot_product(t_, pcls-p0_);
00020   Type tol = vgl_tolerance<Type>::position;
00021   return  dp >= -tol;
00022 }
00023 
00024 
00025 // stream operators
00026 template <class Type>
00027 vcl_ostream& operator<<(vcl_ostream& s, vgl_ray_3d<Type> const & p)
00028 {
00029   return s << "<vgl_ray_3d: origin" << p.origin() << " dir " << p.direction() << " >";
00030 }
00031 
00032 template <class Type>
00033 vcl_istream& operator>>(vcl_istream& s, vgl_ray_3d<Type>& r)
00034 {
00035   vgl_point_3d<Type> p0;
00036   vgl_vector_3d<Type> dir;
00037   s >> p0 >> dir;
00038   r.set(p0, dir);
00039   return s;
00040 }
00041 
00042 #undef VGL_RAY_3D_INSTANTIATE
00043 #define VGL_RAY_3D_INSTANTIATE(Type) \
00044 template class vgl_ray_3d<Type >;\
00045 template vcl_istream& operator>>(vcl_istream&, vgl_ray_3d<Type >&);\
00046 template vcl_ostream& operator<<(vcl_ostream&, vgl_ray_3d<Type > const&)
00047 
00048 #endif // vgl_ray_3d_txx_