
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add pset and pvec point sets. * tests/sort_points.cc: New. * tests/pset.cc: New. * tests/histo.cc: Update. * mln/histo/sort.hh: Rename as... * mln/level/sort_points.hh: ...this new file. (sort_points): New overload. * mln/histo/data.hh (vec): Rename as... (vect): ...this. * mln/core/dpoints_piter.hh: Update. * mln/core/pvec.hh: New. * mln/core/pset.hh: New. * mln/core/internal/set_of.hh: Update. * mln/accu/histo.hh: Update. * mln/accu/bbox.hh: New. mln/accu/bbox.hh | 134 ++++++++++++++++++ mln/accu/histo.hh | 4 mln/core/dpoints_piter.hh | 2 mln/core/internal/set_of.hh | 6 mln/core/pset.hh | 162 ++++++++++++++++++++++ mln/core/pvec.hh | 323 ++++++++++++++++++++++++++++++++++++++++++++ mln/histo/data.hh | 4 mln/level/sort_points.hh | 158 +++++++++++++++++++++ tests/histo.cc | 6 tests/pset.cc | 59 ++++++++ tests/sort_points.cc | 56 +++++++ 11 files changed, 901 insertions(+), 13 deletions(-) Index: tests/sort_points.cc --- tests/sort_points.cc (revision 0) +++ tests/sort_points.cc (revision 0) @@ -0,0 +1,56 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +/*! \file tests/histo.cc + * + * \brief Tests on mln::accu::histo<S> and mln::histo::data<S>. + */ + +#include <iterator> + +#include <mln/core/image2d_b.hh> +#include <mln/value/int_u8.hh> + +#include <mln/debug/iota.hh> +#include <mln/level/sort_points.hh> + + + +int main() +{ + using namespace mln; + using value::int_u8; + + image2d_b<int_u8> ima(3, 3); + debug::iota(ima); + std::vector<point2d> vec = level::sort_points(ima); + + std::copy(vec.begin(), vec.end(), + std::ostream_iterator<point2d>(std::cout, " ")); + std::cout << std::endl; + +} Index: tests/pset.cc --- tests/pset.cc (revision 0) +++ tests/pset.cc (revision 0) @@ -0,0 +1,59 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +/*! \file tests/pset.cc + * + * \brief Tests on mln::pset. + */ + +#include <iterator> + +#include <mln/core/point2d.hh> +#include <mln/core/pset.hh> + + + +int main() +{ + using namespace mln; + + pset<point2d> ps; + ps + .insert(make::point2d(6, 9)) + .insert(make::point2d(4, 2)) + .insert(make::point2d(4, 2)) + .insert(make::point2d(5, 1)); + mln_assertion(ps.npoints() = 3); + + std::cout << ps.bbox() << std::endl; + + std::copy(ps.vect().begin(), ps.vect().end(), + std::ostream_iterator<point2d>(std::cout, " ")); + std::cout << std::endl; + + +} Index: tests/histo.cc --- tests/histo.cc (revision 1037) +++ tests/histo.cc (working copy) @@ -38,7 +38,6 @@ #include <mln/debug/iota.hh> #include <mln/accu/histo.hh> #include <mln/histo/compute.hh> -#include <mln/histo/sort.hh> @@ -65,11 +64,6 @@ debug::iota(ima); histo::data< value::set<int_u8> > h = histo::compute(ima); std::cout << h << std::endl; - - std::vector<point2d> vec = histo::sort_points_decreasing(ima); - std::copy(vec.begin(), vec.end(), - std::ostream_iterator<point2d>(std::cout, " ")); - std::cout << std::endl; } } Index: mln/histo/data.hh --- mln/histo/data.hh (revision 1037) +++ mln/histo/data.hh (working copy) @@ -60,7 +60,7 @@ std::size_t operator()(const value& v) const; std::size_t& operator()(const value& v); - const std::vector<std::size_t>& vec() const; + const std::vector<std::size_t>& vect() const; const S& vset() const; std::size_t operator[](unsigned i) const; @@ -124,7 +124,7 @@ template <typename S> const std::vector<std::size_t>& - data<S>::vec() const + data<S>::vect() const { return h_; } Index: mln/core/dpoints_piter.hh --- mln/core/dpoints_piter.hh (revision 1037) +++ mln/core/dpoints_piter.hh (working copy) @@ -118,7 +118,7 @@ template <typename Dps, typename Pref> dpoints_fwd_piter<D>::dpoints_fwd_piter(const Dps& dps, const Generalized_Point<Pref>& p_ref) - : dps_(exact(dps).vec()), + : dps_(exact(dps).vect()), p_ref_(* internal::force_exact<Pref>(p_ref).pointer_()) { invalidate(); Index: mln/core/pvec.hh --- mln/core/pvec.hh (revision 0) +++ mln/core/pvec.hh (revision 0) @@ -0,0 +1,323 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_CORE_PVEC_HH +# define MLN_CORE_PVEC_HH + +/*! \file mln/core/pvec.hh + * + * \brief Definition of a point set class based on std::vector. + */ + +# include <vector> + +# include <mln/core/concept/point_set.hh> +# include <mln/core/internal/fixme.hh> +# include <mln/accu/bbox.hh> + + +namespace mln +{ + + // Fwd decls. + template <typename P> struct pvec_fwd_piter_; + template <typename P> struct pvec_bkd_piter_; + + + /*! \brief Point set class based on std::vector. + * + * This is a multi-set of points. + * + * \warning We have some troubles with point set comparison based on + * a call to npoints(). FIXME: Explain! + */ + template <typename P> + class pvec : public Point_Set< pvec<P> > + { + public: + + /// Point associated type. + typedef mln_point(P) point; + + /// Point_Site associated type. + typedef P psite; + + /// Forward Point_Iterator associated type. + typedef pvec_fwd_piter_<P> fwd_piter; + + /// Backward Point_Iterator associated type. + typedef internal::fixme bkd_piter; + + /// Constructor. + pvec(); + + /// Constructor from a vector \p vect. + pvec(const std::vector<P>& vect); + + /// Test is \p p belongs to this point set. + bool has(const P& p) const; + + /// Give the number of points. + std::size_t npoints() const; + + /// Give the exact bounding box. + const box_<point>& bbox() const; + + /// Append a point \p p. + pvec<P>& append(const P& p); + + /// Clear this set. + void clear(); + + /// Return the corresponding std::vector of points. + const std::vector<P>& vect() const; + + /// Return the \p i-th point. + const P& operator[](unsigned i) const; + + protected: + + std::vector<P> vect_; + mutable accu::bbox<P> bb_; + mutable bool bb_needs_update_; + + void update_bb_(); + // FIXME: Add invariant bb_.is_valid() <=> npoints() != 0 + }; + + + + /*! \brief Forward iterator on points of a pvec<P>. + * + */ + template <typename P> + struct pvec_fwd_piter_ + { + enum { dim = P::dim }; + + /// Point_Site associated type. + typedef P psite; + + /// Point associated type. + typedef mln_point(P) point; + + /// Dpoint associated type. + typedef mln_dpoint(P) dpoint; + + /// Coordinate associated type. + typedef mln_coord(P) coord; + + /// Coordinate associated type. + template <typename S> + pvec_fwd_piter_(const Point_Set<S>& s); + + /// Give a hook to the point address. + const point* pointer_() const; + + /// Read-only access to the \p i-th coordinate. + coord operator[](unsigned i) const; + + /// Test if the iterator is valid. + bool is_valid() const; + + /// Invalidate the iterator. + void invalidate(); + + /// Start an iteration. + void start(); + + /// Go to the next point. + void next_(); + + /// Convert the iterator into a point. + operator P() const; + + protected: + const std::vector<P>& vect_; + point p_; + }; + + + + +# ifndef MLN_INCLUDE_ONLY + + + // pvec<P> + + + template <typename P> + pvec<P>::pvec() + { + bb_needs_update_ = false; + } + + template <typename P> + pvec<P>::pvec(const std::vector<P>& vect) + : vect_(vect) + { + bb_needs_update_ = true; + } + + template <typename P> + void + pvec<P>::update_bb_() + { + bb_.clear(); + for (unsigned i = 0; i < vect_.size(); ++i) + bb_.take(vect_[i]); + bb_needs_update_ = false; + } + + template <typename P> + bool + pvec<P>::has(const P& p) const + { + for (unsigned i = 0; i < vect_.size(); ++i) + if (vect_[i] = p) + return true; + return false; + } + + template <typename P> + std::size_t + pvec<P>::npoints() const + { + return vect_.size(); + } + + template <typename P> + const box_<mln_point(P)>& + pvec<P>::bbox() const + { + mln_precondition(npoints() != 0); + if (bb_needs_update_) + update_bb_(); + return bb_.to_value(); + } + + template <typename P> + pvec<P>& + pvec<P>::append(const P& p) + { + vect_.push_back(p); + return *this; + } + + template <typename P> + void + pvec<P>::clear() + { + vect_.clear(); + bb_needs_update_ = false; + } + + template <typename P> + const std::vector<P>& + pvec<P>::vect() const + { + return vect_; + } + + template <typename P> + const P& + pvec<P>::operator[](unsigned i) const + { + mln_precondition(i < npoints()); + return vect_[i]; + } + + + + // pvec_fwd_piter_<P> + + + template <typename P> + template <typename S> + pvec_fwd_piter_<P>::pvec_fwd_piter_(const Point_Set<S>& s) + : vect_(exact(s).vect()) + { + invalidate(); + } + + template <typename P> + const mln_point(P)* + pvec_fwd_piter_<P>::pointer_() const + { + return & p_; + } + + template <typename P> + mln_coord(P) + pvec_fwd_piter_<P>::operator[](unsigned i) const + { + mln_precondition(i < dim); + mln_precondition(is_valid()); + return p_[i]; + } + + template <typename P> + bool + pvec_fwd_piter_<P>::is_valid() const + { + return i < vect_.size(); + } + + template <typename P> + void + pvec_fwd_piter_<P>::invalidate() + { + i = vect_.size(); + } + + template <typename P> + void + pvec_fwd_piter_<P>::start() + { + i = 0; + } + + template <typename P> + void + pvec_fwd_piter_<P>::next_() + { + ++i; + } + + template <typename P> + pvec_fwd_piter_<P>::operator P() const + { + mln_precondition(is_valid()); + return p_; + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_PVEC_HH Index: mln/core/pset.hh --- mln/core/pset.hh (revision 0) +++ mln/core/pset.hh (revision 0) @@ -0,0 +1,162 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_CORE_PSET_HH +# define MLN_CORE_PSET_HH + +/*! \file mln/core/pset.hh + * + * \brief Definition of a point set class based on std::set. + */ + +# include <mln/core/concept/point_set.hh> +# include <mln/core/internal/set_of.hh> +# include <mln/accu/bbox.hh> +# include <mln/core/pvec.hh> + + +namespace mln +{ + + /*! \brief Point set class based on std::set. + * + * This is a mathematical set of points (not a multi-set). The + * parameter \p P shall be a Point type. + * + * \todo Test if \p P being a Point_Site is ok. + */ + template <typename P> + class pset : public Point_Set< pset<P> >, + private internal::set_of_<P> + { + typedef internal::set_of_<P> super_; + + public: + + /// Point associated type. + typedef mln_point(P) point; + + /// Point_Site associated type. + typedef P psite; + + /// Forward Point_Iterator associated type. + typedef pvec_fwd_piter_<P> fwd_piter; + + /// Backward Point_Iterator associated type. + typedef internal::fixme bkd_piter; + + /// Constructor. + pset(); + + /// Test is \p p belongs to this point set. + bool has(const P& p) const; + + /// Return the corresponding std::vector of points. + using super_::vect; + + /// Give the number of points. + std::size_t npoints() const; + + /// Insert a point \p p. + pset<P>& insert(const P& p); + + /// Return the \p i-th point. + const P& operator[](unsigned i) const; + + /// Clear this set. + void clear(); + + /// Give the exact bounding box. + const box_<point>& bbox() const; + + protected: + + accu::bbox<P> bb_; + // FIXME: Add invariant bb_.is_valid() <=> npoints() != 0 + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename P> + pset<P>::pset() + { + } + + template <typename P> + bool + pset<P>::has(const P& p) const + { + return this->super_::has(p); + } + + template <typename P> + std::size_t + pset<P>::npoints() const + { + return this->super_::nelements(); + } + + template <typename P> + pset<P>& + pset<P>::insert(const P& p) + { + this->super_::insert(p); + bb_.take(p); + return *this; + } + + template <typename P> + const P& + pset<P>::operator[](unsigned i) const + { + mln_precondition(i < npoints()); + return this->super_::element(i); + } + + template <typename P> + void + pset<P>::clear() + { + this->super_::clear(); + bb_.init(); + } + + template <typename P> + const box_<mln_point(P)>& + pset<P>::bbox() const + { + mln_precondition(npoints() != 0); + return bb_.to_value(); + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_PSET_HH Index: mln/core/internal/set_of.hh --- mln/core/internal/set_of.hh (revision 1037) +++ mln/core/internal/set_of.hh (working copy) @@ -59,6 +59,8 @@ * * The parameter \c E is the element type, which shall not be * const-qualified. + * + * \todo Add a remove method. */ template <typename E> class set_of_ @@ -123,7 +125,7 @@ * * \return An array (std::vector) of elements. */ - const std::vector<E>& vec() const; + const std::vector<E>& vect() const; protected: @@ -245,7 +247,7 @@ template <typename E> const std::vector<E>& - set_of_<E>::vec() const + set_of_<E>::vect() const { if (needs_update_) update_(); Index: mln/core/concept/point_iterator.hh Index: mln/core/concept/point_site.hh Index: mln/level/sort_points.hh --- mln/level/sort_points.hh (revision 0) +++ mln/level/sort_points.hh (revision 0) @@ -0,0 +1,158 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_LEVEL_SORT_POINTS_HH +# define MLN_LEVEL_SORT_POINTS_HH + +/*! \file mln/level/sort_points.hh + * + * \brief Sort_Points the contents of an image into another one. + */ + +# include <vector> +# include <utility> +# include <algorithm> + +# include <mln/core/concept/image.hh> +# include <mln/histo/compute.hh> + + +namespace mln +{ + + namespace level + { + + /*! Sort points the image \p input through a function \p f to set + * the \p output image. + * + * \param[in] input The input image. + * + * \pre \p input.has_data + */ + template <typename I> + std::vector<mln_point(I)> sort_points(const Image<I>& input); + + +# ifndef MLN_INCLUDE_ONLY + + namespace impl + { + + template <typename I> + struct value_point_less_ + { + const I& ima_; + + value_point_less_(const I& ima) + : ima_(ima) + { + } + + bool operator()(const mln_point(I)& lhs, + const mln_point(I)& rhs) const + { + return ima_(lhs) < ima_(rhs) || (ima_(lhs) = ima_(rhs) + && lhs < rhs); + } + }; + + template <typename I> + std::vector<mln_point(I)> + sort_points(metal::false_, // general case + const Image<I>& input_) + { + const I& input = exact(input_); + + std::vector<mln_point(I)> vec; + vec.reserve(input.npoints()); + + mln_fwd_piter(I) p(input.domain()); + for_all(p) + vec.push_back(p); + + std::sort(vec.begin(), vec.end(), + value_point_less_<I>(input)); + return vec; + } + + template <typename I> + std::vector<mln_point(I)> + sort_points(metal::true_, // low quantization + const Image<I>& input_) + { + const I& input = exact(input_); + + typedef mln_vset(I) S; + const S& vset = input.values(); + const unsigned n = vset.nvalues(); + + // h + histo::data<S> h = histo::compute(input); + + // preparing output data + std::vector<unsigned> loc(vset.nvalues()); + loc[0] = 0; + for (unsigned i = 1; i != n; ++i) + loc[i] = loc[i-1] + h[i-1]; + + /* + MEMO. Decreasing case is: + loc[n-1] = 0; + for (unsigned i = n - 2; i != 0; --i) + loc[i] = loc[i+1] + h[i+1]; + */ + + // computing output data + std::vector<mln_point(I)> vec(input.npoints()); + mln_fwd_piter(I) p(input.domain()); + for_all(p) + vec[loc[vset.index_of(input(p))]++] = p; + + return vec; + } + + } // end of namespace mln::level::impl + + + template <typename I> + std::vector<mln_point(I)> + sort_points(const Image<I>& input) + { + mln_precondition(exact(input).has_data()); + return impl::sort_points(mln_is_value_lowq(I)(), exact(input)); + } + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::level + +} // end of namespace mln + + +#endif // ! MLN_LEVEL_SORT_POINTS_HH Index: mln/accu/histo.hh --- mln/accu/histo.hh (revision 1037) +++ mln/accu/histo.hh (working copy) @@ -67,7 +67,7 @@ std::size_t nvalues() const; std::size_t sum() const; - const std::vector<std::size_t>& vec() const; + const std::vector<std::size_t>& vect() const; const S& vset() const; @@ -160,7 +160,7 @@ template <typename S> const std::vector<std::size_t>& - histo<S>::vec() const + histo<S>::vect() const { return h_; } Index: mln/accu/bbox.hh --- mln/accu/bbox.hh (revision 0) +++ mln/accu/bbox.hh (revision 0) @@ -0,0 +1,134 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_ACCU_BBOX_HH +# define MLN_ACCU_BBOX_HH + +/*! \file mln/accu/bbox.hh + * + * \brief Define an accumulator that computes a bbox. + */ + +# include <mln/core/concept/accumulator.hh> +# include <mln/core/box.hh> + + +namespace mln +{ + + namespace accu + { + + + /*! Generic bbox accumulator class. + * + * The parameter \c P is the type of points. + */ + template <typename P> + struct bbox : public Accumulator< bbox<P> > + { + typedef P value; + + bbox(); + void take(const P& p); + void init(); + + operator box_<P>() const; + const box_<P>& to_value() const; + + bool is_valid() const; + + protected: + + bool is_valid_; + box_<P> b_; + }; + + + +# ifndef MLN_INCLUDE_ONLY + + template <typename P> + bbox<P>::bbox() + { + init(); + } + + template <typename P> + void bbox<P>::take(const P& p) + { + if (! is_valid_) + { + b_.pmin() = p; + b_.pmax() = p; + is_valid_ = true; + return; + } + for (unsigned i = 0; i < P::dim; ++i) + if (p[i] < b_.pmin()[i]) + b_.pmin()[i] = p[i]; + else if (p[i] > b_.pmax()[i]) + b_.pmax()[i] = p[i]; + } + + template <typename P> + void + bbox<P>::init() + { + is_valid_ = false; + } + + template <typename P> + bbox<P>::operator box_<P>() const + { + mln_precondition(is_valid_); + return b_; + } + + template <typename P> + const box_<P>& + bbox<P>::to_value() const + { + mln_precondition(is_valid_); + return b_; + } + + template <typename P> + bool + bbox<P>::is_valid() const + { + return is_valid_; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::accu + +} // end of namespace mln + + +#endif // ! MLN_ACCU_BBOX_HH