2005-04-29 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add some function objects.
* oln/funobj/abstract/binary.hh: New file.
* oln/funobj/abstract/unary.hh: Likewise.
* oln/funobj/meta.hh: Likewise.
* oln/funobj/arith.hh: Likewise.
* oln/funobj/logic.hh: Likewise.
* oln/funobj/cmp.hh: Likewise.
* oln/core/typedefs.hh: Update with new typedef decls.
Update of oln/core/pw/*
* oln/core/pw/binary_op.hh: New file.
* oln/core/pw/unary_op.hh: New file.
* oln/core/pw/times.hh,
* oln/core/pw/div.hh,
* oln/core/pw/plus.hh,
* oln/core/pw/minus.hh: Remove, replace by...
* oln/core/pw/arith.hh: ...this new file.
* oln/core/pw/image.hh (image_from_pw): Rename as...
(image_from_pwf): ...this.
(pw::image): Rename as...
(pw::value): ...this.
(p_value): Rename as...
(pw_value): ...this.
* oln/core/pw/image.hh: Move some parts into...
* oln/core/pw/value.hh: ...this new file.
* oln/core/pw/check.hh: ...and this new file.
* oln/core/pw/macros.hh: Update.
* oln/core/pw/abstract/function.hh (ensure): Add.
(operator-, operator!): Comment because not updated yet.
(~function): Use mlc_check_method_impl.
* oln/core/pw/abstract/unary_function.hh (input): Rename as...
(arg): ...this.
(T): Rename as...
(A): ...this.
* oln/core/pw/apply.hh: Update.
* oln/core/pw/literal.hh (p_lit): Rename as...
(p_literal): ...this.
* oln/core/pw/logic.hh: Update.
* oln/core/pw/cmp.hh: Likewise.
* oln/core/pw/all.hh: Likewise.
* oln/arith/ops.hh: Likewise.
* oln/arith/logic.hh: Likewise.
* oln/arith/cmp.hh: New file.
Fix morpho for geodesic_dilation to work.
* oln/morpho/elementary_dilation.hh: New file.
* oln/morpho/tags.hh (max_nbh, impl_max_nbh): New methods.
* oln/funobj/accum.hh (max_accumulator_init): New fun obj.
* oln/morpho/geodesic_dilation.hh
(operator<=): Remove thanks to oln/arith/cmp.hh.
* oln/morpho/geodesic_erosion.hh: Likewise.
* oln/morpho/stat.hh (local_max_nbh): New routine.
Index: oln/funobj/abstract/binary.hh
===================================================================
--- oln/funobj/abstract/binary.hh (revision 0)
+++ oln/funobj/abstract/binary.hh (revision 0)
@@ -0,0 +1,187 @@
+// 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_FUNOBJ_ABSTRACT_BINARY_HH
+# define OLENA_CORE_FUNOBJ_ABSTRACT_BINARY_HH
+
+# include <mlc/any.hh>
+# include <mlc/contract.hh>
+# include <mlc/types.hh>
+# include <ntg/all.hh>
+# include <oln/core/abstract/image.hh>
+
+
+// Macros.
+
+# define oln_fun2_type_of(Fun2Type, Alias) \
+mlc_type_of(oln, oln::category::fun2, Fun2Type, Alias)
+
+# define oln_fun2_type_2_of(Fun2Type,_2, Alias) \
+mlc_type_2_of(oln, oln::category::fun2, Fun2Type,_2, Alias)
+
+
+
+
+namespace oln
+{
+
+ namespace category
+ {
+ struct fun2;
+ }
+
+
+ template <>
+ struct set_default_props < category::fun2 >
+ {
+ typedef mlc::undefined_type res_type;
+ typedef mlc::undefined_type left_type;
+ typedef mlc::undefined_type right_type;
+ };
+
+
+ template <typename F>
+ struct get_props < category::fun2, F >
+ {
+ typedef oln_fun2_type_of(F, res) res_type;
+ typedef oln_fun2_type_of(F, left) left_type;
+ typedef oln_fun2_type_of(F, right) right_type;
+
+ static void echo(std::ostream& ostr)
+ {
+ ostr << "props_of( oln::category::fun1, " << mlc_to_string(F) << " ) =" << std::endl
+ << "{" << std::endl
+ << "\t res_type = " << mlc_to_string(res_type) << std::endl
+ << "\t left_type = " << mlc_to_string(left_type) << std::endl
+ << "\t right_type = " << mlc_to_string(right_type) << std::endl
+ << "}" << std::endl;
+ }
+
+ static void ensure()
+ {
+ mlc::is_ok< res_type >::ensure();
+ mlc::is_ok< left_type >::ensure();
+ mlc::is_ok< right_type >::ensure();
+ }
+ };
+
+
+
+ namespace f_
+ {
+
+
+ template <typename F, typename L, typename R>
+ struct binary_meta_result
+ {
+ typedef mlc::no_type ret;
+ };
+
+
+ namespace abstract {
+
+ // binary
+
+ template <typename E>
+ struct binary : public mlc::any<E>
+ {
+ typedef oln_fun2_type_of(E, res) res_type;
+ typedef oln_fun2_type_of(E, left) left_type;
+ typedef oln_fun2_type_of(E, right) right_type;
+
+ const res_type operator()(const left_type& left, const right_type& right) const
+ {
+ return this->exact().impl_binop(left, right);
+ }
+
+ protected:
+
+ binary()
+ {}
+
+ ~binary()
+ {
+ get_props<category::fun2, E>::ensure();
+ mlc_check_method_impl_2(E, const res_type, binop, const left_type&,
+ const right_type&, const);
+ }
+ };
+
+
+ // mbinary
+
+ template <typename E>
+ struct mbinary : public mlc::any<E>
+ {
+ template <typename L, typename R>
+ const typename binary_meta_result<E,L,R>::ret
+ operator()(const L& left, const R& right) const
+ {
+ return this->exact().impl_binop(left, right);
+ }
+
+ protected:
+
+ mbinary() {}
+ };
+
+
+ } // end of namespace oln::abstract
+
+
+
+
+ // fwd decl
+ template <template <typename, typename> class F> struct binary_meta;
+
+ // result
+ template <template <typename, typename> class F, typename L, typename R>
+ struct binary_meta_result < binary_meta<F>, L, R >
+ {
+ typedef oln_fun2_type_2_of(F<L,R>, res) ret;
+ };
+
+ // class
+ template <template <typename, typename> class F>
+ struct binary_meta : public abstract::mbinary< binary_meta<F> >
+ {
+ template <typename L, typename R>
+ const oln_fun2_type_2_of(F<L,R>, res)
+ impl_binop(const L& l, const R& r) const
+ {
+ static F<L,R> f;
+ return f(l, r);
+ }
+ };
+
+ } // end of namespace oln::f_
+
+} // end of namespace oln
+
+
+
+#endif // ! OLENA_CORE_FUNOBJ_ABSTRACT_BINARY_HH
Index: oln/funobj/abstract/unary.hh
===================================================================
--- oln/funobj/abstract/unary.hh (revision 0)
+++ oln/funobj/abstract/unary.hh (revision 0)
@@ -0,0 +1,169 @@
+// 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_FUNOBJ_ABSTRACT_UNARY_HH
+# define OLENA_CORE_FUNOBJ_ABSTRACT_UNARY_HH
+
+# include <mlc/any.hh>
+# include <mlc/contract.hh>
+# include <ntg/all.hh>
+# include <oln/core/abstract/image.hh>
+
+
+// Macros.
+
+# define oln_fun1_type_of(Fun1Type, Alias) \
+mlc_type_of(oln, oln::category::fun1, Fun1Type, Alias)
+
+
+namespace oln
+{
+
+ namespace category
+ {
+ struct fun1;
+ }
+
+
+ template <>
+ struct set_default_props < category::fun1 >
+ {
+ typedef mlc::undefined_type res_type;
+ typedef mlc::undefined_type arg_type;
+ };
+
+
+ template <typename F>
+ struct get_props < category::fun1, F >
+ {
+ typedef oln_fun1_type_of(F, res) res_type;
+ typedef oln_fun1_type_of(F, arg) arg_type;
+
+ static void echo(std::ostream& ostr)
+ {
+ ostr << "props_of( oln::category::fun1, " << mlc_to_string(F) << " ) =" << std::endl
+ << "{" << std::endl
+ << "\t res_type = " << mlc_to_string(res_type) << std::endl
+ << "\t arg_type = " << mlc_to_string(arg_type) << std::endl
+ << "}" << std::endl;
+ }
+
+ static void ensure()
+ {
+ mlc::is_ok< res_type >::ensure();
+ mlc::is_ok< arg_type >::ensure();
+ }
+ };
+
+
+ namespace f_
+ {
+
+ template <typename F, typename T>
+ struct unary_meta_result
+ {
+ typedef mlc::no_type ret;
+ };
+
+
+ namespace abstract {
+
+ // unary
+
+ template <typename E>
+ struct unary : public mlc::any<E>
+ {
+ typedef oln_fun1_type_of(E, res) res_type;
+ typedef oln_fun1_type_of(E, arg) arg_type;
+ const res_type operator()(const arg_type& arg) const
+ {
+ return this->exact().impl_unop(arg);
+ }
+ protected:
+ unary() {}
+ ~unary()
+ {
+ get_props<category::fun1, E>::ensure();
+ mlc_check_method_impl(E, const res_type, unop, const arg_type&, const);
+ }
+ };
+
+ // munary
+
+ template <typename E>
+ struct munary : public mlc::any<E>
+ {
+ template <typename T>
+ const typename unary_meta_result<E,T>::ret
+ operator()(const T& arg) const
+ {
+ return this->exact().impl_unop(arg);
+ }
+ protected:
+ munary() {}
+ };
+
+
+ } // end of namespace oln::abstract
+
+
+
+
+ /// Meta unary function that relies on a unary function.
+
+
+ // fwd decl
+ template <template <typename> class F> struct unary_meta;
+
+ // result
+ template <template <typename> class F, typename T>
+ struct unary_meta_result < unary_meta<F>, T >
+ {
+ typedef oln_fun1_type_of(F<T>, res) ret;
+ };
+
+ // class
+ template <template <typename> class F>
+ struct unary_meta : public abstract::munary< unary_meta<F> >
+ {
+ template <typename T>
+ const oln_fun1_type_of(F<T>, res)
+ impl_unop(const T& arg) const
+ {
+ static F<T> f;
+ return f(arg);
+ }
+ };
+
+
+ } // end of namespace oln::f_
+
+} // end of namespace oln
+
+
+
+#endif // ! OLENA_CORE_FUNOBJ_ABSTRACT_UNARY_HH
Index: oln/funobj/meta.hh
===================================================================
--- oln/funobj/meta.hh (revision 0)
+++ oln/funobj/meta.hh (revision 0)
@@ -0,0 +1,85 @@
+// 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_FUNOBJ_META_HH
+# define OLENA_CORE_FUNOBJ_META_HH
+
+# include <oln/funobj/abstract/unary.hh>
+# include <oln/funobj/abstract/binary.hh>
+
+
+namespace oln
+{
+
+ /// Plus.
+
+
+ // fwd decl
+ namespace f_ {
+ template <typename L, typename R> struct plus;
+ }
+
+ // super type
+ template <typename L, typename R>
+ struct set_super_type < f_::plus<L,R> > { typedef f_::abstract::binary< f_::plus<L,R> > ret; };
+
+ // props
+ template <typename L, typename R>
+ struct set_props < category::fun2, f_::plus<L,R> >
+ {
+ typedef ntg_return_type(plus, L, R) res_type;
+ typedef L left_type;
+ typedef R right_type;
+ };
+
+ namespace f_
+ {
+
+ // class
+ template <typename L, typename R>
+ struct plus : public oln_super2_of_(f_::plus<L,R>)
+ {
+ typedef plus<L,R> self_type;
+
+ const oln_fun2_type_of(self_type, res)
+ impl_binop(const L& left, const R& right) const
+ {
+ return left + right;
+ }
+ };
+
+ } // end of namespace oln::f_
+
+
+ static f_::binary_meta<f_::plus> f_plus;
+
+
+} // end of namespace oln
+
+
+
+#endif // ! OLENA_CORE_FUNOBJ_META_HH
Index: oln/funobj/arith.hh
===================================================================
--- oln/funobj/arith.hh (revision 0)
+++ oln/funobj/arith.hh (revision 0)
@@ -0,0 +1,143 @@
+// 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_FUNOBJ_ARITH_HH
+# define OLENA_CORE_FUNOBJ_ARITH_HH
+
+# include <oln/funobj/abstract/unary.hh>
+# include <oln/funobj/abstract/binary.hh>
+
+
+# define oln_decl_funobj_binary(OperatorName, OperatorSymbol) \
+ \
+ namespace f_ { \
+ template <typename L, typename R> struct OperatorName##_; \
+ } \
+ \
+ template <typename L, typename R> \
+ struct set_super_type < f_::OperatorName##_<L,R> > \
+ { \
+ typedef f_::abstract::binary< f_::OperatorName##_<L,R> > ret; \
+ }; \
+ \
+ template <typename L, typename R> \
+ struct set_props < category::fun2, f_::OperatorName##_<L,R> > \
+ { \
+ typedef ntg_return_type(OperatorName, L, R) res_type; \
+ typedef L left_type; \
+ typedef R right_type; \
+ }; \
+ \
+ namespace f_ \
+ { \
+ \
+ template <typename L, typename R> \
+ struct OperatorName##_ : public oln_super2_of_(f_::OperatorName##_<L,R>) \
+ { \
+ typedef OperatorName##_<L,R> self_type; \
+ \
+ const oln_fun2_type_of(self_type, res) \
+ impl_binop(const L& left, const R& right) const \
+ { \
+ return left OperatorSymbol right; \
+ } \
+ }; \
+ \
+ } \
+ \
+ typedef f_::binary_meta<f_::OperatorName##_> f_##OperatorName##_type; \
+ static f_##OperatorName##_type f_##OperatorName; \
+ \
+struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
+
+
+
+
+
+
+# define oln_decl_funobj_cmp(OperatorName, OperatorSymbol) \
+ \
+ namespace f_ { \
+ template <typename L, typename R> struct OperatorName##_; \
+ } \
+ \
+ template <typename L, typename R> \
+ struct set_super_type < f_::OperatorName##_<L,R> > \
+ { \
+ typedef f_::abstract::binary< f_::OperatorName##_<L,R> > ret; \
+ }; \
+ \
+ template <typename L, typename R> \
+ struct set_props < category::fun2, f_::OperatorName##_<L,R> > \
+ { \
+ typedef bool res_type; \
+ typedef L left_type; \
+ typedef R right_type; \
+ }; \
+ \
+ namespace f_ \
+ { \
+ \
+ template <typename L, typename R> \
+ struct OperatorName##_ : public oln_super2_of_(f_::OperatorName##_<L,R>) \
+ { \
+ typedef OperatorName##_<L,R> self_type; \
+ \
+ const oln_fun2_type_of(self_type, res) \
+ impl_binop(const L& left, const R& right) const \
+ { \
+ return left OperatorSymbol right; \
+ } \
+ }; \
+ \
+ } \
+ \
+ typedef f_::binary_meta<f_::OperatorName##_> f_##OperatorName##_type; \
+ static f_##OperatorName##_type f_##OperatorName; \
+ \
+struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
+
+
+
+namespace oln
+{
+
+ oln_decl_funobj_binary(plus, +);
+ oln_decl_funobj_binary(minus, -);
+ oln_decl_funobj_binary(times, *);
+ oln_decl_funobj_binary(div, /);
+ oln_decl_funobj_binary(mod, %);
+
+ // FIXME: min, max?
+ // FIXME: uminus?
+
+
+} // end of namespace oln
+
+
+
+#endif // ! OLENA_CORE_FUNOBJ_ARITH_HH
Index: oln/funobj/accum.hh
===================================================================
--- oln/funobj/accum.hh (revision 174)
+++ oln/funobj/accum.hh (working copy)
@@ -142,6 +142,35 @@
};
+ /// Max accumulator with initialization value.
+
+ template <class T>
+ struct max_accumulator_init
+ {
+
+ template <typename U>
+ max_accumulator_init(const U& init) :
+ acc_(init)
+ {}
+
+ void operator()(T t)
+ {
+ if (acc_ < t)
+ acc_ = t;
+ }
+
+ operator T() const
+ {
+ return acc_;
+ }
+
+ private:
+
+ T acc_;
+
+ };
+
+
} // end of namespace oln::funobj
} // end of namespace oln
Index: oln/funobj/logic.hh
===================================================================
--- oln/funobj/logic.hh (revision 0)
+++ oln/funobj/logic.hh (revision 0)
@@ -0,0 +1,97 @@
+// 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_FUNOBJ_LOGIC_HH
+# define OLENA_CORE_FUNOBJ_LOGIC_HH
+
+# include <oln/funobj/abstract/binary.hh>
+
+
+
+
+# define oln_decl_funobj_logic(OperatorName, OperatorBody) \
+ \
+ namespace f_ { \
+ template <typename L, typename R> struct OperatorName##_; \
+ } \
+ \
+ template <typename L, typename R> \
+ struct set_super_type < f_::OperatorName##_<L,R> > \
+ { \
+ typedef f_::abstract::binary< f_::OperatorName##_<L,R> > ret; \
+ }; \
+ \
+ template <typename L, typename R> \
+ struct set_props < category::fun2, f_::OperatorName##_<L,R> > \
+ { \
+ typedef bool res_type; \
+ typedef L left_type; \
+ typedef R right_type; \
+ }; \
+ \
+ namespace f_ \
+ { \
+ \
+ template <typename L, typename R> \
+ struct OperatorName##_ : public oln_super2_of_(f_::OperatorName##_<L,R>) \
+ { \
+ typedef OperatorName##_<L,R> self_type; \
+ \
+ const oln_fun2_type_of(self_type, res) \
+ impl_binop(const L& lhs, const R& rhs) const \
+ { \
+ return OperatorBody; \
+ } \
+ }; \
+ \
+ } \
+ \
+ typedef f_::binary_meta<f_::OperatorName##_> f_##OperatorName##_type; \
+ static f_##OperatorName##_type f_##OperatorName; \
+ \
+struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
+
+
+
+namespace oln
+{
+
+ oln_decl_funobj_logic( and, lhs && rhs);
+ oln_decl_funobj_logic(nand, !(lhs && rhs));
+ oln_decl_funobj_logic( or, lhs || rhs);
+ oln_decl_funobj_logic( nor, !(lhs || rhs));
+ oln_decl_funobj_logic( xor, (lhs && !rhs) || (!lhs && rhs));
+ oln_decl_funobj_logic(xnor, (lhs && rhs) || (!lhs && !rhs));
+
+ // FIXME: what about 'not'?!!!
+
+
+} // end of namespace oln
+
+
+
+#endif // ! OLENA_CORE_FUNOBJ_LOGIC_HH
Index: oln/funobj/cmp.hh
===================================================================
--- oln/funobj/cmp.hh (revision 0)
+++ oln/funobj/cmp.hh (revision 0)
@@ -0,0 +1,97 @@
+// 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_FUNOBJ_CMP_HH
+# define OLENA_CORE_FUNOBJ_CMP_HH
+
+# include <oln/funobj/abstract/binary.hh>
+
+
+
+
+# define oln_decl_funobj_cmp(OperatorName, OperatorSymbol) \
+ \
+ namespace f_ { \
+ template <typename L, typename R> struct OperatorName##_; \
+ } \
+ \
+ template <typename L, typename R> \
+ struct set_super_type < f_::OperatorName##_<L,R> > \
+ { \
+ typedef f_::abstract::binary< f_::OperatorName##_<L,R> > ret; \
+ }; \
+ \
+ template <typename L, typename R> \
+ struct set_props < category::fun2, f_::OperatorName##_<L,R> > \
+ { \
+ typedef bool res_type; \
+ typedef L left_type; \
+ typedef R right_type; \
+ }; \
+ \
+ namespace f_ \
+ { \
+ \
+ template <typename L, typename R> \
+ struct OperatorName##_ : public oln_super2_of_(f_::OperatorName##_<L,R>) \
+ { \
+ typedef OperatorName##_<L,R> self_type; \
+ \
+ const oln_fun2_type_of(self_type, res) \
+ impl_binop(const L& left, const R& right) const \
+ { \
+ return left OperatorSymbol right; \
+ } \
+ }; \
+ \
+ } \
+ \
+ typedef f_::binary_meta<f_::OperatorName##_> f_##OperatorName##_type; \
+ static f_##OperatorName##_type f_##OperatorName; \
+ \
+struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
+
+
+
+namespace oln
+{
+
+ oln_decl_funobj_cmp(eq, ==);
+ oln_decl_funobj_cmp(neq, !=);
+
+ oln_decl_funobj_cmp(less, <);
+ oln_decl_funobj_cmp(leq, <=);
+
+ oln_decl_funobj_cmp(greater, >);
+ oln_decl_funobj_cmp(geq, >=);
+
+
+} // end of namespace oln
+
+
+
+#endif // ! OLENA_CORE_FUNOBJ_CMP_HH
Index: oln/core/typedefs.hh
===================================================================
--- oln/core/typedefs.hh (revision 174)
+++ oln/core/typedefs.hh (working copy)
@@ -41,6 +41,13 @@
# define oln_super_of_(Type) \
oln::internal::get_super_type<Type>::ret
+# define oln_super2_of_(Type,_2) \
+oln::internal::get_super_type<Type,_2>::ret
+
+# define oln_super3_of_(Type,_2,_3) \
+oln::internal::get_super_type<Type,_2,_3>::ret
+
+
# define oln_super_of(Type) \
typename oln_super_of_(Type)
@@ -109,6 +116,14 @@
mlc_decl_typedef(coord_type);
+ // category::fun1 and 2
+
+ mlc_decl_typedef(res_type);
+ mlc_decl_typedef(arg_type);
+ mlc_decl_typedef(left_type);
+ mlc_decl_typedef(right_type);
+
+
} // end of namespace oln
Index: oln/core/pw/times.hh
===================================================================
--- oln/core/pw/times.hh (revision 174)
+++ oln/core/pw/times.hh (working copy)
@@ -1,107 +0,0 @@
-// 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_PW_TIMES_HH
-# define OLENA_CORE_PW_TIMES_HH
-
-# include <oln/core/pw/abstract/binary_function.hh>
-# include <oln/core/pw/literal.hh>
-# include <ntg/all.hh>
-# include <oln/core/pw/macros.hh>
-
-
-namespace oln {
-
- // fwd decl
- namespace pw {
- template <typename L, typename R> struct times;
- }
-
- // super type
- template <typename L, typename R>
- struct set_super_type < pw::times<L, R> > { typedef pw::abstract::binary_function<L, R, pw::times<L, R> > ret; };
-
- // props
- template <typename L, typename R>
- struct set_props < category::pw, pw::times<L, R> >
- {
- typedef ntg_return_type(times,
- oln_pw_type_of(L, value),
- oln_pw_type_of(R, value)) value_type;
- };
-
-
- namespace pw {
-
- template <typename L, typename R>
- struct times : public abstract::binary_function < L, R, times<L, R> >
- {
- typedef times<L, R> self_type;
-
- typedef oln_pw_type_of(self_type, point) point_type;
- typedef oln_pw_type_of(self_type, value) value_type;
- typedef oln_pw_type_of(self_type, size) size_type;
-
- typedef abstract::binary_function<L, R, self_type> super_type;
-
- times(const abstract::function<L>& left,
- const abstract::function<R>& right) :
- super_type(left, right)
- {
- }
-
- const value_type impl_get(const point_type& p) const
- {
- return this->left(p) * this->right(p);
- }
-
- };
-
-
- } // end of namespace oln::pw
-
-} // end of namespace oln
-
-
-
-/// Operator * on pwf
-
-template <typename L, typename R>
-oln::pw::times<L, R> operator * (const oln::pw::abstract::function<L>& lhs,
- const oln::pw::abstract::function<R>& rhs)
-{
- precondition(lhs.size() == rhs.size());
- oln::pw::times<L, R> tmp(lhs, rhs);
- return tmp;
-}
-
-oln_pw_operator(times, *, int)
-oln_pw_operator(times, *, float)
-oln_pw_operator(times, *, double)
-
-
-#endif // ! OLENA_CORE_PW_TIMES_HH
Index: oln/core/pw/binary_op.hh
===================================================================
--- oln/core/pw/binary_op.hh (revision 0)
+++ oln/core/pw/binary_op.hh (revision 0)
@@ -0,0 +1,94 @@
+// 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_PW_BINARY_OP_HH
+# define OLENA_CORE_PW_BINARY_OP_HH
+
+# include <mlc/is_a.hh>
+# include <oln/core/pw/abstract/binary_function.hh>
+# include <oln/funobj/abstract/binary.hh>
+
+
+namespace oln {
+
+
+ // fwd decl
+ namespace pw {
+ template <typename F, typename L, typename R> struct binary_op;
+ }
+
+ // super type
+ template <typename F, typename L, typename R>
+ struct set_super_type < pw::binary_op<F,L,R> > { typedef pw::abstract::binary_function< L, R, pw::binary_op<F,L,R> > ret; };
+
+ // props
+ template <typename F, typename L, typename R>
+ struct set_props < category::pw, pw::binary_op<F,L,R> >
+ {
+ typedef typename f_::binary_meta_result<F,L,R>::ret value_type;
+ };
+
+
+
+ namespace pw {
+
+
+ template <typename F, typename L, typename R>
+ struct binary_op : public abstract::binary_function< L, R, binary_op<F,L,R> >
+ {
+ typedef binary_op<F,L,R> self_type;
+ typedef abstract::binary_function<L,R,self_type> super_type;
+
+ F fun;
+
+ binary_op(const abstract::function<L>& left,
+ const abstract::function<R>& right) :
+ super_type(left, right),
+ fun()
+ {
+ mlc_is_a(F, f_::binary_meta)::ensure();
+ }
+
+ typedef oln_pw_type_of(self_type, point) point_type;
+ typedef oln_pw_type_of(self_type, value) value_type;
+
+ const value_type impl_get(const point_type& p) const
+ {
+ const value_type tmp = this->fun(this->left(p), this->right(p));
+ return tmp;
+ }
+
+ };
+
+
+ } // end of namespace oln::pw
+
+} // end of namespace oln
+
+
+
+#endif // ! OLENA_CORE_PW_BINARY_OP_HH
Index: oln/core/pw/image.hh
===================================================================
--- oln/core/pw/image.hh (revision 174)
+++ oln/core/pw/image.hh (working copy)
@@ -28,12 +28,9 @@
#ifndef OLENA_CORE_PW_IMAGE_HH
# define OLENA_CORE_PW_IMAGE_HH
-# include <mlc/any.hh>
-# include <mlc/cmp.hh>
-# include <oln/core/box.hh>
-# include <oln/core/abstract/image_typeness.hh>
# include <oln/core/abstract/image_entry.hh>
# include <oln/core/pw/abstract/function.hh>
+# include <oln/core/pw/value.hh>
// FIXME: remove
# include <oln/core/2d/grid2d.hh>
@@ -46,85 +43,15 @@
// fwd decl
- namespace pw {
- template <typename I> struct image;
- }
+ template <typename F> class image_from_pwf;
- // super type
- template <typename I>
- struct set_super_type < pw::image<I> > { typedef pw::abstract::function< pw::image<I> > ret; };
-
- // props
- template <typename I>
- struct set_props < category::pw, pw::image<I> >
- {
- typedef oln_type_of(I, point) point_type;
- typedef oln_type_of(I, value) value_type;
- typedef oln_type_of(I, size) size_type;
- };
-
-
- namespace pw { // means "point-wise"
-
- template <typename I>
- struct image : public abstract::function < image<I> >
- {
- oln::box<const I> ima;
-
- image(const oln::abstract::image<I>& ima) :
- ima(ima)
- {
- }
-
- typedef oln_type_of(I, point) point_type;
- typedef oln_type_of(I, value) value_type;
- typedef oln_type_of(I, size) size_type;
-
- const size_type& impl_size() const
- {
- return this->ima.size();
- }
-
- const value_type impl_get(const point_type& p) const
- {
- return this->ima.get(p);
- }
-
- bool impl_hold(const point_type& p) const
- {
- return this->ima.hold(p);
- }
-
- bool impl_hold_large(const point_type& p) const
- {
- return this->ima.hold_large(p);
- }
-
- };
-
- } // end of namespace oln::pw
-
-
- /// Routine that takes an image and outputs a "point value" object
-
- template <typename I>
- pw::image<I> p_value(const abstract::image<I>& ima)
- {
- pw::image<I> tmp(ima);
- return tmp;
- }
-
-
- // fwd decl
- template <typename F> class image_from_pw;
-
// super
template <typename F>
- struct set_super_type < image_from_pw<F> > { typedef abstract::image_entry< image_from_pw<F> > ret; };
+ struct set_super_type < image_from_pwf<F> > { typedef abstract::image_entry< image_from_pwf<F> > ret; };
// props
template <typename F>
- struct set_props < category::image, image_from_pw<F> >
+ struct set_props < category::image, image_from_pwf<F> >
{
typedef oln_pw_type_of(F, point) point_type;
typedef oln_pw_type_of(F, value) value_type;
@@ -143,22 +70,22 @@
};
- /// Class image_from_pw<F>.
+ /// Class image_from_pwf<F>.
template <typename F>
- struct image_from_pw : public abstract::image_entry< image_from_pw<F> >
+ struct image_from_pwf : public abstract::image_entry< image_from_pwf<F> >
{
- typedef image_from_pw<F> self_type;
+ typedef image_from_pwf<F> self_type;
F fun;
- image_from_pw(const pw::abstract::function<F>& fun) :
+ image_from_pwf(const pw::abstract::function<F>& fun) :
fun(fun.exact())
{
this->exact_ptr = this;
}
- image_from_pw(const self_type& rhs) :
+ image_from_pwf(const self_type& rhs) :
fun(rhs.fun)
{
this->exact_ptr = this;
@@ -200,85 +127,48 @@
};
+
/// Routine image_for_all_p.
template <typename F>
- image_from_pw<F> image_for_all_p(const pw::abstract::function<F>& fun)
+ image_from_pwf<F> image_for_all_p(const pw::abstract::function<F>& fun)
{
- image_from_pw<F> tmp(fun);
+ image_from_pwf<F> tmp(fun);
return tmp;
}
- // FIXME: below, produce an error instead of correcting the client code (?)
+ /// Specialization of image_for_all_p (so that "image_for_all_p(pw_value(ima)) == ima").
- /// Specialization of image_for_all_p (so that "image_for_all_p(p_value(ima)) == ima").
-
template <typename I>
- const I& image_for_all_p(const pw::image<I>& pv)
+ const I& image_for_all_p(const pw::value<I>& pwv)
{
- return pv.ima.unbox();
+ return pwv.ima.unbox();
}
- /// Specialization of p_value (so that "p_value(image_for_all_p(fun)) == fun").
- template <typename F>
- F p_value(const image_from_pw<F>& ima)
- {
- return ima.fun;
- }
+ /// Specializations of image_for_all_p to produce compile-time errors.
+ // FIXME: struct OLENA_ERROR__arg_of__image_for_all_p__should_be_a_point_wise_function();
+ template <typename I>
+ void image_for_all_p(const abstract::image<I>&)
+ {}
+ template <typename P>
+ void image_for_all_p(const abstract::point<P>&)
+ {}
+ /// Specialization of pw_value (so that "pw_value(image_for_all_p(fun)) == fun").
-
- /// Routine check.
-
- template <typename I>
- bool check(const abstract::binary_image<I>& pred)
+ template <typename F>
+ F pw_value(const image_from_pwf<F>& ima)
{
- oln_type_of(I, fwd_piter) p(pred.size());
- for_all_p (p)
- if (! pred[p])
- return false;
- return true;
+ F tmp = ima.fun;
+ return tmp;
}
- namespace pw {
- /// Routine oln::pw::check.
-
- template <typename F>
- bool check(const pw::abstract::function<F>& pred)
- {
- mlc::eq< oln_typeness_of(oln_pw_type_of(F, value)), typeness::binary_tag >::ensure();
- return oln::check(image_for_all_p(pred));
- }
-
- } // end of namespace oln::pw
-
-
-
- // FIXME: Does not work with g++-3.4.
- /// Specialization of image_for_all_p that gives a compile-time error.
-
-// template <typename I>
-// void image_for_all_p(const abstract::image<I>&)
-// {
-// struct OLENA_ERROR__arg_of__image_for_all_p__should_not_be_an_image();
-// }
-
-// /// Specialization of image_for_all_p that gives a compile-time error.
-
-// template <typename P>
-// void image_for_all_p(const abstract::point<P>&)
-// {
-// struct OLENA_ERROR__arg_of__image_for_all_p__should_not_be_a_point();
-// }
-
-
-
} // end of namespace oln
Index: oln/core/pw/div.hh
===================================================================
--- oln/core/pw/div.hh (revision 174)
+++ oln/core/pw/div.hh (working copy)
@@ -1,109 +0,0 @@
-// 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_PW_DIV_HH
-# define OLENA_CORE_PW_DIV_HH
-
-# include <oln/core/pw/abstract/binary_function.hh>
-# include <oln/core/pw/literal.hh>
-# include <ntg/all.hh>
-# include <oln/core/pw/macros.hh>
-
-
-namespace oln {
-
- // fwd decl
- namespace pw {
- template <typename L, typename R> struct div;
- }
-
- // super type
- template <typename L, typename R>
- struct set_super_type < pw::div<L, R> > { typedef pw::abstract::binary_function<L, R, pw::div<L, R> > ret; };
-
- // props
- template <typename L, typename R>
- struct set_props < category::pw, pw::div<L, R> >
- {
- typedef ntg_return_type(div,
- oln_pw_type_of(L, value),
- oln_pw_type_of(R, value)) value_type;
- };
-
-
- namespace pw {
-
- template <typename L, typename R>
- struct div : public abstract::binary_function < L, R, div<L, R> >
- {
- typedef div<L, R> self_type;
-
- typedef oln_pw_type_of(self_type, point) point_type;
- typedef oln_pw_type_of(self_type, value) value_type;
- typedef oln_pw_type_of(self_type, size) size_type;
-
- typedef abstract::binary_function<L, R, self_type> super_type;
-
- div(const abstract::function<L>& left,
- const abstract::function<R>& right) :
- super_type(left, right)
- {
- }
-
- const value_type impl_get(const point_type& p) const
- {
- precondition(this->right(p) != 0);
- return this->left(p) / this->right(p);
- }
-
- };
-
-
- } // end of namespace oln::pw
-
-} // end of namespace oln
-
-
-
-/// Operator / on pwf
-
-template <typename L, typename R>
-oln::pw::div<L, R> operator / (const oln::pw::abstract::function<L>& lhs,
- const oln::pw::abstract::function<R>& rhs)
-{
- precondition(lhs.size() == rhs.size());
- oln::pw::div<L, R> tmp(lhs, rhs);
- return tmp;
-}
-
-
-oln_pw_operator(div, /, int)
-oln_pw_operator(div, /, float)
-oln_pw_operator(div, /, double)
-
-
-#endif // ! OLENA_CORE_PW_DIV_HH
Index: oln/core/pw/plus.hh
===================================================================
--- oln/core/pw/plus.hh (revision 174)
+++ oln/core/pw/plus.hh (working copy)
@@ -1,107 +0,0 @@
-// 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_PW_PLUS_HH
-# define OLENA_CORE_PW_PLUS_HH
-
-# include <oln/core/pw/abstract/binary_function.hh>
-# include <oln/core/pw/literal.hh>
-# include <oln/core/pw/macros.hh>
-# include <ntg/all.hh>
-
-
-namespace oln {
-
- // fwd decl
- namespace pw {
- template <typename L, typename R> struct plus;
- }
-
- // super type
- template <typename L, typename R>
- struct set_super_type < pw::plus<L, R> > { typedef pw::abstract::binary_function<L, R, pw::plus<L, R> > ret; };
-
- // props
- template <typename L, typename R>
- struct set_props < category::pw, pw::plus<L, R> >
- {
- typedef ntg_return_type(plus,
- oln_pw_type_of(L, value),
- oln_pw_type_of(R, value)) value_type;
- };
-
-
- namespace pw {
-
- template <typename L, typename R>
- struct plus : public abstract::binary_function < L, R, plus<L, R> >
- {
- typedef plus<L, R> self_type;
-
- typedef oln_pw_type_of(self_type, point) point_type;
- typedef oln_pw_type_of(self_type, value) value_type;
- typedef oln_pw_type_of(self_type, size) size_type;
-
- typedef abstract::binary_function<L, R, self_type> super_type;
-
- plus(const abstract::function<L>& left,
- const abstract::function<R>& right) :
- super_type(left, right)
- {
- }
-
- const value_type impl_get(const point_type& p) const
- {
- return this->left(p) + this->right(p);
- }
-
- };
-
-
- } // end of namespace oln::pw
-
-} // end of namespace oln
-
-
-
-/// Operator + on pwf
-
-template <typename L, typename R>
-oln::pw::plus<L, R> operator + (const oln::pw::abstract::function<L>& lhs,
- const oln::pw::abstract::function<R>& rhs)
-{
- precondition(lhs.size() == rhs.size());
- oln::pw::plus<L, R> tmp(lhs, rhs);
- return tmp;
-}
-
-oln_pw_operator(plus, +, int)
-oln_pw_operator(plus, +, float)
-oln_pw_operator(plus, +, double)
-
-
-#endif // ! OLENA_CORE_PW_PLUS_HH
Index: oln/core/pw/macros.hh
===================================================================
--- oln/core/pw/macros.hh (revision 174)
+++ oln/core/pw/macros.hh (working copy)
@@ -28,53 +28,60 @@
#ifndef OLENA_CORE_PW_MACROS_HH
# define OLENA_CORE_PW_MACROS_HH
+# include <oln/core/pw/unary_op.hh>
+# include <oln/core/pw/binary_op.hh>
+# include <oln/core/pw/literal.hh>
-// FIXME: rename?
-# define oln_pw_operator(NAME, SYMBOL, TYPE) \
-template <typename L> \
-oln::pw::NAME<L, oln::pw::literal<TYPE> > \
-operator SYMBOL (const oln::pw::abstract::function<L>& lhs, \
- const TYPE& value) \
-{ \
- return lhs SYMBOL oln::pw::literal<TYPE>(value); \
-} \
-template <typename R> \
-oln::pw::NAME<oln::pw::literal<TYPE>, R> \
-operator SYMBOL (const TYPE& value, \
- const oln::pw::abstract::function<R>& rhs) \
-{ \
- return oln::pw::literal<TYPE>(value) SYMBOL rhs; \
-}
+# define oln_pw_decl_binary(OperatorName, OperatorSymbol) \
+ \
+template <typename L, typename R> \
+const oln::pw::binary_op< oln::f_##OperatorName##_type, \
+ L, R > \
+operator OperatorSymbol (const oln::pw::abstract::function<L>& lhs, \
+ const oln::pw::abstract::function<R>& rhs) \
+{ \
+ precondition(lhs.size() == rhs.size()); \
+ oln::pw::binary_op< oln::f_##OperatorName##_type, \
+ L, R > tmp(lhs, rhs); \
+ return tmp; \
+} \
+ \
+struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
-// FIXME: rename?
-# define oln_pw_cmp_operator(NAME, SYMBOL, TYPE) \
-template <typename L> \
-oln::pw::cmp<L, oln::pw::literal<TYPE>, oln::pw::internal::NAME> \
-operator SYMBOL (const oln::pw::abstract::function<L>& lhs, \
- const TYPE& value) \
-{ \
- return lhs SYMBOL oln::pw::literal<TYPE>(value); \
-} \
-template <typename R> \
-oln::pw::cmp<oln::pw::literal<TYPE>, R, oln::pw::internal::NAME> \
-operator SYMBOL (const TYPE& value, \
- const oln::pw::abstract::function<R>& rhs) \
-{ \
- return oln::pw::literal<TYPE>(value) SYMBOL rhs; \
-}
+# define oln_pw_decl_binary_with_lit(OperatorName, OperatorSymbol, LiteralType) \
+ \
+template <typename L> \
+const oln::pw::binary_op< oln::f_##OperatorName##_type, \
+ L, oln::pw::literal<LiteralType> > \
+operator OperatorSymbol (const oln::pw::abstract::function<L>& lhs, \
+ const LiteralType& rhs) \
+{ \
+ precondition(lhs.size() == rhs.size()); \
+ oln::pw::binary_op< oln::f_##OperatorName##_type, \
+ L, oln::pw::literal<LiteralType> > tmp(lhs, rhs); \
+ return tmp; \
+} \
+ \
+template <typename R> \
+const oln::pw::binary_op< oln::f_##OperatorName##_type, \
+ oln::pw::literal<LiteralType>, R > \
+operator OperatorSymbol (const LiteralType& lhs, \
+ const oln::pw::abstract::function<R>& rhs) \
+{ \
+ precondition(lhs.size() == rhs.size()); \
+ oln::pw::binary_op< oln::f_##OperatorName##_type, \
+ oln::pw::literal<LiteralType>, R > tmp(lhs, rhs); \
+ return tmp; \
+} \
+ \
+struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
-// FIXME: rename?
-# define oln_pw_cmp_operators(TYPE) \
-oln_pw_cmp_operator(eq, ==, TYPE) \
-oln_pw_cmp_operator(neq, !=, TYPE) \
-oln_pw_cmp_operator(geq, >=, TYPE) \
-oln_pw_cmp_operator(leq, <=, TYPE) \
-oln_pw_cmp_operator(g, >, TYPE) \
-oln_pw_cmp_operator(l, <, TYPE)
+
+
#endif // ! OLENA_CORE_PW_MACROS_HH
Index: oln/core/pw/apply.hh
===================================================================
--- oln/core/pw/apply.hh (revision 174)
+++ oln/core/pw/apply.hh (working copy)
@@ -78,15 +78,15 @@
F f_;
apply1(const mlc::abstract::unary_function<F>& f,
- const abstract::function<T>& input) :
- super_type(input),
+ const abstract::function<T>& arg) :
+ super_type(arg),
f_(f.exact())
{
}
const value_type impl_get(const point_type& p) const
{
- return f_(this->input(p));
+ return f_(this->arg(p));
}
};
Index: oln/core/pw/minus.hh
===================================================================
--- oln/core/pw/minus.hh (revision 174)
+++ oln/core/pw/minus.hh (working copy)
@@ -1,123 +0,0 @@
-// 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_PW_MINUS_HH
-# define OLENA_CORE_PW_MINUS_HH
-
-# include <oln/core/pw/abstract/binary_function.hh>
-# include <oln/core/pw/literal.hh>
-# include <ntg/all.hh>
-# include <oln/core/pw/macros.hh>
-
-
-namespace oln {
-
- // fwd decl
- namespace pw {
- template <typename L, typename R> struct minus;
- }
-
- // super type
- template <typename L, typename R>
- struct set_super_type < pw::minus<L, R> > { typedef pw::abstract::binary_function<L, R, pw::minus<L, R> > ret; };
-
- // props
- template <typename L, typename R>
- struct set_props < category::pw, pw::minus<L, R> >
- {
- typedef ntg_return_type(minus,
- oln_pw_type_of(L, value),
- oln_pw_type_of(R, value)) value_type;
- };
-
-
- namespace pw {
-
- template <typename L, typename R>
- struct minus : public abstract::binary_function < L, R, minus<L, R> >
- {
- typedef minus<L, R> self_type;
-
- typedef oln_pw_type_of(self_type, point) point_type;
- typedef oln_pw_type_of(self_type, value) value_type;
- typedef oln_pw_type_of(self_type, size) size_type;
-
- typedef abstract::binary_function<L, R, self_type > super_type;
-
- minus(const abstract::function<L>& left,
- const abstract::function<R>& right) :
- super_type(left, right)
- {
- }
-
- const value_type impl_get(const point_type& p) const
- {
- return this->left(p) - this->right(p);
- }
-
- };
-
-
- // impl of abstract::function<E>::operator-()
-
- namespace abstract {
-
- template <typename E>
- minus<literal<oln_pw_type_of(E, value)>, E>
- function<E>::operator-() const
- {
- typedef literal<oln_pw_type_of(E, value)> lit_type;
- static const lit_type lhs = 0;
- minus< lit_type, E> tmp(lhs, this->exact());
- return tmp;
- }
-
- } // end of namespace oln::pw::abstract
-
-
- } // end of namespace oln::pw
-
-} // end of namespace oln
-
-
-/// Operator - on pwf
-
-template <typename L, typename R>
-oln::pw::minus<L, R> operator - (const oln::pw::abstract::function<L>& lhs,
- const oln::pw::abstract::function<R>& rhs)
-{
- precondition(lhs.size() == rhs.size());
- oln::pw::minus<L, R> tmp(lhs, rhs);
- return tmp;
-}
-
-oln_pw_operator(minus, -, int)
-oln_pw_operator(minus, -, float)
-oln_pw_operator(minus, -, double)
-
-
-#endif // ! OLENA_CORE_PW_MINUS_HH
Index: oln/core/pw/unary_op.hh
===================================================================
--- oln/core/pw/unary_op.hh (revision 0)
+++ oln/core/pw/unary_op.hh (revision 0)
@@ -0,0 +1,91 @@
+// 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_PW_UNARY_OP_HH
+# define OLENA_CORE_PW_UNARY_OP_HH
+
+# include <mlc/is_a.hh>
+# include <oln/core/pw/abstract/unary_function.hh>
+# include <oln/funobj/abstract/unary.hh>
+
+
+
+namespace oln {
+
+
+ // fwd decl
+ namespace pw {
+ template <typename F, typename A> struct unary_op;
+ }
+
+ // super type
+ template <typename F, typename A>
+ struct set_super_type < pw::unary_op<F,A> > { typedef pw::abstract::unary_function< A, pw::unary_op<F,A> > ret; };
+
+ // props
+ template <typename F, typename A>
+ struct set_props < category::pw, pw::unary_op<F,A> >
+ {
+ typedef typename f_::unary_meta_result<F,A>::ret value_type;
+ };
+
+
+ namespace pw {
+
+ template <typename F, typename A>
+ struct unary_op : public abstract::unary_function< A, pw::unary_op<F,A> >
+ {
+ typedef unary_op<F,A> self_type;
+ typedef abstract::unary_function<A,self_type> super_type;
+
+ F fun;
+
+ unary_op(const abstract::function<A>& arg) :
+ super_type(arg),
+ fun()
+ {
+ mlc_is_a(F, f_::unary_meta)::ensure();
+ }
+
+ typedef oln_pw_type_of(self_type, point) point_type;
+ typedef oln_pw_type_of(self_type, value) value_type;
+
+ const value_type impl_get(const point_type& p) const
+ {
+ const value_type tmp = this->fun(this->arg(p));
+ return tmp;
+ }
+
+ };
+
+
+ } // end of namespace oln::pw
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_PW_UNARY_OP_HH
Index: oln/core/pw/literal.hh
===================================================================
--- oln/core/pw/literal.hh (revision 174)
+++ oln/core/pw/literal.hh (working copy)
@@ -96,13 +96,17 @@
/// Routine that takes a literal and outputs a "point-wise literal" object
template <typename T>
- pw::literal<T> p_lit(const T& value)
+ pw::literal<T> p_literal(const T& value)
{
pw::literal<T> tmp(value);
return tmp;
}
+ // FIXME: Specializations of p_literal to produce compile-time errors.
+ // ...
+
+
} // end of namespace oln
Index: oln/core/pw/logic.hh
===================================================================
--- oln/core/pw/logic.hh (revision 174)
+++ oln/core/pw/logic.hh (working copy)
@@ -28,157 +28,46 @@
#ifndef OLENA_CORE_PW_LOGIC_HH
# define OLENA_CORE_PW_LOGIC_HH
-# include <oln/core/abstract/image_typeness.hh>
-# include <oln/core/pw/abstract/function.hh>
-# include <oln/core/pw/cmp.hh>
+# include <oln/funobj/logic.hh>
+# include <oln/core/pw/macros.hh>
-namespace oln {
+oln_pw_decl_binary(and, and);
+oln_pw_decl_binary(or, or);
+oln_pw_decl_binary(xor, xor);
+// FIXME: not?
- namespace pw {
- // FIXME: move somewhere else
- namespace internal
- {
- struct not_ {
- template <typename T>
- bool operator()(const T& rhs) const {
- return !rhs;
- }
- };
- struct and_ {
- template <typename L, typename R>
- bool operator()(const L& lhs, const R& rhs) const {
- return lhs && rhs;
- }
- };
- struct nand_ {
- template <typename L, typename R>
- bool operator()(const L& lhs, const R& rhs) const {
- return !(lhs && rhs);
- }
- };
- struct or_ {
- template <typename L, typename R>
- bool operator()(const L& lhs, const R& rhs) const {
- return lhs || rhs;
- }
- };
- struct nor_ {
- template <typename L, typename R>
- bool operator()(const L& lhs, const R& rhs) const {
- return !(lhs || rhs);
- }
- };
- struct xor_ {
- template <typename L, typename R>
- bool operator()(const L& lhs, const R& rhs) const {
- return (lhs && !rhs) || (!lhs && rhs);
- }
- };
- struct xnor_ {
- template <typename L, typename R>
- bool operator()(const L& lhs, const R& rhs) const {
- return (lhs && rhs) || (!lhs && !rhs);
- }
- };
- } // end of oln::pw::internal
+# define oln_pw_decl_logic_lit(LiteralType) \
+ \
+oln_pw_decl_binary_with_lit(and, and, LiteralType); \
+oln_pw_decl_binary_with_lit(or, or, LiteralType); \
+oln_pw_decl_binary_with_lit(xor, xor, LiteralType); \
+ \
+struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
- } // end of namespace oln::pw
- // fwd decl
- namespace pw {
- template <typename R> struct not_;
- }
+namespace ntg {
+ struct bin;
+}
- // super type
- template <typename R>
- struct set_super_type < pw::not_<R> > { typedef pw::abstract::function < pw::not_<R> > ret; };
+oln_pw_decl_logic_lit(bool);
+oln_pw_decl_logic_lit(ntg::bin);
- // props
- template <typename R>
- struct set_props < category::pw, pw::not_<R> >
- {
- typedef oln_pw_type_of(R, point) point_type;
- typedef oln_pw_type_of(R, size) size_type;
- typedef bool value_type;
- };
- namespace pw
- {
- template <typename R>
- struct not_ : public abstract::function < not_<R> >
- {
- typedef not_<R> self_type;
+// template <typename E>
+// not_<E>
+// function<E>::operator!() const
+// {
+// mlc::eq< oln_typeness_of(oln_pw_type_of(E, value)), typeness::binary_tag >::ensure();
+// not_<E> tmp(this->exact());
+// return tmp;
+// }
- typedef oln_pw_type_of(R, point) point_type;
- typedef oln_pw_type_of(R, size) size_type;
- typedef oln_pw_type_of(R, value) value_type;
- R right;
- not_(const abstract::function<R>& right) :
- right(right.exact())
- {
- }
-
- const bool impl_get(const point_type& p) const
- {
- return ! this->right(p);
- }
-
- const size_type& impl_size() const
- {
- return this->right.size();
- }
-
- bool impl_hold(const point_type& p) const
- {
- return this->right.hold(p);
- }
-
- bool impl_hold_large(const point_type& p) const
- {
- return this->right.hold_large(p);
- }
-
- };
-
-
- // impl of abstract::function<E>::operator!()
-
- namespace abstract {
-
- template <typename E>
- not_<E>
- function<E>::operator!() const
- {
- mlc::eq< oln_typeness_of(oln_pw_type_of(E, value)), typeness::binary_tag >::ensure();
- not_<E> tmp(this->exact());
- return tmp;
- }
-
- } // end of namespace oln::pw::abstract
-
-
- } // end of namespace oln::pw
-
-
-} // end of namespace oln
-
-
-
-/// Ops on pwf
-
-oln_pw_decl_cmp_op(and_, &&)
-oln_pw_decl_cmp_op(or_, ||)
-
-oln_pw_cmp_operator(and_, &&, bool)
-oln_pw_cmp_operator(or_, ||, bool)
-
-
#endif // ! OLENA_CORE_PW_LOGIC_HH
Index: oln/core/pw/abstract/unary_function.hh
===================================================================
--- oln/core/pw/abstract/unary_function.hh (revision 174)
+++ oln/core/pw/abstract/unary_function.hh (working copy)
@@ -40,20 +40,20 @@
// fwd decl
namespace pw {
namespace abstract {
- template <typename T, typename E> struct unary_function;
+ template <typename A, typename E> struct unary_function;
}
}
// super type
- template <typename T, typename E>
- struct set_super_type < pw::abstract::unary_function<T, E> > { typedef pw::abstract::function<E> ret; };
+ template <typename A, typename E>
+ struct set_super_type < pw::abstract::unary_function<A, E> > { typedef pw::abstract::function<E> ret; };
// props
- template <typename T, typename E>
- struct set_props < category::pw, pw::abstract::unary_function<T, E> >
+ template <typename A, typename E>
+ struct set_props < category::pw, pw::abstract::unary_function<A, E> >
{
- typedef oln_pw_type_of(T, point) point_type;
- typedef oln_pw_type_of(T, size) size_type;
+ typedef oln_pw_type_of(A, point) point_type;
+ typedef oln_pw_type_of(A, size) size_type;
};
@@ -61,15 +61,15 @@
namespace abstract {
- template <typename T, typename E>
+ template <typename A, typename E>
struct unary_function : public function<E>
{
- typedef T input_type;
+ typedef A arg_type;
- T input;
+ A arg;
- unary_function(const abstract::function<T>& input) :
- input(input.exact())
+ unary_function(const abstract::function<A>& arg) :
+ arg(arg.exact())
{
}
@@ -78,17 +78,17 @@
const size_type& impl_size() const
{
- return input.size();
+ return arg.size();
}
bool impl_hold(const point_type& p) const
{
- return input.hold(p);
+ return arg.hold(p);
}
bool impl_hold_large(const point_type& p) const
{
- return input.hold_large(p);
+ return arg.hold_large(p);
}
protected:
Index: oln/core/pw/abstract/function.hh
===================================================================
--- oln/core/pw/abstract/function.hh (revision 174)
+++ oln/core/pw/abstract/function.hh (working copy)
@@ -71,6 +71,13 @@
<< "\t size_type = " << mlc_to_string(size_type) << std::endl
<< "}" << std::endl;
}
+
+ static void ensure()
+ {
+ mlc::is_ok< point_type >::ensure();
+ mlc::is_ok< value_type >::ensure();
+ mlc::is_ok< size_type >::ensure();
+ }
};
@@ -80,9 +87,10 @@
namespace abstract {
template <typename E> struct function;
}
- template <typename L, typename R> struct minus;
template <typename T> struct literal;
- template <typename F> struct not_;
+ // FIXME:...
+// template <typename L, typename R> struct minus;
+// template <typename F> struct not_;
namespace abstract {
@@ -114,34 +122,23 @@
return this->exact().impl_hold_large(p);
}
- minus<literal<value_type>, E> operator-() const;
- not_<E> operator!() const;
+ // FIXME:...
+// minus<literal<value_type>, E> operator-() const;
+// not_<E> operator!() const;
protected:
- function() {}
+ function()
+ {}
+
~function()
{
- { // impl_size
- typedef const size_type& (E::*meth)() const;
- meth adr = &E::impl_size;
- adr = 0;
- }
- { // impl_get
- typedef const value_type (E::*meth)(const point_type&) const;
- meth adr = &E::impl_get;
- adr = 0;
- }
- { // impl_hold
- typedef bool (E::*meth)(const point_type&) const;
- meth adr = &E::impl_hold;
- adr = 0;
- }
- { // impl_hold_large
- typedef bool (E::*meth)(const point_type&) const;
- meth adr = &E::impl_hold_large;
- adr = 0;
- }
+ get_props<category::pw, E>::ensure();
+
+ mlc_check_method_impl(E, const size_type&, size, , const);
+ mlc_check_method_impl(E, const value_type, get, const point_type&, const);
+ mlc_check_method_impl(E, bool, hold, const point_type&, const);
+ mlc_check_method_impl(E, bool, hold_large, const point_type&, const);
}
};
Index: oln/core/pw/arith.hh
===================================================================
--- oln/core/pw/arith.hh (revision 0)
+++ oln/core/pw/arith.hh (revision 0)
@@ -0,0 +1,60 @@
+// 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_PW_ARITH_HH
+# define OLENA_CORE_PW_ARITH_HH
+
+# include <oln/funobj/arith.hh>
+# include <oln/core/pw/macros.hh>
+
+
+oln_pw_decl_binary( plus, + );
+oln_pw_decl_binary( minus, - );
+oln_pw_decl_binary( times, * );
+oln_pw_decl_binary( div, / );
+oln_pw_decl_binary( mod, % );
+
+// FIXME: uminus?
+
+
+# define oln_pw_decl_arith_lit(LiteralType) \
+ \
+oln_pw_decl_binary_with_lit( plus, +, LiteralType); \
+oln_pw_decl_binary_with_lit( minus, -, LiteralType); \
+oln_pw_decl_binary_with_lit( times, +, LiteralType); \
+oln_pw_decl_binary_with_lit( div, /, LiteralType); \
+oln_pw_decl_binary_with_lit( mod, %, LiteralType); \
+ \
+struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
+
+
+oln_pw_decl_arith_lit(int);
+oln_pw_decl_arith_lit(float);
+oln_pw_decl_arith_lit(double);
+
+
+#endif // ! OLENA_CORE_PW_ARITH_HH
Index: oln/core/pw/all.hh
===================================================================
--- oln/core/pw/all.hh (revision 174)
+++ oln/core/pw/all.hh (working copy)
@@ -29,19 +29,17 @@
# define OLENA_CORE_PW_ALL_HH
-# include <oln/core/pw/abstract/function.hh>
+# include <oln/core/pw/value.hh>
# include <oln/core/pw/image.hh>
# include <oln/core/pw/literal.hh>
+// FIXME: # include <oln/core/pw/ternary.hh>
# include <oln/core/pw/cmp.hh>
+# include <oln/core/pw/arith.hh>
# include <oln/core/pw/logic.hh>
-# include <oln/core/pw/plus.hh>
-# include <oln/core/pw/minus.hh>
-# include <oln/core/pw/times.hh>
-# include <oln/core/pw/div.hh>
+# include <oln/core/pw/check.hh>
+# include <oln/core/pw/apply.hh>
-// FIXME: xor mod...
-
#endif // ! OLENA_CORE_PW_ALL_HH
Index: oln/core/pw/value.hh
===================================================================
--- oln/core/pw/value.hh (revision 0)
+++ oln/core/pw/value.hh (revision 0)
@@ -0,0 +1,123 @@
+// 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_PW_VALUE_HH
+# define OLENA_CORE_PW_VALUE_HH
+
+# include <oln/core/box.hh>
+# include <oln/core/abstract/point.hh>
+# include <oln/core/pw/abstract/function.hh>
+
+
+namespace oln {
+
+
+ // fwd decl
+ namespace pw {
+ template <typename I> struct value;
+ }
+
+ // super type
+ template <typename I>
+ struct set_super_type < pw::value<I> > { typedef pw::abstract::function< pw::value<I> > ret; };
+
+ // props
+ template <typename I>
+ struct set_props < category::pw, pw::value<I> >
+ {
+ typedef oln_type_of(I, point) point_type;
+ typedef oln_type_of(I, value) value_type;
+ typedef oln_type_of(I, size) size_type;
+ };
+
+
+ namespace pw { // means "point-wise"
+
+ template <typename I>
+ struct value : public abstract::function < value<I> >
+ {
+ oln::box<const I> ima;
+
+ value(const oln::abstract::image<I>& ima) :
+ ima(ima)
+ {
+ }
+
+ typedef oln_type_of(I, point) point_type;
+ typedef oln_type_of(I, value) value_type;
+ typedef oln_type_of(I, size) size_type;
+
+ const size_type& impl_size() const
+ {
+ return this->ima.size();
+ }
+
+ const value_type impl_get(const point_type& p) const
+ {
+ return this->ima.get(p);
+ }
+
+ bool impl_hold(const point_type& p) const
+ {
+ return this->ima.hold(p);
+ }
+
+ bool impl_hold_large(const point_type& p) const
+ {
+ return this->ima.hold_large(p);
+ }
+
+ };
+
+ } // end of namespace oln::pw
+
+
+ /// Routine that takes an image and outputs a "point value" object
+
+ template <typename I>
+ pw::value<I> pw_value(const abstract::image<I>& ima)
+ {
+ pw::value<I> tmp(ima);
+ return tmp;
+ }
+
+
+ /// Specializations of pw_value to produce compile-time errors.
+ // FIXME: struct OLENA_ERROR__arg_of__pw_value__should_be_a_image();
+
+ template <typename P>
+ void pw_value(const abstract::point<P>&)
+ {}
+
+ // FIXME: add abstract::piter, etc.
+
+
+} // end of namespace oln
+
+
+
+#endif // ! OLENA_CORE_PW_VALUE_HH
Index: oln/core/pw/check.hh
===================================================================
--- oln/core/pw/check.hh (revision 0)
+++ oln/core/pw/check.hh (revision 0)
@@ -0,0 +1,60 @@
+// 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_PW_CHECK_HH
+# define OLENA_CORE_PW_CHECK_HH
+
+# include <mlc/cmp.hh>
+# include <oln/core/abstract/image_typeness.hh>
+# include <oln/core/pw/image.hh>
+
+
+namespace oln {
+
+ namespace pw {
+
+
+ template <typename F>
+ bool check(const abstract::function<F>& pred)
+ {
+ mlc::eq< oln_typeness_of(oln_pw_type_of(F, value)), typeness::binary_tag >::ensure();
+ typedef image_from_pwf<F> I;
+ I ima(pred);
+ oln_type_of(I, fwd_piter) p(ima.size());
+ for_all_p (p)
+ if (not ima[p])
+ return false;
+ return true;
+ }
+
+
+ } // end of namespace oln::pw
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_PW_CHECK_HH
Index: oln/core/pw/cmp.hh
===================================================================
--- oln/core/pw/cmp.hh (revision 174)
+++ oln/core/pw/cmp.hh (working copy)
@@ -28,140 +28,35 @@
#ifndef OLENA_CORE_PW_CMP_HH
# define OLENA_CORE_PW_CMP_HH
-# include <oln/core/pw/abstract/binary_function.hh>
+# include <oln/funobj/cmp.hh>
# include <oln/core/pw/macros.hh>
-namespace oln {
+oln_pw_decl_binary( eq, == );
+oln_pw_decl_binary( neq, != );
+oln_pw_decl_binary( less, < );
+oln_pw_decl_binary( leq, <= );
+oln_pw_decl_binary( greater, > );
+oln_pw_decl_binary( geq, >= );
- namespace pw {
+# define oln_pw_decl_cmp_lit(LiteralType) \
+ \
+oln_pw_decl_binary_with_lit( eq, ==, LiteralType); \
+oln_pw_decl_binary_with_lit( neq, !=, LiteralType); \
+oln_pw_decl_binary_with_lit( less, < , LiteralType); \
+oln_pw_decl_binary_with_lit( leq, <=, LiteralType); \
+oln_pw_decl_binary_with_lit( greater, > , LiteralType); \
+oln_pw_decl_binary_with_lit( geq, >=, LiteralType); \
+ \
+struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
- // FIXME: move somewhere else
- namespace internal
- {
- struct eq {
- template <typename L, typename R>
- bool operator()(const L& lhs, const R& rhs) const {
- return lhs == rhs;
- }
- };
- struct neq {
- template <typename L, typename R>
- bool operator()(const L& lhs, const R& rhs) const {
- return lhs != rhs;
- }
- };
- struct geq {
- template <typename L, typename R>
- bool operator()(const L& lhs, const R& rhs) const {
- return lhs >= rhs;
- }
- };
- struct leq {
- template <typename L, typename R>
- bool operator()(const L& lhs, const R& rhs) const {
- return lhs <= rhs;
- }
- };
- struct g {
- template <typename L, typename R>
- bool operator()(const L& lhs, const R& rhs) const {
- return lhs > rhs;
- }
- };
- struct l {
- template <typename L, typename R>
- bool operator()(const L& lhs, const R& rhs) const {
- return lhs < rhs;
- }
- };
- } // end of oln::pw::internal
+oln_pw_decl_cmp_lit(int);
+oln_pw_decl_cmp_lit(float);
+oln_pw_decl_cmp_lit(double);
- } // end of namespace pw
-
- // fwd decl
- namespace pw {
- template <typename L, typename R, typename C> struct cmp;
- }
-
- // super type
- template <typename L, typename R, typename C>
- struct set_super_type < pw::cmp<L, R, C> > { typedef pw::abstract::binary_function<L, R, pw::cmp<L, R, C> > ret; };
-
- // props
- template <typename L, typename R, typename C>
- struct set_props < category::pw, pw::cmp<L, R, C> >
- {
- typedef bool value_type;
- };
-
-
-
-
- namespace pw
- {
-
- template <typename L, typename R, typename C>
- struct cmp : public abstract::binary_function < L, R, cmp<L, R, C> >
- {
- typedef cmp<L, R, C> self_type;
-
- typedef oln_pw_type_of(self_type, point) point_type;
- typedef oln_pw_type_of(self_type, value) value_type;
- typedef oln_pw_type_of(self_type, size) size_type;
-
- typedef abstract::binary_function<L, R, self_type> super_type;
-
- cmp(const abstract::function<L>& left,
- const abstract::function<R>& right) :
- super_type(left, right)
- {
- }
-
- const bool impl_get(const point_type& p) const
- {
- static const C cmpfun = C();
- return cmpfun(this->left(p), this->right(p));
- }
-
- };
-
- } // end of namespace oln::pw
-
-
-} // end of namespace oln
-
-
-
-/// Ops on pwf
-
-# define oln_pw_decl_cmp_op(NAME, SYMBOL) \
-template <typename L, typename R> \
-oln::pw::cmp<L, R, oln::pw::internal:: NAME > \
-operator SYMBOL (const oln::pw::abstract::function<L>& lhs, \
- const oln::pw::abstract::function<R>& rhs) \
-{ \
- precondition(lhs.size() == rhs.size()); \
- oln::pw::cmp<L, R, oln::pw::internal:: NAME > tmp(lhs, rhs); \
- return tmp; \
-}
-
-oln_pw_decl_cmp_op(eq, ==)
-oln_pw_decl_cmp_op(neq, !=)
-oln_pw_decl_cmp_op(geq, >=)
-oln_pw_decl_cmp_op(leq, <=)
-oln_pw_decl_cmp_op(g, >)
-oln_pw_decl_cmp_op(l, <)
-
-oln_pw_cmp_operators(int)
-oln_pw_cmp_operators(float)
-oln_pw_cmp_operators(double)
-
-
-
#endif // ! OLENA_CORE_PW_CMP_HH
Index: oln/morpho/elementary_dilation.hh
===================================================================
--- oln/morpho/elementary_dilation.hh (revision 0)
+++ oln/morpho/elementary_dilation.hh (revision 0)
@@ -0,0 +1,113 @@
+// 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_MORPHO_ELEMENTARY_DILATION_HH
+# define OLENA_MORPHO_ELEMENTARY_DILATION_HH
+
+# include <oln/utils/record.hh>
+# include <oln/core/gen/image_with_nbh.hh>
+# include <oln/morpho/tags.hh>
+
+
+namespace oln {
+
+ namespace morpho {
+
+
+
+ // Fwd decl of elementary dilation's facade.
+
+ template<typename K, typename I>
+ oln_type_of(I, concrete) elementary_dilation(const tag::kind<K>& kind,
+ const abstract::image_with_nbh<I>& input);
+
+ // Facade for classical elementary dilation.
+
+ template<typename I>
+ oln_type_of(I, concrete) elementary_dilation(const abstract::image_with_nbh<I>& input)
+ {
+ return elementary_dilation(tag::classical, input);
+ }
+
+
+
+ namespace impl {
+
+
+ // generic
+
+ template<typename K, typename I>
+ oln_type_of(I, concrete) elementary_dilation_(const tag::kind<K>& kind,
+ const abstract::image_with_nbh<I>& input)
+ {
+ entering("->generic");
+ registering(input, "input");
+
+ oln_type_of(I, concrete) output(input.size(), "output");
+
+ oln_type_of(I, piter) p(input.size());
+ for_all_p (p)
+ output[p] = kind.max_nbh(input, p);
+
+ exiting("->generic");
+ return output;
+ }
+
+
+ // add some other impls here...
+
+
+ } // end of namespace oln::morpho::impl
+
+
+
+
+ /// Generic elementary_dilation (facade).
+
+ template<typename K, typename I>
+ oln_type_of(I, concrete) elementary_dilation(const tag::kind<K>& kind,
+ const abstract::image_with_nbh<I>& input)
+ {
+ entering("morpho::elementary_dilation");
+ registering(input, "input");
+
+ oln_type_of(I, concrete) output("output");
+ output = impl::elementary_dilation_(kind, input.exact());
+
+ exiting("morpho::elementary_dilation");
+ return output;
+ }
+
+
+
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_MORPHO_ELEMENTARY_DILATION_HH
Index: oln/morpho/tags.hh
===================================================================
--- oln/morpho/tags.hh (revision 174)
+++ oln/morpho/tags.hh (working copy)
@@ -84,6 +84,15 @@
return this->exact().impl_min_nbh(input, p);
}
+ // max value in input of neighborhoods of p
+ template <typename I>
+ oln_type_of(I, value)
+ max_nbh(const abstract::image_with_nbh<I>& input,
+ const oln_type_of(I, point)& p) const
+ {
+ return this->exact().impl_max_nbh(input, p);
+ }
+
};
@@ -119,6 +128,15 @@
return morpho::local_min_nbh(input, p);
}
+ // max value in input of neighborhoods of p
+ template <typename I>
+ oln_type_of(I, value)
+ impl_max_nbh(const abstract::image_with_nbh<I>& input,
+ const oln_type_of(I, point)& p) const
+ {
+ return morpho::local_max_nbh(input, p);
+ }
+
};
const classical_type classical = classical_type();
Index: oln/morpho/geodesic_dilation.hh
===================================================================
--- oln/morpho/geodesic_dilation.hh (revision 174)
+++ oln/morpho/geodesic_dilation.hh (working copy)
@@ -32,22 +32,14 @@
# include <mlc/contract.hh>
# include <oln/utils/record.hh>
-# include <oln/core/pw/all.hh>
+# include <oln/arith/cmp.hh>
# include <oln/core/gen/image_with_nbh.hh> // FIXME: should be in core/abstract/ (?)
# include <oln/morpho/elementary_dilation.hh>
-// FIXME: such routines should be written somewhere else...
-template <typename L, typename R>
-bool operator <= (const oln::abstract::image<L>& lhs,
- const oln::abstract::image<R>& rhs)
-{
- return oln::pw::check(oln::p_value(lhs) <= oln::p_value(rhs));
-}
-
namespace oln {
namespace morpho {
Index: oln/morpho/stat.hh
===================================================================
--- oln/morpho/stat.hh (revision 174)
+++ oln/morpho/stat.hh (working copy)
@@ -58,7 +58,6 @@
return minval;
}
-
template <typename I>
oln_type_of(I, value) local_min_nbh(const abstract::image_with_nbh<I>& input,
const oln_type_of(I, point)& p)
@@ -110,7 +109,20 @@
return maxval;
}
+ template <typename I>
+ oln_type_of(I, value) local_max_nbh(const abstract::image_with_nbh<I>& input,
+ const oln_type_of(I, point)& p)
+ {
+ oln_type_of(I, niter) n(input);
+ funobj::max_accumulator_init<oln_type_of(I, value)> maxval(input[p]);
+
+ for_all_n_of_p (n, p)
+ if (input.hold(n))
+ maxval(input[n]);
+ return maxval;
+ }
+
/// Local max on a set.
template <typename I, typename W>
Index: oln/morpho/geodesic_erosion.hh
===================================================================
--- oln/morpho/geodesic_erosion.hh (revision 174)
+++ oln/morpho/geodesic_erosion.hh (working copy)
@@ -32,23 +32,13 @@
# include <mlc/contract.hh>
# include <oln/utils/record.hh>
-# include <oln/core/pw/all.hh>
+# include <oln/arith/cmp.hh>
# include <oln/core/gen/image_with_nbh.hh> // FIXME: should be in core/abstract/ (?)
# include <oln/morpho/elementary_erosion.hh>
-// FIXME: such routines should be written somewhere else...
-template <typename L, typename R>
-bool operator >= (const oln::abstract::image<L>& lhs,
- const oln::abstract::image<R>& rhs)
-{
- return oln::pw::check(oln::p_value(lhs) >= oln::p_value(rhs));
-}
-
-
-
namespace oln {
namespace morpho {
Index: oln/arith/ops.hh
===================================================================
--- oln/arith/ops.hh (revision 174)
+++ oln/arith/ops.hh (working copy)
@@ -29,108 +29,129 @@
# define OLENA_ARITH_OPS_HH
# include <oln/core/abstract/image.hh>
-# include <oln/core/abstract/image_typeness.hh>
-# include <oln/core/pw/all.hh>
+# include <oln/core/pw/image.hh>
+# include <oln/core/pw/value.hh>
+# include <oln/core/pw/arith.hh>
-/// Operator + between 2 images.
+/// Operator '+' between 2 images.
template <typename L, typename R>
-oln::image_from_pw< oln::pw::plus< oln::pw::image<L>,
- oln::pw::image<R> > >
+oln::image_from_pwf< oln::pw::binary_op< oln::f_plus_type,
+ oln::pw::value<L>,
+ oln::pw::value<R> > >
operator + (const oln::abstract::image<L>& lhs,
const oln::abstract::image<R>& rhs)
{
- return oln::image_for_all_p(oln::p_value(lhs) + oln::p_value(rhs));
+ return oln::image_for_all_p(oln::pw_value(lhs) + oln::pw_value(rhs));
}
-/// Operator - between 2 images.
+/// Operator '-' between 2 images.
template <typename L, typename R>
-oln::image_from_pw< oln::pw::minus< oln::pw::image<L>,
- oln::pw::image<R> > >
+oln::image_from_pwf< oln::pw::binary_op< oln::f_minus_type,
+ oln::pw::value<L>,
+ oln::pw::value<R> > >
operator - (const oln::abstract::image<L>& lhs,
const oln::abstract::image<R>& rhs)
{
- return oln::image_for_all_p(oln::p_value(lhs) - oln::p_value(rhs));
+ return oln::image_for_all_p(oln::pw_value(lhs) - oln::pw_value(rhs));
}
-/// Operator - (unary) on image.
+/// Operator '*' between 2 images.
-template <typename R>
-oln::image_from_pw< oln::pw::minus< oln::pw::literal< oln_pw_type_of(R, value) >,
- oln::pw::image<R> > >
-operator - (const oln::abstract::image<R>& rhs)
+template <typename L, typename R>
+oln::image_from_pwf< oln::pw::binary_op< oln::f_times_type,
+ oln::pw::value<L>,
+ oln::pw::value<R> > >
+operator * (const oln::abstract::image<L>& lhs,
+ const oln::abstract::image<R>& rhs)
{
- return oln::image_for_all_p( - oln::p_value(rhs));
+ return oln::image_for_all_p(oln::pw_value(lhs) * oln::pw_value(rhs));
}
-/// Operator * between 2 images.
+/// Operator '/' between 2 images.
template <typename L, typename R>
-oln::image_from_pw< oln::pw::times< oln::pw::image<L>,
- oln::pw::image<R> > >
-operator * (const oln::abstract::image<L>& lhs,
+oln::image_from_pwf< oln::pw::binary_op< oln::f_div_type,
+ oln::pw::value<L>,
+ oln::pw::value<R> > >
+operator / (const oln::abstract::image<L>& lhs,
const oln::abstract::image<R>& rhs)
{
- return oln::image_for_all_p(oln::p_value(lhs) * oln::p_value(rhs));
+ return oln::image_for_all_p(oln::pw_value(lhs) / oln::pw_value(rhs));
}
-/// Operator / between 2 images.
+/// Operator '%' between 2 images.
template <typename L, typename R>
-oln::image_from_pw< oln::pw::div< oln::pw::image<L>,
- oln::pw::image<R> > >
-operator / (const oln::abstract::image<L>& lhs,
+oln::image_from_pwf< oln::pw::binary_op< oln::f_mod_type,
+ oln::pw::value<L>,
+ oln::pw::value<R> > >
+operator % (const oln::abstract::image<L>& lhs,
const oln::abstract::image<R>& rhs)
{
- return oln::image_for_all_p(oln::p_value(lhs) / oln::p_value(rhs));
+ return oln::image_for_all_p(oln::pw_value(lhs) % oln::pw_value(rhs));
}
-# define oln_decl_binary_operator(NAME, SYMBOL, TYPE) \
-template <typename L> \
-oln::image_from_pw< oln::pw::NAME< oln::pw::image<L>, \
- oln::pw::literal<TYPE> > > \
-operator SYMBOL (const oln::abstract::image<L>& lhs, \
- TYPE value) \
-{ \
- return oln::image_for_all_p(oln::p_value(lhs) SYMBOL oln::p_lit(value)); \
-} \
-template <typename R> \
-oln::image_from_pw< oln::pw::NAME< oln::pw::literal<TYPE>, \
- oln::pw::image<R> > > \
-operator SYMBOL (TYPE value, \
- const oln::abstract::image<R>& rhs) \
-{ \
- return oln::image_for_all_p(oln::p_lit(value) SYMBOL oln::p_value(rhs)); \
-}
+// FIXME...
+// /// Operator - (unary) on image.
-oln_decl_binary_operator(plus, +, int)
-oln_decl_binary_operator(plus, +, float)
-oln_decl_binary_operator(plus, +, double)
+// template <typename R>
+// oln::image_from_pw< oln::pw::minus< oln::pw::literal< oln_pw_type_of(R, value) >,
+// oln::pw::image<R> > >
+// operator - (const oln::abstract::image<R>& rhs)
+// {
+// return oln::image_for_all_p( - oln::p_value(rhs));
+// }
-oln_decl_binary_operator(minus, -, int)
-oln_decl_binary_operator(minus, -, float)
-oln_decl_binary_operator(minus, -, double)
-oln_decl_binary_operator(times, *, int)
-oln_decl_binary_operator(times, *, float)
-oln_decl_binary_operator(times, *, double)
-oln_decl_binary_operator(div, /, int)
-oln_decl_binary_operator(div, /, float)
-oln_decl_binary_operator(div, /, double)
+// # define oln_decl_binary_operator(NAME, SYMBOL, TYPE) \
+// template <typename L> \
+// oln::image_from_pw< oln::pw::NAME< oln::pw::image<L>, \
+// oln::pw::literal<TYPE> > > \
+// operator SYMBOL (const oln::abstract::image<L>& lhs, \
+// TYPE value) \
+// { \
+// return oln::image_for_all_p(oln::p_value(lhs) SYMBOL oln::p_lit(value)); \
+// } \
+// template <typename R> \
+// oln::image_from_pw< oln::pw::NAME< oln::pw::literal<TYPE>, \
+// oln::pw::image<R> > > \
+// operator SYMBOL (TYPE value, \
+// const oln::abstract::image<R>& rhs) \
+// { \
+// return oln::image_for_all_p(oln::p_lit(value) SYMBOL oln::p_value(rhs)); \
+// }
+// oln_decl_binary_operator(plus, +, int)
+// oln_decl_binary_operator(plus, +, float)
+// oln_decl_binary_operator(plus, +, double)
+// oln_decl_binary_operator(minus, -, int)
+// oln_decl_binary_operator(minus, -, float)
+// oln_decl_binary_operator(minus, -, double)
+
+// oln_decl_binary_operator(times, *, int)
+// oln_decl_binary_operator(times, *, float)
+// oln_decl_binary_operator(times, *, double)
+
+// oln_decl_binary_operator(div, /, int)
+// oln_decl_binary_operator(div, /, float)
+// oln_decl_binary_operator(div, /, double)
+
+
+
// template <typename I, typename F>
// void operator + (const oln::abstract::image<I>&,
// const oln::pw::abstract::function<F>&)
Index: oln/arith/logic.hh
===================================================================
--- oln/arith/logic.hh (revision 174)
+++ oln/arith/logic.hh (working copy)
@@ -25,47 +25,64 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLENA_LOGIC_OPS_HH
-# define OLENA_LOGIC_OPS_HH
+#ifndef OLENA_ARITH_LOGIC_HH
+# define OLENA_ARITH_LOGIC_HH
# include <oln/core/abstract/image.hh>
-# include <oln/core/abstract/image_typeness.hh>
-# include <oln/core/pw/all.hh>
+# include <oln/core/pw/image.hh>
+# include <oln/core/pw/value.hh>
+# include <oln/core/pw/logic.hh>
/// Operator 'and' between 2 binary images.
template <typename L, typename R>
-oln::image_from_pw< oln::pw::cmp< oln::pw::image<L>,
- oln::pw::image<R>, oln::pw::internal::and_ > >
-operator && (const oln::abstract::binary_image<L>& lhs,
- const oln::abstract::binary_image<R>& rhs)
+const oln::image_from_pwf< oln::pw::binary_op< oln::f_and_type,
+ oln::pw::value<L>,
+ oln::pw::value<R> > >
+operator and (const oln::abstract::binary_image<L>& lhs,
+ const oln::abstract::binary_image<R>& rhs)
{
- return oln::image_for_all_p(oln::p_value(lhs) && oln::p_value(rhs));
+ return oln::image_for_all_p(oln::pw_value(lhs) and oln::pw_value(rhs));
}
/// Operator 'or' between 2 binary images.
template <typename L, typename R>
-oln::image_from_pw< oln::pw::cmp< oln::pw::image<L>,
- oln::pw::image<R>, oln::pw::internal::or_ > >
-operator || (const oln::abstract::binary_image<L>& lhs,
+const oln::image_from_pwf< oln::pw::binary_op< oln::f_or_type,
+ oln::pw::value<L>,
+ oln::pw::value<R> > >
+operator or (const oln::abstract::binary_image<L>& lhs,
const oln::abstract::binary_image<R>& rhs)
{
- return oln::image_for_all_p(oln::p_value(lhs) || oln::p_value(rhs));
+ return oln::image_for_all_p(oln::pw_value(lhs) or oln::pw_value(rhs));
}
-/// Unary operator 'not' on a binary image.
+/// Operator 'xor' between 2 binary images.
-template <typename I>
-oln::image_from_pw< oln::pw::not_< oln::pw::image<I> > >
-operator ! (const oln::abstract::binary_image<I>& rhs)
+template <typename L, typename R>
+const oln::image_from_pwf< oln::pw::binary_op< oln::f_xor_type,
+ oln::pw::value<L>,
+ oln::pw::value<R> > >
+operator xor (const oln::abstract::binary_image<L>& lhs,
+ const oln::abstract::binary_image<R>& rhs)
{
- return oln::image_for_all_p(!oln::p_value(rhs));
+ return oln::image_for_all_p(oln::pw_value(lhs) xor oln::pw_value(rhs));
}
+// FIXME...
+// /// Unary operator 'not' on a binary image.
-#endif // ! OLENA_LOGIC_OPS_HH
+// template <typename I>
+// oln::image_from_pw< oln::pw::not_< oln::pw::image<I> > >
+// operator ! (const oln::abstract::binary_image<I>& rhs)
+// {
+// return oln::image_for_all_p(!oln::p_value(rhs));
+// }
+
+
+
+#endif // ! OLENA_ARITH_LOGIC_HH
Index: oln/arith/cmp.hh
===================================================================
--- oln/arith/cmp.hh (revision 0)
+++ oln/arith/cmp.hh (revision 0)
@@ -0,0 +1,96 @@
+// 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_ARITH_CMP_HH
+# define OLENA_ARITH_CMP_HH
+
+# include <oln/core/abstract/image.hh>
+# include <oln/core/pw/cmp.hh>
+# include <oln/core/pw/check.hh>
+
+
+/// Operator '==' between 2 images.
+
+template <typename L, typename R>
+bool operator == (const oln::abstract::image<L>& lhs,
+ const oln::abstract::image<R>& rhs)
+{
+ return oln::pw::check(oln::pw_value(lhs) == oln::pw_value(rhs));
+}
+
+
+/// Operator '!=' between 2 images.
+
+template <typename L, typename R>
+bool operator != (const oln::abstract::image<L>& lhs,
+ const oln::abstract::image<R>& rhs)
+{
+ return oln::pw::check(oln::pw_value(lhs) != oln::pw_value(rhs));
+}
+
+
+/// Operator '<' between 2 images.
+
+template <typename L, typename R>
+bool operator < (const oln::abstract::image<L>& lhs,
+ const oln::abstract::image<R>& rhs)
+{
+ return oln::pw::check(oln::pw_value(lhs) < oln::pw_value(rhs));
+}
+
+
+/// Operator '<=' between 2 images.
+
+template <typename L, typename R>
+bool operator <= (const oln::abstract::image<L>& lhs,
+ const oln::abstract::image<R>& rhs)
+{
+ return oln::pw::check(oln::pw_value(lhs) <= oln::pw_value(rhs));
+}
+
+
+/// Operator '>' between 2 images.
+
+template <typename L, typename R>
+bool operator > (const oln::abstract::image<L>& lhs,
+ const oln::abstract::image<R>& rhs)
+{
+ return oln::pw::check(oln::pw_value(lhs) > oln::pw_value(rhs));
+}
+
+
+/// Operator '>=' between 2 images.
+
+template <typename L, typename R>
+bool operator >= (const oln::abstract::image<L>& lhs,
+ const oln::abstract::image<R>& rhs)
+{
+ return oln::pw::check(oln::pw_value(lhs) >= oln::pw_value(rhs));
+}
+
+
+#endif // ! OLENA_ARITH_CMP_HH
2005-04-28 Nicolas Widynski <widyns_n(a)ptaouchnok.lrde.epita.fr>
* oln/morpho/geodesic_dilation.hh: New type of implementation,
like geodesic_erosion.hh
+++ oln/morpho/geodesic_dilation.hh (revision 173)
@@ -0,0 +1,111 @@
+// 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 OLENA_MORPHO_GEODESIC_DILATION_HH
+# define OLENA_MORPHO_GEODESIC_DILATION_HH
+
+# include <mlc/cmp.hh>
+# include <mlc/contract.hh>
+
+# include <oln/utils/record.hh>
+# include <oln/core/pw/all.hh>
+# include <oln/core/gen/image_with_nbh.hh> // FIXME: should be in
core/abstract/ (?)
+# include <oln/morpho/elementary_dilation.hh>
+
+
+// FIXME: such routines should be written somewhere else...
+
+template <typename L, typename R>
+bool operator <= (const oln::abstract::image<L>& lhs,
+ const oln::abstract::image<R>& rhs)
+{
+ return oln::pw::check(oln::p_value(lhs) <= oln::p_value(rhs));
+}
+
+
+
+namespace oln {
+
+ namespace morpho {
+
+
+
+ /// Generic geodesic dilation.
+
+ template<typename K, typename I, typename II>
+ oln_type_of(I, concrete) geodesic_dilation(const tag::kind<K>& kind,
+ const
abstract::image_with_nbh<I>& marker,
+ const
abstract::image<II>& mask)
+ {
+ // FIXME: later, test the short code:
+ // FIXME: return max(elementary_dilation(kind, marker), mask)
+
+ // FIXME: and even later:
+ // FIXME: return elementary_dilation(kind, marker) _max_ mask
+
+ mlc::eq<oln_type_of(I, grid), oln_type_of(II, grid)>::ensure();
+
+ entering("morpho::geodesic_dilation");
+
+ registering(marker, "marker");
+ registering(mask, "mask");
+ precondition(marker.size() == mask.size()
+ and marker <= mask);
+
+ oln_type_of(I, concrete)
+ dil("dil"),
+ output(marker.size(), "output");
+
+ dil = elementary_dilation(kind, marker);
+
+ // FIXME: replace code below by a pw::max...
+ oln_type_of(I, fwd_piter) p(marker.size());
+ for_all_p (p)
+ output[p] = std::min(dil[p].value(), mask[p].value());
+
+ exiting("morpho::geodesic_dilation");
+ return output;
+ }
+
+
+ /// Generic classical geodesic dilation.
+
+ template<typename I, typename II>
+ oln_type_of(I, concrete) geodesic_dilation(const
abstract::image_with_nbh<I>& marker,
+ const
abstract::image<II>& mask)
+ {
+ return geodesic_dilation(tag::classical, marker, mask);
+ }
+
+
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // OLENA_MORPHO_GEODESIC_DILATION_HH
2005-04-27 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* oln/morpho/closing.hh: New-like file.
* oln/morpho/dilation.hh: Likewise.
* oln/morpho/elementary_erosion.hh: Likewise.
* oln/morpho/erosion.hh: Likewise.
* oln/morpho/geodesic_erosion.hh: Likewise.
* oln/morpho/opening.hh: Likewise.
* oln/morpho/stat.hh: Likewise.
* oln/morpho/tags.hh: Likewise.
Index: oln/morpho/closing.hh
===================================================================
--- oln/morpho/closing.hh (revision 0)
+++ oln/morpho/closing.hh (revision 0)
@@ -0,0 +1,103 @@
+// Copyright (C) 2001-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_MORPHO_CLOSING_HH
+# define OLENA_MORPHO_CLOSING_HH
+
+# include <mlc/cmp.hh>
+# include <mlc/to_string.hh>
+
+# include <oln/morpho/erosion.hh>
+# include <oln/morpho/dilation.hh>
+
+
+namespace oln {
+
+ namespace morpho {
+
+
+
+ // fwd decl of facade
+
+ template<typename I, typename W>
+ oln_type_of(I, concrete) closing(const abstract::image<I>& input,
+ const abstract::window<W>& win);
+
+
+
+ namespace impl {
+
+
+
+ // generic
+
+ template<typename I, typename W>
+ oln_type_of(I, concrete) closing_(const abstract::image<I>& input,
+ const abstract::window<W>& win)
+ {
+ entering("generic");
+ oln_type_of(I, concrete) output;
+
+ output = dilation(erosion(input, win), -win);
+
+ exiting("generic");
+ return output;
+ }
+
+
+
+ } // end of namespace oln::morpho::impl
+
+
+
+
+ /// Generic closing (facade).
+
+ template<typename I, typename W>
+ oln_type_of(I, concrete) closing(const abstract::image<I>& input,
+ const abstract::window<W>& win)
+ {
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+
+ entering("morpho::closing");
+ oln_type_of(I, concrete) output;
+
+ output = impl::closing_(input.exact(), win.exact());
+
+ exiting("morpho::closing");
+ return output;
+ }
+
+
+
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_MORPHO_CLOSING_HH
Index: oln/morpho/tags.hh
===================================================================
--- oln/morpho/tags.hh (revision 0)
+++ oln/morpho/tags.hh (revision 0)
@@ -0,0 +1,152 @@
+// 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_MORPHO_TAGS_HH
+# define OLENA_MORPHO_TAGS_HH
+
+# include <mlc/any.hh>
+# include <mlc/cmp.hh>
+# include <oln/basics.hh>
+
+# include <oln/morpho/stat.hh> // FIXME: rename!!!
+
+
+
+namespace oln {
+
+ namespace morpho {
+
+
+ namespace tag
+ {
+
+ // Tags for selecting a given 'morphology' due to
+ // the couple of dual operations performed in erosion
+ // and dilation.
+
+
+ template <typename K>
+ struct kind : public mlc::any<K> // FIXME: name!
+ {
+
+ // min value in input on a window centered at p
+ template <typename I, typename W>
+ oln_type_of(I, value)
+ min(const abstract::image<I>& input,
+ const oln_type_of(I, point)& p,
+ const abstract::window<W>& win) const
+ {
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+ return this->exact().impl_min(input, p, win);
+ }
+
+ // max value in input on a window centered at p
+ template <typename I, typename W>
+ oln_type_of(I, value)
+ max(const abstract::image<I>& input,
+ const oln_type_of(I, point)& p,
+ const abstract::window<W>& win) const
+ {
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+ return this->exact().impl_max(input, p, win);
+ }
+
+ // min value in input of neighborhoods of p
+ template <typename I>
+ oln_type_of(I, value)
+ min_nbh(const abstract::image_with_nbh<I>& input,
+ const oln_type_of(I, point)& p) const
+ {
+ return this->exact().impl_min_nbh(input, p);
+ }
+
+ };
+
+
+
+ struct classical_type : public kind< classical_type >
+ {
+ // min value in input on a window centered at p
+ template <typename I, typename W>
+ oln_type_of(I, value)
+ impl_min(const abstract::image<I>& input,
+ const oln_type_of(I, point)& p,
+ const abstract::window<W>& win) const
+ {
+ return morpho::local_min(input, p, win);
+ }
+
+ // max value in input on a window centered at p
+ template <typename I, typename W>
+ oln_type_of(I, value)
+ impl_max(const abstract::image<I>& input,
+ const oln_type_of(I, point)& p,
+ const abstract::window<W>& win) const
+ {
+ return morpho::local_max(input, p, win);
+ }
+
+ // min value in input of neighborhoods of p
+ template <typename I>
+ oln_type_of(I, value)
+ impl_min_nbh(const abstract::image_with_nbh<I>& input,
+ const oln_type_of(I, point)& p) const
+ {
+ return morpho::local_min_nbh(input, p);
+ }
+
+ };
+
+ const classical_type classical = classical_type();
+
+
+ // Tags for approaches in reconstructions.
+
+ template <typename Op> struct oper {};
+
+ struct by_dilation_type : public oper< by_dilation_type > {};
+ struct by_erosion_type : public oper< by_erosion_type > {};
+
+
+ // Tags for common canvas.
+
+ template <typename A> struct algo {};
+
+ struct sequential_type : public algo< sequential_type > {};
+ struct hybrid_type : public algo< hybrid_type > {};
+ struct parallel_type : public algo< parallel_type > {};
+ struct unionfind_type : public algo< unionfind_type > {};
+
+ } // end of namespace oln::morpho::tag
+
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_MORPHO_EROSION_HH
Index: oln/morpho/opening.hh
===================================================================
--- oln/morpho/opening.hh (revision 0)
+++ oln/morpho/opening.hh (revision 0)
@@ -0,0 +1,118 @@
+// Copyright (C) 2001-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_MORPHO_OPENING_HH
+# define OLENA_MORPHO_OPENING_HH
+
+# include <mlc/cmp.hh>
+# include <mlc/to_string.hh>
+
+# include <oln/morpho/erosion.hh>
+# include <oln/morpho/dilation.hh>
+
+
+namespace oln {
+
+ namespace morpho {
+
+
+
+ // Fwd decl of opening's facade.
+
+ template<typename K, typename I, typename W>
+ oln_type_of(I, concrete) opening(const tag::kind<K>& kind,
+ const abstract::image<I>& input,
+ const abstract::window<W>& win);
+
+ // Facade for classical opening.
+
+ template<typename I, typename W>
+ oln_type_of(I, concrete) opening(const abstract::image<I>& input,
+ const abstract::window<W>& win)
+ {
+ return opening(tag::classical, input, win);
+ }
+
+
+
+ namespace impl {
+
+
+ // generic
+
+ template<typename K, typename I, typename W>
+ oln_type_of(I, concrete) opening_(const tag::kind<K>& kind,
+ const abstract::image<I>& input,
+ const abstract::window<W>& win)
+ {
+ entering("->generic");
+ registering(input, "input");
+
+ oln_type_of(I, concrete) output("output");
+ output = dilation(kind, erosion(kind, input, win), -win);
+
+ exiting("->generic");
+ return output;
+ }
+
+
+ // add some other impls here...
+
+
+ } // end of namespace oln::morpho::impl
+
+
+
+
+ /// Generic opening (facade).
+
+ template<typename K, typename I, typename W>
+ oln_type_of(I, concrete) opening(const tag::kind<K>& kind,
+ const abstract::image<I>& input,
+ const abstract::window<W>& win)
+ {
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+
+ entering("morpho::opening");
+ registering(input, "input");
+
+ oln_type_of(I, concrete) output("output");
+ output = impl::opening_(kind, input.exact(), win.exact());
+
+ exiting("morpho::opening");
+ return output;
+ }
+
+
+
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_MORPHO_OPENING_HH
Index: oln/morpho/elementary_erosion.hh
===================================================================
--- oln/morpho/elementary_erosion.hh (revision 0)
+++ oln/morpho/elementary_erosion.hh (revision 0)
@@ -0,0 +1,113 @@
+// 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_MORPHO_ELEMENTARY_EROSION_HH
+# define OLENA_MORPHO_ELEMENTARY_EROSION_HH
+
+# include <oln/utils/record.hh>
+# include <oln/core/gen/image_with_nbh.hh>
+# include <oln/morpho/tags.hh>
+
+
+namespace oln {
+
+ namespace morpho {
+
+
+
+ // Fwd decl of elementary erosion's facade.
+
+ template<typename K, typename I>
+ oln_type_of(I, concrete) elementary_erosion(const tag::kind<K>& kind,
+ const abstract::image_with_nbh<I>& input);
+
+ // Facade for classical elementary erosion.
+
+ template<typename I>
+ oln_type_of(I, concrete) elementary_erosion(const abstract::image_with_nbh<I>& input)
+ {
+ return elementary_erosion(tag::classical, input);
+ }
+
+
+
+ namespace impl {
+
+
+ // generic
+
+ template<typename K, typename I>
+ oln_type_of(I, concrete) elementary_erosion_(const tag::kind<K>& kind,
+ const abstract::image_with_nbh<I>& input)
+ {
+ entering("->generic");
+ registering(input, "input");
+
+ oln_type_of(I, concrete) output(input.size(), "output");
+
+ oln_type_of(I, piter) p(input.size());
+ for_all_p (p)
+ output[p] = kind.min_nbh(input, p);
+
+ exiting("->generic");
+ return output;
+ }
+
+
+ // add some other impls here...
+
+
+ } // end of namespace oln::morpho::impl
+
+
+
+
+ /// Generic elementary_erosion (facade).
+
+ template<typename K, typename I>
+ oln_type_of(I, concrete) elementary_erosion(const tag::kind<K>& kind,
+ const abstract::image_with_nbh<I>& input)
+ {
+ entering("morpho::elementary_erosion");
+ registering(input, "input");
+
+ oln_type_of(I, concrete) output("output");
+ output = impl::elementary_erosion_(kind, input.exact());
+
+ exiting("morpho::elementary_erosion");
+ return output;
+ }
+
+
+
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_MORPHO_ELEMENTARY_EROSION_HH
Index: oln/morpho/dilation.hh
===================================================================
--- oln/morpho/dilation.hh (revision 0)
+++ oln/morpho/dilation.hh (revision 0)
@@ -0,0 +1,143 @@
+// Copyright (C) 2001-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_MORPHO_DILATION_HH
+# define OLENA_MORPHO_DILATION_HH
+
+# include <mlc/cmp.hh>
+# include <mlc/to_string.hh>
+
+# include <oln/utils/record.hh>
+# include <oln/basics.hh>
+# include <oln/core/2d/window2d.hh>
+# include <oln/morpho/tags.hh>
+
+
+namespace oln {
+
+ namespace morpho {
+
+
+
+ // Fwd decl of dilation's facade.
+
+ template<typename K, typename I, typename W>
+ oln_type_of(I, concrete) dilation(const tag::kind<K>& kind,
+ const abstract::image<I>& input,
+ const abstract::window<W>& win);
+
+ // Facade for classical dilation.
+
+ template<typename I, typename W>
+ oln_type_of(I, concrete) dilation(const abstract::image<I>& input,
+ const abstract::window<W>& win)
+ {
+ return dilation(tag::classical, input, win);
+ }
+
+
+ namespace impl {
+
+ // generic
+
+ template<typename K, typename I, typename W>
+ oln_type_of(I, concrete) dilation_(const tag::kind<K>& kind,
+ const abstract::image<I>& input,
+ const abstract::window<W>& win)
+ {
+ entering("->generic");
+ registering(input, "input");
+
+ oln_type_of(I, concrete) output(input.size(), "output");
+
+ oln_type_of(I, fwd_piter) p(input.size());
+ for_all_p (p)
+ output[p] = kind.min(input, p, win);
+
+ exiting("->generic");
+ return output;
+ }
+
+
+
+ // win is a 2D rectangle
+
+ template<typename K, typename I>
+ oln_type_of(I, concrete) dilation_(const tag::kind<K>& kind,
+ const abstract::image2d<I>& input,
+ const win_rectangle2d& win)
+ {
+ entering("->(image2d,win_rectangle2d)");
+ registering(input, "input");
+
+ oln_type_of(I, concrete) temp("temp"), output("output");
+
+ win_hline2d hline(win.width); // FIXME: Cf. Soille, use L(i,dp)
+ win_vline2d vline(win.height);
+
+ temp = dilation(kind, input, hline);
+ output = dilation(kind, temp, vline);
+
+ exiting("->(image2d,win_rectangle2d)");
+ return output;
+ }
+
+
+ // add some other impls here...
+
+
+ } // end of namespace oln::morpho::impl
+
+
+
+
+ /// Generic dilation (facade).
+
+ template<typename K, typename I, typename W>
+ oln_type_of(I, concrete) dilation(const tag::kind<K>& kind,
+ const abstract::image<I>& input,
+ const abstract::window<W>& win)
+ {
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+ entering("morpho::dilation");
+
+ oln_type_of(I, concrete) output("output");
+ output = impl::dilation_(kind, input.exact(), win.exact());
+
+ exiting("morpho::dilation");
+ return output;
+ }
+
+
+
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_MORPHO_DILATION_HH
Index: oln/morpho/stat.hh
===================================================================
--- oln/morpho/stat.hh (revision 0)
+++ oln/morpho/stat.hh (revision 0)
@@ -0,0 +1,136 @@
+// 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 OLENA_MORPHO_STAT_HH
+# define OLENA_MORPHO_STAT_HH
+
+# include <mlc/cmp.hh>
+# include <ntg/bin.hh>
+# include <oln/basics.hh>
+# include <oln/funobj/accum.hh>
+
+
+namespace oln {
+
+ namespace morpho {
+
+
+ /// Local min on a function.
+
+ template <typename I, typename W>
+ oln_type_of(I, value) local_min(const abstract::image<I>& input,
+ const oln_type_of(I, point)& p,
+ const abstract::window<W>& win)
+ {
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+
+ oln_wn_type_of(W, fwd_iter) q(win);
+ funobj::min_accumulator<oln_type_of(I, value)> minval;
+
+ for_all_q_of_p (q, p)
+ if (input.hold(q))
+ minval(input[q]);
+
+ return minval;
+ }
+
+
+ template <typename I>
+ oln_type_of(I, value) local_min_nbh(const abstract::image_with_nbh<I>& input,
+ const oln_type_of(I, point)& p)
+ {
+ oln_type_of(I, niter) n(input);
+ funobj::min_accumulator_init<oln_type_of(I, value)> minval(input[p]);
+
+ for_all_n_of_p (n, p)
+ if (input.hold(n))
+ minval(input[n]);
+
+ return minval;
+ }
+
+
+ /// Local min on a set.
+
+ template <typename I, typename W>
+ bool local_min(const abstract::binary_image<I>& input,
+ const oln_type_of(I, point)& p,
+ const abstract::window<W>& win)
+ {
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+
+ oln_wn_type_of(W, fwd_iter) q(win);
+ for_all_q_of_p (q, p)
+ if (input.hold(q) and not input[q])
+ return false;
+ return true;
+ }
+
+
+ /// Local max on a function.
+
+ template <typename I, typename W>
+ oln_type_of(I, value) local_max(const abstract::image<I>& input,
+ const oln_type_of(I, point)& p,
+ const abstract::window<W>& win)
+ {
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+
+ oln_wn_type_of(W, fwd_iter) q(win);
+ funobj::max_accumulator<oln_type_of(I, value)> maxval;
+
+ for_all_q_of_p (q, p)
+ if (input.hold(q))
+ maxval(input[q]);
+
+ return maxval;
+ }
+
+
+ /// Local max on a set.
+
+ template <typename I, typename W>
+ bool local_max(const abstract::binary_image<I>& input,
+ const oln_type_of(I, point)& p,
+ const abstract::window<W>& win)
+ {
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+
+ oln_wn_type_of(W, fwd_iter) q(win);
+ for_all_q_of_p (q, p)
+ if (input.hold(q) and input[q])
+ return true;
+ return false;
+ }
+
+
+ } // end of namespace morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_MORPHO_STAT_HH
Index: oln/morpho/erosion.hh
===================================================================
--- oln/morpho/erosion.hh (revision 0)
+++ oln/morpho/erosion.hh (revision 0)
@@ -0,0 +1,143 @@
+// Copyright (C) 2001-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_MORPHO_EROSION_HH
+# define OLENA_MORPHO_EROSION_HH
+
+# include <mlc/cmp.hh>
+# include <mlc/to_string.hh>
+
+# include <oln/utils/record.hh>
+# include <oln/basics.hh>
+# include <oln/core/2d/window2d.hh>
+# include <oln/morpho/tags.hh>
+
+
+namespace oln {
+
+ namespace morpho {
+
+
+
+ // Fwd decl of erosion's facade.
+
+ template<typename K, typename I, typename W>
+ oln_type_of(I, concrete) erosion(const tag::kind<K>& kind,
+ const abstract::image<I>& input,
+ const abstract::window<W>& win);
+
+ // Facade for classical erosion.
+
+ template<typename I, typename W>
+ oln_type_of(I, concrete) erosion(const abstract::image<I>& input,
+ const abstract::window<W>& win)
+ {
+ return erosion(tag::classical, input, win);
+ }
+
+
+ namespace impl {
+
+ // generic
+
+ template<typename K, typename I, typename W>
+ oln_type_of(I, concrete) erosion_(const tag::kind<K>& kind,
+ const abstract::image<I>& input,
+ const abstract::window<W>& win)
+ {
+ entering("->generic");
+ registering(input, "input");
+
+ oln_type_of(I, concrete) output(input.size(), "output");
+
+ oln_type_of(I, fwd_piter) p(input.size());
+ for_all_p (p)
+ output[p] = kind.min(input, p, win);
+
+ exiting("->generic");
+ return output;
+ }
+
+
+
+ // win is a 2D rectangle
+
+ template<typename K, typename I>
+ oln_type_of(I, concrete) erosion_(const tag::kind<K>& kind,
+ const abstract::image2d<I>& input,
+ const win_rectangle2d& win)
+ {
+ entering("->(image2d,win_rectangle2d)");
+ registering(input, "input");
+
+ oln_type_of(I, concrete) temp("temp"), output("output");
+
+ win_hline2d hline(win.width); // FIXME: Cf. Soille, use L(i,dp)
+ win_vline2d vline(win.height);
+
+ temp = erosion(kind, input, hline);
+ output = erosion(kind, temp, vline);
+
+ exiting("->(image2d,win_rectangle2d)");
+ return output;
+ }
+
+
+ // add some other impls here...
+
+
+ } // end of namespace oln::morpho::impl
+
+
+
+
+ /// Generic erosion (facade).
+
+ template<typename K, typename I, typename W>
+ oln_type_of(I, concrete) erosion(const tag::kind<K>& kind,
+ const abstract::image<I>& input,
+ const abstract::window<W>& win)
+ {
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+ entering("morpho::erosion");
+
+ oln_type_of(I, concrete) output("output");
+ output = impl::erosion_(kind, input.exact(), win.exact());
+
+ exiting("morpho::erosion");
+ return output;
+ }
+
+
+
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_MORPHO_EROSION_HH
Index: oln/morpho/geodesic_erosion.hh
===================================================================
--- oln/morpho/geodesic_erosion.hh (revision 0)
+++ oln/morpho/geodesic_erosion.hh (revision 0)
@@ -0,0 +1,112 @@
+// 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_MORPHO_GEODESIC_EROSION_HH
+# define OLENA_MORPHO_GEODESIC_EROSION_HH
+
+# include <mlc/cmp.hh>
+# include <mlc/contract.hh>
+
+# include <oln/utils/record.hh>
+# include <oln/core/pw/all.hh>
+# include <oln/core/gen/image_with_nbh.hh> // FIXME: should be in core/abstract/ (?)
+# include <oln/morpho/elementary_erosion.hh>
+
+
+
+// FIXME: such routines should be written somewhere else...
+
+template <typename L, typename R>
+bool operator >= (const oln::abstract::image<L>& lhs,
+ const oln::abstract::image<R>& rhs)
+{
+ return oln::pw::check(oln::p_value(lhs) >= oln::p_value(rhs));
+}
+
+
+
+namespace oln {
+
+ namespace morpho {
+
+
+
+ /// Generic geodesic erosion.
+
+ template<typename K, typename I, typename II>
+ oln_type_of(I, concrete) geodesic_erosion(const tag::kind<K>& kind,
+ const abstract::image_with_nbh<I>& marker,
+ const abstract::image<II>& mask)
+ {
+ // FIXME: later, test the short code:
+ // FIXME: return max(elementary_erosion(kind, marker), mask)
+
+ // FIXME: and even later:
+ // FIXME: return elementary_erosion(kind, marker) _max_ mask
+
+ mlc::eq<oln_type_of(I, grid), oln_type_of(II, grid)>::ensure();
+
+ entering("morpho::geodesic_erosion");
+
+ registering(marker, "marker");
+ registering(mask, "mask");
+ precondition(marker.size() == mask.size()
+ and marker >= mask);
+
+ oln_type_of(I, concrete)
+ ero("ero"),
+ output(marker.size(), "output");
+
+ ero = elementary_erosion(kind, marker);
+
+ // FIXME: replace code below by a pw::max...
+ oln_type_of(I, fwd_piter) p(marker.size());
+ for_all_p (p)
+ output[p] = std::max(ero[p].value(), mask[p].value());
+
+ exiting("morpho::geodesic_erosion");
+ return output;
+ }
+
+
+ /// Generic classical geodesic erosion.
+
+ template<typename I, typename II>
+ oln_type_of(I, concrete) geodesic_erosion(const abstract::image_with_nbh<I>& marker,
+ const abstract::image<II>& mask)
+ {
+ return geodesic_erosion(tag::classical, marker, mask);
+ }
+
+
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_MORPHO_GEODESIC_EROSION_HH
2005-04-27 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Files in oln/morpho move to 'trash' since inheritance in
image operators will soon be no longer in use.
* oln/morpho/*.hh: Rename as...
* oln/morpho/*.trash: ...this.
* oln/morpho/*.inc: Rename as...
* oln/morpho/*.inctrash: ...this.
* oln/convert/nbh_to_se.hh: Remove cause meaningless.
The changes below are for safety purpose; we should ensure
that some (now commented) features are no more in use.
* oln/core/2d/image2d.hh (operator=(box)): Comment.
(operator=(image_like_): Comment.
(image2d(const image2d&)): Add decl to help compiler.
* oln/core/box.hh (operator I): New.
(operator=(box<II>): Comment.
(operator=(image_like_<I>)): Comment.
(operator=(image_like_<II>)): Comment.
(operator=(image<II>)): Comment.
* oln/utils/clone.hh: Update.
Index: oln/morpho/reconstruction.hh
===================================================================
--- oln/morpho/reconstruction.hh (revision 166)
+++ oln/morpho/reconstruction.hh (working copy)
@@ -1,227 +0,0 @@
-// Copyright (C) 2001, 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 filek 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_MORPHO_RECONSTRUCTION_HH
-# define OLENA_MORPHO_RECONSTRUCTION_HH
-
-# include <queue>
-
-# include <mlc/cmp.hh>
-# include <mlc/contract.hh>
-
-# include <oln/convert/nbh_to_se.hh>
-
-# include <oln/core/abstract/image_operator.hh>
-# include <oln/core/abstract/neighborhood.hh>
-
-# include <oln/level/compare.hh>
-
-# include <oln/morpho/splitse.hh>
-# include <oln/morpho/stat.hh>
-
-# include <oln/utils/clone.hh>
-
-namespace oln {
-
-
- namespace tag {
-
- template <typename Op> struct oper {};
-
- struct by_dilation : public oper< by_dilation > {};
- struct by_erosion : public oper< by_erosion > {};
-
-
- template <typename A> struct algo {};
-
- struct sequential : public algo< sequential > {};
- struct hybrid : public algo< hybrid > {};
-
- } // end of namespace oln::morpho::tag
-
-
-
- namespace morpho {
- template <typename I1, typename I2> struct reconstruction_ret;
- } // end of namespace oln::morpho
-
- // super_type
-
- template <typename I1, typename I2>
- struct set_super_type< morpho::reconstruction_ret<I1, I2> >
- {
- typedef oln_type_of(I1, concrete) output_type;
-
- typedef morpho::reconstruction_ret<I1,I2> self_type;
- typedef abstract::image_binary_operator<output_type, I1, I2, self_type > ret;
- };
-
- namespace morpho {
-
- // Reconstruction as a 'classical' procedure returning an image (do not
- // use it; prefer morpho::reconstruction).
-
- namespace proc {
-
- // FIXME: ...
-
- } // end of namespace oln::morpho::proc
-
-
- template <typename I1, typename I2>
- struct reconstruction_ret :
- // FIXME: oln_super_of_
- public oln::internal::get_super_type< reconstruction_ret<I1,I2> >::ret
- {
- typedef reconstruction_ret<I1, I2> self_type;
- typedef typename oln::internal::get_super_type<self_type>::ret super_type;
-
- box<const I1> marker;
- box<const I2> mask;
-
- reconstruction_ret(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask) :
- super_type(marker, mask),
- marker(marker),
- mask(mask)
- {
- }
-
- const oln_type_of(I1, neighb)& impl_nbh_get() const
- {
- return marker.nbh_get();
- }
-
- };
-
- } // end of namespace morpho
-
-} // end of namespace oln
-
-# include <oln/morpho/reconstruction_canvas.inc>
-
-namespace oln {
-
- namespace morpho {
-
- namespace impl {
-
- template<typename Op, typename A, typename I1, typename I2>
- struct generic_reconstruction;
-
- } // end of namespace impl
-
- } // end of namespace morpho
-
-} // end of namespace oln
-
-# include <oln/morpho/reconstruction_by_dilation.inc>
-# include <oln/morpho/reconstruction_by_erosion.inc>
-
-namespace oln {
-
- namespace morpho {
-
- namespace impl {
-
- // Generic implementation of reconstruction (routine).
-
- template<typename Op, typename A, typename I1, typename I2>
- reconstruction_ret<I1,I2>
- reconstruction(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask)
- {
- generic_reconstruction<Op, A, I1, I2> tmp(marker, mask);
- tmp.run();
- return tmp;
- }
-
- } // end of namespace impl
-
- /// Generic reconstruction (facade).
-
- template<typename Op, typename I1, typename I2, typename A>
- reconstruction_ret<I1,I2>
- reconstruction(const tag::oper<Op>& oper_,
- const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask,
- const tag::algo<A>& algo_)
- {
- return impl::reconstruction<Op,A>(marker.exact(), mask.exact());
- }
-
- // by dilation
-
- template<typename I1, typename I2, typename A>
- reconstruction_ret<I1,I2>
- reconstruction_by_dilation(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask,
- const tag::algo<A>& algo_)
- {
- mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
- precondition(marker.size() == mask.size());
- return reconstruction(tag::by_dilation(), marker, mask, algo_);
- }
-
- template<typename I1, typename I2>
- reconstruction_ret<I1,I2>
- reconstruction_by_dilation(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask)
- {
- mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
- precondition(marker.size() == mask.size());
- return reconstruction(tag::by_dilation(), marker, mask, tag::hybrid());
- }
-
- // by erosion
-
- template<typename I1, typename I2, typename A>
- reconstruction_ret<I1,I2>
- reconstruction_by_erosion(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask,
- const tag::algo<A>& algo_)
- {
- mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
- precondition(marker.size() == mask.size());
- return reconstruction(tag::by_erosion(), marker, mask, algo_);
- }
-
- template<typename I1, typename I2>
- reconstruction_ret<I1,I2>
- reconstruction_by_erosion(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask)
- {
- mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
- precondition(marker.size() == mask.size());
- return reconstruction(tag::by_erosion(), marker, mask, tag::hybrid());
- }
-
- } // end of namespace oln::morpho
-
-} // end of namespace oln
-
-#endif // ! OLENA_MORPHO_RECONSTRUCTION_HH
Index: oln/morpho/reconstruction_by_erosion.inc
===================================================================
--- oln/morpho/reconstruction_by_erosion.inc (revision 166)
+++ oln/morpho/reconstruction_by_erosion.inc (working copy)
@@ -1,141 +0,0 @@
-// 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 filek 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.
-
-namespace oln {
-
- namespace morpho {
-
- namespace impl {
-
- // Sequential version
-
- template<typename I1, typename I2>
- struct generic_reconstruction <tag::by_erosion, tag::sequential, I1, I2>
- : public generic_reconstruction_canvas<I1, I2, tag::sequential,
- generic_reconstruction<tag::by_erosion, tag::sequential, I1, I2> >
- {
- typedef generic_reconstruction<tag::by_erosion,
- tag::sequential, I1,I2> self_type;
- typedef generic_reconstruction_canvas<I1, I2, tag::sequential,
- self_type> super_type;
-
- generic_reconstruction(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask) :
- super_type(marker, mask)
- {
- }
-
-
- void impl_bkd_loop_body()
- {
- this->output[this->bkd_p] = ntg::max(morpho::min(this->output,
- this->bkd_p,
- this->win_minus),
- this->mask[this->bkd_p].value());
- }
-
- void impl_fwd_loop_body()
- {
- this->output[this->fwd_p] = ntg::max(morpho::min(this->output,
- this->fwd_p,
- this->win_plus),
- this->mask[this->fwd_p].value());
- }
-
- void impl_preconditions()
- {
- precondition(level::is_greater_or_equal(this->marker, this->mask));
- }
-
- };
-
- // Hybrid version
-
- template<typename I1, typename I2>
- struct generic_reconstruction <tag::by_erosion, tag::hybrid, I1, I2>
- : public generic_reconstruction_canvas<I1, I2, tag::hybrid,
- generic_reconstruction<tag::by_erosion, tag::hybrid, I1, I2> >
- {
- typedef generic_reconstruction<tag::by_erosion,
- tag::hybrid, I1,I2> self_type;
- typedef generic_reconstruction_canvas<I1, I2, tag::hybrid,
- self_type> super_type;
-
- generic_reconstruction(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask) :
- super_type(marker, mask)
- {
- }
-
-
-
- void impl_bkd_loop_body()
- {
- this->output[this->bkd_p] = ntg::max(morpho::min(this->work,
- this->bkd_p,
- this->win_minus),
- this->mask[this->bkd_p].value());
- }
-
- void impl_fwd_loop_body()
- {
- this->output[this->fwd_p] = ntg::max(morpho::min(this->work,
- this->fwd_p,
- this->win_plus),
- this->mask[this->fwd_p].value());
- }
-
- void impl_fifo_loop_body()
- {
- if ((this->output[this->q] > this->output[this->p]) &&
- (this->mask[this->q] != this->output[this->q]))
- {
- this->output[this->q] = ntg::min(this->output[this->p].value(),
- this->mask[this->q].value());
- this->fifo.push(this->q);
- }
- }
-
- bool impl_exist_init()
- {
- return this->output.hold(this->q) &&
- (this->output[this->q] > this->output[this->bkd_p]) &&
- (this->output[this->q] > this->mask[this->q]);
- }
-
- void impl_preconditions()
- {
- precondition(level::is_greater_or_equal(this->marker, this->mask));
- }
-
- };
-
- }
-
- }
-
-}
Index: oln/morpho/splitse.hh
===================================================================
--- oln/morpho/splitse.hh (revision 166)
+++ oln/morpho/splitse.hh (working copy)
@@ -1,209 +0,0 @@
-// Copyright (C) 2001, 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_MORPHO_SPLITSE_HH
-# define OLENA_MORPHO_SPLITSE_HH
-
-# include <oln/basics.hh>
-
-# include <oln/core/1d/size1d.hh>
-# include <oln/core/2d/size2d.hh>
-# include <oln/core/3d/size3d.hh>
-
-# include <oln/core/abstract/window.hh>
-# include <oln/core/abstract/window.hh>
-
-
-namespace oln {
- namespace morpho {
-
- template <class S>
- struct dim_traits
- {
- };
-
- template <>
- struct dim_traits<size1d>
- {
- enum {dim = 1};
- };
-
- template <>
- struct dim_traits<size2d>
- {
- enum {dim = 2};
- };
-
- template <>
- struct dim_traits<size3d>
- {
- enum {dim = 3};
- };
-
- /*!
- ** \brief Get a sub part of a window.
- **
- ** \param E Exact type of the window.
- **
- ** \arg win The window.
- **
- ** A point p take part of the new window if it exists
- ** a i that belongs to [[0..dim-1]] like p(i) < 0 and for all j
- ** that belongs to [[0..i-1]] p(j) = 0.
- **
- */
-
-
- template<class W>
- W
- get_plus_win_only(const W& win) // FIXME: abstract::window<W>& win)
- {
- W out;
- for (unsigned i = 0; i < win.card(); ++i)
- {
- const oln_wn_type_of(W, dpoint)& dp = win.get_dp()[i];
- unsigned n;
- for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n)
- if (dp.nth(n) < 0) {
- out.add(dp);
- break;
- } else if (dp.nth(n) > 0) {
- break;
- }
- }
- return out;
- }
-
- /*!
- ** \brief Get a sub part of a window.
- **
- ** \param W Exact type of the window.
- **
- ** \arg win The window.
- **
- ** A point p take part of the new window if it exists
- ** a i that belongs to [[0..dim-1]] like p(i) < 0 and for all j
- ** that belongs to [[0..i-1]] p(j) = 0 or if for all i that
- ** belongs to [[0..dim-1]] p(i) = 0.
- **
- */
- template<class W>
- W
- get_plus_win_p(const W& win) // abstract::window<W>& win)
- {
- W out;
- for (unsigned i = 0; i < win.card(); ++i)
- {
- const oln_wn_type_of(W, dpoint)& dp = win.get_dp()[i];
- unsigned n;
- for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n)
- if (dp.nth(n) < 0) {
- out.add(dp);
- break;
- } else if (dp.nth(n) > 0) {
- break;
- }
- // All p.nth(n) are 0.
- if (n == dim_traits<oln_wn_type_of(W, size)>::dim)
- out.add(dp);
- }
- return out;
- }
-
- /*!
- ** \brief Get a sub part of a window.
- **
- ** \param W Exact type of the window.
- **
- ** \arg win The window.
- **
- ** A point p take part of the new window if it exists
- ** a i that belongs to [[0..dim-1]] like p(i) > 0 and for all j
- ** that belongs to [[0..i-1]] p(j) = 0.
- **
- */
- template<class W>
- W
- get_minus_win_only(const W& win) // abstract::window<W>& win)
- {
- W out;
- for (unsigned i = 0; i < win.card(); ++i)
- {
- const oln_wn_type_of(W, dpoint)& dp = win.get_dp()[i];
- unsigned n;
- for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n)
- if (dp.nth(n) > 0) {
- out.add(dp);
- break;
- } else if (dp.nth(n) < 0) {
- break;
- }
- }
- return out;
- }
-
- /*!
- ** \brief Get a sub part of a window.
- **
- ** \param W Exact type of the window.
- **
- ** \arg win The window.
- **
- ** A point p take part of the new window if it exists
- ** a i that belongs to [[0..dim-1]] like p(i) > 0 and for all j
- ** that belongs to [[0..i-1]] p(j) = 0 or if for all i that
- ** belongs to [[0..dim-1]] p(i) = 0.
- **
- */
- template<class W>
- W
- get_minus_win_p(const W& win) // abstract::window<W>& win)
- {
- W out;
- for (unsigned i = 0; i < win.card(); ++i)
- {
- const oln_wn_type_of(W, dpoint)& dp = win.get_dp()[i];
- unsigned n;
- for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n)
- if (dp.nth(n) > 0) {
- out.add(dp);
- break;
- } else if (dp.nth(n) < 0) {
- break;
- }
- // All p.nth(n) are 0.
- if (n == dim_traits<oln_wn_type_of(W, size)>::dim)
- out.add(dp);
- }
- return out;
- }
-
- } // end of namespace oln::morpho
-
-} // end of namespace oln
-
-#endif // ! OLENA_MORPHO_SPLITSE_HH
Index: oln/morpho/cc_tarjan.hh
===================================================================
--- oln/morpho/cc_tarjan.hh (revision 166)
+++ oln/morpho/cc_tarjan.hh (working copy)
@@ -1,233 +0,0 @@
-// 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_CC_TARJAN_HH
-# define OLENA_CC_TARJAN_HH
-
-# include <vector>
-
-# include <oln/basics2d.hh>
-# include <oln/core/abstract/image_operator.hh>
-# include <oln/level/fill.hh>
-
-//
-// Based on "Ruminations on Tarjan's Union-Find algorithm and connected
-// operators" of Thierry Geraud.
-//
-
-
-namespace oln {
-
- // fwd decl
- namespace morpho {
- template <typename T, typename I, typename E> struct cc_tarjan_ret;
- }
-
- // FIXME: this macro is waiting for the mute.
- // (we may use a property to do it)
- #define tmp_mute(I, T) image2d< T >
-
- // category
- template <typename T, typename I, typename E>
- struct set_category< morpho::cc_tarjan_ret<T,I,E> >
- { typedef category::image ret; };
-
- // super_type
- template <typename T, typename I, typename E>
- 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> >
- ret;
- };
-
-
- namespace morpho {
-
- template <typename T, typename I, typename E>
- 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> >
- 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())
- {
- }
-
- };
-
-
- namespace impl {
-
-
- namespace misc {
-
- // FIXME: This code should be generalized.
- // While iterating on image and then on a neighborhood, here we do
- // not want to see the neighborhood points ever seen.
- std::vector<dpoint2d> get_superior(const neighborhood2d& n)
- {
- std::vector<dpoint2d> output;
- for (unsigned i = 0; i < n.card(); ++i)
- {
- dpoint2d dp = n.dp(i);
- if (dp.row() < 0 || (dp.row() == 0 && dp.col() < 0))
- output.push_back(dp);
- }
- return output;
- }
-
- std::vector<dpoint2d> get_inferior(const neighborhood2d& n)
- {
- std::vector<dpoint2d> output;
- for (unsigned i = 0; i < n.card(); ++i)
- {
- dpoint2d dp = n.dp(i);
- if (dp.row() > 0 || (dp.row() == 0 && dp.col() > 0))
- output.push_back(dp);
- }
- return output;
- }
-
- } // end of misc namespace
-
-
- template <typename T, typename I, typename N>
- struct generic_cc_tarjan : public cc_tarjan_ret<T, I, N>
- {
- typedef cc_tarjan_ret<T, I, N> super_type;
- typedef typename super_type::output_type output_type;
-
- tmp_mute(I, oln_type_of(I, point)) parent;
- T ncomps;
-
- generic_cc_tarjan(const abstract::image<I>& input,
- const abstract::neighborhood<N>& ng) :
- super_type(input, ng),
- parent(input.size())
- {
- }
-
- void impl_run()
- {
- mlc::eq<oln_type_of(I, size), oln_type_of(N, size)>::ensure();
-
- output_type tmp(this->input.size()); // FIXME: trick
- this->output = tmp;
-
- first_pass();
- second_pass();
- }
-
- void first_pass()
- {
- std::vector<dpoint2d> neighb = misc::get_inferior(this->ng);
- oln_type_of(I, bkd_piter) p(this->input.size());
- for_all_p (p)
- if (this->input[p])
- {
- make_set(p);
- for (unsigned v = 0; v < neighb.size(); ++v)
- {
- oln_type_of(I, point) n = oln_type_of(I, point)(p) + neighb[v];
- if (this->input[n])
- do_union(n, p);
- }
- }
- }
-
- void second_pass()
- {
- oln_type_of(I, fwd_piter) p(this->input.size());
- level::fill(this->output, 0);
- ncomps = 0;
- for_all_p (p)
- if (this->input[p])
- {
- oln_type_of(I, point) q = parent[p];
- // FIXME: test if ncomps > T::max()
- this->output[p] = (q == p ? ++ncomps : this->output[q]);
- }
- }
-
- void make_set(const oln_type_of(I, point)& x)
- {
- parent[x] = x;
- }
-
- oln_type_of(I, point) find_root(const oln_type_of(I, point)& x)
- {
- if (parent[x] != x)
- {
- parent[x] = find_root(parent[x]);
- return parent[x];
- }
- return x;
- }
-
- 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
-
-
- /// Connected component labelling via Tarjan Union-Find generic routine.
-
- // T is the component label type (usually unsigned).
- template<typename T, typename I, typename N>
- cc_tarjan_ret<T, I, N> cc_tarjan(const abstract::image<I>& input,
- const abstract::neighborhood<N>& ng)
- {
- impl::generic_cc_tarjan<T, I, N> tmp(input, ng);
- tmp.run();
- return tmp;
- }
-
-
- } // end of namespace oln::morpho
-
-} // end of namespace oln
-
-
-#endif // ! OLENA_CC_TARJAN_HH
Index: oln/morpho/reconstruction_canvas.inc
===================================================================
--- oln/morpho/reconstruction_canvas.inc (revision 166)
+++ oln/morpho/reconstruction_canvas.inc (working copy)
@@ -1,238 +0,0 @@
-// 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 filek 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.
-
-
-namespace oln {
-
- namespace morpho {
-
- namespace impl {
-
- template <typename I1, typename I2, typename A, typename E>
- struct generic_reconstruction_canvas;
-
- template <typename I1, typename I2, typename E>
- struct generic_reconstruction_canvas<I1, I2, tag::sequential, E> :
- public reconstruction_ret<I1, I2>
- {
- typedef reconstruction_ret<I1, I2> super_type;
- typedef oln_type_of(I1, neighb) nbh_type;
- typedef oln_type_of(I1, concrete) output_type;
-
- E& exact__()
- {
- return *(E*)(void*)(this);
- }
-
- void bkd_loop_body()
- {
- this->exact__().impl_bkd_loop_body();
- }
- void fwd_loop_body()
- {
- this->exact__().impl_fwd_loop_body();
- }
-
- void preconditions()
- {
- mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
- precondition(this->marker.size() == this->mask.size());
- this->exact__().impl_preconditions();
- }
-
- void init()
- {
- // no call to impl_init here because this canvas can't be generalized yet.
- this->output = utils::clone(this->marker);
- this->work = utils::clone(this->marker);
-
- win_plus = get_plus_win_p(convert::nbh_to_cse(this->marker.nbh_get()));
- win_minus = get_minus_win_p(convert::nbh_to_cse(this->marker.nbh_get()));
- }
-
- bool is_stable()
- {
- // same explanation as above
- return level::is_equal(this->work, this->output);
- }
-
- void impl_run()
- {
- this->preconditions();
- this->init();
- for (;;)
- {
- for_all_p (fwd_p)
- this->fwd_loop_body();
- for_all_p (bkd_p)
- this->bkd_loop_body();
- if (this->is_stable())
- return;
- work = utils::clone(this->output);
- }
- }
-
- protected:
-
- generic_reconstruction_canvas(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask) :
- super_type(marker, mask),
- bkd_p(marker.size()),
- fwd_p(marker.size())
- {
- }
-
-
- oln_type_of(I1, bkd_piter) bkd_p;
- oln_type_of(I1, fwd_piter) fwd_p;
-
- oln_nbh_type_of(nbh_type, window) win_plus;
- oln_nbh_type_of(nbh_type, window) win_minus;
-
- box<oln_type_of(I1, concrete)> work;
- };
-
- template <typename I1, typename I2, typename E>
- struct generic_reconstruction_canvas<I1, I2, tag::hybrid, E> :
- public reconstruction_ret<I1, I2>
- {
- typedef reconstruction_ret<I1, I2> super_type;
- typedef oln_type_of(I1, neighb) nbh_type;
- typedef oln_nbh_type_of(nbh_type, window) window_type;
- typedef oln_type_of(I1, concrete) output_type;
-
- E& exact__()
- {
- return *(E*)(void*)(this);
- }
-
-
- bool exist_init()
- {
- for (unsigned i = 0; i < win_minus.card(); ++i)
- {
- q = win_minus.get_dp()[i] + (oln_type_of(I1, point))bkd_p;
- if (this->exact__().impl_exist_init())
- return true;
- }
- return false;
- }
-
- void bkd_loop_body()
- {
- this->exact__().impl_bkd_loop_body();
- }
- void fwd_loop_body()
- {
- this->exact__().impl_fwd_loop_body();
- }
-
- void fifo_loop_body()
- {
- this->exact__().impl_fifo_loop_body();
- }
-
- void preconditions()
- {
- mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
- precondition(this->marker.size() == this->mask.size());
- this->exact__().impl_preconditions();
- }
-
- void init()
- {
- output_type tmp(this->marker.size());
-
- this->output = tmp;
- this->work = utils::clone(this->marker);
-
- win_plus = get_plus_win_p(convert::nbh_to_cse(this->marker.nbh_get()));
- win_minus = get_minus_win_p(convert::nbh_to_cse(this->marker.nbh_get()));
- }
-
- void impl_run()
- {
- this->preconditions();
- this->init();
-
- for_all_p (fwd_p)
- this->fwd_loop_body();
-
- for_all_p (bkd_p)
- {
- bkd_loop_body();
- if (exist_init())
- fifo.push(bkd_p);
- }
- // Propagation Step
- while (!fifo.empty())
- {
- p = fifo.front();
- fifo.pop();
-
- window_type win = convert::nbh_to_se(this->marker.nbh_get());
- for (unsigned i = 0; i < win.card(); ++i)
- {
- q = win.get_dp()[i] + p;
-
- if (this->output.hold(q))
- fifo_loop_body();
- }
- }
- }
-
- protected:
-
- generic_reconstruction_canvas(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask) :
- super_type(marker, mask),
- bkd_p(marker.size()),
- fwd_p(marker.size())
- {
- }
-
-
- oln_type_of(I1, bkd_piter) bkd_p;
- oln_type_of(I1, fwd_piter) fwd_p;
-
- oln_type_of(I1, point) p;
- oln_type_of(I1, point) q;
-
- window_type win_plus;
- window_type win_minus;
-
- box<oln_type_of(I1, concrete)> work;
-
- std::queue<oln_type_of(I1, point) > fifo;
-
- };
-
- } // end of namespace impl
-
- } // end of namespace morpho
-
-} // end of namespace oln
Index: oln/morpho/closing.hh
===================================================================
--- oln/morpho/closing.hh (revision 166)
+++ oln/morpho/closing.hh (working copy)
@@ -1,165 +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 OLENA_MORPHO_CLOSING_HH
-# define OLENA_MORPHO_CLOSING_HH
-
-# include <mlc/cmp.hh>
-# include <mlc/to_string.hh>
-
-# include <oln/core/abstract/image_operator.hh>
-
-# include <oln/morpho/dilation.hh>
-# include <oln/morpho/erosion.hh>
-# include <oln/core/2d/window2d.hh>
-
-
-namespace oln {
-
-
- // fwd decl
-
- namespace morpho {
- template <typename I> struct closing_ret;
- }
-
- // super_type
-
- template <typename I>
- struct set_super_type< morpho::closing_ret<I> >
- {
- typedef oln_type_of(I, concrete) output_type;
-
- typedef morpho::closing_ret<I> self_type;
- typedef abstract::image_unary_operator<output_type, I, self_type > ret;
- };
-
-
-
-
- namespace morpho {
-
-
-
- // Closing as a 'classical' procedure returning an image (do not
- // use it; prefer morpho::closing).
-
- namespace proc {
-
- template<typename I, typename W>
- oln_type_of(I, concrete) closing(const abstract::image<I>& input,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
- oln_type_of(I, concrete) output(input.size());
- output = morpho::erosion(morpho::dilation(input, win), win);
- return output;
- }
-
- } // end of namespace oln::morpho::proc
-
-
-
- /// Closing return type.
-
- template <typename I>
- struct closing_ret : public oln_super_of_(closing_ret<I>)
- {
- typedef oln_super_of(closing_ret<I>) super_type;
-
- closing_ret(const abstract::image<I>& input) :
- super_type(input)
- {
- }
-
- };
-
-
- // Various implementation.
-
- namespace impl {
-
-
- /// Generic implementation of closing (type).
-
- template <typename I, typename W>
- struct generic_closing : public closing_ret<I>
- {
- typedef closing_ret<I> super_type;
- // FIXME: typedef oln_type_of(super_type, output) output_type;
-
- const W& win;
-
- generic_closing(const abstract::image<I>& input,
- const abstract::window<W>& win) :
- super_type(input),
- win(win.exact())
- {
- }
-
- void impl_run()
- {
- oln_type_of(super_type, output) tmp(input.size());
- tmp = morpho::erosion(morpho::dilation(input, win), win);
- output = tmp;
- }
- };
-
- // Generic implementation of closing (routine).
-
- template<typename I, typename W>
- closing_ret<I> closing(const abstract::image<I>& input,
- const abstract::window<W>& win)
- {
- impl::generic_closing<I,W> tmp(input, win);
- tmp.run();
- return tmp;
- }
-
- // FIXME: Add specialized implementations.
-
- } // end of namespace oln::morpho::impl
-
-
- /// Generic closing (facade).
-
- template<typename I, typename W>
- closing_ret<I> closing(const abstract::image<I>& input,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
- return impl::closing(input.exact(), win.exact());
- }
-
-
- } // end of namespace oln::morpho
-
-
-} // end of namespace oln
-
-
-#endif // ! OLENA_MORPHO_CLOSING_HH
Index: oln/morpho/opening.hh
===================================================================
--- oln/morpho/opening.hh (revision 166)
+++ oln/morpho/opening.hh (working copy)
@@ -1,165 +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 OLENA_MORPHO_OPENING_HH
-# define OLENA_MORPHO_OPENING_HH
-
-# include <mlc/cmp.hh>
-# include <mlc/to_string.hh>
-
-# include <oln/core/abstract/image_operator.hh>
-
-# include <oln/morpho/dilation.hh>
-# include <oln/morpho/erosion.hh>
-# include <oln/core/2d/window2d.hh>
-
-
-namespace oln {
-
-
- // fwd decl
-
- namespace morpho {
- template <typename I> struct opening_ret;
- }
-
- // super_type
-
- template <typename I>
- struct set_super_type< morpho::opening_ret<I> >
- {
- typedef oln_type_of(I, concrete) output_type;
-
- typedef morpho::opening_ret<I> self_type;
- typedef abstract::image_unary_operator<output_type, I, self_type > ret;
- };
-
-
-
-
- namespace morpho {
-
-
-
- // Opening as a 'classical' procedure returning an image (do not
- // use it; prefer morpho::opening).
-
- namespace proc {
-
- template<typename I, typename W>
- oln_type_of(I, concrete) opening(const abstract::image<I>& input,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
- oln_type_of(I, concrete) output(input.size());
- output = morpho::dilation(morpho::erosion(input, win), win);
- return output;
- }
-
- } // end of namespace oln::morpho::proc
-
-
-
- /// Opening return type.
-
- template <typename I>
- struct opening_ret : public oln_super_of_(opening_ret<I>)
- {
- typedef oln_super_of(opening_ret<I>) super_type;
-
- opening_ret(const abstract::image<I>& input) :
- super_type(input)
- {
- }
-
- };
-
-
- // Various implementation.
-
- namespace impl {
-
-
- /// Generic implementation of opening (type).
-
- template <typename I, typename W>
- struct generic_opening : public opening_ret<I>
- {
- typedef opening_ret<I> super_type;
- // FIXME: typedef oln_type_of(super_type, output) output_type;
-
- const W& win;
-
- generic_opening(const abstract::image<I>& input,
- const abstract::window<W>& win) :
- super_type(input),
- win(win.exact())
- {
- }
-
- void impl_run()
- {
- oln_type_of(super_type, output) tmp(input.size());
- tmp = morpho::dilation(morpho::erosion(input, win), win);
- output = tmp;
- }
- };
-
- // Generic implementation of opening (routine).
-
- template<typename I, typename W>
- opening_ret<I> opening(const abstract::image<I>& input,
- const abstract::window<W>& win)
- {
- impl::generic_opening<I,W> tmp(input, win);
- tmp.run();
- return tmp;
- }
-
- // FIXME: Add specialized implementations.
-
- } // end of namespace oln::morpho::impl
-
-
- /// Generic opening (facade).
-
- template<typename I, typename W>
- opening_ret<I> opening(const abstract::image<I>& input,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
- return impl::opening(input.exact(), win.exact());
- }
-
-
- } // end of namespace oln::morpho
-
-
-} // end of namespace oln
-
-
-#endif // ! OLENA_MORPHO_OPENING_HH
Index: oln/morpho/dilation.hh
===================================================================
--- oln/morpho/dilation.hh (revision 166)
+++ oln/morpho/dilation.hh (working copy)
@@ -1,202 +0,0 @@
-// Copyright (C) 2001, 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 filek 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_MORPHO_DILATION_HH
-# define OLENA_MORPHO_DILATION_HH
-
-# include <mlc/cmp.hh>
-
-# include <oln/core/abstract/image_operator.hh>
-# include <oln/morpho/stat.hh>
-
-
-namespace oln {
-
- namespace morpho {
-
-
-
- namespace proc {
-
- /// Dilation as a procedure (do not use it; prefer morpho::dilation).
-
- template<typename I, typename W>
- oln_type_of(I, concrete) dilation(const abstract::image<I>& input,
- const abstract::window<W>& win)
- {
- oln_type_of(I, concrete) output(input.size());
- oln_type_of(I, fwd_piter) p(input.size());
- for_all_p (p)
- output[p] = morpho::max(input, p, win);
- return output;
- }
-
- } // end of namespace oln::morpho::proc
-
-
-
- /*!
- ** \brief Processing dilation.
- **
- ** Compute the morphological dilation of input using win
- ** as structural element.\n
- **
- ** On grey-scale images, each point is replaced by the maximum value
- ** of its neighbors, as indicated by win. On binary images,
- ** a logical or is performed between neighbors.\n
- **
- ** The morpho::fast version of this function use a different
- ** algorithm: This algorithm is described in
- ** Implementation of morphological operations from:
- ** M. Van Droogenbroeck and H. Talbot.
- ** "Fast computation of morphological operations with arbitrary
- ** structuring elements". Pattern Recognition Letters,
- ** 17(14):1451-1460, 1996.\n
- **
- ** An histogram of the value of the neighborhood indicated by
- ** win is updated while iterating over all point of the
- ** image. Doing so is more efficient when the
- ** structural element is large.\n
- **
- ** \param I Exact type of the input image.
- ** \param E Exact type of the neighborhood.
- **
- ** \arg input The input image.
- ** \arg win Structuring element to use.
- **
- ** \code
- ** #include <oln/basics2d.hh>
- ** #include <oln/morpho/dilation.hh>
- ** #include <oln/level/compare.hh>
- ** #include <ntg/all.hh>
- ** int main()
- ** {
- ** typedef oln::image2d<ntg::bin> im_type;
- **
- ** im_type im1(oln::load(IMG_IN "object.pbm"));
- ** save(oln::morpho::dilation(im1, oln::win_c8p()),
- ** IMG_OUT "oln_morpho_dilation.pbm");
- ** }
- ** \endcode
- **
- ** \image html object_pbm.png
- ** \image latex object_pbm.png
- ** =>
- ** \image html oln_morpho_dilation.png
- ** \image latex oln_morpho_dilation.png
- */
-
- // fwd decl
- template <typename I, typename E> struct dilation_ret;
-
- }
-
- // category
- template <typename I, typename E>
- struct set_category< morpho::dilation_ret<I,E> > { typedef category::image ret; };
-
- // super_type
- template <typename I, typename E>
- struct set_super_type< morpho::dilation_ret<I,E> >
- {
- typedef abstract::image_unary_operator<oln_type_of(I, concrete), I, morpho::dilation_ret<I, E> > ret;
- };
-
-
-
- namespace morpho {
-
- /// Dilatation return.
-
- template <typename I, typename W>
- struct dilation_ret : public abstract::image_unary_operator<oln_type_of(I, concrete), I, dilation_ret<I,W> >
- {
- typedef abstract::image_unary_operator<oln_type_of(I, concrete), I, dilation_ret<I,W> > super_type;
- typedef typename super_type::output_type output_type;
-
- const W win;
-
- dilation_ret(const abstract::image<I>& input,
- const abstract::window<W>& win) :
- super_type(input.exact()),
- win(win.exact())
- {
- }
-
- };
-
-
- // Implementation:
-
- namespace impl {
-
- /// Dilation generic implementation.
-
- template <typename I, typename W>
- struct generic_dilation : public dilation_ret<I,W>
- {
- typedef dilation_ret<I,W> super_type;
- typedef typename super_type::output_type output_type;
-
- generic_dilation(const abstract::image<I>& input,
- const abstract::window<W>& win) :
- super_type(input, win)
- {
- }
-
- void impl_run()
- {
- mlc::eq<oln_type_of(I, size), oln_wn_type_of(W, size)>::ensure();
-
- output_type tmp(this->input.size()); // FIXME: trick
- this->output = tmp;
-
- oln_type_of(I, fwd_piter) p(this->input.size());
- for_all_p (p)
- this->output[p] = morpho::max(this->input, p, this->win);
- }
- };
-
- } // end of namespace oln::morpho::impl
-
-
- /// Dilation generic routine.
-
- template<typename I, typename W>
- dilation_ret<I,W> dilation(const abstract::image<I>& input,
- const abstract::window<W>& win)
- {
- impl::generic_dilation<I,W> tmp(input, win);
- tmp.run();
- return tmp;
- }
-
- } // end of morpho
-
-} // end of oln
-
-#endif // ! OLENA_MORPHO_DILATION_HH
Index: oln/morpho/geodesic_dilation.hh
===================================================================
--- oln/morpho/geodesic_dilation.hh (revision 166)
+++ oln/morpho/geodesic_dilation.hh (working copy)
@@ -1,141 +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 OLENA_MORPHO_GEODESIC_DILATION_HH
-# define OLENA_MORPHO_GEODESIC_DILATION_HH
-
-# include <mlc/cmp.hh>
-
-# include <oln/core/abstract/image_operator.hh>
-# include <oln/morpho/stat.hh>
-# include <oln/level/compare.hh>
-# include <oln/arith/min.hh>
-
-# include <oln/core/abstract/neighborhood.hh>
-# include <oln/morpho/dilation.hh>
-
-namespace oln {
-
- namespace morpho {
-
- // fwd declaration
- template <class I1, class I2> struct geodesic_dilation_ret;
-
- namespace proc {
-
- template<class I1, class I2>
- oln_type_of(I1, concrete)
- geodesic_dilation(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask)
- {
- mlc::eq<oln_type_of(I1, size), oln_type_of(I2, size)>::ensure();
- precondition(marker.size() == mask.size());
- precondition(level::is_greater_or_equal(mask, marker));
- oln_type_of(I1, concrete) output(marker.size());
- // FIXME: Useless?
- // marker.border_adapt_copy(marker.nbh_get().delta());
- oln_type_of(I1, piter) p(marker.size());
- for_all_p (p)
- {
- oln_type_of(I1, value) a =
- morpho::max(marker, p, marker.nbh_get().get_win());
- oln_type_of(I2, value) b = mask[p];
- // Min.
- output[p] = a < b ? a : b;
- }
- return output;
- }
-
- } // end of namespace oln::morpho::proc
-
- } // end of namespace oln::morpho
-
-
-
- // super_type
- template <class I1, class I2>
- struct set_super_type< morpho::geodesic_dilation_ret<I1, I2> >
- {
- typedef abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, morpho::geodesic_dilation_ret<I1, I2> > ret;
- };
-
-
- namespace morpho {
-
- template <class I1, class I2>
- struct geodesic_dilation_ret : public abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, morpho::geodesic_dilation_ret<I1, I2> >
- {
- typedef abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, geodesic_dilation_ret<I1, I2> > super_type;
-
- geodesic_dilation_ret(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask) :
- super_type(marker, mask)
- {}
- };
-
-
- namespace safe {
-
- template <class I1, class I2>
- struct geodesic_dilation : public geodesic_dilation_ret<I1, I2>
- {
- typedef geodesic_dilation_ret<I1, I2> super_type;
-
- geodesic_dilation(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask) :
- super_type(marker, mask)
- {}
-
- void impl_run()
- {
- mlc::eq<oln_type_of(I1, size), oln_type_of(I2, size)>::ensure();
- precondition((this->input1).size() == (this->input2).size());
- precondition(level::is_greater_or_equal(this->input2, this->input1));
- this->output =
- arith::min(dilation(this->input1.unbox(),
- this->input1.unbox().nbh_get().get_win()).output.unbox(),
- this->input2.unbox()).output;
- }
- };
-
- } // end of namespace oln::morpho::safe
-
- template<class I1, class I2>
- geodesic_dilation_ret<I1, I2>
- geodesic_dilation(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask)
- {
- safe::geodesic_dilation<I1, I2> tmp(marker, mask);
- tmp.run();
- return tmp;
- }
-
- } // end of namespace oln::morpho
-
-} // end of namespace oln
-
-#endif // OLENA_MORPHO_GEODESIC_DILATION_HH
Index: oln/morpho/reconstruction_by_dilation.inc
===================================================================
--- oln/morpho/reconstruction_by_dilation.inc (revision 166)
+++ oln/morpho/reconstruction_by_dilation.inc (working copy)
@@ -1,142 +0,0 @@
-// 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 filek 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.
-
-namespace oln {
-
- namespace morpho {
-
- namespace impl {
-
- // Sequential version
-
- template<typename I1, typename I2>
- struct generic_reconstruction <tag::by_dilation, tag::sequential, I1, I2>
- : public generic_reconstruction_canvas<I1, I2, tag::sequential,
- generic_reconstruction<tag::by_dilation, tag::sequential, I1, I2> >
- {
- typedef generic_reconstruction<tag::by_dilation,
- tag::sequential, I1,I2> self_type;
- typedef generic_reconstruction_canvas<I1, I2, tag::sequential,
- self_type> super_type;
-
- generic_reconstruction(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask) :
- super_type(marker, mask)
- {
- }
-
-
- void impl_bkd_loop_body()
- {
- this->output[this->bkd_p] = ntg::min(morpho::max(this->output,
- this->bkd_p,
- this->win_minus),
- this->mask[this->bkd_p].value());
- }
-
- void impl_fwd_loop_body()
- {
- this->output[this->fwd_p] = ntg::min(morpho::max(this->output,
- this->fwd_p,
- this->win_plus),
- this->mask[this->fwd_p].value());
- }
-
- void impl_preconditions()
- {
- precondition(level::is_greater_or_equal(this->mask, this->marker));
- }
-
- };
-
-
- // Hybrid version
-
- template<typename I1, typename I2>
- struct generic_reconstruction <tag::by_dilation, tag::hybrid, I1, I2>
- : public generic_reconstruction_canvas<I1, I2, tag::hybrid,
- generic_reconstruction<tag::by_dilation, tag::hybrid, I1, I2> >
- {
- typedef generic_reconstruction<tag::by_dilation,
- tag::hybrid, I1,I2> self_type;
- typedef generic_reconstruction_canvas<I1, I2, tag::hybrid,
- self_type> super_type;
-
- generic_reconstruction(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask) :
- super_type(marker, mask)
- {
- }
-
-
-
- void impl_bkd_loop_body()
- {
- this->output[this->bkd_p] = ntg::min(morpho::max(this->work,
- this->bkd_p,
- this->win_minus),
- this->mask[this->bkd_p].value());
- }
-
- void impl_fwd_loop_body()
- {
- this->output[this->fwd_p] = ntg::min(morpho::max(this->work,
- this->fwd_p,
- this->win_plus),
- this->mask[this->fwd_p].value());
- }
-
- void impl_fifo_loop_body()
- {
- if ((this->output[this->q] < this->output[this->p]) &&
- (this->mask[this->q] != this->output[this->q]))
- {
- this->output[this->q] = ntg::min(this->output[this->p].value(),
- this->mask[this->q].value());
- this->fifo.push(this->q);
- }
- }
-
- bool impl_exist_init()
- {
- return this->output.hold(this->q) &&
- (this->output[this->q] < this->output[this->bkd_p]) &&
- (this->output[this->q] < this->mask[this->q]);
- }
-
- void impl_preconditions()
- {
- precondition(level::is_greater_or_equal(this->mask, this->marker));
- }
-
- };
-
- }
-
- }
-
-}
Index: oln/morpho/stat.hh
===================================================================
--- oln/morpho/stat.hh (revision 166)
+++ oln/morpho/stat.hh (working copy)
@@ -1,122 +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 OLENA_MORPHO_STAT_HH
-# define OLENA_MORPHO_STAT_HH
-
-# include <mlc/cmp.hh>
-# include <ntg/bin.hh>
-# include <oln/core/abstract/image_entry.hh>
-# include <oln/core/abstract/window.hh>
-# include <oln/funobj/accum.hh>
-
-
-namespace oln {
-
- namespace morpho {
-
-
- /// Local min on a function.
-
- template <typename I, typename W>
- oln_type_of(I, value) min(const abstract::image<I>& input,
- const oln_type_of(I, point)& p,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
-
- oln_wn_type_of(W, fwd_iter) q(win);
- funobj::min_accumulator<oln_type_of(I, value)> minval;
-
- for_all_q_of_p (q, p)
- if (input.hold(q))
- minval(input[q]);
-
- return minval;
- }
-
-
- /// Local min on a set.
-
- template <typename I, typename W>
- bool min(const abstract::binary_image<I>& input,
- const oln_type_of(I, point)& p,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
-
- oln_wn_type_of(W, fwd_iter) q(win);
- for_all_q_of_p (q, p)
- if (input.hold(q) and not input[q])
- return false;
- return true;
- }
-
-
- /// Local max on a function.
-
- template <typename I, typename W>
- oln_type_of(I, value) max(const abstract::image<I>& input,
- const oln_type_of(I, point)& p,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
-
- oln_wn_type_of(W, fwd_iter) q(win);
- funobj::max_accumulator<oln_type_of(I, value)> maxval;
-
- for_all_q_of_p (q, p)
- if (input.hold(q))
- maxval(input[q]);
-
- return maxval;
- }
-
-
- /// Local max on a set.
-
- template <typename I, typename W>
- bool max(const abstract::binary_image<I>& input,
- const oln_type_of(I, point)& p,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
-
- oln_wn_type_of(W, fwd_iter) q(win);
- for_all_q_of_p (q, p)
- if (input.hold(q) and input[q])
- return true;
- return false;
- }
-
-
- } // end of namespace morpho
-
-} // end of namespace oln
-
-
-#endif // ! OLENA_MORPHO_STAT_HH
Index: oln/morpho/erosion.hh
===================================================================
--- oln/morpho/erosion.hh (revision 166)
+++ oln/morpho/erosion.hh (working copy)
@@ -1,220 +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 OLENA_MORPHO_EROSION_HH
-# define OLENA_MORPHO_EROSION_HH
-
-# include <mlc/cmp.hh>
-# include <mlc/to_string.hh>
-
-# include <oln/core/abstract/image_operator.hh>
-# include <oln/morpho/stat.hh>
-
-# include <oln/core/2d/window2d.hh>
-
-
-namespace oln {
-
-
- // fwd decl
-
- namespace morpho {
- template <typename I> struct erosion_ret;
-
- template<typename I, typename W>
- erosion_ret<I> erosion(const abstract::image<I>& input,
- const abstract::window<W>& win);
- }
-
- // super_type
-
- template <typename I>
- struct set_super_type< morpho::erosion_ret<I> >
- {
- typedef oln_type_of(I, concrete) output_type;
-
- typedef morpho::erosion_ret<I> self_type;
- typedef abstract::image_unary_operator<output_type, I, self_type > ret;
- };
-
-
-
-
- namespace morpho {
-
-
-
- // Erosion as a 'classical' procedure returning an image (do not
- // use it; prefer morpho::erosion).
-
- namespace proc {
-
- template<typename I, typename W>
- oln_type_of(I, concrete) erosion(const abstract::image<I>& input,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
- oln_type_of(I, concrete) output(input.size());
- oln_type_of(I, fwd_piter) p(input.size());
- for_all_p (p)
- output[p] = morpho::min(input, p, win);
- return output;
- }
-
- } // end of namespace oln::morpho::proc
-
-
-
- /// Erosion return type.
-
- template <typename I>
- struct erosion_ret : public oln_super_of_(erosion_ret<I>)
- {
- typedef oln_super_of(erosion_ret<I>) super_type;
-
- erosion_ret(const abstract::image<I>& input) :
- super_type(input)
- {
- }
-
- };
-
-
- // Various implementation.
-
-
- namespace impl {
-
-
- /// Generic implementation of erosion (type).
-
- template <typename I, typename W>
- struct generic_erosion : public erosion_ret<I>
- {
- typedef erosion_ret<I> super_type;
- // FIXME: typedef oln_type_of(super_type, output) output_type;
-
- const W& win;
-
- generic_erosion(const abstract::image<I>& input,
- const abstract::window<W>& win) :
- super_type(input),
- win(win.exact())
- {
- }
-
- void impl_run()
- {
- oln_type_of(super_type, output) tmp(this->input.size()); // FIXME: trick
- this->output = tmp;
- // FIXME: output.resize(input.size);
-
- oln_type_of(I, fwd_piter) p(this->input.size());
- for_all_p (p)
- this->output[p] = morpho::min(this->input, p, this->win);
- }
- };
-
- // Generic implementation of erosion (routine).
-
- template<typename I, typename W>
- erosion_ret<I> erosion(const abstract::image<I>& input,
- const abstract::window<W>& win)
- {
- impl::generic_erosion<I,W> tmp(input, win);
- tmp.run();
- return tmp;
- }
-
-
-
-
- /// Rectangle2d implementation of erosion (type).
-
- template <typename I>
- struct rectangle2d_erosion : public erosion_ret<I>
- {
- typedef erosion_ret<I> super_type;
- // FIXME: typedef oln_type_of(super_type, output) output_type;
-
- const win_rectangle2d& win;
-
- rectangle2d_erosion(const abstract::image<I>& input,
- const win_rectangle2d& win) :
- super_type(input),
- win(win)
- {}
-
- void impl_run()
- {
- box<oln_type_of(super_type, output)> temp; // FIXME: box?
- // FIXME: output_type temp;
-
- win_hline2d hline(this->win.width);
- win_vline2d vline(this->win.height);
-
- temp = oln::morpho::erosion(this->input, hline);
- this->output = oln::morpho::erosion(temp, vline);
- }
- };
-
- // Rectangle2d implementation of erosion (routine).
-
- template<typename I>
- erosion_ret<I> erosion(const abstract::image<I>& input,
- const win_rectangle2d& win)
- {
- impl::rectangle2d_erosion<I> tmp(input, win);
- tmp.run();
- return tmp;
- }
-
-
-
-
- } // end of namespace oln::morpho::impl
-
-
-
- /// Generic erosion (facade).
-
- template<typename I, typename W>
- erosion_ret<I> erosion(const abstract::image<I>& input,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
- return impl::erosion(input.exact(), win.exact());
- }
-
-
- } // end of namespace oln::morpho
-
-
-} // end of namespace oln
-
-
-#endif // ! OLENA_MORPHO_EROSION_HH
Index: oln/morpho/hit_or_miss.hh
===================================================================
--- oln/morpho/hit_or_miss.hh (revision 166)
+++ oln/morpho/hit_or_miss.hh (working copy)
@@ -1,186 +0,0 @@
-// Copyright (C) 2001, 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 OLENA_MORPHO_HIT_OR_MISS_HH
-# define OLENA_MORPHO_HIT_OR_MISS_HH
-
-# include <oln/core/gen/image_with_nbh.hh>
-# include <oln/morpho/erosion.hh>
-# include <oln/morpho/dilation.hh>
-# include <oln/arith/min.hh>
-# include <oln/utils/invert.hh>
-
-namespace oln {
-
- namespace tag {
-
- // No tags yet
-
- } // end of namespace oln::morpho::tag
-
-
- namespace morpho {
- template <typename I, typename W1, typename W2> struct hit_or_miss_ret;
- } // end of namespace oln::morpho
-
- // super_type
-
- template <typename I, typename W1, typename W2>
- struct set_super_type< morpho::hit_or_miss_ret<I, W1, W2> >
- {
- typedef oln_type_of(I, concrete) output_type;
-
- typedef morpho::hit_or_miss_ret<I, W1, W2> self_type;
- typedef abstract::image_unary_operator<output_type, I, self_type > ret;
- };
-
- namespace morpho {
-
- // Reconstruction as a 'classical' procedure returning an image (do not
- // use it; prefer morpho::hit_or_miss).
-
- namespace proc {
-
- // FIXME: ...
-
- } // end of namespace oln::morpho::proc
-
-
- template <typename I, typename W1, typename W2>
- struct hit_or_miss_ret :
- // FIXME: oln_super_of_
- public oln::internal::get_super_type< hit_or_miss_ret<I, W1, W2> >::ret
- {
- typedef hit_or_miss_ret<I, W1, W2> self_type;
- typedef typename oln::internal::get_super_type<self_type>::ret super_type;
- const W1& win1;
- const W2& win2;
-
- hit_or_miss_ret(const abstract::image<I>& input,
- const abstract::regular_window<oln_type_of(I, grid), W1> win1,
- const abstract::regular_window<oln_type_of(I, grid), W2> win2) :
- super_type(input),
- win1(win1.exact()),
- win2(win2.exact())
- {
- }
-
- };
-
-
- namespace impl {
-
- template <typename I, typename W1, typename W2>
- struct generic_hit_or_miss : public hit_or_miss_ret<I, W1, W2>
- {
- typedef hit_or_miss_ret<I, W1, W2> super_type;
-
- generic_hit_or_miss(const abstract::image<I>& input,
- const abstract::regular_window<oln_type_of(I, grid), W1> win1,
- const abstract::regular_window<oln_type_of(I, grid), W2> win2) :
- super_type(input, win1, win2)
- {
- }
-
- void impl_run()
- {
- this->output = arith::min(erosion(this->input, this->win1),
- erosion(utils::invert(this->input),
- this->win2));
- }
- };
-
- template <typename I, typename W1, typename W2>
- hit_or_miss_ret<I, W1, W2>
- hit_or_miss(const abstract::image<I>& input,
- const abstract::regular_window<oln_type_of(I, grid), W1> win1,
- const abstract::regular_window<oln_type_of(I, grid), W2> win2)
- {
- generic_hit_or_miss<I, W1, W2> tmp(input, win1, win2);
- tmp.run();
- return tmp;
- }
-
- } //end of namespace impl
-
- template <typename I, typename W1, typename W2>
- hit_or_miss_ret<I, W1, W2>
- hit_or_miss(const abstract::image<I>& input,
- const abstract::regular_window<oln_type_of(I, grid), W1> win1,
- const abstract::regular_window<oln_type_of(I, grid), W2> win2)
- {
- // FIXME: win1 inter win2 must be empty
- return impl::hit_or_miss(input.exact(), win1.exact(), win2.exact());
- }
-
-
- template<class I, class W1, class W2>
- dilation_ret<hit_or_miss_ret<I, W1, W2>, W1>
- hit_or_miss_opening(const abstract::image<I>& input,
- const abstract::regular_window<oln_type_of(I, grid), W1> win1,
- const abstract::regular_window<oln_type_of(I, grid), W2> win2)
- {
- return dilation(hit_or_miss(input, win1, win2), -win1);
- }
-
- template<class I, class W1, class W2>
- dilation_ret<hit_or_miss_ret<I, W2, W1>, W2>
- hit_or_miss_opening_bg(const abstract::image<I>& input,
- const abstract::regular_window<oln_type_of(I, grid), W1> win1,
- const abstract::regular_window<oln_type_of(I, grid), W2> win2)
- {
- return hit_or_miss_opening(input, win2, win1);
- }
-
- template<class I, class W1, class W2>
- utils::image_inverted<dilation_ret<hit_or_miss_ret<utils::image_inverted<I>,
- W1, W2>, W1> > // !!!
- hit_or_miss_closing(const abstract::image<I>& input,
- const abstract::regular_window<oln_type_of(I, grid), W1> win1,
- const abstract::regular_window<oln_type_of(I, grid), W2> win2)
- {
- return utils::invert(hit_or_miss_opening(utils::invert(input),
- win1, win2));
- }
-
- template<class I, class W1, class W2>
- utils::image_inverted<dilation_ret<hit_or_miss_ret<utils::image_inverted<I>,
- W2, W1>, W2> > // !!!
- hit_or_miss_closing_bg(const abstract::image<I>& input,
- const abstract::regular_window<oln_type_of(I, grid), W1> win1,
- const abstract::regular_window<oln_type_of(I, grid), W2> win2)
- {
- return hit_or_miss_closing(input, win2, win1);
- }
-
-
-
- } // end of namespace morpho
-
-} // end of namespace oln
-
-#endif // ! OLENA_MORPHO_HIT_OR_MISS_HH
Index: oln/morpho/geodesic_erosion.hh
===================================================================
--- oln/morpho/geodesic_erosion.hh (revision 166)
+++ oln/morpho/geodesic_erosion.hh (working copy)
@@ -1,140 +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 OLENA_MORPHO_GEODESIC_EROSION_HH
-# define OLENA_MORPHO_GEODESIC_EROSION_HH
-
-# include <mlc/cmp.hh>
-
-# include <oln/core/abstract/image_operator.hh>
-# include <oln/morpho/stat.hh>
-# include <oln/level/compare.hh>
-# include <oln/arith/max.hh>
-
-# include <oln/core/abstract/neighborhood.hh>
-# include <oln/morpho/erosion.hh>
-
-namespace oln {
-
- namespace morpho {
-
- // fwd declaration
- template <class I1, class I2> struct geodesic_erosion_ret;
-
- namespace proc {
-
- template<class I1, class I2>
- oln_type_of(I1, concrete)
- geodesic_erosion(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask)
- {
- mlc::eq<oln_type_of(I1, size), oln_type_of(I2, size)>::ensure();
- precondition(marker.size() == mask.size());
- precondition(level::is_greater_or_equal(marker, mask));
- oln_type_of(I1, concrete) output(marker.size());
- // FIXME: Useless?
- // marker.border_adapt_copy(marker.nbh_get().delta());
- oln_type_of(I1, piter) p(marker.size());
- for_all_p (p)
- {
- oln_type_of(I1, value) a =
- morpho::min(marker, p, marker.nbh_get().get_win());
- oln_type_of(I2, value) b = mask[p];
- // Max.
- output[p] = a > b ? a : b;
- }
- return output;
- }
-
- } // end of namespace oln::morpho::proc
-
- } // end of namespace oln::morpho
-
-
- // super_type
- template <class I1, class I2>
- struct set_super_type< morpho::geodesic_erosion_ret<I1, I2> >
- {
- typedef abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, morpho::geodesic_erosion_ret<I1, I2> > ret;
- };
-
-
- namespace morpho {
-
- template <class I1, class I2>
- struct geodesic_erosion_ret : public abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, morpho::geodesic_erosion_ret<I1, I2> >
- {
- typedef abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, geodesic_erosion_ret<I1, I2> > super_type;
-
- geodesic_erosion_ret(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask) :
- super_type(marker, mask)
- {}
- };
-
-
- namespace safe {
-
- template <class I1, class I2>
- struct geodesic_erosion : public geodesic_erosion_ret<I1, I2>
- {
- typedef geodesic_erosion_ret<I1, I2> super_type;
-
- geodesic_erosion(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask) :
- super_type(marker, mask)
- {}
-
- void impl_run()
- {
- mlc::eq<oln_type_of(I1, size), oln_type_of(I2, size)>::ensure();
- precondition((this->input1).size() == (this->input2).size());
- precondition(level::is_greater_or_equal(this->input1, this->input2));
- this->output =
- arith::max(erosion(this->input1.unbox(),
- this->input1.unbox().nbh_get().get_win()).output.unbox(),
- this->input2.unbox()).output;
- }
- };
-
- } // end of namespace oln::morpho::safe
-
- template<class I1, class I2>
- geodesic_erosion_ret<I1, I2>
- geodesic_erosion(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask)
- {
- safe::geodesic_erosion<I1, I2> tmp(marker, mask);
- tmp.run();
- return tmp;
- }
-
- } // end of namespace oln::morpho
-
-} // end of namespace oln
-
-#endif // OLENA_MORPHO_GEODESIC_EROSION_HH