3197: Allow to construct 3D neighborhoods from C arrays.

https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Allow to construct 3D neighborhoods from C arrays. * mln/core/alias/neighb3d.hh: Upgrade file doc style. (from_to_): New overload. * mln/convert/from_to.hxx (from_to_): New fwd decl. * mln/make/box3d.hh (todo): New. Warning: FIX the unconsistency!!! * mln/morpho/tree/compute_attribute_image.hh: Disambiguate. convert/from_to.hxx | 17 +++++++++++ core/alias/neighb3d.hh | 51 +++++++++++++++++++++++++++++---- make/box3d.hh | 2 + morpho/tree/compute_attribute_image.hh | 2 - 4 files changed, 66 insertions(+), 6 deletions(-) Index: mln/core/alias/neighb3d.hh --- mln/core/alias/neighb3d.hh (revision 3196) +++ mln/core/alias/neighb3d.hh (working copy) @@ -1,4 +1,5 @@ // Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,16 +29,17 @@ #ifndef MLN_CORE_ALIAS_NEIGHB3D_HH # define MLN_CORE_ALIAS_NEIGHB3D_HH -/*! \file mln/core/alias/neighb3d.hh - * - * \brief Definition of the mln::neighb3d alias and of some classical - * 3D neighborhoods. - */ +/// \file mln/core/alias/neighb3d.hh +/// +/// Definition of the mln::neighb3d alias and of some classical +/// 3D neighborhoods. + # include <cmath> # include <mln/core/neighb.hh> # include <mln/core/alias/window3d.hh> # include <mln/win/sym.hh> +# include <mln/convert/from_to.hh> namespace mln @@ -105,6 +107,22 @@ + + namespace convert + { + + namespace over_load + { + + template <unsigned S> + void from_to_(const bool (&values)[S], neighb3d& nbh); + + } // end of namespace mln::convert::over_load + + } // end of namespace mln::convert + + + # ifndef MLN_INCLUDE_ONLY inline @@ -164,6 +182,29 @@ return it; } + + namespace convert + { + + namespace over_load + { + + template <unsigned S> + void + from_to_(const bool (&values)[S], neighb3d& nbh) + { + const int h = unsigned(std::pow(float(S), float(1. / 3.))) / 2; + mln_precondition((2 * h + 1) * (2 * h + 1) * (2 * h + 1) == S); + window3d win; + from_to_(values, win); + mln_precondition(win.is_neighbable_()); + nbh.change_window(win); + } + + } // end of namespace mln::convert::over_load + + } // end of namespace mln::convert + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/make/box3d.hh --- mln/make/box3d.hh (revision 3196) +++ mln/make/box3d.hh (working copy) @@ -32,6 +32,8 @@ /// \file mln/make/box3d.hh /// /// Routines to construct an mln::box3d. +/// +/// \todo Not consistent with box2d!!! # include <mln/core/alias/box3d.hh> Index: mln/convert/from_to.hxx --- mln/convert/from_to.hxx (revision 3196) +++ mln/convert/from_to.hxx (working copy) @@ -197,6 +197,14 @@ from_to_(const bool (&values)[R][C], window< dpoint<grid::square, def::coord> >& win); + + // C-array -> window3d + template <unsigned S> + void + from_to_(const bool (&values)[S], + window< dpoint<grid::cube, def::coord> >& win); + + // C-array -> neighb2d template <unsigned S> void @@ -208,6 +216,15 @@ from_to_(bool const (&values)[R][C], neighb< window< dpoint<grid::square, def::coord> > >& nbh); + + // C-array -> neighb3d + template <unsigned S> + void + from_to_(const bool (&values)[S], + neighb< window< dpoint<grid::cube, def::coord> > >& nbh); + + + // Gdpoint -> point template <typename D> void Index: mln/morpho/tree/compute_attribute_image.hh --- mln/morpho/tree/compute_attribute_image.hh (revision 3196) +++ mln/morpho/tree/compute_attribute_image.hh (working copy) @@ -102,7 +102,7 @@ acc(p).take_as_init(make::pix(t.f(), p)); } { - mln_piter(T) p(t.domain()); + mln_fwd_piter(T) p(t.domain()); // Propagate attribute from a site to its parent. for_all(p) if (! t.is_root(p))
participants (1)
-
Thierry Geraud