[PATCH 21/31] Revive Swilena (again).

* box2d.i, dpoint2d.i, dynamic_image2d.i, fill.ixx, image2d.ixx, * image2d_int.i, image2d_int_u8, morpho.ixx, neighb2d.i, * point2d.i, window2d.i: Catch up with current path, names and definitions from Milena. * python/morpho-fun.py, python/morpho-segm.py: Likewise. * morpho.ixx: Use inlined signatures of functions mln::morpho::dilation and mln::morpho::erosion to be wrapped, instead of inclusions of mln/morpho/dilation.hh and mln/morpho/erosion.hh. * neighb2d.i: Instantiate base classes of mln::neighb2d. * window2d.i: Instantiate bases classes of mln::window2d. (insert(int, int)): New method (extension). * point2d.i (row, col): Restrict this method (extension) to mln::point2d. (point<grid::square, def::coord>(int, int)): New ctor (extension). * ch_value.ixx (mln): Aesthetic change. * python/dynamic-image2d-misc.py (simple_image.is_valid): New method. * Makefile.am: Remove dead code. --- swilena/ChangeLog | 24 ++++++ swilena/box2d.i | 30 ++++---- swilena/ch_value.ixx | 2 +- swilena/dpoint2d.i | 16 +++-- swilena/dynamic_image2d.i | 125 ++++++++++++++++++-------------- swilena/fill.ixx | 19 ++--- swilena/image2d.ixx | 10 ++-- swilena/image2d_int.i | 4 +- swilena/image2d_int_u8.i | 6 +- swilena/morpho.ixx | 64 +++++++++++------ swilena/neighb2d.i | 52 +++++++++++--- swilena/point2d.i | 48 +++++++++---- swilena/python/Makefile.am | 9 ++- swilena/python/dynamic-image2d-misc.py | 3 + swilena/python/morpho-fun.py | 15 +--- swilena/python/morpho-segm.py | 9 +-- swilena/window2d.i | 44 +++++++++--- 17 files changed, 306 insertions(+), 174 deletions(-) diff --git a/swilena/ChangeLog b/swilena/ChangeLog index 87a4b3f..135d84c 100644 --- a/swilena/ChangeLog +++ b/swilena/ChangeLog @@ -1,3 +1,27 @@ +2009-05-14 Roland Levillain <roland@lrde.epita.fr> + + Revive Swilena (again). + + * box2d.i, dpoint2d.i, dynamic_image2d.i, fill.ixx, image2d.ixx, + * image2d_int.i, image2d_int_u8, morpho.ixx, neighb2d.i, + * point2d.i, window2d.i: Catch up with current path, names and + definitions from Milena. + * python/morpho-fun.py, python/morpho-segm.py: Likewise. + * morpho.ixx: Use inlined signatures of functions + mln::morpho::dilation and mln::morpho::erosion to be wrapped, + instead of inclusions of mln/morpho/dilation.hh and + mln/morpho/erosion.hh. + * neighb2d.i: Instantiate base classes of mln::neighb2d. + * window2d.i: Instantiate bases classes of mln::window2d. + (insert(int, int)): New method (extension). + * point2d.i (row, col): Restrict this method (extension) to + mln::point2d. + (point<grid::square, def::coord>(int, int)): New ctor (extension). + * ch_value.ixx (mln): Aesthetic change. + * python/dynamic-image2d-misc.py (simple_image.is_valid): + New method. + * Makefile.am: Remove dead code. + 2009-05-15 Guillaume Lazzara <lazzara@lrde.epita.fr> window2d.i: restore the previous version of this file. diff --git a/swilena/box2d.i b/swilena/box2d.i index 64f5474..00e91e1 100644 --- a/swilena/box2d.i +++ b/swilena/box2d.i @@ -32,27 +32,29 @@ %module box2d %{ -#include "mln/core/box.hh" -#include "mln/core/box2d.hh" +#include "mln/core/site_set/box.hh" +#include "mln/core/alias/box2d.hh" %} %include "mln/core/macros.hh"; +%include "mln/metal/is_unqualif.hh"; -%include "mln/core/box.hh"; -%include "mln/core/box2d.hh"; +%include "mln/core/site_set/box.hh"; +%include "mln/core/alias/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); +/* FIXME: Can't we simplify these directives, i.e. use `point2d' + directly? Maybe we could use mln_coord()? */ +%ignore mln::box< mln::point<mln::grid::square, mln::def::coord> > +::box(typename mln::point<mln::grid::square, mln::def::coord>::coord); -%extend mln::box_ +%ignore mln::box< mln::point<mln::grid::square, mln::def::coord> > +::box(typename mln::point<mln::grid::square, mln::def::coord>::coord, + typename mln::point<mln::grid::square, mln::def::coord>::coord, + typename mln::point<mln::grid::square, mln::def::coord>::coord); + +%extend mln::box { unsigned nrows() const { @@ -68,4 +70,4 @@ box_(typename mln::point_<mln::grid::square, int>::coord, } -%template(box2d) mln::box_< mln::point_<mln::grid::square, int> >; +%template(box2d) mln::box< mln::point<mln::grid::square, mln::def::coord> >; diff --git a/swilena/ch_value.ixx b/swilena/ch_value.ixx index 74f0ca4..9ed217c 100644 --- a/swilena/ch_value.ixx +++ b/swilena/ch_value.ixx @@ -46,7 +46,7 @@ namespace mln namespace trait { - template <typename I, typename L> + template <typename I, typename V> struct ch_value { // Nothing by default. diff --git a/swilena/dpoint2d.i b/swilena/dpoint2d.i index b87b8fa..48a4e93 100644 --- a/swilena/dpoint2d.i +++ b/swilena/dpoint2d.i @@ -33,17 +33,19 @@ %{ #include "mln/core/dpoint.hh" -#include "mln/core/dpoint2d.hh" +#include "mln/core/alias/dpoint2d.hh" %} %include "mln/core/dpoint.hh"; -%include "mln/core/dpoint2d.hh"; +%include "mln/core/alias/dpoint2d.hh"; // Swig tries to wrap everything by default; prevent it from wrapping // invalid methods (1D and 3D ctors for a point2d). -%ignore mln::dpoint_<mln::grid::square,int>::dpoint_(const literal::one_t&); -%ignore mln::dpoint_<mln::grid::square,int>::operator=(const literal::one_t&); -%ignore mln::dpoint_<mln::grid::square,int>::dpoint_(int); -%ignore mln::dpoint_<mln::grid::square,int>::dpoint_(int, int, int); +%ignore mln::dpoint<mln::grid::square,mln::def::coord>::dpoint(const literal::one_t&); +%ignore mln::dpoint<mln::grid::square,mln::def::coord>::operator=(const literal::one_t&); +%ignore mln::dpoint<mln::grid::square,mln::def::coord>::dpoint(mln::def::coord); +%ignore mln::dpoint<mln::grid::square,mln::def::coord>::dpoint(mln::def::coord, + mln::def::coord, + mln::def::coord); -%template(dpoint2d) mln::dpoint_<mln::grid::square, int>; +%template(dpoint2d) mln::dpoint<mln::grid::square, mln::def::coord>; diff --git a/swilena/dynamic_image2d.i b/swilena/dynamic_image2d.i index cfdfa89..acee985 100644 --- a/swilena/dynamic_image2d.i +++ b/swilena/dynamic_image2d.i @@ -43,8 +43,8 @@ %{ # include <mln/core/concept/image.hh> -# include <mln/core/box2d.hh> -# include <mln/core/init.hh> +# include <mln/core/alias/box2d.hh> +# include <mln/core/routine/init.hh> # include <mln/value/set.hh> %} @@ -71,28 +71,44 @@ namespace mln namespace trait { + // These traits actually depend on the exact (here dynamic) type + // of the image, therefore we should provide several entry points + // (dynamic_image_ implementations. template <typename T> struct image_< dynamic_image2d<T> > : default_image_< T, dynamic_image2d<T> > { + // misc typedef trait::image::category::primary category; - - typedef trait::image::access::random access; - typedef trait::image::space::two_d space; - typedef trait::image::size::regular size; - typedef trait::image::support::aligned support; - - typedef trait::image::border::none border; - typedef trait::image::data::raw data; - typedef trait::image::io::read_write io; - typedef trait::image::speed::fast speed; + typedef trait::image::speed::slow speed; + typedef trait::image::size::regular size; + + // value + typedef trait::image::vw_io::none vw_io; + typedef trait::image::vw_set::none vw_set; + typedef trait::image::value_access::indirect value_access; + typedef trait::image::value_storage::disrupted value_storage; + typedef trait::image::value_browsing::site_wise_only value_browsing; + typedef trait::image::value_alignment::with_grid value_alignment; + typedef trait::image::value_io::read_write value_io; + + // site / domain + typedef trait::image::pw_io::read_write pw_io; + typedef trait::image::localization::basic_grid localization; + typedef trait::image::dimension::two_d dimension; + + // extended domain + typedef trait::image::ext_domain::none ext_domain; + typedef trait::image::ext_value::irrelevant ext_value; + typedef trait::image::ext_io::irrelevant ext_io; }; } // end of namespace mln::trait /* FIXME: Inherit from internal::image_base to factor methods (see - below)? */ + below)? Probably not, as internal::image_base contains data + (through a tracked_ptr). */ // \brief A semi-abstract class that serves as an entry point // (called « director » by SWIG) for Python code. // @@ -101,14 +117,13 @@ namespace mln template <typename T> struct dynamic_image2d : Image< dynamic_image2d<T> > { - typedef box2d pset; + typedef box2d domain_t; + typedef point2d site; typedef point2d psite; - typedef point2d point; typedef dpoint2d dpoint; typedef mln_fwd_piter(box2d) fwd_piter; typedef mln_bkd_piter(box2d) bkd_piter; - // End of warning. - + typedef fwd_piter piter; /// Value associated type. typedef T value; @@ -139,14 +154,12 @@ namespace mln /// 3). dynamic_image2d(const box2d& b); + // FIXME: Add a virtual dtor? /// Initialize an empty image. virtual void init_(const box2d& b); - /// Test if \p p is valid. - virtual bool owns_(const point2d& p) const; - /// Give the set of values of the image. virtual const vset& values() const; @@ -160,25 +173,30 @@ namespace mln virtual T& operator()(const point2d& p); - // From internal::image_base. - - /// Mesh associated type. - typedef mln_mesh(pset) mesh; - /// Coordinate associated type. - typedef mln_coord(point) coord; - /// Test if \p p belongs to the image domain. virtual bool has(const psite& p) const; /// Give a bounding box of the image domain. virtual const box2d& bbox() const; - /// Give the number of points of the image domain. - virtual std::size_t npoints() const; - /// Test if this image has been initialized; default impl. - virtual bool has_data() const; + + /// Is this image valid? (dummy method). + virtual bool is_valid() const; + + /// Eligible-value-set associated type. + typedef mln::value::set<T> t_eligible_values_set; + + // Return the set of the image eligigle values + const t_eligible_values_set& values_eligible() const; + + /// Value space associated type. + typedef mln::value::set< + typename mln::value::super_value<T>::ret > t_values_space; + + /// Return the value space of the image. + const t_values_space& values_space() const; // We can set domain_ to protected, otherwise Python subclasses // won't see it. - pset domain_; + domain_t domain_; }; @@ -222,15 +240,6 @@ namespace mln template <typename T> inline - bool - dynamic_image2d<T>::owns_(const point2d& p) const - { - mln_precondition(exact(this)->has_data()); - return exact(this)->has(p); - } - - template <typename T> - inline const typename dynamic_image2d<T>::vset& dynamic_image2d<T>::values() const { @@ -242,7 +251,7 @@ namespace mln const box2d& dynamic_image2d<T>::domain() const { - mln_precondition(this->has_data()); + mln_precondition(this->is_valid()); return domain_; } @@ -253,7 +262,7 @@ namespace mln const T& dynamic_image2d<T>::operator()(const point2d& p) const { - // Nothing. + // Dummy. assert(false); } @@ -264,7 +273,7 @@ namespace mln T& dynamic_image2d<T>::operator()(const point2d& p) { - // Nothing. + // Dummy. assert(false); } @@ -273,7 +282,7 @@ namespace mln bool dynamic_image2d<T>::has(const psite& p) const { - mln_precondition(exact(this)->has_data()); + mln_precondition(this->is_valid()); return exact(this)->domain().has(p); } @@ -282,25 +291,33 @@ namespace mln const box2d& dynamic_image2d<T>::bbox() const { - mln_precondition(exact(this)->has_data()); + mln_precondition(this->is_valid()); return exact(this)->domain().bbox(); } template <typename T> inline - std::size_t - dynamic_image2d<T>::npoints() const + bool + dynamic_image2d<T>::is_valid() const { - mln_precondition(exact(this)->has_data()); - return exact(this)->domain().npoints(); + // Dummy. + return false; } template <typename T> inline - bool - dynamic_image2d<T>::has_data() const + const typename dynamic_image2d<T>::t_eligible_values_set& + dynamic_image2d<T>::values_eligible() const + { + return t_eligible_values_set::the(); + } + + template <typename T> + inline + const typename dynamic_image2d<T>::t_values_space& + dynamic_image2d<T>::values_space() const { - return true; + return t_values_space::the(); } } // end of namespace mln @@ -311,7 +328,7 @@ namespace mln %include "fill.ixx" -%template(fill) mln::level::fill< mln::dynamic_image2d< mln::value::int_u<8> > >; +%template(fill) mln::data::fill< mln::dynamic_image2d< mln::value::int_u<8> > >; %include "println.ixx" %template(println) mln::debug::println< mln::dynamic_image2d< mln::value::int_u<8> > >; diff --git a/swilena/fill.ixx b/swilena/fill.ixx index fcbd4bb..a1c1e2c 100644 --- a/swilena/fill.ixx +++ b/swilena/fill.ixx @@ -27,27 +27,24 @@ // Public License. /// \file fill.ixx -/// \brief A wrapper of mln::level::fill. +/// \brief A wrapper of mln::data::fill. %module fill %{ -#include "mln/level/fill.hh" +#include "mln/data/fill.hh" %} %include "mln/core/macros.hh" -/* FIXME: Wrap mln::level::fill by hand to help swig choose the right - overload of the algorithm. We might just try to use %ignore - statements instead. */ +/* Wrap mln::data::fill by hand to help swig choose the right overload + of the algorithm. We might just try to use %ignore statements + instead in a future version. */ namespace mln { - namespace level + namespace data { - template <typename I> void fill(mln::Image<I>& ima, const mln_value(I)& v); - - } // end of namespace mln::level - -} // end of namespace mln + } +} diff --git a/swilena/image2d.ixx b/swilena/image2d.ixx index 491084d..4e46159 100644 --- a/swilena/image2d.ixx +++ b/swilena/image2d.ixx @@ -36,7 +36,7 @@ %import "box2d.i" %{ -#include "mln/core/image2d.hh" +#include "mln/core/image/image2d.hh" %} // Shortcuts macros. @@ -61,14 +61,14 @@ %include "mln/core/internal/image_primary.hh" // mln::image2d definition. -%include "mln/core/image2d.hh" +%include "mln/core/image/image2d.hh" // FIXME: Doc. %define instantiate_image2d(I, T) - // Instantiate base classes of mln::image2d<T> so that swig knows it + // 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_primary< T, mln::box2d, mln::image2d< T > >; + %template() mln::internal::image_base< T, mln::box2d, mln::image2d< T > >; %template() mln::internal::image_checked_< mln::image2d< T > >; // Instantiate mln::image2d<T> %template(I) mln::image2d< T >; diff --git a/swilena/image2d_int.i b/swilena/image2d_int.i index f99cbfe..095be31 100644 --- a/swilena/image2d_int.i +++ b/swilena/image2d_int.i @@ -42,7 +42,7 @@ instantiate_image2d(image2d_int, int) %include "fill.ixx" -%template(fill) mln::level::fill< mln::image2d<int> >; +%template(fill) mln::data::fill< mln::image2d<int> >; %include "println.ixx" %template(println) mln::debug::println< mln::image2d<int> >; @@ -50,7 +50,7 @@ instantiate_image2d(image2d_int, int) %import "window2d.i" // FIXME: The import directive does not include the `%{ ... %}' clauses. %{ -#include "mln/core/window2d.hh" +#include "mln/core/alias/window2d.hh" %} %include "morpho.ixx" diff --git a/swilena/image2d_int_u8.i b/swilena/image2d_int_u8.i index 35bb692..38f1318 100644 --- a/swilena/image2d_int_u8.i +++ b/swilena/image2d_int_u8.i @@ -46,7 +46,7 @@ instantiate_image2d(image2d_int_u8, mln::value::int_u<8>) %template(save) mln::io::pgm::save< mln::image2d< mln::value::int_u<8> > >; %include "fill.ixx" -%template(fill) mln::level::fill< mln::image2d< mln::value::int_u<8> > >; +%template(fill) mln::data::fill< mln::image2d< mln::value::int_u<8> > >; %include "println.ixx" %template(println) mln::debug::println< mln::image2d< mln::value::int_u<8> > >; @@ -54,13 +54,13 @@ instantiate_image2d(image2d_int_u8, mln::value::int_u<8>) %import "window2d.i" // FIXME: The import directive does not include the `%{ ... %}' clauses. %{ -#include "mln/core/window2d.hh" +#include "mln/core/alias/window2d.hh" %} %import "neighb2d.i" // FIXME: The import directive does not include the `%{ ... %}' clauses. %{ -#include "mln/core/neighb2d.hh" +#include "mln/core/alias/neighb2d.hh" %} %include "morpho.ixx" diff --git a/swilena/morpho.ixx b/swilena/morpho.ixx index d01a69d..7145a39 100644 --- a/swilena/morpho.ixx +++ b/swilena/morpho.ixx @@ -43,8 +43,29 @@ #include "mln/morpho/erosion.hh" %} -%include "mln/morpho/dilation.hh" -%include "mln/morpho/erosion.hh" + +/* Files mln/morpho/dilation.hh and mln/morpho/erosion.hh contains too + much implementation details. Using just + + %include "mln/morpho/dilation.hh" + %include "mln/morpho/erosion.hh" + + would require a lot of efforts. Use an explicit prototypes + instead. */ +namespace mln +{ + namespace morpho + { + template <typename I, typename W> + mln_concrete(I) + dilation(const Image<I>& input, const Window<W>& win); + + template <typename I, typename W> + mln_concrete(I) + erosion(const Image<I>& input, const Window<W>& win); + } +} + %define instantiate_dilation(Name, I, W) // Explicit instantiation of this trait for the return type. @@ -58,28 +79,28 @@ %template(Name) mln::morpho::erosion< I, W >; %enddef -/*----------------------------------. -| Morphological closing & opening. | -`----------------------------------*/ +/*-----------------------------------------------. +| Morphological (elementary) closing & opening. | +`-----------------------------------------------*/ %{ -#include "mln/morpho/closing.hh" -#include "mln/morpho/opening.hh" +#include "mln/morpho/elementary/closing.hh" +#include "mln/morpho/elementary/opening.hh" %} -%include "mln/morpho/closing.hh" -%include "mln/morpho/opening.hh" +%include "mln/morpho/elementary/closing.hh" +%include "mln/morpho/elementary/opening.hh" -%define instantiate_closing(Name, I, W) +%define instantiate_closing(Name, I, N) // Explicit instantiation of this trait for the return type. %template() mln::trait::concrete< I >; - %template(Name) mln::morpho::closing< I, W >; + %template(Name) mln::morpho::elementary::closing< I, N >; %enddef -%define instantiate_opening(Name, I, W) +%define instantiate_opening(Name, I, N) // Explicit instantiation of this trait for the return type. %template() mln::trait::concrete< I >; - %template(Name) mln::morpho::opening< I, W >; + %template(Name) mln::morpho::elementary::opening< I, N >; %enddef /*------------. @@ -115,19 +136,19 @@ `-------------------------*/ %{ -#include "mln/morpho/closing_area.hh" -#include "mln/morpho/opening_area.hh" +#include "mln/morpho/closing/area.hh" +#include "mln/morpho/opening/area.hh" %} -%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 >; + %template(Name) mln::morpho::closing::area< I, N >; %enddef %define instantiate_opening_area(Name, I, N) - %template(Name) mln::morpho::opening_area< I, N, I >; + %template(Name) mln::morpho::opening::area< I, N >; %enddef /*------------------------------------. @@ -140,6 +161,7 @@ %include "mln/morpho/meyer_wst.hh" +// FIXME: Wrap mln::morpho::watershed::flooding instead. %define instantiate_meyer_wst(Name, L, I, N) // Explicit instantiation of this trait for the return type. %template() mln::trait::ch_value< I, L >; @@ -154,8 +176,8 @@ instantiate_dilation(dilation, I, W) instantiate_erosion(erosion, I, W) - instantiate_closing(closing, I, W) - instantiate_opening(opening, I, W) + instantiate_closing(closing, I, N) + instantiate_opening(opening, I, N) instantiate_gradient(gradient, I, W) instantiate_gradient_internal(gradient_internal, I, W) diff --git a/swilena/neighb2d.i b/swilena/neighb2d.i index b796b8a..38a4370 100644 --- a/swilena/neighb2d.i +++ b/swilena/neighb2d.i @@ -32,25 +32,57 @@ %module neighb2d %import "dpoint2d.i" +%import "window2d.i" %{ -#include "mln/core/neighb2d.hh" +#include "mln/core/alias/neighb2d.hh" %} +%include "mln/metal/is_a.hh" + %include "mln/core/macros.hh" %include "mln/core/concept/neighborhood.hh" +%include "mln/core/internal/neighborhood_base.hh" %include "mln/core/neighb.hh" -%include "mln/core/neighb2d.hh" +%include "mln/core/alias/neighb2d.hh" // Swig tries to wrap everything by default; prevent it from wrapping // invalid methods (1D and 3D insertions for a neighb2d). -%ignore mln::neighb_< mln::dpoint_<mln::grid::square, int > >:: -insert(const typename mln::dpoint_<mln::grid::square, int>::coord&); -%ignore mln::neighb_< mln::dpoint_<mln::grid::square, int > >:: -insert(const typename mln::dpoint_<mln::grid::square, int>::coord&, - const typename mln::dpoint_<mln::grid::square, int>::coord&, - const typename mln::dpoint_<mln::grid::square, int>::coord&); - -%template(neighb2d) mln::neighb_< mln::dpoint_<mln::grid::square, int > >; +%ignore mln::neighb< mln::window < mln::dpoint<mln::grid::square,mln::def::coord > > > +::insert(const typename mln::dpoint<mln::grid::square,mln::def::coord>::coord&); + +%ignore mln::neighb< mln::window < mln::dpoint<mln::grid::square, mln::def::coord > > > +::insert(const typename mln::dpoint<mln::grid::square,mln::def::coord>::coord&, + const typename mln::dpoint<mln::grid::square,mln::def::coord>::coord&, + const typename mln::dpoint<mln::grid::square,mln::def::coord>::coord&); + +// Instantiate base classes of mln::neighb2d so that Swig knows it +// derives from mln::Neighborhood. +%template() mln::Neighborhood< + mln::neighb< + mln::window< mln::dpoint< mln::grid::square,mln::def::coord > > + > + >; +%template() mln::internal::neighborhood_extra_impl< + mln::window < mln::dpoint<mln::grid::square, mln::def::coord > >, + mln::neighb< + mln::window < mln::dpoint<mln::grid::square, mln::def::coord > > + > + >; +%template() mln::internal::neighborhood_impl< + mln::window < mln::dpoint<mln::grid::square, mln::def::coord > >, + mln::neighb< + mln::window < mln::dpoint<mln::grid::square, mln::def::coord > > + > + >; +%template() mln::internal::neighborhood_base< + mln::window < mln::dpoint<mln::grid::square, mln::def::coord > >, + mln::neighb< + mln::window < mln::dpoint<mln::grid::square, mln::def::coord > > + > + >; +// Instantiate mln::neighb2d. +%template(neighb2d) +mln::neighb< mln::window < mln::dpoint<mln::grid::square, mln::def::coord > > >; diff --git a/swilena/point2d.i b/swilena/point2d.i index e8a6f02..2d3df05 100644 --- a/swilena/point2d.i +++ b/swilena/point2d.i @@ -32,14 +32,15 @@ %module point2d %{ +#include "mln/core/def/coord.hh" #include "mln/core/point.hh" -#include "mln/core/point2d.hh" +#include "mln/core/alias/point2d.hh" %} %include "mln/core/point.hh"; -%include "mln/core/point2d.hh"; +%include "mln/core/alias/point2d.hh"; -/* FIXME: Ignore `mln::point_<M,C>::origin' to circumvent a swig bug. +/* FIXME: Ignore `mln::point<M,C>::origin' to circumvent a swig bug. Without this ignore clause, the generated code would trigger this error : @@ -51,23 +52,42 @@ Check whether this bug has been fixed in a recent release of SWIG or if it has been reported. */ -%ignore mln::point_<mln::grid::square,int>::origin; +%ignore mln::point<mln::grid::square,mln::def::coord>::origin; // Ignoring to_h_vec saves us the wrapping of h_vec. -%ignore mln::point_<mln::grid::square,int>::to_h_vec; +%ignore mln::point<mln::grid::square,mln::def::coord>::to_h_vec; // Swig tries to wrap everything by default; prevent it from wrapping // invalid methods (1D and 3D ctors for a point2d). -%ignore mln::point_<mln::grid::square,int>::point_(const literal::zero_t&); -%ignore mln::point_<mln::grid::square,int>::point_(const literal::one_t&); -%ignore mln::point_<mln::grid::square,int>::point_(int); -%ignore mln::point_<mln::grid::square,int>::point_(int, int, int); +%ignore mln::point<mln::grid::square,mln::def::coord>::point(const literal::zero_t&); +%ignore mln::point<mln::grid::square,mln::def::coord>::point(const literal::one_t&); +%ignore mln::point<mln::grid::square,mln::def::coord>::point(mln::def::coord); +%ignore mln::point<mln::grid::square,mln::def::coord>::point(mln::def::coord, + mln::def::coord, + mln::def::coord); -/* FIXME: Swig doesn't wrap operator[]... Provide row() and col() - accessors instead (we should wrap internal::mutable_coord_impl_ - instead). */ -%extend mln::point_ +/* Milena's `mln::def::coord' is a typedef on `short'. However, this + is unconvenient when using Python's `range()', since this function + produces `int' values, and Python will not implicitly convert them + to `short'. Therefore, we provide an extra ctor to allow the + construction of an mln::point2d from two `int's. */ +%extend mln::point< mln::grid::square, mln::def::coord > +{ + point< mln::grid::square, mln::def::coord >(int row, int col) + { + // ROW and COL are implicitly converted to `short' + return new mln::point2d(row, col); + } +} + +/* Swig doesn't wrap operator[]... Provide row() and col() accessors + instead (we should wrap internal::mutable_coord_impl_ instead). + Note that these methods return `int' values instead of + `mln::def::coord' (i.e., `short') values, to facilitate the + communication with Python (as above). There might be a work + around based on typemaps. */ +%extend mln::point< mln::grid::square, mln::def::coord > { int row() const { return $self->operator[](0); } int col() const { return $self->operator[](1); } } -%template(point2d) mln::point_<mln::grid::square, int>; +%template(point2d) mln::point<mln::grid::square, mln::def::coord>; diff --git a/swilena/python/Makefile.am b/swilena/python/Makefile.am index 6dce7a3..110a9c0 100644 --- a/swilena/python/Makefile.am +++ b/swilena/python/Makefile.am @@ -13,8 +13,6 @@ AM_CXXFLAGS = $(TOOLS_CXXFLAGS) AM_SWIGFLAGS = -Wall -c++ -python -I$(top_srcdir)/milena ## We build modules, not plain libs. AM_LDFLAGS = -avoid-version -module -shared -#### All the modules depend on libhw. -##AM_LIBADD = $(top_builddir)/libhw.la ## Run Swig to create the C++ wrapper files, the Python interface ## files, and the dependency Makefile snippets. @@ -41,6 +39,11 @@ python_PYTHON += data.py ## FIXME: All of this should be generated. ## Don't forget to add a `deps-reset' target as in TC. +## FIXME: Dependencies do not work as expected, e.g., touching +## mln/core/point.hh will not void point-wrap.cc, and Swig will not +## regen it (it will merely recompile _point2d.la). See how other +## projects people handle this. + nodist_python_PYTHON = pyexec_LTLIBRARIES = @@ -154,7 +157,7 @@ python_PYTHON += sps.py # The script to be used in installed distributions. bin_SCRIPTS = sps -# The script to be used in non-installed distributions. +# The script to be used in non-installed build trees. noinst_SCRIPTS = sps-local CLEANFILES += $(bin_SCRIPTS) $(noinst_SCRIPTS) diff --git a/swilena/python/dynamic-image2d-misc.py b/swilena/python/dynamic-image2d-misc.py index 085afab..ffcb709 100644 --- a/swilena/python/dynamic-image2d-misc.py +++ b/swilena/python/dynamic-image2d-misc.py @@ -56,6 +56,9 @@ class simple_image(dyn_ima2d): off = p.row() * self.domain_.ncols() + p.col() return self.values_[off] + def is_valid(self): + return True + # FIXME: Why can't I use # diff --git a/swilena/python/morpho-fun.py b/swilena/python/morpho-fun.py index 881a729..6b8c10e 100644 --- a/swilena/python/morpho-fun.py +++ b/swilena/python/morpho-fun.py @@ -44,19 +44,12 @@ image.save(dilated, "dilation.pgm") eroded = image.erosion(ima, win_c4p()) image.save(eroded, "erosion.pgm") -image.save(image.opening(ima, win_c4p()), "opening.pgm") -image.save(image.closing(ima, win_c4p()), "closing.pgm") +image.save(image.opening(ima, c4()), "opening.pgm") +image.save(image.closing(ima, c4()), "closing.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") +image.save(image.closing_area(ima, c4(), 50), "closing_area.pgm") +image.save(image.closing_area(ima, c4(), 50), "opening_area.pgm") diff --git a/swilena/python/morpho-segm.py b/swilena/python/morpho-segm.py index a4d4de0..5874f19 100644 --- a/swilena/python/morpho-segm.py +++ b/swilena/python/morpho-segm.py @@ -42,17 +42,10 @@ ima = image.load(data.lena) 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) +closed_gradient = image.closing_area(ima, c4(), 50) # 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") diff --git a/swilena/window2d.i b/swilena/window2d.i index 182f6bb..d95b55a 100644 --- a/swilena/window2d.i +++ b/swilena/window2d.i @@ -34,24 +34,48 @@ %import "dpoint2d.i" %{ -#include "mln/core/window2d.hh" +#include "mln/core/alias/window2d.hh" %} %include "mln/core/macros.hh" %include "mln/core/concept/window.hh" +%include "mln/core/internal/window_base.hh" %include "mln/core/window.hh" -%include "mln/core/window2d.hh" +%include "mln/core/alias/window2d.hh" // Swig tries to wrap everything by default; prevent it from wrapping -// invalid methods (1D and 3D insertions for a window2d). -%ignore mln::window< mln::dpoint_<mln::grid::square, int > >:: -insert(const typename mln::dpoint_<mln::grid::square, int>::coord&); -%ignore mln::window< mln::dpoint_<mln::grid::square, int > >:: -insert(const typename mln::dpoint_<mln::grid::square, int>::coord&, - const typename mln::dpoint_<mln::grid::square, int>::coord&, - const typename mln::dpoint_<mln::grid::square, int>::coord&); +// invalid methods (1D and 3D insertions for an mln::window2d). +%ignore mln::window< mln::dpoint<mln::grid::square, mln::def::coord > >:: +insert(const typename mln::dpoint<mln::grid::square, mln::def::coord>::coord&); +%ignore mln::window< mln::dpoint<mln::grid::square, mln::def::coord > >:: +insert(const typename mln::dpoint<mln::grid::square, mln::def::coord>::coord&, + const typename mln::dpoint<mln::grid::square, mln::def::coord>::coord&, + const typename mln::dpoint<mln::grid::square, mln::def::coord>::coord&); -%template(window2d) mln::window< mln::dpoint_<mln::grid::square, int > >; +/* Milena's `mln::def::coord' is a typedef on `short'. However, this + is unconvenient when using Python's builtin integers, since it will + not implicitly convert them to `short'. Therefore, we provide an + extra method to allow the insertion of an mln::window2d from two + `int's. */ +%extend mln::window< mln::dpoint<mln::grid::square,mln::def::coord > > +{ + void insert(int row, int col) + { + /* Explicitly convert ROW and COL to `mln::def::coord' (`short') + to delegate the call. */ + $self->insert(static_cast<mln::def::coord>(row), + static_cast<mln::def::coord>(col)); + } +} +// Instantiate base classes of mln::window2d so that Swig knows it +// derives from mln::Window. +%template() mln::internal::window_base< + mln::dpoint<mln::grid::square, mln::def::coord >, + mln::window< mln::dpoint<mln::grid::square, mln::def::coord > > + >; + // Instantiate mln::window2d. +%template(window2d) +mln::window< mln::dpoint<mln::grid::square,mln::def::coord > >; -- 1.6.1.2
participants (1)
-
Roland Levillain