• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

window.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_CORE_WINDOW_HH
00027 # define MLN_CORE_WINDOW_HH
00028 
00043 # include <mln/core/internal/window_base.hh>
00044 # include <mln/core/concept/gdpoint.hh>
00045 
00046 # include <mln/metal/is_a.hh>
00047 # include <mln/util/set.hh>
00048 # include <mln/fun/i2v/all_to.hh>
00049 # include <mln/norm/linfty.hh>
00050 # include <mln/literal/zero.hh>
00051 
00052 
00053 namespace mln
00054 {
00055 
00056   // Forward declarations.
00057   template <typename D> class window;
00058   template <typename V> class dpsites_fwd_piter;
00059   template <typename V> class dpsites_bkd_piter;
00060 
00061 
00062 
00063   namespace trait
00064   {
00065 
00066     template <typename D>
00067     struct window_< mln::window<D> >
00068     {
00069       typedef trait::window::size::fixed        size;
00070       typedef trait::window::support::regular   support;
00071       typedef trait::window::definition::unique definition;
00072     };
00073 
00074   } // end of namespace mln::trait
00075 
00076 
00077 
00083   template <typename D>
00084   class window : public internal::window_base< D, window<D> >
00085   {
00086   public:
00087 
00089     typedef window<D> regular;
00090 
00091 
00096     window();
00097 
00102     bool is_centered() const;
00103 
00109     bool is_symmetric() const;
00110 
00112     void sym();
00113 
00114 
00118     typedef dpsites_fwd_piter< window<D> > fwd_qiter;
00119 
00123     typedef dpsites_bkd_piter< window<D> > bkd_qiter;
00124 
00128     typedef fwd_qiter qiter;
00129 
00130 
00132     unsigned size() const;
00133 
00136     bool is_empty() const;
00137 
00139     void clear();
00140 
00144     unsigned delta() const;
00145 
00147     const D& dp(unsigned i) const;
00148 
00150     bool has(const D& dp) const;
00151 
00153     window<D>& insert(const D& dp);
00154 
00156     template <typename W>
00157     window<D>& insert(const Window<W>& win);
00158 
00161     window<D>& insert(const mln_coord(D)& dind); // For 1D or index access.
00162 
00163     window<D>& insert(const mln_coord(D)& drow,
00164                       const mln_coord(D)& dcol); // For 2D.
00165 
00166     window<D>& insert(const mln_coord(D)& dsli,
00167                       const mln_coord(D)& drow,
00168                       const mln_coord(D)& dcol); // For 3D.
00170 
00171 
00173     const std::vector<D>& std_vector() const;
00174 
00176     const mln::util::set<D>& dps_hook_() const;
00177 
00179     void print(std::ostream& ostr) const;
00180 
00181   private:
00182 
00183     util::set<D> dps_;
00184 
00185     unsigned delta_(int i) const;                // For indices.
00186     unsigned delta_(const Gdpoint<D>& dp) const; // For grids delta-points.
00187   };
00188 
00189 
00190 
00195   template <typename D>
00196   bool operator==(const window<D>& lhs, const window<D>& rhs);
00197 
00198 
00199 
00200 # ifndef MLN_INCLUDE_ONLY
00201 
00202   // window<D>
00203 
00204   template <typename D>
00205   inline
00206   window<D>::window()
00207   {
00208     // FIXME HERE: Was: mln::metal::is_a<D, Dpoint>::check();
00209     // mln::metal::is_a<D, Delta_Point_Site>::check();
00210   }
00211 
00212   template <typename D>
00213   inline
00214   bool
00215   window<D>::is_symmetric() const
00216   {
00217     window<D> cpy = *this;
00218     cpy.sym();
00219     return cpy == *this;
00220   }
00221 
00222   template <typename D>
00223   inline
00224   bool
00225   window<D>::is_centered() const
00226   {
00227     return this->dps_.has(literal::zero);
00228   }
00229 
00230   template <typename D>
00231   inline
00232   void
00233   window<D>::sym()
00234   {
00235     window<D> tmp;
00236     const unsigned n = size();
00237     for (unsigned i = 0; i < n; ++i)
00238       tmp.insert(- this->dp(i));
00239     *this = tmp;
00240   }
00241 
00242   template <typename D>
00243   inline
00244   bool
00245   window<D>::is_empty() const
00246   {
00247     return dps_.is_empty();
00248   }
00249 
00250   template <typename D>
00251   inline
00252   void
00253   window<D>::clear()
00254   {
00255     dps_.clear();
00256   }
00257 
00258   template <typename D>
00259   inline
00260   unsigned
00261   window<D>::delta() const
00262   {
00263     unsigned d = 0;
00264     const unsigned n = size();
00265     for (unsigned i = 0; i < n; ++i)
00266       {
00267         unsigned dd = delta_(dp(i));
00268         if (dd > d)
00269           d = dd;
00270       }
00271     return d;
00272   }
00273 
00274   template <typename D>
00275   inline
00276   unsigned
00277   window<D>::delta_(int i) const
00278   {
00279     return i;
00280   }
00281 
00282   template <typename D>
00283   inline
00284   unsigned
00285   window<D>::delta_(const Gdpoint<D>& dp) const
00286   {
00287     return norm::linfty(exact(dp).to_vec());
00288   }
00289 
00290   template <typename D>
00291   inline
00292   unsigned
00293   window<D>::size() const
00294   {
00295     return dps_.nelements();
00296   }
00297 
00298   template <typename D>
00299   inline
00300   const D&
00301   window<D>::dp(unsigned i) const
00302   {
00303     mln_precondition(i < size());
00304     return dps_[i];
00305   }
00306 
00307   template <typename D>
00308   inline
00309   bool
00310   window<D>::has(const D& dp) const
00311   {
00312     return dps_.has(dp);
00313   }
00314 
00315   template <typename D>
00316   inline
00317   const std::vector<D>&
00318   window<D>::std_vector() const
00319   {
00320     return dps_.std_vector();
00321   }
00322 
00323   template <typename D>
00324   inline
00325   window<D>&
00326   window<D>::insert(const D& dp)
00327   {
00328     dps_.insert(dp);
00329     return *this;
00330   }
00331 
00332   template <typename D>
00333   template <typename W>
00334   inline
00335   window<D>&
00336   window<D>::insert(const Window<W>& win_)
00337   {
00338     const W& win = exact(win_);
00339     const unsigned n = win.size();
00340     for (unsigned i = 0; i < n; ++i)
00341       dps_.insert(win.dp(i));
00342     return *this;
00343   }
00344 
00345   template <typename D>
00346   inline
00347   window<D>&
00348   window<D>::insert(const mln_coord(D)& dind)
00349   {
00350     mlc_bool(D::dim == 1)::check();
00351     D dp(dind);
00352     return insert(dp);
00353   }
00354 
00355   template <typename D>
00356   inline
00357   window<D>&
00358   window<D>::insert(const mln_coord(D)& drow,
00359                     const mln_coord(D)& dcol)
00360   {
00361     mlc_bool(D::dim == 2)::check();
00362     D dp(drow, dcol);
00363     return insert(dp);
00364   }
00365 
00366   template <typename D>
00367   inline
00368   window<D>&
00369   window<D>::insert(const mln_coord(D)& dsli,
00370                     const mln_coord(D)& drow,
00371                     const mln_coord(D)& dcol)
00372   {
00373     mlc_bool(D::dim == 3)::check();
00374     D dp(dsli, drow, dcol);
00375     return insert(dp);
00376   }
00377 
00378   template <typename D>
00379   inline
00380   const util::set<D>&
00381   window<D>::dps_hook_() const
00382   {
00383     return dps_;
00384   }
00385 
00386   template <typename D>
00387   inline
00388   void
00389   window<D>::print(std::ostream& ostr) const
00390   {
00391     ostr << dps_;
00392   }
00393 
00394 
00395   // Operators.
00396 
00397   template <typename D>
00398   bool
00399   operator==(const window<D>& lhs, const window<D>& rhs)
00400   {
00401     return lhs.dps_hook_() == rhs.dps_hook_();
00402   }
00403 
00404 # endif // ! MLN_INCLUDE_ONLY
00405 
00406 } // end of namespace mln
00407 
00408 
00409 # include <mln/core/dpsites_piter.hh>
00410 
00411 
00412 #endif // ! MLN_CORE_WINDOW_HH

Generated on Thu Sep 8 2011 18:33:04 for Milena (Olena) by  doxygen 1.7.1