vgl_homg_plane_3d.h
Go to the documentation of this file.
1 // This is core/vgl/vgl_homg_plane_3d.h
2 #ifndef vgl_homg_plane_3d_h
3 #define vgl_homg_plane_3d_h
4 //:
5 // \file
6 // \brief homogeneous plane in 3D projective space
7 // \author Don HAMILTON Peter TU
8 //
9 // \verbatim
10 // Modifications
11 // Peter Vanroose 6 July 2001: Now using vgl_vector_3d for normal direction
12 // Peter Vanroose 6 July 2001: Added normal(); replaced data_[4] by a_ b_ c_ d_
13 // Peter Vanroose 6 July 2001: Added constructor from 3 points
14 // CJB (Manchester) 16/03/2001: Tidied up the documentation
15 // Peter Vanroose 15 July 2002: Added constructor from two concurrent lines
16 // cbw (imorphics) 31 Mar 2008: Corrected constructor with normal and point (negated d) and added test
17 // Peter Vanroose 7 March 2009: Added normalize(), similar to the one in vgl_homg_line_2d<T>
18 // \endverbatim
19 
20 #include <iosfwd>
21 #ifdef _MSC_VER
22 # include <vcl_msvc_warnings.h>
23 #endif
24 #include <vgl/vgl_fwd.h> // forward declare vgl_plane_3d and vgl_homg_point_3d
25 #include <vgl/vgl_vector_3d.h>
26 #include <cassert>
27 
28 //: Represents a homogeneous 3D plane
29 template <class Type>
31 {
32  // the four homogeneous coordinates of the plane (dual of a point).
33  Type a_;
34  Type b_;
35  Type c_;
36  Type d_;
37 
38  public:
39  inline vgl_homg_plane_3d () = default;
40 
41  //: Construct from four Types.
42  inline vgl_homg_plane_3d(Type ta, Type tb, Type tc, Type td) : a_(ta), b_(tb), c_(tc), d_(td) {}
43 
44  //: Construct from 4-vector.
45  inline vgl_homg_plane_3d(const Type v[4]) : a_(v[0]), b_(v[1]), c_(v[2]), d_(v[3]) {}
46 
47  //: Construct from non-homogeneous plane.
49 
50  //: Construct from normal and a point
51  // The given point must not be at infinity.
53 
54  //: Construct from three non-collinear points
56  vgl_homg_point_3d<Type> const& p2,
57  vgl_homg_point_3d<Type> const& p3);
58 
59  //: Construct from two concurrent lines
62 
63  // Data Access-------------------------------------------------------------
64 
65  //: Return \a x coefficient
66  inline Type a() const {return a_;}
67  inline Type nx() const {return a_;}
68  //: Return \a y coefficient
69  inline Type b() const {return b_;}
70  inline Type ny() const {return b_;}
71  //: Return \a z coefficient
72  inline Type c() const {return c_;}
73  inline Type nz() const {return c_;}
74  //: Return homogeneous scaling coefficient
75  inline Type d() const {return d_;}
76 
77  //: Set equation \a a*x+b*y+c*z+d*w=0
78  inline void set(Type ta,Type tb,Type tc,Type td) { assert(ta||tb||tc||td);a_=ta;b_=tb;c_=tc;d_=td; }
79 
80  //: the comparison operator
81  bool operator==( vgl_homg_plane_3d<Type> const& pl) const;
82  inline bool operator!=( vgl_homg_plane_3d<Type>const& pl) const { return !operator==(pl); }
83 
84  //: Return true iff the plane is the plane at infinity.
85  // The method checks that max(|a|,|b|,|c|) <= tol * |d|
86  // If called without an argument, tol=0, i.e., a, b and c must be 0.
87  inline bool ideal(Type tol = (Type)0) const
88  {
89 #define vgl_Abs(x) ((x)<0?-(x):(x)) // avoid #include of vcl_cmath.h AND vcl_cstdlib.h
90  return vgl_Abs(a()) <= tol * vgl_Abs(d()) &&
91  vgl_Abs(b()) <= tol * vgl_Abs(d()) &&
92  vgl_Abs(c()) <= tol * vgl_Abs(d());
93 #undef vgl_Abs
94  }
95 
96  inline vgl_vector_3d<double> normal() const { return normalized(vgl_vector_3d<double>(a(),b(),c())); }
97 
98  //: divide all coefficients by sqrt(a^2 + b^2 + c^2)
99  void normalize();
100 };
101 
102 //: Return true iff p is the plane at infinity
103 // The method checks that max(|a|,|b|,|c|) <= tol * |d|
104 // \relatesalso vgl_homg_plane_3d
105 template <class Type>
106 inline bool is_ideal(vgl_homg_plane_3d<Type> const& p, Type tol=(Type)0) { return p.ideal(tol); }
107 
108 // stream operators
109 
110 template <class Type>
111 std::ostream& operator<<(std::ostream& s, const vgl_homg_plane_3d<Type>& p);
112 
113 template <class Type>
114 std::istream& operator>>(std::istream& is, vgl_homg_plane_3d<Type>& p);
115 
116 #define VGL_HOMG_PLANE_3D_INSTANTIATE(T) extern "please include vgl/vgl_homg_plane_3d.hxx first"
117 
118 #endif // vgl_homg_plane_3d_h
void normalize()
divide all coefficients by sqrt(a^2 + b^2 + c^2).
Represents a homogeneous 3D plane.
Definition: vgl_fwd.h:22
direction vector in Euclidean 3D space
Type b() const
Return y coefficient.
Type c() const
Return z coefficient.
vgl_homg_plane_3d(const Type v[4])
Construct from 4-vector.
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
Type d() const
Return homogeneous scaling coefficient.
Represents a homogeneous 3D point.
Definition: vgl_fwd.h:9
#define v
Definition: vgl_vector_2d.h:74
bool operator!=(vgl_homg_plane_3d< Type >const &pl) const
vgl_homg_plane_3d()=default
Represents a Euclidean 3D plane.
Definition: vgl_fwd.h:23
bool is_ideal(l const &line, T tol=(T) 0)
Return true iff line is the line at infinity.
vgl_vector_3d< double > normal() const
#define vgl_Abs(x)
Type a() const
Return x coefficient.
bool operator==(vgl_homg_plane_3d< Type > const &pl) const
the comparison operator.
std::istream & operator>>(std::istream &is, vgl_orient_box_3d< Type > &p)
Read box from stream.
vgl_homg_plane_3d(Type ta, Type tb, Type tc, Type td)
Construct from four Types.
void set(Type ta, Type tb, Type tc, Type td)
Set equation a*x+b*y+c*z+d*w=0.
bool ideal(Type tol=(Type) 0) const
Return true iff the plane is the plane at infinity.
v normalized(v const &a)
Return a normalised version of a.
Represents a homogeneous 3D line using two points.
Definition: vgl_fwd.h:15