https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add fun p2p translation and p2p_image morpher.
* mln/core/image/p2p_image.hh: New.
* mln/core/image/all.hh: Update.
* mln/fun/p2p/all.hh: New.
* mln/fun/p2p/mirror.hh (endif): Fix comment style.
* mln/fun/p2p/translation.hh: New.
* tests/core/image/p2p_image.cc: New.
* tests/core/image/Makefile.am: Update.
* tests/fun/p2p: New.
* tests/fun/p2p/translation.cc: New.
* tests/fun/p2p/Makefile.am: New.
* tests/fun/Makefile.am: Update.
* mln/core/image/image_if.hh (undef): Fix, i.e., remove.
mln/core/image/all.hh | 1
mln/core/image/image_if.hh | 3
mln/core/image/p2p_image.hh | 274 ++++++++++++++++++++++++++++++++++++++++++
mln/fun/p2p/all.hh | 53 ++++++++
mln/fun/p2p/mirror.hh | 2
mln/fun/p2p/translation.hh | 116 +++++++++++++++++
tests/core/image/Makefile.am | 2
tests/core/image/p2p_image.cc | 60 +++++++++
tests/fun/Makefile.am | 2
tests/fun/p2p/Makefile.am | 10 +
tests/fun/p2p/translation.cc | 44 ++++++
11 files changed, 562 insertions(+), 5 deletions(-)
Index: mln/core/image/image_if.hh
--- mln/core/image/image_if.hh (revision 3213)
+++ mln/core/image/image_if.hh (working copy)
@@ -264,7 +264,4 @@
} // end of namespace mln
-# undef Super
-
-
#endif // ! MLN_CORE_IMAGE_IMAGE_IF_HH
Index: mln/core/image/p2p_image.hh
--- mln/core/image/p2p_image.hh (revision 0)
+++ mln/core/image/p2p_image.hh (revision 0)
@@ -0,0 +1,274 @@
+// Copyright (C) 2008 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_CORE_IMAGE_P2P_IMAGE_HH
+# define MLN_CORE_IMAGE_P2P_IMAGE_HH
+
+/// \file mln/core/image/p2p_image.hh
+///
+/// Definition of a image FIXME: Doc!
+
+# include <mln/core/internal/image_domain_morpher.hh>
+# include <mln/core/concept/function.hh>
+# include <mln/accu/bbox.hh>
+
+
+namespace mln
+{
+
+ // Forward declaration.
+ template <typename I, typename F> struct p2p_image;
+
+
+ namespace internal
+ {
+
+ /// Data structure for \c mln::p2p_image<I,F>.
+ template <typename I, typename F>
+ struct data< p2p_image<I,F> >
+ {
+ data(I& ima, const F& f);
+
+ I ima_;
+ F f_;
+ mln_pset(I) b_;
+ };
+
+ } // end of namespace mln::internal
+
+
+ namespace trait
+ {
+
+ template <typename I, typename F>
+ struct image_< p2p_image<I,F> > : default_image_morpher< I,
+ mln_value(I),
+ p2p_image<I,F> >
+ {
+ typedef trait::image::category::domain_morpher category;
+
+ typedef trait::image::ext_domain::none ext_domain; // No extension of
domain.
+ typedef trait::image::ext_value::irrelevant ext_value;
+ typedef trait::image::ext_io::irrelevant ext_io;
+
+ typedef trait::image::vw_io::none vw_io;
+ typedef trait::image::vw_set::none vw_set;
+ typedef trait::image::value_alignement::not_aligned value_alignement;
+ typedef trait::image::value_storage::disrupted value_storage;
+ };
+
+ } // end of namespace mln::trait
+
+
+
+ /// FIXME: Doc!
+ template <typename I, typename F>
+ struct p2p_image : public internal::image_domain_morpher< I,
+ mln_pset(I),
+ p2p_image<I, F> >
+ {
+ /// Skeleton.
+ typedef p2p_image< tag::image_<I>, tag::function_<F> > skeleton;
+
+ /// Constructor without argument.
+ p2p_image();
+
+ /// Constructor from an image \p ima and a predicate \p f.
+ p2p_image(I& ima, const F& f);
+
+ void init_(I& ima, const F& f);
+
+ /// Give the definition domain.
+ const mln_pset(I)& domain() const;
+
+ /// Give the p2p function.
+ const F& fun() const;
+
+ /// Read-only access to the image value located at point \p p.
+ mln_rvalue(I) operator()(const mln_psite(I)& p) const;
+
+ /// Read-write access to the image value located at point \p p.
+ mln_morpher_lvalue(I) operator()(const mln_psite(I)& p);
+ };
+
+
+
+ /// FIXME: Doc!
+ template <typename I, typename F>
+ p2p_image<I,F>
+ apply_p2p(Image<I>& ima, const Function_p2p<F>& f);
+
+ /// FIXME: Doc!
+ template <typename I, typename F>
+ p2p_image<const I,F>
+ apply_p2p(const Image<I>& ima, const Function_p2p<F>& f);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // init_.
+
+ template <typename I, typename F>
+ void init_(tag::function_t, F& f, const p2p_image<I,F>& model)
+ {
+ f = model.fun();
+ }
+
+ template <typename I, typename F, typename J>
+ void init_(tag::image_t, p2p_image<I,F>& target, const J& model)
+ {
+ I ima;
+ init_(tag::image, ima, exact(model));
+ F f;
+ init_(tag::function, f, exact(model));
+ target.init_(ima, f);
+ }
+
+ // internal::data< p2p_image<I,F> >
+
+ namespace internal
+ {
+
+ template <typename I, typename F>
+ inline
+ data< p2p_image<I,F> >::data(I& ima, const F& f)
+ : ima_(ima),
+ f_(f)
+ {
+ accu::bbox<mln_site(I)> a;
+ mln_pset(I) b = ima.domain();
+ a.take(f(b.pmin()));
+ a.take(f(b.pmax()));
+ b_ = a.to_result();
+ mln_invariant(b_.nsites() == b.nsites());
+ }
+
+ }
+
+
+ // p2p_image<I,F>
+
+ template <typename I, typename F>
+ inline
+ p2p_image<I,F>::p2p_image()
+ {
+ }
+
+ template <typename I, typename F>
+ inline
+ p2p_image<I,F>::p2p_image(I& ima, const F& f)
+ {
+ init_(ima, f);
+ }
+
+ template <typename I, typename F>
+ inline
+ void
+ p2p_image<I,F>::init_(I& ima, const F& f)
+ {
+ mln_precondition(! this->is_valid());
+ this->data_ = new internal::data< p2p_image<I,F> >(ima, f);
+ }
+
+ template <typename I, typename F>
+ inline
+ const mln_pset(I)&
+ p2p_image<I,F>::domain() const
+ {
+ mln_precondition(this->is_valid());
+ return this->data_->b_;
+ }
+
+ template <typename I, typename F>
+ inline
+ const F&
+ p2p_image<I,F>::fun() const
+ {
+ mln_precondition(this->is_valid());
+ return this->data_->f_;
+ }
+
+ template <typename I, typename F>
+ inline
+ mln_rvalue(I)
+ p2p_image<I,F>::operator()(const mln_psite(I)& p) const
+ {
+ mln_precondition(this->has(p));
+ mln_invariant(this->data_->ima_.has(this->data_->f_.inverse(p)));
+ return this->data_->ima_(this->data_->f_.inverse(p));
+ }
+
+ template <typename I, typename F>
+ inline
+ mln_morpher_lvalue(I)
+ p2p_image<I,F>::operator()(const mln_psite(I)& p)
+ {
+ mln_precondition(this->has(p));
+ mln_invariant(this->data_->ima_.has(this->data_->f_.inverse(p)));
+ return this->data_->ima_(this->data_->f_.inverse(p));
+ }
+
+
+ // Routines.
+
+ template <typename I, typename F>
+ inline
+ p2p_image<I,F>
+ apply_p2p(Image<I>& ima_, const Function_p2p<F>& f)
+ {
+ mlc_is_a(mln_pset(I), Box)::check();
+
+ I& ima = exact(ima_);
+ mln_precondition(ima.is_valid());
+
+ p2p_image<I,F> tmp(ima, exact(f));
+ return tmp;
+ }
+
+ template <typename I, typename F>
+ inline
+ p2p_image<const I, F>
+ apply_p2p(const Image<I>& ima_, const Function_p2p<F>& f)
+ {
+ mlc_is_a(mln_pset(I), Box)::check();
+
+ const I& ima = exact(ima_);
+ mln_precondition(ima.is_valid());
+
+ p2p_image<const I, F> tmp(ima, exact(f));
+ return tmp;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+
+#endif // ! MLN_CORE_IMAGE_P2P_IMAGE_HH
Index: mln/core/image/all.hh
--- mln/core/image/all.hh (revision 3213)
+++ mln/core/image/all.hh (working copy)
@@ -73,6 +73,7 @@
//# include <mln/core/image/mono_rle_image.hh>
//# include <mln/core/image/obased_rle_encode.hh>
//# include <mln/core/image/obased_rle_image.hh>
+# include <mln/core/image/p2p_image.hh>
# include <mln/core/image/plain.hh>
//# include <mln/core/image/rle_encode.hh>
//# include <mln/core/image/rle_image.hh>
Index: mln/fun/p2p/all.hh
--- mln/fun/p2p/all.hh (revision 0)
+++ mln/fun/p2p/all.hh (revision 0)
@@ -0,0 +1,53 @@
+// Copyright (C) 2008 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_FUN_P2P_ALL_HH
+# define MLN_FUN_P2P_ALL_HH
+
+/// \file mln/fun/p2p/all.hh
+///
+/// File that includes all functions from grid point to grid point.
+
+
+namespace mln
+{
+ namespace fun
+ {
+
+ /// Namespace of functions from grid point to grid point.
+ namespace p2p
+ {}
+
+ }
+}
+
+
+# include <mln/fun/p2p/mirror.hh>
+# include <mln/fun/p2p/translation.hh>
+
+
+#endif // ! MLN_FUN_P2P_ALL_HH
Index: mln/fun/p2p/mirror.hh
--- mln/fun/p2p/mirror.hh (revision 3213)
+++ mln/fun/p2p/mirror.hh (working copy)
@@ -87,5 +87,5 @@
} // end of namespace mln
-#endif /* MLN_FUN_P2P_MIRROR_HH */
+#endif // ! MLN_FUN_P2P_MIRROR_HH
Index: mln/fun/p2p/translation.hh
--- mln/fun/p2p/translation.hh (revision 0)
+++ mln/fun/p2p/translation.hh (revision 0)
@@ -0,0 +1,116 @@
+// Copyright (C) 2008 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_FUN_P2P_TRANSLATION_HH
+# define MLN_FUN_P2P_TRANSLATION_HH
+
+/// \file mln/fun/p2p/translation.hh
+///
+/// FIXME: doc
+
+# include <mln/core/concept/function.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace p2p
+ {
+
+ template <typename P>
+ struct translation_t : public Function_p2p< translation_t<P> >
+ {
+ typedef P result;
+
+ translation_t(const mln_delta(P)& dp);
+
+ P operator()(const P& p) const;
+ P inverse(const P& p) const;
+
+ protected:
+ mln_delta(P) dp_;
+ };
+
+
+ template <typename D>
+ translation_t<mln_site(D)>
+ translation(const Gdpoint<D>& dp);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ inline
+ translation_t<P>::translation_t(const mln_delta(P)& dp)
+ : dp_(dp)
+ {
+ }
+
+ template <typename P>
+ inline
+ P
+ translation_t<P>::operator()(const P& p) const
+ {
+ return p + dp_;
+ }
+
+ template <typename P>
+ inline
+ P
+ translation_t<P>::inverse(const P& p) const
+ {
+ return p - dp_;
+ }
+
+
+ template <typename D>
+ inline
+ translation_t<mln_site(D)>
+ translation(const Gdpoint<D>& dp)
+ {
+ translation_t<mln_site(D)> tmp(exact(dp));
+ return tmp;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::p2p
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_P2P_TRANSLATION_HH
+
+
Index: tests/core/image/p2p_image.cc
--- tests/core/image/p2p_image.cc (revision 0)
+++ tests/core/image/p2p_image.cc (revision 0)
@@ -0,0 +1,60 @@
+// Copyright (C) 2008 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/core/image/image2d.cc
+///
+/// Tests on mln::p2p_image.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/p2p_image.hh>
+#include <mln/fun/p2p/translation.hh>
+
+#include <mln/debug/iota.hh>
+
+
+
+# define ima_ apply_p2p(ima, fun::p2p::translation(dp))
+
+
+
+int main()
+{
+ using namespace mln;
+
+ box2d b = make::box2d(0,0, 2,2);
+ image2d<int> ima(b, 0); // No border.
+
+ debug::iota(ima);
+
+ dpoint2d dp(-1,+1);
+ box2d b_ = make::box2d(-1,+1, 1,3);
+
+ mln_assertion( ima_.domain() == b_ );
+
+ mln_assertion( ima_(point2d(-1,+1)) == 1 );
+ mln_assertion( ima_(point2d( 1, 3)) == 9 );
+}
Index: tests/core/image/Makefile.am
--- tests/core/image/Makefile.am (revision 3213)
+++ tests/core/image/Makefile.am (working copy)
@@ -21,6 +21,7 @@
## mono_obased_rle_image \
## mono_rle_image \
## obased_rle_image \
+ p2p_image \
plain \
## rle_image \
safe_image \
@@ -49,6 +50,7 @@
##mono_obased_rle_image_SOURCES = mono_obased_rle_image.cc
##mono_rle_image_SOURCES = mono_rle_image.cc
##obased_rle_image_SOURCES = obased_rle_image.cc
+p2p_image_SOURCES = p2p_image.cc
plain_SOURCES = plain.cc
##rle_image_SOURCES = rle_image.cc
safe_image_SOURCES = safe_image.cc
Index: tests/fun/p2p/translation.cc
--- tests/fun/p2p/translation.cc (revision 0)
+++ tests/fun/p2p/translation.cc (revision 0)
@@ -0,0 +1,44 @@
+// Copyright (C) 2008 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/fun/p2p/translation.cc
+///
+/// Tests on mln::fun::p2p::translation.
+
+#include <mln/core/alias/point2d.hh>
+#include <mln/fun/p2p/translation.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ point2d p(0,0);
+ dpoint2d dp(-1,+1);
+
+ mln_invariant(fun::p2p::translation(dp)(p) == point2d(-1,+1));
+}
Index: tests/fun/p2p/Makefile.am
--- tests/fun/p2p/Makefile.am (revision 0)
+++ tests/fun/p2p/Makefile.am (revision 0)
@@ -0,0 +1,10 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+include $(top_srcdir)/milena/tests/tests.mk
+
+check_PROGRAMS = \
+ translation
+
+translation_SOURCES = translation.cc
+
+TESTS = $(check_PROGRAMS)
Index: tests/fun/Makefile.am
--- tests/fun/Makefile.am (revision 3213)
+++ tests/fun/Makefile.am (working copy)
@@ -2,4 +2,4 @@
include $(top_srcdir)/milena/tests/tests.mk
-SUBDIRS = i2v p2b p2v v2v vv2v x2x
+SUBDIRS = i2v p2b p2p p2v v2v vv2v x2x