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 #ifndef MLN_CORE_IMAGE_DMORPH_HEXA_HH
00028 # define MLN_CORE_IMAGE_DMORPH_HEXA_HH
00029
00030
00035
00036 # include <mln/core/internal/image_domain_morpher.hh>
00037 # include <mln/core/alias/point2d_h.hh>
00038 # include <mln/core/alias/box2d_h.hh>
00039 # include <mln/core/image/dmorph/hexa_piter.hh>
00040
00041
00042 namespace mln
00043 {
00044
00045
00046 template <typename I> struct hexa;
00047
00048
00049 namespace internal
00050 {
00052 template <typename I>
00053 struct data< hexa<I> >
00054 {
00055 data(I& ima, box2d_h b);
00056
00057 I ima_;
00058 mln::box2d_h b_;
00059 };
00060
00061 }
00062
00063
00064 namespace trait
00065 {
00067 template <typename I>
00068 struct image_< hexa<I> > : default_image_morpher< I, mln_value(I),
00069 hexa<I> >
00070 {
00071
00072
00073
00074
00075
00076 typedef trait::image::category::domain_morpher category;
00077
00078 typedef mln_trait_image_pw_io(I) pw_io;
00079 typedef mln_trait_image_dimension(I) dimension;
00080
00081
00082 typedef mln_trait_image_ext_domain(I) ext_domain;
00083 typedef mln_trait_image_ext_value(I) ext_value;
00084 typedef mln_trait_image_ext_io(I) ext_io;
00085
00086
00087
00088
00089 };
00090
00091 }
00092
00093
00116 template <typename I>
00117 struct hexa :
00118 public internal::image_domain_morpher< I, box2d_h, hexa<I> >
00119 {
00121 typedef hexa< tag::image_<I> > skeleton;
00122
00124 typedef mln_value(I) value;
00125
00127 typedef mln_lvalue(I) lvalue;
00128
00130 typedef mln_rvalue(I) rvalue;
00131
00133 typedef point2d_h psite;
00134
00137 typedef hexa_fwd_piter_<box2d> fwd_piter;
00138
00141 typedef hexa_bkd_piter_<box2d> bkd_piter;
00142
00143
00145 hexa();
00146
00148 hexa(I& ima);
00149
00151 void init_(I& ima);
00152
00154 const box2d_h& domain() const;
00155
00157 bool has(const psite& p) const;
00158
00160 rvalue operator()(const point2d_h& p) const;
00161
00163 lvalue operator()(const point2d_h& p);
00164 };
00165
00166 template <typename I, typename J>
00167 void init_(tag::image_t, hexa<I>& target, const J& model);
00168
00169 # ifndef MLN_INCLUDE_ONLY
00170
00171
00172
00173
00174 template <typename I, typename J>
00175 inline
00176 void init_(tag::image_t, hexa<I>& target, const J& model)
00177 {
00178 I ima;
00179 init_(tag::image, ima, model);
00180 target.init_(ima);
00181 }
00182
00183
00184
00185
00186
00187 namespace internal
00188 {
00189
00190 template <typename I>
00191 inline
00192 data< hexa<I> >::data(I& ima, box2d_h b)
00193 : ima_(ima),
00194 b_(b)
00195 {
00196 }
00197
00198 }
00199
00200
00201 template <typename I>
00202 inline
00203 void
00204 hexa<I>::init_(I& ima)
00205 {
00206 mln_precondition(! this->is_valid());
00207 box2d b_in = ima.bbox();
00208 box2d_h b = make::box2d_h(b_in.pmin()[0] * 2, b_in.pmin()[1],
00209 b_in.pmax()[0] * 2, (b_in.pmax()[1] + 1) * 2 - 1);
00210 this->data_ = new internal::data< hexa<I> >(ima, b);
00211 }
00212
00213
00214 template <typename I>
00215 inline
00216 hexa<I>::hexa()
00217 {
00218 }
00219
00220
00221 template <typename I>
00222 inline
00223 hexa<I>::hexa(I& ima)
00224 {
00225 this->init_(ima);
00226 }
00227
00228 template <typename I>
00229 inline
00230 typename hexa<I>::rvalue
00231 hexa<I>::operator()(const point2d_h& p) const
00232 {
00233 mln_precondition(this->is_valid());
00234 mln_precondition(this->has(p));
00235 return this->data_->ima_(point2d(p[0] / 2, p[1] / 2));
00236 }
00237
00238 template <typename I>
00239 inline
00240 typename hexa<I>::lvalue
00241 hexa<I>::operator()(const point2d_h& p)
00242 {
00243 mln_precondition(this->is_valid());
00244 mln_precondition(this->has(p));
00245 return this->data_->ima_(point2d(p[0] / 2, p[1] / 2));
00246 }
00247
00248 template <typename I>
00249 inline
00250 const box2d_h&
00251 hexa<I>::domain() const
00252 {
00253 mln_precondition(this->is_valid());
00254 return this->data_->b_;
00255 }
00256
00257 template <typename I>
00258 inline
00259 bool
00260 hexa<I>::has(const psite& p) const
00261 {
00262 mln_precondition(this->is_valid());
00263 return this->data_->ima_.has(point2d(p[0] / 2, p[1] / 2));
00264 }
00265
00266
00267 # endif // ! MLN_INCLUDE_ONLY
00268
00269 }
00270
00271
00272 #endif // ! MLN_CORE_IMAGE_DMORPH_HEXA_HH