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