contrib/mul/mfpf/mfpf_region_about_lineseg.h
Go to the documentation of this file.
00001 #ifndef mfpf_region_about_lineseg_h_
00002 #define mfpf_region_about_lineseg_h_
00003 
00004 //:
00005 // \file
00006 // \brief Region centred on line segment between two points
00007 // \author Tim Cootes
00008 
00009 #include <mfpf/mfpf_region_definer.h>
00010 #include <vcl_iosfwd.h>
00011 
00012 //: Region centred on a line between two points.
00013 //  Region defined by two points, p0=pts[i0], p1=pts[i1]
00014 //  The region is centred on 0.5(p0+p1)
00015 //  Bounding box of region is aligned with the vector (p1-p0),
00016 //  and its width and height are defined relative to |p1-p0|
00017 //
00018 //  Parameters in text file:
00019 //  \verbatim
00020 //  { i0: 5 i1: 31 rel_wi: 0.5 rel_wj: 0.2 form: box }
00021 //  \endverbatim
00022 class mfpf_region_about_lineseg : public mfpf_region_definer
00023 {
00024 private:
00025   //: Index of first point defining reference frame
00026   unsigned i0_;
00027   //: Index of second point defining reference frame
00028   unsigned i1_;
00029 
00030   //: Width of ROI, relative to |p1-p0|
00031   double rel_wi_;
00032 
00033   //: Height of ROI, relative to |p1-p0|
00034   double rel_wj_;
00035 
00036   //: Width of ROI in world coords
00037   double wi_;
00038 
00039   //: Height of ROI in world coords
00040   double wj_;
00041 
00042   //: Name of form of shape ("box","ellipse")
00043   vcl_string form_;
00044 
00045 public:
00046 
00047   //: Dflt ctor
00048   mfpf_region_about_lineseg();
00049 
00050   //: Destructor
00051   virtual ~mfpf_region_about_lineseg();
00052 
00053   //: Returns false as the region is not centred on an input point
00054   virtual bool is_centred_on_pt() const;
00055 
00056   //: Returns zero
00057   virtual unsigned ref_point_index() const;
00058 
00059   //: Returns zero also
00060   virtual unsigned orig_ref_point_index() const;
00061 
00062   //: Replace each point index i with new_index[i]
00063   //  Allows for re-numbering of the points used.
00064   //  Returns true if successful.
00065   virtual bool replace_index(const vcl_vector<unsigned>& new_index);
00066 
00067   //: Index of first point defining reference frame
00068   unsigned i0() const { return i0_; }
00069 
00070   //: Index of second point defining reference frame
00071   unsigned i1() const { return i1_; }
00072 
00073   //: Width of ROI, relative to |p1-p0|
00074   double rel_wi() const { return rel_wi_; }
00075 
00076   //: Height of ROI, relative to |p1-p0|
00077   double rel_wj() const { return rel_wj_; }
00078 
00079   //: Width of ROI in world coords
00080   double wi() const { return wi_; }
00081 
00082   //: Height of ROI in world coords
00083   double wj() const { return wj_; }
00084 
00085   //: Name of form of shape ("box","ellipse")
00086   vcl_string form() const { return form_; }
00087 
00088   //: Returns reference point for region, mid_point(pts[i0],pts[i1])
00089   virtual vgl_point_2d<double> get_ref_point(
00090              const vcl_vector<vgl_point_2d<double> >& pts) const;
00091 
00092   //: Defines a region centred on the line between pts[i0] and pts[i1]
00093   virtual mfpf_region_form set_up(
00094              const vcl_vector<vgl_point_2d<double> >& pts);
00095 
00096   //: Defines a region centred on the line between pts[i0] and pts[i1]
00097   //  The aspect ratio of the region will be the same as that
00098   //  from the last call to set_up.
00099   virtual mfpf_region_form get_region(
00100                 const vcl_vector<vgl_point_2d<double> >& pts) const;
00101 
00102   //: Initialise from a stream
00103   virtual bool set_from_stream(vcl_istream &is);
00104 
00105   //: Version number for I/O
00106   short version_no() const;
00107 
00108   //: Name of the class
00109   virtual vcl_string is_a() const;
00110 
00111   //: Create a copy on the heap and return base class pointer
00112   virtual mfpf_region_definer* clone() const;
00113 
00114   //: Print class to os
00115   virtual void print_summary(vcl_ostream& os) const;
00116 
00117   //: Save class to binary file stream
00118   virtual void b_write(vsl_b_ostream& bfs) const;
00119 
00120   //: Load class from binary file stream
00121   virtual void b_read(vsl_b_istream& bfs);
00122 };
00123 
00124 #endif