contrib/mul/mmn/mmn_arc.h
Go to the documentation of this file.
00001 #ifndef mmn_arc_h_
00002 #define mmn_arc_h_
00003 //:
00004 // \file
00005 // \brief Representation of topological arc joining two vertices
00006 // \author Tim Cootes
00007 
00008 
00009 #include <vsl/vsl_binary_io.h>
00010 #include <vcl_iostream.h>
00011 #include <vcl_vector.h>
00012 
00013 //: Representation of topological arc joining two vertices
00014 class mmn_arc
00015 {
00016  public:
00017   unsigned v1,v2;
00018 
00019   mmn_arc() :v1(999999),v2(999999) {}
00020   mmn_arc(unsigned i1, unsigned i2) : v1(i1),v2(i2) {}
00021 
00022   //: Return smallest node index
00023   unsigned min_v() const { return v1<v2?v1:v2; }
00024   //: Return largest node index
00025   unsigned max_v() const { return v1<v2?v2:v1; }
00026 };
00027 
00028 inline bool operator==(const mmn_arc& t1, const mmn_arc& t2)
00029 {
00030   if ((t1.v1==t2.v1) && (t1.v2==t2.v2)) return true;
00031   if ((t1.v1==t2.v2) && (t1.v2==t2.v1)) return true;
00032   return false;
00033 }
00034 
00035 inline bool operator!=(const mmn_arc& t1, const mmn_arc& t2)
00036 { return !(t1==t2); }
00037 
00038 inline vcl_ostream& operator<<(vcl_ostream& os, const mmn_arc& t)
00039 {
00040   return os<<'{'<<t.v1<<','<<t.v2<<'}';
00041 }
00042 
00043 inline vcl_ostream& operator<<(vcl_ostream& os,
00044                                const vcl_vector<mmn_arc>& arcs)
00045 {
00046   for (unsigned i=0;i<arcs.size();++i) os<<arcs[i];
00047   return os;
00048 }
00049 
00050 inline void vsl_b_write(vsl_b_ostream& bfs, const mmn_arc& t)
00051 {
00052   vsl_b_write(bfs,t.v1);
00053   vsl_b_write(bfs,t.v2);
00054 }
00055 
00056 inline void vsl_b_read(vsl_b_istream& bfs, mmn_arc& t)
00057 {
00058   vsl_b_read(bfs,t.v1);
00059   vsl_b_read(bfs,t.v2);
00060 }
00061 
00062 inline void vsl_b_write(vsl_b_ostream& bfs, const vcl_vector<mmn_arc>& a)
00063 {
00064   short version_no = 1;
00065   vsl_b_write(bfs,version_no);
00066   vsl_b_write(bfs,a.size());
00067   for (unsigned i=0;i<a.size();++i) vsl_b_write(bfs,a[i]);
00068 }
00069 
00070 inline void vsl_b_read(vsl_b_istream& bfs, vcl_vector<mmn_arc>& a)
00071 {
00072   if (!bfs) return;
00073   short version;
00074   vsl_b_read(bfs,version);
00075   unsigned n;
00076   switch (version)
00077   {
00078     case (1):
00079       vsl_b_read(bfs,n);
00080       a.resize(n);
00081       for (unsigned i=0;i<n;++i) vsl_b_read(bfs,a[i]);
00082       break;
00083     default:
00084       vcl_cerr << "I/O ERROR: vsl_b_read(bfs,vector<arc>)\n"
00085                << "           Unknown version number "<< version << '\n';
00086       bfs.is().clear(vcl_ios::badbit); // Set an unrecoverable IO error on stream
00087       return;
00088   }
00089 }
00090 
00091 
00092 #endif // mmn_arc_h_