536: Use the new entry/hierarchy system for images.

https://svn.lrde.epita.fr/svn/oln/trunk/olena I wonder whether stc/entry.hh is useful now; maybe we could get rid of it, or (better, IMHO) generalize olena/core/entry.hh, and make it the new stc/entry.hh? Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Use the new entry/hierarchy system for images. * oln/core/abstract/image_entry.hh: Remove. * oln/core/abstract/image_hierarchies.hh: New. * oln/core/abstract/image.hh (oln/core/abstract/image_hierarchies.hh): Include it. * oln/core/image_entry.hh: Aesthetic change. * oln/core/abstract/image_dimension.hh: Update the documentation. (oln::ERROR::UNKNOWN_GRID_TYPE): Remove error message. (oln::grid_dim_tag): Remove tag. (stc::set_entry_node<I, oln::abstract::dimension_tag>): Remove switch. (case_<grid_dim_tag, grid_type, 1>) (case_<grid_dim_tag, grid_type, 2>) (case_<grid_dim_tag, grid_type, 3>): Update and rename as... (case_<image_dimension_hierarchy, E, 1>) (case_<image_dimension_hierarchy, E, 2>) (case_<image_dimension_hierarchy, E, 3>): ...this. (default_case_<grid_dim_tag, grid_type>): Remove. (oln::ext_vtype<abstract::image<I>, typedef_::image_dimension_type>): Remove external vtype. * oln/core/abstract/image_typeness.hh: Rename as... * oln/core/abstract/image_type.hh: ...this. Adjust header guards. Update the documentation. (oln::value_type_tag): Remove tag. (stc::set_entry_node<I, oln::abstract::typeness_tag>): Remove switch. (case_<value_type_tag, value_type, 1>) (case_<value_type_tag, value_type, 2>) (default_case_<value_type_tag, value_type>): Update and rename as... (case_<image_type_hierarchy, E, 1>) (case_<image_type_hierarchy, E, 2>) (default_case_<image_type_hierarchy, E>): ...this. No longer provide an `image_typeness_type' typedef. (oln::ext_vtype<abstract::image<I>, typedef_::image_typeness_type>): Remove external vtype. * oln/core/abstract/image_typeness_integre.hh: Rename as... * oln/core/abstract/image_type_integre.hh: ...this. Adjust header guards. (case_<value_type_tag, value_type, 3>) (case_<value_type_tag, value_type, 4>) (case_<value_type_tag, value_type, 5>) (case_<value_type_tag, value_type, 6>): Update and rename as... (case_<image_type_hierarchy, E, 3>) (case_<image_type_hierarchy, E, 4>) (case_<image_type_hierarchy, E, 5>) (case_<image_type_hierarchy, E, 6>): ...this. No longer provide an `image_typeness_type' typedef. * tests/image_entry.cc (my::image): Set oln::image_entry<my::image> as super type. (oln::vtypes<my::image>::psite_type) (oln::vtypes<my::image>::rvalue_type) (oln::vtypes<my::image>::piter_type): Remove these typedefs, as they are already defined as single typedefs in oln/core/image_entry.hh. (my::image::grid_type, my::image::value_type): Rename as... (my::image::grid_t, my::image::value_t): ...this. (my::image::image_dimension_type, my::image::image_typeness_type): Remove. (main): Adjust, and remove irrelevant assertions. oln/core/abstract/image.hh | 2 oln/core/abstract/image_dimension.hh | 115 +++++-------------------------- oln/core/abstract/image_hierarchies.hh | 57 +++++++++++++++ oln/core/abstract/image_type.hh | 118 +++++++++----------------------- oln/core/abstract/image_type_integre.hh | 69 +++++++----------- tests/image_entry.cc | 30 ++------ 6 files changed, 149 insertions(+), 242 deletions(-) Index: tests/image_entry.cc --- tests/image_entry.cc (revision 535) +++ tests/image_entry.cc (working copy) @@ -32,7 +32,7 @@ // course. #include <oln/core/1d/grid1d.hh> -#include <oln/core/abstract/image_entry.hh> +#include <oln/core/image_entry.hh> namespace my { @@ -46,7 +46,7 @@ namespace oln { // Warning, this sugar might be removed in the future. - stc_set_super(my::image, abstract::image_entry<my::image>); + stc_set_super(my::image, oln::image_entry<my::image>); /// Virtual types associated to my::image. template<> @@ -64,10 +64,7 @@ // FIXME: Dummy values. typedef my::dummy topo_type; - typedef my::dummy psite_type; - typedef my::dummy rvalue_type; typedef my::dummy point_type; - typedef my::dummy piter_type; typedef my::dummy fwd_piter_type; typedef my::dummy bkd_piter_type; typedef my::dummy concrete_type; @@ -82,11 +79,9 @@ public: typedef image self_type; // Internal vtypes. - typedef oln_type_of_(self_type, grid) grid_type; - typedef oln_type_of_(self_type, value) value_type; - // External vtypes. - typedef oln_type_of_(self_type, image_dimension) image_dimension_type; - typedef oln_type_of_(self_type, image_typeness) image_typeness_type; + typedef oln_type_of_(self_type, grid) grid_t; + typedef oln_type_of_(self_type, value) value_t; + // FIXME: Add missing typedefs. }; } @@ -95,21 +90,12 @@ main() { // Check its internally defined vtypes. - mlc::assert_< mlc_eq(my::image::grid_type, oln::grid1d) >::check(); - mlc::assert_< mlc_eq(my::image::value_type, char) >::check(); - // Check its externally defined vtypes. - mlc::assert_< - mlc_eq( my::image::image_dimension_type, - stc::abstraction_as_type<oln::abstract::image1d> ) - >::check(); - mlc::assert_< - mlc_eq( my::image::image_typeness_type, - stc::abstraction_as_type<oln::abstract::grey_level_image> ) - >::check(); + mlc::assert_< mlc_eq(my::image::grid_t, oln::grid1d) >::check(); + mlc::assert_< mlc_eq(my::image::value_t, char) >::check(); // Check its image dimension abstraction. mlc::assert_< mlc_is_a_(my::image, oln::abstract::image1d) >::check(); - // Check its image ``typeness'' abstraction. + // Check its image type abstraction. mlc::assert_< mlc_is_a_(my::image, oln::abstract::grey_level_image) >::check(); Index: oln/core/image_entry.hh Index: oln/core/abstract/image.hh --- oln/core/abstract/image.hh (revision 535) +++ oln/core/abstract/image.hh (working copy) @@ -154,5 +154,7 @@ } // end of namespace oln +# include <oln/core/abstract/image_hierarchies.hh> + #endif // ! OLENA_CORE_ABSTRACT_IMAGE_HH Index: oln/core/abstract/image_type.hh --- oln/core/abstract/image_type.hh (revision 530) +++ oln/core/abstract/image_type.hh (working copy) @@ -25,15 +25,13 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLENA_CORE_ABSTRACT_IMAGE_TYPENESS_HH -# define OLENA_CORE_ABSTRACT_IMAGE_TYPENESS_HH +#ifndef OLENA_CORE_ABSTRACT_IMAGE_TYPE_HH +# define OLENA_CORE_ABSTRACT_IMAGE_TYPE_HH -# include <stc/entry.hh> # include <oln/core/abstract/image.hh> -# include <oln/core/abstract/image_abstractions.hh> -/* Image ``typeness'' hierarchy (summary). +/* Image ``type'' hierarchy (summary). /image<I>/ @@ -48,7 +46,7 @@ | | | ^ | | | | | | | | | | ,---------------------------------------------------------------------. - | The selection of the super classe(s) is made according to the value | + | The selection of the super class(es) is made according to the value | | of type_of(I, value). | `---------------------------------------------------------------------' | | | | | | | @@ -56,21 +54,27 @@ o | - stc::set_entry_node<I, typeness_tag> - (image typeness selector) + /switch_<image_dimension_type, I>::ret/ + (image type selector) ^ | - /image_entry<I>/ + /entry<abstract::image, I>/ + ^ + | + image_entry<I> ^ | I (a concrete image) -*/ -/*------------------------. -| Typeness abstractions. | -`------------------------*/ + Default case: If no known value type is returned by `oln_type_of(I, value)', + the entry is plugged to abstract::data_image<I>. */ + + +/*--------------------. +| Type abstractions. | +`--------------------*/ namespace oln { @@ -212,28 +216,9 @@ } // end of namespace oln -/*------------------. -| Typeness switch. | -`------------------*/ - -namespace oln -{ - /// Case tag for the dimension. - struct value_type_tag; -} - - -// Register the dimension switch/case for oln::abstract::image_entry. -namespace stc -{ - template <typename I> - struct set_entry_node<I, oln::abstract::typeness_tag> : - public oln::case_< oln::value_type_tag, oln_type_of(I, value) >::ret - ::super_type::template instantiated_with<I>::ret - { - }; -} // end of namespace stc - +/*--------------. +| Type switch. | +`--------------*/ namespace oln { @@ -246,33 +231,25 @@ // ----------------------------------------------- // /// Binary case. - template <typename value_type> - struct case_<value_type_tag, value_type, 1> : - public mlc::where_< mlc_eq(value_type, bool) > + template <typename E> + struct case_< image_type_hierarchy, E, 1 > : + where_< mlc::eq_< oln_type_of(E, value), bool > > { // Definition of the super class corresponding to this case. - typedef stc::abstraction_as_type<abstract::binary_image> super_type; - // Definition of the extended virtual type (same as the super - // class in this case). - typedef super_type image_typeness_type; + typedef abstract::binary_image<E> ret; }; /// Grey-level case. - template <typename value_type> - struct case_<value_type_tag, value_type, 2> : - public mlc::where_< - mlc::or_list_< mlc_eq(value_type, char), - mlc_eq(value_type, signed char), - mlc_eq(value_type, unsigned char) > > + template <typename E> + struct case_< image_type_hierarchy, E, 2 > : + where_< mlc::or_list_< mlc::eq_<oln_type_of(E, value), char>, + mlc::eq_<oln_type_of(E, value), signed char>, + mlc::eq_<oln_type_of(E, value), unsigned char> > > { // Definition of the super class corresponding to this case // (abstract::grey_level_image_ is the conjunction of // abstract::grey_level_image and abstract::not_binary_image). - typedef stc::abstraction_as_type<abstract::internal::grey_level_image_> - super_type; - // Definition of the extended virtual type. - typedef stc::abstraction_as_type<abstract::grey_level_image> - image_typeness_type; + typedef abstract::internal::grey_level_image_<E> ret; }; @@ -281,17 +258,13 @@ // -------------- // /// Default case: image of ``data''. - template <typename value_type> - struct default_case_<value_type_tag, value_type> + template <typename E> + struct default_case_< image_type_hierarchy, E > { // Definition of the super class corresponding to this case // (abstract::data_image_ is the conjunction of // abstract::data_image and abstract::not_binary_image). - typedef stc::abstraction_as_type<abstract::internal::data_image_> - super_type; - // Definition of the extended virtual type. - typedef stc::abstraction_as_type<abstract::data_image> - image_typeness_type; + typedef abstract::internal::data_image_<E> ret; }; /// \} @@ -299,27 +272,4 @@ } // end of namespace oln -/*---------------------------------. -| Typeness extended virtual type. | -`---------------------------------*/ - -// FIXME: Is this extended vtype really useful? -namespace oln -{ - /// Image ``typeness'' as an extended vtype of abstract::image. - template <typename I> - struct ext_vtype< abstract::image<I>, - // FIXME: Get rid of this typedef_:: qualifier. - typedef_::image_typeness_type > - { - // Use the same case as the one use in the inheritance-plugging - // mechanism above, but retrieve the extended vtype - // (image_typename_type), not the super type. - typedef - typename oln::case_< oln::value_type_tag, - oln_type_of(I, value) >::ret::image_typeness_type - ret; - }; -} - -#endif // ! OLENA_CORE_ABSTRACT_IMAGE_TYPENESS_HH +#endif // ! OLENA_CORE_ABSTRACT_IMAGE_TYPE_HH Index: oln/core/abstract/image_dimension.hh --- oln/core/abstract/image_dimension.hh (revision 535) +++ oln/core/abstract/image_dimension.hh (working copy) @@ -28,9 +28,7 @@ #ifndef OLENA_CORE_ABSTRACT_IMAGE_DIMENSION_HH # define OLENA_CORE_ABSTRACT_IMAGE_DIMENSION_HH -# include <stc/entry.hh> # include <oln/core/abstract/image.hh> -# include <oln/core/abstract/image_abstractions.hh> /* Image dimension hierarchy (summary). @@ -53,17 +51,23 @@ o | - stc::set_entry_node<I, dimension_tag> + /switch_<image_dimension_hierarchy, I>::ret/ (image dimension selector) ^ | - /image_entry<I>/ + /entry<abstract::image, I>/ + ^ + | + image_entry<I> ^ | I (a concrete image) -*/ + + Default case: If no known grid type is returned by `oln_type_of(I, grid)', + the entry is directly plugged to abstract::image<I>. */ + /*-------------------------. | Dimension abstractions. | @@ -107,118 +111,43 @@ } // end of namespace oln -/*-----------------. -| Error messages. | -`-----------------*/ - -namespace oln -{ - /// Error messages raised by static assertions. - namespace ERROR - { - - template <typename Grid> - struct UNKNOWN_GRID_TYPE; - - } // end of namespace oln::ERROR - -} // end of namespace oln - - /*-------------------. | Dimension switch. | `-------------------*/ namespace oln { - /// Case tag for the dimension. - struct grid_dim_tag; -} - - -// Register the dimension switch for oln::abstract::image_entry. -namespace stc -{ - template <typename I> - struct set_entry_node<I, oln::abstract::dimension_tag> : - public oln::switch_< oln::grid_dim_tag, oln_type_of(I, grid) >::ret - ::template instantiated_with<I>::ret - { - }; -} // end of namespace stc - - -namespace oln -{ // Forward declarations. class grid1d; class grid2d; class grid3d; - - /// Switch on on the grid dimension. - /// \{ - /// 1-D case. - template <typename grid_type> - struct case_<grid_dim_tag, grid_type, 1> : - // Test. - public mlc::where_< mlc_eq(grid_type, oln::grid1d) > + template <typename E> + struct case_< image_dimension_hierarchy, E, 1 > : + where_< mlc::eq_< oln_type_of(E, grid), oln::grid1d > > { - // Super class if test succeeds. - typedef stc::abstraction_as_type<abstract::image1d> ret; + typedef abstract::image1d<E> ret; }; /// 2-D case. - template <typename grid_type> - struct case_<grid_dim_tag, grid_type, 2> : - // Test. - public mlc::where_< mlc_eq(grid_type, oln::grid2d) > + template <typename E> + struct case_< image_dimension_hierarchy, E, 2 > : + where_< mlc::eq_< oln_type_of(E, grid), oln::grid2d > > { - // Super class if test succeeds. - typedef stc::abstraction_as_type<abstract::image2d> ret; + typedef abstract::image2d<E> ret; }; /// 3-D case. - template <typename grid_type> - struct case_<grid_dim_tag, grid_type, 3> : - // Test. - public mlc::where_< mlc_eq(grid_type, oln::grid3d) > - { - // Super class if test succeeds. - typedef stc::abstraction_as_type<abstract::image3d> ret; - }; - - /// Default case: abort when grid_type is not handled by the previous cases. - template <typename grid_type> - struct default_case_<grid_dim_tag, grid_type> + template <typename E> + struct case_< image_dimension_hierarchy, E, 3 > : + where_< mlc::eq_< oln_type_of(E, grid), oln::grid3d > > { - typedef mlc::abort_< grid_dim_tag, ERROR::UNKNOWN_GRID_TYPE<grid_type> > ret; + typedef abstract::image3d<E> ret; }; - /// \} - -} // end of namespace oln - -/*----------------------------------. -| Dimension extended virtual type. | -`----------------------------------*/ - -// FIXME: Is this extended vtype really useful? -namespace oln -{ - /// Image dimension type as an extended vtype of abstract::image. - template <typename I> - struct ext_vtype< abstract::image<I>, - // FIXME: Get rid of this typedef_:: qualifier. - typedef_::image_dimension_type > - { - // Use the same switch as the one use in the inheritance-plugging - // mechanism above. - typedef typename oln::switch_< oln::grid_dim_tag, - oln_type_of(I, grid) >::ret ret; - }; } + #endif // ! OLENA_CORE_ABSTRACT_IMAGE_DIMENSION_HH Index: oln/core/abstract/image_hierarchies.hh --- oln/core/abstract/image_hierarchies.hh (revision 0) +++ oln/core/abstract/image_hierarchies.hh (revision 0) @@ -0,0 +1,57 @@ +// 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_CORE_ABSTRACT_IMAGE_HIERARCHIES_HH +# define OLENA_CORE_ABSTRACT_IMAGE_HIERARCHIES_HH + +# include <oln/core/abstract/image.hh> + + +namespace oln +{ + + typedef hierarchy<abstract::image, 1> image_dimension_hierarchy; + typedef hierarchy<abstract::image, 2> image_type_hierarchy; + + // FIXME: To be continued. +#if 0 + typedef hierarchy<abstract::image, 3> image_value_hierarchy; + // FIXME: Rename (``rawness'' means ``crudit�'' in French...). + typedef hierarchy<abstract::image, 4> image_rawness_hierarchy; + typedef hierarchy<abstract::image, 5> image_neighborhood_hierarchy; + // ... +#endif + +} // end of namespace oln + + +# include <oln/core/abstract/image_dimension.hh> +# include <oln/core/abstract/image_type.hh> + + +#endif // ! OLENA_CORE_ABSTRACT_IMAGE_HIERARCHIES_HH + Index: oln/core/abstract/image_type_integre.hh --- oln/core/abstract/image_type_integre.hh (revision 530) +++ oln/core/abstract/image_type_integre.hh (working copy) @@ -29,10 +29,10 @@ // FIXME: Move this file into Integre? Or in a another project, // serving as a glue between Integre and Olena? -#ifndef OLENA_CORE_ABSTRACT_IMAGE_TYPENESS_INTEGRE_HH -# define OLENA_CORE_ABSTRACT_IMAGE_TYPENESS_INTEGRE_HH +#ifndef OLENA_CORE_ABSTRACT_IMAGE_TYPE_INTEGRE_HH +# define OLENA_CORE_ABSTRACT_IMAGE_TYPE_INTEGRE_HH -# include <oln/core/abstract/image_typeness.hh> +# include <oln/core/abstract/image_type.hh> // Forward declarations. @@ -77,9 +77,9 @@ } // end of namespace ntg -/*--------------------------. -| Typeness switch (cont.). | -`--------------------------*/ +/*----------------------. +| Type switch (cont.). | +`----------------------*/ namespace oln { @@ -91,72 +91,55 @@ // Cases where the value type is an Integre type. // // ----------------------------------------------- // - // (The first cases are located in oln/core/abstract/image_typeness.hh). + // (The first cases are located in oln/core/abstract/image_type.hh). /// Binary case. - template <typename value_type> - struct case_<value_type_tag, value_type, 3> : - public mlc::where_< - mlc::or_list_< mlc_eq(value_type, ntg::bin), - ntg::eq_<ntg::int_u, 1, value_type>, - ntg::eq_<ntg::int_s, 1, value_type> > > + template <typename E> + struct case_< image_type_hierarchy, E, 3 > : + where_< mlc::or_list_< mlc::eq_<oln_type_of(E, value), ntg::bin>, + ntg::eq_<ntg::int_u, 1, oln_type_of(E, value)>, + ntg::eq_<ntg::int_s, 1, oln_type_of(E, value)> > > { // Definition of the super class corresponding to this case. - typedef stc::abstraction_as_type<abstract::binary_image> super_type; - // Definition of the extended virtual type (same as the super - // class in this case). - typedef super_type image_typeness_type; + typedef abstract::binary_image<E> ret; }; /// Grey-level case. - template <typename value_type> - struct case_<value_type_tag, value_type, 4> : - public mlc::where_< mlc_is_a(value_type, ntg::real_value) > + template <typename E> + struct case_< image_type_hierarchy, E, 4 > : + where_< mlc_is_a( mlc_comma_1(oln_type_of(E, value)), ntg::real_value ) > { // Definition of the super class corresponding to this case // (abstract::grey_level_image_ is the conjunction of // abstract::grey_level_image and abstract::not_binary_image). - typedef - stc::abstraction_as_type<abstract::internal::grey_level_image_> - super_type; - // Definition of the extended virtual type. - typedef stc::abstraction_as_type<abstract::grey_level_image> - image_typeness_type; + typedef abstract::internal::grey_level_image_<E> ret; }; /// Label case. - template <typename value_type> - struct case_<value_type_tag, value_type, 5> : - public mlc::where_< mlc_is_a(value_type, ntg::enum_value) > + template <typename E> + struct case_< image_type_hierarchy, E, 5 > : + where_< mlc_is_a( mlc_comma_1(oln_type_of(E, value)), ntg::enum_value ) > { // Definition of the super class corresponding to this case // (abstract::label_image_ is the conjunction of // abstract::label_image and abstract::not_binary_image). - typedef stc::abstraction_as_type<abstract::internal::label_image_> - super_type; - // Definition of the extended virtual type. - typedef stc::abstraction_as_type<abstract::label_image> - image_typeness_type; + typedef abstract::internal::label_image_<E> ret; }; /// Color case. - template <typename value_type> - struct case_<value_type_tag, value_type, 6> : - public mlc::where_< mlc_is_a(value_type, ntg::color_value) > + template <typename E> + struct case_< image_type_hierarchy, E, 6 > : + where_< mlc_is_a( mlc_comma_1(oln_type_of(E, value)), ntg::color_value ) > { // Definition of the super class corresponding to this case // (abstract::color_image_ is the conjunction of // abstract::color_image and abstract::not_binary_image). - typedef stc::abstraction_as_type<abstract::internal::color_image_> - super_type; - // Definition of the extended virtual type. - typedef stc::abstraction_as_type<abstract::color_image> - image_typeness_type; + typedef abstract::internal::color_image_<E> ret; }; /// \} } // end of namespace oln -#endif // ! OLENA_CORE_ABSTRACT_IMAGE_TYPENESS_INTEGRE_HH +#endif // ! OLENA_CORE_ABSTRACT_IMAGE_TYPE_INTEGRE_HH
participants (1)
-
Roland Levillain