contrib/brl/bseg/brip/brip_label_equivalence.h
Go to the documentation of this file.
00001 // This is brl/bseg/brip/brip_label_equivalence.h
00002 #ifndef brip_label_equivalence_h_
00003 #define brip_label_equivalence_h_
00004 //-----------------------------------------------------------------------------
00005 //:
00006 // \file
00007 // \author J.L. Mundy
00008 // \brief Maintain label equivalences and determine transitive closure of equivalence classes.
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   Initial version May 5, 2008
00013 // \endverbatim
00014 //
00015 #include <vcl_map.h>
00016 #include <vcl_set.h>
00017 
00018 class brip_label_equivalence
00019 {
00020  public:
00021   brip_label_equivalence():max_label_(0){}
00022   ~brip_label_equivalence(){}
00023 
00024   //:add a label pair equivalence
00025   void add_label_pair(unsigned la, unsigned lb);
00026 
00027   //:carry out full propagation of label equivalence
00028   void transitive_closure();
00029 
00030   //:the full set of labels
00031   vcl_set<unsigned> labels() const;
00032 
00033   //:the set of labels equivalent to a given label
00034   vcl_map<unsigned, vcl_set<unsigned> >& equivalence_sets()
00035     { return equivalence_sets_;}
00036 
00037  protected:
00038   unsigned max_label_;
00039   bool get_next_label(vcl_set<unsigned> const& labels, unsigned int& label);
00040 
00041   bool merge_equivalence(vcl_map<unsigned int, vcl_set<unsigned int> >& tab,
00042                          unsigned int cur_label,
00043                          unsigned int label);
00044   vcl_map<unsigned, vcl_set<unsigned> > forward_pairs_;
00045   vcl_map<unsigned, vcl_set<unsigned> > reverse_pairs_;
00046   vcl_map<unsigned, vcl_set<unsigned> > equivalence_sets_;
00047 };
00048 
00049 #endif // brip_label_equivalence_h_