https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add level::paste for fast images and fix line_piter.
* tests/line_piter.cc: Fix doc.
(main): Start at non-zero point.
* mln/core/line_piter.hh (operator[]): Fix.
(next_): Fix.
* mln/level/paste.hh: Specialize for Fast_Image.
* tests/level_paste.cc: New.
mln/core/line_piter.hh | 4 +--
mln/level/paste.hh | 36 ++++++++++++++++++++++++++++--
tests/level_paste.cc | 58 +++++++++++++++++++++++++++++++++++++++++++++++++
tests/line_piter.cc | 13 +++-------
4 files changed, 98 insertions(+), 13 deletions(-)
Index: tests/level_paste.cc
--- tests/level_paste.cc (revision 0)
+++ tests/level_paste.cc (revision 0)
@@ -0,0 +1,58 @@
+// 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_fill.cc
+ *
+ * \brief Tests on mln::level::fill
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/level/fill.hh>
+#include <mln/level/paste.hh>
+
+#include <mln/debug/iota.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ box2d b(make::point2d(1,2), make::point2d(2,4));
+ image2d_b<int> ima(b, 2);
+ debug::iota(ima);
+ debug::println(ima);
+
+
+ box2d b2(make::point2d(-1,-2), make::point2d(3,6));
+ image2d_b<int> ima2(b2, 0);
+ debug::iota(ima2);
+ debug::println(ima2);
+
+ level::paste(ima, ima2);
+ debug::println(ima2);
+}
Index: tests/line_piter.cc
--- tests/line_piter.cc (revision 1123)
+++ tests/line_piter.cc (working copy)
@@ -25,9 +25,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/image2d_b.cc
+/*! \file tests/line_piter.cc
*
- * \brief Tests on mln::image2d_b.
+ * \brief Tests on mln::line_piter.
*/
#include <mln/core/image2d_b.hh>
@@ -37,16 +37,11 @@
{
using namespace mln;
- const unsigned nrows = 6;
- const unsigned ncols = 4;
+ box2d b(make::point2d(1,2), make::point2d(5,8));
const unsigned border = 2;
-
- image2d_b<int> f(nrows, ncols, border);
+ image2d_b<int> f(b, border);
image2d_b<int>::line_piter p(f.domain());
-
for_all(p)
- {
std::cout << p <<std::endl;
}
-}
Index: mln/core/line_piter.hh
--- mln/core/line_piter.hh (revision 1123)
+++ mln/core/line_piter.hh (working copy)
@@ -118,7 +118,7 @@
mln_coord(P)
line_piter_<P>::operator[](unsigned i) const
{
- mln_invariant(p_[0] = 0);
+ mln_invariant(p_[dim - 1] = b_.pmin()[dim - 1]);
assert(i < dim);
return p_[i];
}
@@ -148,7 +148,7 @@
void
line_piter_<P>::next_()
{
- for (int c = 1; c < dim; ++c)
+ for (int c = dim - 2; c >= 0; --c)
{
if (p_[c] != b_.pmax()[c])
{
Index: mln/level/paste.hh
--- mln/level/paste.hh (revision 1123)
+++ mln/level/paste.hh (working copy)
@@ -34,6 +34,8 @@
*/
# include <mln/core/concept/image.hh>
+# include <mln/core/inplace.hh>
+# include <mln/level/memcpy_.hh>
namespace mln
@@ -64,18 +66,48 @@
# ifndef MLN_INCLUDE_ONLY
+ namespace impl
+ {
+
template <typename I, typename J>
- void paste(const Image<I>& data_, Image<J>& destination_)
+ void paste_(const Image<I>& data_, Image<J>& destination_)
{
const I& data = exact(data_);
J& destination = exact(destination_);
- mln_precondition(data.domain() <= destination.domain());
mln_piter(I) p(data.domain());
for_all(p)
destination(p) = data(p);
}
+ template <typename I, typename J>
+ void paste_(const Fast_Image<I>& data_, Fast_Image<J>&
destination_)
+ {
+ const I& data = exact(data_);
+ J& destination = exact(destination_);
+
+ typedef mln_point(I) P;
+ std::size_t n = data.bbox().len(P::dim - 1);
+
+ typename I::line_piter p(data.domain());
+ for_all(p)
+ memcpy_(inplace(make::pixel(destination, p)),
+ make::pixel(data, p),
+ n);
+ }
+
+ } // end of namespace mln::level::impl
+
+
+ // Facade.
+
+ template <typename I, typename J>
+ void paste(const Image<I>& data, Image<J>& destination)
+ {
+ mln_precondition(exact(data).domain() <= exact(destination).domain());
+ impl::paste_(exact(data), exact(destination));
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::level