Go to the documentation of this file.00001
00002 #ifndef vil_block_cache_h_
00003 #define vil_block_cache_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012 #include <vcl_iostream.h>
00013 #include <vcl_queue.h>
00014 #include <vcl_vector.h>
00015 #include <vil/vil_image_view_base.h>
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 struct bcell
00026 {
00027 bcell(const unsigned bindex_i, const unsigned bindex_j,
00028 vil_image_view_base_sptr const& blk) :
00029 bindex_i_(bindex_i), bindex_j_(bindex_j), birthdate_(time_++), blk_(blk)
00030 {}
00031
00032
00033 unsigned bindex_i_; unsigned bindex_j_;
00034
00035 unsigned long birthdate_;
00036
00037 vil_image_view_base_sptr blk_;
00038
00039 void touch(){birthdate_=time_++;}
00040
00041 void print() const { vcl_cout << '[' << bindex_i_ << ' ' << bindex_j_
00042 << "](" << birthdate_ << ")\n"; }
00043 private:
00044 static unsigned long time_;
00045 };
00046
00047
00048 class bcell_less
00049 {
00050 public:
00051 bcell_less(){}
00052
00053 bool operator()(bcell* const& ba, bcell* const& bb) const
00054 {
00055 return ba->birthdate_ < bb->birthdate_;
00056 }
00057 };
00058 class vil_block_cache
00059 {
00060 public:
00061 vil_block_cache(const unsigned block_capacity):nblocks_(block_capacity){}
00062 ~vil_block_cache();
00063
00064
00065 bool add_block(const unsigned& block_index_i, const unsigned& block_index_j,
00066 vil_image_view_base_sptr const& blk);
00067
00068
00069 bool get_block(const unsigned& block_index_i, const unsigned& block_index_j,
00070 vil_image_view_base_sptr& blk) const;
00071
00072
00073 unsigned block_size() const{return nblocks_;}
00074 private:
00075
00076 vcl_vector<bcell*> blocks_;
00077
00078 unsigned nblocks_;
00079
00080 bool remove_block();
00081 };
00082
00083 #endif // vil_block_cache_h_