1 // This is oxl/mvl/HomgLine2D.cxx
2 //:
3 // \file
4
5 #include <iostream>
6 #include "HomgLine2D.h"
7
8 #ifdef _MSC_VER
9 # include "vcl_msvc_warnings.h"
10 #endif
11
12 #include <vnl/algo/vnl_svd.h>
13
14 #include <mvl/Homg2D.h>
15 #include <mvl/HomgLineSeg2D.h>
16 #include <mvl/HomgOperator2D.h>
17
18 //--------------------------------------------------------------
19 //
20 //: Construct an ImplicitLine by clipping against the given bounding rectangle.
21 // The return line has been allocated using new.
clip(int rect1_x,int rect1_y,int rect2_x,int rect2_y) const22 HomgLineSeg2D HomgLine2D::clip(int rect1_x, int rect1_y, int rect2_x, int rect2_y) const
23 {
24 return HomgOperator2D::clip_line_to_lineseg(*this, rect1_x, rect1_y, rect2_x, rect2_y);
25 }
26
27 //--------------------------------------------------------------
28 //
29 //: Return some two points which are on the line.
30 // The algorithm actually returns an orthonormal basis for the nullspace of l.
get_2_points_on_line(HomgPoint2D * p1,HomgPoint2D * p2) const31 void HomgLine2D::get_2_points_on_line(HomgPoint2D* p1, HomgPoint2D* p2) const
32 {
33 vnl_matrix<double> M(get_vector().data_block(), 1, 3);
34 vnl_svd<double> svd(M);
35 p1->set(svd.V(0,1), svd.V(1,1), svd.V(2,1));
36 p2->set(svd.V(0,2), svd.V(1,2), svd.V(2,2));
37 }
38
39 //-----------------------------------------------------------------------------
40 //
41 //: Print to std::ostream in the format "<HomgLine2D x y w>"
operator <<(std::ostream & s,const HomgLine2D & p)42 std::ostream& operator<<(std::ostream& s, const HomgLine2D& p)
43 {
44 return s << "<HomgLine2D " << p.get_vector() << ">";
45 }
46