core/vil/vil_blocked_image_resource.h
Go to the documentation of this file.
00001 // This is core/vil/vil_blocked_image_resource.h
00002 #ifndef vil_blocked_image_resource_h_
00003 #define vil_blocked_image_resource_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief A blocked representation of the image_resource
00010 // \author J. L. Mundy
00011 #include <vcl_vector.h>
00012 #include <vil/vil_image_resource.h>
00013 #include <vil/vil_blocked_image_resource_sptr.h>
00014 
00015 //:cast to blocked resource if possible
00016 vil_blocked_image_resource_sptr 
00017 blocked_image_resource(const vil_image_resource_sptr& ir);
00018 
00019 class vil_blocked_image_resource : public vil_image_resource
00020 {
00021   
00022  public:
00023 
00024   vil_blocked_image_resource();
00025   virtual ~vil_blocked_image_resource();
00026 
00027   virtual unsigned nplanes() const =0;
00028   virtual unsigned ni() const = 0;
00029   virtual unsigned nj() const = 0;
00030   
00031   //: Block size in columns
00032   virtual unsigned size_block_i() const = 0;
00033 
00034   //: Block size in rows
00035   virtual unsigned size_block_j() const = 0;
00036 
00037   //: Number of blocks in image width
00038   virtual unsigned n_block_i() const;
00039 
00040   //: Number of blocks in image height
00041   virtual unsigned n_block_j() const;
00042   
00043 
00044   virtual enum vil_pixel_format pixel_format() const = 0;
00045 
00046   virtual vil_image_view_base_sptr 
00047     get_copy_view(unsigned i0, unsigned n_i, unsigned j0, unsigned n_j) const;
00048 
00049   virtual bool put_view(const vil_image_view_base& im, unsigned i0, unsigned j0) = 0;
00050 
00051   //: Block access
00052   virtual vil_image_view_base_sptr get_block( unsigned  block_index_i,
00053                                               unsigned  block_index_j ) const = 0;
00054 
00055 
00056   //: the multiple blocks are in col row order, i.e. blocks[i][j]
00057   virtual bool get_blocks( unsigned start_block_i, unsigned end_block_i,
00058                            unsigned  start_block_j, unsigned end_block_j,
00059                            vcl_vector< vcl_vector< vil_image_view_base_sptr > >& blocks ) const;
00060   
00061   //: put the block into the resource at the indicated location  
00062   virtual bool put_block(unsigned  block_index_i,
00063                          unsigned  block_index_j,
00064                          const vil_image_view_base& view) = 0;
00065 
00066 
00067   //: put multiple blocks in raster order, i.e.,  blocks[i][j]
00068   virtual bool put_blocks( unsigned start_block_i, unsigned end_block_i,
00069                            unsigned  start_block_j, unsigned end_block_j,
00070                            vcl_vector< vcl_vector< vil_image_view_base_sptr > > const& blocks );
00071 
00072   //: Extra property information
00073   virtual bool get_property(char const* tag, void* property_value = 0) const = 0;
00074 
00075  protected:
00076   //Internal functions
00077   vil_image_view_base_sptr fill_block(unsigned i0, unsigned icrop,
00078                                       unsigned j0, unsigned jcrop,
00079                                       vil_image_view_base_sptr& view) const;
00080     
00081   //: Get the offset from the start of the block row for pixel position i
00082   bool block_i_offset(unsigned block_i, unsigned i,
00083                       unsigned& i_offset) const;
00084 
00085   //: Get the offset from the start of the block column for pixel position j
00086   bool block_j_offset(unsigned block_j, unsigned j,
00087                       unsigned& j_offset) const;
00088   
00089   bool trim_border_blocks(unsigned i0, unsigned ni,
00090                           unsigned j0, unsigned nj,
00091                           unsigned start_block_i,
00092                           unsigned start_block_j,
00093                           vcl_vector< vcl_vector< vil_image_view_base_sptr > >& blocks) const;
00094 
00095   vil_image_view_base_sptr  
00096     glue_blocks_together(const vcl_vector< vcl_vector< vil_image_view_base_sptr > >& blocks) const;
00097 
00098  protected:
00099   friend class vil_smart_ptr<vil_blocked_image_resource>;
00100 };
00101 
00102 #endif // vil_blocked_image_resource_h_