URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-11-22 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Review the directory fun and add test.
* mln/fun/x2x/bijective_tr.hh,
* mln/fun/x2x/composed.hh,
* mln/fun/x2x/rotation.hh,
* mln/fun/x2x/translation.hh: Review.
* tests/fun/Makefile.am: Add tests.
* tests/fun/x2x/Makefile.am: Add tests.
* tests/fun_x2x_composed.cc,
* tests/fun_x2x_rotation.cc,
* tests/fun_x2x_translation.cc: Rename as...
* tests/fun/x2x/composed.cc,
* tests/fun/x2x/rotation.cc,
* tests/fun/x2x/translation.cc... this.
* tests/set/Makefile.am: Fix.
---
mln/fun/x2x/bijective_tr.hh | 10 ++++-
mln/fun/x2x/composed.hh | 16 +++++++--
mln/fun/x2x/rotation.hh | 25 ++------------
mln/fun/x2x/translation.hh | 9 ++---
tests/fun/Makefile.am | 2 +
tests/fun/x2x/Makefile.am | 11 ++++++
tests/fun/x2x/composed.cc | 66 +++++++++++++++++++++++++++++++++++++++
tests/fun/x2x/rotation.cc | 72 +++++++++++++++++++++++++++++++++++++++++++
tests/fun/x2x/translation.cc | 59 +++++++++++++++++++++++++++++++++++
tests/set/Makefile.am | 2 -
10 files changed, 239 insertions(+), 33 deletions(-)
Index: trunk/milena/tests/fun_x2x_translation.cc (deleted)
===================================================================
Index: trunk/milena/tests/fun_x2x_rotation.cc (deleted)
===================================================================
Index: trunk/milena/tests/fun_x2x_composed.cc (deleted)
===================================================================
Index: trunk/milena/tests/fun/x2x/translation.cc
===================================================================
--- trunk/milena/tests/fun/x2x/translation.cc (revision 0)
+++ trunk/milena/tests/fun/x2x/translation.cc (revision 1521)
@@ -0,0 +1,59 @@
+// Copyright (C) 2007 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 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/fun_x2x_translation.cc
+ *
+ * \brief Tests on mln::fun::x2x::translation.
+ */
+
+#include <cmath>
+#include <iostream>
+#include <mln/fun/x2x/translation.hh>
+#include <mln/fun/i2v/all_to.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ float
+ a = 2.3,
+ b = 0,
+ c = 2.9;
+
+ metal::vec<3,float> vec1 = make::vec(a, b, c);
+ fun::x2x::translation<3,float> tr1(all_to(1.6));
+
+ std::cout << vec1 << std::endl;
+ std::cout << tr1(vec1) << std::endl;
+ std::cout << tr1.inv()(vec1) << std::endl;
+ mln_assertion(tr1(tr1.inv()(vec1)) == vec1);
+ mln_assertion(fabs(tr1(vec1)[0] - 3.9) <= 0.125 &&
+ fabs(tr1(vec1)[1] - 1.6) <= 0.125 &&
+ fabs(tr1(vec1)[2] - 4.5) <= 0.125);
+}
Index: trunk/milena/tests/fun/x2x/rotation.cc
===================================================================
--- trunk/milena/tests/fun/x2x/rotation.cc (revision 0)
+++ trunk/milena/tests/fun/x2x/rotation.cc (revision 1521)
@@ -0,0 +1,72 @@
+// Copyright (C) 2007 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 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/fun_x2x_rotation.cc
+ *
+ * \brief Tests on mln::fun::x2x::rotation.
+ */
+
+
+#include <iostream>
+#include <mln/fun/x2x/rotation.hh>
+#include <mln/core/image2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/core/interpolated.hh>
+#include <mln/make/vec.hh>
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d<int_u8> lena = io::pgm::load("../../../img/lena.pgm");
+ image2d<int_u8> out(lena.domain());
+
+ interpolated<image2d<int_u8> > inter(lena);
+
+ fun::x2x::rotation<2,float> rot1(0.1);
+
+ image2d<int_u8>::fwd_piter p(out.domain());
+
+ for_all(p)
+ {
+ metal::vec<2,float> v = rot1.inv()((point2d::vec_t)(point2d)p);
+ if (inter.owns_(v))
+ out(p) = inter(v);
+ else
+ out(p) = 255;
+ }
+ io::pgm::save(out, "out.pgm");
+
+ fun::x2x::rotation<2,float> rot2(3.14116);
+ mln_assertion(fabs(rot2(make::vec(0.0, 1.0))[0] -
+ make::vec(0.0, -1.0)[0]) <= 0.125);
+ mln_assertion(fabs(rot2(make::vec(0.0, 1.0))[1] -
+ make::vec(0.0, -1.0)[1]) <= 0.125);
+}
Index: trunk/milena/tests/fun/x2x/Makefile.am
===================================================================
--- trunk/milena/tests/fun/x2x/Makefile.am (revision 1520)
+++ trunk/milena/tests/fun/x2x/Makefile.am (revision 1521)
@@ -1,3 +1,14 @@
## Process this file through Automake to create Makefile.in -*- Makefile -*-
include $(top_srcdir)/milena/tests/tests.mk
+
+check_PROGRAMS = \
+ composed \
+ rotation \
+ translation
+
+composed_SOURCES = composed.cc
+rotation_SOURCES = rotation.cc
+translation_SOURCES = translation_SOURCES
+
+TESTS = $(check_PROGRAMS)
Index: trunk/milena/tests/fun/x2x/composed.cc
===================================================================
--- trunk/milena/tests/fun/x2x/composed.cc (revision 0)
+++ trunk/milena/tests/fun/x2x/composed.cc (revision 1521)
@@ -0,0 +1,66 @@
+// Copyright (C) 2007 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 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/fun_x2x_composed.cc
+ *
+ * \brief Tests on mln::fun::x2x::composed.
+ */
+
+
+#include <iostream>
+#include <mln/fun/x2x/translation.hh>
+#include <mln/fun/x2x/rotation.hh>
+#include <mln/fun/x2x/composed.hh>
+#include <mln/fun/i2v/all_to.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ float
+ a = 2.3,
+ b = 0,
+ c = 2.9;
+
+ metal::vec<3,float> vec1 = make::vec(a, b, c);
+ fun::x2x::translation<3,float> tr(all_to(1.6));
+ fun::x2x::rotation<3,float> rot(0.3, 1);
+
+ std::cout << "vec : " << vec1 << std::endl;
+ std::cout << "tr(vec) : " << tr(vec1) << std::endl;
+ std::cout << "rot(vec) : " << rot(vec1) << std::endl;
+ std::cout << "tr(rot(vec)) : " << compose(tr, rot)(vec1) <<
std::endl;
+ std::cout << "rot(rot_1(vec)) : " << compose(rot,
rot.inv())(vec1) << std::endl;
+ std::cout << "tr(rot(tr(vec))) : " << compose(tr, compose(rot,
tr))(vec1) << std::endl;
+ std::cout << "(rototr_1)(rot(tr(vec)))) : "
+ << compose(compose(rot, tr).inv(), compose(rot, tr))(vec1) <<
std::endl;
+ mln_assertion(fabs(compose(rot, tr)(vec1)[0] - rot(tr(vec1))[0]) <= 0.125);
+ mln_assertion(fabs(compose(rot, tr)(vec1)[1] - rot(tr(vec1))[1]) <= 0.125);
+ mln_assertion(fabs(compose(rot, tr)(vec1)[2] - rot(tr(vec1))[2]) <= 0.125);
+}
Index: trunk/milena/tests/fun/Makefile.am
===================================================================
--- trunk/milena/tests/fun/Makefile.am (revision 1520)
+++ trunk/milena/tests/fun/Makefile.am (revision 1521)
@@ -1,3 +1,5 @@
## Process this file through Automake to create Makefile.in -*- Makefile -*-
include $(top_srcdir)/milena/tests/tests.mk
+
+SUBDIRS = x2x
Index: trunk/milena/tests/set/Makefile.am
===================================================================
--- trunk/milena/tests/set/Makefile.am (revision 1520)
+++ trunk/milena/tests/set/Makefile.am (revision 1521)
@@ -11,7 +11,7 @@
diff_SOURCES = diff.cc
inter_SOURCES = inter.cc
-is_subset_SOURCES = is_subset.cc
+is_subset_of_SOURCES = is_subset.cc
sym_diff_SOURCES = sym_diff.cc
uni_SOURCES = uni.cc
Index: trunk/milena/mln/fun/x2x/composed.hh
===================================================================
--- trunk/milena/mln/fun/x2x/composed.hh (revision 1520)
+++ trunk/milena/mln/fun/x2x/composed.hh (revision 1521)
@@ -30,7 +30,7 @@
/*! \file mln/fun/x2x/composed.hh
*
- * \brief FIXME.
+ * \brief Definition of a composed transformation.
*/
# include <mln/core/concept/function.hh>
@@ -112,8 +112,9 @@
} // end of namespace mln::fun::x2x::internal
- // FIXME: Doc!
-
+ /*! \brief Represent a composition of two transformations.
+ *
+ */
template <typename F, typename G>
struct composed
: public internal::helper_composed_<F, G, composed<F,G>,
@@ -139,6 +140,13 @@
} // end of namespace mln::fun
+ /*! \brief Do a composition of two transformations
+ *
+ * \param[in] f The first transformation.
+ * \param[in] g The second transformation.
+ *
+ * \return The composed transformation fog.
+ */
template <typename F, typename G>
fun::x2x::composed<F,G> compose(F f, G g);
@@ -232,7 +240,9 @@
template <typename F, typename G>
fun::x2x::composed<F,G> compose(F f, G g)
{
+ trace::entering("fun::x2x::compose");
fun::x2x::composed<F,G> comp(f, g);
+ trace::exiting("fun::x2x::compose");
return comp;
}
Index: trunk/milena/mln/fun/x2x/bijective_tr.hh
===================================================================
--- trunk/milena/mln/fun/x2x/bijective_tr.hh (revision 1520)
+++ trunk/milena/mln/fun/x2x/bijective_tr.hh (revision 1521)
@@ -30,7 +30,7 @@
/*! \file mln/fun/x2x/bijective_tr.hh
*
- * \brief FIXME.
+ * \brief Abstraction that describes a bijective transformation.
*/
# include <mln/core/concept/function.hh>
@@ -47,8 +47,12 @@
namespace x2x
{
- // FIXME: Doc!
-
+ /*! \brief Abstraction that describes a bijective transformation.
+ *
+ * All bijective transformation from vector to vector should
+ * should inherit this class.
+ *
+ */
template <typename E>
struct bijective_tr : public Function_x2x< E >
{
Index: trunk/milena/mln/fun/x2x/translation.hh
===================================================================
--- trunk/milena/mln/fun/x2x/translation.hh (revision 1520)
+++ trunk/milena/mln/fun/x2x/translation.hh (revision 1521)
@@ -30,7 +30,7 @@
/*! \file mln/fun/x2x/translation.hh
*
- * \brief FIXME.
+ * \brief Define a translation function.
*/
# include <mln/core/concept/function.hh>
@@ -48,8 +48,9 @@
namespace x2x
{
- // FIXME: Doc!
-
+ /*! \brief Represent a translation function.
+ *
+ */
template <unsigned n, typename C>
struct translation
@@ -82,8 +83,6 @@
template <unsigned n, typename C>
translation<n,C>::translation()
{
-// t_ = make::vec<n,C>(fun::i2v::all<C>(0));
-// this->m_ = h_mat<n,C>::Id;
}
template <unsigned n, typename C>
Index: trunk/milena/mln/fun/x2x/rotation.hh
===================================================================
--- trunk/milena/mln/fun/x2x/rotation.hh (revision 1520)
+++ trunk/milena/mln/fun/x2x/rotation.hh (revision 1521)
@@ -30,7 +30,7 @@
/*! \file mln/fun/x2x/rotation.hh
*
- * \brief FIXME.
+ * \brief Define a rotation function.
*/
# include <mln/core/concept/function.hh>
@@ -48,8 +48,9 @@
namespace x2x
{
- // FIXME: Doc!
-
+ /*! \brief Represent a rotation function.
+ *
+ */
template <unsigned n, typename C>
struct rotation
: internal::x2x_linear_impl_< metal::vec<n,C>, rotation<n,C> >
@@ -82,9 +83,6 @@
template <unsigned n, typename C>
rotation<n,C>::rotation()
{
-// alpha_ = 0;
-// dir_ = 2;
-// this->m_ = h_mat<n,C>::Id;
}
template <unsigned n, typename C>
@@ -159,21 +157,6 @@
}
}
-// template <typename C> FIXME : template parameter should be swapped
-// void
-// rotation<2,C>::update()
-// {
-// const float cos_a = cos(alpha_);
-// const float sin_a = sin(alpha_);
-
-// m_ = metal::mat<3,3,C>::Id;
-// m_(0, 0) = cos_a;
-// m_(0, 1) = -sin_a;
-// m_(1, 0) = sin_a;
-// m_(1, 1) = cos_a;
-// }
-
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::fun::x2x