00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008 #include "vimt_image_pyramid.h"
00009
00010 #include <vcl_cassert.h>
00011 #include <vcl_iostream.h>
00012 #include <vimt/vimt_image.h>
00013
00014
00015
00016 vimt_image_pyramid::vimt_image_pyramid()
00017 : base_pixel_width_(1.0),scale_step_(2.0)
00018 {
00019 }
00020
00021
00022
00023 void vimt_image_pyramid::deleteImages()
00024 {
00025 for (unsigned int i=0;i<image_.size();++i)
00026 delete image_[i];
00027 image_.resize(0);
00028 }
00029
00030 vimt_image_pyramid::~vimt_image_pyramid()
00031 {
00032 deleteImages();
00033 }
00034
00035
00036
00037
00038
00039 const vimt_image_pyramid&
00040 vimt_image_pyramid::operator=(const vimt_image_pyramid& that)
00041 {
00042 if (&that == this) return *this;
00043
00044 base_pixel_width_ = that.base_pixel_width_;
00045 scale_step_ = that.scale_step_;
00046 image_.resize(that.image_.size(),0);
00047 for (unsigned int i=0;i<image_.size();++i)
00048 {
00049 delete image_[i];
00050 image_[i] = that.image_[i]->clone();
00051 }
00052
00053 return *this;
00054 }
00055
00056
00057 void vimt_image_pyramid::deep_copy(const vimt_image_pyramid& im_pyr)
00058 {
00059 if (&im_pyr==this) return;
00060
00061 base_pixel_width_ = im_pyr.base_pixel_width_;
00062 scale_step_ = im_pyr.scale_step_;
00063 image_.resize(im_pyr.image_.size(),0);
00064 for (unsigned int i=0;i<image_.size();++i)
00065 {
00066 delete image_[i];
00067 image_[i] = im_pyr.image_[i]->deep_clone();
00068 }
00069 }
00070
00071
00072
00073
00074 vimt_image_pyramid::vimt_image_pyramid(const vimt_image_pyramid &that)
00075 {
00076 this->operator=(that);
00077 }
00078
00079
00080 void vimt_image_pyramid::resize(int n_levels, const vimt_image& im_type)
00081 {
00082 if (int(image_.size())==n_levels && n_levels>0 && image_[0]->is_a()==im_type.is_a())
00083 return;
00084 deleteImages();
00085 image_.resize(n_levels,0);
00086 for (int i=0;i<n_levels;++i)
00087 image_[i]=im_type.clone();
00088 }
00089
00090
00091 int vimt_image_pyramid::lo() const
00092 {
00093 return 0;
00094 }
00095
00096
00097 int vimt_image_pyramid::hi() const
00098 {
00099 return ((int)image_.size())-1;
00100 }
00101
00102 int vimt_image_pyramid::n_levels() const
00103 {
00104 return image_.size();
00105 }
00106
00107
00108 vimt_image& vimt_image_pyramid::operator()(int L)
00109 {
00110 assert(L>=0 && (unsigned int)L<image_.size());
00111 return *image_[L];
00112 }
00113
00114
00115 const vimt_image& vimt_image_pyramid::operator()(int L) const
00116 {
00117 assert(L>=0 && (unsigned int)L<image_.size());
00118 return *image_[L];
00119 }
00120
00121
00122 double vimt_image_pyramid::base_pixel_width() const
00123 {
00124 return base_pixel_width_;
00125 }
00126
00127
00128
00129
00130 double vimt_image_pyramid::scale_step() const
00131 {
00132 return scale_step_;
00133 }
00134
00135
00136
00137 vcl_vector<vimt_image*>& vimt_image_pyramid::data()
00138 {
00139 return image_;
00140 }
00141
00142
00143 void vimt_image_pyramid::set_widths(double base_pixel_width,
00144 double scale_step)
00145 {
00146 base_pixel_width_ = base_pixel_width;
00147 scale_step_ = scale_step;
00148 }
00149
00150 void vimt_image_pyramid::print_summary(vcl_ostream& os) const
00151 {
00152 os<<"Levels: "<<image_.size()<<vcl_endl;
00153 for (unsigned int i=0;i<image_.size();++i)
00154 os<<"Image at level "<<i<<" : "<<image_[i]<<vcl_endl;
00155 }
00156
00157
00158 void vimt_image_pyramid::print_all(vcl_ostream& os) const
00159 {
00160 os<<"Levels: "<<image_.size()<<vcl_endl;
00161 for (unsigned int i=0;i<image_.size();++i)
00162 {
00163 os<<"Image at level "<<i<<" : ";
00164 image_[i]->print_all(os);
00165 os<<vcl_endl;
00166 }
00167 }
00168
00169 vcl_ostream& operator<<(vcl_ostream& os, const vimt_image_pyramid& im_pyr)
00170 {
00171 im_pyr.print_summary(os);
00172 return os;
00173 }
00174
00175 vcl_ostream& operator<<(vcl_ostream& os, const vimt_image_pyramid* im_pyr)
00176 {
00177 if (im_pyr)
00178 im_pyr->print_summary(os);
00179 else
00180 os<<"NULL";
00181 return os;
00182 }
00183
00184 void vsl_print_summary(vcl_ostream& os, const vimt_image_pyramid& im_pyr)
00185 {
00186 os << im_pyr;
00187 }
00188
00189 void vsl_print_summary(vcl_ostream& os, const vimt_image_pyramid* im_pyr)
00190 {
00191 os << im_pyr;
00192 }