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
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <vcl_string.h>
00017 #include <vcl_iostream.h>
00018 #include <vil/vil_file_format.h>
00019 #include <vil/vil_pyramid_image_resource.h>
00020
00021
00022
00023 class vil_pyramid_image_list_format : public vil_file_format
00024 {
00025 public:
00026 ~vil_pyramid_image_list_format(){}
00027
00028
00029
00030 virtual char const* tag() const {return "pyil";}
00031
00032
00033 virtual vil_image_resource_sptr make_input_image(vil_stream* )
00034 { return 0; }
00035
00036
00037 virtual vil_pyramid_image_resource_sptr
00038 make_input_pyramid_image(char const* directory);
00039
00040
00041
00042
00043
00044
00045
00046
00047 virtual vil_pyramid_image_resource_sptr
00048 make_pyramid_image_from_base(char const* directory,
00049 vil_image_resource_sptr const& base_image,
00050 unsigned int nlevels,
00051 bool copy_base,
00052 char const* level_file_format,
00053 char const* filename);
00054
00055
00056 virtual vil_image_resource_sptr make_output_image(vil_stream* ,
00057 unsigned int ,
00058 unsigned int ,
00059 unsigned int ,
00060 enum vil_pixel_format)
00061 { return 0; }
00062
00063 virtual vil_pyramid_image_resource_sptr
00064 make_pyramid_output_image(char const* directory);
00065 };
00066
00067 struct pyramid_level
00068 {
00069 pyramid_level(vil_image_resource_sptr const& image)
00070 : scale_(1.0f), image_(image), cur_level_(0) {}
00071
00072 float scale_;
00073
00074
00075 vil_image_resource_sptr image_;
00076
00077
00078 unsigned int cur_level_;
00079
00080
00081 void print(const unsigned int l)
00082 {
00083 vcl_cout << "level[" << l << "] scale: " << scale_
00084 << " ni: " << image_->ni() << '\n';
00085 }
00086 };
00087
00088
00089 class vil_pyramid_image_list : public vil_pyramid_image_resource
00090 {
00091 public:
00092 vil_pyramid_image_list(char const* directory);
00093 vil_pyramid_image_list(vcl_vector<vil_image_resource_sptr> const& images);
00094 virtual ~vil_pyramid_image_list();
00095
00096
00097
00098
00099 inline virtual unsigned int nplanes() const
00100 {
00101 if (levels_.size()>0)
00102 return levels_[0]->image_->nplanes();
00103 else
00104 return 0;
00105 }
00106
00107
00108
00109 inline virtual unsigned int ni() const
00110 {
00111 if (levels_.size()>0)
00112 return levels_[0]->image_->ni();
00113 else
00114 return 0;
00115 }
00116
00117
00118
00119 inline virtual unsigned int nj() const
00120 {
00121 if (levels_.size()>0)
00122 return levels_[0]->image_->nj();
00123 else
00124 return 0;
00125 }
00126
00127
00128
00129 inline virtual enum vil_pixel_format pixel_format() const
00130 {
00131 if (levels_.size()>0)
00132 return levels_[0]->image_->pixel_format();
00133 else
00134 return VIL_PIXEL_FORMAT_UNKNOWN;
00135 }
00136
00137
00138
00139 inline virtual vil_image_view_base_sptr get_copy_view(unsigned int i0,
00140 unsigned int n_i,
00141 unsigned int j0,
00142 unsigned int n_j) const
00143 {
00144 if (levels_.size()>0)
00145 return levels_[0]->image_->get_copy_view(i0, n_i, j0, n_j);
00146 else
00147 return 0;
00148 }
00149
00150
00151
00152 virtual char const* file_format() const { return "pryl"; }
00153
00154
00155
00156
00157 virtual unsigned int nlevels() const {return (unsigned int)(levels_.size());}
00158
00159
00160
00161 bool put_resource(vil_image_resource_sptr const& image);
00162
00163
00164
00165 bool add_resource(vil_image_resource_sptr const& image);
00166
00167
00168 vil_image_resource_sptr get_resource(const unsigned int level) const
00169 {return get_level(level);}
00170
00171
00172 inline vil_image_resource_sptr get_level(const unsigned int level) const
00173 { if (level<levels_.size()) return levels_[level]->image_; else return 0; }
00174
00175
00176 virtual vil_image_view_base_sptr get_copy_view(unsigned int i0, unsigned int n_i,
00177 unsigned int j0, unsigned int n_j,
00178 unsigned int level) const;
00179
00180
00181 vil_image_view_base_sptr get_copy_view(const float scale, float& actual_scale) const
00182 { return get_copy_view(0, ni(), 0, nj(), scale, actual_scale); }
00183
00184
00185
00186 vil_image_view_base_sptr get_copy_view(unsigned int i0, unsigned int n_i,
00187 unsigned int j0, unsigned int n_j,
00188 const float scale,
00189 float& actual_scale) const;
00190
00191 void set_directory(char const* directory) { directory_ = directory; }
00192
00193
00194 void print(const unsigned int level)
00195 { if (level<levels_.size()) levels_[level]->print(level); }
00196
00197 protected:
00198
00199 vil_pyramid_image_list();
00200
00201
00202
00203
00204 void normalize_scales();
00205
00206
00207 pyramid_level* closest(const float scale) const;
00208
00209
00210 bool is_same_size(vil_image_resource_sptr const& image);
00211
00212
00213 float find_next_level(vil_image_resource_sptr const& image);
00214
00215
00216
00217 vcl_string directory_;
00218
00219
00220 vcl_vector<pyramid_level*> levels_;
00221 };
00222
00223 #endif // vil_pyramid_image_list_h_