contrib/gel/vtol/vtol_topology_cache.cxx
Go to the documentation of this file.
00001 // This is gel/vtol/vtol_topology_cache.cxx
00002 #include "vtol_topology_cache.h"
00003 //:
00004 //  \file
00005 
00006 //: Set up the cache
00007 vtol_topology_cache::vtol_topology_cache()
00008 {
00009   source_ = 0;
00010   vertices_ = 0;
00011   zerochains_ = 0;
00012   edges_  = 0;
00013   onechains_ = 0;
00014   faces_ =0;
00015   twochains_ =0;
00016   blocks_ =0;
00017 }
00018 
00019 //: Set up the cache
00020 vtol_topology_cache::vtol_topology_cache(vtol_topology_object * to_be_cached)
00021 {
00022   source_ = to_be_cached;
00023   vertices_ = 0;
00024   zerochains_ = 0;
00025   edges_  = 0;
00026   onechains_ = 0;
00027   faces_ =0;
00028   twochains_ =0;
00029   blocks_ =0;
00030 }
00031 
00032 // destructor
00033 vtol_topology_cache::~vtol_topology_cache()
00034 {
00035   this->clear_cache();
00036 }
00037 
00038 //: set the source topology object
00039 void vtol_topology_cache::set_source(vtol_topology_object *to_be_cached)
00040 {
00041   source_ = to_be_cached;
00042 }
00043 
00044 //: reset the list pointers
00045 void vtol_topology_cache::clear_cache()
00046 {
00047   delete vertices_; vertices_ = 0;
00048   delete zerochains_; zerochains_ = 0;
00049   delete edges_; edges_ = 0;
00050   delete onechains_; onechains_ = 0;
00051   delete faces_; faces_ = 0;
00052   delete twochains_; twochains_ = 0;
00053   delete blocks_; blocks_ = 0;
00054 }
00055 
00056 //: If cache is out of date as compared to its source object, then clear the cache.
00057 
00058 void vtol_topology_cache::validate_cache()
00059 {
00060   //timestamp here is a static number maintained
00061   //by our process, owned by vul_timestamp,
00062   //and incremented everytime you get_unique_timestamp
00063 
00064   // if this cache is younger than the source
00065   // then the cache does not need to be cleared
00066   if ( timestamp_ >= source_->get_time_stamp() )
00067     return;
00068   // this is out of date compared to the source
00069   // so clear the cache
00070   this->clear_cache();
00071 
00072   //now set the time stamp
00073   touch();
00074 }
00075 
00076 
00077 //: Get the vertex lists
00078 void vtol_topology_cache::vertices(vertex_list& verts)
00079 {
00080   this->validate_cache();
00081   if (!vertices_)
00082     vertices_ = source_->compute_vertices();
00083 
00084   // copy the lists
00085 
00086   verts.clear();
00087   for (vcl_vector<vtol_vertex*>::iterator it = vertices_->begin();
00088        it != vertices_->end(); ++it){
00089     verts.push_back(*it);
00090   }
00091 }
00092 
00093 //: Get the zero chain lists
00094 void vtol_topology_cache::zero_chains(zero_chain_list& zchains)
00095 {
00096   this->validate_cache();
00097   if (!zerochains_)
00098     zerochains_ = source_->compute_zero_chains();
00099 
00100     // copy the lists
00101 
00102   zchains.clear();
00103   for (vcl_vector<vtol_zero_chain*>::iterator it = zerochains_->begin();
00104        it != zerochains_->end(); ++it){
00105     zchains.push_back(*it);
00106   }
00107 }
00108 
00109 
00110 //: Get the edge lists
00111 void vtol_topology_cache::edges(edge_list& oedges)
00112 {
00113   this->validate_cache();
00114   if (!edges_)
00115     edges_ = source_->compute_edges();
00116     // copy the lists
00117 
00118   oedges.clear();
00119   for (vcl_vector<vtol_edge*>::iterator it = edges_->begin();
00120        it != edges_->end(); ++it){
00121     oedges.push_back(*it);
00122   }
00123 }
00124 
00125 //: get the one chain lists
00126 void vtol_topology_cache::one_chains(one_chain_list& ochains)
00127 {
00128   this->validate_cache();
00129   if (!onechains_)
00130     onechains_ = source_->compute_one_chains();
00131 
00132   ochains.clear();
00133   for (vcl_vector<vtol_one_chain*>::iterator it = onechains_->begin();
00134        it != onechains_->end(); ++it){
00135     ochains.push_back(*it);
00136   }
00137 }
00138 
00139 //: get the face lists
00140 void vtol_topology_cache::faces(face_list& ofaces)
00141 {
00142   this->validate_cache();
00143   if (!faces_)
00144     faces_ = source_->compute_faces();
00145 
00146   ofaces.clear();
00147   for (vcl_vector<vtol_face*>::iterator it = faces_->begin();
00148        it != faces_->end(); ++it){
00149     ofaces.push_back(*it);
00150   }
00151 }
00152 
00153 
00154 //: get the two_chain lists
00155 void vtol_topology_cache::two_chains(two_chain_list& otwo_chains)
00156 {
00157   this->validate_cache();
00158   if (!twochains_)
00159     twochains_ = source_->compute_two_chains();
00160 
00161   otwo_chains.clear();
00162   for (vcl_vector<vtol_two_chain*>::iterator it = twochains_->begin();
00163        it != twochains_->end(); ++it){
00164     otwo_chains.push_back(*it);
00165   }
00166 }
00167 
00168 
00169 //: get the block lists
00170 void vtol_topology_cache::blocks(block_list& oblocks)
00171 {
00172   this->validate_cache();
00173   if (!blocks_)
00174     blocks_ = source_->compute_blocks();
00175 
00176   oblocks.clear();
00177   for (vcl_vector<vtol_block*>::iterator it = blocks_->begin();
00178        it != blocks_->end(); ++it){
00179     oblocks.push_back(*it);
00180   }
00181 }