Commit ef48f52d authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Add proper inheritance to functions.

	* mln/core/concept/doc/neighborhood.hh,
	* mln/core/concept/neighborhood.hh,
	* mln/core/neighb.hh (point): New.
	* mln/convert/to_image.hh
	(helper_dim_, helper_image_from_): New in mln::internal.
	(image_from_): New in mln.
	(mln_image_from): New macro.
	(to_image): Fix; now generalized.

	* mln/metal/all.hh: New.
	* mln/metal/equal.hh: Update.
	(mlc_equal): New.
	* mln/metal/if.hh: New.
	* mln/metal/is_a.hh: New.
	* mln/metal/unptr.hh: New.
	* mln/metal/unqualif.hh: New.
	* mln/metal/unref.hh: New.

	* mln/core/concept/function.hh (result): New in Function_p2b.
	* mln/fun/internal: New directory.
	* mln/pw/cst.hh: Precise inheritance.
	* mln/pw/value.hh: Likewise.
	(select_function_): Move to...
	* mln/fun/internal/selector.hh: ...this new file.
	(select_function_): Rename as...
	(selector_): ...this.
	* mln/fun/c.hh: New.
	* mln/convert/to_fun.hh: New.

	* mln/convert/to_window.hh (to_window): New overload.
	* mln/estim/mean.hh (mean): New overload.
	* mln/estim/sum.hh: New.
	* mln/level/run.hh: Rename as...
	* mln/level/compute.hh: ...this.
	(run): Rename as...
	(compute): ...this.
	* tests/w_window2d_int.cc: Augment.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1053 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 7d205129
