URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2009-09-25 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Fix non generic stuff in translation function and fix transform morpher.
* core/image/imorph/tr_image.hh,
* core/site_set/p_transformed.hh,
* core/site_set/p_transformed_piter.hh:
Make them less strict with function return type. Allow
functions having values that can be converted in the requested
site. (ex: vector<1, u> -> point1d).
* fun/p2p/translation.hh: Add argument type definition.
* fun/x2x/translation.hh: Add inverse function.
* geom/translate.hh: Fix non generic stuff and bug.
---
core/image/imorph/tr_image.hh | 4 ++--
core/site_set/p_transformed.hh | 8 +++++---
core/site_set/p_transformed_piter.hh | 5 +++--
fun/p2p/translation.hh | 1 +
fun/x2x/translation.hh | 10 ++++++++++
geom/translate.hh | 26 +++++++++++++-------------
6 files changed, 34 insertions(+), 20 deletions(-)
Index: trunk/milena/mln/core/site_set/p_transformed.hh
===================================================================
--- trunk/milena/mln/core/site_set/p_transformed.hh (revision 4552)
+++ trunk/milena/mln/core/site_set/p_transformed.hh (revision 4553)
@@ -33,7 +33,7 @@
# include <mln/core/internal/site_set_base.hh>
# include <mln/core/concept/function.hh>
-
+# include <mln/convert/from_to.hh>
namespace mln
{
@@ -81,7 +81,7 @@
template <typename S, typename F>
class p_transformed
: public internal::site_set_base_< mln_psite(S), p_transformed<S,F> >,
- private metal::equal< mln_result(F), mln_psite(S) >::check_t
+ private mlc_converts_to(mln_result(F), mln_psite(S))::check_t
{
typedef p_transformed<S,F> self_;
typedef internal::site_set_base_<mln_result(F), self_> super_;
@@ -171,7 +171,9 @@
bool
p_transformed<S,F>::has(const psite& p) const
{
- return s_.has(f_(p));
+ mln_argument(F) arg;
+ convert::from_to(p, arg);
+ return s_.has(f_.inverse(arg));
}
template <typename S, typename F>
Index: trunk/milena/mln/core/site_set/p_transformed_piter.hh
===================================================================
--- trunk/milena/mln/core/site_set/p_transformed_piter.hh (revision 4552)
+++ trunk/milena/mln/core/site_set/p_transformed_piter.hh (revision 4553)
@@ -32,6 +32,7 @@
# include <mln/core/internal/site_set_iterator_base.hh>
# include <mln/core/site_set/p_transformed.hh>
+# include <mln/convert/to.hh>
namespace mln
@@ -123,7 +124,7 @@
{
pi_.start();
if (pi_.is_valid())
- p_ = s_->function()(pi_);
+ p_ = s_->function()(convert::to<mln_argument(F)>(pi_));
}
template <typename Pi, typename S, typename F>
@@ -133,7 +134,7 @@
{
pi_.next();
if (pi_.is_valid())
- p_ = s_->function()(pi_);
+ p_ = s_->function()(convert::to<mln_argument(F)>(pi_));
}
template <typename Pi, typename S, typename F>
Index: trunk/milena/mln/core/image/imorph/tr_image.hh
===================================================================
--- trunk/milena/mln/core/image/imorph/tr_image.hh (revision 4552)
+++ trunk/milena/mln/core/image/imorph/tr_image.hh (revision 4553)
@@ -81,12 +81,12 @@
//
template <typename S, typename I, typename T>
struct tr_image :
- public mln::internal::image_identity< I, mln_domain(I), tr_image<S,I,T>
>
+ public mln::internal::image_identity< I, S, tr_image<S,I,T> >
{
/// Super type.
typedef
- mln::internal::image_identity< I, mln_domain(I), tr_image<S,I,T> >
super_;
+ mln::internal::image_identity< I, S, tr_image<S,I,T> > super_;
/// Point_Site associated type.
typedef mln_psite(I) psite;
Index: trunk/milena/mln/geom/translate.hh
===================================================================
--- trunk/milena/mln/geom/translate.hh (revision 4552)
+++ trunk/milena/mln/geom/translate.hh (revision 4553)
@@ -35,10 +35,10 @@
# include <mln/core/concept/box.hh>
# include <mln/core/routine/extend.hh>
-
+# include <mln/core/site_set/p_transformed.hh>
# include <mln/core/image/imorph/tr_image.hh>
-# include <mln/data/paste.hh>
+# include <mln/data/fill.hh>
# include <mln/fun/x2x/translation.hh>
@@ -105,22 +105,22 @@
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();
+ //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);
+ //mln_psite(I) c = geom::bbox(input).center();
+ typedef fun::x2x::translation<mln_site_(I)::dim, V> trans_t;
+ typedef p_transformed<mln_domain(I), trans_t> trans_domain_t;
+ typedef tr_image<trans_domain_t, I, trans_t> tr_ima_t;
+
+ trans_t t(ref);
+ trans_domain_t d(input.domain(), t);
+ tr_ima_t tr_ima(d, input, t);
- data::paste(extend(tr_ima, extension), output);
+ mln_concrete(I) output(output_domain);
+ data::fill(output, extend(tr_ima, extension) | output_domain);
trace::exiting("geom::translate");
return output;
Index: trunk/milena/mln/fun/p2p/translation.hh
===================================================================
--- trunk/milena/mln/fun/p2p/translation.hh (revision 4552)
+++ trunk/milena/mln/fun/p2p/translation.hh (revision 4553)
@@ -47,6 +47,7 @@
struct translation_t : public Function_v2v< translation_t<P> >
{
typedef P result;
+ typedef P argument;
translation_t(const mln_delta(P)& dp);
Index: trunk/milena/mln/fun/x2x/translation.hh
===================================================================
--- trunk/milena/mln/fun/x2x/translation.hh (revision 4552)
+++ trunk/milena/mln/fun/x2x/translation.hh (revision 4553)
@@ -66,6 +66,8 @@
/// Perform the translation of the given vector
algebra::vec<n,C> operator()(const algebra::vec<n,C>& v) const;
+ algebra::vec<n,C> inverse(const algebra::vec<n,C>& v) const;
+
/// Set a net translation vector.
void set_t(const algebra::vec<n,C>& t);
@@ -106,6 +108,14 @@
template <unsigned n, typename C>
inline
+ algebra::vec<n,C>
+ translation<n,C>::inverse(const algebra::vec<n,C>& v) const
+ {
+ return v - t_;
+ }
+
+ template <unsigned n, typename C>
+ inline
translation<n,C>
translation<n,C>::inv() const
{