https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena/sandbox
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Augment line iteration sandbox code.
* geraud/browsing/fwd.cc: Add some code closer to what we
expect.
fwd.cc | 358 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 338 insertions(+), 20 deletions(-)
Index: geraud/browsing/fwd.cc
--- geraud/browsing/fwd.cc (revision 2534)
+++ geraud/browsing/fwd.cc (working copy)
@@ -1,6 +1,8 @@
# include <mln/core/image/image2d.hh>
# include <mln/core/alias/window2d.hh>
-# include <mln/accu/min.hh>
+# include <mln/value/int_u8.hh>
+# include <mln/accu/min_h.hh>
+# include <mln/accu/max_h.hh>
# include <mln/debug/println.hh>
# include <mln/debug/iota.hh>
@@ -86,96 +88,412 @@
namespace mln
{
- template <typename I>
- void line_inc(const I& ima, unsigned half)
- {
- box2d b = ima.domain();
- unsigned nrows = b.nrows(), ncols = b.ncols();
+ // template <typename I>
+ // void line_inc(const I& ima, unsigned half)
+ // {
+ // box2d b = ima.domain();
+ // unsigned nrows = b.nrows(), ncols = b.ncols();
+
+ // for (unsigned row = 0; row < nrows; ++row)
+ // {
+ // unsigned col = 0;
+
+ // std::cout << std::endl
+ // << "START : "
+ // << std::endl
+ // << std::endl;
+
+ // for (unsigned c = 0; c <= half; ++c)
+ // std::cout << " take " << ima.at(row, c) << "
";
+ // std::cout << std::endl;
+
+ // std::cout << " --> OK at " << ima.at(row, col) <<
std::endl;
+ // // ok (row, col) at line start
+
+
+ // std::cout << std::endl
+ // << "BEGIN : "
+ // << std::endl
+ // << std::endl;
+
+ // unsigned col_plus = half;
+
+ // while (col < half)
+ // {
+ // ++col;
+ // ++col_plus;
+ // std::cout << " take " << ima.at(row, col_plus) <<
" ";
+ // std::cout << " --> OK at " << ima.at(row, col)
<< std::endl;
+ // }
+
+ // std::cout << std::endl
+ // << "MIDDLE : "
+ // << std::endl
+ // << std::endl;
+
+ // int col_minus = -1;
+
+ // while (col < ncols - half - 1)
+ // {
+ // ++col;
+ // ++col_plus;
+ // ++col_minus;
+ // std::cout << " take " << ima.at(row, col_plus) <<
" ";
+ // std::cout << " untake " << ima.at(row, col_minus)
<< " ";
+ // std::cout << " --> OK at " << ima.at(row, col)
<< std::endl;
+ // // ok (row, col) at line middle
+ // }
+ // std::cout << std::endl;
+
+
+ // std::cout << std::endl
+ // << "END : "
+ // << std::endl
+ // << std::endl;
+
+ // while (col < ncols - 1)
+ // {
+ // ++col;
+ // ++col_minus;
+ // std::cout << " untake " << ima.at(row, col_minus)
<< " ";
+ // std::cout << " --> OK at " << ima.at(row, col)
<< std::endl;
+ // }
+ // std::cout << std::endl;
+
+ // abort();
+ // }
+ // }
- for (unsigned row = 0; row < nrows; ++row)
- {
- unsigned col = 0;
+
+
+ /*
+
+ template <typename I>
+ void line_inc(const I& ima,
+ const mln_site(I)& pstart, unsigned len,
+ unsigned half)
+ {
+ unsigned row = pstart.row();
+ const unsigned col_start = pstart.col();
+ const unsigned col_last = col_start + len - 1;
std::cout << std::endl
<< "START : "
<< std::endl
<< std::endl;
- for (unsigned c = 0; c <= half; ++c)
- std::cout << " take " << ima.at(row, c) << " ";
+ unsigned col = col_start;
+
+ for (unsigned c = 0; c <= half && c < len; ++c)
+ std::cout << " take " << ima.at(row, col + c) << "
";
std::cout << std::endl;
std::cout << " --> OK at " << ima.at(row, col) <<
std::endl;
// ok (row, col) at line start
+ if (col == col_last)
+ return;
std::cout << std::endl
<< "BEGIN : "
<< std::endl
<< std::endl;
- unsigned col_plus = half;
+ unsigned col_plus = col_start + half;
- while (col < half)
+ while (col < col_start + half && col < col_last)
{
++col;
++col_plus;
+ if (col_plus <= col_last)
std::cout << " take " << ima.at(row, col_plus) << "
";
std::cout << " --> OK at " << ima.at(row, col) <<
std::endl;
}
+ if (col == col_last)
+ return;
+
std::cout << std::endl
<< "MIDDLE : "
<< std::endl
<< std::endl;
- int col_minus = -1;
+ int col_minus = col_start - 1;
- while (col < ncols - half - 1)
+
+ while (col < col_last - half)
{
++col;
++col_plus;
++col_minus;
+ mln_invariant(col_plus >= col_start && col_plus <= col_last);
std::cout << " take " << ima.at(row, col_plus) <<
" ";
+ mln_invariant(col_minus >= col_start && col_minus <= col_last);
std::cout << " untake " << ima.at(row, col_minus) <<
" ";
std::cout << " --> OK at " << ima.at(row, col) <<
std::endl;
// ok (row, col) at line middle
}
std::cout << std::endl;
+ if (col == col_last)
+ return;
std::cout << std::endl
<< "END : "
<< std::endl
<< std::endl;
- while (col < ncols - 1)
+ while (col < col_last)
{
++col;
++col_minus;
+ mln_invariant(col_minus >= col_start && col_minus <= col_last);
std::cout << " untake " << ima.at(row, col_minus) <<
" ";
std::cout << " --> OK at " << ima.at(row, col) <<
std::endl;
}
std::cout << std::endl;
- abort();
}
+
+ */
+
+
+
+ /*
+
+ template <typename I>
+ void line_inc(unsigned dir,
+ const I& ima,
+ const mln_site(I)& p_start, unsigned len,
+ unsigned half)
+ {
+ typedef mln_site(I) P;
+ const unsigned start = p_start[dir];
+ const unsigned last = start + len - 1;
+
+ std::cout << std::endl
+ << "START : "
+ << std::endl
+ << std::endl;
+
+ P p = p_start;
+
+ P q = p;
+ for (unsigned c = 0; c <= half && c < len; ++c)
+ {
+ std::cout << " take " << ima(q) << " ";
+ ++q[dir];
+ }
+ std::cout << std::endl;
+
+ std::cout << " --> OK at " << ima(p) << std::endl;
+
+ def::coord& cur = p[dir];
+ if (cur == last)
+ return;
+
+ std::cout << std::endl
+ << "BEGIN : "
+ << std::endl
+ << std::endl;
+
+ P p_plus = p_start;
+ def::coord& plus = p_plus[dir];
+ plus += half;
+
+ while (cur < start + half && cur < last)
+ {
+ ++cur;
+ ++plus;
+ if (plus <= last)
+ std::cout << " take " << ima(p_plus) << " ";
+ std::cout << " --> OK at " << ima(p) << std::endl;
+ }
+
+ if (cur == last)
+ return;
+
+ std::cout << std::endl
+ << "MIDDLE : "
+ << std::endl
+ << std::endl;
+
+ P p_minus = p_start;
+ def::coord& minus = p_minus[dir];
+ --minus;
+
+ while (cur < last - half)
+ {
+ ++cur;
+ ++plus;
+ ++minus;
+ mln_invariant(plus >= start && plus <= last);
+ std::cout << " take " << ima(p_plus) << " ";
+ mln_invariant(minus >= start && minus <= last);
+ std::cout << " untake " << ima(p_minus) << " ";
+ std::cout << " --> OK at " << ima(p) << std::endl;
+ // ok (row, cur) at line middle
+ }
+ std::cout << std::endl;
+
+ if (cur == last)
+ return;
+
+ std::cout << std::endl
+ << "END : "
+ << std::endl
+ << std::endl;
+
+ while (cur < last)
+ {
+ ++cur;
+ ++minus;
+ mln_invariant(minus >= start && minus <= last);
+ std::cout << " untake " << ima(p_minus) << " ";
+ std::cout << " --> OK at " << ima(p) << std::endl;
+ }
+ std::cout << std::endl;
+
+ }
+
+*/
+
+
+ template <typename I, typename A, typename O>
+ void line_inc(unsigned dir,
+ const I& input,
+ const mln_site(I)& p_start, unsigned len,
+ A a, unsigned half,
+ O& output)
+ {
+ typedef mln_site(I) P;
+ const unsigned start = p_start[dir];
+ const unsigned last = start + len - 1;
+
+ std::cout << std::endl
+ << "START : "
+ << std::endl
+ << std::endl;
+
+ P p = p_start;
+ a.init();
+
+ P q = p;
+ for (unsigned c = 0; c <= half && c < len; ++c)
+ {
+ a.take(input(q));
+ std::cout << " take " << debug::format(input(q)) << "
";
+ ++q[dir];
+ }
+ std::cout << std::endl;
+
+ std::cout << " --> OK at " << debug::format(input(p))
<< std::endl;
+ output(p) = a;
+
+ def::coord& cur = p[dir];
+ if (cur == last)
+ return;
+
+ std::cout << std::endl
+ << "BEGIN : "
+ << std::endl
+ << std::endl;
+
+ P p_plus = p_start;
+ def::coord& plus = p_plus[dir];
+ plus += half;
+
+ while (cur < start + half && cur < last)
+ {
+ ++cur;
+ ++plus;
+ if (plus <= last)
+ {
+ a.take(input(p_plus));
+ std::cout << " take " << debug::format(input(p_plus)) <<
" ";
+ }
+ std::cout << " --> OK at " << debug::format(input(p)) <<
std::endl;
+ output(p) = a;
+ }
+
+ if (cur == last)
+ return;
+
+ std::cout << std::endl
+ << "MIDDLE : "
+ << std::endl
+ << std::endl;
+
+ P p_minus = p_start;
+ def::coord& minus = p_minus[dir];
+ --minus;
+
+ while (cur < last - half)
+ {
+ ++cur;
+ ++plus;
+ ++minus;
+ mln_invariant(plus >= start && plus <= last);
+ a.take(input(p_plus));
+ std::cout << " take " << debug::format(input(p_plus)) <<
" ";
+ mln_invariant(minus >= start && minus <= last);
+ a.untake(input(p_minus));
+ std::cout << " untake " << debug::format(input(p_minus)) <<
" ";
+ std::cout << " --> OK at " << debug::format(input(p)) <<
std::endl;
+ output(p) = a;
+ // ok (row, cur) at line middle
+ }
+ std::cout << std::endl;
+
+ if (cur == last)
+ return;
+
+ std::cout << std::endl
+ << "END : "
+ << std::endl
+ << std::endl;
+
+ while (cur < last)
+ {
+ ++cur;
+ ++minus;
+ mln_invariant(minus >= start && minus <= last);
+ a.untake(input(p_minus));
+ std::cout << " untake " << debug::format(input(p_minus)) <<
" ";
+ std::cout << " --> OK at " << debug::format(input(p)) <<
std::endl;
+ output(p) = a;
+ }
+ std::cout << std::endl;
+
}
+
+
} // mln
+
+
int main()
{
using namespace mln;
+ using value::int_u8;
- typedef image2d<unsigned> I;
- I ima(3, 12, 0);
+ typedef image2d<int_u8> I;
+ I ima(12, 12);
debug::iota(ima);
debug::println(ima);
- line_inc(ima, 2);
+ I out(12, 12);
+ point2d p_start(0, 0);
+ line_inc(0, // dir
+ ima, p_start, ima.ncols(),
+ accu::min_h<int_u8>(), 4, // half
+ out);
+
+ debug::println(out);
+
// typedef window2d W;
// W win;