core/vgl/vgl_intersection.h

Go to the documentation of this file.
00001 // This is core/vgl/vgl_intersection.h
00002 #ifndef vgl_intersection_h_
00003 #define vgl_intersection_h_
00004 //:
00005 // \file
00006 // \brief Set of intersection functions
00007 // \author Jan 25, 2007 Gamze Tunali
00008 //
00009 // For intersections of "homogeneous coordinates" objects like vgl_homg_line_2d<T>,
00010 // see the static methods of vgl/algo/vgl_homg_operators_2d<T> and _3d.
00011 //
00012 // \verbatim
00013 //  Modifications
00014 //   01 Mar 2007 - Gamze Tunali - split up into vgl/algo and vgl parts
00015 //   21 Jul 2009 - Peter Vanroose - added box intersection (2d and 3d)
00016 //   21 Jul 2009 - Peter Vanroose - added inlined point intersection functions
00017 // \endverbatim
00018 
00019 #include <vgl/vgl_fwd.h> // forward declare various vgl classes
00020 #include <vgl/vgl_box_2d.h> // method "contains()"
00021 #include <vgl/vgl_box_3d.h> // method "contains()"
00022 #include <vgl/vgl_point_2d.h> // method "operator==()"
00023 #include <vgl/vgl_point_3d.h> // method "operator==()"
00024 #include <vgl/vgl_line_3d_2_points.h>
00025 #include <vgl/vgl_line_segment_3d.h>
00026 #include <vgl/vgl_infinite_line_3d.h>
00027 #include <vcl_vector.h>
00028 
00029 //: Return true if the two points intersect, i.e., coincide
00030 // \relatesalso vgl_point_2d
00031 template <class T>
00032 inline bool vgl_intersection(vgl_point_2d<T> const& p0,
00033                              vgl_point_2d<T> const& p1)
00034 { return p0 == p1; }
00035 
00036 //: Return true if the two points intersect, i.e., coincide
00037 // \relatesalso vgl_point_2d
00038 template <class T>
00039 inline bool vgl_intersection(vgl_point_3d<T> const& p0,
00040                              vgl_point_3d<T> const& p1)
00041 { return p0 == p1; }
00042 
00043 //: Return true if line intersects box. If so, compute intersection points.
00044 // \relatesalso vgl_line_2d
00045 template <class T>
00046 bool vgl_intersection(vgl_box_2d<T> const& box,
00047                       vgl_line_2d<T> const& line,
00048                       vgl_point_2d<T>& p0,
00049                       vgl_point_2d<T>& p1);
00050 
00051 //: Returns the number of intersections of a line segment with a box, up to two are returned in p0 and p1.
00052 // \relatesalso vgl_line_segment_2d
00053 template <class T>
00054 unsigned vgl_intersection(vgl_box_2d<T> const& box,
00055                           vgl_line_segment_2d<T> const& line,
00056                           vgl_point_2d<T>& p0,
00057                           vgl_point_2d<T>& p1);
00058 
00059 //: Return the intersection point of two concurrent lines
00060 // \relatesalso vgl_line_3d_2_points
00061 //Allows intersection points outside the line segments
00062 //Throws an assertion if lines not concurrent
00063 template <class T>
00064 vgl_point_3d<T> vgl_intersection(vgl_line_3d_2_points<T> const& l1,
00065                                  vgl_line_3d_2_points<T> const& l2);
00066 
00067 //: Return the intersection point of segments of two concurrent lines. Returns false if the intersection point is not inside both line segments
00068 // \relatesalso vgl_line_segment_3d. 
00069 // 
00070 template <class T>
00071 bool vgl_intersection(vgl_line_segment_3d<T> const& l1,
00072                       vgl_line_segment_3d<T> const& l2,
00073                       vgl_point_3d<T>& i_pnt);
00074 
00075 //: Return the intersection point of segments of a concurrent line and line segment pair. Returns false if the intersection point is not inside both line segments
00076 // \relatesalso vgl_line_segment_3d
00077 // \relatesalso vgl_line_3d_2_points
00078 template <class T>
00079 bool vgl_intersection(vgl_line_3d_2_points<T> const& l1,
00080                       vgl_line_segment_3d<T> const& l2,
00081                       vgl_point_3d<T>& i_pnt);
00082 
00083 template <class T> inline
00084 bool vgl_intersection(vgl_line_segment_3d<T> const& l1,
00085                       vgl_line_3d_2_points<T> const& l2,
00086                       vgl_point_3d<T>& i_pnt)
00087 {
00088   return vgl_intersection(l2, l1, i_pnt);
00089 }
00090 
00091 //: Return the intersection point of infinite lines, if concurrent.
00092 // \relatesalso vgl_infinite_line_3d
00093 template <class T>
00094 bool vgl_intersection(vgl_infinite_line_3d<T> const& l1,
00095                       vgl_infinite_line_3d<T> const& l2,
00096                       vgl_point_3d<T>& i_pnt);
00097 
00098 
00099 //: Return the intersection point of two lines. Return false if lines are parallel
00100 // \relatesalso vgl_line_2d
00101 template <class T>
00102 bool vgl_intersection(vgl_line_2d<T>  const& line0,
00103                       vgl_line_2d<T>  const& line1,
00104                       vgl_point_2d<T>       &intersection_point );
00105 
00106 
00107 //: Return the intersection point of a line and a plane.
00108 // \relatesalso vgl_line_3d_2_points
00109 // \relatesalso vgl_plane_3d
00110 template <class T>
00111 vgl_point_3d<T> vgl_intersection(vgl_line_3d_2_points<T> const& line,
00112                                  vgl_plane_3d<T> const& plane);
00113 
00114 //: Return the intersection point of a line and a plane.
00115 // \relatesalso vgl_line_segment_3d
00116 // \relatesalso vgl_plane_3d
00117 template <class T>
00118 bool vgl_intersection(vgl_line_segment_3d<T> const& line,
00119                       vgl_plane_3d<T> const& plane,
00120                       vgl_point_3d<T> & i_pt);
00121 
00122 
00123 //: Return the intersection point of a line and a plane.
00124 // \relatesalso vgl_line_segment_3d
00125 // \relatesalso vgl_plane_3d
00126 template <class T>
00127 bool vgl_intersection(vgl_infinite_line_3d<T> const& line,
00128                       vgl_plane_3d<T> const& plane,
00129                       vgl_point_3d<T> & i_pt);
00130 
00131 //: Return the intersection line of two planes.
00132 // Returns false if planes are effectively parallel
00133 // \relatesalso vgl_line_segment_3d
00134 // \relatesalso vgl_plane_3d
00135 template <class T>
00136 bool vgl_intersection(vgl_plane_3d<T> const& plane0,
00137                       vgl_plane_3d<T> const& plane1,
00138                       vgl_line_segment_3d<T> & line){
00139   vgl_infinite_line_3d<T> inf_l;
00140   bool status = vgl_intersection(plane0, plane1, inf_l);
00141   if (status)
00142     line.set(inf_l.point_t(T(0)), inf_l.point_t(T(1)));
00143   return status;
00144 }
00145 
00146 template <class T>
00147 bool vgl_intersection(vgl_plane_3d<T> const& plane0,
00148                       vgl_plane_3d<T> const& plane1,
00149                       vgl_line_3d_2_points<T> & line){
00150   vgl_infinite_line_3d<T> inf_l;
00151   bool status = vgl_intersection(plane0, plane1, inf_l);
00152   if (status)
00153     line.set(inf_l.point_t(T(0)), inf_l.point_t(T(1)));
00154   return status;
00155 }
00156 
00157 template <class T>
00158 bool vgl_intersection(vgl_plane_3d<T> const& plane0,
00159                       vgl_plane_3d<T> const& plane1,
00160                       vgl_infinite_line_3d<T> & line);
00161 
00162 //: Return the intersection point of three planes.
00163 // \relatesalso vgl_plane_3d
00164 template <class T>
00165 vgl_point_3d<T> vgl_intersection(vgl_plane_3d<T> const& p1,
00166                                  vgl_plane_3d<T> const& p2,
00167                                  vgl_plane_3d<T> const& p3);
00168 
00169 //: Return true if any point on [p1,p2] is within tol of [q1,q2]
00170 //  Tests two line segments for intersection or near intersection
00171 //  (within given tolerance).
00172 // \author Dan jackson
00173 // \relatesalso vgl_point_2d
00174 template <class T>
00175 bool vgl_intersection(vgl_point_2d<T> const& p1,
00176                       vgl_point_2d<T> const& p2,
00177                       vgl_point_2d<T> const& q1,
00178                       vgl_point_2d<T> const& q2,
00179                       double tol = 1e-6);
00180 
00181 //: Return true if the point lies inside the box
00182 // \relatesalso vgl_point_2d
00183 // \relatesalso vgl_box_2d
00184 template <class T>
00185 inline bool vgl_intersection(vgl_box_2d<T> const& b, vgl_point_2d<T> const& p)
00186 { return b.contains(p); }
00187 
00188 //: Return true if the point lies inside the box
00189 // \relatesalso vgl_point_2d
00190 // \relatesalso vgl_box_2d
00191 template <class T>
00192 inline bool vgl_intersection(vgl_point_2d<T> const& p, vgl_box_2d<T> const& b)
00193 { return b.contains(p); }
00194 
00195 //: Return true if the point lies inside the box
00196 // \relatesalso vgl_point_3d
00197 // \relatesalso vgl_box_3d
00198 template <class T>
00199 inline bool vgl_intersection(vgl_box_3d<T> const& b, vgl_point_3d<T> const& p)
00200 { return b.contains(p); }
00201 
00202 //: Return true if the point lies inside the box
00203 // \relatesalso vgl_point_3d
00204 // \relatesalso vgl_box_3d
00205 template <class T>
00206 inline bool vgl_intersection(vgl_point_3d<T> const& p, vgl_box_3d<T> const& b)
00207 { return b.contains(p); }
00208 
00209 //: Return true if line intersects box. If so, compute intersection points.
00210 // \relatesalso vgl_infinite_line_3d
00211 template <class T>
00212 bool vgl_intersection(vgl_box_3d<T> const& box,
00213                       vgl_infinite_line_3d<T> const& line,
00214                       vgl_point_3d<T>& p0,
00215                       vgl_point_3d<T>& p1);
00216 
00217 //: Return true if a box and plane intersect in 3D
00218 // \relatesalso vgl_plane_3d
00219 // \relatesalso vgl_box_3d
00220 template <class T>
00221 bool vgl_intersection(vgl_box_3d<T> const& b, vgl_plane_3d<T> const& plane);
00222 
00223 
00224 //: Return the intersection of two boxes (which is itself either a box, or empty)
00225 // \relatesalso vgl_box_2d
00226 template <class T>
00227 vgl_box_2d<T> vgl_intersection(vgl_box_2d<T> const&,vgl_box_2d<T> const&);
00228 
00229 //: Return the intersection of two boxes (which is itself either a box, or empty)
00230 // \relatesalso vgl_box_3d
00231 template <class T>
00232 vgl_box_3d<T> vgl_intersection(vgl_box_3d<T> const&,vgl_box_3d<T> const&);
00233 
00234 //: Return true if the box and polygon regions intersect, regions include boundaries
00235 // \relatesalso vgl_polygon
00236 // \relatesalso vgl_box_2d
00237 template <class T>
00238 bool vgl_intersection(vgl_box_2d<T> const& b, vgl_polygon<T> const& poly);
00239 
00240 //: Return the points from the list that lie inside the box
00241 // \relatesalso vgl_point_2d
00242 // \relatesalso vgl_box_2d
00243 template <class T>
00244 vcl_vector<vgl_point_2d<T> > vgl_intersection(vgl_box_2d<T> const& b, vcl_vector<vgl_point_2d<T> > const& p);
00245 
00246 //: Return the points from the list that lie inside the box
00247 // \relatesalso vgl_point_2d
00248 // \relatesalso vgl_box_2d
00249 template <class T>
00250 vcl_vector<vgl_point_2d<T> > vgl_intersection(vcl_vector<vgl_point_2d<T> > const& p, vgl_box_2d<T> const& b);
00251 
00252 //: Return the points from the list that lie inside the box
00253 // \relatesalso vgl_point_3d
00254 // \relatesalso vgl_box_3d
00255 template <class T>
00256 vcl_vector<vgl_point_3d<T> > vgl_intersection(vgl_box_3d<T> const& b, vcl_vector<vgl_point_3d<T> > const& p);
00257 
00258 //: Return the points from the list that lie inside the box
00259 // \relatesalso vgl_point_3d
00260 // \relatesalso vgl_box_3d
00261 template <class T>
00262 vcl_vector<vgl_point_3d<T> > vgl_intersection(vcl_vector<vgl_point_3d<T> > const& p, vgl_box_3d<T> const& b);
00263 
00264 
00265 #define VGL_INTERSECTION_INSTANTIATE(T) extern "please include vgl/vgl_intersection.txx first"
00266 #define VGL_INTERSECTION_BOX_INSTANTIATE(T) extern "please include vgl/vgl_intersection.txx first"
00267 
00268 #endif // vgl_intersection_h_

Generated on Mon Mar 8 05:07:50 2010 for core/vgl by  doxygen 1.5.1