core/vgl/vgl_1d_basis.txx
Go to the documentation of this file.
00001 // This is core/vgl/vgl_1d_basis.txx
00002 #ifndef vgl_1d_basis_txx_
00003 #define vgl_1d_basis_txx_
00004 
00005 #include "vgl_1d_basis.h"
00006 #include <vcl_cassert.h>
00007 #include <vcl_iostream.h>
00008 
00009 template <class T>
00010 vgl_1d_basis<T>::vgl_1d_basis(T const& o, T const& u, T const& i)
00011   : origin_(o), unity_(u), inf_pt_(i), affine_(false)
00012 {
00013   assert(collinear(o,i,u) && o!=i && o!=u && i!=u);
00014 }
00015 
00016 template <class T>
00017 vgl_1d_basis<T>::vgl_1d_basis(T const& o, T const& u)
00018   : origin_(o), unity_(u), affine_(true)
00019 {
00020   assert(o!=u && !is_ideal(o) && !is_ideal(u));
00021 }
00022 
00023 template <class T>
00024 vgl_homg_point_1d<double> vgl_1d_basis<T>::project(T const& p)
00025 {
00026   if (affine_) // In this case, do not use the uninitialised inf_pt_
00027   {
00028     double d = ratio(origin_,unity_,p);
00029     return vgl_homg_point_1d<double>(d,1);
00030   }
00031   else // !affine_
00032   {
00033     if (p == inf_pt_) return vgl_homg_point_1d<double>(1,0);
00034     double d = cross_ratio(inf_pt_,origin_,unity_,p);
00035     return vgl_homg_point_1d<double>(d,1);
00036   }
00037 }
00038 
00039 template <class T>
00040 vcl_ostream& operator<<(vcl_ostream& s, vgl_1d_basis<T> const& b)
00041 {
00042   s << "<vgl_1d_basis "<< b.origin() << ' ' << b.unity();
00043   if (!b.affine()) s << ' ' << b.inf_pt();
00044   s <<  " > ";
00045   return s;
00046 }
00047 
00048 #undef VGL_1D_BASIS_INSTANTIATE
00049 #define VGL_1D_BASIS_INSTANTIATE(T) \
00050 template class vgl_1d_basis<T >;\
00051 template vcl_ostream& operator<<(vcl_ostream&, vgl_1d_basis<T > const&)
00052 
00053 #endif // vgl_1d_basis_txx_