https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
New domain morpher, though a function from site to site.
* mln/core/site_set/p_transformed.hh: New.
* mln/core/site_set/p_transformed_piter.hh: New.
* mln/core/site_set/all.hh: Update.
* mln/core/image/all.hh: Update.
* mln/core/image/dmorph: New directory.
* mln/core/image/dmorph/transformed_image.hh: New.
* mln/core/image/dmorph/all.hh: New.
* tests/core/site_set/p_transformed.cc: New.
* tests/core/site_set/pset_if.cc: Rename as...
* tests/core/site_set/p_if.cc: ...this.
* tests/core/site_set/Makefile.am: Update.
* tests/core/image/dmorph: New directory.
* tests/core/image/dmorph/Makefile.am: New.
* tests/core/image/dmorph/transformed_image.cc: New.
* tests/core/image/Makefile.am: Update.
Misc.
* mln/core/image/image_if.hh: Layout.
* mln/core/image/sub_image.hh: Layout.
* mln/core/internal/image_base.hh: Layout.
* mln/core/internal/image_morpher.hh: Layout.
* mln/core/internal/image_domain_morpher.hh: Upgrade doc style.
* tests/core/image/p2p_image.cc: Move echo.
mln/core/image/all.hh | 7
mln/core/image/dmorph/all.hh | 39 +++
mln/core/image/dmorph/transformed_image.hh | 272 +++++++++++++++++++++++++++
mln/core/image/image_if.hh | 6
mln/core/image/sub_image.hh | 2
mln/core/internal/image_base.hh | 5
mln/core/internal/image_domain_morpher.hh | 10
mln/core/internal/image_morpher.hh | 2
mln/core/site_set/all.hh | 4
mln/core/site_set/p_transformed.hh | 218 +++++++++++++++++++++
mln/core/site_set/p_transformed_piter.hh | 159 +++++++++++++++
tests/core/image/Makefile.am | 3
tests/core/image/dmorph/Makefile.am | 10
tests/core/image/dmorph/transformed_image.cc | 58 +++++
tests/core/image/p2p_image.cc | 7
tests/core/site_set/Makefile.am | 6
tests/core/site_set/p_if.cc | 6
tests/core/site_set/p_transformed.cc | 58 +++++
18 files changed, 853 insertions(+), 19 deletions(-)
Index: mln/core/site_set/all.hh
--- mln/core/site_set/all.hh (revision 3857)
+++ mln/core/site_set/all.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 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
@@ -51,6 +52,7 @@
# include <mln/core/site_set/p_run.hh>
# include <mln/core/site_set/p_set.hh>
# include <mln/core/site_set/p_set_of.hh>
+# include <mln/core/site_set/p_transformed.hh>
# include <mln/core/site_set/p_vaccess.hh>
# include <mln/core/site_set/p_vertices.hh>
Index: mln/core/site_set/p_transformed.hh
--- mln/core/site_set/p_transformed.hh (revision 0)
+++ mln/core/site_set/p_transformed.hh (revision 0)
@@ -0,0 +1,218 @@
+// 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_CORE_SITE_SET_P_TRANSFORMED_HH
+# define MLN_CORE_SITE_SET_P_TRANSFORMED_HH
+
+/// \file mln/core/site_set/p_transformed.hh
+///
+/// Definition of a site set defined by the transformation of another
+/// site set.
+
+# include <mln/core/internal/site_set_base.hh>
+# include <mln/core/concept/function.hh>
+
+
+namespace mln
+{
+
+ // Forward declarations.
+ template <typename S, typename F> struct p_transformed;
+ template <typename Pi, typename S, typename F> struct p_transformed_piter;
+
+
+ namespace trait
+ {
+
+ template <typename S, typename F>
+ struct site_set_< p_transformed<S,F> >
+ {
+ typedef trait::site_set::nsites::unknown nsites;
+ typedef trait::site_set::bbox::unknown bbox;
+ typedef trait::site_set::contents::fixed contents;
+ typedef trait::site_set::arity::multiple arity;
+ };
+
+ } // end of namespace trait
+
+
+ /// Transform a site set \p s through the function \p f.
+ ///
+ /// \param[in] s A site set.
+ /// \param[in] f A function from site to site.
+ /// \return The transformed site set.
+ template <typename S, typename F>
+ p_transformed<S, F>
+ transform(const Site_Set<S>& s, const Function_v2v<F>& f);
+
+
+
+ /// \brief Site set transformed through a function.
+ ///
+ /// \ingroup modsitesetsparse
+ ///
+ /// Parameter \c S is a site set type; parameter F is a function
+ /// from site to site.
+ 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
+ {
+ typedef p_transformed<S,F> self_;
+ typedef internal::site_set_base_<mln_result(F), self_> super_;
+ public:
+
+ /// Element associated type.
+ typedef mln_element(S) element;
+
+
+ /// Psite associated type.
+ typedef mln_psite(S) psite;
+
+ /// Forward Site_Iterator associated type.
+ typedef p_transformed_piter<mln_fwd_piter(S), S, F> fwd_piter;
+
+ /// Backward Site_Iterator associated type.
+ typedef p_transformed_piter<mln_bkd_piter(S), S, F> bkd_piter;
+
+ /// Site_Iterator associated type.
+ typedef fwd_piter piter;
+
+
+ /// Constructor with a site set \p s and a predicate \p f.
+ p_transformed(const S& s, const F& f);
+
+ /// Constructor without argument.
+ p_transformed();
+
+
+ /// Test if this site set is valid.
+ bool is_valid() const;
+
+
+ /// Test if \p p belongs to the subset.
+ bool has(const psite& p) const;
+
+
+ /// Return the size of this site set in memory.
+ std::size_t memory_size() const;
+
+ /// Return the primary set.
+ const S& primary_set() const;
+
+ /// Return the transformation function.
+ const F& function() const;
+
+ protected:
+
+ S s_;
+ F f_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename S, typename F>
+ inline
+ p_transformed<S, F>
+ transform(const Site_Set<S>& s, const Function_v2v<F>& f)
+ {
+ mlc_equal(mln_result(F), mln_psite(S))::check();
+ p_transformed<S, F> tmp(exact(s), exact(f));
+ return tmp;
+ }
+
+
+ // p_transformed<S,F>
+
+ template <typename S, typename F>
+ inline
+ p_transformed<S,F>::p_transformed()
+ {
+ }
+
+ template <typename S, typename F>
+ inline
+ p_transformed<S,F>::p_transformed(const S& s, const F& f)
+ : s_(s),
+ f_(f)
+ {
+ }
+
+ template <typename S, typename F>
+ inline
+ bool
+ p_transformed<S,F>::has(const psite& p) const
+ {
+ return s_.has(f_(p));
+ }
+
+ template <typename S, typename F>
+ inline
+ bool
+ p_transformed<S,F>::is_valid() const
+ {
+ return s_.is_valid();
+ }
+
+ template <typename S, typename F>
+ inline
+ std::size_t
+ p_transformed<S,F>::memory_size() const
+ {
+ return s_.memory_size() + sizeof(f_);
+ }
+
+ template <typename S, typename F>
+ inline
+ const S&
+ p_transformed<S,F>::primary_set() const
+ {
+ return s_;
+ }
+
+ template <typename S, typename F>
+ inline
+ const F&
+ p_transformed<S,F>::function() const
+ {
+ return f_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+
+# include <mln/core/site_set/p_transformed_piter.hh>
+
+
+
+#endif // ! MLN_CORE_SITE_SET_P_TRANSFORMED_HH
Index: mln/core/site_set/p_transformed_piter.hh
--- mln/core/site_set/p_transformed_piter.hh (revision 0)
+++ mln/core/site_set/p_transformed_piter.hh (revision 0)
@@ -0,0 +1,159 @@
+// Copyright (C) 2009 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.
+
+#ifndef MLN_CORE_SITE_SET_P_TRANSFORMED_PITER_HH
+# define MLN_CORE_SITE_SET_P_TRANSFORMED_PITER_HH
+
+/// \file mln/core/site_set/p_transformed_piter.hh
+///
+/// Definition of iterators on p_transformed<S,F>.
+
+# include <mln/core/internal/site_set_iterator_base.hh>
+# include <mln/core/site_set/p_transformed.hh>
+
+
+namespace mln
+{
+
+
+ /// Iterator on p_transformed<S,F>.
+ ///
+ /// Parameter \c S is a site set type; parameter F is a function
+ /// from point to Boolean.
+ ///
+ /// \see mln::p_transformed
+ //
+ template <typename Pi, typename S, typename F>
+ struct p_transformed_piter
+ : public internal::site_set_iterator_base< p_transformed<S,F>, // Site_Set.
+ p_transformed_piter<Pi,S,F> > // Exact.
+ {
+ /// Constructor without argument.
+ p_transformed_piter();
+
+ /// Constructor from a site set.
+ p_transformed_piter(const p_transformed<S,F>& s);
+
+ /// Test the iterator validity.
+ bool is_valid_() const;
+
+ /// Invalidate the iterator.
+ void invalidate_();
+
+ /// Start an iteration.
+ void start_();
+
+ /// Go to the next point.
+ void next_();
+
+ /// Change the set site targeted by this iterator.
+ void change_target(const p_transformed<S,F>& s);
+
+ private:
+ typedef p_transformed_piter<Pi,S,F> self_;
+ typedef internal::site_set_iterator_base<p_transformed<S,F>, self_> super_;
+
+ protected:
+ using super_::s_;
+ using super_::p_;
+
+ // The underlying site iterator.
+ Pi pi_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename Pi, typename S, typename F>
+ inline
+ p_transformed_piter<Pi,S,F>::p_transformed_piter()
+ {
+ }
+
+ template <typename Pi, typename S, typename F>
+ inline
+ p_transformed_piter<Pi,S,F>::p_transformed_piter(const p_transformed<S,F>& s)
+ {
+ this->change_target(s);
+ }
+
+ template <typename Pi, typename S, typename F>
+ inline
+ bool
+ p_transformed_piter<Pi,S,F>::is_valid_() const
+ {
+ return pi_.is_valid();
+ }
+
+ template <typename Pi, typename S, typename F>
+ inline
+ void
+ p_transformed_piter<Pi,S,F>::invalidate_()
+ {
+ pi_.invalidate();
+ }
+
+ template <typename Pi, typename S, typename F>
+ inline
+ void
+ p_transformed_piter<Pi,S,F>::start_()
+ {
+ pi_.start();
+ if (pi_.is_valid())
+ p_ = s_->function()(pi_);
+ }
+
+ template <typename Pi, typename S, typename F>
+ inline
+ void
+ p_transformed_piter<Pi,S,F>::next_()
+ {
+ pi_.next();
+ if (pi_.is_valid())
+ p_ = s_->function()(pi_);
+ }
+
+ template <typename Pi, typename S, typename F>
+ inline
+ void
+ p_transformed_piter<Pi,S,F>::change_target(const p_transformed<S,F>& s)
+ {
+ s_ = & s;
+ // p might be also updated since it can hold a pointer towards
+ // the set it designates, so:
+ pi_.change_target(s.primary_set());
+ // Last:
+ this->invalidate();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_SITE_SET_P_TRANSFORMED_PITER_HH
Index: mln/core/image/image_if.hh
--- mln/core/image/image_if.hh (revision 3857)
+++ mln/core/image/image_if.hh (working copy)
@@ -92,6 +92,7 @@
/// \brief Image which domain is restricted by a function.
///
/// \ingroup modimagedomainmorpher
+ //
template <typename I, typename F>
struct image_if : public internal::image_domain_morpher< I,
p_if<mln_domain(I), F>,
@@ -115,18 +116,23 @@
operator image_if<const I, F>() const;
};
+
+
// Operators.
+
// Image | Function_p2b.
/// ima | f creates an image_if with the image ima and the function
/// f.
+ //
template <typename I, typename F>
image_if<I,F>
operator | (Image<I>& ima, const Function_p2b<F>& f);
/// ima | f creates an image_if with the image ima and the function
/// f.
+ //
template <typename I, typename F>
image_if<const I,F>
operator | (const Image<I>& ima, const Function_p2b<F>& f);
Index: mln/core/image/all.hh
--- mln/core/image/all.hh (revision 3857)
+++ mln/core/image/all.hh (working copy)
@@ -34,6 +34,13 @@
/// File that includes all image types.
+// Sub-directories.
+
+# include <mln/core/image/dmorph/all.hh>
+
+
+// Files.
+
# include <mln/core/image/cast_image.hh>
# include <mln/core/image/ch_piter.hh>
# include <mln/core/image/complex_image.hh>
Index: mln/core/image/sub_image.hh
--- mln/core/image/sub_image.hh (revision 3857)
+++ mln/core/image/sub_image.hh (working copy)
@@ -29,7 +29,6 @@
#ifndef MLN_CORE_IMAGE_SUB_IMAGE_HH
# define MLN_CORE_IMAGE_SUB_IMAGE_HH
-
/// \file mln/core/image/sub_image.hh
///
/// Definition of morpher that makes an image become restricted
@@ -38,7 +37,6 @@
/// \todo Add a special case for "ima | box"; think about some other
/// special cases...
-
# include <mln/core/internal/image_domain_morpher.hh>
Index: mln/core/image/dmorph/transformed_image.hh
--- mln/core/image/dmorph/transformed_image.hh (revision 0)
+++ mln/core/image/dmorph/transformed_image.hh (revision 0)
@@ -0,0 +1,272 @@
+// 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_CORE_IMAGE_DMORPH_TRANSFORMED_IMAGE_HH
+# define MLN_CORE_IMAGE_DMORPH_TRANSFORMED_IMAGE_HH
+
+/// \file mln/core/image/dmorph/transformed_image.hh
+///
+/// Definition of an image morpher that has a site set transformed
+/// through a function.
+///
+/// \todo It is a rough code.
+
+# include <mln/core/internal/image_domain_morpher.hh>
+# include <mln/core/site_set/p_transformed.hh>
+
+
+namespace mln
+{
+
+
+ // Forward declaration.
+ template <typename I, typename F> class transformed_image;
+
+
+ namespace internal
+ {
+
+ /// Data structure for \c mln::transformed_image<I,F>.
+ template <typename I, typename F>
+ struct data< transformed_image<I,F> >
+ {
+ data(I& ima, const F& f);
+
+ I ima_;
+ F f_;
+ p_transformed< mln_domain(I), F> domain_;
+ };
+
+ } // end of namespace mln::internal
+
+
+
+ namespace trait
+ {
+
+ template <typename I, typename F>
+ struct image_< transformed_image<I,F> > : default_image_morpher< I,
+ mln_value(I),
+ transformed_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_alignment::not_aligned value_alignment;
+ typedef trait::image::value_storage::disrupted value_storage;
+ };
+
+ } // end of namespace mln::trait
+
+
+
+ /// \brief Image having its domain restricted by a site set.
+ ///
+ /// \ingroup modimagedomainmorpher
+ //
+ template <typename I, typename F>
+ struct transformed_image : public internal::image_domain_morpher< I,
+ p_transformed< mln_domain(I), F>,
+ transformed_image<I,F> >
+ {
+ /// Skeleton.
+ typedef transformed_image< tag::image_<I>, tag::function_<F> > skeleton;
+
+ /// Constructor without argument.
+ transformed_image();
+
+ /// Constructor.
+ transformed_image(I& ima, const F& f);
+
+ /// Initialization.
+ void init_(I& ima, const F& f);
+
+
+ /// Give the definition domain.
+ const p_transformed< mln_domain(I), F>& domain() const;
+
+
+ /// Read-only access of pixel value at point site \p p.
+ mln_rvalue(I) operator()(const mln_psite(I)& p) const;
+
+ /// Read and "write if possible" access of pixel value at point
+ /// site \p p.
+ mln_morpher_lvalue(I) operator()(const mln_psite(I)& p);
+
+
+ /// Const promotion via conversion.
+ operator transformed_image<const I, F>() const;
+ };
+
+
+
+ // Morpher creation.
+
+ template <typename I, typename F>
+ transformed_image<const I, F>
+ transform_domain(const Image<I>& ima, const Function_v2v<F>& f);
+
+ template <typename I, typename F>
+ transformed_image<I, F>
+ transform_domain(Image<I>& ima, const Function_v2v<F>& f);
+
+
+
+ template <typename I, typename F, typename J>
+ void init_(tag::image_t, transformed_image<I,F>& target, const J& model);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // init_
+
+ template <typename I, typename F, typename J>
+ inline
+ void init_(tag::image_t, transformed_image<I,F>& target, const J& model)
+ {
+ I ima;
+ init_(tag::image, ima, model);
+ F f;
+ init_(tag::function, f, model);
+ target.init_(ima, f);
+ }
+
+
+ // internal::data< transformed_image<I,F> >
+
+ namespace internal
+ {
+
+ template <typename I, typename F>
+ inline
+ data< transformed_image<I,F> >::data(I& ima, const F& f)
+ : ima_(ima),
+ f_(f),
+ domain_(ima.domain(), f)
+ {
+ }
+
+ } // end of namespace mln::internal
+
+
+ // transformed_image<I,F>
+
+ template <typename I, typename F>
+ inline
+ transformed_image<I,F>::transformed_image()
+ {
+ }
+
+ template <typename I, typename F>
+ inline
+ transformed_image<I,F>::transformed_image(I& ima, const F& f)
+ {
+ init_(ima, f);
+ }
+
+ template <typename I, typename F>
+ inline
+ void
+ transformed_image<I,F>::init_(I& ima, const F& f)
+ {
+ mln_precondition(! this->is_valid());
+ this->data_ = new internal::data< transformed_image<I,F> >(ima, f);
+ }
+
+ template <typename I, typename F>
+ inline
+ const p_transformed< mln_domain(I), F>&
+ transformed_image<I,F>::domain() const
+ {
+ return this->data_->domain_;
+ }
+
+template <typename I, typename F>
+inline
+mln_rvalue(I)
+transformed_image<I,F>::operator()(const mln_psite(I)& p) const
+{
+ mln_precondition(this->delegatee_() != 0);
+ mln_precondition(exact(this)->has(p));
+ mln_precondition(this->delegatee_()->has(p));
+ return this->delegatee_()->operator()(this->data_->f_(p));
+}
+
+template <typename I, typename F>
+inline
+mln_morpher_lvalue(I)
+transformed_image<I,F>::operator()(const mln_psite(I)& p)
+{
+ mln_precondition(this->delegatee_() != 0);
+ mln_precondition(exact(this)->has(p));
+ mln_precondition(this->delegatee_()->has(p));
+ return this->delegatee_()->operator()(this->data_->f_(p));
+}
+
+
+ template <typename I, typename F>
+ inline
+ transformed_image<I,F>::operator transformed_image<const I, F>() const
+ {
+ transformed_image<const I, F> tmp(this->data_->ima_,
+ this->data_->f_);
+ return tmp;
+ }
+
+
+ // Morpher creation.
+
+ template <typename I, typename F>
+ inline
+ transformed_image<const I, F>
+ transform_domain(const Image<I>& ima, const Function_v2v<F>& f)
+ {
+ transformed_image<const I, F> tmp(exact(ima), exact(f));
+ return tmp;
+ }
+
+ template <typename I, typename F>
+ inline
+ transformed_image<I, F>
+ transform_domain(Image<I>& ima, const Function_v2v<F>& f)
+ {
+ transformed_image<I, F> tmp(exact(ima), exact(f));
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_IMAGE_DMORPH_TRANSFORMED_IMAGE_HH
Index: mln/core/image/dmorph/all.hh
--- mln/core/image/dmorph/all.hh (revision 0)
+++ mln/core/image/dmorph/all.hh (revision 0)
@@ -0,0 +1,39 @@
+// 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_CORE_IMAGE_DMORPH_ALL_HH
+# define MLN_CORE_IMAGE_DMORPH_ALL_HH
+
+/// \file mln/core/image/dmorph/all.hh
+///
+/// File that includes all domain morpher image types.
+
+
+# include <mln/core/image/dmorph/transformed_image.hh>
+
+
+#endif // ! MLN_CORE_IMAGE_DMORPH_ALL_HH
Index: mln/core/internal/image_base.hh
--- mln/core/internal/image_base.hh (revision 3857)
+++ mln/core/internal/image_base.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008, 2009 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
@@ -75,8 +76,10 @@
/// A base class for images.
+ ///
/// Parameter \p T is the image value type.
/// Parameter \p S is the image site set type.
+ //
template <typename T, typename S, typename E>
struct image_base
:
Index: mln/core/internal/image_morpher.hh
--- mln/core/internal/image_morpher.hh (revision 3857)
+++ mln/core/internal/image_morpher.hh (working copy)
@@ -48,7 +48,9 @@
{
/// A base class for images that are morphers. Parameter
+ ///
/// \c I is the underlying-morphed image type.
+ //
template <typename I, typename T, typename S, typename E>
class image_morpher : public image_base<T, S, E>
{
Index: mln/core/internal/image_domain_morpher.hh
--- mln/core/internal/image_domain_morpher.hh (revision 3857)
+++ mln/core/internal/image_domain_morpher.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008, 2009 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
@@ -28,10 +29,9 @@
#ifndef MLN_CORE_INTERNAL_IMAGE_DOMAIN_MORPHER_HH
# define MLN_CORE_INTERNAL_IMAGE_DOMAIN_MORPHER_HH
-/*! \file mln/core/internal/image_domain_morpher.hh
- *
- * \brief Definition of a base class for image morphers w.r.t. domain.
- */
+/// \file mln/core/internal/image_domain_morpher.hh
+///
+/// Definition of a base class for image morphers w.r.t. domain.
# include <mln/core/internal/image_morpher.hh>
Index: tests/core/site_set/p_transformed.cc
--- tests/core/site_set/p_transformed.cc (revision 0)
+++ tests/core/site_set/p_transformed.cc (revision 0)
@@ -0,0 +1,58 @@
+// 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/core/site_set/p_transformed.cc
+///
+/// Tests on mln::p_transformed.
+
+#include <mln/core/alias/box2d.hh>
+#include <mln/core/site_set/p_transformed.hh>
+#include <mln/geom/bbox.hh>
+
+
+
+
+struct wrap : mln::Function_v2v< wrap >
+{
+ typedef mln::point2d result;
+ result operator()(const result& p) const
+ {
+ return result(p.row() + 5, p.col() + 1);
+ }
+};
+
+
+int main()
+{
+ using namespace mln;
+
+ box2d b(2, 2);
+ p_transformed<box2d,wrap> s(b, wrap());
+ box2d b_ = geom::bbox(s);
+
+ mln_assertion(b_.pmin() == point2d(5,1));
+}
Index: tests/core/site_set/p_if.cc
--- tests/core/site_set/p_if.cc (revision 3853)
+++ tests/core/site_set/p_if.cc (working copy)
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2007, 2008, 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
@@ -26,7 +26,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file tests/core/site_set/pset_if.cc
+/// \file tests/core/site_set/p_if.cc
///
/// Tests on mln::p_if.
Property changes on: tests/core/site_set/p_if.cc
___________________________________________________________________
Added: svn:mergeinfo
Index: tests/core/site_set/Makefile.am
--- tests/core/site_set/Makefile.am (revision 3857)
+++ tests/core/site_set/Makefile.am (working copy)
@@ -13,7 +13,8 @@
p_queue \
p_queue_fast \
p_set \
- pset_if \
+ p_if \
+ p_transformed \
p_vaccess \
p_vertices
@@ -26,7 +27,8 @@
p_queue_SOURCES = p_queue.cc
p_queue_fast_SOURCES = p_queue_fast.cc
p_set_SOURCES = p_set.cc
-pset_if_SOURCES = pset_if.cc
+p_if_SOURCES = p_if.cc
+p_transformed_SOURCES = p_transformed.cc
p_vaccess_SOURCES = p_vaccess.cc
p_vertices_SOURCES = p_vertices.cc
p_edges_SOURCES = p_edges.cc
Index: tests/core/image/p2p_image.cc
--- tests/core/image/p2p_image.cc (revision 3857)
+++ tests/core/image/p2p_image.cc (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 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
@@ -33,8 +34,6 @@
#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))
@@ -48,8 +47,6 @@
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);
Index: tests/core/image/dmorph/Makefile.am
--- tests/core/image/dmorph/Makefile.am (revision 0)
+++ tests/core/image/dmorph/Makefile.am (revision 0)
@@ -0,0 +1,10 @@
+## Process this file through Automake to create Makefile.in.
+
+include $(top_srcdir)/milena/tests/tests.mk
+
+check_PROGRAMS = \
+ transformed_image
+
+transformed_image_SOURCES = transformed_image.cc
+
+TESTS = $(check_PROGRAMS)
Index: tests/core/image/dmorph/transformed_image.cc
--- tests/core/image/dmorph/transformed_image.cc (revision 0)
+++ tests/core/image/dmorph/transformed_image.cc (revision 0)
@@ -0,0 +1,58 @@
+// 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/core/image/dmorph/transformed_image.cc
+///
+/// Tests on mln::transformed_image.
+
+#include <mln/core/var.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/fun/p2p/translation.hh>
+#include <mln/debug/iota.hh>
+#include <mln/geom/bbox.hh>
+
+#include <mln/core/image/dmorph/transformed_image.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ box2d b(2, 3);
+ image2d<int> ima(b);
+ debug::iota(ima);
+
+ dpoint2d dp(-1,+1);
+ mln_VAR( ima_, transform_domain( ima,
+ fun::p2p::translation_t<point2d>(dp) ) );
+
+ box2d b_ = geom::bbox(ima_.domain());
+
+ mln_assertion( b_.pmin() == b.pmin() + dp &&
+ b_.pmax() == b.pmax() + dp );
+}
Index: tests/core/image/Makefile.am
--- tests/core/image/Makefile.am (revision 3857)
+++ tests/core/image/Makefile.am (working copy)
@@ -2,6 +2,9 @@
include $(top_srcdir)/milena/tests/tests.mk
+SUBDIRS = \
+ dmorph
+
##FIXME: re-enable tests
check_PROGRAMS = \
cast_image \
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2009-05-19 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Extend plot I/O with load() function.
* mln/io/all.hh: Update plot/ entries.
* mln/io/plot/all.hh: New file including plot/ files.
* mln/io/plot/load.hh: New draft for plot loading, nonfunctional.
* mln/io/plot/save.hh: Update delimiter to simple whitespace.
* mln/labeling/compute.hh: Allow accumulator array to be
passed as an argument.
---
io/all.hh | 1
io/plot/all.hh | 50 +++++++++++++++++++++
io/plot/load.hh | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++
io/plot/save.hh | 7 ---
labeling/compute.hh | 79 ++++++++++++++++++++++++++++++++++
5 files changed, 251 insertions(+), 5 deletions(-)
Index: trunk/milena/mln/io/all.hh
===================================================================
--- trunk/milena/mln/io/all.hh (revision 3854)
+++ trunk/milena/mln/io/all.hh (revision 3855)
@@ -53,6 +53,7 @@
# include <mln/io/pbm/all.hh>
# include <mln/io/pfm/all.hh>
# include <mln/io/pgm/all.hh>
+# include <mln/io/plot/all.hh>
# include <mln/io/pnm/all.hh>
# include <mln/io/ppm/all.hh>
# include <mln/io/tiff/all.hh>
Index: trunk/milena/mln/io/plot/all.hh
===================================================================
--- trunk/milena/mln/io/plot/all.hh (revision 0)
+++ trunk/milena/mln/io/plot/all.hh (revision 3855)
@@ -0,0 +1,50 @@
+// 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_IO_PLOT_ALL_HH
+# define MLN_IO_PLOT_ALL_HH
+
+/// \file mln/io/plot/all.hh
+///
+/// File that includes all plot io materials.
+
+
+namespace mln
+{
+
+ namespace io
+ {
+ /// Namespace of plot input/output handling.
+ namespace plot {}
+ }
+
+}
+
+# include <mln/io/plot/load.hh>
+# include <mln/io/plot/save.hh>
+
+#endif // ! MLN_IO_PLOT_ALL_HH
Index: trunk/milena/mln/io/plot/save.hh
===================================================================
--- trunk/milena/mln/io/plot/save.hh (revision 3854)
+++ trunk/milena/mln/io/plot/save.hh (revision 3855)
@@ -36,10 +36,7 @@
# include <iostream>
# include <fstream>
# include <mln/core/image/image1d.hh>
-# include <mln/metal/equal.hh>
# include <mln/util/array.hh>
-# include <mln/value/int_u8.hh>
-# include <mln/value/rgb8.hh>
namespace mln
@@ -88,7 +85,7 @@
std::ofstream file_out(filename.c_str());
for (unsigned i = 0; i < ima.ninds(); ++i)
- file_out << start_value + i << ", " << ima.at_(i) << std::endl;
+ file_out << start_value + i << " " << ima.at_(i) << std::endl;
trace::exiting("mln::io::plot::save");
}
@@ -102,7 +99,7 @@
std::ofstream file_out(filename.c_str());
for (unsigned i = 0; i < arr.nelements(); ++i)
- file_out << start_value + i << ", " << arr[i] << std::endl;
+ file_out << start_value + i << " " << arr[i] << std::endl;
trace::exiting("mln::io::plot::save");
}
Index: trunk/milena/mln/io/plot/load.hh
===================================================================
--- trunk/milena/mln/io/plot/load.hh (revision 0)
+++ trunk/milena/mln/io/plot/load.hh (revision 3855)
@@ -0,0 +1,119 @@
+// Copyright (C) 2009 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.
+
+#ifndef MLN_IO_PLOT_LOAD_HH
+# define MLN_IO_PLOT_LOAD_HH
+
+///
+/// \file mln/io/plot/load.hh
+///
+/// Define a routine which loads in a plot format.
+
+# include <iostream>
+# include <fstream>
+# include <mln/core/image/image1d.hh>
+# include <mln/metal/equal.hh>
+# include <mln/util/array.hh>
+# include <mln/value/int_u8.hh>
+# include <mln/value/rgb8.hh>
+
+
+namespace mln
+{
+
+ namespace io
+ {
+
+ namespace plot
+ {
+
+ /*! Load a Milena 1D image from a plot file.
+ *
+ * \param[in] ima A reference to the image to load.
+ * \param[out] filename The output file.
+ * \param[in] start_value The start index value of the plot
+ * (optional).
+ */
+ template <typename I>
+ void load(image1d<I>& ima,
+ const std::string& filename);
+
+ /*! Load a Milena array from a plot file.
+ *
+ * \param[in] arr A reference to the array to load.
+ * \param[out] filename The output file.
+ * \param[in] start_value The start index value of the plot
+ * (optional).
+ */
+ template <typename I>
+ void load(util::array<I>& arr,
+ const std::string& filename);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I>
+ inline
+ void load(image1d<I>& ima, const std::string& filename)
+ {
+ trace::entering("mln::io::plot::load");
+
+ std::ifstream file_out(filename.c_str());
+ for (unsigned i = 0; i < ima.ninds(); ++i)
+ file_out << start_value + i << ", " << ima.at_(i) << std::endl;
+
+ trace::exiting("mln::io::plot::load");
+ }
+
+ template <typename I>
+ inline
+ void load(util::array<I>& arr, const std::string& filename)
+ {
+ trace::entering("mln::io::plot::load");
+
+ std::ifstream file_out(filename.c_str());
+ while (!oef)
+ {
+ if (line is comment)
+ continue;
+ }
+
+ trace::exiting("mln::io::plot::load");
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::io::plot
+
+ } // end of namespace mln::io
+
+} // end of namespace mln
+
+
+#endif // ! MLN_IO_PLOT_LOAD_HH
Index: trunk/milena/mln/labeling/compute.hh
===================================================================
--- trunk/milena/mln/labeling/compute.hh (revision 3854)
+++ trunk/milena/mln/labeling/compute.hh (revision 3855)
@@ -63,6 +63,23 @@
/// Compute an accumulator onto the pixel values of the image \p input.
/// for each component of the image \p label.
///
+ /// \param[in] a An array of accumulator.
+ /// \param[in] input The input image.
+ /// \param[in] label The labeled image.
+ /// \param[in] nlabels The number of labels in \p label.
+ /// \return A mln::p_array of accumulator result (one result per label).
+ //
+ template <typename A, typename I, typename L>
+ util::array<mln_result(A)>
+ compute(util::array<A>& a,
+ const Image<I>& input,
+ const Image<L>& label,
+ const mln_value(L)& nlabels);
+
+
+ /// Compute an accumulator onto the pixel values of the image \p input.
+ /// for each component of the image \p label.
+ ///
/// \param[in] a An accumulator.
/// \param[in] input The input image.
/// \param[in] label The labeled image.
@@ -227,6 +244,35 @@
return res;
}
+ template <typename A, typename I, typename L>
+ inline
+ util::array<mln_result(A)>
+ compute(util::array<A>& accus,
+ const Image<I>& input_,
+ const Image<L>& label_,
+ const mln_value(L)& nlabels)
+ {
+ trace::entering("labeling::impl::generic::compute");
+ //internal::compute_tests(a_, input_, label_, nlabels);
+
+ //const A& a = exact(a_);
+ const I& input = exact(input_);
+ const L& label = exact(label_);
+
+ // FIXME: Check accus size with nlabels.
+ //util::array<A> accus(static_cast<unsigned>(nlabels) + 1, a);
+
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ accus[label(p)].take(input(p));
+
+ util::array<mln_result(A)> res;
+ convert::from_to(accus, res);
+
+ trace::exiting("labeling::impl::generic::compute");
+ return res;
+ }
+
} // end of namespace mln::labeling::impl::generic
} // end of namespace mln::labeling::impl
@@ -236,6 +282,7 @@
namespace internal
{
+
template <typename A, typename L>
inline
util::array<mln_result(A)>
@@ -258,6 +305,19 @@
return impl::generic::compute(a, input, label, nlabels);
}
+
+ template <typename A, typename I, typename L>
+ inline
+ util::array<mln_result(A)>
+ compute_dispatch(util::array<A>& a,
+ const Image<I>& input,
+ const Image<L>& label,
+ const mln_value(L)& nlabels)
+ {
+ return impl::generic::compute(a, input, label, nlabels);
+ }
+
+
} // end of namespace mln::labeling::internal
@@ -267,6 +327,25 @@
template <typename A, typename I, typename L>
inline
util::array<mln_result(A)>
+ compute(util::array<A>& a,
+ const Image<I>& input,
+ const Image<L>& label,
+ const mln_value(L)& nlabels)
+ {
+ trace::entering("labeling::compute");
+
+ //internal::compute_tests(a, input, label, nlabels);
+
+ typedef util::array<mln_result(A)> R;
+ R res = internal::compute_dispatch(a, input, label, nlabels);
+
+ trace::exiting("labeling::compute");
+ return res;
+ }
+
+ template <typename A, typename I, typename L>
+ inline
+ util::array<mln_result(A)>
compute(const Accumulator<A>& a,
const Image<I>& input,
const Image<L>& label,