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 struct bcell
00019 {
00020 bcell(const unsigned bindex_i, const unsigned bindex_j,
00021 vil_image_view_base_sptr const& blk) :
00022 bindex_i_(bindex_i), bindex_j_(bindex_j), birthdate_(time_++), blk_(blk)
00023 {}
00024
00025
00026 unsigned bindex_i_; unsigned bindex_j_;
00027
00028 unsigned long birthdate_;
00029
00030 vil_image_view_base_sptr blk_;
00031
00032 void touch(){birthdate_=time_++;}
00033
00034 void print() const { vcl_cout << '[' << bindex_i_ << ' ' << bindex_j_
00035 << "](" << birthdate_ << ")\n"; }
00036 private:
00037 static unsigned long time_;
00038 };
00039
00040 class vil_block_cache
00041 {
00042 public:
00043 vil_block_cache(const unsigned block_capacity):nblocks_(block_capacity){}
00044 ~vil_block_cache();
00045
00046
00047 bool add_block(const unsigned& block_index_i, const unsigned& block_index_j,
00048 vil_image_view_base_sptr const& blk);
00049
00050
00051 bool get_block(const unsigned& block_index_i, const unsigned& block_index_j,
00052 vil_image_view_base_sptr& blk) const;
00053
00054
00055 unsigned block_size() const{return nblocks_;}
00056 private:
00057 struct compare
00058 {
00059 bool operator()(bcell* const& c1, bcell* const& c2) const
00060 { if (c1&&c2)return c1->birthdate_ > c2->birthdate_; else return false; }
00061 };
00062
00063 vcl_priority_queue<compare, vcl_vector<bcell*> > queue_;
00064
00065 vcl_vector<bcell*> blocks_;
00066
00067 unsigned nblocks_;
00068
00069 bool remove_block();
00070 };
00071
00072 #endif // vil_block_cache_h_