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