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_WINDOW_HH
00028 # define MLN_CORE_WINDOW_HH
00029
00044 # include <mln/core/internal/window_base.hh>
00045 # include <mln/core/concept/gdpoint.hh>
00046
00047 # include <mln/metal/is_a.hh>
00048 # include <mln/util/set.hh>
00049 # include <mln/fun/i2v/all_to.hh>
00050 # include <mln/norm/linfty.hh>
00051 # include <mln/literal/zero.hh>
00052
00053
00054 namespace mln
00055 {
00056
00057
00058 template <typename D> class window;
00059 template <typename V> class dpsites_fwd_piter;
00060 template <typename V> class dpsites_bkd_piter;
00061
00062
00063
00064 namespace trait
00065 {
00066
00067 template <typename D>
00068 struct window_< mln::window<D> >
00069 {
00070 typedef trait::window::size::fixed size;
00071 typedef trait::window::support::regular support;
00072 typedef trait::window::definition::unique definition;
00073 };
00074
00075 }
00076
00077
00078
00084 template <typename D>
00085 class window : public internal::window_base< D, window<D> >
00086 {
00087 public:
00088
00090 typedef window<D> regular;
00091
00092
00097 window();
00098
00103 bool is_centered() const;
00104
00110 bool is_symmetric() const;
00111
00113 void sym();
00114
00115
00119 typedef dpsites_fwd_piter< window<D> > fwd_qiter;
00120
00124 typedef dpsites_bkd_piter< window<D> > bkd_qiter;
00125
00129 typedef fwd_qiter qiter;
00130
00131
00133 unsigned size() const;
00134
00137 bool is_empty() const;
00138
00140 void clear();
00141
00145 unsigned delta() const;
00146
00148 const D& dp(unsigned i) const;
00149
00151 bool has(const D& dp) const;
00152
00154 window<D>& insert(const D& dp);
00155
00157 template <typename W>
00158 window<D>& insert(const Window<W>& win);
00159
00162 window<D>& insert(const mln_coord(D)& dind);
00163
00164 window<D>& insert(const mln_coord(D)& drow,
00165 const mln_coord(D)& dcol);
00166
00167 window<D>& insert(const mln_coord(D)& dsli,
00168 const mln_coord(D)& drow,
00169 const mln_coord(D)& dcol);
00171
00172
00174 const std::vector<D>& std_vector() const;
00175
00177 const mln::util::set<D>& dps_hook_() const;
00178
00180 void print(std::ostream& ostr) const;
00181
00182 private:
00183
00184 util::set<D> dps_;
00185
00186 unsigned delta_(int i) const;
00187 unsigned delta_(const Gdpoint<D>& dp) const;
00188 };
00189
00190
00191
00196 template <typename D>
00197 bool operator==(const window<D>& lhs, const window<D>& rhs);
00198
00199
00200
00201 # ifndef MLN_INCLUDE_ONLY
00202
00203
00204
00205 template <typename D>
00206 inline
00207 window<D>::window()
00208 {
00209
00210
00211 }
00212
00213 template <typename D>
00214 inline
00215 bool
00216 window<D>::is_symmetric() const
00217 {
00218 window<D> cpy = *this;
00219 cpy.sym();
00220 return cpy == *this;
00221 }
00222
00223 template <typename D>
00224 inline
00225 bool
00226 window<D>::is_centered() const
00227 {
00228 return this->dps_.has(literal::zero);
00229 }
00230
00231 template <typename D>
00232 inline
00233 void
00234 window<D>::sym()
00235 {
00236 window<D> tmp;
00237 const unsigned n = size();
00238 for (unsigned i = 0; i < n; ++i)
00239 tmp.insert(- this->dp(i));
00240 *this = tmp;
00241 }
00242
00243 template <typename D>
00244 inline
00245 bool
00246 window<D>::is_empty() const
00247 {
00248 return dps_.is_empty();
00249 }
00250
00251 template <typename D>
00252 inline
00253 void
00254 window<D>::clear()
00255 {
00256 dps_.clear();
00257 }
00258
00259 template <typename D>
00260 inline
00261 unsigned
00262 window<D>::delta() const
00263 {
00264 unsigned d = 0;
00265 const unsigned n = size();
00266 for (unsigned i = 0; i < n; ++i)
00267 {
00268 unsigned dd = delta_(dp(i));
00269 if (dd > d)
00270 d = dd;
00271 }
00272 return d;
00273 }
00274
00275 template <typename D>
00276 inline
00277 unsigned
00278 window<D>::delta_(int i) const
00279 {
00280 return i;
00281 }
00282
00283 template <typename D>
00284 inline
00285 unsigned
00286 window<D>::delta_(const Gdpoint<D>& dp) const
00287 {
00288 return norm::linfty(exact(dp).to_vec());
00289 }
00290
00291 template <typename D>
00292 inline
00293 unsigned
00294 window<D>::size() const
00295 {
00296 return dps_.nelements();
00297 }
00298
00299 template <typename D>
00300 inline
00301 const D&
00302 window<D>::dp(unsigned i) const
00303 {
00304 mln_precondition(i < size());
00305 return dps_[i];
00306 }
00307
00308 template <typename D>
00309 inline
00310 bool
00311 window<D>::has(const D& dp) const
00312 {
00313 return dps_.has(dp);
00314 }
00315
00316 template <typename D>
00317 inline
00318 const std::vector<D>&
00319 window<D>::std_vector() const
00320 {
00321 return dps_.std_vector();
00322 }
00323
00324 template <typename D>
00325 inline
00326 window<D>&
00327 window<D>::insert(const D& dp)
00328 {
00329 dps_.insert(dp);
00330 return *this;
00331 }
00332
00333 template <typename D>
00334 template <typename W>
00335 inline
00336 window<D>&
00337 window<D>::insert(const Window<W>& win_)
00338 {
00339 const W& win = exact(win_);
00340 const unsigned n = win.size();
00341 for (unsigned i = 0; i < n; ++i)
00342 dps_.insert(win.dp(i));
00343 return *this;
00344 }
00345
00346 template <typename D>
00347 inline
00348 window<D>&
00349 window<D>::insert(const mln_coord(D)& dind)
00350 {
00351 mlc_bool(D::dim == 1)::check();
00352 D dp(dind);
00353 return insert(dp);
00354 }
00355
00356 template <typename D>
00357 inline
00358 window<D>&
00359 window<D>::insert(const mln_coord(D)& drow,
00360 const mln_coord(D)& dcol)
00361 {
00362 mlc_bool(D::dim == 2)::check();
00363 D dp(drow, dcol);
00364 return insert(dp);
00365 }
00366
00367 template <typename D>
00368 inline
00369 window<D>&
00370 window<D>::insert(const mln_coord(D)& dsli,
00371 const mln_coord(D)& drow,
00372 const mln_coord(D)& dcol)
00373 {
00374 mlc_bool(D::dim == 3)::check();
00375 D dp(dsli, drow, dcol);
00376 return insert(dp);
00377 }
00378
00379 template <typename D>
00380 inline
00381 const util::set<D>&
00382 window<D>::dps_hook_() const
00383 {
00384 return dps_;
00385 }
00386
00387 template <typename D>
00388 inline
00389 void
00390 window<D>::print(std::ostream& ostr) const
00391 {
00392 ostr << dps_;
00393 }
00394
00395
00396
00397
00398 template <typename D>
00399 bool
00400 operator==(const window<D>& lhs, const window<D>& rhs)
00401 {
00402 return lhs.dps_hook_() == rhs.dps_hook_();
00403 }
00404
00405 # endif // ! MLN_INCLUDE_ONLY
00406
00407 }
00408
00409
00410 # include <mln/core/dpsites_piter.hh>
00411
00412
00413 #endif // ! MLN_CORE_WINDOW_HH