555: Fix the identity and neighborhood addition morphers.

https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Fix the identity and neighborhood addition morphers. * oln/automatic/image_having_neighborhood.hh: Add a forward declaration of oln::abstract::image_having_neighborhood. (impl<abstract::image_having_neighborhood, morpher::tag::identity, E>): Inherit from abstract::image<E>. (impl_neighborhood): Make it const. Get the exact type before calling delegate(). * oln/core/abstract/image_having_neighborhood.hh (oln/automatic/image_having_neighborhood.hh): Include it. (oln::abstract::image_having_neighborhood::neighborhood): New. (case_<image_hierarchy_wrt_neighborhood, E, 1>): Only inherit from oln::abstract::image_having_neighborhood if neighborhood is different from mlc::not_found. (oln::ext_vtype<image_entry<E>, typedef_::neighborhood_type>): Remove. * oln/core/image_entry.hh (single_vtype<image_entry<E>, typedef_::morpher_type>): Remove. Instead, defined the `morpher' virtual type... (vtypes< image_entry<E> >): ...here. * oln/morpher/internal/image_extension.hh (image_extension): Fix the inheritance: derive from `oln::image_entry<Exact>' instead of `oln::image_entry< image_extension<Image, Exact> >'. * oln/morpher/identity.hh (oln/morpher/tags.hh): Include it. (oln::single_vtype<morpher::identity<Image>, typedef_::morpher_type>): Remove. Instead, defined the `morpher' virtual type... (oln::vtypes< morpher::identity<Image> >): ...here (oln::morpher::tag::identity): Move... * oln/morpher/tags.hh: ...here (new file). * oln/morpher/add_neighborhood.hh (oln/morpher/tags.hh) (oln/core/2d/aliases.hh): Include them. (oln::single_vtype<morpher::add_neighborhood<Image>, typedef_::morpher_type>): Remove. Instead, defined the `morpher' virtual type... (oln::vtypes< morpher::add_neighborhood<Image> >): ...here (oln::morpher::add_neighborhood::neighborhood_t): Fix the virtual type retrieval: get it from `self_t', not from `Image'. (ext_vtype<morpher::add_neighborhood< oln::image2d<T> >, typedef_::neighborhood_type>): Remove. Remove corresponding forward declarations as well. (oln::morpher::tag::add_neighborhood): Move... * oln/morpher/tags.hh: ...here. * tests/identity_morpher.cc, tests/morphers.cc: Fix the test. Add more static assertions. * oln/Makefile.am (nobase_oln_HEADERS): Add core/2d/neighb2d.hh, core/abstract/neighborhood.hh, core/gen/neighb.hh and core/neighborhood_entry.hh. * oln/core/2d/image2d.hh: Fix copyright header. oln/Makefile.am | 4 + oln/automatic/image_having_neighborhood.hh | 28 +++++++---- oln/core/2d/image2d.hh | 3 - oln/core/abstract/image_having_neighborhood.hh | 33 +++++-------- oln/core/image_entry.hh | 14 +---- oln/morpher/add_neighborhood.hh | 57 +++++----------------- oln/morpher/identity.hh | 16 +----- oln/morpher/internal/image_extension.hh | 9 +-- oln/morpher/tags.hh | 49 +++++++++++++++++++ tests/identity_morpher.cc | 20 +++++++ tests/morphers.cc | 63 ++++++++++++++++++------- 11 files changed, 180 insertions(+), 116 deletions(-) Index: tests/morphers.cc --- tests/morphers.cc (revision 554) +++ tests/morphers.cc (working copy) @@ -25,38 +25,67 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/// Test the identity morpher. +/// Test some morphers. + +#include <mlc/assert.hh> +#include <mlc/is_a.hh> // FIXME: We should not include oln/basics2d.hh, but oln/core/2d/image2d.hh. #include <oln/basics2d.hh> #include <oln/morpher/identity.hh> #include <oln/morpher/add_neighborhood.hh> -// FIXME: Fake! -// To be removed as soon as neighborhood2d is written. -namespace oln -{ - struct neighborhood2d {}; -} int main() { - typedef oln::image2d<int> image_t; + /*----------------. + | image2d<char>. | + `----------------*/ + + typedef oln::image2d<char> image_t; + // Sanity check: abstractions realized by oln::image2d. + mlc::assert_< mlc_is_a_(image_t, oln::abstract::image2d) >::check(); + mlc::assert_< mlc_is_a_(image_t, + oln::abstract::grey_level_image) >::check(); + mlc::assert_< mlc_is_a_(image_t, + oln::abstract::not_binary_image) >::check(); image_t ima (42, 51); + + /*------------------------------------. + | add_neighborhood< image2d<char> >. | + `------------------------------------*/ + typedef oln::morpher::add_neighborhood<image_t> image_with_nbh_t; - // FIXME: Using `oln_type_of_(image_t, neighborhood)' seems - // mandatory here. In fact, we cannot use oln::neighborhood2d - // directly like this - // - // oln::neighborhood2d nbh; - // - // since it confuses the compiler (g++ 4.0)! - typedef oln_type_of_(image_t, neighborhood) neighborhood_t; - neighborhood_t nbh; + // Check that the instantiated neighborhood addition morpher + // realizes the same abstraction as the underlying morphed image. + mlc::assert_< mlc_is_a_(image_with_nbh_t, oln::abstract::image2d) >::check(); + mlc::assert_< mlc_is_a_(image_with_nbh_t, + oln::abstract::image_having_neighborhood) >::check(); + // Check the type of neighborhood. + mlc::assert_< mlc_eq(oln_type_of_(image_with_nbh_t, neighborhood), + oln::neighb2d) >::check(); + + oln::neighb2d nbh; image_with_nbh_t ima_with_nbh(ima, nbh); + oln::neighb2d nbh2 = ima_with_nbh.neighborhood(); + + + /*------------------------------------------------. + | identity< add_neighborhood< image2d<char> > >. | + `------------------------------------------------*/ typedef oln::morpher::identity<image_with_nbh_t> image_with_nbh_id_t; + // Check that the instantiated identity morpher realizes the same + // abstraction as the underlying morphed image. + mlc::assert_< mlc_is_a_(image_with_nbh_id_t, + oln::abstract::image2d) >::check(); + mlc::assert_< mlc_is_a_(image_with_nbh_id_t, + oln::abstract::image_having_neighborhood) >::check(); + // Check the type of neighborhood. + mlc::assert_< mlc_eq(oln_type_of_(image_with_nbh_id_t, neighborhood), + oln::neighb2d) >::check(); image_with_nbh_id_t ima_with_nbh_id(ima_with_nbh); + oln::neighb2d nbh3 = ima_with_nbh_id.neighborhood(); } Index: tests/identity_morpher.cc --- tests/identity_morpher.cc (revision 554) +++ tests/identity_morpher.cc (working copy) @@ -27,6 +27,9 @@ /// Test the identity morpher. +#include <mlc/assert.hh> +#include <mlc/is_a.hh> + // FIXME: We should not include oln/basics2d.hh, but oln/core/2d/image2d.hh. #include <oln/basics2d.hh> #include <oln/morpher/identity.hh> @@ -34,9 +37,24 @@ int main() { - typedef oln::image2d<int> image_t; + + + typedef oln::image2d<char> image_t; + // Sanity check: abstractions realized by oln::image2d. + mlc::assert_< mlc_is_a_(image_t, oln::abstract::image2d) >::check(); + mlc::assert_< mlc_is_a_(image_t, + oln::abstract::grey_level_image) >::check(); + mlc::assert_< mlc_is_a_(image_t, + oln::abstract::not_binary_image) >::check(); image_t ima (42, 51); typedef oln::morpher::identity<image_t> image_id_t; image_id_t ima_id(ima); + // Check that the instantiated identity morpher realizes the same + // abstraction as the underlying morphed image. + mlc::assert_< mlc_is_a_(image_id_t, oln::abstract::image2d) >::check(); + mlc::assert_< mlc_is_a_(image_id_t, + oln::abstract::grey_level_image) >::check(); + mlc::assert_< mlc_is_a_(image_id_t, + oln::abstract::not_binary_image) >::check(); } Index: oln/automatic/image_having_neighborhood.hh --- oln/automatic/image_having_neighborhood.hh (revision 554) +++ oln/automatic/image_having_neighborhood.hh (working copy) @@ -29,33 +29,41 @@ # define OLENA_AUTOMATIC_IMAGE_HAVING_NEIGHBORDHOOD_HH # include <oln/core/typedefs.hh> -# include <oln/morphers/identity.hh> -# include <oln/core/abstract/image_dimension.hh> +# include <oln/morpher/tags.hh> + namespace oln { - namespace automatic + // Forward declaration. + namespace abstract { + template <typename E> class image_having_neighborhood; + + } // end of namespace oln::abstract + + namespace automatic + { /// Implementation corresponding to the interface /// oln::abstract::image1d for an identity morpher. - template <abstract::image_having_neighborhood, morpher::tag::identity, - typename E> - class impl + template <typename E> + class impl< abstract::image_having_neighborhood, + morpher::tag::identity, + E> : + public virtual abstract::image<E> { private: typedef oln_type_of(E, neighborhood) neighborhood_t; public: /// Accessor delegation. - neighborhood_t impl_neighborhood() + neighborhood_t impl_neighborhood() const { - return delegate().impl_neighborhood() - + return this->exact().delegate().impl_neighborhood(); } }; - } // end of namespace automatic + } // end of namespace oln::automatic } // end of namespace oln Index: oln/core/image_entry.hh --- oln/core/image_entry.hh (revision 554) +++ oln/core/image_entry.hh (working copy) @@ -68,7 +68,10 @@ typedef mlc::undefined concrete_type; - // morpher_type: see below. + /// \brief Morpher type. + /// + /// Optionally contains a tag indicating a kind of morpher. + typedef mlc::none morpher_type; }; @@ -92,15 +95,6 @@ typedef oln_type_of(E, value) ret; }; - /// \brief Morpher type. - /// - /// Optionally contains a tag indicating a kind of morpher. - template <typename E> - struct single_vtype< image_entry<E>, typedef_::morpher_type > - { - typedef mlc::none ret; - }; - } // end of namespace oln Index: oln/core/abstract/image_having_neighborhood.hh --- oln/core/abstract/image_having_neighborhood.hh (revision 554) +++ oln/core/abstract/image_having_neighborhood.hh (working copy) @@ -30,6 +30,9 @@ # include <oln/core/abstract/image.hh> +// Automatically-inherited implementations. +# include <oln/automatic/image_having_neighborhood.hh> + /* Image having neighborhood hierarchy (summary). @@ -52,7 +55,7 @@ namespace abstract { - /// Class of 1-D images. + /// Image having a neighborhood. template <typename E> struct image_having_neighborhood : public virtual image<E>, @@ -60,6 +63,15 @@ oln_type_of(E, morpher), E > { + private: + typedef oln_type_of(E, neighborhood) neighborhood_t; + + public: + neighborhood_t neighborhood() const + { + return this->exact().impl_neighborhood(); + } + protected: /// Constructor (protected, empty). image_having_neighborhood() {} @@ -72,29 +84,14 @@ | Dimension switch. | `-------------------*/ - /// With neig + /// With neighborhood. template <typename E> struct case_< image_hierarchy_wrt_neighborhood, E, 1 > : - where_< mlc::neq_< oln_type_of(E, neighborhood), mlc::none > > + where_< mlc::neq_< oln_type_of(E, neighborhood), mlc::not_found > > { typedef abstract::image_having_neighborhood<E> ret; }; - - /*-----------------. - | External vtype. | - `-----------------*/ - - // Forward declaration. - template <typename E> struct image_entry; - - /// Neighborhood type, as extended virtual type. - template <typename E> - struct ext_vtype < image_entry<E>, typedef_::neighborhood_type > - { - typedef mlc::none ret; - }; - } // end of namespace oln Index: oln/core/2d/image2d.hh --- oln/core/2d/image2d.hh (revision 554) +++ oln/core/2d/image2d.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2006 EPITA Research and Development Laboratory +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 EPITA Research and +// Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms Index: oln/Makefile.am --- oln/Makefile.am (revision 554) +++ oln/Makefile.am (working copy) @@ -12,6 +12,7 @@ core/2d/dpoint2d.hh \ core/2d/grid2d.hh \ core/2d/image2d.hh \ + core/2d/neighb2d.hh \ core/2d/point2d.hh \ \ core/3d/grid3d.hh \ @@ -31,6 +32,7 @@ core/abstract/image_type_integre.hh \ core/abstract/iterator.hh \ core/abstract/iterator_on_points.hh \ + core/abstract/neighborhood.hh \ core/abstract/point.hh \ core/abstract/point_set.hh \ core/abstract/point_set_being_connected.hh \ @@ -46,6 +48,7 @@ core/gen/bbox.hh \ core/gen/bbox_bkd_piter.hh \ core/gen/bbox_fwd_piter.hh \ + core/gen/neighb.hh \ core/gen/topo_bbox.hh \ \ core/internal/dpoint_nd.hh \ @@ -54,6 +57,7 @@ core/case.hh \ core/image_entry.hh \ core/macros.hh \ + core/neighborhood_entry.hh \ core/point_set_entry.hh \ core/traits.hh \ core/traits_id.hh \ Index: oln/morpher/identity.hh --- oln/morpher/identity.hh (revision 554) +++ oln/morpher/identity.hh (working copy) @@ -29,6 +29,7 @@ # define OLENA_MORPHER_IDENTITY # include <oln/morpher/internal/image_extension.hh> +# include <oln/morpher/tags.hh> namespace oln @@ -37,16 +38,7 @@ namespace morpher { // Forward declaration. - template <typename Image> - struct identity; - - - namespace tag - { - /// Tag associated to oln::morpher::identity. - struct identity; - - } // end of namespace oln::morpher::tag + template <typename Image> struct identity; } // end of namespace oln::morpher @@ -63,9 +55,9 @@ /// New virtual types associated with oln::morpher::identity. /// \{ template <typename Image> - struct single_vtype < morpher::identity<Image>, typedef_::morpher_type > + struct vtypes< morpher::identity<Image> > { - typedef oln::morpher::tag::identity ret; + typedef oln::morpher::tag::identity morpher_type; }; /// \} Index: oln/morpher/internal/image_extension.hh --- oln/morpher/internal/image_extension.hh (revision 554) +++ oln/morpher/internal/image_extension.hh (working copy) @@ -40,7 +40,7 @@ // Forward declaration. template <typename Image, typename Exact> - struct image_extension; + class image_extension; } // end of namespace oln::morpher::internal @@ -52,8 +52,8 @@ /// oln::morpher::internal::image_extension to the morphed \a Image, /// so as to get all its virtual types. template <typename Image, typename Exact> - struct set_pseudosuper_type< morpher::internal::image_extension<Image, - Exact> > + struct + set_pseudosuper_type< morpher::internal::image_extension<Image, Exact> > { typedef Image ret; }; @@ -66,8 +66,7 @@ /// Image_Extension morpher. template <typename Image, typename Exact> - class image_extension : - public oln::image_entry< image_extension<Image, Exact> > + class image_extension : public oln::image_entry<Exact> { private: typedef image_extension<Image, Exact> self_t; Index: oln/morpher/tags.hh --- oln/morpher/tags.hh (revision 0) +++ oln/morpher/tags.hh (revision 0) @@ -0,0 +1,49 @@ +// Copyright (C) 2006 EPITA Research and Development Laboratory +// +// 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. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_MORPHER_TAGS +# define OLENA_MORPHER_TAGS + + +namespace oln +{ + namespace morpher + { + namespace tag + { + /// Tag associated to oln::morpher::identity. + struct identity; + /// Tag associated to oln::morpher::add_neighborhood. + struct add_neighborhood; + + } // end of namespace oln::morpher::tag + + } // end of namespace oln::morpher + +} // end of namespace oln + +#endif // ! OLENA_MORPHER_TAGS Index: oln/morpher/add_neighborhood.hh --- oln/morpher/add_neighborhood.hh (revision 554) +++ oln/morpher/add_neighborhood.hh (working copy) @@ -29,6 +29,8 @@ # define OLENA_MORPHER_ADD_NEIGHBORHOOD # include <oln/morpher/internal/image_extension.hh> +# include <oln/morpher/tags.hh> +# include <oln/core/2d/aliases.hh> namespace oln @@ -37,15 +39,7 @@ namespace morpher { // Forward declaration. - template <typename Image> - struct add_neighborhood; - - namespace tag - { - /// Tag associated to oln::morpher::add_neighborhood. - struct add_neighborhood; - - } // end of namespace oln::morpher::tag + template <typename Image> struct add_neighborhood; } // end of namespace oln::morpher @@ -58,16 +52,17 @@ typedef morpher::internal::image_extension<Image, self_t> ret; }; - - /// New virtual types associated with oln::morpher::add_neighborhood. - /// \{ template <typename Image> - struct single_vtype < morpher::add_neighborhood<Image>, - typedef_::morpher_type > + struct vtypes< morpher::add_neighborhood<Image> > { - typedef oln::morpher::tag::add_neighborhood ret; + // Morpher type. + typedef oln::morpher::tag::add_neighborhood morpher_type; + + // Neighborhood type. + typedef + mlc_if( mlc_is_a_(Image, abstract::image2d), neighb2d, mlc::none ) + neighborhood_type; }; - /// \} namespace morpher @@ -79,7 +74,10 @@ private: typedef add_neighborhood<Image> self_t; typedef stc_get_nth_super(self_t, 1) super_t; - typedef oln_type_of(Image, neighborhood) neighborhood_t; + // FIXME: This should be replaced by a call to a new version of + // `oln_type_of', (named, for instance, `oln_check_type_of' or + // `oln_type_of_defined_'). Do the necessary changes in Static. + typedef oln_type_of(self_t, neighborhood) neighborhood_t; public: // FIXME: Handle the constness. @@ -102,29 +100,4 @@ } // end of namespace oln -// FIXME: This is probably not the right place for this. -// Where should we move this? -#include <oln/core/abstract/image.hh> -namespace oln -{ - /// Neighborhood-related definitions. - /// \{ - // Forward declarations. - template <typename T> struct image2d; - struct neighborhood2d; - namespace morpher { - template <typename Image> struct add_neighborhood; - } - - // External vtype. - template <typename T> - struct ext_vtype < morpher::add_neighborhood< oln::image2d<T> >, - typedef_::neighborhood_type > - { - typedef neighborhood2d ret; - }; - /// \} -} - - #endif // ! OLENA_MORPHER_ADD_NEIGHBORHOOD

Roland Levillain a écrit :
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr>
Fix the identity and neighborhood addition morphers.
[...] Unfortunately, this patch temporarily (hopefully) breaks the compatibility with g++ 3.4 and g++ 4.0. :( The only compilers able to compile the tests on morphers are g++ 4.1 and g++ 4.2 (from Debian's gcc-snapshot package). I'll try to fix this and bug-report to Debian and/or the GCC Team.
participants (1)
-
Roland Levillain