2006-09-25 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Update image_extension, add_neighborhood, and some related
classes.
* oln/automatic/image.hh: New.
* oln/core/abstract/image.hh: Include oln/automatic/image.hh.
Inherit from automatic::impl.
(has): Add FIXME.
* oln/core/abstract/image_having_neighborhood.hh (neighborhood):
Change so that it relies on topo(). impl_neighborhood() is now
obsolete in image classes.
* oln/core/2d/aliases.hh (topo2d, fwd_piter2d, bkd_piter2d):
Update aliases.
* oln/basics2d.hh: Update.
* oln/core/2d/image2d.hh (topo2d, fwd_piter2d, bkd_piter2d):
Update and make them explicit.
(ctor): Add border argument with default.
(impl_op_read): Change fake code.
* oln/core/2d/neighb2d.hh: Cosmetics.
* oln/core/gen/bbox.hh: Include files for piter types.
* oln/morpher/internal/image_extension.hh (morpher_type): New.
This class thus factors this definition.
(impl_topo, impl_op_read, impl_has): Remove. These methods
are expected to be automatically fetch from top implementation
classes.
(self_t, image_t, topo_t, value_t, point_t): Remove cause obsolete.
* oln/morpher/add_neighborhood.hh (add_neighborhood): Add second
parameter Neighb.
(include, set_super_type): Update.
(neighborhood_type): Change.
(ctor): Update.
(impl_neighborhood): Remove.
(impl_topo): New.
(nbh_): Remove.
(topo_): New.
* tests/add_neighborhood_morpher.cc: Update.
* tests/morphers.cc: Update.
Index: tests/add_neighborhood_morpher.cc
===================================================================
--- tests/add_neighborhood_morpher.cc (revision 564)
+++ tests/add_neighborhood_morpher.cc (working copy)
@@ -58,7 +58,7 @@
| add_neighborhood< image2d<char> >. |
`------------------------------------*/
- typedef oln::morpher::add_neighborhood<image_t> image_with_nbh_t;
+ typedef oln::morpher::add_neighborhood<image_t, oln::neighb2d> image_with_nbh_t;
// Check that the instantiated add_neighborhood morpher realizes the
// same interfaces as the underlying morphed image.
Index: tests/morphers.cc
===================================================================
--- tests/morphers.cc (revision 564)
+++ tests/morphers.cc (working copy)
@@ -40,6 +40,8 @@
int
main()
{
+ typedef oln::neighb2d neighb_t;
+
/*----------------.
| image2d<char>. |
`----------------*/
@@ -60,7 +62,7 @@
| add_neighborhood< image2d<char> >. |
`------------------------------------*/
- typedef oln::morpher::add_neighborhood<image_t> image_with_nbh_t;
+ typedef oln::morpher::add_neighborhood<image_t, neighb_t> image_with_nbh_t;
// Check that the instantiated neighborhood addition morpher
// realizes the same abstraction as the underlying morphed image.
@@ -80,9 +82,9 @@
oln::neighb2d nbh2 = ima_with_nbh.neighborhood();
- /*------------------------------------------------.
- | identity< add_neighborhood< image2d<char> > >. |
- `------------------------------------------------*/
+ /*----------------------------------------------------------.
+ | identity< add_neighborhood< image2d<char>, neighb_t > >. |
+ `----------------------------------------------------------*/
typedef oln::morpher::identity<image_with_nbh_t> image_with_nbh_id_t;
Index: oln/automatic/image.hh
===================================================================
--- oln/automatic/image.hh (revision 0)
+++ oln/automatic/image.hh (revision 0)
@@ -0,0 +1,82 @@
+// 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_AUTOMATIC_IMAGE_HH
+# define OLENA_AUTOMATIC_IMAGE_HH
+
+# include <oln/core/typedefs.hh>
+# include <oln/morpher/tags.hh>
+
+
+namespace oln
+{
+ // Forward declaration.
+ namespace abstract
+ {
+ template <typename E> class image;
+
+ } // end of namespace oln::abstract
+
+
+ namespace automatic
+ {
+
+ /// Implementation corresponding to the interface
+ /// oln::abstract::image for an identity morpher.
+ template <typename E>
+ class impl< abstract::image,
+ morpher::tag::identity,
+ E> :
+ public virtual stc::any__simple<E>
+ {
+ private:
+
+ typedef oln_type_of(E, topo) topo_t;
+ typedef oln_type_of(E, rvalue) rvalue_t;
+ typedef oln_type_of(E, psite) psite_t;
+
+ public:
+
+ /// Delegation.
+
+ const topo_t& impl_topo() const
+ {
+ return this->exact().delegate().topo();
+ }
+
+ rvalue_t impl_op_read(const psite_t& p) const
+ {
+ return this->exact().delegate().operator()(p);
+ }
+
+ };
+
+ } // end of namespace oln::automatic
+
+} // end of namespace oln
+
+#endif // ! OLENA_AUTOMATIC_IMAGE_HH
Index: oln/core/abstract/image.hh
===================================================================
--- oln/core/abstract/image.hh (revision 564)
+++ oln/core/abstract/image.hh (working copy)
@@ -30,7 +30,7 @@
# define OLENA_CORE_ABSTRACT_IMAGE_HH
# include <oln/core/typedefs.hh>
-// # include <oln/core/abstract/internal/image_impl.hh>
+# include <oln/automatic/image.hh>
namespace oln
@@ -54,8 +54,10 @@
template <typename E>
struct image : public virtual stc::any__simple<E>,
- public virtual oln::type
- // , public internal::get_image_impl < image<E>, E >
+ public virtual oln::type,
+ public automatic::impl< image,
+ oln_type_of(E, morpher),
+ E >
{
public:
@@ -138,6 +140,8 @@
return this->exact().impl_has(p);
}
+ // FIXME: has should *not* be defined for all image classes.
+
protected:
/*! \brief Constructor (protected, empty).
Index: oln/core/abstract/image_having_neighborhood.hh
===================================================================
--- oln/core/abstract/image_having_neighborhood.hh (revision 564)
+++ oln/core/abstract/image_having_neighborhood.hh (working copy)
@@ -69,7 +69,7 @@
public:
neighborhood_t neighborhood() const
{
- return this->exact().impl_neighborhood();
+ return this->topo().neighborhood();
}
protected:
Index: oln/core/2d/aliases.hh
===================================================================
--- oln/core/2d/aliases.hh (revision 564)
+++ oln/core/2d/aliases.hh (working copy)
@@ -39,9 +39,9 @@
template <typename C> class dpoint2d_;
template <typename D> class neighb_;
template <typename P> class bbox_;
- template <typename P> class topo_bbox_;
- template <typename P> class bbox_fwd_piter_;
- template <typename P> class bbox_bkd_piter_;
+ template <typename P> class topo_lbbox_;
+ template <typename T> class fwd_piter_bbox_;
+ template <typename T> class bkd_piter_bbox_;
class grid2d;
/// \}
@@ -54,9 +54,9 @@
typedef neighb_<dpoint2d> neighb2d;
typedef bbox_<point2d> bbox2d;
- typedef bbox_fwd_piter_<point2d> fwd_piter2d;
- typedef bbox_bkd_piter_<point2d> bkd_piter2d;
- typedef topo_bbox_<point2d> topo2d;
+ typedef topo_lbbox_<point2d> topo2d;
+ typedef fwd_piter_bbox_<topo2d> fwd_piter2d;
+ typedef bkd_piter_bbox_<topo2d> bkd_piter2d;
typedef point2d_<float> point2df;
typedef dpoint2d_<float> dpoint2df;
Index: oln/core/2d/neighb2d.hh
===================================================================
--- oln/core/2d/neighb2d.hh (revision 564)
+++ oln/core/2d/neighb2d.hh (working copy)
@@ -101,4 +101,3 @@
#endif // ! OLENA_CORE_2D_NEIGHB2D_HH
-
Index: oln/core/2d/image2d.hh
===================================================================
--- oln/core/2d/image2d.hh (revision 564)
+++ oln/core/2d/image2d.hh (working copy)
@@ -43,13 +43,13 @@
template <typename T>
struct vtypes< image2d<T> >
{
- typedef topo2d topo_type;
+ typedef topo_lbbox_<point2d> topo_type;
typedef grid2d grid_type;
typedef point2d point_type;
- typedef fwd_piter2d fwd_piter_type;
- typedef bkd_piter2d bkd_piter_type;
+ typedef fwd_piter_bbox_<topo_type> fwd_piter_type;
+ typedef bkd_piter_bbox_<topo_type> bkd_piter_type;
typedef T value_type;
@@ -75,8 +75,8 @@
public:
/// Ctor.
- image2d(unsigned nrows, unsigned ncols)
- : topo_( bbox2d( point2d(0,0), point2d(nrows-1, ncols-1) ) )
+ image2d(unsigned nrows, unsigned ncols, unsigned border = 2)
+ : topo_( bbox2d( point2d(0,0), point2d(nrows-1, ncols-1)), border )
{
}
@@ -87,8 +87,9 @@
T impl_op_read(const point2d& p) const
{
- static T val_;
- return ++val_;
+ return (T)(void*)this;
+// static T val_;
+// return ++val_;
}
bool impl_has(const point2d& p) const
Index: oln/core/gen/bbox.hh
===================================================================
--- oln/core/gen/bbox.hh (revision 564)
+++ oln/core/gen/bbox.hh (working copy)
@@ -218,4 +218,8 @@
} // end of namespace oln
+# include <oln/core/gen/bbox_fwd_piter.hh>
+# include <oln/core/gen/bbox_bkd_piter.hh>
+
+
#endif // ! OLENA_CORE_GEN_BBOX_HH
Index: oln/basics2d.hh
===================================================================
--- oln/basics2d.hh (revision 564)
+++ oln/basics2d.hh (working copy)
@@ -41,14 +41,14 @@
# include <oln/core/gen/bbox.hh>
namespace oln { template class bbox_<point2d>; }
-# include <oln/core/gen/bbox_fwd_piter.hh>
-namespace oln { template class bbox_fwd_piter_<point2d>; }
+# include <oln/core/gen/topo_lbbox.hh>
+namespace oln { template class topo_lbbox_<point2d>; }
-# include <oln/core/gen/bbox_bkd_piter.hh>
-namespace oln { template class bbox_bkd_piter_<point2d>; }
+# include <oln/core/gen/fwd_piter_bbox.hh>
+namespace oln { template class fwd_piter_bbox_<topo2d>; }
-# include <oln/core/gen/topo_bbox.hh>
-namespace oln { template class topo_bbox_<point2d>; }
+# include <oln/core/gen/bkd_piter_bbox.hh>
+namespace oln { template class bkd_piter_bbox_<topo2d>; }
# include <oln/core/gen/neighb.hh>
namespace oln { template class neighb_<dpoint2d>; }
Index: oln/morpher/internal/image_extension.hh
===================================================================
--- oln/morpher/internal/image_extension.hh (revision 564)
+++ oln/morpher/internal/image_extension.hh (working copy)
@@ -57,6 +57,15 @@
typedef Image ret;
};
+
+ template <typename Image, typename Exact>
+ struct vtypes< morpher::internal::image_extension<Image, Exact> >
+ {
+ // Morpher type.
+ typedef oln::morpher::tag::identity morpher_type;
+ };
+
+
namespace morpher
{
namespace internal
@@ -66,46 +75,19 @@
template <typename Image, typename Exact>
class image_extension : public oln::image_entry<Exact>
{
- private:
- typedef image_extension<Image, Exact> self_t;
-
- /// Type of morphed image.
- typedef Image image_t;
-
- typedef oln_direct_type_of(Exact, topo) topo_t;
- typedef oln_direct_type_of(Exact, value) value_t;
- typedef oln_direct_type_of(Exact, point) point_t;
-
public:
+
// FIXME: Handle the constness.
image_extension(const Image& image) :
image_(image)
- {
- }
+ {
+ }
const Image& delegate() const
{
return image_;
}
- /// Delegations.
- /// \{
- const topo_t& impl_topo() const
- {
- return delegate()->impl_topo();
- }
-
- value_t impl_op_read(const point_t& p) const
- {
- return delegate()->impl_op_read(p);
- }
-
- bool impl_has(const point_t& p) const
- {
- return delegate()->impl_has(p);
- }
- /// \}
-
protected:
const Image& image_;
};
Index: oln/morpher/add_neighborhood.hh
===================================================================
--- oln/morpher/add_neighborhood.hh (revision 564)
+++ oln/morpher/add_neighborhood.hh (working copy)
@@ -30,7 +30,7 @@
# include <oln/morpher/internal/image_extension.hh>
# include <oln/morpher/tags.hh>
-# include <oln/core/2d/aliases.hh>
+# include <oln/core/gen/topo_add_nbh.hh>
namespace oln
@@ -39,61 +39,81 @@
namespace morpher
{
// Forward declaration.
- template <typename Image> struct add_neighborhood;
+ template <typename Image, typename Neighb> struct add_neighborhood;
} // end of namespace oln::morpher
/// Super type.
- template <typename Image>
- struct set_super_type< morpher::add_neighborhood<Image> >
+ template <typename Image, typename Neighb>
+ struct set_super_type< morpher::add_neighborhood<Image, Neighb> >
{
- typedef morpher::add_neighborhood<Image> self_t;
+ typedef morpher::add_neighborhood<Image, Neighb> self_t;
typedef morpher::internal::image_extension<Image, self_t> ret;
};
- template <typename Image>
- struct vtypes< morpher::add_neighborhood<Image> >
+ template <typename Image, typename Neighb>
+ struct vtypes< morpher::add_neighborhood<Image, Neighb> >
{
+ // Topology type.
+ typedef topo_add_nbh< oln_type_of(Image, topo), Neighb > topo_type;
+
// Morpher type.
- typedef oln::morpher::tag::add_neighborhood morpher_type;
+ typedef oln::morpher::tag::identity morpher_type;
// Neighborhood type.
- typedef
- mlc_if( mlc_is_a_(Image, abstract::image2d), neighb2d, mlc::none )
- neighborhood_type;
+ typedef Neighb neighborhood_type;
};
namespace morpher
{
/// Neighborhood addition morpher.
- template <typename Image>
- class add_neighborhood : public stc_get_supers(add_neighborhood<Image>)
+ template <typename Image, typename Neighb>
+ class add_neighborhood : public stc_get_supers(mlc_comma_1(add_neighborhood<Image,
Neighb>))
{
private:
- typedef add_neighborhood<Image> self_t;
+
+ typedef add_neighborhood<Image, Neighb> self_t;
typedef stc_get_nth_super(self_t, 1) super_t;
- typedef oln_check_type_of(self_t, neighborhood) neighborhood_t;
+ typedef oln_type_of(self_t, topo) topo_t;
public:
+
// FIXME: Handle the constness.
- add_neighborhood(const Image& image, const neighborhood_t& nbh) :
- super_t(image), nbh_(nbh)
+
+ add_neighborhood(const Image& image, const Neighb& nbh) :
+ super_t(image),
+ topo_(image.topo(), nbh)
{
+ mlc::assert_equal_<oln_type_of(Image, grid), oln_type_of(Neighb, grid)>::check();
+ // FIXME: check that Image is without a nbh
}
- neighborhood_t impl_neighborhood() const
+ const topo_t& impl_topo() const
{
- return nbh_;
+ return topo_;
}
protected:
- neighborhood_t nbh_;
+ topo_t topo_;
};
} // end of namespace oln::morpher
+
+ template <typename I, typename N>
+ morpher::add_neighborhood<I, N>
+ operator + (const abstract::image<I>& image,
+ const abstract::neighborhood<N>& nbh)
+ {
+ mlc::assert_equal_<oln_type_of(I, grid), oln_type_of(N, grid)>::check();
+ // FIXME: check that Image is without a nbh
+ morpher::add_neighborhood<I, N> tmp(image.exact(), nbh.exact());
+ return tmp;
+ }
+
+
} // end of namespace oln