Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development 00002 // Laboratory (LRDE) 00003 // 00004 // This file is part of Olena. 00005 // 00006 // Olena is free software: you can redistribute it and/or modify it under 00007 // the terms of the GNU General Public License as published by the Free 00008 // Software Foundation, version 2 of the License. 00009 // 00010 // Olena is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software project without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to produce 00022 // an executable, this file does not by itself cause the resulting 00023 // executable to be covered by the GNU General Public License. This 00024 // exception does not however invalidate any other reasons why the 00025 // executable file might be covered by the GNU General Public License. 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 // Forward declarations. 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 } // end of namespace mln::trait 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); // For 1D or index access. 00163 00164 window<D>& insert(const mln_coord(D)& drow, 00165 const mln_coord(D)& dcol); // For 2D. 00166 00167 window<D>& insert(const mln_coord(D)& dsli, 00168 const mln_coord(D)& drow, 00169 const mln_coord(D)& dcol); // For 3D. 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; // For indices. 00187 unsigned delta_(const Gdpoint<D>& dp) const; // For grids delta-points. 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 // window<D> 00204 00205 template <typename D> 00206 inline 00207 window<D>::window() 00208 { 00209 // FIXME HERE: Was: mln::metal::is_a<D, Dpoint>::check(); 00210 // mln::metal::is_a<D, Delta_Point_Site>::check(); 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 // Operators. 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 } // end of namespace mln 00408 00409 00410 # include <mln/core/dpsites_piter.hh> 00411 00412 00413 #endif // ! MLN_CORE_WINDOW_HH