2006-10-02 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add isubset image morpher and subsequent tools.
* oln/core/gen/piter_isubset.hh: New.
* oln/core/gen/topo_add_isubset.hh: New.
* oln/morpher/add_isubset.hh: New.
* oln/debug/print.hh (println): New.
* oln/core/typedefs.hh (isubset): New.
* oln/core/automatic/image_being_random_accessible.hh
(set_impl): Remove; cause error-prone.
* oln/core/abstract/image/type/hierarchy.hh
(where_): Rely on xtd_is_binary instead of an hard-coded test.
(include): Update.
* oln/core/gen/fwd_piter_bbox.hh (topo_type): new.
(topo_): Change ref into plain type so it is more secure.
* oln/core/gen/bkd_piter_bbox.hh (topo_type): new.
(topo_): Change ref into plain type so it is more secure.
* oln/core/gen/topo_add_nbh.hh (operator topo_t): New.
* oln/core/internal/topology_morpher.hh
(delegated_type): New.
Index: oln/debug/print.hh
===================================================================
--- oln/debug/print.hh (revision 596)
+++ oln/debug/print.hh (working copy)
@@ -80,6 +80,7 @@
} // end of namespace oln::debug::impl
+
/// Facade.
template <typename I>
void print(const abstract::image<I>& input, std::ostream& ostr)
@@ -88,6 +89,15 @@
}
+ /// Facade.
+ template <typename I>
+ void println(const abstract::image<I>& input, std::ostream& ostr)
+ {
+ print(input, ostr);
+ ostr << std::endl;
+ }
+
+
} // end of namespace oln::debug
} // end of namespace oln
Index: oln/core/typedefs.hh
===================================================================
--- oln/core/typedefs.hh (revision 596)
+++ oln/core/typedefs.hh (working copy)
@@ -134,6 +134,7 @@
mlc_decl_typedef(dpoint_type);
mlc_decl_typedef(neighborhood_type);
+ mlc_decl_typedef(isubset);
// --------------------------------------------------------------------
// FIXME: To be enabled later.
@@ -152,6 +153,7 @@
// mlc_decl_typedef(window_type);
// --------------------------------------------------------------------
+
// ------------------------------ //
// Extension in image_operators. //
// ------------------------------ //
Index: oln/core/automatic/image_being_random_accessible.hh
===================================================================
--- oln/core/automatic/image_being_random_accessible.hh (revision 596)
+++ oln/core/automatic/image_being_random_accessible.hh (working copy)
@@ -72,33 +72,6 @@
};
- /// Implementation corresponding to the interface
- /// oln::abstract::image_being_random_accessible for an identity morpher.
-
- template <typename E>
- class set_impl< abstract::image_being_random_accessible,
- morpher::tag::identity,
- E > :
- public virtual stc::any__simple<E>
- {
- private:
-
- typedef oln_type_of(E, point) point_t;
-
- public:
-
- bool impl_has(const point_t& p) const
- {
- return this->exact().delegate().has(p);
- }
-
- bool impl_has_large(const point_t& p) const
- {
- return this->exact().delegate().has_large(p);
- }
-
- };
-
} // end of namespace oln::automatic
} // end of namespace oln
Index: oln/core/abstract/image/type/hierarchy.hh
===================================================================
--- oln/core/abstract/image/type/hierarchy.hh (revision 596)
+++ oln/core/abstract/image/type/hierarchy.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLN_CORE_ABSTRACT_IMAGE_TYPE_HIERARCHY_HH
# define OLN_CORE_ABSTRACT_IMAGE_TYPE_HIERARCHY_HH
+# include <xtd/valtraits.hh>
# include <oln/core/abstract/image.hh>
@@ -105,7 +106,7 @@
/// Binary case.
template <typename E>
struct case_< image_hierarchy_wrt_type, E, 1 > :
- where_< mlc::eq_< oln_type_of(E, value), bool > >
+ where_< xtd_is_binary(oln_type_of(E, value)) >
{
// Definition of the super class corresponding to this case.
typedef abstract::binary_image<E> ret;
Index: oln/core/gen/piter_isubset.hh
===================================================================
--- oln/core/gen/piter_isubset.hh (revision 0)
+++ oln/core/gen/piter_isubset.hh (revision 0)
@@ -0,0 +1,141 @@
+// 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 OLN_CORE_GEN_PITER_ISUBSET_HH
+# define OLN_CORE_GEN_PITER_ISUBSET_HH
+
+# include <oln/core/abstract/topology.hh>
+# include <oln/core/abstract/iterator_on_points.hh>
+
+
+namespace oln
+{
+
+
+ // Forward declaration.
+ template <typename piter_t, typename isubset_t> class piter_isubset_;
+
+
+ // Super type declaration.
+ template <typename piter_t, typename isubset_t>
+ struct set_super_type< piter_isubset_<piter_t, isubset_t> >
+ {
+ typedef piter_isubset_<piter_t, isubset_t> self_t;
+ typedef abstract::iterator_on_points<self_t> ret;
+ };
+
+
+ /// Virtual types associated to oln::piter_isubset_<piter_t, isubset_t>.
+ template <typename piter_t, typename isubset_t>
+ struct vtypes< piter_isubset_<piter_t, isubset_t> >
+ {
+ typedef oln_type_of(piter_t, point) point_type;
+ typedef oln_type_of(piter_t, grid) grid_type;
+
+ typedef topo_add_isubset<oln_type_of(piter_t, topo), isubset_t> topo_type;
+ };
+
+
+
+ /// Abstract forward point iterator class.
+ template <typename piter_t, typename isubset_t>
+ class piter_isubset_ : public abstract::iterator_on_points<
piter_isubset_<piter_t, isubset_t> >
+ {
+ typedef piter_isubset_<piter_t, isubset_t> self_t;
+ typedef abstract::iterator_on_points<self_t> super_t;
+
+ typedef oln_type_of(self_t, point) topo_t;
+ typedef oln_type_of(piter_t, point) point_t;
+
+ public:
+
+ template <typename T>
+ piter_isubset_(const abstract::topology<T>& topo)
+ : p_(topo),
+ isubset_(topo.exact().isubset())
+ {
+ }
+
+ void impl_start()
+ {
+ p_.start();
+ while (p_.is_valid() and isubset_(p_) == false)
+ p_.next();
+ }
+
+ void impl_next()
+ {
+ do
+ p_.next();
+ while (p_.is_valid() and isubset_(p_) == false);
+ }
+
+ void impl_invalidate()
+ {
+ p_.invalidate();
+ }
+
+ bool impl_is_valid() const
+ {
+ return p_.is_valid();
+ }
+
+ point_t impl_to_point() const
+ {
+ return p_.to_point();
+ }
+
+ const point_t* impl_point_adr() const
+ {
+ return p_.point_adr();
+ }
+
+ const topo_t& topo() const
+ {
+ topo_t tmp(p_.topo(), isubset_);
+ return tmp;
+ }
+
+ template <typename new_topo_t>
+ struct change_topology_
+ {
+ typedef typename piter_t::template change_topology_<new_topo_t>::ret
new_piter_t;
+ typedef piter_isubset_<new_piter_t, isubset_t> ret;
+ };
+
+ protected:
+
+ piter_t p_;
+ const isubset_t& isubset_;
+
+ }; // end of class oln::piter_isubset_<point>
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_PITER_ISUBSET_HH
Index: oln/core/gen/topo_add_isubset.hh
===================================================================
--- oln/core/gen/topo_add_isubset.hh (revision 0)
+++ oln/core/gen/topo_add_isubset.hh (revision 0)
@@ -0,0 +1,115 @@
+// 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 OLN_CORE_GEN_TOPO_ADD_ISUBSET_HH
+# define OLN_CORE_GEN_TOPO_ADD_ISUBSET_HH
+
+# include <oln/core/internal/topology_morpher.hh>
+
+
+
+namespace oln
+{
+
+
+ // Forward declarations.
+ template <typename topo, typename isubset> class topo_add_isubset;
+
+
+ // Super type declaration.
+ template <typename topo, typename isubset>
+ struct set_super_type< topo_add_isubset<topo, isubset> >
+ {
+ typedef topo_add_isubset<topo, isubset> self_t;
+ typedef internal::topology_morpher<topo, self_t> ret;
+ };
+
+
+ /// Virtual types associated to oln::bbox_<point>.
+ template <typename topo, typename isubset>
+ struct vtypes< topo_add_isubset<topo, isubset> >
+ {
+ typedef isubset isubset_type;
+ };
+
+
+ /// Bounding box topology based on a point class.
+ template <typename topo_t, typename isubset_t>
+ class topo_add_isubset
+ : public internal::topology_morpher<topo_t, topo_add_isubset<topo_t,
isubset_t> >
+ {
+ typedef topo_add_isubset<topo_t, isubset_t> self_t;
+ typedef oln_type_of(self_t, point) point_t;
+
+ public:
+
+ topo_add_isubset()
+ {
+ }
+
+ topo_add_isubset(const topo_t& topo, const isubset_t& isubset)
+ : topo_(topo),
+ isubset_(isubset)
+ {
+ }
+
+ bool impl_has(const point_t& p) const
+ {
+ return topo_.has(p) and isubset_(p) == true;
+ }
+
+ bool impl_has_large(const point_t& p) const
+ {
+ return topo_.has(p) and isubset_(p) == true;
+ }
+
+ const topo_t& delegate() const
+ {
+ return topo_;
+ }
+
+ const isubset_t& isubset() const
+ {
+ return isubset_;
+ }
+
+ operator topo_t() const
+ {
+ return topo_;
+ }
+
+ protected:
+
+ topo_t topo_;
+ isubset_t isubset_;
+ };
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_TOPO_ADD_ISUBSET_HH
Index: oln/core/gen/fwd_piter_bbox.hh
===================================================================
--- oln/core/gen/fwd_piter_bbox.hh (revision 596)
+++ oln/core/gen/fwd_piter_bbox.hh (working copy)
@@ -56,6 +56,7 @@
{
typedef oln_type_of(topo, point) point_type;
typedef oln_type_of(topo, grid) grid_type;
+ typedef topo topo_type;
};
@@ -103,7 +104,7 @@
protected:
- const topo_t& topo_;
+ const topo_t topo_;
}; // end of class oln::fwd_piter_bbox_<point>
Index: oln/core/gen/bkd_piter_bbox.hh
===================================================================
--- oln/core/gen/bkd_piter_bbox.hh (revision 596)
+++ oln/core/gen/bkd_piter_bbox.hh (working copy)
@@ -56,6 +56,7 @@
{
typedef oln_type_of(topo, point) point_type;
typedef oln_type_of(topo, grid) grid_type;
+ typedef topo topo_type;
};
@@ -103,7 +104,7 @@
protected:
- const topo_t& topo_;
+ const topo_t topo_;
}; // end of class oln::bkd_piter_bbox_<point>
Index: oln/core/gen/topo_add_nbh.hh
===================================================================
--- oln/core/gen/topo_add_nbh.hh (revision 596)
+++ oln/core/gen/topo_add_nbh.hh (working copy)
@@ -89,6 +89,11 @@
return topo_;
}
+ operator topo_t() const
+ {
+ return topo_;
+ }
+
protected:
topo_t topo_;
Index: oln/core/internal/topology_morpher.hh
===================================================================
--- oln/core/internal/topology_morpher.hh (revision 596)
+++ oln/core/internal/topology_morpher.hh (working copy)
@@ -54,7 +54,13 @@
typedef morpher::tag::identity ret;
};
+ template <typename Topo, typename E>
+ struct single_vtype< internal::topology_morpher<Topo, E>,
typedef_::delegated_type >
+ {
+ typedef Topo ret;
+ };
+
namespace internal
{
Index: oln/morpher/add_isubset.hh
===================================================================
--- oln/morpher/add_isubset.hh (revision 0)
+++ oln/morpher/add_isubset.hh (revision 0)
@@ -0,0 +1,125 @@
+// 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 OLN_MORPHER_ADD_ISUBSET
+# define OLN_MORPHER_ADD_ISUBSET
+
+# include <oln/morpher/internal/image_extension.hh>
+# include <oln/morpher/tags.hh>
+# include <oln/core/gen/topo_add_isubset.hh>
+# include <oln/core/gen/piter_isubset.hh>
+
+
+namespace oln
+{
+
+ namespace morpher
+ {
+ // Forward declaration.
+ template <typename Image, typename Isubset> struct add_isubset;
+
+ } // end of namespace oln::morpher
+
+
+ /// Super type.
+ template <typename Image, typename Isubset>
+ struct set_super_type< morpher::add_isubset<Image, Isubset> >
+ {
+ typedef morpher::add_isubset<Image, Isubset> self_t;
+ typedef morpher::internal::image_extension<Image, self_t> ret;
+ };
+
+ template <typename Image, typename Isubset>
+ struct vtypes< morpher::add_isubset<Image, Isubset> >
+ {
+ // Topology type.
+ typedef topo_add_isubset< oln_type_of(Image, topo), Isubset > topo_type;
+
+ // Piter types.
+ typedef piter_isubset_<oln_type_of(Image, fwd_piter), Isubset> fwd_piter_type;
+ typedef piter_isubset_<oln_type_of(Image, bkd_piter), Isubset> bkd_piter_type;
+
+ // Isubset type.
+ typedef Isubset subset_type;
+ };
+
+
+ namespace morpher
+ {
+ /// Isubset addition morpher.
+ template <typename Image, typename Isubset>
+ class add_isubset : public stc_get_supers(mlc_comma_1(add_isubset<Image,
Isubset>))
+ {
+ private:
+
+ typedef add_isubset<Image, Isubset> self_t;
+ typedef stc_get_nth_super(self_t, 1) super_t;
+ typedef oln_type_of(self_t, topo) topo_t;
+
+ public:
+
+ // FIXME: Handle the constness.
+
+ add_isubset(const Image& image, const Isubset& isubset) :
+ super_t(image),
+ topo_(image.topo(), isubset)
+ {
+ mlc::assert_equal_<oln_type_of(Image, grid), oln_type_of(Isubset,
grid)>::check();
+ // FIXME: check that Image is without a isubset
+ }
+
+ const topo_t& impl_topo() const
+ {
+ return topo_;
+ }
+
+ protected:
+ topo_t topo_;
+ };
+
+ } // end of namespace oln::morpher
+
+
+ template <typename I, typename S>
+ morpher::add_isubset<I, S>
+ operator | (const abstract::image<I>& image,
+ const abstract::binary_image<S>& isubset)
+ {
+ mlc::assert_equal_<oln_type_of(I, grid), oln_type_of(S, grid)>::check();
+ // FIXME: check that Image does not have yet a subset
+ morpher::add_isubset<I, S> tmp(image.exact(), isubset.exact());
+ return tmp;
+ }
+
+ // FIXME: Register this operator.
+ // FIXME: Add mutable version.
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHER_ADD_ISUBSET