3834: Add transformation::rotation.

* mln/transformation/all.hh, * mln/transformation/essential.hh: new headers. * mln/transformation/rotate.hh: new routine. * tests/transformation/Makefile.am, * tests/transformation/rotate.cc: new associated test. --- milena/ChangeLog | 12 +++ milena/mln/transformation/all.hh | 45 +++++++++++ milena/mln/transformation/essential.hh | 33 ++++++++ milena/mln/transformation/rotate.hh | 128 +++++++++++++++++++++++++++++++ milena/tests/Makefile.am | 1 + milena/tests/transformation/Makefile.am | 10 +++ milena/tests/transformation/rotate.cc | 60 ++++++++++++++ 7 files changed, 289 insertions(+), 0 deletions(-) create mode 100644 milena/mln/transformation/all.hh create mode 100644 milena/mln/transformation/essential.hh create mode 100644 milena/mln/transformation/rotate.hh create mode 100644 milena/tests/transformation/Makefile.am create mode 100644 milena/tests/transformation/rotate.cc diff --git a/milena/ChangeLog b/milena/ChangeLog index c6701bf..d4ff83d 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,17 @@ 2009-05-15 Guillaume Lazzara <lazzara@lrde.epita.fr> + Add transformation::rotation. + + * mln/transformation/all.hh, + * mln/transformation/essential.hh: new headers. + + * mln/transformation/rotate.hh: new routine. + + * tests/transformation/Makefile.am, + * tests/transformation/rotate.cc: new associated test. + +2009-05-15 Guillaume Lazzara <lazzara@lrde.epita.fr> + Improve io::magick tests. * tests/io/magick/Makefile.am, diff --git a/milena/mln/transformation/all.hh b/milena/mln/transformation/all.hh new file mode 100644 index 0000000..1379093 --- /dev/null +++ b/milena/mln/transformation/all.hh @@ -0,0 +1,45 @@ +// Copyright (C) 2009 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 +// 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_TRANSFORMATION_ALL_HH_ +# define MLN_TRANSFORMATION_ALL_HH_ + +namespace mln +{ + + /// Namespace of transformation routines. + namespace transformation + { + + } // end of namespace mln::transformation + +} // end of namespace mln + + +# include <mln/transformation/rotation.hh> + +# endif // ! MLN_TRANSFORMATION_ALL_HH_ diff --git a/milena/mln/transformation/essential.hh b/milena/mln/transformation/essential.hh new file mode 100644 index 0000000..990bf83 --- /dev/null +++ b/milena/mln/transformation/essential.hh @@ -0,0 +1,33 @@ +// Copyright (C) 2009 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 +// 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_TRANSFORMATION_ESSENTIAL_HH_ +# define MLN_TRANSFORMATION_ESSENTIAL_HH_ + +// None. + +# endif // ! MLN_TRANSFORMATION_ESSENTIAL_HH_ diff --git a/milena/mln/transformation/rotate.hh b/milena/mln/transformation/rotate.hh new file mode 100644 index 0000000..635db66 --- /dev/null +++ b/milena/mln/transformation/rotate.hh @@ -0,0 +1,128 @@ +// Copyright (C) 2009 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 +// 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_TRANSFORMATION_ROTATE_HH +# define MLN_TRANSFORMATION_ROTATE_HH + +# include <mln/core/routine/extend.hh> + +# include <mln/core/image/tr_image.hh> + +# include <mln/data/paste.hh> + +# include <mln/geom/bbox.hh> + +# include <mln/fun/x2x/composed.hh> +# include <mln/fun/x2x/rotation.hh> +# include <mln/fun/x2x/translation.hh> + +# include <mln/literal/zero.hh> + +# include <mln/math/pi.hh> + + +namespace mln +{ + + namespace transformation + { + + /// Perform a rotation from the center of an image. + /// + /// \param[in] input_ An image. + /// \param[in] angle An angle in degrees. + /// \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 rotation. + /// + /// \return An image with the same domain as \p input_. + // + template <typename I, typename Ext> + mln_concrete(I) + rotate(const Image<I>& input_, double angle, const Ext& extension_); + + + /// \overload + /// Use literal::zero as default value for the extension. + template <typename I> + mln_concrete(I) + rotate(const Image<I>& input_, double angle); + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename I, typename Ext> + mln_concrete(I) + rotate(const Image<I>& input_, double angle, const Ext& extension_) + { + trace::entering("transformation::rotate"); + + const I& input = exact(input_); + + mln_precondition(input.is_valid()); + mln_precondition(angle >= -360.0f && angle <= 360.0f); + /// FIXME: A precondition is probably missing for the extension value. + + mln_site(I) c = geom::bbox(input).center(); + fun::x2x::translation<2,double> + t(-1 * c.to_vec()), + t_1(c.to_vec()); + + typedef fun::x2x::rotation<2,double> rot_t; + rot_t rot(math::pi * angle / 180.f, literal::origin); + + mln_concrete(I) output; + initialize(output, input); + data::paste(transposed_image(input.domain(), + extend(input, extension_), + compose(t_1, compose(rot, t))), + output); + + trace::exiting("transformation::rotate"); + return output; + } + + + template <typename I> + mln_concrete(I) + rotate(const Image<I>& input, double angle) + { + return rotate(input, angle, literal::zero); + } + + +# endif // ! MLN_INCLUDE_ONLY + + + } // end of namespace mln::transformation + +} // end of namespace mln + + +#endif // ! MLN_TRANSFORMATION_ROTATE_HH diff --git a/milena/tests/Makefile.am b/milena/tests/Makefile.am index cf419b8..53e12ab 100644 --- a/milena/tests/Makefile.am +++ b/milena/tests/Makefile.am @@ -43,6 +43,7 @@ SUBDIRS = \ trace \ trait \ transform \ + transformation \ unit_test \ util \ value \ diff --git a/milena/tests/transformation/Makefile.am b/milena/tests/transformation/Makefile.am new file mode 100644 index 0000000..39471ee --- /dev/null +++ b/milena/tests/transformation/Makefile.am @@ -0,0 +1,10 @@ +## Process this file through Automake to create Makefile.in -*- Makefile -*- + +include $(top_srcdir)/milena/tests/tests.mk + +check_PROGRAMS = \ + rotate + +rotate_SOURCES = rotate.cc + +TESTS = $(check_PROGRAMS) diff --git a/milena/tests/transformation/rotate.cc b/milena/tests/transformation/rotate.cc new file mode 100644 index 0000000..8bdd90c --- /dev/null +++ b/milena/tests/transformation/rotate.cc @@ -0,0 +1,60 @@ +// Copyright (C) 2009 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 +// 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 tests/transformation/rotate.cc +/// +/// Test mln::transformation::rotate. + +# include <mln/core/image/image2d.hh> +# include <mln/transformation/rotate.hh> +# include <mln/make/image.hh> +# include <mln/level/compare.hh> + +# include <mln/debug/println.hh> + +int main() +{ + using namespace mln; + + bool ref_values[][5] = { { 0, 1, 0, 0, 0 }, + { 0, 1, 1, 0, 0 }, + { 0, 0, 1, 1, 0 }, + { 0, 0, 0, 1, 1 }, + { 0, 0, 0, 0, 1 } }; + + 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); + image2d<bool> ref = make::image(ref_values); + + image2d<bool> ima_rot = transformation::rotate(ima, 45); + mln_assertion(ima_rot == ref); +} -- 1.5.6.5
participants (1)
-
Guillaume Lazzara