vgl_1d_basis.h
Go to the documentation of this file.
1 // This is core/vgl/vgl_1d_basis.h
2 #ifndef vgl_1d_basis_h_
3 #define vgl_1d_basis_h_
4 //:
5 // \file
6 // \brief storage for 3 collinear points to serve as 1-D projective basis
7 //
8 // vgl_1d_basis<T> is a class templated on the point type that
9 // will be stored. Typically, T will be vgl_point_2d<double> or
10 // vgl_homg_point_2d<int> or even vgl_line_2d<float> or vgl_point_3d<T>.
11 //
12 // This class stores three unequal collinear points and will use these to
13 // define a projection from e.g. 2d points on a line to a 1-dimensional
14 // projective space: the first point receives coordinates (0,1), the second
15 // one (1,0), and the third one (the unit point) coordinates (1,1).
16 //
17 // Note that this class can also be used for ``projecting'' from e.g.
18 // vgl_homg_point_1d<float> or vgl_point_1d<int> to vgl_homg_point_1d<double>,
19 // i.e., a kind of type casting operation, by passing it the homogeneous
20 // points (0,1), (1,0) and (1,1). Note that the destination space is
21 // always vgl_homg_point_1d<double>.
22 //
23 // The only conditions on template type T are the following:
24 // - It must know the concept of collinearity, viz. there must be a function
25 // ``bool collinear(T,T,T)''.
26 // (This is not necessary when using the constructor with two arguments.)
27 // - There must be a function ``double cross_ratio(T,T,T,T)'', or alternatively
28 // (when using the constructor with two arguments) there must be a function
29 // ``double ratio(T,T,T)''. These functions should return 0 if the last
30 // argument equals the 2-but-last and 1 if it equals the 1-but-last.
31 //
32 // These conditions are satisfied for the vgl_point_[23]d<Type> and
33 // vgl_homg_point_[123]d<Type> classes. For concurrent vgl_line_2d's
34 // the method project() has to be specialised (which is easily done by
35 // taking its intersection with the line at infinity!)
36 //
37 // \warning the C++ standard requires that these functions are
38 // declared before they are used, which, for this, means in the
39 // definition of the functions in the .hxx file. So, for maximum
40 // portability, make sure they are at least declared before the .hxx
41 // file is included.
42 //
43 // \author Peter Vanroose
44 // \date 7 July, 2001
45 //
46 // \verbatim
47 // Modifications
48 // Feb.2002 - Peter Vanroose - brief doxygen comment placed on single line
49 // \endverbatim
50 
51 #include <iosfwd>
52 #include <vgl/vgl_fwd.h>
53 #include <vgl/vgl_homg_point_1d.h>
54 #ifdef _MSC_VER
55 # include <vcl_msvc_warnings.h>
56 #endif
57 #include <cassert>
58 
59 //----------------------------------------------------------------------
60 
61 //: Storage for 3 collinear points to serve as 1-D projective basis.
62 // This class is templated on the point type that will be stored.
63 // Typically, T will be vgl_point_2d<double> or
64 // vgl_homg_point_2d<int> or even vgl_line_2d<float> or vgl_point_3d<T>.
65 //
66 // This class stores three unequal collinear points and will use these to
67 // define a projection from e.g. 2d points on a line to a 1-dimensional
68 // projective space: the first point receives coordinates (0,1), the second
69 // one (the unit point) (1,1), and the third one (point at infinity) (1,0).
70 //
71 // Note that this class can also be used for ``projecting'' from e.g.
72 // vgl_homg_point_1d<float> or vgl_point_1d<int> to vgl_homg_point_1d<double>,
73 // i.e., a kind of type casting operation, by passing it the homogeneous
74 // points (0,1), (1,1) and (1,0). Note that the destination space is
75 // always vgl_homg_point_1d<double>.
76 //
77 // The only conditions on template type T are the following:
78 // - It must know the concept of collinearity, viz. there must be a function
79 // ``bool collinear(T,T,T)''.
80 // (This is not necessary when using the constructor with two arguments.)
81 // - There must be a function ``double cross_ratio(T,T,T,T)'', or alternatively
82 // (when using the constructor with two arguments) there must be a function
83 // ``double ratio(T,T,T)''. These functions should return 0 if the last
84 // argument equals the 2-but-last and 1 if it equals the 1-but-last.
85 //
86 // These conditions are satisfied for the vgl_point_[23]d<Type> and
87 // vgl_homg_point_[123]d<Type> classes. For concurrent vgl_line_2d's
88 // the method project() has to be specialised (which is easily done by
89 // taking its intersection with the line at infinity!)
90 //
91 template <class T>
93 {
94  // Data members are private:
95  T origin_; //!< The point to be mapped to homogeneous (0,1)
96  T unity_; //!< The point to be mapped to homogeneous (1,1)
97  T inf_pt_; //!< The point to be mapped to homogeneous (1,0)
98  bool affine_; //!< normally false; if true, inf_pt_ is not used: affine basis
99  // No usable default constructor:
100  inline vgl_1d_basis() = default;
101 
102  public:
103  inline T origin() const { return origin_; }
104  inline T unity() const { return unity_; }
105  inline T inf_pt() const { assert(!affine_); return inf_pt_; }
106  inline bool affine() const { return affine_; }
107  inline bool projective() const { return !affine_; }
108 
109  //: Construct from three collinear points (projective basis).
110  // It will serve as origin (0,1), unity (1,1) and point at infinity (1,0).
111  // The points must be collinear, and different from each other.
112  //
113  // Note that there is no valid default constructor, since any sensible default
114  // heavily depends on the structure of the point class T, the template type.
115  //
116  // Note that there is no way to overwrite an existing vgl_basis_1d;
117  // just create a new one if you need a different one.
118  // Hence it is not possible to read a vgl_basis_1d from stream with >>.
119  //
120  vgl_1d_basis(T const& o, T const& u, T const& i);
121 
122  //: Construct from two points (affine basis).
123  // It will serve as origin (0,1) and unity point (1,1).
124  // The points must be different from each other, and not at infinity.
125  // This creates an affine basis, i.e., the point at infinity of the basis
126  // will be the point at infinity of the line o-u in the source space.
127  vgl_1d_basis(T const& o, T const& u);
128 
129  //: Projection from a point in the source space to a 1-D homogeneous point
131 };
132 
133 // +-+-+ 1d_basis simple I/O +-+-+
134 
135 //: Write "<vgl_1d_basis o u i> " to stream
136 // \relatesalso vgl_1d_basis
137 template <class T> std::ostream& operator<<(std::ostream& s, vgl_1d_basis<T> const&);
138 
139 #define VGL_1D_BASIS_INSTANTIATE(T) extern "please include vgl/vgl_1d_basis.hxx first"
140 
141 #endif // vgl_1d_basis_h_
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.
a point in homogeneous 1-D space, i.e., a homogeneous pair (x,w)
vgl_1d_basis()=default
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
T inf_pt_
The point to be mapped to homogeneous (1,0)
Definition: vgl_1d_basis.h:97
Storage for 3 collinear points to serve as 1-D projective basis.
Definition: vgl_1d_basis.h:92
bool projective() const
Definition: vgl_1d_basis.h:107
T origin_
The point to be mapped to homogeneous (0,1)
Definition: vgl_1d_basis.h:95
T unity_
The point to be mapped to homogeneous (1,1)
Definition: vgl_1d_basis.h:96
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
bool affine_
normally false; if true, inf_pt_ is not used: affine basis
Definition: vgl_1d_basis.h:98