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
September 2008
- 12 participants
- 359 discussions
* mln/core/complex_iter.hh (mln::internal::complex_iter_<D, E>):
New class.
Use it to factor...
(mln::complex_fwd_iter_<D>, mln::complex_bkd_iter_<D>):
...these.
(operator<<(std::ostream&, const complex_iter_<D, E>&)):
New.
(operator<<(std::ostream&, const complex_fwd_iter_<D>&))
(operator<<(std::ostream&, const complex_bkd_iter_<D>&)):
Remove.
* tests/core/complex.cc: Use clearer names for iterators.
---
milena/ChangeLog | 16 ++
milena/mln/core/complex_iter.hh | 410 ++++++++++++++++++++-------------------
milena/tests/core/complex.cc | 17 +-
3 files changed, 238 insertions(+), 205 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index cd60428..e766670 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,19 @@
+2008-09-12 Roland Levillain <roland(a)lrde.epita.fr>
+
+ Factor iterators on complexes.
+
+ * mln/core/complex_iter.hh (mln::internal::complex_iter_<D, E>):
+ New class.
+ Use it to factor...
+ (mln::complex_fwd_iter_<D>, mln::complex_bkd_iter_<D>):
+ ...these.
+ (operator<<(std::ostream&, const complex_iter_<D, E>&)):
+ New.
+ (operator<<(std::ostream&, const complex_fwd_iter_<D>&))
+ (operator<<(std::ostream&, const complex_bkd_iter_<D>&)):
+ Remove.
+ * tests/core/complex.cc: Use clearer names for iterators.
+
2008-09-11 Roland Levillain <roland(a)lrde.epita.fr>
Factor iterators on p_complexes with iterator on complexes.
diff --git a/milena/mln/core/complex_iter.hh b/milena/mln/core/complex_iter.hh
index 7588a32..4aa9b99 100644
--- a/milena/mln/core/complex_iter.hh
+++ b/milena/mln/core/complex_iter.hh
@@ -31,40 +31,118 @@
/// \file mln/core/complex_iter.hh
/// \brief Definition of forward and backward iterators on complexes.
-
# include <limits>
# include <mln/core/concept/iterator.hh>
# include <mln/core/complex.hh>
-
-// Factor complex_fwd_iter_<D> and complex_bkd_iter_<D>?
-
namespace mln
{
// Fwd decls.
template <unsigned D> class complex;
+ /*--------------------------------.
+ | internal::complex_iter_<D, E>. |
+ `--------------------------------*/
+
+ namespace internal
+ {
+ /// \brief Factoring classe for iterators on all the faces of
+ /// a mln::complex<D>.
+ ///
+ /// \arg \p D The dimension of the complex this iterator belongs to.
+ /// \arg \p E The type exact type of the iterator.
+ template <unsigned D, typename E>
+ class complex_iter_ : public Iterator<E>
+ {
+ typedef complex_iter_<D, E> self_;
+
+ public:
+ typedef any_face_handle<D> face;
+
+ /// Construction and assignment.
+ /// \{
+ complex_iter_();
+ /* FIXME: Keep this non-const? See a (big) comment about this in
+ milena/tests/complex_image.cc. */
+ complex_iter_(complex<D>& c);
+ complex_iter_(const self_& rhs);
+ self_& operator= (const self_& rhs);
+ /// \}
+
+ /// Manipulation.
+ /// \{
+ /// Test if the iterator is valid.
+ bool is_valid() const;
+ /// Invalidate the iterator.
+ void invalidate();
+ /// \}
+
+ /// Conversion and accessors.
+ /// \{
+ /// Reference to the corresponding any-face handle.
+ const face& to_face () const;
+ /// Convert the iterator into an any-face handle.
+ operator face() const;
+ /// \}
+
+ protected:
+ /// The face handle this iterator is pointing to.
+ face face_;
+
+ private:
+ /// \brief An invalid value for both the dimension and the id of
+ /// the face.
+ ///
+ /// Use a function instead of a static constant, since `static'
+ /// variables needs to be compiled once, which requires a compiled
+ /// library to avoid duplicate symbols, which is something that
+ /// was not really planned in Milena. A function tagged `inlined'
+ /// can appear multiple times in a program, and solves this
+ /// problem. We rely on the compiler to inline this call.
+ ///
+ /// Of course, we could have used UINT_MAX, but it is not very
+ /// C++.
+ unsigned invalid_unsigned_() const;
+ };
+
+
+ /* FIXME: This hand-made delegation is painful. We should rely on
+ the general mechanism provided by Point_Site. But then again, we
+ need to refine/adjust the interface of Point_Site w.r.t. the
+ mandatory conversions to points. */
+ template <unsigned D, typename E>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const complex_iter_<D, E>& p);
+
+ } // end of mln::internal
+
/*-----------------------.
| complex_fwd_iter_<D>. |
`-----------------------*/
- /// \brief Forward iterator on all the faces of mln::complex<D>.
+ /// \brief Forward iterator on all the faces of a mln::complex<D>.
+ ///
+ /// \arg \p D The dimension of the complex this iterator belongs to.
template <unsigned D>
- class complex_fwd_iter_ : public Iterator< complex_fwd_iter_<D> >
+ class complex_fwd_iter_
+ : public internal::complex_iter_< D, complex_fwd_iter_<D> >
{
typedef complex_fwd_iter_<D> self_;
+ typedef internal::complex_iter_< D, self_ > super_;
public:
- typedef any_face_handle<D> face;
+ using super_::is_valid;
+ using super_::invalidate;
+ public:
/// Construction and assignment.
/// \{
complex_fwd_iter_();
- /* FIXME: Keep this non-const? See a (big) comment about this in
- milena/tests/complex_image.cc. */
+ // FIXME: See above (internal::complex_iter_'s default ctor).
complex_fwd_iter_(complex<D>& c);
complex_fwd_iter_(const self_& rhs);
self_& operator= (const self_& rhs);
@@ -77,72 +155,39 @@ namespace mln
void set_cplx(complex<D>& c);
/// Test if the iterator is valid.
- bool is_valid() const;
- /// Invalidate the iterator.
- void invalidate();
- /// Start an iteration.
void start();
-
/// Go to the next point.
void next_();
/// \}
- /// Conversion and accessors.
- /// \{
- /// Reference to the corresponding any-face handle.
- const face& to_face () const;
- /// Convert the iterator into an any-face handle.
- operator face() const;
- /// \}
-
private:
- /// The face handle this iterator is pointing to.
- face face_;
-
- /// \brief An invalid value for both the dimension and the id of
- /// the face.
- ///
- /// Use a function instead of a static constant, since `static'
- /// variables needs to be compiled once, which requires a compiled
- /// library to avoid duplicate symbols, which is something that
- /// was not really planned in Milena. A function tagged `inlined'
- /// can appear multiple times in a program, and solves this
- /// problem. We rely on the compiler to inline this call.
- ///
- /// Of course, we could have used UINT_MAX, but it is not very
- /// C++.
- unsigned invalid_unsigned_() const;
+ using super_::face_;
};
- /* FIXME: This hand-made delegation is painful. We should rely on
- the general mechanism provided by Point_Site. But then again, we
- need to refine/adjust the interface of Point_Site w.r.t. the
- mandatory conversions to points. */
- template <unsigned D>
- inline
- std::ostream&
- operator<<(std::ostream& ostr, const complex_fwd_iter_<D>& p);
-
-
/*-----------------------.
| complex_bkd_iter_<D>. |
`-----------------------*/
- /// \brief Backward iterator on all the faces of mln::complex<D>.
+ /// \brief Backward iterator on all the faces of a mln::complex<D>.
+ ///
+ /// \arg \p D The dimension of the complex this iterator belongs to.
template <unsigned D>
- class complex_bkd_iter_ : public Iterator< complex_bkd_iter_<D> >
+ class complex_bkd_iter_
+ : public internal::complex_iter_< D, complex_bkd_iter_<D> >
{
typedef complex_bkd_iter_<D> self_;
+ typedef internal::complex_iter_< D, self_ > super_;
public:
- typedef any_face_handle<D> face;
+ using super_::is_valid;
+ using super_::invalidate;
+ public:
/// Construction and assignment.
/// \{
complex_bkd_iter_();
- /* FIXME: Keep this non-const? See a (big) comment about this in
- milena/tests/complex_image.cc. */
+ // FIXME: See above (internal::complex_iter_'s default ctor).
complex_bkd_iter_(complex<D>& c);
complex_bkd_iter_(const self_& rhs);
self_& operator= (const self_& rhs);
@@ -154,57 +199,126 @@ namespace mln
// FIXME: Same comment as the ctor above.
void set_cplx(complex<D>& c);
- /// Test if the iterator is valid.
- bool is_valid() const;
- /// Invalidate the iterator.
- void invalidate();
/// Start an iteration.
void start();
-
/// Go to the next point.
void next_();
/// \}
- /// Conversion and accessors.
- /// \{
- /// Reference to the corresponding any-face handle.
- const face& to_face () const;
- /// Convert the iterator into an any-face handle.
- operator face() const;
- /// \}
-
private:
- /// The face handle this iterator is pointing to.
- face face_;
-
- /// \brief An invalid value for both the dimension and the id of
- /// the face.
- ///
- /// Use a function instead of a static constant, since `static'
- /// variables needs to be compiled once, which requires a compiled
- /// library to avoid duplicate symbols, which is something that
- /// was not really planned in Milena. A function tagged `inlined'
- /// can appear multiple times in a program, and solves this
- /// problem. We rely on the compiler to inline this call.
- ///
- /// Of course, we could have used UINT_MAX, but it is not very
- /// C++.
- unsigned invalid_unsigned_() const;
+ using super_::face_;
};
- /* FIXME: This hand-made delegation is painful. We should rely on
- the general mechanism provided by Point_Site. But then again, we
- need to refine/adjust the interface of Point_Site w.r.t. the
- mandatory conversions to points. */
- template <unsigned D>
- inline
- std::ostream&
- operator<<(std::ostream& ostr, const complex_bkd_iter_<D>& p);
+# ifndef MLN_INCLUDE_ONLY
+ /*--------------------------------.
+ | internal::complex_iter_<D, E>. |
+ `--------------------------------*/
+
+ namespace internal
+ {
+
+ template <unsigned D, typename E>
+ inline
+ complex_iter_<D, E>::complex_iter_()
+ {
+ // Invalidate face_.
+ invalidate();
+ }
+
+ template <unsigned D, typename E>
+ inline
+ complex_iter_<D, E>::complex_iter_(complex<D>& c)
+ {
+ face_.set_cplx(c);
+ // Invalidate face_.
+ invalidate();
+ }
+
+ template <unsigned D, typename E>
+ inline
+ complex_iter_<D, E>::complex_iter_(const complex_iter_<D, E>& rhs)
+ : face_(rhs.face_)
+ {
+ }
+
+ template <unsigned D, typename E>
+ inline
+ complex_iter_<D, E>&
+ complex_iter_<D, E>::operator=(const complex_iter_<D, E>& rhs)
+ {
+ if (&rhs == this)
+ return *this;
+ face_ = rhs.face_;
+ return *this;
+ }
+
+ template <unsigned D, typename E>
+ inline
+ bool
+ complex_iter_<D, E>::is_valid() const
+ {
+ return face_.is_valid();
+ }
+
+ template <unsigned D, typename E>
+ inline
+ void
+ complex_iter_<D, E>::invalidate()
+ {
+ face_.set_n(invalid_unsigned_());
+ face_.set_face_id(invalid_unsigned_());
+ }
+
+ template <unsigned D, typename E>
+ inline
+ const any_face_handle<D>&
+ complex_iter_<D, E>::to_face() const
+ {
+ return face_;
+ }
+
+ template <unsigned D, typename E>
+ inline
+ complex_iter_<D, E>::operator any_face_handle<D>() const
+ {
+ mln_precondition(is_valid());
+ return face_;
+ }
+
+ template <unsigned D, typename E>
+ unsigned
+ complex_iter_<D, E>::invalid_unsigned_() const
+ {
+ return std::numeric_limits<unsigned>::max();
+ }
+
+ template <unsigned D, typename E>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const complex_iter_<D, E>& p)
+ {
+ /* FIXME: We should use p.to_face() here, but as it lacks the
+ precondition the conversion operator has, so we use the latter.
+
+ We should
+ - rename `to_face' as `to_face_';
+ - write a new `to_face' routine checking the validity of the
+ iterator;
+ - have the conversion operator to face use this new `to_face'
+ routine;
+ - adjust former clients of `to_face'
+
+ This is a general remark that applies to all iterators of
+ Milena. */
+ any_face_handle<D> f = p;
+ return ostr << "(dim = " << f.n() << ", id = " << f.face_id() << ')';
+ }
+
+ } // end of mln::internal
-# ifndef MLN_INCLUDE_ONLY
/*-----------------------.
| complex_fwd_iter_<D>. |
@@ -213,8 +327,8 @@ namespace mln
template <unsigned D>
inline
complex_fwd_iter_<D>::complex_fwd_iter_()
+ : super_()
{
- invalidate();
}
template <unsigned D>
@@ -228,7 +342,7 @@ namespace mln
template <unsigned D>
inline
complex_fwd_iter_<D>::complex_fwd_iter_(const complex_fwd_iter_<D>& rhs)
- : face_(rhs.face_)
+ : super_(rhs)
{
}
@@ -239,7 +353,7 @@ namespace mln
{
if (&rhs == this)
return *this;
- face_ = rhs.face_;
+ super_::operator=(rhs);
return *this;
}
@@ -255,23 +369,6 @@ namespace mln
template <unsigned D>
inline
- bool
- complex_fwd_iter_<D>::is_valid() const
- {
- return face_.is_valid();
- }
-
- template <unsigned D>
- inline
- void
- complex_fwd_iter_<D>::invalidate()
- {
- face_.set_n(invalid_unsigned_());
- face_.set_face_id(invalid_unsigned_());
- }
-
- template <unsigned D>
- inline
void
complex_fwd_iter_<D>::start()
{
@@ -311,49 +408,18 @@ namespace mln
}
}
- template <unsigned D>
- inline
- const any_face_handle<D>&
- complex_fwd_iter_<D>::to_face() const
- {
- return face_;
- }
-
- template <unsigned D>
- inline
- complex_fwd_iter_<D>::operator any_face_handle<D>() const
- {
- mln_precondition(is_valid());
- return face_;
- }
-
- template <unsigned D>
- unsigned
- complex_fwd_iter_<D>::invalid_unsigned_() const
- {
- return std::numeric_limits<unsigned>::max();
- }
-
-
- template <unsigned D>
- inline
- std::ostream&
- operator<<(std::ostream& ostr, const complex_fwd_iter_<D>& p)
- {
- return ostr << "(dim = " << p.to_face().n()
- << ", id = " << p.to_face().face_id() << ')';
- }
-
/*-----------------------.
| complex_bkd_iter_<D>. |
`-----------------------*/
+ // FIXME: Resume here.
+
template <unsigned D>
inline
complex_bkd_iter_<D>::complex_bkd_iter_()
+ : super_()
{
- invalidate();
}
template <unsigned D>
@@ -367,7 +433,7 @@ namespace mln
template <unsigned D>
inline
complex_bkd_iter_<D>::complex_bkd_iter_(const complex_bkd_iter_<D>& rhs)
- : face_(rhs.face_)
+ : super_(rhs)
{
}
@@ -378,7 +444,7 @@ namespace mln
{
if (&rhs == this)
return *this;
- face_ = rhs.face_;
+ super_::operator=(rhs);
return *this;
}
@@ -394,23 +460,6 @@ namespace mln
template <unsigned D>
inline
- bool
- complex_bkd_iter_<D>::is_valid() const
- {
- return face_.is_valid();
- }
-
- template <unsigned D>
- inline
- void
- complex_bkd_iter_<D>::invalidate()
- {
- face_.set_n(invalid_unsigned_());
- face_.set_face_id(invalid_unsigned_());
- }
-
- template <unsigned D>
- inline
void
complex_bkd_iter_<D>::start()
{
@@ -450,39 +499,6 @@ namespace mln
}
}
- template <unsigned D>
- inline
- const any_face_handle<D>&
- complex_bkd_iter_<D>::to_face() const
- {
- return face_;
- }
-
- template <unsigned D>
- inline
- complex_bkd_iter_<D>::operator any_face_handle<D>() const
- {
- mln_precondition(is_valid());
- return face_;
- }
-
- template <unsigned D>
- unsigned
- complex_bkd_iter_<D>::invalid_unsigned_() const
- {
- return std::numeric_limits<unsigned>::max();
- }
-
-
- template <unsigned D>
- inline
- std::ostream&
- operator<<(std::ostream& ostr, const complex_bkd_iter_<D>& p)
- {
- return ostr << "(dim = " << p.to_face().n()
- << ", id = " << p.to_face().face_id() << ')';
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of mln
diff --git a/milena/tests/core/complex.cc b/milena/tests/core/complex.cc
index 1bacd6e..91bae55 100644
--- a/milena/tests/core/complex.cc
+++ b/milena/tests/core/complex.cc
@@ -115,18 +115,19 @@ int main()
| Iteration. |
`------------*/
- // Iterators on a complex (not complex_image), or more precisely on
- // the faces of a complex.
+ // FIXME: Possibly split this test (create a test for iterators).
- mln_fwd_citer_(complex<D>) ff(c);
- for_all(ff)
- std::cout << ff << std::endl;
+ // Iterators on a complex (not complex_image), or more precisely on
+ // (all) the faces of complex C.
+ mln_fwd_citer_(complex<D>) fwd_f(c);
+ for_all(fwd_f)
+ std::cout << fwd_f << std::endl;
std::cout << std::endl;
- mln_bkd_citer_(complex<D>) bf(c);
- for_all(bf)
- std::cout << bf << std::endl;
+ mln_bkd_citer_(complex<D>) bkd_f(c);
+ for_all(bkd_f)
+ std::cout << bkd_f << std::endl;
/* FIXME: Exercice more iterators (see
milena/tests/core/complex_image.cc) and ticket #162
--
1.6.0.1
1
0
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;
}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
ChangeLog:
2008-09-12 Guillaume Lazzara <z(a)lrde.epita.fr>
Add missing init_().
* milena/mln/core/image/cast_image.hh,
* milena/mln/core/image/decorated_image.hh: add missing init_().
---
cast_image.hh | 15 +++++++++++----
decorated_image.hh | 14 ++++++++++++++
2 files changed, 25 insertions(+), 4 deletions(-)
Index: branches/cleanup-2008/milena/mln/core/image/cast_image.hh
===================================================================
--- branches/cleanup-2008/milena/mln/core/image/cast_image.hh (revision 2240)
+++ branches/cleanup-2008/milena/mln/core/image/cast_image.hh (revision 2241)
@@ -95,10 +95,11 @@
/// Skeleton.
typedef cast_image_< tag::value_<T>, tag::image_<I> > skeleton;
-
/// Constructor.
cast_image_(const Image<I>& ima);
+ /// Initialize an empty image.
+ void init_(const Image<I>& ima);
/// Read-only access of pixel value at point site \p p.
T operator()(const mln_psite(I)& p) const;
@@ -108,7 +109,6 @@
};
-
template <typename T, typename I>
cast_image_<T,I>
cast_image(const Image<I>& ima)
@@ -119,7 +119,6 @@
}
-
# ifndef MLN_INCLUDE_ONLY
@@ -137,7 +136,6 @@
} // end of namespace mln::internal
-
// cast_image_<T,I>
template <typename T, typename I>
@@ -150,6 +148,15 @@
template <typename T, typename I>
inline
+ void
+ cast_image_<T,I>::init_(const Image<I>& ima)
+ {
+ mln_precondition(exact(ima).has_data());
+ this->data_ = new internal::data<cast_image_<T,I> >(exact(ima));
+ }
+
+ template <typename T, typename I>
+ inline
T
cast_image_<T,I>::operator()(const mln_psite(I)& p) const
{
Index: branches/cleanup-2008/milena/mln/core/image/decorated_image.hh
===================================================================
--- branches/cleanup-2008/milena/mln/core/image/decorated_image.hh (revision 2240)
+++ branches/cleanup-2008/milena/mln/core/image/decorated_image.hh (revision 2241)
@@ -101,6 +101,10 @@
/// Ctors
decorated_image();
decorated_image(I& ima, const D& deco);
+
+ /// Initialize an empty image.
+ void init_(I& ima, const D& deco);
+
/// Dtor
~decorated_image();
@@ -166,6 +170,16 @@
inline
decorated_image<I,D>::decorated_image(I& ima, const D& deco)
{
+ mln_precondition(exact(ima).has_data());
+ this->data_ = new internal::data< decorated_image<I,D> >(ima, deco);
+ }
+
+ template <typename I, typename D>
+ inline
+ void
+ decorated_image<I,D>::init_(I& ima, const D& deco)
+ {
+ mln_precondition(exact(ima).has_data());
this->data_ = new internal::data< decorated_image<I,D> >(ima, deco);
}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
ChangeLog:
2008-09-12 Guillaume Lazzara <z(a)lrde.epita.fr>
Fix few tests.
* milena/mln/core/site_set/p_complex.hh,
* milena/mln/core/site_set/p_complex_piter.hh,
* milena/mln/core/site_set/p_faces.hh,
* milena/mln/core/site_set/p_bgraph_piter.hh,
* milena/mln/core/site_set/p_graph_piter.hh:
remove useless '_' in class names.
* milena/tests/canvas/browsing/directional.cc,
* milena/tests/canvas/browsing/fwd.cc,
* milena/tests/canvas/browsing/snake_fwd.cc: rename point to site.
* milena/mln/core/alias/dpoint2d_h.hh,
* milena/mln/core/alias/point2d_h.hh,
* milena/tests/algebra/h_vec.cc,
* milena/tests/core/alias/point2d.cc,
* milena/tests/core/alias/point1d.cc: Use def::coord instead of int.
* milena/tests/set/diff.cc,
* milena/tests/core/site_set/p_image2d.cc: Update.
---
mln/core/alias/dpoint2d_h.hh | 2 -
mln/core/alias/point2d_h.hh | 2 -
mln/core/site_set/p_bgraph_piter.hh | 4 +-
mln/core/site_set/p_complex.hh | 4 +-
mln/core/site_set/p_complex_piter.hh | 10 +++---
mln/core/site_set/p_faces.hh | 4 +-
mln/core/site_set/p_graph_piter.hh | 9 ++----
tests/algebra/h_vec.cc | 10 +++---
tests/canvas/browsing/directional.cc | 2 -
tests/canvas/browsing/fwd.cc | 2 -
tests/canvas/browsing/snake_fwd.cc | 2 -
tests/core/alias/point1d.cc | 2 -
tests/core/alias/point2d.cc | 2 -
tests/core/site_set/p_image2d.cc | 15 +++++-----
tests/set/diff.cc | 52 +++++++++++++++++------------------
15 files changed, 61 insertions(+), 61 deletions(-)
Index: branches/cleanup-2008/milena/tests/core/site_set/p_image2d.cc
===================================================================
--- branches/cleanup-2008/milena/tests/core/site_set/p_image2d.cc (revision 2239)
+++ branches/cleanup-2008/milena/tests/core/site_set/p_image2d.cc (revision 2240)
@@ -30,19 +30,20 @@
* \brief Tests on mln::p_image2d.
*/
-#include <mln/core/p_image2d.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/site_set/p_image.hh>
int main()
{
using namespace mln;
trace::quiet = false;
- p_image2d<point2d> ps(20,20);
- ps
- .insert(make::point2d(6, 9))
- .insert(make::point2d(4, 2))
- .insert(make::point2d(4, 2))
- .insert(make::point2d(5, 1));
+ image2d<bool> ima(box2d(20,20));
+ p_image<image2d<bool> > ps(ima);
+ ps.insert(make::point2d(6, 9));
+ ps.insert(make::point2d(4, 2));
+ ps.insert(make::point2d(4, 2));
+ ps.insert(make::point2d(5, 1));
mln_assertion(ps.nsites() == 3);
ps.remove(make::point2d(5, 1));
Index: branches/cleanup-2008/milena/tests/core/alias/point1d.cc
===================================================================
--- branches/cleanup-2008/milena/tests/core/alias/point1d.cc (revision 2239)
+++ branches/cleanup-2008/milena/tests/core/alias/point1d.cc (revision 2240)
@@ -43,7 +43,7 @@
// assignment
p[0] = 4;
- algebra::vec<1,int> v = p;
+ algebra::vec<1,def::coord> v = p;
std::cout << v << std::endl;
p.ind() += 1;
Index: branches/cleanup-2008/milena/tests/core/alias/point2d.cc
===================================================================
--- branches/cleanup-2008/milena/tests/core/alias/point2d.cc (revision 2239)
+++ branches/cleanup-2008/milena/tests/core/alias/point2d.cc (revision 2240)
@@ -74,5 +74,5 @@
for (unsigned i = 0; i < p.dim; ++i)
mln_assertion(q[i] == 0);
- std::cout << 3.4 * algebra::vec<2, int>(p) << std::endl;
+ std::cout << 3.4 * algebra::vec<2, def::coord>(p) << std::endl;
}
Index: branches/cleanup-2008/milena/tests/set/diff.cc
===================================================================
--- branches/cleanup-2008/milena/tests/set/diff.cc (revision 2239)
+++ branches/cleanup-2008/milena/tests/set/diff.cc (revision 2240)
@@ -39,20 +39,20 @@
{
window<dpoint2d> win1;
- win1
- .insert( 2, 7)
- .insert( 2, 1)
- .insert(-4, 0)
- .insert( 0, 0)
- .insert( 1, 1)
- .insert( 6, 5);
+ win1.insert( 2, 7);
+ win1.insert( 2, 1);
+ win1.insert(-4, 0);
+ win1.insert( 0, 0);
+ win1.insert( 1, 1);
+ win1.insert( 6, 5);
+
window<dpoint2d> win2;
- win2
- .insert( 2, 7)
- .insert(-2, 1)
- .insert(-4, 0)
- .insert( 1,-1)
- .insert( 6, 5);
+ win2.insert( 2, 7);
+ win2.insert(-2, 1);
+ win2.insert(-4, 0);
+ win2.insert( 1,-1);
+ win2.insert( 6, 5);
+
window<dpoint2d> win3 = set::diff(win1, win2);
mln_assertion(win3.has(dpoint2d( 2, 1)));
mln_assertion(win3.has(dpoint2d( 0, 0)));
@@ -66,20 +66,20 @@
{
p_set<point2d> pst1;
- pst1
- .insert(point2d( 2, 7))
- .insert(point2d( 2, 1))
- .insert(point2d(-4, 0))
- .insert(point2d( 0, 0))
- .insert(point2d( 1, 1))
- .insert(point2d( 6, 5));
+ pst1.insert(point2d( 2, 7));
+ pst1.insert(point2d( 2, 1));
+ pst1.insert(point2d(-4, 0));
+ pst1.insert(point2d( 0, 0));
+ pst1.insert(point2d( 1, 1));
+ pst1.insert(point2d( 6, 5));
+
p_set<point2d> pst2;
- pst2
- .insert(point2d( 2, 7))
- .insert(point2d(-2, 1))
- .insert(point2d(-4, 0))
- .insert(point2d( 1,-1))
- .insert(point2d( 6, 5));
+ pst2.insert(point2d( 2, 7));
+ pst2.insert(point2d(-2, 1));
+ pst2.insert(point2d(-4, 0));
+ pst2.insert(point2d( 1,-1));
+ pst2.insert(point2d( 6, 5));
+
p_set<point2d> pst3 = set::diff(pst1, pst2);
mln_assertion(pst3.has(point2d( 2, 1)));
mln_assertion(pst3.has(point2d( 0, 0)));
Index: branches/cleanup-2008/milena/tests/algebra/h_vec.cc
===================================================================
--- branches/cleanup-2008/milena/tests/algebra/h_vec.cc (revision 2239)
+++ branches/cleanup-2008/milena/tests/algebra/h_vec.cc (revision 2240)
@@ -36,11 +36,11 @@
using namespace mln;
-void run_in_3d(const algebra::vec<3, int>&)
+void run_in_3d(const algebra::vec<3, def::coord>&)
{
}
-void run_in_3d_h(const algebra::h_vec<3, int>&)
+void run_in_3d_h(const algebra::h_vec<3, def::coord>&)
{
}
@@ -53,10 +53,10 @@
int main()
{
- algebra::vec<3, int> x;
- algebra::h_vec<3, int> w = x.to_h_vec();
+ algebra::vec<3, def::coord> x;
+ algebra::h_vec<3, def::coord> w = x.to_h_vec();
- typedef algebra::h_vec<3, int> p3d;
+ typedef algebra::h_vec<3, def::coord> p3d;
p3d p;
run_in_3d(p.to_vec());
Index: branches/cleanup-2008/milena/tests/canvas/browsing/directional.cc
===================================================================
--- branches/cleanup-2008/milena/tests/canvas/browsing/directional.cc (revision 2239)
+++ branches/cleanup-2008/milena/tests/canvas/browsing/directional.cc (revision 2240)
@@ -44,7 +44,7 @@
struct assign_browsing_functor
{
typedef I_ I;
- enum { dim = I::point::dim };
+ enum { dim = I::site::dim };
I input;
Index: branches/cleanup-2008/milena/tests/canvas/browsing/fwd.cc
===================================================================
--- branches/cleanup-2008/milena/tests/canvas/browsing/fwd.cc (revision 2239)
+++ branches/cleanup-2008/milena/tests/canvas/browsing/fwd.cc (revision 2240)
@@ -42,7 +42,7 @@
struct assign_browsing_functor
{
typedef I_ I;
- enum { dim = I::point::dim };
+ enum { dim = I::site::dim };
I input;
Index: branches/cleanup-2008/milena/tests/canvas/browsing/snake_fwd.cc
===================================================================
--- branches/cleanup-2008/milena/tests/canvas/browsing/snake_fwd.cc (revision 2239)
+++ branches/cleanup-2008/milena/tests/canvas/browsing/snake_fwd.cc (revision 2240)
@@ -41,7 +41,7 @@
template <typename I, typename F>
struct assign_browsing_functor
{
- enum { dim = I::point::dim };
+ enum { dim = I::site::dim };
I input;
Index: branches/cleanup-2008/milena/mln/core/site_set/p_graph_piter.hh
===================================================================
--- branches/cleanup-2008/milena/mln/core/site_set/p_graph_piter.hh (revision 2239)
+++ branches/cleanup-2008/milena/mln/core/site_set/p_graph_piter.hh (revision 2240)
@@ -41,7 +41,6 @@
template <typename P> class p_graph;
template <typename P> class graph_psite;
-
/*------------------------.
| p_graph_fwd_piter_<P>. |
`------------------------*/
@@ -49,10 +48,10 @@
/// \brief Forward iterator on point sites of a mln::p_graph<P>.
template <typename P>
class p_graph_fwd_piter_
- : public internal::site_iterator_base_< P, p_graph_fwd_piter_<P> >
+ : public internal::site_iterator_base< P, p_graph_fwd_piter_<P> >
{
typedef p_graph_fwd_piter_<P> self_;
- typedef internal::site_iterator_base_< P, self_ > super_;
+ typedef internal::site_iterator_base< P, self_ > super_;
public:
// Make definitions from super class available.
@@ -125,10 +124,10 @@
/// \brief Backward iterator on point sites of a mln::p_graph<P>.
template <typename P>
class p_graph_bkd_piter_
- : public internal::site_iterator_base_< P, p_graph_bkd_piter_<P> >
+ : public internal::site_iterator_base< P, p_graph_bkd_piter_<P> >
{
typedef p_graph_bkd_piter_<P> self_;
- typedef internal::site_iterator_base_< P, self_ > super_;
+ typedef internal::site_iterator_base< P, self_ > super_;
public:
// Make definitions from super class available.
Index: branches/cleanup-2008/milena/mln/core/site_set/p_bgraph_piter.hh
===================================================================
--- branches/cleanup-2008/milena/mln/core/site_set/p_bgraph_piter.hh (revision 2239)
+++ branches/cleanup-2008/milena/mln/core/site_set/p_bgraph_piter.hh (revision 2240)
@@ -49,10 +49,10 @@
// FIXME: check the constraint due to the boost iterators
template<typename P>
class p_bgraph_piter_
- : public internal::site_iterator_base_< P, p_bgraph_piter_<P> >
+ : public internal::site_iterator_base< P, p_bgraph_piter_<P> >
{
typedef p_bgraph_piter_<P> self_;
- typedef internal::site_iterator_base_< P, self_ > super_;
+ typedef internal::site_iterator_base< P, self_ > super_;
typedef std::pair<typename p_bgraph<P>::node_iterator,
typename p_bgraph<P>::node_iterator> iterators_type_;
Index: branches/cleanup-2008/milena/mln/core/site_set/p_complex.hh
===================================================================
--- branches/cleanup-2008/milena/mln/core/site_set/p_complex.hh (revision 2239)
+++ branches/cleanup-2008/milena/mln/core/site_set/p_complex.hh (revision 2240)
@@ -31,7 +31,7 @@
/// \file mln/core/site_set/p_complex.hh
/// \brief Definition of a point set based on a complex.
-# include <mln/core/internal/point_set_base.hh>
+# include <mln/core/internal/site_set_base.hh>
# include <mln/accu/bbox.hh>
# include <mln/util/tracked_ptr.hh>
@@ -59,7 +59,7 @@
/// dimension \p D (a \p D-complex).
template <unsigned D, typename P>
struct p_complex
- : public internal::point_set_base_< complex_psite<D, P>,
+ : public internal::site_set_base_< complex_psite<D, P>,
p_complex<D, P> >
{
/// \brief Construct a complex psite set from a complex.
Index: branches/cleanup-2008/milena/mln/core/site_set/p_complex_piter.hh
===================================================================
--- branches/cleanup-2008/milena/mln/core/site_set/p_complex_piter.hh (revision 2239)
+++ branches/cleanup-2008/milena/mln/core/site_set/p_complex_piter.hh (revision 2240)
@@ -30,7 +30,7 @@
# include <limits>
-# include <mln/core/internal/point_iterator_base.hh>
+# include <mln/core/internal/site_iterator_base.hh>
# include <mln/core/site_set/p_complex.hh>
# include <mln/core/complex_psite.hh>
@@ -55,10 +55,10 @@
/// \brief Forward iterator on point sites of a mln::p_complex<D, P>.
template <unsigned D, typename P>
class p_complex_fwd_piter_
- : public internal::point_iterator_base_< P, p_complex_fwd_piter_<D, P> >
+ : public internal::site_iterator_base< P, p_complex_fwd_piter_<D, P> >
{
typedef p_complex_fwd_piter_<D, P> self_;
- typedef internal::point_iterator_base_< P, self_ > super_;
+ typedef internal::site_iterator_base< P, self_ > super_;
public:
// Make definitions from super class available.
@@ -148,10 +148,10 @@
/// \brief Backward iterator on point sites of a mln::p_complex<D, P>.
template <unsigned D, typename P>
class p_complex_bkd_piter_
- : public internal::point_iterator_base_< P, p_complex_bkd_piter_<D, P> >
+ : public internal::site_iterator_base< P, p_complex_bkd_piter_<D, P> >
{
typedef p_complex_bkd_piter_<D, P> self_;
- typedef internal::point_iterator_base_< P, self_ > super_;
+ typedef internal::site_iterator_base< P, self_ > super_;
public:
// Make definitions from super class available.
Index: branches/cleanup-2008/milena/mln/core/site_set/p_faces.hh
===================================================================
--- branches/cleanup-2008/milena/mln/core/site_set/p_faces.hh (revision 2239)
+++ branches/cleanup-2008/milena/mln/core/site_set/p_faces.hh (revision 2240)
@@ -32,7 +32,7 @@
/// \brief Definition of a point set based on the set of n-faces of a
/// complex.
-# include <mln/core/internal/point_set_base.hh>
+# include <mln/core/internal/site_set_base.hh>
# include <mln/accu/bbox.hh>
# include <mln/util/tracked_ptr.hh>
@@ -57,7 +57,7 @@
/// dimension \p D (a \p D-complex).
template <unsigned N, unsigned D, typename P>
struct p_faces
- : public internal::point_set_base_< faces_psite<N, D, P>,
+ : public internal::site_set_base_< faces_psite<N, D, P>,
p_faces<N, D, P> >
{
/// \brief Construct a complex psite set from a complex.
Index: branches/cleanup-2008/milena/mln/core/alias/point2d_h.hh
===================================================================
--- branches/cleanup-2008/milena/mln/core/alias/point2d_h.hh (revision 2239)
+++ branches/cleanup-2008/milena/mln/core/alias/point2d_h.hh (revision 2240)
@@ -42,7 +42,7 @@
/// \brief Type alias for a point defined on the 2D hexagonal grid
/// with integer coordinates.
- typedef point_<grid::hexa, int> point2d_h;
+ typedef point<grid::hexa, def::coord> point2d_h;
} // end of namespace mln
Index: branches/cleanup-2008/milena/mln/core/alias/dpoint2d_h.hh
===================================================================
--- branches/cleanup-2008/milena/mln/core/alias/dpoint2d_h.hh (revision 2239)
+++ branches/cleanup-2008/milena/mln/core/alias/dpoint2d_h.hh (revision 2240)
@@ -44,7 +44,7 @@
/*! \brief Type alias for a delta-point defined on the 2D square
* grid with integer coordinates.
*/
- typedef dpoint_<mln::grid::hexa, int> dpoint2d_h;
+ typedef dpoint<mln::grid::hexa, def::coord> dpoint2d_h;
} // end of namespace mln
1
0
URL: https://svn.lrde.epita.fr/svn/scool/branches/scool-ng
ChangeLog:
2008-09-12 Maxime van Noppen <yabo(a)lrde.epita.fr>
Handle functions and the 'var' keyword
* concrete-syn/concrete-syn.sdf: Add escape sequence for FunctionType.
* scoolt/Declaration.str: Handle function declarations and the 'var' keyword.
* scoolt/Expression.str: Consider identifiers as expressions.
* scoolt/Function.str: New.
* scoolt/Type.str: Const-reference non-scalar types.
concrete-syn/concrete-syn.sdf | 1
scoolt/Declaration.str | 49 +++++++++++++++++++++++++++++-------------
scoolt/Expression.str | 5 ++++
scoolt/Function.str | 17 ++++++++++++++
scoolt/Type.str | 20 +++++++++++++++--
5 files changed, 75 insertions(+), 17 deletions(-)
Index: branches/scool-ng/src/scoolt/Expression.str
===================================================================
--- branches/scool-ng/src/scoolt/Expression.str (revision 77)
+++ branches/scool-ng/src/scoolt/Expression.str (revision 78)
@@ -9,3 +9,8 @@
ExpressionToCxx:
Integer(int) -> CxxInt(int)
+
+ ExpressionToCxx:
+ idf -> cxx_idf
+ where
+ <IdentifierToCxx> idf => cxx_idf
Index: branches/scool-ng/src/scoolt/Type.str
===================================================================
--- branches/scool-ng/src/scoolt/Type.str (revision 77)
+++ branches/scool-ng/src/scoolt/Type.str (revision 78)
@@ -1,8 +1,24 @@
module Type
-imports libstratego-lib Cxx Scool Type
+imports libstratego-lib Cxx Scool
rules
+ IsScalar:
+ SimpleType(type) -> type
+ where
+ <eq> (type, "char")
+ <+ <eq> (type, "bool")
+ <+ <eq> (type, "short")
+ <+ <eq> (type, "int")
+ <+ <eq> (type, "float")
+ <+ <eq> (type, "double")
+
TypeToCxx:
- SimpleType(t) -> CxxType(t)
+ SimpleType(type) -> CxxType(type)
+
+ TypeToConstRefCxx:
+ type -> CxxConstType(CxxRefType(<TypeToCxx> type))
+ where
+ <not (IsScalar)> type
+ ; <not (?ReferenceType(_))> type
Index: branches/scool-ng/src/scoolt/Declaration.str
===================================================================
--- branches/scool-ng/src/scoolt/Declaration.str (revision 77)
+++ branches/scool-ng/src/scoolt/Declaration.str (revision 78)
@@ -1,32 +1,51 @@
module Declaration
-imports libstratego-lib Cxx Scool Type Expression
+imports libstratego-lib Cxx Scool Type Expression Function
rules
+ ////////////////////////////////////////////////////////////////////////////////
+ // Variables //
+ ////////////////////////////////////////////////////////////////////////////////
+
DeclarationToCxx:
- |[ ~i : ~t; ]| -> ![ const ~cxx_t ~cxx_i; ]!
+ |[ ~idf : ~type; ]| -> ![ const ~cxx_type ~cxx_idf; ]!
where
- <TypeToCxx> t => cxx_t
- ; <IdentifierToCxx> i => cxx_i
+ <TypeToCxx> type => cxx_type
+ ; <IdentifierToCxx> idf => cxx_idf
DeclarationToCxx:
- |[ var ~i : ~t; ]| -> ![ ~cxx_t ~cxx_i; ]!
+// |[ var ~i : ~t; ]| -> ![ ~cxx_t ~cxx_i; ]!
+ SimpleDeclaration(Some("var"), idf, type, None()) -> ![ ~cxx_type ~cxx_idf; ]!
where
- <TypeToCxx> t => cxx_t
- ; <IdentifierToCxx> i => cxx_i
+ <TypeToCxx> type => cxx_type
+ ; <IdentifierToCxx> idf => cxx_idf
DeclarationToCxx:
- |[ ~i : ~t = ~exp:e; ]| -> ![ const ~cxx_t ~cxx_i = ~exp:cxx_e; ]!
+ |[ ~idf : ~type = ~exp:exp; ]| -> ![ const ~cxx_type ~cxx_idf = ~exp:cxx_exp; ]!
where
- <TypeToCxx> t => cxx_t
- ; <IdentifierToCxx> i => cxx_i
- ; <ExpressionToCxx> e => cxx_e
+ <TypeToCxx> type => cxx_type
+ ; <IdentifierToCxx> idf => cxx_idf
+ ; <ExpressionToCxx> exp => cxx_exp
DeclarationToCxx:
- |[ var ~i : ~t = ~exp:e; ]| -> ![ ~cxx_t ~cxx_i = ~exp:cxx_e; ]!
+// |[ var ~i : ~t = ~exp:exp; ]| -> ![ ~cxx_t ~cxx_i = ~exp:cxx_exp; ]!
+ SimpleDeclaration(Some("var"), idf, type, Some(Initialiser(exp))) -> ![ ~cxx_type ~cxx_idf = ~exp:cxx_exp; ]!
where
- <TypeToCxx> t => cxx_t
- ; <IdentifierToCxx> i => cxx_i
- ; <ExpressionToCxx> e => cxx_e
+ <TypeToCxx> type => cxx_type
+ ; <IdentifierToCxx> idf => cxx_idf
+ ; <ExpressionToCxx> exp => cxx_exp
+
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // Functions //
+ ////////////////////////////////////////////////////////////////////////////////
+
+ DeclarationToCxx:
+ |[ ~idf : ~ft:fun_type; ]| -> CxxFun([], cxx_ret_type, cxx_idf, cxx_args)
+ where
+ <IdentifierToCxx> idf => cxx_idf
+ ; <TypeToCxx> <GetReturnType> fun_type => cxx_ret_type
+ ; <ArgumentsToCxx> <GetArguments> fun_type => cxx_args
+
Index: branches/scool-ng/src/scoolt/Function.str
===================================================================
--- branches/scool-ng/src/scoolt/Function.str (revision 0)
+++ branches/scool-ng/src/scoolt/Function.str (revision 78)
@@ -0,0 +1,17 @@
+module Function
+
+imports libstratego-lib Cxx Scool Type
+
+rules
+
+ GetReturnType:
+ FunctionType(_, _, ret_type) -> ret_type
+
+ GetArguments:
+ FunctionType(_, args, _) -> args
+
+ ArgumentsToCxx:
+ ArgumentsDeclaration(arg_list) -> <map (ArgumentToCxx)> arg_list
+
+ ArgumentToCxx:
+ TypedId(idf, type) -> (<TypeToConstRefCxx <+ TypeToCxx> type, <IdentifierToCxx> idf)
Index: branches/scool-ng/src/concrete-syn/concrete-syn.sdf
===================================================================
--- branches/scool-ng/src/concrete-syn/concrete-syn.sdf (revision 77)
+++ branches/scool-ng/src/concrete-syn/concrete-syn.sdf (revision 78)
@@ -13,6 +13,7 @@
"~" StrategoTerm -> Identifier {cons("FromTerm"), prefer}
"~" StrategoTerm -> SimpleType {cons("FromTerm"), prefer}
+ "~ft:" StrategoTerm -> FunctionType {cons("FromTerm"), prefer}
"~exp:" StrategoTerm -> Expression {cons("FromTerm"), prefer}
--
\__/ \__/
(00) Maxime `yabo` van Noppen (00)
___) \ Epita 2009 / (___
(_____/ \_____)
1
0
URL: https://svn.lrde.epita.fr/svn/scool/branches/scool-ng
ChangeLog:
2008-09-12 Maxime van Noppen <yabo(a)lrde.epita.fr>
Add tests
* function/c++_ast/declaration_001.aterm: New.
* function/c++_ast/declaration_002.aterm: New.
* function/c++_ast/declaration_003.aterm: New.
* function/scool_ast/static_dynamic_parameters_005.aterm: New.
* function/scool_src/static_dynamic_parameters_005.scl: New.
* variable/c++_ast/declaration_003.aterm: New.
* variable/c++_ast/declaration_004.aterm: New.
* variable/c++_ast/declaration_008.aterm: New.
* variable/c++_ast/mixed_declarations_001.aterm: New.
* variable/scool_ast/declaration_008.aterm: New.
* variable/scool_src/declaration_008.scl: New.
* variable/c++_ast/declaration_001.aterm,
* variable/c++_ast/declaration_007.aterm: Update regarding grammar changes.
function/c++_ast/declaration_001.aterm | 1 +
function/c++_ast/declaration_002.aterm | 1 +
function/c++_ast/declaration_003.aterm | 1 +
function/scool_ast/static_dynamic_parameters_005.aterm | 1 +
function/scool_src/static_dynamic_parameters_005.scl | 1 +
variable/c++_ast/declaration_001.aterm | 2 +-
variable/c++_ast/declaration_003.aterm | 1 +
variable/c++_ast/declaration_004.aterm | 1 +
variable/c++_ast/declaration_007.aterm | 2 +-
variable/c++_ast/declaration_008.aterm | 1 +
variable/c++_ast/mixed_declarations_001.aterm | 1 +
variable/scool_ast/declaration_008.aterm | 1 +
variable/scool_src/declaration_008.scl | 1 +
13 files changed, 13 insertions(+), 2 deletions(-)
Index: branches/scool-ng/tests/function/c++_ast/declaration_001.aterm
===================================================================
--- branches/scool-ng/tests/function/c++_ast/declaration_001.aterm (revision 0)
+++ branches/scool-ng/tests/function/c++_ast/declaration_001.aterm (revision 77)
@@ -0,0 +1 @@
+CxxProgram([CxxFun([],CxxType("void"),CxxId("foo"),[])])
Index: branches/scool-ng/tests/function/c++_ast/declaration_002.aterm
===================================================================
--- branches/scool-ng/tests/function/c++_ast/declaration_002.aterm (revision 0)
+++ branches/scool-ng/tests/function/c++_ast/declaration_002.aterm (revision 77)
@@ -0,0 +1 @@
+CxxProgram([CxxFun([],CxxType("void"),CxxId("foo"),[(CxxType("int"),CxxId("a"))])])
Index: branches/scool-ng/tests/function/c++_ast/declaration_003.aterm
===================================================================
--- branches/scool-ng/tests/function/c++_ast/declaration_003.aterm (revision 0)
+++ branches/scool-ng/tests/function/c++_ast/declaration_003.aterm (revision 77)
@@ -0,0 +1 @@
+CxxProgram([CxxFun([],CxxType("void"),CxxId("foo"),[(CxxType("int"),CxxId("a")),(CxxConstType(CxxRefType(CxxType("bar"))),CxxId("b"))])])
Index: branches/scool-ng/tests/function/scool_ast/static_dynamic_parameters_005.aterm
===================================================================
--- branches/scool-ng/tests/function/scool_ast/static_dynamic_parameters_005.aterm (revision 0)
+++ branches/scool-ng/tests/function/scool_ast/static_dynamic_parameters_005.aterm (revision 77)
@@ -0,0 +1 @@
+Program([FunctionDefinition(None,Identifier("f"),FunctionType(Some(ParametersDeclaration([TypedId(Identifier("T"),"type"),TypedId(Identifier("U"),"type")])),ArgumentsDeclaration([TypedId(Identifier("a"),SimpleType("T")),TypedId(Identifier("b"),SimpleType("U"))]),SimpleType("T")),Identifier("a"))])
Index: branches/scool-ng/tests/function/scool_src/static_dynamic_parameters_005.scl
===================================================================
--- branches/scool-ng/tests/function/scool_src/static_dynamic_parameters_005.scl (revision 0)
+++ branches/scool-ng/tests/function/scool_src/static_dynamic_parameters_005.scl (revision 77)
@@ -0,0 +1 @@
+f : [T : type, U : type] (a : T, b : U) -> T => a;
Index: branches/scool-ng/tests/variable/c++_ast/declaration_004.aterm
===================================================================
--- branches/scool-ng/tests/variable/c++_ast/declaration_004.aterm (revision 0)
+++ branches/scool-ng/tests/variable/c++_ast/declaration_004.aterm (revision 77)
@@ -0,0 +1 @@
+CxxProgram([CxxDecl(CxxType("int"),CxxId("i"),CxxInt("42"))])
Index: branches/scool-ng/tests/variable/c++_ast/declaration_007.aterm
===================================================================
--- branches/scool-ng/tests/variable/c++_ast/declaration_007.aterm (revision 76)
+++ branches/scool-ng/tests/variable/c++_ast/declaration_007.aterm (revision 77)
@@ -1 +1 @@
-CxxProgram([CxxDecl(CxxConstType(CxxType("int")),Identifier("i"))])
+CxxProgram([CxxDecl(CxxConstType(CxxType("int")),CxxId("i"))])
Index: branches/scool-ng/tests/variable/c++_ast/declaration_008.aterm
===================================================================
--- branches/scool-ng/tests/variable/c++_ast/declaration_008.aterm (revision 0)
+++ branches/scool-ng/tests/variable/c++_ast/declaration_008.aterm (revision 77)
@@ -0,0 +1 @@
+CxxProgram([CxxDecl(CxxType("int"),CxxId("i"),CxxId("j"))])
Index: branches/scool-ng/tests/variable/c++_ast/mixed_declarations_001.aterm
===================================================================
--- branches/scool-ng/tests/variable/c++_ast/mixed_declarations_001.aterm (revision 0)
+++ branches/scool-ng/tests/variable/c++_ast/mixed_declarations_001.aterm (revision 77)
@@ -0,0 +1 @@
+CxxProgram([CxxDecl(CxxConstType(CxxType("int")),CxxId("answer"),CxxInt("42")),CxxDecl(CxxType("int"),CxxId("i")),CxxDecl(CxxType("int"),CxxId("j"),CxxId("i"))])
Index: branches/scool-ng/tests/variable/c++_ast/declaration_001.aterm
===================================================================
--- branches/scool-ng/tests/variable/c++_ast/declaration_001.aterm (revision 76)
+++ branches/scool-ng/tests/variable/c++_ast/declaration_001.aterm (revision 77)
@@ -1 +1 @@
-CxxProgram([CxxDecl(CxxConstType(CxxType("int")),Identifier("i"))])
+CxxProgram([CxxDecl(CxxConstType(CxxType("int")),CxxId("i"))])
Index: branches/scool-ng/tests/variable/c++_ast/declaration_003.aterm
===================================================================
--- branches/scool-ng/tests/variable/c++_ast/declaration_003.aterm (revision 0)
+++ branches/scool-ng/tests/variable/c++_ast/declaration_003.aterm (revision 77)
@@ -0,0 +1 @@
+CxxProgram([CxxDecl(CxxType("int"),CxxId("i"))])
Index: branches/scool-ng/tests/variable/scool_ast/declaration_008.aterm
===================================================================
--- branches/scool-ng/tests/variable/scool_ast/declaration_008.aterm (revision 0)
+++ branches/scool-ng/tests/variable/scool_ast/declaration_008.aterm (revision 77)
@@ -0,0 +1 @@
+Program([SimpleDeclaration(Some("var"),Identifier("i"),SimpleType("int"),Some(Initialiser(Identifier("j"))))])
Index: branches/scool-ng/tests/variable/scool_src/declaration_008.scl
===================================================================
--- branches/scool-ng/tests/variable/scool_src/declaration_008.scl (revision 0)
+++ branches/scool-ng/tests/variable/scool_src/declaration_008.scl (revision 77)
@@ -0,0 +1 @@
+var i : int = j;
--
\__/ \__/
(00) Maxime `yabo` van Noppen (00)
___) \ Epita 2009 / (___
(_____/ \_____)
1
0
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Make tests on some queue types pass.
* tests/core/site_set/p_queue_fast.cc: Update.
* tests/core/site_set/p_queue.cc: Likewise.
* tests/core/site_set/p_priority_queue.cc
(operator[]): De-activate since priority queues do not (cannot)
have such a method.
(has): Likewise; replace the calls to this method by calling...
* mln/set/has.hh: ...this new procedure.
It is useful when a site set is not "point-wise" random
accessible.
* mln/core/site_set/p_priority.hh (Q): New static check.
mln/core/site_set/p_priority.hh | 14 +++--
mln/set/has.hh | 85 ++++++++++++++++++++++++++++++++
tests/core/site_set/p_priority_queue.cc | 55 +++++++++++---------
tests/core/site_set/p_queue.cc | 14 ++---
tests/core/site_set/p_queue_fast.cc | 14 ++---
5 files changed, 139 insertions(+), 43 deletions(-)
Index: tests/core/site_set/p_queue_fast.cc
--- tests/core/site_set/p_queue_fast.cc (revision 2238)
+++ tests/core/site_set/p_queue_fast.cc (working copy)
@@ -32,6 +32,8 @@
#include <mln/core/alias/point2d.hh>
#include <mln/core/site_set/p_queue_fast.hh>
+#include <mln/geom/bbox.hh>
+#include <mln/make/box2d.hh>
@@ -40,18 +42,16 @@
using namespace mln;
p_queue_fast<point2d> q;
- q
- .push(make::point2d(6, 9))
- .push(make::point2d(5, 1))
- .push(make::point2d(4, 2));
+ q.push(point2d(6, 9));
+ q.push(point2d(5, 1));
+ q.push(point2d(4, 2));
mln_assertion(q.nsites() == 3);
- std::cout << q.bbox() << std::endl;
- std::cout << q << std::endl;
+ mln_assertion(geom::bbox(q) == make::box2d(4,1, 6,9));
q.pop();
mln_assertion(q.nsites() == 2);
point2d p = q.front();
mln_assertion(q.nsites() == 2);
- mln_assertion(p == make::point2d(5, 1));
+ mln_assertion(p == point2d(5, 1));
}
Index: tests/core/site_set/p_queue.cc
--- tests/core/site_set/p_queue.cc (revision 2238)
+++ tests/core/site_set/p_queue.cc (working copy)
@@ -32,6 +32,8 @@
#include <mln/core/alias/point2d.hh>
#include <mln/core/site_set/p_queue.hh>
+#include <mln/geom/bbox.hh>
+#include <mln/make/box2d.hh>
@@ -40,18 +42,16 @@
using namespace mln;
p_queue<point2d> q;
- q
- .push(make::point2d(6, 9))
- .push(make::point2d(5, 1))
- .push(make::point2d(4, 2));
+ q.push(point2d(6, 9));
+ q.push(point2d(5, 1));
+ q.push(point2d(4, 2));
mln_assertion(q.nsites() == 3);
- std::cout << q.bbox() << std::endl;
- std::cout << q << std::endl;
+ mln_assertion(geom::bbox(q) == make::box2d(4,1, 6,9));
q.pop();
mln_assertion(q.nsites() == 2);
point2d p = q.front();
mln_assertion(q.nsites() == 2);
- mln_assertion(p == make::point2d(5, 1));
+ mln_assertion(p == point2d(5, 1));
}
Index: tests/core/site_set/p_priority_queue.cc
--- tests/core/site_set/p_priority_queue.cc (revision 2238)
+++ tests/core/site_set/p_priority_queue.cc (working copy)
@@ -32,12 +32,18 @@
#include <mln/core/alias/point2d.hh>
#include <mln/core/site_set/p_priority.hh>
+#include <mln/core/site_set/p_queue.hh>
+#include <mln/geom/bbox.hh>
+#include <mln/make/box2d.hh>
+#include <mln/set/has.hh>
+
int main ()
{
using namespace mln;
- p_priority<point2d, unsigned> q;
+ typedef p_queue<point2d> Q;
+ p_priority<unsigned, Q> q;
point2d p1 (6, 9);
point2d p2 (5, 1);
point2d p3 (4, 2);
@@ -46,53 +52,52 @@
mln_assertion (q.nsites() == 0);
- q.push_force (p3);
- q.push_force (p1, 3);
- q.push_force (p2, 5);
+ q.push(0, p3);
+ q.push(3, p1);
+ q.push(5, p2);
- std::cout << q.bbox () << std::endl;
- std::cout << q << std::endl;
+ mln_assertion(geom::bbox(q) == make::box2d(4,1, 6,9));
mln_assertion (!q.is_empty ());
- mln_assertion (q.has (p1));
- mln_assertion (q.has (p2));
- mln_assertion (q.has (p3));
+ mln_assertion(set::has(q, p1));
+ mln_assertion(set::has(q, p2));
+ mln_assertion(set::has(q, p3));
mln_assertion (q.nsites() == 3);
mln_assertion (q.front () == p2);
q.pop ();
- mln_assertion (q.has (p1));
- mln_assertion (!q.has (p2));
- mln_assertion (q.has (p3));
+ mln_assertion(set::has(q, p1));
+ mln_assertion(! set::has(q, p2));
+ mln_assertion(set::has(q, p3));
mln_assertion (q.nsites() == 2);
mln_assertion (q.front () == p1);
q.pop ();
- mln_assertion (!q.has (p1));
- mln_assertion (!q.has (p2));
- mln_assertion (q.has (p3));
+ mln_assertion(! set::has(q, p1));
+ mln_assertion(! set::has(q, p2));
+ mln_assertion(set::has(q, p3));
mln_assertion (q.nsites() == 1);
mln_assertion (q.front () == p3);
q.pop ();
- mln_assertion (!q.has (p1));
- mln_assertion (!q.has (p2));
- mln_assertion (!q.has (p3));
+ mln_assertion(! set::has(q, p1));
+ mln_assertion(! set::has(q, p2));
+ mln_assertion(! set::has(q, p3));
mln_assertion (q.nsites() == 0);
mln_assertion (q.is_empty ());
- q.push_force (p3);
- q.push_force (p2, 5);
- q.push_force (p1, 3);
-
- mln_assertion (q[2] == p3);
- mln_assertion (q[1] == p1);
- mln_assertion (q[0] == p2);
+ q.push(0, p3);
+ q.push(5, p2);
+ q.push(3, p1);
+
+// mln_assertion(q[2] == p3);
+// mln_assertion(q[1] == p1);
+// mln_assertion(q[0] == p2);
q.clear ();
mln_assertion (q.is_empty ());
}
Index: mln/core/site_set/p_priority.hh
--- mln/core/site_set/p_priority.hh (revision 2238)
+++ mln/core/site_set/p_priority.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
@@ -68,11 +68,16 @@
/*! \brief Priority queue class.
*
- * FIXME
+ * The parameter \p P is the type of the priorities (for instance
+ * unsigned).
+ *
+ * The parameter \p Q is a type of queue (for instance
+ * p_queue<point2d>).
*/
template <typename P, typename Q>
class p_priority : public internal::site_set_base_< mln_site(Q),
- p_priority<P,Q> >
+ p_priority<P,Q> >,
+ private mlc_is_a(Q, Site_Set)::check_t
{
typedef p_priority<P,Q> self_;
public:
@@ -267,7 +272,8 @@
p_priority<P,Q>::front() const
{
mln_precondition(! this->is_empty()); // Also test invariants.
- return q_[highest_priority()].front();
+ std::map<P,Q>& q__ = const_cast< std::map<P,Q>& >(q_);
+ return q__[highest_priority()].front();
}
template <typename P, typename Q>
Index: mln/set/has.hh
--- mln/set/has.hh (revision 0)
+++ mln/set/has.hh (revision 0)
@@ -0,0 +1,85 @@
+// Copyright (C) 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
+// 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_SET_HAS_HH
+# define MLN_SET_HAS_HH
+
+/*! \file mln/set/has.hh
+ *
+ * \brief Algorithm that tests if a site set has a given site.
+ *
+ * \todo Layout and specialize.
+ */
+
+# include <mln/core/concept/site_set.hh>
+
+
+
+namespace mln
+{
+
+ namespace set
+ {
+
+ /// FIXME
+ template <typename S>
+ bool
+ has(const Site_Set<S>& s, const mln_site(S)& e);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename S>
+ bool
+ has(const Site_Set<S>& s_, const mln_site(S)& e)
+ {
+ trace::entering("set::has");
+ const S& s = exact(s_);
+
+ mln_precondition(s.is_valid());
+ bool found = false;
+
+ mln_piter(S) p(s);
+ for_all(p)
+ if (p == e)
+ {
+ found = true;
+ break;
+ }
+
+ trace::exiting("set::has");
+ return found;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::set
+
+} // end of namespace mln
+
+
+#endif // ! MLN_SET_HAS_HH
1
0
12 Sep '08
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Update fill_with_image and fill_with_value.
* mln/level/fill_with_image.hh
(fill_with_image_tests): New.
(generic): Strengthen signature and use tests.
(impl): Move specialized impl into...
* mln/level/fill_with_image.spe.hh: ...this new file.
Update.
* mln/level/fill_with_value.hh,
* mln/level/fill_with_value.spe.hh: Likewise.
* mln/level/fill.spe.hh: Remove; dead empty file.
fill_with_image.hh | 48 ++++++------
fill_with_image.spe.hh | 84 ++++++++++++++++++++++
fill_with_value.hh | 129 +++++++---------------------------
fill_with_value.spe.hh | 185 ++++++++++++-------------------------------------
4 files changed, 183 insertions(+), 263 deletions(-)
Index: mln/level/fill_with_image.hh
--- mln/level/fill_with_image.hh (revision 2236)
+++ mln/level/fill_with_image.hh (working copy)
@@ -38,6 +38,9 @@
# include <mln/core/concept/image.hh>
# include <mln/core/image/inplace.hh>
+// Specializations are in:
+# include <mln/level/fill_with_image.spe.hh>
+
namespace mln
{
@@ -62,6 +65,24 @@
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+ template <typename I, typename J>
+ inline
+ void fill_with_image_tests(Image<I>& ima, const Image<J>& data)
+ {
+ mlc_is(mln_trait_image_value_io(I),
+ mln::trait::image::value_io::read_write)::check();
+ mlc_converts_to(mln_value(J), mln_value(I))::check();
+ mln_precondition(exact(ima).has_data());
+ mln_precondition(exact(data).has_data());
+ mln_precondition(exact(ima).domain() <= exact(data).domain());
+ }
+
+ } // end of namespace mln::level::internal
+
+
namespace impl
{
@@ -70,9 +91,10 @@
template <typename I, typename J>
inline
- void fill_with_image(I& ima, const J& data)
+ void fill_with_image(Image<I>& ima, const Image<J>& data)
{
trace::entering("level::impl::generic::fill_with_image");
+ internal::fill_with_image_tests(ima, data);
mln_piter(I) p(ima.domain());
for_all(p)
@@ -83,37 +105,19 @@
} // end if namespace mln::level::impl::generic
-
- // Selector.
-
- template <typename I, typename J>
- inline
- void fill_with_image_(I& ima, const J& data)
- {
- generic::fill_with_image(ima, data);
- }
-
} // end of namespace mln::level::impl
-
/// Facade.
template <typename I, typename J>
inline
- void fill_with_image(Image<I>& ima_, const Image<J>& data_)
+ void fill_with_image(Image<I>& ima, const Image<J>& data)
{
trace::entering("level::fill_with_image");
- mlc_is(mln_trait_image_value_io(I),
- mln::trait::image::value_io::read_write)::check();
- mlc_converts_to(mln_value(J), mln_value(I))::check();
-
- I& ima = exact(ima_);
- const J& data = exact(data_);
- mln_precondition(ima.domain() <= data.domain());
-
- impl::fill_with_image_(ima, data);
+ internal::fill_with_image_tests(ima, data);
+ internal::fill_with_image_dispatch(ima, data);
trace::exiting("level::fill_with_image");
}
Index: mln/level/fill_with_value.spe.hh
--- mln/level/fill_with_value.spe.hh (revision 2236)
+++ mln/level/fill_with_value.spe.hh (working copy)
@@ -25,77 +25,60 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
+#ifndef MLN_LEVEL_FILL_WITH_VALUE_SPE_HH
+# define MLN_LEVEL_FILL_WITH_VALUE_SPE_HH
+
+/// \file mln/level/fill_with_value.spe.hh
+/// Specializations for mln::level::fill_with_value.
+///
+/// \todo See todos in mln/level/fill.hh
+
#ifndef MLN_LEVEL_FILL_WITH_VALUE_HH
-# define MLN_LEVEL_FILL_WITH_VALUE_HH
+# error "Forbidden inclusion of *.spe.hh"
+# endif // ! MLN_LEVEL_FILL_WITH_VALUE_HH
-/*! \file mln/level/fill_with_value.hh
- *
- * \brief Fill an image with a value, that is, set all pixel values to
- * the given value.
- *
- * \todo Overload for fastest images.
- * \todo Handle all value_storage properties (piecewise, etc.)
- * \todo Make memset_ work and use it when appropriate.
- * \todo Move specializations in a extra file.
- * \toto Activate fill_with_value_cell_wise.
- */
-
-# include <cstdlib>
-
-# include <mln/core/concept/image.hh>
-# include <mln/core/image/inplace.hh>
-# include <mln/core/image/instant.hh>
+# ifndef MLN_INCLUDE_ONLY
+
namespace mln
{
namespace level
{
- /*! Fill the whole image \p ima with the single value \p v.
- *
- * \param[in,out] ima The image to be filled.
- * \param[in] val The value to assign to all sites.
- *
- * \pre \p ima has to be initialized.
- *
- * \todo Optimize when \p ima is large and sizeof(mln_value(I)) > 1.
- */
- template <typename I, typename V>
- void fill_with_value(Image<I>& ima, const V& val);
-
-
- // Case of instant images.
+ namespace internal
+ {
template <typename I, typename V>
- void fill_with_value(const Image< instant_<I> >& ima, const V& val);
+ inline
+ void fill_with_value_tests(Image<I>& ima, const V& val);
+ }
-
-# ifndef MLN_INCLUDE_ONLY
+ // Implementations.
+ // ----------------
namespace impl
{
- template <typename I>
- inline
- void fill_with_value_site_wise_any(I& ima, const mln_value(I)& val)
+ namespace generic
{
- trace::entering("level::impl::fill_with_value_site_wise_any");
+ template <typename I, typename V>
+ void fill_with_value(Image<I>& ima, const V& val);
+ }
- mln_piter(I) p(ima.domain());
- for_all(p)
- ima(p) = val;
- trace::exiting("level::impl::fill_with_value_site_wise_any");
- }
+ // FIXME: Add specializations here...
template <typename I, typename V>
inline
- void fill_with_value_site_wise_one_block(I& ima, const V& val)
+ void fill_with_value_one_block(Image<I>& ima_, const V& val)
{
- trace::entering("level::impl::fill_with_value_site_wise_one_block");
+ trace::entering("level::impl::fill_with_value_one_block");
+
+ I& ima = exact(ima_);
+ internal::fill_with_value_tests(ima, val);
// level::memset_(ima, ima.point_at_index(0), v, ima.nelements());
const unsigned n = ima.nelements();
@@ -103,126 +86,50 @@
for (unsigned i = 0; i < n; ++i)
*ptr++ = val;
- trace::exiting("level::impl::fill_with_value_site_wise_one_block");
+ trace::exiting("level::impl::fill_with_value_one_block");
}
-
template <typename I, typename V>
inline
- void fill_with_value_cell_wise(I& ima, const V& val)
+ void fill_with_value_cell_wise(Image<I>& ima_, const V& val)
{
trace::entering("level::impl::fill_with_value_cell_wise");
- abort();
+ I& ima = exact(ima_);
+ internal::fill_with_value_tests(ima, val);
- // mln_viter(I) v(ima.values());
- // for_all(v)
- // v.change_to(val);
+ mln_viter(I) v(ima.values());
+ for_all(v)
+ v.change_to(val);
trace::exiting("level::impl::fill_with_value_cell_wise");
}
+ } // end of namespace mln::level::impl
- namespace dispatch
- {
-
- // Cases for "value_browsing == site_wise_only" w.r.t. value_storage.
-
- template <typename I, typename V>
- inline
- void fill_with_value_site_wise_(mln::trait::image::value_storage::any,
- I& ima, const V& val)
- {
- fill_with_value_site_wise_any(ima, val);
- }
-
- template <typename I, typename V>
- inline
- void fill_with_value_site_wise_(mln::trait::image::value_storage::one_block,
- I& ima, const V& val)
- {
- fill_with_value_site_wise_one_block(ima, val);
- }
-
- // Case site_wise -> selector w.r.t. value_storage.
-
- template <typename I, typename V>
- inline
- void fill_with_value_site_wise(I& ima, const V& val)
- {
- fill_with_value_site_wise_(mln_trait_image_value_storage(I)(),
- ima, val);
- }
-
-
- // Cases w.r.t. value_browsing.
- template <typename I, typename V>
- inline
- void fill_with_value_(mln::trait::image::value_browsing::site_wise_only,
- I& ima, const V& val)
- {
- fill_with_value_site_wise(ima, val);
- }
+ // Dispatch.
+ // ---------
- template <typename I, typename V>
- inline
- void fill_with_value_(mln::trait::image::value_browsing::cell_wise,
- I& ima, const V& val)
+ namespace internal
{
- fill_with_value_cell_wise(ima, val);
- }
-
- // Selector w.r.t. value_browsing.
template <typename I, typename V>
inline
- void fill_with_value_(I& ima, const V& val)
+ void fill_with_value_dispatch(Image<I>& ima, const V& val)
{
- fill_with_value_(mln_trait_image_value_browsing(I)(),
- ima, val);
+ impl::generic::fill_with_value(ima, val);
}
- } // end of namespace mln::level::impl::dispatch
-
- } // end of namespace mln::level::impl
+ } // end of namespace mln::level::internal
+ } // end of namespace mln::level
- /// Facade.
-
- template <typename I, typename V>
- inline
- void fill_with_value(Image<I>& ima, const V& val)
- {
- trace::entering("level::fill");
-
- mlc_is(mln_trait_image_value_io(I),
- mln::trait::image::value_io::read_write)::check();
- mlc_converts_to(V, mln_value(I))::check();
-
- mln_precondition(exact(ima).has_data());
-
- impl::dispatch::fill_with_value_(exact(ima), exact(val));
-
- trace::exiting("level::fill");
- }
-
-
- // Un-instant.
-
- template <typename I, typename V>
- void fill_with_value(const Image< instant_<I> >& ima, const V& val)
- {
- fill_with_value(exact(ima).un_instant_(), val);
- }
+} // end of namespace mln
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::level
-} // end of namespace mln
-
-
-#endif // ! MLN_LEVEL_FILL_WITH_VALUE_HH
+#endif // ! MLN_LEVEL_FILL_WITH_VALUE_SPE_HH
Index: mln/level/fill_with_value.hh
--- mln/level/fill_with_value.hh (revision 2236)
+++ mln/level/fill_with_value.hh (working copy)
@@ -38,6 +38,7 @@
* \todo Make memset_ work and use it when appropriate.
* \todo Move specializations in a extra file.
* \toto Activate fill_with_value_cell_wise.
+ * \todo Optimize when \p ima is large and sizeof(mln_value(I)) > 1.
*/
# include <cstdlib>
@@ -46,6 +47,9 @@
# include <mln/core/image/inplace.hh>
# include <mln/core/image/instant.hh>
+// Specializations are in:
+# include <mln/level/fill_with_value.spe.hh>
+
namespace mln
{
@@ -59,8 +63,6 @@
* \param[in] val The value to assign to all sites.
*
* \pre \p ima has to be initialized.
- *
- * \todo Optimize when \p ima is large and sizeof(mln_value(I)) > 1.
*/
template <typename I, typename V>
void fill_with_value(Image<I>& ima, const V& val);
@@ -74,138 +76,61 @@
# ifndef MLN_INCLUDE_ONLY
- namespace impl
- {
-
- template <typename I>
- inline
- void fill_with_value_site_wise_any(I& ima, const mln_value(I)& val)
+ namespace internal
{
- trace::entering("level::impl::fill_with_value_site_wise_any");
-
- mln_piter(I) p(ima.domain());
- for_all(p)
- ima(p) = val;
-
- trace::exiting("level::impl::fill_with_value_site_wise_any");
- }
-
template <typename I, typename V>
inline
- void fill_with_value_site_wise_one_block(I& ima, const V& val)
+ void fill_with_value_tests(Image<I>& ima, const V& val)
{
- trace::entering("level::impl::fill_with_value_site_wise_one_block");
-
- // level::memset_(ima, ima.point_at_index(0), v, ima.nelements());
- const unsigned n = ima.nelements();
- mln_value(I)* ptr = ima.buffer();
- for (unsigned i = 0; i < n; ++i)
- *ptr++ = val;
-
- trace::exiting("level::impl::fill_with_value_site_wise_one_block");
- }
-
-
- template <typename I, typename V>
- inline
- void fill_with_value_cell_wise(I& ima, const V& val)
- {
- trace::entering("level::impl::fill_with_value_cell_wise");
-
- abort();
-
- // mln_viter(I) v(ima.values());
- // for_all(v)
- // v.change_to(val);
-
- trace::exiting("level::impl::fill_with_value_cell_wise");
+ mlc_is(mln_trait_image_value_io(I),
+ mln::trait::image::value_io::read_write)::check();
+ mlc_converts_to(mln_exact(V), mln_value(I))::check();
+ mln_precondition(exact(ima).has_data());
}
+ } // end of namespace mln::level::internal
- namespace dispatch
- {
-
- // Cases for "value_browsing == site_wise_only" w.r.t. value_storage.
-
- template <typename I, typename V>
- inline
- void fill_with_value_site_wise_(mln::trait::image::value_storage::any,
- I& ima, const V& val)
- {
- fill_with_value_site_wise_any(ima, val);
- }
- template <typename I, typename V>
- inline
- void fill_with_value_site_wise_(mln::trait::image::value_storage::one_block,
- I& ima, const V& val)
+ namespace impl
{
- fill_with_value_site_wise_one_block(ima, val);
- }
- // Case site_wise -> selector w.r.t. value_storage.
-
- template <typename I, typename V>
- inline
- void fill_with_value_site_wise(I& ima, const V& val)
+ namespace generic
{
- fill_with_value_site_wise_(mln_trait_image_value_storage(I)(),
- ima, val);
- }
-
-
- // Cases w.r.t. value_browsing.
template <typename I, typename V>
- inline
- void fill_with_value_(mln::trait::image::value_browsing::site_wise_only,
- I& ima, const V& val)
+ void fill_with_value(Image<I>& ima_, const V& val)
{
- fill_with_value_site_wise(ima, val);
- }
+ trace::entering("level::impl::generic::fill_with_value");
- template <typename I, typename V>
- inline
- void fill_with_value_(mln::trait::image::value_browsing::cell_wise,
- I& ima, const V& val)
- {
- fill_with_value_cell_wise(ima, val);
- }
+ I& ima = exact(ima_);
+ internal::fill_with_value_tests(ima, val);
- // Selector w.r.t. value_browsing.
+ mln_value(I) v = exact(val);
+ mln_piter(I) p(ima.domain());
+ for_all(p)
+ ima(p) = v;
- template <typename I, typename V>
- inline
- void fill_with_value_(I& ima, const V& val)
- {
- fill_with_value_(mln_trait_image_value_browsing(I)(),
- ima, val);
+ trace::exiting("level::impl::generic::fill_with_value");
}
- } // end of namespace mln::level::impl::dispatch
+ } // end if namespace mln::level::impl::generic
} // end of namespace mln::level::impl
-
/// Facade.
template <typename I, typename V>
inline
void fill_with_value(Image<I>& ima, const V& val)
{
- trace::entering("level::fill");
-
- mlc_is(mln_trait_image_value_io(I),
- mln::trait::image::value_io::read_write)::check();
- mlc_converts_to(V, mln_value(I))::check();
-
- mln_precondition(exact(ima).has_data());
+ trace::entering("level::fill_with_value");
- impl::dispatch::fill_with_value_(exact(ima), exact(val));
+ internal::fill_with_value_tests(ima, val);
+ internal::fill_with_value_dispatch(ima, val);
- trace::exiting("level::fill");
+ trace::exiting("level::fill_with_value");
}
Index: mln/level/fill_with_image.spe.hh
--- mln/level/fill_with_image.spe.hh (revision 0)
+++ mln/level/fill_with_image.spe.hh (revision 0)
@@ -0,0 +1,84 @@
+// Copyright (C) 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
+// 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_LEVEL_FILL_WITH_IMAGE_SPE_HH
+# define MLN_LEVEL_FILL_WITH_IMAGE_SPE_HH
+
+/*! \file mln/level/fill_with_image.spe.hh
+ *
+ * \brief Specializations for mln::level::fill_with_image.
+ *
+ * \todo Add specializations then rewrite the dispatch.
+ */
+
+# ifndef MLN_LEVEL_FILL_WITH_IMAGE_HH
+# error "Forbidden inclusion of *.spe.hh"
+# endif // ! MLN_LEVEL_FILL_WITH_IMAGE_HH
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+namespace mln
+{
+
+ namespace level
+ {
+
+ namespace impl
+ {
+
+ namespace generic
+ {
+ template <typename I, typename J>
+ void fill_with_image(const Image<I>& data, Image<J>& destination);
+ }
+
+ // FIXME: Add specializations here...
+
+ } // end of namespace mln::level::impl
+
+ namespace internal
+ {
+
+ template <typename I, typename J>
+ inline
+ void fill_with_image_dispatch(Image<I>& ima, const Image<J>& data)
+ {
+ impl::generic::fill_with_image(ima, data);
+ }
+
+ } // end of namespace mln::level::internal
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+#endif // ! MLN_LEVEL_FILL_WITH_IMAGE_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Alexandre Abraham <abraham(a)lrde.epita.fr>
Fix Bugs In Watershed.
* abraham/tests/morpho/test_component_tree.cc: Update some printing
functions.
* abraham/tests/morpho/test_watershed.cc: Idem.
* abraham/tests/morpho/test_watershed_topo.cc: Make it clean.
* abraham/tests/morpho/ref/src/lib/lwshedtopo.c: Remove debug printing.
* abraham/mln/morpho/basic_najman.hh: Fix bugs
basic_najman::compressTree: New
basic_najman::removeOneSonNodes(): New.
mln/morpho/basic_najman.hh | 386 +++++++++++++++++++---------------
tests/morpho/ref/src/lib/lwshedtopo.c | 4
tests/morpho/test_component_tree.cc | 8
tests/morpho/test_watershed.cc | 4
tests/morpho/test_watershed_topo.cc | 38 ---
5 files changed, 241 insertions(+), 199 deletions(-)
Index: abraham/tests/morpho/test_component_tree.cc
--- abraham/tests/morpho/test_component_tree.cc (revision 2236)
+++ abraham/tests/morpho/test_component_tree.cc (working copy)
@@ -107,9 +107,11 @@
test_tree<image2d<int_u8>::psite> *res = new test_tree<image2d<int_u8>::psite>(ima.Par_node(root));
- p_array<image2d<int_u8>::psite>::fwd_piter it (n.children);
- for_all(it)
- res->insert_child(test_convert(ima, it.to_psite()));
+ // p_array<image2d<int_u8>::psite>::fwd_piter it (n.children);
+ // for_all(it)
+ // res->insert_child(test_convert(ima, it.to_psite()));
+ for (unsigned i=0; i < n.children.size(); ++i)
+ res->insert_child(test_convert(ima, n.children[i]));
return res;
}
Index: abraham/tests/morpho/test_watershed.cc
--- abraham/tests/morpho/test_watershed.cc (revision 2236)
+++ abraham/tests/morpho/test_watershed.cc (working copy)
@@ -22,9 +22,9 @@
// #define TEST
- io::pgm::load(input, "./images/test_watershed.pgm");
+ //io::pgm::load(input, "./images/test_watershed.pgm");
// io::pgm::load(input, "./images/little_test.pgm");
- // io::pgm::load(input, "./images/test_2.pgm");
+ io::pgm::load(input, "./images/test_4.pgm");
// io::pgm::load(input, "./images/lena_light.pgm");
// io::pgm::load(mverif, "./images/result_m_watershed.pgm");
Index: abraham/tests/morpho/test_watershed_topo.cc
--- abraham/tests/morpho/test_watershed_topo.cc (revision 2236)
+++ abraham/tests/morpho/test_watershed_topo.cc (working copy)
@@ -13,49 +13,27 @@
#include <string>
#include <iostream>
-int print_and_exit (std::string s)
-{
- std::cerr << s << std::endl;
- return 1;
-}
-
-int main ()
+int main (int argc, const char* argv [])
{
using namespace mln;
using value::int_u8;
typedef image2d<int_u8> image2dint;
- image2dint input, mverif, wverif;
+ image2dint input;
- // #define TEST
+ if (argc != 2) {
+ std::cerr << "usage: " << argv[0] << " in.pgm out.pgm" << std::endl;
+ return 1;
+ }
- // io::pgm::load(input, "./images/test_watershed.pgm");
- // io::pgm::load(input, "./images/little_test.pgm");
- io::pgm::load(input, "./images/test_4.pgm");
- // io::pgm::load(input, "../../img/dots.pgm");
- //io::pgm::load(input, "./images/+irm6.pgm");
-
- // io::pgm::load(input, "./images/lena_light.pgm");
- // io::pgm::load(mverif, "./images/result_m_watershed.pgm");
- // io::pgm::load(wverif, "./images/result_topo_watershed.pgm");
+ io::pgm::load(input, argv[1]);
morpho::basic_najman< image2d<int_u8>, neighb2d> n(input, c4());
- /*
- image2dint::fwd_piter it(input.domain());
- for_all(it)
- {
- input(it) = input(it)/17;
- mverif(it) = mverif(it)/17;
- }
- */
-
- // io::tikz::save(input, "start.tex");
-
n.gotopo();
- io::pgm::save(n.pima, "out.pgm");
+ io::pgm::save(n.pima, argv[2]);
return 0;
}
Index: abraham/tests/morpho/ref/src/lib/lwshedtopo.c
--- abraham/tests/morpho/ref/src/lib/lwshedtopo.c (revision 2236)
+++ abraham/tests/morpho/ref/src/lib/lwshedtopo.c (working copy)
@@ -266,13 +266,13 @@
}
}
}
- //#ifdef _DEBUG_
+ #ifdef _DEBUG_
for (i=0; i<logn; i++) {
for (j=0; j<nbRepresent; j++)
printf("M[%d][%d] = %d - ", i, j, Minim[i][j]);
printf("\n");
}
- //#endif
+ #endif
return Minim;
}
Index: abraham/mln/morpho/basic_najman.hh
--- abraham/mln/morpho/basic_najman.hh (revision 2236)
+++ abraham/mln/morpho/basic_najman.hh (working copy)
@@ -21,16 +21,16 @@
class najman_distance
{
public:
- typedef mln_psite(I) psite;
+ typedef mln_point(I) point;
najman_distance(const Image<I>& ima);
/// Is \a x greater than \a y?
- bool operator()(const psite& x, const psite& y);
+ bool operator()(const point& x, const point& y);
// mln_value(I)
int
- D(const mln_psite(I)& x);
+ D(const mln_point(I)& x);
private:
const I& ima_;
@@ -52,14 +52,14 @@
template <typename I>
// mln_value(I)
int
- najman_distance<I>::D(const mln_psite(I)& x)
+ najman_distance<I>::D(const mln_point(I)& x)
{
const I& ima = exact(ima_);
mln_piter(I) it(ima.domain());
it.start();
- mln_psite(I) min = it.to_point();
+ mln_point(I) min = it.to_point();
for_all(it)
{
@@ -82,7 +82,7 @@
template <typename I>
bool
- najman_distance<I>::operator()(const mln_psite(I)& x, const mln_psite(I)& y)
+ najman_distance<I>::operator()(const mln_point(I)& x, const mln_point(I)& y)
{
if (ima_(x) < ima_(y))
return false;
@@ -437,43 +437,49 @@
struct basic_najman
{
- typedef mln_psite(I) psite;
+ typedef mln_point(I) point;
struct node {
mln_value(I) level;
int area;
int highest;
- p_array<mln_psite(I)> children;
+ typedef mln_point(I) point;
+ // Can't modify the points in a p_array
+ // p_array<mln_point(I)> children;
+ std::vector<point> children;
void addChildren(const node& n)
{
- typename p_array<mln_psite(I)>::fwd_piter it(n.children);
- for (it.start();
- it.is_valid();
- it.next())
- children.append(it.to_psite());
+ // typename p_array<mln_point(I)>::fwd_piter it(n.children);
+ // for (it.start();
+ // it.is_valid();
+ // it.next())
+ // children.append(it.to_point());
+ for (unsigned i=0; i < n.children.size(); ++i)
+ children.push_back(n.children[i]);
}
- void addChild(const psite n)
+ void addChild(const point p)
{
- children.append(n);
+ // children.append(n);
+ children.push_back(p);
}
}; // struct node
I pima;
const Neighborhood<N>& nbh;
- mln_ch_value(I, psite) Par_node;
- mln_ch_value(I, psite) Par_tree;
+ mln_ch_value(I, point) Par_node;
+ mln_ch_value(I, point) Par_tree;
mln_ch_value(I, int) Rnk_tree;
mln_ch_value(I, int) Rnk_node;
- mln_ch_value(I, psite) subtreeRoot;
+ mln_ch_value(I, point) subtreeRoot;
mln_ch_value(I, node) nodes;
mln_ch_value(I, bool) isproc;
- psite Root;
- p_array<mln_psite(I)> S;
- // std::map<psite,psite> M; // to keep the root of any point.
+ point Root;
+ p_array<mln_point(I)> S;
+ // std::map<point,point> M; // to keep the root of any point.
// Ctor
basic_najman(const Image<I>& i,
@@ -490,33 +496,33 @@
{
}
- void MakeSet_tree(psite x)
+ void MakeSet_tree(point x)
{
Par_tree(x) = x;
Rnk_tree(x) = 0;
}
- void MakeSet_node(psite x)
+ void MakeSet_node(point x)
{
Par_node(x) = x;
Rnk_node(x) = 0;
}
- psite Find_tree(psite x)
+ point Find_tree(point x)
{
if (Par_tree(x) != x)
Par_tree(x) = Find_tree(Par_tree(x));
return Par_tree(x);
}
- void swap(psite& x, psite& y)
+ void swap(point& x, point& y)
{
- psite memo = x;
+ point memo = x;
x = y;
y = memo;
}
- psite Find_node(psite x)
+ point Find_node(point x)
{
if (Par_node(x) != x)
Par_node(x) = Find_node(Par_node(x));
@@ -548,7 +554,7 @@
level::fill(isproc, false);
for (int ip = 0; ip < int(S.npoints()); ++ip)
{
- psite p = S[ip];
+ point p = S[ip];
MakeSet_node(p);
MakeSet_tree(p);
// if (subtreeRoot.hold(p))
@@ -561,20 +567,20 @@
void BuildComponentTree()
{
- typename p_array<mln_psite(I)>::fwd_piter ip(S);
+ typename p_array<mln_point(I)>::fwd_piter ip(S);
for_all(ip)
{
- psite p = ip.to_point();
+ point p = ip.to_point();
- psite curCanonicalElt = Find_tree(p);
- psite curNode = Find_node(subtreeRoot(curCanonicalElt));
+ point curCanonicalElt = Find_tree(p);
+ point curNode = Find_node(subtreeRoot(curCanonicalElt));
mln_niter(N) q(nbh, p);
for_all(q)
if (pima.has(q) and isproc(q) and pima(q) <= pima(p))
{
- psite adjCanonicalElt = Find_tree(q);
- psite adjNode = Find_node(subtreeRoot(adjCanonicalElt));
+ point adjCanonicalElt = Find_tree(q);
+ point adjNode = Find_node(subtreeRoot(adjCanonicalElt));
if (curNode != adjNode)
{
if (nodes(curNode).level == nodes(adjNode).level)
@@ -595,7 +601,7 @@
// Pour garder une map de correspondance point <-> local_root
// for (int ip = 0; ip < int(S.size()); ++ip)
// {
- // psite p = S[ip];
+ // point p = S[ip];
// M(p) = Find_node(p);
// }
@@ -603,14 +609,14 @@
for_all(r)
Par_node(r) = Find_node(r);
- Root = subtreeRoot(Find_tree(Find_node(psite(0, 0))));
+ Root = subtreeRoot(Find_tree(Find_node(point(0, 0))));
}
- psite MergeNode(psite& node1, psite& node2)
+ point MergeNode(point& node1, point& node2)
{
- psite tmpNode = Link_node(node1, node2);
- psite tmpNode2;
+ point tmpNode = Link_node(node1, node2);
+ point tmpNode2;
if (tmpNode == node2)
{
nodes(node2).addChildren(nodes(node1));
@@ -626,7 +632,7 @@
return tmpNode;
}
- psite Link_tree(psite x, psite y)
+ point Link_tree(point x, point y)
{
if (Rnk_tree(x) > Rnk_tree(y))
swap(x, y);
@@ -637,7 +643,7 @@
return y;
}
- psite Link_node(psite x, psite y)
+ point Link_node(point x, point y)
{
if (Rnk_node(x) > Rnk_node(y))
swap(x, y);
@@ -664,7 +670,7 @@
{
for(unsigned int j = 0; j < img.domain().len(1); ++j)
{
- C l = (img(psite(i, j)));//.row() * img.domain().len(1) + (img(psite(i, j))).col();
+ C l = (img(point(i, j)));//.row() * img.domain().len(1) + (img(point(i, j))).col();
std::cout << " " << l << " ";
}
std::cout << std::endl;
@@ -673,40 +679,41 @@
- void print_tree(psite p)
+ void print_tree(point p)
{
node& n = nodes(p);
- std::cout << "psite " << p << "(" << n.level << ")=" << (p.row() * exact(subtreeRoot).domain().len(1) + p.col()) << " : ";
+ std::cout << "point " << p << "(" << n.level << ")=" << (p.row() * exact(subtreeRoot).domain().len(1) + p.col()) << " : ";
- typename p_array<mln_psite(I)>::fwd_piter it(n.children);
+ typename p_array<mln_point(I)>::fwd_piter it(n.children);
for_all(it)
{
- psite q = it.to_psite();
+ point q = it.to_point();
std::cout << q << "=" << (q.row() * subtreeRoot.domain().len(1) + q.col()) << " ";
}
std::cout << std::endl;
for_all(it)
{
- print_tree(it.to_psite());
+ print_tree(it.to_point());
}
}
- psite lca (psite a, psite b)
+ point lca (point a, point b)
{
- psite r = lca_rec(Root, Par_node(a), Par_node(b));
+ // point r = lca_rec(Root, Par_node(a), Par_node(b));
+ point r = lca_rec(Root, a, b);
// These two conditions make the lca become a plca
// if (r == Par_node(a))
- // return psite(-1, -1);
+ // return point(-1, -1);
// if (r == Par_node(b))
- // return psite(-1, -1);
+ // return point(-1, -1);
return r;
}
- psite lca_rec (psite cur, psite a, psite b)
+ point lca_rec (point cur, point a, point b)
{
// FIXME : naive implementation, make something better
@@ -721,16 +728,19 @@
// We're on a leaf, the point has not been found
- if (nodes(cur).children.npoints() == 0)
- return psite (-1, -1);
+ // if (nodes(cur).children.npoints() == 0)
+ if (nodes(cur).children.size() == 0)
+ return point (-1, -1);
- psite tmp, acc = psite(-1, -1);
+ point tmp, acc = point(-1, -1);
int n = 0;
- typename p_array<mln_psite(I)>::fwd_piter it(nodes(cur).children);
- for_all(it)
- {
- tmp = lca_rec(it.to_psite(), a, b);
- if (tmp != psite(-1, -1))
+ // typename p_array<mln_point(I)>::fwd_piter it(nodes(cur).children);
+ // for_all(it)
+ for (unsigned i=0; i < nodes(cur).children.size(); ++i)
+ {
+ // tmp = lca_rec(it.to_point(), a, b);
+ tmp = lca_rec(nodes(cur).children[i], a, b);
+ if (tmp != point(-1, -1))
{
// On of the point has been encountered in a child branch
@@ -760,13 +770,13 @@
return acc;
}
- psite min (p_set<psite>& components)
+ point min (p_set<point>& components)
{
if (components.npoints() == 0)
- return psite(-1, -1);
+ return point(-1, -1);
- typename p_set<psite>::fwd_piter it(components);
- psite min = components[0];
+ typename p_set<point>::fwd_piter it(components);
+ point min = components[0];
for_all(it)
if (pima(it.to_point()) < pima(min))
@@ -775,13 +785,13 @@
return min;
}
- psite max (p_set<psite>& components)
+ point max (p_set<point>& components)
{
if (components.npoints() == 0)
- return psite(-1, -1);
+ return point(-1, -1);
- typename p_set<psite>::fwd_piter it(components);
- psite max = components[0];
+ typename p_set<point>::fwd_piter it(components);
+ point max = components[0];
for_all(it)
if (pima(it.to_point()) > pima(max))
@@ -791,166 +801,165 @@
}
- psite highest_fork (p_set<psite>& components)
+ point highest_fork (p_set<point>& components)
{
if (components.npoints() == 0)
{
std::cerr << "highest fork : empty set" << std::endl;
- return psite(-1, -1);
+ return point(-1, -1);
}
// if (components.npoints() == 1)
// return components[0];
- psite
+ point
m = min(components),
hfork = m;
- typename p_set<psite>::fwd_piter it(components);
+ typename p_set<point>::fwd_piter it(components);
for_all(it)
{
// Can't remove the point from the set
if (it.to_point() == m)
continue;
- psite c = lca(hfork, it.to_point());
+ point c = lca(hfork, it.to_point());
if (c != it.to_point())
// hfork = it.to_point();
hfork = c;
}
if (nodes(m).level == nodes(hfork).level)
- return psite(-1, -1);
+ return point(-1, -1);
return hfork;
}
- psite w_destructible(psite p)
+ point w_destructible(point p)
{
mln_niter(N) q(nbh, p);
- p_set<psite> v;
+ p_set<point> v;
for_all(q)
if (pima.has(q) && pima(q) < pima(p))
v.insert(Par_node(q));
if (v.npoints() == 0)
- return psite(-1, -1);
+ return point(-1, -1);
- psite hf = highest_fork(v);
+ point hf = highest_fork(v);
- if (hf == psite(-1, -1))
+ if (hf == point(-1, -1))
return min(v);
if (nodes(hf).level <= pima(p))
return hf;
- return psite(-1, -1);
+ return point(-1, -1);
}
- psite m_destructible(psite p)
+ point m_destructible(point p)
{
mln_niter(N) q(nbh, p);
- p_set<psite> v = p_set<psite>();
+ p_set<point> v = p_set<point>();
for_all(q)
if (pima.has(q) && pima(q) < pima(p))
v.insert(Par_node(q));
if (v.npoints() == 0)
- return psite(-1, -1);
+ return point(-1, -1);
- if (nodes(min(v)).children.npoints() != 0)
- return (psite(-1, -1));
+ // if (nodes(min(v)).children.npoints() != 0)
+ if (nodes(min(v)).children.size() != 0)
+ return (point(-1, -1));
//std::cout << "hf of " << p << ":" << v;
- psite hf = highest_fork(v);
+ point hf = highest_fork(v);
//std::cout << " is " << hf << std::endl;
- if (hf == psite(-1, -1))
+ if (hf == point(-1, -1))
return min(v);
- return psite(-1, -1);
+ return point(-1, -1);
}
- psite w_constructible(psite p)
+ point w_constructible(point p)
{
mln_niter(N) q(nbh, p);
- p_set<psite> v;
+ p_set<point> v;
for_all(q)
if (pima.has(q) && pima(q) > pima(p))
v.insert(Par_node(q));
if (v.npoints() == 0)
- return psite(-1, -1);
+ return point(-1, -1);
if (v.npoints() == 1)
- {
- if (nodes(v[0]).children.npoints() == 1)
- std::cout << "SINGL QUI MERDE" << std::endl;
return v[0];
- }
- psite
+ point
c = max(v),
cmax = c;
- typename p_set<psite>::fwd_piter it(v);
+ typename p_set<point>::fwd_piter it(v);
for_all(it)
{
// Can't remove the point from the set
if (it.to_point() == cmax)
continue;
- psite c1 = lca_opt(c, it.to_point());
+ point c1 = lca_opt(c, it.to_point());
+ // point c2 = lca(c, it.to_point());
+
+ // if (c1 != c2)
+ // std::cout << "DIFF LCA! points : " << c << " and " << it.to_point() << " opt : " << c1 << " classic : " << c2 << std::endl;
+
if (c1 != it.to_point())
c = c1;
}
if (nodes(c).level <= pima(p))
- return psite(-1, -1);
-
- if (nodes(c).children.npoints() == 1)
- std::cout << "LCA QUI MERDE" << std::endl;
+ return point(-1, -1);
return c;
}
- psite w_constructible_slow(psite p)
+ point w_constructible_slow(point p)
{
mln_niter(N) q(nbh, p);
- p_set<psite> v;
+ p_set<point> v;
for_all(q)
if (pima.has(q) && pima(q) > pima(p))
v.insert(Par_node(q));
if (v.npoints() == 0)
- return psite(-1, -1);
+ return point(-1, -1);
if (v.npoints() == 1)
return v[0];
- psite
+ point
c = max(v),
cmax = c;
- typename p_set<psite>::fwd_piter it(v);
+ typename p_set<point>::fwd_piter it(v);
for_all(it)
{
// Can't remove the point from the set
if (it.to_point() == cmax)
continue;
- psite c1 = lca(c, it.to_point());
+ point c1 = lca(c, it.to_point());
if (c1 != it.to_point())
c = c1;
}
if (nodes(c).level <= pima(p))
- return psite(-1, -1);
+ return point(-1, -1);
return c;
}
@@ -961,8 +970,8 @@
// FIXME : make a better priority function
typedef
- std::priority_queue< psite, std::vector<psite>, util::greater_psite<I> >
- // std::priority_queue< psite, std::vector<psite>, util::najman_distance<I> >
+ std::priority_queue< point, std::vector<point>, util::greater_psite<I> >
+ // std::priority_queue< point, std::vector<point>, util::najman_distance<I> >
ordered_queue_type;
@@ -974,14 +983,14 @@
mln_piter(I) it(pima.domain());
for_all(it)
- if (m_destructible(it.to_point()) != psite(-1, -1))
+ if (m_destructible(it.to_point()) != point(-1, -1))
{
//std::cout << "init: push " << it.to_point() << std::endl;
l.push(it.to_point());
isproc(it.to_point()) = true;
}
- psite p, i;
+ point p, i;
while (!l.empty())
{
// Extract priority queue
@@ -994,7 +1003,7 @@
i = m_destructible(p);
//std::cout << "point " << p << "is m-destructible " << i << std::endl;
- if (i != psite(-1, -1))
+ if (i != point(-1, -1))
{
pima(p) = nodes(i).level - 1 ;
Par_node(p) = i;
@@ -1002,10 +1011,10 @@
mln_niter(N) q(nbh, p);
for_all(q)
if (pima.has(q) && !isproc(q))
- if (m_destructible(q) != psite(-1, -1))
+ if (m_destructible(q) != point(-1, -1))
{
- // if (q == psite(1, 1))
- // std::cout << "psite(1, 1) ajoute dans la boucle" << std::endl;
+ // if (q == point(1, 1))
+ // std::cout << "point(1, 1) ajoute dans la boucle" << std::endl;
// Add priority queue
l.push(q);
@@ -1019,7 +1028,7 @@
void w_watershed()
{
- std::map< mln_value(I), std::set<psite> > L;
+ std::map< mln_value(I), std::set<point> > L;
// Setting the min and the max of the image
mln_value(I) k, kmin, kmax;
@@ -1027,24 +1036,24 @@
// For k From kmin to kmax - 1 Do Lk <- <empty set>
for (k = kmin; k < kmax; k++)
- L[k] = std::set<psite>();
+ L[k] = std::set<point>();
// I K(pima.domain(), pima.border());
mln_ch_value(I, int) K(pima.domain(), pima.border());
level::fill(K, 73320);
- mln_ch_value(I, psite) H(pima.domain(), pima.border());
+ mln_ch_value(I, point) H(pima.domain(), pima.border());
// For All p of E do
mln_piter(I) it(pima.domain());
for_all(it)
{
- psite p = it.to_point();
+ point p = it.to_point();
// i <- W-Destructible(p)
- psite i = w_destructible(p);
+ point i = w_destructible(p);
// If i != infinity then
- if (i != psite(-1, -1))
+ if (i != point(-1, -1))
{
L[nodes(i).level - 1].insert(p);
K(p) = nodes(i).level - 1;
@@ -1054,11 +1063,11 @@
for (k = kmin; k < kmax; k++)
{
- std::set<psite>& Lk = L[k];
+ std::set<point>& Lk = L[k];
while (!Lk.empty())
{
- psite p = *(Lk.begin());
+ point p = *(Lk.begin());
Lk.erase(p);
if (K(p) == 73320)
@@ -1073,8 +1082,8 @@
for_all(q)
if (pima.has(q) && k < pima(q))
{
- psite i = w_destructible(q);
- if (i == psite(-1, -1))
+ point i = w_destructible(q);
+ if (i == point(-1, -1))
K(q) = 10000;
else
if (K(q) != nodes(i).level - 1)
@@ -1092,8 +1101,8 @@
std::cout << "cas improbable" << std::endl;
- psite i = w_destructible(p);
- if (i == psite(-1, -1))
+ point i = w_destructible(p);
+ if (i == point(-1, -1))
K(p) = 10000;
else
if (K(p) != nodes(i).level - 1)
@@ -1112,16 +1121,17 @@
}
- void revert_tree (psite p)
+ void revert_tree (point p)
{
node& n = nodes(p);
n.level = 255 - n.level;
- typename p_array<mln_psite(I)>::fwd_piter it(n.children);
-
- for_all(it)
- revert_tree(it.to_psite());
+ // typename p_array<mln_point(I)>::fwd_piter it(n.children);
+ // for_all(it)
+ // revert_tree(it.to_point());
+ for (unsigned i=0; i < n.children.size(); ++i)
+ revert_tree(n.children[i]);
}
void gotopo()
@@ -1132,6 +1142,10 @@
BuildComponentTree();
std::cout << " done" << std::endl;
+ std::cout << "Compressing tree..." << std::endl;
+ compressTree();
+ std::cout << " done" << std::endl;
+
mln_piter(I) p (pima.domain());
for_all(p)
pima(p) = 255 - pima(p);
@@ -1166,14 +1180,15 @@
// Not used
// level::fill(isproc, false);
- util::fah_queue < psite, mln_value(I) > l;
+ util::fah_queue < point, mln_value(I) > l;
mln_value(I) max = mln_max(mln_value(I));
// Flag C-maxima
level::fill(cmax, false);
mln_piter(I) it(Par_node.domain());
for_all(it)
- if (nodes(Par_node(it.to_point())).children.npoints() == 0)
+ // if (nodes(Par_node(it.to_point())).children.npoints() == 0)
+ if (nodes(Par_node(it.to_point())).children.size() == 0)
cmax(it.to_point()) = true;
// Optimisation : enqueue minima's neighbours
@@ -1196,32 +1211,34 @@
// Main loop
while(!l.is_empty())
{
- psite x = l.top();
+ point x = l.top();
l.pop();
enqueued(x) = false;
- psite c = w_constructible(x);
- // psite d = w_constructible_slow(x);
+ point c = w_constructible(x);
+ // point d = w_constructible_slow(x);
//if (c != d)
// std::cerr << "COUILLE AVEC LE LCA : " << x << " donne " << c << " au lieu de " << d << std::endl;
- if (c != psite(-1, -1))
+ if (c != point(-1, -1))
{
pima(x) = nodes(c).level;
Par_node(x) = c;
// isproc(x) = true;
- if (nodes(c).children.npoints() == 0)
+ // if (nodes(c).children.npoints() == 0)
+ if (nodes(c).children.size() == 0)
cmax(x) = true;
else
- if (nodes(c).children.npoints() > 1)
+ // if (nodes(c).children.npoints() > 1)
+ if (nodes(c).children.size() > 1)
{
}
else
{
- std::cerr << "ERREUR COMPOSANTE BRANCHE " << nodes(c).children.npoints() << std::endl;
+ std::cerr << "ERREUR COMPOSANTE BRANCHE " << nodes(c).children.size() << std::endl;
}
@@ -1233,7 +1250,7 @@
l.push(q, max - pima(q));
}
- } // if (c != psite(-1, -1))
+ } // if (c != point(-1, -1))
} // while(!l.empty())
for_all(it)
@@ -1246,23 +1263,26 @@
int *euler;
int *depth;
int ctree_size;
- std::map<psite, int> pos;
- psite *repr;
+ std::map<point, int> pos;
+ point *repr;
int *minim;
int **Minim;
- void compute_ctree_size (psite p)
+ void compute_ctree_size (point p)
{
ctree_size += 1;
node& n = nodes(p);
- typename p_array<mln_psite(I)>::fwd_piter it(n.children);
- for_all(it)
- compute_ctree_size(it.to_point());
+ // typename p_array<mln_point(I)>::fwd_piter it(n.children);
+ // for_all(it)
+ // compute_ctree_size(it.to_point());
+
+ for (unsigned i=0; i < n.children.size(); ++i)
+ compute_ctree_size(n.children[i]);
}
- void build_euler_tour_rec(psite p, int &position, int d)
+ void build_euler_tour_rec(point p, int &position, int d)
{
if (pos.find(p) == pos.end())
pos[p] = position;
@@ -1273,16 +1293,24 @@
++position;
node& n = nodes(p);
- typename p_array<mln_psite(I)>::fwd_piter it(n.children);
- for_all(it)
+ // typename p_array<mln_point(I)>::fwd_piter it(n.children);
+ // for_all(it)
+ // {
+ // build_euler_tour_rec(it.to_point(), position, d+1);
+ // depth[position] = d; // Not optimized
+ // euler[position] = pos[p];
+ // repr[position] = p; // Pas necessaire?
+ // ++position;
+ // }
+
+ for(unsigned i=0; i < n.children.size(); ++i)
{
- build_euler_tour_rec(it.to_point(), position, d+1);
+ build_euler_tour_rec(n.children[i], position, d+1);
depth[position] = d; // Not optimized
euler[position] = pos[p];
repr[position] = p; // Pas necessaire?
++position;
}
-
}
void build_euler_tour ()
@@ -1295,7 +1323,7 @@
// FIXME : free this
euler = new int[size];
depth = new int[size];
- repr = new psite[size];
+ repr = new point[size];
int position = 0;
build_euler_tour_rec(Root, position, 0);
@@ -1341,7 +1369,7 @@
} // void build_minim ()
- psite lca_opt (psite a, psite b)
+ point lca_opt (point a, point b)
{
int
m = pos[a],
@@ -1367,6 +1395,40 @@
}
}
+
+ void removeOneSonNodes(point *p, mln_ch_value(I, point) &newPar_node)
+ {
+ node &n = nodes(*p);
+
+ if (n.children.size() == 1) // this node has 1 son, delete it
+ {
+ n.area = -1;
+ newPar_node(*p) = n.children[0];
+ *p = n.children[0];
+ removeOneSonNodes(p, newPar_node);
+ }
+ else // there is more than one son, recursive call
+ {
+ for (unsigned i = 0; i < n.children.size(); ++i)
+ removeOneSonNodes(&(n.children[i]), newPar_node);
+ }
+ }
+
+
+ void compressTree()
+ {
+ mln_ch_value(I, point) newPar_node(Par_node.domain(), Par_node.border());
+
+ // Remove the nodes with one son
+ removeOneSonNodes(&Root, newPar_node);
+
+ // Update the references on deleted nodes
+ mln_piter(I) p(Par_node.domain());
+ for_all(p)
+ while (nodes(Par_node(p)).area == -1)
+ Par_node(p) = newPar_node(Par_node(p));
+ }
+
}; // struct basic_najman
}; // namespace morpho
1
0
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Fix level fill.
* mln/level/fill.hh: Fix missing exact.
fill.hh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Index: mln/level/fill.hh
--- mln/level/fill.hh (revision 2235)
+++ mln/level/fill.hh (working copy)
@@ -82,7 +82,7 @@
template <typename I, typename D>
void fill_dispatch(Image<I>& ima, const D& data)
{
- fill_dispatch_overload(ima, exact(data));
+ fill_dispatch_overload(exact(ima), exact(data));
}
// dispatch_overload
1
0