core/vcsl/vcsl_graph.cxx
Go to the documentation of this file.
00001 // This is core/vcsl/vcsl_graph.cxx
00002 #include "vcsl_graph.h"
00003 #include <vcl_cassert.h>
00004 #include <vcsl/vcsl_spatial.h>
00005 
00006 //---------------------------------------------------------------------------
00007 // Has `this' `cs' as node ?
00008 //---------------------------------------------------------------------------
00009 bool vcsl_graph::has(const vcsl_spatial_sptr &cs) const
00010 {
00011   bool result;
00012 
00013   vcl_vector<vcsl_spatial_sptr>::const_iterator i;
00014 
00015   result=false;
00016   for (i=vertices_.begin();i!=vertices_.end()&&!result;++i)
00017     result=(*i)==cs;
00018 
00019   return result;
00020 }
00021 
00022 //---------------------------------------------------------------------------
00023 // Spatial coordinate system number `index'
00024 // REQUIRE: valid_index(index)
00025 //---------------------------------------------------------------------------
00026 vcsl_spatial_sptr vcsl_graph::item(unsigned int index) const
00027 {
00028   // require
00029   assert(valid_index(index));
00030 
00031   return vertices_[index];
00032 }
00033 
00034 //---------------------------------------------------------------------------
00035 // Add `cs' in `this'
00036 // REQUIRE: !has(cs)
00037 //---------------------------------------------------------------------------
00038 void vcsl_graph::put(const vcsl_spatial_sptr &cs)
00039 {
00040   // require
00041   assert(!has(cs));
00042 
00043   vertices_.push_back(cs);
00044 }
00045 
00046 //---------------------------------------------------------------------------
00047 // Remove `cs' from `this'
00048 // REQUIRE: has(cs)
00049 //---------------------------------------------------------------------------
00050 void vcsl_graph::remove(const vcsl_spatial_sptr &cs)
00051 {
00052   // require
00053   assert(has(cs));
00054 
00055   vcl_vector<vcsl_spatial_sptr>::iterator i;
00056 
00057   for (i=vertices_.begin(); i!=vertices_.end()&&((*i)!=cs); ++i)
00058     ;
00059   vertices_.erase(i);
00060 }
00061 
00062 // Set the flag `reached' to false for each spatial coordinate system
00063 // Used by the search path algorithm
00064 void vcsl_graph::init_vertices() const
00065 {
00066   vcl_vector<vcsl_spatial_sptr>::const_iterator i;
00067 
00068   for (i=vertices_.begin();i!=vertices_.end();++i)
00069     (*i)->set_reached(false);
00070 }