vgl_1d_basis.hxx
Go to the documentation of this file.
1 // This is core/vgl/vgl_1d_basis.hxx
2 #ifndef vgl_1d_basis_hxx_
3 #define vgl_1d_basis_hxx_
4 
5 #include <iostream>
6 #include "vgl_1d_basis.h"
7 #include <cassert>
8 #ifdef _MSC_VER
9 # include <vcl_msvc_warnings.h>
10 #endif
11 
12 template <class T>
13 vgl_1d_basis<T>::vgl_1d_basis(T const& o, T const& u, T const& i)
14  : origin_(o), unity_(u), inf_pt_(i), affine_(false)
15 {
16  assert(collinear(o,i,u) && o!=i && o!=u && i!=u);
17 }
18 
19 template <class T>
20 vgl_1d_basis<T>::vgl_1d_basis(T const& o, T const& u)
21  : origin_(o), unity_(u), affine_(true)
22 {
23  assert(o!=u && !is_ideal(o) && !is_ideal(u));
24 }
25 
26 template <class T>
28 {
29  if (affine_) // In this case, do not use the uninitialised inf_pt_
30  {
31  double d = ratio(origin_,unity_,p);
32  return {d,1};
33  }
34  else // !affine_
35  {
36  if (p == inf_pt_) return {1,0};
37  double d = cross_ratio(inf_pt_,origin_,unity_,p);
38  return {d,1};
39  }
40 }
41 
42 template <class T>
43 std::ostream& operator<<(std::ostream& s, vgl_1d_basis<T> const& b)
44 {
45  s << "<vgl_1d_basis "<< b.origin() << ' ' << b.unity();
46  if (!b.affine()) s << ' ' << b.inf_pt();
47  s << " > ";
48  return s;
49 }
50 
51 #undef VGL_1D_BASIS_INSTANTIATE
52 #define VGL_1D_BASIS_INSTANTIATE(T) \
53 template class vgl_1d_basis<T >;\
54 template std::ostream& operator<<(std::ostream&, vgl_1d_basis<T > const&)
55 
56 #endif // vgl_1d_basis_hxx_
T unity() const
Definition: vgl_1d_basis.h:104
vgl_homg_point_1d< double > project(T const &p)
Projection from a point in the source space to a 1-D homogeneous point.
vgl_1d_basis()=default
storage for 3 collinear points to serve as 1-D projective basis
double cross_ratio(vgl_homg_point_1d< T >const &p1, vgl_homg_point_1d< T >const &p2, vgl_homg_point_1d< T >const &p3, vgl_homg_point_1d< T >const &p4)
cross ratio of four points.
bool collinear(l const &l1, vgl_homg_point_3d< Type > const &p)
Does a line pass through a point, i.e., are the point and the line collinear?.
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
Storage for 3 collinear points to serve as 1-D projective basis.
Definition: vgl_1d_basis.h:92
double ratio(vgl_homg_point_1d< T > const &p1, vgl_homg_point_1d< T > const &p2, vgl_homg_point_1d< T > const &p3)
Return the relative distance to p1 wrt p1-p2 of p3.
bool is_ideal(l const &line, T tol=(T) 0)
Return true iff line is the line at infinity.
Represents a homogeneous 1-D point, i.e., a homogeneous pair (x,w).
Definition: vgl_fwd.h:7
T origin() const
Definition: vgl_1d_basis.h:103
bool affine() const
Definition: vgl_1d_basis.h:106
T inf_pt() const
Definition: vgl_1d_basis.h:105