https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Make the median_fast test pass.
* tests/convert/to_window.cc,
* tests/win/cuboid3d.cc,
* tests/win/rectangle2d.cc,
* mln/core/w_window.hh,
* mln/core/window.hh,
* mln/core/dpoints_pixter.hh,
* mln/core/internal/dpoints_base.hh,
* mln/convert/to_p_array.hh,
* sandbox/geraud/dmap.cc,
* sandbox/geraud/cs2d/dbl_neighb.hh (ndpoints): Update to...
(size): ...its new name.
* mln/core/window.hh (has): New method.
* mln/core/dpoints_pixter.hh (p_ref): Use get_adr.
* mln/level/fast_median.hh (int, median): Replace by...
(def::coord, median_h): ...this.
Update.
* mln/geom/shift.hh: Rewrite.
* mln/set/diff.hh: Rewrite without std::set.
* mln/win/rectangle2d.hh (typedef): Import super ones.
mln/convert/to_p_array.hh | 2 +-
mln/core/dpoints_pixter.hh | 22 ++++++++++++----------
mln/core/internal/dpoints_base.hh | 8 ++++----
mln/core/w_window.hh | 30 +++++++++++++++---------------
mln/core/window.hh | 13 +++++++++++--
mln/geom/shift.hh | 14 +++++++-------
mln/level/fast_median.hh | 14 ++++++++------
mln/set/diff.hh | 31 ++++++++++++++++++-------------
mln/win/rectangle2d.hh | 6 ++++++
sandbox/geraud/cs2d/dbl_neighb.hh | 4 ++--
sandbox/geraud/dmap.cc | 2 +-
tests/convert/to_window.cc | 4 ++--
tests/win/cuboid3d.cc | 2 +-
tests/win/rectangle2d.cc | 2 +-
14 files changed, 89 insertions(+), 65 deletions(-)
Index: tests/convert/to_window.cc
--- tests/convert/to_window.cc (revision 2241)
+++ tests/convert/to_window.cc (working copy)
@@ -47,8 +47,8 @@
void test(window2d ref, window2d cmp)
{
- mln_assertion(ref.ndpoints() == cmp.ndpoints());
- for (unsigned i = 0; i < ref.ndpoints(); ++i)
+ mln_assertion(ref.size() == cmp.size());
+ for (unsigned i = 0; i < ref.size(); ++i)
mln_assertion(ref.dp(i) == cmp.dp(i));
}
Index: tests/win/cuboid3d.cc
--- tests/win/cuboid3d.cc (revision 2241)
+++ tests/win/cuboid3d.cc (working copy)
@@ -48,7 +48,7 @@
mln_assertion(cuboid.is_centered());
mln_assertion(cuboid.is_symmetric());
mln_assertion(cuboid == geom::sym(cuboid));
- mln_assertion(cuboid.ndpoints() == d * h * w);
+ mln_assertion(cuboid.size() == d * h * w);
mln_assertion(cuboid.delta() == 3);
Index: tests/win/rectangle2d.cc
--- tests/win/rectangle2d.cc (revision 2241)
+++ tests/win/rectangle2d.cc (working copy)
@@ -48,7 +48,7 @@
mln_assertion(rec.is_centered());
mln_assertion(rec.is_symmetric());
mln_assertion(rec == geom::sym(rec));
- mln_assertion(rec.ndpoints() == h * w);
+ mln_assertion(rec.size() == h * w);
mln_assertion(rec.delta() == 2);
Index: mln/core/w_window.hh
--- mln/core/w_window.hh (revision 2241)
+++ mln/core/w_window.hh (working copy)
@@ -95,7 +95,7 @@
const D& dp(unsigned i) const;
/// Give the number of delta-points.
- unsigned ndpoints() const;
+ unsigned size() const;
/// Give access to the vector of delta-points.
const std::vector<D>& vect() const;
@@ -191,18 +191,18 @@
const D&
w_window<D,W>::dp(unsigned i) const
{
- mln_precondition(i < win_.ndpoints());
- mln_invariant(wei_.size() == win_.ndpoints());
+ mln_precondition(i < win_.size());
+ mln_invariant(wei_.size() == win_.size());
return win_.dp(i);
}
template <typename D, typename W>
inline
unsigned
- w_window<D,W>::ndpoints() const
+ w_window<D,W>::size() const
{
- mln_invariant(wei_.size() == win_.ndpoints());
- return win_.ndpoints();
+ mln_invariant(wei_.size() == win_.size());
+ return win_.size();
}
template <typename D, typename W>
@@ -227,7 +227,7 @@
w_window<D,W>::w(unsigned i) const
{
mln_precondition(i < wei_.size());
- mln_invariant(wei_.size() == win_.ndpoints());
+ mln_invariant(wei_.size() == win_.size());
return wei_[i];
}
@@ -236,7 +236,7 @@
w_window<D,W>&
w_window<D,W>::insert(const W& w, const D& d)
{
- mln_invariant(wei_.size() == win_.ndpoints());
+ mln_invariant(wei_.size() == win_.size());
mln_precondition(! win_.has(d));
if (w == W(0)) // FIXME: Implicit restriction "W scalar"...
@@ -245,7 +245,7 @@
// memorization: d_i -> w_i
std::map<D, W> memo_wei_;
- for (unsigned i = 0; i < win_.ndpoints(); ++i)
+ for (unsigned i = 0; i < win_.size(); ++i)
memo_wei_[win_.dp(i)] = wei_[i];
// insertion of d and w:
@@ -253,11 +253,11 @@
memo_wei_[d] = w;
// re-mapping: w_i <- d_i
- wei_.resize(win_.ndpoints());
- for (unsigned i = 0; i < win_.ndpoints(); ++i)
+ wei_.resize(win_.size());
+ for (unsigned i = 0; i < win_.size(); ++i)
wei_[i] = memo_wei_[win_.dp(i)];
- mln_invariant(wei_.size() == win_.ndpoints());
+ mln_invariant(wei_.size() == win_.size());
return *this;
}
@@ -267,7 +267,7 @@
w_window<D,W>::sym()
{
w_window<D,W> tmp;
- for (unsigned i = 0; i < this->ndpoints(); ++i)
+ for (unsigned i = 0; i < this->size(); ++i)
tmp.insert(this->w(i), - this->dp(i));
*this = tmp;
return *this;
@@ -280,7 +280,7 @@
std::ostream& operator<<(std::ostream& ostr, const
w_window<D,W>& w_win)
{
ostr << '[';
- for (unsigned i = 0; i < w_win.win().ndpoints(); ++i)
+ for (unsigned i = 0; i < w_win.win().size(); ++i)
ostr << w_win.vect()[i] << ':' << w_win.w(i) <<
' ';
return ostr << ']';
}
@@ -289,7 +289,7 @@
inline
bool operator==(const w_window<D,Wl>& lhs, const w_window<D,Wr>&
rhs)
{
- if (lhs.ndpoints() != rhs.ndpoints())
+ if (lhs.size() != rhs.size())
return false;
if (lhs.win() != rhs.win())
return false;
Index: mln/core/window.hh
--- mln/core/window.hh (revision 2241)
+++ mln/core/window.hh (working copy)
@@ -119,10 +119,11 @@
*/
unsigned delta() const;
- // Give the \p i-th delta-point.
+ /// Give the \p i-th delta-point.
const D& dp(unsigned i) const;
-
+ /// Test if \p dp is in this window definition.
+ bool has(const D& dp) const;
/// Insert a delta-point \p dp.
window<D>& insert(const D& dp);
@@ -254,6 +255,14 @@
template <typename D>
inline
+ bool
+ window<D>::has(const D& dp) const
+ {
+ return dps_.has(dp);
+ }
+
+ template <typename D>
+ inline
const std::vector<D>&
window<D>::std_vector() const
{
Index: mln/core/dpoints_pixter.hh
--- mln/core/dpoints_pixter.hh (revision 2241)
+++ mln/core/dpoints_pixter.hh (working copy)
@@ -190,7 +190,7 @@
private:
/// \brief Offset of each delta-point.
///
- /// offset_[dps.ndpoints() - 1] is absolute, while other offsets
+ /// offset_[dps.size() - 1] is absolute, while other offsets
/// are relative (i.e., offset_[i] is the memory difference to go
/// from pixel i+1 to pixel i.
std::vector<int> offset_;
@@ -225,7 +225,8 @@
: super_(image)
{
mln_precondition(image.has_data());
- p_ref_ = & exact(p_ref).to_site();
+ internal::get_adr(p_ref_, p_ref);
+// p_ref_ = & exact(p_ref).to_site();
value_ref_ = 0;
init_(dps);
}
@@ -263,12 +264,12 @@
void
dpoints_fwd_pixter<I>::init_(const Dps& dps)
{
- for (unsigned i = 0; i < dps.ndpoints(); ++i)
+ for (unsigned i = 0; i < dps.size(); ++i)
offset_.push_back(this->image_.delta_index(dps.dp(i)));
// offset_[0] is absolute
// other offsets are relative:
- if (dps.ndpoints() > 1)
- for (unsigned i = dps.ndpoints() - 1; i > 0; --i)
+ if (dps.size() > 1)
+ for (unsigned i = dps.size() - 1; i > 0; --i)
offset_[i] -= offset_[i - 1];
invalidate();
}
@@ -336,7 +337,8 @@
: super_(image)
{
mln_precondition(image.has_data());
- p_ref_ = & exact(p_ref).to_site();
+ internal::get_adr(p_ref_, p_ref);
+// p_ref_ = & exact(p_ref).to_site();
value_ref_ = 0;
init_(dps);
}
@@ -374,12 +376,12 @@
void
dpoints_bkd_pixter<I>::init_(const Dps& dps)
{
- for (unsigned i = 0; i < dps.ndpoints(); ++i)
+ for (unsigned i = 0; i < dps.size(); ++i)
offset_.push_back(this->image_.delta_index(dps.dp(i)));
- // offset_[ndpoints() - 1] is absolute
+ // offset_[size() - 1] is absolute
// other offsets are relative:
- if (dps.ndpoints() > 1)
- for (unsigned i = 0; i < dps.ndpoints() - 1; ++i)
+ if (dps.size() > 1)
+ for (unsigned i = 0; i < dps.size() - 1; ++i)
offset_[i] -= offset_[i + 1];
invalidate();
}
Index: mln/core/internal/dpoints_base.hh
--- mln/core/internal/dpoints_base.hh (revision 2241)
+++ mln/core/internal/dpoints_base.hh (working copy)
@@ -92,7 +92,7 @@
unsigned delta() const;
/// Give the number of delta-points.
- unsigned ndpoints() const;
+ unsigned size() const;
/// Test if the delta-point \p dp belongs to the window.
bool has(const D& dp) const;
@@ -149,7 +149,7 @@
template <typename D, typename E>
inline
unsigned
- dpoints_base_<D,E>::ndpoints() const
+ dpoints_base_<D,E>::size() const
{
return win_.size();
}
@@ -159,7 +159,7 @@
const D&
dpoints_base_<D,E>::dp(unsigned i) const
{
- mln_precondition(i < ndpoints());
+ mln_precondition(i < size());
return win_.dp(i);
}
@@ -184,7 +184,7 @@
bool
dpoints_base_<D,E>::has(const D& dp) const
{
- return win_.dps_hook_().has(dp);
+ return win_.has(dp);
}
template <typename D, typename E>
Index: mln/level/fast_median.hh
--- mln/level/fast_median.hh (revision 2241)
+++ mln/level/fast_median.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 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
@@ -31,11 +31,13 @@
/*! \file mln/level/fast_median.hh
*
* \brief Fast Median filtering of an image.
+ *
+ * \todo There are implicit assumptions about input being 2D!!!
*/
# include <mln/core/concept/image.hh>
# include <mln/core/alias/window2d.hh>
-# include <mln/accu/median.hh>
+# include <mln/accu/median_h.hh>
# include <mln/geom/shift.hh>
# include <mln/geom/min_col.hh>
# include <mln/geom/min_row.hh>
@@ -79,7 +81,7 @@
mln_precondition(input.has_data());
mln_precondition(output.has_data());
- int
+ def::coord
min_row = geom::min_row(input), max_row = geom::max_row(input),
min_col = geom::min_col(input), max_col = geom::max_col(input);
@@ -91,7 +93,7 @@
win_bot = set::diff(win, geom::shift(win, up)),
win_top = set::diff(geom::shift(win, up), win);
- accu::median<mln_vset(I)> med(input.values());
+ accu::median_h<mln_value(I)> med;
// initialization
@@ -109,8 +111,8 @@
med.take(q.val());
}
- int& row = p.row();
- int& col = p.col();
+ def::coord& row = p.row();
+ def::coord& col = p.col();
bool fwd = true;
mln_assertion(p.col() == min_col);
Index: mln/convert/to_p_array.hh
--- mln/convert/to_p_array.hh (revision 2241)
+++ mln/convert/to_p_array.hh (working copy)
@@ -82,7 +82,7 @@
const mln_psite(W)& p)
{
p_array<mln_psite(W)> v;
- v.reserve(exact(win).ndpoints());
+ v.reserve(exact(win).size());
mln_qiter(W) q(win, p);
for_all(q)
v.append(q);
Index: mln/geom/shift.hh
--- mln/geom/shift.hh (revision 2241)
+++ mln/geom/shift.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 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
@@ -34,7 +34,6 @@
*/
# include <mln/core/window.hh>
-# include <mln/convert/to.hh>
@@ -55,13 +54,14 @@
template <typename W>
inline
window<mln_dpsite(W)>
- shift(const Window<W>& win, const mln_dpsite(W)& dp)
+ shift(const Window<W>& win_, const mln_dpsite(W)& dp)
{
- typedef mln_site(W) P;
+ const W& win = exact(win_);
+
window<mln_dpsite(W)> tmp;
- mln_qiter(W) q(win, P::origin);
- for_all(q)
- tmp.insert(convert::to(q) + dp);
+ unsigned n = win.size();
+ for (unsigned i = 0; i < n; ++i)
+ tmp.insert(win.dp(i) + dp);
return tmp;
}
Index: mln/set/diff.hh
--- mln/set/diff.hh (revision 2241)
+++ mln/set/diff.hh (working copy)
@@ -54,7 +54,7 @@
* \relates mln::Window
*/
template <typename Wl, typename Wr>
- window<mln_dpoint(Wl)>
+ window<mln_dpsite(Wl)>
diff(const Window<Wl>& lhs, const Window<Wr>& rhs);
/*! \brief Set theoretic difference of \p lhs and \p rhs.
@@ -70,21 +70,26 @@
template <typename Wl, typename Wr>
inline
- window<mln_dpoint(Wl)>
- diff(const Window<Wl>& lhs, const Window<Wr>& rhs)
+ window<mln_dpsite(Wl)>
+ diff(const Window<Wl>& lhs_, const Window<Wr>& rhs_)
{
trace::entering("set::diff");
- mln::metal::equal<mln_dpoint(Wl), mln_dpoint(Wr)>::check();
- typedef mln_dpoint(Wl) D;
- std::set<D>
- sl = convert::to_std_set(lhs),
- sr = convert::to_std_set(rhs),
- s;
- std::set_difference(sl.begin(), sl.end(),
- sr.begin(), sr.end(),
- std::inserter(s, s.begin()));
+ mlc_equal(mln_dpsite(Wl), mln_dpsite(Wr))::check();
+
+ const Wl& lhs = exact(lhs_);
+ const Wr& rhs = exact(rhs_);
+ window<mln_dpsite(Wl)> tmp;
+
+ const unsigned n = lhs.size();
+ for (unsigned i = 0; i < n; ++i)
+ {
+ if (rhs.has(lhs.dp(i)))
+ continue;
+ tmp.insert(lhs.dp(i));
+ }
+
trace::exiting("set::diff");
- return convert::to_window(s);
+ return tmp;
}
template <typename Wl, typename Wr>
Index: mln/win/rectangle2d.hh
--- mln/win/rectangle2d.hh (revision 2241)
+++ mln/win/rectangle2d.hh (working copy)
@@ -60,6 +60,12 @@
struct rectangle2d : public internal::window_base< dpoint2d, rectangle2d >,
public internal::dpoints_base_< dpoint2d, rectangle2d >
{
+ typedef internal::dpoints_base_< dpoint2d, rectangle2d > super_;
+
+ typedef super_::site site;
+ typedef super_::psite psite;
+ typedef super_::dpsite dpsite;
+
/*! \brief Constructor.
*
* \param[in] height Height of the rectangle2d.
Index: sandbox/geraud/dmap.cc
--- sandbox/geraud/dmap.cc (revision 2241)
+++ sandbox/geraud/dmap.cc (working copy)
@@ -29,7 +29,7 @@
// Mod determination.
mln_accu_with_(accu::max, unsigned) max;
- for (unsigned i = 0; i < win.ndpoints(); ++i)
+ for (unsigned i = 0; i < win.size(); ++i)
max.take(win.w(i));
unsigned mod = unsigned(max) + 1;
Index: sandbox/geraud/cs2d/dbl_neighb.hh
--- sandbox/geraud/cs2d/dbl_neighb.hh (revision 2241)
+++ sandbox/geraud/cs2d/dbl_neighb.hh (working copy)
@@ -52,7 +52,7 @@
dbl_neighb_& when_true(const Neighborhood<N>& nbh_)
{
const N& nbh = exact(nbh_);
- for (unsigned i = 0; i < nbh.ndpoints(); ++i)
+ for (unsigned i = 0; i < nbh.size(); ++i)
trues.push_back(nbh.dp(i));
return *this;
}
@@ -61,7 +61,7 @@
dbl_neighb_& when_false(const Neighborhood<N>& nbh_)
{
const N& nbh = exact(nbh_);
- for (unsigned i = 0; i < nbh.ndpoints(); ++i)
+ for (unsigned i = 0; i < nbh.size(); ++i)
falses.push_back(nbh.dp(i));
return *this;
}