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
00030 #ifndef OLENA_MORPHER_GENERIC_MORPHER_HH
00031 # define OLENA_MORPHER_GENERIC_MORPHER_HH
00032
00033 # include <string>
00034
00035 # include <oln/basics1d.hh>
00036 # include <oln/basics2d.hh>
00037 # include <oln/basics3d.hh>
00038
00039
00040 namespace oln {
00041
00043
00044 namespace morpher {
00045
00047
00048 namespace abstract {
00049
00050 template <class SrcType, class Exact>
00051 class generic_morpher;
00052
00053 }
00054 }
00055
00056 template <class Exact, class SrcType>
00057 struct image_traits<morpher::abstract::generic_morpher<SrcType, Exact> >:
00058 public image_traits<abstract::image_with_impl<typename image_id<Exact>::impl_type,
00059 typename image_id<Exact>::exact_type> >
00060 {
00061
00062 };
00063
00064 namespace morpher {
00065
00066 namespace abstract {
00067
00068 template <unsigned Dim, class T>
00069 struct dest_type;
00070
00071 template <class T>
00072 struct dest_type<1, T>
00073 {
00074 typedef image1d<T> ret;
00075 };
00076
00077
00078 template <class T>
00079 struct dest_type<2, T>
00080 {
00081 typedef image2d<T> ret;
00082 };
00083
00084
00085 template <class T>
00086 struct dest_type<3, T>
00087 {
00088 typedef image3d<T> ret;
00089 };
00090
00091
00092
00093
00106 template <class SrcType, class Exact>
00107 class generic_morpher :
00108 public oln::abstract::image_with_impl<typename image_id<Exact>::impl_type,
00109 Exact>
00110 {
00111 protected:
00112
00116 generic_morpher(const SrcType &Ima) : super_type(), ima_(Ima) {}
00117
00119 generic_morpher(): ima_(SrcType()) {}
00120
00122 const SrcType &ima_;
00123
00124 public:
00125
00127 typedef generic_morpher<SrcType, Exact> self_type;
00128
00130 typedef Exact exact_type;
00132 typedef typename image_traits<exact_type>::point_type point_type;
00134 typedef typename image_traits<exact_type>::dpoint_type dpoint_type;
00136 typedef typename image_traits<exact_type>::iter_type iter_type;
00138 typedef typename image_traits<exact_type>::fwd_iter_type fwd_iter_type;
00140 typedef typename image_traits<exact_type>::bkd_iter_type bkd_iter_type;
00142 typedef typename image_traits<exact_type>::value_type value_type;
00144 typedef typename image_traits<exact_type>::size_type size_type;
00146 typedef typename image_traits<exact_type>::impl_type impl_type;
00147
00148 typedef typename dest_type<image_traits<exact_type>::dim, value_type>::ret DestType;
00149
00151 typedef SrcType src_self_type;
00153 typedef oln_point_type(SrcType) src_point_type;
00155 typedef oln_dpoint_type(SrcType) src_dpoint_type;
00157 typedef oln_iter_type(SrcType) src_iter_type;
00159 typedef oln_fwd_iter_type(SrcType) src_fwd_iter_type;
00161 typedef oln_bkd_iter_type(SrcType) src_bkd_iter_type;
00163 typedef oln_value_type(SrcType) src_value_type;
00165 typedef oln_size_type(SrcType) src_size_type;
00167 typedef oln_impl_type(SrcType) src_impl_type;
00168
00170 typedef oln_exact_type(SrcType) src_exact_type;
00171
00173 typedef oln::abstract::image_with_impl<impl_type,
00174 exact_type>
00175 super_type;
00176
00177
00179 const SrcType&
00180 get_ima() const
00181 {
00182 return ima_;
00183 }
00184
00186 DestType
00187 unmorph() const
00188 {
00189 DestType res(to_exact(*this).size());
00190 oln_iter_type(DestType) it(res);
00191
00192 for_all(it)
00193 res[it] = (*this)[it];
00194 return res;
00195 }
00196
00197
00205 const src_value_type
00206 at(const src_point_type& p) const
00207 {
00208 return ima_[p];
00209 }
00210
00218 src_value_type&
00219 at(const src_point_type& p)
00220 {
00221 return ima_[p];
00222 }
00223
00225 const src_impl_type*
00226 impl() const
00227 {
00228 return ima_.impl();
00229 }
00230
00232 src_impl_type*
00233 impl()
00234 {
00235 return ima_.impl();
00236 }
00237
00242 src_exact_type
00243 clone_() const
00244 {
00245 return to_exact(ima_).clone();
00246 }
00247
00252 size_t
00253 npoints_()
00254 {
00255 return to_exact(ima_).npoints();
00256 }
00257
00262 src_exact_type&
00263 assign(src_exact_type& rhs)
00264 {
00265 return to_exact(ima_).assign(rhs);
00266 }
00267
00273 void
00274 border_set_width(oln::coord min_border,
00275 bool copy_border = false) const
00276 {
00277 return to_exact(ima_).border_set_width(min_border, copy_border);
00278 }
00279
00284 self_type&
00285 operator=(self_type& rhs)
00286 {
00287 return to_exact(*this).assign(rhs.exact());
00288 }
00289
00290 static std::string
00291 name()
00292 {
00293 return "generic_morpher<" + super_type::name() + ">";
00294 }
00295
00296 };
00297
00298 }
00299
00300 }
00301
00302 }
00303
00304
00305 #endif // !OLENA_MORPHER_GENERIC_MORPHER_HH