00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00097 mln_piter(S) p(pset);
00098 p.start();
00099 mln_precondition(p.is_valid());
00100 pmin = pmax = p;
00101
00102
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 }
00116
00117
00118
00119
00120 template <typename S>
00121 inline
00122 box<mln_site(S)> bbox(const Site_Set<S>& pset)
00123 {
00124
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 }
00167
00168 }
00169
00170
00171 #endif // ! MLN_GEOM_BBOX_HH