https://svn.lrde.epita.fr/svn/oln/trunk/swilena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Simplify the wrapping of mln::image2d and make it (more) generic.
* box2d.i: New.
* image2d.ixx: Import dpoint2d.i and box2d.i.
Wrap mln::image2d directly, instead of using a simplified,
inlined declaration.
(instantiate_image2d): New macro.
Use it...
* image2d_int.i, image2d_int_u8.i: ...here.
* Makefile.am (wrappers): Add box2d.i.
* python/swilena.py: Import box2d.
* python/Makefile.am: Build module box2d.
Makefile.am | 2
box2d.i | 62 +++++++++++++++++++++
image2d.ixx | 153 +++++++++++++----------------------------------------
image2d_int.i | 2
image2d_int_u8.i | 10 ---
python/Makefile.am | 30 ++++++----
python/swilena.py | 1
7 files changed, 126 insertions(+), 134 deletions(-)
Index: image2d.ixx
--- image2d.ixx (revision 2133)
+++ image2d.ixx (working copy)
@@ -32,125 +32,50 @@
%module image2d
%import "point2d.i"
+%import "dpoint2d.i"
+%import "box2d.i"
%{
#include "mln/core/image2d.hh"
%}
-%include "mln/core/box2d.hh"
-%include "mln/core/dpoint2d.hh"
+// Shortcuts macros.
+%include "mln/core/macros.hh"
-%include "mln/core/concept/image.hh"
-
-// FIXME: Wrap mln::image2d by hand, for Milena macros disturb swig.
-// Annotate the original source code instead?
-namespace mln
-{
- template <typename T>
- struct image2d
- /* FIXME: Cheat, so that generic algorithms can use mln::image2d. */
- // : public internal::image_primary_< box2d, image2d<T> >
- : public Image< image2d<T> >
- {
- // Warning: just to make effective types appear in Doxygen:
- typedef box2d pset;
- typedef point2d psite;
- typedef point2d point;
- typedef dpoint2d dpoint;
-// FIXME: Those typedefs disturb swig.
-// typedef mln_fwd_piter(box2d) fwd_piter;
-// typedef mln_bkd_piter(box2d) bkd_piter;
- typedef line_piter_<point> line_piter;
- // End of warning.
-
-
- /// Value associated type.
- typedef T value;
-
- /// Return type of read-only access.
- typedef const T& rvalue;
-
- /// Return type of read-write access.
- typedef T& lvalue;
-
-
- /// Skeleton.
- typedef image2d< tag::value_<T> > skeleton;
-
-
- /// Value_Set associated type.
- typedef mln::value::set<T> vset;
-
-
- /// Constructor without argument.
- image2d();
-
- /// Constructor with the numbers of rows and columns and the
- /// border thickness.
- image2d(int nrows, int ncols, unsigned bdr = border::thickness);
-
- /// Constructor with a box and the border thickness (default is
- /// 3).
- image2d(const box2d& b, unsigned bdr = border::thickness);
-
-
- /// Initialize an empty image.
- void init_(const box2d& b, unsigned bdr = border::thickness);
-
-
- /// Test if \p p is valid.
- bool owns_(const point2d& p) const;
+// Associated types.
+// %include "mln/core/box2d.hh"
+// %include "mln/core/dpoint2d.hh"
+
+// Meta-expressions used in traits.
+// %include "mln/metal/bexpr.hh"
+%include "mln/metal/equal.hh"
+%include "mln/metal/if.hh"
+%include "mln/metal/is_const.hh"
+
+// Traits.
+%include "mln/trait/value_.hh"
+// %include "mln/trait/image/props.hh"
+%include "mln/trait/images.hh"
- /// Give the set of values of the image.
- const vset& values() const;
-
- /// Give the definition domain.
- const box2d& domain() const;
-
- /// Give the border thickness.
- unsigned border() const;
-
- /// Give the number of cells (points including border ones).
- std::size_t ncells() const;
-
- /// Read-only access to the image value located at point \p p.
- const T& operator()(const point2d& p) const;
-
- /// Read-write access to the image value located at point \p p.
- T& operator()(const point2d& p);
-
-// FIXME: swig won't wrap this operator.
-// /// Read-only access to the image value located at offset \p o.
-// const T& operator[](unsigned o) const;
-
-// FIXME: swig won't wrap this operator.
-// /// Read-write access to the image value located at offset \p o.
-// T& operator[](unsigned o);
-
- /// Read-only access to the image value located at (\p row, \p col).
- const T& at(int row, int col) const;
-
- /// Read-write access to the image value located at (\p row, \p col).
- T& at(int row, int col);
-
-
- /// Fast Image method
-
- /// Give the offset corresponding to the delta-point \p dp.
- int offset(const dpoint2d& dp) const;
-
- /// Give the point corresponding to the offset \p o.
- point2d point_at_offset(unsigned o) const;
-
- /// Give a hook to the value buffer.
- const T* buffer() const;
-
- /// Give a hook to the value buffer.
- T* buffer();
-
-
- /// Resize image border with new_border.
- void resize_(unsigned new_border);
- };
+// Concept.
+%include "mln/core/concept/image.hh"
-} // end of namespace mln
+// Base classes.
+%include "mln/core/internal/check/image_fastest.hh"
+%include "mln/core/internal/check/image_all.hh"
+%include "mln/core/internal/image_base.hh"
+%include "mln/core/internal/image_primary.hh"
+
+// mln::image2d definition.
+%include "mln/core/image2d.hh"
+
+// FIXME: Doc.
+%define instantiate_image2d(I, T)
+// Instantiate base classes of mln::image2d<T> so that swig knows it
+// derives from mln::Image.
+%template() mln::internal::image_primary_< mln::box2d, mln::image2d< T > >;
+%template() mln::internal::image_base_< mln::box2d, mln::image2d< T > >;
+%template() mln::internal::image_checked_< mln::image2d< T > >;
+// Instantiate mln::image2d<T>
+%template(I) mln::image2d< T >;
+%enddef
Index: python/Makefile.am
--- python/Makefile.am (revision 2133)
+++ python/Makefile.am (working copy)
@@ -52,6 +52,26 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_point2d-wrap.Pcc@am__quote@
nodist_python_PYTHON += point2d.py
+## dpoint2d.
+pyexec_LTLIBRARIES += _dpoint2d.la
+nodist__dpoint2d_la_SOURCES = dpoint2d-wrap.cc
+_dpoint2d_la_LIBADD = $(AM_LIBADD)
+CLEANFILES += $(nodist__dpoint2d_la_SOURCES) dpoint2d.py dpoint2d.py[co]
+## Include the dependency files. Copied from Automake's generated
+## case for C++.
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_dpoint2d-wrap.Pcc@am__quote@
+nodist_python_PYTHON += dpoint2d.py
+
+## box2d.
+pyexec_LTLIBRARIES += _box2d.la
+nodist__box2d_la_SOURCES = box2d-wrap.cc
+_box2d_la_LIBADD = $(AM_LIBADD)
+CLEANFILES += $(nodist__box2d_la_SOURCES) box2d.py box2d.py[co]
+## Include the dependency files. Copied from Automake's generated
+## case for C++.
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_box2d-wrap.Pcc@am__quote@
+nodist_python_PYTHON += box2d.py
+
## int_u8.
pyexec_LTLIBRARIES += _int_u8.la
nodist__int_u8_la_SOURCES = int_u8-wrap.cc
@@ -72,16 +92,6 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_int_u32-wrap.Pcc@am__quote@
nodist_python_PYTHON += int_u32.py
-## dpoint2d.
-pyexec_LTLIBRARIES += _dpoint2d.la
-nodist__dpoint2d_la_SOURCES = dpoint2d-wrap.cc
-_dpoint2d_la_LIBADD = $(AM_LIBADD)
-CLEANFILES += $(nodist__dpoint2d_la_SOURCES) dpoint2d.py dpoint2d.py[co]
-## Include the dependency files. Copied from Automake's generated
-## case for C++.
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_dpoint2d-wrap.Pcc@am__quote@
-nodist_python_PYTHON += dpoint2d.py
-
## neighb2d.
pyexec_LTLIBRARIES += _neighb2d.la
nodist__neighb2d_la_SOURCES = neighb2d-wrap.cc
Index: python/swilena.py
--- python/swilena.py (revision 2133)
+++ python/swilena.py (working copy)
@@ -31,6 +31,7 @@
from point2d import *
from dpoint2d import *
+from box2d import *
from neighb2d import *
from window2d import *
Index: image2d_int_u8.i
--- image2d_int_u8.i (revision 2133)
+++ image2d_int_u8.i (working copy)
@@ -33,13 +33,8 @@
%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> >;
+instantiate_image2d(image2d_int_u8, mln::value::int_u<8>)
%include "pgm.ixx"
%template(load) mln::io::pgm::load< mln::value::int_u<8> >;
@@ -92,8 +87,7 @@
`-------------------*/
// FIXME: Rearrange and move this elsewhere.
-
-%template(image2d_int_u32) mln::image2d< mln::value::int_u<32> >;
+instantiate_image2d(image2d_int_u32, mln::value::int_u<32>)
%template(println32) mln::debug::println<
mln::image2d< mln::value::int_u<32> >
Index: box2d.i
--- box2d.i (revision 0)
+++ box2d.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 box2d.i
+/// \brief A wrapper of mln::box2d.
+
+%module box2d
+
+%{
+#include "mln/core/box.hh"
+#include "mln/core/box2d.hh"
+%}
+
+%include "mln/core/macros.hh";
+
+// %include "mln/core/grids.hh";
+
+// %include "mln/core/point.hh";
+// %include "mln/core/point2d.hh";
+
+%include "mln/core/box.hh";
+%include "mln/core/box2d.hh";
+
+// Swig tries to wrap everything by default; prevent it from wrapping
+// invalid methods (1D and 3D ctors for a box2d).
+/* FIXME: Can't we simplify these directives, i.e. use `point2d' and
+ `int' directly? */
+%ignore mln::box_< mln::point_<mln::grid::square, int> >::box_(
+ typename mln::point_<mln::grid::square, int>::coord
+);
+%ignore mln::box_< mln::point_<mln::grid::square, int> >::box_(
+ typename mln::point_<mln::grid::square, int>::coord,
+ typename mln::point_<mln::grid::square, int>::coord,
+ typename mln::point_<mln::grid::square, int>::coord
+);
+
+%template(box2d) mln::box_< mln::point_<mln::grid::square, int> >;
Index: image2d_int.i
--- image2d_int.i (revision 2133)
+++ image2d_int.i (working copy)
@@ -34,7 +34,7 @@
%include "intp.ixx"
%include "image2d.ixx"
-%template(image2d_int) mln::image2d<int>;
+instantiate_image2d(image2d_int, int)
%include "fill.ixx"
%template(fill) mln::level::fill< mln::image2d<int> >;
Index: Makefile.am
--- Makefile.am (revision 2133)
+++ Makefile.am (working copy)
@@ -10,7 +10,7 @@
# Wrappers (generating actual modules).
wrappers = \
- dpoint2d.i image2d_int.i image2d_int_u8.i int_u8.i \
+ box2d.i dpoint2d.i image2d_int.i image2d_int_u8.i int_u8.i \
int_u32.i neighb2d.i point2d.i window2d.i
EXTRA_DIST = $(meta_wrappers) $(wrappers)
https://svn.lrde.epita.fr/svn/oln/trunk/swilena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add support for mln_concrete in Swilena.
* concrete.ixx: New.
Use it...
* morpho.ixx: ...here.
Wrap mln::morpho::dilation.hh and mln::morpho::erosion directly,
instead of using a simplified declaration (previously used to
circumvent the lack of support of mln_concrete).
Fix documentation.
* image2d_int.i, image2d_int_u8.i: Instantiate
mln::trait::concrete to have swig understand the return types of
mln::morpho::dilation.hh and mln::morpho::erosion.
* ch_value.ixx: Adjust documentation.
* Makefile.am (meta_wrappers, wrappers): New variables.
Use them...
(EXTRA_DIST): ...here.
(meta_wrappers): Add concrete.ixx.
Makefile.am | 10 +++++---
ch_value.ixx | 6 ++---
concrete.ixx | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
image2d_int.i | 3 ++
image2d_int_u8.i | 4 +++
morpho.ixx | 41 ++++++-----------------------------
6 files changed, 88 insertions(+), 40 deletions(-)
Index: image2d_int_u8.i
--- image2d_int_u8.i (revision 2131)
+++ image2d_int_u8.i (working copy)
@@ -64,6 +64,10 @@
%}
%include "morpho.ixx"
+
+// Explicit instantiation of this trait for the return type of
+// mln::morpho::dilation and mln::morpho::erosion.
+%template() mln::trait::concrete< mln::image2d< mln::value::int_u<8> > >;
/* FIXME: Can't we use `mln::value::int8' directlt here (as we can
use `mln::window2d', which is a really just typedef for
`mln::window< mln::dpoint_<mln::grid::square, int> >')? */
Index: ch_value.ixx
--- ch_value.ixx (revision 2131)
+++ ch_value.ixx (working copy)
@@ -28,12 +28,12 @@
/// \file ch_value.i
/// \brief A wrapper of mln::trait::ch_value.
+///
+/// This is a very limited workaround for the difficult wrapping of
+/// mln::trait::ch_value (or even of a subset of it).
%module ch_value
-/* FIXME: Use this very limited workaround instead of
- mln/trait/ch_value.hh or even a subset of it for the moment. */
-
%{
#include "mln/trait/ch_value.hh"
%}
Index: image2d_int.i
--- image2d_int.i (revision 2131)
+++ image2d_int.i (working copy)
@@ -49,5 +49,8 @@
%}
%include "morpho.ixx"
+// Explicit instantiation of this trait for the return type of
+// mln::morpho::dilation and mln::morpho::erosion.
+%template() mln::trait::concrete< mln::image2d< int > >;
%template(dilation) mln::morpho::dilation< mln::image2d<int>, mln::window2d >;
%template(erosion) mln::morpho::erosion< mln::image2d<int>, mln::window2d >;
Index: Makefile.am
--- Makefile.am (revision 2131)
+++ Makefile.am (working copy)
@@ -4,13 +4,15 @@
# Meta-wrappers (templates), not generating a module, but factoring
# common parts.
-EXTRA_DIST = \
- ch_value.ixx fill.ixx image2d.ixx intp.ixx int_u.ixx \
- morpho.ixx pgm.ixx println.ixx
+meta_wrappers = \
+ ch_value.ixx concrete.ixx fill.ixx image2d.ixx intp.ixx \
+ int_u.ixx morpho.ixx pgm.ixx println.ixx
# Wrappers (generating actual modules).
-EXTRA_DIST += \
+wrappers = \
dpoint2d.i image2d_int.i image2d_int_u8.i int_u8.i \
int_u32.i neighb2d.i point2d.i window2d.i
+EXTRA_DIST = $(meta_wrappers) $(wrappers)
+
check_SCRIPTS = run
Index: concrete.ixx
--- concrete.ixx (revision 0)
+++ concrete.ixx (revision 0)
@@ -0,0 +1,64 @@
+// -*- 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 concrete.i
+/// \brief A wrapper of mln::trait::concrete.
+///
+/// This is a very limited workaround for the difficult wrapping of
+/// mln::trait::concrete.
+
+%module concrete
+
+%{
+#include "mln/trait/concrete.hh"
+%}
+
+# define mln_concrete(I) typename mln::trait::concrete< I >::ret
+
+namespace mln
+{
+ namespace trait
+ {
+ /* Swig is not powerful enough to parse difficult templates. For
+ instance, it won't match this specialization.
+
+ mln::trait::concrete depends on mln::trait::ch_value.ixx that
+ swig cannot wrap yet (see ch_value.ixx). So we just give it
+ simple ``inlined'' equivalent traits that are compatible with
+ the ones in mln/trait/ch_value.hh. */
+
+ // By default, assume the concrete type is the paramater itself.
+ template <typename I>
+ struct concrete
+ {
+ typedef I ret;
+ };
+
+ } // end of namespace mln::morpho
+
+} // end of namespace mln
Index: morpho.ixx
--- morpho.ixx (revision 2131)
+++ morpho.ixx (working copy)
@@ -26,49 +26,24 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file fill.i
+/// \file morpho.i
/// \brief Wrappers of morphological algorithms from mln::morpho.
%module morpho
-/*---------------------------.
-| Dilation and erxrebosion. |
-`---------------------------*/
+/*-----------------------.
+| Dilation and erosion. |
+`-----------------------*/
+
+%include "concrete.ixx"
%{
#include "mln/morpho/dilation.hh"
#include "mln/morpho/erosion.hh"
%}
-// FIXME: Wrap mln::morpho::erosion by hand, for mln_concrete(I)
-// disturbs swig. Annotate the original source code instead?
-namespace mln
-{
- namespace morpho
- {
-
- /* FIXME: How can we handle concrete in Swilena? Simplify this
- for the moment, and use I directly as return type.
-
- 2008-08-08: Actualy, it's very simple: just ask swig to wrap
- the macro `mln_concrete'. See how we did it with
- `mln_ch_value'.
-
- We should apply this to as many wrappers as we can: we have
- inlined many `mln_*' macros so far, and it is a pain to
- maintain. */
-
- template <typename I, typename W>
- I
- dilation(const Image<I>& input, const Window<W>& win);
-
- template <typename I, typename W>
- I
- erosion(const Image<I>& input, const Window<W>& win);
-
- } // end of namespace mln::morpho
-
-} // end of namespace mln
+%include "mln/morpho/dilation.hh"
+%include "mln/morpho/erosion.hh"
/*------------------------------------.
https://svn.lrde.epita.fr/svn/oln/trunk/swilena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Wrap meyer_wst for image2d<int_u8>.
* int_u.ixx: New.
Use it...
* int_u8.i: ...here.
Actually instantiate and wrap int_u8.
* int_u32.i: New.
* ch_value.ixx: New.
Use it...
* morpho.ixx: ...here.
Wrap meyer_wst for image2d<int_u8>.
* neighb2d.i: New.
* image2d_int_u8.i: Add support for meyer_wst.
* window2d.i: Aesthetic changes.
* Makefile.am (EXTRA_DIST): Add ch_value.ixx, int_u.ixx, int_u32.i
and neighb2d.i.
* python/lena.py: Exercise meyer_wst.
* python/Makefile.am: Handle modules int_u32 and neighb2d.
* python/swilena.py: Import neighb2d, int_u8 and int_u32.
Makefile.am | 12 +++--
ch_value.ixx | 78 +++++++++++++++++++++++++++++++++
image2d_int_u8.i | 32 +++++++++++++
int_u.ixx | 113 +++++++++++++++++++++++++++++++++++++++++++++++
int_u32.i | 42 +++++++++++++++++
int_u8.i | 4 +
morpho.ixx | 27 +++++++++++
neighb2d.i | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++
python/Makefile.am | 20 ++++++++
python/lena.py | 29 ++++++++++--
python/swilena.py | 5 ++
window2d.i | 11 ++--
12 files changed, 483 insertions(+), 15 deletions(-)
Index: python/lena.py
--- python/lena.py (revision 2129)
+++ python/lena.py (working copy)
@@ -30,14 +30,33 @@
import os
from swilena import *
+# Factor this part in a shared test Python file.
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)
+# Module alias.
+image = image2d_int_u8
-eroded = image2d_int_u8.erosion (ima, win_c4p())
-image2d_int_u8.save(eroded, "eroded.pgm")
+ima = image.load(lena)
-dilated = image2d_int_u8.dilation (ima, win_c4p())
-image2d_int_u8.save(dilated, "dilated.pgm")
+eroded = image.erosion (ima, win_c4p())
+image.save(eroded, "eroded.pgm")
+
+dilated = image.dilation (ima, win_c4p())
+image.save(dilated, "dilated.pgm")
+
+# Watershed Transform.
+# FIXME: Run a gradient and an area closing first.
+nbasins = int_u32();
+ws = image.meyer_wst (ima, c4(), nbasins)
+print (type (ws))
+# FIXME: Ugly name; move int_u32 methods outside image2d_int_u8.
+image.println32(ws)
+# FIXME: Actualy print the number of basins; for the moment, thus
+# statement outputs something like
+#
+# <int_u32.int_u32; proxy of <Swig Object of type 'mln::value::int_u< 32 > *'
+# at 0x816e160> >
+#
+print nbasins
Index: python/Makefile.am
--- python/Makefile.am (revision 2129)
+++ python/Makefile.am (working copy)
@@ -62,6 +62,16 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_int_u8-wrap.Pcc@am__quote@
nodist_python_PYTHON += int_u8.py
+## int_u32.
+pyexec_LTLIBRARIES += _int_u32.la
+nodist__int_u32_la_SOURCES = int_u32-wrap.cc
+_int_u32_la_LIBADD = $(AM_LIBADD)
+CLEANFILES += $(nodist__int_u32_la_SOURCES) int_u32.py int_u32.py[co]
+## Include the dependency files. Copied from Automake's generated
+## case for C++.
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_int_u32-wrap.Pcc@am__quote@
+nodist_python_PYTHON += int_u32.py
+
## dpoint2d.
pyexec_LTLIBRARIES += _dpoint2d.la
nodist__dpoint2d_la_SOURCES = dpoint2d-wrap.cc
@@ -72,6 +82,16 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_dpoint2d-wrap.Pcc@am__quote@
nodist_python_PYTHON += dpoint2d.py
+## neighb2d.
+pyexec_LTLIBRARIES += _neighb2d.la
+nodist__neighb2d_la_SOURCES = neighb2d-wrap.cc
+_neighb2d_la_LIBADD = $(AM_LIBADD)
+CLEANFILES += $(nodist__neighb2d_la_SOURCES) neighb2d.py neighb2d.py[co]
+## Include the dependency files. Copied from Automake's generated
+## case for C++.
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_neighb2d-wrap.Pcc@am__quote@
+nodist_python_PYTHON += neighb2d.py
+
## window2d.
pyexec_LTLIBRARIES += _window2d.la
nodist__window2d_la_SOURCES = window2d-wrap.cc
Index: python/swilena.py
--- python/swilena.py (revision 2129)
+++ python/swilena.py (working copy)
@@ -31,6 +31,11 @@
from point2d import *
from dpoint2d import *
+from neighb2d import *
from window2d import *
+
+from int_u8 import *
+from int_u32 import *
+
import image2d_int
import image2d_int_u8
Index: window2d.i
--- window2d.i (revision 2129)
+++ window2d.i (working copy)
@@ -37,17 +37,17 @@
#include "mln/core/window2d.hh"
%}
+// FIXME: Move mln::window to its own file.
+
%include "mln/core/concept/window.hh"
-// FIXME: Wrap mln::image2d by hand, for Milena macros disturb swig.
+// FIXME: Wrap mln::window by hand, for Milena macros disturb swig.
// Annotate the original source code instead?
namespace mln
{
template <typename D>
- class window
- /* FIXME: Simplify, so as to minimize the work. */
- : public Window< window<D> >
- , public internal::dpoints_base_<D, window<D> >
+ class window : public Window< window<D> >,
+ public internal::dpoints_base_<D, window<D> >
{
typedef internal::dpoints_base_<D, window<D> > super_;
public:
@@ -103,6 +103,7 @@
// box_<mln_point(D)> b_;
box_<typename D::point> b_;
};
+
} // end of namespace mln
%include "mln/core/window2d.hh"
Index: image2d_int_u8.i
--- image2d_int_u8.i (revision 2129)
+++ image2d_int_u8.i (working copy)
@@ -57,8 +57,40 @@
#include "mln/core/window2d.hh"
%}
+%import "neighb2d.i"
+// FIXME: The import directive does not include the `%{ ... %}' clauses.
+%{
+#include "mln/core/neighb2d.hh"
+%}
+
%include "morpho.ixx"
+/* FIXME: Can't we use `mln::value::int8' directlt here (as we can
+ use `mln::window2d', which is a really just typedef for
+ `mln::window< mln::dpoint_<mln::grid::square, int> >')? */
%template(dilation) mln::morpho::dilation< mln::image2d< mln::value::int_u<8> >,
mln::window2d >;
%template(erosion) mln::morpho::erosion< mln::image2d< mln::value::int_u<8> >,
mln::window2d >;
+
+// Explicit instantiation of this trait for the return type of
+// mln::morpho::meyer_wst.
+%template() mln::trait::ch_value< mln::image2d< mln::value::int_u<8> >,
+ mln::value::int_u<32> >;
+%template(meyer_wst) mln::morpho::meyer_wst<
+ mln::value::int_u<32>,
+ mln::image2d< mln::value::int_u<8> >,
+ mln::neighb2d
+ >;
+
+
+/*-------------------.
+| image2d<int_u32>. |
+`-------------------*/
+
+// FIXME: Rearrange and move this elsewhere.
+
+%template(image2d_int_u32) mln::image2d< mln::value::int_u<32> >;
+
+%template(println32) mln::debug::println<
+ mln::image2d< mln::value::int_u<32> >
+ >;
Index: int_u.ixx
--- int_u.ixx (revision 0)
+++ int_u.ixx (revision 0)
@@ -0,0 +1,113 @@
+// -*- 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_u.i
+/// \brief A wrapper of mln::value::int_u.
+
+%module int_u
+
+%{
+#include "mln/value/int_u.hh"
+%}
+
+// FIXME: Wrap mln::int_u by hand, for Milena macros disturb swig.
+// Annotate the original source code instead?
+namespace mln
+{
+
+ namespace value
+ {
+
+ /*! \brief Unsigned integer value class.
+ *
+ * The parameter is \c n the number of encoding bits.
+ */
+ template <unsigned n>
+ struct int_u
+ :
+ public Integer< int_u<n> >,
+
+ public internal::value_like_< unsigned, // Equivalent.
+ typename internal::encoding_unsigned_<n>::ret, // Enc.
+ int, // Interoperation.
+ int_u<n> > // Exact.
+ {
+ protected:
+ /// Encoding associated type.
+ typedef typename internal::encoding_unsigned_<n>::ret enc_;
+
+ public:
+
+ /// Constructor without argument.
+ int_u();
+
+ /// Constructor from an integer.
+ int_u(int i);
+
+ /// \{ Constructors/assignments with literals.
+ int_u(const mln::literal::zero_t&);
+ int_u& operator=(const mln::literal::zero_t&);
+ int_u(const mln::literal::one_t&);
+ int_u& operator=(const mln::literal::one_t&);
+ /// \}
+
+ /// Conversion to an unsigned integer.
+ operator unsigned() const;
+
+ /// Unary operator minus.
+ int operator-() const;
+
+ /// Assignment from an integer.
+ int_u<n>& operator=(int i);
+ };
+
+
+ // Safety.
+ template <> struct int_u<0>;
+ template <> struct int_u<1>;
+
+
+
+ /*! \brief Print an unsigned integer \p i into the output stream \p ostr.
+ *
+ * \param[in,out] ostr An output stream.
+ * \param[in] i An unsigned integer.
+ *
+ * \return The modified output stream \p ostr.
+ */
+ template <unsigned n>
+ std::ostream& operator<<(std::ostream& ostr, const int_u<n>& i);
+
+
+ // FIXME: Doc!
+ template <unsigned n>
+ std::istream& operator>>(std::istream& istr, int_u<n>& i);
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
Index: ch_value.ixx
--- ch_value.ixx (revision 0)
+++ ch_value.ixx (revision 0)
@@ -0,0 +1,78 @@
+// -*- 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 ch_value.i
+/// \brief A wrapper of mln::trait::ch_value.
+
+%module ch_value
+
+/* FIXME: Use this very limited workaround instead of
+ mln/trait/ch_value.hh or even a subset of it for the moment. */
+
+%{
+#include "mln/trait/ch_value.hh"
+%}
+
+# define mln_ch_value(I, V) typename mln::trait::ch_value< I, V >::ret
+# define mln_ch_value_(I, V) mln::trait::ch_value< I, V >::ret
+
+namespace mln
+{
+ namespace trait
+ {
+
+ template <typename I, typename L>
+ struct ch_value
+ {
+ // Nothing by default.
+ };
+
+ /* Swig is not powerful enough to parse difficult templates. For
+ instance, it won't match this specialization.
+
+ template <typename T, typename U>
+ struct ch_value< mln::image2d< T >, U >
+ {
+ typedef mln::image2d< U > ret;
+ };
+
+ (which is even simpler than what mln/trait/ch_value.hh contains!)
+
+ So we just give it simple ``inlined'' equivalent traits that
+ are compatible with the ones in mln/trait/ch_value.hh. */
+
+ template <>
+ struct ch_value< mln::image2d< mln::value::int_u<8> >,
+ mln::value::int_u<32> >
+ {
+ typedef mln::image2d< mln::value::int_u<32> > ret;
+ };
+
+ } // end of namespace mln::morpho
+
+} // end of namespace mln
Index: int_u8.i
--- int_u8.i (revision 2129)
+++ int_u8.i (working copy)
@@ -31,8 +31,12 @@
%module int_u8
+%include "int_u.ixx"
+
%{
#include "mln/value/int_u8.hh"
%}
%include "mln/value/int_u8.hh"
+
+%template (int_u8) mln::value::int_u<8>;
Index: Makefile.am
--- Makefile.am (revision 2129)
+++ Makefile.am (working copy)
@@ -2,11 +2,15 @@
SUBDIRS = python
-# Meta-wrappers (templates).
-EXTRA_DIST = fill.ixx image2d.ixx intp.ixx morpho.ixx pgm.ixx println.ixx
-# Wrappers.
+# Meta-wrappers (templates), not generating a module, but factoring
+# common parts.
+EXTRA_DIST = \
+ ch_value.ixx fill.ixx image2d.ixx intp.ixx int_u.ixx \
+ morpho.ixx pgm.ixx println.ixx
+
+# Wrappers (generating actual modules).
EXTRA_DIST += \
dpoint2d.i image2d_int.i image2d_int_u8.i int_u8.i \
- point2d.i window2d.i
+ int_u32.i neighb2d.i point2d.i window2d.i
check_SCRIPTS = run
Index: neighb2d.i
--- neighb2d.i (revision 0)
+++ neighb2d.i (revision 0)
@@ -0,0 +1,125 @@
+// -*- 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 neighb2d.i
+/// \brief A wrapper of mln::neighb2d.
+
+%module neighb2d
+
+%import "dpoint2d.i"
+
+%{
+#include "mln/core/neighb2d.hh"
+%}
+
+// FIXME: Move mln::neighb_ to its own file.
+
+%include "mln/core/concept/neighborhood.hh"
+
+// FIXME: Wrap mln::neighb by hand, for Milena macros disturb swig.
+// Annotate the original source code instead?
+namespace mln
+{
+
+ // fwd decls
+ template <typename D> class dpoints_fwd_piter;
+ template <typename D> class dpoints_bkd_piter;
+
+
+ /*! \brief Generic neighborhood class.
+ *
+ * This neighborhood of window is just like a set of delta-points.
+ * The parameter is \c D, type of delta-point.
+ */
+ template <typename D>
+ struct neighb_ : public Neighborhood< neighb_<D> >,
+ public internal::dpoints_base_<D, neighb_<D> >
+ {
+ /// Dpoint associated type.
+ typedef D dpoint;
+
+// FIXME: The macro mln_point disturbs swig.
+// /// Point associated type.
+// typedef mln_point(D) point;
+ typedef typename D::point point;
+
+ /*! \brief Point_Iterator type to browse the points of a generic
+ * neighborhood w.r.t. the ordering of delta-points.
+ */
+ typedef dpoints_fwd_piter<D> fwd_niter;
+
+ /*! \brief Point_Iterator type to browse the points of a generic
+ * neighborhood w.r.t. the reverse ordering of delta-points.
+ */
+ typedef dpoints_bkd_piter<D> bkd_niter;
+
+ /*! \brief Same as fwd_niter.
+ */
+ typedef fwd_niter niter;
+
+ /*! \brief Constructor without argument.
+ *
+ * The constructed neighborhood is empty. You have to use insert()
+ * to proceed to the neighborhood definition.
+ */
+ neighb_();
+
+ /*! \brief Insert a delta-point \p dp in the neighborhood
+ * definition.
+ *
+ * \param[in] dp The delta-point to insert.
+ *
+ * This method also insert the symmetrical delta-point, - \p dp,
+ * in the neighborhood definition; thus the client has not to
+ * ensure the symmetry property; that is automatic.
+ */
+ neighb_<D>& insert(const D& dp);
+
+// FIXME: Swig tries to wrap everything by default; prevent it from wrapping
+// invalid methods (1D and 3D ctors for a point2d).
+ /// \{ Insertion of a delta-point with different numbers of
+ /// arguments (coordinates) w.r.t. the dimension.
+// neighb_<D>& insert(const mln_coord(D)& dind); // For 1D.
+
+// FIXME: The macro mln_coord disturbs swig.
+// neighb_<D>& insert(const mln_coord(D)& drow,
+// const mln_coord(D)& dcol); // For 2D.
+ neighb_<D>& insert(const typename D::coord& drow,
+ const typename D::coord& dcol); // For 2D.
+
+// neighb_<D>& insert(const mln_coord(D)& dsli,
+// const mln_coord(D)& drow,
+// const mln_coord(D)& dcol); // For 3D.
+ /// \}
+ };
+
+} // end of namespace mln
+
+%include "mln/core/neighb2d.hh"
+
+%template(neighb2d) mln::neighb_< mln::dpoint_<mln::grid::square, int > >;
Index: int_u32.i
--- int_u32.i (revision 0)
+++ int_u32.i (revision 0)
@@ -0,0 +1,42 @@
+// -*- 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_u32.i
+/// \brief A wrapper of mln::value::int_u32.
+
+%module int_u32
+
+%include "int_u.ixx"
+
+%{
+#include "mln/value/int_u32.hh"
+%}
+
+%include "mln/value/int_u32.hh"
+
+%template (int_u32) mln::value::int_u<32>;
Index: morpho.ixx
--- morpho.ixx (revision 2129)
+++ morpho.ixx (working copy)
@@ -31,6 +31,10 @@
%module morpho
+/*---------------------------.
+| Dilation and erxrebosion. |
+`---------------------------*/
+
%{
#include "mln/morpho/dilation.hh"
#include "mln/morpho/erosion.hh"
@@ -44,7 +48,15 @@
{
/* FIXME: How can we handle concrete in Swilena? Simplify this
- for the moment, and use I directly as return type. */
+ for the moment, and use I directly as return type.
+
+ 2008-08-08: Actualy, it's very simple: just ask swig to wrap
+ the macro `mln_concrete'. See how we did it with
+ `mln_ch_value'.
+
+ We should apply this to as many wrappers as we can: we have
+ inlined many `mln_*' macros so far, and it is a pain to
+ maintain. */
template <typename I, typename W>
I
@@ -57,3 +69,16 @@
} // end of namespace mln::morpho
} // end of namespace mln
+
+
+/*------------------------------------.
+| Meyer's Watershed Transform (WST). |
+`------------------------------------*/
+
+%include "ch_value.ixx"
+
+%{
+#include "mln/morpho/meyer_wst.hh"
+%}
+
+%include "mln/morpho/meyer_wst.hh"