vgl_homg_line_3d_2_points.h
Go to the documentation of this file.
1 // This is core/vgl/vgl_homg_line_3d_2_points.h
2 #ifndef vgl_homg_line_3d_2_points_h_
3 #define vgl_homg_line_3d_2_points_h_
4 //:
5 // \file
6 // \author Don HAMILTON Peter TU Francois BERTEL
7 //
8 // \verbatim
9 // Modifications
10 // Peter Vanroose - 4 July 2001 - constructors now use force_point2_infinite()
11 // Peter Vanroose - 27 June 2001 - Added operator==
12 // Peter Vanroose - 15 July 2002 - Added concurrent(), coplanar() and intersection()
13 // \endverbatim
14 
15 #include <iosfwd>
16 #ifdef _MSC_VER
17 # include <vcl_msvc_warnings.h>
18 #endif
19 #include <vgl/vgl_homg_point_3d.h> // data member of this class
20 
21 //:Represents a homogeneous 3D line using two points
22 // A class to hold a homogeneous representation of a 3D Line. The line is
23 // stored as a pair of homogeneous 3d points.
24 template <class Type>
26 {
27  // Data Members------------------------------------------------------------
28 
29  //: Any finite point on the line
31  //: the (unique) point at infinity
33 
34  public:
35  //+**************************************************************************
36  // Initialization
37  //+**************************************************************************
38 
39  //: Default constructor with (0,0,0,1) and (1,0,0,0), which is the line \a y=z=0
41  : point_finite_(0,0,0,1), point_infinite_(1,0,0,0) {}
42 
43  //: Copy constructor
46 
47  //: Construct from two points
49  vgl_homg_point_3d<Type> const& point_2)
50  : point_finite_(point_1), point_infinite_(point_2) {force_point2_infinite();}
51 
52 #if 0
53  //: Destructor (does nothing)
54  inline ~vgl_homg_line_3d_2_points() {}
55 #endif
56 
57  //: comparison
58  bool operator==(vgl_homg_line_3d_2_points<Type> const& l) const;
59  inline bool operator!=(vgl_homg_line_3d_2_points<Type> const& l) const{return !operator==(l);}
60 
61  // Data access
62 
63  //: Finite point (Could be an ideal point, if the whole line is at infinity.)
65  //: Infinite point: the intersection of the line with the plane at infinity
67 
68  //: The point at infinity defines the direction of the line
71  point_infinite_.z());
72  return dir/static_cast<Type>(dir.length());}
73  //: Assignment
74  inline void set(vgl_homg_point_3d<Type> const& p1, vgl_homg_point_3d<Type> const& p2)
76 
77  // Utility methods
78 
79  //: Return true iff line is at infinity
80  inline bool ideal(Type tol = (Type)0) const { return point_finite_.ideal(tol); }
81 
82  protected:
83  //: force the point point_infinite_ to infinity, without changing the line
84  // This is called by the constructors
85  void force_point2_infinite(void) const; // mutable const
86 };
87 
88 #define l vgl_homg_line_3d_2_points<Type>
89 
90 //: Return true iff line is at infinity
91 // \relatesalso vgl_homg_line_3d_2_points
92 template <class Type>
93 inline bool is_ideal(l const& line, Type tol=(Type)0)
94 { return line.ideal(tol); }
95 
96 //: Does a line pass through a point, i.e., are the point and the line collinear?
97 // \relatesalso vgl_homg_line_3d_2_points
98 // \relatesalso vgl_homg_point_3d
99 template <class Type>
100 inline bool collinear(l const& l1, vgl_homg_point_3d<Type> const& p)
101 { return collinear(l1.point_finite(),l1.point_infinite(),p); }
102 
103 //: Are two lines coplanar, i.e., do they intersect?
104 // \relatesalso vgl_homg_line_3d_2_points
105 template <class Type>
106 inline bool coplanar(l const& l1, l const& l2)
107 { return coplanar(l1.point_finite(),l1.point_infinite(),l2.point_finite(),l2.point_infinite()); }
108 
109 //: Are two lines concurrent, i.e., do they intersect?
110 // \relatesalso vgl_homg_line_3d_2_points
111 template <class Type>
112 inline bool concurrent(l const& l1, l const& l2) { return coplanar(l1,l2); }
113 
114 //: Are two points coplanar with a line?
115 // \relatesalso vgl_homg_line_3d_2_points
116 // \relatesalso vgl_homg_point_3d
117 template <class Type>
118 inline bool coplanar(l const& l1, vgl_homg_point_3d<Type> const& p1, vgl_homg_point_3d<Type> const& p2)
119 { return coplanar(l1.point_finite(),l1.point_infinite(),p1,p2); }
120 
121 //: Are three lines coplanar, i.e., are they in a common plane?
122 // \relatesalso vgl_homg_line_3d_2_points
123 template <class Type>
124 inline bool coplanar(l const& l1, l const& l2, l const& l3)
125 {
126  vgl_homg_point_3d<Type> p = l2.point_finite();
127  if (collinear(l1,p)) p = l2.point_infinite();
128  return coplanar(l1,l2) && coplanar(l1,l3) &&
129  coplanar(l1,p,l3.point_finite()) &&
130  coplanar(l1,p,l3.point_infinite());
131 }
132 
133 //: Return the intersection point of two concurrent lines
134 // \relatesalso vgl_homg_line_3d_2_points
135 template <class Type>
136 vgl_homg_point_3d<Type> intersection(l const& l1, l const& l2);
137 
138 //: Are three lines concurrent, i.e., do they pass through a common point?
139 // \relatesalso vgl_homg_line_3d_2_points
140 template <class Type>
141 inline bool concurrent(l const& l1, l const& l2, l const& l3)
142 {
143  if (!concurrent(l1,l2) || !concurrent(l1,l3) || !concurrent(l2,l3)) return false;
144  return intersection(l1,l2) == intersection(l1,l3);
145 }
146 
147 //+****************************************************************************
148 // stream operators
149 //+****************************************************************************
150 
151 //: Write to stream (verbose)
152 // \relatesalso vgl_homg_line_3d_2_points
153 template <class Type>
154 std::ostream &operator<<(std::ostream&s, l const& p);
155 
156 //: Read parameters from stream
157 // \relatesalso vgl_homg_line_3d_2_points
158 template <class Type>
159 std::istream &operator>>(std::istream &is, l &p);
160 
161 #undef l
162 
163 #define VGL_HOMG_LINE_3D_2_POINTS_INSTANTIATE(T) extern "please include vgl/vgl_homg_line_3d_2_points.hxx first"
164 
165 #endif // vgl_homg_line_3d_2_points_h_
point in projective 3D space
vgl_homg_line_3d_2_points(const vgl_homg_line_3d_2_points< Type > &that)
Copy constructor.
vgl_homg_point_3d< Type > point_infinite_
the (unique) point at infinity.
bool ideal(Type tol=(Type) 0) const
Return true iff line is at infinity.
bool concurrent(l const &l1, l const &l2, l const &l3)
Are three lines concurrent, i.e., do they pass through a common point?.
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
Represents a homogeneous 3D point.
Definition: vgl_fwd.h:9
void force_point2_infinite(void) const
force the point point_infinite_ to infinity, without changing the line.
vgl_vector_3d< Type > direction() const
The point at infinity defines the direction of the line.
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?.
vgl_homg_point_3d< Type > point_finite_
Any finite point on the line.
bool is_ideal(l const &line, T tol=(T) 0)
Return true iff line is the line at infinity.
bool coplanar(l const &l1, l const &l2)
Are two lines coplanar, i.e., do they intersect?.
vgl_homg_line_3d_2_points(void)
Default constructor with (0,0,0,1) and (1,0,0,0), which is the line y=z=0.
std::istream & operator>>(std::istream &is, vgl_orient_box_3d< Type > &p)
Read box from stream.
bool operator==(vgl_homg_line_3d_2_points< Type > const &l) const
comparison.
#define l
vgl_homg_point_3d< Type > intersection(l const &l1, l const &l2)
Return the intersection point of two concurrent lines.
bool operator!=(vgl_homg_line_3d_2_points< Type > const &l) const
vgl_homg_point_3d< Type > point_finite() const
Finite point (Could be an ideal point, if the whole line is at infinity.).
void set(vgl_homg_point_3d< Type > const &p1, vgl_homg_point_3d< Type > const &p2)
Assignment.
vgl_homg_point_3d< Type > point_infinite() const
Infinite point: the intersection of the line with the plane at infinity.
Represents a homogeneous 3D line using two points.
Definition: vgl_fwd.h:15
vgl_homg_line_3d_2_points(vgl_homg_point_3d< Type > const &point_1, vgl_homg_point_3d< Type > const &point_2)
Construct from two points.