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
00029 #ifndef OLENA_CORE_ABSTRACT_IMAGE_HH
00030 # define OLENA_CORE_ABSTRACT_IMAGE_HH
00031
00032 # include <mlc/type.hh>
00033 # include <mlc/contract.hh>
00034 # include <oln/core/coord.hh>
00035 # include <oln/core/abstract/point.hh>
00036 # include <oln/core/abstract/iter.hh>
00037
00041 namespace oln {
00042
00046 namespace abstract {
00047
00048
00049 template <class Exact>
00050 class image;
00051
00052 }
00053
00054 template<class Exact>
00055 struct image_id;
00056
00057 template<class Ima>
00058 struct image_traits;
00059
00066 template <class Exact>
00067 struct image_traits<abstract::image<Exact> >
00068 {
00069 typedef Exact exact_type;
00070 };
00071
00072
00073
00074 namespace abstract {
00075
00082 template <class Exact>
00083 class image : public mlc_hierarchy::any_with_diamond<Exact>
00084 {
00085 public:
00086 typedef typename image_traits<Exact>::point_type point_type;
00092 typedef typename image_traits<Exact>::dpoint_type dpoint_type;
00098 typedef typename image_traits<Exact>::iter_type iter_type;
00104 typedef typename image_traits<Exact>::fwd_iter_type fwd_iter_type;
00106 typedef typename image_traits<Exact>::bkd_iter_type bkd_iter_type;
00108 typedef typename image_traits<Exact>::value_type value_type;
00112 typedef typename image_traits<Exact>::size_type size_type;
00117 typedef typename image_traits<Exact>::impl_type impl_type;
00119 typedef image<Exact> self_type;
00120 typedef Exact exact_type;
00121
00122 enum { dim = image_traits<Exact>::dim };
00123
00124
00129 const value_type
00130 operator[](const abstract::point<point_type>& p) const
00131 {
00132 return this->exact().at(p.exact());
00133 }
00134
00139 value_type&
00140 operator[](const abstract::point<point_type>& p)
00141 {
00142 return this->exact().at(p.exact());
00143 }
00144
00150 bool
00151 has_impl() const
00152 {
00153 return this->exact().impl() != 0;
00154 }
00155
00162 exact_type
00163 clone() const
00164 {
00165 return this->exact().clone_();
00166 }
00167
00173 bool
00174 hold(const abstract::point<point_type>& p) const
00175 {
00176 assertion(has_impl());
00177 return this->exact().impl()->hold(p.exact());
00178 }
00179
00181
00182 const size_type
00183 size() const
00184 {
00185 assertion(has_impl());
00186 return this->exact().size();
00187 }
00188
00190
00191 coord
00192 border() const
00193 {
00194 return size().border();
00195 }
00196
00202 size_t
00203 npoints() const
00204 {
00205 return this->exact().npoints_();
00206 }
00207
00215 exact_type&
00216 operator=(self_type rhs)
00217 {
00218 return this->exact().assign(rhs.exact());
00219 }
00220
00221 static std::string
00222 name()
00223 {
00224 return
00225 std::string("abstract::image<")
00226 + Exact::name() + ">";
00227 }
00228
00229
00230
00231
00246 void
00247 border_set_width(coord new_border, bool copy_border = false) const
00248 {
00249 precondition(new_border >= 0);
00250 precondition(has_impl());
00251 if (border() == new_border)
00252 return;
00253
00254 const_cast<impl_type *>(this->exact().impl())->border_reallocate_and_copy(new_border, copy_border);
00255 }
00256
00270 void
00271 border_adapt_width(coord min_border, bool copy_border =
00272 false) const
00273 {
00274 precondition(min_border >= 0);
00275 if (border() >= min_border)
00276 return;
00277
00278 this->exact().border_set_width(min_border, copy_border);
00279 }
00280
00289 void
00290 border_adapt_copy(coord min_border) const
00291 {
00292 border_adapt_width(min_border);
00293 const_cast<impl_type *>(this->exact().impl())->border_replicate();
00294 }
00295
00304 void
00305 border_adapt_mirror(coord min_border) const
00306 {
00307 border_adapt_width(min_border);
00308 const_cast<impl_type *>(this->exact().impl())->border_mirror();
00309 }
00310
00321 void
00322 border_adapt_assign(coord min_border, value_type val) const
00323 {
00324 border_adapt_width(min_border);
00325 const_cast<impl_type *>(this->exact().impl())->border_assign(val);
00326 }
00327
00328 protected:
00329
00330 image()
00331 {}
00332
00333 image(self_type& rhs)
00334 {};
00335 };
00336
00337 }
00338
00339 # define oln_value_type(ImgType) \
00340 mlc_exact_type(ImgType)::value_type
00341 # define oln_value_type_(ImgType) \
00342 mlc_exact_type_(ImgType)::value_type
00343
00344 # define oln_concrete_type(ImgType) \
00345 typename oln::mute<ImgType >::ret
00346
00347 # define oln_exact_type(ImgType) \
00348 mlc_exact_type(ImgType)
00349 # define oln_exact_type_(ImgType) \
00350 mlc_exact_type_(ImgType)
00351
00352 # define oln_iter_type(Iterable) \
00353 mlc_exact_type(Iterable)::iter_type
00354 # define oln_iter_type_(Iterable) \
00355 mlc_exact_type_(Iterable)::iter_type
00356
00357 # define oln_fwd_iter_type(Fwd_Iterable) \
00358 mlc_exact_type(Fwd_Iterable)::fwd_iter_type
00359 # define oln_fwd_iter_type_(Fwd_Iterable) \
00360 mlc_exact_type_(Fwd_Iterable)::fwd_iter_type
00361
00362 # define oln_bkd_iter_type(Bkd_Iterable) \
00363 mlc_exact_type(Bkd_Iterable)::bkd_iter_type
00364 # define oln_bkd_iter_type_(Bkd_Iterable) \
00365 mlc_exact_type_(Bkd_Iterable)::bkd_iter_type
00366
00367 # define oln_size_type(ImgType) \
00368 mlc_exact_type(ImgType)::size_type
00369 # define oln_size_type_(ImgType) \
00370 mlc_exact_type_(ImgType)::size_type
00371
00372 # define oln_impl_type(ImgType) \
00373 mlc_exact_type(ImgType)::impl_type
00374 # define oln_impl_type_(ImgType) \
00375 mlc_exact_type_(ImgType)::impl_type
00376
00377 # define oln_point_type(Pointable) \
00378 mlc_exact_type(Pointable)::point_type
00379 # define oln_point_type_(Pointable) \
00380 mlc_exact_type_(Pointable)::point_type
00381
00382 # define oln_dpoint_type(DPointable) \
00383 mlc_exact_type(DPointable)::dpoint_type
00384 # define oln_dpoint_type_(DPointable) \
00385 mlc_exact_type_(DPointable)::dpoint_type
00386
00387 }
00388
00389 #endif // ! OLENA_CORE_ABSTRACT_IMAGE_HH