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
00008
00009
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
00017
00018 class vil_pyramid_image_list_format : public vil_file_format
00019 {
00020 public:
00021 ~vil_pyramid_image_list_format(){}
00022
00023
00024
00025 virtual char const* tag() const {return "pyil";}
00026
00027
00028 virtual vil_image_resource_sptr make_input_image(vil_stream* vs)
00029 { return 0; }
00030
00031
00032 virtual vil_pyramid_image_resource_sptr
00033 make_input_pyramid_image(char const* directory);
00034
00035
00036
00037
00038
00039
00040
00041
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
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
00068 float scale_;
00069
00070
00071 vil_image_resource_sptr image_;
00072
00073
00074 unsigned cur_level_;
00075
00076
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
00092
00093
00094
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
00103
00104
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
00113
00114
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
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
00134
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
00147
00148 virtual char const* file_format() const { return "pryl"; }
00149
00150
00151
00152
00153 virtual unsigned nlevels() const {return levels_.size();}
00154
00155
00156
00157 bool put_resource(vil_image_resource_sptr const& image);
00158
00159
00160
00161 bool add_resource(vil_image_resource_sptr const& image);
00162
00163
00164 vil_image_resource_sptr get_resource(const unsigned level) const
00165 {return get_level(level);}
00166
00167
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
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
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
00181
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
00190 void print(const unsigned level)
00191 { if (level<levels_.size()) levels_[level]->print(level); }
00192
00193 protected:
00194
00195 vil_pyramid_image_list();
00196
00197
00198
00199
00200 void normalize_scales();
00201
00202
00203 pyramid_level* closest(const float scale) const;
00204
00205
00206 bool is_same_size(vil_image_resource_sptr const& image);
00207
00208
00209 float find_next_level(vil_image_resource_sptr const& image);
00210
00211
00212
00213 vcl_string directory_;
00214
00215
00216 vcl_vector<pyramid_level*> levels_;
00217 };
00218
00219 #endif // vil_pyramid_image_list_h_