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