Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vil_pyramid_image_list.h

Go to the documentation of this file.
00001 #ifndef vil_pyramid_image_list_h_
00002 #define vil_pyramid_image_list_h_
00003 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00004 #pragma interface
00005 #endif
00006 //:
00007 // \file
00008 // \brief A pyramid image resource based on multiple file-based image resources
00009 // \author J.L. Mundy March 20, 2006
00010 
00011 #include <vcl_string.h>
00012 #include <vcl_iostream.h>
00013 #include <vil/vil_file_format.h>
00014 #include <vil/vil_pyramid_image_resource.h>
00015 
00016 //The pyramid resource is made up of a set of image resources in
00017 // a single directory - the image list.
00018 class vil_pyramid_image_list_format : public vil_file_format
00019 {
00020  public:
00021   ~vil_pyramid_image_list_format(){}
00022 
00023   //: Return a character string which uniquely identifies this format.
00024   //E.g. "pnm", "jpeg", etc.
00025   virtual char const* tag() const {return "pyil";}//pyramid image list
00026 
00027   //: should return 0 so that no attempt is made to create a single image resource
00028   virtual vil_image_resource_sptr make_input_image(vil_stream* vs)
00029   { return 0; }
00030 
00031   //: Read a pyramid resource. Image list files are stored in directory.
00032   virtual vil_pyramid_image_resource_sptr
00033   make_input_pyramid_image(char const* directory);
00034 
00035 
00036   //: Construct a pyramid image resource from a base image
00037   //  Each level has the same scale ratio (0.5) to the preceeding level.
00038   //  Level 0 is the original base image. If copy base is false then
00039   //  Level 0 is already present in the directory and is used without
00040   //  modification. Each pyramid file in the directory is named
00041   //  filename + "level_index", e.g. R0, R1, ... Rn.
00042   virtual vil_pyramid_image_resource_sptr
00043   make_pyramid_image_from_base(char const* directory,
00044                                vil_image_resource_sptr const& base_image,
00045                                unsigned nlevels,
00046                                bool copy_base,
00047                                char const* level_file_format,
00048                                char const* filename
00049                               );
00050 
00051   //: A non-pyramid output image doesn't make sense here
00052   virtual vil_image_resource_sptr make_output_image(vil_stream* vs,
00053                                                     unsigned ni,
00054                                                     unsigned nj,
00055                                                     unsigned nplanes,
00056                                                     enum vil_pixel_format)
00057   { return 0; }
00058 
00059   virtual vil_pyramid_image_resource_sptr
00060     make_pyramid_output_image(char const* directory);
00061 };
00062 
00063 struct pyramid_level
00064 {
00065   pyramid_level(vil_image_resource_sptr const& image)
00066   : scale_(1.0f), image_(image), cur_level_(0) {}
00067   //: scale associated with level
00068   float scale_;
00069 
00070   //:the resource
00071   vil_image_resource_sptr image_;
00072 
00073   //:the currel pyramid level for this resource
00074   unsigned cur_level_;
00075 
00076   //:print ni and scale and values
00077   void print(const unsigned l)
00078   {
00079     vcl_cout << "level[" << l <<  "]  scale: " << scale_
00080              << "  ni: " << image_->ni() << '\n';
00081   }
00082 };
00083 
00084 
00085 class vil_pyramid_image_list : public vil_pyramid_image_resource
00086 {
00087  public:
00088   vil_pyramid_image_list(char const* directory);
00089   vil_pyramid_image_list(vcl_vector<vil_image_resource_sptr> const& images);
00090   virtual ~vil_pyramid_image_list();
00091   //: The number of planes (or components) in the image.
00092   // This method refers to the base (max resolution) image
00093   // Dimensions:  Planes x ni x nj.
00094   // This concept is treated as a synonym to components.
00095   inline virtual unsigned nplanes() const
00096   {
00097     if (levels_.size()>0)
00098       return levels_[0]->image_->nplanes();
00099     else
00100       return 0;
00101   }
00102   //: The number of pixels in each row.
00103   // This method refers to the base (max resolution) image
00104   // Dimensions:  Planes x ni x nj.
00105   inline virtual unsigned ni() const
00106   {
00107     if (levels_.size()>0)
00108       return levels_[0]->image_->ni();
00109     else
00110       return 0;
00111   }
00112   //: The number of pixels in each column.
00113   // This method refers to the base (max resolution) image
00114   // Dimensions:  Planes x ni x nj.
00115   inline virtual unsigned nj() const
00116   {
00117     if (levels_.size()>0)
00118       return levels_[0]->image_->nj();
00119     else
00120       return 0;
00121   }
00122 
00123   //: Pixel Format.
00124 
00125   inline virtual enum vil_pixel_format pixel_format() const
00126   {
00127     if (levels_.size()>0)
00128       return levels_[0]->image_->pixel_format();
00129     else
00130       return VIL_PIXEL_FORMAT_UNKNOWN;
00131   }
00132 
00133   //: Create a read/write view of a copy of this data.
00134   // Applies only to the base image
00135   inline virtual vil_image_view_base_sptr get_copy_view(unsigned i0,
00136                                                         unsigned n_i,
00137                                                         unsigned j0,
00138                                                         unsigned n_j) const
00139   {
00140     if (levels_.size()>0)
00141       return levels_[0]->image_->get_copy_view(i0, n_i, j0, n_j);
00142     else
00143       return 0;
00144   }
00145 
00146   //: Return a string describing the file format.
00147   // Only file images have a format, others return 0
00148   virtual char const* file_format() const { return "pryl"; }
00149 
00150   //:Methods particular to pyramid resource
00151 
00152   //: number of levels in the pyramid
00153   virtual unsigned nlevels() const {return levels_.size();}
00154 
00155   //:Copy an image resource to the pyramid.
00156   // If an image of the same scale already exists, then method returns false.
00157   bool put_resource(vil_image_resource_sptr const& image);
00158 
00159   //:Add an image resource directly to the pyramid without copying.
00160   // If an image of the same scale already exists, then method returns false.
00161   bool add_resource(vil_image_resource_sptr const& image);
00162 
00163   //: vitural method for getting a level of the pyramid
00164   vil_image_resource_sptr get_resource(const unsigned level) const
00165     {return get_level(level);}
00166 
00167   //: Get a level image resource of the pyramid
00168   inline vil_image_resource_sptr get_level(const unsigned level) const
00169   { if (level<levels_.size()) return levels_[level]->image_; else return 0; }
00170 
00171   //:Get a partial view from the image from a specified pyramid level
00172   virtual vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned n_i,
00173                                                  unsigned j0, unsigned n_j,
00174                                                  unsigned level) const;
00175 
00176   //:Get a view from the image in the pyramid closest to scale
00177   vil_image_view_base_sptr get_copy_view(const float scale, float& actual_scale) const
00178   { return get_copy_view(0, ni(), 0, nj(), scale, actual_scale); }
00179 
00180   //:Get a partial view from the image in the pyramid closest to scale.
00181   // The origin and size parameters are in the coordinate system of the base image.
00182   vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned n_i,
00183                                          unsigned j0, unsigned n_j,
00184                                          const float scale,
00185                                          float& actual_scale) const;
00186 
00187   void set_directory(char const* directory) { directory_ = directory; }
00188 
00189   //for debugging purposes
00190   void print(const unsigned level)
00191   { if (level<levels_.size()) levels_[level]->print(level); }
00192 
00193  protected:
00194   // no default constructor;
00195   vil_pyramid_image_list();
00196 
00197   //    --- utility functions ---
00198 
00199   //:normalize the scale factors so that the base image scale = 1.0
00200   void normalize_scales();
00201 
00202   //:find the image resource with scale closest to specified scale
00203   pyramid_level* closest(const float scale) const;
00204 
00205   //:input image is the same size as one already in the pyramid
00206   bool is_same_size(vil_image_resource_sptr const& image);
00207 
00208   //:find the nearest level to the image size
00209   float find_next_level(vil_image_resource_sptr const& image);
00210 
00211   //    ---  members ---
00212 
00213   vcl_string directory_;
00214 
00215   //The set of images in the pyramid. levels_[0] is the base image
00216   vcl_vector<pyramid_level*> levels_;
00217 };
00218 
00219 #endif // vil_pyramid_image_list_h_

Generated on Thu Jan 10 14:40:00 2008 for core/vil by  doxygen 1.4.4