Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
April 2005
- 8 participants
- 73 discussions
Index: ChangeLog
from Nicolas Widynski <nicolas.widynski(a)lrde.epita.fr>
* oln/core/properties.hh: Change properties for neighborhood hierarchy.
* oln/core/abstract/image.hh: Add neigbh_type property.
* oln/core/abstract/image_neighbness.hh: New. Add neighborhood
hierarchy.
* oln/core/abstract/entry.hh: Add image_neighbness into hierarchy.
* oln/core/abstract/image_with_extension.hh: New. Add image with extension hierarchy.
* oln/core/gen/image_with_nbh.hh: New. Concrete image and neighborhood class.
abstract/entry.hh | 4 -
abstract/image.hh | 8 ++
abstract/image_neighbness.hh | 76 +++++++++++++++++++++++++
abstract/image_with_extension.hh | 118 +++++++++++++++++++++++++++++++++++++++
gen/image_with_nbh.hh | 110 ++++++++++++++++++++++++++++++++++++
properties.hh | 3
6 files changed, 318 insertions(+), 1 deletion(-)
Index: oln/core/properties.hh
--- oln/core/properties.hh (revision 123)
+++ oln/core/properties.hh (working copy)
@@ -55,9 +55,11 @@
{
struct data_type;
struct value_type;
+ struct neighb_type;
struct value_storage_type;
struct storage_type;
struct point_type;
+ struct image_type;
struct concrete_type;
struct dpoint_type;
struct piter_type;
@@ -70,6 +72,7 @@
struct se_type;
struct window_type;
+ struct image_neighbness_type;
struct image_constness_type;
struct image_dimension_type;
struct image_vectorialness_type;
Index: oln/core/abstract/image.hh
--- oln/core/abstract/image.hh (revision 123)
+++ oln/core/abstract/image.hh (working copy)
@@ -45,6 +45,7 @@
namespace abstract {
template <typename E> struct image;
template <typename E> struct readonly_image;
+ template <typename E> struct image_without_nbh;
}
// category
@@ -70,7 +71,10 @@
mlc_decl_prop_with_default(category::image, value_storage_type, mlc::no_type);
mlc_decl_prop_with_default(category::image, storage_type, mlc::no_type);
mlc_decl_prop_with_default(category::image, delegated_type, mlc::no_type);
+ mlc_decl_prop_with_default(category::image, neighb_type, mlc::no_type);
+
+ mlc_decl_prop_with_default(category::image, image_neighbness_type, is_a<abstract::image_without_nbh>);
mlc_decl_prop_with_default(category::image, image_constness_type, is_a<abstract::readonly_image>);
mlc_decl_prop(category::image, image_dimension_type);
mlc_decl_prop(category::image, image_vectorialness_type);
@@ -83,6 +87,7 @@
<< ", " << typeid(type).name() << ") = {"
<< " concrete_type = " << typeid(concrete_type).name()
<< " value_type = " << typeid(value_type).name()
+ << " neighb_type = " << typeid(neighb_type).name()
<< " point_type = " << typeid(point_type).name()
<< " size_type = " << typeid(size_type).name()
<< " fwd_piter_type = " << typeid(fwd_piter_type).name()
@@ -93,12 +98,14 @@
<< " image_constness_type = " << typeid(image_constness_type).name()
<< " image_dimension_type = " << typeid(image_dimension_type).name()
<< " image_vectorialness_type = " << typeid(image_vectorialness_type).name()
+ << " image_neighbness_type = " << typeid(image_neighbness_type).name()
<< " }" << std::endl;
}
};
+ mlc_register_prop(category::image, neighb_type);
mlc_register_prop(category::image, concrete_type);
mlc_register_prop(category::image, value_type);
mlc_register_prop(category::image, point_type);
@@ -113,6 +120,7 @@
mlc_register_prop(category::image, image_constness_type);
mlc_register_prop(category::image, image_dimension_type);
mlc_register_prop(category::image, image_vectorialness_type);
+ mlc_register_prop(category::image, image_neighbness_type);
Index: oln/core/abstract/image_neighbness.hh
--- oln/core/abstract/image_neighbness.hh (revision 0)
+++ oln/core/abstract/image_neighbness.hh (revision 0)
@@ -0,0 +1,76 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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_NEIGHBNESS_HH
+# define OLENA_CORE_ABSTRACT_IMAGE_NEIGHBNESS_HH
+
+# include <mlc/bool.hh>
+
+# include <ntg/basics.hh>
+
+# include <oln/core/abstract/image.hh>
+
+/*! \namespace oln
+** \brief oln namespace.
+*/
+namespace oln {
+
+ /*! \namespace oln::abstract
+ ** \brief oln::abstract namespace.
+ */
+ namespace abstract {
+
+
+ template <typename E>
+ struct image_with_nbh : public virtual image<E>
+ {
+ public:
+
+ typedef oln_type_of(E, neighb) neighb_type;
+
+ const neighb_type& nbh_get() const
+ {
+ return this->exact().impl_nbh_get();
+ }
+
+ protected:
+ image_with_nbh() {}
+ };
+
+ template <typename E>
+ struct image_without_nbh : public virtual image<E>
+ {
+ protected:
+ image_without_nbh() {}
+ };
+
+
+ } // end of namespace oln::abstract
+
+} // end of namespace oln
+
+#endif // ! OLENA_CORE_ABSTRACT_IMAGE_NEIGHBNESS_HH
Index: oln/core/abstract/entry.hh
--- oln/core/abstract/entry.hh (revision 123)
+++ oln/core/abstract/entry.hh (working copy)
@@ -31,6 +31,7 @@
# include <oln/core/abstract/image_constness.hh>
# include <oln/core/abstract/image_dimension.hh>
# include <oln/core/abstract/image_vectorialness.hh>
+# include <oln/core/abstract/image_neighbness.hh>
// FIXME: this file should move to oln/core/abstract/
@@ -70,8 +71,9 @@
// intrusive:
public oln_type_of_(E, image_constness) ::template instantiated_with<E>::ret,
public oln_type_of_(E, image_dimension) ::template instantiated_with<E>::ret,
+ public oln_type_of_(E, image_neighbness) ::template instantiated_with<E>::ret,
public oln_type_of_(E, image_vectorialness) ::template instantiated_with<E>::ret
- // ...
+ // ...
{
protected:
image_entry() {}
Index: oln/core/abstract/image_with_extension.hh
--- oln/core/abstract/image_with_extension.hh (revision 0)
+++ oln/core/abstract/image_with_extension.hh (revision 0)
@@ -0,0 +1,118 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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_WITH_EXTENSION__HH
+# define OLENA_CORE_ABSTRACT_IMAGE_WITH_EXTENSION__HH
+
+# include <oln/core/abstract/image_by_delegation.hh>
+
+
+namespace oln {
+
+
+ // fwd decl
+ namespace abstract {
+ template <typename I, typename E> struct image_with_extension_;
+ }
+
+ // category
+
+ template <typename I, typename E>
+ struct set_category< abstract::image_with_extension_<I, E> > {
+ typedef category::image ret;
+ };
+
+ // super type
+
+ template <typename I, typename E>
+ struct set_super_type < abstract::image_with_extension_<I, E> >
+ {
+ typedef abstract::image_by_delegation<I, E> ret;
+ };
+
+ // props
+
+ template <typename I, typename E>
+ struct set_props < category::image, abstract::image_with_extension_<I, E> > : public props_of<category::image>
+ {
+ typedef oln_type_of(I, concrete) concrete_type;
+ };
+
+
+ namespace abstract {
+
+ /// Mutable version of image_with_extension_.
+
+ template <typename I, typename E>
+ struct image_with_extension_ : public image_by_delegation<I, E>
+ {
+ typedef image_by_delegation<I, E> super_type;
+
+ public:
+
+ image_with_extension_ ()
+ {
+ }
+
+ image_with_extension_(abstract::image<I>& image) :
+ super_type(image)
+ {
+ }
+
+ const I& real() const
+ {
+ return this->image_.unbox();
+ }
+
+ I& real()
+ {
+ return this->image_.unbox();
+ }
+
+ ~image_with_extension_ ()
+ {
+ // FIXME : This class must check all properties
+
+// mlc_or( mlc_eq(oln_type_of(I,neighb_type), mlc::no_type),
+// mlc_eq(oln_type_of(I,neighb_type), oln_type_of(E,neighb_type))
+// )::ensure();
+
+ // if (Prop(I) != no_type)
+ // Prop(E) = Prop(I)
+ }
+
+
+ };
+
+ } // end of namespace oln::abstract
+
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_ABSTRACT_IMAGE_WITH_EXTENSION__HH
Index: oln/core/gen/image_with_nbh.hh
--- oln/core/gen/image_with_nbh.hh (revision 0)
+++ oln/core/gen/image_with_nbh.hh (revision 0)
@@ -0,0 +1,110 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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_GEN_IMAGE_WITH_NBH_HH
+# define OLENA_CORE_GEN_IMAGE_WITH_NBH_HH
+
+# include <oln/core/abstract/image_with_extension.hh>
+# include <oln/core/abstract/image.hh>
+# include <oln/core/abstract/neighborhood.hh>
+# include <oln/core/properties.hh>
+
+namespace oln {
+
+ // fwd decls
+
+ namespace internal {
+ template <typename I, typename N> struct image_with_nbh;
+ }
+
+ // category
+
+ template <typename I, typename N>
+ struct set_category< internal::image_with_nbh<I, N> > {
+ typedef category::image ret;
+ };
+
+ // super type
+
+ template <typename I, typename N>
+ struct set_super_type < internal::image_with_nbh<I, N> >
+ {
+ typedef abstract::image_with_extension_ < I, internal::image_with_nbh<I, N> > ret;
+ };
+
+ template <typename I, typename N>
+ struct set_props < category::image, internal::image_with_nbh<I, N> > : public props_of<category::image>
+ {
+ typedef is_a<abstract::image_with_nbh> image_neighbness_type;
+ typedef N neighb_type;
+ };
+
+ namespace internal
+ {
+
+ template <typename I, typename N>
+ struct image_with_nbh : public oln::abstract::image_with_extension_ < I, image_with_nbh<I, N> >
+ {
+ typedef image_with_nbh<I, N> self_type;
+ typedef oln::abstract::image_with_extension_ < I, self_type > super_type;
+
+ public:
+
+ image_with_nbh(abstract::image<I>& rhs,
+ abstract::neighborhood<N>& nbh) :
+ super_type(rhs), nbh_(nbh.exact())
+ {
+ }
+
+ const N& impl_nbh_get() const
+ {
+ return nbh_;
+ }
+
+ protected:
+ N& nbh_;
+ };
+
+ } // end of namespace oln::internal
+
+
+
+ /// the 'image_with_nbh' method for images
+
+ template <typename I, typename N>
+ internal::image_with_nbh<I, N>
+ join(abstract::image<I>& ima,
+ abstract::neighborhood<N>& nbh)
+ {
+ internal::image_with_nbh<I, N> tmp(ima, nbh);
+ return tmp;
+ }
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_GEN_IMAGE_WITH_NBH_HH
1
0
2005-04-06 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* oln/core/value_box.hh: Fix.
Index: oln/core/value_box.hh
===================================================================
--- oln/core/value_box.hh (revision 122)
+++ oln/core/value_box.hh (working copy)
@@ -29,7 +29,6 @@
# define OLENA_CORE_VALUE_BOX_HH
# include <iostream>
-
# include <oln/core/properties.hh>
@@ -79,58 +78,42 @@
typedef oln_type_of(I, point) point_type;
- /// op==
-
- bool operator==(const value_box<I>& rhs) const
- {
- return this->value() == rhs.value();
- }
-
+ /// Operator == (rhs is a value_box).
template <typename II>
bool operator==(const value_box<II>& rhs) const
{
- return this->value() < rhs.value();
+ return this->value() == rhs.value();
}
+ /// Operator == (rhs is a value).
template <typename V>
bool operator==(const V& rhs) const
{
return this->value() == rhs;
}
+ /// Operator !=.
template <typename V>
bool operator!=(const V& rhs) const
{
return ! this->operator==(rhs);
}
- /*! \brief operator <
- **
- ** Define the main comparison operator for value_box. <= >= and >
- ** are computed using integre operators \see ntg/core/global_ops.hh:138.
- */
-
- template <typename V>
- bool operator<(const V& rhs) const
- {
- return this->value() < rhs;
- }
-
+ /// Operator < (rhs is a value_box).
template <typename II>
bool operator<(const value_box<II>& rhs) const
{
return this->value() < rhs.value();
}
- /*! \brief specialized version for value_box<I>
- **
- ** FIXME: why do we need this class ???
- */
- bool operator<(const value_box<I>& rhs) const
+ /// Operator < (rhs is a value).
+ template <typename V>
+ bool operator<(const V& rhs) const
{
- return this->value() < rhs.value();
+ return this->value() < rhs;
}
+
/*! \brief op=
** FIXME:...
** \return (*this)
@@ -277,47 +260,42 @@
typedef oln_type_of(I, point) point_type;
- /// op==
- bool operator==(const value_box<const I>& rhs) const
+ /// Operator == (rhs is a value_box).
+ template <typename II>
+ bool operator==(const value_box<II>& rhs) const
{
return this->value() == rhs.value();
}
- template <typename II>
- bool operator==(const value_box<const II>& rhs) const
- {
- return this->value() < rhs.value();
- }
-
+ /// Operator == (rhs is a value).
template <typename V>
bool operator==(const V& rhs) const
{
return this->value() == rhs;
}
+ /// Operator !=.
template <typename V>
bool operator!=(const V& rhs) const
{
return ! this->operator==(rhs);
}
- template <typename V>
- bool operator<(const V& rhs) const
- {
- return this->value() < rhs;
- }
-
+ /// Operator < (rhs is a value_box).
template <typename II>
- bool operator<(const value_box<const II>& rhs) const
+ bool operator<(const value_box<II>& rhs) const
{
return this->value() < rhs.value();
}
- bool operator<(const value_box<const I>& rhs) const
+ /// Operator < (rhs is a value).
+ template <typename V>
+ bool operator<(const V& rhs) const
{
- return this->value() < rhs.value();
+ return this->value() < rhs;
}
+
/*! \brief Assignment (op=) is declared but undefined.
*/
@@ -400,7 +378,7 @@
} // end of namespace oln
-
+/// Operator <<.
template <typename I>
std::ostream& operator<<(std::ostream& ostr, const oln::value_box<I>& vb)
{
@@ -408,5 +386,4 @@
}
-
#endif // ! OLENA_CORE_VALUE_BOX_HH
1
0
2005-04-06 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* oln/core/abstract/image_vectorialness.hh: Conform to mlc.
Index: oln/core/abstract/image_vectorialness.hh
===================================================================
--- oln/core/abstract/image_vectorialness.hh (revision 121)
+++ oln/core/abstract/image_vectorialness.hh (working copy)
@@ -93,19 +93,19 @@
{
typedef typename mlc::bool_switch_<
- mlc::bool_case_<ntg_is_a(T, ntg::binary)::ret,
+ mlc::bool_case_<ntg_is_a(T, ntg::binary)::val,
is_a<abstract::binary_image>,
- mlc::bool_case_<ntg_is_a(T, ntg::integer)::ret,
+ mlc::bool_case_<ntg_is_a(T, ntg::integer)::val,
is_a<abstract::integer_image>,
- mlc::bool_case_<ntg_is_a(T, ntg::decimal)::ret,
+ mlc::bool_case_<ntg_is_a(T, ntg::decimal)::val,
is_a<abstract::decimal_image>,
- mlc::bool_case_<ntg_is_a(T, ntg::vectorial)::ret,
+ mlc::bool_case_<ntg_is_a(T, ntg::vectorial)::val,
is_a<abstract::vectorial_image>,
- mlc::bool_case_<ntg_is_a(T, ntg::non_vectorial)::ret,
+ mlc::bool_case_<ntg_is_a(T, ntg::non_vectorial)::val,
is_a<abstract::non_vectorial_image>,
mlc::bool_case_<true,
1
0
2005-04-06 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* mlc/int.hh: Remove (redundant with mlc/arith.hh).
* mlc/fun.hh: Add fwd decls for std::unary_function and
std::binary_function.
Index: mlc/fun.hh
===================================================================
--- mlc/fun.hh (revision 120)
+++ mlc/fun.hh (working copy)
@@ -30,6 +30,15 @@
# include <mlc/any.hh>
+
+// fwd decls
+namespace std {
+ template <class Arg, class Ret> struct unary_function;
+ template <class Arg1, class Arg2, class Ret> struct binary_function;
+}
+
+
+
namespace mlc
{
@@ -45,7 +54,7 @@
namespace abstract {
template <typename E>
- class unary_function : public mlc::any__best_memory<E>
+ class unary_function : public mlc::any<E>
{
public:
typedef E exact_type;
@@ -71,7 +80,7 @@
// FIXME: Add meta_unary_function.
template <typename E>
- class binary_function : public mlc::any__best_memory<E>
+ class binary_function : public mlc::any<E>
{
public:
typedef E exact_type;
Index: mlc/int.hh
===================================================================
--- mlc/int.hh (revision 120)
+++ mlc/int.hh (working copy)
@@ -1,62 +0,0 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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 METALIC_ARITH_HH
-# define METALIC_ARITH_HH
-
-# include <mlc/bool.hh>
-
-
-
-namespace mlc
-{
-
- namespace arith {
-
- template <typename T, T i, T j> struct eq : public value <bool, (i == j)> {};
- template <typename T, T i, T j> struct neq : public value <bool, (i != j)> {};
-
- template <typename T, T i, T j> struct less : public value <bool, (i < j)> {};
- template <typename T, T i, T j> struct leq : public value <bool, (i <= j)> {};
-
- template <typename T, T i, T j> struct greater : public value <bool, (i > j)> {};
- template <typename T, T i, T j> struct geq : public value <bool, (i >= j)> {};
-
- template <typename T, T i, T j> struct min : public value<T, (i < j ? i : j)> {};
- template <typename T, T i, T j> struct max : public value<T, (i > j ? i : j)> {};
-
- template <typename T, T i, T j, T N> struct maxN : public value<T, (i > j ?
- (i > N ? N : i) :
- (j > N ? N : j))> {};
- template <typename T, T i, T N> struct saturateN : public value<T, (i > N ? N : i)> {};
-
- } // end of namespace mlc::arith
-
-} // end of namespace mlc
-
-
-#endif // ! METALIC_ARITH_HH
1
0
2005-04-06 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* mlc/int.hh: New file.
Index: mlc/int.hh
===================================================================
--- mlc/int.hh (revision 0)
+++ mlc/int.hh (revision 0)
@@ -0,0 +1,62 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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 METALIC_ARITH_HH
+# define METALIC_ARITH_HH
+
+# include <mlc/bool.hh>
+
+
+
+namespace mlc
+{
+
+ namespace arith {
+
+ template <typename T, T i, T j> struct eq : public value <bool, (i == j)> {};
+ template <typename T, T i, T j> struct neq : public value <bool, (i != j)> {};
+
+ template <typename T, T i, T j> struct less : public value <bool, (i < j)> {};
+ template <typename T, T i, T j> struct leq : public value <bool, (i <= j)> {};
+
+ template <typename T, T i, T j> struct greater : public value <bool, (i > j)> {};
+ template <typename T, T i, T j> struct geq : public value <bool, (i >= j)> {};
+
+ template <typename T, T i, T j> struct min : public value<T, (i < j ? i : j)> {};
+ template <typename T, T i, T j> struct max : public value<T, (i > j ? i : j)> {};
+
+ template <typename T, T i, T j, T N> struct maxN : public value<T, (i > j ?
+ (i > N ? N : i) :
+ (j > N ? N : j))> {};
+ template <typename T, T i, T N> struct saturateN : public value<T, (i > N ? N : i)> {};
+
+ } // end of namespace mlc::arith
+
+} // end of namespace mlc
+
+
+#endif // ! METALIC_ARITH_HH
1
0
2005-04-06 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* ntg/real/int_s.hh: Conform to mlc.
* ntg/real/int_u.hh: Likewise.
* ntg/real/behavior.hh: Likewise.
* ntg/core/macros.hh: Likewise.
* tests/types/tests/ntg_compare_nb_comp: Likewise.
1
0
proto-1.0 118: Introduce oln::apply for binary functions and use mlc::abstract::{un,bin}ary_function
by Roland Levillain 06 Apr '05
by Roland Levillain 06 Apr '05
06 Apr '05
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0/olena
ChangeLog | 18 +++++
oln/core/apply.hh | 148 +++++++++++++++++++++++++++++-------------
tests/core/tests/apply | 54 ---------------
tests/core/tests/apply-binary | 79 ++++++++++++++++++++++
tests/core/tests/apply-unary | 87 ++++++++++++++++++++++++
5 files changed, 288 insertions(+), 98 deletions(-)
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Introduce oln::apply for binary functions.
Use mlc::abstract::unary_function and
mlc::abstract::binary_function to enforce onstraints on signatures
of applied functions.
* oln/core/apply.hh: s/apply_type/apply1_type/g.
(apply (const abstract::image<I>&)): Remove functions.
(apply2_type): New class.
(apply(const mlc::abstract::binary_function<F>&,
const abstract::image<I>&, const abstract::image<I>&)): New
function.
* tests/core/tests/apply: Adjust tests.
Rename as...
* tests/core/tests/apply-unary: ...this.
* tests/core/tests/apply-binary: New test.
Index: tests/core/tests/apply-unary
--- tests/core/tests/apply-unary (revision 0)
+++ tests/core/tests/apply-unary (revision 0)
@@ -0,0 +1,87 @@
+ // -*- C++ -*-
+#include <functional>
+#include <oln/basics2d.hh>
+#include <oln/core/apply.hh>
+#include <oln/level/fill.hh>
+#include <oln/level/compare.hh>
+#include <ntg/int.hh>
+
+
+// Fwd decl.
+struct f_mult_3;
+
+// Traits of f_mult_3.
+namespace mlc {
+ template<>
+ struct function_traits<f_mult_3>
+ {
+ typedef int argument_type;
+ typedef int result_type;
+ };
+} // end of namespace mlc
+
+struct f_mult_3 : public mlc::abstract::unary_function<f_mult_3>
+{
+ result_type
+ impl_op_paren (const argument_type& x) const
+ {
+ return 3 * x;
+ }
+};
+
+
+int
+mult_3 (int x)
+{
+ return 3 * x;
+}
+
+
+bool check()
+{
+ oln::image2d<int> ima1(10, 10);
+ oln::level::fill(ima1, 10);
+ oln::image2d<int> ima2(10, 10);
+ oln::level::fill(ima2, 30);
+ oln::image2d<int> ima3(10, 10);
+ oln::level::fill(ima3, -10);
+
+ // oln::apply, with a hand-made mlc::abstract::unary_function.
+ {
+ oln::image2d<int> ima;
+ ima = oln::apply(f_mult_3(), ima1);
+ if (oln::level::is_equal(ima, ima2))
+ return false;
+ }
+
+ // oln::apply, with a mlc::unary_function built using the helper
+ // function mlc::make_unary_fun on a classic function.
+ {
+ oln::image2d<int> ima;
+ ima = oln::apply(mlc::make_unary_fun(mult_3), ima1);
+ if (oln::level::is_equal(ima, ima2))
+ return false;
+ }
+
+ // oln::apply, with a mlc::unary_function built using the helper
+ // function mlc::make_unary_fun on a std::unary_function.
+ {
+ oln::image2d<int> ima;
+ ima = oln::apply (mlc::make_unary_fun(std::negate<int>()), ima1);
+ if (oln::level::is_equal(ima, ima3))
+ return false;
+ }
+
+ // oln::apply, with a (more complex) mlc::unary_function built using
+ // the helper function mlc::make_unary_fun on a std::unary_function.
+ {
+ oln::image2d<int> ima;
+ ima =
+ oln::apply (mlc::make_unary_fun(std::bind2nd(std::multiplies<int>(), 3)),
+ ima1);
+ if (oln::level::is_equal(ima, ima2))
+ return false;
+ }
+
+ return true;
+}
Index: tests/core/tests/apply
--- tests/core/tests/apply (revision 116)
+++ tests/core/tests/apply (working copy)
@@ -1,54 +0,0 @@
- // -*- C++ -*-
-#include <functional>
-#include <oln/basics2d.hh>
-#include <oln/core/apply.hh>
-#include <oln/level/fill.hh>
-#include <oln/level/compare.hh>
-#include <ntg/int.hh>
-
-
-bool check()
-{
- // oln::apply, with an instantiated Adaptable Unary Function.
- {
- oln::image2d<ntg::int_u8> ima1(10, 10);
- oln::level::fill(ima1, 10);
- oln::image2d<ntg::int_u8> ima2(10, 10);
- oln::level::fill(ima2, 30);
- oln::image2d<ntg::int_u8> ima;
-
- ima = oln::apply (std::bind2nd(std::multiplies<ntg::int_u8>(), 3), ima1);
- if (oln::level::is_equal(ima, ima2))
- return false;
- }
-
- // oln::apply, with a non-instantiated Adaptable Unary Function.
- {
- oln::image2d<ntg::int_s8> ima1(10, 10);
- oln::level::fill(ima1, 10);
- oln::image2d<ntg::int_s8> ima2(10, 10);
- oln::level::fill(ima2, -10);
- oln::image2d<ntg::int_s8> ima;
-
- typedef std::negate<ntg::int_s8> negate_int_s8;
- ima = oln::apply<negate_int_s8> (ima1);
- if (oln::level::is_equal(ima, ima2))
- return false;
- }
-
- // oln::apply, with a non-instantiated template Adaptable Unary
- // Function.
- {
- oln::image2d<ntg::int_s8> ima1(10, 10);
- oln::level::fill(ima1, 10);
- oln::image2d<ntg::int_s8> ima2(10, 10);
- oln::level::fill(ima2, -10);
- oln::image2d<ntg::int_s8> ima;
-
- ima = oln::apply<std::negate> (ima1);
- if (oln::level::is_equal(ima, ima2))
- return false;
- }
-
- return true;
-}
Index: tests/core/tests/apply-binary
--- tests/core/tests/apply-binary (revision 0)
+++ tests/core/tests/apply-binary (revision 0)
@@ -0,0 +1,79 @@
+ // -*- C++ -*-
+#include <functional>
+#include <oln/basics2d.hh>
+#include <oln/core/apply.hh>
+#include <oln/level/fill.hh>
+#include <oln/level/compare.hh>
+#include <ntg/int.hh>
+
+
+// Fwd decl.
+struct f_mult;
+
+// Traits of f_mult_3.
+namespace mlc {
+ template<>
+ struct function_traits<f_mult>
+ {
+ typedef int argument1_type;
+ typedef int argument2_type;
+ typedef int result_type;
+ };
+} // end of namespace mlc
+
+struct f_mult : public mlc::abstract::binary_function<f_mult>
+{
+ result_type
+ impl_op_paren (const argument1_type& x, const argument1_type& y) const
+ {
+ return x * y;
+ }
+};
+
+
+int
+mult (int x, int y)
+{
+ return x * y;
+}
+
+
+bool check()
+{
+ oln::image2d<int> ima1(10, 10);
+ oln::level::fill(ima1, 3);
+ oln::image2d<int> ima2(10, 10);
+ oln::level::fill(ima2, 4);
+ oln::image2d<int> ima3(10, 10);
+ oln::level::fill(ima3, 12);
+
+ // oln::apply, with a hand-made mlc::abstract::binary_function.
+ {
+ oln::image2d<int> ima;
+
+ ima = oln::apply(f_mult(), ima1, ima2);
+ if (oln::level::is_equal(ima, ima3))
+ return false;
+ }
+
+ // oln::apply, with a mlc::binary_function built using the helper
+ // function mlc::make_binary_fun on a classic function.
+ {
+ oln::image2d<int> ima;
+ ima = oln::apply(mlc::make_binary_fun(mult), ima1, ima2);
+ if (oln::level::is_equal(ima, ima3))
+ return false;
+ }
+
+ // oln::apply, with a mlc::binary_function built using the helper
+ // function mlc::make_binary_fun on a std::binary_function.
+ {
+ oln::image2d<int> ima;
+ ima =
+ oln::apply (mlc::make_binary_fun(std::multiplies<int>()), ima1, ima2);
+ if (oln::level::is_equal(ima, ima3))
+ return false;
+ }
+
+ return true;
+}
Index: oln/core/apply.hh
--- oln/core/apply.hh (revision 116)
+++ oln/core/apply.hh (working copy)
@@ -28,6 +28,8 @@
#ifndef OLENA_CORE_APPLY_HH
# define OLENA_CORE_APPLY_HH
+# include <mlc/fun.hh>
+
# include <oln/basics.hh>
# include <oln/core/abstract/op.hh>
# include <oln/core/ch_value_type.hh>
@@ -38,44 +40,45 @@
| Unary. |
`--------*/
- // fwd decl
+ // Fwd decl.
namespace impl {
- template <typename AdaptableUnaryFun, typename I> struct apply_type;
+ template <typename F, typename I>
+ struct apply1_type;
}
- // category
- template <typename AdaptableUnaryFun, typename I>
- struct set_category< impl::apply_type<AdaptableUnaryFun, I> >
+ // Category.
+ template <typename F, typename I>
+ struct set_category< impl::apply1_type<F, I> >
{
typedef category::image ret;
};
- // super_type
- template <typename AdaptableUnaryFun, typename I>
- struct set_super_type< impl::apply_type<AdaptableUnaryFun, I> >
- {
- typedef typename abstract::op<I, impl::apply_type<AdaptableUnaryFun, I> >
- ret;
+ // Super type.
+ template <typename F, typename I>
+ struct set_super_type< impl::apply1_type<F, I> >
+ {
+ typedef typename ch_value_type<I,
+ typename F::result_type>::ret output_type;
+ typedef typename abstract::op<output_type, impl::apply1_type<F, I> > ret;
};
namespace impl {
- template <typename AdaptableUnaryFun, typename I>
- struct apply_type :
+ template <typename F, typename I>
+ struct apply1_type :
public abstract::op<
- typename ch_value_type<
- I, typename AdaptableUnaryFun::result_type>::ret,
- apply_type<AdaptableUnaryFun, I> >
+ typename ch_value_type<I, typename F::result_type>::ret,
+ apply1_type<F, I> >
{
- typedef typename
- ch_value_type<I, typename AdaptableUnaryFun::result_type>::ret
+ typedef typename ch_value_type<I, typename F::result_type>::ret
output_type;
- AdaptableUnaryFun f_;
+ F f_;
box<const I> input_;
- apply_type(AdaptableUnaryFun f, const abstract::image<I>& input) :
- f_(f),
+ apply1_type(const mlc::abstract::unary_function<F>& f,
+ const abstract::image<I>& input) :
+ f_(f.exact ()),
input_(input.exact())
{
}
@@ -98,40 +101,97 @@
** Apply a function \a f to each element of \a input, the function
** is passed as a type and is instantiated.
*/
- template <class AdaptableUnaryFun, typename I>
- impl::apply_type<AdaptableUnaryFun, I>
- apply(AdaptableUnaryFun f, const abstract::image<I>& input)
+ template <typename F, typename I>
+ impl::apply1_type<F, I>
+ apply(const mlc::abstract::unary_function<F>& f,
+ const abstract::image<I>& input)
{
- impl::apply_type<AdaptableUnaryFun, I> tmp(f, input);
+ impl::apply1_type<F, I> tmp(f, input);
tmp.run();
return tmp;
}
- /*! \brief Standard unary \a apply procedure.
- **
- ** Apply a function \a f to each element of \a input, the function
- ** is passed as a type and is instantiated.
- */
- template<class AdaptableUnaryFun, class I>
- impl::apply_type<AdaptableUnaryFun, I>
- apply(const abstract::image<I>& input)
+
+ /*---------.
+ | Binary. |
+ `---------*/
+
+ // Fwd decl.
+ namespace impl {
+ template <typename F, typename I1, typename I2>
+ struct apply2_type;
+ }
+
+ // Category.
+ template <typename F, typename I1, typename I2>
+ struct set_category< impl::apply2_type<F, I1, I2> >
{
- return apply(AdaptableUnaryFun(), input);
+ typedef category::image ret;
+ };
+
+ // Super type.
+ template <typename F, typename I1, typename I2>
+ struct set_super_type< impl::apply2_type<F, I1, I2> >
+ {
+ typedef typename ch_value_type<I1,
+ typename F::result_type>::ret output_type;
+ typedef typename abstract::op<output_type,
+ impl::apply2_type<F, I1, I2> > ret;
+ };
+
+ namespace impl {
+
+ template <typename F, typename I1, typename I2>
+ struct apply2_type :
+ public abstract::op<
+ typename ch_value_type<I1, typename F::result_type>::ret,
+ apply2_type<F, I1, I2> >
+ {
+ typedef typename ch_value_type<I1, typename F::result_type>::ret
+ output_type;
+
+ F f_;
+ box<const I1> input1_;
+ box<const I2> input2_;
+
+ apply2_type(const mlc::abstract::binary_function<F>& f,
+ const abstract::image<I1>& input1,
+ const abstract::image<I2>& input2) :
+ f_(f.exact ()),
+ input1_(input1.exact()),
+ input2_(input2.exact())
+ {
+ assertion (input1_.size() == input2_.size());
}
- /*! \brief Standard unary \a apply procedure.
+ void impl_run()
+ {
+ output_type output(input1_.size());
+ oln_type_of(I1, fwd_piter) p(input1_.size());
+ for_all(p)
+ output[p] = f_(input1_[p], input2_[p]);
+ this->image_ = output;
+ }
+ };
+
+ } // end of namespace impl
+
+
+ /*! \brief Standard binary \a apply procedure.
**
- ** Apply function \a f to each element of \a input, the function is
- ** passed as a type and is instantiated. For template functions
- ** passed as template-id, one need to instantiate the function for
- ** the type of the abstract::image.
+ ** Apply a function \a f to each pair of elements of
+ ** \a input1 x \a input2.
*/
- template<template<class> class AdaptableUnaryFun, class I>
- typename impl::apply_type<AdaptableUnaryFun<oln_type_of(I, value)>, I>
- apply(const abstract::image<I>& input)
+ template <typename F, typename I1, typename I2>
+ impl::apply2_type<F, I1, I2>
+ apply(const mlc::abstract::binary_function<F>& f,
+ const abstract::image<I1>& input1,
+ const abstract::image<I2>& input2)
{
- AdaptableUnaryFun<oln_type_of(I, value)> tmp;
- return apply(tmp, input);
+ assertion (input1.size() == input2.size());
+ impl::apply2_type<F, I1, I2> tmp(f, input1, input2);
+ tmp.run();
+ return tmp;
}
} // end of namespace oln
1
0
proto-1.0 117: Introduce Metalic abstractions for unary and binary functions
by Roland Levillain 06 Apr '05
by Roland Levillain 06 Apr '05
06 Apr '05
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0/metalic
ChangeLog | 7
mlc/fun.hh | 410 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
mlc/makefile.src | 3
3 files changed, 419 insertions(+), 1 deletion(-)
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Introduce Metalic abstractions for unary and binary functions.
* mlc/fun.hh: New file.
* mlc/makefile.src (MLC_DEP): Add fun.hh.
Index: mlc/fun.hh
--- mlc/fun.hh (revision 0)
+++ mlc/fun.hh (revision 0)
@@ -0,0 +1,410 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 METALIC_FUN_HH
+# define METALIC_FUN_HH
+
+# include <mlc/any.hh>
+
+namespace mlc
+{
+
+ // Fwd decl.
+ template <typename T>
+ struct function_traits;
+
+
+ /*---------------.
+ | Abstractions. |
+ `---------------*/
+
+ namespace abstract {
+
+ template <typename E>
+ class unary_function : public mlc::any__best_memory<E>
+ {
+ public:
+ typedef E exact_type;
+ typedef typename function_traits<exact_type>::argument_type
+ argument_type;
+ typedef typename function_traits<exact_type>::result_type
+ result_type;
+
+ public:
+ result_type
+ operator()(const argument_type& arg) const
+ {
+ // Check for "exact_type::impl_op_paren".
+ typedef
+ result_type (exact_type::*fun_type)(const argument_type&) const;
+ static fun_type fun_adr = &exact_type::impl_op_paren;
+ assert(fun_adr != 0);
+
+ return this->exact().impl_op_paren(arg);
+ }
+ };
+
+ // FIXME: Add meta_unary_function.
+
+ template <typename E>
+ class binary_function : public mlc::any__best_memory<E>
+ {
+ public:
+ typedef E exact_type;
+ typedef typename function_traits<exact_type>::argument1_type
+ argument1_type;
+ typedef typename function_traits<exact_type>::argument2_type
+ argument2_type;
+ typedef typename function_traits<exact_type>::result_type
+ result_type;
+
+ public:
+ result_type
+ operator()(const argument1_type& arg1, const argument2_type& arg2) const
+ {
+ // Check for "exact_type::impl_op_paren".
+ typedef
+ result_type (exact_type::*fun_type)(const argument1_type&,
+ const argument2_type&) const;
+ static fun_type fun_adr = &exact_type::impl_op_paren;
+ assert(fun_adr != 0);
+
+ return this->exact().impl_op_paren(arg1, arg2);
+ }
+ };
+
+ // FIXME: Add meta_binary_function.
+
+ } // end of namespace abstract
+
+
+ enum function_type
+ {
+ unknown_function_tag = 0,
+ // C-like functions.
+ classic_unary_function_tag,
+ classic_unary_function_ptr_tag,
+ classic_binary_function_tag,
+ classic_binary_function_ptr_tag,
+ // Functions deriving from the std namespace.
+ std_unary_function_tag,
+ std_binary_function_tag,
+ // Functions deriving from the oln namespace.
+ oln_unary_function_tag,
+ oln_binary_function_tag,
+ oln_meta_unary_function_tag
+ };
+
+ struct fun_info_helper
+ {
+ template <function_type t>
+ struct case_ { char dummy[t]; };
+
+ // C-like functions.
+
+ template <typename A, typename R>
+ static case_<classic_unary_function_tag> on(R (**)(A));
+
+ template <typename A, typename R>
+ static case_<classic_unary_function_ptr_tag> on(R (*)(A));
+
+ template <typename A1, typename A2, typename R>
+ static case_<classic_binary_function_tag> on(R (**)(A1, A2));
+
+ template <typename A1, typename A2, typename R>
+ static case_<classic_binary_function_ptr_tag> on(R (*)(A1, A2));
+
+ // Functions deriving from the std namespace.
+
+ template <typename A, typename R>
+ static case_<std_unary_function_tag>
+ on(const std::unary_function<A, R>*);
+
+ template <typename A1, typename A2, typename R>
+ static case_<std_binary_function_tag>
+ on(const std::binary_function<A1, A2, R>*);
+
+ // Functions deriving from the oln namespace.
+ // FIXME: To do.
+
+ static case_<unknown_function_tag> on(...);
+ };
+
+
+ /*--------------------------------.
+ | Helpers for classic functions. |
+ `--------------------------------*/
+
+ template <typename A>
+ struct get_result;
+
+ template <typename A, typename R>
+ struct get_result <R (*)(A)> { typedef R ret; };
+
+ template <typename A1, typename A2, typename R>
+ struct get_result <R (*)(A1,A2)> { typedef R ret; };
+
+
+ template <typename A>
+ struct get_argument;
+
+ template <typename A, typename R>
+ struct get_argument <R (*)(A)> { typedef A ret; };
+
+
+ template <typename A>
+ struct get_argument1;
+
+ template <typename A1, typename A2, typename R>
+ struct get_argument1 <R (*)(A1, A2)> { typedef A1 ret; };
+
+
+ template <typename A>
+ struct get_argument2;
+
+ template <typename A1, typename A2, typename R>
+ struct get_argument2 <R (*)(A1, A2)> { typedef A2 ret; };
+
+
+ /*-----------------------.
+ | Function information. |
+ `-----------------------*/
+
+ // Create a static pointer on type T.
+ template <typename T>
+ struct make
+ {
+ static T* ptr();
+ };
+
+
+ // Information on result type and argument type(s).
+ template <typename F, typename T, unsigned>
+ struct fun_info;
+
+ // R (*)(A).
+ template <typename F, typename T>
+ struct fun_info <F, T, classic_unary_function_tag>
+ {
+ typedef typename get_argument<F>::ret argument_type;
+ typedef typename get_result<F>::ret result_type;
+ };
+
+ // R (**)(A).
+ template <typename F, typename T>
+ struct fun_info <F, T, classic_unary_function_ptr_tag>
+ {
+ typedef typename get_argument<F*>::ret argument_type;
+ typedef typename get_result<F*>::ret result_type;
+ };
+
+ // R (*)(A1, A2).
+ template <typename F, typename T>
+ struct fun_info <F, T, classic_binary_function_tag>
+ {
+ typedef typename get_argument1<F>::ret argument1_type;
+ typedef typename get_argument2<F>::ret argument2_type;
+ typedef typename get_result<F>::ret result_type;
+ };
+
+ // R (**)(A1, A2).
+ template <typename F, typename T>
+ struct fun_info <F, T, classic_binary_function_ptr_tag>
+ {
+ typedef typename get_argument1<F*>::ret argument1_type;
+ typedef typename get_argument2<F*>::ret argument2_type;
+ typedef typename get_result<F*>::ret result_type;
+ };
+
+ // std::unary_function<A, R>
+ template <typename F, typename T>
+ struct fun_info <F, T, std_unary_function_tag>
+ {
+ typedef typename F::argument_type argument_type;
+ typedef typename F::result_type result_type;
+ };
+
+ // std::binary_function<A1, A2, R>
+ template <typename F, typename T>
+ struct fun_info <F, T, std_binary_function_tag>
+ {
+ typedef typename F::first_argument_type argument1_type;
+ typedef typename F::second_argument_type argument2_type;
+ typedef typename F::result_type result_type;
+ };
+
+ // FIXME: To be re-enabled later.
+# if 0
+ // oln::unary_function<E>
+ template <typename F, typename T>
+ struct fun_info <F, T, oln_unary_function_tag>
+ {
+ typedef oln_result_type(F) result_type;
+ };
+
+ // oln::binary_function<E>
+ template <typename F, typename T>
+ struct fun_info <F, T, oln_binary_function_tag>
+ {
+ typedef oln_result_type(F) result_type;
+ };
+
+ // oln::meta_unary_function<E>
+ template <typename F, typename T>
+ struct fun_info <F, T, oln_meta_unary_function_tag>
+ {
+ typedef oln_result_type_from(F,T) result_type;
+ };
+# endif
+
+
+ /*-------------------------------------.
+ | Unary functions, with their traits. |
+ `-------------------------------------*/
+
+ // Fwd decl.
+ template <typename F>
+ class unary_function;
+
+ template <typename F>
+ struct function_traits< unary_function <F> >
+ {
+ static const int case_id = sizeof(fun_info_helper::on(make<F>::ptr()));
+ typedef typename fun_info<F, void, case_id>::argument_type argument_type;
+ typedef typename fun_info<F, void, case_id>::result_type result_type;
+ };
+
+ template <typename F>
+ class unary_function :
+ public mlc::abstract::unary_function< unary_function<F> >
+ {
+ public:
+ typedef unary_function<F> self_type;
+ typedef abstract::unary_function< unary_function<F> > super_type;
+
+ typedef typename function_traits<self_type>::argument_type argument_type;
+ typedef typename function_traits<self_type>::result_type result_type;
+
+ public:
+ unary_function(F f) : super_type(), f_(f)
+ {
+ }
+
+ result_type
+ impl_op_paren (const argument_type& arg) const
+ {
+ return f_(arg);
+ }
+
+ private:
+ F f_;
+ };
+
+ template <typename F>
+ unary_function<F>
+ make_unary_fun(F f)
+ {
+ return unary_function<F> (f);
+ }
+
+
+ /*--------------------------------------.
+ | Binary functions, with their traits. |
+ `--------------------------------------*/
+
+ // Fwd decl.
+ template <typename F>
+ class binary_function;
+
+ template <typename F>
+ struct function_traits< binary_function <F> >
+ {
+ static const int case_id = sizeof(fun_info_helper::on(make<F>::ptr()));
+ typedef typename fun_info<F, void, case_id>::argument1_type argument1_type;
+ typedef typename fun_info<F, void, case_id>::argument2_type argument2_type;
+ typedef typename fun_info<F, void, case_id>::result_type result_type;
+ };
+
+ template <typename F>
+ class binary_function :
+ public mlc::abstract::binary_function< binary_function<F> >
+ {
+ public:
+ typedef binary_function<F> self_type;
+ typedef abstract::binary_function< binary_function<F> > super_type;
+
+ typedef typename function_traits<self_type>::argument1_type argument1_type;
+ typedef typename function_traits<self_type>::argument2_type argument2_type;
+ typedef typename function_traits<self_type>::result_type result_type;
+
+ public:
+ binary_function(F f) : super_type(), f_(f)
+ {
+ }
+
+ result_type
+ impl_op_paren (const argument1_type& arg1,
+ const argument1_type& arg2) const
+ {
+ return f_(arg1, arg2);
+ }
+
+ private:
+ F f_;
+ };
+
+ template <typename F>
+ binary_function<F>
+ make_binary_fun(F f)
+ {
+ return binary_function<F> (f);
+ }
+
+
+ /*------------------------------------------.
+ | Meta-unary functions, with their traits. |
+ `------------------------------------------*/
+
+ // FIXME: To be re-enabled later.
+# if 0
+ template <typename F>
+ struct meta_fun_info
+ {
+ template <typename T>
+ struct with
+ {
+ static const case_id = sizeof(fun_info_helper::on(make<F>::ptr()));
+ typedef typename fun_info_result_type<F, T, case_id>::ret result_type;
+ };
+ };
+#endif
+
+
+} // end of namespace mlc
+
+
+#endif // ! METALIC_FUN_HH
Index: mlc/makefile.src
--- mlc/makefile.src (revision 116)
+++ mlc/makefile.src (working copy)
@@ -1,4 +1,4 @@
-##
+## -*- Makefile -*-
## List of headers in metalic
## Include this file to have access to their name.
##
@@ -20,6 +20,7 @@
cmp.hh \
config/system.hh \
contract.hh \
+ fun.hh \
if.hh \
is_a.hh \
math.hh \
1
0
2005-04-06 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* mlc/bool.hh: Make clear that ::ret is not ::val.
* mlc/properties.hh: Likewise.
* mlc/if.hh: Likewise.
* mlc/value.hh: Likewise.
* tests/main/tests/is_a1: Likewise.
Index: tests/main/tests/is_a1
===================================================================
--- tests/main/tests/is_a1 (revision 115)
+++ tests/main/tests/is_a1 (working copy)
@@ -13,21 +13,21 @@
template <class T>
void foo()
{
- is_false<mlc_is_a(int, bool)::ret>::ensure();
- is_true<mlc_is_a(B, A)::ret>::ensure();
- is_true<mlc_is_a(C, A)::ret>::ensure();
- is_false<mlc_is_a(A, B)::ret>::ensure();
+ is_false<mlc_is_a(int, bool)::val>::ensure();
+ is_true<mlc_is_a(B, A)::val>::ensure();
+ is_true<mlc_is_a(C, A)::val>::ensure();
+ is_false<mlc_is_a(A, B)::val>::ensure();
}
int main()
{
- is_false<mlc_is_a_(int, bool)::ret>::ensure();
- is_true<mlc_is_a_(B, A)::ret>::ensure();
- is_true<mlc_is_a_(C, A)::ret>::ensure();
- is_false<mlc_is_a_(A, B)::ret>::ensure();
+ is_false<mlc_is_a_(int, bool)::val>::ensure();
+ is_true<mlc_is_a_(B, A)::val>::ensure();
+ is_true<mlc_is_a_(C, A)::val>::ensure();
+ is_false<mlc_is_a_(A, B)::val>::ensure();
- is_true<mlc_is_a_(T_B<int>, T_A)::ret>::ensure();
- is_false<mlc_is_a_(T_A<int>, T_B)::ret>::ensure();
+ is_true<mlc_is_a_(T_B<int>, T_A)::val>::ensure();
+ is_false<mlc_is_a_(T_A<int>, T_B)::val>::ensure();
foo<int>();
}
Index: mlc/bool.hh
===================================================================
--- mlc/bool.hh (revision 115)
+++ mlc/bool.hh (working copy)
@@ -34,30 +34,62 @@
namespace mlc
{
+ struct Boolean_value
+ {
+ };
- /// Specialization of mlc::value for T = bool and v = true; it provides ::ensure().
+ /// Specializations of mlc::value for T = bool; when v = true, ensure() is provided.
+
template <>
- struct value <bool, true>
+ struct value <bool, true> : public Boolean_value
{
+ static const bool b = true;
+ static const bool val = true;
static void ensure() {}
- static const bool ret = true;
- private:
- value();
+ protected:
+ value() {}
};
+ template <>
+ struct value <bool, false> : public Boolean_value
+ {
+ static const bool b = false;
+ static const bool val = false;
+ protected:
+ value() {}
+ };
+
/// Typedefs of true_type and false_type.
typedef value<bool, true> true_type;
typedef value<bool, false> false_type;
- /// Class is_true<b> (provided for bkd compability).
- template <bool b>
- struct is_true : public value<bool, b>
+ /// Classes is_true<b> and is_false<b> (provided for bkd compability).
+
+ template <bool b> struct is_true {};
+ template <> struct is_true <true> { static void ensure() {} };
+
+ template <bool b> struct is_false {};
+ template <> struct is_false <false> { static void ensure() {} };
+
+
+
+ /// Logical unary not of a Boolean type
+
+ template <typename T>
+ struct not_ : public value<bool, !T::b>
{
+ // FIXME: static assert here and below s.a. ~not_() { mlc_is_a(not_<T>, Boolean_value); }
};
+ /// Logical binary operators between a couple of Boolean types
+ template <typename L, typename R> struct and_ : public value <bool, (L::b && R::b)> {};
+ template <typename L, typename R> struct or_ : public value <bool, (L::b || R::b)> {};
+ template <typename L, typename R> struct nand_ : public value <bool, (L::b && !R::b)> {};
+ template <typename L, typename R> struct xor_ : public value <bool, ((L::b && !R::b) || (!L::b && R::b))> {};
+
} // end of namespace mlc
Index: mlc/properties.hh
===================================================================
--- mlc/properties.hh (revision 115)
+++ mlc/properties.hh (working copy)
@@ -33,6 +33,7 @@
# include <mlc/if.hh>
# include <mlc/cmp.hh>
+# include <mlc/types.hh>
Index: mlc/if.hh
===================================================================
--- mlc/if.hh (revision 115)
+++ mlc/if.hh (working copy)
@@ -38,19 +38,30 @@
namespace mlc
{
- template <typename cond_type, typename then_type, typename else_type>
- struct if_;
-
- template <typename then_type, typename else_type>
- struct if_ <true_type, then_type, else_type>
+ namespace internal
{
- typedef then_type ret;
- };
- template <typename then_type, typename else_type>
- struct if_ <false_type, then_type, else_type>
+ template <bool b, typename then_type, typename else_type>
+ struct if_;
+
+ template <typename then_type, typename else_type>
+ struct if_ <true, then_type, else_type>
+ {
+ typedef then_type ret;
+ };
+
+ template <typename then_type, typename else_type>
+ struct if_ <false, then_type, else_type>
+ {
+ typedef else_type ret;
+ };
+
+ } // end of namespace mlc::internal
+
+
+ template <typename cond_type, typename then_type, typename else_type>
+ struct if_ : public internal::if_ < cond_type::b, then_type, else_type >
{
- typedef else_type ret;
};
Index: mlc/value.hh
===================================================================
--- mlc/value.hh (revision 115)
+++ mlc/value.hh (working copy)
@@ -39,9 +39,9 @@
template <typename T, T v>
struct value
{
- static const T ret = v;
- private:
- value();
+ static const T val = v;
+ value() {}
+ operator T() const { return v; }
};
1
0
Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* oln/convert/ng_to_se.hh: Remove.
* oln/convert/nbh_to_se.hh: New.
* oln/core/abstract/internal/image_impl.hh: Add missing inclusion.
* oln/makefile.src: Commit name change for ng_to_se.hh.
* oln/morpho/reconstruction.hh: Factor code.
* oln/morpho/cc_tarjan.hh: Conform to mlc macros.
* oln/arith/min.hh: Conform to image_operator.
* oln/arith/max.hh: Conform to image_operator.
arith/max.hh | 23 -
arith/min.hh | 23 -
convert/nbh_to_se.hh | 22 -
convert/ng_to_se.hh | 88 ----
core/abstract/internal/image_impl.hh | 1
makefile.src | 2
morpho/cc_tarjan.hh | 33 -
morpho/reconstruction.hh | 650 ++++++++++++-----------------------
8 files changed, 282 insertions(+), 560 deletions(-)
Index: oln/convert/ng_to_se.hh
--- oln/convert/ng_to_se.hh (revision 114)
+++ oln/convert/ng_to_se.hh (working copy)
@@ -1,88 +0,0 @@
-// Copyright (C) 2002, 2004, 2005 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, 59 Temple Place - Suite 330, 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_CONVERT_NG_TO_SE_HH
-# define OLENA_CONVERT_NG_TO_SE_HH
-
-# include <oln/basics.hh>
-
-// because of the internal function in this file
-//# include <oln/basics1d.hh>
-# include <oln/basics2d.hh>
-//# include <oln/basics3d.hh>
-//# include <oln/core/1d/neighborhood1d.hh>
-# include <oln/core/2d/neighborhood2d.hh>
-//# include <oln/core/3d/neighborhood3d.hh>
-
-namespace oln {
- namespace convert {
- /*! Convert a neighborhood to a window.
- **
- ** \see ng_to_cse
- */
- template<class N>
- oln_type_of(N, window)
- ng_to_se(const oln::abstract::neighborhood<N>& ng)
- {
- oln_type_of(N, window) output;
-
- for (unsigned i = 0; i < ng.card(); i++)
- output.add(ng[i]);
- return output;
- }
-
- void dpoint_zero(dpoint2d& dp)
- {
- dp.row() = 0;
- dp.col() = 0;
- }
-
- /*! Convert a neighborhood to a window and add the center.
- **
- ** \see ng_to_cs
- */
- template<class N>
- oln_type_of(N, window)
- ng_to_cse(const oln::abstract::neighborhood<N>& ng)
- {
- oln_type_of(N, window) output;
-
- for (unsigned i = 0; i < ng.card(); i++)
- output.add(ng[i]);
-
- oln_type_of(N, dpoint) zero;
- dpoint_zero(zero);
- output.add(zero);
- return output;
- }
-
-
- } // convert
-} // oln
-
-
-#endif // OLENA_CONVERT_NG_TO_SE_HH
Index: oln/convert/nbh_to_se.hh
--- oln/convert/nbh_to_se.hh (revision 114)
+++ oln/convert/nbh_to_se.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLENA_CONVERT_NG_TO_SE_HH
-# define OLENA_CONVERT_NG_TO_SE_HH
+#ifndef OLENA_CONVERT_NBH_TO_SE_HH
+# define OLENA_CONVERT_NBH_TO_SE_HH
# include <oln/basics.hh>
@@ -42,16 +42,16 @@
namespace convert {
/*! Convert a neighborhood to a window.
**
- ** \see ng_to_cse
+ ** \see nbh_to_cse
*/
template<class N>
oln_type_of(N, window)
- ng_to_se(const oln::abstract::neighborhood<N>& ng)
+ nbh_to_se(const oln::abstract::neighborhood<N>& nbh)
{
oln_type_of(N, window) output;
- for (unsigned i = 0; i < ng.card(); i++)
- output.add(ng[i]);
+ for (unsigned i = 0; i < nbh.card(); i++)
+ output.add(nbh[i]);
return output;
}
@@ -63,16 +63,16 @@
/*! Convert a neighborhood to a window and add the center.
**
- ** \see ng_to_cs
+ ** \see nbh_to_cs
*/
template<class N>
oln_type_of(N, window)
- ng_to_cse(const oln::abstract::neighborhood<N>& ng)
+ nbh_to_cse(const oln::abstract::neighborhood<N>& nbh)
{
oln_type_of(N, window) output;
- for (unsigned i = 0; i < ng.card(); i++)
- output.add(ng[i]);
+ for (unsigned i = 0; i < nbh.card(); i++)
+ output.add(nbh[i]);
oln_type_of(N, dpoint) zero;
dpoint_zero(zero);
@@ -85,4 +85,4 @@
} // oln
-#endif // OLENA_CONVERT_NG_TO_SE_HH
+#endif // OLENA_CONVERT_NBH_TO_SE_HH
Index: oln/core/abstract/internal/image_impl.hh
--- oln/core/abstract/internal/image_impl.hh (revision 114)
+++ oln/core/abstract/internal/image_impl.hh (working copy)
@@ -29,6 +29,7 @@
# define PROTO_OLN_CORE_ABSTRACT_INTERNAL_IMAGE_IMPL_HH
# include <mlc/any.hh>
+# include <mlc/types.hh>
# include <oln/core/properties.hh>
Index: oln/makefile.src
--- oln/makefile.src (revision 114)
+++ oln/makefile.src (working copy)
@@ -14,7 +14,7 @@
basics3d.hh \
config/pconf.hh \
config/system.hh \
- convert/ng_to_se.hh \
+ convert/nbh_to_se.hh \
convert/value_to_point.hh \
core/1d/array1d.hh \
core/1d/dpoint1d.hh \
Index: oln/morpho/reconstruction.hh
--- oln/morpho/reconstruction.hh (revision 114)
+++ oln/morpho/reconstruction.hh (working copy)
@@ -30,15 +30,20 @@
# include <queue>
-# include <mlc/contract.hh>
# include <mlc/cmp.hh>
+# include <mlc/contract.hh>
-# include <oln/convert/ng_to_se.hh>
-# include <oln/morpho/splitse.hh>
-# include <oln/level/compare.hh>
+# include <oln/convert/nbh_to_se.hh>
+
+# include <oln/core/abstract/image_operator.hh>
# include <oln/core/abstract/neighborhood.hh>
# include <oln/core/properties.hh>
-# include <oln/core/abstract/image_operator.hh>
+
+# include <oln/level/compare.hh>
+
+# include <oln/morpho/splitse.hh>
+# include <oln/morpho/stat.hh>
+
# include <oln/utils/clone.hh>
// FIXME: ADD TESTS !!!!
@@ -73,80 +78,35 @@
{
typedef abstract::image_binary_operator<I, I, I, reconstruction_ret<I, N> > super_type;
- const N ng;
+ const N nbh;
reconstruction_ret(const abstract::non_vectorial_image<I>& input1,
const abstract::non_vectorial_image<I>& input2,
- const abstract::neighborhood<N>& ng) :
+ const abstract::neighborhood<N>& nbh) :
super_type(input1.exact(), input2.exact()),
- ng(ng.exact())
+ nbh(nbh.exact())
{}
};
namespace sequential {
- /*!
- ** \brief Perform a geodesic reconstruction dilation.
- **
- ** Compute the reconstruction by dilation of marker with respect
- ** to the mask image using se as structuring element. Soille
- ** p.160. The algorithm used is the one defined as sequential in
- ** Vincent(1993), Morphological grayscale reconstruction in
- ** image analysis: applications and efficient algorithms, itip,
- ** 2(2), 176--201.
- **
- ** \pre Mask must be greater or equal than marker.
- **
- ** \param I1 Exact type of image marker.
- ** \param I2 Exact type of image mask.
- ** \param N Exact type of neighborhood.
- **
- ** \arg marker Image to work on.
- ** \arg mask Image used for geodesic dilation.
- ** \arg Ng Neighborhood to use.
- **
- ** \code
- ** #include <oln/basics2d.hh>
- ** #include <oln/morpho/opening.hh>
- ** #include <oln/morpho/reconstruction.hh>
- ** #include <oln/level/compare.hh>
- ** #include <ntg/all.hh>
- ** int main()
- ** {
- ** typedef oln::image2d<ntg::int_u8> im_type;
- **
- ** im_type im1(oln::load(IMG_IN "lena128.pgm"));
- ** im_type im2 = oln::morpho::opening(im1, oln::win_c4p());
- **
- ** oln::save(oln::morpho::sequential::geodesic_reconstruction_dilation(im2,
- ** im1,
- ** oln::neighb_c4()),
- ** IMG_OUT "oln_morpho_sequential_geodesic_reconstruction_dilation.pbm");
- ** return 0;
- ** }
- ** \endcode
- **
- ** \image html lena128_pgm.png
- ** \image latex lena128_pgm.png
- ** =>
- ** \image html oln_morpho_sequential_geodesic_reconstruction_dilation.png
- ** \image latex oln_morpho_sequential_geodesic_reconstruction_dilation.png
- **
- */
namespace impl {
template <typename I, typename N>
- struct reconstruction_dilation_ret : public reconstruction_ret<I, N>
+ struct reconstruction_sequential_ret : public reconstruction_ret<I, N>
{
typedef reconstruction_ret<I, N> super_type;
- reconstruction_dilation_ret(const abstract::non_vectorial_image<I>& input1, //marker
- const abstract::non_vectorial_image<I>& input2, //mask
- const abstract::neighborhood<N>& ng)
- : super_type(input1, input2, ng)
- {}
+ virtual const oln_type_of(I, value) process(const I& work,
+ const oln_type_of(I, point)& p,
+ const oln_type_of(N, window)& se,
+ const oln_type_of(I, value)& v)
+ {
+ std::cerr << "oops in " << __func__ << std::endl;
+ return oln_type_of(I, value)();
+ }
void impl_run()
{
@@ -155,139 +115,153 @@
precondition(level::is_greater_or_equal(this->input2, this->input1));
// Conversion of neighborhood into a SE.
- oln_type_of(N, window) se_plus = get_plus_se_p(convert::ng_to_cse(this->ng));
- oln_type_of(N, window) se_minus = get_minus_se_p(convert::ng_to_cse(this->ng));
+ oln_type_of(N, window) se_plus = get_plus_se_p(convert::nbh_to_cse(this->nbh));
+ oln_type_of(N, window) se_minus = get_minus_se_p(convert::nbh_to_cse(this->nbh));
I output;
output = utils::clone(this->input1);
bool non_stability = true;
oln_type_of(I, fwd_piter) fwd_p(output.size());
- oln_type_of(I, fwd_piter) bkd_p(output.size());
+ oln_type_of(I, bkd_piter) bkd_p(output.size());
while (non_stability)
{
I work;
work = utils::clone(output);
for_all (fwd_p)
- work[fwd_p] = ntg::min(morpho::max(work, fwd_p, se_plus), this->input2[fwd_p].value());
+ work[fwd_p] = this->process(work, fwd_p, se_plus, this->input2[fwd_p].value());
for_all (bkd_p)
- work[bkd_p] = ntg::min(morpho::max(work, bkd_p, se_minus), this->input2[bkd_p].value());
+ work[bkd_p] = this->process(work, bkd_p, se_minus, this->input2[bkd_p].value());
+
non_stability = !(level::is_equal(work, output));
output = work;
}
this->output = output;
}
+
+ protected:
+ reconstruction_sequential_ret(const abstract::non_vectorial_image<I>& input1, //marker
+ const abstract::non_vectorial_image<I>& input2, //mask
+ const abstract::neighborhood<N>& nbh)
+ : super_type(input1, input2, nbh)
+ {}
+
+
};
+
+ template <typename I, typename N>
+ struct reconstruction_dilation_ret : public reconstruction_sequential_ret<I, N>
+ {
+ typedef reconstruction_sequential_ret<I, N> super_type;
+
+ reconstruction_dilation_ret(const abstract::non_vectorial_image<I>& input1, //marker
+ const abstract::non_vectorial_image<I>& input2, //mask
+ const abstract::neighborhood<N>& nbh)
+
+ : super_type(input1, input2, nbh)
+ {}
+
+ const oln_type_of(I, value) process(const I& work,
+ const oln_type_of(I, point)& p,
+ const oln_type_of(N, window)& se,
+ const oln_type_of(I, value)& v)
+ {
+ return ntg::min(morpho::max(work, p, se), v);
+ }
+
+ };
+
+
+ template <typename I, typename N>
+ struct reconstruction_erosion_ret : public reconstruction_sequential_ret<I, N>
+ {
+ typedef reconstruction_sequential_ret<I, N> super_type;
+
+ reconstruction_erosion_ret(const abstract::non_vectorial_image<I>& input1, //marker
+ const abstract::non_vectorial_image<I>& input2, //mask
+ const abstract::neighborhood<N>& nbh)
+
+ : super_type(input1, input2, nbh)
+ {}
+
+ const oln_type_of(I, value) process(const I& work,
+ const oln_type_of(I, point)& p,
+ const oln_type_of(N, window)& se,
+ const oln_type_of(I, value)& v) const
+ {
+ return ntg::max(morpho::min(work, p, se), v);
+ }
+ };
+
}
template<class I, class N>
reconstruction_ret<I, N>
geodesic_reconstruction_dilation(const abstract::non_vectorial_image<I> & marker,
const abstract::non_vectorial_image<I> & mask,
- const abstract::neighborhood<N>& ng)
+ const abstract::neighborhood<N>& nbh)
{
- impl::reconstruction_dilation_ret<I, N> tmp(marker, mask, ng);
+ impl::reconstruction_dilation_ret<I, N> tmp(marker, mask, nbh);
tmp.run();
return tmp;
}
+
+ template<class I, class N>
+ reconstruction_ret<I, N>
+ geodesic_reconstruction_erosion(const abstract::non_vectorial_image<I> & marker,
+ const abstract::non_vectorial_image<I> & mask,
+ const abstract::neighborhood<N>& nbh)
+ {
+ impl::reconstruction_erosion_ret<I, N> tmp(marker, mask, nbh);
+ tmp.run();
+ return tmp;
+ }
+
}// sequential
namespace hybrid {
- namespace internal {
-
- /*!
- ** \brief Check if it exists initialization for dilation.
- **
- ** \arg p Point to consider.
- ** \arg marker Image to work on.
- ** \arg mask Image used as mask.
- ** \arg Ng Neighborhood to use.
- */
- template<class P, class I1, class I2, class E> inline
- static bool
- exist_init_dilation(const abstract::point<P>& p,
- const abstract::non_vectorial_image<I1>& marker,
- const abstract::non_vectorial_image<I2>& mask,
- const abstract::struct_elt<E>& se)
- {
- oln_type_of(E, fwd_witer) dp(se.exact());
- for_all (dp)
- {
- P q = (oln_type_of(E, dpoint))dp + p.exact();
- if (marker.hold(q) && (marker[q] < marker[p.exact()]) &&
- (marker[q] < mask[q]))
- return true;
- }
- return false;
- }
-
- } //internal
-
- /*!
- ** \brief Perform a geodesic reconstruction dilation.
- **
- ** Compute the reconstruction by dilation of marker with
- ** respect to the mask image using se as structuring
- ** element. Soille p.160. The algorithm used is the one defined
- ** as hybrid in Vincent(1993), Morphological grayscale
- ** reconstruction in image analysis: applications and efficient
- ** algorithms, itip, 2(2), 176--201.
- **
- ** \pre Mask must be greater or equal than marker.
- **
- ** \param I1 Exact type of image marker.
- ** \param I2 Exact type of image mask.
- ** \param N Exact type of neighborhood.
- **
- ** \arg marker Image to work on.
- ** \arg mask Image used for geodesic dilation.
- ** \arg Ng Neighborhood to use.
- **
- ** \code
- ** #include <oln/basics2d.hh>
- ** #include <oln/morpho/opening.hh>
- ** #include <oln/morpho/reconstruction.hh>
- ** #include <oln/level/compare.hh>
- ** #include <ntg/all.hh>
- ** int main()
- ** {
- ** typedef oln::image2d<ntg::int_u8> im_type;
- **
- ** im_type im1(oln::load(IMG_IN "lena128.pgm"));
- ** im_type im2 = oln::morpho::opening(im1, oln::win_c4p());
- **
- ** oln::save(oln::morpho::hybrid::geodesic_reconstruction_dilation(im2,
- ** im1,
- ** oln::neighb_c4()),
- ** IMG_OUT "oln_morpho_hybrid_geodesic_reconstruction_dilation.pbm");
- ** return 0;
- ** }
- ** \endcode
- **
- ** \image html lena128_pgm.png
- ** \image latex lena128_pgm.png
- ** =>
- ** \image html oln_morpho_hybrid_geodesic_reconstruction_dilation.png
- ** \image latex oln_morpho_hybrid_geodesic_reconstruction_dilation.png
- **
- */
-
namespace impl {
template <typename I, typename N>
- struct reconstruction_dilation_ret : public reconstruction_ret<I, N>
+ struct reconstruction_hybrid_ret : public reconstruction_ret<I, N>
{
typedef reconstruction_ret<I, N> super_type;
- reconstruction_dilation_ret(const abstract::non_vectorial_image<I>& input1, //marker
- const abstract::non_vectorial_image<I>& input2, //mask
- const abstract::neighborhood<N>& ng)
+ reconstruction_hybrid_ret(const abstract::non_vectorial_image<I>& input1, //marker
+ const abstract::non_vectorial_image<I>& input2, //mask
+ const abstract::neighborhood<N>& nbh)
- : super_type(input1, input2, ng)
+ : super_type(input1, input2, nbh)
{}
+ virtual const oln_type_of(I, value) process(const I& work,
+ const oln_type_of(I, point)& p,
+ const oln_type_of(N, window)& se,
+ const oln_type_of(I, value)& v) const
+ {
+ std::cerr << "oops in " << __func__ << std::endl;
+ return oln_type_of(I, value)();
+ }
+
+ virtual void loop_body(const oln_type_of(I, point)& p,
+ const oln_type_of(I, point)& q,
+ oln_type_of(I, concrete)& output,
+ std::queue<oln_type_of(I, point) >& fifo)
+ {
+ std::cerr << "oops in " << __func__ << std::endl;
+ }
+
+ virtual bool exist_init(const oln_type_of(I, point)& p,
+ const oln_type_of(I, concrete)& output,
+ const oln_type_of(N, window)& se) const
+ {
+ std::cerr << "oops in " << __func__ << std::endl;
+ return true;
+ }
+
+
void impl_run()
{
mlc::eq<oln_type_of(I, size), oln_type_of(N, size)>::ensure();
@@ -297,22 +271,19 @@
oln_type_of(I, concrete) output;
output = utils::clone(this->input1);
{
- oln_type_of(N, window) se_plus = get_plus_se_p(convert::ng_to_cse(this->ng));
- oln_type_of(N, window) se_minus = get_minus_se_p(convert::ng_to_cse(this->ng));
+ oln_type_of(N, window) se_plus = get_plus_se_p(convert::nbh_to_cse(this->nbh));
+ oln_type_of(N, window) se_minus = get_minus_se_p(convert::nbh_to_cse(this->nbh));
oln_type_of(I, fwd_piter) fwd_p(output.size());
oln_type_of(I, fwd_piter) bkd_p(output.size());
for_all (fwd_p)
- output[fwd_p] = ntg::min(morpho::max(output, fwd_p, se_plus),
- this->input2[fwd_p].value());
+ output[fwd_p] = this->process(output, fwd_p, se_plus, this->input2[fwd_p].value());
std::queue<oln_type_of(I, point) > fifo;
for_all (bkd_p)
{
- output[bkd_p] = ntg::min(morpho::max(output, bkd_p, se_minus),
- this->input2[bkd_p].value());
- if (internal::exist_init_dilation((oln_type_of(I, point))bkd_p, output,
- this->input2, se_minus))
+ output[bkd_p] = this->process(output, bkd_p, se_minus, this->input2[bkd_p].value());
+ if (this->exist_init((oln_type_of(I, point))bkd_p, output, se_minus))
fifo.push(bkd_p);
}
// Propagation Step
@@ -321,22 +292,13 @@
oln_type_of(I, point) p = fifo.front();
fifo.pop();
typedef oln_type_of(N, window) window_type;
- window_type w = convert::ng_to_se(this->ng);
+ window_type w = convert::nbh_to_se(this->nbh);
oln_type_of(window_type, fwd_witer) dp(w);
for_all (dp)
{
oln_type_of(I, point) q = (oln_type_of(window_type, dpoint))dp + p;
- if (output.hold(q))
- {
- if ((output[q] < output[p]) &&
- (this->input2[q] != output[q]))
- {
- output[q] = ntg::min(output[p].value(),
- this->input2[q].value());
- fifo.push(q);
- }
- }
+ this->loop_body(p, q, output, fifo);
}
}
}
@@ -344,294 +306,144 @@
}
};
- }
- template<class I, class N>
- reconstruction_ret<I, N>
- geodesic_reconstruction_dilation(const abstract::non_vectorial_image<I> & marker,
- const abstract::non_vectorial_image<I> & mask,
- const abstract::neighborhood<N>& ng)
- {
- impl::reconstruction_dilation_ret<I, N> tmp(marker, mask, ng);
- tmp.run();
- return tmp;
- }
- }// hybrid
-
-
- namespace sequential {
-
- /*!
- ** \brief Perform a geodesic reconstruction erosion.
- **
- ** Compute the reconstruction by erosion of marker with respect
- ** to the mask image using se as structuring element. Soille
- ** p.160. The algorithm used is the one defined as sequential
- ** in Vincent(1993), Morphological grayscale reconstruction in
- ** image analysis: applications and efficient algorithms, itip,
- ** 2(2), 176--201.
- **
- ** \pre Marker must be greater or equal than mask.
- **
- ** \param I1 Exact type of image marker.
- ** \param I2 Exact type of image mask.
- ** \param N Exact type of neighborhood.
- **
- ** \arg marker Image to work on.
- ** \arg mask Image used for geodesic erosion.
- ** \arg Ng Neighborhood to use.
- **
- ** \code
- ** #include <oln/basics2d.hh>
- ** #include <oln/morpho/opening.hh>
- ** #include <oln/morpho/reconstruction.hh>
- ** #include <oln/level/compare.hh>
- ** #include <ntg/all.hh>
- ** int main()
- ** {
- ** typedef oln::image2d<ntg::int_u8> im_type;
- **
- ** im_type im1(oln::load(IMG_IN "lena128.pgm"));
- ** im_type im2 = oln::morpho::opening(im1, oln::win_c4p());
- **
- ** oln::save(oln::morpho::sequential::geodesic_reconstruction_erosion(im1,
- ** im2,
- ** oln::neighb_c4()),
- ** IMG_OUT "oln_morpho_sequential_geodesic_reconstruction_erosion.pbm");
- ** return 0;
- ** }
- ** \endcode
- **
- ** \image html lena128_pgm.png
- ** \image latex lena128_pgm.png
- ** =>
- ** \image html oln_morpho_sequential_geodesic_reconstruction_erosion.png
- ** \image latex oln_morpho_sequential_geodesic_reconstruction_erosion.png
- **
- */
-
-
- namespace impl {
-
template <typename I, typename N>
- struct reconstruction_erosion_ret : public reconstruction_ret<I, N>
+ struct reconstruction_dilation_ret : public reconstruction_hybrid_ret<I, N>
{
- typedef reconstruction_ret<I, N> super_type;
+ typedef reconstruction_hybrid_ret<I, N> super_type;
- reconstruction_erosion_ret(const abstract::non_vectorial_image<I>& input1, //marker
+ reconstruction_dilation_ret(const abstract::non_vectorial_image<I>& input1, //marker
const abstract::non_vectorial_image<I>& input2, //mask
- const abstract::neighborhood<N>& ng)
+ const abstract::neighborhood<N>& nbh)
- : super_type(input1, input2, ng)
+ : super_type(input1, input2, nbh)
{}
- void impl_run()
+ const oln_type_of(I, value) process(const I& work,
+ const oln_type_of(I, point)& p,
+ const oln_type_of(N, window)& se,
+ const oln_type_of(I, value)& v) const
{
- mlc::eq<oln_type_of(I, size), oln_type_of(N, size)>::ensure();
- precondition(this->input1.size() == this->input2.size());
- precondition(level::is_greater_or_equal(this->input2, this->input1));
+ return ntg::min(morpho::max(work, p, se), v);
+ }
- // Conversion of neighborhood into a SE.
- oln_type_of(N, window) se_plus = get_plus_se_p(convert::ng_to_cse(this->ng));
- oln_type_of(N, window) se_minus = get_minus_se_p(convert::ng_to_cse(this->ng));
-
- I output;
- output = utils::clone(this->input1);
- bool non_stability = true;
- oln_type_of(I, fwd_piter) fwd_p(output.size());
- oln_type_of(I, fwd_piter) bkd_p(output.size());
- while (non_stability)
+ virtual void loop_body(const oln_type_of(I, point)& p,
+ const oln_type_of(I, point)& q,
+ oln_type_of(I, concrete)& output,
+ std::queue<oln_type_of(I, point) >& fifo)
+ {
+ if (output.hold(q))
{
- I work;
- work = utils::clone(output);
- for_all (fwd_p)
- work[fwd_p] = ntg::max(morpho::min(work, fwd_p, se_plus),
- this->input2[fwd_p].value());
- for_all (bkd_p)
- work[bkd_p] = ntg::max(morpho::min(work, bkd_p, se_minus),
- this->input2[bkd_p].value());
- non_stability = !(level::is_equal(work, output));
- output = work;
+ if ((output[q] < output[p]) &&
+ (this->input2[q] != output[q]))
+ {
+ output[q] = ntg::min(output[p].value(),
+ this->input2[q].value());
+ fifo.push(q);
+ }
}
- this->output = output;
+
}
- };
- }
- template<class I, class N>
- reconstruction_ret<I, N>
- geodesic_reconstruction_erosion(const abstract::non_vectorial_image<I> & marker,
- const abstract::non_vectorial_image<I> & mask,
- const abstract::neighborhood<N>& ng)
- {
- impl::reconstruction_erosion_ret<I, N> tmp(marker, mask, ng);
- tmp.run();
- return tmp;
- }
+ virtual bool exist_init(const oln_type_of(I, point)& p,
+ const oln_type_of(I, concrete)& marker,
+ const oln_type_of(N, window)& se) const
+ {
+ typedef oln_type_of(N, window) se_type;
+ oln_type_of(se_type, fwd_witer) dp(se);
+ for_all (dp)
+ {
+ oln_type_of(I, point) q = (oln_type_of(se_type, dpoint))dp + p;
+ if (marker.hold(q) && (marker[q] < marker[p]) &&
+ (marker[q] < this->input2[q]))
+ return true;
+ }
+ return false;
+ }
- } // sequential
+ };
- namespace hybrid {
- namespace internal {
- /*!
- ** \brief Check if it exists initialization for erosion.
- **
- ** \arg p Point to consider.
- ** \arg marker Image to work on.
- ** \arg mask Image used as mask.
- ** \arg Ng Neighborhood to use.
- */
- template<class P, class I1, class I2, class E> inline
- static bool
- exist_init_erosion(const abstract::point<P>& p,
- const abstract::non_vectorial_image<I1>& marker,
- const abstract::non_vectorial_image<I2>& mask,
- const abstract::struct_elt<E>& se)
- {
- oln_type_of(E, fwd_witer) dp(se.exact());
- for_all (dp)
- {
- P q = (oln_type_of(E, dpoint))dp + p.exact();
- if (marker.hold(q) && (marker[q] > marker[p.exact()]) &&
- (marker[q] > mask[q]))
- return true;
- }
- return false;
- }
-
- } //internal
-
- /*!
- ** \brief Perform a geodesic reconstruction erosion.
- **
- ** Compute the reconstruction by erosion of marker with respect
- ** to the mask mask image using se as structuring
- ** element. Soille p.160. The algorithm used is the one defined
- ** as hybrid in Vincent(1993), Morphological grayscale
- ** reconstruction in image analysis: applications and efficient
- ** algorithms, itip, 2(2), 176--201.
- **
- ** \pre Marker must be greater or equal than mask.
- **
- ** \param I1 Exact type of image marker.
- ** \param I2 Exact type of image mask.
- ** \param N Exact type of neighborhood.
- **
- ** \arg marker Image to work on.
- ** \arg mask Image used for geodesic erosion.
- ** \arg Ng Neighborhood to use.
- **
- ** \code
- ** #include <oln/basics2d.hh>
- ** #include <oln/morpho/opening.hh>
- ** #include <oln/morpho/reconstruction.hh>
- ** #include <oln/level/compare.hh>
- ** #include <ntg/all.hh>
- ** int main()
- ** {
- ** typedef oln::image2d<ntg::int_u8> im_type;
- **
- ** im_type im1(oln::load(IMG_IN "lena128.pgm"));
- ** im_type im2 = oln::morpho::opening(im1, oln::win_c4p());
- **
- ** oln::save(oln::morpho::hybrid::geodesic_reconstruction_erosion(im1,
- ** im2,
- ** oln::neighb_c4()),
- ** IMG_OUT "oln_morpho_hybrid_geodesic_reconstruction_erosion.pbm");
- ** return 0;
- ** }
- ** \endcode
- **
- ** \image html lena128_pgm.png
- ** \image latex lena128_pgm.png
- ** =>
- ** \image html oln_morpho_hybrid_geodesic_reconstruction_erosion.png
- ** \image latex oln_morpho_hybrid_geodesic_reconstruction_erosion.png
- **
- */
-
- namespace impl {
-
template <typename I, typename N>
- struct reconstruction_erosion_ret : public reconstruction_ret<I, N>
+ struct reconstruction_erosion_ret : public reconstruction_hybrid_ret<I, N>
{
- typedef reconstruction_ret<I, N> super_type;
+ typedef reconstruction_hybrid_ret<I, N> super_type;
reconstruction_erosion_ret(const abstract::non_vectorial_image<I>& input1, //marker
const abstract::non_vectorial_image<I>& input2, //mask
- const abstract::neighborhood<N>& ng)
+ const abstract::neighborhood<N>& nbh)
- : super_type(input1, input2, ng)
+ : super_type(input1, input2, nbh)
{}
- void impl_run()
+ const oln_type_of(I, value) process(const I& work,
+ const oln_type_of(I, point)& p,
+ const oln_type_of(N, window)& se,
+ const oln_type_of(I, value)& v) const
{
- mlc::eq<oln_type_of(I, size), oln_type_of(N, size)>::ensure();
- precondition(this->input1.size() == this->input2.size());
- precondition(level::is_greater_or_equal(this->input2, this->input1));
+ return ntg::max(morpho::min(work, p, se), v);
+ }
- oln_type_of(I, concrete) output;
- output = utils::clone(this->input1);
- {
- oln_type_of(N, window) se_plus = get_plus_se_p(convert::ng_to_cse(this->ng));
- oln_type_of(N, window) se_minus = get_minus_se_p(convert::ng_to_cse(this->ng));
- oln_type_of(I, fwd_piter) fwd_p(output.size());
- oln_type_of(I, fwd_piter) bkd_p(output.size());
+ virtual void loop_body(const oln_type_of(I, point)& p,
+ const oln_type_of(I, point)& q,
+ oln_type_of(I, concrete)& output,
+ std::queue<oln_type_of(I, point) >& fifo)
+ {
+ if (output.hold(q))
+ {
+ if ((output[q] > output[p]) &&
+ (this->input2[q] != output[q]))
+ {
+ output[q] = ntg::max(output[p].value(),
+ this->input2[q].value());
+ fifo.push(q);
+ }
+ }
+ }
- for_all (fwd_p)
- output[fwd_p] = ntg::max(morpho::min(output, fwd_p, se_plus),
- this->input2[fwd_p].value());
- std::queue<oln_type_of(I, point) > fifo;
- for_all (bkd_p)
- {
- output[bkd_p] = ntg::max(morpho::min(output, bkd_p, se_minus),
- this->input2[bkd_p].value());
- if (internal::exist_init_erosion((oln_type_of(I, point))bkd_p, output,
- this->input2, se_minus))
- fifo.push(bkd_p);
- }
- // Propagation Step
- while (!fifo.empty())
- {
- oln_type_of(I, point) p = fifo.front();
- fifo.pop();
- typedef oln_type_of(N, window) window_type;
- window_type w = convert::ng_to_se(this->ng);
- oln_type_of(window_type, fwd_witer) dp(w);
-
- for_all (dp)
- {
- oln_type_of(I, point) q = (oln_type_of(window_type, dpoint))dp + p;
- if (output.hold(q))
- {
- if ((output[q] > output[p]) &&
- (this->input2[q] != output[q]))
- {
- output[q] = ntg::max(output[p].value(),
- this->input2[q].value());
- fifo.push(q);
- }
- }
- }
- }
- }
- this->output = output;
+ virtual bool exist_init(const oln_type_of(I, point)& p,
+ const oln_type_of(I, concrete)& marker,
+ const oln_type_of(N, window)& se) const
+ {
+ typedef oln_type_of(N, window) se_type;
+ oln_type_of(se_type, fwd_witer) dp(se);
+ for_all (dp)
+ {
+ oln_type_of(I, point) q = (oln_type_of(se_type, dpoint))dp + p;
+ if (marker.hold(q) && (marker[q] > marker[p]) &&
+ (marker[q] > this->input2[q]))
+ return true;
+ }
+ return false;
}
+
};
+
+
}
template<class I, class N>
reconstruction_ret<I, N>
+ geodesic_reconstruction_dilation(const abstract::non_vectorial_image<I> & marker,
+ const abstract::non_vectorial_image<I> & mask,
+ const abstract::neighborhood<N>& nbh)
+ {
+ impl::reconstruction_dilation_ret<I, N> tmp(marker, mask, nbh);
+ tmp.run();
+ return tmp;
+ }
+
+ template<class I, class N>
+ reconstruction_ret<I, N>
geodesic_reconstruction_erosion(const abstract::non_vectorial_image<I> & marker,
const abstract::non_vectorial_image<I> & mask,
- const abstract::neighborhood<N>& ng)
+ const abstract::neighborhood<N>& nbh)
{
- impl::reconstruction_erosion_ret<I, N> tmp(marker, mask, ng);
+ impl::reconstruction_erosion_ret<I, N> tmp(marker, mask, nbh);
tmp.run();
return tmp;
}
Index: oln/morpho/cc_tarjan.hh
--- oln/morpho/cc_tarjan.hh (revision 114)
+++ oln/morpho/cc_tarjan.hh (working copy)
@@ -53,7 +53,7 @@
// category
template <typename T, typename I, typename E>
- struct set_category< morpho::cc_tarjan_ret<T,I,E> >
+ struct set_category< morpho::cc_tarjan_ret<T,I,E> >
{ typedef category::image ret; };
// super_type
@@ -61,7 +61,7 @@
struct set_super_type< morpho::cc_tarjan_ret<T,I,E> >
{
typedef abstract::image_unary_operator
- <tmp_mute(I, T), I, morpho::cc_tarjan_ret<T, I, E> >
+ <tmp_mute(I, T), I, morpho::cc_tarjan_ret<T, I, E> >
ret;
};
@@ -69,24 +69,24 @@
namespace morpho {
template <typename T, typename I, typename E>
- struct cc_tarjan_ret
+ struct cc_tarjan_ret
: public abstract::image_unary_operator
<tmp_mute(I, T), I, cc_tarjan_ret<T, I, E> >
{
typedef abstract::image_unary_operator
- <tmp_mute(I, T), I, cc_tarjan_ret<T, I, E> >
+ <tmp_mute(I, T), I, cc_tarjan_ret<T, I, E> >
super_type;
typedef typename super_type::output_type output_type;
const E ng;
-
+
cc_tarjan_ret(const abstract::image<I>& input,
const abstract::neighborhood<E>& ng) :
super_type(input),
ng(ng.exact())
{
}
-
+
};
@@ -123,8 +123,8 @@
}
} // end of misc namespace
-
+
template <typename T, typename I, typename N>
struct generic_cc_tarjan : public cc_tarjan_ret<T, I, N>
{
@@ -143,8 +143,7 @@
void impl_run()
{
- mlc::is_true<mlc::type::eq<oln_type_of(I, size),
- oln_type_of(N, size)>::ret>::ensure();
+ mlc::eq<oln_type_of(I, size), oln_type_of(N, size)>::ensure();
output_type tmp(this->input.size()); // FIXME: trick
this->output = tmp;
@@ -167,20 +166,20 @@
if (this->input[n])
do_union(n, p);
}
- }
+ }
}
void second_pass()
{
oln_type_of(I, fwd_piter) p(this->input.size());
- level::fill(output, 0);
+ level::fill(this->output, 0);
ncomps = 0;
for_all(p)
if (this->input[p])
- {
+ {
oln_type_of(I, point) q = parent[p];
// FIXME: test if ncomps > T::max()
- output[p] = (q == p ? ++ncomps : output[q]);
+ this->output[p] = (q == p ? ++ncomps : this->output[q]);
}
}
@@ -198,16 +197,16 @@
}
return x;
}
-
- void do_union(const oln_type_of(I, point)& n,
+
+ void do_union(const oln_type_of(I, point)& n,
const oln_type_of(I, point)& p)
{
oln_type_of(I, point) r = find_root(n);
if (r != p)
parent[r] = p;
}
-
-
+
+
};
} // end of namespace oln::morpho::impl
Index: oln/arith/min.hh
--- oln/arith/min.hh (revision 114)
+++ oln/arith/min.hh (working copy)
@@ -29,7 +29,8 @@
# define OLENA_ARITH_MIN_HH
# include <oln/basics.hh>
-# include <oln/core/abstract/op.hh>
+# include <oln/core/abstract/image_operator.hh>
+
# include <ntg/all.hh>
namespace oln {
@@ -53,7 +54,7 @@
template <typename I>
struct set_super_type< arith::impl::min_type<I> >
{
- typedef abstract::op<I, arith::impl::min_type<I> > ret;
+ typedef abstract::image_binary_operator<I, I, I, arith::impl::min_type<I> > ret;
};
namespace arith {
@@ -61,27 +62,25 @@
namespace impl {
template <class I>
- struct min_type : public abstract::op<I, min_type<I> >
+ struct min_type : public abstract::image_binary_operator<I, I, I, min_type<I> >
{
- box<const I> input1_;
- box<const I> input2_;
+ typedef abstract::image_binary_operator<I, I, I, min_type<I> > super_type;
min_type(const abstract::non_vectorial_image<I>& input1,
const abstract::non_vectorial_image<I>& input2) :
- input1_(input1.exact()),
- input2_(input2.exact())
+ super_type(input1.exact(), input2.exact())
{}
void impl_run()
{
- precondition(input1_.size() == input2_.size());
- I output(input1_.size());
- oln_type_of(I, fwd_piter) p(input1_.size());
+ precondition(this->input1.size() == this->input2.size());
+ I output(this->input1.size());
+ oln_type_of(I, fwd_piter) p(this->input1.size());
for_all(p)
- output[p] = ntg::min(input1_[p].value(), input2_[p].value());
+ output[p] = ntg::min(this->input1[p].value(), this->input2[p].value());
- this->image_ = output;
+ this->output = output;
}
};
Index: oln/arith/max.hh
--- oln/arith/max.hh (revision 114)
+++ oln/arith/max.hh (working copy)
@@ -29,7 +29,8 @@
# define OLENA_ARITH_MAX_HH
# include <oln/basics.hh>
-# include <oln/core/abstract/op.hh>
+# include <oln/core/abstract/image_operator.hh>
+
# include <ntg/all.hh>
namespace oln {
@@ -53,7 +54,7 @@
template <typename I>
struct set_super_type< arith::impl::max_type<I> >
{
- typedef abstract::op<I, arith::impl::max_type<I> > ret;
+ typedef abstract::image_binary_operator<I, I, I, arith::impl::max_type<I> > ret;
};
namespace arith {
@@ -61,27 +62,25 @@
namespace impl {
template <class I>
- struct max_type : public abstract::op<I, max_type<I> >
+ struct max_type : public abstract::image_binary_operator<I, I, I, max_type<I> >
{
- box<const I> input1_;
- box<const I> input2_;
+ typedef abstract::image_binary_operator<I, I, I, max_type<I> > super_type;
max_type(const abstract::non_vectorial_image<I>& input1,
const abstract::non_vectorial_image<I>& input2) :
- input1_(input1.exact()),
- input2_(input2.exact())
+ super_type(input1.exact(), input2.exact())
{}
void impl_run()
{
- precondition(input1_.size() == input2_.size());
- I output(input1_.size());
- oln_type_of(I, fwd_piter) p(input1_.size());
+ precondition(this->input1.size() == this->input2.size());
+ I output(this->input1.size());
+ oln_type_of(I, fwd_piter) p(this->input1.size());
for_all(p)
- output[p] = ntg::max(input1_[p].value(), input2_[p].value());
+ output[p] = ntg::max(this->input1[p].value(), this->input2[p].value());
- this->image_ = output;
+ this->output = output;
}
};
1
0