https://svn.lrde.epita.fr/svn/oln/trunk/swilena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Wrap more morphological filters.
* morpho.ixx: Wrap mln::morpho::closing, mln::morpho::opening
mln::morpho::gradient_internal, mln::morpho::gradient_external,
mln::morpho::opening_area.
(instantiate_closing, instantiate_opening)
(instantiate_gradient_internal, instantiate_gradient_external)
(instantiate_opening_area):
New macros.
Use them...
(instantiate_morpho): ...here.
Deduce the previous `L' parameter from `mln_value(I)', and remove
it from the list of parameters of the macro.
* image2d_int_u8.i: Adjust.
* image2d_int.i: Use macros instantiate_erosion and
instantiate_dilation.
* python/data.py: New.
* python/test.py: Rename as...
* python/image2d-misc.py: ...this.
* python/lena.py: Rename as...
* python/morpho-fun.py: ...this.
Exercise more morphological filters.
Move WST-based segmentation tests...
* python/morpho-segm.py: ...here (new test).
* python/swilena.py: Add documentation header.
* python/Makefile.am (python_PYTHON): Add data.py.
(TESTS): Add morpho-segm.py.
s/test.py/image2d-misc.py/
s/lena.py/morpho-fun.py/
image2d_int.i | 7 +----
image2d_int_u8.i | 3 --
morpho.ixx | 67 +++++++++++++++++++++++++++++++++++++++-----------
python/Makefile.am | 4 ++
python/data.py | 37 +++++++++++++++++++++++++++
python/morpho-fun.py | 50 +++++++++++++++++--------------------
python/morpho-segm.py | 60 ++++++++++++++++++++++++++++++++++++++++++++
python/swilena.py | 3 ++
8 files changed, 183 insertions(+), 48 deletions(-)
Index: python/data.py
--- python/data.py (revision 0)
+++ python/data.py (revision 0)
@@ -0,0 +1,37 @@
+#! /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.
+
+# \file python/data.py
+# \brief Access to the data of the distribution (images, meshes, etc.).
+
+import os
+
+top_srcdir = os.environ["top_srcdir"]
+img_dir = os.path.join(top_srcdir, "milena", "img")
+lena = os.path.join (img_dir, "lena.pgm")
Index: python/morpho-fun.py
--- python/morpho-fun.py (revision 2138)
+++ python/morpho-fun.py (working copy)
@@ -27,38 +27,36 @@
# reasons why the executable file might be covered by the GNU General
# Public License.
-import os
-from swilena import *
+# \file python/morpho-fun.py
+# \brief Test on mathematical morphology on functions (scalar images).
-# 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")
+import data
+from swilena import *
# Module alias.
image = image2d_int_u8
-ima = image.load(lena)
+ima = image.load(data.lena)
+
+dilated = image.dilation(ima, win_c4p())
+image.save(dilated, "dilation.pgm")
eroded = image.erosion(ima, win_c4p())
-image.save(eroded, "eroded.pgm")
+image.save(eroded, "erosion.pgm")
-dilated = image.dilation(ima, win_c4p())
-image.save(dilated, "dilated.pgm")
+image.save(image.opening(ima, win_c4p()), "opening.pgm")
+image.save(image.closing(ima, win_c4p()), "closing.pgm")
-# Gradient.
-gradient = image.gradient(ima, win_c4p())
-# Area closing.
-closed_gradient = image.image2d_int_u8(gradient.domain())
-image.closing_area(ima, c4(), 50, closed_gradient)
-# Watershed transform.
-nbasins = int_u8();
-ws = image.meyer_wst (closed_gradient, c4(), nbasins)
-# FIXME: Actualy print the number of basins; for the moment, this
-# statement outputs something like
-#
-# <int_u32.int_u32; proxy of <Swig Object of type 'mln::value::int_u< 32 > *'
-# at 0x816e160> >
-#
-print nbasins
-image.save(ws, "ws.pgm")
+image.save(image.gradient(ima, win_c4p()), "gradient.pgm")
+image.save(image.gradient_internal(ima, win_c4p()), "gradient_internal.pgm")
+image.save(image.gradient_external(ima, win_c4p()), "gradient_external.pgm")
+
+# FIXME: The interface of closing_area/opening_area is a pain: the
+# output should be returned, not taken as argument.
+closed_ima = image.image2d_int_u8(ima.domain())
+image.closing_area(ima, c4(), 50, closed_ima)
+image.save(closed_ima, "closing_area.pgm")
+
+opened_ima = image.image2d_int_u8(ima.domain())
+image.closing_area(ima, c4(), 50, opened_ima)
+image.save(opened_ima, "opening_area.pgm")
Property changes on: python/morpho-fun.py
___________________________________________________________________
Added: svn:mergeinfo
Index: python/morpho-segm.py
--- python/morpho-segm.py (revision 0)
+++ python/morpho-segm.py (revision 0)
@@ -0,0 +1,60 @@
+#! /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.
+
+# \file python/morpho-segm.py
+# \brief Test on watershed transform-based segmentation.
+
+import data
+from swilena import *
+
+# Module alias.
+image = image2d_int_u8
+
+ima = image.load(data.lena)
+
+# Gradient.
+gradient = image.gradient(ima, win_c4p())
+image.save(gradient, "gradient.pgm")
+# Area closing of the gradient.
+closed_gradient = image.image2d_int_u8(gradient.domain())
+image.closing_area(ima, c4(), 50, closed_gradient)
+# Watershed transform.
+nbasins = int_u8();
+ws = image.meyer_wst (closed_gradient, c4(), nbasins)
+# FIXME: Actualy print the number of basins; for the moment, this
+# statement outputs something like
+#
+# <int_u32.int_u32; proxy of <Swig Object of type 'mln::value::int_u< 32 > *'
+# at 0x816e160> >
+#
+print nbasins
+image.save(ws, "segm.pgm")
+
+# FIXME: Also re-enable the naive segmentation with no gradient
+# simplification, and an output on an image2d<int_u32>.
Property changes on: python/image2d-misc.py
___________________________________________________________________
Added: svn:mergeinfo
Index: python/Makefile.am
--- python/Makefile.am (revision 2138)
+++ python/Makefile.am (working copy)
@@ -30,6 +30,8 @@
python_PYTHON = ltihooks.py
# swilena.py: The whole Swilena suite.
python_PYTHON += swilena.py
+# data.py: Access to the data of the distribution (images, meshes, etc.)
+python_PYTHON += data.py
## ----------------- ##
@@ -170,5 +172,5 @@
$(MAKE) $(AM_MAKEFLAGS) $(RUN)
@mv -f $@.tmp $@
-TESTS = test.py lena.py
+TESTS = image2d-misc.py morpho-fun.py morpho-segm.py
EXTRA_DIST += $(TESTS)
Index: python/swilena.py
--- python/swilena.py (revision 2138)
+++ python/swilena.py (working copy)
@@ -27,6 +27,9 @@
# reasons why the executable file might be covered by the GNU General
# Public License.
+# \file swilena.py
+# \brief The whole Swilena suite.
+
import ltihooks
from point2d import *
Index: image2d_int_u8.i
--- image2d_int_u8.i (revision 2138)
+++ image2d_int_u8.i (working copy)
@@ -68,8 +68,7 @@
then. */
instantiate_morpho(mln::image2d< mln::value::int_u<8> >,
mln::window2d,
- mln::neighb2d,
- mln::value::int_u<8>)
+ mln::neighb2d)
/*---------------------------------------.
| image2d<int_u8> and image2d<int_u32>. |
Index: image2d_int.i
--- image2d_int.i (revision 2138)
+++ image2d_int.i (working copy)
@@ -54,8 +54,5 @@
%}
%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 >;
+instantiate_erosion(erosion, mln::image2d<int>, mln::window2d)
+instantiate_dilation(dilation, mln::image2d<int>, mln::window2d)
Index: morpho.ixx
--- morpho.ixx (revision 2138)
+++ morpho.ixx (working copy)
@@ -31,12 +31,13 @@
%module morpho
+%include "concrete.ixx"
+%include "ch_value.ixx"
+
/*-----------------------------------.
| Morphological dilation & erosion. |
`-----------------------------------*/
-%include "concrete.ixx"
-
%{
#include "mln/morpho/dilation.hh"
#include "mln/morpho/erosion.hh"
@@ -52,22 +53,39 @@
%enddef
%define instantiate_erosion(Name, I, W)
+ // Explicit instantiation of this trait for the return type.
%template() mln::trait::concrete< I >;
%template(Name) mln::morpho::erosion< I, W >;
%enddef
/*----------------------------------.
-| Morphological opening & closing. |
+| Morphological closing & opening. |
`----------------------------------*/
-// FIXME: Add them.
+%{
+#include "mln/morpho/closing.hh"
+#include "mln/morpho/opening.hh"
+%}
+
+%include "mln/morpho/closing.hh"
+%include "mln/morpho/opening.hh"
+
+%define instantiate_closing(Name, I, W)
+ // Explicit instantiation of this trait for the return type.
+ %template() mln::trait::concrete< I >;
+ %template(Name) mln::morpho::closing< I, W >;
+%enddef
+
+%define instantiate_opening(Name, I, W)
+ // Explicit instantiation of this trait for the return type.
+ %template() mln::trait::concrete< I >;
+ %template(Name) mln::morpho::opening< I, W >;
+%enddef
/*------------.
| Gradients. |
`------------*/
-// FIXME: Add other gradient.
-
%{
#include "mln/morpho/gradient.hh"
%}
@@ -80,28 +98,42 @@
%template(Name) mln::morpho::gradient< I, W >;
%enddef
+%define instantiate_gradient_internal(Name, I, W)
+ // Explicit instantiation of this trait for the return type.
+ %template() mln::trait::concrete< I >;
+ %template(Name) mln::morpho::gradient_internal< I, W >;
+%enddef
+
+%define instantiate_gradient_external(Name, I, W)
+ // Explicit instantiation of this trait for the return type.
+ %template() mln::trait::concrete< I >;
+ %template(Name) mln::morpho::gradient_external< I, W >;
+%enddef
+
/*-------------------------.
| Area closing & opening. |
`-------------------------*/
-// FIXME: Add area opening.
-
%{
#include "mln/morpho/closing_area.hh"
+#include "mln/morpho/opening_area.hh"
%}
%include "mln/morpho/closing_area.hh"
+%include "mln/morpho/opening_area.hh"
%define instantiate_closing_area(Name, I, N)
%template(Name) mln::morpho::closing_area< I, N, I >;
%enddef
+%define instantiate_opening_area(Name, I, N)
+ %template(Name) mln::morpho::opening_area< I, N, I >;
+%enddef
+
/*------------------------------------.
| Meyer's Watershed Transform (WST). |
`------------------------------------*/
-%include "ch_value.ixx"
-
%{
#include "mln/morpho/meyer_wst.hh"
%}
@@ -118,12 +150,19 @@
| Instantiate everything. |
`-------------------------*/
-%define instantiate_morpho(I, W, N, L)
+%define instantiate_morpho(I, W, N)
instantiate_dilation(dilation, I, W)
instantiate_erosion(erosion, I, W)
+
+ instantiate_closing(closing, I, W)
+ instantiate_opening(opening, I, W)
+
instantiate_gradient(gradient, I, W)
+ instantiate_gradient_internal(gradient_internal, I, W)
+ instantiate_gradient_external(gradient_external, I, W)
+
instantiate_closing_area(closing_area, I, N)
- // FIXME: Could we used `typename I::value' instead of `L' here, and
- // remove L from the list of arguments?
- instantiate_meyer_wst(meyer_wst, L, I, N)
+ instantiate_opening_area(opening_area, I, N)
+
+ instantiate_meyer_wst(meyer_wst, mln_value(I), I, N)
%enddef
#154: Revive Swilena in Olena 1.0
---------------------------------------------------+------------------------
Reporter: levill_r | Owner: levill_r
Type: task | Status: new
Priority: major | Milestone: Olena 1.0
Component: Swilena | Version: 1.0
Keywords: dynamic interpreter shell interactive |
---------------------------------------------------+------------------------
Start with a very small test (e.g., a single image type + some
morphological filters + a (topological) watershed transform).
BTW, we might want to promote [https://svn.lrde.epita.fr/svn/clspr/trunk/
clspr] (C++-Libtool-SWIG-Python-Ruby) as a reusable component (but this is
just an idea; it might not be usable as-is practically).
(N.B. : Some future users of Olena have requested this (fast)
reintroduction of Swilena; we should work on the distribution of the
project in parallel as well, to have something usable for them.)
--
Ticket URL: <https://trac.lrde.org/olena/ticket/154>
Olena <http://olena.lrde.epita.fr>
Olena, a generic and efficient C++ image processing library.
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"
/*------------------------------------.