contrib/gel/vdgl/vdgl_edgel_chain.h
Go to the documentation of this file.
00001 // This is gel/vdgl/vdgl_edgel_chain.h
00002 #ifndef vdgl_edgel_chain_h
00003 #define vdgl_edgel_chain_h
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Represents an edgel list which is a 2d set of edgels
00010 // \author Geoff Cross
00011 //
00012 // \verbatim
00013 //  Modifications:
00014 //   10-Apr-2002 Peter Vanroose - Added & implemented split(), extract_subchain()
00015 //   17-May-2004 Joseph Mundy - Added digital I/O
00016 //   10-Sep-2004 Peter Vanroose Added copy ctor with explicit vbl_ref_count init
00017 // \endverbatim
00018 
00019 #include <vcl_iosfwd.h>
00020 #include <vcl_vector.h>
00021 #include <vul/vul_timestamp.h>
00022 #include <vbl/vbl_ref_count.h>
00023 #include <vsl/vsl_binary_io.h>
00024 #include "vdgl_edgel_chain_sptr.h"
00025 #include <vdgl/vdgl_edgel.h>
00026 
00027 class vdgl_edgel_chain : public vul_timestamp,
00028                          public vbl_ref_count
00029 {
00030   // PUBLIC INTERFACE----------------------------------------------------------
00031  public:
00032 
00033   // Constructors/Destructors--------------------------------------------------
00034   vdgl_edgel_chain() {}
00035   vdgl_edgel_chain(vcl_vector<vdgl_edgel> const& edgels) : es_( edgels) {}
00036 
00037   //: make a straight edgel chain from p0 to p1.
00038   //  Useful for boundary filling and debugging
00039   vdgl_edgel_chain( const double x0, const double y0,
00040                     const double x1, const double y1);
00041   vdgl_edgel_chain(vdgl_edgel_chain const& x)
00042     : vul_timestamp(), vbl_ref_count(), es_(x.es_) {}
00043   ~vdgl_edgel_chain() {}
00044 
00045   // Operators----------------------------------------------------------------
00046 
00047   bool add_edgel( const vdgl_edgel &e);
00048   bool add_edgels( const vcl_vector<vdgl_edgel> &es, const int index);
00049   bool set_edgel( const int index, const vdgl_edgel &e);
00050   //: return a new edgel_chain, containing the edgels numbered start up to end.
00051   vdgl_edgel_chain_sptr extract_subchain(int start, int end);
00052   //: split the current edgel_chain at or around the given point (x,y)
00053   bool split( double x, double y,
00054               vdgl_edgel_chain_sptr &ec1, vdgl_edgel_chain_sptr &ec2);
00055 
00056   friend vcl_ostream& operator<<(vcl_ostream& s, const vdgl_edgel_chain& p);
00057   friend bool operator==( const vdgl_edgel_chain &ec1, const vdgl_edgel_chain &ec2);
00058   friend bool operator!=( const vdgl_edgel_chain &ec1, const vdgl_edgel_chain &ec2);
00059   // Data Access---------------------------------------------------------------
00060 
00061   unsigned int size() const { return es_.size(); }
00062   vdgl_edgel& edgel( int i) { return es_[i]; }
00063   vdgl_edgel const& edgel( int i) const { return es_[i]; }
00064   vdgl_edgel& operator[]( int i) { return es_[i]; }
00065   vdgl_edgel const& operator[]( int i) const { return es_[i]; }
00066 
00067   //: should call this if one of the edgels is likely to have changed
00068   void notify_change();
00069 
00070   // ==== Binary IO methods ======
00071 
00072   //: Binary save self to stream.
00073   void b_write(vsl_b_ostream &os) const;
00074 
00075   //: Binary load self from stream.
00076   void b_read(vsl_b_istream &is);
00077 
00078   //: Return IO version number;
00079   short version() const;
00080 
00081   //: Print an ascii summary to the stream
00082   void print_summary(vcl_ostream &os) const;
00083 
00084   //: Return a platform independent string identifying the class
00085   virtual vcl_string is_a() const { return vcl_string("vdgl_edgel_chain"); }
00086 
00087   //: Return true if the argument matches the string identifying the class or any parent class
00088   virtual bool is_class(vcl_string const& cls) const { return cls==is_a(); }
00089 
00090   // INTERNALS-----------------------------------------------------------------
00091  protected:
00092 
00093   // Utility functions
00094 
00095   //: Advance along a line and generate contiguous pixels on the line.
00096   bool line_gen(double xs, double ys, double xe, double ye,
00097                 bool& init, bool& done, double& x, double& y);
00098 
00099   // Data Members--------------------------------------------------------------
00100 
00101   vcl_vector<vdgl_edgel> es_;
00102 };
00103 
00104 //: Stream operator
00105 vcl_ostream& operator<<(vcl_ostream& s, const vdgl_edgel_chain& e);
00106 
00107 //: Binary save vdgl_edgel_chain* to stream.
00108 void vsl_b_write(vsl_b_ostream &os, const vdgl_edgel_chain* e);
00109 
00110 //: Binary load vdgl_edgel_chain* from stream.
00111 void vsl_b_read(vsl_b_istream &is, vdgl_edgel_chain* &e);
00112 
00113 //: Print human readable summary of vdgl_edgel_chain* to a stream.
00114 void vsl_print_summary(vcl_ostream &os, const vdgl_edgel_chain* e);
00115 
00116 
00117 #endif // vdgl_edgel_chain_h