core/vil/vil_pyramid_image_resource.h
Go to the documentation of this file.
00001 // This is core/vil/vil_pyramid_image_resource.h
00002 #ifndef vil_pyramid_image_resource_h_
00003 #define vil_pyramid_image_resource_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Representation of a pyramid resolution hierarchy
00010 //
00011 // \author J. L. Mundy
00012 // \date 19 March 2006
00013 
00014 #include <vcl_vector.h>
00015 #include <vil/vil_image_view_base.h>
00016 #include <vil/vil_smart_ptr.h>
00017 #include <vil/vil_image_resource.h>
00018 #include <vil/vil_image_resource_sptr.h>
00019 #include <vil/vil_blocked_image_resource_sptr.h>
00020 
00021 //: Representation of a pyramid resolution hierarchy; mostly pure virtual methods
00022 //
00023 // The pyramid consists of a set of scaled (lower resolution) copies of the base
00024 // image.  A typical case is where the copies are each a factor of two smaller
00025 // than the next lower image in the pyramid. However, there is no intrinsic
00026 // assumption about the scale difference between copies at different levels.
00027 //
00028 // All image positions and sizes are expressed in the coordinate system of
00029 // the base image. The transformation from base image coordinates to one
00030 // of the copy images is given by:  ic = ib*scale, jc = jb*scale. Thus the
00031 // base image is considered to have scale = 1.0.
00032 // The copies all have scale<1.0.
00033 
00034 class vil_pyramid_image_resource : public vil_image_resource
00035 {
00036  public:
00037   vil_pyramid_image_resource(vcl_vector<vil_image_resource_sptr> const& images);
00038   virtual ~vil_pyramid_image_resource();
00039 
00040   //: The number of planes (or components) in the image.
00041   // Dimensions:  Planes x ni x nj.
00042   // This method refers to the base (max resolution) image
00043   // This concept is treated as a synonym to components.
00044   virtual unsigned nplanes() const = 0;
00045 
00046   //: The number of pixels in each row.
00047   // Dimensions:  Planes x ni x nj.
00048   // This method refers to the base (max resolution) image
00049   virtual unsigned ni() const = 0;
00050 
00051   //: The number of pixels in each column.
00052   // Dimensions:  Planes x ni x nj.
00053   // This method refers to the base (max resolution) image
00054   virtual unsigned nj() const = 0;
00055 
00056   //: Pixel Format.
00057   virtual enum vil_pixel_format pixel_format() const = 0;
00058 
00059   //: Create a read/write view of a copy of this data.
00060   // Applies only to the base image
00061   virtual vil_image_view_base_sptr get_copy_view(unsigned i0,
00062                                                  unsigned n_i,
00063                                                  unsigned j0,
00064                                                  unsigned n_j) const
00065     {return this->get_copy_view(i0, n_i, j0, n_j, 0);}
00066 
00067   //: Put the data in this view back into the base image.
00068   // Pyramid is readonly.
00069   // This is essentially (although not formally) a pure virtual function.
00070   virtual bool put_view(vil_image_view_base const& /*im*/, unsigned /*i0*/, unsigned /*j0*/)
00071   { return false; }
00072 
00073   //: Return a string describing the file format.
00074   // Only file images have a format, others return 0
00075   virtual char const* file_format() const = 0;
00076 
00077   //: Extra property information
00078   virtual bool get_property(char const* tag, void* property_value = 0) const;
00079 
00080   // === Methods particular to pyramid resource ===
00081 
00082   //: Number of pyramid levels
00083   virtual unsigned nlevels() const = 0;
00084 
00085   //: Get a partial view from the image from a specified pyramid level
00086   virtual vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned n_i,
00087                                                  unsigned j0, unsigned n_j,
00088                                                  unsigned level) const = 0;
00089 
00090   //: Get a complete view from a specified pyramid level.
00091   // This method needs no specialisation.
00092   virtual vil_image_view_base_sptr get_copy_view(unsigned level) const
00093   { return get_copy_view(0, ni(), 0, nj(), level); }
00094 
00095   //: Get a partial view from the image in the pyramid closest to scale.
00096   // The origin and size parameters are in the coordinate system of the base image.
00097   // The scale factor is with respect to the base image (base scale = 1.0).
00098   virtual vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned n_i,
00099                                                  unsigned j0, unsigned n_j,
00100                                                  const float scale,
00101                                                  float& actual_scale) const = 0;
00102 
00103   //: Get a complete view from the image in the pyramid closest to the specified scale.
00104   // The scale factor is with respect to the base image (base scale = 1.0).
00105   // This method needs no specialisation.
00106   virtual vil_image_view_base_sptr get_copy_view(const float scale, float& actual_scale) const
00107   { return get_copy_view(0, ni(), 0, nj(), scale, actual_scale); }
00108 
00109   //: Copy a resource into the pyramid, level is determined by resource scale
00110   virtual bool put_resource(vil_image_resource_sptr const& resc) = 0;
00111 
00112   //: Get an image resource from the pyramid at the specified level
00113   virtual vil_image_resource_sptr get_resource(const unsigned level) const = 0;
00114 
00115   //: A utility function to decimate a resource using blocks.
00116   // The new scale is one half the input resource scale
00117   static bool
00118     blocked_decimate(vil_blocked_image_resource_sptr const & brsc,
00119                      vil_blocked_image_resource_sptr& dec_resc);
00120 
00121   //: Utility for decimating a resource to create a new pyramid level.
00122   // The new scale is one half the input resource scale. Creates a
00123   // new resource from filename according to file format
00124   static vil_image_resource_sptr decimate(vil_image_resource_sptr const& resc,
00125                                           char const* filename,
00126                                           char const* format="tiff");
00127 
00128   //: for debug purposes
00129   virtual void print(const unsigned level) = 0;
00130 
00131  protected:
00132   //smart pointer
00133   friend class vil_smart_ptr<vil_pyramid_image_resource>;
00134   // no default constructor
00135   vil_pyramid_image_resource();
00136 };
00137 
00138 #include <vil/vil_pyramid_image_resource_sptr.h>
00139 
00140 #endif // vil_pyramid_image_resource_h_