URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-01-25 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Add a replace routine.
* mln/level/replace.hh: New, the routine replace a value by another
one in an image.
* tests/level/replace.cc: New, a little test.
---
mln/level/replace.hh | 105 +++++++++++++++++++++++++++++++++++++++++++++++++
tests/level/replace.cc | 63 +++++++++++++++++++++++++++++
2 files changed, 168 insertions(+)
Index: trunk/milena/tests/level/replace.cc
===================================================================
--- trunk/milena/tests/level/replace.cc (revision 0)
+++ trunk/milena/tests/level/replace.cc (revision 1683)
@@ -0,0 +1,63 @@
+// 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.
+
+/*! \file tests/level/replace.cc
+ *
+ * \brief Tests on mln::level::replace.
+ */
+
+#include <mln/core/image2d.hh>
+#include <mln/level/replace.hh>
+#include <mln/level/compare.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ int vs[3][3] = {
+
+ { 10, 3, 4 },
+ { 5, 10, 7 },
+ { 8, 9, 10 },
+
+ };
+
+ image2d<int> rhs = make::image2d(vs);
+
+ level::replace(rhs, 10, 11);
+
+ int vs_ref[3][3] = {
+
+ { 11, 3, 4 },
+ { 5, 11, 7 },
+ { 8, 9, 11 },
+ };
+
+ mln_assertion(make::image2d(vs_ref) == rhs);
+
+}
Index: trunk/milena/mln/level/replace.hh
===================================================================
--- trunk/milena/mln/level/replace.hh (revision 0)
+++ trunk/milena/mln/level/replace.hh (revision 1683)
@@ -0,0 +1,105 @@
+// Copyright (C) 2007, 2008 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_LEVEL_REPLACE_HH
+# define MLN_LEVEL_REPLACE_HH
+
+/*! \file mln/level/replace.hh
+ *
+ * \brief Replace the contents of an image into another one.
+ *
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/image_if.hh>
+
+# include <mln/level/fill.hh>
+# include <mln/pw/value.hh>
+# include <mln/pw/cst.hh>
+
+namespace mln
+{
+
+ namespace level
+ {
+
+ /*! Replace \p old_value by \p new_value in the image \p input
+ *
+ * \param[in] input The input image.
+ * \param[in] old_value The value to be replaced...
+ * \param[in] new_value ...by this one.
+ *
+ */
+ template <typename I>
+ void replace(Image<I>& input, const mln_value(I)& old_value,
+ const mln_value(I)& new_value);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ namespace generic
+ {
+
+ template <typename I>
+ inline
+ void replace_(Image<I>& input_, const mln_value(I)& old_value,
+ const mln_value(I)& new_value)
+ {
+ trace::entering("level::impl::generic::replace");
+ level::fill(inplace(exact(input_) | pw::value(input_) == pw::cst(old_value)),
new_value);
+ trace::exiting("level::impl::generic::replace");
+ }
+
+ } // end of namespace mln::level::impl::generic
+
+ } // end of namespace mln::level::impl
+
+
+ // Facade.
+ template <typename I>
+ void replace(Image<I>& input, const mln_value(I)& old_value,
+ const mln_value(I)& new_value)
+ {
+ trace::entering("level::replace");
+
+ mln_precondition(exact(input).has_data());
+
+ impl::generic::replace_<I>(exact(input), old_value, new_value);
+ trace::exiting("level::replace");
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LEVEL_REPLACE_HH