contrib/mul/fhs/fhs_arc.h
Go to the documentation of this file.
00001 // This is mul/fhs/fhs_arc.h
00002 #ifndef fhs_arc_h_
00003 #define fhs_arc_h_
00004 //:
00005 // \file
00006 // \author Tim Cootes
00007 // \brief Link between one node and another
00008 
00009 #include <vsl/vsl_binary_io.h>
00010 #include <vcl_vector.h>
00011 #include <vcl_iosfwd.h>
00012 
00013 //: Link between one node and another
00014 //  Indicates that position of node j, p(j) = p(i) + (N(dx,var_x),N(dy,var_y))
00015 //  where N(m,var) is a gaussian with mean m and variance var
00016 class fhs_arc
00017 {
00018 private:
00019   unsigned i_;
00020   unsigned j_;
00021   double dx_;
00022   double dy_;
00023   double var_x_;
00024   double var_y_;
00025 public:
00026     //: Default constructor
00027   fhs_arc()
00028     : i_(0),j_(0),dx_(0),dy_(0),var_x_(1.0),var_y_(1.0) {}
00029 
00030     //: Constructor
00031   fhs_arc(int i, int j, double dx, double dy, double var_x, double var_y)
00032     : i_(i),j_(j),dx_(dx),dy_(dy),var_x_(var_x),var_y_(var_y) {}
00033 
00034   //: Return arc from j to i (ie directions reversed)
00035   fhs_arc flipped() const
00036   { return fhs_arc(j(),i(),-dx(),-dy(),var_x(),var_y()); }
00037 
00038     //: Index of first node
00039   unsigned i() const { return i_; }
00040 
00041     //: Index of second node
00042   unsigned j() const { return j_; }
00043 
00044     //: Mean x offset of j() from i()
00045   double dx() const { return dx_; }
00046 
00047     //: Mean y offset of j() from i()
00048   double dy() const { return dy_; }
00049 
00050     //: Variance of x offset of j() from i()
00051   double var_x() const { return var_x_; }
00052 
00053     //: Variance of y offset of j() from i()
00054   double var_y() const { return var_y_; }
00055 
00056     //: Write to binary stream
00057   void b_write(vsl_b_ostream& bfs) const;
00058 
00059     //: Read from binary stream
00060   void b_read(vsl_b_istream& bfs);
00061 };
00062 
00063 //: Re-order list of arcs so that parents precede their children
00064 //  Assumes that there are n nodes (indexed 0..n-1),
00065 //  thus n-1 arcs defining a tree.
00066 //  On exit children[i] gives list of children of node i
00067 bool fhs_order_tree_from_root(const vcl_vector<fhs_arc>& arc0,
00068                          vcl_vector<fhs_arc>& new_arc,
00069                          vcl_vector<vcl_vector<unsigned> >& children,
00070                          unsigned new_root);
00071 
00072 
00073 //: Print
00074 vcl_ostream& operator<<(vcl_ostream& os, const fhs_arc& c);
00075 
00076 //: Print set
00077 vcl_ostream& operator<<(vcl_ostream& os, const vcl_vector<fhs_arc>& arc);
00078 
00079 //: Save
00080 inline void vsl_b_write(vsl_b_ostream& bfs, const fhs_arc& t)
00081 {
00082   t.b_write(bfs);
00083 }
00084 
00085 //: Load
00086 inline void vsl_b_read(vsl_b_istream& bfs, fhs_arc& t)
00087 {
00088   t.b_read(bfs);
00089 }
00090 
00091 //: Print
00092 void vsl_print_summary(vcl_ostream& os, const fhs_arc& t);
00093 
00094 #endif // fhs_arc_h_