contrib/oxl/mvl/HomgPoint3D.cxx
Go to the documentation of this file.
00001 // This is oxl/mvl/HomgPoint3D.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 
00008 #include "HomgPoint3D.h"
00009 #include <vcl_iostream.h>
00010 
00011 //--------------------------------------------------------------
00012 //
00013 //: Return the non-homogeneous coordinates of the point.
00014 // If the point is at infinity, return false and set the
00015 // output values to Homg::infinity.
00016 bool
00017 HomgPoint3D::get_nonhomogeneous(double& vx, double& vy, double& vz) const
00018 {
00019   double hx = x();
00020   double hy = y();
00021   double hz = z();
00022   double hw = w();
00023   if (hw == 0) {
00024     vx = vy = vz = Homg::infinity;
00025     return false;
00026   }
00027 
00028   hw = 1.0/hw;
00029   vx = hx * hw;
00030   vy = hy * hw;
00031   vz = hz * hw;
00032 
00033   return true;
00034 }
00035 
00036 //--------------------------------------------------------------
00037 //
00038 //: Return the non-homogeneous coordinates of the point as a vector of doubles
00039 // If the point is at infinity, return a vector of Homg::infinity
00040 vnl_double_3
00041 HomgPoint3D::get_double3() const
00042 {
00043   vnl_double_3 ret;
00044   get_nonhomogeneous(ret[0], ret[1], ret[2]);
00045   return ret;
00046 }
00047 
00048 //-----------------------------------------------------------------------------
00049 //--------------------------------------------------------------
00050 //
00051 //: Rescale point
00052 // If the point is at infinity, return false
00053 bool
00054 HomgPoint3D::rescale_w(double new_w)
00055 {
00056   double hx = x();
00057   double hy = y();
00058   double hz = z();
00059   double hw = w();
00060 
00061   if (hw == 0)
00062     return false;
00063 
00064   hw = new_w/hw;
00065 
00066   homg_vector_[0] = hx*hw;
00067   homg_vector_[1] = hy*hw;
00068   homg_vector_[2] = hz*hw;
00069   homg_vector_[3] = new_w;
00070 
00071   return true;
00072 }
00073 
00074 //
00075 //: Print to vcl_ostream
00076 vcl_ostream& operator<<(vcl_ostream& s, const HomgPoint3D& p)
00077 {
00078   return s << "<HomgPoint3D " << p.get_vector() << '>';
00079 }