https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Start a site/psite refactorization example.
* sandbox/ballas/refactorization: New.
* sandbox/ballas/refactorization/test: New.
* sandbox/ballas/refactorization/test/test.cc: New.
* sandbox/ballas/refactorization/metal: New.
* sandbox/ballas/refactorization/metal/equal.hh: New.
* sandbox/ballas/refactorization/metal/bool.hh: New.
* sandbox/ballas/refactorization/metal/bexpr.hh: New.
* sandbox/ballas/refactorization/exact.hh: New.
* sandbox/ballas/refactorization/concept.hh: New.
* sandbox/ballas/refactorization/internal: New.
* sandbox/ballas/refactorization/internal/exact.hh: New.
* sandbox/ballas/refactorization/internal/pset_base.hh: New.
* sandbox/ballas/refactorization/internal/image_base.hh: New.
* sandbox/ballas/refactorization/internal/piter_base.hh: New.
* sandbox/ballas/refactorization/internal/site_base.hh: New.
* sandbox/ballas/refactorization/internal/psite_base.hh: New.
concept.hh | 182 +++++++++++++++++++++++++++++++++++++++++++++++++
exact.hh | 95 +++++++++++++++++++++++++
internal/exact.hh | 124 +++++++++++++++++++++++++++++++++
internal/image_base.hh | 39 ++++++++++
internal/piter_base.hh | 74 +++++++++++++++++++
internal/pset_base.hh | 22 +++++
internal/psite_base.hh | 40 ++++++++++
internal/site_base.hh | 21 +++++
metal/bexpr.hh | 80 +++++++++++++++++++++
metal/bool.hh | 99 ++++++++++++++++++++++++++
metal/equal.hh | 63 ++++++++++++++++
test/test.cc | 7 +
12 files changed, 846 insertions(+)
Index: sandbox/ballas/refactorization/test/test.cc
--- sandbox/ballas/refactorization/test/test.cc (revision 0)
+++ sandbox/ballas/refactorization/test/test.cc (revision 0)
@@ -0,0 +1,7 @@
+#include <internal/image_base.hh>
+
+
+int main()
+{
+ return 0;
+}
Index: sandbox/ballas/refactorization/metal/equal.hh
--- sandbox/ballas/refactorization/metal/equal.hh (revision 0)
+++ sandbox/ballas/refactorization/metal/equal.hh (revision 0)
@@ -0,0 +1,63 @@
+// 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.
+
+#ifndef MLN_METAL_EQUAL_HH
+# define MLN_METAL_EQUAL_HH
+
+/*!
+ * \file mln/metal/equal.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <metal/bool.hh>
+
+
+# define mlc_equal(T1, T2) mln::metal::equal< T1, T2 >
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <typename T1, typename T2>
+ struct equal : false_
+ {};
+
+ template <typename T>
+ struct equal< T, T > : true_
+ {};
+
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_EQUAL_HH
Index: sandbox/ballas/refactorization/metal/bool.hh
--- sandbox/ballas/refactorization/metal/bool.hh (revision 0)
+++ sandbox/ballas/refactorization/metal/bool.hh (revision 0)
@@ -0,0 +1,99 @@
+// 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.
+
+#ifndef MLN_METAL_BOOL_HH
+# define MLN_METAL_BOOL_HH
+
+/*! \file mln/metal/bool.hh
+ *
+ * \brief Definition of a Boolean value type.
+ */
+
+# include <string>
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ // Fwd decl.
+ template <bool b> struct bool_;
+
+
+ /// "true" type.
+ template <>
+ struct bool_< true >
+ {
+ typedef bool_<true> check_t;
+ static const bool value = true;
+ typedef bool_<true> eval;
+ static void check();
+ std::string name() const { return "true"; }
+ };
+
+ typedef bool_<true> true_;
+
+
+ /// "false" type.
+ template <>
+ struct bool_< false >
+ {
+ typedef bool_<false> check_not_t;
+ static const bool value = false;
+ typedef bool_<false> eval;
+ static void check_not();
+ std::string name() const { return "false"; }
+ };
+
+ typedef bool_<false> false_;
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ inline
+ void true_::check()
+ {
+ }
+
+ inline
+ void false_::check_not()
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+# include <metal/bexpr.hh>
+
+
+#endif // ! MLN_METAL_BOOL_HH
Index: sandbox/ballas/refactorization/metal/bexpr.hh
--- sandbox/ballas/refactorization/metal/bexpr.hh (revision 0)
+++ sandbox/ballas/refactorization/metal/bexpr.hh (revision 0)
@@ -0,0 +1,80 @@
+// 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.
+
+#ifndef MLN_METAL_BEXPR_HH
+# define MLN_METAL_BEXPR_HH
+
+/*! \file mln/metal/bexpr.hh
+ *
+ * \brief Definition of types for static Boolean expressions.
+ */
+
+# include <metal/bool.hh>
+
+
+# define mlc_not( B ) mln::metal::not_< B >
+# define mlc_and( B1, B2 ) mln::metal::and_< B1, B2 >
+# define mlc_or( B1, B2 ) mln::metal::or_ < B1, B2 >
+# define mlc_xor( B1, B2 ) mln::metal::xor_< B1, B2 >
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ /// Negate type.
+ template <typename B>
+ struct not_ : bool_<( ! B::value )>
+ {};
+
+
+ /// And type.
+ template <typename L, typename R>
+ struct and_ : bool_<( L::value && R::value )>
+ {};
+
+
+ /// Or type.
+ template <typename L, typename R>
+ struct or_ : bool_<( L::value || R::value )>
+ {};
+
+
+ /// Xor type.
+ template <typename L, typename R>
+ struct xor_ : bool_<( L::value ^ R::value )>
+ {};
+
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_BOOL_HH
Index: sandbox/ballas/refactorization/exact.hh
--- sandbox/ballas/refactorization/exact.hh (revision 0)
+++ sandbox/ballas/refactorization/exact.hh (revision 0)
@@ -0,0 +1,95 @@
+// 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.
+
+#ifndef MLN_CORE_EXACT_HH
+# define MLN_CORE_EXACT_HH
+
+/*! \file mln/core/exact.hh
+ * \brief Definition of the mln::exact downcast routines.
+ */
+
+#include <internal/exact.hh>
+
+
+/// FIXME: Doc!
+#define mln_exact(T) typename internal::exact_<T>::ret
+
+
+
+namespace mln
+{
+
+ /*! \brief Exact cast routine for mln objects.
+ *
+ * This set of routines can be used to downcast an object towards
+ * its exact type. The only argument, respectively \p ptr or \p
+ * ref, should be an mln::Object.
+ *
+ * \c The parameter E is the exact type of the object.
+ *
+ * \return The return follows the nature of the argument (either a
+ * pointer or a reference, const or not).
+ */
+ /// \{
+
+ template <typename T>
+ typename internal::exact_<T>::ret*
+ exact(T* ptr);
+
+ template <typename T>
+ typename internal::exact_<T>::ret&
+ exact(T& ref);
+
+ /// \}
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // exact
+
+ template <typename T>
+ inline
+ typename internal::exact_<T>::ret*
+ exact(T* ptr)
+ {
+ return internal::exact_<T>::run(ptr);
+ }
+
+ template <typename T>
+ inline
+ typename internal::exact_<T>::ret&
+ exact(T& ref)
+ {
+ return *exact(&ref);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_EXACT_HH
Index: sandbox/ballas/refactorization/concept.hh
--- sandbox/ballas/refactorization/concept.hh (revision 0)
+++ sandbox/ballas/refactorization/concept.hh (revision 0)
@@ -0,0 +1,182 @@
+#ifndef CORE_CONCEPT_HH_
+# define CORE_CONCEPT_HH_
+
+# include <cassert>
+
+/// This file describes all the concepts
+
+namespace mln
+{
+
+ /// Object
+ template <typename E>
+ struct Object
+ {
+ typedef E exact_t;
+ protected:
+ Object();
+ };
+
+ /// Site concept
+ template <typename E>
+ struct Site : public Object<E>
+ {
+ /*
+ typedef site
+ typedef dsite;
+
+ const psite& ref_();
+ */
+ protected:
+ Site();
+ };
+
+
+ /// Psite Concept
+ /// Do we need a concept for representing psite?
+ template <typename E>
+ struct Psite : public Object<E>
+ {
+ /*
+ // Site must be different from psite,
+ // if site = psite, then the psite has no sense.
+ typedef site;
+ typedef psite;
+
+ // Site conversion
+ const site& to_site() const;
+ operator point() const;
+
+
+ const psite& ref_();
+ */
+
+ protected:
+ Psite();
+ };
+
+ /// Piter concept
+ /// Psite iterator
+ /// use template specializaion for psite == site or psite != psite
+ /// to deal with the cast problem
+ template <typename E>
+ struct Piter : public Object<E>
+ {
+ /*
+ bool is_valid() const;
+ void start();
+ void next_();
+
+ typedef psite;
+ const psite& to_psite() const;
+ operator psite() const;
+
+ typedef site;
+ const site& to_site() const;
+ operator site() const;
+ */
+
+ void next();
+ protected:
+ Piter();
+ };
+
+ /// Pset
+ /// Psite set
+ template <typename E>
+ struct Pset : public Object<E>
+ {
+ /*
+ typedef psite;
+ typedef fwd_piter;
+ typedef bkd_piter;
+
+ bool has(const psite& p) const;
+ */
+ protected:
+ Pset();
+ };
+
+
+ ///FIXME values concepts:....
+
+ /// Image concept:
+ template <typename E>
+ struct Image : public Object<E>
+ {
+ /*
+ typedef values;
+ typedef rvalues;
+ typedef lvalues;
+ //typedef vset;
+ //const vset& destination() const;
+ // const vset& values() const;
+ bool is_ready();
+
+ typedef site;
+ typedef psite;
+ rvalue operator() (const psite&) const;
+ lvalue operator() (const psite);
+ bool owns_(const psite&) const;
+ bool has(const psite&) const;
+
+ typedef fwd_piter;
+ typedef bkd_piter;
+ */
+
+ protected:
+ Image();
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ /// Object
+ template <typename E>
+ inline
+ Object<E>::Object()
+ {
+ }
+
+ /// Site
+ template <typename E>
+ inline
+ Site<E>::Site()
+ {
+ /// FIXME
+ }
+
+ /// Psite
+ template <typename E>
+ inline
+ Psite<E>::Psite()
+ {
+ }
+
+ /// Piter
+ template <typename E>
+ inline
+ Piter<E>::Piter()
+ {
+ }
+
+ template <typename E>
+ void
+ Piter<E>::next()
+ {
+ exact(this)->next_();
+ }
+
+ template <typename E>
+ Image<E>::Image()
+ {
+ /// FIXME
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+}
+
+
+
+#endif // ! CORE_CONCEPT_HH_
Index: sandbox/ballas/refactorization/internal/exact.hh
--- sandbox/ballas/refactorization/internal/exact.hh (revision 0)
+++ sandbox/ballas/refactorization/internal/exact.hh (revision 0)
@@ -0,0 +1,124 @@
+// 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.
+
+#ifndef MLN_CORE_INTERNAL_EXACT_HH
+# define MLN_CORE_INTERNAL_EXACT_HH
+
+/*! \file mln/core/internal/exact.hh
+ * \brief Meta-code for the mln::exact downcast routines.
+ */
+
+# include <concept.hh>
+
+namespace mln
+{
+
+ namespace internal
+ {
+
+ typedef char yes_;
+ struct no_ { char dummy[2]; };
+
+ template <typename T>
+ struct make_
+ {
+ static T* ptr();
+ };
+
+ template <unsigned id, typename T>
+ struct exact_ret_;
+
+ template <typename T>
+ struct exact_ret_< 1, T >
+ {
+ typedef typename T::exact_t ret;
+ };
+
+ template <typename T>
+ struct exact_ret_< 2, T >
+ {
+ typedef T ret;
+ };
+
+ template <typename E>
+ yes_ exact_selector_(Object<E>*);
+
+ no_ exact_selector_(void*);
+
+ template <typename E, typename T>
+ E* exact_run_(Object<E>* t, T*);
+
+ template <typename T>
+ T* exact_run_(void*, T* t);
+
+ template <typename T>
+ struct exact_
+ {
+ enum { id = sizeof(exact_selector_(make_<T>::ptr())) };
+ typedef typename exact_ret_<id, T>::ret ret;
+ static ret* run(T* t)
+ {
+ return exact_run_(t, t);
+ }
+ };
+
+ template <typename T>
+ struct exact_<const T>
+ {
+ enum { id = sizeof(exact_selector_(make_<T>::ptr())) };
+ typedef const typename exact_ret_<id, T>::ret ret;
+ static ret* run(const T* t)
+ {
+ return exact_run_((T*)t, (T*)t);
+ }
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E, typename T>
+ inline
+ E* exact_run_(Object<E>* t, T*)
+ {
+ return (E*)(void*)t;
+ }
+
+ template <typename T>
+ inline
+ T* exact_run_(void*, T* t)
+ {
+ return t;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::internal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INTERNAL_EXACT_HH
Index: sandbox/ballas/refactorization/internal/pset_base.hh
--- sandbox/ballas/refactorization/internal/pset_base.hh (revision 0)
+++ sandbox/ballas/refactorization/internal/pset_base.hh (revision 0)
@@ -0,0 +1,22 @@
+#ifndef INTERNAL_PSET_BASE_HH_
+# define INTERNAL_PSET_BASE_HH_
+
+
+namespace mln
+{
+ namespace internal
+ {
+ /// pset base class
+ /// P is the psite type
+ /// FIXME: psite = site => Do we declare a site
+ /// typedef in site_base class?
+ template <typename P, typename E>
+ struct pset_base_
+ {
+ typedef typename P::site site;
+ typedef P psite;
+ };
+ }
+}
+
+#endif // ! INTENAL_PSET_BASE_HH_
Index: sandbox/ballas/refactorization/internal/image_base.hh
--- sandbox/ballas/refactorization/internal/image_base.hh (revision 0)
+++ sandbox/ballas/refactorization/internal/image_base.hh (revision 0)
@@ -0,0 +1,39 @@
+#ifndef INTERNAL_IMAGE_BASE_HH_
+# define INTERNAL_IMAGE_BASE_HH_
+
+#include <concept.hh>
+
+namespace mln
+{
+ namespace internal
+ {
+ /// Image base
+ /// S is the point set type
+ template <typename S, typename E>
+ struct image_base_ : public Image<E>
+ {
+ typedef S pset;
+ typedef typename S::psite psite;
+ typedef typename S::site site;
+
+ typedef typename S::fwd_piter fwd_piter;
+ typedef typename S::bkd_piter bkd_piter;
+
+ protected:
+ image_base_();
+ };
+
+ ///FIXME: is_ready
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename S, typename E>
+ image_base_<S, E>::image_base_()
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+ }
+}
+
+#endif // ! INTERNAL_IMAGE_BASE_HH_
Index: sandbox/ballas/refactorization/internal/piter_base.hh
--- sandbox/ballas/refactorization/internal/piter_base.hh (revision 0)
+++ sandbox/ballas/refactorization/internal/piter_base.hh (revision 0)
@@ -0,0 +1,74 @@
+#ifndef INTERNAL_PITER_BASE_HH_
+# define INTERNAL_PITER_BASE_HH_
+
+# include <concept.hh>
+# include <exact.hh>
+# include <metal/bool.hh>
+# include <metal/equal.hh>
+
+namespace mln
+{
+
+ namespace internal
+ {
+
+ /// fwd declaration
+ template <typename E, typename B>
+ struct piter_base_site_cast;
+
+ /// Psite = Site
+ template <typename E>
+ struct piter_base_site_cast<E, metal::true_> : public Piter<E>
+ {
+ };
+
+ /// Psite != site
+ template <typename E>
+ struct piter_base_site_cast<E, metal::false_> : public Piter<E>
+ {
+ operator typename E::site() const;
+ };
+
+ /// Piter base
+ template <typename E>
+ struct piter_base_ :
+ public piter_base_site_cast<E,
+ typename mlc_equal(typename E::site,
+ typename E::psite)::eval>
+ {
+ operator typename E::psite() const;
+
+ protected:
+ piter_base_();
+
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ piter_base_site_cast<E, metal::false_>::operator typename E::site () const
+ {
+ return exact(this)->to_site();
+ }
+
+
+ template <typename E>
+ piter_base_<E>::operator typename E::psite () const
+ {
+ return exact(this)->to_site();
+ }
+
+
+ template <typename E>
+ piter_base_<E>::piter_base_()
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ }
+
+}
+
+
+#endif // !INTERNAL_PITER_BASE_HH_
Index: sandbox/ballas/refactorization/internal/site_base.hh
--- sandbox/ballas/refactorization/internal/site_base.hh (revision 0)
+++ sandbox/ballas/refactorization/internal/site_base.hh (revision 0)
@@ -0,0 +1,21 @@
+#ifndef INTERNAL_SITE_BASE_HH_
+# define INTERNAL_SITE_BASE_HH_
+
+# include <concept>
+
+namespace mln
+{
+ namespace internal
+ {
+
+ /// Site base class
+ template <typename S, typename E>
+ struct site_base_ : public site_base_<E>
+ {
+ typedef S site;
+ };
+ }
+}
+
+
+#endif // ! INTERNAL_SITE_BASE_HH_
Index: sandbox/ballas/refactorization/internal/psite_base.hh
--- sandbox/ballas/refactorization/internal/psite_base.hh (revision 0)
+++ sandbox/ballas/refactorization/internal/psite_base.hh (revision 0)
@@ -0,0 +1,40 @@
+#ifndef INTERNAL_PSITE_BASE_HH_
+# define INTERNAL_PSITE_BASE_HH_
+
+# include <concept.hh>
+# include <exact.hh>
+
+namespace mln
+{
+ namespace internal
+ {
+
+ template <typename E>
+ struct psite_base : public Psite<E>
+ /// FIXME Get implementation
+ {
+ operator typename E::psite () const;
+
+ protected:
+ psite_base();
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ psite_base<E>::operator typename E::psite () const
+ {
+ return exact(this)->to_site();
+ }
+
+ template <typename E>
+ psite_base<E>::psite_base()
+ {
+ }
+
+# endif // !MLN_INCLUDE_ONLY
+
+ }
+}
+
+#endif // ! INTERNAL_PSITE_BASE_HH_
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Subsampling. Draft icp.
* mln/subsampling: New.
* mln/subsampling/subsampling.hh: New.
* mln/subsampling/gaussian_subsampling.hh: gaussian blur + subsampling.
* mln/algebra: New.
* mln/algebra/vec.hh: Copy of metal::vec.
* sandbox/jardonnet/test/gaussian_subsampling.cc: New Test.
* sandbox/jardonnet/subsampling/subsampling_2d.hh: Remove.
* sandbox/jardonnet/subsampling/gaussian_subsampling.hh: New.
* sandbox/jardonnet/registration: New.
* sandbox/jardonnet/registration/icp.hh: Draft.
mln/algebra/vec.hh | 562 ++++++++++++++++++
mln/linear/gaussian.hh | 1
mln/subsampling/gaussian_subsampling.hh | 93 ++
mln/subsampling/subsampling.hh | 117 +++
sandbox/jardonnet/registration/icp.hh | 122 +++
sandbox/jardonnet/subsampling/gaussian_subsampling.hh | 93 ++
sandbox/jardonnet/test/Makefile | 12
sandbox/jardonnet/test/gaussian_subsampling.cc | 21
sandbox/jardonnet/test/subsampling.cc | 6
9 files changed, 1021 insertions(+), 6 deletions(-)
Index: mln/subsampling/subsampling.hh
--- mln/subsampling/subsampling.hh (revision 0)
+++ mln/subsampling/subsampling.hh (revision 0)
@@ -0,0 +1,117 @@
+// Copyright (C) 2008 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_SUBSAMPLING_SUBSAMPLING_HH
+# define MLN_SUBSAMPLING_SUBSAMPLING_HH
+
+/*! \file mln/binarization/threshold.hh
+ *
+ * \brief Produce a subsampled image
+ */
+
+# include <mln/geom/ncols.hh>
+# include <mln/geom/nrows.hh>
+
+
+namespace mln
+{
+
+ namespace subsampling
+ {
+
+ /*! Subsampling FIXME : doxy
+ *
+ *
+ */
+ template <typename I>
+ inline
+ mln_concrete(I)
+ subsampling(const Image<I>& input,
+ const mln_dpoint(I)& first_p,
+ const mln_coord(I)& gap);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ //FIXME : add version for every image types.
+
+ template <typename T>
+ inline
+ mln_concrete(image2d<T>)
+ subsampling_(const image2d<T>& input,
+ const mln_dpoint(image2d<T>)& first_p,
+ const mln_coord(image2d<T>)& gap)
+ {
+ trace::entering("subsampling::impl::subsampling_");
+ mln_concrete(image2d<T>) output(geom::nrows(input) / gap,
+ geom::ncols(input) / gap);
+
+ for (unsigned j = 0; j < geom::ncols(output); ++j)
+ for (unsigned i = 0; i < geom::nrows(output); ++i)
+ {
+ point2d p1(i, j);
+ point2d p2(first_p[0] + i * gap, first_p[1] + j * gap);
+
+ output(p1) = input(p2);
+ }
+
+ trace::exiting("subsampling::impl::subsampling_");
+ return output;
+ }
+
+ } // end of namespace mln::subsampling::impl
+
+
+ template <typename I>
+ inline
+ mln_concrete(I)
+ subsampling(const Image<I>& input,
+ const mln_dpoint(I)& first_p,
+ const mln_coord(I)& gap)
+ {
+ trace::entering("subsampling::subsampling");
+ mln_precondition(exact(input).has_data());
+
+ mln_concrete(I) output(geom::nrows(input) / gap,
+ geom::ncols(input) / gap); // FIXME: only 2d here
+
+ output = impl::subsampling_(exact(input), first_p, gap);
+
+ trace::exiting("subsampling::subsampling");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::subsampling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_SUBSAMPLING_SUBSAMPLING_HH
Index: mln/subsampling/gaussian_subsampling.hh
--- mln/subsampling/gaussian_subsampling.hh (revision 0)
+++ mln/subsampling/gaussian_subsampling.hh (revision 0)
@@ -0,0 +1,93 @@
+// Copyright (C) 2008 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_SUBSAMPLING_GAUSSIAN_SUBSAMPLING_HH
+# define MLN_SUBSAMPLING_GAUSSIAN_SUBSAMPLING_HH
+
+/*! \file mln/binarization/threshold.hh
+ *
+ * \brief Produce a subsampled image
+ */
+
+# include <mln/geom/ncols.hh>
+# include <mln/geom/nrows.hh>
+
+
+# include <mln/linear/gaussian.hh>
+# include <mln/subsampling/subsampling.hh>
+
+
+
+namespace mln
+{
+
+ namespace subsampling
+ {
+
+ /*! Gaussian subsampling FIXME : doxy
+ *
+ *
+ */
+ template <typename I>
+ inline
+ mln_concrete(I)
+ gaussian_subsampling(const Image<I>& input, float sigma
+ const mln_dpoint(I)& first_p,
+ const mln_coord(I)& gap);
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I>
+ inline
+ mln_concrete(I)
+ gaussian_subsampling(const Image<I>& input, float sigma,
+ const mln_dpoint(I)& first_p,
+ const mln_coord(I)& gap)
+ {
+ trace::entering("subsampling::gaussian_subsampling");
+ mln_precondition(exact(input).has_data());
+
+ mln_concrete(I) temp(exact(input).domain());
+ mln_concrete(I) output(geom::nrows(input) / gap,
+ geom::ncols(input) / gap); //FIXME : image2d only
+
+ linear::gaussian(input, 0.1, temp);
+ output = impl::subsampling_(exact(temp), first_p, gap);
+
+ trace::exiting("subsampling::gaussian_subsampling");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::subsampling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_SUBSAMPLING_GAUSSIAN_SUBSAMPLING_HH
Index: mln/linear/gaussian.hh
--- mln/linear/gaussian.hh (revision 1765)
+++ mln/linear/gaussian.hh (working copy)
@@ -1,3 +1,4 @@
+
// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development
// Laboratory
//
Index: mln/algebra/vec.hh
--- mln/algebra/vec.hh (revision 0)
+++ mln/algebra/vec.hh (revision 0)
@@ -0,0 +1,562 @@
+// Copyright (C) 2006 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_ALGEBRA_VEC_HH
+# define MLN_ALGEBRA_VEC_HH
+
+/*!
+ * \file mln/algebra/vec.hh
+ *
+ * \brief Definition of a generic vector class.
+ */
+
+# include <iostream>
+# include <cmath>
+
+# include <mln/core/concept/object.hh>
+
+# include <mln/trait/all.hh>
+# include <mln/trait/value_.hh>
+# include <mln/fun/i2v/all_to.hh>
+# include <mln/debug/format.hh>
+
+# include <mln/value/ops.hh>
+
+
+// FIXME: Document.
+
+
+namespace mln
+{
+
+ // Fwd decls.
+ namespace algebra {
+ template <unsigned n, typename T> class vec;
+ }
+ namespace literal {
+ struct zero_t;
+ }
+ template <unsigned d, typename C> struct h_vec;
+
+
+
+ namespace trait
+ {
+
+ template <unsigned n, typename T>
+ struct value_< mln::algebra::vec<n,T> >
+ {
+ typedef trait::value::nature::vectorial nature;
+ typedef trait::value::kind::data kind;
+
+ enum {
+ nbits = n * mln_nbits(T),
+ card = n * mln_card(T)
+ };
+ typedef mln_value_quant_from_(card) quant;
+
+ typedef algebra::vec<n, mln_sum(T)> sum;
+ };
+
+ } // end of namespace mln::trait
+
+
+
+ namespace algebra
+ {
+
+ namespace internal
+ {
+
+ template <unsigned n, typename T>
+ class vec_base_ : public Object< vec<n,T> >
+ {
+ protected:
+ T data_[n];
+ };
+
+ template <typename T>
+ class vec_base_ <1, T> : public Object< vec<1,T> >
+ {
+ public:
+ void set(const T& val0)
+ {
+ data_[0] = val0;
+ }
+ protected:
+ T data_[1];
+ };
+
+ template <typename T>
+ class vec_base_ <2, T> : public Object< vec<2,T> >
+ {
+ public:
+ void set(const T& val0, const T& val1)
+ {
+ data_[0] = val0;
+ data_[1] = val1;
+ }
+ protected:
+ T data_[2];
+ };
+
+ template <typename T>
+ class vec_base_ <3, T> : public Object< vec<3,T> >
+ {
+ public:
+ void set(const T& val0, const T& val1, const T& val2)
+ {
+ data_[0] = val0;
+ data_[1] = val1;
+ data_[2] = val2;
+ }
+ protected:
+ T data_[3];
+ };
+
+ template <typename T>
+ class vec_base_ <4, T> : public Object< vec<4,T> >
+ {
+ public:
+ void set(const T& val0, const T& val1, const T& val2, const T& val3)
+ {
+ data_[0] = val0;
+ data_[1] = val1;
+ data_[2] = val2;
+ data_[3] = val3;
+ }
+ protected:
+ T data_[4];
+ };
+
+
+ } // end of namespace mln::algebra::internal
+
+
+
+ template <unsigned n, typename T>
+ class vec : public internal::vec_base_<n, T>
+ {
+ typedef internal::vec_base_<n, T> super_;
+
+ protected:
+ using super_::data_;
+
+ public:
+
+ typedef T equiv[n];
+ typedef T enc[n];
+
+ typedef T coord;
+ enum { dim = n };
+
+ vec();
+
+ /// \{ Constructors/assignments with literal zero.
+ vec(const literal::zero_t&);
+ vec& operator=(const literal::zero_t&);
+ /// \}
+
+ vec(const vec<n, T>& rhs);
+
+ template <typename U>
+ vec(const vec<n, U>& rhs);
+
+ template <typename U>
+ vec& operator=(const vec<n, U>& rhs);
+
+
+ // Immersion of the vector into its homogeneous space.
+ h_vec<n, T> to_h_vec() const;
+
+
+ const T& operator[](unsigned i) const;
+
+ T& operator[](unsigned i);
+
+ void set_all(const T& val);
+
+ unsigned size() const;
+
+ const vec<n, T>& normalize();
+
+ /// Constructor; coordinates are set by function \p f.
+ template <typename F>
+ vec(const Function_i2v<F>& f);
+
+ /// Zero value.
+ static const vec<n, T> zero;
+
+ /// Origin value.
+ static const vec<n, T> origin;
+ };
+
+ } // end of namespace mln::algebra
+
+
+ namespace trait
+ {
+
+ // For unary traits.
+
+ template < template <class> class Name,
+ unsigned n, typename T >
+ struct set_precise_unary_< Name, algebra::vec<n, T> >
+ {
+ typedef mln_trait_unary(Name, T) V;
+ typedef algebra::vec<n, V> ret;
+ };
+
+ // For binary traits.
+
+ template < template <class, class> class Name,
+ unsigned n, typename T,
+ typename U >
+ struct set_precise_binary_< Name,
+ algebra::vec<n, T>, algebra::vec<n, U> >
+ {
+ typedef mln_trait_binary(Name, T, U) V;
+ typedef algebra::vec<n, V> ret;
+ };
+
+ template < unsigned n, typename T,
+ typename U >
+ struct set_precise_binary_< op::times,
+ algebra::vec<n, T>, algebra::vec<n, U> >
+ {
+ typedef mln_sum_x(T,U) ret;
+ };
+
+ template < template <class, class> class Name,
+ unsigned n, typename T,
+ typename S >
+ struct set_precise_binary_< Name,
+ algebra::vec<n, T>, mln::value::scalar_<S> >
+ {
+ typedef mln_trait_binary(Name, T, S) V;
+ typedef algebra::vec<n, V> ret;
+ };
+
+ template < template<class, class> class Name,
+ unsigned n, typename T,
+ typename S >
+ struct set_binary_< Name,
+ mln::Object, algebra::vec<n, T>,
+ mln::value::Scalar, S >
+ {
+ typedef mln_trait_binary(Name, T, S) V;
+ typedef algebra::vec<n, V> ret;
+ };
+
+ } // end of namespace mln::trait
+
+
+
+ namespace algebra
+ {
+
+ // eq
+
+ template <unsigned n, typename T, typename U>
+ bool operator==(const vec<n,T>& lhs, const vec<n,U>& rhs);
+
+ // +
+
+ template <unsigned n, typename T, typename U>
+ vec<n, mln_trait_op_plus(T,U)>
+ operator+(const vec<n,T>& lhs, const vec<n,U>& rhs);
+
+ // -
+
+ template <unsigned n, typename T, typename U>
+ vec<n, mln_trait_op_minus(T,U)>
+ operator-(const vec<n,T>& lhs, const vec<n,U>& rhs);
+
+ // vec * vec
+
+ template <unsigned n, typename T, typename U>
+ mln_sum_x(T,U)
+ operator*(const vec<n,T>& lhs, const vec<n,U>& rhs);
+
+ // vec * s
+
+ template <unsigned n, typename T, typename S>
+ vec<n, mln_trait_op_times(T, S)>
+ operator*(const vec<n,T>& lhs, const mln::value::scalar_<S>& s);
+
+ // vec / s
+
+ template <unsigned n, typename T, typename S>
+ vec<n, mln_trait_op_div(T, S)>
+ operator/(const vec<n,T>& lhs, const mln::value::scalar_<S>& s);
+
+ // <<
+
+ template <unsigned n, typename T>
+ std::ostream&
+ operator<<(std::ostream& ostr, const vec<n,T>& v);
+
+ // vprod // FIXME: Generalize...
+
+ template <typename T, typename U>
+ vec<3, mln_trait_op_times(T,U)> // FIXME: Sum of product...
+ vprod(const vec<3, T>& lhs, const vec<3, U>& rhs);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned n, typename T>
+ inline
+ vec<n,T>::vec()
+ {
+ }
+
+ template <unsigned n, typename T>
+ inline
+ vec<n,T>::vec(const literal::zero_t&)
+ {
+ this->set_all(0);
+ }
+
+ template <unsigned n, typename T>
+ inline
+ vec<n,T>&
+ vec<n,T>::operator=(const literal::zero_t&)
+ {
+ this->set_all(0);
+ return *this;
+ }
+
+ template <unsigned n, typename T>
+ inline
+ vec<n,T>::vec(const vec<n,T>& rhs)
+ : super_()
+ {
+ for (unsigned i = 0; i < n; ++i)
+ data_[i] = rhs[i];
+ }
+
+ template <unsigned n, typename T>
+ template <typename U>
+ inline
+ vec<n,T>::vec(const vec<n, U>& rhs)
+ : super_()
+ {
+ for (unsigned i = 0; i < n; ++i)
+ data_[i] = rhs[i];
+ }
+
+ template <unsigned n, typename T>
+ template <typename U>
+ inline
+ vec<n,T>& vec<n,T>::operator=(const vec<n, U>& rhs)
+ {
+ for (unsigned i = 0; i < n; ++i)
+ data_[i] = rhs[i];
+ return *this;
+ }
+
+ template <unsigned n, typename T>
+ inline
+ const T& vec<n,T>::operator[](unsigned i) const
+ {
+ mln_precondition(i < dim);
+ return data_[i];
+ }
+
+ template <unsigned n, typename T>
+ inline
+ T& vec<n,T>::operator[](unsigned i)
+ {
+ mln_precondition(i < dim);
+ return data_[i];
+ }
+
+ template <unsigned n, typename T>
+ inline
+ void vec<n,T>::set_all(const T& val)
+ {
+ for (unsigned i = 0; i < n; ++i)
+ data_[i] = val;
+ }
+
+ template <unsigned n, typename T>
+ inline
+ unsigned vec<n,T>::size() const
+ {
+ return n;
+ }
+
+ template <unsigned n, typename T>
+ inline
+ const vec<n, T>& vec<n, T>::normalize()
+ {
+ float n_l2 = 0;
+ for (unsigned i = 0; i < n; ++i)
+ n_l2 += data_[i] * data_[i];
+ n_l2 = sqrt(n_l2);
+ for (unsigned i = 0; i < n; ++i)
+ data_[i] = T(data_[i] / n_l2);
+ return *this;
+ }
+
+ template <unsigned n, typename T>
+ template <typename F>
+ inline
+ vec<n, T>::vec(const Function_i2v<F>& f_)
+ {
+ mlc_converts_to(mln_result(F), T)::check();
+ const F& f = exact(f_);
+ for (unsigned i = 0; i < n; ++i)
+ data_[i] = f(i);
+ }
+
+
+ template <unsigned n, typename T>
+ const vec<n, T> vec<n, T>::zero = all_to(0);
+
+ template <unsigned n, typename T>
+ const vec<n, T> vec<n, T>::origin = all_to(0);
+
+
+ // Operators.
+
+
+ template <unsigned n, typename T, typename U>
+ inline
+ bool operator==(const vec<n,T>& lhs, const vec<n,U>& rhs)
+ {
+ for (unsigned i = 0; i < n; ++i)
+ if (lhs[i] != rhs[i])
+ return false;
+ return true;
+ }
+
+
+ template <unsigned n, typename T, typename U>
+ inline
+ vec<n, mln_trait_op_plus(T,U)>
+ operator+(const vec<n,T>& lhs, const vec<n,U>& rhs)
+ {
+ vec<n, mln_trait_op_plus(T,U)> tmp;
+ for (unsigned i = 0; i < n; ++i)
+ tmp[i] = lhs[i] + rhs[i];
+ return tmp;
+ }
+
+ template <unsigned n, typename T, typename U>
+ inline
+ vec<n, mln_trait_op_minus(T,U)>
+ operator-(const vec<n,T>& lhs, const vec<n,U>& rhs)
+ {
+ vec<n, mln_trait_op_minus(T,U)> tmp;
+ for (unsigned i = 0; i < n; ++i)
+ tmp[i] = lhs[i] - rhs[i];
+ return tmp;
+ }
+
+ template <unsigned n, typename T, typename U>
+ inline
+ mln_sum_x(T,U)
+ operator*(const vec<n,T>& lhs, const vec<n,U>& rhs)
+ {
+ mln_sum_x(T,U) tmp(literal::zero);
+ for (unsigned i = 0; i < n; ++i)
+ tmp += lhs[i] * rhs[i];
+ return tmp;
+ }
+
+ template <unsigned n, typename T, typename S>
+ inline
+ vec<n, mln_trait_op_times(T, S)>
+ operator*(const vec<n,T>& lhs, const mln::value::scalar_<S>& s)
+ {
+ // FIXME: We made a choice here but is it correct?
+ // FIXME: We "un-scalar" s so that the scalar status do not propagate.
+
+ // Think of the case: vec<mat> v * scalar(vec w) s
+ // It gives: for all i, v[i] * w so the i-th mat * vec w -> vec
+ // The result is a vec<vec>
+
+ // If we really want to propage the "scalar" status then
+ // we shall allow for scalar(scalar(..)) !!! => FIXME
+
+ vec<n, mln_trait_op_times(T, S)> tmp;
+ for (unsigned i = 0; i < n; ++i)
+ tmp[i] = lhs[i] * s.to_equiv();
+ return tmp;
+ }
+
+ template <unsigned n, typename T, typename S>
+ inline
+ vec<n, mln_trait_op_div(T, S)>
+ operator/(const vec<n,T>& lhs, const mln::value::scalar_<S>& s)
+ {
+ mln_precondition(value::equiv(s) != literal::zero);
+ vec<n, mln_trait_op_div(T, S)> tmp;
+ for (unsigned i = 0; i < n; ++i)
+ tmp[i] = lhs[i] / s.to_equiv();
+ return tmp;
+ }
+
+
+ template <unsigned n, typename T>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const vec<n,T>& v)
+ {
+ ostr << '(';
+ for (unsigned i = 0; i < n; ++i)
+ ostr << debug::format(v[i]) << (i == n - 1 ? ")" : ", ");
+ return ostr;
+ }
+
+ // vprod
+
+ template <typename T, typename U>
+ inline
+ vec<3, mln_trait_op_times(T,U)> // FIXME: typename binary_arith_trait<T, U>::ret>
+ vprod(const vec<3, T>& lhs, const vec<3, U>& rhs)
+ {
+ vec<3, mln_trait_op_times(T,U)> tmp; // FIXME: Likewise.
+ tmp[0] = lhs[1] * rhs[2] - lhs[2] * rhs[1];
+ tmp[1] = lhs[2] * rhs[0] - lhs[0] * rhs[2];
+ tmp[2] = lhs[0] * rhs[1] - lhs[1] * rhs[0];
+ return tmp;
+ }
+
+# endif // MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::algebra
+
+} // end of namespace mln
+
+
+# include <mln/make/vec.hh>
+
+
+#endif // ! MLN_ALGEBRA_VEC_HH
Index: sandbox/jardonnet/test/gaussian_subsampling.cc
--- sandbox/jardonnet/test/gaussian_subsampling.cc (revision 0)
+++ sandbox/jardonnet/test/gaussian_subsampling.cc (revision 0)
@@ -0,0 +1,21 @@
+#include <mln/core/image2d.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <sandbox/jardonnet/subsampling/gaussian_subsampling.hh>
+
+
+int main(int argc, char*)
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d<int_u8> img;
+
+ io::pgm::load(img, "../../../img/lena.pgm");
+
+ image2d<int_u8> output = subsampling::gaussian_subsampling(img, make::dpoint2d(1,1), argc);
+
+ io::pgm::save(output, "gsub.pgm");
+}
Index: sandbox/jardonnet/test/subsampling.cc
--- sandbox/jardonnet/test/subsampling.cc (revision 1765)
+++ sandbox/jardonnet/test/subsampling.cc (working copy)
@@ -3,7 +3,7 @@
#include <mln/io/pgm/load.hh>
#include <mln/io/pgm/save.hh>
-#include <sandbox/jardonnet/subsampling/subsampling_2d.hh>
+#include <mln/subsampling/subsampling.hh>
int main(int argc, char*)
@@ -16,7 +16,7 @@
io::pgm::load(img, "../../../img/lena.pgm");
std::cout << geom::nrows(img) << geom::ncols(img) << std::endl;
- image2d<int_u8> output = subsampling::subsampling_2d(img, make::dpoint2d(1,1), argc);
+ image2d<int_u8> output = subsampling::subsampling(img, make::dpoint2d(1,1), argc);
- io::pgm::save(output, "out1.pgm");
+ io::pgm::save(output, "sub.pgm");
}
Index: sandbox/jardonnet/test/Makefile
--- sandbox/jardonnet/test/Makefile (revision 1765)
+++ sandbox/jardonnet/test/Makefile (working copy)
@@ -1,8 +1,14 @@
SOURCE=test.cc subsampling.cc
FLAG=-Wall -W -I../../.. -g
-all:
- g++ $(SOURCE) $(FLAG) -o '+a.out'
+all: sub gsub
+
sub:
- g++ subsampling.cc $(FLAG) -o '+a.out'
+ g++ subsampling.cc $(FLAG) -o '+sub.exe'
+
+gsub:
+ g++ gaussian_subsampling.cc $(FLAG) -o '+gsub.exe'
+
+run:
+ time ./+sub.exe . . ; time ./+gsub.exe . .
\ No newline at end of file
Index: sandbox/jardonnet/subsampling/gaussian_subsampling.hh
--- sandbox/jardonnet/subsampling/gaussian_subsampling.hh (revision 0)
+++ sandbox/jardonnet/subsampling/gaussian_subsampling.hh (revision 0)
@@ -0,0 +1,93 @@
+// Copyright (C) 2008 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_SUBSAMPLING_GAUSSIAN_SUBSAMPLING_HH
+# define MLN_SUBSAMPLING_GAUSSIAN_SUBSAMPLING_HH
+
+/*! \file mln/binarization/threshold.hh
+ *
+ * \brief Produce a subsampled image
+ */
+
+# include <mln/geom/ncols.hh>
+# include <mln/geom/nrows.hh>
+
+
+# include <mln/linear/gaussian.hh>
+# include <mln/subsampling/subsampling.hh>
+
+
+
+namespace mln
+{
+
+ namespace subsampling
+ {
+
+ /*! Subsampling FIXME : doxy
+ *
+ *
+ */
+ template <typename I>
+ inline
+ mln_concrete(I)
+ gaussian_subsampling(const Image<I>& input, float sigma
+ const mln_dpoint(I)& first_p,
+ const mln_coord(I)& gap);
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I>
+ inline
+ mln_concrete(I)
+ gaussian_subsampling(const Image<I>& input, float sigma,
+ const mln_dpoint(I)& first_p,
+ const mln_coord(I)& gap)
+ {
+ trace::entering("subsampling::gaussian_subsampling");
+ mln_precondition(exact(input).has_data());
+
+ mln_concrete(I) temp(exact(input).domain());
+ mln_concrete(I) output(geom::nrows(input) / gap,
+ geom::ncols(input) / gap); //FIXME : only for image2d.
+
+ linear::gaussian(input, 0.1, temp);
+ output = impl::subsampling_(exact(temp), first_p, gap);
+
+ trace::exiting("subsampling::gaussian_subsampling");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::subsampling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_SUBSAMPLING_GAUSSIAN_SUBSAMPLING_HH
Index: sandbox/jardonnet/registration/icp.hh
--- sandbox/jardonnet/registration/icp.hh (revision 0)
+++ sandbox/jardonnet/registration/icp.hh (revision 0)
@@ -0,0 +1,122 @@
+// Copyright (C) 2008 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_REGISTRATION_REGISTRATION_HH
+# define MLN_REGISTRATION_REGISTRATION_HH
+
+/*! \file mln/binarization/threshold.hh
+ *
+ * \brief Produce a subsampled image
+ */
+
+# include <mln/value/quat.hh>
+# include <mln/algebra/vec.hh>
+
+namespace mln
+{
+
+ namespace registration
+ {
+
+ /*! Registration FIXME : doxy
+ *
+ *
+ */
+ template <typename I>
+ inline
+ void
+ icp(const Image<I>& cloud,
+ const Image<J>& surface);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ //FIXME : add version for every image types.
+
+ template <typename I, typename J>
+ inline
+ void
+ icp_(const I& P,
+ const J& X)
+ {
+ trace::entering("registration::impl::icp_");
+
+ mln_concrete(I) Pk(cloud.domain());
+
+ const float epsilon = 1e-3;
+ float err, err_bis;
+ quat old_qk, qk;
+ unsigned int k;
+
+
+ k = 0;
+ Pk = P;
+ do {
+ //projection
+
+ old_qk = qk;
+
+ //qk = match(P, mu_P, Xk, mu_Xk);
+
+ // error =
+
+ } while (k < 3 || (qk - old_qk).sqr_norm() > epsilon);
+
+
+ trace::exiting("registration::impl::icp_");
+ }
+
+ } // end of namespace mln::registration::impl
+
+
+ template <typename I, typename J>
+ inline
+ void
+ icp(const Image<I>& cloud,
+ const Image<J>& surface)
+ {
+ trace::entering("registration::icp");
+ mln_precondition(exact(cloud).has_data());
+ mln_precondition(exact(surface).has_data());
+
+ output = impl::icp_(exact(cloud), exact(surface));
+
+ trace::exiting("registration::icp");
+ }
+
+ //cloud == image ?
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::registration
+
+} // end of namespace mln
+
+
+#endif // ! MLN_REGISTRATION_ICP_HH
https://svn.lrde.epita.fr/svn/oln/trunk
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Augment tutorial on image types.
* milena/doc/tutorial/image_types.txt: Augment.
image_types.txt | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 128 insertions(+), 1 deletion(-)
Index: milena/doc/tutorial/image_types.txt
--- milena/doc/tutorial/image_types.txt (revision 1763)
+++ milena/doc/tutorial/image_types.txt (working copy)
@@ -59,6 +59,14 @@
for all v of ima.values
| print v.
+For such image types, we have several points (sites) associated with a
+single value cell. It is rather different from having couples (p,v);
+we actually have one value cell -> a set of points. Such data
+structure allows for compressing data because each value cell is
+shared by several points.
+
+*** Example 1
+
Consider for instance the following image:
+-----+
@@ -67,6 +75,8 @@
| 22 |
+-----+
+We have one value per run.
+
The value type is int_u2 (unsigned integer on 2 bit), that is, the
type of the interval [0,3] of N. The image is defined by a run-length
encoding with a single value per run. Precisely, this image is:
@@ -93,6 +103,115 @@
v v v
{ ((a,1),2), ((b,3),1), ((c,2),2) }
+**** A clue?
+
+***** part 1
+
+When we have value cells, it is usually related to the fact that the
+image is not point-wise writable. For instance, with the image type
+having one value per run, the operation "ima(p) := v" is not possible.
+Otherwise, that would mean that a run is split on such a write access,
+which is too slow (thus not allowed).
+
+Some rare image types can be both point-wise writable and value cell
+iterable. For instance:
+
+ image<int_u8> data;
+ map<int_u8, rgb_3x8> lut; // with i != j => lut[i] != lut[j]
+ map<rgb_3x8, int_u8> reverse_lut;
+
+The keys, resp. the values, of the lut are the values, resp. the keys,
+of the reverse_lut. With this structure, we can have a rather efficient
+point-wise writable image.
+
+ima(p) <- v {
+ it <- reverse_lut.find(v)
+ if (it is not found)
+ ++n
+ lut(n) <- v
+ reverse_lut(v) <- n
+ data(p) <- n
+ else
+ data(p) <- it.key
+}
+
+***** part 2
+
+When an image is value-wise writable, we can form:
+ ima.value(red) = blue;
+It means that we can quickly access to the cell (or the cells)
+having the value 'red'.
+
+When an image is value-cell writable, we can have:
+ for v in ima.values()
+ ima.cell(v) = v'
+In that case, a 'v' is a value cell, not a value.
+
+***** part 3
+
+Is the notion of value-wise readable relevant?
+ ima.value(red) // read-access
+gives:
+ - red, which is dummy!
+or - the corresponding point set, which can be great!
+
+This is another property...
+
+
+*** Example 2
+
+Consider this image type:
+
+{ data + +-----------+
+ | 0 2 1 0 2 |
+ | 0 0 3 2 1 |
+ | 2 1 2 2 0 |
+ +-----------+;
+ lut + +---+---------------+
+ | 0 | (255, 0, 0) | red (r)
+ | 1 | (127,127,127) | medium grey (m)
+ | 2 | ( 0, 0,255) | blue (b)
+ | 3 | (127,127,127) | medium grey (m) again
+ +---+---------------+
+}
+
+This image is defined with a look-up table; its external
+representation actually is:
+
+ +-----------+
+ | r b m r b |
+ | r r m b m |
+ | b m b b r |
+ +-----------+
+
+(conversely, the internal representation is the 'data' image.)
+
+We have I::value = rgb_3x8
+so the image appears to be highly quantized (24 bit).
+
+Yet the number of possible values is limited (here up to 4, even if
+two value cells are identical) and stored by the image in the look-up
+table.
+
+It leads to:
+ code A) rbmrbrrmbmbmbbr
+ code B) rmb
+ code C) rmbm
+
+ima.destination (browsed by code B) is an instance of
+value::subset<rgb_3x8>.
+
+FIXME: OR (?)
+
+It leads to:
+ code A) rbmrbrrmbmbmbbr
+ code B) impossible because 24bit data
+ code C) rmbm
+
+and I.destination gives value::set<rgb_3x8>.
+
** associated types
@@ -232,7 +351,15 @@
|
+ -- high
-****
+**** low
+
+I::value defines a set of possible values whose cardinality is less
+than or equal to 2^16.
+
+FIXME: OR (?)
+
+I.destination (same definition)
+
*** value
|
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Add an image type based on boost adjacency_list.
* tests/core/bgraph_image.cc,
* tests/core/p_bgraph.cc: New test.
* mln/core/p_bgraph_piter.hh: Point Iterator on p_bgraph.
* mln/core/bgraph_image.hh: New image type (not fully tested yet).
* mln/core/p_bgraph.hh: New, Point Set based on a boost graph.
* mln/core/bgraph_psite.hh: New.
* mln/util/internal/boost_graph.hh,
* mln/util/internal/boost_graph_structure.hh: Fix some bugs.
mln/core/bgraph_image.hh | 309 +++++++++++++++++++++++++++++
mln/core/bgraph_psite.hh | 178 ++++++++++++++++
mln/core/p_bgraph.hh | 221 ++++++++++++++++++++
mln/core/p_bgraph_piter.hh | 244 ++++++++++++++++++++++
mln/util/internal/boost_graph.hh | 43 +++-
mln/util/internal/boost_graph_structure.hh | 12 -
tests/core/bgraph_image.cc | 94 ++++++++
tests/core/p_bgraph.cc | 87 ++++++++
8 files changed, 1178 insertions(+), 10 deletions(-)
Index: tests/core/bgraph_image.cc
--- tests/core/bgraph_image.cc (revision 0)
+++ tests/core/bgraph_image.cc (revision 0)
@@ -0,0 +1,94 @@
+// Copyright (C) 2007, 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/bgraph_image.cc
+/// \brief Tests on mln::bgraph_image.
+
+#include <vector>
+#include <mln/core/point2d.hh>
+#include <mln/core/bgraph_image.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ /*--------.
+ | Graph. |
+ `--------*/
+ using namespace mln;
+ typedef util::internal::boost_graph<point2d, util::empty> Graph;
+
+ // Make convenient labels for the vertices
+ const int num_vertices = 5;
+
+ // writing out the edges in the graph
+ typedef std::pair<int, int> Edge;
+ Edge edge_array[] = {
+ Edge(0, 1), Edge(0, 3), Edge(2, 0), Edge(3, 2),
+ Edge(2, 4), Edge(1, 3), Edge(3, 4)
+ };
+
+ const int num_edges = sizeof(edge_array)/sizeof(edge_array[0]);
+ // declare a graph object
+ Graph g(num_vertices);
+
+ // add the edges to the graph object
+ for (int i = 0; i < num_edges; ++i)
+ boost::add_edge(edge_array[i].first, edge_array[i].second, g);
+
+ g[0] = make::point2d(0, 0);
+ g[1] = make::point2d(0, 1);
+ g[2] = make::point2d(1, 0);
+ g[3] = make::point2d(1, 1);
+ g[4] = make::point2d(0, 2);
+
+ /*------------------.
+ | Boost Graph Image |
+ `-------------------*/
+
+ /*--------------.
+ | Vector values |
+ `--------------*/
+
+ typedef bgraph_image<point2d, int> ima_type;
+
+ std::vector<int> values;
+ values.push_back(1);
+ values.push_back(2);
+ values.push_back(3);
+ values.push_back(4);
+ values.push_back(5);
+
+ ima_type ima(g, values);
+ mln_piter_(ima_type) p(ima.domain());
+ for_all(p)
+ std::cout << ima(p) << std::endl;
+
+ return 0;
+}
Index: tests/core/p_bgraph.cc
--- tests/core/p_bgraph.cc (revision 0)
+++ tests/core/p_bgraph.cc (revision 0)
@@ -0,0 +1,87 @@
+// Copyright (C) 2007, 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/p_bgraph.cc
+/// \brief Tests on mln::p_bgraph (the psite based on boost-graph).
+
+#include <mln/core/p_bgraph.hh>
+#include <mln/core/point2d.hh>
+#include <mln/util/internal/boost_graph.hh>
+#include <boost/typeof/std/utility.hpp>
+
+struct empty {};
+
+int main()
+{
+ /*--------------.
+ | boost_graph. |
+ `--------------*/
+
+ using namespace mln;
+ typedef util::internal::boost_graph<point2d, util::empty> Graph;
+
+ // Make convenient labels for the vertices
+ const int num_vertices = 5;
+
+ // writing out the edges in the graph
+ typedef std::pair<int, int> Edge;
+ Edge edge_array[] = {
+ Edge(0, 1), Edge(0, 3), Edge(2, 0), Edge(3, 2),
+ Edge(2, 4), Edge(1, 3), Edge(3, 4)
+ };
+
+ const int num_edges = sizeof(edge_array)/sizeof(edge_array[0]);
+ // declare a graph object
+ Graph g(num_vertices);
+
+ // add the edges to the graph object
+ for (int i = 0; i < num_edges; ++i)
+ boost::add_edge(edge_array[i].first, edge_array[i].second, g);
+
+ g[0] = make::point2d(0, 0);
+ g[1] = make::point2d(0, 1);
+ g[2] = make::point2d(1, 0);
+ g[3] = make::point2d(1, 1);
+ g[4] = make::point2d(0, 2);
+
+ /*-----------.
+ | p_bgraph. |
+ `-----------*/
+
+ /// Creation
+ p_bgraph<point2d> pset(g);
+
+ /// Iterator
+ p_bgraph_piter_<point2d> p(pset);
+
+ for (p.start(); p.is_valid(); p.next())
+ std::cout << p << std::endl;
+
+
+
+ return 0;
+}
Index: mln/core/p_bgraph_piter.hh
--- mln/core/p_bgraph_piter.hh (revision 0)
+++ mln/core/p_bgraph_piter.hh (revision 0)
@@ -0,0 +1,244 @@
+// Copyright (C) 2007, 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.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_P_BGRAPH_PITER_HH
+# define MLN_CORE_P_BGRAPH_PITER_HH
+
+# include <utility>
+
+# include <mln/core/internal/point_iterator_base.hh>
+# include <mln/core/p_bgraph.hh>
+# include <mln/core/bgraph_psite.hh>
+
+/*! \file mln/core/p_bgraph_piter.hh
+ *
+ * \brief Definition of point iterator on boost-graph-based point set.
+ */
+
+namespace mln
+{
+ // Fwd decls.
+ template<typename P> class p_bgraph;
+ template<typename P> class bgraph_psite;
+
+
+ // FIXME: check the constraint due to the boost iterators
+ template<typename P>
+ class p_bgraph_piter_
+ : public internal::point_iterator_base_< P, p_bgraph_piter_<P> >
+ {
+ typedef p_bgraph_piter_<P> self_;
+ typedef internal::point_iterator_base_< P, self_ > super_;
+ typedef std::pair<typename p_bgraph<P>::node_iterator,
+ typename p_bgraph<P>::node_iterator> iterators_type_;
+
+ public:
+
+ // Make definitions from super class available.
+ enum { dim = super_::dim };
+ typedef bgraph_psite<P> psite;
+ typedef P point;
+
+ p_bgraph_piter_(const p_bgraph<P>& pg);
+
+ /// Read-only access to the \p i-th coordinate.
+ mln_coord(P) operator[](unsigned i) const;
+
+ /// Test if the iterator is valid.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ /// Update the internal data of the iterator.
+ void update_();
+
+ /// Reference to the corresponding point.
+ const point& to_point () const;
+
+ /// Reference to the corresponding point site.
+ const psite& to_psite () const;
+
+ /// Convert the iterator into a point.
+ operator point() const;
+
+ /// Convert the iterator into a graph psite.
+ operator psite() const;
+
+ protected:
+ /// The p_graph this point site belongs to.
+ const p_bgraph<P>& pg_;
+
+ /// The psite corresponding to this iterator.
+ psite psite_;
+ /// The point corresponding to this iterator.
+ point p_;
+
+ private:
+ iterators_type_ iterators_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template<typename P>
+ inline
+ p_bgraph_piter_<P>::p_bgraph_piter_(const p_bgraph<P>& pg)
+ : pg_(pg),
+ // Initialize psite_ to a dummy value.
+ psite_(pg, pg_.npoints()),
+ p_()
+ {
+ // Initialize the iterators
+ start();
+
+ // Invalidate id_.
+ invalidate();
+ }
+
+ template<typename P>
+ inline
+ mln_coord(P)
+ p_bgraph_piter_<P>::operator[](unsigned i) const
+ {
+ return p_[i];
+ }
+
+ template<typename P>
+ inline
+ bool
+ p_bgraph_piter_<P>::is_valid() const
+ {
+ return iterators_.first != iterators_.second;
+ }
+
+ template<typename P>
+ inline
+ void
+ p_bgraph_piter_<P>::invalidate()
+ {
+ iterators_.first == iterators_.second;
+ }
+
+ template<typename P>
+ inline
+ void
+ p_bgraph_piter_<P>::start()
+ {
+ /// FIXME: Hide implementation details?
+ iterators_ = boost::vertices(pg_.to_graph());
+ update_();
+ }
+
+ template<typename P>
+ inline
+ void
+ p_bgraph_piter_<P>::next_()
+ {
+ ++iterators_.first;
+ update_();
+ }
+
+ template<typename P>
+ inline
+ void
+ p_bgraph_piter_<P>::update_()
+ {
+ // Update psite_.
+ psite_ = bgraph_psite<P>(pg_, *iterators_.first);
+ // Update p_.
+ p_ = pg_.point_from_id(*iterators_.first);
+ }
+
+ template<typename P>
+ inline
+ const P&
+ p_bgraph_piter_<P>::to_point() const
+ {
+ /* We don't check whether the iterator is valid before returning
+ the value using
+
+ mln_precondition(is_valid());
+
+ since this method may be called *before* the iterator is
+ actually initialized. This is the case for instance when this
+ point iterator (say, P) is used to initialize another iterator
+ on window or neighborhood (say, Q); most of the time, for_all()
+ is responsible for the initialization of P, but it takes place
+ *after* the creation of Q. */
+ return p_;
+ }
+
+ template<typename P>
+ inline
+ const bgraph_psite<P>&
+ p_bgraph_piter_<P>::to_psite() const
+ {
+ /* We don't check whether the iterator is valid before returning
+ the value using
+
+ mln_precondition(is_valid());
+
+ since this method may be called *before* the iterator is
+ actually initialized. This is the case for instance when this
+ point iterator (say, P) is used to initialize another iterator
+ on window or neighborhood (say, Q); most of the time, for_all()
+ is responsible for the initialization of P, but it takes place
+ *after* the creation of Q. */
+
+ return psite_;
+ }
+
+ template<typename P>
+ inline
+ p_bgraph_piter_<P>::operator P() const
+ {
+ mln_precondition(is_valid());
+ return p_;
+ }
+
+ template<typename P>
+ inline
+ p_bgraph_piter_<P>::operator bgraph_psite<P>() const
+ {
+ mln_precondition(is_valid());
+ return psite_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of mln
+
+
+#endif // MLN_P_BGRAPH_PITER_HH
Index: mln/core/bgraph_image.hh
--- mln/core/bgraph_image.hh (revision 0)
+++ mln/core/bgraph_image.hh (revision 0)
@@ -0,0 +1,309 @@
+// Copyright (C) 2007, 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_BGRAPH_IMAGE_HH
+# define MLN_CORE_BGRAPH_IMAGE_HH
+
+/// \file mln/core/bgraph_image.hh
+/// \brief Definition of a boost-graph-based image.
+
+# include <mln/trait/images.hh>
+# include <mln/core/internal/image_primary.hh>
+# include <mln/metal/vec.hh>
+
+# include <mln/core/p_bgraph.hh>
+# include <mln/core/bgraph_psite.hh>
+# include <mln/value/set.hh>
+# include <vector>
+
+namespace mln
+{
+
+ // Fwd decl.
+ template <typename P, typename V> struct bgraph_image;
+
+ namespace internal
+ {
+
+ /// \internal Data structure for \c mln::bgraph_image<P,V>.
+ template <typename P, typename V>
+ struct data_< bgraph_image<P, V> >
+ {
+ data_(const p_bgraph<P>& g, const std::vector<V>& val);
+
+ std::vector<V> val_;
+ /* The graph point set is handled by address, so that we can
+ check the compatibility of images w.r.t. to their point
+ sites. We could use a safer (and more complex) facility to
+ ensure (memory) equality of line graph point sets, but using
+ addresses is simple and efficient enough for the moment. */
+ const p_bgraph<P>& pg_;
+ };
+
+ } // end of namespace mln::internal
+
+
+ namespace trait
+ {
+
+ template <typename P, typename V>
+ struct image_< bgraph_image<P, V> > :
+ default_image_< V, bgraph_image<P, V> >
+ {
+ typedef trait::image::category::primary category;
+
+ // FIXME: Is that right?
+ typedef trait::image::access::random access;
+ typedef typename trait::image::space_from_point<P>::ret space;
+ typedef trait::image::size::regular size;
+ typedef trait::image::support::irregular support;
+
+ typedef trait::image::border::none border;
+ typedef trait::image::data::stored data;
+ typedef trait::image::io::read_write io;
+ // FIXME: Is that right?
+ typedef trait::image::speed::fast speed;
+ };
+
+ } // end of namespace mln::trait
+
+ /*! \brief Kind of image based on a boost graph structure.
+ *
+ */
+ template <typename P, typename V>
+ struct bgraph_image :
+ public internal::image_primary_< p_bgraph<P>, bgraph_image<P, V> >
+ {
+
+ typedef mln::internal::image_base_< p_bgraph<P>, bgraph_image<P, V> >
+ super_;
+
+ /// Value associated type.
+ typedef V value;
+
+ /// Return type of read-write access.
+ ///
+ /// We use the associated type \c reference instead of a plain
+ /// reference on th value type (\v V), because it's the only way
+ /// to safely form a reference on the element in the case of a
+ /// std::vector<bool>.
+ typedef typename std::vector<V>::reference lvalue;
+
+ /// Return type of read-only access.
+ typedef typename std::vector<V>::const_reference rvalue;
+
+ /// Value set associated type.
+ typedef mln::value::set<value> vset;
+
+
+ /// Skeleton.
+ typedef bgraph_image< tag::psite_<P>, tag::value_<V> > skeleton;
+
+ /// Constructors.
+ /// \{
+ bgraph_image();
+ bgraph_image(const p_bgraph<P>& g);
+ bgraph_image(const p_bgraph<P>& g, const std::vector<V>& val);
+ /// \}
+
+ /// Initialize an empty image.
+ void init_(const p_bgraph<P>& g, const std::vector<V>& val);
+
+ /// Read-only access of pixel value at point site \p p.
+ rvalue operator()(const bgraph_psite<P>& p) const;
+
+ /// Read-write access of pixel value at point site \p p.
+ lvalue operator()(const bgraph_psite<P>& p);
+
+ /// Accessors.
+ /// \{
+ /// Return the domain of psites od the image.
+ const p_bgraph<P>& domain() const;
+ /// Return the domain of values of the image.
+ const vset& values() const;
+
+ /// Return the array of values associated to the nodes.
+ const std::vector<V>& node_values() const;
+ /// \}
+
+ /* FIXME: Do we want to provide these two methods? (at least, in
+ the interface of the class? */
+
+ /// Return the point of the first node adjacent to the edge with
+ /// id \a e.
+ const P& node1(const typename p_bgraph<P>::edge_id& e) const;
+ /// Return the point of the second node adjacent to the edge with
+ /// id \a e.
+ const P& node2(const typename p_bgraph<P>::edge_id& e) const;
+};
+
+ // Fwd decl.
+ template <typename P, typename V>
+ void init_(tag::image_t,
+ bgraph_image<P, V>& target, const bgraph_image<P, V>& model);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ /*-----------------.
+ | Initialization. |
+ `-----------------*/
+
+ template <typename P, typename V>
+ inline
+ void init_(tag::image_t,
+ bgraph_image<P, V>& target, const bgraph_image<P, V>& model)
+ {
+ target.init_(model.domain(), model.node_values ());
+ }
+
+ /*-------.
+ | Data. |
+ `-------*/
+
+ namespace internal
+ {
+ template <typename P, typename V>
+ inline
+ data_< bgraph_image<P, V> >::data_(const p_bgraph<P>& g,
+ const std::vector<V>& val)
+ : val_ (val),
+ pg_ (g)
+ {
+ }
+
+ } // end of namespace mln::internal
+
+ /*---------------.
+ | Construction. |
+ `---------------*/
+
+ template <typename P, typename V>
+ inline
+ bgraph_image<P, V>::bgraph_image()
+ {
+ }
+
+ template <typename P, typename V>
+ inline
+ bgraph_image<P, V>::bgraph_image(const p_bgraph<P>& g)
+ {
+ init_(g, std::vector<V>(g.npoints()));
+ }
+
+ template <typename P, typename V>
+ inline
+ bgraph_image<P, V>::bgraph_image(const p_bgraph<P>& g,
+ const std::vector<V>& val)
+ {
+ init_(g, val);
+ }
+
+ template <typename P, typename V>
+ inline
+ void
+ bgraph_image<P, V>::init_(const p_bgraph<P>& g, const std::vector<V>& val)
+ {
+ /* FIXME: We leak memory here: calling init_ twice loses the
+ previous content pointed by data_.
+
+ We should definitely write down formal guidelines on
+ initialization and memory management in general! */
+ this->data_ = new internal::data_< bgraph_image<P, V> > (g, val);
+ }
+
+ /*---------------.
+ | Manipulation. |
+ `---------------*/
+
+ template <typename P, typename V>
+ inline
+ typename bgraph_image<P, V>::rvalue
+ bgraph_image<P, V>::operator()(const bgraph_psite<P>& p) const
+ {
+ mln_precondition(&p.pg() == &this->data_->pg_);
+ mln_precondition(p.id() < this->data_->val_.size());
+ return this->data_->val_[p.id()];
+ }
+
+ template <typename P, typename V>
+ inline
+ typename bgraph_image<P, V>::lvalue
+ bgraph_image<P, V>::operator()(const bgraph_psite<P>& p)
+ {
+ mln_precondition(&p.pg() == &this->data_->pg_);
+ mln_precondition(p.id() < this->data_->val_.size());
+ return this->data_->val_[p.id()];
+ }
+
+ template <typename P, typename V>
+ inline
+ const mln::value::set<V> &
+ bgraph_image<P, V>::values() const
+ {
+ return vset::the();
+ }
+
+ template <typename P, typename V>
+ inline
+ const std::vector<V>&
+ bgraph_image<P, V>::node_values() const
+ {
+ return this->data_->val_;
+ }
+
+ template <typename P, typename V>
+ inline
+ const p_bgraph<P>&
+ bgraph_image<P, V>::domain() const
+ {
+ mln_precondition(this->has_data());
+ return this->data_->pg_;
+ }
+
+ template <typename P, typename V>
+ inline
+ const P&
+ bgraph_image<P, V>::node1(const typename p_bgraph<P>::edge_id& e) const
+ {
+ return this->domain().node1(e);
+ }
+
+ template <typename P, typename V>
+ inline
+ const P&
+ bgraph_image<P, V>::node2(const typename p_bgraph<P>::edge_id& e) const
+ {
+ return this->domain().node2(e);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_BGRAPH_IMAGE_HH
Index: mln/core/p_bgraph.hh
--- mln/core/p_bgraph.hh (revision 0)
+++ mln/core/p_bgraph.hh (revision 0)
@@ -0,0 +1,221 @@
+// Copyright (C) 2007, 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.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_BGRAPH_P_HH
+# define MLN_CORE_BGRAPH_P_HH
+
+# include <utility>
+
+# include <mln/core/concept/point_site.hh>
+# include <mln/core/internal/point_set_base.hh>
+# include <mln/accu/bbox.hh>
+# include <mln/util/internal/boost_graph.hh>
+# include <mln/core/bgraph_psite.hh>
+# include <mln/core/p_bgraph_piter.hh>
+
+
+
+/// \file mln/core/p_bgraph.hh
+/// \brief Definition of a point set based on a boost graph.
+
+namespace mln
+{
+
+ template<typename P> class p_bgraph_piter_;
+
+ template<typename P>
+ struct p_bgraph
+ : public internal::point_set_base_< graph_psite<P>, p_bgraph<P> >
+ {
+ typedef util::internal::boost_graph<P, util::empty> graph;
+
+ /// Construct a graph psite set from a graph of points.
+ p_bgraph (graph& gr);
+
+ /// Point_Site associated type.
+ typedef bgraph_psite<P> psite;
+
+ /// Forward Point_Iterator associated type.
+ typedef p_bgraph_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef p_bgraph_piter_<P> bkd_piter;
+
+ /// Graph vertex/edge identifier
+ typedef typename graph::vertex_descriptor node_id;
+ typedef typename graph::edge_descriptor edge_id;
+
+ /// Graph vertex/edge iterator
+ typedef typename graph::vertex_iterator node_iterator;
+ typedef typename graph::edge_iterator edge_iterator;
+ typedef std::pair<node_iterator, node_iterator> node_iterators;
+
+
+ /// Return The number of points (i.e., nodes) in the graph.
+ std::size_t npoints() const;
+
+ /// Return The number of lines (i.e., edges) in the graph.
+ std::size_t nlines() const;
+
+ /// Give the exact bounding box.
+ const box_<P>& bbox() const;
+
+ bool has(const psite& p) const;
+
+ /// Return the graph point (FIXME site?) from an index
+ const P& point_from_id(const node_id& id) const;
+ P& point_from_id(const node_id& id);
+
+ /// Return the point contained in the first node adjacent
+ // to the edge id \a e.
+ const P& node1(const edge_id& e) const;
+ /// Return the point contained in the second node adjacent
+ /// to the edge id \a e.
+ const P& node2(const edge_id& e) const;
+
+ /// Return the graph associated to the p_bgraph domain:
+ const graph& to_graph() const;
+ graph& to_graph();
+
+
+ private:
+ graph gr_;
+ // FIXME: (Roland) Is it really useful/needed?
+ /* 2007-12-19: It seems so, since graph_image must implement a method
+ named bbox(). Now the question is: should each image type have a
+ bounding box? */
+ box_<P> bb_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template<typename P>
+ inline
+ p_bgraph<P>::p_bgraph (typename p_bgraph<P>::graph& gr)
+ : gr_ (gr)
+ {
+ // FIXME: Warning: if the underlying graph is updated later, this
+ // won't be taken into account by this p_bgraph!
+ accu::bbox<P> a;
+
+ for (node_iterators iter = boost::vertices(gr_);
+ iter.first != iter.second;
+ ++iter.first)
+ a.take(gr_[*iter.first]);
+ bb_ = a.to_result();
+ }
+
+ template<typename P>
+ inline
+ std::size_t
+ p_bgraph<P>::npoints() const
+ {
+ return boost::num_vertices((gr_));
+ }
+
+ template<typename P>
+ inline
+ std::size_t
+ p_bgraph<P>::nlines() const
+ {
+ return boost::num_edges(gr_.nedges());
+ }
+
+ template<typename P>
+ inline
+ const box_<P>&
+ p_bgraph<P>::bbox() const
+ {
+ return bb_;
+ }
+
+ template<typename P>
+ inline
+ bool
+ p_bgraph<P>::has(const psite& p) const
+ {
+ return
+ // Check whether P is compatible with this psite set.
+ (&p.pg() == this) &&
+ // Check that the node id of P belongs to the range of valid node ids.
+ (p.id() < this->npoints());
+ }
+
+
+ template <typename P>
+ const P&
+ p_bgraph<P>::point_from_id(const typename p_bgraph<P>::node_id& id) const
+ {
+ return this->gr_[id];
+ }
+
+ template <typename P>
+ P&
+ p_bgraph<P>::point_from_id(const typename p_bgraph<P>::node_id& id)
+ {
+ return this->gr_[id];
+ }
+
+
+ /// FIXME: Compare to p_bgraph, here we are loosing the vertex ordering
+ /// information. Is it bad??
+ template <typename P>
+ const P&
+ p_bgraph<P>::node1(const typename p_bgraph<P>::edge_id& e) const
+ {
+ return this->point_from_id(source(e, this->gr_));
+ }
+
+ /// FIXME: same as node1...
+ template <typename P>
+ const P&
+ p_bgraph<P>::node2(const typename p_bgraph<P>::edge_id& e) const
+ {
+ return this->point_from_id(target(e, this->gr_));
+ }
+
+ template <typename P>
+ const typename p_bgraph<P>::graph&
+ p_bgraph<P>::to_graph() const
+ {
+ return this->gr_;
+ }
+
+ template <typename P>
+ typename p_bgraph<P>::graph&
+ p_bgraph<P>::to_graph()
+ {
+ return this->gr_;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of mln
+
+
+#endif // MLN_CORE_BGRAPH_P_HH
Index: mln/core/bgraph_psite.hh
--- mln/core/bgraph_psite.hh (revision 0)
+++ mln/core/bgraph_psite.hh (revision 0)
@@ -0,0 +1,178 @@
+// Copyright (C) 2007, 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.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_BGRAPH_PSITE_HH
+# define MLN_CORE_BGRAPH_PSITE_HH
+
+/// \file mln/core/bgraph_psite.hh
+/// \brief Definition of a boost-graph-based point site.
+
+# include <mln/core/p_graph.hh>
+
+
+namespace mln
+{
+
+ // Fwd decl.
+ template<typename P> class p_bgraph;
+
+
+ /// \brief Point site associated to a mln::graph_image.
+ template<typename P>
+ class bgraph_psite : public Point_Site< bgraph_psite<P> >
+ {
+ typedef bgraph_psite<P> self_;
+ typedef Point_Site< bgraph_psite<P> > super_;
+
+ public:
+ typedef mln_mesh(P) mesh;
+ enum { dim = P::dim };
+ typedef P point;
+ typedef mln_dpoint(P) dpoint;
+ typedef mln_coord(P) coord;
+
+ /// Construction and assignment.
+ /// \{
+ bgraph_psite(const p_bgraph<P>& pg_, typename p_bgraph<P>::node_id id);
+ bgraph_psite(const self_& rhs);
+ /// \pre This psite must have the same graph point set as \a rhs.
+ self_& operator= (const self_& rhs);
+ /// \}
+
+ /// Access to psite.
+ const self_& to_psite() const;
+
+ /// Access to point.
+ /// \{
+ operator P() const;
+ const point& to_point() const;
+ coord operator[](unsigned id) const;
+ /// \}
+
+ /// Return the p_graph this point site belongs to.
+ const p_bgraph<P>& pg() const;
+ /// Return the node id of this point site.
+ typename p_bgraph<P>::node_id id() const;
+
+ private:
+ /// The p_graph this point site belongs to.
+ const p_bgraph<P>& pg_;
+ /// The id of the node this psite is pointing towards.
+ typename p_bgraph<P>::node_id id_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template<typename P>
+ inline
+ bgraph_psite<P>::bgraph_psite(const p_bgraph<P>& g,
+ typename p_bgraph<P>::node_id id)
+ : pg_(g),
+ id_(id)
+ {
+ }
+
+
+ /// FIXME: Is it normal to have to call super_() ?
+ template<typename P>
+ inline
+ bgraph_psite<P>::bgraph_psite(const bgraph_psite<P>& rhs)
+ : super_(),
+ pg_(rhs.pg_),
+ id_(rhs.id_)
+ {
+ }
+
+ template<typename P>
+ inline
+ bgraph_psite<P>&
+ bgraph_psite<P>::operator= (const bgraph_psite<P>& rhs)
+ {
+ if (&rhs == this)
+ return *this;
+ // Assigning a psite from a graph point set to a psite from
+ // another graph point set is meaningless.
+ mln_assertion(&pg_ == &rhs.pg_);
+ id_ = rhs.id_;
+ return *this;
+ }
+
+ template<typename P>
+ inline
+ const bgraph_psite<P>&
+ bgraph_psite<P>::to_psite() const
+ {
+ return *this;
+ }
+
+ template<typename P>
+ inline
+ bgraph_psite<P>::operator P() const
+ {
+ return pg_.point_from_id(id_);
+ }
+
+ template<typename P>
+ inline
+ const P&
+ bgraph_psite<P>::to_point() const
+ {
+ return pg_.point_from_id(id_);
+ }
+
+ template<typename P>
+ inline
+ mln_coord(P)
+ bgraph_psite<P>::operator[](unsigned i) const
+ {
+ return to_point()[i];
+ }
+
+ template<typename P>
+ inline
+ const p_bgraph<P>&
+ bgraph_psite<P>::pg() const
+ {
+ return pg_;
+ }
+
+ template<typename P>
+ inline
+ typename p_bgraph<P>::node_id
+ bgraph_psite<P>::id() const
+ {
+ return id_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+} // end of mln
+
+#endif // MLN_CORE_BGRAPH_PSITE_HH
Index: mln/util/internal/boost_graph.hh
--- mln/util/internal/boost_graph.hh (revision 1760)
+++ mln/util/internal/boost_graph.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_UTIL_BOOST_GRAPH_HH
-# define MLN_UTIL_BOOST_GRAPH_HH
+#ifndef MLN_UTIL_INTERNAL_BOOST_GRAPH_HH
+# define MLN_UTIL_INTERNAL_BOOST_GRAPH_HH
/// \file mln/util/internal/boost_graph.hh
/// \brief Definition of the boost::adjacenly_list decorator.
@@ -39,12 +39,15 @@
namespace util
{
+ struct empty {};
+
namespace internal
{
/// \brief Boost graph decorator base
/// Graph class which rests on boost::adjacency_list class.
- template <typename VertexProperty, typename EdgeProperty>
+ template <typename VertexProperty = empty,
+ typename EdgeProperty = empty>
class boost_graph
{
typedef boost_graph<VertexProperty, EdgeProperty> self_type;
@@ -74,8 +77,12 @@
typedef typename decorated::edge_parallel_category
edge_parallel_category;
typedef typename decorated::vertex_property_type vertex_property_type;
+ typedef typename decorated::edge_property_type edge_property_type;
typedef typename decorated::graph_tag graph_tag;
+ /// Properties.
+ typedef typename decorated::vertex_bundled vertex_bundled;
+
/// Sizes.
typedef typename decorated::vertices_size_type vertices_size_type;
typedef typename decorated::edges_size_type edges_size_type;
@@ -108,6 +115,10 @@
const decorated&
graph() const;
+ /// Provides acces to the graph bundle properties
+ vertex_bundled& operator[](vertex_descriptor v);
+ const vertex_bundled& operator[](vertex_descriptor v) const;
+
protected:
decorated graph_;
@@ -161,19 +172,39 @@
}
template <typename VertexProp, typename EdgeProp>
- inline typename boost_graph<VertexProp, EdgeProp>::decorated&
+ inline
+ typename boost_graph<VertexProp, EdgeProp>::decorated&
boost_graph<VertexProp, EdgeProp>::graph()
{
return this->graph_;
}
template <typename VertexProp, typename EdgeProp>
- inline const typename boost_graph<VertexProp, EdgeProp>::decorated&
+ inline
+ const typename boost_graph<VertexProp, EdgeProp>::decorated&
boost_graph<VertexProp, EdgeProp>::graph() const
{
return this->graph_;
}
+ template <typename V, typename E>
+ inline
+ typename boost_graph<V, E>::vertex_bundled&
+ boost_graph<V, E>::operator[](typename boost_graph<V, E>::
+ vertex_descriptor v)
+ {
+ return this->graph_[v];
+ }
+
+ template <typename V, typename E>
+ inline
+ const typename boost_graph<V, E>::vertex_bundled&
+ boost_graph<V, E>::operator[](typename boost_graph<V, E>::
+ vertex_descriptor v) const
+ {
+ return this->graph_[v];
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::util::internal
@@ -186,4 +217,4 @@
# include "boost_graph_structure.hh"
# include "boost_graph_property.hh"
-#endif // ! MLN_UTIL_BOOST_GRAPH_HH
+#endif // ! MLN_UTIL_INTERNAL_BOOST_GRAPH_HH
Index: mln/util/internal/boost_graph_structure.hh
--- mln/util/internal/boost_graph_structure.hh (revision 1760)
+++ mln/util/internal/boost_graph_structure.hh (working copy)
@@ -64,7 +64,8 @@
std::pair<typename mlnu::boost_graph<VProp, EProp>::edge_descriptor, bool>
add_edge(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
- const typename mlnu::boost_graph<VProp, EProp>::EdgeProperties& p,
+ const typename mlnu::boost_graph<VProp, EProp>::
+ edge_property_type& p,
typename mlnu::boost_graph<VProp, EProp>& g);
/// \brief Removes the edge (u,v) from the graph.
@@ -122,7 +123,8 @@
/// Returns the vertex descriptor for the new vertex.
template <typename VProp, typename EProp>
typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor
- add_vertex(const typename mlnu::boost_graph<VProp, EProp>::VertexProperties& p,
+ add_vertex(const typename mlnu::boost_graph<VProp, EProp>::
+ vertex_property_type& p,
typename mlnu::boost_graph<VProp, EProp>& g);
/// \brief Removes all edges to and from vertex u.
@@ -170,7 +172,8 @@
bool>
add_edge(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
- const typename mlnu::boost_graph<VProp, EProp>::EdgeProperties& p,
+ const typename mlnu::boost_graph<VProp, EProp>::
+ edge_property_type& p,
typename mlnu::boost_graph<VProp, EProp>& g)
{
return add_edge(u, v, p, g.graph());
@@ -235,7 +238,8 @@
template <typename VProp, typename EProp>
typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor
- add_vertex(const typename mlnu::boost_graph<VProp, EProp>::VertexProperties& p,
+ add_vertex(const typename mlnu::boost_graph<VProp, EProp>::
+ vertex_property_type& p,
typename mlnu::boost_graph<VProp, EProp>& g)
{
return add_vertex(p, g.graph());