00001
00002 #ifndef vgl_homg_operators_2d_h_
00003 #define vgl_homg_operators_2d_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <vcl_list.h>
00025 #include <vcl_vector.h>
00026 #include <vnl/vnl_fwd.h>
00027 #include <vgl/vgl_fwd.h>
00028
00029
00030 template <class T>
00031 class vgl_homg_operators_2d
00032 {
00033 public:
00034
00035 static vnl_vector_fixed<T,3> get_vector(vgl_homg_point_2d<T> const& p);
00036
00037
00038 static vnl_vector_fixed<T,3> get_vector(vgl_homg_line_2d<T> const& l);
00039
00040
00041 static vnl_vector_fixed<T,6> get_vector(vgl_conic<T> const& c);
00042
00043
00044 static void unitize(vgl_homg_point_2d<T>& a);
00045
00046 static double angle_between_oriented_lines(const vgl_homg_line_2d<T>& line1,
00047 const vgl_homg_line_2d<T>& line2);
00048
00049 static double abs_angle(const vgl_homg_line_2d<T>& line1,
00050 const vgl_homg_line_2d<T>& line2);
00051
00052
00053 static T distance(const vgl_homg_point_2d<T>& point1,
00054 const vgl_homg_point_2d<T>& point2);
00055
00056
00057 static T distance_squared(const vgl_homg_point_2d<T>& point1,
00058 const vgl_homg_point_2d<T>& point2);
00059
00060
00061
00062
00063
00064
00065
00066 static T perp_dist_squared(const vgl_homg_point_2d<T>& point,
00067 const vgl_homg_line_2d<T>& line);
00068 static T perp_dist_squared(const vgl_homg_line_2d<T>& line,
00069 const vgl_homg_point_2d<T>& point)
00070 { return perp_dist_squared(point, line); }
00071
00072
00073 static bool is_within_distance(const vgl_homg_point_2d<T>& p1,
00074 const vgl_homg_point_2d<T>& p2, double d)
00075 {
00076 if (d <= 0) return false;
00077 return distance_squared(p1, p2) < d*d;
00078 }
00079
00080
00081 static double line_angle(const vgl_homg_line_2d<T>& line);
00082
00083
00084 static vgl_homg_line_2d<T> join(const vgl_homg_point_2d<T>& point1,
00085 const vgl_homg_point_2d<T>& point2);
00086
00087
00088
00089
00090 static vgl_homg_line_2d<T> join_oriented(const vgl_homg_point_2d<T>& point1,
00091 const vgl_homg_point_2d<T>& point2);
00092
00093
00094 static vgl_homg_point_2d<T> intersection(const vgl_homg_line_2d<T>& line1,
00095 const vgl_homg_line_2d<T>& line2);
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 static vgl_homg_line_2d<T> perp_line_through_point(const vgl_homg_line_2d<T>& line,
00106 const vgl_homg_point_2d<T>& point);
00107
00108
00109 static vgl_homg_point_2d<T> perp_projection(const vgl_homg_line_2d<T>& line,
00110 const vgl_homg_point_2d<T>& point);
00111
00112
00113 static vgl_homg_point_2d<T> midpoint(const vgl_homg_point_2d<T>& p1,
00114 const vgl_homg_point_2d<T>& p2);
00115
00116
00117 static vgl_homg_point_2d<T> lines_to_point(const vcl_vector<vgl_homg_line_2d<T> >& lines);
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 static double cross_ratio(const vgl_homg_point_2d<T>& p1,
00140 const vgl_homg_point_2d<T>& p2,
00141 const vgl_homg_point_2d<T>& p3,
00142 const vgl_homg_point_2d<T>& p4);
00143
00144
00145
00146
00147 static vgl_homg_point_2d<T> conjugate(const vgl_homg_point_2d<T>& a,
00148 const vgl_homg_point_2d<T>& b,
00149 const vgl_homg_point_2d<T>& c,
00150 double cr = -1.0);
00151
00152
00153 static vnl_vector_fixed<T,3> most_orthogonal_vector(const vcl_vector<vgl_homg_line_2d<T> >& lines);
00154
00155
00156 static vnl_vector_fixed<T,3> most_orthogonal_vector_svd(const vcl_vector<vgl_homg_line_2d<T> >& lines);
00157
00158
00159 static vgl_conic<T> vgl_conic_from_matrix(vnl_matrix_fixed<T,3,3> const& mat);
00160 static vnl_matrix_fixed<T,3,3> matrix_from_conic(vgl_conic<T> const&);
00161 static vnl_matrix_fixed<T,3,3> matrix_from_dual_conic(vgl_conic<T> const&);
00162
00163
00164 static vcl_list<vgl_homg_point_2d<T> > intersection(vgl_conic<T> const& c,
00165 vgl_homg_line_2d<T> const& l);
00166
00167
00168 static vcl_list<vgl_homg_point_2d<T> > intersection(vgl_conic<T> const& c1,
00169 vgl_conic<T> const& c2);
00170
00171
00172 static vcl_list<vgl_homg_line_2d<T> > tangent_from(vgl_conic<T> const& c,
00173 vgl_homg_point_2d<T> const& p);
00174
00175
00176 static vcl_list<vgl_homg_line_2d<T> > common_tangents(vgl_conic<T> const& c1,
00177 vgl_conic<T> const& c2);
00178
00179
00180 static vgl_homg_point_2d<T> closest_point(vgl_homg_line_2d<T> const& l,
00181 vgl_homg_point_2d<T> const& p);
00182
00183
00184 static vgl_homg_point_2d<T> closest_point(vgl_conic<T> const& c,
00185 vgl_homg_point_2d<T> const& p);
00186
00187
00188 static vgl_homg_point_2d<T> closest_point(vgl_conic<T> const& c,
00189 vgl_point_2d<T> const& p);
00190
00191
00192 inline static T distance_squared(vgl_conic<T> const& c,
00193 vgl_homg_point_2d<T> const& p)
00194 { return distance_squared(closest_point(c,p), p); }
00195
00196
00197 static vgl_box_2d<T> compute_bounding_box(vgl_conic<T> const& c);
00198
00199 private:
00200
00201 static vcl_list<vgl_homg_point_2d<T> > do_intersect(vgl_conic<T> const& q, vgl_homg_line_2d<T> const& l);
00202 static vcl_list<vgl_homg_point_2d<T> > do_intersect(vgl_conic<T> const& c1, vgl_conic<T> const& c2);
00203 };
00204
00205
00206
00207 template <class T>
00208 vgl_homg_point_2d<T> operator*(vnl_matrix_fixed<T,3,3> const& m,
00209 vgl_homg_point_2d<T> const& p);
00210
00211
00212
00213 template <class T>
00214 vgl_homg_line_2d<T> operator*(vnl_matrix_fixed<T,3,3> const& m,
00215 vgl_homg_line_2d<T> const& p);
00216
00217 #define VGL_HOMG_OPERATORS_2D_INSTANTIATE(T) \
00218 "Please #include <vgl/algo/vgl_homg_operators_2d.txx>"
00219
00220 #endif // vgl_homg_operators_2d_h_