
* mln/geom/all.hh: Add new include. * mln/geom/translate.hh: New routine. * tests/geom/Makefile.am, * tests/geom/translate.cc: New test. --- milena/ChangeLog | 11 ++ milena/mln/geom/all.hh | 1 + milena/mln/geom/translate.hh | 159 ++++++++++++++++++++ milena/tests/geom/Makefile.am | 5 +- .../{mln/geom/all.hh => tests/geom/translate.cc} | 66 +++----- 5 files changed, 199 insertions(+), 43 deletions(-) create mode 100644 milena/mln/geom/translate.hh copy milena/{mln/geom/all.hh => tests/geom/translate.cc} (50%) diff --git a/milena/ChangeLog b/milena/ChangeLog index d2fb43a..7e12744 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,14 @@ +2009-09-15 Guillaume Lazzara <lazzara@lrde.epita.fr> + + Add geom::translate. + + * mln/geom/all.hh: Add new include. + + * mln/geom/translate.hh: New routine. + + * tests/geom/Makefile.am, + * tests/geom/translate.cc: New test. + 2009-09-14 Fabien Freling <fabien.freling@lrde.epita.fr> Disable tiled2d image support (still experimental). diff --git a/milena/mln/geom/all.hh b/milena/mln/geom/all.hh index f2d1fd3..813d164 100644 --- a/milena/mln/geom/all.hh +++ b/milena/mln/geom/all.hh @@ -68,6 +68,7 @@ namespace mln # include <mln/geom/size1d.hh> # include <mln/geom/size2d.hh> # include <mln/geom/size3d.hh> +# include <mln/geom/translate.hh> #endif // ! MLN_GEOM_ALL_HH diff --git a/milena/mln/geom/translate.hh b/milena/mln/geom/translate.hh new file mode 100644 index 0000000..334edc8 --- /dev/null +++ b/milena/mln/geom/translate.hh @@ -0,0 +1,159 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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 +/// +/// Translate an image. + +#ifndef MLN_GEOM_TRANSLATE_HH +# define MLN_GEOM_TRANSLATE_HH + +# include <mln/core/concept/image.hh> +# include <mln/core/concept/site_set.hh> +# include <mln/core/concept/box.hh> + +# include <mln/core/routine/extend.hh> + +# include <mln/core/image/imorph/tr_image.hh> + +# include <mln/data/paste.hh> + +# include <mln/fun/x2x/translation.hh> + +# include <mln/literal/zero.hh> + + +namespace mln +{ + + namespace geom + { + + /// Perform a translation from the center of an image. + /// + /// \param[in] input An image. + /// \param[in] ref The translation vector. + /// \param[in] extension Function, image or value which will be used + /// as extension. This extension allows to map + /// values to sites which where not part + /// of the domain before the translation. + /// \param[in] output_domain The domain of the output image. An + /// invalid domain, causes the routine + /// to use the translated input_ domain. + /// + /// \return An image with the same domain as \p input. + // + template <typename I, typename V, typename Ext, typename S> + mln_concrete(I) + translate(const Image<I>& input, + const algebra::vec<mln_site_(I)::dim, V>& ref, + const Ext& extension, const Site_Set<S>& output_domain); + + + /// \overload + template <typename I, typename V, typename Ext> + mln_concrete(I) + translate(const Image<I>& input, + const algebra::vec<mln_site_(I)::dim, V>& ref, + const Ext& extension); + + + /// \overload + /// Use literal::zero as default value for the extension. + template <typename I, typename V> + mln_concrete(I) + translate(const Image<I>& input, + const algebra::vec<mln_site_(I)::dim, V>& ref); + + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename I, typename V, typename Ext, typename S> + mln_concrete(I) + translate(const Image<I>& input_, + const algebra::vec<mln_site_(I)::dim, V>& ref, + const Ext& extension_, const Site_Set<S>& output_domain_) + { + trace::entering("geom::translate"); + + const I& input = exact(input_); + const S& output_domain = exact(output_domain_); + const mln_exact(Ext)& extension = exact(extension_); + mlc_converts_to(mln_exact(Ext), mln_value(I))::check(); + + mln_precondition(input.is_valid()); + mln_precondition(output_domain.is_valid()); + + point2d c = geom::bbox(input).center(); + typedef fun::x2x::translation<2,double> trans_t; + trans_t + t(ref); + + tr_image<S,I,trans_t> tr_ima(output_domain, input, t); + + mln_concrete(I) output; + initialize(output, tr_ima); + + data::paste(extend(tr_ima, extension), output); + + trace::exiting("geom::translate"); + return output; + } + + + template <typename I, typename V, typename Ext> + mln_concrete(I) + translate(const Image<I>& input, + const algebra::vec<mln_site_(I)::dim, V>& ref, + const Ext& extension) + { + // Old versions of GCC (including Apple GCC 4.0.1) do not parse + // correctly `mln_box(I)()'. Hence, we need to typedef + // `mln_box(I)' first. + typedef mln_domain(I) domain_t; + return translate(input, ref, extension, domain_t()); + } + + + template <typename I, typename V> + mln_concrete(I) + translate(const Image<I>& input, + const algebra::vec<mln_site_(I)::dim, V>& ref) + { + return translate(input, ref, literal::zero); + } + + +# endif // ! MLN_INCLUDE_ONLY + + + } // end of namespace mln::geom + +} // end of namespace mln + + +#endif // ! MLN_GEOM_TRANSLATE_HH diff --git a/milena/tests/geom/Makefile.am b/milena/tests/geom/Makefile.am index 8572a6b..16600dd 100644 --- a/milena/tests/geom/Makefile.am +++ b/milena/tests/geom/Makefile.am @@ -37,7 +37,8 @@ nslis \ pmin_pmax \ rotate \ seed2tiling \ -seed2tiling_roundness +seed2tiling_roundness \ +translate bbox_SOURCES = bbox.cc @@ -58,6 +59,6 @@ pmin_pmax_SOURCES = pmin_pmax.cc rotate_SOURCES = rotate.cc seed2tiling_SOURCES = seed2tiling.cc seed2tiling_roundness_SOURCES = seed2tiling_roundness.cc - +translate_SOURCES = translate.cc TESTS = $(check_PROGRAMS) diff --git a/milena/mln/geom/all.hh b/milena/tests/geom/translate.cc similarity index 50% copy from milena/mln/geom/all.hh copy to milena/tests/geom/translate.cc index f2d1fd3..2efd753 100644 --- a/milena/mln/geom/all.hh +++ b/milena/tests/geom/translate.cc @@ -1,5 +1,4 @@ -// Copyright (C) 2007, 2008, 2009 EPITA Research and Development -// Laboratory (LRDE) +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -24,50 +23,35 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_GEOM_ALL_HH -# define MLN_GEOM_ALL_HH +# include <mln/core/image/image2d.hh> +# include <mln/geom/translate.hh> +# include <mln/make/image.hh> +# include <mln/data/compare.hh> -/// \file -/// -/// File that includes all geometry related things. +#include <mln/debug/println.hh> - -namespace mln +int main() { + using namespace mln; - /// Namespace of all things related to geometry. - namespace geom - { - /// Implementation namespace of geom namespace. - namespace impl {} - } + bool values[][5] = { { 0, 0, 1, 0, 0 }, + { 0, 0, 1, 0, 0 }, + { 0, 0, 1, 0, 0 }, + { 0, 0, 1, 0, 0 }, + { 0, 0, 1, 0, 0 } }; -} + image2d<bool> ima = make::image(values); -# include <mln/geom/bbox.hh> -# include <mln/geom/chamfer.hh> -# include <mln/geom/complex_geometry.hh> -# include <mln/geom/delta.hh> -# include <mln/geom/max_col.hh> -# include <mln/geom/max_ind.hh> -# include <mln/geom/max_row.hh> -# include <mln/geom/max_sli.hh> -# include <mln/geom/min_col.hh> -# include <mln/geom/min_ind.hh> -# include <mln/geom/min_row.hh> -# include <mln/geom/min_sli.hh> -# include <mln/geom/ncols.hh> -# include <mln/geom/ninds.hh> -# include <mln/geom/nrows.hh> -# include <mln/geom/nsites.hh> -# include <mln/geom/nslis.hh> -# include <mln/geom/pmin_pmax.hh> -# include <mln/geom/rotate.hh> -# include <mln/geom/seeds2tiling.hh> -# include <mln/geom/seeds2tiling_roundness.hh> -# include <mln/geom/size1d.hh> -# include <mln/geom/size2d.hh> -# include <mln/geom/size3d.hh> + box2d b = make::box2d(-2, -2, 2, 2); + image2d<bool> + ima_rot = geom::translate(ima, + -1 * ima.domain().center().to_vec(), + literal::zero, b); + mln_piter_(image2d<bool>) + p1(ima.domain()), + p2(ima_rot.domain()); -#endif // ! MLN_GEOM_ALL_HH + for_all_2(p1,p2) + mln_assertion(ima(p1) == ima_rot(p2)); +} -- 1.5.6.5