contrib/oxl/mvl/HomgLine3D.cxx
Go to the documentation of this file.
00001 // This is oxl/mvl/HomgLine3D.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 //  \file
00007 
00008 #include "HomgLine3D.h"
00009 #include <mvl/Homg3D.h>
00010 #include <vcl_iostream.h>
00011 
00012 //--------------------------------------------------------------
00013 //
00014 //: Constructor
00015 HomgLine3D::HomgLine3D()
00016 {
00017 }
00018 
00019 //--------------------------------------------------------------
00020 //
00021 //: Constructor
00022 HomgLine3D::HomgLine3D( const HomgLine3D &that)
00023   : point_finite_(that.point_finite_)
00024   , point_infinite_(that.point_infinite_)
00025 {
00026 }
00027 
00028 //--------------------------------------------------------------
00029 //
00030 //: Constructor, initialise using the specified distinct points on the line.
00031 HomgLine3D::HomgLine3D (const HomgPoint3D& start,
00032                         const HomgPoint3D& end)
00033 {
00034   // ho_quadvecstd_points2_to_line
00035   bool start_finite = start.w() != 0.0;
00036   bool end_finite = end.w() != 0.0;
00037 
00038   if (start_finite && end_finite) {
00039     point_finite_ = start;
00040 
00041     vnl_double_3 start_trivec = start.get_double3();
00042     vnl_double_3 end_trivec = end.get_double3();
00043     vnl_double_3 direction = (end_trivec - start_trivec);
00044     direction.normalize();
00045 
00046     point_infinite_.set(direction[0], direction[1], direction[2], 0.0);
00047   } else if (end_finite) {
00048     // Start infinite
00049     point_finite_ = end;
00050 
00051     const vnl_vector<double>& dir = start.get_vector().as_ref();
00052     point_infinite_ = HomgPoint3D(dir / dir.magnitude());
00053   } else {
00054     // End infinite -- just assign
00055     point_finite_ = start;
00056     const vnl_vector<double>& dir = end.get_vector().as_ref();
00057     point_infinite_ = HomgPoint3D(dir / dir.magnitude());
00058   }
00059 }
00060 
00061 //--------------------------------------------------------------
00062 //
00063 //: Destructor
00064 HomgLine3D::~HomgLine3D()
00065 {
00066 }
00067 
00068 //-----------------------------------------------------------------------------
00069 //
00070 //: print to vcl_ostream
00071 vcl_ostream& operator<<(vcl_ostream& s, const HomgLine3D& l)
00072 {
00073   return s << "<HomgLine3D " << l.get_point_finite() << " dir " << l.get_point_infinite() << ">";
00074 }
00075 
00076 //: Push point2 off to infinity
00077 void HomgLine3D::force_point2_infinite()
00078 {
00079 }
00080 
00081 //: Return line direction as a 3-vector
00082 vnl_double_3 HomgLine3D::dir() const
00083 {
00084   const vnl_vector<double>& d = point_infinite_.get_vector().as_ref();
00085   if (d[3] != 0) {
00086     vcl_cerr << *this;
00087     vcl_cerr << "*** HomgLine3D: Infinite point not at infinity!! ***\n";
00088   }
00089   return vnl_double_3(d[0], d[1], d[2]);
00090 }