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