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

Add oln_plain_value, update level::apply, and provide a sample test code.

	* oln/core/internal/f_ch_value.hh (oln_plain_value): New.
	* oln/core/internal/image_base.hh (include): Add f_ch_value.
	* oln/level/apply.hh: Inactivate almost the whole code.
	(apply): Update a single version.
	* tests/core/apply.cc: New.
	* tests/core/Makefile.am: Update.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@870 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 3ee9a03a
2007-03-13 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add oln_plain_value, update level::apply, and provide a sample test code.
* oln/core/internal/f_ch_value.hh (oln_plain_value): New.
* oln/core/internal/image_base.hh (include): Add f_ch_value.
* oln/level/apply.hh: Inactivate almost the whole code.
(apply): Update a single version.
* tests/core/apply.cc: New.
* tests/core/Makefile.am: Update.
2007-03-13 Thierry Geraud <thierry.geraud@lrde.epita.fr> 2007-03-13 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add plain and ch_value functions on images. Add plain and ch_value functions on images.
......
...@@ -38,6 +38,10 @@ oln::internal::f_ch_value_< stc_type_in_(oln, I, skeleton), T >::ret ...@@ -38,6 +38,10 @@ oln::internal::f_ch_value_< stc_type_in_(oln, I, skeleton), T >::ret
typename oln::internal::f_ch_value_< stc_type_in(oln, I, skeleton), T >::ret typename oln::internal::f_ch_value_< stc_type_in(oln, I, skeleton), T >::ret
# define oln_plain_value(I, T) \
typename oln::internal::f_ch_value_< stc_type_in(oln, oln_plain(I), skeleton), T >::ret
namespace oln namespace oln
{ {
......
...@@ -416,4 +416,9 @@ namespace oln ...@@ -416,4 +416,9 @@ namespace oln
} // end of namespace oln } // end of namespace oln
// FIXME: Bad!
# include <oln/core/internal/f_ch_value.hh>
#endif // ! OLN_CORE_INTERNAL_IMAGE_BASE_HH #endif // ! OLN_CORE_INTERNAL_IMAGE_BASE_HH
...@@ -29,9 +29,7 @@ ...@@ -29,9 +29,7 @@
#ifndef OLN_LEVEL_APPLY_HH #ifndef OLN_LEVEL_APPLY_HH
# define OLN_LEVEL_APPLY_HH # define OLN_LEVEL_APPLY_HH
# include <oln/core/abstract/image.hh> # include <oln/core/concept/image.hh>
# include <oln/core/abstract/iterator.hh>
# include <oln/core/abstract/functions.hh>
namespace oln namespace oln
...@@ -41,22 +39,23 @@ namespace oln ...@@ -41,22 +39,23 @@ namespace oln
{ {
/// Fwd decl. /// Fwd decl.
template <typename I, typename V> template <typename R, typename A, typename I>
oln_plain_value(I, V) oln_plain_value(I, R)
apply(const abstract::image<I>& input, V (*fun)(const oln_value(I)&)); apply(R (*fun)(A), const Image<I>& input);
/// Fwd decl.
template <typename I, typename F>
oln_plain_value(I, typename F::result_value)
apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun);
/// Fwd decl. // /// Fwd decl.
template <typename I, typename V> // template <typename I, typename F>
void apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&)); // oln_plain_value(I, typename F::result_value)
// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun);
/// Fwd decl. // /// Fwd decl.
template <typename I, typename F> // template <typename I, typename V>
void apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun); // void apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&));
// /// Fwd decl.
// template <typename I, typename F>
// void apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun);
# ifndef OLN_INCLUDE_ONLY # ifndef OLN_INCLUDE_ONLY
...@@ -65,85 +64,87 @@ namespace oln ...@@ -65,85 +64,87 @@ namespace oln
{ {
/// Generic version. /// Generic version.
template <typename I, typename V>
oln_plain_value(I, V)
apply(const abstract::image<I>& input, V (*fun)(const oln_value(I)&))
{
oln_plain_value(I, V) output(input.topo());
oln_piter(I) p(input.topo());
for_all(p)
output(p) = fun(input(p));
return output;
}
/// Generic version. template <typename R, typename A, typename I>
template <typename I, typename F> oln_plain_value(I, R)
oln_plain_value(I, typename F::result_value) apply(R (*fun)(A), const Image<I>& input)
apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
{ {
oln_plain_value(I, typename F::result_value) output(input.topo()); oln_plain_value(I, R) output(input.points());
oln_piter(I) p(input.topo()); oln_piter(I) p(input.points());
for_all(p) for_all(p)
output(p) = fun.exact()(input(p)); output(p) = fun(input(p));
return output; return output;
} }
/// Generic version. // /// Generic version.
template <typename I, typename V> // template <typename I, typename F>
void // oln_plain_value(I, typename F::result_value)
apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&)) // apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
{ // {
oln_piter(I) p(input.topo()); // oln_plain_value(I, typename F::result_value) output(input.topo());
for_all(p) // oln_piter(I) p(input.topo());
input(p) = fun(input(p)); // for_all(p)
} // output(p) = fun.exact()(input(p));
// return output;
/// Generic version. // }
template <typename I, typename F>
void
apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun) // /// Generic version.
{ // template <typename I, typename V>
oln_piter(I) p(input.topo()); // void
for_all(p) // apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&))
input(p) = fun.exact()(input(p)); // {
} // oln_piter(I) p(input.topo());
// for_all(p)
// input(p) = fun(input(p));
// }
// /// Generic version.
// template <typename I, typename F>
// void
// apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun)
// {
// oln_piter(I) p(input.topo());
// for_all(p)
// input(p) = fun.exact()(input(p));
// }
} // end of namespace oln::level::impl } // end of namespace oln::level::impl
/// Facade. /// Facade.
template <typename I, typename V> template <typename R, typename A, typename I>
oln_plain_value(I, V) oln_plain_value(I, R)
apply(const abstract::image<I>& input, V (*fun)(const oln_value(I)&)) apply(R (*fun)(A), const Image<I>& input)
{
return impl::apply(input, fun);
}
/// Facade.
template <typename I, typename F>
oln_plain_value(I, typename F::result_value)
apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
{
return impl::apply(input, fun);
}
/// Facade.
template <typename I, typename V>
void
apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&))
{ {
return impl::apply_inplace(input, fun); return impl::apply(fun, exact(input));
} }
/// Facade. // /// Facade.
template <typename I, typename F> // template <typename I, typename F>
void // oln_plain_value(I, typename F::result_value)
apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun) // apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
{ // {
return impl::apply_inplace(input, fun); // return impl::apply(input, fun);
} // }
// /// Facade.
// template <typename I, typename V>
// void
// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&))
// {
// return impl::apply_inplace(input, fun);
// }
// /// Facade.
// template <typename I, typename F>
// void
// apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun)
// {
// return impl::apply_inplace(input, fun);
// }
# endif # endif
......
...@@ -19,6 +19,7 @@ AM_CXXFLAGS = $(TESTS_CXXFLAGS) ...@@ -19,6 +19,7 @@ AM_CXXFLAGS = $(TESTS_CXXFLAGS)
check_PROGRAMS = \ check_PROGRAMS = \
apply \
dpoint2d \ dpoint2d \
point2d \ point2d \
grid \ grid \
...@@ -41,5 +42,8 @@ neighb2d_SOURCES = neighb2d.cc ...@@ -41,5 +42,8 @@ neighb2d_SOURCES = neighb2d.cc
# Methods. # Methods.
at_SOURCES = at.cc at_SOURCES = at.cc
# FIXME: Temp!
apply_SOURCES = apply.cc
TESTS = $(check_PROGRAMS) TESTS = $(check_PROGRAMS)
// 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.
// FIXME: Move this file into tests/level/.
#include <oln/core/2d/image2d.hh>
#include <oln/level/apply.hh>
namespace my
{
bool negate(bool b)
{
return not b;
}
}
int main()
{
using namespace oln;
image2d<bool> ima(3,3);
ima = level::apply(my::negate, ima);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment