Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

vgl_homg_plane_3d.txx

Go to the documentation of this file.
00001 // This is core/vgl/vgl_homg_plane_3d.txx
00002 #ifndef vgl_homg_plane_3d_txx_
00003 #define vgl_homg_plane_3d_txx_
00004 //:
00005 // \file
00006 
00007 #include "vgl_homg_plane_3d.h"
00008 #include <vcl_cassert.h>
00009 #include <vcl_iostream.h>
00010 #include <vgl/vgl_plane_3d.h>
00011 #include <vgl/vgl_homg_point_3d.h>
00012 #include <vgl/vgl_homg_line_3d_2_points.h>
00013 
00014 //: Construct from non-homogeneous plane
00015 template <class Type>
00016 vgl_homg_plane_3d<Type>::vgl_homg_plane_3d(vgl_plane_3d<Type> const& pl)
00017   : a_(pl.a()), b_(pl.b()), c_(pl.c()), d_(pl.d()) {}
00018 
00019 //: Construct from three points
00020 template <class Type>
00021 vgl_homg_plane_3d<Type>::vgl_homg_plane_3d (vgl_homg_point_3d<Type> const& p1,
00022                                             vgl_homg_point_3d<Type> const& p2,
00023                                             vgl_homg_point_3d<Type> const& p3)
00024 : a_(p1.w()*(p2.y()*p3.z()-p2.z()*p3.y())
00025     +p2.w()*(p3.y()*p1.z()-p3.z()*p1.y())
00026     +p3.w()*(p1.y()*p2.z()-p1.z()*p2.y()))
00027 , b_(p1.w()*(p2.z()*p3.x()-p2.x()*p3.z())
00028     +p2.w()*(p3.z()*p1.x()-p3.x()*p1.z())
00029     +p3.w()*(p1.z()*p2.x()-p1.x()*p2.z()))
00030 , c_(p1.w()*(p2.x()*p3.y()-p2.y()*p3.x())
00031     +p2.w()*(p3.x()*p1.y()-p3.y()*p1.x())
00032     +p3.w()*(p1.x()*p2.y()-p1.y()*p2.x()))
00033 , d_(p1.x()*(p2.z()*p3.y()-p2.y()*p3.z())
00034     +p2.x()*(p1.y()*p3.z()-p1.z()*p3.y())
00035     +p3.x()*(p1.z()*p2.y()-p1.y()*p2.z()))
00036 {
00037   assert(a_||b_||c_||d_); // points should not be collinear or coinciding
00038 }
00039 
00040 //: Construct from two concurrent lines
00041 template <class Type>
00042 vgl_homg_plane_3d<Type>::vgl_homg_plane_3d(vgl_homg_line_3d_2_points<Type> const& l1,
00043                                            vgl_homg_line_3d_2_points<Type> const& l2)
00044 {
00045   assert(concurrent(l1,l2));
00046   vgl_homg_point_3d<Type> p1 = l1.point_finite();
00047   vgl_homg_point_3d<Type> p2 = l1.point_infinite();
00048   vgl_homg_point_3d<Type> p3 = l2.point_finite();
00049   if (collinear(p1,p2,p3)) p3 = l2.point_infinite();
00050   *this = vgl_homg_plane_3d<Type>(p1,p2,p3);
00051 }
00052 
00053 //: Construct from normal and a point
00054 // This will fail when the given point is at infinity!
00055 template <class Type>
00056 vgl_homg_plane_3d<Type>::vgl_homg_plane_3d(vgl_vector_3d<Type> const& n,
00057                                            vgl_homg_point_3d<Type> const&p)
00058  : a_(n.x()*p.w()), b_(n.y()*p.w()), c_(n.z()*p.w()),
00059    d_(n.x()*p.x()+n.y()*p.y()+n.z()*p.z()) {}
00060 
00061 template <class Type>
00062 bool vgl_homg_plane_3d<Type>::operator==(vgl_homg_plane_3d<Type> const& p) const
00063 {
00064   return (this==&p) ||
00065          (   (a()*p.b()==p.a()*b())
00066           && (a()*p.c()==p.a()*c())
00067           && (a()*p.d()==p.a()*d())
00068           && (b()*p.c()==p.b()*c())
00069           && (b()*p.d()==p.b()*d())
00070           && (c()*p.d()==p.c()*d()) );
00071 }
00072 
00073 template <class Type>
00074 vcl_ostream& operator<<(vcl_ostream& s, const vgl_homg_plane_3d<Type>& p)
00075 {
00076   return s << " <vgl_homg_plane_3d "
00077            << p.a() << " x + "
00078            << p.b() << " y + "
00079            << p.c() << " z + "
00080            << p.d() << " w = 0 >";
00081 }
00082 
00083 template <class Type>
00084 vcl_istream& operator>>(vcl_istream& s, vgl_homg_plane_3d<Type>& p)
00085 {
00086   Type a, b, c, d;
00087   s >> a >> b >> c >> d;
00088   p.set(a,b,c,d);
00089   return s;
00090 }
00091 
00092 #undef VGL_HOMG_PLANE_3D_INSTANTIATE
00093 #define VGL_HOMG_PLANE_3D_INSTANTIATE(T) \
00094 template class vgl_homg_plane_3d<T >; \
00095 template vcl_ostream& operator<<(vcl_ostream&, vgl_homg_plane_3d<T >const&); \
00096 template vcl_istream& operator>>(vcl_istream&, vgl_homg_plane_3d<T >&)
00097 
00098 #endif // vgl_homg_plane_3d_txx_

Generated on Thu Jan 10 14:39:24 2008 for core/vgl by  doxygen 1.4.4