
https://svn.lrde.epita.fr/svn/oln/trunk Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add milena neighborhood. * milena/test/main.cc: Update. * milena/core/neighb2d.hh: New. * milena/core/neighb.hh: New. * milena/core/concept/neighborhood.hh: New. * milena/core/dpoints_qiter.hh: Rename as... * milena/core/dpoints_piter.hh: ...this. * milena/core/internal/set_of.hh (operator<<): New; factor code. * milena/core/rectangle2d.hh: Update. * milena/core/window.hh: Update. core/concept/neighborhood.hh | 39 +++++++++++++++++++++ core/dpoints_piter.hh | 28 +++++++-------- core/internal/set_of.hh | 15 ++++++++ core/neighb.hh | 56 ++++++++++++++++++++++++++++++ core/neighb2d.hh | 79 +++++++++++++++++++++++++++++++++++++++++++ core/rectangle2d.hh | 6 +-- core/window.hh | 25 ++----------- test/main.cc | 5 ++ 8 files changed, 216 insertions(+), 37 deletions(-) Index: milena/test/main.cc --- milena/test/main.cc (revision 985) +++ milena/test/main.cc (working copy) @@ -7,6 +7,8 @@ #include <core/window2d.hh> #include <core/rectangle2d.hh> +#include <core/neighb2d.hh> + #include <morpho/erosion.hh> @@ -29,6 +31,8 @@ 0, 1, 0, 1, 0, 0 }; window2d win = mk_window2d(w); + std::cout << win << std::endl; + std::cout << c8() << std::endl; /* { @@ -56,4 +60,5 @@ image2d<int> ima2 = morpho::erosion(ima, win); debug::println(ima2); } + } Index: milena/core/neighb2d.hh --- milena/core/neighb2d.hh (revision 0) +++ milena/core/neighb2d.hh (revision 0) @@ -0,0 +1,79 @@ +#ifndef MLN_CORE_NEIGHB2D_HH +# define MLN_CORE_NEIGHB2D_HH + +# include <cmath> +# include <core/neighb.hh> +# include <core/dpoint2d.hh> + + +namespace mln +{ + + typedef neighb_<dpoint2d> neighb2d; + + const neighb2d& c4(); + const neighb2d& c8(); + const neighb2d& c2_row(); + const neighb2d& c2_col(); + + +# ifndef MLN_INCLUDE_ONLY + + const neighb2d& c4() + { + static bool flower = true; + static neighb2d it; + if (flower) + { + it.insert(mk_dpoint2d(0, 1)); + it.insert(mk_dpoint2d(1, 0)); + flower = false; + } + return it; + } + + const neighb2d& c8() + { + static bool flower = true; + static neighb2d it; + if (flower) + { + it.insert(mk_dpoint2d(0, 1)); + it.insert(mk_dpoint2d(1,-1)); + it.insert(mk_dpoint2d(1, 0)); + it.insert(mk_dpoint2d(1, 1)); + flower = false; + } + return it; + } + + const neighb2d& c2_row() + { + static bool flower = true; + static neighb2d it; + if (flower) + { + it.insert(mk_dpoint2d(0, 1)); + flower = false; + } + return it; + } + + const neighb2d& c2_col() + { + static bool flower = true; + static neighb2d it; + if (flower) + { + it.insert(mk_dpoint2d(1, 0)); + flower = false; + } + return it; + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_NEIGHB2D_HH Index: milena/core/dpoints_piter.hh --- milena/core/dpoints_piter.hh (revision 985) +++ milena/core/dpoints_piter.hh (working copy) @@ -1,5 +1,5 @@ -#ifndef MLN_CORE_DPOINTS_QITER_HH -# define MLN_CORE_DPOINTS_QITER_HH +#ifndef MLN_CORE_DPOINTS_PITER_HH +# define MLN_CORE_DPOINTS_PITER_HH # include <core/concept/piter.hh> # include <core/concept/genpoint.hh> @@ -9,7 +9,7 @@ { template <typename D> - class dpoints_fwd_qiter : public Piter< dpoints_fwd_qiter<D> > + class dpoints_fwd_piter : public Piter< dpoints_fwd_piter<D> > { public: @@ -21,7 +21,7 @@ typedef mln_coord(D) coord; template <typename Dps, typename Pref> - dpoints_fwd_qiter(const Dps& dps, + dpoints_fwd_piter(const Dps& dps, const GenPoint<Pref>& p_ref); operator point() const; @@ -48,7 +48,7 @@ template <typename D> template <typename Dps, typename Pref> - dpoints_fwd_qiter<D>::dpoints_fwd_qiter(const Dps& dps, + dpoints_fwd_piter<D>::dpoints_fwd_piter(const Dps& dps, const GenPoint<Pref>& p_ref) : dps_(exact(dps).vec()), p_ref_(* force_exact<Pref>(p_ref).pointer()) @@ -57,7 +57,7 @@ } template <typename D> - dpoints_fwd_qiter<D>::operator mln_point(D)() const + dpoints_fwd_piter<D>::operator mln_point(D)() const { assert(is_valid()); return p_; @@ -65,28 +65,28 @@ template <typename D> const mln_point(D)* - dpoints_fwd_qiter<D>::pointer() const + dpoints_fwd_piter<D>::pointer() const { return & p_; } template <typename D> bool - dpoints_fwd_qiter<D>::is_valid() const + dpoints_fwd_piter<D>::is_valid() const { return i_ != dps_.size(); } template <typename D> void - dpoints_fwd_qiter<D>::invalidate() + dpoints_fwd_piter<D>::invalidate() { i_ = dps_.size(); } template <typename D> void - dpoints_fwd_qiter<D>::start() + dpoints_fwd_piter<D>::start() { i_ = 0; update_p_(); @@ -94,7 +94,7 @@ template <typename D> void - dpoints_fwd_qiter<D>::next_() + dpoints_fwd_piter<D>::next_() { ++i_; update_p_(); @@ -102,7 +102,7 @@ template <typename D> void - dpoints_fwd_qiter<D>::update_p_() + dpoints_fwd_piter<D>::update_p_() { if (is_valid()) p_ = p_ref_ + dps_[i_]; @@ -110,7 +110,7 @@ template <typename D> mln_coord(D) - dpoints_fwd_qiter<D>::operator[](unsigned i) const + dpoints_fwd_piter<D>::operator[](unsigned i) const { return p_[i]; } @@ -120,4 +120,4 @@ } // end of namespace mln -#endif // ! MLN_CORE_DPOINTS_QITER_HH +#endif // ! MLN_CORE_DPOINTS_PITER_HH Index: milena/core/rectangle2d.hh --- milena/core/rectangle2d.hh (revision 985) +++ milena/core/rectangle2d.hh (working copy) @@ -4,7 +4,7 @@ # include <core/concept/window.hh> # include <core/internal/set_of.hh> # include <core/dpoint2d.hh> -# include <core/dpoints_qiter.hh> +# include <core/dpoints_piter.hh> namespace mln @@ -13,8 +13,8 @@ struct rectangle2d : public Window< rectangle2d >, public internal::set_of_<dpoint2d> { - typedef dpoints_fwd_qiter<dpoint2d> fwd_qiter; - typedef dpoints_bkd_qiter<dpoint2d> bkd_qiter; + typedef dpoints_fwd_piter<dpoint2d> fwd_qiter; + typedef dpoints_bkd_piter<dpoint2d> bkd_qiter; typedef fwd_qiter qiter; rectangle2d(unsigned half_height, unsigned half_width); Index: milena/core/neighb.hh --- milena/core/neighb.hh (revision 0) +++ milena/core/neighb.hh (revision 0) @@ -0,0 +1,56 @@ +#ifndef MLN_CORE_NEIGHB_HH +# define MLN_CORE_NEIGHB_HH + +# include <core/concept/neighborhood.hh> +# include <core/internal/set_of.hh> +# include <core/dpoint.hh> + + +namespace mln +{ + + // fwd decls + template <typename D> class dpoints_fwd_piter; + template <typename D> class dpoints_bkd_piter; + + + template <typename D> + struct neighb_ : public Neighborhood< neighb_<D> >, + public internal::set_of_<D> + { + typedef dpoints_fwd_piter<D> fwd_niter; + typedef dpoints_bkd_piter<D> bkd_niter; + typedef fwd_niter niter; + + neighb_(); + + void insert(const D& dp); + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename D> + neighb_<D>::neighb_() + { + } + + template <typename D> + void + neighb_<D>::insert(const D& dp) + { + typedef internal::set_of_<D> super; + this->super::insert( dp); + this->super::insert(-dp); + } + + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +# include <core/dpoints_piter.hh> + + +#endif // ! MLN_CORE_NEIGHB_HH Index: milena/core/concept/neighborhood.hh --- milena/core/concept/neighborhood.hh (revision 0) +++ milena/core/concept/neighborhood.hh (revision 0) @@ -0,0 +1,39 @@ +#ifndef MLN_CORE_CONCEPT_NEIGHBORHOOD_HH +# define MLN_CORE_CONCEPT_NEIGHBORHOOD_HH + +# include <core/concept/object.hh> + + +namespace mln +{ + + template <typename E> + struct Neighborhood : public Object<E> + { + /* + typedef niter; + typedef fwd_niter; + typedef bkd_niter; + */ + + protected: + Neighborhood(); + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename E> + Neighborhood<E>::Neighborhood() + { + typedef mln_niter(E) niter; + typedef mln_fwd_niter(E) fwd_niter; + typedef mln_bkd_niter(E) bkd_niter; + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_CONCEPT_NEIGHBORHOOD_HH Index: milena/core/window.hh --- milena/core/window.hh (revision 985) +++ milena/core/window.hh (working copy) @@ -10,16 +10,16 @@ { // fwd decls - template <typename D> class dpoints_fwd_qiter; - template <typename D> class dpoints_bkd_qiter; + template <typename D> class dpoints_fwd_piter; + template <typename D> class dpoints_bkd_piter; template <typename D> struct window_ : public Window< window_<D> >, public internal::set_of_<D> { - typedef dpoints_fwd_qiter<D> fwd_qiter; - typedef dpoints_bkd_qiter<D> bkd_qiter; + typedef dpoints_fwd_piter<D> fwd_qiter; + typedef dpoints_bkd_piter<D> bkd_qiter; typedef fwd_qiter qiter; window_(); @@ -28,10 +28,6 @@ bool is_symmetric() const; }; - template <typename D> - std::ostream& operator<<(std::ostream& ostr, - const window_<D>& win); - # ifndef MLN_INCLUDE_ONLY @@ -54,23 +50,12 @@ return false; } - template <typename D> - std::ostream& operator<<(std::ostream& ostr, - const window_<D>& win) - { - ostr << '['; - for (unsigned i = 0; i < win.nelements(); ++i) - ostr << win.element(i) - << (i = win.nelements() - 1 ? ']' : ','); - return ostr; - } - # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln -# include <core/dpoints_qiter.hh> +# include <core/dpoints_piter.hh> #endif // ! MLN_CORE_WINDOW_HH Index: milena/core/internal/set_of.hh --- milena/core/internal/set_of.hh (revision 985) +++ milena/core/internal/set_of.hh (working copy) @@ -36,6 +36,10 @@ }; + template <typename E> + std::ostream& operator<<(std::ostream& ostr, const set_of_<E>& s); + + # ifndef MLN_INCLUDE_ONLY template <typename E> @@ -98,6 +102,17 @@ std::copy(s_.begin(), s_.end(), std::back_inserter(v_)); } + template <typename E> + std::ostream& operator<<(std::ostream& ostr, + const set_of_<E>& s) + { + ostr << '['; + for (unsigned i = 0; i < s.nelements(); ++i) + ostr << s.element(i) + << (i = s.nelements() - 1 ? ']' : ','); + return ostr; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::internal