https://svn.lrde.epita.fr/svn/oln/trunk/milena
Complex-based images will follow... soon.
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add a first implementation of general complexes.
* mln/core/complex.hh, mln/core/face.hh: New.
* tests/core/complex.cc: New test.
* tests/core/Makefile.am (check_PROGRAMS): Add complex.
(complex_SOURCES): New. Set to complex.cc.
mln/core/complex.hh | 347 +++++++++++++++++++++++++++++++++++++++++++++++++
mln/core/face.hh | 287 ++++++++++++++++++++++++++++++++++++++++
tests/core/Makefile.am | 2
tests/core/complex.cc | 75 ++++++++++
4 files changed, 711 insertions(+)
Index: mln/core/complex.hh
--- mln/core/complex.hh (revision 0)
+++ mln/core/complex.hh (revision 0)
@@ -0,0 +1,347 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_COMPLEX_HH
+# define MLN_CORE_COMPLEX_HH
+
+/// \file mln/core/complex.hh
+/// \brief Structures for general complexes.
+///
+/// A complexes defines a topological space which can be used as a
+/// support for an image (i.e., as site sets).
+///
+/// FIXME: More.
+
+# include <iosfwd>
+
+# include <mln/metal/bool.hh>
+
+# include <mln/core/face.hh>
+
+
+namespace mln
+{
+
+ // Forward declaration.
+ namespace internal
+ {
+ template <unsigned N, unsigned D>
+ struct faces_set_mixin;
+ }
+
+
+ /*----------.
+ | Complex. |
+ `----------*/
+
+ /// \brief General complex of dimension \p D.
+ template <unsigned D>
+ class complex : private internal::faces_set_mixin<D, D>
+ {
+ public:
+ /// Complex construction.
+ /// \{
+
+ /// \brief Add a 0-face to the complex.
+ face_handle<0u, D> add_face();
+
+ /// \brief Add a \p (N+1)-face to the complex (with \p N >= 0).
+ ///
+ /// \param adjacent_faces The (\p N-1)-faces adjacent to the new
+ /// \p N-face.
+ template <unsigned N>
+ face_handle<N + 1, D> add_face(const faces_set<N, D>& adjacent_faces);
+ /// \}
+
+ /// Pretty-printing.
+ /// \{
+ /// Print the complex.
+ void print(std::ostream& ostr) const;
+ /// Print the faces of dimension \p N.
+ template <unsigned N>
+ void print_faces(std::ostream& ostr) const;
+ /// \}
+
+ private:
+ /// Accessors.
+ /// \{
+ template <unsigned N, unsigned D_> friend class face_handle;
+
+ template <unsigned N>
+ face<N, D>& face_(unsigned face_id);
+
+ template <unsigned N>
+ const face<N, D>& face_(unsigned face_id) const;
+ /// \}
+
+ /// \brief connect two faces.
+ ///
+ /// \param f1 A face of dimension \p N
+ /// \param f2 A face of dimension \p N + 1
+ ///
+ /// \pre \p N must be lower or equal to \p D.
+ template <unsigned N>
+ void connect_(const face_handle<N, D>& f1,
+ const face_handle<N + 1, D>& f2);
+ };
+
+
+ // FIXME: Move and renamed as mln::debug::println?
+ /// Pretty print a complex.
+ template <unsigned D>
+ std::ostream&
+ operator<<(std::ostream& ostr, const complex<D>& c);
+
+
+ /*---------------------.
+ | Faces of a complex. |
+ `---------------------*/
+
+ // FIXME: Move these declarations after � Complex �.
+
+ /// The sets of n-faces of a complex are recursively aggregated as
+ /// mixins.
+ namespace internal
+ {
+
+ // FIXME: Factor common things here.
+
+ /// \brief Recursive mixins of set of faces.
+ /// \{
+ template <unsigned N, unsigned D>
+ struct faces_set_mixin : faces_set_mixin<N - 1, D>
+ {
+ std::vector< face<N, D> > faces_;
+
+ /// Pretty-printing.
+ /// \{
+ /// Print the faces of dimension \p N.
+ void print(std::ostream& ostr) const;
+ /// Recursively print the faces of dimensions 0 to \p N
+ /// (in ascending dimension).
+ void print_rec_asc(std::ostream& ostr) const;
+ /// \}
+ };
+
+ template <unsigned D>
+ struct faces_set_mixin<0u, D>
+ {
+ std::vector< face<0u, D> > faces_;
+
+ /// Pretty-printing.
+ /// \{
+ /// Print the faces of dimension 0.
+ void print(std::ostream& ostr) const;
+ void print_rec_asc(std::ostream& ostr) const;
+ /// \}
+ };
+ /// \}
+
+ } // end of namespace mln::internal
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned D>
+ face_handle<0u, D>
+ complex<D>::add_face()
+ {
+ /* FIXME: This is not thread-proof (these two lines should
+ form an atomic section). */
+ internal::faces_set_mixin<0u, D>::faces_.push_back(face<0u, D>());
+ unsigned id = internal::faces_set_mixin<0u, D>::faces_.size() - 1;
+
+ return face_handle<0u, D>(*this, id);
+ }
+
+ template <unsigned D>
+ template <unsigned N>
+ face_handle<N + 1, D>
+ complex<D>::add_face(const faces_set<N, D>& adjacent_faces)
+ {
+ // FIXME: Ensure ADJACENT_FACES are already part of the complex.
+
+ face<N + 1, D> f;
+ /* FIXME: This is not thread-proof (these two lines should
+ form an atomic section). */
+ internal::faces_set_mixin<N + 1, D>::faces_.push_back(f);
+ unsigned id = internal::faces_set_mixin<N + 1, D>::faces_.size() - 1;
+
+ face_handle<N + 1, D> fh(*this, id);
+ // Connect F and its ADJACENT_FACES.
+ /* FIXME: Use <fonctional> or Milena's functors. */
+ for (typename std::vector< face_handle<N, D> >::const_iterator a =
+ adjacent_faces.faces().begin();
+ a != adjacent_faces.faces().end(); ++a)
+ connect_(*a, fh);
+
+ return fh;
+ }
+
+ template <unsigned D>
+ template <unsigned N>
+ face<N, D>&
+ complex<D>::face_(unsigned face_id)
+ {
+ return internal::faces_set_mixin<N, D>::faces_[face_id];
+ }
+
+ template <unsigned D>
+ template <unsigned N>
+ const face<N, D>&
+ complex<D>::face_(unsigned face_id) const
+ {
+ return internal::faces_set_mixin<N, D>::faces_[face_id];
+ }
+
+ template <unsigned D>
+ template <unsigned N>
+ void
+ complex<D>::connect_(const face_handle<N, D>& f1,
+ const face_handle<N + 1, D>& f2)
+ {
+ // Ensure N is compatible with D.
+ metal::bool_< N <= D >::check();
+
+ f1.get().connect_higher_dim_face(f2);
+ f2.get().connect_lower_dim_face(f1);
+ }
+
+
+ /*------------------.
+ | Pretty-printing. |
+ `------------------*/
+
+ template <unsigned D>
+ std::ostream&
+ operator<<(std::ostream& ostr, const complex<D>& c)
+ {
+ c.print(ostr);
+ return ostr;
+ }
+
+ template <unsigned D>
+ void
+ complex<D>::print(std::ostream& ostr) const
+ {
+ internal::faces_set_mixin<D, D>::print_rec_asc(ostr);
+ }
+
+ template <unsigned D>
+ template <unsigned N>
+ void
+ complex<D>::print_faces(std::ostream& ostr) const
+ {
+ // Ensure N is compatible with D.
+ metal::bool_< N <= D >::check();
+
+ internal::faces_set_mixin<N, D>::print(ostr);
+ }
+
+
+ namespace internal
+ {
+
+ // FIXME: Factor common things here.
+
+ template <unsigned N, unsigned D>
+ void
+ faces_set_mixin<N, D>::print_rec_asc(std::ostream& ostr) const
+ {
+ faces_set_mixin<N - 1, D>::print_rec_asc(ostr);
+ print(ostr);
+ }
+
+ template <unsigned D>
+ void
+ faces_set_mixin<0, D>::print_rec_asc(std::ostream& ostr) const
+ {
+ print(ostr);
+ }
+
+ template <unsigned N, unsigned D>
+ void
+ faces_set_mixin<N, D>::print(std::ostream& ostr) const
+ {
+ ostr << "Faces of dimension " << N
+ << " and their ajacent faces of dimension "
+ << N - 1 << " and "
+ << N + 1 << std::endl;
+ for (unsigned f = 0; f < faces_.size(); ++f)
+ {
+ ostr << " " << f << ": dim " << N - 1 << ": { ";
+ for (typename std::vector< face_handle<N - 1, D> >::const_iterator l =
+ faces_[f].lower_dim_faces_.begin();
+ l != faces_[f].lower_dim_faces_.end();
+ ++l)
+ ostr << l->face_id_ << " ";
+ ostr << "}, dim " << N + 1 << ": { ";
+ for (typename std::vector< face_handle<N + 1, D> >::const_iterator h =
+ faces_[f].higher_dim_faces_.begin();
+ h != faces_[f].higher_dim_faces_.end();
+ ++h)
+ ostr << h->face_id_ << " ";
+ ostr << "}";
+ ostr << std::endl;
+ }
+ }
+
+ template <unsigned D>
+ void
+ faces_set_mixin<0u, D>::print(std::ostream& ostr) const
+ {
+ // FIXME: Much could be factored with the previous routine.
+ const unsigned N = 0;
+ ostr << "Faces of dimension " << N
+ << " and their ajacent faces of dimension "
+ << N + 1 << std::endl;
+ for (unsigned f = 0; f < faces_.size(); ++f)
+ {
+ ostr << " " << f << " dim " << N + 1 << ": { ";
+ for (typename std::vector< face_handle<N + 1, D> >::const_iterator h =
+ faces_[f].higher_dim_faces_.begin();
+ h != faces_[f].higher_dim_faces_.end();
+ ++h)
+ ostr << h->face_id_ << " ";
+ ostr << "}";
+ ostr << std::endl;
+ }
+ }
+
+
+ // FIXME: Handle faces_set_mixin<D, D>::print.
+
+
+ } // end of namespace mln::internal
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_COMPLEX_HH
Index: mln/core/face.hh
--- mln/core/face.hh (revision 0)
+++ mln/core/face.hh (revision 0)
@@ -0,0 +1,287 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_FACE_HH
+# define MLN_CORE_FACE_HH
+
+/// \file mln/core/face.hh
+/// \brief Face of a complex.
+///
+/// FIXME: More.
+
+#include <vector>
+
+#include <mln/core/contract.hh>
+
+
+namespace mln
+{
+
+ // Forward declarations.
+ template <unsigned D> class complex;
+ template <unsigned N, unsigned D> class face_handle;
+ namespace internal
+ {
+ template <unsigned N, unsigned D>
+ struct faces_set_mixin;
+ }
+
+
+ /*-------.
+ | Face. |
+ `-------*/
+
+ /* FIXME: we might want to factor connect_{higher,lower}_dim_cell
+ and {higher,lower_dim_faces_} as member of super classes. */
+
+ template <unsigned N, unsigned D>
+ class face
+ {
+ public:
+ void connect_higher_dim_face(const face_handle<N + 1, D>& f);
+ void connect_lower_dim_face (const face_handle<N - 1, D>& f);
+
+ private:
+ friend class mln::internal::faces_set_mixin<N, D>;
+
+ // FIXME: Provide accessors instead of using `friend' if there are
+ // clients other than mln::internal::faces_set_mixin<N, D>.
+ std::vector< face_handle<N + 1, D> > higher_dim_faces_;
+ std::vector< face_handle<N - 1, D> > lower_dim_faces_;
+ };
+
+ template <unsigned D>
+ class face<0u, D>
+ {
+ public:
+ void connect_higher_dim_face(const face_handle<1u, D>& f);
+
+ private:
+ friend class mln::internal::faces_set_mixin<0, D>;
+
+ // FIXME: Provide accessors instead of using `friend; if there are
+ // clients other than mln::internal::faces_set_mixin<0, D>.
+ std::vector< face_handle<1u, D> > higher_dim_faces_;
+ };
+
+ // FIXME: Handle face<0u, 0u>.
+
+
+ /*--------------.
+ | Face handle. |
+ `--------------*/
+
+ // Face handle in a complex.
+ template <unsigned N, unsigned D>
+ struct face_handle
+ {
+ face_handle(complex<D>& complex, unsigned face_id);
+
+ /// Copy and assignment.
+ /// \{
+ face_handle(const face_handle<N, D>& rhs);
+ face_handle<N, D>& operator=(const face_handle<N, D>& rhs);
+ /// \}
+
+ /// Accessors.
+ /// \{
+ /// Return the mln::face pointed by this handle.
+ face<N, D>& get() const;
+ /// \}
+
+ /* FIXME: Hide data. */
+ // A const face_handle can be used to modify a complex.
+ mutable complex<D>& c_;
+ unsigned face_id_;
+ };
+
+ template <unsigned N, unsigned D>
+ face_handle<N, D>
+ make_face_handle(const complex<D>& c, unsigned face_id);
+
+
+ /*----------------------.
+ | Set of face handles. |
+ `----------------------*/
+
+ /// \brief Set of face handles of dimension \p N.
+ template <unsigned N, unsigned D>
+ class faces_set
+ {
+ public:
+ void add(const face_handle<N, D>& f);
+
+ /// \brief Accessors.
+ ///
+ /// Return the set of handles.
+ /// \{
+ const std::vector< face_handle<N, D> >& faces() const;
+ /// \}
+
+ private:
+ friend class mln::complex<D>;
+
+ // FIXME: Rename this as `handles_'?
+ std::vector< face_handle<N, D> > faces_;
+ };
+
+
+ /// Construction helpers for mln::faces_set.
+ /// \{
+ template <unsigned N, unsigned D>
+ faces_set<N, D>
+ operator+(const face_handle<N, D>& f1, const face_handle<N, D>& f2);
+
+ template <unsigned N, unsigned D>
+ faces_set<N, D>
+ operator+(const faces_set<N, D>& fs, const face_handle<N, D>& f);
+ /// \}
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ /*--------------.
+ | Face handle. |
+ `--------------*/
+
+ template <unsigned N, unsigned D>
+ face_handle<N, D>::face_handle(complex<D>& c, unsigned face_id)
+ : c_(c), face_id_(face_id)
+ {
+ }
+
+ template <unsigned N, unsigned D>
+ face_handle<N, D>::face_handle(const face_handle<N, D>& rhs)
+ : c_(rhs.c_), face_id_(rhs.face_id_)
+ {
+ }
+
+ template <unsigned N, unsigned D>
+ face_handle<N, D>&
+ face_handle<N, D>::operator=(const face_handle<N, D>& rhs)
+ {
+ if (&rhs != this)
+ {
+ c_ = rhs.c_;
+ face_id_ = rhs.face_id_;
+ }
+ return *this;
+ }
+
+ template <unsigned N, unsigned D>
+ face<N, D>&
+ face_handle<N, D>::get() const
+ {
+ return c_.template face_<N>(face_id_);
+ }
+
+
+ template <unsigned N, unsigned D>
+ face_handle<N, D>
+ make_face_handle(const complex<D>& c, unsigned face_id)
+ {
+ return face_handle<N, D>(c, face_id);
+ }
+
+
+ /*--------.
+ | Faces. |
+ `--------*/
+
+ template <unsigned N, unsigned D>
+ void
+ face<N, D>::connect_higher_dim_face(const face_handle<N + 1, D>& f)
+ {
+ higher_dim_faces_.push_back(f);
+ }
+
+ template <unsigned N, unsigned D>
+ void
+ face<N, D>::connect_lower_dim_face(const face_handle<N - 1, D>& f)
+ {
+ lower_dim_faces_.push_back(f);
+ }
+
+ template <unsigned D>
+ void
+ face<0u, D>::connect_higher_dim_face(const face_handle<1u, D>& f)
+ {
+ higher_dim_faces_.push_back(f);
+ }
+
+
+ /*---------------.
+ | Set of faces. |
+ `---------------*/
+
+ template <unsigned N, unsigned D>
+ void
+ faces_set<N, D>::add(const face_handle<N, D>& f)
+ {
+ // Check consistency.
+ if (!faces_.empty())
+ mln_assertion(&faces_.front().c_ == &f.c_);
+
+ /* FIXME: This is not thread-proof (these two lines should
+ form an atomic section). */
+ faces_.push_back (f);
+ }
+
+ template <unsigned N, unsigned D>
+ const std::vector< face_handle<N, D> >&
+ faces_set<N, D>::faces() const
+ {
+ return faces_;
+ }
+
+
+ template <unsigned N, unsigned D>
+ faces_set<N, D>
+ operator+(const face_handle<N, D>& f1, const face_handle<N, D>& f2)
+ {
+ faces_set<N, D> fs;
+ fs.add(f1);
+ fs.add(f2);
+ return fs;
+ }
+
+ template <unsigned N, unsigned D>
+ faces_set<N, D>
+ operator+(const faces_set<N, D>& fs, const face_handle<N, D>& f)
+ {
+ faces_set<N, D> fs2(fs);
+ fs2.add(f);
+ return fs2;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_FACE_HH
Index: tests/core/complex.cc
--- tests/core/complex.cc (revision 0)
+++ tests/core/complex.cc (revision 0)
@@ -0,0 +1,75 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/// \file tests/core/complex.cc
+/// \brief Test of mln::complex.
+
+#include <iostream>
+
+#include <mln/core/complex.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ /* A 2-d (simplicial) complex.
+
+ v0 e3 v3
+ o-----------o
+ / \ /
+ / \ t2 /
+ e0 / \ / e4
+ / t1 \e1 /
+ / \ /
+ o-----------o
+ v1 e2 v2
+
+ */
+
+
+ complex<2> c;
+
+ // 0-faces (points).
+ face_handle<0, 2> v0 = c.add_face();
+ face_handle<0, 2> v1 = c.add_face();
+ face_handle<0, 2> v2 = c.add_face();
+ face_handle<0, 2> v3 = c.add_face();
+
+ // 1-faces (segments).
+ face_handle<1, 2> e0 = c.add_face(v0 + v1);
+ face_handle<1, 2> e1 = c.add_face(v0 + v2);
+ face_handle<1, 2> e2 = c.add_face(v1 + v2);
+ face_handle<1, 2> e3 = c.add_face(v0 + v3);
+ face_handle<1, 2> e4 = c.add_face(v2 + v3);
+
+ // 2-faces (triangles).
+ face_handle<2, 2> t0 = c.add_face(e0 + e1 + e2);
+ face_handle<2, 2> t1 = c.add_face(e1 + e3 + e4);
+
+ std::cout << c << std::endl;
+}
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 2113)
+++ tests/core/Makefile.am (working copy)
@@ -12,6 +12,7 @@
clock_neighb2d \
clock_test \
clone \
+ complex \
\
decorated_image \
dpoint1d \
@@ -98,6 +99,7 @@
clock_neighb2d_SOURCES = clock_neighb2d.cc
clock_test_SOURCES = clock_test.cc
clone_SOURCES = clone.cc
+complex_SOURCES = complex.cc
decorated_image_SOURCES = decorated_image.cc
dpoint1d_SOURCES = dpoint1d.cc
https://svn.lrde.epita.fr/svn/oln/trunk/swilena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Wrap mln::image2d<int_u8> as well as I/O routines.
* pgm.ixx, int_u8.i, image2d_int_u8.i: New.
* Makefile.am (EXTRA_DIST): Add pgm.ixx, image2d_int_u8.i and
int_u8.i.
* fill.ixx, println.ixx: Fix doxygen headers.
* image2d_int.i: Typo.
* python/lena.py: New test.
* python/Makefile.am: Handle modules int_u8 and image2d_int_u8.
(top_srcdir): Add top_srcdir and top_builddir into the
environment.
(TESTS): Add lena.py.
* python/swilena.py: Import image2d_int_u8.
Makefile.am | 6 +++--
fill.ixx | 2 -
image2d_int.i | 2 -
image2d_int_u8.i | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++
int_u8.i | 38 ++++++++++++++++++++++++++++++++
pgm.ixx | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
println.ixx | 2 -
python/Makefile.am | 27 +++++++++++++++++++----
python/lena.py | 39 +++++++++++++++++++++++++++++++++
python/swilena.py | 1
10 files changed, 229 insertions(+), 9 deletions(-)
Index: python/lena.py
--- python/lena.py (revision 0)
+++ python/lena.py (revision 0)
@@ -0,0 +1,39 @@
+#! /usr/bin/env python
+
+# Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+#
+# This file is part of the Olena Library. This library is free
+# software; you can redistribute it and/or modify it under the terms
+# of the GNU General Public License version 2 as published by the
+# Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this library; see the file COPYING. If not, write to
+# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+# Boston, MA 02111-1307, USA.
+#
+# As a special exception, you may use this file as part of a free
+# software library without restriction. Specifically, if other files
+# instantiate templates or use macros or inline functions from this
+# file, or you compile this file and link it with other files to
+# produce an executable, this file does not by itself cause the
+# resulting executable to be covered by the GNU General Public
+# License.
+# reasons why the executable file might be covered by the GNU General
+# Public License.
+
+import os
+from swilena import *
+
+top_srcdir = os.environ["top_srcdir"]
+img_dir = os.path.join(top_srcdir, "milena", "img")
+lena = os.path.join (img_dir, "lena.pgm")
+
+ima = image2d_int_u8.load(lena)
+eroded = image2d_int_u8.erosion (ima, win_c4p())
+image2d_int_u8.save(eroded, "out.pgm")
Index: python/Makefile.am
--- python/Makefile.am (revision 2105)
+++ python/Makefile.am (working copy)
@@ -50,6 +50,16 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_point2d-wrap.Pcc@am__quote@
nodist_python_PYTHON += point2d.py
+## int_u8.
+pyexec_LTLIBRARIES += _int_u8.la
+nodist__int_u8_la_SOURCES = int_u8-wrap.cc
+_int_u8_la_LIBADD = $(AM_LIBADD)
+CLEANFILES += $(nodist__int_u8_la_SOURCES) int_u8.py int_u8.py[co]
+## Include the dependency files. Copied from Automake's generated
+## case for C++.
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_int_u8-wrap.Pcc@am__quote@
+nodist_python_PYTHON += int_u8.py
+
## dpoint2d.
pyexec_LTLIBRARIES += _dpoint2d.la
nodist__dpoint2d_la_SOURCES = dpoint2d-wrap.cc
@@ -80,6 +90,16 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_image2d_int-wrap.Pcc@am__quote@
nodist_python_PYTHON += image2d_int.py
+## image2d_int_u8.
+pyexec_LTLIBRARIES += _image2d_int_u8.la
+nodist__image2d_int_u8_la_SOURCES = image2d_int_u8-wrap.cc
+_image2d_int_u8_la_LIBADD = $(AM_LIBADD)
+CLEANFILES += $(nodist__image2d_int_u8_la_SOURCES) image2d_int_u8.py image2d_int_u8.py[co]
+## Include the dependency files. Copied from Automake's generated
+## case for C++.
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_image2d_int_u8-wrap.Pcc@am__quote@
+nodist_python_PYTHON += image2d_int_u8.py
+
## ---------------------------- ##
## Swilena Python Shell (sps). ##
@@ -103,9 +123,8 @@
include $(top_srcdir)/swilena/run.mk
## FIXME: Do we really need to pass top_srcdir and top_builddir to run?
-##TESTS_ENVIRONMENT = \
-## top_srcdir="$(top_srcdir)" top_builddir="$(top_builddir)" $(RUN)
-TESTS_ENVIRONMENT = $(RUN)
+TESTS_ENVIRONMENT = \
+ top_srcdir="$(top_srcdir)" top_builddir="$(top_builddir)" $(RUN)
# Ensure `run' is rebuilt before the tests are run.
$(TESTS): $(srcdir)/run.stamp
# The dependency is on `run.in' and not `run', since `run' is
@@ -119,5 +138,5 @@
$(MAKE) $(AM_MAKEFLAGS) $(RUN)
@mv -f $@.tmp $@
-TESTS = test.py
+TESTS = test.py lena.py
EXTRA_DIST += $(TESTS)
Index: python/swilena.py
--- python/swilena.py (revision 2105)
+++ python/swilena.py (working copy)
@@ -33,3 +33,4 @@
from dpoint2d import *
from window2d import *
import image2d_int
+import image2d_int_u8
Index: image2d_int_u8.i
--- image2d_int_u8.i (revision 0)
+++ image2d_int_u8.i (revision 0)
@@ -0,0 +1,62 @@
+// -*- C++ -*-
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/// \file image2d.i
+/// \brief A simple wrapping of mln::image2d<mln::value::int_u8> along
+/// with some algorithms.
+
+%module image2d_int_u8
+
+%import "int_u8.i"
+// FIXME: The import directive does not include the `%{ ... %}' clauses.
+// %{
+// #include "mln/value/int_u8.hh"
+// %}
+//
+%include "image2d.ixx"
+%template(image2d_int_u8) mln::image2d< mln::value::int_u<8> >;
+
+%include "pgm.ixx"
+%template(load) mln::io::pgm::load< mln::value::int_u<8> >;
+%template(save) mln::io::pgm::save< mln::image2d< mln::value::int_u<8> > >;
+
+%include "fill.ixx"
+%template(fill) mln::level::fill< mln::image2d< mln::value::int_u<8> > >;
+
+%include "println.ixx"
+%template(println) mln::debug::println< mln::image2d< mln::value::int_u<8> > >;
+
+%import "window2d.i"
+// FIXME: The import directive does not include the `%{ ... %}' clauses.
+%{
+#include "mln/core/window2d.hh"
+%}
+
+%include "morpho.ixx"
+%template(erosion) mln::morpho::erosion< mln::image2d< mln::value::int_u<8> >,
+ mln::window2d >;
Index: pgm.ixx
--- pgm.ixx (revision 0)
+++ pgm.ixx (revision 0)
@@ -0,0 +1,59 @@
+// -*- C++ -*-
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/// \file pgm.ixx
+/// \brief A wrapper of mln::io::pgm::load and mln::io::pgm::save
+
+%module pgm
+
+%include std_string.i
+
+%{
+#include "mln/io/pgm/load.hh"
+#include "mln/io/pgm/save.hh"
+%}
+
+// Wrap mln::io::pgm::load(const std::string&) by hand, to force swig
+// to choose this overloading.
+namespace mln
+{
+ namespace io
+ {
+ namespace pgm
+ {
+
+ template <typename V>
+ mln::image2d<V> load(const std::string& filename);
+
+ } // end of namespace mln::io::pgm
+
+ } // end of namespace mln::io
+
+} // end of namespace mln
+
+%include "mln/io/pgm/save.hh"
Index: int_u8.i
--- int_u8.i (revision 0)
+++ int_u8.i (revision 0)
@@ -0,0 +1,38 @@
+// -*- C++ -*-
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/// \file int_u8.i
+/// \brief A wrapper of mln::value::int_u8.
+
+%module int_u8
+
+%{
+#include "mln/value/int_u8.hh"
+%}
+
+%include "mln/value/int_u8.hh"
Index: fill.ixx
--- fill.ixx (revision 2105)
+++ fill.ixx (working copy)
@@ -26,7 +26,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file fill.i
+/// \file fill.ixx
/// \brief A wrapper of mln::level::fill.
%module fill
Index: println.ixx
--- println.ixx (revision 2105)
+++ println.ixx (working copy)
@@ -26,7 +26,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file println.i
+/// \file println.ixx
/// \brief A wrapper of mln::debug::println.
%{
Index: Makefile.am
--- Makefile.am (revision 2105)
+++ Makefile.am (working copy)
@@ -3,8 +3,10 @@
SUBDIRS = python
# Meta-wrappers (templates).
-EXTRA_DIST = fill.ixx image2d.ixx intp.ixx morpho.ixx println.ixx
+EXTRA_DIST = fill.ixx image2d.ixx intp.ixx morpho.ixx pgm.ixx println.ixx
# Wrappers.
-EXTRA_DIST += dpoint2d.i image2d_int.i point2d.i window2d.i
+EXTRA_DIST += \
+ dpoint2d.i image2d_int.i image2d_int_u8.i int_u8.i \
+ point2d.i window2d.i
check_SCRIPTS = run
Index: image2d_int.i
--- image2d_int.i (revision 2105)
+++ image2d_int.i (working copy)
@@ -43,7 +43,7 @@
%template(println) mln::debug::println< mln::image2d<int> >;
%import "window2d.i"
-// FIXME: The import directive does not import the `%{ ... %}' clauses.
+// FIXME: The import directive does not include the `%{ ... %}' clauses.
%{
#include "mln/core/window2d.hh"
%}