URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-18 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add tests for labeling level.
* labeling_level_fast_10000x1000.cc: Test labeling::level with
fast version.
* labeling_level_generic_10000x1000.cc: Test labeling::level with
generic version.
* labeling_level_fast.cc,
* labeling_level.hh,
* border_fill.hh: Update.
---
border_fill.hh | 18 +++++++---
labeling_level.hh | 33 +++++++++++++++++-
labeling_level_fast.cc | 14 -------
labeling_level_fast_10000x1000.cc | 63 +++++++++++++++++++++++++++++++++++
labeling_level_generic_10000x1000.cc | 63 +++++++++++++++++++++++++++++++++++
5 files changed, 171 insertions(+), 20 deletions(-)
Index: trunk/milena/sandbox/duhamel/border_fill.hh
===================================================================
--- trunk/milena/sandbox/duhamel/border_fill.hh (revision 1128)
+++ trunk/milena/sandbox/duhamel/border_fill.hh (revision 1129)
@@ -39,10 +39,11 @@
//# include <mln/core/line_piter.hh>
#include <mln/geom/nrows.hh>
#include <mln/geom/ncols.hh>
-#include <mln/core/image2d_b.hh>
-#include <mln/core/image2d_b.hh>
#include <mln/core/pixel.hh>
#include <mln/core/line_piter.hh>
+# include <mln/core/inplace.hh>
+# include <mln/level/memcpy_.hh>
+# include <mln/core/point2d.hh>
namespace mln
{
@@ -72,7 +73,7 @@
const I& ima = exact(ima_);
mln_precondition(ima.has_data());
// FIX
- typedef mln_point(I) point;
+ typedef mln_point(I) P;
typedef mln_dpoint(I) delta_point;
Fast_Image<I> im (ima);
@@ -80,15 +81,24 @@
std::size_t border = ima.border ();
std::size_t nbrows = geom::max_row(ima) - geom::min_row(ima);
std::size_t nbcols = geom::max_col(ima) - geom::min_col(ima);
+ // std::size_t n = ima.bbox().len(P::dim - 1);
point2d p = ima.bbox ().pmin ();
// FIXME : REMOVE THIS LOOP BY MEMSET
-
std::size_t s = border * (2 * (border + 1) + nbcols);
for (std::size_t i = 0; i < s; ++i)
const_cast<I&>(ima)[i] = v;
+ // typename I::line_piter p(ima.domain());
+
+// for (std::size_t i = 0; i < border; ++i, p = p.next ())
+// {
+// // memset_(inplace(make::pixel(ima, p)),
+// // v,
+// // n);
+// }
+
// ACCESS TO RIGHT UP CORNER
s = nbcols + 1;
for (std::size_t i = 0; i < s; ++i)
Index: trunk/milena/sandbox/duhamel/labeling_level_generic_10000x1000.cc
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_level_generic_10000x1000.cc (revision 0)
+++ trunk/milena/sandbox/duhamel/labeling_level_generic_10000x1000.cc (revision 1129)
@@ -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/labeling_foreground.cc
+ *
+ * \brief Test on mln::labeling::foreground.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/neighb2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/pw/all.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/labeling/level.hh>
+#include <mln/debug/iota.hh>
+#include <mln/debug/println_with_border.hh>
+
+#include "paste.hh"
+#include "fill.hh"
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ unsigned border = 1;
+
+ image2d_b<value::int_u8> i1(10000, 1000, border);
+ i1[10009] = i1[10010] = 2;
+
+ unsigned n;
+ image2d_b<value::int_u8> out(i1.domain(), border);
+ labeling::level(i1, 2, c4(), out, n);
+
+ mln_assertion (n == 1);
+}
Index: trunk/milena/sandbox/duhamel/labeling_level.hh
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_level.hh (revision 1128)
+++ trunk/milena/sandbox/duhamel/labeling_level.hh (revision 1129)
@@ -38,11 +38,36 @@
# include <mln/debug/println.hh>
# include <mln/core/window2d.hh>
# include <mln/convert/to_window.hh>
+# include <mln/core/concept/dpoint.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/window.hh>
+# include <mln/pw/image.hh>
+# include <mln/pw/cst.hh>
+# include <mln/metal/is_a.hh>
+
namespace mln
{
+ namespace convert
+ {
+ template <typename N>
+ window<mln_dpoint(N)> to_upper_window(const Neighborhood<N>& nbh_)
+ {
+ const N& nbh = exact(nbh_);
+ typedef mln_dpoint(N) D;
+ typedef mln_point(D) P;
+ window<D> win;
+ mln_niter(N) n(nbh, P::zero);
+ for_all(n)
+ // FIXME: pour Guillaume
+ if (n < P::zero)
+ win.insert(n - P::zero);
+ return win;
+ }
+
+ } // end of namespace convert
template <typename F>
struct labeling_fast_try2
@@ -65,6 +90,8 @@
void run()
{
+// std::cout << "fast"
+// << std::endl;
// init
{
f.nlabels = 0;
@@ -72,8 +99,10 @@
}
// first pass
{
+ typedef mln_point (I) P;
mln_bkd_pixter(const I) p(f.input);
mln_nixter(const I, N) n(p, f.nbh);
+ // mln_qixter(const I, window<P>) n(p, convert::to_upper_window(f.nbh));
for_all(p) if (f.handles(p))
{
@@ -153,8 +182,8 @@
// const S& s;
void init() { mln::level::fill(this->output, 0); }
- bool handles(unsigned p) const { return input[p] == val; }
- bool equiv(unsigned n, unsigned) const { return input[n] == val; }
+ bool handles(unsigned p) const { return
mln::labeling::impl::base_fast_<I_,N_,O_>::input[p] == val; }
+ bool equiv(unsigned n, unsigned) const { return
mln::labeling::impl::base_fast_<I_,N_,O_>::input[n] == val; }
const mln_value(I_)& val;
Index: trunk/milena/sandbox/duhamel/labeling_level_fast.cc
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_level_fast.cc (revision 1128)
+++ trunk/milena/sandbox/duhamel/labeling_level_fast.cc (revision 1129)
@@ -63,18 +63,4 @@
std::cout << "n = " << n << std::endl;
debug::println(out);
-
-// image2d_b<int_u8>
-// lena = io::pgm::load("../../img/tiny.pgm"),
-// out(lena.domain());
-
-// debug::println_with_border(out);
-
-// labeling::foreground((pw::value(lena) > pw::cst(127)) | lena.domain(),
-// c4(), out, n);
-
- // debug::println_with_border(out);
-
-// io::pgm::save(out, "out.pgm");
-// mln_assertion(n == 14);
}
Index: trunk/milena/sandbox/duhamel/labeling_level_fast_10000x1000.cc
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_level_fast_10000x1000.cc (revision 0)
+++ trunk/milena/sandbox/duhamel/labeling_level_fast_10000x1000.cc (revision 1129)
@@ -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/labeling_foreground.cc
+ *
+ * \brief Test on mln::labeling::foreground.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/neighb2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/pw/all.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+#include "labeling_level.hh"
+#include <mln/debug/iota.hh>
+#include <mln/debug/println_with_border.hh>
+
+#include "paste.hh"
+#include "fill.hh"
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ unsigned border = 1;
+
+ image2d_b<value::int_u8> i1(10000, 1000, border);
+ i1[10009] = i1[10010] = 2;
+
+ unsigned n;
+ image2d_b<value::int_u8> out(i1.domain(), border);
+ labeling_level_fast(i1, 2, c4(), out, n);
+
+ mln_assertion (n == 1);
+}