core/vgl/vgl_homg_line_3d_2_points.h
Go to the documentation of this file.
00001 // This is core/vgl/vgl_homg_line_3d_2_points.h
00002 #ifndef vgl_homg_line_3d_2_points_h_
00003 #define vgl_homg_line_3d_2_points_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author Don HAMILTON Peter TU François BERTEL
00010 //
00011 // \verbatim
00012 //  Modifications
00013 //   Peter Vanroose -  4 July 2001 - constructors now use force_point2_infinite()
00014 //   Peter Vanroose - 27 June 2001 - Added operator==
00015 //   Peter Vanroose - 15 July 2002 - Added concurrent(), coplanar() and intersection()
00016 // \endverbatim
00017 
00018 #include <vcl_iosfwd.h>
00019 #include <vgl/vgl_homg_point_3d.h> // data member of this class
00020 
00021 //:Represents a homogeneous 3D line using two points
00022 // A class to hold a homogeneous representation of a 3D Line.  The line is
00023 // stored as a pair of homogeneous 3d points.
00024 template <class Type>
00025 class vgl_homg_line_3d_2_points
00026 {
00027   // Data Members------------------------------------------------------------
00028 
00029   //: Any finite point on the line
00030   mutable vgl_homg_point_3d<Type> point_finite_;
00031   //: the (unique) point at infinity
00032   mutable vgl_homg_point_3d<Type> point_infinite_;
00033 
00034  public:
00035   //+**************************************************************************
00036   // Initialization
00037   //+**************************************************************************
00038 
00039   //: Default constructor with (0,0,0,1) and (1,0,0,0), which is the line \a y=z=0
00040   inline vgl_homg_line_3d_2_points(void)
00041   : point_finite_(0,0,0,1), point_infinite_(1,0,0,0) {}
00042 
00043   //: Copy constructor
00044   inline vgl_homg_line_3d_2_points(const vgl_homg_line_3d_2_points<Type> &that)
00045   : point_finite_(that.point_finite_), point_infinite_(that.point_infinite_) {}
00046 
00047   //: Construct from two points
00048   inline vgl_homg_line_3d_2_points(vgl_homg_point_3d<Type> const& point_1,
00049                                    vgl_homg_point_3d<Type> const& point_2)
00050   : point_finite_(point_1), point_infinite_(point_2) {force_point2_infinite();}
00051 
00052 #if 0
00053   //: Destructor (does nothing)
00054   inline ~vgl_homg_line_3d_2_points() {}
00055 #endif
00056 
00057   //: comparison
00058   bool operator==(vgl_homg_line_3d_2_points<Type> const& l) const;
00059   inline bool operator!=(vgl_homg_line_3d_2_points<Type> const& l) const{return !operator==(l);}
00060 
00061   // Data access
00062 
00063   //: Finite point (Could be an ideal point, if the whole line is at infinity.)
00064   inline vgl_homg_point_3d<Type> point_finite() const {return point_finite_;}
00065   //: Infinite point: the intersection of the line with the plane at infinity
00066   inline vgl_homg_point_3d<Type> point_infinite()const{return point_infinite_;}
00067 
00068   //: Assignment
00069   inline void set(vgl_homg_point_3d<Type> const& p1, vgl_homg_point_3d<Type> const& p2)
00070   { point_finite_ = p1; point_infinite_ = p2; force_point2_infinite(); }
00071 
00072   // Utility methods
00073 
00074   //: Return true iff line is at infinity
00075   inline bool ideal(Type tol = (Type)0) const { return point_finite_.ideal(tol); }
00076 
00077  protected:
00078   //: force the point point_infinite_ to infinity, without changing the line
00079   // This is called by the constructors
00080   void force_point2_infinite(void) const; // mutable const
00081 };
00082 
00083 #define l vgl_homg_line_3d_2_points<Type>
00084 
00085 //: Return true iff line is at infinity
00086 // \relatesalso vgl_homg_line_3d_2_points
00087 template <class Type>
00088 inline bool is_ideal(l const& line, Type tol=(Type)0)
00089 { return line.ideal(tol); }
00090 
00091 //: Does a line pass through a point, i.e., are the point and the line collinear?
00092 // \relatesalso vgl_homg_line_3d_2_points
00093 // \relatesalso vgl_homg_point_3d
00094 template <class Type>
00095 inline bool collinear(l const& l1, vgl_homg_point_3d<Type> const& p)
00096 { return collinear(l1.point_finite(),l1.point_infinite(),p); }
00097 
00098 //: Are two lines coplanar, i.e., do they intersect?
00099 // \relatesalso vgl_homg_line_3d_2_points
00100 template <class Type>
00101 inline bool coplanar(l const& l1, l const& l2)
00102 { return coplanar(l1.point_finite(),l1.point_infinite(),l2.point_finite(),l2.point_infinite()); }
00103 
00104 //: Are two lines concurrent, i.e., do they intersect?
00105 // \relatesalso vgl_homg_line_3d_2_points
00106 template <class Type>
00107 inline bool concurrent(l const& l1, l const& l2) { return coplanar(l1,l2); }
00108 
00109 //: Are two points coplanar with a line?
00110 // \relatesalso vgl_homg_line_3d_2_points
00111 // \relatesalso vgl_homg_point_3d
00112 template <class Type>
00113 inline bool coplanar(l const& l1, vgl_homg_point_3d<Type> const& p1, vgl_homg_point_3d<Type> const& p2)
00114 { return coplanar(l1.point_finite(),l1.point_infinite(),p1,p2); }
00115 
00116 //: Are three lines coplanar, i.e., are they in a common plane?
00117 // \relatesalso vgl_homg_line_3d_2_points
00118 template <class Type>
00119 inline bool coplanar(l const& l1, l const& l2, l const& l3)
00120 {
00121   vgl_homg_point_3d<Type> p = l2.point_finite();
00122   if (collinear(l1,p)) p = l2.point_infinite();
00123   return coplanar(l1,l2) && coplanar(l1,l3) &&
00124          coplanar(l1,p,l3.point_finite()) &&
00125          coplanar(l1,p,l3.point_infinite());
00126 }
00127 
00128 //: Return the intersection point of two concurrent lines
00129 // \relatesalso vgl_homg_line_3d_2_points
00130 template <class Type>
00131 vgl_homg_point_3d<Type> intersection(l const& l1, l const& l2);
00132 
00133 //: Are three lines concurrent, i.e., do they pass through a common point?
00134 // \relatesalso vgl_homg_line_3d_2_points
00135 template <class Type>
00136 inline bool concurrent(l const& l1, l const& l2, l const& l3)
00137 {
00138   if (!concurrent(l1,l2) || !concurrent(l1,l3) || !concurrent(l2,l3)) return false;
00139   return intersection(l1,l2) == intersection(l1,l3);
00140 }
00141 
00142 //+****************************************************************************
00143 // stream operators
00144 //+****************************************************************************
00145 
00146 //: Write to stream (verbose)
00147 // \relatesalso vgl_homg_line_3d_2_points
00148 template <class Type>
00149 vcl_ostream &operator<<(vcl_ostream&s, l const& p);
00150 
00151 //: Read parameters from stream
00152 // \relatesalso vgl_homg_line_3d_2_points
00153 template <class Type>
00154 vcl_istream &operator>>(vcl_istream &is, l &p);
00155 
00156 #undef l
00157 
00158 #define VGL_HOMG_LINE_3D_2_POINTS_INSTANTIATE(T) extern "please include vgl/vgl_homg_line_3d_2_points.txx first"
00159 
00160 #endif // vgl_homg_line_3d_2_points_h_