
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Renaming. * mln/core/fimage.hh, * tests/fimage.cc: Rename as... * mln/pw/image.hh, * tests/pw_image.cc: ...these. * mln/pw/all.hh, * mln/draw/line.hh, * tests/line2d.cc: Update. * mln/core/pqueue.hh, * mln/core/pvec.hh, * mln/core/pvec_piter.hh, * mln/core/pset.hh, * tests/pqueue.cc, * tests/pset.cc: Rename as... * mln/core/queue_p.hh, * mln/core/vec_p.hh, * mln/core/vec_p_piter.hh, * mln/core/set_p.hh, * tests/queue_p.cc, * tests/set_p.cc: ...these. * mln/core/line2d.hh: Update. * mln/core/psubset.hh, * mln/core/psubset_piter.hh, * mln/core/subimage.hh, * tests/psubset.cc, * tests/subimage.cc: Rename as... * mln/core/pset_if.hh, * mln/core/pset_if_piter.hh, * mln/core/image_if.hh, * tests/pset_if.cc, * tests/image_if.cc: ...these. * tests/to_image.cc: Update. * mln/accu/counter.hh: Rename as... * mln/accu/count.hh: ...this. * mln/accu/count.hh, * mln/accu/mean.hh, * mln/accu/sum.hh (operator+=): New. * mln/value/props.hh (mln_sum, sum): New. * mln/accu/mean.hh, * mln/accu/sum.hh, * mln/value/int_u.hh, * mln/value/int_s.hh: Update. * mln/level/apply.hh: Move accumulator version into... * mln/level/take.hh: ...this new file. * mln/level/run.hh: New. * mln/estim/mean.hh: Update. * mln/core/internal/set_of.hh (operator=): Remove; too error-prone. * mln/core/concept/window.hh (operator=): New. * tests/rectangle2d.cc: Fix. mln/accu/count.hh | 119 ++++++++++++++++++++ mln/accu/mean.hh | 26 +++- mln/accu/sum.hh | 19 ++- mln/core/concept/window.hh | 28 ++++ mln/core/image_if.hh | 118 ++++++++++++++++++++ mln/core/internal/set_of.hh | 22 --- mln/core/line2d.hh | 6 - mln/core/pset_if.hh | 191 +++++++++++++++++++++++++++++++++ mln/core/pset_if_piter.hh | 125 +++++++++++++++++++++ mln/core/queue_p.hh | 253 ++++++++++++++++++++++++++++++++++++++++++++ mln/core/set_p.hh | 162 ++++++++++++++++++++++++++++ mln/core/vec_p.hh | 208 ++++++++++++++++++++++++++++++++++++ mln/core/vec_p_piter.hh | 172 +++++++++++++++++++++++++++++ mln/draw/line.hh | 30 +---- mln/estim/mean.hh | 28 +--- mln/level/apply.hh | 51 ++++---- mln/level/run.hh | 79 +++++++++++++ mln/level/take.hh | 102 +++++++++++++++++ mln/pw/all.hh | 1 mln/pw/image.hh | 192 +++++++++++++++++++++++++++++++++ mln/value/int_s.hh | 1 mln/value/int_u.hh | 1 mln/value/props.hh | 13 ++ tests/image_if.cc | 46 ++++++++ tests/line2d.cc | 7 - tests/mean.cc | 53 +++++++++ tests/pset_if.cc | 45 +++++++ tests/pw_image.cc | 44 +++++++ tests/queue_p.cc | 57 +++++++++ tests/rectangle2d.cc | 2 tests/set_p.cc | 59 ++++++++++ tests/to_image.cc | 2 32 files changed, 2152 insertions(+), 110 deletions(-) Index: tests/set_p.cc --- tests/set_p.cc (revision 0) +++ tests/set_p.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/set_p.cc + * + * \brief Tests on mln::set_p. + */ + +#include <iterator> + +#include <mln/core/point2d.hh> +#include <mln/core/set_p.hh> + + + +int main() +{ + using namespace mln; + + set_p<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/line2d.cc --- tests/line2d.cc (revision 1047) +++ tests/line2d.cc (working copy) @@ -35,13 +35,8 @@ #include <mln/core/image2d_b.hh> #include <mln/level/fill.hh> -#include <mln/draw/line.hh> -#include <mln/debug/println.hh> - -#include <mln/core/fimage.hh> -#include <mln/pw/cst.hh> -#include <mln/level/paste.hh> #include <mln/level/compare.hh> +#include <mln/draw/line.hh> int main() Index: tests/mean.cc --- tests/mean.cc (revision 0) +++ tests/mean.cc (revision 0) @@ -0,0 +1,53 @@ +// 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/assign.cc + * + * \brief Tests on mln::level::assign. + */ + +#include <mln/core/image2d_b.hh> +#include <mln/value/int_u8.hh> + +#include <mln/debug/iota.hh> +#include <mln/estim/mean.hh> + + +int main() +{ + using namespace mln; + using value::int_u8; + + image2d_b<int_u8> ima(3, 3); + debug::iota(ima); + // 1 2 3 + // 4 5 6 + // 7 8 9 + mln_assertion(estim::mean(ima) = 5); + + // FIXME: Add example on accu::mean used several times. +} Index: tests/to_image.cc --- tests/to_image.cc (revision 1047) +++ tests/to_image.cc (working copy) @@ -32,7 +32,7 @@ #include <mln/core/image2d_b.hh> #include <mln/core/window2d.hh> -#include <mln/core/psubset.hh> +#include <mln/core/pset_if.hh> #include <mln/fun/p2b/chess.hh> #include <mln/level/compare.hh> Index: tests/pw_image.cc --- tests/pw_image.cc (revision 0) +++ tests/pw_image.cc (revision 0) @@ -0,0 +1,44 @@ +// 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/fimage.cc + * + * \brief Tests on mln::fimage. + */ + +#include <mln/fun/p2b/chess.hh> +#include <mln/core/box2d.hh> +#include <mln/pw/image.hh> +#include <mln/debug/println.hh> + + +int main() +{ + using namespace mln; + + debug::println( fun::p2b::chess | make::box2d(8, 8) ); +} Index: tests/rectangle2d.cc --- tests/rectangle2d.cc (revision 1047) +++ tests/rectangle2d.cc (working copy) @@ -44,6 +44,6 @@ mln_assertion(rec.is_centered()); mln_assertion(rec.is_symmetric()); mln_assertion(rec = -rec); - mln_assertion(rec.nelements() = h * w); + mln_assertion(rec.ndpoints() = h * w); } Index: tests/image_if.cc --- tests/image_if.cc (revision 0) +++ tests/image_if.cc (revision 0) @@ -0,0 +1,46 @@ +// 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/image_if.cc + * + * \brief Tests on mln::image_if. + */ + +#include <mln/core/image2d_b.hh> +#include <mln/core/image_if.hh> +#include <mln/fun/p2b/chess.hh> +#include <mln/debug/println.hh> + + +int main() +{ + using namespace mln; + + image2d_b<int> ima(8, 8); + // debug::println(ima | fun::p2b::chess); + mln_assertion((ima | fun::p2b::chess).npoints() = 32); +} Index: tests/queue_p.cc --- tests/queue_p.cc (revision 0) +++ tests/queue_p.cc (revision 0) @@ -0,0 +1,57 @@ +// 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/queue_p.cc + * + * \brief Tests on mln::queue_p. + */ + +#include <mln/core/point2d.hh> +#include <mln/core/queue_p.hh> + + + +int main() +{ + using namespace mln; + + queue_p<point2d> q; + q + .push(make::point2d(6, 9)) + .push(make::point2d(5, 1)) + .push(make::point2d(4, 2)); + mln_assertion(q.npoints() = 3); + + std::cout << q.bbox() << std::endl; + std::cout << q << std::endl; + + q.pop(); + mln_assertion(q.npoints() = 2); + point2d p = q.front(); + mln_assertion(q.npoints() = 2); + mln_assertion(p = make::point2d(5, 1)); +} Index: tests/pset_if.cc --- tests/pset_if.cc (revision 0) +++ tests/pset_if.cc (revision 0) @@ -0,0 +1,45 @@ +// 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_if.cc + * + * \brief Tests on mln::pset_if. + */ + +#include <mln/core/image2d_b.hh> +#include <mln/core/pset_if.hh> +#include <mln/fun/p2b/chess.hh> +#include <mln/convert/to_image.hh> + + +int main() +{ + using namespace mln; + + box2d box_8x8 = make::box2d(8, 8); + mln_assertion((box_8x8 | fun::p2b::chess).npoints() = 32); +} Index: mln/estim/mean.hh --- mln/estim/mean.hh (revision 1047) +++ mln/estim/mean.hh (working copy) @@ -33,8 +33,8 @@ * \brief Compute the mean pixel value. */ -# include <mln/core/concept/image.hh> # include <mln/accu/mean.hh> +# include <mln/level/run.hh> namespace mln @@ -43,32 +43,22 @@ namespace estim { - /*! \brief Compute the mean value of the pixels of image \p input. * - * Parameter \c S is the type of the mean value. + * \param[in] input The image. */ - template <typename S, typename I> - S mean(const Image<I>& input); - + template <typename I> + mln_sum(mln_value(I)) mean(const Image<I>& input); # ifndef MLN_INCLUDE_ONLY - template <typename S, typename I> - S - mean(const Image<I>& input_) + template <typename I> + mln_sum(mln_value(I)) mean(const Image<I>& input) { - const I& input = exact(input_); - mln_precondition(input.has_data()); - - accu::mean<mln_value(I), S> m; - - mln_piter(I) p(input.domain()); - for_all(p) - m.take(input(p)); - - return m; + typedef mln_value(I) V; + typedef mln_sum(V) S; + return level::run(input, accu::mean<V, S>()); } # endif // ! MLN_INCLUDE_ONLY Index: mln/pw/image.hh --- mln/pw/image.hh (revision 0) +++ mln/pw/image.hh (revision 0) @@ -0,0 +1,192 @@ +// 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_PW_IMAGE_HH +# define MLN_PW_IMAGE_HH + +/*! \file mln/pw/image.hh + * + * \brief Definition of an image class FIXME + */ + +# include <mln/core/internal/image_base.hh> +# include <mln/core/concept/function.hh> +# include <mln/value/set.hh> + + +namespace mln +{ + + // Fwd decl. + namespace pw { template <typename F, typename S> struct image; } + + + + /*! \brief FIXME + * + */ + template <typename F, typename S> + pw::image<F,S> + operator | (const Function_p2v<F>& f, const Point_Set<S>& ps); + + + + namespace pw + { + + /*! \brief FIXME + * + */ + template <typename F, typename S> + struct image : public internal::image_base_< S, image<F,S> > + { + /// Point_Site associated type. + typedef mln_psite(S) psite; + + /// Point_Set associated type. + typedef S pset; + + /// Value associated type. + typedef mln_result(F) value; + + /// Return type of read-only access. + typedef mln_result(F) rvalue; + + /// Return type of read-write access. + typedef void lvalue; // FIXME + + /// Value set associated type. + typedef mln::value::set<mln_result(F)> vset; + + + /// Constructor. + image(const Function_p2v<F>& f, const Point_Set<S>& ps); + + + /// Test if this image has been initialized. + bool has_data() const; + + /// Test if a pixel value is accessible at \p p. + bool owns_(const psite& p) const; + + /// Give the definition domain. + const S& domain() const; + + /// Read-only access of pixel value at point site \p p. + mln_result(F) operator()(const psite& p) const; + + /// Read-write access is present but disabled. + void operator()(const psite&); + + /// Give the set of values of the image. + const vset& values() const; + + /// Change value type. FIXME! + template <typename U> + struct change_value + { + typedef void ret; + }; + + protected: + F f_; + S pset_; + }; + + } // end of namespace mln::pw + + + +# ifndef MLN_INCLUDE_ONLY + + template <typename F, typename S> + pw::image<F,S> + operator | (const Function_p2v<F>& f, const Point_Set<S>& ps) + { + pw::image<F,S> tmp(f, ps); + return tmp; + } + + namespace pw + { + + template <typename F, typename S> + image<F,S>::image(const Function_p2v<F>& f, const Point_Set<S>& ps) + : f_(exact(f)), + pset_(exact(ps)) + { + } + + template <typename F, typename S> + bool image<F,S>::has_data() const + { + return true; + } + + template <typename F, typename S> + bool image<F,S>::owns_(const psite& p) const + { + return pset_.has(p); + } + + template <typename F, typename S> + const S& + image<F,S>::domain() const + { + return pset_; + } + + template <typename F, typename S> + mln_result(F) + image<F,S>::operator()(const psite& p) const + { + mln_precondition(pset_.has(p)); + return f_(p); + } + + template <typename F, typename S> + void + image<F,S>::operator()(const psite&) + { + mln_invariant(0); // FIXME: Turn into a compile-time error... + } + + template <typename F, typename S> + const mln::value::set<mln_result(F)>& + image<F,S>::values() const + { + return vset::the(); + } + + } // end of namespace mln::pw + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_PW_IMAGE_HH Index: mln/pw/all.hh --- mln/pw/all.hh (revision 1047) +++ mln/pw/all.hh (working copy) @@ -47,6 +47,7 @@ # include <mln/pw/value.hh> # include <mln/pw/cst.hh> # include <mln/pw/var.hh> +# include <mln/pw/image.hh> # include <mln/fun/ops.hh> Index: mln/core/image_if.hh --- mln/core/image_if.hh (revision 0) +++ mln/core/image_if.hh (revision 0) @@ -0,0 +1,118 @@ +// 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_IMAGE_IF_HH +# define MLN_CORE_IMAGE_IF_HH + +/*! \file mln/core/image_if.hh + * + * \brief Definition of a base class for image adaptors. + */ + +# include <mln/core/internal/image_adaptor.hh> +# include <mln/core/pset_if.hh> + + +namespace mln +{ + + /*! \brief A base class for image adaptors. + * + */ + template <typename I, typename F> + struct image_if : public internal::image_adaptor_< I, + image_if<I,F>, + pset_if<mln_pset(I),F> > + { + /// Point_Set associated type. + typedef pset_if<mln_pset(I), F> pset; + + /// Constructor from an \p adaptee image. + image_if(I& adaptee, const F& f); + + /// Test if a pixel value is accessible at \p p. + bool owns_(const mln_psite(I)& p) const; + + /// Give the definition domain. + const pset& domain() const; + + template <typename T> + struct change_value + { + typedef image_if<mln_ch_value(I,T), F> ret; + }; + + protected: + + pset pset_; + F f_; + + typedef image_if<I,F> self_; + typedef internal::image_adaptor_< I, self_, pset > super_; + }; + + + + template <typename I, typename F> + image_if<I, F> + operator | (Image<I>& ima, const Function_p2b<F>& f) + { + image_if<I, F> tmp(exact(ima), exact(f)); + return tmp; + } + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I, typename F> + image_if<I,F>::image_if(I& adaptee, const F& f) + : super_(adaptee), + pset_(adaptee.domain() | f), + f_(f) + { + } + + template <typename I, typename F> + bool + image_if<I,F>::owns_(const mln_psite(I)& p) const + { + return pset_.has(p); + } + + template <typename I, typename F> + const pset_if<mln_pset(I), F>& + image_if<I,F>::domain() const + { + return pset_; + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_IMAGE_IF_HH Index: mln/core/queue_p.hh --- mln/core/queue_p.hh (revision 0) +++ mln/core/queue_p.hh (revision 0) @@ -0,0 +1,253 @@ +// 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_QUEUE_P_HH +# define MLN_CORE_QUEUE_P_HH + +/*! \file mln/core/queue_p.hh + * + * \brief Definition of a point set class based on std::deque. + */ + +# include <vector> +# include <deque> +# include <algorithm> +# include <iterator> + +# include <mln/core/concept/point_set.hh> +# include <mln/core/vec_p_piter.hh> +# include <mln/accu/bbox.hh> + + +namespace mln +{ + + // Fwd decls. + template <typename P> struct vec_p_fwd_piter_; + template <typename P> struct vec_p_bkd_piter_; + + + /*! \brief Point queue class (based on std::deque). + * + * This is a mathematical set of points (unique insertion). + * + * \todo Make it work with P being a Point_Site. + * \todo Add a parameter flag to choose another policy for "push" + * (i.e., no-op if multiple or allow multiple insertions). + * + * \warning We have some troubles with point set comparison based on + * a call to npoints() when this container is multiple. + */ + template <typename P> + class queue_p : public Point_Set< queue_p<P> > + { + public: + + /// Point associated type. + typedef P point; + + /// Point_Site associated type. + typedef P psite; + + /// Forward Point_Iterator associated type. + typedef vec_p_fwd_piter_<P> fwd_piter; + + /// Backward Point_Iterator associated type. + typedef vec_p_bkd_piter_<P> bkd_piter; + + /// Constructor. + queue_p(); + + /// 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_<P>& bbox() const; + + /// Push a point \p p in the queue. + queue_p<P>& push(const P& p); + + /// Pop (remove) the front point \p p from the queue; \p p is the + /// least recently inserted point. + void pop(); + + /// Give the front point \p p of the queue; \p p is the least + /// recently inserted point. + const P& front() const; + + /// Clear the queue. + 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::deque<P> q_; + + mutable std::vector<P> vect_; + mutable bool vect_needs_update_; + void vect_update_() const; + + mutable accu::bbox<P> bb_; + mutable bool bb_needs_update_; + void bb_update_() const; + + }; + + + +# ifndef MLN_INCLUDE_ONLY + + template <typename P> + queue_p<P>::queue_p() + { + vect_needs_update_ = false; + bb_needs_update_ = false; + } + + template <typename P> + void + queue_p<P>::vect_update_() const + { + vect_.clear(); + vect_.reserve(q_.size()); + std::copy(q_.begin(), q_.end(), + std::back_inserter(vect_)); + vect_needs_update_ = false; + } + + template <typename P> + void + queue_p<P>::bb_update_() const + { + bb_.init(); + for (unsigned i = 0; i < q_.size(); ++i) + bb_.take(q_[i]); + bb_needs_update_ = false; + } + + template <typename P> + bool + queue_p<P>::has(const P& p) const + { + for (unsigned i = 0; i < q_.size(); ++i) + if (q_[i] = p) + return true; + return false; + } + + template <typename P> + std::size_t + queue_p<P>::npoints() const + { + return q_.size(); + } + + template <typename P> + const box_<P>& + queue_p<P>::bbox() const + { + mln_precondition(npoints() != 0); + if (bb_needs_update_) + bb_update_(); + return bb_.to_value(); + } + + template <typename P> + queue_p<P>& + queue_p<P>::push(const P& p) + { + mln_precondition(! has(p)); + // FIXME: Our choice is "error if multiple insertions" + q_.push_back(p); + if (! vect_needs_update_) + { + vect_needs_update_ = true; + bb_needs_update_ = true; + } + } + + template <typename P> + void + queue_p<P>::pop() + { + q_.pop_front(); + if (! vect_needs_update_) + { + vect_needs_update_ = true; + bb_needs_update_ = true; + } + } + + template <typename P> + const P& + queue_p<P>::front() const + { + mln_precondition(! q_.empty()); + return q_.front(); + } + + template <typename P> + void + queue_p<P>::clear() + { + q_.clear(); + vect_.clear(); + vect_needs_update_ = false; + bb_needs_update_ = false; + } + + template <typename P> + const std::vector<P>& + queue_p<P>::vect() const + { + if (vect_needs_update_) + vect_update_(); + return vect_; + } + + template <typename P> + const P& + queue_p<P>::operator[](unsigned i) const + { + mln_precondition(i < npoints()); + return q_[i]; + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_QUEUE_P_HH Index: mln/core/internal/set_of.hh --- mln/core/internal/set_of.hh (revision 1047) +++ mln/core/internal/set_of.hh (working copy) @@ -173,16 +173,6 @@ std::ostream& operator<<(std::ostream& ostr, const set_of_<E>& s); - /*! \brief Test if both sets \p lhs and \p rhs are equal. - * - * \param[in] lhs A set. - * \param[in] rhs Another set. - * - * \relates mln::internal::set_of_ - */ - template <typename E> - bool operator=(const set_of_<E>& lhs, const set_of_<E>& rhs); - # ifndef MLN_INCLUDE_ONLY @@ -279,18 +269,6 @@ return ostr; } - template <typename E> - bool operator=(const set_of_<E>& lhs, const set_of_<E>& rhs) - { - if (lhs.nelements() != rhs.nelements()) - return false; - const unsigned n = lhs.nelements(); - for (unsigned i = 0; i < n; ++i) - if (rhs.element(i) != lhs.element(i)) - return false; - return true; - } - # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::internal Index: mln/core/pset_if.hh --- mln/core/pset_if.hh (revision 0) +++ mln/core/pset_if.hh (revision 0) @@ -0,0 +1,191 @@ +// 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_IF_HH +# define MLN_CORE_PSET_IF_HH + +/*! \file mln/core/pset_if.hh + * + * \brief Definition of the restriction of a point set w.r.t. a predicate. + */ + +# include <mln/core/concept/point_set.hh> +# include <mln/core/concept/function.hh> + + +namespace mln +{ + + // Fwd decls. + template <typename S, typename F> struct pset_if; + template <typename S, typename F> struct pset_if_fwd_piter_; + template <typename S, typename F> struct pset_if_bkd_piter_; + + + + /*! \brief Restrict a point set \p pset to points that verify \p f. + * + * \param[in] pset A point set. + * \param[in] f A function from point to Boolean. + * \return A subset of points. + */ + template <typename S, typename F> + pset_if<S, F> + operator | (const Point_Set<S>& pset, const Function_p2b<F>& f); + + + + /*! \brief Generic subset class. + * + * Parameter \c S is a point set type; parameter F is a function + * from point to Boolean. + */ + template <typename S, typename F> + struct pset_if : public Point_Set< pset_if<S,F> > + { + /// Point_Site associated type. + typedef mln_psite(S) psite; + + /// Point associated type. + typedef mln_point(S) point; + + + /// Forward Point_Iterator associated type. + typedef pset_if_fwd_piter_<S,F> fwd_piter; + + /// Backward Point_Iterator associated type. + typedef internal::fixme bkd_piter; + + + /// Constructor without argument. + pset_if(const S& pset, const F& f); + + + /// Test if \p p belongs to the subset. + bool has(const psite& p) const; + + /// Give a bounding box of the subset. + const box_<point>& bbox() const; + + /// Give the number of points of the subset. + std::size_t npoints() const; + + /// Give the primary overset. + const S& overset() const; + + /// Test predicate on point site \p p. + bool pred(const psite& p) const; + + protected: + + const S& pset_; + F f_; + }; + + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename S, typename F> + pset_if<S, F> + operator | (const Point_Set<S>& pset, const Function_p2b<F>& f) + { + pset_if<S, F> tmp(exact(pset), exact(f)); + return tmp; + } + + + // pset_if<S,F> + + template <typename S, typename F> + bool + pset_if<S,F>::has(const psite& p) const + { + return pset_.has(p) && f_(p); + } + + template <typename S, typename F> + const box_<mln_point(S)>& + pset_if<S,F>::bbox() const + { + return pset_.bbox(); + } + + template <typename S, typename F> + const S& + pset_if<S,F>::overset() const + { + return pset_; + } + + template <typename S, typename F> + bool + pset_if<S,F>::pred(const psite& p) const + { + return f_(p); + } + + template <typename S, typename F> + pset_if<S,F>::pset_if(const S& pset, const F& f) + : pset_(pset), + f_(f) + { + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + + +# include <mln/core/pset_if_piter.hh> + + + +namespace mln +{ + +# ifndef MLN_INCLUDE_ONLY + + template <typename S, typename F> + std::size_t + pset_if<S,F>::npoints() const + { + std::size_t n = 0; + fwd_piter p(*this); + for_all(p) + ++n; + return n; + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_PSET_IF_HH Index: mln/core/pset_if_piter.hh --- mln/core/pset_if_piter.hh (revision 0) +++ mln/core/pset_if_piter.hh (revision 0) @@ -0,0 +1,125 @@ +// 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_IF_PITER_HH +# define MLN_CORE_PSET_IF_PITER_HH + +/*! \file mln/core/pset_if_piter.hh + * + * \brief Definition of iterators on points of pset_ifes. + */ + +# include <mln/core/concept/point_iterator.hh> +# include <mln/core/internal/piter_adaptor.hh> +# include <mln/core/internal/fixme.hh> +# include <mln/core/pset_if.hh> + + +namespace mln +{ + + /*! \brief A generic forward iterator on points of subsets. + * + * Parameter \c S is a point set type; parameter F is a function + * from point to Boolean. + * + * \see mln::pset_if + */ + template <typename S, typename F> + class pset_if_fwd_piter_ + : public internal::piter_adaptor_< mln_fwd_piter(S), + pset_if_fwd_piter_<S,F> > + { + typedef mln_fwd_piter(S) adaptee_; + typedef pset_if_fwd_piter_<S,F> self_; + typedef internal::piter_adaptor_<adaptee_, self_> super_; + + public: + + /// Constructor from a subset of points. + pset_if_fwd_piter_(const pset_if<S,F>& subset); + + /// Start an iteration. + void start(); + + /// Go to the next point. + void next_(); + + private: + + const pset_if<S,F>& subset_; + }; + + + // FIXME: + template <typename S, typename F> + class pset_if_bkd_piter_ + : public internal::fixme + {}; + + + +# ifndef MLN_INCLUDE_ONLY + + + // pset_if_fwd_piter_<S,F> + + template <typename S, typename F> + pset_if_fwd_piter_<S,F>::pset_if_fwd_piter_(const pset_if<S,F>& subset) + : super_(adaptee_(subset.overset())), + subset_(subset) + { + } + + template <typename S, typename F> + void + pset_if_fwd_piter_<S,F>::start() + { + this->piter_.start(); + while (this->piter_.is_valid() && ! subset_.pred(this->piter_)) + this->piter_.next(); + } + + template <typename S, typename F> + void + pset_if_fwd_piter_<S,F>::next_() + { + do + this->piter_.next(); + while (this->piter_.is_valid() && ! subset_.pred(this->piter_)); + } + + + // FIXME: pset_if_bkd_piter_<S,F> + + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_PSET_IF_PITER_HH Index: mln/core/vec_p.hh --- mln/core/vec_p.hh (revision 0) +++ mln/core/vec_p.hh (revision 0) @@ -0,0 +1,208 @@ +// 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_VEC_P_HH +# define MLN_CORE_VEC_P_HH + +/*! \file mln/core/vec_p.hh + * + * \brief Definition of a point set class based on std::vector. + */ + +# include <vector> + +# include <mln/core/concept/point_set.hh> +# include <mln/accu/bbox.hh> + + +namespace mln +{ + + // Fwd decls. + template <typename P> struct vec_p_fwd_piter_; + template <typename P> struct vec_p_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! + * + * \todo Make it work with P being a Point_Site. + */ + template <typename P> + class vec_p : public Point_Set< vec_p<P> > + { + public: + + /// Point associated type. + typedef P point; + + /// Point_Site associated type. + typedef P psite; + + /// Forward Point_Iterator associated type. + typedef vec_p_fwd_piter_<P> fwd_piter; + + /// Backward Point_Iterator associated type. + typedef vec_p_bkd_piter_<P> bkd_piter; + + /// Constructor. + vec_p(); + + /// Constructor from a vector \p vect. + vec_p(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_<P>& bbox() const; + + /// Append a point \p p. + vec_p<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_() const; + // FIXME: Add invariant bb_.is_valid() <=> npoints() != 0 + }; + + + +# ifndef MLN_INCLUDE_ONLY + + template <typename P> + vec_p<P>::vec_p() + { + bb_needs_update_ = false; + } + + template <typename P> + vec_p<P>::vec_p(const std::vector<P>& vect) + : vect_(vect) + { + bb_needs_update_ = true; + } + + template <typename P> + void + vec_p<P>::update_bb_() const + { + bb_.init(); + for (unsigned i = 0; i < vect_.size(); ++i) + bb_.take(vect_[i]); + bb_needs_update_ = false; + } + + template <typename P> + bool + vec_p<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 + vec_p<P>::npoints() const + { + return vect_.size(); + } + + template <typename P> + const box_<P>& + vec_p<P>::bbox() const + { + mln_precondition(npoints() != 0); + if (bb_needs_update_) + update_bb_(); + return bb_.to_value(); + } + + template <typename P> + vec_p<P>& + vec_p<P>::append(const P& p) + { + vect_.push_back(p); + if (! bb_needs_update_) + bb_needs_update_ = true; + return *this; + } + + template <typename P> + void + vec_p<P>::clear() + { + vect_.clear(); + bb_needs_update_ = false; + } + + template <typename P> + const std::vector<P>& + vec_p<P>::vect() const + { + return vect_; + } + + template <typename P> + const P& + vec_p<P>::operator[](unsigned i) const + { + mln_precondition(i < npoints()); + return vect_[i]; + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +# include <mln/core/vec_p_piter.hh> + + +#endif // ! MLN_CORE_VEC_P_HH Index: mln/core/concept/window.hh --- mln/core/concept/window.hh (revision 1047) +++ mln/core/concept/window.hh (working copy) @@ -77,6 +77,14 @@ W operator-(const Window<W>& rhs); + /*! \brief Equality comparison between windows \p lhs and \p rhs. + * + * \relates mln::Window + */ + template <typename Wl, typename Wr> + bool operator=(const Window<Wl>& lhs, const Window<Wr>& rhs); + + # ifndef MLN_INCLUDE_ONLY template <typename E> @@ -107,6 +115,26 @@ return exact(rhs).sym_(); } + template <typename Wl, typename Wr> + bool operator=(const Window<Wl>& lhs, const Window<Wr>& rhs) + { + // FIXME: Same grid! + typedef mln_point(Wl) P; + + mln_fwd_qiter(Wl) ql(exact(lhs), P::zero); + mln_fwd_qiter(Wr) qr(exact(rhs), P::zero); + + for (ql.start(), qr.start(); + ql.is_valid() && qr.is_valid(); + ql.next(), qr.next()) + if (ql != qr) + return false; // difference found + + // both windows are equal only if both browsings are completed at + // the same time: + return ! ql.is_valid() && ! qr.is_valid(); + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/core/vec_p_piter.hh --- mln/core/vec_p_piter.hh (revision 0) +++ mln/core/vec_p_piter.hh (revision 0) @@ -0,0 +1,172 @@ +// 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_VEC_P_PITER_HH +# define MLN_CORE_VEC_P_PITER_HH + +/*! \file mln/core/vec_p_piter.hh + * + * \brief Definition of point iterators on mln::vec_p. + */ + +# include <mln/core/vec_p.hh> +# include <mln/core/internal/fixme.hh> + + +namespace mln +{ + + /*! \brief Forward iterator on points of a vec_p<P>. + * + */ + template <typename P> + struct vec_p_fwd_piter_ : public Point_Iterator< vec_p_fwd_piter_<P> > + { + enum { dim = P::dim }; + + /// Point_Site associated type. + typedef P psite; + + /// Point associated type. + typedef P point; + + /// Dpoint associated type. + typedef mln_dpoint(P) dpoint; + + /// Coordinate associated type. + typedef mln_coord(P) coord; + + /// Coordinate associated type. + template <typename S> + vec_p_fwd_piter_(const Point_Set<S>& s); + + /// Give a hook to the point address. + const P* 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_; + unsigned i_; + P p_; + }; + + + + // FIXME: + template <typename P> + struct vec_p_bkd_piter_ : internal::fixme + {}; + + + +# ifndef MLN_INCLUDE_ONLY + + template <typename P> + template <typename S> + vec_p_fwd_piter_<P>::vec_p_fwd_piter_(const Point_Set<S>& s) + : vect_(exact(s).vect()) + { + invalidate(); + } + + template <typename P> + const P* + vec_p_fwd_piter_<P>::pointer_() const + { + return & p_; + } + + template <typename P> + mln_coord(P) + vec_p_fwd_piter_<P>::operator[](unsigned i) const + { + mln_precondition(i < dim); + mln_precondition(is_valid()); + return p_[i]; + } + + template <typename P> + bool + vec_p_fwd_piter_<P>::is_valid() const + { + return i_ < vect_.size(); + } + + template <typename P> + void + vec_p_fwd_piter_<P>::invalidate() + { + i_ = vect_.size(); + } + + template <typename P> + void + vec_p_fwd_piter_<P>::start() + { + i_ = 0; + if (is_valid()) + p_ = vect_[i_]; + } + + template <typename P> + void + vec_p_fwd_piter_<P>::next_() + { + ++i_; + p_ = vect_[i_]; + } + + template <typename P> + vec_p_fwd_piter_<P>::operator P() const + { + mln_precondition(is_valid()); + return p_; + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_VEC_P_PITER_HH Index: mln/core/set_p.hh --- mln/core/set_p.hh (revision 0) +++ mln/core/set_p.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_SET_P_HH +# define MLN_CORE_SET_P_HH + +/*! \file mln/core/set_p.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/vec_p.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 set_p : public Point_Set< set_p<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 vec_p_fwd_piter_<P> fwd_piter; + + /// Backward Point_Iterator associated type. + typedef vec_p_bkd_piter_<P> bkd_piter; + + /// Constructor. + set_p(); + + /// 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. + set_p<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> + set_p<P>::set_p() + { + } + + template <typename P> + bool + set_p<P>::has(const P& p) const + { + return this->super_::has(p); + } + + template <typename P> + std::size_t + set_p<P>::npoints() const + { + return this->super_::nelements(); + } + + template <typename P> + set_p<P>& + set_p<P>::insert(const P& p) + { + this->super_::insert(p); + bb_.take(p); + return *this; + } + + template <typename P> + const P& + set_p<P>::operator[](unsigned i) const + { + mln_precondition(i < npoints()); + return this->super_::element(i); + } + + template <typename P> + void + set_p<P>::clear() + { + this->super_::clear(); + bb_.init(); + } + + template <typename P> + const box_<mln_point(P)>& + set_p<P>::bbox() const + { + mln_precondition(npoints() != 0); + return bb_.to_value(); + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_SET_P_HH Index: mln/core/line2d.hh --- mln/core/line2d.hh (revision 1047) +++ mln/core/line2d.hh (working copy) @@ -36,7 +36,7 @@ # include <vector> # include <mln/core/concept/point_set.hh> -# include <mln/core/pvec_piter.hh> +# include <mln/core/vec_p_piter.hh> # include <mln/core/box2d.hh> # include <mln/math/all.hh> @@ -58,10 +58,10 @@ typedef point2d psite; /// Forward Point_Iterator associated type. - typedef pvec_fwd_piter_<point2d> fwd_piter; + typedef vec_p_fwd_piter_<point2d> fwd_piter; /// Backward Point_Iterator associated type. - typedef pvec_bkd_piter_<point2d> bkd_piter; + typedef vec_p_bkd_piter_<point2d> bkd_piter; /// Constructor from point \p beg to point \p end. Index: mln/draw/line.hh --- mln/draw/line.hh (revision 1047) +++ mln/draw/line.hh (working copy) @@ -35,6 +35,9 @@ # include <mln/core/concept/image.hh> # include <mln/core/line2d.hh> +# include <mln/level/paste.hh> +# include <mln/pw/image.hh> +# include <mln/pw/cst.hh> namespace mln @@ -43,7 +46,8 @@ namespace draw { - /// Draw a line at level \p v in image \p ima between the points \p beg and \p end. + /// Draw a line at level \p v in image \p ima between the points + /// \p beg and \p end. template <typename I> void line(Image<I>& ima, const mln_point(I)& beg, const mln_point(I)& end, @@ -52,27 +56,6 @@ # ifndef MLN_INCLUDE_ONLY - namespace impl - { - - template <typename I> - void line(I& ima, - const point2d& beg, const point2d& end, - const mln_value(I)& v) - { - line2d l(beg, end); - mln_piter(line2d) p(l); - for_all(p) - ima(p) = v; - } - - // FIXME: Overload. - - } // end of namespace mln::draw::impl - - - // Facade. - template <typename I> void line(Image<I>& ima, const mln_point(I)& beg, const mln_point(I)& end, @@ -80,7 +63,8 @@ { mln_precondition(exact(ima).has_data()); mln_precondition(exact(ima).has(beg) && exact(ima).has(end)); - impl::line(exact(ima), beg, end, v); + level::paste(pw::cst(v) | line2d(beg, end), + ima); } # endif // ! MLN_INCLUDE_ONLY Index: mln/level/take.hh --- mln/level/take.hh (revision 0) +++ mln/level/take.hh (revision 0) @@ -0,0 +1,102 @@ +// 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_TAKE_HH +# define MLN_LEVEL_TAKE_HH + +/*! \file mln/level/take.hh + * + * \brief Make an accumulator take image pixel values. + */ + +# include <mln/core/concept/accumulator.hh> +# include <mln/core/concept/image.hh> + + +namespace mln +{ + + namespace level + { + + /*! Make an accumulator take the values of the image \p input. + * + * \param[in,out] a The accumulator. + * \param[in] input The input image. + * + * This routine runs: \n + * for all p of \p input, \p a.take( \p input(p) ) \n + * + * \warning This routine does not perform a.init(). + */ + template <typename A, typename I> + void take(Accumulator<A>& a, const Image<I>& input); + + +# ifndef MLN_INCLUDE_ONLY + + namespace impl + { + + template <typename A, typename I> + void take(A& a, const Image<I>& input_) + { + const I& input = exact(input_); + mln_piter(I) p(input.domain()); + for_all(p) + a.take(input(p)); + } + + template <typename A, typename I> + void take(A& a, const Fast_Image<I>& input_) + { + const I& input = exact(input_); + mln_pixter(const I) pxl(input); + for_all(pxl) + a.take(*pxl); + } + + } // end of namespace mln::level::impl + + + // Facade. + + template <typename A, typename I> + void take(Accumulator<A>& a, const Image<I>& input) + { + mln_precondition(exact(input).has_data()); + impl::take(exact(a), exact(input)); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::level + +} // end of namespace mln + + +#endif // ! MLN_LEVEL_TAKE_HH Index: mln/level/apply.hh --- mln/level/apply.hh (revision 1047) +++ mln/level/apply.hh (working copy) @@ -30,7 +30,7 @@ /*! \file mln/level/apply.hh * - * \brief Apply some function-objects on an image. + * \brief Apply a function-object onto image pixel values. */ # include <mln/core/concept/image.hh> @@ -52,34 +52,25 @@ * This routine runs: \n * for all p of \p input, \p f( \p input(p) ) \n * return \p f + * + * \todo Find a meaning for this routine! (Clue: f is mutable + * and/or same for input?) */ template <typename I, typename F> F apply(const Image<I>& input, const Function<F>& f); - /*! Apply an accumulator to the image \p input. - * - * \param[in] input The input image. - * \param[in] a The accumulator. - * \result A copy of the accumulator. - * - * This routine runs: \n - * a.init() \n - * for all p of \p input, \p a.take( \p input(p) ) \n - * return \p a - */ - template <typename I, typename A> - A apply(const Image<I>& input, const Accumulator<A>& a); - # ifndef MLN_INCLUDE_ONLY + namespace impl + { + template <typename I, typename F> F apply(const Image<I>& input_, const Function<F>& f_) { const I& input = exact(input_); F f = exact(f_); - mln_precondition(input.has_data()); mln_piter(I) p(input.domain()); for_all(p) @@ -87,18 +78,28 @@ return f; } - template <typename I, typename A> - A apply(const Image<I>& input_, const Accumulator<A>& a_) + template <typename I, typename F> + F apply(const Fast_Image<I>& input_, const Function<F>& f_) { const I& input = exact(input_); - A a = exact(a_); - mln_precondition(input.has_data()); + F f = exact(f_); - a.init(); - mln_piter(I) p(input.domain()); - for_all(p) - a.take(input(p)); - return a; + mln_pixter(const I) pxl(input); + for_all(pxl) + f(input(*pxl)); + return f; + } + + } // end of namespace mln::level::impl + + + // Facades. + + template <typename I, typename F> + F apply(const Image<I>& input, const Function<F>& f) + { + mln_precondition(exact(input).has_data()); + return impl::apply(exact(input), f); } # endif // ! MLN_INCLUDE_ONLY Index: mln/level/run.hh --- mln/level/run.hh (revision 0) +++ mln/level/run.hh (revision 0) @@ -0,0 +1,79 @@ +// 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_RUN_HH +# define MLN_LEVEL_RUN_HH + +/*! \file mln/level/run.hh + * + * \brief Run an accumulator onto image pixel values. + */ + +# include <mln/level/take.hh> + + +namespace mln +{ + + namespace level + { + + /*! Run an accumulator onto the pixel values of the image \p input. + * + * \param[in] input The input image. + * \param[in] a The accumulator. + * \return A resulting accumulator. + * + * This routine runs: \n + * res = \p a \n + * res.init() \n + * level::take(res, \p input) \n + * return res \n + */ + template <typename I, typename A> + A run(const Image<I>& input, const Accumulator<A>& a); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I, typename A> + A run(const Image<I>& input, const Accumulator<A>& a) + { + A res = exact(a); + res.init(); + level::take(res, input); + return res; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::level + +} // end of namespace mln + + +#endif // ! MLN_LEVEL_RUN_HH Index: mln/accu/sum.hh --- mln/accu/sum.hh (revision 1047) +++ mln/accu/sum.hh (working copy) @@ -34,6 +34,7 @@ */ # include <mln/core/concept/accumulator.hh> +# include <mln/value/props.hh> namespace mln @@ -46,10 +47,10 @@ /*! Generic sum accumulator class. * * Parameter \c V is the type of values that we sum. Parameter \c - * S is the type to store the sum value; the default type of - * \c S is \c V. + * S is the type to store the value sum; the default type of + * \c S is the summation type (property) of \c V. */ - template <typename V, typename S = V> + template <typename V, typename S = mln_sum(V)> struct sum : public Accumulator< sum<V,S> > { typedef V value; @@ -61,6 +62,8 @@ operator S() const; S to_value() const; + sum<V,S>& operator+=(const sum<V,S>& rhs); + protected: S sum_; @@ -99,7 +102,15 @@ S sum<V,S>::to_value() const { - return sum_ / count_; + return sum_; + } + + template <typename V, typename S> + sum<V,S>& + sum<V,S>::operator+=(const sum<V,S>& rhs) + { + sum_ += rhs.sum_; + return *this; } # endif // ! MLN_INCLUDE_ONLY Index: mln/accu/count.hh --- mln/accu/count.hh (revision 0) +++ mln/accu/count.hh (revision 0) @@ -0,0 +1,119 @@ +// 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_COUNT_HH +# define MLN_ACCU_COUNT_HH + +/*! \file mln/accu/count.hh + * + * \brief Define an accumulator that counts. + */ + +# include <mln/core/concept/accumulator.hh> + + +namespace mln +{ + + namespace accu + { + + + /*! Generic counter accumulator class. + */ + template <typename V> + struct count : public Accumulator< count<V> > + { + typedef V value; + + count(); + void take(const value&); + void init(); + + operator std::size_t() const; + std::size_t to_value() const; + + count<V>& operator+=(const count<V>& rhs); + + protected: + + std::size_t count_; + }; + + + +# ifndef MLN_INCLUDE_ONLY + + template <typename V> + count<V>::count() + { + init(); + } + + template <typename V> + void + count<V>::take(const value&) + { + ++count_; + } + + template <typename V> + void + count<V>::init() + { + count_ = 0; + } + + template <typename V> + count<V>::operator std::size_t() const + { + return to_value(); + } + + template <typename V> + std::size_t + count<V>::to_value() const + { + return count_; + } + + template <typename V> + count<V>& + count<V>::operator+=(const count<V>& rhs) + { + count_ += rhs.count_; + return *this; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::accu + +} // end of namespace mln + + +#endif // ! MLN_ACCU_COUNT_HH Index: mln/accu/mean.hh --- mln/accu/mean.hh (revision 1047) +++ mln/accu/mean.hh (working copy) @@ -33,7 +33,7 @@ * \brief Define an accumulator that computes a mean. */ -# include <mln/accu/counter.hh> +# include <mln/accu/count.hh> # include <mln/accu/sum.hh> @@ -48,10 +48,13 @@ * * Parameter \c V is the type of values that we sum. Parameter \c * S is the type to store the sum of values; the default type of - * \c S is \c V. Parameter \c M is the type of the mean value; - * the default type of \c M is \c S. + * \c S is the summation type (property) of \c V. Parameter \c M + * is the type of the mean value; the default type of \c M is \c + * S. */ - template <typename V, typename S = V, typename M = S> + template <typename V, + typename S = mln_sum(V), + typename M = S> struct mean : public Accumulator< mean<V,S,M> > { typedef V value; @@ -63,9 +66,11 @@ operator M() const; M to_value() const; + mean<V,S,M>& operator+=(const mean<V,S,M>& rhs); + protected: - accu::counter<V> count_; + accu::count<V> count_; accu::sum<V,S> sum_; }; @@ -97,7 +102,7 @@ template <typename V, typename S, typename M> mean<V,S,M>::operator M() const { - return to_value; + return to_value(); } template <typename V, typename S, typename M> @@ -107,6 +112,15 @@ return sum_.to_value() / count_.to_value(); } + template <typename V, typename S, typename M> + mean<V,S,M>& + mean<V,S,M>::operator+=(const mean<V,S,M>& rhs) + { + count_ += rhs.count_; + sum_ += rhs.sum_; + return *this; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu Index: mln/value/props.hh --- mln/value/props.hh (revision 1047) +++ mln/value/props.hh (working copy) @@ -61,6 +61,9 @@ # define mln_is_lowq(T) typename metal::bool_<( mln_card_(T) != 0 )>::type +/// Give the summation type for values of type \c T. +# define mln_sum(T) typename mln::value::props< T >::sum + namespace mln @@ -121,6 +124,7 @@ static const unsigned char max = 255; static const std::size_t card_ = 256; typedef data_kind kind; + typedef float sum; }; template <> @@ -130,6 +134,7 @@ static const signed char max = 127; static const std::size_t card_ = 256; typedef data_kind kind; + typedef float sum; }; template <> @@ -139,6 +144,7 @@ static const unsigned short max = 65535; static const std::size_t card_ = 65536; typedef data_kind kind; + typedef float sum; }; template <> @@ -148,6 +154,7 @@ static const signed short max = 32767; static const std::size_t card_ = 655356; typedef data_kind kind; + typedef float sum; }; template <> @@ -157,6 +164,7 @@ static const unsigned int max = UINT_MAX; typedef data_kind kind; static const std::size_t card_ = 0; + typedef float sum; }; template <> @@ -166,6 +174,7 @@ static const signed int max = INT_MAX; typedef data_kind kind; static const std::size_t card_ = 0; + typedef float sum; }; template <> @@ -175,6 +184,7 @@ static const unsigned long int max = ULONG_MAX; typedef data_kind kind; static const std::size_t card_ = 0; + typedef float sum; }; template <> @@ -184,6 +194,7 @@ static const signed long int max = LONG_MAX; typedef data_kind kind; static const std::size_t card_ = 0; + typedef float sum; }; @@ -196,6 +207,7 @@ static const float max() { return FLT_MAX; } typedef data_kind kind; static const std::size_t card_ = 0; + typedef float sum; }; template <> @@ -205,6 +217,7 @@ static const double max() { return DBL_MAX; } typedef data_kind kind; static const std::size_t card_ = 0; + typedef double sum; }; } // end of namespace mln::value Index: mln/value/int_s.hh --- mln/value/int_s.hh (revision 1047) +++ mln/value/int_s.hh (working copy) @@ -97,6 +97,7 @@ static const std::size_t card_ = metal::pow<2, n>::value; static const unsigned nbits = n; typedef data_kind kind; + typedef float sum; }; Index: mln/value/int_u.hh --- mln/value/int_u.hh (revision 1047) +++ mln/value/int_u.hh (working copy) @@ -99,6 +99,7 @@ static const int_u<n> max; // = card_ - 1 static const unsigned nbits = n; typedef data_kind kind; + typedef float sum; };
participants (1)
-
Thierry Geraud