vgl_ray_3d.hxx
Go to the documentation of this file.
1 // This is core/vgl/vgl_ray_3d.hxx
2 #ifndef vgl_ray_3d_hxx_
3 #define vgl_ray_3d_hxx_
4 
5 #include <algorithm>
6 #include <iostream>
7 #include <cmath>
8 #include "vgl_ray_3d.h"
9 #include <cassert>
10 #ifdef _MSC_VER
11 # include <vcl_msvc_warnings.h>
12 #endif
13 #include <vgl/vgl_closest_point.h>
14 #include <vgl/vgl_tolerance.h>
15 template <class Type>
17 {
18  vgl_point_3d<Type> pcls = vgl_closest_point(*this, p);
19  Type len = static_cast<Type>(length(pcls-p));
20  if(len*len > static_cast<Type>(10) * std::max(vgl_tolerance<Type>::position, p.x()*p.x()+p.y()*p.y()+p.z()*p.z()) * vgl_tolerance<Type>::position)
21  return false;
22  Type dp = dot_product(t_, pcls-p0_);
24  return dp >= -tol;
25 }
26 
27 
28 // stream operators
29 template <class Type>
30 std::ostream& operator<<(std::ostream& s, vgl_ray_3d<Type> const & p)
31 {
32  return s << "<vgl_ray_3d: origin" << p.origin() << " dir " << p.direction() << " >";
33 }
34 
35 template <class Type>
36 std::istream& operator>>(std::istream& s, vgl_ray_3d<Type>& r)
37 {
40  s >> p0 >> dir;
41  r.set(p0, dir);
42  return s;
43 }
44 
45 #undef VGL_RAY_3D_INSTANTIATE
46 #define VGL_RAY_3D_INSTANTIATE(Type) \
47 template class vgl_ray_3d<Type >;\
48 template std::istream& operator>>(std::istream&, vgl_ray_3d<Type >&);\
49 template std::ostream& operator<<(std::ostream&, vgl_ray_3d<Type > const&)
50 
51 #endif // vgl_ray_3d_hxx_
T dot_product(v const &a, v const &b)
dot product or inner product of two vectors.
Represents a cartesian 3D point.
Definition: vgl_fwd.h:11
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
A 3-d ray defined by an origin and a direction vector.
double length(v const &a)
Return the length of a vector.
Definition: vgl_vector_2d.h:94
Type & z()
Definition: vgl_point_3d.h:73
Set of closest-point functions.
vgl_point_2d< T > vgl_closest_point(vgl_line_2d< T > const &l, vgl_point_2d< T > const &p)
Return the point on the given line closest to the given point.
Represents a 3-d ray.
Definition: vgl_fwd.h:21
vgl_point_3d< Type > origin() const
Accessors.
Definition: vgl_ray_3d.h:66
Type & x()
Definition: vgl_point_3d.h:71
std::istream & operator>>(std::istream &is, vgl_orient_box_3d< Type > &p)
Read box from stream.
void set(vgl_point_3d< Type > const &p0, vgl_vector_3d< Type > const &direction)
Assignment.
Definition: vgl_ray_3d.h:79
bool contains(const vgl_point_3d< Type > &p) const
Check if point p is on the ray and lies in the positive ray direction.
Definition: vgl_ray_3d.hxx:16
vgl_vector_3d< Type > direction() const
Definition: vgl_ray_3d.h:68
Type & y()
Definition: vgl_point_3d.h:72