core/vgl/vgl_infinite_line_3d.h
Go to the documentation of this file.
00001 // This is core/vgl/vgl_infinite_line_3d.h
00002 #ifndef vgl_infinite_line_3d_h_
00003 #define vgl_infinite_line_3d_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief A 3-d infinite line with position parameterized by orthogonal plane coordinates
00010 // \author  J.L. Mundy
00011 //
00012 // \verbatim
00013 // Modifications
00014 // Initial version July 25, 2009
00015 // \endverbatim
00016 
00017 #include <vcl_iosfwd.h>
00018 #include <vgl/vgl_vector_2d.h>
00019 #include <vgl/vgl_vector_3d.h>
00020 #include <vgl/vgl_point_3d.h>
00021 #include <vgl/vgl_line_segment_3d.h>
00022 #include <vgl/vgl_line_3d_2_points.h>
00023 
00024 //: Represents a 3-d line with position defined in the orthogonal plane passing through the origin.
00025 //  The line direction is t_.
00026 //  The 2-d plane coordinate system (u, v) is aligned with the 3-d coordinate
00027 //  system (X, Y, X), where v = t x X and u = v x t.
00028 template <class Type>
00029 class vgl_infinite_line_3d
00030 {
00031   vgl_vector_2d<Type> x0_; //!< line position vector
00032   vgl_vector_3d<Type> t_;  //!< line direction vector (tangent)
00033  public:
00034   //: Default constructor - does not initialise!
00035   inline vgl_infinite_line_3d() {}
00036 
00037   //: Copy constructor
00038   inline vgl_infinite_line_3d(vgl_infinite_line_3d<Type> const& l)
00039     : x0_(l.x0()), t_(l.direction()) {}
00040 
00041   //: Construct from x0 and direction
00042   inline vgl_infinite_line_3d(vgl_vector_2d<Type> const& x_0,
00043                               vgl_vector_3d<Type> const& direction)
00044     : x0_(x_0), t_(direction) {}
00045 
00046   //: Construct from two points
00047   vgl_infinite_line_3d(vgl_point_3d<Type> const& p1,
00048                        vgl_point_3d<Type> const& p2);
00049 
00050   //: Construct from a point and direction
00051   vgl_infinite_line_3d(vgl_point_3d<Type> const& p,
00052                        vgl_vector_3d<Type> const& direction);
00053 
00054   //: Construct from a line segment
00055   inline vgl_infinite_line_3d(vgl_line_segment_3d<Type> const& ls)
00056   {
00057     vgl_infinite_line_3d<Type> inf_l(ls.point1(), ls.point2());
00058     x0_ = inf_l.x0(); t_ = inf_l.direction();
00059   }
00060 
00061   //: Construct from a line 2 points
00062   inline vgl_infinite_line_3d(vgl_line_3d_2_points<Type> const& ls)
00063   {
00064     vgl_infinite_line_3d<Type> inf_l(ls.point1(), ls.point2());
00065     x0_ = inf_l.x0(); t_ = inf_l.direction();
00066   }
00067 
00068   //: Destructor
00069   inline ~vgl_infinite_line_3d() {}
00070 
00071   //: Accessors
00072   inline vgl_vector_2d<Type> x0() const { return x0_; } // return a copy
00073   inline vgl_vector_3d<Type> direction() const
00074   { return t_/static_cast<Type>(t_.length()); } // return a copy
00075 
00076   //: The comparison operator
00077   inline bool operator==(vgl_infinite_line_3d<Type> const& l) const
00078   { return (this==&l) || (direction() == l.direction() && x0() == l.x0()); }
00079 
00080   inline bool operator!=(vgl_infinite_line_3d<Type>const& other) const
00081   { return !operator==(other); }
00082 
00083   //: Assignment
00084   inline void set(vgl_vector_2d<Type> const& x_0, vgl_vector_3d<Type> const& direction)
00085   { x0_ = x_0; t_ = direction; }
00086 
00087   //: Return the point on the line closest to the origin
00088   vgl_point_3d<Type> point() const;
00089 
00090   //: Return a point on the line defined by a scalar parameter \a t.
00091   // \a t=0.0 corresponds to the closest point on the line to the origin
00092   vgl_point_3d<Type> point_t(const double t) const { return point() + t*direction(); }
00093 
00094   //: Check if point \a p is on the line
00095   bool contains(const vgl_point_3d<Type>& p ) const;
00096 
00097   //: The unit vectors perpendicular to the line direction
00098   void compute_uv_vectors(vgl_vector_3d<Type>& u, vgl_vector_3d<Type>& v) const;
00099 };
00100 
00101 //: Write to stream
00102 // \relatesalso vgl_infinite_line_3d
00103 template <class Type>
00104 vcl_ostream&  operator<<(vcl_ostream& s, const vgl_infinite_line_3d<Type>& p);
00105 
00106 //: Read from stream
00107 // \relatesalso vgl_infinite_line_3d
00108 template <class Type>
00109 vcl_istream&  operator>>(vcl_istream& is,  vgl_infinite_line_3d<Type>& p);
00110 #define VGL_INFINITE_LINE_3D_INSTANTIATE(T) extern "please include vgl/vgl_infinite_line_3d.txx first"
00111 
00112 #endif // vgl_infinite_line_3d_h_