core/vil/vil_cached_image_resource.cxx
Go to the documentation of this file.
00001 // This is core/vil/vil_cached_image_resource.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 
00006 #include "vil_cached_image_resource.h"
00007 #include <vil/vil_image_view_base.h>
00008 
00009 // Get a view that is the size of a block.
00010 // Uses the cache to retrieve frequently used blocks
00011 vil_image_view_base_sptr 
00012 vil_cached_image_resource::get_block( unsigned  block_index_i,
00013                                       unsigned  block_index_j ) const
00014 {
00015   // check if the block is already in the buffer
00016    vil_image_view_base_sptr blk;
00017   if (cache_.get_block(block_index_i, block_index_j, blk))
00018     return blk;
00019   // no - so get the block from the resource
00020   blk = bir_->get_block(block_index_i, block_index_j);
00021   if (!blk)
00022     return blk; // get block failed
00023   // put the block in the cache (cast away const since we are just caching)
00024   vil_cached_image_resource* non_const = (vil_cached_image_resource*)this;
00025   non_const->cache_.add_block(block_index_i, block_index_j, blk);
00026   return blk;
00027 }
00028