URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-11 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Tests on composed transformations (does not work).
* mln/fun/internal/x2x_impl.hh: Update.
* mln/fun/x2x/composed.hh: Update.
* tests/fun_x2x_composed.cc: New.
---
mln/fun/internal/x2x_impl.hh | 1
mln/fun/x2x/composed.hh | 178 ++++++++++++++++++++++++++++++++-----------
tests/fun_x2x_composed.cc | 57 +++++++++++++
3 files changed, 191 insertions(+), 45 deletions(-)
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 1312)
@@ -0,0 +1,57 @@
+// 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/image2d.cc
+ *
+ * \brief Tests on mln::image2d.
+ */
+
+
+#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.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(1.6));
+ fun::x2x::rotation<3,float> rot(0.3, 1);
+ std::cout << vec1 << std::endl;
+ std::cout << compose(tr, rot)(vec1) << std::endl;
+ std::cout << compose(rot, tr)(vec1) << std::endl;
+}
Index: trunk/milena/mln/fun/x2x/composed.hh
===================================================================
--- trunk/milena/mln/fun/x2x/composed.hh (revision 1311)
+++ trunk/milena/mln/fun/x2x/composed.hh (revision 1312)
@@ -55,42 +55,50 @@
namespace internal
{
- template <typename F, typename G, typename E>
- struct helper_;
-
- template <typename F, typename G, typename E>
- struct helper_<Function_x2x<F>, Function_x2x<G>, E>
- : Function_x2x<E>
+ template <typename F, typename G, typename E, bool is_bij = true>
+ struct helper_composed_
+ : public fun::internal::x2x_impl_<mln_result(F), E >,
+ public Bijection_x2x<E>
{
- };
+ typedef fun::internal::x2x_impl_<typename F::result, E > super_;
- template <typename F, typename G, typename E>
- struct helper_<Bijection_x2x<F>, Bijection_x2x<G>, E >
- : Bijection_x2x<E>
- {
- typedef composed<G::invert,F::invert> invert;
+ using super_::dim;
+
+ helper_composed_();
+ helper_composed_(const F& f, const G& g);
+
+ using super_::operator();
+ metal::vec<dim,mln_result(F)>
+ operator()(const metal::vec<dim,mln_result(F)>& v) const;
+
+ void set_first(const F& f);
+ void set_second(const G& g);
+
+ protected:
+
+ F f_;
+ G g_;
+
+ typedef composed<mln_invert(G),mln_invert(F)> invert;
invert inv() const;
};
- }
- // FIXME: Doc!
-
- template <typename F, typename G>
- struct composed
- : internal::x2x_impl_<F::result, composed<F,G> >,
- public internal::helper_< F, G, composed<F,G> >,
- private typename metal::bool<(F::dim == G::dim)>::check_t,
- private typename metal::is<F::argument, G::result>::check_t
+ template <typename F, typename G, typename E>
+ struct helper_composed_<F, G, E, false>
+ : public fun::internal::x2x_impl_<mln_result(F), E >,
+ public Function_x2x<E>
{
+ typedef fun::internal::x2x_impl_<typename F::result, E > super_;
- typedef internal::x2x_impl_<F::result, composed<F,G> > super_
+ using super_::dim;
- composed();
- composed(const F& f, const G& g);
+ helper_composed_();
+ helper_composed_(const F& f, const G& g);
- using super_:operator();
- metal::vec<super_::dim,C> operator()(const metal::vec<super_::dim,C>& v)
const;
+ using super_::operator();
+ metal::vec<dim,mln_result(F)>
+ operator()(const metal::vec<dim,mln_result(F)>& v) const;
void set_first(const F& f);
void set_second(const G& g);
@@ -101,61 +109,143 @@
G g_;
};
+ } // end of namespace mln::fun::x2x::internal
+
+ // FIXME: Doc!
+
+ template <typename F, typename G>
+ struct composed
+ : public internal::helper_composed_<F, G, composed<F,G>,
+ mlc_is(F, Bijection_x2x<F>)::value &&
+ mlc_is(G, Bijection_x2x<G>)::value>,
+ private metal::bool_<(F::dim == G::dim)>::check_t,
+ private metal::is<mln_argument(F), mln_result(G)>::check_t
+ {
+ typedef internal::helper_composed_<F, G, composed<F,G>,
+ mlc_is(F, Bijection_x2x<F>)::value &&
+ mlc_is(G, Bijection_x2x<G>)::value> super_;
+
+ composed() {}
+
+ composed(const F& f, const G& g)
+ : helper_composed_<F, G, composed<F,G>,
+ mlc_is(F, Bijection_x2x<F>)::value &&
+ mlc_is(G, Bijection_x2x<G>)::value>(f, g)
+ {
+ }
+ };
+
+ } // end of namespace mln::fun::x2x
+
+ } // end of namespace mln::fun
+
+ template <typename F, typename G>
+ fun::x2x::composed<F,G> compose(F f, G g);
# ifndef MLN_INCLUDE_ONLY
+ namespace fun
+ {
+
+ namespace x2x
+ {
+
+ namespace internal
+ {
+
+ // Implementation of the bijective version.
+
template <typename F, typename G>
- composed<F,G>::composed()
+ helper_composed_<F,G,E,true>::helper_composed_()
{
- m_ = h_mat<n,C>::Id;
+ this->m_ = h_mat<dim,mln_result(F)>::Id;
}
template <typename F, typename G>
- composed<F,G>::composed(const F& f, const G& g)
+ helper_composed_<F,G,E,true>::helper_composed_(const F& f, const G& g)
:f_(f),
g_(g)
{
- m_ = f_.mat() * g_.mat();
+ this->m_ = f_.mat() * g_.mat();
+ }
+
+ template <typename F, typename G>
+ metal::vec<helper_composed_<F,G,E,true>::dim, mln_result(F)>
+ helper_composed_<F,G,E,true>::operator()(const metal::vec<dim,
mln_result(F)>& v) const
+ {
+ return this->m_(v);
+ }
+
+ template <typename F, typename G>
+ void
+ helper_composed_<F,G,E,true>::set_first(const F& f)
+ {
+ this->f_ = f;
+ this->m_ = this->f_.mat() * this->g_.mat();
}
template <typename F, typename G>
- metal::vec<super_::dim,C>
- composed<F,G>::operator()(const metal::vec<super_::dim,C>& v)
const
+ void
+ helper_composed_<F,G,E,true>::set_second(const G& g)
{
- return m_(v);
+ this->g_ = g;
+ this->m_ = this->f_.mat() * this->g_.mat();
}
+ // Implementation of the non bijective version.
+
template <typename F, typename G>
- composed<F,G>::invert
- composed<F,G>::inv() const
+ helper_composed_<F,G,E,false>::helper_composed_()
{
- typename composed::invert res(tr2_.inv(), tr1_.inv());
+ this->m_ = h_mat<dim,mln_result(F)>::Id;
+ }
+
+ template <typename F, typename G>
+ helper_composed_<F,G,E,false>::helper_composed_(const F& f, const G& g)
+ :f_(f),
+ g_(g)
+ {
+ this->m_ = f_.mat() * g_.mat();
+ }
- return res;
+ template <typename F, typename G>
+ metal::vec<helper_composed_<F,G,E,false>::dim, mln_result(F)>
+ helper_composed_<F,G,E,false>::operator()(const metal::vec<dim,
mln_result(F)>& v) const
+ {
+ return this->m_(v);
}
template <typename F, typename G>
void
- composed<F,G>::set_first(const F& f)
+ helper_composed_<F,G,E,false>::set_first(const F& f)
{
- f_ = f;
- m_ = f_.mat() * g_.mat();
+ this->f_ = f;
+ this->m_ = this->f_.mat() * this->g_.mat();
}
template <typename F, typename G>
void
- composed<F,G>::set_second(const G& g)
+ helper_composed_<F,G,E,false>::set_second(const G& g)
{
- g_ = g;
- m_ = f_.mat() * g_.mat();
+ this->g_ = g;
+ this->m_ = this->f_.mat() * this->g_.mat();
}
-# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace mln::fun::x2x::internal
} // end of namespace mln::fun::x2x
} // end of namespace mln::fun
+ template <typename F, typename G>
+ fun::x2x::composed<F,G> compose(F f, G g)
+ {
+ fun::x2x::composed<F,G> comp(f, g);
+ return comp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace mln
Index: trunk/milena/mln/fun/internal/x2x_impl.hh
===================================================================
--- trunk/milena/mln/fun/internal/x2x_impl.hh (revision 1311)
+++ trunk/milena/mln/fun/internal/x2x_impl.hh (revision 1312)
@@ -37,7 +37,6 @@
# include <mln/core/h_mat.hh>
# include <mln/core/h_vec.hh>
-
namespace mln
{