vil_pyramid_image_resource.h
Go to the documentation of this file.
1 // This is core/vil/vil_pyramid_image_resource.h
2 #ifndef vil_pyramid_image_resource_h_
3 #define vil_pyramid_image_resource_h_
4 //:
5 // \file
6 // \brief Representation of a pyramid resolution hierarchy
7 //
8 // \author J. L. Mundy
9 // \date 19 March 2006
10 
11 #include <vector>
12 #ifdef _MSC_VER
13 # include <vcl_msvc_warnings.h>
14 #endif
16 #include <vil/vil_smart_ptr.h>
17 #include <vil/vil_image_resource.h>
20 
21 //: Representation of a pyramid resolution hierarchy; mostly pure virtual methods
22 //
23 // The pyramid consists of a set of scaled (lower resolution) copies of the base
24 // image. A typical case is where the copies are each a factor of two smaller
25 // than the next lower image in the pyramid. However, there is no intrinsic
26 // assumption about the scale difference between copies at different levels.
27 //
28 // All image positions and sizes are expressed in the coordinate system of
29 // the base image. The transformation from base image coordinates to one
30 // of the copy images is given by: ic = ib*scale, jc = jb*scale. Thus the
31 // base image is considered to have scale = 1.0.
32 // The copies all have scale<1.0.
33 
35 {
36  public:
37  vil_pyramid_image_resource(std::vector<vil_image_resource_sptr> const& images);
38  ~vil_pyramid_image_resource() override;
39 
40  //: The number of planes (or components) in the image.
41  // Dimensions: Planes x ni x nj.
42  // This method refers to the base (max resolution) image
43  // This concept is treated as a synonym to components.
44  unsigned nplanes() const override = 0;
45 
46  //: The number of pixels in each row.
47  // Dimensions: Planes x ni x nj.
48  // This method refers to the base (max resolution) image
49  unsigned ni() const override = 0;
50 
51  //: The number of pixels in each column.
52  // Dimensions: Planes x ni x nj.
53  // This method refers to the base (max resolution) image
54  unsigned nj() const override = 0;
55 
56  //: Pixel Format.
57  enum vil_pixel_format pixel_format() const override = 0;
58 
59  //: Create a read/write view of a copy of this data.
60  // Applies only to the base image
62  unsigned n_i,
63  unsigned j0,
64  unsigned n_j) const override
65  {return this->get_copy_view(i0, n_i, j0, n_j, 0);}
66 
67  //: Put the data in this view back into the base image.
68  // Pyramid is readonly.
69  // This is essentially (although not formally) a pure virtual function.
70  bool put_view(vil_image_view_base const& /*im*/, unsigned /*i0*/, unsigned /*j0*/) override
71  { return false; }
72 
73  //: Return a string describing the file format.
74  // Only file images have a format, others return 0
75  char const* file_format() const override = 0;
76 
77  //: Extra property information
78  bool get_property(char const* tag, void* property_value = nullptr) const override;
79 
80  // === Methods particular to pyramid resource ===
81 
82  //: Number of pyramid levels
83  virtual unsigned nlevels() const = 0;
84 
85  //: Get a partial view from the image from a specified pyramid level
86  virtual vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned n_i,
87  unsigned j0, unsigned n_j,
88  unsigned level) const = 0;
89 
90  //: Get a complete view from a specified pyramid level.
91  // This method needs no specialisation.
92  virtual vil_image_view_base_sptr get_copy_view(unsigned level) const
93  { return get_copy_view(0, ni(), 0, nj(), level); }
94 
95  //: Get a partial view from the image in the pyramid closest to scale.
96  // The origin and size parameters are in the coordinate system of the base image.
97  // The scale factor is with respect to the base image (base scale = 1.0).
98  virtual vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned n_i,
99  unsigned j0, unsigned n_j,
100  const float scale,
101  float& actual_scale) const = 0;
102 
103  //: Get a complete view from the image in the pyramid closest to the specified scale.
104  // The scale factor is with respect to the base image (base scale = 1.0).
105  // This method needs no specialisation.
106  virtual vil_image_view_base_sptr get_copy_view(const float scale, float& actual_scale) const
107  { return get_copy_view(0, ni(), 0, nj(), scale, actual_scale); }
108 
109  //: Copy a resource into the pyramid, level is determined by resource scale
110  virtual bool put_resource(vil_image_resource_sptr const& resc) = 0;
111 
112  //: Get an image resource from the pyramid at the specified level
113  virtual vil_image_resource_sptr get_resource(const unsigned level) const = 0;
114 
115  //: A utility function to decimate a resource using blocks.
116  // The new scale is one half the input resource scale
117  static bool
120 
121  //: Utility for decimating a resource to create a new pyramid level.
122  // The new scale is one half the input resource scale. Creates a
123  // new resource from filename according to file format
125  char const* filename,
126  char const* format="tiff");
127 
128  //: for debug purposes
129  virtual void print(const unsigned level) = 0;
130 
131  protected:
132  //smart pointer
134  // no default constructor
136 };
137 
139 
140 #endif // vil_pyramid_image_resource_h_
An abstract base class of smart pointers to actual image data in memory.
vil_pixel_format
Describes the type of the concrete data.
unsigned nj() const override=0
The number of pixels in each column.
virtual void print(const unsigned level)=0
for debug purposes.
A base class reference-counting view of some image data.
static vil_image_resource_sptr decimate(vil_image_resource_sptr const &resc, char const *filename, char const *format="tiff")
Utility for decimating a resource to create a new pyramid level.
Representation of a pyramid resolution hierarchy; mostly pure virtual methods.
Smart pointer to an image resource.
virtual vil_image_view_base_sptr get_copy_view(unsigned level) const
Get a complete view from a specified pyramid level.
enum vil_pixel_format pixel_format() const override=0
Pixel Format.
~vil_pyramid_image_resource() override
unsigned ni() const override=0
The number of pixels in each row.
unsigned nplanes() const override=0
The number of planes (or components) in the image.
vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned n_i, unsigned j0, unsigned n_j) const override
Create a read/write view of a copy of this data.
Abstract representation of an image source or image destination.
virtual vil_image_view_base_sptr get_copy_view(const float scale, float &actual_scale) const
Get a complete view from the image in the pyramid closest to the specified scale.
vil_image_view_base_sptr get_copy_view() const
Create a read/write view of a copy of all the data.
virtual bool put_resource(vil_image_resource_sptr const &resc)=0
Copy a resource into the pyramid, level is determined by resource scale.
Smart pointer to an image resource.
Contains a templated smart pointer class.
Representation of a generic image source or destination.
virtual unsigned nlevels() const =0
Number of pyramid levels.
static bool blocked_decimate(vil_blocked_image_resource_sptr const &brsc, vil_blocked_image_resource_sptr &dec_resc)
A utility function to decimate a resource using blocks.
bool get_property(char const *tag, void *property_value=nullptr) const override
Extra property information.
Smart pointer to an image resource.
virtual vil_image_resource_sptr get_resource(const unsigned level) const =0
Get an image resource from the pyramid at the specified level.
char const * file_format() const override=0
Return a string describing the file format.
bool put_view(vil_image_view_base const &, unsigned, unsigned) override
Put the data in this view back into the base image.