2007-08-27 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add proper inheritance to functions.
* mln/core/concept/doc/neighborhood.hh,
* mln/core/concept/neighborhood.hh,
* mln/core/neighb.hh (point): New.
* mln/convert/to_image.hh
(helper_dim_, helper_image_from_): New in mln::internal.
(image_from_): New in mln.
(mln_image_from): New macro.
(to_image): Fix; now generalized.
* mln/metal/all.hh: New.
* mln/metal/equal.hh: Update.
(mlc_equal): New.
* mln/metal/if.hh: New.
* mln/metal/is_a.hh: New.
* mln/metal/unptr.hh: New.
* mln/metal/unqualif.hh: New.
* mln/metal/unref.hh: New.
* mln/core/concept/function.hh (result): New in Function_p2b.
* mln/fun/internal: New directory.
* mln/pw/cst.hh: Precise inheritance.
* mln/pw/value.hh: Likewise.
(select_function_): Move to...
* mln/fun/internal/selector.hh: ...this new file.
(select_function_): Rename as...
(selector_): ...this.
* mln/fun/c.hh: New.
* mln/convert/to_fun.hh: New.
* mln/convert/to_window.hh (to_window): New overload.
* mln/estim/mean.hh (mean): New overload.
* mln/estim/sum.hh: New.
* mln/level/run.hh: Rename as...
* mln/level/compute.hh: ...this.
(run): Rename as...
(compute): ...this.
* tests/w_window2d_int.cc: Augment.
2007-08-27 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add some linear filters and augment related tools.
......
// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef MLN_CONVERT_TO_FUN_HH
# define MLN_CONVERT_TO_FUN_HH
/*! \file mln/convert/to_fun.hh
*
* \brief Conversions towards some mln::Function.
*/
# include <mln/pw/value.hh>
# include <mln/fun/c.hh>
namespace mln
{
namespace convert
{
/// Convert a C unary function into an mln::fun::C.
template <typename R, typename A>
fun::C<R(*)(A)> to_fun(R (*f)(A));
/// Convert an image into a function.
template <typename I>
pw::value_<I> to_fun(const Image<I>& ima);
# ifndef MLN_INCLUDE_ONLY
template <typename R, typename A>
fun::C<R(*)(A)> to_fun(R (*f_)(A))
{
fun::C<R(*)(A)> f(f_);
return f;
}
template <typename I>
pw::value_<I> to_fun(const Image<I>& ima)
{
return pw::value(ima);
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert
} // end of namespace mln
#endif // ! MLN_CONVERT_TO_FUN_HH
......@@ -45,36 +45,73 @@
# include <mln/level/fill.hh>
# define mln_image_from(Src, Value) typename mln::image_from_< Src, Value >::ret
namespace mln
{
// FIXME: Move elsewhere.
namespace internal
{
template <typename T>
struct helper_dim_
{
typedef mln_point(T) P;
enum { value = P::dim };
};
template <unsigned dim, typename V> struct helper_image_from_;
template <typename V>
struct helper_image_from_< 2, V >
{
typedef image2d_b<V> ret;
};
} // end of namespace mln::internal
// FIXME: Doc + move elsewhere!
template <typename T, typename V>
struct image_from_
{
enum { dim = internal::helper_dim_<T>::value };
typedef typename internal::helper_image_from_< dim, V >::ret ret;
};
namespace convert
{
/// Convert a point set \p pset into a binary image.
template <typename S>
image2d_b<bool> to_image(const Point_Set<S>& pset);
mln_image_from(S, bool) to_image(const Point_Set<S>& pset);
/// Convert a window \p win into a binary image.
template <typename W>
image2d_b<bool> to_image(const Window<W>& win);
mln_image_from(W, bool) to_image(const Window<W>& win);
/// Convert a neighborhood \p nbh into a binary image.
template <typename N>
image2d_b<bool> to_image(const Neighborhood<N>& nbh);
mln_image_from(N, bool) to_image(const Neighborhood<N>& nbh);
/// Convert a weighted window \p w_win into an image.
template <typename W>
image2d_b<mln_weight(W)> to_image(const Weighted_Window<W>& w_win);
mln_image_from(W, mln_weight(W)) to_image(const Weighted_Window<W>& w_win);
# ifndef MLN_INCLUDE_ONLY
template <typename S>
image2d_b<bool> to_image(const Point_Set<S>& pset_)
mln_image_from(S, bool) to_image(const Point_Set<S>& pset_)
{
const S& pset = exact(pset_);
image2d_b<bool> ima(pset.bbox());
mln_image_from(S, bool) ima(pset.bbox());
level::fill(ima, false);
mln_piter(S) p(pset);
for_all(p)
......@@ -83,14 +120,14 @@ namespace mln
}
template <typename W>
image2d_b<bool> to_image(const Window<W>& win_)
mln_image_from(W, bool) to_image(const Window<W>& win_)
{
const W& win = exact(win_);
mln_precondition(! win.is_empty());
typedef mln_point(W) P;
box2d b = geom::bbox(win);
image2d_b<bool> ima(b);
mln_image_from(W, bool) ima(b);
level::fill(ima, false);
mln_qiter(W) q(win, P::zero);
for_all(q)
......@@ -99,20 +136,20 @@ namespace mln
}
template <typename N>
image2d_b<bool> to_image(const Neighborhood<N>& nbh)
mln_image_from(N, bool) to_image(const Neighborhood<N>& nbh)
{
return to_image(convert::to_window(nbh));
}
template <typename W>
image2d_b<mln_weight(W)> to_image(const Weighted_Window<W>& w_win_)
mln_image_from(W, mln_weight(W)) to_image(const Weighted_Window<W>& w_win_)
{
const W& w_win = exact(w_win_);
mln_precondition(! w_win.is_empty());
typedef mln_point(W) P;
box2d b = geom::bbox(w_win);
image2d_b<mln_weight(W)> ima(b);
mln_image_from(W, mln_weight(W)) ima(b);
mln_qiter(W) q(w_win, P::zero);
for_all(q)
ima(q) = q.w();
......
......@@ -33,9 +33,10 @@
* \brief Conversions to mln::window.
*/
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/core/window.hh>
# include <mln/pw/image.hh>
# include <mln/pw/cst.hh>
namespace mln
......@@ -48,9 +49,13 @@ namespace mln
template <typename N>
window<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh);
/// Convert a binary image \p input into a window.
/// Convert a binary image \p ima into a window.
template <typename I>
window<mln_dpoint(I)> to_window(const Image<I>& input);
window<mln_dpoint(I)> to_window(const Image<I>& ima);
/// Convert a point set \p pset into a window.
template <typename S, typename F>
window<mln_dpoint(S)> to_window(const Point_Set<S>& pset);
# ifndef MLN_INCLUDE_ONLY
......@@ -69,21 +74,27 @@ namespace mln
}
template <typename I>
window<mln_dpoint(I)> to_window(const Image<I>& input_)
window<mln_dpoint(I)> to_window(const Image<I>& ima_)
{
const I& input = exact(input_);
mln_precondition(input.has_data());
// FIXME: Check that input is binary!
const I& ima = exact(ima_);
mln_precondition(ima.has_data());
// FIXME: Check that ima is binary!
typedef mln_dpoint(I) D;
typedef mln_point(D) P;
window<D> win;
mln_piter(I) p(input.domain());
mln_piter(I) p(ima.domain());
for_all(p)
if (input(p))
if (ima(p))
win.insert(p - P::zero);
return win;
}
template <typename S, typename F>
window<mln_dpoint(S)> to_window(const Point_Set<S>& pset)
{
return to_window(pw::cst(true) | pset);
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert
......
......@@ -59,6 +59,9 @@ namespace mln
/// Dpoint associated type.
typedef void dpoint;
/// Point associated type.
typedef void point;
};
} // end of namespace mln::doc
......
......@@ -99,6 +99,7 @@ namespace mln
template <typename E>
struct Function_p2b : public Function_p2v<E>
{
typedef bool result;
protected:
Function_p2b();
};
......
......@@ -52,6 +52,7 @@ namespace mln
typedef bkd_niter;
typedef dpoint;
typedef point;
*/
protected:
......@@ -68,6 +69,7 @@ namespace mln
typedef mln_fwd_niter(E) fwd_niter;
typedef mln_bkd_niter(E) bkd_niter;
typedef mln_dpoint(E) dpoint;
typedef mln_point(E) point;
}
# endif // ! MLN_INCLUDE_ONLY
......
......@@ -58,6 +58,9 @@ namespace mln
/// Dpoint associated type.
typedef D dpoint;
/// Point associated type.
typedef mln_point(D) point;
/*! \brief Point_Iterator type to browse the points of a generic
* neighborhood w.r.t. the ordering of delta-points.
*/
......
......@@ -34,7 +34,7 @@
*/
# include <mln/accu/mean.hh>
# include <mln/level/run.hh>
# include <mln/level/compute.hh>
namespace mln
......@@ -46,20 +46,40 @@ namespace mln
/*! \brief Compute the mean value of the pixels of image \p input.
*
* \param[in] input The image.
* \return The mean value.
*/
template <typename I>
mln_sum(mln_value(I)) mean(const Image<I>& input);
/*! \brief Compute the mean value of the pixels of image \p input.
*
* \param[in] input The image.
* \param[out] result The mean value.
*
* The free parameter \c S is the type used to compute the
* summation.
*/
template <typename S, typename I, typename M>
void mean(const Image<I>& input, M& result);
# ifndef MLN_INCLUDE_ONLY
template <typename I>
mln_sum(mln_value(I)) mean(const Image<I>& input)
{
mln_precondition(exact(input).has_data());
typedef mln_value(I) V;
typedef mln_sum(V) S;
return level::run(input, accu::mean<V, S>()).to_value();
return level::compute(input,
accu::mean<mln_value(I)>()).to_value();
}
template <typename S, typename I, typename M>
void mean(const Image<I>& input, M& result)
{
mln_precondition(exact(input).has_data());
result = level::compute(input,
accu::mean<mln_value(I), S, M>()).to_value();
}
# endif // ! MLN_INCLUDE_ONLY
......
// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef MLN_ESTIM_SUM_HH
# define MLN_ESTIM_SUM_HH
/*! \file mln/estim/sum.hh
*
* \brief Compute the sum pixel value.
*/
# include <mln/accu/sum.hh>
# include <mln/level/compute.hh>
namespace mln
{
namespace estim
{
/*! \brief Compute the sum value of the pixels of image \p input.
*
* \param[in] input The image.
* \return The sum value.
*/
template <typename I>
mln_sum(mln_value(I)) sum(const Image<I>& input);
/*! \brief Compute the sum value of the pixels of image \p input.
*
* \param[in] input The image.
* \param[out] result The sum value.
*/
template <typename I, typename S>
void sum(const Image<I>& input, S& result);
# ifndef MLN_INCLUDE_ONLY
template <typename I>
mln_sum(mln_value(I)) sum(const Image<I>& input)
{
mln_precondition(exact(input).has_data());
return level::compute(input, accu::sum<mln_value(I)>()).to_value();
}
template <typename I, typename S>
void sum(const Image<I>& input, S& result)
{
mln_precondition(exact(input).has_data());
result = level::compute(input,
accu::sum<mln_value(I), S>()).to_value();
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::estim
} // end of namespace mln
#endif // ! MLN_ESTIM_SUM_HH
// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef MLN_FUN_C_HH
# define MLN_FUN_C_HH
/*! \file mln/fun/c.hh
*
* \brief FIXME.
*/
# include <mln/fun/internal/selector.hh>
# include <mln/metal/unqualif.hh>
namespace mln
{
namespace fun
{
template <typename F> struct C;
// FIXME: Doc!
template <typename R, typename A>
struct C< R (*)(A) >
:
fun::internal::selector_< R, A, C<R(*)(A)> >::ret
{
C(R (*f)(A));
typedef R result;
R operator()(const mlc_unqualif(A)& a) const;
protected:
R (*f_)(A);
};
# ifndef MLN_INCLUDE_ONLY
template <typename R, typename A>
C<R(*)(A)>::C(R (*f)(A))
: f_(f)
{
}
template <typename R, typename A>
R
C<R(*)(A)>::operator()(const mlc_unqualif(A)& a) const
{
return f_(a);
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::fun
} // end of namespace mln
#endif // ! MLN_FUN_P2B_C_HH
// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef MLN_FUN_INTERNAL_SELECTOR_HH
# define MLN_FUN_INTERNAL_SELECTOR_HH
/*! \file mln/fun/internal/selector.hh
*
* \brief FIXME.
*/
# include <mln/core/concept/function.hh>
# include <mln/core/concept/point.hh>
# include <mln/metal/unqualif.hh>
# include <mln/metal/if.hh>
# include <mln/metal/is_a.hh>