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