contrib/gel/vifa/vifa_imp_line.h
Go to the documentation of this file.
00001 // This is gel/vifa/vifa_imp_line.h
00002 #ifndef _VIFA_IMP_LINE_H_
00003 #define _VIFA_IMP_LINE_H_
00004 //-----------------------------------------------------------------------------
00005 //:
00006 // \file
00007 // \brief Implicit line segment.
00008 //
00009 // The vifa_imp_line class provides an implicit line segment for computing
00010 // attributes for the edges of intensity faces.  A subclass of the core class
00011 // vgl_line_segment_2d, additional API's for axis projection and parametric
00012 // evaluation are provided.
00013 //
00014 // \author Mike Petersen, June 2003
00015 //
00016 //-----------------------------------------------------------------------------
00017 
00018 #include <vbl/vbl_ref_count.h>
00019 #include <vgl/vgl_point_2d.h>
00020 #include <vgl/vgl_vector_2d.h>
00021 #include <vgl/vgl_line_segment_2d.h>
00022 
00023 template <class Type>
00024 class vifa_imp_line : public vbl_ref_count, public vgl_line_segment_2d<Type>
00025 {
00026  protected:
00027   //: X-axis span of line segment
00028   double dx_;
00029 
00030   //: Y-axis span of line segment
00031   double dy_;
00032 
00033  public:
00034   //: Default constructor - does not initialize
00035   inline vifa_imp_line(void) {}
00036 
00037   // copy constructor - compiler-provided one sets ref_count to nonzero which is wrong -PVr
00038   vifa_imp_line(vifa_imp_line const& l)
00039     : vbl_ref_count(), vgl_line_segment_2d<Type>(l), dx_(l.dx_), dy_(l.dy_) {}
00040 
00041   //: Line segment constructor
00042   vifa_imp_line(vgl_point_2d<Type> const& p1,
00043                 vgl_point_2d<Type> const& p2);
00044 
00045   //: Direction/midpoint constructor
00046   vifa_imp_line(vgl_vector_2d<Type> d,
00047                 vgl_point_2d<Type>  m);
00048 
00049   //: Implicit coefficient constructor
00050   vifa_imp_line(Type a, Type b, Type c);
00051 
00052   //: Test if a value is near 0.0
00053   inline bool near_zero(double x) const { return x < 1e-6; }
00054 
00055   //: Compute unit projection along X-axis
00056   double get_dir_x(void);
00057 
00058   //: Compute unit projection along Y-axis
00059   double get_dir_y(void);
00060 
00061   //: Compute length of line segment
00062   double length(void);
00063 
00064   //: Assignment
00065   void set_points(vgl_point_2d<Type> const& p1,
00066                   vgl_point_2d<Type> const& p2);
00067 
00068   //: Project a 2D point onto the line
00069   void project_2d_pt(const Type& p,
00070                      const Type& q,
00071                      Type&       x,
00072                      Type&       y) const;
00073 
00074   vgl_point_2d<Type> project_2d_pt(const vgl_point_2d<Type>& t) const;
00075 
00076   //: Find parametric t-value for a given point relative to line segment.
00077   double find_t(const vgl_point_2d<Type>& p);
00078 
00079   //: Find point on line (defined by line segment) for a parametric t-value.
00080   vgl_point_2d<Type> find_at_t(double t);
00081 };
00082 
00083 #endif // _VIFA_IMP_LINE_H_