
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Clean-up windows! * mln/core/internal/dpoints_base.hh: New. * mln/core/concept/doc/weighted_window.hh: New. * mln/core/w_window.hh (element, nelements): Rename as... (dp, ndpoints): ...these. (sym_): Add body. Update. * mln/core/window.hh (super_): Update. (qiter): Remove; obsolete. (point, dpoint, is_centered, delta): Remove; factored. * mln/core/dpoints_pixter.hh: Update. * mln/core/concept/weighted_window.hh (is_symmetric): Remove; too ambiguous. * mln/core/win/vline2d.hh: Update inheritance. * mln/core/win/hline2d.hh: Likewise. * mln/core/win/rectangle2d.hh: Likewise. (qiter): Remove; obsolete. concept/doc/weighted_window.hh | 83 ++++++++++++++++++++ concept/weighted_window.hh | 16 +-- dpoints_pixter.hh | 8 - internal/dpoints_base.hh | 166 +++++++++++++++++++++++++++++++++++++++++ w_window.hh | 79 ++++++++++--------- win/hline2d.hh | 4 win/rectangle2d.hh | 8 - win/vline2d.hh | 4 window.hh | 61 ++++----------- 9 files changed, 329 insertions(+), 100 deletions(-) Index: mln/core/w_window.hh --- mln/core/w_window.hh (revision 1044) +++ mln/core/w_window.hh (working copy) @@ -62,21 +62,21 @@ /// Dpoint associated type. typedef D dpoint; - /// Point_Iterator type to browse the points of a generic w_window. + + /// Point_Iterator type to browse (forward) the points of a generic w_window. typedef with_w_< dpoints_fwd_piter<D>, W > fwd_qiter; - /// Point_Iterator type to browse the points of a generic w_window. + /// Point_Iterator type to browse (backward) the points of a generic w_window. typedef with_w_< dpoints_bkd_piter<D>, W > bkd_qiter; /// Constructor without argument. w_window_(); - /// Give the corresponding window. - const window_<D>& window() const; - /// Give the symmetrical w_window. - w_window_<D,W> sym_() const; + /// Insert a delta-point \p d and its associated weight \p w. + w_window_<D,W>& insert(const D& d, const W& w); + /// Give the \p i-th weight. W weight(unsigned i) const; @@ -84,17 +84,22 @@ /// Give access to the vector of weights. const std::vector<W>& weights() const; + + // Give the \p i-th delta-point. + const D& dp(unsigned i) const; + + /// Give the number of delta-points. + unsigned ndpoints() const; + /// Give access to the vector of delta-points. const std::vector<D>& vect() const; - /// Insert a delta-point \p d and its associated weight \p w. - w_window_<D,W>& insert(const D& d, const W& w); + /// Give the corresponding window. + const window_<D>& window() const; - /// Give the number of elements (pairs of delta-point/weight). - unsigned nelements() const; - // FIXME: Rename as dpoint(i); same in mln/core/dpoints_pixter.hh:174. - const D& element(unsigned i) const; + /// Give the symmetrical w_window. + w_window_<D,W> sym_() const; protected: @@ -154,7 +159,7 @@ std::ostream& operator<<(std::ostream& ostr, const w_window_<D,W>& wwin) { ostr << '['; - for (unsigned i = 0; i < wwin.window().nelements(); ++i) + for (unsigned i = 0; i < wwin.window().ndpoints(); ++i) ostr << wwin.vect()[i] << ':' << wwin.weight(i) << ' '; return ostr << ']'; } @@ -172,34 +177,34 @@ } template <typename D, typename W> - const std::vector<D>& - w_window_<D,W>::vect() const + const D& + w_window_<D,W>::dp(unsigned i) const { - return win_.vect(); + mln_precondition(i < win_.ndpoints()); + mln_invariant(wei_.size() = win_.ndpoints()); + return win_.dp(i); } template <typename D, typename W> - const std::vector<W>& - w_window_<D,W>::weights() const + unsigned + w_window_<D,W>::ndpoints() const { - return wei_; + mln_invariant(wei_.size() = win_.ndpoints()); + return win_.ndpoints(); } template <typename D, typename W> - unsigned - w_window_<D,W>::nelements() const + const std::vector<D>& + w_window_<D,W>::vect() const { - mln_invariant(wei_.size() = win_.nelements()); - return win_.nelements(); + return win_.vect(); } template <typename D, typename W> - const D& - w_window_<D,W>::element(unsigned i) const + const std::vector<W>& + w_window_<D,W>::weights() const { - mln_precondition(i < wei_.size()); - mln_invariant(wei_.size() = win_.nelements()); - return win_.element(i); + return wei_; } template <typename D, typename W> @@ -207,7 +212,7 @@ w_window_<D,W>::weight(unsigned i) const { mln_precondition(i < wei_.size()); - mln_invariant(wei_.size() = win_.nelements()); + mln_invariant(wei_.size() = win_.ndpoints()); return wei_[i]; } @@ -215,24 +220,27 @@ w_window_<D,W>& w_window_<D,W>::insert(const D& d, const W& w) { + mln_invariant(wei_.size() = win_.ndpoints()); + if (win_.has(d)) // no-op return *this; // memorization: d_i -> w_i std::map<D, W> memo_wei_; - for (unsigned i = 0; i < win_.nelements(); ++i) - memo_wei_[win_.element(i)] = wei_[i]; + for (unsigned i = 0; i < win_.ndpoints(); ++i) + memo_wei_[win_.dp(i)] = wei_[i]; // insertion of d and w: win_.insert(d); memo_wei_[d] = w; // re-mapping: w_i <- d_i - wei_.resize(win_.nelements()); - for (unsigned i = 0; i < win_.nelements(); ++i) - wei_[i] = memo_wei_[win_.element(i)]; + wei_.resize(win_.ndpoints()); + for (unsigned i = 0; i < win_.ndpoints(); ++i) + wei_[i] = memo_wei_[win_.dp(i)]; + mln_invariant(wei_.size() = win_.ndpoints()); return *this; } @@ -241,7 +249,8 @@ w_window_<D,W> w_window_<D,W>::sym_() const { - // FIXME + w_window_<D,W> tmp(*this); + tmp.win_ = - this->win_; return *this; } Index: mln/core/window.hh --- mln/core/window.hh (revision 1044) +++ mln/core/window.hh (working copy) @@ -35,13 +35,11 @@ # include <mln/core/concept/window.hh> # include <mln/core/concept/generalized_point.hh> -# include <mln/core/internal/set_of.hh> +# include <mln/core/internal/dpoints_base.hh> # include <mln/core/dpoint.hh> # include <mln/core/box.hh> # include <mln/convert/to_dpoint.hh> -# include <mln/fun/i2v/all.hh> -# include <mln/norm/infty.hh> namespace mln @@ -58,14 +56,11 @@ * parameter is \c D, type of delta-point. */ template <typename D> - struct window_ : public Window< window_<D> >, - public internal::set_of_<D> + class window_ : public Window< window_<D> >, + public internal::dpoints_base_<D, window_<D> > { - /// Point associated type. - typedef mln_point(D) point; - - /// Dpoint associated type. - typedef D dpoint; + typedef internal::dpoints_base_<D, window_<D> > super_; + public: /*! \brief Point_Iterator type to browse the points of a generic window * w.r.t. the ordering of delta-points. @@ -75,11 +70,7 @@ /*! \brief Point_Iterator type to browse the points of a generic window * w.r.t. the reverse ordering of delta-points. */ - typedef internal::fixme bkd_qiter; - - /*! \brief Same as fwd_qiter. - */ - typedef fwd_qiter qiter; + typedef dpoints_bkd_piter<D> bkd_qiter; /*! \brief Constructor without argument. @@ -88,27 +79,20 @@ */ window_(); - /*! \brief Test if the window is centered. - * - * \return True if the delta-point 0 belongs to the window. - */ - bool is_centered() const; /*! \brief Test if the window is symmetric. */ bool is_symmetric() const; - /*! \brief Give the maximum coordinate gap between the window - center and a window point. - */ - unsigned delta() const; + /// Insert a delta-point \p dp. + window_<D>& insert(const D& dp); /// Give the symmetrical window. window_<D> sym_() const; protected: - box_<point> b_; + box_<mln_point(D)> b_; }; @@ -142,30 +126,18 @@ } template <typename D> - bool window_<D>::is_centered() const - { - static const D origin = all(0); - return this->has(origin); - } - - template <typename D> bool window_<D>::is_symmetric() const { return this->sym_() = *this; } template <typename D> - unsigned window_<D>::delta() const + window_<D>& + window_<D>::insert(const D& dp) { - unsigned d = 0; - const unsigned n = this->nelements(); - for (unsigned i = 0; i < n; ++i) - { - unsigned dd = norm::infty(this->element(i).to_vec()); - if (dd > d) - d = dd; - } - return d; + mln_precondition(! has(dp)); + this->super_::insert(dp); + return *this; } template <typename D> @@ -173,12 +145,13 @@ window_<D>::sym_() const { window_<D> tmp; - const unsigned n = this->nelements(); + const unsigned n = this->ndpoints(); for (unsigned i = 0; i < n; ++i) - tmp.insert(- this->element(i)); + tmp.insert(- this->dp(i)); return tmp; } + // operators template <typename W> Index: mln/core/dpoints_pixter.hh --- mln/core/dpoints_pixter.hh (revision 1044) +++ mln/core/dpoints_pixter.hh (working copy) @@ -170,12 +170,12 @@ void dpoints_fwd_pixter<I>::init_(const Dps& dps) { - for (unsigned i = 0; i < dps.nelements(); ++i) - offset_.push_back(this->image_.offset(dps.element(i))); + for (unsigned i = 0; i < dps.ndpoints(); ++i) + offset_.push_back(this->image_.offset(dps.dp(i))); // offset_[0] is absolute // other offsets are relative: - if (dps.nelements() > 1) - for (unsigned i = dps.nelements() - 1; i > 0; --i) + if (dps.ndpoints() > 1) + for (unsigned i = dps.ndpoints() - 1; i > 0; --i) offset_[i] -= offset_[i - 1]; invalidate(); } Index: mln/core/internal/dpoints_base.hh --- mln/core/internal/dpoints_base.hh (revision 0) +++ mln/core/internal/dpoints_base.hh (revision 0) @@ -0,0 +1,166 @@ +// 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_INTERNAL_DPOINTS_BASE_HH +# define MLN_CORE_INTERNAL_DPOINTS_BASE_HH + +/*! \file mln/core/internal/dpoints_base_.hh + * + * \brief Definition of a base class for classes based on a set of dpoints. + */ + +# include <mln/core/internal/set_of.hh> +# include <mln/fun/i2v/all.hh> +# include <mln/norm/infty.hh> + + +namespace mln +{ + + namespace internal + { + + + /*! \brief FIXME. + */ + template <typename D, typename E> + class dpoints_base_ : protected internal::set_of_<D> + { + typedef internal::set_of_<D> super_; + public: + + /// Point associated type. + typedef mln_point(D) point; + + /// Dpoint associated type. + typedef D dpoint; + + + /*! \brief Test if the window is centered. + * + * \return True if the delta-point 0 belongs to the window. + */ + bool is_centered() const; + + /*! \brief Test if the window is empty (null size; no delta-point). + */ + bool is_empty() const; + + /*! \brief Give the maximum coordinate gap between the window + center and a window point. + */ + unsigned delta() const; + + /// Give the number of delta-points. + unsigned ndpoints() const; + + /// Test if the delta-point \p dp belongs to the window. + bool has(const D& dp) const; + + // Give the \p i-th delta-point. + const D& dp(unsigned i) const; + + // Give the vector of delta-points. + const std::vector<D>& vect() const; + + protected: + dpoints_base_(); + }; + + + +# ifndef MLN_INCLUDE_ONLY + + template <typename D, typename E> + dpoints_base_<D,E>::dpoints_base_() + { + } + + template <typename D, typename E> + bool dpoints_base_<D,E>::is_centered() const + { + static const D origin = all(0); + return this->super_::has(origin); + } + + template <typename D, typename E> + bool dpoints_base_<D,E>::is_empty() const + { + return this->super_::is_empty(); + } + + template <typename D, typename E> + unsigned dpoints_base_<D,E>::delta() const + { + unsigned d = 0; + const unsigned n = ndpoints(); + for (unsigned i = 0; i < n; ++i) + { + unsigned dd = norm::infty(dp(i).to_vec()); + if (dd > d) + d = dd; + } + return d; + } + + template <typename D, typename E> + unsigned + dpoints_base_<D,E>::ndpoints() const + { + return this->super_::nelements(); + } + + template <typename D, typename E> + const D& + dpoints_base_<D,E>::dp(unsigned i) const + { + mln_precondition(i < ndpoints()); + return this->element(i); + } + + template <typename D, typename E> + const std::vector<D>& + dpoints_base_<D,E>::vect() const + { + return this->super_::vect(); + } + + template <typename D, typename E> + bool + dpoints_base_<D,E>::has(const D& dp) const + { + return this->super_::has(dp); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace internal + +} // end of namespace mln + + +#endif // ! MLN_CORE_INTERNAL_DPOINTS_BASE_HH Index: mln/core/concept/weighted_window.hh --- mln/core/concept/weighted_window.hh (revision 1044) +++ mln/core/concept/weighted_window.hh (working copy) @@ -50,30 +50,30 @@ struct Weighted_Window : public Object<E> { /* + typedef fwd_qiter; + typedef bkd_piter; + typedef point; typedef dpoint; - typedef fwd_qiter; - typedef bkd_qiter; - E sym_() const; */ + /// Test if the weighted window is empty; final method. bool is_empty() const { return exact(this)->window().is_empty(); } + /// Test if the weighted window is centered; final method. bool is_centered() const { return exact(this)->window().is_centered(); } - bool is_symmetric() const - { - return exact(this)->window().is_symmetric(); - } + // FIXME: Remove because too ambiguous: bool is_symmetric() const + /// Give the maximum coordinate gap. unsigned delta() const { return exact(this)->window().delta(); @@ -84,7 +84,7 @@ }; - /*! \brief Compute the symmetrical weighted_window of \p rhs. + /*! \brief Compute the symmetrical weighted window of \p rhs. * * \relates mln::Weighted_Window */ Index: mln/core/concept/doc/weighted_window.hh --- mln/core/concept/doc/weighted_window.hh (revision 0) +++ mln/core/concept/doc/weighted_window.hh (revision 0) @@ -0,0 +1,83 @@ +// 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 mln/core/concept/doc/weighted_window.hh + * \brief This file documents the concept of mln::Weighted_Window. + */ + +namespace mln +{ + + namespace doc + { + + /*! \brief Documentation class for mln::Weighted_Window. + * + * A weighted_window is the definition of a set of points located + * around a central point, with a weight associated to each point. + * + * \see mln::Weighted_Window + */ + template <typename E> + struct Weighted_Window : public Object<E> + { + + /*! \brief Point_Iterator type associated to this weighted_window to browse its + * points in a forward way. + */ + typedef void fwd_qiter; + + /*! \brief Point_Iterator type associated to this weighted_window to browse its + * points in a backward way. + */ + typedef void bkd_qiter; + + /*! \brief Test if the weighted window is empty. + * + * A weighted_window of null size is empty. + */ + bool is_empty() const; + + /*! \brief Test if the weighted_window is centered. + * + * A weighted window is centered is the origin belongs to it. + */ + bool is_centered() const; + + /*! \brief Give the maximum coordinate gap between the window + center and a window point. + */ + unsigned delta() const; + + /*! \brief Give the symmetrical weighted_window. + */ + E sym_() const; + }; + + } // end of namespace mln::doc + +} // end of namespace mln Index: mln/core/win/vline2d.hh --- mln/core/win/vline2d.hh (revision 1044) +++ mln/core/win/vline2d.hh (working copy) @@ -34,7 +34,7 @@ */ # include <mln/core/concept/window.hh> -# include <mln/core/internal/set_of.hh> +# include <mln/core/internal/dpoints_base.hh> # include <mln/core/dpoint2d.hh> # include <mln/core/dpoints_piter.hh> @@ -57,7 +57,7 @@ * is defined with length = 5. */ struct vline2d : public Window< vline2d >, - public mln::internal::set_of_<dpoint2d> + public internal::dpoints_base_< dpoint2d, vline2d > { /// Point associated type. typedef point2d point; Index: mln/core/win/hline2d.hh --- mln/core/win/hline2d.hh (revision 1044) +++ mln/core/win/hline2d.hh (working copy) @@ -34,7 +34,7 @@ */ # include <mln/core/concept/window.hh> -# include <mln/core/internal/set_of.hh> +# include <mln/core/internal/dpoints_base.hh> # include <mln/core/dpoint2d.hh> # include <mln/core/dpoints_piter.hh> @@ -55,7 +55,7 @@ * is defined with length = 5. */ struct hline2d : public Window< hline2d >, - public mln::internal::set_of_<dpoint2d> + public internal::dpoints_base_< dpoint2d, hline2d > { /// Point associated type. typedef point2d point; Index: mln/core/win/rectangle2d.hh --- mln/core/win/rectangle2d.hh (revision 1044) +++ mln/core/win/rectangle2d.hh (working copy) @@ -34,7 +34,7 @@ */ # include <mln/core/concept/window.hh> -# include <mln/core/internal/set_of.hh> +# include <mln/core/internal/dpoints_base.hh> # include <mln/core/dpoint2d.hh> # include <mln/core/dpoints_piter.hh> @@ -57,7 +57,7 @@ * is defined with height = 3 and width = 5. */ struct rectangle2d : public Window< rectangle2d >, - public mln::internal::set_of_<dpoint2d> + public internal::dpoints_base_< dpoint2d, rectangle2d > { /// Point associated type. typedef point2d point; @@ -75,9 +75,6 @@ */ typedef dpoints_bkd_piter<dpoint2d> bkd_qiter; - /*! \brief Same as fwd_qiter. - */ - typedef fwd_qiter qiter; /*! \brief Constructor. * @@ -88,6 +85,7 @@ */ rectangle2d(unsigned height, unsigned width); + /*! \brief Test if the window is centered. * * \return True.