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

pmin_pmax.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_GEOM_PMIN_PMAX_HH
00027 # define MLN_GEOM_PMIN_PMAX_HH
00028 
00033 
00034 # include <utility>
00035 
00036 # include <mln/core/concept/site_set.hh>
00037 # include <mln/core/concept/box.hh>
00038 
00039 
00040 
00041 namespace mln
00042 {
00043 
00044   namespace geom
00045   {
00046 
00047 
00049     template <typename S>
00050     std::pair<mln_site(S), mln_site(S)>
00051     pmin_pmax(const Site_Set<S>& s);
00052 
00053 
00056     template <typename S>
00057     void
00058     pmin_pmax(const Site_Set<S>& s,  mln_site(S)& pmin, mln_site(S)& pmax);
00059 
00060 
00063     template <typename I>
00064     std::pair<mln_site(I), mln_site(I)>
00065     pmin_pmax(const Site_Iterator<I>& p);
00066 
00067 
00070     template <typename I>
00071     void
00072     pmin_pmax(const Site_Iterator<I>& p,  mln_site(I)& pmin, mln_site(I)& pmax);
00073 
00074 
00075 
00076 # ifndef MLN_INCLUDE_ONLY
00077 
00078 
00079     // Versions with point iterator. 
00080 
00081     template <typename I>
00082     inline
00083     void
00084     pmin_pmax(const Site_Iterator<I>& p_, mln_site(I)& pmin, mln_site(I)& pmax)
00085     {
00086       I p = exact(p_); // a copy of p_
00087 
00088       // init with first point
00089       p.start();
00090       mln_precondition(p.is_valid());
00091       pmin = pmax = p;
00092 
00093       // update with remaining points
00094       typedef mln_site(I) P;
00095       for_all_remaining(p)
00096         for (unsigned i = 0; i < P::dim; ++i)
00097           if (p[i] < pmin[i])
00098             pmin[i] = p[i];
00099           else if (p[i] > pmax[i])
00100             pmax[i] = p[i];
00101     }
00102 
00103     template <typename I>
00104     inline
00105     std::pair<mln_site(I), mln_site(I)>
00106     pmin_pmax(const Site_Iterator<I>& p)
00107     {
00108       typedef mln_site(I) P;
00109       std::pair<P, P> tmp;
00110       pmin_pmax(p, tmp.first, tmp.second); // Calls the previous version.
00111       return tmp;
00112     }
00113 
00114 
00115     // Versions with point set. 
00116 
00117     namespace impl
00118     {
00119 
00120       // General case.
00121 
00122       template <typename S>
00123       inline
00124       void
00125       pmin_pmax_(const Site_Set<S>& s, mln_site(S)& pmin, mln_site(S)& pmax)
00126       {
00127         mln_piter(S) it(exact(s));
00128         pmin_pmax(it, pmin, pmax);
00129       }
00130 
00131       // Box.
00132 
00133       template <typename B>
00134       inline
00135       void
00136       pmin_pmax_(const Box<B>& b, mln_site(B)& pmin, mln_site(B)& pmax)
00137       {
00138         pmin = exact(b).pmin();
00139         pmax = exact(b).pmax();
00140       }
00141 
00142     } // end of namespace mln::geom::impl
00143 
00144 
00145     template <typename S>
00146     inline
00147     void
00148     pmin_pmax(const Site_Set<S>& s, mln_site(S)& pmin, mln_site(S)& pmax)
00149     {
00150       mln_precondition(exact(s).nsites() != 0);
00151       impl::pmin_pmax_(exact(s), pmin, pmax);
00152     }
00153 
00154     template <typename S>
00155     inline
00156     std::pair<mln_site(S), mln_site(S)>
00157     pmin_pmax(const Site_Set<S>& s)
00158     {
00159       mln_precondition(exact(s).nsites() != 0);
00160       typedef mln_site(S) P;
00161       std::pair<P, P> tmp;
00162       pmin_pmax(s, tmp.first, tmp.second); // Calls the previous version.
00163       return tmp;
00164     }
00165 
00166 # endif // ! MLN_INCLUDE_ONLY
00167 
00168   } // end of namespace mln::geom
00169 
00170 } // end of namespace mln
00171 
00172 
00173 #endif // ! MLN_GEOM_PMIN_PMAX_HH

Generated on Tue Oct 4 2011 15:24:19 for Milena (Olena) by  doxygen 1.7.1