00001 // This is brl/bseg/sdet/sdet_region_edge.cxx 00002 #include "sdet_region_edge.h" 00003 //: 00004 // \file 00005 #include <vcl_algorithm.h> // find 00006 #include <vtol/vtol_edge_2d.h> 00007 00008 sdet_region_edge::sdet_region_edge(vtol_edge_2d_sptr e) 00009 : edge_(e) 00010 { 00011 } 00012 00013 sdet_region_edge::~sdet_region_edge() 00014 { 00015 } 00016 00017 bool sdet_region_edge::is_vertex() const 00018 { 00019 return !edge_; // returns true if edge_ is a null (smart) pointer 00020 } 00021 00022 bool sdet_region_edge::SetNewLabel(unsigned int label) 00023 { 00024 if (label == 0) return false; 00025 if (vcl_find(labels_.begin(), labels_.end(), label) == labels_.end()) 00026 labels_.push_back(label); 00027 return true; 00028 } 00029 00030 unsigned int sdet_region_edge::NumLabels(unsigned int max_label) const 00031 { 00032 unsigned int n = labels_.size(); 00033 if (n<=max_label) 00034 return n; 00035 else 00036 { 00037 vcl_cout << "In sdet_region_edge::NumLabels(..) - # labels exceeds max label\n"; 00038 return 0; 00039 } 00040 } 00041 00042 //-------------------------------------------------------- 00043 //: Conditionally propagate the labels of a sdet_region_edge. 00044 // In this approach we don't differentiate between Right 00045 // and Left. Here we allow an unlimited number of labels 00046 // to be assigned to an edge, which is necessary due to 00047 // small regions which don't have proper closure but 00048 // whose edges are on the boundary of larger legitimate 00049 // regions. 00050 void sdet_region_edge::Prop(sdet_region_edge_sptr const& re, unsigned int label, 00051 unsigned int max_label) 00052 { 00053 //First try to propagate the labels 00054 //Do not allow propagation to occur 00055 //between different edges 00056 //re is the old edge whose information is being propagated to *this 00057 vtol_edge_2d_sptr source = re->get_edge(); 00058 vtol_edge_2d_sptr target = this->get_edge(); 00059 00060 //copy the labels from source to the new target 00061 if (source&&target&&*source==*target) 00062 for (unsigned int i = 0; i<re->NumLabels(max_label); ++i) 00063 this->SetNewLabel(re->GetLabel(i, max_label)); 00064 //set the new label onto this 00065 this->SetNewLabel(label); 00066 } 00067