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