
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Misc fixes. * mln/core/window.hh: Layout doc. * mln/core/internal/window_base.hh: Typo. * mln/core/internal/site_relative_iterator_base.hh (is_valid_, invalidate_): Remove decls; meaningless. * mln/core/internal/site_iterator_base.hh (s_): Fix missing initialization in ctor without arg. * mln/core/dpsites_piter.hh (dpsites_fwd_piter, dpsites_bkd_piter): New ctor overload. * mln/core/init.hh: Fix missing exact. * mln/core/image2d.hh (coord): Reactivate. * mln/accu/pair.hh (first, second): New methods. * mln/make/neighb2d.hh: Fix missing mln::. * mln/pw/var.hh (var_): New ctor overload. * mln/win/rectangle2d.hh: Revamp. * mln/util/index.hh (dim): New; required for window<D>. * sandbox/geraud/win_fun.hh: New. * sandbox/geraud/win_fun.cc: New. mln/accu/pair.hh | 21 ++- mln/core/dpsites_piter.hh | 16 ++ mln/core/image2d.hh | 3 mln/core/init.hh | 4 mln/core/internal/site_iterator_base.hh | 1 mln/core/internal/site_relative_iterator_base.hh | 6 mln/core/internal/window_base.hh | 4 mln/core/window.hh | 13 + mln/make/neighb2d.hh | 4 mln/pw/var.hh | 18 ++ mln/util/index.hh | 7 + mln/win/rectangle2d.hh | 63 ++++----- sandbox/geraud/win_fun.cc | 160 +++++++++++++++++++++++ sandbox/geraud/win_fun.hh | 160 +++++++++++++++++++++++ 14 files changed, 428 insertions(+), 52 deletions(-) Index: mln/core/window.hh --- mln/core/window.hh (revision 2083) +++ mln/core/window.hh (working copy) @@ -78,12 +78,14 @@ */ bool is_centered() const; - /*! \brief Test if the window is symmetric. + /*! Test if the window is symmetric. + * + * \return True if for every dp of this window, -dp is also in + * this window. */ bool is_symmetric() const; - /*! Apply a central symmetry to the target window. - */ + /// Apply a central symmetry to the target window. void sym(); @@ -125,7 +127,7 @@ /// \{ Insertion of a delta-point with different numbers of /// arguments (coordinates) w.r.t. the dimension. - window<D>& insert(const mln_coord(D)& dind); // For 1D. + window<D>& insert(const mln_coord(D)& dind); // For 1D or index access. window<D>& insert(const mln_coord(D)& drow, const mln_coord(D)& dcol); // For 2D. @@ -135,7 +137,8 @@ const mln_coord(D)& dcol); // For 3D. /// \} - /// Give the vector of delta-points. + + /// Give the std vector of delta-points. const std::vector<D>& std_vector() const; /// Hook to the set of D. Index: mln/core/internal/window_base.hh --- mln/core/internal/window_base.hh (revision 2083) +++ mln/core/internal/window_base.hh (working copy) @@ -67,9 +67,9 @@ # ifndef MLN_INCLUDE_ONLY - template <typename S, typename E> + template <typename D, typename E> inline - window_base<S,E>::window_base() + window_base<D,E>::window_base() { } Index: mln/core/internal/site_relative_iterator_base.hh --- mln/core/internal/site_relative_iterator_base.hh (revision 2083) +++ mln/core/internal/site_relative_iterator_base.hh (working copy) @@ -67,12 +67,6 @@ template <typename P> void center_at(const P& c); - /// Test the iterator validity. - bool is_valid_() const; - - /// Invalidate the iterator. - void invalidate_(); - /// Start an iteration. void start_(); Index: mln/core/internal/site_iterator_base.hh --- mln/core/internal/site_iterator_base.hh (revision 2083) +++ mln/core/internal/site_iterator_base.hh (working copy) @@ -109,6 +109,7 @@ template <typename S, typename E> inline site_iterator_base<S, E>::site_iterator_base() + : s_(0) { } Index: mln/core/dpsites_piter.hh --- mln/core/dpsites_piter.hh (revision 2083) +++ mln/core/dpsites_piter.hh (working copy) @@ -61,6 +61,9 @@ template <typename P> dpsites_fwd_piter(const V& v, const P& c); + /// Constructor without argument. + dpsites_fwd_piter(); + /// Test the iterator validity. bool is_valid_() const; @@ -102,6 +105,9 @@ template <typename P> dpsites_bkd_piter(const V& v, const P& c); + /// Constructor without argument. + dpsites_bkd_piter(); + /// Test the iterator validity. bool is_valid_() const; @@ -129,6 +135,11 @@ // Forward. + template <typename V> + inline + dpsites_fwd_piter<V>::dpsites_fwd_piter() + { + } template <typename V> template <typename P> @@ -182,6 +193,11 @@ // Backward. + template <typename V> + inline + dpsites_bkd_piter<V>::dpsites_bkd_piter() + { + } template <typename V> template <typename P> Index: mln/core/init.hh --- mln/core/init.hh (revision 2083) +++ mln/core/init.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -78,7 +78,7 @@ inline void init_(tag::bbox_t, B& b, const Image<I>& ima) { - b = geom::bbox(ima.domain()); + b = geom::bbox(exact(ima).domain()); } template <typename I> Index: mln/core/image2d.hh --- mln/core/image2d.hh (revision 2083) +++ mln/core/image2d.hh (working copy) @@ -122,6 +122,9 @@ template <typename T> struct image2d : public internal::image_primary< box2d, image2d<T> > { + /// Coordinate associated type. + typedef int coord; + /// Value associated type. typedef T value; Index: mln/accu/pair.hh --- mln/accu/pair.hh (revision 2083) +++ mln/accu/pair.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -75,6 +75,9 @@ result to_result() const; void get_result(result_1& r1, result_2& r2) const; + result_1 first() const; + result_2 second() const; + protected: A1 a1_; @@ -161,6 +164,22 @@ r2 = a2_.to_result(); } + template <typename A1, typename A2, typename T> + inline + result_1 + pair_<A1,A2,T>::first()const + { + return a1_.to_result(); + } + + template <typename A1, typename A2, typename T> + inline + result_2 + pair_<A1,A2,T>::second() const + { + return a2_.to_result(); + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu Index: mln/make/neighb2d.hh --- mln/make/neighb2d.hh (revision 2083) +++ mln/make/neighb2d.hh (working copy) @@ -76,7 +76,7 @@ enum { h = mlc_sqrt_int(S) / 2 }; mlc_bool((2 * h + 1) * (2 * h + 1) == S)::check(); mln::window2d win = make::window2d(values); - neighb2d tmp(win); + mln::neighb2d tmp(win); return tmp; } @@ -88,7 +88,7 @@ mlc_bool(R % 2 == 1)::check(); mlc_bool(C % 2 == 1)::check(); mln::window2d win = make::window2d(values); - neighb2d tmp(win); + mln::neighb2d tmp(win); return tmp; } Index: mln/pw/var.hh --- mln/pw/var.hh (revision 2083) +++ mln/pw/var.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -49,13 +49,15 @@ { typedef V result; + var_(); + var_(const V& v); template <typename P> const V& operator()(const P&) const; private: - const V& v_; + const V* v_; }; @@ -69,8 +71,15 @@ template <typename V> inline + var_<V>::var_() + : v_(0) + { + } + + template <typename V> + inline var_<V>::var_(const V& v) - : v_(v) + : v_(&v) { } @@ -80,7 +89,8 @@ const V& var_<V>::operator()(const P&) const { - return v_; + mln_precondition(v_ != 0); + return *v_; } // pw::var(v) Index: mln/win/rectangle2d.hh --- mln/win/rectangle2d.hh (revision 2083) +++ mln/win/rectangle2d.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -31,12 +31,11 @@ /*! \file mln/win/rectangle2d.hh * * \brief Definition of the mln::win::rectangle2d window. + * + * \todo Reactivate includes at EOF. */ -# include <mln/core/concept/window.hh> -# include <mln/core/internal/dpoints_base.hh> -# include <mln/core/dpoint2d.hh> -# include <mln/core/dpoints_piter.hh> +# include <mln/core/window.hh> namespace mln @@ -56,27 +55,20 @@ * o o o o o \n * is defined with height = 3 and width = 5. */ - struct rectangle2d : public Window< rectangle2d >, - public internal::dpoints_base_< dpoint2d, rectangle2d > + struct rectangle2d : public internal::window_base< dpoint2d, rectangle2d > { - /// Point Site associated type. - typedef point2d psite; - - /// Point associated type. - typedef point2d point; - - /// Dpoint associated type. - typedef dpoint2d dpoint; /*! \brief Site_Iterator type to browse a rectangle such as: "for each row * (increasing), for each column (increasing)." */ - typedef dpoints_fwd_piter<dpoint2d> fwd_qiter; + typedef dpsites_fwd_piter<rectangle2d> fwd_qiter; /*! \brief Site_Iterator type to browse a rectangle such as: "for each row * (decreasing), for each column (decreasing)." */ - typedef dpoints_bkd_piter<dpoint2d> bkd_qiter; + typedef dpsites_fwd_piter<rectangle2d> bkd_qiter; + + typedef fwd_qiter qiter; /*! \brief Constructor. @@ -101,16 +93,13 @@ */ bool is_symmetric() const; - /*! \brief Give the rectangle height. - */ + /// Give the rectangle height. unsigned height() const; - /*! \brief Give the rectangle width. - */ + /// Give the rectangle width. unsigned width() const; - /*! \brief Give the rectangle area. - */ + /// Give the rectangle area. unsigned area() const; /*! \brief Give the maximum coordinate gap between the window @@ -118,11 +107,17 @@ */ unsigned delta() const; - /// Apply a central symmetry to the target window. - rectangle2d& sym(); + /// Apply a central symmetry to the target window; a no-op here. + void sym(); + + + /// Give the std vector of delta-points. + const std::vector<dpoint2d>& std_vector() const; protected: + unsigned height_, width_; + window2d win_; }; @@ -151,7 +146,7 @@ const int drow = height / 2, dcol = width / 2; for (int row = - drow; row <= drow; ++row) for (int col = - dcol; col <= dcol; ++col) - insert(make::dpoint2d(row, col)); + win_.insert(row, col); } inline @@ -191,9 +186,17 @@ } inline - rectangle2d& rectangle2d::sym() + void + rectangle2d::sym() + { + // No-op. + } + + inline + const std::vector<dpoint2d>& + rectangle2d::std_vector() const { - return *this; + return win_.std_vector(); } inline @@ -212,8 +215,8 @@ // When rectangle2d is involved, one surely also wants: -# include <mln/win/hline2d.hh> -# include <mln/win/vline2d.hh> +// # include <mln/win/hline2d.hh> +// # include <mln/win/vline2d.hh> #endif // ! MLN_WIN_RECTANGLE2D_HH Index: mln/util/index.hh --- mln/util/index.hh (revision 2083) +++ mln/util/index.hh (working copy) @@ -31,6 +31,9 @@ /*! \file mln/util/index.hh * * \brief Definition of an "index" type. + * + * \todo Remove coord and dim, then make window<dindex> work. + */ # include <mln/core/concept/object.hh> @@ -53,7 +56,9 @@ struct index_ // : public Object< index_<Tag> > { typedef dindex_<Tag> dpsite; + typedef int coord; + enum { dim = 1 }; int i_; @@ -71,7 +76,9 @@ { typedef index_<Tag> psite; typedef index_<Tag> site; + typedef int coord; + enum { dim = 1 }; int i_; Index: sandbox/geraud/win_fun.hh --- sandbox/geraud/win_fun.hh (revision 0) +++ sandbox/geraud/win_fun.hh (revision 0) @@ -0,0 +1,160 @@ +// Copyright (C) 2008 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 infun 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_WIN_FUN_HH +# define MLN_WIN_FUN_HH + +/*! \file mln/win/fun.hh + * + * \brief Definition of the mln::win::fun window. + */ + +# include <mln/core/internal/window_base.hh> +# include <mln/core/internal/site_relative_iterator_base.hh> + + +namespace mln +{ + + namespace win + { + + // Fwd decl. + template <typename F> class fun_piter; + + + /*! \brief Window defined by a function. + */ + template <typename F> + struct fun : public internal::window_base< mln_deduce(F, result, dpsite), + fun<F> > + { + + /// Site_Iterator type to browse a fun forward + typedef fun_piter<F> fwd_qiter; + + /// Site_Iterator type to browse a fun backward + typedef fun_piter<F> bkd_qiter; + + /// Same as fwd_qiter + typedef fwd_qiter qiter; + + /// Constructor. + fun(const F& f) : f(f) {} + + /// Test if the window is centered. + bool is_centered() const { return false; } + + /// Test if the window is empty. + bool is_empty() const { return false; } + + /// Test if the window is symmetric. + bool is_symmetric() const { return false; } + + /// Give the maximum coordinate gap between the window + unsigned delta() const { return 100; } // FIXME + + /// Apply a central symmetry to the target window. + void sym() {} + + const F& f; + }; + + + template <typename F> + class fun_piter + : public internal::site_relative_iterator_base< fun<F>, + fun_piter<F> > + { + public: + + typedef mln_result(F) W; + + /// Constructor. + template <typename P> + fun_piter(const fun<F>& win, const P& c) + : f_(win.f) + { + q_.center_at(c); + this->change_target(win); + this->center_at(c); + } + + /// Test the iterator validity. + bool is_valid_() const + { + return this->c_ != 0 && q_.is_valid(); + } + + /// Invalidate the iterator. + void invalidate_() + { + q_.invalidate(); + } + + /// Start an iteration. + void do_start_() + { + q_.change_target(f_(*this->c_)); + q_.start(); + } + + /// Go to the next point. + void do_next_() + { + q_.next(); + } + + /// Compute the current psite. + mln_psite(W) compute_p_() const + { + return q_; + } + + protected: + + const F& f_; + mln_fwd_qiter(W) q_; + }; + + +# ifndef MLN_INCLUDE_ONLY + + // FIXME: Move code here. + + // MEMO: mln_fwd_qiter(mln_result(F)) + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::win + +} // end of namespace mln + + + +#endif // ! MLN_WIN_FUN_HH Index: sandbox/geraud/win_fun.cc --- sandbox/geraud/win_fun.cc (revision 0) +++ sandbox/geraud/win_fun.cc (revision 0) @@ -0,0 +1,160 @@ +# include <mln/core/image2d.hh> +# include <mln/core/window2d.hh> +# include <mln/win/rectangle2d.hh> +# include <mln/win/fun.hh> + +# include <mln/debug/iota.hh> +# include <mln/debug/println.hh> + + +// # include <mln/morpho/gradient.bis.hh> +// # include <mln/morpho/erosion.bis.hh> + +// # include <mln/value/int_u8.hh> +// # include <mln/io/pgm/load.hh> +// # include <mln/io/pgm/save.hh> + + +template <typename I, typename W, typename P> +void picture(const I& ima, const W& win, const P& p) +{ + std::cout << ima(p) << ": "; + mln_qiter(W) q(win, p); + for_all(q) + if (ima.has(q)) + std::cout << ima(q) << ' '; + else + std::cout << "- "; + std::cout << std::endl; +} + + + +struct uni_t +{ + typedef mln::window2d result; + mln::window2d win_; + uni_t() { win_.insert(-1,0).insert(0,-1); } + const mln::window2d& operator()(const mln::point2d& p) const { return win_; } +} uni; + + +struct bi_t +{ + typedef mln::window2d result; + mln::window2d win1_, win2_; + bi_t() { + win1_.insert(-1,0).insert(0,-1); + win2_.insert( 1,0).insert(0, 1); + } + const mln::window2d& operator()(const mln::point2d& p) const { + return p.col() % 2 ? win1_ : win2_; + } +} bi; + + +struct bi_rect_t +{ + typedef mln::win::rectangle2d result; + result *win1_, *win2_; + bi_rect_t() { + win1_ = new result(1,3); + win2_ = new result(3,1); + } + const result& operator()(const mln::point2d& p) const { + return p.row() % 2 ? *win1_ : *win2_; + } +} bi_rect; + + +// template <typename T> +// struct grad_t +// { +// typedef mln::win::rectangle2d result; +// mln::image2d<T> grad_; +// std::vector<result*> win_; + +// grad_t(const mln::image2d<T>& gr) +// { +// grad_ = gr; +// for (unsigned i = 0; i < 10; ++i) +// { +// unsigned l = i % 2 ? i : i + 1; +// win_.push_back(new result(l, l)); +// } +// } +// const result& operator()(const mln::point2d& p) const { +// float s = 1.f - grad_(p) / 256.f; +// s *= s * s; +// return * win_[unsigned(s * 9)]; +// } +// }; + + + + +int main() +{ + using namespace mln; + + typedef image2d<unsigned> I; + I ima(2, 3, 0); // no border + debug::iota(ima); + debug::println(ima); + + + { + win::fun<uni_t> win(uni); + mln_fwd_piter_(I) p(ima.domain()); + for_all(p) + picture(ima, win, p); + std::cout << std::endl; + } + + { + win::fun<bi_t> win(bi); + mln_fwd_piter_(I) p(ima.domain()); + for_all(p) + picture(ima, win, p); + std::cout << std::endl; + } + + { + win::rectangle2d rect(3, 3); + mln_fwd_piter_(I) p(ima.domain()); + for_all(p) + picture(ima, rect, p); + std::cout << std::endl; + } + + { + win::fun<bi_rect_t> win(bi_rect); + mln_fwd_piter_(I) p(ima.domain()); + for_all(p) + picture(ima, win, p); + std::cout << std::endl; + } + + + +// { +// using value::int_u8; +// image2d<int_u8> ima(2, 2); +// // io::pgm::load(ima, "small.pgm"); + +// window2d c4p; +// c4p.insert(-1,0).insert(0,-1).insert(0,0).insert(0,1).insert(1,0); + +// grad_t<int_u8> f(morpho::gradient(ima, c4p)); +// win::fun< grad_t<int_u8> > win(f); + +// image2d<int_u8> ero = morpho::erosion(ima, win); +// // io::pgm::save(ero, "ero.pgm"); + +// mln_fwd_piter_(I) p(ima.domain()); +// for_all(p) +// picture(ima, win, p); +// std::cout << std::endl; +// } + +}