Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
07 Dec '07
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-12-07 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Update tests for level and border and fix typo.
* tests/border/duplicate_full.cc,
* tests/border/fill.cc,
* tests/border/fill_full.cc,
* tests/border/mirror_full.cc: Update 1d version.
* tests/display/color_pretty.cc,
* tests/level/abs_full.cc,
* tests/level/sort_points_full.cc,
* tests/logical/and_not_full.cc,
* tests/logical/not_full.cc: Update and fix typo.
* mln/trait/value/kind.hh: Fix typo.
---
mln/trait/value/kind.hh | 3
tests/border/duplicate_full.cc | 168 ++++++++++++++++++++++++-------------
tests/border/fill.cc | 2
tests/border/fill_full.cc | 24 ++---
tests/border/mirror_full.cc | 178 +++++++++++++++++++++++++---------------
tests/display/color_pretty.cc | 2
tests/level/abs_full.cc | 2
tests/level/sort_points_full.cc | 2
tests/logical/and_not_full.cc | 2
tests/logical/not_full.cc | 4
10 files changed, 245 insertions(+), 142 deletions(-)
Index: trunk/milena/tests/level/abs_full.cc
===================================================================
--- trunk/milena/tests/level/abs_full.cc (revision 1600)
+++ trunk/milena/tests/level/abs_full.cc (revision 1601)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/level/abs.cc
+/*! \file tests/level/abs_full.cc
*
* \brief Tests on mln::level::abs.
*/
Index: trunk/milena/tests/level/sort_points_full.cc
===================================================================
--- trunk/milena/tests/level/sort_points_full.cc (revision 1600)
+++ trunk/milena/tests/level/sort_points_full.cc (revision 1601)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/level/sort_points.cc
+/*! \file tests/level/sort_points_full.cc
*
* \brief Tests on mln::level::sort_points.
*/
Index: trunk/milena/tests/display/color_pretty.cc
===================================================================
--- trunk/milena/tests/display/color_pretty.cc (revision 1600)
+++ trunk/milena/tests/display/color_pretty.cc (revision 1601)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/color_pretty.cc
+/*! \file tests/display/color_pretty.cc
*
* \brief Tests on mln::display::color::pretty.
*/
Index: trunk/milena/tests/border/duplicate_full.cc
===================================================================
--- trunk/milena/tests/border/duplicate_full.cc (revision 1600)
+++ trunk/milena/tests/border/duplicate_full.cc (revision 1601)
@@ -30,34 +30,115 @@
* \brief Tests on mln::border::duplicate.
*/
+#include <mln/core/image1d.hh>
#include <mln/core/image2d.hh>
#include <mln/debug/iota.hh>
#include <mln/border/duplicate.hh>
#include <mln/value/int_u8.hh>
#include <mln/value/int_s8.hh>
+namespace mln
+{
+
+ template <typename T>
+ void chck1d(int cols, int border, T ref[])
+ {
+ int c = cols + 2 * border;
+
+ image1d<T> ima(cols, border);
+ debug::iota(ima);
+ border::duplicate(ima);
+
+ for (int i = 0; i < c; ++i)
+ mln_assertion(ima[i] == ref[i]);
+ }
+
+ template <typename T>
+ void chck2d(int rows, int cols, int border, T ref[])
+ {
+ int r = rows + 2 * border;
+ int c = cols + 2 * border;
+
+ image2d<T> ima(rows, cols, border);
+ debug::iota(ima);
+ border::duplicate(ima);
+
+ for (int i = 0; i < c * r; ++i)
+ mln_assertion(ima[i] == ref[i]);
+ }
+
+}
-using namespace mln;
int
main (void)
{
+ using namespace mln;
+
+ std::cerr << "Tests border::duplicate:" << std::endl;
+
{
- (std::cerr << "Test border::mirror on int with border = 3 ... ").flush ();
+ std::cerr << " in 1d :" << std::endl;
- typedef int T;
+ {
+ (std::cerr << " on int_u8 with border = 3 ... ").flush ();
+
+ typedef value::int_u8 T;
int border = 3;
- int row = 4;
- int col = 5;
+ int cols = 2;
+ T ref[8] = {1, 1, 1, 1, 2, 2, 2, 2};
- int r = row + 2 * border;
- int c = col + 2 * border;
+ chck1d(cols, border, ref);
+ std::cerr << "OK" << std::endl;
+ }
- image2d<T> ima(row, col, border);
- debug::iota (ima);
- border::duplicate (ima);
+ {
+ (std::cerr << " on int with border = 2 ... ").flush ();
+
+ typedef int T;
+ int border = 2;
+ int cols = 3;
+ T ref[7] = {1, 1, 1, 2, 3, 3, 3};
+
+ chck1d(cols, border, ref);
+ std::cerr << "OK" << std::endl;
+ }
- T vs[110] =
+ {
+ (std::cerr << " on int_s8 with border = 1 ... ").flush ();
+
+ typedef value::int_s8 T;
+ int border = 1;
+ int cols = 2;
+ T ref[4] = {1, 1, 2, 2};
+
+ chck1d(cols, border, ref);
+ std::cerr << "OK" << std::endl;
+ }
+
+ {
+ (std::cerr << " on int with border = 0 ... ").flush ();
+ typedef int T;
+ int border = 0;
+ int cols = 4;
+ T ref[4] = {1, 2, 3, 4};
+
+ chck1d(cols, border, ref);
+ std::cerr << "OK" << std::endl;
+ }
+ } // end of 1d
+
+
+ {
+ std::cerr << " in 2d :" << std::endl;
+
+ {
+ (std::cerr << " on int with border = 3 ... ").flush ();
+ typedef int T;
+ int border = 3;
+ int rows = 4;
+ int cols = 5;
+ T ref[110] =
{
1, 1, 1, 1, 2, 3, 4, 5, 5, 5, 5,
1, 1, 1, 1, 2, 3, 4, 5, 5, 5, 5,
@@ -71,27 +152,17 @@
16, 16, 16, 16, 17, 18, 19, 20, 20, 20, 20
};
- for (int i = 0; i < c * r; ++i)
- mln_assertion(ima[i] == vs[i]);
+ chck2d(rows, cols, border, ref);
std::cerr << "OK" << std::endl;
}
{
- (std::cerr << "Test border::mirror on int_u8 with border = 2 ... ").flush ();
-
+ (std::cerr << " on int_u8 with border = 3 ... ").flush ();
typedef value::int_u8 T;
int border = 2;
- int row = 4;
- int col = 5;
-
- int r = row + 2 * border;
- int c = col + 2 * border;
-
- image2d<T> ima(row, col, border);
- debug::iota (ima);
- border::duplicate (ima);
-
- T vs[72] =
+ int rows = 4;
+ int cols = 5;
+ T ref[72] =
{
1, 1, 1, 2, 3, 4, 5, 5, 5,
1, 1, 1, 2, 3, 4, 5, 5, 5,
@@ -103,27 +174,17 @@
16, 16, 16, 17, 18, 19, 20, 20, 20
};
- for (int i = 0; i < c * r; ++i)
- mln_assertion(ima[i] == vs[i]);
+ chck2d(rows, cols, border, ref);
std::cerr << "OK" << std::endl;
}
{
- (std::cerr << "Test border::mirror on int_s8 with border = 1 ... ").flush ();
-
+ (std::cerr << " on int_s8 with border = 1 ... ").flush ();
typedef value::int_s8 T;
int border = 1;
- int row = 4;
- int col = 5;
-
- int r = row + 2 * border;
- int c = col + 2 * border;
-
- image2d<T> ima(row, col, border);
- debug::iota (ima);
- border::duplicate (ima);
-
- T vs[49] =
+ int rows = 4;
+ int cols = 5;
+ T ref[49] =
{
1, 1, 2, 3, 4, 5, 5,
1, 1, 2, 3, 4, 5, 5,
@@ -133,28 +194,17 @@
16, 16, 17, 18, 19, 20, 20
};
- for (int i = 0; i < c * r; ++i)
- mln_assertion(ima[i] == vs[i]);
+ chck2d(rows, cols, border, ref);
std::cerr << "OK" << std::endl;
}
-
{
- (std::cerr << "Test border::mirror on int with border = 0 ... ").flush ();
-
+ (std::cerr << " on int with border = 0 ... ").flush ();
typedef int T;
int border = 0;
- int row = 4;
- int col = 5;
-
- int r = row + 2 * border;
- int c = col + 2 * border;
-
- image2d<T> ima(row, col, border);
- debug::iota (ima);
- border::duplicate (ima);
-
- T vs[20] =
+ int rows = 4;
+ int cols = 5;
+ T ref[20] =
{
1, 2, 3, 4, 5,
6, 7, 8, 9, 10,
@@ -162,10 +212,10 @@
16, 17, 18, 19, 20
};
- for (int i = 0; i < c * r; ++i)
- mln_assertion(ima[i] == vs[i]);
+ chck2d(rows, cols, border, ref);
std::cerr << "OK" << std::endl;
}
+ } // end of 2d
}
Index: trunk/milena/tests/border/mirror_full.cc
===================================================================
--- trunk/milena/tests/border/mirror_full.cc (revision 1600)
+++ trunk/milena/tests/border/mirror_full.cc (revision 1601)
@@ -37,28 +37,110 @@
#include <mln/value/int_u8.hh>
#include <mln/value/int_s8.hh>
-using namespace mln;
+
+namespace mln
+{
+
+ template <typename T>
+ void chck1d (int cols, int border, T ref[])
+ {
+ int c = cols + 2 * border;
+
+ image1d<T> ima(cols, border);
+ debug::iota(ima);
+ border::mirror(ima);
+
+ for (int i = 0; i < c; ++i)
+ mln_assertion(ima[i] == ref[i]);
+ }
+
+ template <typename T>
+ void chck2d (int rows, int cols, int border, T ref[])
+ {
+ int r = rows + 2 * border;
+ int c = cols + 2 * border;
+
+ image2d<T> ima(rows, cols, border);
+ debug::iota(ima);
+ border::mirror(ima);
+
+ for (int i = 0; i < c * r; ++i)
+ mln_assertion(ima[i] == ref[i]);
+ }
+
+}
+
int
main (void)
{
+ using namespace mln;
+
+
+ std::cerr << "Tests border::mirror:" << std::endl;
+
+ {
+ std::cerr << " in 1d :" << std::endl;
{
- (std::cerr << "Test border::mirror on int with border = 3 ... ").flush ();
+ (std::cerr << " on int_u8 with border = 3 ... ").flush ();
- typedef int T;
+ typedef value::int_u8 T;
int border = 3;
- int row = 4;
- int col = 5;
+ int cols = 2;
+ T ref[8] = {2, 2, 1, 1, 2, 2, 1, 1};
+
+ chck1d(cols, border, ref);
+ std::cerr << "OK" << std::endl;
+ }
- int r = row + 2 * border;
- int c = col + 2 * border;
+ {
+ (std::cerr << " on int with border = 2 ... ").flush ();
- image2d<T> ima(row, col, border);
- debug::iota (ima);
- border::mirror (ima);
+ typedef int T;
+ int border = 2;
+ int cols = 3;
+ T ref[7] = {2, 1, 1, 2, 3, 3, 2};
+
+ chck1d(cols, border, ref);
+ std::cerr << "OK" << std::endl;
+ }
+
+ {
+ (std::cerr << " on int_s8 with border = 1 ... ").flush ();
+
+ typedef value::int_s8 T;
+ int border = 1;
+ int cols = 2;
+ T ref[4] = {1, 1, 2, 2};
+
+ chck1d(cols, border, ref);
+ std::cerr << "OK" << std::endl;
+ }
+
+ {
+ (std::cerr << " on int with border = 0 ... ").flush ();
+ typedef int T;
+ int border = 0;
+ int cols = 4;
+ T ref[4] = {1, 2, 3, 4};
+
+ chck1d(cols, border, ref);
+ std::cerr << "OK" << std::endl;
+ }
+
+ } // end of 1d
- T vs[110] =
+ {
+ std::cerr << " in 2d :" << std::endl;
+
+ {
+ (std::cerr << " on int with border = 3 ... ").flush ();
+ typedef int T;
+ int border = 3;
+ int rows = 4;
+ int cols = 5;
+ T ref[110] =
{
1, 1, 1, 11, 12, 13, 14, 15, 5, 5, 5,
1, 1, 1, 6, 7, 8, 9, 10, 5, 5, 5,
@@ -72,28 +154,17 @@
16, 16, 16, 6, 7, 8, 9, 10, 20, 20, 20
};
- for (int i = 0; i < c * r; ++i)
- mln_assertion(ima[i] == vs[i]);
-
+ chck2d(rows, cols, border, ref);
std::cerr << "OK" << std::endl;
}
{
- (std::cerr << "Test border::mirror on int_s8 with border = 2 ... ").flush ();
-
- typedef value::int_s8 T;
+ (std::cerr << " on int_u8 with border = 3 ... ").flush ();
+ typedef value::int_u8 T;
int border = 2;
- int row = 4;
- int col = 5;
-
- int r = row + 2 * border;
- int c = col + 2 * border;
-
- image2d<T> ima(row, col, border);
- debug::iota (ima);
- border::mirror (ima);
-
- T vs[72] =
+ int rows = 4;
+ int cols = 5;
+ T ref[72] =
{
1, 1, 6, 7, 8, 9, 10, 5, 5,
1, 1, 1, 2, 3, 4, 5, 5, 5,
@@ -105,28 +176,17 @@
16, 16, 11, 12, 13, 14, 15, 20, 20
};
- for (int i = 0; i < c * r; ++i)
- mln_assertion(ima[i] == vs[i]);
-
+ chck2d(rows, cols, border, ref);
std::cerr << "OK" << std::endl;
}
{
- (std::cerr << "Test border::mirror on int_u8 with border = 1 ... ").flush ();
-
- typedef value::int_u8 T;
+ (std::cerr << " on int_s8 with border = 1 ... ").flush ();
+ typedef value::int_s8 T;
int border = 1;
- int row = 4;
- int col = 5;
-
- int r = row + 2 * border;
- int c = col + 2 * border;
-
- image2d<T> ima(row, col, border);
- debug::iota (ima);
- border::mirror (ima);
-
- T vs[49] =
+ int rows = 4;
+ int cols = 5;
+ T ref[49] =
{
1, 1, 2, 3, 4, 5, 5,
1, 1, 2, 3, 4, 5, 5,
@@ -136,27 +196,17 @@
16, 16, 17, 18, 19, 20, 20
};
- for (int i = 0; i < c * r; ++i)
- mln_assertion(ima[i] == vs[i]);
-
+ chck2d(rows, cols, border, ref);
std::cerr << "OK" << std::endl;
}
{
- (std::cerr << "Test border::mirror on int with border = 0 ... ").flush ();
-
+ (std::cerr << " on int with border = 0 ... ").flush ();
+ typedef int T;
int border = 0;
- int row = 4;
- int col = 5;
-
- int r = row + 2 * border;
- int c = col + 2 * border;
-
- image2d<int> ima(row, col, border);
- debug::iota (ima);
- border::mirror (ima);
-
- int vs[20] =
+ int rows = 4;
+ int cols = 5;
+ T ref[20] =
{
1, 2, 3, 4, 5,
6, 7, 8, 9, 10,
@@ -164,10 +214,10 @@
16, 17, 18, 19, 20
};
- for (int i = 0; i < c * r; ++i)
- mln_assertion(ima[i] == vs[i]);
-
+ chck2d(rows, cols, border, ref);
std::cerr << "OK" << std::endl;
}
+ } // end of 2d
+
}
Index: trunk/milena/tests/border/fill_full.cc
===================================================================
--- trunk/milena/tests/border/fill_full.cc (revision 1600)
+++ trunk/milena/tests/border/fill_full.cc (revision 1601)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/border_fill/test_border_fill_image2d_1.cc
+/*! \file tests/border/fill_full.cc
*
* \brief Tests on mln::border::fill.
*/
@@ -133,8 +133,10 @@
{
int limits = 10;
+ std::cerr << "Tests border::fill:" << std::endl;
+
{
- std::cerr << "Tests border::fill on int:" << std::endl;
+ std::cerr << " on int:" << std::endl;
typedef int T;
T value = (T) -1;
@@ -160,7 +162,7 @@
}
{
- std::cerr << "Tests border::fill on unsigned:" << std::endl;
+ std::cerr << " on unsigned:" << std::endl;
typedef unsigned T;
T value = (T) -1;
@@ -186,7 +188,7 @@
}
{
- std::cerr << "Tests border::fill on int_u8 ... " << std::endl;
+ std::cerr << " on int_u8:" << std::endl;
typedef value::int_u8 T;
T value = 255;
@@ -212,7 +214,7 @@
}
{
- std::cerr << "Tests border::fill on int_u16 ... " << std::endl;
+ std::cerr << " on int_u16:" << std::endl;
typedef value::int_u16 T;
T value = 65535;
@@ -238,7 +240,7 @@
}
{
- std::cerr << "Tests border::fill on int_s8 ... " << std::endl;
+ std::cerr << " on int_s8:" << std::endl;
typedef value::int_s8 T;
T value = 127;
@@ -264,7 +266,7 @@
}
{
- std::cerr << "Tests border::fill on int_s16 ... " << std::endl;
+ std::cerr << " on int_s16:" << std::endl;
typedef value::int_s16 T;
T value = 32767;
@@ -290,7 +292,7 @@
}
{
- std::cerr << "Tests border::fill on rgb8 ... " << std::endl;
+ std::cerr << " on rgb8:" << std::endl;
typedef value::rgb8 T;
T value = T(255, 255, 255);
@@ -316,7 +318,7 @@
}
{
- std::cerr << "Tests border::fill on rgb16:" << std::endl;
+ std::cerr << " on rgb16:" << std::endl;
typedef value::rgb16 T;
T value = T(65535, 65535, 65535);
@@ -343,7 +345,7 @@
{
- std::cerr << "Tests border::fill on float01_8:" << std::endl;
+ std::cerr << " on float01_8:" << std::endl;
typedef value::float01_8 T;
T value = T(0.9999);
@@ -369,7 +371,7 @@
}
{
- std::cerr << "Tests border::fill on float01_16:" << std::endl;
+ std::cerr << " on float01_16:" << std::endl;
typedef value::float01_16 T;
T value = T(0.9999);
Index: trunk/milena/tests/border/fill.cc
===================================================================
--- trunk/milena/tests/border/fill.cc (revision 1600)
+++ trunk/milena/tests/border/fill.cc (revision 1601)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/border_fill/test_border_fill_image2d_1.cc
+/*! \file tests/border/fill.cc
*
* \brief Tests on mln::border::fill.
*/
Index: trunk/milena/tests/logical/not_full.cc
===================================================================
--- trunk/milena/tests/logical/not_full.cc (revision 1600)
+++ trunk/milena/tests/logical/not_full.cc (revision 1601)
@@ -25,9 +25,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/logical/and_full.cc
+/*! \file tests/logical/not_full.cc
*
- * \brief Tests on mln::logical::and.
+ * \brief Tests on mln::logical::not.
*/
#include <mln/core/image1d.hh>
Index: trunk/milena/tests/logical/and_not_full.cc
===================================================================
--- trunk/milena/tests/logical/and_not_full.cc (revision 1600)
+++ trunk/milena/tests/logical/and_not_full.cc (revision 1601)
@@ -27,7 +27,7 @@
/*! \file tests/logical/and_not_full.cc
*
- * \brief Tests on mln::logical::and.
+ * \brief Tests on mln::logical::and_not.
*/
#include <mln/core/image1d.hh>
Index: trunk/milena/mln/trait/value/kind.hh
===================================================================
--- trunk/milena/mln/trait/value/kind.hh (revision 1600)
+++ trunk/milena/mln/trait/value/kind.hh (revision 1601)
@@ -56,13 +56,14 @@
struct logic : label { std::string name() const { return "kind::logic"; } };
struct binary : logic { std::string name() const { return "kind::binary"; } };
+ /*
// FIXME: Why not?
// label logic
// \ / \
// \ nary_logic \
// \ / \ \
// binary ternary fuzzy
-
+ */
struct data : any { std::string name() const { return "kind::data"; } };
};
1
0
07 Dec '07
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-12-07 Simon Nivault <simon.nivault(a)lrde.epita.fr>
The set of a lazy_set can be cleared.
* mln/util/lazy_set.hh: The set can be cleared.
* tests/util/Makefile.am,
* tests/util/lazy_set.cc: New test.
* mln/core/internal/run_image.hh,
* mln/core/mono_obased_rle_encode.hh,
* mln/core/mono_obased_rle_image.hh,
* mln/core/mono_rle_encode.hh,
* mln/core/mono_rle_image.hh,
* mln/core/obased_rle_encode.hh,
* mln/core/obased_rle_image.hh,
* mln/core/p_runs.hh,
* mln/core/rle_encode.hh,
* mln/core/rle_image.hh,
* mln/core/sparse_encode.hh,
* mln/core/sparse_image.hh: Use new lazy_set features.
---
mln/core/internal/run_image.hh | 34 +++++++++++++++++
mln/core/mono_obased_rle_encode.hh | 1
mln/core/mono_obased_rle_image.hh | 14 +++++++
mln/core/mono_rle_encode.hh | 1
mln/core/mono_rle_image.hh | 11 +++++
mln/core/obased_rle_encode.hh | 1
mln/core/obased_rle_image.hh | 11 +++++
mln/core/p_runs.hh | 17 ++++++++
mln/core/rle_encode.hh | 1
mln/core/rle_image.hh | 11 +++++
mln/core/sparse_encode.hh | 5 --
mln/core/sparse_image.hh | 11 +++++
mln/util/lazy_set.hh | 71 +++++++++++++++++++++++++++++++++++--
tests/util/Makefile.am | 2 +
tests/util/lazy_set.cc | 64 +++++++++++++++++++++++++++++++++
15 files changed, 248 insertions(+), 7 deletions(-)
Index: trunk/milena/tests/util/Makefile.am
===================================================================
--- trunk/milena/tests/util/Makefile.am (revision 1599)
+++ trunk/milena/tests/util/Makefile.am (revision 1600)
@@ -8,6 +8,7 @@
branch_iter_ind \
eat \
graph \
+ lazy_set \
ordpair \
tree \
tree_fast \
@@ -19,6 +20,7 @@
branch_iter_ind_SOURCES = branch_iter_ind.cc
eat_SOURCES = eat.cc
graph_SOURCES = graph.cc
+lazy_set_SOURCES = lazy_set.cc
ordpair_SOURCES = ordpair.cc
tree_SOURCES = tree.cc
tree_fast_SOURCES = tree_fast.cc
Index: trunk/milena/tests/util/lazy_set.cc
===================================================================
--- trunk/milena/tests/util/lazy_set.cc (revision 0)
+++ trunk/milena/tests/util/lazy_set.cc (revision 1600)
@@ -0,0 +1,64 @@
+// 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/util/lazy_set.cc
+ *
+ * \brief test of mln::util::lazy_set
+ *
+ */
+
+#include <iostream>
+
+#include <mln/util/lazy_set.hh>
+
+int main ()
+{
+ using namespace mln;
+
+ util::lazy_set_<int> s1;
+ util::lazy_set_<int> s2;
+
+ s1.insert(3);
+ s1.insert(-2);
+ s1.insert(9);
+ s1.insert(0);
+ s2.insert(3);
+ s2.insert(-2);
+ s2.insert(9);
+ s2.insert(0);
+
+ mln_assertion(s1.nelements() == 4);
+ s2.set_const_mode(true);
+ mln_assertion(s2.nelements() == 4);
+
+ for (unsigned i = 0; i < s1.nelements(); ++i)
+ {
+ std::cout << s1[i] << " = " << s2[i] << std::endl;
+ mln_assertion(s1[i] == s2[i]);
+ }
+}
Index: trunk/milena/mln/core/mono_rle_encode.hh
===================================================================
--- trunk/milena/mln/core/mono_rle_encode.hh (revision 1599)
+++ trunk/milena/mln/core/mono_rle_encode.hh (revision 1600)
@@ -98,6 +98,7 @@
rstart = p;
}
}
+ output.finalize();
return output;
}
Index: trunk/milena/mln/core/sparse_encode.hh
===================================================================
--- trunk/milena/mln/core/sparse_encode.hh (revision 1599)
+++ trunk/milena/mln/core/sparse_encode.hh (revision 1600)
@@ -88,30 +88,27 @@
{
++len;
rstart = p;
- std::cout << "New run " << p << ": *";
rvalue.push_back(ima(p));
}
else
if ((!ignore_zero || ima(p) != literal::zero) &&
on_the_same_line(rstart, mln_point(I)(p), len))
{
- std::cout << "*";
++len;
rvalue.push_back(ima(p));
}
else
{
- std::cout << std::endl;
output.insert(p_run<P>(rstart, len), rvalue);
rvalue.clear();
if ((len = (!ignore_zero || ima(p) != literal::zero)))
{
rstart = p;
- std::cout << "New run " << p << ": ";
rvalue.push_back(ima(p));
}
}
}
+ output.finalize();
return output;
}
Index: trunk/milena/mln/core/internal/run_image.hh
===================================================================
--- trunk/milena/mln/core/internal/run_image.hh (revision 1599)
+++ trunk/milena/mln/core/internal/run_image.hh (revision 1600)
@@ -56,7 +56,22 @@
run_image_();
public:
+ /*! \brief Give the rate of compression.
+ *
+ * Give the rate of space gained by coding an image in this
+ * format. A rate of 1 means there is no compression. Less than
+ * 1 means we have gained space.
+ *
+ * \return The rate of compression.
+ */
float compression() const;
+
+ /*! \brief Finalize the construction.
+ *
+ * For internal use, this method has to be called to have
+ * actually an lighter image. So it improves compression.
+ */
+ void finalize();
};
# ifndef MLN_INCLUDE_ONLY
@@ -72,10 +87,29 @@
float
run_image_<T, P, E>::compression() const
{
+ std::cout << float(exact(this)->data_->size_mem())
+ << " / ( "
+ << float (sizeof(T))
+ << " * "
+ << float (exact(this)->data_->domain_.bbox().npoints())
+ << " )"
+ << std::endl;
+ std::cout << exact(this)->data_->domain_.bbox().pmin()
+ << " "
+ << exact(this)->data_->domain_.bbox().pmax()
+ << std::endl;
return float(exact(this)->data_->size_mem()) /
float (sizeof(T) * exact(this)->data_->domain_.bbox().npoints());
}
+ template <typename T, typename P, typename E>
+ inline
+ void
+ run_image_<T, P, E>::finalize()
+ {
+ exact(this)->data_->finalize();
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace internal
Index: trunk/milena/mln/core/rle_image.hh
===================================================================
--- trunk/milena/mln/core/rle_image.hh (revision 1599)
+++ trunk/milena/mln/core/rle_image.hh (revision 1600)
@@ -62,6 +62,9 @@
/// Return the size of the data in memory.
unsigned size_mem() const;
+
+ /// Finalize the domain (internal use).
+ void finalize();
};
} // end of namespace mln::internal
@@ -157,6 +160,14 @@
return sizeof(T) * values_.size() + domain_.size_mem();
}
+ template <typename P, typename T>
+ inline
+ void
+ data_< rle_image<P,T> >::finalize()
+ {
+ domain_.finalize();
+ }
+
} // end of namespace mln::internal
template <typename P, typename T>
Index: trunk/milena/mln/core/obased_rle_encode.hh
===================================================================
--- trunk/milena/mln/core/obased_rle_encode.hh (revision 1599)
+++ trunk/milena/mln/core/obased_rle_encode.hh (revision 1600)
@@ -110,6 +110,7 @@
}
}
}
+ output.finalize();
return output;
}
Index: trunk/milena/mln/core/mono_rle_image.hh
===================================================================
--- trunk/milena/mln/core/mono_rle_image.hh (revision 1599)
+++ trunk/milena/mln/core/mono_rle_image.hh (revision 1600)
@@ -62,6 +62,9 @@
/// Return the size of the data in memory.
unsigned size_mem() const;
+
+ /// Finalize the domain (internal use).
+ void finalize();
};
} // end of namespace mln::internal
@@ -162,6 +165,14 @@
return sizeof(T) + domain_.size_mem();
}
+ template <typename P, typename T>
+ inline
+ void
+ data_< mono_rle_image<P,T> >::finalize()
+ {
+ domain_.finalize();
+ }
+
} // end of namespace mln::internal
template <typename P, typename T>
Index: trunk/milena/mln/core/obased_rle_image.hh
===================================================================
--- trunk/milena/mln/core/obased_rle_image.hh (revision 1599)
+++ trunk/milena/mln/core/obased_rle_image.hh (revision 1600)
@@ -72,6 +72,9 @@
/// Return the size of the data in memory.
unsigned size_mem() const;
+
+ /// Finalize the domain (internal use).
+ void finalize();
};
} // end of namespace mln::internal
@@ -179,6 +182,14 @@
+ (sizeof(unsigned) + sizeof(T)) * domain_.nruns();
}
+ template <typename P, typename T>
+ inline
+ void
+ data_< obased_rle_image<P,T> >::finalize()
+ {
+ domain_.finalize();
+ }
+
} // end of namespace mln::internal
template <typename P, typename T>
Index: trunk/milena/mln/core/mono_obased_rle_encode.hh
===================================================================
--- trunk/milena/mln/core/mono_obased_rle_encode.hh (revision 1599)
+++ trunk/milena/mln/core/mono_obased_rle_encode.hh (revision 1600)
@@ -110,6 +110,7 @@
}
}
}
+ output.finalize();
return output;
}
Index: trunk/milena/mln/core/mono_obased_rle_image.hh
===================================================================
--- trunk/milena/mln/core/mono_obased_rle_image.hh (revision 1599)
+++ trunk/milena/mln/core/mono_obased_rle_image.hh (revision 1600)
@@ -67,6 +67,9 @@
/// Return the size of the data in memory.
unsigned size_mem() const;
+
+ /// Finalize the domain (internal use).
+ void finalize();
};
} // end of namespace mln::internal
@@ -166,6 +169,17 @@
return domain_.size_mem() * 2 + sizeof(T) * (values_.size() + ima_.size());
}
+ template <typename P, typename T>
+ inline
+ void
+ data_< mono_obased_rle_image<P,T> >::finalize()
+ {
+ domain_.finalize();
+ for (typename std::vector< mono_rle_image<P, T> >::iterator it = ima_.begin();
+ it != ima_.end(); ++it)
+ it->finalize();
+ }
+
} // end of namespace mln::internal
template <typename P, typename T>
Index: trunk/milena/mln/core/rle_encode.hh
===================================================================
--- trunk/milena/mln/core/rle_encode.hh (revision 1599)
+++ trunk/milena/mln/core/rle_encode.hh (revision 1600)
@@ -103,6 +103,7 @@
}
}
}
+ output.finalize();
return output;
}
Index: trunk/milena/mln/core/sparse_image.hh
===================================================================
--- trunk/milena/mln/core/sparse_image.hh (revision 1599)
+++ trunk/milena/mln/core/sparse_image.hh (revision 1600)
@@ -62,6 +62,9 @@
/// Return the size of the data in memory.
unsigned size_mem() const;
+
+ /// Finalize the domain (internal use).
+ void finalize();
};
} // end of namespace mln::internal
@@ -157,6 +160,14 @@
return sizeof(T) * domain_.npoints() + domain_.size_mem();
}
+ template <typename P, typename T>
+ inline
+ void
+ data_< sparse_image<P,T> >::finalize()
+ {
+ domain_.finalize();
+ }
+
} // end of namespace mln::internal
template <typename P, typename T>
Index: trunk/milena/mln/core/p_runs.hh
===================================================================
--- trunk/milena/mln/core/p_runs.hh (revision 1599)
+++ trunk/milena/mln/core/p_runs.hh (revision 1600)
@@ -93,6 +93,9 @@
/// Return the size of the data in memory.
unsigned size_mem() const;
+ /// Finalize the lazy_set (internal use)
+ void finalize();
+
// /// Return the container of the pset (internal use only).
// const container& con() const;
@@ -225,9 +228,21 @@
unsigned
p_runs_<P>::size_mem() const
{
- return nruns() * 2 * (sizeof(P) + sizeof(unsigned));
+ if (con_.get_mode())
+ return nruns() * (sizeof(P) + sizeof(unsigned));
+ else
+ return 2 * nruns() * (sizeof(P) + sizeof(unsigned));
}
+ template <typename P>
+ inline
+ void
+ p_runs_<P>::finalize()
+ {
+ con_.set_const_mode(true);
+ }
+
+
// template <typename P>
// const typename p_runs_<P>::container&
// p_runs_<P>::con() const
Index: trunk/milena/mln/util/lazy_set.hh
===================================================================
--- trunk/milena/mln/util/lazy_set.hh (revision 1599)
+++ trunk/milena/mln/util/lazy_set.hh (revision 1600)
@@ -39,6 +39,7 @@
# include <algorithm>
# include <mln/core/internal/force_exact.hh>
+# include <mln/core/contract.hh>
namespace mln
@@ -136,6 +137,8 @@
*
* All elements contained in the set are destroyed so the set is
* emptied.
+ * The lazy set can be cleared even if it is in const mode
+ * and then it is set in non-const mode.
*
* \post is_empty() == true
*/
@@ -153,6 +156,21 @@
/// Constructor without arguments.
lazy_set_();
+ /*! \brief Set the mode of the lazy_set
+ *
+ * The lazy set can have two modes :
+ * - const : The lazy set is as light as a vector but you cannot
+ * modify it
+ * - non-const : The lazy set use a std::set to have lazy manipulation
+ *
+ * \param[in] mode True for const mode, false for non-const.
+ *
+ */
+ void set_const_mode(bool mode);
+
+ /// Get the mode of the lazy set.
+ bool get_mode() const;
+
private:
/*! \brief Array of elements.
@@ -177,6 +195,9 @@
/// Tell if \a v_ needs to be updated.
mutable bool needs_update_;
+
+ /// Tell what the lazy set mode is.
+ bool mode_;
};
@@ -203,6 +224,7 @@
lazy_set_<E>::lazy_set_()
{
needs_update_ = false;
+ mode_ = false;
}
template <typename E>
@@ -210,6 +232,7 @@
lazy_set_<E>&
lazy_set_<E>::insert(const E& elt)
{
+ mln_assertion(!mode_);
s_.insert(elt);
if (needs_update_ == false)
needs_update_ = true;
@@ -221,6 +244,7 @@
lazy_set_<E>&
lazy_set_<E>::remove(const E& elt)
{
+ mln_assertion(!mode_);
// FIXME : doesn't compile
std::remove(s_.begin(), s_.end(), elt);
if (needs_update_ == false)
@@ -233,7 +257,9 @@
const E&
lazy_set_<E>::element(unsigned i) const
{
- assert(i < s_.size());
+ assert((!mode_ && i < s_.size())
+ || i < v_.size());
+ if (!mode_)
if (needs_update_)
update_();
return v_[i];
@@ -252,7 +278,10 @@
unsigned
lazy_set_<E>::nelements() const
{
+ if (!mode_)
return s_.size();
+ else
+ return v_.size();
}
template <typename E>
@@ -260,7 +289,10 @@
bool
lazy_set_<E>::has(const E& elt) const
{
+ if (!mode_)
return s_.find(elt) != s_.end();
+ else
+ return v_.find(elt) != v_.end();
}
template <typename E>
@@ -279,6 +311,7 @@
v_.clear();
s_.clear();
needs_update_ = false;
+ mode_ = false;
mln_postcondition(is_empty());
}
@@ -287,6 +320,7 @@
const std::vector<E>&
lazy_set_<E>::vect() const
{
+ if (!mode_)
if (needs_update_)
update_();
return v_;
@@ -295,9 +329,42 @@
template <typename E>
inline
void
+ lazy_set_<E>::set_const_mode(bool mode)
+ {
+ if (mode != mode_)
+ {
+ if (mode)
+ {
+ if (needs_update_)
+ update_();
+ s_.clear();
+ }
+ else
+ {
+ mln_assertion(s_.size() == 0);
+ for (typename std::vector<E>::iterator it = v_.begin();
+ it != v_.end(); it++)
+ s_.insert(*it);
+ needs_update_ = false;
+ }
+ mode_ = mode;
+ }
+ }
+
+ template <typename E>
+ inline
+ bool
+ lazy_set_<E>::get_mode() const
+ {
+ return mode_;
+ }
+
+ template <typename E>
+ inline
+ void
lazy_set_<E>::update_() const
{
- mln_precondition(needs_update_);
+ mln_precondition(needs_update_ && !mode_);
v_.clear();
std::copy(s_.begin(), s_.end(), std::back_inserter(v_));
// no s_.clear() here:
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Clean up 'labeling' and fix pbm i/o.
* doc/examples: New directory.
* tests/labeling_blobs.cc: Rename as...
* tests/labeling/blobs.cc: ...this.
* tests/labeling_algo.cc: Rename as...
* doc/examples/labeling_algo.cc: ...this.
* tests/labeling_level_fast.cc: Rename as...
* tests/labeling/level.cc: ...this.
* tests/labeling_regional_maxima.cc: Rename as...
* tests/labeling/regional_maxima.cc: ...this.
* tests/labeling_foreground.cc: Rename as...
* tests/labeling/foreground.cc: ...this.
* tests/labeling_estimate.cc: Remove; meaningless.
* mln/labeling/estimate.hh: Rename as...
* sandbox/geraud/estimate.hh: ...this.
* tests/labeling/background.cc: New.
* tests/labeling/flat_zones.cc: New.
* tests/labeling/regional_minima.cc: New.
* tests/labeling/Makefile.am: Update.
* mln/canvas/labeling.hh,
* mln/labeling/blobs.hh,
* mln/labeling/flat_zones.hh,
* mln/labeling/level.hh,
* mln/labeling/regional_minima.hh,
* mln/labeling/foreground.hh,
* mln/labeling/regional_maxima.hh,
* mln/labeling/background.hh: Clean up.
* mln/labeling/all.hh: Update.
* mln/labeling/base.hh: Remove.
* mln/labeling/level.spe.hh: New.
* tests/value/rgb8.cc: Add comment.
* mln/trait/value/kind.hh: Add comment about tags' hierarchy.
* mln/core/internal/set_of.hh (element): Fix precondition.
* mln/value/rgb.hh (operator metal::vec): New; experimental.
* mln/fun/v2v/saturate.hh: Uncomment.
* mln/io/pbm/save.hh (save_),
* mln/io/pbm/load.hh (load_ascii, load_raw_2d): Swap 0 and 1.
* img/tiny.pgm: Rename as...
* img/small.pgm: ...this.
* img/tiny.pgm: New 16x16 lena reduction.
* img/README: New.
img/README | 8 +
mln/canvas/labeling.hh | 116 +++++++++++++++----------
mln/core/internal/set_of.hh | 2
mln/fun/v2v/saturate.hh | 2
mln/io/pbm/load.hh | 5 -
mln/io/pbm/save.hh | 2
mln/labeling/all.hh | 2
mln/labeling/background.hh | 19 +++-
mln/labeling/blobs.hh | 54 ++++++++---
mln/labeling/flat_zones.hh | 103 +++++++++++++++-------
mln/labeling/foreground.hh | 15 +++
mln/labeling/level.hh | 145 ++++++++++++-------------------
mln/labeling/level.spe.hh | 175 ++++++++++++++++++++++++++++++++++++++
mln/labeling/regional_maxima.hh | 103 +++++++++++++++-------
mln/labeling/regional_minima.hh | 105 +++++++++++++++-------
mln/trait/value/kind.hh | 7 +
mln/value/rgb.hh | 2
sandbox/geraud/estimate.hh | 39 +++++---
tests/labeling/Makefile.am | 19 ++++
tests/labeling/background.cc | 48 ++++++++++
tests/labeling/blobs.cc | 40 +-------
tests/labeling/flat_zones.cc | 65 ++++++++++++++
tests/labeling/foreground.cc | 36 +------
tests/labeling/level.cc | 34 +++----
tests/labeling/regional_maxima.cc | 17 +--
tests/labeling/regional_minima.cc | 52 +++++++++++
tests/value/rgb8.cc | 5 +
27 files changed, 861 insertions(+), 359 deletions(-)
Index: tests/value/rgb8.cc
--- tests/value/rgb8.cc (revision 1598)
+++ tests/value/rgb8.cc (working copy)
@@ -50,6 +50,11 @@
v.blue() = 2;
rgb8 c(0, 1, 2);
+ // FIXME: Do not compile because we lack ops!
+ // mln_sum_(rgb8) sum;
+ // sum + c;
+ // c = c + c;
+
std::cout << c << std::endl;
std::cout << v << std::endl;
Index: tests/labeling/regional_maxima.cc
--- tests/labeling/regional_maxima.cc (revision 1528)
+++ tests/labeling/regional_maxima.cc (working copy)
@@ -25,18 +25,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/labeling_regional_maxima.cc
+/*! \file tests/labeling/regional_maxima.cc
*
* \brief Test on mln::labeling::regional_maxima.
*/
#include <mln/core/image2d.hh>
-#include <mln/core/neighb2d.hh>
#include <mln/value/int_u8.hh>
-
+#include <mln/core/neighb2d.hh>
#include <mln/io/pgm/load.hh>
-#include <mln/io/pgm/save.hh>
-
#include <mln/labeling/regional_maxima.hh>
@@ -45,13 +42,9 @@
using namespace mln;
using value::int_u8;
- image2d<int_u8>
- lena = io::pgm::load("../img/lena.pgm"),
- out(lena.domain());
+ image2d<int_u8> lena = io::pgm::load<int_u8>("../../img/tiny.pgm");
unsigned n;
- labeling::regional_maxima(lena, c4(), out, n);
- mln_assertion(n = 255);
-
- io::pgm::save(out, "out.pgm");
+ labeling::regional_maxima(lena, c4(), n);
+ mln_assertion(n = 25);
}
Index: tests/labeling/background.cc
--- tests/labeling/background.cc (revision 0)
+++ tests/labeling/background.cc (revision 0)
@@ -0,0 +1,48 @@
+// 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/background.cc
+ *
+ * \brief Test on mln::labeling::background.
+ */
+
+#include <mln/core/image2d.hh>
+#include <mln/io/pbm/load.hh>
+#include <mln/core/neighb2d.hh>
+#include <mln/labeling/background.hh>
+#include <mln/logical/not.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ image2d<bool> pic = io::pbm::load("../../img/picasso.pbm");
+ unsigned n;
+ labeling::background(logical::not_(pic), c4(), n);
+ mln_assertion(n = 33);
+}
Index: tests/labeling/blobs.cc
--- tests/labeling/blobs.cc (revision 1528)
+++ tests/labeling/blobs.cc (working copy)
@@ -25,51 +25,23 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/labeling_blob.cc
+/*! \file tests/labeling/blobs.cc
*
- * \brief Test on mln::labeling::blob.
+ * \brief Test on mln::labeling::blobs.
*/
#include <mln/core/image2d.hh>
-#include <mln/core/cast_image.hh>
+#include <mln/io/pbm/load.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/blobs.hh>
-#include <mln/level/transform.hh>
-
-
-struct fold_t : public mln::Function_v2v< fold_t >
-{
- typedef mln::value::int_u8 result;
- result operator()(unsigned i) const { return i = 0 ? 0 : i % 255 + 1; }
-};
-
int main()
{
using namespace mln;
- using value::int_u8;
-
- image2d<int_u8> lena = io::pgm::load("../img/tiny.pgm");
+ image2d<bool> pic = io::pbm::load("../../img/picasso.pbm");
unsigned n;
- io::pgm::save(cast_image<int_u8>( labeling::blobs((pw::value(lena) > pw::cst(127u)) | lena.domain(),
- c4(), n) ),
- "out.pgm");
- mln_assertion(n = 14);
-
-// image2d<int_u8>
-// lena = io::pgm::load("../img/lena.pgm"),
-// out;
-// unsigned n;
-// image2d<unsigned> labels = labeling::blobs((pw::value(lena) > pw::cst(127u)) | lena.domain(),
-// c8(), n);
-// mln_assertion(n = 528);
-// io::pgm::save( level::transform(labels, fold_t()),
-// "out.pgm" );
+ labeling::blobs(pic, c4(), n);
+ mln_assertion(n = 33);
}
Index: tests/labeling/flat_zones.cc
--- tests/labeling/flat_zones.cc (revision 0)
+++ tests/labeling/flat_zones.cc (revision 0)
@@ -0,0 +1,65 @@
+// 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/flat_zones.cc
+ *
+ * \brief Test on mln::labeling::flat_zones.
+ */
+
+#include <mln/core/image2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/io/pgm/load.hh>
+#include <mln/core/neighb2d.hh>
+#include <mln/labeling/flat_zones.hh>
+
+#include <mln/labeling/blobs.hh>
+#include <mln/pw/all.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d<int_u8> lena = io::pgm::load<int_u8>("../../img/tiny.pgm");
+
+ unsigned n;
+ image2d<unsigned> labels = labeling::flat_zones(lena, c4(), n);
+ mln_assertion(n = 247);
+
+ {
+ unsigned n_ = 0;
+ for (unsigned i = 0; i <= 255; ++i)
+ {
+ unsigned n_i;
+ labeling::blobs((pw::value(lena) = pw::cst(i)) | lena.domain(),
+ c4(), n_i);
+ n_ += n_i;
+ }
+ mln_assertion(n_ = n);
+ }
+}
Index: tests/labeling/Makefile.am
--- tests/labeling/Makefile.am (revision 1598)
+++ tests/labeling/Makefile.am (working copy)
@@ -1,3 +1,22 @@
## Process this file through Automake to create Makefile.in -*- Makefile -*-
include $(top_srcdir)/milena/tests/tests.mk
+
+check_PROGRAMS = \
+ background \
+ blobs \
+ flat_zones \
+ foreground \
+ level \
+ regional_maxima \
+ regional_minima
+
+background_SOURCES = background.cc
+blobs_SOURCES = blobs.cc
+flat_zones_SOURCES = flat_zones.cc
+foreground_SOURCES = foreground.cc
+level_SOURCES = level.cc
+regional_maxima_SOURCES = regional_maxima.cc
+regional_minima_SOURCES = regional_minima.cc
+
+TESTS = $(check_PROGRAMS)
Index: tests/labeling/level.cc
--- tests/labeling/level.cc (revision 1528)
+++ tests/labeling/level.cc (working copy)
@@ -25,21 +25,23 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/labeling_level_fast.cc
+/*! \file tests/labeling/level.cc
*
* \brief Test on mln::labeling::level.
*/
#include <mln/core/image2d.hh>
-#include <mln/core/image1d.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/accu/count.hh>
+#include <mln/accu/compute.hh>
#include <mln/labeling/level.hh>
-#include <mln/debug/iota.hh>
+#include <mln/level/paste.hh>
+#include <mln/pw/all.hh>
+#include <mln/core/image_if.hh>
+
#include <mln/debug/println.hh>
@@ -48,15 +50,15 @@
using namespace mln;
using value::int_u8;
- image2d<value::int_u8> i1(5, 5);
- debug::iota(i1);
- i1(point2d(0, 2)) = i1(point2d(1, 2)) = i1(point2d(1, 3)) = i1(point2d(2, 3)) = i1(point2d(2, 4)) = 2;
- i1(point2d(2, 0)) = i1(point2d(3, 0)) = 2;
- debug::println(i1);
-
- unsigned n;
- image2d<unsigned> out = labeling::level(i1, 2, c4(), n);
+ image2d<int_u8> lena = io::pgm::load<int_u8>("../../img/tiny.pgm");
+ image2d<bool> lvl(lena.domain());
- std::cout << "n = " << n << std::endl;
- debug::println(out);
+ unsigned n, npixels = 0;
+ for (unsigned l = 0; l <= 255; ++l)
+ {
+ image2d<unsigned> labels = labeling::level(lena, l, c4(), n);
+ unsigned npix = accu::compute< accu::count >(labels | (pw::value(labels) != pw::cst(0)));
+ npixels += npix;
+ }
+ mln_assertion(npixels = lena.npoints());
}
Index: tests/labeling/foreground.cc
--- tests/labeling/foreground.cc (revision 1528)
+++ tests/labeling/foreground.cc (working copy)
@@ -25,49 +25,23 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/labeling_foreground.cc
+/*! \file tests/labeling/foreground.cc
*
* \brief Test on mln::labeling::foreground.
*/
#include <mln/core/image2d.hh>
+#include <mln/io/pbm/load.hh>
#include <mln/core/neighb2d.hh>
-#include <mln/value/int_u8.hh>
-#include <mln/pw/all.hh>
-#include <mln/core/cast_image.hh>
-
-#include <mln/io/pgm/load.hh>
-#include <mln/io/pgm/save.hh>
#include <mln/labeling/foreground.hh>
-#include <mln/level/transform.hh>
-
-
-struct fold_t : public mln::Function_v2v< fold_t >
-{
- typedef mln::value::int_u8 result;
- result operator()(unsigned i) const { return i = 0 ? 0 : i % 255 + 1; }
-};
int main()
{
using namespace mln;
- using value::int_u8;
- image2d<int_u8> lena = io::pgm::load("../img/tiny.pgm");
+ image2d<bool> pic = io::pbm::load("../../img/picasso.pbm");
unsigned n;
- io::pgm::save(cast_image<int_u8>( labeling::foreground((pw::value(lena) > pw::cst(127u)) | lena.domain(),
- c4(), n) ),
- "out.pgm");
- mln_assertion(n = 14);
-
-// image2d<int_u8>
-// lena = io::pgm::load("../img/lena.pgm"),
-// out;
-// unsigned n;
-// image2d<unsigned> labels = labeling::foreground((pw::value(lena) > pw::cst(127u)) | lena.domain(),
-// c8(), n);
-// mln_assertion(n = 528);
-// io::pgm::save( level::transform(labels, fold_t()),
-// "out.pgm" );
+ labeling::foreground(pic, c4(), n);
+ mln_assertion(n = 33);
}
Index: tests/labeling/regional_minima.cc
--- tests/labeling/regional_minima.cc (revision 0)
+++ tests/labeling/regional_minima.cc (revision 0)
@@ -0,0 +1,52 @@
+// 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/regional_minima.cc
+ *
+ * \brief Test on mln::labeling::regional_minima.
+ */
+
+#include <mln/core/image2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/core/neighb2d.hh>
+#include <mln/io/pgm/load.hh>
+#include <mln/pw/all.hh>
+#include <mln/labeling/regional_minima.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d<int_u8> lena = io::pgm::load<int_u8>("../../img/tiny.pgm");
+
+ unsigned n;
+ labeling::regional_minima((pw::cst(255) - pw::value(lena)) | lena.domain(),
+ c4(), n);
+ mln_assertion(n = 25);
+}
Index: mln/trait/value/kind.hh
--- mln/trait/value/kind.hh (revision 1598)
+++ mln/trait/value/kind.hh (working copy)
@@ -56,6 +56,13 @@
struct logic : label { std::string name() const { return "kind::logic"; } };
struct binary : logic { std::string name() const { return "kind::binary"; } };
+ // FIXME: Why not?
+ // label logic
+ // \ / \
+ // \ nary_logic \
+ // \ / \ \
+ // binary ternary fuzzy
+
struct data : any { std::string name() const { return "kind::data"; } };
};
Index: mln/core/internal/set_of.hh
--- mln/core/internal/set_of.hh (revision 1598)
+++ mln/core/internal/set_of.hh (working copy)
@@ -224,9 +224,9 @@
const E&
set_of_<E>::element(unsigned i) const
{
- assert(i < v_.size());
if (needs_update_)
update_();
+ mln_precondition(i < v_.size());
return v_[i];
}
Index: mln/value/rgb.hh
--- mln/value/rgb.hh (revision 1598)
+++ mln/value/rgb.hh (working copy)
@@ -125,6 +125,8 @@
rgb<n>(const metal::vec<3, unsigned>& rhs);
rgb<n>(const metal::vec<3, int_u<n> >& rhs);
+ operator metal::vec<3, float>() const { return this->v_; }
+
/// \{ Constructors with literals.
rgb<n>(const literal::white_t&);
rgb<n>(const literal::black_t&);
Index: mln/fun/v2v/saturate.hh
--- mln/fun/v2v/saturate.hh (revision 1598)
+++ mln/fun/v2v/saturate.hh (working copy)
@@ -102,7 +102,7 @@
min_W = mln::value::cast<W>(min_);
max_W = mln::value::cast<W>(max_);
// FIXME
-// needs_update_ = false;
+ needs_update_ = false;
}
// FIXME: Below we need something more powerful that mlc_converts_to
Index: mln/io/pbm/save.hh
--- mln/io/pbm/save.hh (revision 1598)
+++ mln/io/pbm/save.hh (working copy)
@@ -95,7 +95,7 @@
for_all(p)
{
c <<= 1;
- c += (ima(p) = true ? 1 : 0); // FIXME: Swap.
+ c += (ima(p) = true ? 0 : 1); // In pbm, '0' means 'white' so 'object', thus 'true'!
if (++col >= ncols)
{
c <<= (8 - stride - 1);
Index: mln/io/pbm/load.hh
--- mln/io/pbm/load.hh (revision 1598)
+++ mln/io/pbm/load.hh (working copy)
@@ -87,7 +87,8 @@
{
unsigned value;
file >> value;
- ima(p) = value;
+ mln_assertion(value = 0 || value = 1);
+ ima(p) = (value = 0); // In pbm, '0' means 'white' so 'object', thus 'true'!
// FIXME: Test alt code below.
// file >> ima(p);
}
@@ -116,7 +117,7 @@
{
if (i % 8 = 0)
file.read((char*)(&c), 1);
- ima(p) = c & 128;
+ ima(p) = !(c & 128);
c *= 2;
++i;
}
Index: mln/canvas/labeling.hh
--- mln/canvas/labeling.hh (revision 1598)
+++ mln/canvas/labeling.hh (working copy)
@@ -34,9 +34,9 @@
* image.
*/
+# include <mln/core/concept/image.hh>
# include <mln/level/fill.hh>
-# include <mln/level/sort_points.hh>
-# include <mln/convert/to_window.hh>
+# include <mln/convert/to_window.hh> // FIXME: to_upper_window
namespace mln
@@ -50,35 +50,52 @@
template <typename F>
struct labeling
{
+ // Functor.
F& f;
typedef typename F::I I;
typedef typename F::N N;
- typedef typename F::O O;
+ typedef typename F::L L;
typedef typename F::S S;
- typedef mln_point(I) point;
- // aux:
- mln_ch_value(O, bool) deja_vu;
- mln_ch_value(O, point) parent;
+ // Local type.
+ typedef mln_psite(I) point;
+ // Auxiliary data.
+ mln_ch_value(I, bool) deja_vu;
+ mln_ch_value(I, point) parent;
+
+ // Output.
+ mln_ch_value(I, L) output;
+ L nlabels;
+ bool status;
+
+ // Ctor.
labeling(F& f)
: f(f)
{
- run();
+ trace::entering("canvas::labeling");
+
+ init();
+ f.init(); // Client initialization.
+ pass_1();
+ pass_2();
+
+ trace::exiting("canvas::labeling");
}
- void run()
- {
- // init
+
+ void init()
{
initialize(deja_vu, f.input);
mln::level::fill(deja_vu, false);
initialize(parent, f.input);
- f.nlabels = 0;
- f.init();
+ initialize(output, f.input);
+ mln::level::fill(output, 0); // FIXME: Use literal::zero.
+ nlabels = 0;
}
- // first pass
+
+ void pass_1()
{
mln_fwd_piter(S) p(f.s);
mln_niter(N) n(f.nbh, p);
@@ -95,7 +112,7 @@
}
}
- // second pass
+ void pass_2()
{
mln_bkd_piter(S) p(f.s);
for_all(p) if (f.handles(p))
@@ -104,21 +121,22 @@
{
if (f.labels(p))
{
- if (f.nlabels = mln_max(mln_value(O)))
+ if (nlabels = mln_max(L))
{
- f.status = false;
+ status = false;
return;
}
- f.output(p) = ++f.nlabels;
+ output(p) = ++nlabels;
}
}
else
- f.output(p) = f.output(parent(p));
+ output(p) = output(parent(p));
}
- f.status = true;
+ status = true;
}
- } // end of run()
+
+ // Auxiliary methods.
void make_set(const point& p)
{
@@ -152,41 +170,52 @@
};
- // FIXME: Fast version.
template <typename F>
- struct labeling_fast
+ struct labeling_fastest
{
+ // Functor.
F& f;
typedef typename F::I I;
typedef typename F::N N;
- typedef typename F::O O;
+ typedef typename F::L L;
+
+ // Auxiliary data.
+ mln_ch_value(I, unsigned) parent;
- // aux:
- mln_ch_value(O, unsigned) parent;
+ // Output.
+ mln_ch_value(I, L) output;
+ L nlabels;
+ bool status;
- labeling_fast(F& f)
+ // Ctor.
+ labeling_fastest(F& f)
: f(f)
{
- run();
+ trace::entering("canvas::labeling_fastest");
+
+ init();
+ f.init(); // Client initialization.
+ pass_1();
+ pass_2();
+
+ trace::exiting("canvas::labeling_fastest");
}
- void run()
- {
- // init
+ void init()
{
initialize(parent, f.input);
- f.nlabels = 0;
- f.init();
- // make_set for all points:
for (unsigned p = 0; p < parent.ncells(); ++p)
- parent[p] = p;
+ parent[p] = p; // make_set
+ initialize(output, f.input);
+ mln::level::fill(output, 0); // FIXME: Use literal::zero.
+ nlabels = 0;
}
- // first pass
+ void pass_1()
{
mln_bkd_pixter(const I) p(f.input);
@@ -205,30 +234,31 @@
}
}
- // second pass
+ void pass_2()
{
mln_fwd_pixter(const I) p(f.input);
+
for_all(p) if (f.handles(p))
{
if (is_root(p))
{
if (f.labels(p))
{
- if (f.nlabels = mln_max(mln_value(O)))
+ if (nlabels = mln_max(L))
{
- f.status = false;
+ status = false;
return;
}
- f.output[p] = ++f.nlabels;
+ output[p] = ++nlabels;
}
}
else
- f.output[p] = f.output[parent[p]];
+ output[p] = output[parent[p]];
}
- f.status = true;
+ status = true;
}
- } // end of run()
+ // Auxiliary methods.
bool is_root(unsigned p) const
{
Index: mln/labeling/blobs.hh
--- mln/labeling/blobs.hh (revision 1598)
+++ mln/labeling/blobs.hh (working copy)
@@ -30,8 +30,8 @@
/*! \file mln/labeling/blobs.hh
*
- * \brief Connected component labeling of the image objects at a given
- * blobs.
+ * \brief Connected component labeling of the binary objects of a binary
+ * image using a queue-based algorithm.
*/
# include <mln/core/concept/image.hh>
@@ -55,6 +55,8 @@
* \param[out] nlabels The number of labels.
* \return The label image.
*
+ * \pre The input image has to be binary (checked at compile-time).
+ *
* A fast queue is used so that the algorithm is not recursive and
* can handle large binary objects (blobs).
*/
@@ -69,22 +71,13 @@
namespace impl
{
- // ...
-
- } // end of namespace mln::labeling::impl
-
-
- // Facade.
+ namespace generic
+ {
template <typename I, typename N>
- inline
mln_ch_value(I, unsigned)
- blobs(const Image<I>& input_, const Neighborhood<N>& nbh_, unsigned& nlabels)
+ blobs_(const I& input, const N& nbh, unsigned& nlabels)
{
- const I& input = exact(input_);
- const N& nbh = exact(nbh_);
- mln_precondition(input.has_data());
-
typedef mln_psite(I) P;
P cur;
@@ -125,6 +118,39 @@
return output;
}
+ } // end of namespace mln::labeling::impl::generic
+
+
+ template <typename I, typename N>
+ mln_ch_value(I, unsigned)
+ blobs_(const I& input, const N& nbh, unsigned& nlabels)
+ {
+ // The only implementation is the generic one.
+ return generic::blobs_(input, nbh, nlabels);
+ }
+
+ } // end of namespace mln::labeling::impl
+
+
+ // Facade.
+
+ template <typename I, typename N>
+ inline
+ mln_ch_value(I, unsigned)
+ blobs(const Image<I>& input_, const Neighborhood<N>& nbh_, unsigned& nlabels)
+ {
+ trace::entering("labeling::blobs");
+ mlc_equal(mln_trait_image_kind(I), mln::trait::image::kind::binary)::check();
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ mln_precondition(input.has_data());
+
+ mln_ch_value(I, unsigned) output = impl::blobs_(input, nbh, nlabels);
+
+ trace::exiting("labeling::blobs");
+ return output;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::labeling
Index: mln/labeling/flat_zones.hh
--- mln/labeling/flat_zones.hh (revision 1598)
+++ mln/labeling/flat_zones.hh (working copy)
@@ -33,7 +33,9 @@
* \brief Connected component labeling of the flat zones of an image.
*/
-# include <mln/labeling/base.hh>
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/canvas/labeling.hh>
namespace mln
@@ -46,15 +48,14 @@
*
* \param[in] input The input image.
* \param[in] nbh The neighborhood to consider.
- * \param[out] output The label image.
* \param[out] nlabels The number of labels.
- *
- * \return The number of labels.
+ * \return The label image.
*/
- template <typename I, typename N, typename O>
- bool flat_zones(const Image<I>& input, const Neighborhood<N>& nbh,
- Image<O>& output,
- unsigned& nlabels);
+ template <typename I, typename N, typename L>
+ mln_ch_value(I, L)
+ flat_zones(const Image<I>& input, const Neighborhood<N>& nbh,
+ L& nlabels);
+
# ifndef MLN_INCLUDE_ONLY
@@ -62,47 +63,87 @@
namespace impl
{
- template <typename I_, typename N_, typename O_>
- struct flat_zones_ : base_<I_,N_,O_>
+ // Flat zone functor for the labeling canvas.
+
+ template <typename I_, typename N_, typename L_>
+ struct flat_zones_functor
{
- typedef mln_point(I_) P;
+ typedef mln_psite(I_) P;
// requirements from mln::canvas::labeling:
- typedef mln_pset(I_) S;
+ typedef I_ I;
+ typedef N_ N;
+ typedef L_ L;
+ typedef mln_pset(I) S;
+
+ const I& input;
+ const N& nbh;
const S& s;
- mln_value(O) nlabels;
- bool status;
- inline
- bool equiv(const P& n, const P&) const { return input(n) = input(p); }
+ bool handles(const P&) const { return true; }
+ bool equiv(const P& n, const P& p) const { return input(n) = input(p); }
+
+ void init() {}
+ bool labels(const P&) const { return true; }
+ void do_no_union(const P&, const P&) {}
+ void init_attr(const P&) {}
+ void merge_attr(const P&, const P&) {}
// end of requirements
- inline
- flat_zones_(const I_& input, const N_& nbh, O_& output)
- : base_<I_,N_,O_>(input, nbh, output),
+ flat_zones_functor(const I_& input, const N_& nbh)
+ : input(input),
+ nbh(nbh),
s(input.domain())
{}
};
+
+ // Generic implementation.
+
+ namespace generic
+ {
+
+ template <typename I, typename N, typename L>
+ mln_ch_value(I, L)
+ flat_zones_(const I& input, const N& nbh, L& nlabels)
+ {
+ trace::entering("labeling::impl::generic::flat_zones_");
+
+ typedef flat_zones_functor<I,N,L> F;
+ F f(input, nbh);
+ canvas::labeling<F> run(f);
+ nlabels = run.nlabels;
+
+ trace::exiting("labeling::impl::generic::flat_zones_");
+ return run.output;
+ }
+
+ } // end of namespace mln::labeling::impl::generic
+
+
} // end of namespace mln::labeling::impl
+
// Facade.
- template <typename I, typename N, typename O>
- inline
- bool flat_zones(const Image<I>& input, const Neighborhood<N>& nbh,
- Image<O>& output,
- unsigned& nlabels)
- {
- mln_precondition(exact(output).domain() = exact(input).domain());
- typedef impl::flat_zones_<I,N,O> F;
- F f(exact(input), exact(nbh), exact(output));
- canvas::labeling<F> run(f);
- nlabels = f.nlabels;
- return f.status;
+ template <typename I, typename N, typename L>
+ mln_ch_value(I, L)
+ flat_zones(const Image<I>& input_, const Neighborhood<N>& nbh_,
+ L& nlabels)
+ {
+ trace::entering("labeling::flat_zones");
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ mln_precondition(input.has_data());
+
+ // Calls the only (generic) impl.
+ mln_ch_value(I, L) output = impl::generic::flat_zones_(input, nbh, nlabels);
+
+ trace::exiting("labeling::flat_zones");
+ return output;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/labeling/level.hh
--- mln/labeling/level.hh (revision 1598)
+++ mln/labeling/level.hh (working copy)
@@ -35,10 +35,12 @@
*/
# include <mln/core/concept/image.hh>
-# include <mln/labeling/base.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/canvas/labeling.hh>
# include <mln/level/fill.hh>
-# include <mln/border/adjust.hh>
-# include <mln/value/other.hh>
+
+// The 'fastest' specialization is in:
+# include <mln/labeling/level.spe.hh>
@@ -57,10 +59,11 @@
* \param[out] nlabels The number of labels.
* \return The label image.
*/
- template <typename I, typename N>
- mln_ch_value(I, unsigned)
+ template <typename I, typename N, typename L>
+ mln_ch_value(I, L)
level(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
- unsigned& nlabels);
+ L& nlabels);
+
# ifndef MLN_INCLUDE_ONLY
@@ -68,125 +71,91 @@
namespace impl
{
- // Functors.
+ // Generic functor.
- template <typename I_, typename N_, typename O_>
- struct level_t : base_<I_,N_,O_>
+ template <typename I_, typename N_, typename L_>
+ struct level_functor
{
- typedef mln_point(I_) P;
+ typedef mln_psite(I_) P;
// requirements from mln::canvas::labeling:
- typedef mln_pset(I_) S;
+ typedef I_ I;
+ typedef N_ N;
+ typedef L_ L;
+ typedef mln_pset(I) S;
+
+ const I& input;
+ const N& nbh;
const S& s;
- inline
- void init() { mln::level::fill(this->output, 0); } // FIXME: use literal::zero
- inline
bool handles(const P& p) const { return input(p) = val; }
- inline
bool equiv(const P& n, const P&) const { return input(n) = val; }
+ void init() {}
+ bool labels(const P&) const { return true; }
+ void do_no_union(const P&, const P&) {}
+ void init_attr(const P&) {}
+ void merge_attr(const P&, const P&) {}
+
// end of requirements
const mln_value(I_)& val;
- inline
- level_t(const I_& input, const mln_value(I_)& val, const N_& nbh, O_& output)
- : base_<I_,N_,O_>(input, nbh, output),
+ level_functor(const I_& input, const mln_value(I_)& val, const N_& nbh)
+ : input(input),
+ nbh(nbh),
s(input.domain()),
val(val)
{}
};
- // Routines.
- template <typename I, typename N>
- inline
- mln_ch_value(I, unsigned)
- level_(trait::image::speed::any, const I& input,
- const mln_value(I)& val, const Neighborhood<N>& nbh,
- unsigned& nlabels)
- {
- typedef mln_ch_value(I, unsigned) O;
- O output;
- initialize(output, input);
+ // Generic implementation.
- typedef impl::level_t<I,N,O> F;
- F f(input, val, exact(nbh), output);
- canvas::labeling<F> run(f);
-
- nlabels = f.nlabels;
- // FIXME: Handle f.status
- return output;
- }
-
- // FIXME: Add fast versions.
-
- template <typename I_, typename N_, typename O_>
- struct level_fast_t : labeling::impl::base_fast_<I_,N_,O_>
+ namespace generic
{
- typedef mln_point(I_) P;
-
- // typedef mln_pset(I_) S;
- // const S& s;
-
- inline
- void init() { mln::level::fill(this->output, 0); }
- inline
- bool handles(unsigned p) const { return this->input[p] = val; }
- inline
- bool equiv(unsigned n, unsigned) const { return this->input[n] = val; }
-
- const mln_value(I_)& val;
- inline
- level_fast_t(const I_& input, const mln_value(I_)& val, const N_& nbh, O_& output)
- : labeling::impl::base_fast_<I_,N_,O_>(input, nbh, output),
- // s(input.domain()),
- val(val)
- {}
- };
+ template <typename I, typename N, typename L>
+ mln_ch_value(I, L)
+ level_(const I& input, const mln_value(I)& val, const N& nbh,
+ L& nlabels)
+ {
+ trace::entering("labeling::impl::generic::level_");
+ typedef level_functor<I,N,L> F;
+ F f(input, val, nbh);
+ canvas::labeling<F> run(f);
- template <typename I, typename N>
- inline
- mln_ch_value(I, unsigned)
- level_(trait::image::speed::fastest, const I& input,
- const mln_value(I)& val, const Neighborhood<N>& nbh,
- unsigned& nlabels)
- {
- typedef mln_ch_value(I, unsigned) O;
- typedef level_fast_t<I,N,O> F;
-
- border::adjust(input, exact(nbh).delta());
- O output;
- initialize(output, input);
- mln_assertion(output.border() = input.border());
+ nlabels = run.nlabels;
+ // FIXME: Handle run.status
- F f(input, val, exact(nbh), output);
- canvas::labeling_fast<F> run(f);
+ trace::exiting("labeling::impl::generic::level_");
+ return run.output;
+ }
- // FIXME: Handle f.status
+ } // end of namespace mln::labeling::impl::generic
- nlabels = f.nlabels;
- return output;
- }
} // end of namespace mln::labeling::impl
+
// Facade.
- template <typename I, typename N>
- inline
- mln_ch_value(I, unsigned)
+ template <typename I, typename N, typename L>
+ mln_ch_value(I, L)
level(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
- unsigned& nlabels)
+ L& nlabels)
{
+ trace::entering("labeling::level");
mln_precondition(exact(input).has_data());
- return impl::level_(mln_trait_image_speed(I)(), exact(input),
- val, nbh, nlabels);
+
+ mln_ch_value(I, L) output = impl::level_(mln_trait_image_speed(I)(),
+ exact(input), val, exact(nbh), nlabels);
+
+ trace::exiting("labeling::level");
+ return output;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/labeling/all.hh
--- mln/labeling/all.hh (revision 1598)
+++ mln/labeling/all.hh (working copy)
@@ -47,7 +47,7 @@
}
# include <mln/labeling/background.hh>
-# include <mln/labeling/base.hh>
+# include <mln/labeling/blobs.hh>
# include <mln/labeling/estimate.hh>
# include <mln/labeling/flat_zones.hh>
# include <mln/labeling/foreground.hh>
Index: mln/labeling/regional_minima.hh
--- mln/labeling/regional_minima.hh (revision 1598)
+++ mln/labeling/regional_minima.hh (working copy)
@@ -34,7 +34,10 @@
* image.
*/
-# include <mln/labeling/base.hh>
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/canvas/labeling.hh>
+# include <mln/level/fill.hh>
# include <mln/level/sort_points.hh>
@@ -49,14 +52,14 @@
*
* \param[in] input The input image.
* \param[in] nbh The neighborhood to consider.
- * \param[out] output The label image.
- * \param[out] nlabels The number of labels.
+ * \param[out] nlabels The number of labeled regions.
+ * \return The label image.
*
- * \return The number of labels.
*/
- template <typename I, typename N, typename O>
- bool regional_minima(const Image<I>& input, const Neighborhood<N>& nbh,
- Image<O>& output, unsigned& nlabels);
+ template <typename I, typename N, typename L>
+ mln_ch_value(I, L)
+ regional_minima(const Image<I>& input, const Neighborhood<N>& nbh,
+ L& nlabels);
@@ -65,58 +68,92 @@
namespace impl
{
- template <typename I_, typename N_, typename O_>
- struct regional_minima_ : base_<I_,N_,O_>
+ // Generic functor.
+
+ template <typename I_, typename N_, typename L_>
+ struct regional_minima_functor
{
- typedef mln_point(I_) P;
+ typedef mln_psite(I_) P;
// requirements from mln::canvas::labeling:
+ typedef I_ I;
+ typedef N_ N;
+ typedef L_ L;
typedef p_array<P> S;
+
+ const I& input;
+ const N& nbh;
S s;
- inline
- void init() { mln::level::fill(this->output, 0);
- level::fill(attr, true); }
- inline
+ void init() { level::fill(attr, true); }
+ bool handles(const P&) const { return true; }
bool labels(const P& p) const { return attr(p); }
- inline
bool equiv(const P& n, const P& p) const { return input(n) = input(p); }
- inline
void do_no_union(const P& n, const P& p) { mln_invariant(input(n) < input(p));
attr(p) = false; }
- inline
+ void init_attr(const P&) {}
void merge_attr(const P& r, const P& p) { attr(p) = attr(p) && attr(r); }
// end of requirements
- mln_ch_value(O_, bool) attr;
+ mln_ch_value(I, bool) attr;
- inline
- regional_minima_(const I_& input, const N_& nbh, O_& output)
- : base_<I_,N_,O_>(input, nbh, output),
- s(level::sort_points_increasing(input)),
- attr(output.domain())
+ regional_minima_functor(const I_& input, const N_& nbh)
+ : input(input),
+ nbh(nbh),
+ s(level::sort_points_increasing(input)), // FIXME: sort_psites_increasing
+ attr(input.domain())
{
}
};
+
+ // Generic implementation.
+
+ namespace generic
+ {
+
+ template <typename I, typename N, typename L>
+ mln_ch_value(I, L)
+ regional_minima_(const I& input, const N& nbh,
+ L& nlabels)
+ {
+ trace::entering("labeling::impl::generic::regional_minima_");
+
+ typedef impl::regional_minima_functor<I,N,L> F;
+ F f(input, nbh);
+ canvas::labeling<F> run(f);
+ nlabels = run.nlabels;
+
+ trace::exiting("labeling::impl::generic::regional_minima_");
+ return run.output;
+ }
+
+ } // end of namespace mln::labeling::impl::generic
+
+
} // end of namespace mln::labeling::impl
+
// Facade.
- template <typename I, typename N, typename O>
- inline
- bool regional_minima(const Image<I>& input, const Neighborhood<N>& nbh,
- Image<O>& output, unsigned& nlabels)
- {
- mln_precondition(exact(output).domain() = exact(input).domain());
- typedef impl::regional_minima_<I,N,O> F;
- F f(exact(input), exact(nbh), exact(output));
- canvas::labeling<F> run(f);
- nlabels = f.nlabels;
- return f.status;
+ template <typename I, typename N, typename L>
+ mln_ch_value(I, L)
+ regional_minima(const Image<I>& input_, const Neighborhood<N>& nbh_,
+ L& nlabels)
+ {
+ trace::entering("labeling::regional_minima");
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ mln_precondition(input.has_data());
+
+ // Calls the only (generic) impl.
+ mln_ch_value(I, L) output = impl::generic::regional_minima_(input, nbh, nlabels);
+
+ trace::exiting("labeling::regional_minima");
+ return output;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/labeling/foreground.hh
--- mln/labeling/foreground.hh (revision 1598)
+++ mln/labeling/foreground.hh (working copy)
@@ -50,6 +50,13 @@
* \param[in] nbh The neighborhood to consider.
* \param[out] nlabels The number of labels.
* \return The label image.
+ *
+ * \pre The input image has to be binary (checked at compile-time).
+ *
+ * This routine actually calls mln::labeling::level with the level
+ * value set to \c true.
+ *
+ * \see mln::labeling::level
*/
template <typename I, typename N>
mln_ch_value(I, unsigned)
@@ -65,8 +72,14 @@
foreground(const Image<I>& input, const Neighborhood<N>& nbh,
unsigned& nlabels)
{
+ trace::entering("labeling::foreground");
+ mlc_equal(mln_trait_image_kind(I), mln::trait::image::kind::binary)::check();
mln_precondition(exact(input).has_data());
- return labeling::level(input, true, nbh, nlabels);
+
+ mln_ch_value(I, unsigned) output = labeling::level(input, true, nbh, nlabels);
+
+ trace::exiting("labeling::foreground");
+ return output;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/labeling/regional_maxima.hh
--- mln/labeling/regional_maxima.hh (revision 1598)
+++ mln/labeling/regional_maxima.hh (working copy)
@@ -34,7 +34,10 @@
* image.
*/
-# include <mln/labeling/base.hh>
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/canvas/labeling.hh>
+# include <mln/level/fill.hh>
# include <mln/level/sort_points.hh>
@@ -49,14 +52,14 @@
*
* \param[in] input The input image.
* \param[in] nbh The neighborhood to consider.
- * \param[out] output The label image.
* \param[out] nlabels The number of labeled regions.
+ * \return The label image.
*
- * \return The number of labels.
*/
- template <typename I, typename N, typename O>
- bool regional_maxima(const Image<I>& input, const Neighborhood<N>& nbh,
- Image<O>& output, unsigned& nlabels);
+ template <typename I, typename N, typename L>
+ mln_ch_value(I, L)
+ regional_maxima(const Image<I>& input, const Neighborhood<N>& nbh,
+ L& nlabels);
@@ -65,58 +68,92 @@
namespace impl
{
- template <typename I_, typename N_, typename O_>
- struct regional_maxima_ : base_<I_,N_,O_>
+ // Generic functor.
+
+ template <typename I_, typename N_, typename L_>
+ struct regional_maxima_functor
{
- typedef mln_point(I_) P;
+ typedef mln_psite(I_) P;
// requirements from mln::canvas::labeling:
+ typedef I_ I;
+ typedef N_ N;
+ typedef L_ L;
typedef p_array<P> S;
+
+ const I& input;
+ const N& nbh;
S s;
- inline
- void init() { mln::level::fill(this->output, 0);
- level::fill(attr, true); }
- inline
+ void init() { level::fill(attr, true); }
+ bool handles(const P&) const { return true; }
bool labels(const P& p) const { return attr(p); }
- inline
bool equiv(const P& n, const P& p) const { return input(n) = input(p); }
- inline
void do_no_union(const P& n, const P& p) { mln_invariant(input(n) > input(p));
attr(p) = false; }
- inline
+ void init_attr(const P&) {}
void merge_attr(const P& r, const P& p) { attr(p) = attr(p) && attr(r); }
// end of requirements
- mln_ch_value(O_, bool) attr;
+ mln_ch_value(I, bool) attr;
- inline
- regional_maxima_(const I_& input, const N_& nbh, O_& output)
- : base_<I_,N_,O_>(input, nbh, output),
- s(level::sort_points_decreasing(input)),
- attr(output.domain())
+ regional_maxima_functor(const I_& input, const N_& nbh)
+ : input(input),
+ nbh(nbh),
+ s(level::sort_points_decreasing(input)), // FIXME: sort_psites_decreasing
+ attr(input.domain())
{
}
};
+
+ // Generic implementation.
+
+ namespace generic
+ {
+
+ template <typename I, typename N, typename L>
+ mln_ch_value(I, L)
+ regional_maxima_(const I& input, const N& nbh,
+ L& nlabels)
+ {
+ trace::entering("labeling::impl::generic::regional_maxima_");
+
+ typedef impl::regional_maxima_functor<I,N,L> F;
+ F f(input, nbh);
+ canvas::labeling<F> run(f);
+ nlabels = run.nlabels;
+
+ trace::exiting("labeling::impl::generic::regional_maxima_");
+ return run.output;
+ }
+
+ } // end of namespace mln::labeling::impl::generic
+
+
} // end of namespace mln::labeling::impl
+
// Facade.
- template <typename I, typename N, typename O>
- inline
- bool regional_maxima(const Image<I>& input, const Neighborhood<N>& nbh,
- Image<O>& output, unsigned& nlabels)
- {
- mln_precondition(exact(output).domain() = exact(input).domain());
- typedef impl::regional_maxima_<I,N,O> F;
- F f(exact(input), exact(nbh), exact(output));
- canvas::labeling<F> run(f);
- nlabels = f.nlabels;
- return f.status;
+ template <typename I, typename N, typename L>
+ mln_ch_value(I, L)
+ regional_maxima(const Image<I>& input_, const Neighborhood<N>& nbh_,
+ L& nlabels)
+ {
+ trace::entering("labeling::regional_maxima");
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ mln_precondition(input.has_data());
+
+ // Calls the only (generic) impl.
+ mln_ch_value(I, L) output = impl::generic::regional_maxima_(input, nbh, nlabels);
+
+ trace::exiting("labeling::regional_maxima");
+ return output;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/labeling/level.spe.hh
--- mln/labeling/level.spe.hh (revision 0)
+++ mln/labeling/level.spe.hh (revision 0)
@@ -0,0 +1,175 @@
+// 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.
+
+#ifndef MLN_LABELING_LEVEL_SPE_HH
+# define MLN_LABELING_LEVEL_SPE_HH
+
+/*! \file mln/labeling/level.spe.hh
+ *
+ * \brief Specialization for mln::labeling::level.
+ */
+
+# include <mln/border/adjust.hh>
+# include <mln/border/fill.hh>
+# include <mln/value/other.hh>
+
+
+
+namespace mln
+{
+
+ namespace labeling
+ {
+
+ /*! Connected component labeling of the image objects at a given
+ * level.
+ *
+ * \param[in] input The input image.
+ * \param[in] val The level to consider for the labeling.
+ * \param[in] nbh The neighborhood.
+ * \param[out] nlabels The number of labels.
+ * \return The label image.
+ */
+ template <typename I, typename N, typename L>
+ mln_ch_value(I, L)
+ level(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
+ L& nlabels);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Fwd decl of the Generic version.
+
+ namespace generic
+ {
+
+ template <typename I, typename N, typename L>
+ mln_ch_value(I, L)
+ level_(const I& input, const mln_value(I)& val, const N& nbh,
+ L& nlabels);
+
+ } // end of namespace mln::labeling::impl::generic
+
+
+
+ // Fastest functor.
+
+ template <typename I_, typename N_, typename L_>
+ struct level_fastest_functor
+ {
+ // requirements from mln::canvas::labeling:
+
+ typedef I_ I;
+ typedef N_ N;
+ typedef L_ L;
+ typedef mln_pset(I) S;
+
+ const I& input;
+ const N& nbh;
+ const S& s;
+
+ bool handles(unsigned p) const { return input[p] = val; }
+ bool equiv(unsigned n, unsigned) const { return input[n] = val; }
+
+ void init() {}
+ bool labels(unsigned) const { return true; }
+ void do_no_union(unsigned, unsigned) {}
+ void init_attr(unsigned) {}
+ void merge_attr(unsigned, unsigned) {}
+
+ // end of requirements
+
+ const mln_value(I_)& val;
+
+ level_fastest_functor(const I_& input, const mln_value(I_)& val, const N_& nbh)
+ : input(input),
+ nbh(nbh),
+ s(input.domain()),
+ val(val)
+ {}
+ };
+
+
+ // Fastest routine.
+
+ template <typename I, typename N, typename L>
+ mln_ch_value(I, L)
+ level_fastest_(const I& input, const mln_value(I)& val, const N& nbh,
+ L& nlabels)
+ {
+ trace::entering("labeling::impl::level_fastest_");
+
+ border::adjust(input, nbh.delta());
+ border::fill(input, value::other(val));
+
+ typedef level_fastest_functor<I,N,L> F;
+ F f(input, val, nbh);
+ canvas::labeling_fastest<F> run(f);
+
+ nlabels = run.nlabels;
+ // FIXME: Handle run.status
+
+ trace::exiting("labeling::impl::level_fastest_");
+ return run.output;
+ }
+
+
+ // Disjunction between "fastest" and "not fastest".
+
+ template <typename I, typename N, typename L>
+ mln_ch_value(I, L)
+ level_(trait::image::speed::any,
+ const I& input, const mln_value(I)& val, const N& nbh,
+ L& nlabels)
+ {
+ return generic::level_(input, val, nbh, nlabels);
+ }
+
+ template <typename I, typename N, typename L>
+ mln_ch_value(I, L)
+ level_(trait::image::speed::fastest,
+ const I& input, const mln_value(I)& val, const N& nbh,
+ L& nlabels)
+ {
+ return level_fastest_(input, val, nbh, nlabels);
+ }
+
+
+ } // end of namespace mln::labeling::impl
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::labeling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LABELING_LEVEL_SPE_HH
Index: mln/labeling/background.hh
--- mln/labeling/background.hh (revision 1598)
+++ mln/labeling/background.hh (working copy)
@@ -43,13 +43,20 @@
namespace labeling
{
- /*! Connected component labeling of the background in a binary
- * image.
+ /*! Connected component labeling of the background part in a
+ * binary image.
*
* \param[in] input The input image.
* \param[in] nbh The neighborhood to consider.
* \param[out] nlabels The number of labels.
* \return The label image.
+ *
+ * \pre The input image has to be binary (checked at compile-time).
+ *
+ * This routine actually calls mln::labeling::level with the level
+ * value set to \c false.
+ *
+ * \see mln::labeling::level
*/
template <typename I, typename N>
mln_ch_value(I, unsigned)
@@ -65,8 +72,14 @@
background(const Image<I>& input, const Neighborhood<N>& nbh,
unsigned& nlabels)
{
+ trace::entering("labeling::background");
+ mlc_equal(mln_trait_image_kind(I), mln::trait::image::kind::binary)::check();
mln_precondition(exact(input).has_data());
- return labeling::level(input, false, nbh, nlabels);
+
+ mln_ch_value(I, unsigned) output = labeling::level(input, false, nbh, nlabels);
+
+ trace::exiting("labeling::background");
+ return output;
}
# endif // ! MLN_INCLUDE_ONLY
Index: img/README
--- img/README (revision 0)
+++ img/README (revision 0)
@@ -0,0 +1,8 @@
+ -*- outline -*-
+
+* tiny.pgm
+
+lena 16x16, graylevel / 8bit
+
+it was obtained by running the command:
+convert -geometry 3.125% lena.pgm tiny.pgm
Index: sandbox/geraud/estimate.hh
--- sandbox/geraud/estimate.hh (revision 1593)
+++ sandbox/geraud/estimate.hh (working copy)
@@ -33,8 +33,13 @@
* \brief Compute the estimate pixel value.
*/
-# include <mln/core/image_if_value.hh>
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/canvas/labeling.hh>
+
# include <mln/accu/compute.hh>
+// # include <mln/core/image_if_value.hh>
+
namespace mln
@@ -43,28 +48,36 @@
namespace labeling
{
- /*! \brief FIXME: Compute an estimate over the pixels of image \p
- * input with value \p val.
+ /*! \brief Label a binary image and compute some estimations over
+ * the components.
*
* \param[in] input The image.
- * \param[in] val value.
- * \result The estimate value.
+ *
+ * The free parameter \c A is a type of accumulator.
+ *
+ * FIXME: Not yet impled.
*/
template <typename A, typename I>
- mln_accu_with(A, util::pix<I>)::result
- estimate(const Image<I>& input, const mln_value(I)& val);
+ void
+ estimate(const Image<I>& input);
# ifndef MLN_INCLUDE_ONLY
template <typename A, typename I>
- inline
- mln_accu_with(A, util::pix<I>)::result
- estimate(const Image<I>& input, const mln_value(I)& val)
+ void
+ estimate(const Image<I>& input)
{
-// void* v = (input | val);
-// return 0;
- return accu::compute<A>(input | val);
+ trace::entering("labeling::estimate");
+ mlc_equal(mln_trait_image_kind(I), mln::trait::image::kind::binary)::check();
+ mln_precondition(exact(input).has_data());
+
+ std::cerr << "Sorry: mln::labeling::estimate is not yet implemented!" << std::endl;
+
+ // FIXME: Was:
+ // mln_accu_with(A, util::pix<I>)::result res = accu::compute<A>(input | val);
+
+ trace::exiting("labeling::estimate");
}
# endif // ! MLN_INCLUDE_ONLY
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-12-06 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add 1d version for border::mirror.
* mln/border/mirror.hh: Add 1d version for this algorithm.
Update tests
* tests/border/mirror.cc,
* tests/border/mirror_full.cc: Fix typo and add test for this.
---
mln/border/mirror.hh | 72 ++++++++++++++++++++++++++++++++------------
tests/border/mirror.cc | 22 ++++++++++++-
tests/border/mirror_full.cc | 4 +-
3 files changed, 75 insertions(+), 23 deletions(-)
Index: trunk/milena/tests/border/mirror_full.cc
===================================================================
--- trunk/milena/tests/border/mirror_full.cc (revision 1597)
+++ trunk/milena/tests/border/mirror_full.cc (revision 1598)
@@ -25,9 +25,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/border/duplicate_full.cc
+/*! \file tests/border/mirror_full.cc
*
- * \brief Tests on mln::border::duplicate.
+ * \brief Tests on mln::border::mirror.
*/
#include <mln/core/image1d.hh>
Index: trunk/milena/tests/border/mirror.cc
===================================================================
--- trunk/milena/tests/border/mirror.cc (revision 1597)
+++ trunk/milena/tests/border/mirror.cc (revision 1598)
@@ -25,20 +25,38 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/border_duplicate/test_border_duplicate_image2d_1.cc
+/*! \file tests/border/mirror.cc
*
- * \brief Tests on mln::border::duplicate.
+ * \brief Tests on mln::border::mirror.
*/
+#include <mln/core/image1d.hh>
#include <mln/core/image2d.hh>
#include <mln/debug/iota.hh>
#include <mln/border/mirror.hh>
+#include <mln/debug/println_with_border.hh>
+
using namespace mln;
int
main (void)
{
+ {
+ image1d<int> im(2, 3);
+ debug::iota(im);
+ border::mirror(im);
+ mln_assertion(im[0] == 2);
+ mln_assertion(im[1] == 2);
+ mln_assertion(im[2] == 1);
+ mln_assertion(im[3] == 1);
+ mln_assertion(im[4] == 2);
+ mln_assertion(im[5] == 2);
+ mln_assertion(im[6] == 1);
+ mln_assertion(im[7] == 1);
+ }
+
+
image2d<int> ima(2, 3, 2);
debug::iota(ima);
Index: trunk/milena/mln/border/mirror.hh
===================================================================
--- trunk/milena/mln/border/mirror.hh (revision 1597)
+++ trunk/milena/mln/border/mirror.hh (revision 1598)
@@ -34,6 +34,10 @@
* mirroring effect.
*/
+# include <mln/core/image1d.hh>
+# include <mln/core/image2d.hh>
+# include <mln/core/image3d.hh>
+
# include <mln/core/concept/image.hh>
# include <mln/core/internal/fixme.hh>
# include <mln/core/internal/fixme.hh>
@@ -41,7 +45,7 @@
# include <mln/geom/max_row.hh>
# include <mln/geom/min_col.hh>
# include <mln/geom/max_col.hh>
-
+# include <mln/geom/ninds.hh>
namespace mln
{
@@ -56,7 +60,7 @@
*
* \pre \p ima has to be initialized.
*
- * \todo Implement 1d and 3d version + optimize with memset if possible.
+ * \todo Implement 3d version + optimize with memset if possible.
*/
template <typename I>
void mirror(const Image<I>& ima);
@@ -69,16 +73,51 @@
template <typename I>
inline
- void mirror_1d_(const I& ima)
+ void mirror_(const box1d&, const I& ima)
{
- mln::internal::fixme();
+ trace::entering("border::impl::mirror_");
+
+ std::size_t border = ima.border ();
+ std::size_t nbinds = geom::ninds(ima);
+ std::size_t min;
+
+ if (border > nbinds)
+ min = nbinds;
+ else
+ min = border;
+
+ /// left border
+ {
+ std::size_t i = 0;
+ for (; i < min; ++i)
+ const_cast<I&>(ima)[border - 1 - i] = ima(point1d(i));
+
+ for (; i < border; ++i)
+ const_cast<I&>(ima)[border - 1 - i] = ima(point1d(min - 1));
+ }
+
+ /// right border
+ {
+ std::size_t i = 0,
+ j = nbinds - 1;
+ for (;
+ i < min;
+ ++i, --j)
+ const_cast<I&>(ima)[border + nbinds + i] = ima(point1d(j));
+ ++j;
+ for (;
+ i < border;
+ ++i)
+ const_cast<I&>(ima)[border + nbinds + i] = ima(point1d(j));
+ }
+ trace::exiting("border::impl::mirror_");
}
template <typename I>
inline
- void mirror_2d_(const I& ima)
+ void mirror_(const box2d&, const I& ima)
{
- trace::entering("border::impl::mirror_2d_");
+ trace::entering("border::impl::mirror_");
std::size_t border = ima.border ();
std::size_t nbrows = geom::max_row(ima) - geom::min_row(ima);
@@ -87,24 +126,24 @@
std::size_t start = real_nbcols * border + border;
std::size_t s = start;
- // duplicate top left corner
+ // mirror top left corner
for (std::size_t i = 0; i < border; ++i)
for (std::size_t j = 0; j < border; ++j)
const_cast<I&>(ima)[i * ((nbcols + 1) + 2 * border) + j] = ima[s];
- // duplicate top left corner
+ // mirror top left corner
s = start + nbcols;
for (std::size_t i = 0; i < border; ++i)
for (std::size_t j = 1; j <= border; ++j)
const_cast<I&>(ima)[i * ((nbcols + 1) + 2 * border) + (nbcols + border + j)] = ima[s];
- // duplicate bottom left corner
+ // mirror bottom left corner
s = start + (nbrows * real_nbcols);
for (std::size_t i = 1; i <= border; ++i)
for (std::size_t j = 1; j <= border; ++j)
const_cast<I&>(ima)[s - i + (j * (real_nbcols))] = ima[s];
- // duplicate bottom right corner
+ // mirror bottom right corner
s = start + (nbrows * real_nbcols) + nbcols;
for (std::size_t i = 1; i <= border; ++i)
for (std::size_t j = 1; j <= border; ++j)
@@ -134,18 +173,18 @@
for (std::size_t j = 1; j <= border; ++j)
const_cast<I&>(ima)[s + i + (j * real_nbcols)] = ima[s + i - ((j - 1)* real_nbcols)];
- trace::exiting("border::impl::mirror_2d_");
+ trace::exiting("border::impl::mirror_");
}
template <typename I>
inline
- void mirror_3d_(const I& ima)
+ void mirror_(const box3d&, const I& ima)
{
mln::internal::fixme();
}
- } // end of namespace mln::border::mirror
+ } // end of namespace mln::border::impl
template <typename I>
@@ -164,12 +203,7 @@
if (!ima.border ())
return;
- if (P::dim == 1)
- impl::mirror_1d_(ima);
- if (P::dim == 2)
- impl::mirror_2d_(ima);
- if (P::dim == 3)
- impl::mirror_3d_(ima);
+ impl::mirror_(ima.bbox(), ima);
trace::exiting("border::mirror");
}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-12-06 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Fix doxygen header of value tests.
* bool.cc,
* builtin.cc,
* equiv.cc,
* float01.cc,
* float01_bis.cc,
* float01_f.cc,
* int_s.cc,
* int_s16.cc,
* int_u8.cc,
* interop.cc,
* label.cc,
* quat.cc,
* rgb8.cc,
* rgb_full.cc,
* scalar.cc,
* set.cc: Fix doxygen headers.
* Makefile.am: Disable check_full_PROGRAMS to pass ./bootstrap.
* graylevel.cc: Rename as...
* graylevel_full.cc: ...this.
---
Makefile.am | 11 +
bool.cc | 2
builtin.cc | 2
equiv.cc | 2
float01.cc | 2
float01_bis.cc | 27 +--
float01_f.cc | 2
graylevel_full.cc | 370 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
int_s.cc | 2
int_s16.cc | 2
int_u8.cc | 2
interop.cc | 2
label.cc | 2
quat.cc | 2
rgb8.cc | 2
rgb_full.cc | 3
scalar.cc | 2
set.cc | 2
18 files changed, 404 insertions(+), 35 deletions(-)
Index: trunk/milena/tests/value/graylevel.cc (deleted)
===================================================================
Index: trunk/milena/tests/value/set.cc
===================================================================
--- trunk/milena/tests/value/set.cc (revision 1596)
+++ trunk/milena/tests/value/set.cc (revision 1597)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/value_set.cc
+/*! \file tests/value/set.cc
*
* \brief Tests on mln::value::set_<T>.
*/
Index: trunk/milena/tests/value/bool.cc
===================================================================
--- trunk/milena/tests/value/bool.cc (revision 1596)
+++ trunk/milena/tests/value/bool.cc (revision 1597)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/value_bool.cc
+/*! \file tests/value/bool.cc
*
* \brief Tests on mln::value::set.
*/
Index: trunk/milena/tests/value/rgb_full.cc
===================================================================
--- trunk/milena/tests/value/rgb_full.cc (revision 1596)
+++ trunk/milena/tests/value/rgb_full.cc (revision 1597)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/value_rgb.cc
+/*! \file tests/value/rgb.cc
*
* \brief Tests on mln::value::rgb.
*/
@@ -55,6 +55,7 @@
V1.green() OP V2 , \
V1.blue() OP V2 \
)
+
// Interop between 2 rgbs.
#define test_interop(T1, T2, OP, V1, V2) \
{ \
Index: trunk/milena/tests/value/rgb8.cc
===================================================================
--- trunk/milena/tests/value/rgb8.cc (revision 1596)
+++ trunk/milena/tests/value/rgb8.cc (revision 1597)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/value_rgb8.cc
+/*! \file tests/value/rgb8.cc
*
* \brief Tests on mln::value::rgb8.
*/
Index: trunk/milena/tests/value/float01_bis.cc
===================================================================
--- trunk/milena/tests/value/float01_bis.cc (revision 1596)
+++ trunk/milena/tests/value/float01_bis.cc (revision 1597)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/value_float01_bis.cc
+/*! \file tests/value/float01_bis.cc
*
* \brief Tests on mln::value::float01.
*/
@@ -38,21 +38,16 @@
{
using namespace mln::value;
-// float01_8 a;
+ float01_8 a;
- std::cout << "a = " << std::endl;
- std::cout << "testsetestest\n"<< std::endl;
+ gl8 a = white;
+ gl16 b = white;
+ assert((a == b) == true);
+ gl8 c = (a + b) / 2;
+ assert(c == white);
+ c = a;
+ assert(c == white);
-// gl8 a = white;
-// gl16 b = white;
-// assert((a == b) == true);
-// gl8 c = (a + b) / 2;
-// assert(c == white);
-// c = a;
-// assert(c == white);
-
-// c = (a * 2) / 2;
-// assert(c == white);
-
- std::cout << "testsetestest\n"<< std::endl;
+ c = (a * 2) / 2;
+ assert(c == white);
}
Index: trunk/milena/tests/value/scalar.cc
===================================================================
--- trunk/milena/tests/value/scalar.cc (revision 1596)
+++ trunk/milena/tests/value/scalar.cc (revision 1597)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/value_scalar.cc
+/*! \file tests/value/scalar.cc
*
* \brief Tests on mln::value::scalar.
*/
Index: trunk/milena/tests/value/int_u8.cc
===================================================================
--- trunk/milena/tests/value/int_u8.cc (revision 1596)
+++ trunk/milena/tests/value/int_u8.cc (revision 1597)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/value_int_u8.cc
+/*! \file tests/value/int_u8.cc
*
* \brief Tests on mln::value::int_u8.
*/
Index: trunk/milena/tests/value/float01.cc
===================================================================
--- trunk/milena/tests/value/float01.cc (revision 1596)
+++ trunk/milena/tests/value/float01.cc (revision 1597)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/value_float01.cc
+/*! \file tests/value/float01.cc
*
* \brief Tests on mln::value::float01.
*/
Index: trunk/milena/tests/value/builtin.cc
===================================================================
--- trunk/milena/tests/value/builtin.cc (revision 1596)
+++ trunk/milena/tests/value/builtin.cc (revision 1597)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/value_builtin.cc
+/*! \file tests/value/builtin.cc
*
* \brief Tests on mln::trait::op with a builtin.
*/
Index: trunk/milena/tests/value/quat.cc
===================================================================
--- trunk/milena/tests/value/quat.cc (revision 1596)
+++ trunk/milena/tests/value/quat.cc (revision 1597)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/value_quat.cc
+/*! \file tests/value/quat.cc
*
* \brief Tests on mln::value::quat.
*/
Index: trunk/milena/tests/value/float01_f.cc
===================================================================
--- trunk/milena/tests/value/float01_f.cc (revision 1596)
+++ trunk/milena/tests/value/float01_f.cc (revision 1597)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/value_float01_f.cc
+/*! \file tests/value/float01_f.cc
*
* \brief Tests on mln::value::float01_f.
*/
Index: trunk/milena/tests/value/graylevel_full.cc
===================================================================
--- trunk/milena/tests/value/graylevel_full.cc (revision 0)
+++ trunk/milena/tests/value/graylevel_full.cc (revision 1597)
@@ -0,0 +1,370 @@
+// 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/value/graylevel_full.cc
+ *
+ * \brief Tests on mln::value::graylevel. Tests operations between
+ * graylevel of different encodings.
+ *
+ */
+
+#include <mln/value/graylevel2.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/literal/black.hh>
+#include <mln/literal/white.hh>
+
+
+
+int main()
+{
+ using namespace mln::value;
+
+ using mln::literal::white;
+ using mln::literal::black;
+
+ gl8 a = 255;
+ gl8 b = 255;
+
+ // Constructions
+ {
+ gl8 x;
+
+ gl8 a = 12;
+ gl8 b(12);
+ mln_assertion(a == b);
+
+ {
+ gl16 c = 2335;
+ gl8 d = c;
+ mln_assertion(c == d);
+ }
+
+ gl8 d = 250;
+ gl16 c = d;
+ mln_assertion(c == d);
+
+ gl8 e = gray(white);
+ std::cout << e << std::endl;
+ std::cout << gray(white) << std::endl;
+
+ mln_assertion(gray(e) == gray(white));
+
+ gl8 f = 12;
+ gl8 g = f;
+ gl8 h(f);
+
+ mln_assertion(f == g);
+ mln_assertion(h == g);
+ }
+
+ // Literals
+ {
+ gl8 a(white);
+ gl16 b(white);
+
+ mln_assertion(a == b);
+ mln_assertion(a.value() == float(255));
+ mln_assertion(b.value() == float(65535));
+ mln_assertion(a == white);
+ mln_assertion(b == white);
+
+ gl8 c(white);
+ mln_assertion(c == white);
+ mln_assertion(c.value() == float(255));
+
+ a = black;
+ b = black;
+
+ mln_assertion(a == b);
+ mln_assertion(a.value() == float(0));
+ mln_assertion(b.value() == float(0));
+ }
+
+ // Assigment
+ {
+ gl8 a;
+ gl16 b;
+
+ a = white;
+ mln_assertion(a == white);
+ mln_assertion(a.value() == float(255));
+
+ a = 23;
+ mln_assertion(a != white);
+ mln_assertion(a != black);
+ mln_assertion(a.value() == float(23));
+
+ b = 2;
+ mln_assertion(b != white);
+ mln_assertion(b != black);
+ mln_assertion(b.value() == float(2));
+
+ a = b;
+ mln_assertion(a.value() == float(2 / 257));
+
+ signed char c = 51;
+ a = c;
+ mln_assertion(a.value() == float(51));
+
+ // bounds
+ a = 255;
+ mln_assertion(a.value() == float(255));
+ a = 0;
+ mln_assertion(a.value() == float(0));
+ }
+
+ // Addition
+ {
+ gl8 a;
+ gl16 b;
+
+ // gl8 <- gl8 + gl8
+ a = 42;
+ a += a;
+ mln_assertion(a.value() == float(84));
+
+ a = 42;
+ a = a + a;
+ mln_assertion(a.value() == float(84));
+
+ // gl8 <- gl8 + gl16
+ a = 42;
+ b = 16969;
+ a = a + b;
+ mln_assertion(a.value() == float((42 + b.value() / 257) ));
+ a = 42;
+ b = 16969;
+ a += b;
+ mln_assertion(a.value() == float((42 + b.value() / 256) ));
+
+
+ // gl16 <- gl8 + gl16
+ a = 42;
+ b = 16969;
+ b += a;
+ std::cout << "b = " << b << std::endl;
+ std::cout << "res = " << float(42 * 256 + 128 + 16969) << std::endl;
+ mln_assertion(b.value() == float((42 * 256 + 128 + 16969) ));
+
+ a = 42;
+ b = 16969;
+ b = a + b;
+ mln_assertion(b.value() == float((42 * 256 + 128 + 16969) ));
+
+ // misc
+ a = 255;
+ b = 0;
+ a = a + b;
+ mln_assertion(a.value() == float(255));
+
+ a = 0;
+ b = 65535;
+ //FIXME for tomorow: this doesn't work.
+ a = a + b;
+ std::cout << "a = " << a << std::endl;
+ std::cout << "a + b = " << a + b << std::endl;
+ mln_assertion(a.value() == float(255));
+ }
+
+
+ // Soustraction
+ {
+ gl8 a;
+ gl16 b;
+
+ // gl8 <- gl8 - gl8
+ a = 42;
+ a -= a;
+ mln_assertion(a == black);
+
+ a = 42;
+ a = a - a;
+ mln_assertion(a == black);
+
+ // gl8 <- gl8 - gl16
+ a = 42;
+ b = 5969;
+
+ a = b;
+ std::cout << "a.value() = " << int(a.value()) << std::endl;
+ std::cout << "should be " << (b.value() / 256) << std::endl;
+
+ {
+ a = 42;
+ gl8 t;
+ t = a - b;
+ t = t + b;
+ std::cout << t << " == " << a << std::endl;
+ mln_assertion(a == t);
+ }
+
+ a = 42;
+ a = a - b;
+ std::cout << int(a.value()) << ":" << floor(42 - b.value() / 256.0) << std::endl;
+ mln_assertion(a.value() == float((42 - b.value() / 256) ));
+ a = 42;
+ b = 9969;
+ a -= b;
+ mln_assertion(a.value() == float((42 - round(float(b.value()) / 256)) ));
+
+
+ // gl16 <- gl8 - gl16
+ a = 100;
+ b = 30969;
+ b -= a;
+ mln_assertion(b.value() == float(30969 - 100 * 256));
+
+ a = 100;
+ b = 20969;
+ b = a - b;
+ mln_assertion(b.value() == float((100 * 256 - 20969) ));
+
+ // misc
+ a = 255;
+ b = 0;
+ a = a - b;
+ mln_assertion(a.value() == float(255));
+
+ a = 255;
+ b = 65535;
+ a = a - b;
+ mln_assertion(a.value() == float(0));
+
+ // ...
+ {
+ graylevel<2> a = 2;
+ graylevel<3> b = 5;
+ graylevel<2> c;
+ graylevel<3> d;
+
+ c = a - b;
+ d = a - b;
+ mln_assertion(c == d);
+ }
+
+ {
+
+ // ...
+ gl8 a = 42;
+ gl16 b = 5969;
+ gl8 p;
+ p = b;
+ gl8 q;
+ gl8 r;
+
+ q = a - p;
+ r = a - b;
+ std::cout << int(q.value()) << " " << int(r.value()) << std::endl;
+ mln_assertion(q == r);
+
+ }
+
+ }
+
+ // Multiplication
+ {
+ gl8 a;
+ gl16 b;
+
+ // gl8 <- gl8 * gl8
+ a = 8;
+ a *= a;
+ std::cout << a << std::endl;
+ mln_assertion(a.value() == 42);
+
+ a = 21;
+ a = a * a;
+ mln_assertion(a.value() == 42);
+
+ // gl8 <- gl8 * gl16
+ a = 10;
+ b = 5969;
+ a = a * b;
+ mln_assertion(a.value() == float((10 * b.value() / 256) ));
+
+ a = 10;
+ b = 16969;
+ a *= b;
+ mln_assertion(a.value() == float((10 * b.value() / 256) ));
+
+
+ // gl16 <- gl8 * gl16
+ a = 10;
+ b = 5969;
+ b *= a;
+ mln_assertion(b.value() == float((10 * 256 * 5969) ));
+
+ a = 10;
+ b = 5969;
+ b = a * b;
+ mln_assertion(b.value() == float((10 * 256 * 5969) ));
+
+ // misc
+ a = 255;
+ b = 0;
+ a = a * b;
+ mln_assertion(a == black);
+
+ a = 0;
+ b = 65535;
+ a = a * b;
+ mln_assertion(a == black);
+
+ // ...
+ {
+ graylevel<2> a = 2;
+ graylevel<3> b = 5;
+ graylevel<2> c;
+ graylevel<3> d;
+
+ c = a * b;
+ d = a * b;
+ mln_assertion(c == d);
+ }
+
+ {
+
+ // ...
+ gl8 a = 7;
+ gl16 b = 5969;
+
+ gl8 p;
+ p = b;
+
+ gl8 q;
+ gl8 r;
+
+ q = a * p;
+ r = a * b;
+ std::cout << int(q.value()) << " " << int(r.value()) << std::endl;
+ mln_assertion(q == r);
+
+ }
+
+ }
+}
Index: trunk/milena/tests/value/int_s.cc
===================================================================
--- trunk/milena/tests/value/int_s.cc (revision 1596)
+++ trunk/milena/tests/value/int_s.cc (revision 1597)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/value_int_s.cc
+/*! \file tests/value/int_s.cc
*
* \brief Tests on mln::value::int_s.
*/
Index: trunk/milena/tests/value/label.cc
===================================================================
--- trunk/milena/tests/value/label.cc (revision 1596)
+++ trunk/milena/tests/value/label.cc (revision 1597)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/value_label.cc
+/*! \file tests/value/label.cc
*
* \brief Tests on mln::value::label.
*/
Index: trunk/milena/tests/value/interop.cc
===================================================================
--- trunk/milena/tests/value/interop.cc (revision 1596)
+++ trunk/milena/tests/value/interop.cc (revision 1597)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/value_interop.cc
+/*! \file tests/value/interop.cc
*
* \brief Tests interoperability on mln::value::*.
*/
Index: trunk/milena/tests/value/int_s16.cc
===================================================================
--- trunk/milena/tests/value/int_s16.cc (revision 1596)
+++ trunk/milena/tests/value/int_s16.cc (revision 1597)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/value_int_s16.cc
+/*! \file tests/value/int_s16.cc
*
* \brief Tests on mln::value::int_s16.
*/
Index: trunk/milena/tests/value/Makefile.am
===================================================================
--- trunk/milena/tests/value/Makefile.am (revision 1596)
+++ trunk/milena/tests/value/Makefile.am (revision 1597)
@@ -24,8 +24,9 @@
scalar \
set
-check_full_PROGRAMS = \
- rgb_full
+# FIXME: activate when make check_full will work.
+# check_full_PROGRAMS = \
+# rgb_full
bool_SOURCES = bool.cc
builtin_SOURCES = builtin.cc
@@ -44,7 +45,9 @@
scalar_SOURCES = scalar.cc
set_SOURCES = set.cc
-rgb_full_SOURCES = rgb_full.cc
+# FIXME: activate when make check_full will work.
+# rgb_full_SOURCES = rgb_full.cc
TESTS = $(check_PROGRAMS)
-TESTS_FULL = $(check_full_PROGRAMS)
+# FIXME: activate when make check_full will work.
+# TESTS_FULL = $(check_full_PROGRAMS)
Index: trunk/milena/tests/value/equiv.cc
===================================================================
--- trunk/milena/tests/value/equiv.cc (revision 1596)
+++ trunk/milena/tests/value/equiv.cc (revision 1597)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/value_equiv.cc
+/*! \file tests/value/equiv.cc
*
* \brief Tests on mln::value::equiv.
*
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-12-06 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add new full tests for level subdirectory.
* tests/level/apply_full.cc,
* tests/level/paste_full.cc,
* tests/level/saturate_full.cc,
* tests/level/sort_points_full.cc,
* tests/level/stretch_full.cc,
* tests/level/transform_full.cc: New full tests for level.
* mln/fun/v2v/saturate.hh: Fix bug but need to review.
* mln/level/paste.spe.hh: Add comment.
---
mln/fun/v2v/saturate.hh | 14 +
mln/level/paste.spe.hh | 1
tests/level/apply_full.cc | 172 +++++++++++++++++++++
tests/level/paste_full.cc | 280 +++++++++++++++++++++++++++++++++++
tests/level/saturate_full.cc | 241 ++++++++++++++++++++++++++++++
tests/level/sort_points_full.cc | 318 ++++++++++++++++++++++++++++++++++++++++
tests/level/stretch_full.cc | 174 +++++++++++++++++++++
tests/level/transform_full.cc | 165 ++++++++++++++++++++
8 files changed, 1363 insertions(+), 2 deletions(-)
Index: trunk/milena/tests/level/transform_full.cc
===================================================================
--- trunk/milena/tests/level/transform_full.cc (revision 0)
+++ trunk/milena/tests/level/transform_full.cc (revision 1596)
@@ -0,0 +1,165 @@
+// 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/transform_full.cc
+ *
+ * \brief Tests on mln::level::transform
+ */
+
+#include <cmath>
+
+#include <mln/core/image1d.hh>
+#include <mln/core/image2d.hh>
+#include <mln/core/image3d.hh>
+#include <mln/core/sub_image.hh>
+
+#include <mln/core/image_if.hh>
+#include <mln/fun/p2b/chess.hh>
+
+#include <mln/literal/origin.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u16.hh>
+
+#include <mln/value/int_s8.hh>
+#include <mln/value/int_s16.hh>
+
+#include <mln/level/fill.hh>
+#include <mln/level/transform.hh>
+
+#include <mln/debug/iota.hh>
+
+#include <mln/arith/plus.hh>
+
+
+
+
+struct mysqrt : mln::Function_v2v<mysqrt>
+{
+ typedef unsigned short result;
+ result operator()(int c) const
+ {
+ return result(c % 42);
+ }
+};
+
+
+namespace mln
+{
+ template <typename I>
+ void
+ chck(const Image<I>& ref_)
+ {
+ const I& ref = exact(ref_);
+
+ I out (ref.domain());
+ {
+ level::transform(ref, mysqrt(), out);
+ mln_piter(I) p (ref.domain ());
+ for_all(p)
+ mln_assertion ((mln_value(I))(ref(p) % 42) == out(p) );
+ }
+ }
+
+ template <typename V>
+ void
+ chk()
+ {
+ unsigned sli = 4;
+ unsigned row = 16;
+ unsigned col = 64;
+
+
+ (std::cerr << "in 1d ... ").flush ();
+ {
+ typedef image1d<V> I;
+ typedef sub_image<I, box1d> J;
+
+ for (unsigned i = 1; i < col; ++i)
+ {
+ I ima(i);
+ debug::iota(ima);
+ chck (ima);
+ }
+ }
+ std::cerr << "OK" << std::endl;
+
+ (std::cerr << "in 2d ... ").flush ();
+ {
+ typedef image2d<V> I;
+
+ for (unsigned i = 1; i < col; ++i)
+ for (unsigned j = 1; j < row; ++j)
+ {
+ I ima(j, i);
+ debug::iota(ima);
+ chck (ima);
+ }
+ }
+ std::cerr << "OK" << std::endl;
+
+ (std::cerr << "in 3d ... ").flush ();
+ {
+ typedef image3d<V> I;
+
+ for (unsigned i = 1; i < col; ++i)
+ for (unsigned j = 1; j < row; ++j)
+ for (unsigned k = 1; k < sli; ++k)
+ {
+ I ima(k, j, i);
+ debug::iota(ima);
+ chck (ima);
+ }
+ }
+ std::cerr << "OK" << std::endl;
+ }
+
+}
+
+
+
+
+
+int main()
+{
+ using namespace mln;
+
+ std::cerr << "Tests level::transform:" << std::endl;
+ std::cerr << "on int:" << std::endl;
+ chk<int>();
+ std::cerr << "on unsigned:" << std::endl;
+ chk<unsigned>();
+ std::cerr << "on int_u8:" << std::endl;
+ chk<value::int_u8>();
+ std::cerr << "on int_u16:" << std::endl;
+ chk<value::int_u16>();
+ std::cerr << "on int_s8:" << std::endl;
+ chk<value::int_s8>();
+ std::cerr << "on int_s16:" << std::endl;
+ chk<value::int_s16>();
+}
+
Index: trunk/milena/tests/level/apply_full.cc
===================================================================
--- trunk/milena/tests/level/apply_full.cc (revision 0)
+++ trunk/milena/tests/level/apply_full.cc (revision 1596)
@@ -0,0 +1,172 @@
+// 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/apply_full.cc
+ *
+ * \brief Tests on mln::level::apply.
+ */
+
+#include <mln/core/image1d.hh>
+#include <mln/core/image2d.hh>
+#include <mln/core/image3d.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u16.hh>
+#include <mln/value/int_s8.hh>
+#include <mln/value/int_s16.hh>
+
+
+#include <mln/core/clone.hh>
+#include <mln/level/apply.hh>
+#include <mln/debug/iota.hh>
+
+#include <mln/debug/println.hh>
+
+struct qrde : mln::Function_v2v<qrde>
+{
+ typedef unsigned short result;
+ result operator()(int c) const
+ {
+ return result(c % 42);
+ }
+};
+
+
+namespace mln
+{
+ template <typename I>
+ void
+ chck(I& ref)
+ {
+ I out = clone (ref);
+
+ mln_piter(I) p (ref.domain ());
+
+ {
+ level::apply(out, qrde());
+
+ for_all(p)
+ mln_assertion((mln_value(I))(ref(p) % 42) == out(p));
+ }
+
+ }
+
+ template <typename I>
+ void
+ chk1d(unsigned cols)
+ {
+ image1d<I> ima (cols);
+ debug::iota (ima);
+ chck(ima);
+ }
+
+ template <typename I>
+ void
+ chk2d(unsigned rows,
+ unsigned cols)
+ {
+ image2d<I> ima (rows, cols);
+ debug::iota (ima);
+ chck(ima);
+ }
+
+ template <typename I>
+ void
+ chk3d(unsigned slis,
+ unsigned rows,
+ unsigned cols)
+ {
+ image3d<I> ima (slis, rows, cols);
+ debug::iota (ima);
+ chck(ima);
+ }
+
+}
+
+
+int main()
+{
+ using namespace mln;
+
+ unsigned slis_start = 1;
+ unsigned slis_end = 3;
+
+ unsigned rows_start = 1;
+ unsigned rows_end = 8;
+
+ unsigned cols_start = 2;
+ unsigned cols_end = 256;
+
+
+ std::cerr << "Tests level::apply" << std::endl;
+
+ (std::cerr << "in 1d ... ").flush ();
+ {
+ for (unsigned i = cols_start; i < cols_end; ++i)
+ {
+ chk1d<int>(i);
+ chk1d<unsigned>(i);
+ chk1d<value::int_u8>(i);
+ chk1d<value::int_u16>(i);
+ chk1d<value::int_s8>(i);
+ chk1d<value::int_s16>(i);
+ }
+ }
+ std::cerr << "OK" << std::endl;
+
+ (std::cerr << "in 2d ... ").flush ();
+ {
+ for (unsigned h = rows_start; h < rows_end; ++h)
+ for (unsigned i = cols_start; i < cols_end; ++i)
+ {
+ chk2d<int>(h, i);
+ chk2d<unsigned>(h, i);
+ chk2d<value::int_u8>(h, i);
+ chk2d<value::int_u16>(h, i);
+ chk2d<value::int_s8>(h, i);
+ chk2d<value::int_s16>(h, i);
+ }
+ }
+ std::cerr << "OK" << std::endl;
+
+
+ (std::cerr << "in 3d ... ").flush ();
+ {
+ for (unsigned g = slis_start; g < slis_end; ++g)
+ for (unsigned h = rows_start; h < rows_end; ++h)
+ for (unsigned i = cols_start; i < cols_end; ++i)
+ {
+ chk3d<int>(g, h, i);
+ chk3d<unsigned>(g, h, i);
+ chk3d<value::int_u8>(g, h, i);
+ chk3d<value::int_u16>(g, h, i);
+ chk3d<value::int_s8>(g, h, i);
+ chk3d<value::int_s16>(g, h, i);
+ }
+ }
+ std::cerr << "OK" << std::endl;
+}
Index: trunk/milena/tests/level/paste_full.cc
===================================================================
--- trunk/milena/tests/level/paste_full.cc (revision 0)
+++ trunk/milena/tests/level/paste_full.cc (revision 1596)
@@ -0,0 +1,280 @@
+// 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/paste_full.cc
+ *
+ * \brief Tests on mln::level::paste.
+ */
+
+
+
+#include <mln/core/image1d.hh>
+#include <mln/core/image2d.hh>
+#include <mln/core/image3d.hh>
+#include <mln/core/sub_image.hh>
+
+#include <mln/core/image_if.hh>
+#include <mln/fun/p2b/chess.hh>
+
+#include <mln/literal/origin.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u16.hh>
+
+#include <mln/value/int_s8.hh>
+#include <mln/value/int_s16.hh>
+
+
+#include <mln/debug/iota.hh>
+
+#include <mln/level/saturate.hh>
+#include <mln/level/paste.hh>
+
+
+
+struct f_box1d_t : mln::Function_p2b< f_box1d_t >
+{
+ f_box1d_t(const mln::box1d& b)
+ : b_(b)
+ {
+ }
+ mln::box1d b_;
+ bool operator()(const mln::point1d& p) const
+ {
+ return b_.has(p);
+ }
+};
+
+struct f_box2d_t : mln::Function_p2b< f_box2d_t >
+{
+ f_box2d_t(const mln::box2d& b)
+ : b_(b)
+ {
+ }
+ mln::box2d b_;
+ bool operator()(const mln::point2d& p) const
+ {
+ return b_.has(p);
+ }
+};
+
+struct f_box3d_t : mln::Function_p2b< f_box3d_t >
+{
+ f_box3d_t(const mln::box3d& b)
+ : b_(b)
+ {
+ }
+ mln::box3d b_;
+ bool operator()(const mln::point3d& p) const
+ {
+ return b_.has(p);
+ }
+};
+
+
+
+namespace mln
+{
+ template <typename I, typename J>
+ void
+ chck(Image<I>& input_, Image<J>& output_)
+ {
+ typedef mln_value(I) T;
+ typedef mln_value(J) V;
+ unsigned max_i = mln_max (T);
+ unsigned max_j = mln_max (V);
+ I& input = exact(input_);
+ J& output = exact(output_);
+
+ if (max_i > max_j)
+ level::saturate_inplace(input, 0, (T)max_j);
+
+ level::paste(input, output);
+
+ mln_piter(I) p (input.domain ());
+ for_all(p)
+ mln_assertion ((V)(input(p)) == output(p));
+ }
+
+ template <typename I, typename J>
+ void
+ chk1d(unsigned cols)
+ {
+ box1d b1(literal::origin, point1d(1));
+ f_box1d_t f_b1(b1);
+
+ {
+ image1d<I> input (cols);
+ debug::iota(input);
+ image1d<J> output (cols);
+ chck(input, output);
+ }
+
+ {
+ image1d<I> in (cols);
+ sub_image<image1d<I>, box1d> input (in, b1);
+ debug::iota(input);
+ image1d<J> output (cols);
+ chck(input, output);
+ }
+
+// {
+// image1d<I> in (cols);
+// image_if<image1d<I>, f_box1d_t> input(in, f_b1);
+// debug::iota(input);
+// image1d<J> output (cols);
+// chck(input, output);
+// }
+ }
+
+ template <typename I, typename J>
+ void
+ chk2d(unsigned rows, unsigned cols)
+ {
+ box2d b2(literal::origin, point2d(1, 1));
+ f_box2d_t f_b2(b2);
+
+ {
+ image2d<I> input (rows, cols);
+ debug::iota(input);
+ image2d<J> output (rows, cols);
+ chck(input, output);
+ }
+
+ {
+ image2d<I> in (rows, cols);
+ sub_image<image2d<I>, box2d> input (in, b2);
+ debug::iota(input);
+ image2d<J> output (rows, cols);
+ chck(input, output);
+ }
+
+// {
+// image2d<I> in (rows, cols);
+// image_if<image2d<I>, f_box2d_t> input(in, f_b2);
+// debug::iota(input);
+// image2d<J> output (rows, cols);
+// chck(input, output);
+// }
+ }
+
+ template <typename I, typename J>
+ void
+ chk3d(unsigned slis, unsigned rows, unsigned cols)
+ {
+ box3d b3(literal::origin, point3d(1, 1, 1));
+ f_box3d_t f_b3(b3);
+
+ {
+ image3d<I> input (slis, rows, cols);
+ debug::iota(input);
+ image3d<J> output (slis, rows, cols);
+ chck(input, output);
+ }
+
+ {
+ image3d<I> in (slis, rows, cols);
+ sub_image<image3d<I>, box3d> input (in, b3);
+ debug::iota(input);
+ image3d<J> output (slis, rows, cols);
+ chck(input, output);
+ }
+
+// {
+// image3d<I> in (slis, rows, cols);
+// image_if<image3d<I>, f_box3d_t> input(in, f_b3);
+// debug::iota(input);
+// image3d<J> output (slis, rows, cols);
+// chck(input, output);
+// }
+ }
+
+
+ template <typename I, typename J>
+ void
+ chk(unsigned slis, unsigned rows, unsigned cols)
+ {
+ (std::cerr << " in 1d ... ").flush ();
+ {
+ for (unsigned i = 2; i < cols; ++i)
+ chk1d<I, J>(i);
+ }
+ std::cerr << "OK" << std::endl;
+
+ (std::cerr << " in 2d ... ").flush ();
+ {
+ for (unsigned j = 2; j < rows; ++j)
+ for (unsigned i = 2; i < cols; ++i)
+ chk2d<I, J>(j, i);
+ }
+ std::cerr << "OK" << std::endl;
+
+ (std::cerr << " in 3d ... ").flush ();
+ {
+ for (unsigned k = 2; k < slis; ++k)
+ for (unsigned j = 2; j < rows; ++j)
+ for (unsigned i = 2; i < cols; ++i)
+ chk3d<I, J>(k, j, i);
+ }
+ std::cerr << "OK" << std::endl;
+ }
+
+ template <typename I>
+ void
+ ch(unsigned slis, unsigned rows, unsigned cols)
+ {
+ std::cerr << " into int:" << std::endl;
+ chk<I, int>(slis, rows, cols);
+ std::cerr << " into unsigned:" << std::endl;
+ chk<I, unsigned>(slis, rows, cols);
+ std::cerr << " into int_u8:" << std::endl;
+ chk<I, value::int_u8>(slis, rows, cols);
+ std::cerr << " into int_u16:" << std::endl;
+ chk<I, value::int_u16>(slis, rows, cols);
+ std::cerr << " into int_s8:" << std::endl;
+ chk<I, value::int_s8>(slis, rows, cols);
+ std::cerr << " into int_s16:" << std::endl;
+ chk<I, value::int_s16>(slis, rows, cols);
+ }
+}
+
+
+int main()
+{
+ using namespace mln;
+
+ unsigned slis = 4;
+ unsigned rows = 4;
+ unsigned cols = 16;
+
+ std::cerr << "Tests level::paste:" << std::endl;
+ std::cerr << "on int:" << std::endl;
+ ch<int>(slis, rows, cols);
+ std::cerr << "on unsigned:" << std::endl;
+ ch<unsigned>(slis, rows, cols);
+}
+
Index: trunk/milena/tests/level/stretch_full.cc
===================================================================
--- trunk/milena/tests/level/stretch_full.cc (revision 0)
+++ trunk/milena/tests/level/stretch_full.cc (revision 1596)
@@ -0,0 +1,174 @@
+// 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/stretch_full.cc
+ *
+ * \brief Tests on mln::level::stretch.
+ */
+
+
+#include <mln/core/image1d.hh>
+#include <mln/core/image2d.hh>
+#include <mln/core/image3d.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u16.hh>
+
+#include <mln/value/int_s8.hh>
+#include <mln/value/int_s16.hh>
+
+
+#include <mln/debug/iota.hh>
+
+#include <mln/level/saturate.hh>
+#include <mln/level/stretch.hh>
+
+
+
+namespace mln
+{
+ template <typename I, typename J>
+ void
+ chck(Image<I>& input_, Image<J>& output_)
+ {
+ typedef mln_value(I) T;
+ typedef mln_value(J) V;
+ unsigned max_i = mln_max (T);
+ unsigned max_j = mln_max (V);
+ I& input = exact(input_);
+ J& output = exact(output_);
+
+ level::stretch(input, output);
+
+ // FIXME : How test that?
+ }
+
+ template <typename I, typename J>
+ void
+ chk1d(unsigned cols)
+ {
+ {
+ image1d<I> input (cols);
+ debug::iota(input);
+ image1d<J> output (cols);
+ chck(input, output);
+ }
+
+ }
+
+ template <typename I, typename J>
+ void
+ chk2d(unsigned rows, unsigned cols)
+ {
+
+ {
+ image2d<I> input (rows, cols);
+ debug::iota(input);
+ image2d<J> output (rows, cols);
+ chck(input, output);
+ }
+
+ }
+
+ template <typename I, typename J>
+ void
+ chk3d(unsigned slis, unsigned rows, unsigned cols)
+ {
+
+ {
+ image3d<I> input (slis, rows, cols);
+ debug::iota(input);
+ image3d<J> output (slis, rows, cols);
+ chck(input, output);
+ }
+
+ }
+
+
+ template <typename I, typename J>
+ void
+ chk(unsigned slis, unsigned rows, unsigned cols)
+ {
+ (std::cerr << " in 1d ... ").flush ();
+ {
+ for (unsigned i = 2; i < cols; ++i)
+ chk1d<I, J>(i);
+ }
+ std::cerr << "OK" << std::endl;
+
+ (std::cerr << " in 2d ... ").flush ();
+ {
+ for (unsigned j = 2; j < rows; ++j)
+ for (unsigned i = 2; i < cols; ++i)
+ chk2d<I, J>(j, i);
+ }
+ std::cerr << "OK" << std::endl;
+
+ (std::cerr << " in 3d ... ").flush ();
+ {
+ for (unsigned k = 2; k < slis; ++k)
+ for (unsigned j = 2; j < rows; ++j)
+ for (unsigned i = 2; i < cols; ++i)
+ chk3d<I, J>(k, j, i);
+ }
+ std::cerr << "OK" << std::endl;
+ }
+
+ template <typename I>
+ void
+ ch(unsigned slis, unsigned rows, unsigned cols)
+ {
+ std::cerr << " into int_u8:" << std::endl;
+ chk<I, value::int_u8>(slis, rows, cols);
+ std::cerr << " into int_u16:" << std::endl;
+ chk<I, value::int_u16>(slis, rows, cols);
+ }
+}
+
+
+int main()
+{
+ using namespace mln;
+
+ unsigned slis = 4;
+ unsigned rows = 4;
+ unsigned cols = 16;
+
+ std::cerr << "Tests level::stretch:" << std::endl;
+ std::cerr << "on int:" << std::endl;
+ ch<int>(slis, rows, cols);
+ std::cerr << "on unsigned:" << std::endl;
+ ch<unsigned>(slis, rows, cols);
+ std::cerr << "on int_u8:" << std::endl;
+ ch<value::int_u8>(slis, rows, cols);
+ std::cerr << "on int_u16:" << std::endl;
+ ch<value::int_u16>(slis, rows, cols);
+ std::cerr << "on int_s8:" << std::endl;
+ ch<value::int_s8>(slis, rows, cols);
+ std::cerr << "on int_s16:" << std::endl;
+ ch<value::int_s16>(slis, rows, cols);
+}
Index: trunk/milena/tests/level/sort_points_full.cc
===================================================================
--- trunk/milena/tests/level/sort_points_full.cc (revision 0)
+++ trunk/milena/tests/level/sort_points_full.cc (revision 1596)
@@ -0,0 +1,318 @@
+// 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/sort_points.cc
+ *
+ * \brief Tests on mln::level::sort_points.
+ */
+
+#include <mln/core/image1d.hh>
+#include <mln/core/image2d.hh>
+#include <mln/core/image3d.hh>
+#include <mln/core/sub_image.hh>
+
+#include <mln/core/image_if.hh>
+#include <mln/fun/p2b/chess.hh>
+
+#include <mln/literal/origin.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u16.hh>
+
+#include <mln/value/int_s8.hh>
+#include <mln/value/int_s16.hh>
+
+#include <mln/core/p_array.hh>
+#include <mln/debug/iota.hh>
+
+#include <mln/level/saturate.hh>
+#include <mln/level/paste.hh>
+#include <mln/level/sort_points.hh>
+
+
+
+struct f_box1d_t : mln::Function_p2b< f_box1d_t >
+{
+ f_box1d_t(const mln::box1d& b)
+ : b_(b)
+ {
+ }
+ mln::box1d b_;
+ bool operator()(const mln::point1d& p) const
+ {
+ return b_.has(p);
+ }
+};
+
+struct f_box2d_t : mln::Function_p2b< f_box2d_t >
+{
+ f_box2d_t(const mln::box2d& b)
+ : b_(b)
+ {
+ }
+ mln::box2d b_;
+ bool operator()(const mln::point2d& p) const
+ {
+ return b_.has(p);
+ }
+};
+
+struct f_box3d_t : mln::Function_p2b< f_box3d_t >
+{
+ f_box3d_t(const mln::box3d& b)
+ : b_(b)
+ {
+ }
+ mln::box3d b_;
+ bool operator()(const mln::point3d& p) const
+ {
+ return b_.has(p);
+ }
+};
+
+
+
+namespace mln
+{
+ template <typename I, typename J>
+ void
+ chck(Image<I>& input_, p_array<J>& array_inc_ref, p_array<J>& array_dec_ref)
+ {
+ I& input = exact(input_);
+
+ p_array<J> array_inc = level::sort_points_increasing(input);
+ p_array<J> array_dec = level::sort_points_decreasing(input);
+
+ mln_assertion(array_inc == array_inc_ref);
+ mln_assertion(array_dec == array_dec_ref);
+ }
+
+ template <typename I>
+ void
+ chk1d(int cols)
+ {
+ box1d b1(literal::origin, point1d(1));
+ f_box1d_t f_b1(b1);
+
+ {
+ image1d<I> input (cols);
+ debug::iota(input);
+
+ p_array<point1d> array_inc_ref;
+ p_array<point1d> array_dec_ref;
+
+ for (int i = 0; i < cols; ++i)
+ array_inc_ref.append(point1d(i));
+
+ for (int i = cols - 1; i >= 0; --i)
+ array_dec_ref.append(point1d(i));
+
+ chck(input, array_inc_ref, array_dec_ref);
+ }
+
+ p_array<point1d> array_inc_ref;
+ p_array<point1d> array_dec_ref;
+
+ for (int i = 0; i < 2; ++i)
+ array_inc_ref.append(point1d(i));
+
+ for (int i = 1; i >= 0; --i)
+ array_dec_ref.append(point1d(i));
+
+ {
+ image1d<I> in (cols);
+ sub_image<image1d<I>, box1d> input (in, b1);
+ debug::iota(input);
+ chck(input, array_inc_ref, array_dec_ref);
+ }
+
+ {
+ image1d<I> in (cols);
+ image_if<image1d<I>, f_box1d_t> input(in, f_b1);
+ debug::iota(input);
+ chck(input, array_inc_ref, array_dec_ref);
+ }
+ }
+
+ template <typename I>
+ void
+ chk2d(int rows, int cols)
+ {
+ box2d b2(literal::origin, point2d(1, 1));
+ f_box2d_t f_b2(b2);
+
+ {
+ image2d<I> input (rows, cols);
+ debug::iota(input);
+
+ p_array<point2d> array_inc_ref;
+ p_array<point2d> array_dec_ref;
+
+ for (int j = 0; j < rows; ++j)
+ for (int i = 0; i < cols; ++i)
+ array_inc_ref.append(point2d(j, i));
+
+ for (int j = rows - 1; j >= 0; --j)
+ for (int i = cols - 1; i >= 0; --i)
+ array_dec_ref.append(point2d(j, i));
+
+ chck(input, array_inc_ref, array_dec_ref);
+ }
+
+ p_array<point2d> array_inc_ref;
+ p_array<point2d> array_dec_ref;
+
+ for (int j = 0; j < 2; ++j)
+ for (int i = 0; i < 2; ++i)
+ array_inc_ref.append(point2d(j, i));
+
+ for (int j = 1; j >= 0; --j)
+ for (int i = 1; i >= 0; --i)
+ array_dec_ref.append(point2d(j, i));
+
+ {
+ image2d<I> in (rows, cols);
+ sub_image<image2d<I>, box2d> input (in, b2);
+ debug::iota(input);
+ chck(input, array_inc_ref, array_dec_ref);
+ }
+
+ {
+ image2d<I> in (rows, cols);
+ image_if<image2d<I>, f_box2d_t> input(in, f_b2);
+ debug::iota(input);
+ chck(input, array_inc_ref, array_dec_ref);
+ }
+ }
+
+ template <typename I>
+ void
+ chk3d(int slis, int rows, int cols)
+ {
+ box3d b3(literal::origin, point3d(1, 1, 1));
+ f_box3d_t f_b3(b3);
+
+ {
+ image3d<I> input (slis, rows, cols);
+ debug::iota(input);
+
+ p_array<point3d> array_inc_ref;
+ p_array<point3d> array_dec_ref;
+
+ for (int k = 0; k < slis; ++k)
+ for (int j = 0; j < rows; ++j)
+ for (int i = 0; i < cols; ++i)
+ array_inc_ref.append(point3d(k, j, i));
+
+ for (int k = slis - 1; k >= 0; --k)
+ for (int j = rows - 1; j >= 0; --j)
+ for (int i = cols - 1; i >= 0; --i)
+ array_dec_ref.append(point3d(k, j, i));
+
+ chck(input, array_inc_ref, array_dec_ref);
+ }
+
+ p_array<point3d> array_inc_ref;
+ p_array<point3d> array_dec_ref;
+
+ for (int k = 0; k < 2; ++k)
+ for (int j = 0; j < 2; ++j)
+ for (int i = 0; i < 2; ++i)
+ array_inc_ref.append(point3d(k, j, i));
+
+ for (int k = 1; k >= 0; --k)
+ for (int j = 1; j >= 0; --j)
+ for (int i = 1; i >= 0; --i)
+ array_dec_ref.append(point3d(k, j, i));
+
+ {
+ image3d<I> in (slis, rows, cols);
+ sub_image<image3d<I>, box3d> input (in, b3);
+ debug::iota(input);
+ chck(input, array_inc_ref, array_dec_ref);
+ }
+
+ {
+ image3d<I> in (slis, rows, cols);
+ image_if<image3d<I>, f_box3d_t> input(in, f_b3);
+ debug::iota(input);
+ chck(input, array_inc_ref, array_dec_ref);
+ }
+
+ }
+
+
+ template <typename I>
+ void
+ chk(int slis, int rows, int cols)
+ {
+ (std::cerr << " in 1d ... ").flush ();
+ {
+ for (int i = 2; i < cols; ++i)
+ chk1d<I>(i);
+ }
+ std::cerr << "OK" << std::endl;
+
+ (std::cerr << " in 2d ... ").flush ();
+ {
+ for (int j = 2; j < rows; ++j)
+ for (int i = 2; i < cols; ++i)
+ chk2d<I>(j, i);
+ }
+ std::cerr << "OK" << std::endl;
+
+ (std::cerr << " in 3d ... ").flush ();
+ {
+ for (int k = 2; k < slis; ++k)
+ for (int j = 2; j < rows; ++j)
+ for (int i = 2; i < cols; ++i)
+ chk3d<I>(k, j, i);
+ }
+ std::cerr << "OK" << std::endl;
+ }
+
+}
+
+
+int main()
+{
+ using namespace mln;
+
+ int slis = 8;
+ int rows = 8;
+ int cols = 8;
+
+ std::cerr << "Tests level::sort_points:" << std::endl;
+ std::cerr << "in int:" << std::endl;
+ chk<int>(slis, rows, cols);
+ std::cerr << "in unsigned:" << std::endl;
+ chk<unsigned>(slis, rows, cols);
+ std::cerr << "in int_u16:" << std::endl;
+ chk<value::int_u16>(slis, rows, cols);
+ std::cerr << "in int_s16:" << std::endl;
+ chk<value::int_s16>(slis, rows, cols);
+}
Index: trunk/milena/tests/level/saturate_full.cc
===================================================================
--- trunk/milena/tests/level/saturate_full.cc (revision 0)
+++ trunk/milena/tests/level/saturate_full.cc (revision 1596)
@@ -0,0 +1,241 @@
+// 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/saturate_full.cc
+ *
+ * \brief Tests on mln::level::saturate.
+ */
+
+
+#include <mln/core/image1d.hh>
+#include <mln/core/image2d.hh>
+#include <mln/core/image3d.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u16.hh>
+#include <mln/value/int_s8.hh>
+#include <mln/value/int_s16.hh>
+
+
+#include <mln/core/clone.hh>
+#include <mln/level/saturate.hh>
+#include <mln/debug/iota.hh>
+
+#include <mln/debug/println.hh>
+
+
+namespace mln
+{
+ template <typename I, typename J>
+ void
+ chck(I& ref, J& out, mln_value(I) min, mln_value(I) max)
+ {
+ mln_value(J) min2 = min;
+ mln_value(J) max2 = max;
+
+ mln_piter(I) p (ref.domain ());
+
+ {
+ level::saturate(ref, min, max, out);
+
+ for_all(p)
+ {
+ if (ref(p) <= min)
+ {
+ mln_assertion(out(p) == min2);
+ continue;
+ }
+ if (ref(p) >= max)
+ {
+ mln_assertion(out(p) == max2);
+ continue;
+ }
+ mln_assertion(ref(p) == (mln_value(I)) out(p));
+ }
+ }
+
+ {
+ level::saturate_inplace(ref, min, max);
+
+ for_all(p)
+ {
+ mln_assertion(ref(p) == (mln_value(I)) out(p));
+ }
+ }
+ }
+
+ template <typename I, typename J>
+ void
+ chk1d(unsigned cols,
+ int min,
+ int max)
+ {
+ image1d<I> ima (cols);
+ image1d<J> out (cols);
+ debug::iota (ima);
+ chck(ima, out, min, max);
+ }
+
+ template <typename I, typename J>
+ void
+ chk2d(unsigned rows,
+ unsigned cols,
+ int min,
+ int max)
+ {
+ image2d<I> ima (rows, cols);
+ image2d<J> out (rows, cols);
+ debug::iota (ima);
+ chck(ima, out, min, max);
+ }
+
+ template <typename I, typename J>
+ void
+ chk3d(unsigned slis,
+ unsigned rows,
+ unsigned cols,
+ int min,
+ int max)
+ {
+ image3d<I> ima (slis, rows, cols);
+ image3d<J> out (slis, rows, cols);
+ debug::iota (ima);
+ chck(ima, out, min, max);
+ }
+
+}
+
+
+int main()
+{
+ using namespace mln;
+
+ unsigned slis_start = 1;
+ unsigned slis_end = 3;
+
+ unsigned rows_start = 1;
+ unsigned rows_end = 5;
+
+ unsigned cols_start = 2;
+ unsigned cols_end = 6;
+
+
+ std::cerr << "Tests level::saturate" << std::endl;
+
+ (std::cerr << "in 1d ... ").flush ();
+ {
+ for (unsigned i = cols_start; i < cols_end; ++i)
+ for (unsigned j = 1; j < i; ++j)
+ for (unsigned k = j + 1; k <= i; ++k)
+ {
+ chk1d<int, int>(i, j, k);
+ chk1d<unsigned, unsigned>(i, j, k);
+ chk1d<int, unsigned>(i, j, k);
+ chk1d<unsigned, int>(i, j, k);
+
+ chk1d<value::int_u8, value::int_u8>(i, j, k);
+ chk1d<value::int_u16, value::int_u16>(i, j, k);
+ chk1d<value::int_s8, value::int_s8>(i, j, k);
+ chk1d<value::int_s16, value::int_s16>(i, j, k);
+
+ chk1d<unsigned, value::int_u8>(i, j, k);
+ chk1d<unsigned, value::int_u16>(i, j, k);
+ chk1d<int, value::int_s8>(i, j, k);
+ chk1d<int, value::int_s16>(i, j, k);
+
+ chk1d<value::int_u8, unsigned>(i, j, k);
+ chk1d<value::int_u16, unsigned>(i, j, k);
+ chk1d<value::int_s8, int>(i, j, k);
+ chk1d<value::int_s16, int>(i, j, k);
+ }
+ }
+ std::cerr << "OK" << std::endl;
+
+ (std::cerr << "in 2d ... ").flush ();
+ {
+ for (unsigned h = rows_start; h < rows_end; ++h)
+ for (unsigned i = cols_start; i < cols_end; ++i)
+ for (unsigned j = 1; j < i; ++j)
+ for (unsigned k = j + 1; k <= i; ++k)
+ {
+ chk2d<int, int>(h, i, j, k);
+ chk2d<unsigned, unsigned>(h, i, j, k);
+ chk2d<int, unsigned>(h, i, j, k);
+ chk2d<unsigned, int>(h, i, j, k);
+
+ chk2d<value::int_u8, value::int_u8>(h, i, j, k);
+ chk2d<value::int_u16, value::int_u16>(h, i, j, k);
+ chk2d<value::int_s8, value::int_s8>(h, i, j, k);
+ chk2d<value::int_s16, value::int_s16>(h, i, j, k);
+
+ chk2d<unsigned, value::int_u8>(h, i, j, k);
+ chk2d<unsigned, value::int_u16>(h, i, j, k);
+ chk2d<int, value::int_s8>(h, i, j, k);
+ chk2d<int, value::int_s16>(h, i, j, k);
+
+ chk2d<value::int_u8, unsigned>(h, i, j, k);
+ chk2d<value::int_u16, unsigned>(h, i, j, k);
+ chk2d<value::int_s8, int>(h, i, j, k);
+ chk2d<value::int_s16, int>(h, i, j, k);
+ }
+ }
+ std::cerr << "OK" << std::endl;
+
+
+ (std::cerr << "in 3d ... ").flush ();
+ {
+ for (unsigned g = slis_start; g < slis_end; ++g)
+ for (unsigned h = rows_start; h < rows_end; ++h)
+ for (unsigned i = cols_start; i < cols_end; ++i)
+ for (unsigned j = 1; j < i; ++j)
+ for (unsigned k = j + 1; k <= i; ++k)
+ {
+ chk3d<int, int>(g, h, i, j, k);
+ chk3d<unsigned, unsigned>(g, h, i, j, k);
+ chk3d<int, unsigned>(g, h, i, j, k);
+ chk3d<unsigned, int>(g, h, i, j, k);
+
+ chk3d<value::int_u8, value::int_u8>(g, h, i, j, k);
+ chk3d<value::int_u16, value::int_u16>(g, h, i, j, k);
+ chk3d<value::int_s8, value::int_s8>(g, h, i, j, k);
+ chk3d<value::int_s16, value::int_s16>(g, h, i, j, k);
+
+ chk3d<unsigned, value::int_u8>(g, h, i, j, k);
+ chk3d<unsigned, value::int_u16>(g, h, i, j, k);
+ chk3d<int, value::int_s8>(g, h, i, j, k);
+ chk3d<int, value::int_s16>(g, h, i, j, k);
+
+ chk3d<value::int_u8, unsigned>(g, h, i, j, k);
+ chk3d<value::int_u16, unsigned>(g, h, i, j, k);
+ chk3d<value::int_s8, int>(g, h, i, j, k);
+ chk3d<value::int_s16, int>(g, h, i, j, k);
+ }
+ }
+ std::cerr << "OK" << std::endl;
+
+
+}
Index: trunk/milena/mln/level/paste.spe.hh
===================================================================
--- trunk/milena/mln/level/paste.spe.hh (revision 1595)
+++ trunk/milena/mln/level/paste.spe.hh (revision 1596)
@@ -65,6 +65,7 @@
// FIXME: For linear data images, we should get the len for each line...
typename I::line_piter p(data.domain()); // FIXME: Alias mln_line_piter!
+ // mln_line_piter(I) p(data.domain());
for_all(p)
memcpy_(inplace(make::pixel(destination, p)),
make::pixel(data, p),
Index: trunk/milena/mln/fun/v2v/saturate.hh
===================================================================
--- trunk/milena/mln/fun/v2v/saturate.hh (revision 1595)
+++ trunk/milena/mln/fun/v2v/saturate.hh (revision 1596)
@@ -62,6 +62,7 @@
protected:
V min_, max_;
+ bool needs_update_;
};
@@ -73,6 +74,7 @@
: min_(mln_min(V)),
max_(mln_max(V))
{
+ needs_update_ = true;
}
template <typename V>
@@ -82,6 +84,7 @@
max_(max)
{
mln_precondition(max > min);
+ needs_update_ = true;
}
template <typename V>
@@ -92,8 +95,15 @@
{
// FIXME: Check that W is a larger type than V; otherwise
// alt code.
- static const W min_W = mln::value::cast<W>(min_);
- static const W max_W = mln::value::cast<W>(max_);
+
+ static W min_W, max_W;
+ if (needs_update_)
+ {
+ min_W = mln::value::cast<W>(min_);
+ max_W = mln::value::cast<W>(max_);
+ // FIXME
+// needs_update_ = false;
+ }
// FIXME: Below we need something more powerful that mlc_converts_to
// for instance, with W=int_s<10u> and V=int_u<8u>, it does not
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-12-06 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add sparse image and test.
* mln/core/sparse_encode.hh: Rewrite.
* mln/core/sparse_image.hh: Rewrite.
* tests/core/Makefile.am: Add test.
* tests/core/sparse_image.cc: New.
---
mln/core/sparse_encode.hh | 81 ++++++++++++++++++++++++++-----------------
mln/core/sparse_image.hh | 83 +++++++++++++++++++++++++++++++++------------
tests/core/Makefile.am | 2 +
tests/core/sparse_image.cc | 76 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 189 insertions(+), 53 deletions(-)
Index: trunk/milena/tests/core/sparse_image.cc
===================================================================
--- trunk/milena/tests/core/sparse_image.cc (revision 0)
+++ trunk/milena/tests/core/sparse_image.cc (revision 1595)
@@ -0,0 +1,76 @@
+// 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/core/sparse_image.cc
+ *
+ * \brief Test on mln::sparse_image.hh.
+ */
+
+#include <mln/core/image2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/io/pgm/load.hh>
+#include <mln/pw/all.hh>
+#include <mln/core/neighb2d.hh>
+
+#include <mln/labeling/blobs.hh>
+#include <mln/level/transform.hh>
+#include <mln/level/paste.hh>
+#include <mln/level/compare.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <mln/core/sparse_encode.hh>
+
+struct fold_t : public mln::Function_v2v< fold_t >
+{
+ typedef mln::value::int_u8 result;
+ result operator()(unsigned i) const { return i == 0 ? 0 : (i - 1) % 255 + 1; }
+};
+
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d<int_u8> lena;
+ io::pgm::load(lena, "../../img/tiny.pgm");
+ image2d<int_u8> cmp(lena.domain());
+
+ unsigned n;
+ image2d<unsigned> labels = labeling::blobs((pw::value(lena) > pw::cst(172u)) | lena.domain(),
+ c4(), n);
+
+ sparse_image<point2d, int_u8> sparse = sparse_encode(level::transform(labels, fold_t()));
+
+ std::cout << n << ", compression :" << sparse.compression() << std::endl;
+
+ level::fill(cmp, literal::zero);
+ level::paste(sparse, cmp);
+
+ mln_assertion(cmp == level::transform(labels, fold_t()));
+}
Index: trunk/milena/tests/core/Makefile.am
===================================================================
--- trunk/milena/tests/core/Makefile.am (revision 1594)
+++ trunk/milena/tests/core/Makefile.am (revision 1595)
@@ -12,6 +12,7 @@
obased_rle_image \
p_runs \
rle_image \
+ sparse_image \
t_image
category_SOURCES = category.cc
@@ -23,6 +24,7 @@
obased_rle_image_SOURCES = obased_rle_image.cc
p_runs_SOURCES = p_runs.cc
rle_image_SOURCES = rle_image.cc
+sparse_image_SOURCES = sparse_image.cc
t_image_SOURCES = t_image.cc
TESTS = $(check_PROGRAMS)
Index: trunk/milena/mln/core/sparse_encode.hh
===================================================================
--- trunk/milena/mln/core/sparse_encode.hh (revision 1594)
+++ trunk/milena/mln/core/sparse_encode.hh (revision 1595)
@@ -30,71 +30,88 @@
/*! \file mln/core/sparse_encode.hh
*
- * \brief FIXME.
+ * \brief Definintion of function which encodes an image in sparse_image.
*/
# include <mln/core/sparse_image.hh>
-# include <vector>
namespace mln
{
/*!
- ** encode a generic image to a sparse image format
+ ** encode an image class to a sparse_image
**
- ** @param input an Image
+ ** @param input has to respect the Image concept
**
- ** @return a sparse image
+ ** @return sparse_image
*/
template <typename I>
sparse_image<mln_point(I), mln_value(I)>
- sparse_encode(const Image<I>& input);
+ sparse_encode(const Image<I>& input, bool ignore_zero = true);
# ifndef MLN_INCLUDE_ONLY
+ /*!
+ ** test if Point p1 and p2 are on the same line
+ */
+ template <typename P>
+ inline
+ bool
+ on_the_same_line(const P& p1, const P& p2, int len)
+ {
+ const unsigned dim = P::dim;
+ bool same_line = true;
+
+ for (unsigned n = 0; same_line && n < dim - 1; ++n)
+ same_line = (p1[n] == p2[n]);
+ return same_line && p1[dim - 1] + len == p2[dim - 1];
+ }
template <typename I>
inline
sparse_image<mln_point(I), mln_value(I)>
- sparse_encode(const Image<I>& input)
+ sparse_encode(const Image<I>& input, bool ignore_zero)
{
+ typedef mln_point(I) P;
+
sparse_image<mln_point(I), mln_value(I)> output;
+ const I& ima = exact(input);
mln_piter(I) p(exact(input).domain());
- unsigned len = 1;
- // old point first dim coordinate
- typename I::coord old = 1;
- // range pointstart
+ unsigned len = 0;
mln_point(I) rstart;
- // range value
- std::vector<mln_value(I)> values;
-
- p.start();
- if (not p.is_valid())
- return output;
+ std::vector< mln_value(I) > rvalue;
+ rvalue.clear();
- rstart = p;
-
- old = p[0];
- values.push_back(exact(input)(p));
- p.next_();
- while (p.is_valid())
+ for_all(p)
+ if (!ignore_zero || ima(p) != literal::zero || len)
{
- if (p[0] - 1 == old)
+ if (len == 0)
{
++len;
- values.push_back(exact(input)(p));
+ rstart = p;
+ std::cout << "New run " << p << ": *";
+ rvalue.push_back(ima(p));
}
else
+ if ((!ignore_zero || ima(p) != literal::zero) &&
+ on_the_same_line(rstart, mln_point(I)(p), len))
+ {
+ std::cout << "*";
+ ++len;
+ rvalue.push_back(ima(p));
+ }
+ else
+ {
+ std::cout << std::endl;
+ output.insert(p_run<P>(rstart, len), rvalue);
+ rvalue.clear();
+ if ((len = (!ignore_zero || ima(p) != literal::zero)))
{
- output.insert(rstart, len, values);
rstart = p;
- len = 1;
- values.clear();
- values.push_back(exact(input)(p));
+ std::cout << "New run " << p << ": ";
+ rvalue.push_back(ima(p));
+ }
}
- old = p[0];
- p.next_();
}
- output.insert(rstart, len, values);
return output;
}
Index: trunk/milena/mln/core/sparse_image.hh
===================================================================
--- trunk/milena/mln/core/sparse_image.hh (revision 1594)
+++ trunk/milena/mln/core/sparse_image.hh (revision 1595)
@@ -30,12 +30,12 @@
/*! \file mln/core/sparse_image.hh
*
- * \brief Definition of mln::sparse_image
+ * \brief Definition of an image with sparse encoding.
*/
# include <mln/core/internal/run_image.hh>
-# include <mln/core/internal/run_pset.hh>
-# include <mln/core/internal/run_psite.hh>
+# include <mln/core/p_runs.hh>
+# include <mln/core/runs_psite.hh>
# include <mln/value/set.hh>
# include <vector>
@@ -45,6 +45,7 @@
// Fwd decl.
template <typename P, typename T> struct sparse_image;
+
namespace internal
{
@@ -55,13 +56,41 @@
/// Image values.
std::vector< std::vector<T> > values_;
+
/// domain of the image
- run_pset_<P> domain_;
+ p_runs_<P> domain_;
+
+ /// Return the size of the data in memory.
+ unsigned size_mem() const;
};
} // end of namespace mln::internal
- /*! \brief Sparse image.
+
+ namespace trait
+ {
+
+ template <typename P, typename T>
+ struct image_< sparse_image<P,T> > : default_image_< T, sparse_image<P,T> >
+ {
+ typedef trait::image::category::primary category;
+
+ typedef trait::image::access::browsing access;
+ // FIXME: Put the right dimension.
+ typedef trait::image::space::two_d space;
+ typedef trait::image::size::regular size;
+ typedef trait::image::support::aligned support;
+
+ typedef trait::image::border::none border;
+ typedef trait::image::data::linear data;
+ typedef trait::image::io::read_only io;
+ typedef trait::image::speed::slow speed;
+ };
+
+ } // end of namespace mln::trait
+
+
+ /*! \brief SPARSE image.
*
*
* Parameter \c P is the type of the image points.
@@ -69,15 +98,16 @@
* This image is not point wise accessible.
*/
template <typename P, typename T>
- class sparse_image : public internal::run_image_< P, sparse_image<P, T> >
+ class sparse_image : public internal::run_image_< T, P, sparse_image<P, T> >
{
public:
typedef T value;
typedef T& lvalue;
typedef const T rvalue;
- typedef internal::run_psite<P> psite;
+ typedef runs_psite<P> psite;
typedef mln::value::set<T> vset;
- typedef internal::run_pset_<P> pset;
+ typedef p_runs_<P> pset;
+
/// Skeleton.
typedef sparse_image< tag::psite_<P>, tag::value_<T> > skeleton;
@@ -86,13 +116,13 @@
sparse_image();
/// Add a new range to the image.
- void insert(const P& p, unsigned len, const std::vector<T>& value);
+ void insert(const p_run<P>& pr, const std::vector<T>& value);
/// Read-only access to the image value located at point \p p.
- rvalue operator() (const psite& p) const;
+ rvalue operator() (const psite& site) const;
/// Read-write access to the image value located at point \p p.
- lvalue operator() (const psite& p);
+ lvalue operator() (const psite& site);
/// Test if this image has been initialized.
bool has_data() const;
@@ -102,8 +132,10 @@
/// Give the definition domain.
const pset& domain() const;
+
};
+
# ifndef MLN_INCLUDE_ONLY
namespace internal
@@ -117,12 +149,21 @@
{
}
+ template <typename P, typename T>
+ inline
+ unsigned
+ data_< sparse_image<P,T> >::size_mem() const
+ {
+ return sizeof(T) * domain_.npoints() + domain_.size_mem();
+ }
+
} // end of namespace mln::internal
template <typename P, typename T>
inline
sparse_image<P, T>::sparse_image()
{
+ this->data_ = new internal::data_< sparse_image<P,T> >();
}
template <typename P, typename T>
@@ -144,32 +185,32 @@
template <typename P, typename T>
inline
void
- sparse_image<P, T>::insert(const P& p, unsigned len,
- const std::vector<T>& value)
+ sparse_image<P, T>::insert(const p_run<P>& pr, const std::vector<T>& value)
{
if (!this->has_data())
this->data_ = new internal::data_< sparse_image<P,T> >();
- this->data_->domain_.insert(p, len);
+ mln_assertion(this->data_->values_.size() == 0 ||
+ pr.first() > this->data_->domain_[this->data_->domain_.nruns() - 1].first());
+ this->data_->domain_.insert(pr);
this->data_->values_.push_back(value);
}
template <typename P, typename T>
inline
typename sparse_image<P, T>::rvalue
- sparse_image<P, T>::operator()
- (const typename sparse_image<P, T>::psite& site) const
+ sparse_image<P, T>::operator() (const typename sparse_image<P, T>::psite& site)
+ const
{
- mln_precondition(this->has_data() &&
- site.pset_pos_() < this->data_->values_.size() &&
- site.index_() < this->data_->values_[site.pset_pos_()].size());
+ mln_precondition(this->has_data());
+ mln_precondition(site.pset_pos_() < this->data_->values_.size());
+ mln_precondition(site.index_() < this->data_->values_[site.pset_pos_()].size());
return this->data_->values_[site.pset_pos_()][site.index_()];
}
template <typename P, typename T>
inline
typename sparse_image<P, T>::lvalue
- sparse_image<P, T>::operator()
- (const typename sparse_image<P,T>::psite& site)
+ sparse_image<P, T>::operator() (const typename sparse_image<P, T>::psite& site)
{
mln_precondition(this->has_data() &&
site.pset_pos_() < this->data_->values_.size() &&
1
0
05 Dec '07
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-12-05 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add mono object based rle image and add test.
* mln/core/mono_obased_rle_encode.hh: New.
* mln/core/mono_obased_rle_image.hh: New.
* mln/core/mono_rle_encode.hh: Fix.
* mln/core/mono_rle_image.hh: Add get_value() method.
* mln/core/obased_rle_image.hh: Add vector of value for easier
acces to the image.
* tests/core/Makefile.am: Add test.
* tests/core/mono_obased_rle_image.cc: New.
---
mln/core/mono_obased_rle_encode.hh | 120 ++++++++++++++++
mln/core/mono_obased_rle_image.hh | 255 ++++++++++++++++++++++++++++++++++++
mln/core/mono_rle_encode.hh | 5
mln/core/mono_rle_image.hh | 19 ++
mln/core/obased_rle_image.hh | 36 +----
tests/core/Makefile.am | 2
tests/core/mono_obased_rle_image.cc | 78 +++++++++++
7 files changed, 483 insertions(+), 32 deletions(-)
Index: trunk/milena/tests/core/Makefile.am
===================================================================
--- trunk/milena/tests/core/Makefile.am (revision 1593)
+++ trunk/milena/tests/core/Makefile.am (revision 1594)
@@ -7,6 +7,7 @@
clone \
exact \
initialize \
+ mono_obased_rle_image \
mono_rle_image \
obased_rle_image \
p_runs \
@@ -17,6 +18,7 @@
clone_SOURCES = clone.cc
exact_SOURCES = exact.cc
initialize_SOURCES = initialize.cc
+mono_obased_rle_image_SOURCES = mono_obased_rle_image.cc
mono_rle_image_SOURCES = mono_rle_image.cc
obased_rle_image_SOURCES = obased_rle_image.cc
p_runs_SOURCES = p_runs.cc
Index: trunk/milena/tests/core/mono_obased_rle_image.cc
===================================================================
--- trunk/milena/tests/core/mono_obased_rle_image.cc (revision 0)
+++ trunk/milena/tests/core/mono_obased_rle_image.cc (revision 1594)
@@ -0,0 +1,78 @@
+// 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/core/mono_obased_rle_image.cc
+ *
+ * \brief Test on mln::mono_obased_rle_image.hh.
+ */
+
+#include <mln/core/image2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/io/pgm/load.hh>
+#include <mln/pw/all.hh>
+#include <mln/core/neighb2d.hh>
+
+#include <mln/labeling/blobs.hh>
+#include <mln/level/transform.hh>
+#include <mln/level/paste.hh>
+#include <mln/level/compare.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <mln/core/mono_obased_rle_encode.hh>
+
+struct fold_t : public mln::Function_v2v< fold_t >
+{
+ typedef mln::value::int_u8 result;
+ result operator()(unsigned i) const { return i == 0 ? 0 : (i - 1) % 255 + 1; }
+};
+
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d<int_u8> lena;
+ io::pgm::load(lena, "../../img/tiny.pgm");
+ image2d<int_u8> cmp(lena.domain());
+
+ unsigned n;
+ image2d<unsigned>
+ labels = labeling::blobs((pw::value(lena) > pw::cst(172u)) | lena.domain(),
+ c4(), n);
+
+ mono_obased_rle_image<point2d, int_u8>
+ rle = mono_obased_rle_encode(level::transform(labels, fold_t()));
+
+ std::cout << n << ", compression :" << rle.compression() << std::endl;
+
+ level::fill(cmp, literal::zero);
+ level::paste(rle, cmp);
+
+ mln_assertion(cmp == level::transform(labels, fold_t()));
+}
Index: trunk/milena/mln/core/mono_rle_encode.hh
===================================================================
--- trunk/milena/mln/core/mono_rle_encode.hh (revision 1593)
+++ trunk/milena/mln/core/mono_rle_encode.hh (revision 1594)
@@ -94,11 +94,8 @@
else
{
output.insert(p_run<P>(rstart, len));
- if ((len = (!ignore_zero || ima(p) != literal::zero)))
- {
+ if ((len = (ima(p) == val)))
rstart = p;
- rvalue = ima(p);
- }
}
}
return output;
Index: trunk/milena/mln/core/mono_rle_image.hh
===================================================================
--- trunk/milena/mln/core/mono_rle_image.hh (revision 1593)
+++ trunk/milena/mln/core/mono_rle_image.hh (revision 1594)
@@ -55,7 +55,7 @@
data_(const T& val);
/// Image value.
- T value;
+ T value_;
/// domain of the image
p_runs_<P> domain_;
@@ -128,6 +128,9 @@
/// Test if this image has been initialized.
bool has_data() const;
+ /// Give the uniq value of the image.
+ rvalue get_value() const;
+
/// Give the set of values of the image.
const vset& values() const;
@@ -147,7 +150,7 @@
template <typename P, typename T>
inline
data_< mono_rle_image<P,T> >::data_(const T& val)
- : value(val)
+ : value_(val)
{
}
@@ -201,7 +204,15 @@
const
{
mln_precondition(site.pset_pos_() < this->data_->domain_.nruns());
- return this->data_->value;
+ return this->data_->value_;
+ }
+
+ template <typename P, typename T>
+ inline
+ typename mono_rle_image<P, T>::rvalue
+ mono_rle_image<P, T>::get_value() const
+ {
+ return this->data_->value_;
}
template <typename P, typename T>
@@ -210,7 +221,7 @@
mono_rle_image<P, T>::operator() (const typename mono_rle_image<P, T>::psite& site)
{
mln_precondition(site.pset_pos_() < this->data_->domain_.nruns());
- return this->data_->value;
+ return this->data_->value_;
}
template <typename P, typename T>
Index: trunk/milena/mln/core/obased_rle_image.hh
===================================================================
--- trunk/milena/mln/core/obased_rle_image.hh (revision 1593)
+++ trunk/milena/mln/core/obased_rle_image.hh (revision 1594)
@@ -62,6 +62,9 @@
std::vector< accu::bbox<P> > bbox_;
/// Value of Objects.
+ std::vector<T> v_obj_;
+
+ /// Image values.
std::vector<T> values_;
/// domain of the image
@@ -163,7 +166,7 @@
bbox_(values.size())
{
std::copy(values.begin(), values.end(),
- std::back_inserter(this->values_));
+ std::back_inserter(this->v_obj_));
}
template <typename P, typename T>
@@ -173,7 +176,7 @@
{
return domain_.size_mem() + bbox_.size()
* (sizeof(T) + sizeof(box_<P>) + sizeof(std::vector<unsigned>))
- + sizeof(unsigned) * domain_.nruns();
+ + (sizeof(unsigned) + sizeof(T)) * domain_.nruns();
}
} // end of namespace mln::internal
@@ -206,14 +209,15 @@
void
obased_rle_image<P, T>::insert(const p_run<P>& pr, T value)
{
- mln_assertion(this->data_->values_.size() == 0 || this->data_->domain_.nruns() == 0 ||
+ mln_assertion(this->data_->v_obj_.size() == 0 || this->data_->domain_.nruns() == 0 ||
pr.first() > this->data_->domain_[this->data_->domain_.nruns() - 1].first());
this->data_->domain_.insert(pr);
+ this->data_->values_.push_back(value);
unsigned i;
- for (i = 0; i < this->data_->values_.size()
- && this->data_->values_[i] != value; ++i)
+ for (i = 0; i < this->data_->v_obj_.size()
+ && this->data_->v_obj_[i] != value; ++i)
;
- mln_assertion(i != this->data_->values_.size());
+ mln_assertion(i != this->data_->v_obj_.size());
this->data_->obj_[i].push_back(this->data_->domain_.nruns() - 1);
this->data_->bbox_[i].take(pr.bbox().pmin());
this->data_->bbox_[i].take(pr.bbox().pmax());
@@ -227,15 +231,7 @@
{
mln_precondition(this->has_data() &&
site.pset_pos_() < this->data_->domain_.nruns());
- for (unsigned i = 0; i < this->data_->obj_.size(); ++i)
- {
- for (typename std::vector<unsigned>::const_iterator it = this->data_->obj_[i].begin();
- it != this->data_->obj_[i].end(); it++)
- if (*it == site.pset_pos_())
- return this->data_->values_[i];
- }
- mln_assertion(false);
- return this->data_->values_[0];
+ return this->data_->values_[site.pset_pos_()];
}
template <typename P, typename T>
@@ -245,15 +241,7 @@
{
mln_precondition(this->has_data() &&
site.pset_pos_() < this->data_->domain_.nruns());
- for (unsigned i = 0; i < this->data_->obj_.size(); ++i)
- {
- for (typename std::vector<unsigned>::const_iterator it = this->data_->obj_[i].begin();
- it != this->data_->obj_[i].end(); it++)
- if (*it == site.pset_pos_())
- return this->data_->values_[i];
- }
- mln_assertion(false);
- return this->data_->values_[0];
+ return this->data_->values_[site.pset_pos_()];
}
template <typename P, typename T>
Index: trunk/milena/mln/core/mono_obased_rle_encode.hh
===================================================================
--- trunk/milena/mln/core/mono_obased_rle_encode.hh (revision 0)
+++ trunk/milena/mln/core/mono_obased_rle_encode.hh (revision 1594)
@@ -0,0 +1,120 @@
+// 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.
+
+#ifndef MLN_CORE_MONO_OBASED_RLE_ENCODE_HH
+# define MLN_CORE_MONO_OBASED_RLE_ENCODE_HH
+
+/*! \file mln/core/mono_obased_rle_encode.hh
+ *
+ * \brief Definintion of function which encodes an image in mono_obased_rle_image.
+ */
+
+# include <mln/core/mono_obased_rle_image.hh>
+
+namespace mln
+{
+
+ /*!
+ ** encode an image class to a mono_obased_rle_image
+ **
+ ** @param input has to respect the Image concept
+ **
+ ** @return mono_obased_rle_image
+ */
+ template <typename I>
+ mono_obased_rle_image<mln_point(I), mln_value(I)>
+ mono_obased_rle_encode(const Image<I>& input, bool ignore_zero = true);
+
+# ifndef MLN_INCLUDE_ONLY
+ /*!
+ ** test if Point p1 and p2 are on the same line
+ */
+ template <typename P>
+ inline
+ bool
+ on_the_same_line(const P& p1, const P& p2)
+ {
+ const unsigned dim = P::dim;
+ bool same_line = true;
+
+ for (unsigned n = 0; same_line && n < dim - 1; ++n)
+ same_line = (p1[n] == p2[n]);
+ return same_line;
+ }
+
+ template <typename I>
+ inline
+ mono_obased_rle_image<mln_point(I), mln_value(I)>
+ mono_obased_rle_encode(const Image<I>& input, bool ignore_zero)
+ {
+ typedef mln_point(I) P;
+
+ const I& ima = exact(input);
+ mln_piter(I) p (exact(input).domain());
+ unsigned len = 0;
+ mln_point(I) rstart;
+ mln_value(I) rvalue;
+ std::set< mln_value(I) > sv;
+
+ for_all(p)
+ {
+ if (!ignore_zero || ima(p) != literal::zero)
+ sv.insert(ima(p));
+ }
+
+ mono_obased_rle_image<mln_point(I), mln_value(I)> output(sv);
+ for_all(p)
+ if (!ignore_zero || ima(p) != literal::zero || len)
+ {
+ if (len == 0)
+ {
+ ++len;
+ rstart = p;
+ rvalue = ima(p);
+ }
+ else
+ if (rvalue == ima(p)
+ && on_the_same_line(rstart, mln_point(I)(p)))
+ ++len;
+ else
+ {
+ output.insert(p_run<P>(rstart, len), rvalue);
+ if ((len = (!ignore_zero || ima(p) != literal::zero)))
+ {
+ rstart = p;
+ rvalue = ima(p);
+ }
+ }
+ }
+ return output;
+ }
+
+#endif // ! MLN_INCLUDE_ONLY
+
+}
+
+#endif // ! MLN_CORE_MONO_OBASED_RLE_ENCODE_HH
Index: trunk/milena/mln/core/mono_obased_rle_image.hh
===================================================================
--- trunk/milena/mln/core/mono_obased_rle_image.hh (revision 0)
+++ trunk/milena/mln/core/mono_obased_rle_image.hh (revision 1594)
@@ -0,0 +1,255 @@
+// 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.
+
+#ifndef MLN_CORE_MONO_OBASED_RLE_IMAGE_HH
+# define MLN_CORE_MONO_OBASED_RLE_IMAGE_HH
+
+/*! \file mln/core/mono_obased_rle_image.hh
+ *
+ * \brief Definition of an image with rle encoding.
+ */
+
+# include <mln/core/internal/run_image.hh>
+# include <mln/core/p_runs.hh>
+# include <mln/core/runs_psite.hh>
+# include <mln/core/box.hh>
+# include <mln/value/set.hh>
+# include <mln/core/mono_rle_image.hh>
+# include <vector>
+
+namespace mln
+{
+
+ // Fwd decl.
+ template <typename P, typename T> struct mono_obased_rle_image;
+
+
+ namespace internal
+ {
+
+ template <typename P, typename T>
+ struct data_< mono_obased_rle_image<P,T> >
+ {
+ data_(const std::set<T>& values);
+
+ /// Objects.
+ std::vector< mono_rle_image<P, T> > ima_;
+
+ /// Image value.
+ std::vector<T> values_;
+
+ /// domain of the image
+ p_runs_<P> domain_;
+
+ /// Return the size of the data in memory.
+ unsigned size_mem() const;
+ };
+
+ } // end of namespace mln::internal
+
+
+ namespace trait
+ {
+
+ template <typename P, typename T>
+ struct image_< mono_obased_rle_image<P,T> > : default_image_< T, mono_obased_rle_image<P,T> >
+ {
+ typedef trait::image::category::primary category;
+
+ typedef trait::image::access::browsing access;
+ // FIXME: Put the right dimension.
+ typedef trait::image::space::two_d space;
+ typedef trait::image::size::regular size;
+ typedef trait::image::support::aligned support;
+
+ typedef trait::image::border::none border;
+ typedef trait::image::data::linear data;
+ typedef trait::image::io::read_only io;
+ typedef trait::image::speed::slow speed;
+ };
+
+ } // end of namespace mln::trait
+
+
+ /*! \brief RLE image.
+ *
+ *
+ * Parameter \c P is the type of the image points.
+ * Parameter \c T is the type of the pixel values.
+ * This image is not point wise accessible.
+ */
+ template <typename P, typename T>
+ class mono_obased_rle_image : public internal::run_image_< T, P, mono_obased_rle_image<P, T> >
+ {
+ public:
+ typedef T value;
+ typedef T& lvalue;
+ typedef const T rvalue;
+ typedef runs_psite<P> psite;
+ typedef mln::value::set<T> vset;
+ typedef p_runs_<P> pset;
+
+
+ /// Skeleton.
+ typedef mono_obased_rle_image< tag::psite_<P>, tag::value_<T> > skeleton;
+
+
+ mono_obased_rle_image(const std::set<T>& values);
+
+ /// Add a new range to the image.
+ void insert(const p_run<P>& pr, T value);
+
+ /// Read-only access to the image value located at point \p p.
+ rvalue operator() (const psite& site) const;
+
+ /// Read-write access to the image value located at point \p p.
+ lvalue operator() (const psite& site);
+
+ /// Test if this image has been initialized.
+ bool has_data() const;
+
+ /// Give the set of values of the image.
+ const vset& values() const;
+
+ /// Give the definition domain.
+ const pset& domain() const;
+
+ /// Give the index vector of the i-th object.
+ const mono_rle_image<P, T>& object(unsigned i) const;
+
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ // internal::data_< mono_obased_rle_image<P,T> >
+
+ template <typename P, typename T>
+ inline
+ data_< mono_obased_rle_image<P,T> >::data_(const std::set<T>& values)
+ : ima_(values.begin(), values.end())
+ {
+ }
+
+ template <typename P, typename T>
+ inline
+ unsigned
+ data_< mono_obased_rle_image<P,T> >::size_mem() const
+ {
+ return domain_.size_mem() * 2 + sizeof(T) * (values_.size() + ima_.size());
+ }
+
+ } // end of namespace mln::internal
+
+ template <typename P, typename T>
+ inline
+ mono_obased_rle_image<P, T>::mono_obased_rle_image(const std::set<T>& values)
+ {
+ this->data_ = new internal::data_< mono_obased_rle_image<P,T> >(values);
+ }
+
+ template <typename P, typename T>
+ inline
+ bool
+ mono_obased_rle_image<P, T>::has_data() const
+ {
+ return this->data_->ima_.size() != 0;
+ }
+
+ template <typename P, typename T>
+ inline
+ const typename mono_obased_rle_image<P, T>::vset&
+ mono_obased_rle_image<P, T>::values() const
+ {
+ return vset::the();
+ }
+
+ template <typename P, typename T>
+ inline
+ void
+ mono_obased_rle_image<P, T>::insert(const p_run<P>& pr, T value)
+ {
+ mln_assertion(this->data_->values_.size() == 0 || this->data_->domain_.nruns() == 0 ||
+ pr.first() > this->data_->domain_[this->data_->domain_.nruns() - 1].first());
+ this->data_->domain_.insert(pr);
+ this->data_->values_.push_back(value);
+ unsigned i;
+ for (i = 0; i < this->data_->ima_.size()
+ && this->data_->ima_[i].get_value() != value; ++i)
+ ;
+ mln_assertion(i != this->data_->ima_.size());
+ this->data_->ima_[i].insert(pr);
+ }
+
+ template <typename P, typename T>
+ inline
+ typename mono_obased_rle_image<P, T>::rvalue
+ mono_obased_rle_image<P, T>::operator() (const typename mono_obased_rle_image<P, T>::psite& site)
+ const
+ {
+ mln_precondition(this->has_data() &&
+ site.pset_pos_() < this->data_->domain_.nruns());
+ return this->data_->values_[site.pset_pos_()];
+ }
+
+ template <typename P, typename T>
+ inline
+ typename mono_obased_rle_image<P, T>::lvalue
+ mono_obased_rle_image<P, T>::operator() (const typename mono_obased_rle_image<P, T>::psite& site)
+ {
+ mln_precondition(this->has_data() &&
+ site.pset_pos_() < this->data_->domain_.nruns());
+ return this->data_->values_[site.pset_pos_()];
+ }
+
+ template <typename P, typename T>
+ inline
+ const typename mono_obased_rle_image<P, T>::pset&
+ mono_obased_rle_image<P, T>::domain() const
+ {
+ return this->data_->domain_;
+ }
+
+ template <typename P, typename T>
+ inline
+ const mono_rle_image<P, T>&
+ mono_obased_rle_image<P, T>::object(unsigned i) const
+ {
+ mln_assertion(i < this->data_->ima_.size());
+ return this->data_->ima_[i];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_MONO_OBASED_RLE_IMAGE_HH
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-12-04 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
New full tests for level.
* tests/level/assign_full.cc,
* tests/level/compare_full.cc,
* tests/level/compute_full.cc: New full tests.
---
assign_full.cc | 263 ++++++++++++++++++++++++++++++++++++++++++++++++++++
compare_full.cc | 260 ++++++++++++++++++++++++++++++++++++++++++++++++++++
compute_full.cc | 280 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 803 insertions(+)
Index: trunk/milena/tests/level/compute_full.cc
===================================================================
--- trunk/milena/tests/level/compute_full.cc (revision 0)
+++ trunk/milena/tests/level/compute_full.cc (revision 1593)
@@ -0,0 +1,280 @@
+// 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/compute_full.cc
+ *
+ * \brief Tests on mln::level::compute.
+ */
+
+#include <mln/core/image1d.hh>
+#include <mln/core/image2d.hh>
+#include <mln/core/image3d.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u16.hh>
+#include <mln/value/int_s8.hh>
+#include <mln/value/int_s16.hh>
+
+#include <mln/core/sub_image.hh>
+#include <mln/core/image_if.hh>
+#include <mln/fun/p2b/chess.hh>
+
+#include <mln/accu/min.hh>
+#include <mln/accu/max.hh>
+#include <mln/debug/iota.hh>
+#include <mln/debug/println.hh>
+#include <mln/level/compute.hh>
+
+
+
+struct f_box1d_t : mln::Function_p2b< f_box1d_t >
+{
+ f_box1d_t(const mln::box1d& b)
+ : b_(b)
+ {
+ }
+ mln::box1d b_;
+ bool operator()(const mln::point1d& p) const
+ {
+ return b_.has(p);
+ }
+};
+
+struct f_box2d_t : mln::Function_p2b< f_box2d_t >
+{
+ f_box2d_t(const mln::box2d& b)
+ : b_(b)
+ {
+ }
+ mln::box2d b_;
+ bool operator()(const mln::point2d& p) const
+ {
+ return b_.has(p);
+ }
+};
+
+struct f_box3d_t : mln::Function_p2b< f_box3d_t >
+{
+ f_box3d_t(const mln::box3d& b)
+ : b_(b)
+ {
+ }
+ mln::box3d b_;
+ bool operator()(const mln::point3d& p) const
+ {
+ return b_.has(p);
+ }
+};
+
+
+namespace mln
+{
+ template <typename I>
+ void
+ chk1d(unsigned cols)
+ {
+ box1d b1(literal::origin, point1d(1));
+
+ image1d<I> ima (cols);
+ debug::iota (ima);
+ I real_min = 1;
+ I real_min2 = 1;
+ I real_max = (I)(cols % (unsigned) mln_max(I));
+ I real_max2 = 2;
+ if (cols >= (unsigned)mln_max(I))
+ {
+ real_min = 0;
+ real_max = mln_max(I) - 1;
+ }
+
+
+ {
+ accu::min_<I> acu_min;
+ accu::max_<I> acu_max;
+
+ I min = level::compute(ima, acu_min);
+ I max = level::compute(ima, acu_max);
+ mln_assertion(min == real_min);
+ mln_assertion(max == real_max);
+ }
+
+ {
+ sub_image<image1d<I>, box1d> sub_ima (ima, b1);
+
+ accu::min_<I> acu_min;
+ accu::max_<I> acu_max;
+
+ I min = level::compute(sub_ima, acu_min);
+ I max = level::compute(sub_ima, acu_max);
+ mln_assertion(min == real_min2);
+ mln_assertion(max == real_max2);
+ }
+
+ {
+ f_box1d_t f_b(b1);
+ image_if<image1d<I>, f_box1d_t> if_ima(ima, f_b);
+
+ accu::min_<I> acu_min;
+ accu::max_<I> acu_max;
+
+ I min = level::compute(if_ima, acu_min);
+ I max = level::compute(if_ima, acu_max);
+ mln_assertion(min == real_min2);
+ mln_assertion(max == real_max2);
+ }
+ }
+
+ template <typename I>
+ void
+ chk2d(unsigned rows, unsigned cols)
+ {
+ box2d b2(literal::origin, point2d(1, 1));
+
+ image2d<I> ima (rows, cols);
+ debug::iota (ima);
+ I real_min = 1;
+ I real_min2 = 1;
+ I real_max;
+ if (rows * cols >= (unsigned)mln_max(I))
+ {
+ real_min = 0;
+ real_max = mln_max(I) - 1;
+ }
+ else
+ {
+ real_max = (I)(rows * cols);
+ if ((cols == (unsigned)mln_max(I) - 2) ||
+ (cols == (unsigned)mln_max(I) - 1))
+ real_min2 = 0;
+ }
+
+ {
+ accu::min_<I> acu_min;
+ accu::max_<I> acu_max;
+
+ I min = level::compute(ima, acu_min);
+ I max = level::compute(ima, acu_max);
+
+ mln_assertion(min == real_min);
+ mln_assertion(max == real_max);
+ }
+
+ }
+
+ template <typename I>
+ void
+ chk3d(unsigned slis, unsigned rows, unsigned cols)
+ {
+ box3d b3(literal::origin, point3d(1, 1, 1));
+
+ image3d<I> ima (slis, rows, cols);
+ debug::iota (ima);
+ I real_min = 1;
+ I real_min2 = 1;
+ I real_max;
+ if (slis * rows * cols >= (unsigned)mln_max(I))
+ {
+ real_min = 0;
+ real_max = mln_max(I) - 1;
+ }
+ else
+ real_max = (I)(slis * rows * cols);
+ {
+ accu::min_<I> acu_min;
+ accu::max_<I> acu_max;
+
+ I min = level::compute(ima, acu_min);
+ I max = level::compute(ima, acu_max);
+
+ mln_assertion(min == real_min);
+ mln_assertion(max == real_max);
+ }
+
+ }
+}
+
+
+int main()
+{
+ using namespace mln;
+
+ unsigned slis_start = 2;
+ unsigned slis_end = 3;
+
+ unsigned rows_start = 2;
+ unsigned rows_end = 16;
+
+ unsigned cols_start = 2;
+ unsigned cols_end = 256;
+
+
+ std::cerr << "Tests level::compute:" << std::endl;
+
+ (std::cerr << "in 1d ... ").flush ();
+ {
+ for (unsigned i = cols_start; i < cols_end; ++i)
+ {
+ chk1d<int>(i);
+ chk1d<unsigned>(i);
+ chk1d<value::int_u8>(i);
+ chk1d<value::int_u16>(i);
+ chk1d<value::int_s8>(i);
+ chk1d<value::int_s16>(i);
+ }
+ }
+ std::cerr << "OK" << std::endl;
+
+ (std::cerr << "in 2d ... ").flush ();
+ {
+ for (unsigned j = rows_start; j < rows_end; ++j)
+ for (unsigned i = cols_start; i < cols_end; ++i)
+ {
+ chk2d<int>(j, i);
+ chk2d<unsigned>(j, i);
+ chk2d<value::int_u8>(j, i);
+ chk2d<value::int_u16>(j, i);
+ chk2d<value::int_s8>(j, i);
+ chk2d<value::int_s16>(j, i);
+ }
+ }
+ std::cerr << "OK" << std::endl;
+
+ (std::cerr << "in 3d ... ").flush ();
+ {
+ for (unsigned k = slis_start; k < slis_end; ++k)
+ for (unsigned j = rows_start; j < rows_end; ++j)
+ for (unsigned i = cols_start; i < cols_end; ++i)
+ {
+ chk3d<int>(k, j, i);
+ chk3d<unsigned>(k, j, i);
+ chk3d<value::int_u8>(k, j, i);
+ chk3d<value::int_u16>(k, j, i);
+ chk3d<value::int_s8>(k, j, i);
+ }
+ }
+ std::cerr << "OK" << std::endl;
+}
Index: trunk/milena/tests/level/assign_full.cc
===================================================================
--- trunk/milena/tests/level/assign_full.cc (revision 0)
+++ trunk/milena/tests/level/assign_full.cc (revision 1593)
@@ -0,0 +1,263 @@
+// 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/assign_full.cc
+ *
+ * \brief Tests on mln::level::assign.
+ */
+
+
+#include <mln/core/image1d.hh>
+#include <mln/core/image2d.hh>
+#include <mln/core/image3d.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u16.hh>
+#include <mln/value/int_s8.hh>
+#include <mln/value/int_s16.hh>
+
+
+#include <mln/core/sub_image.hh>
+
+#include <mln/core/image_if.hh>
+#include <mln/fun/p2b/chess.hh>
+
+
+#include <mln/core/clone.hh>
+#include <mln/level/assign.hh>
+#include <mln/level/compare.hh>
+#include <mln/debug/iota.hh>
+
+#include <mln/debug/println.hh>
+
+struct f_box1d_t : mln::Function_p2b< f_box1d_t >
+{
+ f_box1d_t(const mln::box1d& b)
+ : b_(b)
+ {
+ }
+ mln::box1d b_;
+ bool operator()(const mln::point1d& p) const
+ {
+ return b_.has(p);
+ }
+};
+
+struct f_box2d_t : mln::Function_p2b< f_box2d_t >
+{
+ f_box2d_t(const mln::box2d& b)
+ : b_(b)
+ {
+ }
+ mln::box2d b_;
+ bool operator()(const mln::point2d& p) const
+ {
+ return b_.has(p);
+ }
+};
+
+struct f_box3d_t : mln::Function_p2b< f_box3d_t >
+{
+ f_box3d_t(const mln::box3d& b)
+ : b_(b)
+ {
+ }
+ mln::box3d b_;
+ bool operator()(const mln::point3d& p) const
+ {
+ return b_.has(p);
+ }
+};
+
+
+namespace mln
+{
+ template <typename I, typename J>
+ void
+ chck(I& lhs, J& rhs)
+ {
+ level::assign(lhs, rhs);
+ mln_piter (I) p (lhs.domain ());
+ for_all (p)
+ mln_assertion (lhs(p) == (mln_value(I))rhs(p));
+
+ }
+
+ template <typename I, typename J>
+ void
+ chk1d(unsigned cols)
+ {
+ image1d<I> lhs (cols);
+ image1d<J> rhs (cols);
+ debug::iota (rhs);
+ chck(lhs, rhs);
+
+ level::fill(lhs, 0);
+ box1d b1(literal::origin, point1d(1));
+ sub_image<image1d<I>, box1d> sub_lhs (lhs, b1);
+ sub_image<image1d<J>, box1d> sub_rhs (rhs, b1);
+ chck(sub_lhs, sub_rhs);
+
+ level::fill(lhs, 0);
+ f_box1d_t f_b(b1);
+ image_if<image1d<I>, f_box1d_t> if_lhs(lhs, f_b);
+ image_if<image1d<J>, f_box1d_t> if_rhs(rhs, f_b);
+ chck(if_lhs, if_rhs);
+ }
+
+ template <typename I, typename J>
+ void
+ chk2d(unsigned rows, unsigned cols)
+ {
+ image2d<I> lhs (rows, cols);
+ image2d<J> rhs (rows, cols);
+ debug::iota (rhs);
+ chck(lhs, rhs);
+
+ level::fill(lhs, 0);
+ box2d b2(literal::origin, point2d(1, 1));
+ sub_image<image2d<I>, box2d> sub_lhs (lhs, b2);
+ sub_image<image2d<J>, box2d> sub_rhs (rhs, b2);
+ chck(sub_lhs, sub_rhs);
+
+ level::fill(lhs, 0);
+ f_box2d_t f_b(b2);
+ image_if<image2d<I>, f_box2d_t> if_lhs(lhs, f_b);
+ image_if<image2d<J>, f_box2d_t> if_rhs(rhs, f_b);
+ chck(if_lhs, if_rhs);
+ }
+
+ template <typename I, typename J>
+ void
+ chk3d(unsigned slis, unsigned rows, unsigned cols)
+ {
+ image3d<I> lhs (slis, rows, cols);
+ image3d<J> rhs (slis, rows, cols);
+ debug::iota (rhs);
+ chck(lhs, rhs);
+
+ level::fill(lhs, 0);
+ box3d b3(literal::origin, point3d(1, 1, 1));
+ sub_image<image3d<I>, box3d> sub_lhs (lhs, b3);
+ sub_image<image3d<J>, box3d> sub_rhs (rhs, b3);
+ chck(sub_lhs, sub_rhs);
+
+ level::fill(lhs, 0);
+ f_box3d_t f_b(b3);
+ image_if<image3d<I>, f_box3d_t> if_lhs(lhs, f_b);
+ image_if<image3d<J>, f_box3d_t> if_rhs(rhs, f_b);
+ chck(if_lhs, if_rhs);
+ }
+}
+
+
+int main()
+{
+ using namespace mln;
+
+ unsigned slis_start = 1;
+ unsigned slis_end = 4;
+
+ unsigned rows_start = 1;
+ unsigned rows_end = 16;
+
+ unsigned cols_start = 1;
+ unsigned cols_end = 32;
+
+
+ std::cerr << "Tests level::assign" << std::endl;
+
+ (std::cerr << "in 1d ... ").flush ();
+ {
+ for (unsigned i = cols_start; i < cols_end; ++i)
+ {
+ chk1d<int, int>(i);
+ chk1d<unsigned, unsigned>(i);
+ chk1d<int, unsigned>(i);
+ chk1d<unsigned, int>(i);
+
+ chk1d<value::int_u8, value::int_u8>(i);
+ chk1d<value::int_u16, value::int_u16>(i);
+ chk1d<value::int_s8, value::int_s8>(i);
+ chk1d<value::int_s16, value::int_s16>(i);
+
+ chk1d<unsigned, value::int_u8>(i);
+ chk1d<unsigned, value::int_u16>(i);
+ chk1d<int, value::int_s8>(i);
+ chk1d<int, value::int_s16>(i);
+
+ }
+ }
+ std::cerr << "OK" << std::endl;
+
+ (std::cerr << "in 2d ... ").flush ();
+ {
+ for (unsigned j = rows_start; j < rows_end; ++j)
+ for (unsigned i = cols_start; i < cols_end; ++i)
+ {
+ chk2d<int, int>(j, i);
+ chk2d<unsigned, unsigned>(j, i);
+ chk2d<int, unsigned>(j, i);
+ chk2d<unsigned, int>(j, i);
+
+ chk2d<value::int_u8, value::int_u8>(j, i);
+ chk2d<value::int_u16, value::int_u16>(j, i);
+ chk2d<value::int_s8, value::int_s8>(j, i);
+ chk2d<value::int_s16, value::int_s16>(j, i);
+
+ chk2d<unsigned, value::int_u8>(j, i);
+ chk2d<unsigned, value::int_u16>(j, i);
+ chk2d<int, value::int_s8>(j, i);
+ chk2d<int, value::int_s16>(j, i);
+ }
+ }
+ std::cerr << "OK" << std::endl;
+
+ (std::cerr << "in 3d ... ").flush ();
+ {
+ for (unsigned k = slis_start; k < slis_end; ++k)
+ for (unsigned j = rows_start; j < rows_end; ++j)
+ for (unsigned i = cols_start; i < cols_end; ++i)
+ {
+ chk3d<int, int>(k, j, i);
+ chk3d<unsigned, unsigned>(k, j, i);
+ chk3d<int, unsigned>(k, j, i);
+ chk3d<unsigned, int>(k, j, i);
+
+ chk3d<value::int_u8, value::int_u8>(k, j, i);
+ chk3d<value::int_u16, value::int_u16>(k, j, i);
+ chk3d<value::int_s8, value::int_s8>(k, j, i);
+ chk3d<value::int_s16, value::int_s16>(k, j, i);
+
+ chk3d<unsigned, value::int_u8>(k, j, i);
+ chk3d<unsigned, value::int_u16>(k, j, i);
+ chk3d<int, value::int_s8>(k, j, i);
+ chk3d<int, value::int_s16>(k, j, i);
+ }
+ }
+ std::cerr << "OK" << std::endl;
+}
Index: trunk/milena/tests/level/compare_full.cc
===================================================================
--- trunk/milena/tests/level/compare_full.cc (revision 0)
+++ trunk/milena/tests/level/compare_full.cc (revision 1593)
@@ -0,0 +1,260 @@
+// 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/compare_full.cc
+ *
+ * \brief Tests on mln::level::compare.
+ */
+
+#include <mln/core/image1d.hh>
+#include <mln/core/image2d.hh>
+#include <mln/core/image3d.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u16.hh>
+#include <mln/value/int_s8.hh>
+#include <mln/value/int_s16.hh>
+
+#include <mln/level/compare.hh>
+
+#include <mln/debug/iota.hh>
+
+#include <mln/arith/plus.hh>
+#include <mln/arith/minus.hh>
+
+
+struct f_box1d_t : mln::Function_p2b< f_box1d_t >
+{
+ f_box1d_t(const mln::box1d& b)
+ : b_(b)
+ {
+ }
+ mln::box1d b_;
+ bool operator()(const mln::point1d& p) const
+ {
+ return b_.has(p);
+ }
+};
+
+struct f_box2d_t : mln::Function_p2b< f_box2d_t >
+{
+ f_box2d_t(const mln::box2d& b)
+ : b_(b)
+ {
+ }
+ mln::box2d b_;
+ bool operator()(const mln::point2d& p) const
+ {
+ return b_.has(p);
+ }
+};
+
+struct f_box3d_t : mln::Function_p2b< f_box3d_t >
+{
+ f_box3d_t(const mln::box3d& b)
+ : b_(b)
+ {
+ }
+ mln::box3d b_;
+ bool operator()(const mln::point3d& p) const
+ {
+ return b_.has(p);
+ }
+};
+
+
+namespace mln
+{
+ template<typename I, typename J>
+ void
+ test_less(I& lhs, J& rhs)
+ {
+ mln_assertion(! (lhs == rhs));
+ mln_assertion( (lhs <= rhs));
+ mln_assertion( (lhs < rhs));
+ mln_assertion(! (lhs >= rhs));
+ mln_assertion(! (lhs > rhs));
+
+ mln_assertion(! (rhs == lhs));
+ mln_assertion(! (rhs <= lhs));
+ mln_assertion(! (rhs < lhs));
+ mln_assertion( (rhs >= lhs));
+ mln_assertion( (rhs > lhs));
+ }
+
+ template<typename I, typename J>
+ void
+ test_more(I& lhs, J& rhs)
+ {
+ mln_assertion(! (lhs == rhs));
+ mln_assertion( (lhs <= rhs));
+ mln_assertion( (lhs < rhs));
+ mln_assertion(! (lhs >= rhs));
+ mln_assertion(! (lhs > rhs));
+
+ mln_assertion(! (rhs == lhs));
+ mln_assertion(! (rhs <= lhs));
+ mln_assertion(! (rhs < lhs));
+ mln_assertion( (rhs >= lhs));
+ mln_assertion( (rhs > lhs));
+ }
+
+ template<typename I, typename J>
+ void
+ test_equal(I& lhs, J& rhs)
+ {
+ mln_assertion( (lhs == rhs));
+ mln_assertion( (lhs <= rhs));
+ mln_assertion(! (lhs < rhs));
+ mln_assertion( (lhs >= rhs));
+ mln_assertion(! (lhs > rhs));
+
+ mln_assertion( (rhs == lhs));
+ mln_assertion( (rhs <= lhs));
+ mln_assertion(! (rhs < lhs));
+ mln_assertion( (rhs >= lhs));
+ mln_assertion(! (rhs > lhs));
+ }
+
+ template <typename I>
+ void
+ chk1d(unsigned cols)
+ {
+ image1d<I> lhs (cols);
+ image1d<I> rhs (cols);
+ debug::iota (lhs);
+ debug::iota (rhs);
+
+ test_equal(lhs, rhs);
+ image1d<int> lhs2 = lhs + 0;
+ image1d<int> rhs2 = rhs + 1;
+ test_less(lhs2, rhs2);
+ image1d<int> lhs3 = lhs - 1;
+ image1d<int> rhs3 = rhs + 0;
+ test_more(lhs3, rhs3);
+ }
+
+ template <typename I>
+ void
+ chk2d(unsigned rows, unsigned cols)
+ {
+ image2d<I> lhs (rows, cols);
+ image2d<I> rhs (rows, cols);
+ debug::iota (lhs);
+ debug::iota (rhs);
+
+ test_equal(lhs, rhs);
+ image2d<int> lhs2 = lhs + 0;
+ image2d<int> rhs2 = rhs + 1;
+ test_less(lhs2, rhs2);
+ image2d<int> lhs3 = lhs - 1;
+ image2d<int> rhs3 = rhs + 0;
+ test_more(lhs3, rhs3);
+ }
+
+ template <typename I>
+ void
+ chk3d(unsigned slis, unsigned rows, unsigned cols)
+ {
+ image3d<I> lhs (slis, rows, cols);
+ image3d<I> rhs (slis, rows, cols);
+ debug::iota (lhs);
+ debug::iota (rhs);
+
+ test_equal(lhs, rhs);
+ image3d<int> lhs2 = lhs + 0;
+ image3d<int> rhs2 = rhs + 1;
+ test_less(lhs2, rhs2);
+ image3d<int> lhs3 = lhs - 1;
+ image3d<int> rhs3 = rhs + 0;
+ test_more(lhs3, rhs3);
+ }
+}
+
+
+
+
+int main()
+{
+ using namespace mln;
+
+ unsigned slis_start = 1;
+ unsigned slis_end = 3;
+
+ unsigned rows_start = 1;
+ unsigned rows_end = 16;
+
+ unsigned cols_start = 1;
+ unsigned cols_end = 32;
+
+ std::cerr << "Tests level::compare" << std::endl;
+
+ (std::cerr << "in 1d ... ").flush ();
+ {
+ for (unsigned i = cols_start; i < cols_end; ++i)
+ {
+ chk1d<int>(i);
+ chk1d<unsigned>(i);
+ chk1d<value::int_u8>(i);
+ chk1d<value::int_u16>(i);
+ chk1d<value::int_s8>(i);
+ chk1d<value::int_s16>(i);
+ }
+ }
+ std::cerr << "OK" << std::endl;
+
+ (std::cerr << "in 2d ... ").flush ();
+ {
+ for (unsigned j = rows_start; j < rows_end; ++j)
+ for (unsigned i = cols_start; i < cols_end; ++i)
+ {
+ chk2d<int>(j, i);
+ chk2d<unsigned>(j, i);
+ chk2d<value::int_u8>(j, i);
+ chk2d<value::int_u16>(j, i);
+ chk2d<value::int_s8>(j, i);
+ chk2d<value::int_s16>(j, i);
+ }
+ }
+ std::cerr << "OK" << std::endl;
+
+ (std::cerr << "in 3d ... ").flush ();
+ {
+ for (unsigned k = slis_start; k < slis_end; ++k)
+ for (unsigned j = rows_start; j < rows_end; ++j)
+ for (unsigned i = cols_start; i < cols_end; ++i)
+ {
+ chk3d<int>(k, j, i);
+ chk3d<unsigned>(k, j, i);
+ chk3d<value::int_u8>(k, j, i);
+ chk3d<value::int_u16>(k, j, i);
+ chk3d<value::int_s8>(k, j, i);
+ chk3d<value::int_s16>(k, j, i);
+ }
+ }
+ std::cerr << "OK" << std::endl;
+}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-12-04 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Fix compile in graylevel.
* mln/value/graylevel.hh: Add a fwd declaration of convert_.
---
graylevel.hh | 2 ++
1 file changed, 2 insertions(+)
Index: trunk/milena/mln/value/graylevel.hh
===================================================================
--- trunk/milena/mln/value/graylevel.hh (revision 1591)
+++ trunk/milena/mln/value/graylevel.hh (revision 1592)
@@ -248,6 +248,8 @@
namespace internal
{
+ // Fwd decl;
+ template <typename T> struct convert_;
// convert for graylevel
template <unsigned n>
1
0