URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-20 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Fix duplicate border.
* border_duplicate.cc: Test for duplicate 3d.
* border_duplicate.hh: Fix for 1d and 3d.
* labeling_level_fast.cc: Update.
---
border_duplicate.cc | 61 +++++++++++++++----
border_duplicate.hh | 156 ++++++++++++++++++++++++++++++++++++++++++++++++-
labeling_level_fast.cc | 6 +
3 files changed, 207 insertions(+), 16 deletions(-)
Index: trunk/milena/sandbox/duhamel/border_duplicate.cc
===================================================================
--- trunk/milena/sandbox/duhamel/border_duplicate.cc (revision 1142)
+++ trunk/milena/sandbox/duhamel/border_duplicate.cc (revision 1143)
@@ -31,31 +31,68 @@
*/
#include "border_duplicate.hh"
+#include "border_fill.hh"
+#include <mln/core/image3d_b.hh>
#include <mln/core/image2d_b.hh>
+#include <mln/core/image1d_b.hh>
#include <mln/value/int_u8.hh>
#include <mln/pw/all.hh>
#include <mln/debug/println_with_border.hh>
+#include <mln/debug/iota.hh>
using namespace mln;
+template <typename I>
+void print_3d_with_border (const Fast_Image<I>& input_)
+{
+ const I& ima = exact(input_);
+ mln_precondition(ima.has_data());
+
+ typedef mln_point(I) P;
+
+ std::size_t len_s = exact(ima).bbox().len(P::dim - 3);
+ std::size_t len_r = exact(ima).bbox().len(P::dim - 1);
+ std::size_t len_c = exact(ima).bbox().len(P::dim - 2);
+ std::size_t border = ima.border ();
+ std::size_t real_len_s = len_s + 2 * border;
+ std::size_t real_len_r = len_r + 2 * border;
+ std::size_t real_len_c = len_c + 2 * border;
+
+ for (std::size_t k = 0; k < real_len_s; ++k)
+ {
+ for (std::size_t j = 0; j < real_len_c; ++j)
+ {
+ for (std::size_t i = 0; i < real_len_r; ++i)
+ std::cout << ima[k * (real_len_r * real_len_c) + j * real_len_r + i]
+ << " ";
+ std::cout << std::endl;
+ }
+ std::cout << std::endl;
+ }
+ std::cout << std::endl;
+}
+
int
main (void)
{
- image2d_b<value::int_u8> i1(10000, 1000);
- // Fill with randomized value.
-// for (unsigned int i = 0; i < i1.ncells (); ++i)
-// i1[i] = i;//(i * 4452) % 10;
-// std::cout << "before duplicate"
-// << std::endl
-// << std::endl;
-// debug::println_with_border(i1);
+ image3d_b<value::int_u8> i1(2, 3, 4, 2);
+ std::cerr << i1.ncells ()
+ << std::endl;
+ for (std::size_t i = 0; i < i1.ncells (); ++i)
+ i1[i] = i % 9 + 1;
+
+ border::fill (i1, 0);
+ std::cout << "before duplicate"
+ << std::endl
+ << std::endl;
+ print_3d_with_border(i1);
border::duplicate (i1);
-// std::cout << "after duplicate"
-// << std::endl
-// << std::endl;
-// debug::println_with_border(i1);
+ std::cout << "after duplicate"
+ << std::endl
+ << std::endl;
+ print_3d_with_border(i1);
}
Index: trunk/milena/sandbox/duhamel/border_duplicate.hh
===================================================================
--- trunk/milena/sandbox/duhamel/border_duplicate.hh (revision 1142)
+++ trunk/milena/sandbox/duhamel/border_duplicate.hh (revision 1143)
@@ -65,8 +65,11 @@
# ifndef MLN_INCLUDE_ONLY
+ namespace impl
+ {
+
template <typename I>
- void duplicate(const Fast_Image<I>& ima_)
+ void duplicate_(const Fast_Image<I>& ima_)
{
const I& ima = exact(ima_);
mln_precondition(ima.has_data());
@@ -127,10 +130,159 @@
for (std::size_t i = 0; i <= border; ++i)
for (std::size_t j = 0; j <= border; ++j)
const_cast<I&>(ima)[s + i + (j * real_nbcols)] = ima[s];
+ //END FIX
+ }
+
+ template <typename I>
+ void duplicate_1d_(const Fast_Image<I>& ima_)
+ {
+ const I& ima = exact(ima_);
+ mln_precondition(ima.has_data());
+ typedef mln_point(I) P;
+ typename I::line_piter pl(ima.domain());
+ std::size_t len_c = exact(ima).bbox().len(P::dim - 1);
+ std::size_t border = ima.border ();
+ for (std::size_t i = 0; i < border; ++i)
+ const_cast<I&>(ima)[i] = ima[border];
- //END FIX
+ std::size_t st = border + len_c - 1;
+ for (std::size_t i = st + 1; i < ima.ncells (); ++i)
+ const_cast<I&>(ima)[i] = ima[st];
+ }
+
+ template <typename I>
+ void duplicate_2d_(const Fast_Image<I>& ima_)
+ {
+ const I& ima = exact(ima_);
+ mln_precondition(ima.has_data());
+
+ typedef mln_point(I) P;
+ typename I::line_piter pl(ima.domain());
+ std::size_t border = ima.border ();
+ std::size_t border_2x = 2 * ima.border ();
+ std::size_t len_c = exact(ima).bbox().len(P::dim - 1);
+ std::size_t len_r = exact(ima).bbox().len(P::dim - 2);
+ std::size_t real_len_c = len_c + border_2x;
+
+
+ pl.start ();
+
+ // Duplicate first line
+ std::size_t st = ima.offset_at (pl);
+ for (std::size_t i = 0; i < border; ++i)
+ const_cast<I&>(ima)[i] = ima[st];
+
+ std::size_t end = len_c + border;
+ for (std::size_t i = 0; i < len_c; ++i)
+ const_cast<I&>(ima)[border + i] = ima[st + i];
+
+ end = len_c + border * 2;
+ for (std::size_t i = len_c + border; i < end; ++i)
+ const_cast<I&>(ima)[i] = ima[len_c + border - 1];
+
+ // Duplicate n * border line
+ for (std::size_t k = 1; k < border; ++k)
+ for (std::size_t i = 0; i < real_len_c; ++i)
+ const_cast<I&>(ima)[k * real_len_c + i] = ima[i];
+
+ // Duplicate
+ for_all (pl)
+ {
+ st = ima.offset_at (pl);
+ for (std::size_t i = 1; i <= border; ++i)
+ const_cast<I&>(ima)[st - i] = ima[st];
+ st = st + len_c - 1;
+ for (std::size_t i = 1; i <= border; ++i)
+ const_cast<I&>(ima)[st + i] = ima[st];
+ }
+
+ // Duplicate n last * border line
+ st = real_len_c * (border + len_r - 1);
+ for (std::size_t k = 1; k <= border; ++k)
+ for (std::size_t i = st; i < st + real_len_c; ++i)
+ const_cast<I&>(ima)[k * real_len_c + i] = ima[i];
+ }
+
+ template <typename I>
+ void duplicate_3d_(const Fast_Image<I>& ima_)
+ {
+ const I& ima = exact(ima_);
+ mln_precondition(ima.has_data());
+
+ typedef mln_point(I) P;
+ typename I::line_piter pl(ima.domain());
+ std::size_t border = ima.border ();
+ std::size_t border_2x = 2 * ima.border ();
+ std::size_t len_c = exact(ima).bbox().len(P::dim - 1);
+ std::size_t len_r = exact(ima).bbox().len(P::dim - 2);
+ std::size_t len_s = exact(ima).bbox().len(P::dim - 3);
+ std::size_t real_len_c = len_c + border_2x;
+ std::size_t real_len_r = len_r + border_2x;
+ std::size_t face = real_len_c * real_len_r;
+ std::size_t st;
+
+ pl.start ();
+
+ for (std::size_t k = 0; k < len_s; ++k)
+ {
+
+ // Duplicate
+ for (std::size_t j = 0; j < len_r; ++j)
+ {
+ st = ima.offset_at (pl);
+ for (std::size_t i = 1; i <= border; ++i)
+ const_cast<I&>(ima)[st - i] = ima[st];
+ st = st + len_c - 1;
+ for (std::size_t i = 1; i <= border; ++i)
+ const_cast<I&>(ima)[st + i] = ima[st];
+ pl.next ();
+ }
+
+ // Duplicate n last * border line
+ st = border * face + k * face + border * real_len_c ;
+ for (std::size_t j = 1; j <= border; ++j)
+ for (std::size_t i = 0; i < real_len_c; ++i)
+ const_cast<I&>(ima)[st - j * real_len_c + i] = ima[st + i];
+
+ // Duplicate n last * border line
+ st = border * face + k * face + (len_r + border - 1) * real_len_c ;
+ for (std::size_t j = 1; j <= border; ++j)
+ for (std::size_t i = 0; i < real_len_c; ++i)
+ const_cast<I&>(ima)[st + j * real_len_c + i] = ima[st + i];
+ }
+
+ // Duplicate n first * border face
+ st = border * face;
+ for (std::size_t k = 0; k < border; ++k)
+ for (std::size_t i = 0; i < face; ++i)
+ const_cast<I&>(ima)[k * face + i] = ima[st + i];
+
+ // Duplicate n last * border face
+ st = (len_s + border - 1) * face;
+ for (std::size_t k = 1; k <= border; ++k)
+ for (std::size_t i = 0; i < face; ++i)
+ const_cast<I&>(ima)[st + k * face + i] = ima[st + i];
+ }
+
+
+
+ } // end of namespace mln::border::impl
+
+
+ // Facade.
+
+ template <typename I>
+ void duplicate(const Fast_Image<I>& ima_)
+ {
+ typedef mln_point(I) P;
+ if (P::dim == 1)
+ impl::duplicate_1d_(ima_);
+ if (P::dim == 2)
+ impl::duplicate_2d_(ima_);
+ if (P::dim == 3)
+ impl::duplicate_3d_(ima_);
}
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/sandbox/duhamel/labeling_level_fast.cc
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_level_fast.cc (revision 1142)
+++ trunk/milena/sandbox/duhamel/labeling_level_fast.cc (revision 1143)
@@ -31,6 +31,7 @@
*/
#include <mln/core/image2d_b.hh>
+#include <mln/core/image1d_b.hh>
#include <mln/core/neighb2d.hh>
#include <mln/value/int_u8.hh>
#include <mln/pw/all.hh>
@@ -52,9 +53,10 @@
unsigned border = 1;
- image2d_b<value::int_u8> i1(3, 3, border);
+ image2d_b<value::int_u8> i1(5, 5, border);
debug::iota(i1);
- i1[12] = i1[18] = 2;
+ i1[10] = i1[17] = i1[18] = i1[25] = i1[26] = i1[22] = i1[29] = 2;
+ // i1[5] = i1[6] = 2;
debug::println_with_border(i1);
unsigned n;