Index: ChangeLog
from Simon Odou <simon(a)lrde.epita.fr>
* oln/convert/value_to_point.hh: New.
Conversion of value to point. This is temporary: waiting for a
coherent `convert' in this prototype.
* tests/convert/tests/value_to_point: New.
* tests/convert: New.
* tests/convert/tests: New.
* tests/convert/Makefile.am: New.
* oln/convert: New.
oln/convert/value_to_point.hh | 106 +++++++++++++++++++++++++++++++++++++
tests/convert/Makefile.am | 5 +
tests/convert/tests/value_to_point | 27 +++++++++
3 files changed, 138 insertions(+)
Index: tests/convert/tests/value_to_point
--- tests/convert/tests/value_to_point (revision 0)
+++ tests/convert/tests/value_to_point (revision 0)
@@ -0,0 +1,27 @@
+
+#include <iostream>
+
+#include <ntg/basics.hh>
+#include <ntg/color.hh>
+#include <oln/convert/value_to_point.hh>
+
+#include "check.hh"
+#include "data.hh"
+
+bool check()
+{
+ oln::point1d p = oln::convert::value_to_point(42u);
+ oln::point3d p2 = oln::convert::value_to_point(ntg::rgb_8(1,6,64));
+ std::cout << p.index() << std::endl;
+ std::cout << p2.row() << std::endl;
+ std::cout << p2.col() << std::endl;
+ std::cout << p2.slice() << std::endl;
+ std::cout << p2 << std::endl;
+fdas
+ if (p.index() != 42 ||
+ p2.row() != 6 ||
+ p2.col() != 64 ||
+ p2.slice() != 1)
+ return true;
+ return false;
+}
Index: tests/convert/Makefile.am
--- tests/convert/Makefile.am (revision 0)
+++ tests/convert/Makefile.am (revision 0)
@@ -0,0 +1,5 @@
+include ../check/Makefile.runtests
+include ../check/Makefile.check
+
+
+check-local: check-runtests
Index: oln/convert/value_to_point.hh
--- oln/convert/value_to_point.hh (revision 0)
+++ oln/convert/value_to_point.hh (revision 0)
@@ -0,0 +1,106 @@
+// 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_VALUE_TO_POINT
+# define OLENA_VALUE_TO_POINT
+
+# include <ntg/basics.hh>
+
+# include <oln/core/1d/point1d.hh>
+# include <oln/core/3d/point3d.hh>
+
+// FIXME: waiting for a coherent convert.
+
+namespace oln {
+
+ namespace convert {
+ /*! Convert a value of pixel to a point.
+ **
+ ** For example, transform an RGB color to a 3D point
+ ** (ntg::rgb_8 => oln::point3d).
+ ** This function is useful to build the histogram. \n
+ ** Example:
+ ** \verbatim
+ ** f(oln::convert::value_to_point<ntg::rgb_8>()(ntg::rgb_8(1,6,64)));
+ ** // is equivalent to:
+ ** f(oln::point3d(1, 6, 64));
+ ** \endverbatim
+ */
+
+ namespace internal {
+
+ template <typename ValueType>
+ struct value_to_point
+ {
+ typedef ValueType value_type;
+ typedef point1d point_type;
+
+ value_to_point(const value_type& v)
+ : v_(v)
+ {}
+
+ operator point_type()
+ {
+ return point1d(v_ - ntg_min_val(value_type));
+ }
+
+ const value_type& v_;
+ };
+
+ template <unsigned Qbits, template <unsigned> class S>
+ struct value_to_point< ntg::color<3, Qbits, S> >
+ {
+ typedef ntg::color<3, Qbits, S> value_type;
+ typedef point3d point_type;
+
+ value_to_point(const value_type& v)
+ : v_(v)
+ {}
+
+ operator point_type()
+ {
+ return point_type(coord_t(v_[0]), coord_t(v_[1]), coord_t(v_[2]));
+ }
+
+ const value_type& v_;
+ };
+
+
+ }
+
+ template <typename ValueType>
+ typename internal::value_to_point<ValueType>::point_type
+ value_to_point(const ValueType& v)
+ {
+ return internal::value_to_point<ValueType>(v);
+ }
+
+ } // convert
+
+} // oln
+
+#endif
Index: ChangeLog
from Simon Odou <simon(a)lrde.epita.fr>
* oln/morpho: New.
* oln/morpho/stat.hh: New. Add morphological min and max.
* oln/core/abstract/piter.hh: Add `for_all_remaining' macro.
* oln/core/abstract/point.hh: Fix a return type (was abstract).
* tests/morpho: New. Add test suite for morpho.
* tests/morpho/tests: New. Likewise.
* tests/morpho/Makefile.am: New. Likewise.
* oln/basics.hh: Add headers.
oln/basics.hh | 2
oln/core/abstract/piter.hh | 6 +
oln/core/abstract/point.hh | 4
oln/morpho/stat.hh | 185 +++++++++++++++++++++++++++++++++++++++++++++
tests/morpho/Makefile.am | 1
5 files changed, 196 insertions(+), 2 deletions(-)
Index: tests/morpho/Makefile.am
--- tests/morpho/Makefile.am (revision 0)
+++ tests/morpho/Makefile.am (revision 0)
@@ -0,0 +1 @@
+include ../check/Makefile.runtests
Index: oln/basics.hh
--- oln/basics.hh (revision 85)
+++ oln/basics.hh (working copy)
@@ -57,8 +57,10 @@
# include <oln/core/abstract/size.hh>
# include <oln/core/abstract/point.hh>
# include <oln/core/abstract/images.hh>
+# include <oln/core/abstract/entry.hh>
# include <oln/core/abstract/piter.hh>
+# include <oln/core/abstract/witer.hh>
// # include <oln/core/abstract/niter.hh>
# include <oln/core/abstract/struct_elt.hh>
Index: oln/morpho/stat.hh
--- oln/morpho/stat.hh (revision 0)
+++ oln/morpho/stat.hh (revision 0)
@@ -0,0 +1,185 @@
+// 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 <oln/basics.hh>
+# include <ntg/bin.hh>
+
+namespace oln {
+
+ namespace morpho {
+
+ namespace internal {
+
+ /*!
+ ** \brief Min and Max on a structuring element.
+ **
+ ** We need to use this inner definition in order to specialize
+ ** max and min on binary images.
+ **
+ ** \param I Image exact type.
+ ** \param E Structuring element type.
+ ** \param V Associated value type.
+ */
+ template <class I, class E, class V =oln_type_of(I, value)>
+ struct stat_
+ {
+ /*!
+ ** \brief Maximum of a structuring element.
+ **
+ ** Look for the maximum in the structuring element se disposed
+ ** on the image input, at the point p.
+ **
+ ** \arg input Input image.
+ ** \arg p Point of the image to move the structuring element on.
+ ** \arg se The structuring element to use.
+ */
+ static V
+ max(const I& input, const oln_type_of(I, point)& p, const E& se)
+ {
+ // FIXME: test dim I == dim E
+
+ oln_type_of(E, fwd_witer) dp(se);
+ dp.start();
+ V val = input[p + dp];
+ for_all_remaining (dp)
+ if (val < input[p + dp].value())
+ val = input[p + dp].value();
+ return val;
+ }
+
+ /*!
+ ** \brief Minimum of a structuring element.
+ **
+ ** Look for the minimum in the structuring element se disposed
+ ** on the image input, at the point p.
+ **
+ ** \arg input Input image.
+ ** \arg p Point of the image to move the structuring element on.
+ ** \arg se The structuring element to use.
+ */
+ static V
+ min(const I& input, const oln_type_of(I, point)& p, const E& se)
+ {
+ // FIXME: test dim I == dim E
+
+ oln_type_of(E, fwd_witer) dp(se);
+ dp.start();
+ V val = input[p + dp];
+ for_all_remaining (dp)
+ if (val > input[p + dp].value())
+ val = input[p + dp].value();
+ return val;
+ }
+
+ };
+
+ /* Binary specialization. */
+
+ template <class I, class E>
+ struct stat_<I, E, ntg::bin>
+ {
+ static ntg::bin
+ max(const I& input, const oln_type_of(I, point)& p, const E& se)
+ {
+ mlc::eq<I::dim, E::dim>::ensure();
+ oln_type_of(E, fwd_witer) dp(se);
+ for_all (dp)
+ if (input[p + dp] == true)
+ return true;
+ return false;
+ }
+
+ static ntg::bin
+ min(const I& input, const oln_type_of(I, point)& p, const E& se)
+ {
+ mlc::eq<I::dim, E::dim>::ensure();
+ oln_type_of(E, fwd_witer) dp(se);
+ for_all (dp)
+ if (input[p + dp] == false)
+ return false;
+ return true;
+ }
+
+ };
+
+ } // internal
+
+ /*!
+ ** \brief Maximum of a structuring element.
+ **
+ ** Look for the maximum in the structuring element se disposed
+ ** on the image input, at the point p.
+ **
+ ** \param I Image exact type.
+ ** \param E Structuring element type.
+ **
+ ** \arg input Input image.
+ ** \arg p Point of the image to move the structuring element on.
+ ** \arg se The structuring element to use.
+ */
+ template<class I, class E>
+ oln_type_of(I, value)
+ max(const abstract::non_vectorial_image<I>& input,
+ const oln_type_of(I, point)& p,
+ const abstract::struct_elt<E>& se)
+ {
+ // FIXME: test dim I == dim E
+ return internal::stat_<I, E>::max(input.exact(), p, se.exact());
+ }
+
+ /*! ** \brief Minimum of a structuring element.
+ **
+ ** Look for the minimum in the structuring element se disposed
+ ** on the image input, at the point p.
+ **
+ ** \param I Image exact type.
+ ** \param E Structuring element type.
+ **
+ ** \arg input Input image.
+ ** \arg p Point of the image to move the structuring element on.
+ ** \arg se The structuring element to use.
+ */
+ template<class I, class E>
+ oln_type_of(I, value)
+ min(const abstract::non_vectorial_image<I>& input,
+ const oln_type_of(I, point)& p,
+ // const mlc_exact_type(I)::iter_type& p,
+ const abstract::struct_elt<E>& se)
+ {
+ // FIXME: test dim I == dim E
+ return internal::stat_<I, E>::min(input.exact(), p, se.exact());
+ }
+
+ } // end of namespace morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_MORPHO_STAT_HH
Index: oln/core/abstract/piter.hh
--- oln/core/abstract/piter.hh (revision 85)
+++ oln/core/abstract/piter.hh (working copy)
@@ -37,9 +37,13 @@
-# define for_all(p) for(p.start(); p.is_valid(); p.next())
+# define for_all(p) \
+ for(p.start(); p.is_valid(); p.next())
+# define for_all_remaining(p) \
+ for(; p.is_valid(); p.next())
+
namespace oln {
// fwd decl
Index: oln/core/abstract/point.hh
--- oln/core/abstract/point.hh (revision 85)
+++ oln/core/abstract/point.hh (working copy)
@@ -87,6 +87,8 @@
struct point : public mlc::any__best_memory<E>
{
+ typedef E exact_type;
+
/*! \brief Test equality of two points. Nota bene: this method
** is abstract-like.
**
@@ -111,7 +113,7 @@
typedef oln_type_of(E, dpoint) dpoint_type;
- const point operator+(const dpoint_type& dp) const
+ const exact_type operator+(const dpoint_type& dp) const
{
return this->exact().impl_plus(dp);
}
Index: ChangeLog
from Simon Odou <simon(a)lrde.epita.fr>
* oln/core/2d/fwd_witer2d.hh: New. Forward window iterator in 2d.
fwd_witer2d.hh | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 68 insertions(+)
Index: oln/core/2d/fwd_witer2d.hh
--- oln/core/2d/fwd_witer2d.hh (revision 0)
+++ oln/core/2d/fwd_witer2d.hh (revision 0)
@@ -0,0 +1,68 @@
+// Copyright (C) 2001, 2003, 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_FWD_WITER2D_HH
+# define OLENA_CORE_FWD_WITER2D_HH
+
+# include <oln/core/abstract/witer.hh>
+# include <oln/core/2d/window2d.hh>
+
+# include <string>
+
+namespace oln {
+
+ // fwd decl
+ struct fwd_witer2d;
+
+ // category
+ template <>
+ struct set_category<fwd_witer2d> { typedef category::witer ret; };
+
+ // props
+ template <>
+ struct set_props < category::witer, fwd_witer2d > : public props_of<category::witer>
+ {
+ typedef window2d se_type;
+ };
+
+ struct fwd_witer2d : public abstract::witer< fwd_witer2d >
+ {
+
+ typedef abstract::witer<fwd_witer2d> super_type;
+
+ fwd_witer2d(const se_type& se) :
+ super_type(se)
+ {
+ this->exact_ptr = this;
+ this->invalidate();
+ }
+
+ };
+
+} // oln
+
+#endif // OLENA_CORE_FWD_WITER2D_HH
Index: ChangeLog
from Simon Odou <simon(a)lrde.epita.fr>
* oln/makefile.src: Add compose.hh.
* oln/core/compose.hh: New.
core/compose.hh | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
makefile.src | 3
2 files changed, 172 insertions(+), 1 deletion(-)
Index: oln/makefile.src
--- oln/makefile.src (revision 76)
+++ oln/makefile.src (working copy)
@@ -45,8 +45,9 @@
core/abstract/point.hh \
core/abstract/size.hh \
core/abstract/neighborhood.hh \
- core/abstract/window.hh \
+ core/abstract/struct_elt.hh \
core/coord.hh \
+ core/compose.hh \
core/properties.hh \
core/value_box.hh \
fancy/iota.hh \
Index: oln/core/compose.hh
--- oln/core/compose.hh (revision 0)
+++ oln/core/compose.hh (revision 0)
@@ -0,0 +1,170 @@
+// Copyright (C) 2001, 2004 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_COMPOSE_HH
+# define OLENA_CORE_COMPOSE_HH
+
+# include <functional>
+
+namespace oln {
+
+ namespace internal {
+
+ /*! \class compose_uu_
+ **
+ ** The operator () of this class performs a composition between
+ ** two unary functors \a F1 & \a F2.
+ */
+
+ template< class F1, class F2 >
+ struct compose_uu_ :
+ public std::unary_function <typename F2::argument_type,
+ typename F1::result_type>
+ {
+ typedef compose_uu_ self_type;
+
+ typename self_type::result_type
+ operator()(typename self_type::argument_type arg) const
+ {
+ return f1_(f2_(arg));
+ }
+
+ compose_uu_(const F1& f1, const F2& f2) : f1_(f1), f2_(f2) {}
+
+ private:
+
+ const F1 f1_;
+ const F2 f2_;
+
+ };
+
+ /*! \class compose_ub_
+ **
+ ** The operator () of this class performs a composition between
+ ** a unary functor \a F1 and a binary functor \a F2.
+ */
+
+
+ template< class F1, class F2 >
+ struct compose_ub_ :
+ public std::binary_function <typename F2::first_argument_type,
+ typename F2::second_argument_type,
+ typename F1::result_type>
+ {
+ typedef compose_ub_ self_type;
+
+ typename self_type::result_type
+ operator()(typename self_type::first_argument_type arg1,
+ typename self_type::second_argument_type arg2) const
+ {
+ return f1_(f2_(arg1, arg2));
+ }
+
+ compose_ub_(const F1& f1, const F2& f2) : f1_(f1), f2_(f2) {}
+
+ private:
+
+ const F1 f1_;
+ const F2 f2_;
+
+ };
+
+ /*! \class compose_bu_
+ **
+ ** The operator () of this class performs a composition between
+ ** a binary functor \a F1 and an unary functor \a F2.
+ */
+
+ template< class F1, class F2 >
+ struct compose_bu_ :
+ public std::binary_function <typename F2::argument_type,
+ typename F2::argument_type,
+ typename F1::result_type>
+ {
+ typedef compose_bu_ self_type;
+
+ typename self_type::result_type
+ operator()(typename self_type::first_argument_type arg1,
+ typename self_type::second_argument_type arg2) const
+ {
+ return f1_(f2_(arg1), f2_(arg2));
+ }
+
+ compose_bu_(const F1& f1, const F2& f2) : f1_(f1), f2_(f2) {}
+
+ private:
+
+ const F1 f1_;
+ const F2 f2_;
+
+ };
+
+ }
+
+
+ /// Compose two unary functors \a F1 & \a F2.
+ template<class UF1, class UF2>
+ internal::compose_uu_<UF1, UF2>
+ compose_uu(const UF1& f1, const UF2& f2)
+ {
+ return internal::compose_uu_<UF1, UF2>(f1, f2);
+ }
+
+ /// Compose a unary functor \a F1 with a binary functor \a F2.
+ template<class UF1, class BF2>
+ internal::compose_ub_<UF1, BF2>
+ compose_ub(const UF1& f1, const BF2& f2)
+ {
+ return internal::compose_ub_<UF1, BF2>(f1, f2);
+ }
+
+ /// Compose a binary functor \a F1 and an unary functor \a F2.
+ template<class BF1, class UF2>
+ internal::compose_bu_<BF1, UF2>
+ compose_bu(const BF1& f1, const UF2& f2)
+ {
+ return internal::compose_bu_<BF1, UF2>(f1, f2);
+ }
+
+ /*! \class f_identity
+ **
+ ** This functor returns its argument.
+ */
+
+ template<class T>
+ struct f_identity : std::unary_function<T, T>
+ {
+ T
+ operator()(T t) const
+ {
+ return t;
+ }
+ };
+
+} // end of oln
+
+#endif // OLENA_CORE_COMPOSE_HH