00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef OLENA_CORE_IMPL_IMAGE_ARRAY1D_HH
00029 # define OLENA_CORE_IMPL_IMAGE_ARRAY1D_HH
00030
00031 # include <oln/core/impl/image_array.hh>
00032 # include <oln/core/image1d_size.hh>
00033 # include <oln/core/point1d.hh>
00034
00035 namespace oln {
00036
00037
00039
00040 template<class T>
00041 void
00042 pretreat_1d_data_(T*& buffer, T*& buffer_, const image1d_size& s)
00043 {
00044 precondition(s.ncols() > 0 && s.border() >= 0);
00045 buffer_ = buffer + s.border();
00046 }
00047
00048
00049 namespace impl {
00050 template<class T>
00051 class image_array1d;
00052 }
00053
00060 template<class T>
00061 struct impl_traits<impl::image_array1d<T> >: public impl_traits<impl::image_array<T, impl::image_array1d<T> > >
00062 {
00063 enum { dim = 1 };
00064 typedef point1d point_type;
00065 typedef image1d_size size_type;
00066 typedef T value_type;
00067 };
00068
00069 namespace impl {
00070
00071
00077 template<class T>
00078 class image_array1d :
00079 public image_array<T, image_array1d<T> >
00080 {
00081
00082 public:
00083
00084 typedef image_array1d<T> self_type;
00085 typedef image_array1d<T> exact_type;
00086
00087 typedef typename impl_traits<exact_type>::point_type point_type;
00088 typedef typename impl_traits<exact_type>::value_type value_type;
00089 typedef typename impl_traits<exact_type>::size_type size_type;
00090
00091 typedef image_array<T, image_array1d<T> > super_type;
00092
00093
00094 friend class image_impl<image_array1d<T> >;
00095 friend class image_array<T, image_array1d<T> >;
00096
00097 image_array1d(const size_type& s): super_type(s)
00098 {
00099 pretreat_1d_data_(this->buffer_, buffer__, s);
00100 }
00101
00102 image_array1d() {}
00103
00104 ~image_array1d() {}
00105
00106 protected:
00107
00109
00110 bool
00111 hold_(const point_type& p) const
00112 {
00113 return
00114 p.col() >= 0 &&
00115 p.col() < this->size_.ncols();
00116 }
00117
00119
00120 bool
00121 hold_large_(const point_type& p) const
00122 {
00123 return
00124 p.col() >= - this->size_.border() &&
00125 p.col() < this->size_.ncols() + this->size_.border();
00126 }
00127
00128
00130 value_type&
00131 at_(const point_type& p)
00132 {
00133 return at_(p.col());
00134 }
00135
00137 value_type&
00138 at_(coord col)
00139 {
00140 invariant(this->buffer_ != 0);
00141 precondition_hold_large(point_type(col));
00142 return buffer__[col];
00143 }
00144
00145
00147 size_t
00148 len_(const size_type& s) const
00149 {
00150 coord ncols_eff = s.ncols() + 2 * s.border();
00151 return size_t(ncols_eff);
00152 }
00153
00154
00155
00159 void
00160 border_reallocate_and_copy_(coord new_border, bool copy_border)
00161 {
00162 T* buffer = 0;
00163
00164 allocate_data_(buffer, len_(size_type(this->size_.ncols(), new_border)));
00165
00166 coord border = this->size_.border();
00167 if (border > new_border)
00168 border = new_border;
00169 coord src_min_col = copy_border ? -border : 0;
00170 coord src_ncols = this->size_.ncols() + (copy_border ? (border * 2) : 0);
00171 memcpy(buffer + new_border, &at_(src_min_col),
00172 src_ncols * sizeof(T));
00173
00174
00175 this->size_.border() = new_border;
00176 pretreat_1d_data_(buffer, buffer__,
00177 size_type(this->size_.ncols(), new_border));
00178 desallocate_data_(this->buffer_);
00179 this->buffer_ = buffer;
00180
00181 }
00182
00188 void
00189 border_replicate_(void)
00190 {
00191 for (coord j = - this->size_.border(); j; ++j)
00192 {
00193 at_(j) = at_(0);
00194 at_(this->size_.ncols() - j - 1) = at_(this->size_.ncols() - 1);
00195 }
00196 }
00197
00202 void
00203 border_mirror_(void)
00204 {
00205 for (coord j = - this->size_.border(); j; ++j)
00206 {
00207 at_(j) = at_(-j);
00208 at_(this->size_.ncols() - j - 1) = at_(this->size_.ncols() + j - 1);
00209 }
00210 }
00211
00213
00214 void
00215 border_assign_(value_type val)
00216 {
00217 for (coord j = - this->size_.border(); j; ++j)
00218 {
00219 at_(j) = val;
00220 at_(this->size_.ncols() - j - 1) = val;
00221 }
00222 }
00223
00224 private:
00225
00226 T* buffer__;
00227
00228 };
00229
00230 }
00231
00232 }
00233
00234 #endif // ! OLENA_CORE_IMPL_IMAGE_ARRAY1D_HH