Commit 507b4bda authored by Roland Levillain's avatar Roland Levillain
Browse files

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.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@555 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 3034fd5d
2006-09-20 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.
2006-09-20 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr>
Add classes for classical 2d neighborhood.
* oln/core/neighborhood_entry.hh: New.
* oln/core/abstract/neighborhood.hh: New.
* oln/core/2d/neighb2d.hh: New.
* oln/core/gen/neighb.hh: New.
* oln/core/2d/aliases.hh (neighb2d): New.
* oln/basics2d.hh: Update.
2006-09-18 Roland Levillain <roland@lrde.epita.fr>
Add the first two morphers: identity and neighborhood addition.
......
......@@ -12,6 +12,7 @@ nobase_oln_HEADERS = \
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 @@ nobase_oln_HEADERS = \
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 @@ nobase_oln_HEADERS = \
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 @@ nobase_oln_HEADERS = \
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 \
......
......@@ -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
......
// 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
......
......@@ -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 oln
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 @@ namespace oln
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 @@ namespace oln
| 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
......
......@@ -68,7 +68,10 @@ namespace oln
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 @@ namespace oln
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
......
......@@ -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 oln
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 @@ namespace oln
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 @@ namespace oln
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 @@ namespace oln
} // 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
......@@ -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 oln
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 @@ namespace oln
/// 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;
};
/// \}
......
......@@ -40,7 +40,7 @@ namespace oln
// Forward declaration.
template <typename Image, typename Exact>
struct image_extension;
class image_extension;
} // end of namespace oln::morpher::internal
......@@ -52,8 +52,8 @@ namespace oln
/// 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 @@ namespace oln
/// 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;
......
// 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
......@@ -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;
image_t ima (42, 51);
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();
}
......@@ -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;
image_t ima (42, 51);
/*----------------.
| 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();
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment