vgl_line_3d_2_points.h
Go to the documentation of this file.
1 // This is core/vgl/vgl_line_3d_2_points.h
2 #ifndef vgl_line_3d_2_points_h_
3 #define vgl_line_3d_2_points_h_
4 //:
5 // \file
6 // \brief non-homogeneous 3D line, represented by 2 points.
7 // \author Peter Vanroose
8 //
9 // \verbatim
10 // Modifications
11 // Gamze Tunali 26 Jan 2007: Deprecated intersection(). Moved into vgl_intersection.
12 // Peter Vanroose 30 Mar 2007: Commented out deprecated intersection() functions.
13 // \endverbatim
14 
15 #include <iosfwd>
16 #ifdef _MSC_VER
17 # include <vcl_msvc_warnings.h>
18 #endif
19 #include <cassert>
20 #include <vgl/vgl_point_3d.h> // data member of this class
21 #include <vgl/vgl_vector_3d.h>
22 
23 //: A class to hold a non-homogeneous representation of a 3D line.
24 // The line is stored as a pair of non-homogeneous 3D points.
25 template <class Type>
27 {
28  // Data Members------------------------------------------------------------
29 
30  //: Any point on the line
32  //: Any other point on the line
34 
35  public:
36  //+**************************************************************************
37  // Initialization
38  //+**************************************************************************
39 
40  //: Default constructor with (0,0,0) and (1,0,0), which is the line \a y=z=0
41  inline vgl_line_3d_2_points(void)
42  : point1_(0,0,0), point2_(1,0,0) {}
43 
44  //: Copy constructor
46  : point1_(that.point1_), point2_(that.point2_) {}
47 
48  //: Construct from two points
50  vgl_point_3d<Type> const& p2)
51  : point1_(p1), point2_(p2) {assert(p1!=p2);}
52 
53  //: comparison
54  bool operator==(vgl_line_3d_2_points<Type> const& l) const;
55  bool operator!=(vgl_line_3d_2_points<Type> const& l) const{return !operator==(l);}
56 
57  // Data access
58 
59  //: Return the first point representing this line
60  inline vgl_point_3d<Type> point1() const {return point1_;}
61  //: Return the second point representing this line
62  inline vgl_point_3d<Type> point2() const{ return point2_;}
63 
64  //: Assignment
65  inline void set(vgl_point_3d<Type> const& p1, vgl_point_3d<Type> const& p2)
66  { assert(p1!=p2); point1_ = p1; point2_ = p2; }
67 
68  // Utility methods
69 
70  //: Return true iff line is at infinity (which is always false)
71  inline bool ideal(Type /*tol*/ = (Type)0) const { return false; }
72 
73  //: Return the direction vector of this line (not normalised - but perhaps it should be, like other line classes?)
74  inline vgl_vector_3d<Type> direction() const { return point2()-point1(); }
75 
76  //: Return a point on the line defined by a scalar parameter \a t such that \a t=0.0 at point1 and \a t=1.0 at point2.
77  //\note Assumes that direction() is not normalized.
78  inline vgl_point_3d<Type> point_t(const double t) const { return point1() + t*direction(); }
79 };
80 
81 #define l vgl_line_3d_2_points<Type>
82 
83 //: Return true iff line is at infinity (which is always false)
84 // \relatesalso vgl_line_3d_2_points
85 template <class Type>
86 inline bool is_ideal(l const&, Type=(Type)0) { return false; }
87 
88 //: Does a line pass through a point, i.e., are the point and the line collinear?
89 // \relatesalso vgl_line_3d_2_points
90 // \relatesalso vgl_point_3d
91 template <class Type>
92 inline bool collinear(l const& l1, vgl_point_3d<Type> const& p)
93 {
94  return collinear(l1.point1(),l1.point2(),p);
95 }
96 
97 //: Are two lines coplanar, i.e., do they either intersect or are parallel?
98 // \relatesalso vgl_line_3d_2_points
99 template <class Type>
100 inline bool coplanar(l const& l1, l const& l2)
101 { return coplanar(l1.point1(),l1.point2(),l2.point1(),l2.point2()); }
102 
103 //: Are two lines concurrent, i.e., do they intersect in a finite point?
104 // \relatesalso vgl_line_3d_2_points
105 template <class Type>
106 inline bool concurrent(l const& l1, l const& l2)
107 {
108  return coplanar(l1,l2) && !parallel(l1.direction(),l2.direction());
109 }
110 
111 //: Are two points coplanar with a line?
112 // \relatesalso vgl_line_3d_2_points
113 // \relatesalso vgl_point_3d
114 template <class Type>
115 inline bool coplanar(l const& l1, vgl_point_3d<Type> const& p1, vgl_point_3d<Type> const& p2)
116 { return coplanar(l1.point1(),l1.point2(),p1,p2); }
117 
118 //: Are three lines coplanar, i.e., are they in a common plane?
119 // \relatesalso vgl_line_3d_2_points
120 template <class Type>
121 inline bool coplanar(l const& l1, l const& l2, l const& l3)
122 {
123  vgl_point_3d<Type> p = l2.point1();
124  if (collinear(l1,p)) p = l2.point2();
125  return coplanar(l1,l2) && coplanar(l1,l3) &&
126  coplanar(l1,p,l3.point1()) && coplanar(l1,p,l3.point2());
127 }
128 
129 #if 0 // deprecated
130 //: Return the intersection point of two concurrent lines
131 // \relatesalso vgl_line_3d_2_points
132 // \deprecated in favour of vgl_intersection.
133 // Can be removed after the release of VXL 1.8
134 template <class Type>
135 vgl_point_3d<Type> intersection(l const& l1, l const& l2)
136 { return vgl_intersection(l1, l2); }
137 
138 //: Return the intersection point of a line and a plane.
139 // \relatesalso vgl_line_3d_2_points
140 // \deprecated in favour of vgl_intersection.
141 // Can be removed after the release of VXL 1.8
142 template <class Type>
143 vgl_point_3d<Type> intersection(l const& line, vgl_plane_3d<Type> const& plane)
144 { return vgl_intersection(line, plane); }
145 #endif // 0
146 
147 //: Are three lines concurrent, i.e., do they pass through a common point?
148 // \relatesalso vgl_line_3d_2_points
149 template <class Type>
150 inline bool concurrent(l const& l1, l const& l2, l const& l3)
151 {
152  if (!concurrent(l1,l2) || !concurrent(l1,l3) || !concurrent(l2,l3)) return false;
153  return vgl_intersection(l1,l2) == vgl_intersection(l1,l3);
154 }
155 
156 //+****************************************************************************
157 // stream operators
158 //+****************************************************************************
159 
160 //: Write to stream (verbose)
161 // \relatesalso vgl_line_3d_2_points
162 template <class Type>
163 std::ostream &operator<<(std::ostream&s, l const& );
164 
165 //: Read parameters from stream
166 // \relatesalso vgl_line_3d_2_points
167 template <class Type>
168 std::istream &operator>>(std::istream &is, l &);
169 
170 #undef l
171 
172 #define VGL_LINE_3D_2_POINTS_INSTANTIATE(T) extern "please include vgl/vgl_line_3d_2_points.hxx first"
173 
174 #endif // vgl_line_3d_2_points_h_
vgl_line_3d_2_points(const vgl_line_3d_2_points< Type > &that)
Copy constructor.
void set(vgl_point_3d< Type > const &p1, vgl_point_3d< Type > const &p2)
Assignment.
vgl_point_3d< Type > point_t(const double t) const
Return a point on the line defined by a scalar parameter t such that t=0.0 at point1 and t=1....
bool operator!=(vgl_line_3d_2_points< Type > const &l) const
vgl_line_3d_2_points(void)
Default constructor with (0,0,0) and (1,0,0), which is the line y=z=0.
direction vector in Euclidean 3D space
Represents a cartesian 3D point.
Definition: vgl_fwd.h:11
bool concurrent(l const &l1, l const &l2, l const &l3)
Are three lines concurrent, i.e., do they pass through a common point?.
bool ideal(Type=(Type) 0) const
Return true iff line is at infinity (which is always false).
bool operator==(vgl_line_3d_2_points< Type > const &l) const
comparison.
vgl_vector_3d< Type > direction() const
Return the direction vector of this line (not normalised - but perhaps it should be,...
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
vgl_point_3d< T > vgl_intersection(const std::vector< vgl_plane_3d< T > > &p)
Return the intersection point of vector of planes.
A class to hold a non-homogeneous representation of a 3D line.
Definition: vgl_fwd.h:17
vgl_point_3d< Type > point2_
Any other point on 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?.
a point in 3D nonhomogeneous space
vgl_point_3d< Type > point1() const
Return the first point representing this line.
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.
#define l
bool coplanar(l const &l1, l const &l2)
Are two lines coplanar, i.e., do they intersect?.
std::istream & operator>>(std::istream &is, vgl_orient_box_3d< Type > &p)
Read box from stream.
vgl_homg_point_3d< Type > intersection(l const &l1, l const &l2)
Return the intersection point of two concurrent lines.
vgl_point_3d< Type > point2() const
Return the second point representing this line.
vgl_line_3d_2_points(vgl_point_3d< Type > const &p1, vgl_point_3d< Type > const &p2)
Construct from two points.
bool parallel(v const &a, v const &b, double eps=0.0)
are two vectors parallel, i.e., is one a scalar multiple of the other?.
vgl_point_3d< Type > point1_
Any point on the line.