2130: Wrap meyer_wst for image2d<int_u8>.

https://svn.lrde.epita.fr/svn/oln/trunk/swilena Index: ChangeLog from Roland Levillain <roland@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"
participants (1)
-
Roland Levillain