00001 // This is gel/pop/pop_vertex.cxx 00002 #include "pop_vertex.h" 00003 //: 00004 // \file 00005 #include <pop/pop_edge.h> 00006 00007 00008 // make the static 00009 static vcl_list<pop_vertex*> all_vertex_; 00010 00011 //: constructor 00012 pop_vertex::pop_vertex() 00013 { 00014 touched_ = false; 00015 // add this to the list of all known vertex 00016 all_vertex_.push_back(this); 00017 } 00018 00019 00020 //: destructor 00021 pop_vertex::~pop_vertex() 00022 { 00023 } 00024 00025 00026 //: A list of edges that can lead to other vertex 00027 void pop_vertex::add_edge(pop_edge* ed) 00028 { 00029 edges_.push_back(ed); 00030 } 00031 00032 //: set all vertex to untouched 00033 void pop_vertex::clear() 00034 { 00035 // mark all vertex as un touched 00036 vcl_list<pop_vertex*>::iterator it; 00037 for (it= all_vertex_.begin();it!=all_vertex_.end();it++) { 00038 (*it)->touched_ = false; 00039 } 00040 } 00041 00042 //: find a path to another vertex 00043 bool pop_vertex::search(pop_vertex *destination, vcl_list<pop_edge*> &path) 00044 { 00045 // if this vertex has already been touched return false; 00046 if (touched_) { 00047 return false; 00048 } 00049 00050 // set touched to true so we will not go through this vertex again 00051 touched_ = true; 00052 00053 // search all edges 00054 00055 vcl_list<pop_edge*>::iterator ei; 00056 00057 // perform a depth first search 00058 00059 for (ei=edges_.begin();ei!=edges_.end();ei++) { 00060 if ((*ei)->search(destination,path)) { 00061 return true; 00062 } 00063 } 00064 // it looks like no path exists so return false 00065 return false; 00066 } 00067 00068 //: find a path of edges to the following vertex 00069 bool pop_vertex::find_path(pop_vertex *destination, vcl_list<pop_edge*> &path) 00070 { 00071 // clear all the vertex touched flags 00072 clear(); 00073 00074 // start to search for the path 00075 return search(destination,path); 00076 }
1.5.1