contrib/mul/mmn/mmn_dependancy.h
Go to the documentation of this file.
00001 #ifndef mmn_dependancy_h_
00002 #define mmn_dependancy_h_
00003 
00004 //:
00005 // \file
00006 // \brief Store information about which node a given node depends on.
00007 // \author Tim Cootes
00008 
00009 #include <vsl/vsl_binary_io.h>
00010 #include <vcl_iostream.h>
00011 
00012 //: Value to indicate no valid arc
00013 const unsigned mmn_no_arc=99999;
00014 
00015 //: Value to indicate no valid triangle
00016 const unsigned mmn_no_tri=99999;
00017 
00018 //: Store information about which node a given node depends on
00019 //  If n_dep==1, then v0 depends only on v1 through arc1
00020 //  If n_dep==2 then v0 depends on v1 and v2, through arc1 and arc2 and tri1
00021 class mmn_dependancy
00022 {
00023  public:
00024   unsigned v0,v1,v2;
00025   unsigned arc1, arc2, arc12;
00026   unsigned n_dep;
00027   unsigned tri1;
00028 
00029   //: Default constructor
00030   mmn_dependancy()
00031     : v0(0), v1(0),v2(0),
00032       arc1(0),arc2(0),arc12(0),
00033       n_dep(0),tri1(mmn_no_tri) {}
00034 
00035   //: Construct with a single dependancy
00036   mmn_dependancy(unsigned u0, unsigned u1, unsigned a1)
00037     : v0(u0), v1(u1), v2(9999),
00038       arc1(a1), arc2(mmn_no_arc),arc12(mmn_no_arc),
00039       n_dep(1),tri1(mmn_no_tri) {}
00040 
00041   //: Construct with a dual dependancy but no triplet relation
00042   mmn_dependancy(unsigned u0, unsigned u1, unsigned u2,
00043                  unsigned a1, unsigned a2, unsigned a12)
00044     : v0(u0), v1(u1), v2(u2),
00045       arc1(a1), arc2(a2),arc12(a12),
00046       n_dep(2), tri1(mmn_no_tri) {}
00047 
00048   //: Construct with a dual dependancy, including triplet
00049   mmn_dependancy(unsigned u0, unsigned u1, unsigned u2,
00050                  unsigned a1, unsigned a2, unsigned a12, unsigned t1)
00051     : v0(u0), v1(u1), v2(u2),
00052       arc1(a1), arc2(a2),arc12(a12),
00053       n_dep(2), tri1(t1) {}
00054 };
00055 
00056 inline vcl_ostream& operator<<(vcl_ostream& os, const mmn_dependancy& t)
00057 {
00058   os<<'{';
00059   if (t.n_dep==1) os<<t.v0<<':'<<t.v1<<'}';
00060   if (t.n_dep==2) os<<t.v0<<":("<<t.v1<<','<<t.v2<<")}";
00061   return os;
00062 }
00063 
00064 inline void vsl_b_write(vsl_b_ostream& bfs, const mmn_dependancy& t)
00065 {
00066   vsl_b_write(bfs,short(1)); // Version 1
00067   vsl_b_write(bfs,t.v0);
00068   vsl_b_write(bfs,t.v1);
00069   vsl_b_write(bfs,t.v2);
00070   vsl_b_write(bfs,t.arc1);
00071   vsl_b_write(bfs,t.arc2);
00072   vsl_b_write(bfs,t.arc12);
00073   vsl_b_write(bfs,t.tri1);
00074   vsl_b_write(bfs,t.n_dep);
00075 }
00076 
00077 inline void vsl_b_read(vsl_b_istream& bfs, mmn_dependancy& t)
00078 {
00079   if (!bfs) return;
00080   short version;
00081   vsl_b_read(bfs,version);
00082   switch (version)
00083   {
00084     case 1:
00085       vsl_b_read(bfs,t.v0);
00086       vsl_b_read(bfs,t.v1);
00087       vsl_b_read(bfs,t.v2);
00088       vsl_b_read(bfs,t.arc1);
00089       vsl_b_read(bfs,t.arc2);
00090       vsl_b_read(bfs,t.arc12);
00091       vsl_b_read(bfs,t.tri1);
00092       vsl_b_read(bfs,t.n_dep);
00093       return;
00094     default:
00095       vcl_cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&)\n"
00096                << "           Unknown version number "<< version << vcl_endl;
00097       bfs.is().clear(vcl_ios::badbit); // Set an unrecoverable IO error on stream
00098       return;
00099   }
00100 }
00101 
00102 #endif // mmn_dependancy_h_
00103