URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-11 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add fill, paste for fast_image and FIXME rle and sparse image.
* fill.hh: New.
* fills_test.cc: .
* main.cc: New.
* mem.hh: New.
* paste.hh: New.
---
fill.hh | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
fills_test.cc | 7 ++-
main.cc | 34 +++++++++++++++
mem.hh | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++
paste.hh | 35 +++++++++++++++
5 files changed, 319 insertions(+), 2 deletions(-)
Index: trunk/milena/sandbox/duhamel/fill.hh
===================================================================
--- trunk/milena/sandbox/duhamel/fill.hh (revision 0)
+++ trunk/milena/sandbox/duhamel/fill.hh (revision 1102)
@@ -0,0 +1,127 @@
+# include <cstring>
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/function.hh>
+# include <mln/level/memset_.hh>
+
+
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/debug/println.hh>
+
+
+#include <mln/geom/nrows.hh>
+#include <mln/geom/ncols.hh>
+
+#include <mln/level/fill.hh>
+
+#include <mln/debug/println_with_border.hh>
+
+namespace mln
+{
+
+ namespace level
+ {
+
+ template <typename I>
+ void fill_opt1(I& ima, const mln_value(I)& value)
+ {
+ mln_pixter(I) pix(ima);
+ mln_pixter(I) s(ima);
+
+ pix.start();
+ s.start ();
+
+ mln_coord(I) min_row = geom::min_row(exact(ima));
+ mln_coord(I) min_col = geom::min_col(exact(ima));
+ mln_coord(I) max_row = geom::max_row(exact(ima));
+ mln_coord(I) max_col = geom::max_col(exact(ima));
+
+ mln_coord(I) nb_cols = max_col - min_col;
+ mln_coord(I) nb_rows = max_row - min_row;
+
+ std::cerr << "min_row : "
+ << min_row
+ << std::endl
+ << "max_row : "
+ << max_row
+ << std::endl
+ << "min_col : "
+ << min_col
+ << std::endl
+ << "max_col : "
+ << max_col
+ << std::endl;
+
+ // fill row
+ for (std::size_t i = 0; i < nb_cols; ++i)
+ {
+ pix.val () = value;
+ pix.next ();
+ }
+
+ for (std::size_t i = 1; i < nb_rows; ++i)
+ {
+ // copy row into current row
+ std::memcpy (&(pix.val ()),
+ &(s.val ()),
+ sizeof(mln_value(I)) * nb_cols);
+
+ // Jump to next row
+ for (std::size_t j = 0; j < nb_cols; ++j)
+ pix.next ();
+ }
+
+ std::memcpy (&(pix.val ()),
+ &(s.val ()),
+ sizeof(mln_value(I)) * nb_cols);
+ }
+
+ template <typename I>
+ void fill_opt2(I& ima, const mln_value(I)& value)
+ {
+ mln_value(I)* ptr = & ima[0];
+
+ mln_pixter(I) pix(ima);
+ mln_pixter(I) s(ima);
+ point2d min = ima.bbox ().pmin ();
+ point2d u = min;
+ point2d v = min + down;
+ std::size_t k = ima.offset (down);
+ std::size_t max = ima.ncells() / k;
+
+ for (std::size_t i = 0; i < k; ++i)
+ *ptr++ = value;
+
+ ptr = & ima[0];
+
+ for (std::size_t i = 0;
+ i < max - 1;
+ ++i)
+ {
+ u = u + down;
+ std::memcpy (&ima[ima.offset (u - min)],
+ ptr,
+ sizeof (mln_value(I)) * k);
+ }
+ }
+
+ template <typename I, typename J>
+ void fill(sparse_image<I, J> & ima, const mln_value(J)& value)
+ {
+ mln::internal::run_pset_<I> my_set;
+
+ for (std::size_t i = 0; i < 0; ++i)
+ {
+
+ }
+ imaset_(ima, value, 42);
+ }
+
+ template <typename I, typename J>
+ void fill(rle_image<I, J> & ima, const mln_value(J)& value)
+ {
+ imaset_(ima, value, 42);
+ }
+ }
+}
Index: trunk/milena/sandbox/duhamel/main.cc
===================================================================
--- trunk/milena/sandbox/duhamel/main.cc (revision 0)
+++ trunk/milena/sandbox/duhamel/main.cc (revision 1102)
@@ -0,0 +1,34 @@
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/debug/println.hh>
+
+
+#include <mln/geom/nrows.hh>
+#include <mln/geom/ncols.hh>
+
+#include <mln/level/fill.hh>
+
+#include <mln/debug/println_with_border.hh>
+
+#include "paste.hh"
+#include "fill.hh"
+
+ using namespace mln;
+
+int main (void)
+{
+ image2d_b<int> i1(3, 3);
+ image2d_b<int> i2(3, 3);
+ mln::sparse_image<mln::point2d, int> sparse;
+ mln::sparse_image<mln::point2d, int> sparse2;
+ mln::rle_image<mln::point2d, int> rle1;
+ mln::rle_image<mln::point2d, int> rle2;
+
+// level::fill_opt2(i1, 8);
+// debug::println_with_border(i1);
+ level::paste(rle1, rle2);
+ // level::fill(sparse, 42);
+// debug::println_with_border(i2);
+
+ return (0);
+}
Index: trunk/milena/sandbox/duhamel/paste.hh
===================================================================
--- trunk/milena/sandbox/duhamel/paste.hh (revision 0)
+++ trunk/milena/sandbox/duhamel/paste.hh (revision 1102)
@@ -0,0 +1,35 @@
+#include "mem.hh"
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/fast_image.hh>
+# include <mln/core/sparse_image.hh>
+# include <mln/core/sparse_encode.hh>
+# include <mln/core/rle_image.hh>
+# include <mln/core/rle_encode.hh>
+
+namespace mln
+{
+ namespace level
+ {
+
+ template <typename I>
+ void paste(const I& data_, I& destination_)
+ {
+ imacpy_ (destination_, data_, destination_.ncells());
+ }
+
+ template <typename I, typename J>
+ void paste(const sparse_image<I, J>& data_, sparse_image<I, J>&
destination_)
+ {
+ imacpy_ (destination_, data_, data_.size ());
+ }
+
+ template <typename I, typename J>
+ void paste(const rle_image<I, J>& data_, rle_image<I, J>&
destination_)
+ {
+ imacpy_ (destination_, data_, data_.size ());
+ }
+
+
+ }
+}
Index: trunk/milena/sandbox/duhamel/mem.hh
===================================================================
--- trunk/milena/sandbox/duhamel/mem.hh (revision 0)
+++ trunk/milena/sandbox/duhamel/mem.hh (revision 1102)
@@ -0,0 +1,118 @@
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/debug/println.hh>
+
+
+#include <mln/geom/nrows.hh>
+#include <mln/geom/ncols.hh>
+
+#include <mln/level/fill.hh>
+
+#include <mln/debug/println_with_border.hh>
+
+# include <mln/core/sparse_image.hh>
+# include <mln/core/sparse_encode.hh>
+
+# include <mln/core/rle_image.hh>
+# include <mln/core/rle_encode.hh>
+
+namespace mln
+{
+ namespace level
+ {
+
+ template <typename I>
+ void imaset_(I& ima, const mln_value(I)& value, std::size_t n)
+ {
+ // FIXME Preconditions
+ mln_value(I)* ptr = &ima[0];
+
+ for (std::size_t i = 0; i < n; ++i)
+ *ptr++ = value;
+ }
+
+ template <typename I, typename J>
+ void imaset_(sparse_image<I, J>& ima_,
+ const mln_value(J)& value_,
+ std::size_t n)
+ {
+ // FIXME
+ const mln_value(I)& v;
+ std::size_t i = n;
+
+ i = n;
+ v = value_;
+ ima_.domain ();
+ std::cerr << "imaset_ sparse_image\n";
+ }
+
+ template <typename I, typename J>
+ void imaset_(rle_image<I, J>& ima_,
+ const mln_value(J)& value_,
+ std::size_t n)
+ {
+ // FIXME
+// mln::internal::run_pset_<I> my_set;
+ const mln_value(J)& v;
+
+ for (std::size_t i = 0; i < n; ++i)
+ ;
+
+ v = value_;
+ ima_.domain ();
+ std::cerr << "imaset_ sparse_image\n";
+ }
+
+ template <typename I>
+ void imacpy_(I& dst, I& src, std::size_t n)
+ {
+ // FIXME Preconditions
+ mln_value(I)* u = &dst[0];
+ mln_value(I)* v = &src[0];
+
+ for (std::size_t i = 0; i < n; ++i)
+ *u++ = *v++;
+ }
+
+ template <typename I>
+ void imacpy_(I& dst, const I& src, std::size_t n)
+ {
+ // FIXME Preconditions
+ mln_value(I)* u = &dst[0];
+ const mln_value(I)* v = &src[0];
+
+ for (std::size_t i = 0; i < n; ++i)
+ *u++ = *v++;
+ }
+
+ template <typename I, typename J>
+ void imacpy_(sparse_image<I, J>& dst,
+ const sparse_image<I, J>& src,
+ std::size_t n)
+ {
+ // mln::internal::run_pset_<I> my_set;
+
+ for (std::size_t i = 0; i < n; ++i)
+ ;
+
+ dst.domain ();
+ src.domain ();
+ std::cout << "imacpy_ sparse_image\n";
+
+ }
+
+ template <typename I, typename J>
+ void imacpy_(rle_image<I, J>& dst,
+ const rle_image<I, J>& src,
+ std::size_t n)
+ {
+ std::size_t i = n;
+
+ i = n;
+ dst.domain ();
+ src.domain ();
+ std::cout << "imacpy_ rle_image\n";
+ }
+
+ }
+}
Index: trunk/milena/sandbox/duhamel/fills_test.cc
===================================================================
--- trunk/milena/sandbox/duhamel/fills_test.cc (revision 1101)
+++ trunk/milena/sandbox/duhamel/fills_test.cc (revision 1102)
@@ -40,6 +40,9 @@
#include <mln/level/fill.hh>
+#include <mln/debug/println_with_border.hh>
+
+
namespace mln
{
@@ -213,10 +216,10 @@
debug::println(ima);
imaset_(i1, 3, 50);
- debug::println(i1);
+ debug::println_with_border(i1);
mln_assertion (i1[42] == 3);
imacpy_(i2, i1, 50);
- debug::println(i2);
+ debug::println_with_border(i2);
for (int i = 0; i < 50; ++i)
mln_assertion (i1[i] == i2[i]);