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

bbox.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_BBOX_HH
00027 # define MLN_GEOM_BBOX_HH
00028 
00042 # include <mln/core/site_set/box.hh>
00043 # include <mln/core/concept/image.hh>
00044 # include <mln/core/concept/window.hh>
00045 # include <mln/core/concept/weighted_window.hh>
00046 # include <mln/literal/zero.hh>
00047 # include <mln/accu/shape/bbox.hh>
00048 
00049 
00050 namespace mln
00051 {
00052 
00053   namespace geom
00054   {
00055 
00057     template <typename S>
00058     box<mln_site(S)> bbox(const Site_Set<S>& pset);
00059 
00060 
00062     template <typename I>
00063     box<mln_site(I)> bbox(const Image<I>& ima);
00064 
00065 
00067     template <typename W>
00068     box<mln_psite(W)> bbox(const Window<W>& win);
00069 
00071     template <typename W>
00072     box<mln_psite(W)> bbox(const Weighted_Window<W>& win);
00073 
00074 
00075 
00076 # ifndef MLN_INCLUDE_ONLY
00077 
00078     namespace impl
00079     {
00080 
00081       template <typename S>
00082       box<mln_site(S)> bbox_(const trait::site_set::bbox::known&,
00083                              const S& pset)
00084       {
00085         return pset.bbox();
00086       }
00087 
00088       template <typename S>
00089       box<mln_site(S)> bbox_(trait::site_set::bbox::unknown,
00090                              const S& pset)
00091       {
00092         typedef mln_site(S) P;
00093         P pmin, pmax;
00094 
00095         // Init with first point.
00096         mln_piter(S) p(pset);
00097         p.start();
00098         mln_precondition(p.is_valid());
00099         pmin = pmax = p;
00100 
00101         // Update with remaining points.
00102         for_all_remaining(p)
00103           for (unsigned i = 0; i < P::dim; ++i)
00104             if (p[i] < pmin[i])
00105               pmin[i] = p[i];
00106             else
00107               if (p[i] > pmax[i])
00108                 pmax[i] = p[i];
00109 
00110         box<P> bb(pmin, pmax);
00111         return bb;
00112       }
00113 
00114     } // end of namespace mln::geom::impl
00115 
00116 
00117     // Facade.
00118 
00119     template <typename S>
00120     inline
00121     box<mln_site(S)> bbox(const Site_Set<S>& pset)
00122     {
00123       trace::entering("geom::bbox");
00124 //       mln_precondition(set::is_empty(pset) != 0);
00125 
00126       box<mln_site(S)> b = impl::bbox_(mln_trait_site_set_bbox(S)(),
00127                                        exact(pset));
00128 
00129       trace::exiting("geom::bbox");
00130       return b;
00131     }
00132 
00133     template <typename I>
00134     box<mln_site(I)> bbox(const Image<I>& ima_)
00135     {
00136       trace::entering("geom::bbox");
00137 
00138       const I& ima = exact(ima_);
00139       mln_precondition(ima.is_valid());
00140       box<mln_site(I)> b = geom::bbox(ima.domain());
00141 
00142       trace::exiting("geom::bbox");
00143       return b;
00144     }
00145 
00146     template <typename W>
00147     box<mln_psite(W)> bbox(const Window<W>& win)
00148     {
00149       trace::entering("geom::bbox");
00150 
00151       typedef mln_psite(W) P;
00152       accu::shape::bbox<P> b;
00153       P O = literal::origin;
00154       mln_qiter(W) q(exact(win), O);
00155       for_all(q)
00156         b.take(q);
00157 
00158       trace::exiting("geom::bbox");
00159       return b;
00160     }
00161 
00162     template <typename W>
00163     box<mln_psite(W)> bbox(const Weighted_Window<W>& win)
00164     {
00165       trace::entering("geom::bbox");
00166 
00167       box<mln_psite(W)> b = bbox(exact(win).win());
00168 
00169       trace::exiting("geom::bbox");
00170       return b;
00171     }
00172 
00173 
00174 # endif // ! MLN_INCLUDE_ONLY
00175 
00176   } // end of namespace mln::geom
00177 
00178 } // end of namespace mln
00179 
00180 
00181 #endif // ! MLN_GEOM_BBOX_HH

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