Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Get rid of Generalized_Point, replaced by Point_Site.
* mln/core/concept/point_iterator.hh: Change inheritance
from Iterator to Point_Site.
* mln/core/concept/doc/generalized_point.hh: Rename as...
* mln/core/concept/doc/point_site.hh: ...this; update.
Then update.
* tests/rle_image.cc: Add todo.
* mln/core/internal/point_iterator_base.hh
(operator[]): New.
* mln/core/rle_image.hh: Conform to style.
* mln/core/concept/generalized_point.hh: Remove.
* mln/core/concept/delta_point_site.hh: New.
* mln/core/concept/point.hh (Point<void>): New.
* mln/core/concept/dpoint.hh (Dpoint<void>): New.
(operator): Remove all; obsolete.
* mln/value/concept/built_in.hh: Add comment.
* mln/core/dpoints_piter.hh,
* mln/core/mesh_psite.hh,
* mln/core/window.hh,
* mln/core/dpoints_pixter.hh,
* mln/core/mesh_p.hh,
* mln/core/internal/piter_adaptor.hh,
* mln/core/internal/run_pset.hh,
* mln/core/internal/run_psite.hh,
* mln/core/internal/check/image_fastest.hh,
* mln/core/mesh_p_piter.hh,
* mln/core/line_piter.hh,
* mln/core/vec_p_piter.hh,
* mln/core/box_piter.hh,
* mln/core/concept/dpoint.hh,
* mln/core/concept/value_iterator.hh,
* mln/core/concept/point.hh,
* mln/core/concept/point_set.hh,
* mln/core/concept/point_site.hh,
* mln/linear/local/convolve.hh,
* mln/convert/to_window.hh,
* mln/convert/to_set_p.hh,
* mln/convert/to_dpoint.hh: Update.
mln/convert/to_dpoint.hh | 12 -
mln/convert/to_set_p.hh | 4
mln/convert/to_window.hh | 5
mln/core/box_piter.hh | 20 +-
mln/core/concept/delta_point_site.hh | 218 +++++++++++++++++++++++
mln/core/concept/doc/point_site.hh | 32 +--
mln/core/concept/dpoint.hh | 151 +---------------
mln/core/concept/point.hh | 80 +++++---
mln/core/concept/point_iterator.hh | 40 +++-
mln/core/concept/point_set.hh | 2
mln/core/concept/point_site.hh | 286 ++++++++++++++++++++++++++++---
mln/core/concept/value_iterator.hh | 2
mln/core/dpoints_piter.hh | 20 +-
mln/core/dpoints_pixter.hh | 10 -
mln/core/internal/check/image_fastest.hh | 7
mln/core/internal/piter_adaptor.hh | 10 -
mln/core/internal/point_iterator_base.hh | 11 +
mln/core/internal/run_pset.hh | 39 +++-
mln/core/internal/run_psite.hh | 15 +
mln/core/line_piter.hh | 10 -
mln/core/mesh_p.hh | 2
mln/core/mesh_p_piter.hh | 19 --
mln/core/mesh_psite.hh | 26 +-
mln/core/rle_image.hh | 3
mln/core/vec_p_piter.hh | 20 +-
mln/core/window.hh | 5
mln/linear/local/convolve.hh | 14 -
mln/value/concept/built_in.hh | 3
tests/rle_image.cc | 2
29 files changed, 750 insertions(+), 318 deletions(-)
Index: tests/rle_image.cc
--- tests/rle_image.cc (revision 1397)
+++ tests/rle_image.cc (working copy)
@@ -28,6 +28,8 @@
/*! \file tests/rle_image.cc
*
* \brief Tests on mln::rle_image.
+ *
+ * \todo Trouble with ctor/init since there is no ctor with arg!
*/
#include <mln/core/image2d.hh>
Index: mln/core/dpoints_piter.hh
--- mln/core/dpoints_piter.hh (revision 1397)
+++ mln/core/dpoints_piter.hh (working copy)
@@ -35,7 +35,7 @@
*/
# include <mln/core/internal/point_iterator_base.hh>
-# include <mln/core/concept/generalized_point.hh>
+# include <mln/core/concept/point_site.hh>
namespace mln
@@ -58,13 +58,13 @@
*/
template <typename Dps, typename Pref>
dpoints_fwd_piter(const Dps& dps, // FIXME: explicitly set_of_<D>?
- const Generalized_Point<Pref>& p_ref);
+ const Point_Site<Pref>& p_ref);
/// Convertion to point.
operator mln_point(D) () const;
- /// Address of the point this iterator designates.
- const mln_point(D)* pointer_() const;
+ /// Reference to the corresponding point.
+ const mln_point(D)& to_point() const;
/// Test the iterator validity.
bool is_valid() const;
@@ -95,7 +95,7 @@
unsigned i_;
mln_point(D) p_; // location of this iterator; p_ makes this iterator be
- // itself a potential center point (Cf. the pointer_() method).
+ // itself a potential center point.
};
@@ -110,9 +110,9 @@
template <typename D>
template <typename Dps, typename Pref>
dpoints_fwd_piter<D>::dpoints_fwd_piter(const Dps& dps,
- const Generalized_Point<Pref>& p_ref)
+ const Point_Site<Pref>& p_ref)
: dps_(exact(dps).vect()),
- p_ref_(* internal::force_exact<Pref>(p_ref).pointer_())
+ p_ref_(exact(p_ref).to_point())
{
invalidate();
}
@@ -125,10 +125,10 @@
}
template <typename D>
- const mln_point(D)*
- dpoints_fwd_piter<D>::pointer_() const
+ const mln_point(D)&
+ dpoints_fwd_piter<D>::to_point() const
{
- return & p_;
+ return p_;
}
template <typename D>
Index: mln/core/mesh_psite.hh
--- mln/core/mesh_psite.hh (revision 1397)
+++ mln/core/mesh_psite.hh (working copy)
@@ -31,13 +31,19 @@
/*! \file mln/core/mesh_p.hh
*
* \brief Definition of a graph-based point site.
+ *
+ * \todo Clean-up!
*/
+
namespace mln
{
+ // Fwd decl.
template<typename P> class mesh_p;
+
+ // FIXME: Doc!
template<typename P>
struct mesh_psite : public Point_Site< mesh_psite<P> >
{
@@ -48,12 +54,15 @@
typedef mln_coord(P) coord;
mesh_psite(unsigned i, mesh_p<P>* m_ptr);
- P to_point() const;
+
operator P() const;
- const point* pointer_() const;
+
+ const point& to_point() const;
+
coord operator[](unsigned i) const;
unsigned i_;
+
mesh_p<P>* m_ptr_;
};
@@ -67,23 +76,16 @@
}
template<typename P>
- P
- mesh_psite<P>::to_point() const
- {
- return m_ptr_->loc_[i_];
- }
-
- template<typename P>
mesh_psite<P>::operator P() const
{
return m_ptr_->loc_[i_];
}
template<typename P>
- const P*
- mesh_psite<P>::pointer_() const
+ const P&
+ mesh_psite<P>::to_point() const
{
- return 0;
+ return m_ptr_->loc_[i_];
}
template<typename P>
Index: mln/core/window.hh
--- mln/core/window.hh (revision 1397)
+++ mln/core/window.hh (working copy)
@@ -37,7 +37,7 @@
*/
# include <mln/core/concept/window.hh>
-# include <mln/core/concept/generalized_point.hh>
+# include <mln/core/concept/point_site.hh>
# include <mln/core/internal/dpoints_base.hh>
# include <mln/core/dpoint.hh>
# include <mln/core/box.hh>
@@ -132,7 +132,8 @@
template <typename D>
window<D>::window()
{
- mln::metal::is_a<D, Dpoint>::check();
+ // FIXME HERE: Was: mln::metal::is_a<D, Dpoint>::check();
+ mln::metal::is_a<D, Delta_Point_Site>::check();
}
template <typename D>
Index: mln/core/dpoints_pixter.hh
--- mln/core/dpoints_pixter.hh (revision 1397)
+++ mln/core/dpoints_pixter.hh (working copy)
@@ -38,7 +38,7 @@
# include <vector>
# include <mln/core/concept/pixel_iterator.hh>
-# include <mln/core/concept/generalized_pixel.hh>
+# include <mln/core/concept/point_site.hh>
# include <mln/core/internal/pixel_impl.hh>
@@ -62,12 +62,12 @@
*
* \param[in] image Image subject to iteration.
* \param[in] dps Object that can provide a set of delta-points.
- * \param[in] p_ref Center (generalized) point to iterate around.
+ * \param[in] p_ref Center point to iterate around.
*/
template <typename Dps, typename Pref>
dpoints_fwd_pixter(I& image,
const Dps& dps,
- const Generalized_Point<Pref>& p_ref);
+ const Point_Site<Pref>& p_ref);
/*! \brief Constructor.
*
@@ -129,11 +129,11 @@
template <typename Dps, typename Pref>
dpoints_fwd_pixter<I>::dpoints_fwd_pixter(I& image,
const Dps& dps,
- const Generalized_Point<Pref>& p_ref)
+ const Point_Site<Pref>& p_ref)
: super_(image)
{
mln_precondition(image.has_data());
- p_ref_ = internal::force_exact<Pref>(p_ref).pointer_();
+ p_ref_ = & exact(p_ref).to_point();
value_ref_ = 0;
init_(dps);
}
Index: mln/core/mesh_p.hh
--- mln/core/mesh_p.hh (revision 1397)
+++ mln/core/mesh_p.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef MLN_MESH_P_HH
# define MLN_MESH_P_HH
-# include <mln/core/concept/point.hh>
+# include <mln/core/concept/point_site.hh>
# include <mln/core/internal/point_set_base.hh>
# include <mln/accu/bbox.hh>
# include <mln/util/graph.hh>
Index: mln/core/internal/point_iterator_base.hh
--- mln/core/internal/point_iterator_base.hh (revision 1397)
+++ mln/core/internal/point_iterator_base.hh (working copy)
@@ -71,6 +71,9 @@
/// Coord associated type.
typedef mln_coord(point) coord;
+ // Access to the i-th coordinate.
+ coord operator[](unsigned i) const;
+
protected:
/// Constructor.
point_iterator_base_();
@@ -85,6 +88,14 @@
mln::metal::is_a<P, Point_Site>::check();
}
+ template <typename P, typename E>
+ typename point_iterator_base_<P, E>::coord
+ point_iterator_base_<P, E>::operator[](unsigned i) const
+ {
+ mln_precondition(i < dim);
+ return exact(*this).to_point()[i];
+ }
+
#endif // ! MLN_INCLUDE_ONLY
} // end of namespace internal
Index: mln/core/internal/piter_adaptor.hh
--- mln/core/internal/piter_adaptor.hh (revision 1397)
+++ mln/core/internal/piter_adaptor.hh (working copy)
@@ -63,8 +63,8 @@
/// Convertion to point.
operator mln_point(Pi) () const;
- /// Address of the point.
- const mln_point(Pi)* pointer_() const;
+ /// Reference to the corresponding point.
+ const mln_point(Pi)& to_point() const;
/// Give the i-th coordinate.
mln_coord(Pi) operator[](unsigned i) const;
@@ -105,10 +105,10 @@
}
template <typename Pi, typename E>
- const mln_point(Pi)*
- piter_adaptor_<Pi,E>::pointer_() const
+ const mln_point(Pi)&
+ piter_adaptor_<Pi,E>::to_point() const
{
- return piter_.pointer_();
+ return piter_.to_point();
}
template <typename Pi, typename E>
Index: mln/core/internal/run_pset.hh
--- mln/core/internal/run_pset.hh (revision 1397)
+++ mln/core/internal/run_pset.hh (working copy)
@@ -69,15 +69,19 @@
run_pset_();
+
/// Test is \p p belongs to this point set.
bool has(const run_psite<P>& p) const;
+
/// Give the exact bounding box.
const box_<P>& bbox() const;
+
/// Give the number of points.
typename std::size_t npoints() const;
/// Insert a range, start at point \p p wit len \p len.
void insert(const P& p, unsigned len);
+
/// Return the len of the range starting at point \p p.
unsigned range_len_(const P& p) const;
@@ -85,10 +89,13 @@
const std_container& con() const;
protected:
+
/// Number of points.
typename std::size_t npoints_;
+
/// Points container
std_container con_;
+
/// Exact bounding box.
accu::bbox<P> fb_;
};
@@ -182,18 +189,24 @@
/// Convertion into a point-site.
operator internal::run_psite<P> () const;
+
/// Convertion into a point.
operator P () const;
- /// Return a pointer of the current point.
- const P* pointer_() const;
+
+ /// Reference to the corresponding point.
+ const P& to_point() const;
+
/// Access to the current point coordinates.
mln_coord(P) operator[](unsigned i) const;
protected:
+
/// Current point.
P p_;
+
/// Current site.
internal::run_psite<P> site_;
+
/// Point set container.
const std_container& con_;
@@ -222,11 +235,11 @@
}
template <typename P, typename E>
- const P*
- run_piter_<P, E>::pointer_() const
+ const P&
+ run_piter_<P, E>::to_point() const
{
mln_precondition(exact(this)->is_valid());
- return &p_;
+ return p_;
}
template <typename P, typename E>
@@ -236,6 +249,7 @@
mln_precondition(exact(this)->is_valid());
return p_[i];
}
+
# endif // ! MLN_INCLUDE_ONLY
@@ -253,17 +267,24 @@
/// Test the iterator validity.
bool is_valid() const;
+
/// Invalidate the iterator.
void invalidate();
+
/// Start an iteration.
void start();
+
/// Go to the next point.
void next_();
+
protected:
typename super::std_container::const_iterator it_;
};
+
+
# ifndef MLN_INCLUDE_ONLY
+
template <typename P>
run_fwd_piter_<P>::run_fwd_piter_(const run_pset_<P>& pset) :
super(pset)
@@ -318,6 +339,7 @@
# endif // ! MLN_INCLUDE_ONLY
+
/*! \brief Backward iterator on run_pset_ point set.
*
* Parameter \c P is the type of the point used in the point set.
@@ -332,17 +354,24 @@
/// Test the iterator validity.
bool is_valid() const;
+
/// Invalidate the iterator.
void invalidate();
+
/// Start an iteration.
void start();
+
/// Go to the next point.
void next_();
+
protected:
typename super::std_container::const_reverse_iterator it_;
};
+
+
# ifndef MLN_INCLUDE_ONLY
+
template <typename P>
run_bkd_piter_<P>::run_bkd_piter_(const run_pset_<P>& pset) :
super(pset)
Index: mln/core/internal/run_psite.hh
--- mln/core/internal/run_psite.hh (revision 1397)
+++ mln/core/internal/run_psite.hh (working copy)
@@ -80,13 +80,16 @@
/// Return the position of this psite in the current range.
unsigned& index_();
- const P* pointer_() const;
+ /// Reference to the corresponding point.
+ const P& to_point() const;
+
+ /// Give the i-th coordinate of the corresponding point.
mln_coord(P) operator[](unsigned i) const;
protected:
/// Start of the psite range.
- P point_;
+ P point_; // FIXME: Rename as p_ (like everywhere else!)
/// Position in the psite range.
unsigned range_index_;
@@ -95,7 +98,9 @@
unsigned pset_position_;
};
+
# ifndef MLN_INCLUDE_ONLY
+
template <typename P>
run_psite<P>::run_psite()
{
@@ -160,10 +165,10 @@
}
template <typename P>
- const P*
- run_psite<P>::pointer_() const
+ const P&
+ run_psite<P>::to_point() const
{
- return & point_;
+ return point_;
}
template <typename P>
Index: mln/core/internal/check/image_fastest.hh
--- mln/core/internal/check/image_fastest.hh (revision 1397)
+++ mln/core/internal/check/image_fastest.hh (working copy)
@@ -34,6 +34,7 @@
* images.
*/
+# include <mln/core/internal/force_exact.hh>
namespace mln
@@ -62,7 +63,7 @@
*/
template <typename P>
unsigned
- offset_at(const Generalized_Point<P>& p) const;
+ offset_at(const Point_Site<P>& p) const;
protected:
image_fastest_();
@@ -118,11 +119,11 @@
template <typename E, typename B>
template <typename P>
unsigned // FIXME: std::size_t?
- image_fastest_<E,B>::offset_at(const Generalized_Point<P>& p_) const
+ image_fastest_<E,B>::offset_at(const Point_Site<P>& p_) const
{
// FIXME: check that P is mln_point(E)
const E* this_ = & internal::force_exact<E>(*this);
- const P& p = internal::force_exact<P>(p_);
+ const P& p = exact(p_);
mln_precondition(this_->has_data());
mln_precondition(this_->owns_(p));
Index: mln/core/mesh_p_piter.hh
--- mln/core/mesh_p_piter.hh (revision 1397)
+++ mln/core/mesh_p_piter.hh (working copy)
@@ -54,8 +54,8 @@
mesh_p_piter_(const mesh_p<P>& s);
- /// Give a hook to the point address.
- const P* pointer_() const;
+ /// Reference to the corresponding point.
+ const P& to_point() const;
/// Read-only access to the \p i-th coordinate.
mln_coord(P) operator[](unsigned i) const;
@@ -81,6 +81,8 @@
P p_;
};
+
+
# ifndef MLN_INCLUDE_ONLY
template<typename P>
@@ -90,15 +92,13 @@
invalidate();
}
-
template<typename P>
- const P*
- mesh_p_piter_<P>::pointer_() const
+ const P&
+ mesh_p_piter_<P>::to_point() const
{
- return & p_;
+ return p_;
}
-
template<typename P>
mln_coord(P)
mesh_p_piter_<P>::operator[](unsigned i) const
@@ -106,7 +106,6 @@
return p_[i];
}
-
template<typename P>
bool
mesh_p_piter_<P>::is_valid() const
@@ -114,7 +113,6 @@
return i_ != loc_.size();
}
-
template<typename P>
void
mesh_p_piter_<P>::invalidate()
@@ -122,7 +120,6 @@
i_ = loc_.size();
}
-
template<typename P>
void
mesh_p_piter_<P>::start()
@@ -132,7 +129,6 @@
p_ = loc_[i_];
}
-
template<typename P>
void
mesh_p_piter_<P>::next_()
@@ -142,7 +138,6 @@
p_ = loc_[i_];
}
-
template<typename P>
mesh_p_piter_<P>::operator P() const
{
Index: mln/core/rle_image.hh
--- mln/core/rle_image.hh (revision 1397)
+++ mln/core/rle_image.hh (working copy)
@@ -45,6 +45,7 @@
// Fwd decl.
template <typename P, typename T> struct rle_image;
+
namespace internal
{
@@ -62,6 +63,8 @@
} // end of namespace mln::internal
+
+
/*! \brief RLE image.
*
*
Index: mln/core/line_piter.hh
--- mln/core/line_piter.hh (revision 1397)
+++ mln/core/line_piter.hh (working copy)
@@ -64,8 +64,8 @@
/// Convertion to point.
operator P() const;
- /// Address of the point.
- const P* pointer_() const;
+ /// Reference to the corresponding point.
+ const P& to_point() const;
/// Give the i-th coordinate.
mln_coord(P) operator[](unsigned i) const;
@@ -115,10 +115,10 @@
}
template <typename P>
- const P*
- line_piter_<P>::pointer_() const
+ const P&
+ line_piter_<P>::to_point() const
{
- return & p_;
+ return p_;
}
template <typename P>
Index: mln/core/vec_p_piter.hh
--- mln/core/vec_p_piter.hh (revision 1397)
+++ mln/core/vec_p_piter.hh (working copy)
@@ -56,8 +56,8 @@
template <typename S>
vec_p_fwd_piter_(const Point_Set<S>& s);
- /// Give a hook to the point address.
- const P* pointer_() const;
+ /// Reference of the corresponding point.
+ const P& to_point() const;
/// Read-only access to the \p i-th coordinate.
mln_coord(P) operator[](unsigned i) const;
@@ -102,8 +102,8 @@
template <typename S>
vec_p_bkd_piter_(const Point_Set<S>& s);
- /// Give a hook to the point address.
- const P* pointer_() const;
+ /// Reference of the corresponding point.
+ const P& to_point() const;
/// Read-only access to the \p i-th coordinate.
mln_coord(P) operator[](unsigned i) const;
@@ -144,10 +144,10 @@
}
template <typename P>
- const P*
- vec_p_fwd_piter_<P>::pointer_() const
+ const P&
+ vec_p_fwd_piter_<P>::to_point() const
{
- return & p_;
+ return p_;
}
template <typename P>
@@ -210,10 +210,10 @@
}
template <typename P>
- const P*
- vec_p_bkd_piter_<P>::pointer_() const
+ const P&
+ vec_p_bkd_piter_<P>::to_point() const
{
- return & p_;
+ return p_;
}
template <typename P>
Index: mln/core/box_piter.hh
--- mln/core/box_piter.hh (revision 1397)
+++ mln/core/box_piter.hh (working copy)
@@ -65,8 +65,8 @@
/// Convertion to point.
operator P() const;
- /// Address of the point.
- const P* pointer_() const;
+ /// Reference to the corresponding point.
+ const P& to_point() const;
/// Give the i-th coordinate.
mln_coord(P) operator[](unsigned i) const;
@@ -115,8 +115,8 @@
/// Convertion to point.
operator P() const;
- /// Address of the point.
- const P* pointer_() const;
+ /// Reference to the corresponding point.
+ const P& to_point() const;
/// Give the i-th coordinate.
mln_coord(P) operator[](unsigned i) const;
@@ -162,10 +162,10 @@
}
template <typename P>
- const P*
- box_fwd_piter_<P>::pointer_() const
+ const P&
+ box_fwd_piter_<P>::to_point() const
{
- return & p_;
+ return p_;
}
template <typename P>
@@ -233,10 +233,10 @@
template <typename P>
- const P*
- box_bkd_piter_<P>::pointer_() const
+ const P&
+ box_bkd_piter_<P>::to_point() const
{
- return & p_;
+ return p_;
}
template <typename P>
Index: mln/core/concept/value_iterator.hh
--- mln/core/concept/value_iterator.hh (revision 1397)
+++ mln/core/concept/value_iterator.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/core/concept/iterator.hh>
-# include <mln/core/concept/generalized_point.hh>
+# include <mln/core/concept/point_site.hh>
namespace mln
Index: mln/core/concept/delta_point_site.hh
--- mln/core/concept/delta_point_site.hh (revision 0)
+++ mln/core/concept/delta_point_site.hh (revision 0)
@@ -0,0 +1,218 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_CONCEPT_DELTA_POINT_SITE_HH
+# define MLN_CORE_CONCEPT_DELTA_POINT_SITE_HH
+
+/*! \file mln/core/concept/delta_point_site.hh
+ *
+ * \brief Definition of the concept of mln::Delta_Point_Site.
+ */
+
+# include <mln/core/concept/object.hh>
+# include <mln/core/grids.hh>
+# include <mln/trait/all.hh>
+
+
+namespace mln
+{
+
+ // Fwd decl.
+ template <typename E> struct Delta_Point_Site;
+
+
+
+ namespace trait
+ {
+
+ template < typename L, typename R >
+ struct set_binary_< op::plus,
+ mln::Delta_Point_Site, L, mln::Delta_Point_Site, R >
+ {
+ typedef mln_dpoint(L) ret;
+ };
+
+ template < typename L, typename R >
+ struct set_binary_< op::minus,
+ mln::Delta_Point_Site, L, mln::Delta_Point_Site, R >
+ {
+ typedef mln_dpoint(L) ret;
+ };
+
+ } // end of namespace mln::trait
+
+
+
+ /// Delta point site category flag type.
+ template <>
+ struct Delta_Point_Site<void>
+ {
+ typedef Object<void> super;
+ };
+
+
+ /*! \brief FIXME: Doc!
+ */
+ template <typename E>
+ struct Delta_Point_Site : public Object<E>
+ {
+ typedef Delta_Point_Site<void> category;
+
+ /*
+ enum { dim };
+ typedef mesh;
+
+ typedef point;
+ typedef dpoint;
+ typedef coord;
+
+ const dpoint& to_dpoint() const;
+ coord operator[](unsigned i) const;
+ */
+
+ protected:
+ Delta_Point_Site();
+ };
+
+
+
+ // Operators.
+
+ template <typename D>
+ std::ostream&
+ operator<<(std::ostream& ostr, const Delta_Point_Site<D>& dp);
+
+
+ template <typename L, typename R>
+ bool
+ operator=(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs);
+
+ template <typename L, typename R>
+ bool
+ operator<(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs);
+
+
+ template <typename L, typename R>
+ mln_dpoint(L) // FIXME: promote!
+ operator+(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs);
+
+ template <typename L, typename R>
+ mln_dpoint(L) // FIXME: promote!
+ operator-(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs);
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ Delta_Point_Site<E>::Delta_Point_Site()
+ {
+ int dim = E::dim;
+ mln_invariant(dim > 0);
+ dim = 0;
+ typedef mln_mesh(E) mesh;
+ typedef mln_point(E) point;
+ typedef mln_dpoint(E) dpoint;
+ typedef mln_coord(E) coord;
+ const dpoint& (E::*m1)() const = & E::to_dpoint;
+ m1 = 0;
+ coord (E::*m2)(unsigned i) const = & E::operator[];
+ m2 = 0;
+ }
+
+
+ template <typename D>
+ std::ostream& operator<<(std::ostream& ostr, const Delta_Point_Site<D>& dp_)
+ {
+ const D& dp = exact(dp_);
+ ostr << '(';
+ for (unsigned i = 0; i < D::dim; ++i)
+ ostr << dp[i] << (i = D::dim - 1 ? ')' : ',');
+ return ostr;
+ }
+
+
+ template <typename L, typename R>
+ bool operator=(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_)
+ {
+ mln::metal::bool_<(int(L::dim) = int(R::dim))>::check();
+ const L& lhs = exact(lhs_);
+ const R& rhs = exact(rhs_);
+ for (unsigned i = 0; i < L::dim; ++i)
+ if (lhs[i] != rhs[i])
+ return false;
+ return true;
+ }
+
+ template <typename L, typename R>
+ bool operator<(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_)
+ {
+ mln::metal::bool_<(int(L::dim) = int(R::dim))>::check();
+ const L& lhs = exact(lhs_);
+ const R& rhs = exact(rhs_);
+ for (unsigned i = 0; i < L::dim; ++i)
+ {
+ if (lhs[i] = rhs[i])
+ continue;
+ return lhs[i] < rhs[i];
+ }
+ return false;
+ }
+
+ template <typename L, typename R>
+ mln_dpoint(L) // FIXME: promote!
+ operator+(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_)
+ {
+ mln::metal::bool_<(int(L::dim) = int(R::dim))>::check();
+ const L& lhs = exact(lhs_);
+ const R& rhs = exact(rhs_);
+ mln_dpoint(L) tmp;
+ for (unsigned i = 0; i < L::dim; ++i)
+ tmp[i] = lhs[i] + rhs[i];
+ return tmp;
+ }
+
+ template <typename L, typename R>
+ mln_dpoint(L) // FIXME: promote!
+ operator-(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_)
+ {
+ mln::metal::bool_<(int(L::dim) = int(R::dim))>::check();
+ const L& lhs = exact(lhs_);
+ const R& rhs = exact(rhs_);
+ mln_dpoint(L) tmp;
+ for (unsigned i = 0; i < L::dim; ++i)
+ tmp[i] = lhs[i] - rhs[i];
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_CONCEPT_DELTA_POINT_SITE_HH
Index: mln/core/concept/point.hh
--- mln/core/concept/point.hh (revision 1397)
+++ mln/core/concept/point.hh (working copy)
@@ -34,11 +34,24 @@
*/
# include <mln/core/concept/point_site.hh>
+# include <mln/core/concept/dpoint.hh>
namespace mln
{
+ // Fwd decl.
+ template <typename E> struct Point;
+
+
+ // Point category flag type.
+ template <>
+ struct Point<void>
+ {
+ typedef Point_Site<void> super;
+ };
+
+
/*! \brief Base class for implementation of point classes.
*
* A point is an element of a space.
@@ -53,47 +66,43 @@
*/
typedef P point;
- /*! \brief The pointer is this point address.
+ /*! \brief It is a Point so it returns itself.
*/
- const P* pointer_() const;
+ const P& to_point() const;
protected:
Point();
};
- /*! \brief Add a delta-point \p rhs to a point \p lhs.
+ /*! \brief Shift a point \p by a delta-point \p dp.
*
- * \param[in,out] lhs The targeted point.
- * \param[in] rhs A delta-point.
+ * \param[in,out] p The targeted point.
+ * \param[in] dp A delta-point.
+ * \return A reference to the point \p p once translated by \p dp.
*
- * \pre The type of \p rhs has to be the Dpoint type associated with
- * the type of \p lhs; otherwise this test does not compile.
- *
- * \return A reference to the point \p lhs once translated by \p
- * rhs.
+ * \pre The type of \p dp has to be compatible with the type of \p
+ * p.
*
* \relates mln::Point
*/
- template <typename P>
- P& operator+=(Point<P>& lhs, const mln_dpoint(P)& rhs);
+ template <typename P, typename D>
+ P& operator+=(Point<P>& p, const Dpoint<D>& dp);
- /*! \brief Remove a delta-point \p rhs to a point \p lhs.
- *
- * \param[in,out] lhs The targeted point.
- * \param[in] rhs A delta-point.
+ /*! \brief Shift a point \p by the negate of a delta-point \p dp.
*
- * \pre The type of \p rhs has to be the Dpoint type associated with
- * the type of \p lhs; otherwise this test does not compile.
+ * \param[in,out] p The targeted point.
+ * \param[in] dp A delta-point.
+ * \return A reference to the point \p p once translated by - \p dp.
*
- * \return A reference to the point \p lhs once translated by - \p
- * rhs.
+ * \pre The type of \p dp has to be compatible with the type of \p
+ * p.
*
* \relates mln::Point
*/
- template <typename P>
- P& operator-=(Point<P>& lhs, const mln_dpoint(P)& rhs);
+ template <typename P, typename D>
+ P& operator-=(Point<P>& p, const Dpoint<D>& dp);
@@ -105,25 +114,32 @@
}
template <typename P>
- const P* Point<P>::pointer_() const
+ const P&
+ Point<P>::to_point() const
{
- return exact(this);
+ return exact(*this);
}
- template <typename P>
- P& operator+=(Point<P>& lhs, const mln_dpoint(P)& rhs)
+ template <typename P, typename D>
+ P& operator+=(Point<P>& p_, const Dpoint<D>& dp_)
{
+ P& p = exact(p_);
+ const D& dp = exact(dp_);
+ // FIXME: Use to_vec()!
for (unsigned i = 0; i < P::dim; ++i)
- exact(lhs)[i] += rhs[i];
- return lhs;
+ p[i] += dp[i];
+ return p;
}
- template <typename P>
- P& operator-=(Point<P>& lhs, const mln_dpoint(P)& rhs)
+ template <typename P, typename D>
+ P& operator-=(Point<P>& p_, const Dpoint<D>& dp_)
{
+ P& p = exact(p_);
+ const D& dp = exact(dp_);
+ // FIXME: Use to_vec()!
for (unsigned i = 0; i < P::dim; ++i)
- exact(lhs)[i] -= rhs[i];
- return lhs;
+ p[i] -= dp[i];
+ return p;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/concept/dpoint.hh
--- mln/core/concept/dpoint.hh (revision 1397)
+++ mln/core/concept/dpoint.hh (working copy)
@@ -32,7 +32,7 @@
* \brief Definition of the concept of mln::Dpoint.
*/
-# include <mln/core/concept/object.hh>
+# include <mln/core/concept/delta_point_site.hh>
# include <mln/core/grids.hh>
@@ -42,11 +42,12 @@
// Fwd decl.
template <typename E> struct Dpoint;
+
// Dpoint category flag type.
template <>
struct Dpoint<void>
{
- typedef Object<void> super;
+ typedef Delta_Point_Site<void> super;
};
@@ -61,160 +62,32 @@
* contents.
*/
template <typename E>
- struct Dpoint : public Object<E>
+ struct Dpoint : public Delta_Point_Site<E>
{
typedef Dpoint<void> category;
- /*
- typedef point;
- typedef coord;
- enum { dim };
- coord operator[](unsigned i) const;
- */
+ typedef E dpoint;
+
+ /// It is a Dpoint so it returns itself.
+ const E& to_dpoint() const;
protected:
Dpoint();
};
- /*! \brief Give the negate of the delta-point \p rhs.
- *
- * \param[in] rhs The targeted delta-point.
- *
- * \invariant For all delta-point dp, we have: -(-dp) = dp.
- *
- * \return A delta-point (temporary object).
- *
- * \relates mln::Dpoint
- */
- template <typename D>
- D operator-(const Dpoint<D>& rhs);
-
-
- /*! \brief Add the couple of delta-points \p lhs and \p rhs.
- *
- * \param[in] lhs A delta-point.
- * \param[in] rhs Another delta-point.
- *
- * \return A delta-point (temporary object).
- *
- * \relates mln::Dpoint
- */
- template <typename D>
- D operator+(const Dpoint<D>& lhs, const Dpoint<D>& rhs);
-
-
- /*! \brief Equality comparison between a couple of delta-point \p lhs
- * and \p rhs.
- *
- * \param[in] lhs A first delta-point.
- * \param[in] rhs A second delta-point.
- *
- * \pre Both \p lhs and \p rhs have to be defined on the same
- * topology; otherwise this test does not compile.
- *
- * \return True if both delta-points have the same coordinates,
- * otherwise false.
- *
- * \relates mln::Dpoint
- */
- template <typename Dl, typename Dr>
- bool operator=(const Dpoint<Dl>& lhs, const Dpoint<Dr>& rhs);
-
-
- /*! \brief Ordering "less than" comparison between a couple of
- * delta-points \p lhs and \p rhs.
- *
- * \param[in] lhs A first delta-point.
- * \param[in] rhs A second delta-point.
- *
- * \pre Both \p lhs and \p rhs have to be defined on the same
- * topology; otherwise this test does not compile.
- *
- * \return True if both delta-points have the same coordinates,
- * otherwise false.
- *
- * \relates mln::Dpoint
- */
- template <typename Dl, typename Dr>
- bool operator<(const Dpoint<Dl>& lhs, const Dpoint<Dr>& rhs);
-
-
- /*! \brief Print a delta-point \p p into the output stream \p ostr.
- *
- * \param[in,out] ostr An output stream.
- * \param[in] dp A delta-point.
- *
- * \return The modified output stream \p ostr.
- *
- * \relates mln::Dpoint
- */
- template <typename D>
- std::ostream& operator<<(std::ostream& ostr, const Dpoint<D>& dp);
-
-
-
# ifndef MLN_INCLUDE_ONLY
template <typename E>
Dpoint<E>::Dpoint()
{
- typedef mln_point(E) point;
- typedef mln_coord(E) coord;
- enum { dim = E::dim };
- coord (E::*m)(unsigned i) const = & E::operator[];
- m = 0;
}
- template <typename D>
- D operator-(const Dpoint<D>& rhs)
- {
- D tmp;
- for (unsigned i = 0; i < D::dim; ++i)
- tmp[i] = - exact(rhs)[i];
- return tmp;
- }
-
- template <typename D>
- D operator+(const Dpoint<D>& lhs, const Dpoint<D>& rhs)
- {
- D tmp;
- for (unsigned i = 0; i < D::dim; ++i)
- tmp[i] = exact(lhs)[i] + exact(rhs)[i];
- return tmp;
- }
-
- template <typename Dl, typename Dr>
- bool operator=(const Dpoint<Dl>& lhs, const Dpoint<Dr>& rhs)
- {
- for (unsigned i = 0; i < Dl::dim; ++i)
- if (exact(lhs)[i] != exact(rhs)[i])
- return false;
- return true;
- }
-
- template <typename Dl, typename Dr>
- bool operator<(const Dpoint<Dl>& lhs, const Dpoint<Dr>& rhs)
- {
- for (unsigned i = 0; i < Dl::dim; ++i)
- {
- if (exact(lhs)[i] = exact(rhs)[i])
- continue;
- return exact(lhs)[i] < exact(rhs)[i];
- }
- return false;
- }
-
- template <typename D>
- std::ostream& operator<<(std::ostream& ostr, const Dpoint<D>& dp)
- {
- ostr << '(';
- for (unsigned i = 0; i < D::dim; ++i)
+ template <typename E>
+ const E&
+ Dpoint<E>::to_dpoint() const
{
- ostr << exact(dp)[i]
- << (i = D::dim - 1 ? ')' : ',');
- }
- return ostr;
+ return exact(*this);
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/concept/point_iterator.hh
--- mln/core/concept/point_iterator.hh (revision 1397)
+++ mln/core/concept/point_iterator.hh (working copy)
@@ -31,11 +31,12 @@
/*! \file mln/core/concept/point_iterator.hh
*
* \brief Definition of the concept of mln::Point_Iterator.
+ *
+ * \todo Fix mln/core/concept/doc/point_iterator.hh
*/
-# include <mln/core/concept/iterator.hh>
-# include <mln/core/concept/generalized_point.hh>
# include <mln/core/concept/point_site.hh>
+# include <mln/core/concept/iterator.hh> // To fetch the macros.
namespace mln
@@ -51,22 +52,44 @@
* contents.
*/
template <typename E>
- struct Point_Iterator : public Iterator<E>,
- public Generalized_Point<E>
+ struct Point_Iterator : public Point_Site<E>
{
/*
typedef psite;
+ bool is_valid() const;
+ void invalidate();
+ void start();
+ void next_();
operator psite() const;
*/
+ /*! \brief Go to the next element.
+ *
+ * \warning This is a final method; iterator classes should not
+ * re-defined this method. The actual "next" operation has to be
+ * defined through the \em next_ method.
+ *
+ * \pre The iterator is valid.
+ */
+ void next(); // final
+
protected:
Point_Iterator();
};
+
# ifndef MLN_INCLUDE_ONLY
template <typename E>
+ void
+ Point_Iterator<E>::next() // final
+ {
+ assert(exact(this)->is_valid());
+ exact(this)->next_();
+ }
+
+ template <typename E>
Point_Iterator<E>::Point_Iterator()
{
typedef mln_psite(E) psite;
@@ -74,6 +97,15 @@
psite (E::*m)() const = & E::operator psite;
m = 0;
+
+ bool (E::*m1)() const = & E::is_valid;
+ m1 = 0;
+ void (E::*m2)() = & E::invalidate;
+ m2 = 0;
+ void (E::*m3)() = & E::start;
+ m3 = 0;
+ void (E::*m4)() = & E::next_;
+ m4 = 0;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/concept/point_set.hh
--- mln/core/concept/point_set.hh (revision 1397)
+++ mln/core/concept/point_set.hh (working copy)
@@ -38,7 +38,7 @@
* \todo Move out the ops.
*/
-# include <mln/core/concept/point.hh>
+# include <mln/core/concept/point_site.hh>
# include <mln/core/concept/point_iterator.hh>
Index: mln/core/concept/doc/point_site.hh
--- mln/core/concept/doc/point_site.hh (revision 1395)
+++ mln/core/concept/doc/point_site.hh (working copy)
@@ -25,8 +25,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file mln/core/concept/doc/generalized_point.hh
- * \brief This file documents the concept of mln::Generalized_Point.
+/*! \file mln/core/concept/doc/point_site.hh
+ *
+ * \brief This file documents the concept of mln::Point_Site.
*/
namespace mln
@@ -35,12 +36,12 @@
namespace doc
{
- /*! \brief Documentation class for mln::Generalized_Point.
+ /*! \brief Documentation class for mln::Point_Site.
*
- * \see mln::Generalized_Point
+ * \see mln::Point_Site
*/
template <typename E>
- struct Generalized_Point
+ struct Point_Site
{
/*! \var dim
* \brief Dimension of the space.
@@ -48,6 +49,11 @@
*/
enum { dim };
+ /*! \brief Mesh associated type.
+ * \invariant This type has to derive from mln::Mesh.
+ */
+ typedef void mesh;
+
/*! \brief Point associated type.
* \invariant This type has to derive from mln::Point.
*/
@@ -63,23 +69,13 @@
typedef void coord;
- // FIXME: typedef void topo;
-
-
- /*! \brief Either \c E is a point or an convertion operator into
- * a point is defined.
- *
- * \return A point.
- */
- operator point() const;
-
- /*! \brief Give a hook to the point address.
+ /*! \brief Give a reference to the corresponding point.
*
* This method allows for iterators to refer to a point.
*
- * \return A point address.
+ * \return A point constant reference.
*/
- const point* pointer_() const;
+ const point& to_point() const;
/*! \brief Read-only access to the \p i-th coordinate value.
*
Index: mln/core/concept/point_site.hh
--- mln/core/concept/point_site.hh (revision 1397)
+++ mln/core/concept/point_site.hh (working copy)
@@ -25,29 +25,61 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_CONCEPT_PSITE_HH
-# define MLN_CORE_CONCEPT_PSITE_HH
+#ifndef MLN_CORE_CONCEPT_POINT_SITE_HH
+# define MLN_CORE_CONCEPT_POINT_SITE_HH
/*! \file mln/core/concept/point_site.hh
+ *
* \brief Definition of the concept of mln::Point_Site.
*/
-# include <mln/core/concept/generalized_point.hh>
+# include <mln/core/concept/object.hh>
+# include <mln/core/concept/delta_point_site.hh>
+# include <mln/core/grids.hh>
+# include <mln/trait/all.hh>
+
namespace mln
{
- // FIXME: Hack is "Point" instead of "Points_Site"; change it!
+ // Fwd decls.
+ template <typename E> struct Point_Site;
+
+
+
+ namespace trait
+ {
+ template < typename P, typename D >
+ struct set_binary_< op::plus,
+ mln::Point_Site, P, mln::Delta_Point_Site, D >
+ {
+ typedef mln_point(P) ret;
+ };
- // Fwd decl.
- template <typename E> struct Point;
+ template < typename P, typename D >
+ struct set_binary_< op::minus,
+ mln::Point_Site, P, mln::Delta_Point_Site, D >
+ {
+ typedef mln_point(P) ret;
+ };
+ template < typename L, typename R >
+ struct set_binary_< op::minus,
+ mln::Point_Site, L, mln::Point_Site, R >
+ {
+ typedef mln_dpoint(L) ret;
+ };
- /// Point_Site category flag type.
+ } // end of namespace mln::trait
+
+
+
+
+ /// Point site category flag type.
template <>
- struct Point<void>
+ struct Point_Site<void>
{
typedef Object<void> super;
};
@@ -58,13 +90,10 @@
*
* A point site ("psite" for short) is an object that allows an
* efficient access to data associated with a point. A point site
- * is either a point or designates a point: regular points, deriving
- * from mln::Point, are point sites, yet some point sites are not
- * points.) A point site has the behavior expected from every
- * point; see mln::Generalized_Point.
+ * is either a point or designates a point.
*
- * When a point site is not a point, it is automatically convertible
- * to the point it designates.
+ * When a point site is not really a point, it is automatically
+ * convertible to the point it designates.
*
*
* Let us take the example of a 2D image encoded as an array of runs
@@ -76,16 +105,21 @@
* proper point site is a pair (index of run, index within the run).
*/
template <typename E>
- struct Point_Site : public Object<E>,
- public Generalized_Point<E>
+ struct Point_Site : public Object<E>
{
- typedef Point<void> category; // FIXME: This is a hack! Change the hierarchy...
+ typedef Point_Site<void> category;
/*
- const point* pointer_() const
- {
- return & (exact(this)->operator point());
- }
+ enum { dim };
+ typedef mesh;
+
+ typedef point;
+ typedef dpoint;
+ typedef coord;
+
+ const point& to_point() const;
+
+ coord operator[](unsigned i) const;
*/
protected:
@@ -93,11 +127,219 @@
};
+ /*! \brief Equality comparison between a couple of point site \p lhs
+ * and \p rhs.
+ *
+ * \param[in] lhs A first point site.
+ * \param[in] rhs A second point site.
+ *
+ * \pre Both \p lhs and \p rhs have to be defined on the same
+ * topology; otherwise this test does not compile.
+ *
+ * \return True if both point sites have the same
+ * coordinates, otherwise false.
+ *
+ * \relates mln::Point_Site
+ */
+ template <typename L, typename R>
+ bool operator=(const Point_Site<L>& lhs, const Point_Site<R>& rhs);
+
+
+ /*! \brief Ordering "less than" comparison between a couple of
+ * point sites \p lhs and \p rhs.
+ *
+ * \param[in] lhs A first point site.
+ * \param[in] rhs A second point site.
+ *
+ * This test is based on a lexicographical ordering over coordinates.
+ *
+ * \warning In the general case this ordering relationship is \em
+ * not bound to the way of browsing a domain with a forward point
+ * iterator.
+ *
+ * \pre Both \p lhs and \p rhs have to be defined on the same
+ * topology; otherwise this test does not compile.
+ *
+ * \return True if \p lhs is before \p rhs in the sense of the
+ * coordinates lexicographic comparison, otherwise false.
+ *
+ * \relates mln::Point_Site
+ */
+ template <typename L, typename R>
+ bool operator<(const Point_Site<L>& lhs, const Point_Site<R>& rhs);
+
+
+ /*! \brief Difference between a couple of point site \p lhs and \p
+ * rhs.
+ *
+ * \param[in] lhs A first point site.
+ * \param[in] rhs A second point site.
+ *
+ * \warning There is no type promotion in milena so the client
+ * has to make sure that both points are defined with the same
+ * type of coordinates.
+ *
+ * \pre Both \p lhs and \p rhs have to be defined on the same
+ * topology and with the same type of coordinates; otherwise this
+ * test does not compile.
+ *
+ * \post The result, \p dp, is such as \p lhs = \p rhs + \p dp.
+ *
+ * \return A delta point (temporary object).
+ *
+ * \relates mln::Point_Site
+ * \see mln::Delta_Point_Site
+ */
+ template <typename L, typename R>
+ mln_dpoint(L)
+ operator-(const Point_Site<L>& lhs, const Point_Site<R>& rhs);
+
+
+ /*! \brief Add a delta-point \p rhs to a point site \p lhs.
+ *
+ * \param[in] p A point site.
+ * \param[in] dp A delta-point.
+ *
+ * The type of \p dp has to compatible with the type of \p p.
+ *
+ * \return A point (temporary object).
+ *
+ * \relates mln::Point_Site
+ * \see mln::Delta_Point_Site
+ */
+ template <typename P, typename D>
+ mln_point(P)
+ operator+(const Point_Site<P>& p, const Delta_Point_Site<D>& dp);
+
+
+ /*! \brief Substract a delta-point \p rhs to a point site \p lhs.
+ *
+ * \param[in] p A point site.
+ * \param[in] dp A delta-point.
+ *
+ * The type of \p dp has to compatible with the type of \p p.
+ *
+ * \return A point (temporary object).
+ *
+ * \see mln::Dpoint
+ * \see mln::Delta_Point_Site
+ */
+ template <typename P, typename D>
+ mln_point(P)
+ operator-(const Point_Site<P>& p, const Delta_Point_Site<D>& dp);
+
+
+ /*! \brief Print a point site \p p into the output stream \p ostr.
+ *
+ * \param[in,out] ostr An output stream.
+ * \param[in] p A point site.
+ *
+ * \return The modified output stream \p ostr.
+ *
+ * \relates mln::Point_Site
+ */
+ template <typename P>
+ std::ostream& operator<<(std::ostream& ostr, const Point_Site<P>& p);
+
+
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename E>
Point_Site<E>::Point_Site()
{
+ int dim = E::dim;
+ mln_invariant(dim > 0);
+ dim = 0;
+ typedef mln_mesh(E) mesh;
+ typedef mln_point(E) point;
+ typedef mln_dpoint(E) dpoint;
+ typedef mln_coord(E) coord;
+ const point& (E::*m1)() const = & E::to_point;
+ m1 = 0;
+ coord (E::*m2)(unsigned i) const = & E::operator[];
+ m2 = 0;
+ }
+
+
+ // Operators.
+
+ template <typename L, typename R>
+ bool operator=(const Point_Site<L>& lhs_, const Point_Site<R>& rhs_)
+ {
+ mln::metal::bool_<(int(L::dim) = int(R::dim))>::check();
+ const L& lhs = exact(lhs_);
+ const R& rhs = exact(rhs_);
+ for (unsigned i = 0; i < L::dim; ++i)
+ if (lhs[i] != rhs[i])
+ return false;
+ return true;
+ }
+
+ template <typename L, typename R>
+ bool operator<(const Point_Site<L>& lhs_, const Point_Site<R>& rhs_)
+ {
+ mln::metal::bool_<(int(L::dim) = int(R::dim))>::check();
+ const L& lhs = exact(lhs_);
+ const R& rhs = exact(rhs_);
+ for (unsigned i = 0; i < L::dim; ++i)
+ {
+ if (lhs[i] = rhs[i])
+ continue;
+ return lhs[i] < rhs[i];
+ }
+ return false;
+ }
+
+ template <typename L, typename R>
+ mln_dpoint(L) // FIXME: promote!
+ operator-(const Point_Site<L>& lhs_, const Point_Site<R>& rhs_)
+ {
+ mln::metal::bool_<(int(L::dim) = int(R::dim))>::check();
+ const L& lhs = exact(lhs_);
+ const R& rhs = exact(rhs_);
+ mln_dpoint(L) tmp;
+ for (unsigned i = 0; i < L::dim; ++i)
+ tmp[i] = lhs[i] - rhs[i];
+ mln_postcondition(rhs_ + tmp = lhs_);
+ return tmp;
+ }
+
+ template <typename P, typename D>
+ mln_point(P) // FIXME: promote!
+ operator+(const Point_Site<P>& p_, const Delta_Point_Site<D>& dp_)
+ {
+ mln::metal::bool_<(int(P::dim) = int(D::dim))>::check();
+ const P& p = exact(p_);
+ const D& dp = exact(dp_);
+ mln_point(P) tmp;
+ for (unsigned i = 0; i < P::dim; ++i)
+ tmp[i] = p[i] + dp[i];
+ return tmp;
+ }
+
+ template <typename P, typename D>
+ mln_point(P) // FIXME: promote!
+ operator-(const Point_Site<P>& p_, const Delta_Point_Site<D>& dp_)
+ {
+ mln::metal::bool_<(int(P::dim) = int(D::dim))>::check();
+ const P& p = exact(p_);
+ const D& dp = exact(dp_);
+ mln_point(P) tmp;
+ for (unsigned i = 0; i < P::dim; ++i)
+ tmp[i] = p[i] - dp[i];
+ return tmp;
+ }
+
+ template <typename P>
+ std::ostream& operator<<(std::ostream& ostr, const Point_Site<P>& p_)
+ {
+ const P& p = exact(p_);
+ ostr << '(';
+ for (unsigned i = 0; i < P::dim; ++i)
+ ostr << p[i] << (i = P::dim - 1 ? ')' : ',');
+ return ostr;
}
# endif // ! MLN_INCLUDE_ONLY
@@ -105,4 +347,4 @@
} // end of namespace mln
-#endif // ! MLN_CORE_CONCEPT_PSITE_HH
+#endif // ! MLN_CORE_CONCEPT_POINT_SITE_HH
Index: mln/linear/local/convolve.hh
--- mln/linear/local/convolve.hh (revision 1397)
+++ mln/linear/local/convolve.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/core/concept/image.hh>
-# include <mln/core/concept/generalized_point.hh>
+# include <mln/core/concept/point_site.hh>
# include <mln/core/concept/generalized_pixel.hh>
# include <mln/core/concept/weighted_window.hh>
# include <mln/metal/const.hh>
@@ -61,7 +61,7 @@
*/
template <typename I, typename P, typename W, typename R>
void convolve(const Image<I>& input,
- const Generalized_Point<P>& p,
+ const Point_Site<P>& p,
const Weighted_Window<W>& w_win,
R& result);
@@ -88,11 +88,11 @@
template <typename I, typename P, typename W, typename R>
void convolve(trait::image::speed::any, const I& input,
- const Generalized_Point<P>& p_,
+ const Point_Site<P>& p_,
const W& w_win,
R& result)
{
- const P& p = internal::force_exact<P>(p_);
+ const P& p = exact(p_);
R tmp = 0; // FIXME: zero?
mln_qiter(W) q(w_win, p);
@@ -103,11 +103,11 @@
template <typename I, typename P, typename W, typename R>
void convolve(trait::image::speed::fastest, const I& input,
- const Generalized_Point<P>& p_,
+ const Point_Site<P>& p_,
const W& w_win,
R& result)
{
- const P& p = internal::force_exact<P>(p_);
+ const P& p = exact(p_);
mln_precondition(input.border() >= w_win.delta());
@@ -144,7 +144,7 @@
template <typename I, typename P, typename W, typename R>
void convolve(const Image<I>& input,
- const Generalized_Point<P>& p,
+ const Point_Site<P>& p,
const Weighted_Window<W>& w_win,
R& result)
{
Index: mln/value/concept/built_in.hh
--- mln/value/concept/built_in.hh (revision 1397)
+++ mln/value/concept/built_in.hh (working copy)
@@ -42,7 +42,10 @@
namespace value
{
+ // Fwd decl.
template <typename B> struct Built_In;
+
+
// Category flag type.
template <>
struct Built_In<void> // No inheritance here since this category is special (on the side).
Index: mln/convert/to_window.hh
--- mln/convert/to_window.hh (revision 1397)
+++ mln/convert/to_window.hh (working copy)
@@ -35,7 +35,7 @@
# include <set>
-# include <mln/core/concept/dpoint.hh>
+# include <mln/core/concept/delta_point_site.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/core/window.hh>
# include <mln/pw/image.hh>
@@ -124,7 +124,8 @@
template <typename D>
window<D> to_window(const std::set<D>& s)
{
- mln::metal::is_a<D, Dpoint>::check();
+ // FIXME: Was: mln::metal::is_a<D, Dpoint>::check();
+ mln::metal::is_a<D, Delta_Point_Site>::check();
window<D> win;
for (typename std::set<D>::const_iterator i = s.begin();
i != s.end(); ++i)
Index: mln/convert/to_set_p.hh
--- mln/convert/to_set_p.hh (revision 1397)
+++ mln/convert/to_set_p.hh (working copy)
@@ -35,8 +35,8 @@
# include <set>
-# include <mln/core/concept/dpoint.hh>
# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/concept/point_site.hh>
# include <mln/core/set_p.hh>
# include <mln/pw/image.hh>
# include <mln/pw/cst.hh>
@@ -112,7 +112,7 @@
template <typename P>
set_p<P> to_set_p(const std::set<P>& s)
{
- mln::metal::is_a<P, Point>::check();
+ mln::metal::is_a<P, Point_Site>::check();
set_p<P> pset;
for (typename std::set<P>::const_iterator i = s.begin();
i != s.end(); ++i)
Index: mln/convert/to_dpoint.hh
--- mln/convert/to_dpoint.hh (revision 1397)
+++ mln/convert/to_dpoint.hh (working copy)
@@ -33,7 +33,7 @@
* \brief Conversions to mln::Dpoint.
*/
-# include <mln/core/concept/generalized_point.hh>
+# include <mln/core/concept/point_site.hh>
namespace mln
@@ -42,17 +42,19 @@
namespace convert
{
- /// Convert a generalized point \p p into a delta-point.
+ /// Convert a point site \p p into a delta-point.
template <typename P>
- mln_dpoint(P) to_dpoint(const Generalized_Point<P>& p);
+ mln_dpoint(P) to_dpoint(const Point_Site<P>& p);
# ifndef MLN_INCLUDE_ONLY
template <typename P>
- mln_dpoint(P) to_dpoint(const Generalized_Point<P>& p_)
+ mln_dpoint(P) to_dpoint(const Point_Site<P>& p_)
{
- const P& p = internal::force_exact<P>(p_);
+ const P& p = exact(p_);
+ // FIXME HERE: Add ctors from vec in point_ and dpoint_.
+ // FIXME HERE: Then change to "return mln_dpoint(P)(p.to_vec());"
mln_dpoint(P) dp;
for (unsigned i = 0; i < P::dim; ++i)
dp[i] = p[i];
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-26 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Update tree for tests.
* mln/util/tree.hh,
* mln/util/tree_fast.hh,
* mln/util/tree_to_image.hh,
* tests/tree.cc,
* tests/tree_fast_to_image.cc,
* tests/tree_to_image.cc: Update.
---
mln/util/tree.hh | 5 ++--
mln/util/tree_fast.hh | 24 ++++++++++---------
mln/util/tree_to_image.hh | 2 -
tests/tree.cc | 4 +--
tests/tree_fast_to_image.cc | 25 ++++++++++++++++----
tests/tree_to_image.cc | 55 ++++++++++++++++++++++++--------------------
6 files changed, 69 insertions(+), 46 deletions(-)
Index: trunk/milena/tests/tree.cc
===================================================================
--- trunk/milena/tests/tree.cc (revision 1391)
+++ trunk/milena/tests/tree.cc (revision 1392)
@@ -47,9 +47,9 @@
unsigned elt6= 42;
util::node<unsigned> node(elt1);
- node.add_child(elt2);
+ util::node<unsigned>* node2 = node.add_child(elt2);
node.add_child(elt3);
- util::node<unsigned>* node2 = node.search(elt2);
+// util::node<unsigned>* node2 = node.search(elt2);
mln_assertion(node2);
node2->add_child(elt4);
node2->add_child(elt5);
Index: trunk/milena/tests/tree_fast_to_image.cc
===================================================================
--- trunk/milena/tests/tree_fast_to_image.cc (revision 1391)
+++ trunk/milena/tests/tree_fast_to_image.cc (revision 1392)
@@ -50,6 +50,21 @@
mln::set_p<P> holes;
};
+
+template <typename P, typename V>
+bool operator==(const mln::set_p<P>& lhs, const mln::set_p<P>& rhs)
+{
+ std::size_t n = lhs.npoints ();
+ mln::set_p<P> tmp;
+
+ if (n != rhs.npoints ())
+ return false;
+
+// for (std::size_t i = 0; i < n; ++i)
+// if ()
+
+}
+
template <typename P, typename V>
bool operator==(const struct fllt_node<P,V>& lhs, const struct fllt_node<P,V>& rhs)
{
@@ -58,11 +73,11 @@
/// FIXME
-// if (lhs.points != rhs.points)
-// return false;
+ if (!(lhs.points == rhs.points))
+ return false;
-// if (lhs.holes != rhs.holes)
-// return false;
+ if (!(lhs.holes == rhs.holes))
+ return false;
return true;
}
@@ -113,7 +128,7 @@
s7.value = 10;
util::tree_fast<T> tree(s1);
- tree.add_child(tree.search(s1), s2);
+ tree.add_child(tree.root_, s2);
tree.add_child(tree.search(s1), s3);
tree.add_child(tree.search(s2), s4);
tree.add_child(tree.search(s2), s5);
Index: trunk/milena/tests/tree_to_image.cc
===================================================================
--- trunk/milena/tests/tree_to_image.cc (revision 1391)
+++ trunk/milena/tests/tree_to_image.cc (revision 1392)
@@ -42,12 +42,21 @@
#include <vector>
#include <mln/util/tree_to_image.hh>
+template <typename P, typename V>
+struct fllt_node
+{
+ V value;
+ mln::set_p<P> points;
+ mln::set_p<P> holes;
+};
+
+
int main (void)
{
using namespace mln;
using value::int_u8;
- typedef set_p<point2d > I;
+ typedef fllt_node<point2d , int_u8> I;
image2d<int_u8> output (300, 300);
@@ -61,43 +70,44 @@
for (int i = 0; i < 100; ++i)
for (int j = 0; j < 100; ++j)
- s1.insert(point2d(i, j));
-
+ s1.points.insert(point2d(i, j));
+ s1.value = 60;
for (int i = 200; i < 300; ++i)
for (int j = 0; j < 100; ++j)
- s2.insert(point2d(i, j));
-
+ s2.points.insert(point2d(i, j));
+ s1.value = 100;
for (int i = 0; i < 100; ++i)
for (int j = 0; j < 100; ++j)
- s3.insert(point2d(i, j));
-
+ s3.points.insert(point2d(i, j));
+ s3.value = 110;
for (int i = 260; i < 290; ++i)
for (int j = 0; j < 50; ++j)
- s4.insert(point2d(i, j));
-
+ s4.points.insert(point2d(i, j));
+ s4.value = 170;
for (int i = 200; i < 210; ++i)
for (int j = 0; j < 50; ++j)
- s5.insert(point2d(i, j));
-
+ s5.points.insert(point2d(i, j));
+ s5.value = 180;
for (int i = 270; i < 280; ++i)
for (int j = 50; j < 60; ++j)
- s6.insert(point2d(i, j));
-
+ s6.points.insert(point2d(i, j));
+ s6.value = 210;
for (int i = 0; i < 300; ++i)
for (int j = 0; j < 200; ++j)
- s7.insert(point2d(i, j));
+ s7.points.insert(point2d(i, j));
+ s7.value = 10;
util::node<I> node(s1);
node.add_child(s2);
node.add_child(s3);
- util::node<I>* node2 = node.search(s2);
- mln_assertion(node2);
- node2->add_child(s4);
- node2->add_child(s5);
- util::node<I>* node3 = node.search(s4);
- mln_assertion(node3);
- node3->add_child(s6);
+// util::node<I>* node2 = node.search(s2);
+// mln_assertion(node2);
+ node.add_child(s4);
+ node.add_child(s5);
+// util::node<I>* node3 = node.search(s4);
+// mln_assertion(node3);
+ node.add_child(s6);
util::tree<I> tree (&node);
@@ -113,7 +123,4 @@
std::cout << "out.pgm generate"
<< std::endl;
-
-// tree3 = tree2->search(s1);
-// mln_assertion(!tree3);
}
Index: trunk/milena/mln/util/tree_to_image.hh
===================================================================
--- trunk/milena/mln/util/tree_to_image.hh (revision 1391)
+++ trunk/milena/mln/util/tree_to_image.hh (revision 1392)
@@ -66,8 +66,6 @@
for_all(p)
{
- std::cout << p
- << std::endl;
output(p) = node->elt_.value;
}
typename std::vector< util::node<T>* >::const_iterator it = node->child_.begin();
Index: trunk/milena/mln/util/tree_fast.hh
===================================================================
--- trunk/milena/mln/util/tree_fast.hh (revision 1391)
+++ trunk/milena/mln/util/tree_fast.hh (revision 1392)
@@ -49,15 +49,15 @@
template <typename T>
struct tree_fast
{
-// tree_fast();
+ tree_fast();
tree_fast(T& elt);
const unsigned size() const;
bool has (T& elt) const;
unsigned search (T& elt) const;
bool is_root (unsigned i) const;
- void add_child (unsigned i, T& elt);
- void add_parent (T& elt);
+ unsigned add_child (unsigned i, T& elt);
+ unsigned add_parent (T& elt);
std::vector<T> data_;
std::vector<unsigned> parent_;
@@ -67,10 +67,10 @@
# ifndef MLN_INCLUDE_ONLY
-// template <typename T>
-// tree_fast<T>::tree_fast()
-// {
-// }
+ template <typename T>
+ tree_fast<T>::tree_fast()
+ {
+ }
template <typename T>
tree_fast<T>::tree_fast(T& elt)
@@ -121,7 +121,7 @@
}
template <typename T>
- void
+ unsigned
tree_fast<T>::add_child (unsigned i, T& elt)
{
mln_assertion (i < data_.size ());
@@ -130,19 +130,21 @@
parent_.push_back(i);
child_.push_back(v);
child_[i].push_back(data_.size () - 1);
+ return (data_.size () - 1);
}
template <typename T>
- void
+ unsigned
tree_fast<T>::add_parent (T& elt)
{
- std::vector<unsigned> v;
data_.push_back(elt);
parent_.push_back(data_.size () - 1);
+ std::vector<unsigned> v;
+ v.push_back (root_);
child_.push_back(v);
- child_[data_.size () - 1].push_back(root_);
parent_[root_] = data_.size () - 1;
root_ = data_.size () - 1;
+ return (data_.size () - 1);
}
Index: trunk/milena/mln/util/tree.hh
===================================================================
--- trunk/milena/mln/util/tree.hh (revision 1391)
+++ trunk/milena/mln/util/tree.hh (revision 1392)
@@ -53,7 +53,7 @@
T& content();
const T& content() const;
- void add_child(T& elt);
+ node<T>* add_child(T& elt);
void set_parent(node<T>* parent);
node<T>* get_parent();
void print_rec(int n) const;
@@ -152,13 +152,14 @@
}
template <typename T>
- void
+ node<T>*
node<T>::add_child(T& elt)
{
node<T>* s = new node<T>(elt);
s->parent_ = this;
this->child_.push_back(s);
+ return s;
}
template <typename T>
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add traits for comparison and logical operators.
* mln/trait/op/leq.hh: New.
* mln/trait/op/greater.hh: New.
* mln/trait/op/not.hh: New.
* mln/trait/op/and.hh: New.
* mln/trait/op/less.hh: New.
* mln/trait/op/xor.hh: New.
* mln/trait/op/geq.hh: New.
* mln/trait/op/or.hh: New.
* mln/trait/op/all.hh: Update.
* mln/trait/op/times.hh,
* mln/trait/op/div.hh,
* mln/trait/op/plus.hh,
* mln/trait/op/neq.hh,
* mln/trait/op/minus.hh,
* mln/trait/op/postdec.hh,
* mln/trait/op/predec.hh,
* mln/trait/op/eq.hh,
* mln/trait/op/uplus.hh,
* mln/trait/op/postinc.hh,
* mln/trait/op/mod.hh,
* mln/trait/op/uminus.hh,
* mln/trait/op/preinc.hh: Add file doc.
Remove obsolete fwd decl.
* mln/core/ops.hh: New trait defs for new ops.
* mln/core/concept/point_set.hh
(Point_Set<void>): New category.
* mln/core/concept/point_site.hh: Fix doc.
* mln/value/ops.hh: Remove dead code.
(opertor<): New overload for the couples "scalar_ and Literal".
* mln/value/gray.hh (enc, interop): Change from long to int.
* mln/value/concept/built_in.hh: Remove dead code.
(super): Fix to be compliant with solve.
* mln/value/builtin/integers.hh: Update.
* mln/value/concept/integer.hh: Fix doc.
* mln/value/builtin/ops.hh: New traits for op::uminus and
op::uplus.
Remove unary trait for builtin.
New traits for comparison and logical ops.
* mln/value/builtin/promotions.hh: Update.
* tests/value_scalar.cc: Augment.
* tests/value_builtin.cc: New.
mln/core/concept/point_set.hh | 19 ++++++
mln/core/concept/point_site.hh | 3 -
mln/core/ops.hh | 52 ++++++++++++++---
mln/trait/op/all.hh | 11 +++
mln/trait/op/and.hh | 65 +++++++++++++++++++++
mln/trait/op/div.hh | 5 +
mln/trait/op/eq.hh | 5 +
mln/trait/op/geq.hh | 65 +++++++++++++++++++++
mln/trait/op/greater.hh | 65 +++++++++++++++++++++
mln/trait/op/leq.hh | 65 +++++++++++++++++++++
mln/trait/op/less.hh | 65 +++++++++++++++++++++
mln/trait/op/minus.hh | 7 --
mln/trait/op/mod.hh | 5 +
mln/trait/op/neq.hh | 5 +
mln/trait/op/not.hh | 65 +++++++++++++++++++++
mln/trait/op/or.hh | 65 +++++++++++++++++++++
mln/trait/op/plus.hh | 7 --
mln/trait/op/postdec.hh | 9 +--
mln/trait/op/postinc.hh | 9 +--
mln/trait/op/predec.hh | 9 +--
mln/trait/op/preinc.hh | 9 +--
mln/trait/op/times.hh | 7 --
mln/trait/op/uminus.hh | 10 ---
mln/trait/op/uplus.hh | 9 +--
mln/trait/op/xor.hh | 65 +++++++++++++++++++++
mln/value/builtin/integers.hh | 16 ++---
mln/value/builtin/ops.hh | 66 ++++++++++++++++++----
mln/value/builtin/promotions.hh | 47 ---------------
mln/value/concept/built_in.hh | 14 ----
mln/value/concept/integer.hh | 20 ++----
mln/value/gray.hh | 4 -
mln/value/ops.hh | 49 ++++++++--------
tests/value_builtin.cc | 120 ++++++++++++++++++++++++++++++++++++++++
tests/value_scalar.cc | 49 +++++++++++++++-
34 files changed, 912 insertions(+), 174 deletions(-)
Index: tests/value_scalar.cc
--- tests/value_scalar.cc (revision 1390)
+++ tests/value_scalar.cc (working copy)
@@ -31,7 +31,9 @@
*/
#include <iostream>
+
#include <mln/value/scalar.hh>
+#include <mln/value/int_u8.hh>
template <typename T>
@@ -40,12 +42,53 @@
std::cout << mln::value::scalar(t) << std::endl;
}
+namespace mln
+{
+ namespace trait
+ {
+// template <typename O1, typename O2>
+// struct set_binary_< op::less, Object,O1, Object,O2 > { typedef bool ret; };
+
+// template < typename Vl, typename Vr >
+// struct set_binary_< op::less, mln::value::Scalar, Vl, mln::value::Scalar, Vr >
+// {
+// typedef double ret;
+// };
+
+// template <typename B, typename O>
+// struct set_binary_< op::less,
+// mln::value::Integer, B,
+// mln::value::Scalar, O >
+// {
+// typedef bool ret;
+// };
+
+ }
+}
+
int main()
{
using namespace mln;
- int i = 51;
- foo(i);
- foo( value::scalar(i) );
+// int i = 51;
+// foo(i);
+// foo( value::scalar(i) );
+
+
+ {
+ bool b;
+ value::int_u8 i, j;
+
+ b = 1 > value::scalar(j);
+
+ b = value::scalar(j) < value::scalar(j);
+
+// mln_trait_op_less_(value::scalar_< value::int_u8 >, value::scalar_< value::int_u8 >) tmp;
+// void* v = tmp;
+
+// mln_trait_op_less_(int, value::scalar_< value::int_u8 >) tmp;
+// void* v = tmp;
+ }
+
}
Index: tests/value_builtin.cc
--- tests/value_builtin.cc (revision 0)
+++ tests/value_builtin.cc (revision 0)
@@ -0,0 +1,120 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/value_builtin.cc
+ *
+ * \brief Tests on mln::trait::op with a builtin.
+ */
+
+#include <iostream>
+
+#include <mln/value/scalar.hh>
+#include <mln/value/int_u8.hh>
+
+
+namespace mln
+{
+ namespace trait
+ {
+
+ namespace op
+ {
+
+ template <typename T>
+ struct test;
+
+ template <typename L, typename R>
+ struct test_2;
+
+ }
+
+ // unary
+
+ template < typename S >
+ struct set_unary_< op::test, mln::value::Scalar, S >
+ {
+ typedef double ret;
+ };
+
+// template <typename I>
+// struct set_unary_< op::test,
+// mln::value::Integer, I >
+// {
+// typedef float ret;
+// };
+
+// template <typename I>
+// struct set_unary_< op::test,
+// mln::value::Built_In, I >
+// {
+// typedef bool ret;
+// };
+
+
+ // binary
+
+ template < typename S1, typename S2 >
+ struct set_binary_< op::test_2,
+ mln::value::Scalar, S1,
+ mln::value::Scalar, S2 >
+ {
+ typedef double ret;
+ };
+
+// template < typename I, typename S >
+// struct set_binary_< op::test_2,
+// mln::value::Integer, I,
+// mln::value::Scalar, S >
+// {
+// typedef float ret;
+// };
+
+// template < typename B, typename S >
+// struct set_binary_< op::test_2,
+// mln::value::Built_In, B,
+// mln::value::Scalar, S >
+// {
+// typedef bool ret;
+// };
+
+ }
+}
+
+
+int main()
+{
+ using namespace mln;
+
+ {
+ mln::trait::solve_binary< trait::op::test_2, int, value::scalar_< value::int_u8 > >::ret tmp;
+ double& d = tmp;
+ }
+ {
+ mln::trait::solve_unary< trait::op::test, int >::ret tmp;
+ double& d = tmp;
+ }
+}
Index: mln/trait/op/leq.hh
--- mln/trait/op/leq.hh (revision 0)
+++ mln/trait/op/leq.hh (revision 0)
@@ -0,0 +1,65 @@
+// Copyright (C) 2006 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_TRAIT_OP_LEQ_HH
+# define MLN_TRAIT_OP_LEQ_HH
+
+/*! \file mln/trait/op/leq.hh
+ *
+ * \brief Declaration of the "binary less-or-equal" operator trait.
+ */
+
+# include <mln/trait/solve.hh>
+
+
+# define mln_trait_op_leq(L, R) typename mln::trait::op::leq< L , R >::ret
+# define mln_trait_op_leq_(L, R) mln::trait::op::leq< L , R >::ret
+
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+ namespace op
+ {
+
+ template <typename L, typename R>
+ struct leq : public solve_binary<leq, L, R>
+ {
+ };
+
+ } // end of namespace mln::trait::op
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRAIT_OP_LEQ_HH
Index: mln/trait/op/times.hh
--- mln/trait/op/times.hh (revision 1390)
+++ mln/trait/op/times.hh (working copy)
@@ -28,14 +28,11 @@
#ifndef MLN_TRAIT_OP_TIMES_HH
# define MLN_TRAIT_OP_TIMES_HH
-/*!
- * \file mln/trait/op/times.hh
- *
- * \brief FIXME
+/*! \file mln/trait/op/times.hh
*
+ * \brief Declaration of the "binary multiplication" operator trait.
*/
-
# include <mln/trait/promote.hh>
Index: mln/trait/op/div.hh
--- mln/trait/op/div.hh (revision 1390)
+++ mln/trait/op/div.hh (working copy)
@@ -28,6 +28,11 @@
#ifndef MLN_TRAIT_OP_DIV_HH
# define MLN_TRAIT_OP_DIV_HH
+/*! \file mln/trait/op/div.hh
+ *
+ * \brief Declaration of the "binary division" operator trait.
+ */
+
# include <mln/trait/promote.hh>
Index: mln/trait/op/plus.hh
--- mln/trait/op/plus.hh (revision 1390)
+++ mln/trait/op/plus.hh (working copy)
@@ -28,14 +28,11 @@
#ifndef MLN_TRAIT_OP_PLUS_HH
# define MLN_TRAIT_OP_PLUS_HH
-/*!
- * \file mln/trait/op/plus.hh
- *
- * \brief FIXME
+/*! \file mln/trait/op/plus.hh
*
+ * \brief Declaration of the "binary plus" operator trait.
*/
-
# include <mln/trait/promote.hh>
Index: mln/trait/op/neq.hh
--- mln/trait/op/neq.hh (revision 1390)
+++ mln/trait/op/neq.hh (working copy)
@@ -28,6 +28,11 @@
#ifndef MLN_TRAIT_OP_NEQ_HH
# define MLN_TRAIT_OP_NEQ_HH
+/*! \file mln/trait/op/neq.hh
+ *
+ * \brief Declaration of the "binary un-equality" operator trait.
+ */
+
# include <mln/trait/solve.hh>
Index: mln/trait/op/greater.hh
--- mln/trait/op/greater.hh (revision 0)
+++ mln/trait/op/greater.hh (revision 0)
@@ -0,0 +1,65 @@
+// Copyright (C) 2006 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_TRAIT_OP_GREATER_HH
+# define MLN_TRAIT_OP_GREATER_HH
+
+/*! \file mln/trait/op/greater.hh
+ *
+ * \brief Declaration of the "binary greater" operator trait.
+ */
+
+# include <mln/trait/solve.hh>
+
+
+# define mln_trait_op_greater(L, R) typename mln::trait::op::greater< L , R >::ret
+# define mln_trait_op_greater_(L, R) mln::trait::op::greater< L , R >::ret
+
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+ namespace op
+ {
+
+ template <typename L, typename R>
+ struct greater : public solve_binary<greater, L, R>
+ {
+ };
+
+ } // end of namespace mln::trait::op
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRAIT_OP_GREATER_HH
Index: mln/trait/op/minus.hh
--- mln/trait/op/minus.hh (revision 1390)
+++ mln/trait/op/minus.hh (working copy)
@@ -28,14 +28,11 @@
#ifndef MLN_TRAIT_OP_MINUS_HH
# define MLN_TRAIT_OP_MINUS_HH
-/*!
- * \file mln/trait/op/minus.hh
- *
- * \brief FIXME
+/*! \file mln/trait/op/minus.hh
*
+ * \brief Declaration of the "binary minus" operator trait.
*/
-
# include <mln/trait/promote.hh>
Index: mln/trait/op/not.hh
--- mln/trait/op/not.hh (revision 0)
+++ mln/trait/op/not.hh (revision 0)
@@ -0,0 +1,65 @@
+// Copyright (C) 2006 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_TRAIT_OP_NOT_HH
+# define MLN_TRAIT_OP_NOT_HH
+
+/*! \file mln/trait/op/not.hh
+ *
+ * \brief Declaration of the "unary negation" operator trait.
+ */
+
+# include <mln/trait/solve.hh>
+
+
+# define mln_trait_op_not(T) typename mln::trait::op::not_< T >::ret
+# define mln_trait_op_not_(T) mln::trait::op::not_< T >::ret
+
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+ namespace op
+ {
+
+ template <typename T>
+ struct not_ : public solve_unary<not_, T>
+ {
+ };
+
+ } // end of namespace mln::trait::op
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRAIT_OP_NOT_HH
Index: mln/trait/op/postdec.hh
--- mln/trait/op/postdec.hh (revision 1390)
+++ mln/trait/op/postdec.hh (working copy)
@@ -28,6 +28,11 @@
#ifndef MLN_TRAIT_OP_POSTDEC_HH
# define MLN_TRAIT_OP_POSTDEC_HH
+/*! \file mln/trait/op/postdec.hh
+ *
+ * \brief Declaration of the "unary post-decrementation" operator trait.
+ */
+
# include <mln/trait/solve.hh>
@@ -39,10 +44,6 @@
namespace mln
{
- // Fwd decl.
- template <typename E> struct Object;
-
-
namespace trait
{
Index: mln/trait/op/predec.hh
--- mln/trait/op/predec.hh (revision 1390)
+++ mln/trait/op/predec.hh (working copy)
@@ -28,6 +28,11 @@
#ifndef MLN_TRAIT_OP_PREDEC_HH
# define MLN_TRAIT_OP_PREDEC_HH
+/*! \file mln/trait/op/predec.hh
+ *
+ * \brief Declaration of the "unary pre-decrementation" operator trait.
+ */
+
# include <mln/trait/solve.hh>
@@ -39,10 +44,6 @@
namespace mln
{
- // Fwd decl.
- template <typename E> struct Object;
-
-
namespace trait
{
Index: mln/trait/op/and.hh
--- mln/trait/op/and.hh (revision 0)
+++ mln/trait/op/and.hh (revision 0)
@@ -0,0 +1,65 @@
+// Copyright (C) 2006 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_TRAIT_OP_AND_HH
+# define MLN_TRAIT_OP_AND_HH
+
+/*! \file mln/trait/op/and.hh
+ *
+ * \brief Declaration of the "binary and" operator trait.
+ */
+
+# include <mln/trait/solve.hh>
+
+
+# define mln_trait_op_and(L, R) typename mln::trait::op::and_< L , R >::ret
+# define mln_trait_op_and_(L, R) mln::trait::op::and_< L , R >::ret
+
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+ namespace op
+ {
+
+ template <typename L, typename R>
+ struct and_ : public solve_binary<and_, L, R>
+ {
+ };
+
+ } // end of namespace mln::trait::op
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRAIT_OP_AND_HH
Index: mln/trait/op/eq.hh
--- mln/trait/op/eq.hh (revision 1390)
+++ mln/trait/op/eq.hh (working copy)
@@ -28,6 +28,11 @@
#ifndef MLN_TRAIT_OP_EQ_HH
# define MLN_TRAIT_OP_EQ_HH
+/*! \file mln/trait/op/eq.hh
+ *
+ * \brief Declaration of the "binary equality" operator trait.
+ */
+
# include <mln/trait/solve.hh>
Index: mln/trait/op/less.hh
--- mln/trait/op/less.hh (revision 0)
+++ mln/trait/op/less.hh (revision 0)
@@ -0,0 +1,65 @@
+// Copyright (C) 2006 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_TRAIT_OP_LESS_HH
+# define MLN_TRAIT_OP_LESS_HH
+
+/*! \file mln/trait/op/less.hh
+ *
+ * \brief Declaration of the "binary less" operator trait.
+ */
+
+# include <mln/trait/solve.hh>
+
+
+# define mln_trait_op_less(L, R) typename mln::trait::op::less< L , R >::ret
+# define mln_trait_op_less_(L, R) mln::trait::op::less< L , R >::ret
+
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+ namespace op
+ {
+
+ template <typename L, typename R>
+ struct less : public solve_binary<less, L, R>
+ {
+ };
+
+ } // end of namespace mln::trait::op
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRAIT_OP_LESS_HH
Index: mln/trait/op/all.hh
--- mln/trait/op/all.hh (revision 1390)
+++ mln/trait/op/all.hh (working copy)
@@ -65,7 +65,16 @@
# include <mln/trait/op/eq.hh>
# include <mln/trait/op/neq.hh>
-// FIXME: eq, less, ... + and, xor, ...
+# include <mln/trait/op/less.hh>
+# include <mln/trait/op/leq.hh>
+# include <mln/trait/op/geq.hh>
+# include <mln/trait/op/greater.hh>
+
+# include <mln/trait/op/and.hh>
+# include <mln/trait/op/or.hh>
+# include <mln/trait/op/xor.hh>
+
+# include <mln/trait/op/not.hh>
#endif // ! MLN_TRAIT_OP_ALL_HH
Index: mln/trait/op/uplus.hh
--- mln/trait/op/uplus.hh (revision 1390)
+++ mln/trait/op/uplus.hh (working copy)
@@ -28,6 +28,11 @@
#ifndef MLN_TRAIT_OP_UPLUS_HH
# define MLN_TRAIT_OP_UPLUS_HH
+/*! \file mln/trait/op/uplus.hh
+ *
+ * \brief Declaration of the "unary plus" operator trait.
+ */
+
# include <mln/trait/solve.hh>
@@ -39,10 +44,6 @@
namespace mln
{
- // Fwd decl.
- template <typename E> struct Object;
-
-
namespace trait
{
Index: mln/trait/op/xor.hh
--- mln/trait/op/xor.hh (revision 0)
+++ mln/trait/op/xor.hh (revision 0)
@@ -0,0 +1,65 @@
+// Copyright (C) 2006 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_TRAIT_OP_XOR_HH
+# define MLN_TRAIT_OP_XOR_HH
+
+/*! \file mln/trait/op/xor.hh
+ *
+ * \brief Declaration of the "binary xor" operator trait.
+ */
+
+# include <mln/trait/solve.hh>
+
+
+# define mln_trait_op_xor(L, R) typename mln::trait::op::xor_< L , R >::ret
+# define mln_trait_op_xor_(L, R) mln::trait::op::xor_< L , R >::ret
+
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+ namespace op
+ {
+
+ template <typename L, typename R>
+ struct xor_ : public solve_binary<xor_, L, R>
+ {
+ };
+
+ } // end of namespace mln::trait::op
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRAIT_OP_XOR_HH
Index: mln/trait/op/geq.hh
--- mln/trait/op/geq.hh (revision 0)
+++ mln/trait/op/geq.hh (revision 0)
@@ -0,0 +1,65 @@
+// Copyright (C) 2006 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_TRAIT_OP_GEQ_HH
+# define MLN_TRAIT_OP_GEQ_HH
+
+/*! \file mln/trait/op/geq.hh
+ *
+ * \brief Declaration of the "binary greater-or-equal" operator trait.
+ */
+
+# include <mln/trait/solve.hh>
+
+
+# define mln_trait_op_geq(L, R) typename mln::trait::op::geq< L , R >::ret
+# define mln_trait_op_geq_(L, R) mln::trait::op::geq< L , R >::ret
+
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+ namespace op
+ {
+
+ template <typename L, typename R>
+ struct geq : public solve_binary<geq, L, R>
+ {
+ };
+
+ } // end of namespace mln::trait::op
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRAIT_OP_GEQ_HH
Index: mln/trait/op/postinc.hh
--- mln/trait/op/postinc.hh (revision 1390)
+++ mln/trait/op/postinc.hh (working copy)
@@ -28,6 +28,11 @@
#ifndef MLN_TRAIT_OP_POSTINC_HH
# define MLN_TRAIT_OP_POSTINC_HH
+/*! \file mln/trait/op/postinc.hh
+ *
+ * \brief Declaration of the "unary post-incrementation" operator trait.
+ */
+
# include <mln/trait/solve.hh>
@@ -39,10 +44,6 @@
namespace mln
{
- // Fwd decl.
- template <typename E> struct Object;
-
-
namespace trait
{
Index: mln/trait/op/mod.hh
--- mln/trait/op/mod.hh (revision 1390)
+++ mln/trait/op/mod.hh (working copy)
@@ -28,6 +28,11 @@
#ifndef MLN_TRAIT_OP_MOD_HH
# define MLN_TRAIT_OP_MOD_HH
+/*! \file mln/trait/op/mod.hh
+ *
+ * \brief Declaration of the "binary modulus" operator trait.
+ */
+
# include <mln/trait/promote.hh>
Index: mln/trait/op/uminus.hh
--- mln/trait/op/uminus.hh (revision 1390)
+++ mln/trait/op/uminus.hh (working copy)
@@ -28,11 +28,9 @@
#ifndef MLN_TRAIT_OP_UMINUS_HH
# define MLN_TRAIT_OP_UMINUS_HH
-/*!
- * \file mln/trait/op/uminus.hh
- *
- * \brief FIXME
+/*! \file mln/trait/op/uminus.hh
*
+ * \brief Declaration of the "unary minus" operator trait.
*/
# include <mln/trait/solve.hh>
@@ -46,10 +44,6 @@
namespace mln
{
- // Fwd decl.
- template <typename E> struct Object;
-
-
namespace trait
{
Index: mln/trait/op/preinc.hh
--- mln/trait/op/preinc.hh (revision 1390)
+++ mln/trait/op/preinc.hh (working copy)
@@ -28,6 +28,11 @@
#ifndef MLN_TRAIT_OP_PREINC_HH
# define MLN_TRAIT_OP_PREINC_HH
+/*! \file mln/trait/op/predec.hh
+ *
+ * \brief Declaration of the "unary pre-decrementation" operator trait.
+ */
+
# include <mln/trait/solve.hh>
@@ -39,10 +44,6 @@
namespace mln
{
- // Fwd decl.
- template <typename E> struct Object;
-
-
namespace trait
{
Index: mln/trait/op/or.hh
--- mln/trait/op/or.hh (revision 0)
+++ mln/trait/op/or.hh (revision 0)
@@ -0,0 +1,65 @@
+// Copyright (C) 2006 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_TRAIT_OP_OR_HH
+# define MLN_TRAIT_OP_OR_HH
+
+/*! \file mln/trait/op/or.hh
+ *
+ * \brief Declaration of the "binary or" operator trait.
+ */
+
+# include <mln/trait/solve.hh>
+
+
+# define mln_trait_op_or(L, R) typename mln::trait::op::or_< L , R >::ret
+# define mln_trait_op_or_(L, R) mln::trait::op::or_< L , R >::ret
+
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+ namespace op
+ {
+
+ template <typename L, typename R>
+ struct or_ : public solve_binary<or_, L, R>
+ {
+ };
+
+ } // end of namespace mln::trait::op
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRAIT_OP_OR_HH
Index: mln/core/ops.hh
--- mln/core/ops.hh (revision 1390)
+++ mln/core/ops.hh (working copy)
@@ -86,7 +86,37 @@
struct set_binary_< op::eq, Object,O1, Object,O2 > { typedef bool ret; };
template <typename O1, typename O2>
- struct set_binary_< op::neq, Object,O1, Object,O2 > { typedef bool ret; };
+ struct set_binary_< op::neq, Object,O1, Object,O2 >
+ {
+ // O1 != O2 --> ! (O1 = O2)
+ typedef mln_trait_op_eq(O1, O2) B_;
+ typedef mln_trait_op_not(B_) ret;
+ };
+
+ template <typename O1, typename O2>
+ struct set_binary_< op::less, Object,O1, Object,O2 > { typedef bool ret; };
+
+ template <typename O1, typename O2>
+ struct set_binary_< op::leq, Object,O1, Object,O2 >
+ {
+ // O1 <= O2 --> ! (O2 < 01)
+ typedef mln_trait_op_less(O2, O1) B_;
+ typedef mln_trait_op_not(B_) ret;
+ };
+
+ template <typename O1, typename O2>
+ struct set_binary_< op::geq, Object,O1, Object,O2 >
+ {
+ // O1 >= O2 --> O2 <= O1
+ typedef mln_trait_op_leq(O2, O1) ret;
+ };
+
+ template <typename O1, typename O2>
+ struct set_binary_< op::greater, Object,O1, Object,O2 >
+ {
+ // O1 > O2 --> O2 < O1
+ typedef mln_trait_op_less(O2, O1) ret;
+ };
// FIXME: Same for the other definitions below...
@@ -151,7 +181,8 @@
* in milena when applying on a couple of mln::Object.
*/
template <typename O1, typename O2>
- bool operator>(const Object<O1>& lhs, const Object<O2>& rhs);
+ mln_trait_op_greater(O1, O2)
+ operator>(const Object<O1>& lhs, const Object<O2>& rhs);
/*! \brief General definition of the "greater than or equal to"
@@ -165,7 +196,8 @@
* in milena when applying on a couple of mln::Object.
*/
template <typename O1, typename O2>
- bool operator>=(const Object<O1>& lhs, const Object<O2>& rhs);
+ mln_trait_op_geq(O1, O2)
+ operator>=(const Object<O1>& lhs, const Object<O2>& rhs);
/*! \brief Default definition of the "less than or equal to"
@@ -179,7 +211,8 @@
* operator has to be re-defined.
*/
template <typename O1, typename O2>
- bool operator<=(const Object<O1>& lhs, const Object<O2>& rhs);
+ mln_trait_op_leq(O1, O2)
+ operator<=(const Object<O1>& lhs, const Object<O2>& rhs);
/* \brief Default definition of the post-incrementation operator.
@@ -423,7 +456,7 @@
return exact(rhs);
}
- // Not equal to.
+ // Comparisons.
template <typename O1, typename O2>
mln_trait_op_neq(O1, O2)
@@ -433,19 +466,22 @@
}
template <typename O1, typename O2>
- bool operator>(const Object<O1>& lhs, const Object<O2>& rhs)
+ mln_trait_op_greater(O1, O2)
+ operator>(const Object<O1>& lhs, const Object<O2>& rhs)
{
return exact(rhs) < exact(lhs);
}
template <typename O1, typename O2>
- bool operator>=(const Object<O1>& lhs, const Object<O2>& rhs)
+ mln_trait_op_geq(O1, O2)
+ operator>=(const Object<O1>& lhs, const Object<O2>& rhs)
{
return exact(rhs) <= exact(lhs);
}
template <typename O1, typename O2>
- bool operator<=(const Object<O1>& lhs, const Object<O2>& rhs)
+ mln_trait_op_leq(O1, O2)
+ operator<=(const Object<O1>& lhs, const Object<O2>& rhs)
{
// if partial ordering, this operator should be re-defined!
return ! (exact(rhs) < exact(lhs));
Index: mln/core/concept/point_set.hh
--- mln/core/concept/point_set.hh (revision 1390)
+++ mln/core/concept/point_set.hh (working copy)
@@ -32,8 +32,10 @@
*
* \brief Definition of the concept of mln::Point_Set.
*
- * \todo Think about adding an 'insert' method (not os easy because of
+ * \todo Think about adding an 'insert' method (not so easy because of
* pset_if...)
+ *
+ * \todo Move out the ops.
*/
# include <mln/core/concept/point.hh>
@@ -43,6 +45,18 @@
namespace mln
{
+ // Fwd decl.
+ template <typename E> struct Point_Set;
+
+
+ /// Point_Set category flag type.
+ template <>
+ struct Point_Set<void>
+ {
+ typedef Object<void> super;
+ };
+
+
/*! \brief Base class for implementation classes of point sets.
*
* \see mln::doc::Point_Set for a complete documentation of this
@@ -225,4 +239,7 @@
} // end of namespace mln
+# include <mln/core/ops.hh>
+
+
#endif // ! MLN_CORE_CONCEPT_POINT_SET_HH
Index: mln/core/concept/point_site.hh
--- mln/core/concept/point_site.hh (revision 1390)
+++ mln/core/concept/point_site.hh (working copy)
@@ -44,7 +44,8 @@
// Fwd decl.
template <typename E> struct Point;
- // Point_Site category flag type.
+
+ /// Point_Site category flag type.
template <>
struct Point<void>
{
Index: mln/value/ops.hh
--- mln/value/ops.hh (revision 1390)
+++ mln/value/ops.hh (working copy)
@@ -301,8 +301,8 @@
return value::equiv(lhs) % value::equiv(rhs);
}
- // ...
+ // Operator =.
template <typename Sl, typename Sr>
mln_trait_op_eq(Sl, Sr)
@@ -311,33 +311,10 @@
return value::equiv(lhs) = value::equiv(rhs);
}
-
- // FIXME: Uncomment when less and leq are handled.
-
-// template <typename Sl, typename Sr>
-// mln_trait_op_less(Sl, Sr)
-// operator < (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs)
-// {
-// return value::equiv(lhs) < value::equiv(rhs);
-// }
-
-// template <typename Sl, typename Sr>
-// mln_trait_op_leq(Sl, Sr)
-// operator <= (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs)
-// {
-// return value::equiv(lhs) <= value::equiv(rhs);
-// }
-
- // ...
-
-
-
-
template <typename O, typename L>
mln_trait_op_eq(O, O)
operator=(const value::scalar_<O>& lhs, const Literal<L>& rhs)
{
- // mlc_converts_to(L, O)::check();
return exact(lhs) = mln_value_equiv(O)(exact(rhs));
}
@@ -345,11 +322,33 @@
mln_trait_op_eq(O, O)
operator=(const Literal<L>& lhs, const value::scalar_<O>& rhs)
{
- // mlc_converts_to(L, O)::check();
return mln_value_equiv(O)(exact(lhs)) = exact(rhs);
}
+ // Operator <.
+
+ template <typename Sl, typename Sr>
+ mln_trait_op_less(Sl, Sr)
+ operator < (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs)
+ {
+ return value::equiv(lhs) < value::equiv(rhs);
+ }
+
+ template <typename O, typename L>
+ mln_trait_op_less(O, O)
+ operator < (const value::scalar_<O>& lhs, const Literal<L>& rhs)
+ {
+ return exact(lhs) < mln_value_equiv(O)(exact(rhs));
+ }
+
+ template <typename L, typename O>
+ mln_trait_op_less(O, O)
+ operator < (const Literal<L>& lhs, const value::scalar_<O>& rhs)
+ {
+ return mln_value_equiv(O)(exact(lhs)) < exact(rhs);
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/value/gray.hh
--- mln/value/gray.hh (revision 1390)
+++ mln/value/gray.hh (working copy)
@@ -72,10 +72,10 @@
public:
/// Encoding associated type.
- typedef long enc;
+ typedef int enc;
/// Equivalent associated type.
- typedef long equiv;
+ typedef int equiv;
/// Constructor without argument.
gray();
Index: mln/value/concept/built_in.hh
--- mln/value/concept/built_in.hh (revision 1390)
+++ mln/value/concept/built_in.hh (working copy)
@@ -39,17 +39,6 @@
namespace mln
{
- // Fwd decl.
- namespace value { template <typename E> struct Built_In; }
-
-
- namespace trait
- {
- // FIXME...
-
- } // end of namespace mln::trait
-
-
namespace value
{
@@ -58,8 +47,7 @@
struct Built_In<void> // No inheritance here since this category is special (on the side).
{
// Every builtin belongs to a sub-category of Value but we do not know which one.
- // FIXME HERE FIRST: was void* below
- typedef Unknown<void> super;
+ typedef void* super;
};
} // end of namespace mln::value
Index: mln/value/concept/integer.hh
--- mln/value/concept/integer.hh (revision 1390)
+++ mln/value/concept/integer.hh (working copy)
@@ -31,6 +31,8 @@
/*! \file mln/value/concept/integer.hh
*
* \brief Define a generic class for integer values.
+ *
+ * \todo Similar files needs to be cleaned-up.
*/
# include <mln/value/concept/scalar.hh>
@@ -39,28 +41,22 @@
namespace mln
{
- // Fwd decl.
- namespace value { template <typename E> struct Integer; }
-
-
- namespace trait
+ namespace value
{
- // FIXME...
-
- } // end of namespace mln::trait
+ // Fwd decl.
+ template <typename E> struct Integer;
- namespace value
- {
-
- // Category flag type.
+ /// Category flag type.
template <>
struct Integer<void>
{
typedef Scalar<void> super;
};
+
+ /// Concept of integer.
template <typename E>
struct Integer : public Scalar<E>
{
Index: mln/value/builtin/ops.hh
--- mln/value/builtin/ops.hh (revision 1390)
+++ mln/value/builtin/ops.hh (working copy)
@@ -318,6 +318,41 @@
namespace trait
{
+ // Unary traits.
+
+ template< typename B >
+ struct set_unary_< op::uplus,
+ mln::value::Built_In, B >
+ {
+ typedef B ret;
+ };
+
+ template<>
+ struct set_precise_unary_< op::not_, bool >
+ {
+ typedef bool ret;
+ };
+
+ template<> struct set_precise_unary_< op::uminus, signed char > { typedef signed char ret; };
+ template<> struct set_precise_unary_< op::uminus, unsigned char > { typedef int ret; };
+ template<> struct set_precise_unary_< op::uminus, signed short > { typedef signed short ret; };
+ template<> struct set_precise_unary_< op::uminus, unsigned short > { typedef int ret; };
+ template<> struct set_precise_unary_< op::uminus, signed int > { typedef signed int ret; };
+
+ // Disabled cause no correct result can be obtained
+ // e.g., (- unsigned int) is an (unsigned int)!
+ template<> struct set_precise_unary_< op::uminus, unsigned int > {};
+ template<> struct set_precise_unary_< op::uminus, signed long > {};
+ template<> struct set_precise_unary_< op::uminus, unsigned long > {};
+ template<> struct set_precise_unary_< op::uminus, bool > {};
+
+ template<> struct set_precise_unary_< op::uminus, float > { typedef float ret; };
+ template<> struct set_precise_unary_< op::uminus, double > { typedef double ret; };
+
+
+ // FIXME: Is that all?
+
+
// A couple of builtins => promotion...
mln_internal_set_builtin_trait_is_promotion_(op::plus);
@@ -326,23 +361,28 @@
mln_internal_set_builtin_trait_is_promotion_(op::div);
mln_internal_set_builtin_trait_is_promotion_(op::mod);
- // ...or for comparisons => bool.
+ // For comparisons (such as "less-than"), we get bool.
mln_internal_set_builtin_trait_is_bool_(op::eq);
mln_internal_set_builtin_trait_is_bool_(op::neq);
- // FIXME: ...
- // FIXME: What about +=, etc.
+ mln_internal_set_builtin_trait_is_bool_(op::less);
+ mln_internal_set_builtin_trait_is_bool_(op::leq);
+ mln_internal_set_builtin_trait_is_bool_(op::geq);
+ mln_internal_set_builtin_trait_is_bool_(op::greater);
+
+ mln_internal_set_builtin_trait_is_bool_(op::and_);
+ mln_internal_set_builtin_trait_is_bool_(op::or_);
+ mln_internal_set_builtin_trait_is_bool_(op::xor_);
+ // FIXME: We want to disable some ops; for instance "bool + int" and "int and int"...
+
+
+
+
+ // FIXME: What about +=, etc.
- template< template <class> class Name,
- typename B >
- struct set_unary_< Name,
- mln::value::Built_In, B >
- {
- typedef B ret; // FIXME: Wrong because some types are unsigned!
- };
// Operators "Object OP Built_In" => "Object OP scalar_"
@@ -377,6 +417,12 @@
typedef mln_trait_op_mod(O, mln::value::scalar_<B>) ret;
};
+ template <typename O, typename B>
+ struct set_binary_< op::less, mln::Object, O, mln::value::Built_In, B >
+ {
+ typedef mln_trait_op_less(O, mln::value::scalar_<B>) ret;
+ };
+
// 'Op+' is commutative so "o + b" => "o + scalar(b)".
Index: mln/value/builtin/promotions.hh
--- mln/value/builtin/promotions.hh (revision 1390)
+++ mln/value/builtin/promotions.hh (working copy)
@@ -68,28 +68,6 @@
struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
-# define mln_internal_set_uminus_bi_(Builtin, Result) \
- \
- template<> \
- struct set_precise_unary_< op::uminus, Builtin > \
- { \
- typedef Result ret; \
- }; \
- \
- struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
-
-
-# define mln_internal_set_uplus_bi_(Builtin) \
- \
- template<> \
- struct set_precise_unary_< op::uplus, Builtin > \
- { \
- typedef Builtin ret; \
- }; \
- \
- struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
-
-
namespace mln
{
@@ -171,31 +149,6 @@
mln_internal_set_promotion_auto_( float, double);
-
- // Builtin unary traits.
-
- mln_internal_set_uplus_bi_(unsigned char );
- mln_internal_set_uplus_bi_( signed char );
- mln_internal_set_uplus_bi_(unsigned short);
- mln_internal_set_uplus_bi_( signed short);
- mln_internal_set_uplus_bi_(unsigned int );
- mln_internal_set_uplus_bi_( signed int );
- mln_internal_set_uplus_bi_(unsigned long );
- mln_internal_set_uplus_bi_( signed long );
- mln_internal_set_uplus_bi_( float );
- mln_internal_set_uplus_bi_( double );
-
- mln_internal_set_uminus_bi_(unsigned char, unsigned char);
- mln_internal_set_uminus_bi_( signed char, signed char);
- mln_internal_set_uminus_bi_(unsigned short, unsigned short);
- mln_internal_set_uminus_bi_( signed short, signed short);
- mln_internal_set_uminus_bi_(unsigned int, unsigned int);
- mln_internal_set_uminus_bi_( signed int, signed int);
- mln_internal_set_uminus_bi_(unsigned long, unsigned long);
- mln_internal_set_uminus_bi_( signed long, signed long);
- mln_internal_set_uminus_bi_( float, float);
- mln_internal_set_uminus_bi_( double, double);
-
} // end of namespace mln::trait
} // end of namespace mln
Index: mln/value/builtin/integers.hh
--- mln/value/builtin/integers.hh (revision 1390)
+++ mln/value/builtin/integers.hh (working copy)
@@ -45,14 +45,14 @@
namespace mln
{
- template <> struct category< unsigned char > { typedef value::Built_In<void*> ret; typedef value::Integer<void> super; };
- template <> struct category< signed char > { typedef value::Built_In<void*> ret; typedef value::Integer<void> super; };
- template <> struct category< unsigned short > { typedef value::Built_In<void*> ret; typedef value::Integer<void> super; };
- template <> struct category< signed short > { typedef value::Built_In<void*> ret; typedef value::Integer<void> super; };
- template <> struct category< unsigned int > { typedef value::Built_In<void*> ret; typedef value::Integer<void> super; };
- template <> struct category< signed int > { typedef value::Built_In<void*> ret; typedef value::Integer<void> super; };
- template <> struct category< unsigned long > { typedef value::Built_In<void*> ret; typedef value::Integer<void> super; };
- template <> struct category< signed long > { typedef value::Built_In<void*> ret; typedef value::Integer<void> super; };
+ template <> struct category< unsigned char > { typedef value::Built_In<void> ret; typedef value::Integer<void> super; };
+ template <> struct category< signed char > { typedef value::Built_In<void> ret; typedef value::Integer<void> super; };
+ template <> struct category< unsigned short > { typedef value::Built_In<void> ret; typedef value::Integer<void> super; };
+ template <> struct category< signed short > { typedef value::Built_In<void> ret; typedef value::Integer<void> super; };
+ template <> struct category< unsigned int > { typedef value::Built_In<void> ret; typedef value::Integer<void> super; };
+ template <> struct category< signed int > { typedef value::Built_In<void> ret; typedef value::Integer<void> super; };
+ template <> struct category< unsigned long > { typedef value::Built_In<void> ret; typedef value::Integer<void> super; };
+ template <> struct category< signed long > { typedef value::Built_In<void> ret; typedef value::Integer<void> super; };
namespace trait
1
0
URL: https://svn.lrde.org/svn/oln/trunk/milena
ChangeLog:
2007-10-26 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Fix on tree for compiling, and Fix in fllt.
* mln/util/tree.hh,
* mln/util/tree_fast.hh,
* sandbox/garrigues/fllt.hh: Fix.
---
mln/util/tree.hh | 2 ++
mln/util/tree_fast.hh | 2 ++
sandbox/garrigues/fllt.hh | 4 +---
3 files changed, 5 insertions(+), 3 deletions(-)
Index: trunk/milena/mln/util/tree_fast.hh
===================================================================
--- trunk/milena/mln/util/tree_fast.hh (revision 1389)
+++ trunk/milena/mln/util/tree_fast.hh (revision 1390)
@@ -29,6 +29,8 @@
# define MLN_UTIL_TREE_FAST_HH
# include <vector>
+# include <iostream>
+
# include <mln/core/contract.hh>
/*!
Index: trunk/milena/mln/util/tree.hh
===================================================================
--- trunk/milena/mln/util/tree.hh (revision 1389)
+++ trunk/milena/mln/util/tree.hh (revision 1390)
@@ -30,6 +30,8 @@
# include <vector>
+# include <mln/core/contract.hh>
+
/*!
* \file mln/util/tree.hh
*
Index: trunk/milena/sandbox/garrigues/fllt.hh
===================================================================
--- trunk/milena/sandbox/garrigues/fllt.hh (revision 1389)
+++ trunk/milena/sandbox/garrigues/fllt.hh (revision 1390)
@@ -249,11 +249,9 @@
current_region->content().value = g;
for_all(p)
{
- if (regions(p) == 0)
- {
current_region->content().points.insert(p);
+ if (regions(p) == 0)
regions(p) = current_region;
- }
else
{
if (regions(p)->get_parent() == 0)
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Some more definitions of traits and ops.
* tests/arith_plus.cc: New.
* tests/literal_zero.cc: Augment.
* mln/trait/solve.hh
(mln_trait_unary_, mln_trait_binary_): New macros.
* mln/literal/ops.hh: Add FIXME.
* mln/metal/vec.hh: Fix precondition.
* mln/arith/times.hh: New.
* mln/arith/plus.hh: Add traits.
(operator+, operator+=): New.
* mln/arith/includes.hh: New.
* mln/arith/all.hh: Sort includes.
* mln/value/ops.hh: New traits for Scalar OP Literal.
(operator=): New overloads.
* mln/value/scalar.hh (operator T): Remove; too dangerous.
* mln/value/quat.hh: Update.
* mln/value/equiv.hh (mln_value_equiv_): New macro.
* mln/value/builtin/ops.hh: Add material for cmp ops.
mln/arith/all.hh | 8 +
mln/arith/includes.hh | 42 +++++++
mln/arith/plus.hh | 124 ++++++++++++++++-----
mln/arith/times.hh | 271 +++++++++++++++++++++++++++++++++++++++++++++++
mln/literal/ops.hh | 2
mln/metal/vec.hh | 3
mln/trait/solve.hh | 2
mln/value/builtin/ops.hh | 75 ++++++++++++-
mln/value/equiv.hh | 1
mln/value/ops.hh | 68 +++++++++++
mln/value/quat.hh | 4
mln/value/scalar.hh | 9 -
tests/arith_plus.cc | 97 ++++++++++++++++
tests/literal_zero.cc | 4
14 files changed, 660 insertions(+), 50 deletions(-)
Index: tests/arith_plus.cc
--- tests/arith_plus.cc (revision 0)
+++ tests/arith_plus.cc (revision 0)
@@ -0,0 +1,97 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/arith_plus.cc
+ *
+ * \brief Tests on mln::image2d.
+ */
+
+#include <mln/core/image2d.hh>
+#include <mln/core/clone.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/arith/plus.hh>
+#include <mln/arith/times.hh>
+#include <mln/level/compare.hh>
+
+#include <mln/debug/iota.hh>
+#include <mln/debug/println.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ {
+ image2d<int> ref(3,3);
+ debug::iota(ref);
+
+ image2d<int> ima_i = clone(ref);
+ ima_i += ima_i;
+ mln_assertion(ima_i = 2 * ref);
+
+// debug::println(ima_i);
+// ima_i += 1;
+// debug::println(ima_i);
+
+// debug::iota(ima_f);
+// debug::println(ima_i + ima_f);
+ }
+
+}
+
+
+
+// Bench:
+
+// {
+// unsigned size = 5000;
+// image2d<unsigned char> ima_uc(size, size);
+// image2d<unsigned> ima_u;
+// ima_u = 2u + ima_uc;
+// }
+// {
+// unsigned size = 5000;
+// image2d<value::int_u8> ima_uc(size, size);
+// image2d<unsigned> ima_u;
+// ima_u = 2u + ima_uc;
+// }
+
+// {
+// unsigned size = 5000;
+// image2d<unsigned char> ima_uc(size, size);
+// image2d<unsigned> ima_u;
+// ima_u = ima_uc + ima_uc;
+// }
+// {
+// unsigned size = 5000;
+// image2d<value::int_u8> ima_u8(size, size);
+// image2d<unsigned> ima_u;
+// ima_u = ima_u8 + ima_u8;
+// }
+
Index: tests/literal_zero.cc
--- tests/literal_zero.cc (revision 1388)
+++ tests/literal_zero.cc (working copy)
@@ -36,6 +36,7 @@
#include <mln/value/int_u8.hh>
+
int main()
{
using namespace mln;
@@ -52,5 +53,6 @@
value::int_u8 u(literal::zero), uu;
uu = literal::zero;
- mln_assertion(u = 0);
+
+ mln_assertion(u = 0 && 0 = u);
}
Index: mln/trait/solve.hh
--- mln/trait/solve.hh (revision 1388)
+++ mln/trait/solve.hh (working copy)
@@ -49,8 +49,10 @@
# define mln_trait_unary(Name, T) typename mln::trait::solve_unary< Name, T >::ret
+# define mln_trait_unary_(Name, T) mln::trait::solve_unary< Name, T >::ret
# define mln_trait_binary(Name, T1, T2) typename mln::trait::solve_binary< Name, T1, T2 >::ret
+# define mln_trait_binary_(Name, T1, T2) mln::trait::solve_binary< Name, T1, T2 >::ret
Index: mln/literal/ops.hh
--- mln/literal/ops.hh (revision 1388)
+++ mln/literal/ops.hh (working copy)
@@ -259,6 +259,8 @@
return mlc_equal(L1, L2)::value;
}
+ // FIXME: Add less, etc.
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/metal/vec.hh
--- mln/metal/vec.hh (revision 1388)
+++ mln/metal/vec.hh (working copy)
@@ -466,7 +466,6 @@
return tmp;
}
-
template <unsigned n, typename T, typename S>
vec<n, mln_trait_op_times(T, S)>
operator*(const vec<n,T>& lhs, const mln::value::scalar_<S>& s)
@@ -491,7 +490,7 @@
vec<n, mln_trait_op_div(T, S)>
operator/(const vec<n,T>& lhs, const mln::value::scalar_<S>& s)
{
- mln_precondition(s != 0);
+ mln_precondition(value::equiv(s) != literal::zero);
vec<n, mln_trait_op_div(T, S)> tmp;
for (unsigned i = 0; i < n; ++i)
tmp[i] = lhs[i] / s.to_equiv();
Index: mln/arith/times.hh
--- mln/arith/times.hh (revision 0)
+++ mln/arith/times.hh (revision 0)
@@ -0,0 +1,271 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_ARITH_TIMES_HH
+# define MLN_ARITH_TIMES_HH
+
+/*! \file mln/arith/times.hh
+ *
+ * \brief Point-wise multiplication between images.
+ *
+ * \todo Speedup; some versions are not optimal.
+ */
+
+# include <mln/arith/includes.hh>
+
+
+namespace mln
+{
+
+
+ namespace trait
+ {
+
+ template <typename L, typename R>
+ struct set_binary_< op::times, Image, L, Image, R >
+ {
+ typedef mln_trait_op_times(mln_value(L), mln_value(R)) value;
+ typedef mln_ch_value(L, value) ret;
+ };
+
+ template <typename I, typename S>
+ struct set_binary_< op::times, Image, I, mln::value::Scalar, S >
+ {
+ typedef mln_trait_op_times(mln_value(I), S) value;
+ typedef mln_ch_value(I, value) ret;
+ };
+
+ } // end of namespace mln::trait
+
+
+
+ template <typename L, typename R>
+ mln_trait_op_times(L,R)
+ operator*(const Image<L>& lhs, const Image<R>& rhs);
+
+ template <typename L, typename R>
+ L&
+ operator*=(Image<L>& lhs, const Image<R>& rhs);
+
+
+ template <typename I, typename S>
+ mln_trait_op_times(I,S)
+ operator*(const Image<I>& ima, const value::Scalar<S>& s);
+
+ template <typename I, typename S>
+ I&
+ operator*=(Image<I>& ima, const value::Scalar<S>& s);
+
+
+
+ namespace arith
+ {
+
+ /*! Point-wise addition of images \p lhs and \p rhs.
+ *
+ * \param[in] lhs First operand image.
+ * \param[in] rhs Second operand image.
+ * \param[out] output The result image.
+ *
+ * \pre \p output.domain = \p lhs.domain = \p rhs.domain
+ */
+ template <typename L, typename R, typename O>
+ void times(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output);
+
+
+ /*! Point-wise addition of the value \p val to image \p input.
+ *
+ * \param[in] input The image.
+ * \param[in] val The value.
+ * \param[out] output The result image.
+ *
+ * \pre \p output.domain = \p input.domain
+ */
+ template <typename I, typename V, typename O>
+ void times_cst(const Image<I>& input, const V& val, Image<O>& output);
+
+
+ /*! Point-wise addition of image \p rhs in image \p lhs.
+ *
+ * \param[in] lhs First operand image (subject to addition).
+ * \param[in,out] rhs Second operand image (to be added to \p lhs).
+ *
+ * This addition performs: \n
+ * for all p of rhs.domain \n
+ * lhs(p) *= rhs(p)
+ *
+ * \pre \p rhs.domain <= \p lhs.domain
+ */
+ template <typename L, typename R>
+ void times_inplace(Image<L>& lhs, const Image<R>& rhs);
+
+
+ } // end of namespace mln::arith
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename L, typename R>
+ mln_trait_op_times(L,R)
+ operator*(const Image<L>& lhs, const Image<R>& rhs)
+ {
+ mln_precondition(exact(rhs).domain() = exact(lhs).domain());
+ mln_trait_op_times(L,R) tmp;
+ initialize(tmp, lhs);
+ arith::times(lhs, rhs, tmp);
+ return tmp;
+ }
+
+ template <typename L, typename R>
+ L&
+ operator*=(Image<L>& lhs, const Image<R>& rhs)
+ {
+ mln_precondition(exact(rhs).domain() = exact(lhs).domain());
+ arith::times_inplace(lhs, rhs);
+ return exact(lhs);
+ }
+
+
+ template <typename I, typename S>
+ mln_trait_op_times(I,S)
+ operator*(const Image<I>& ima, const value::Scalar<S>& s)
+ {
+ mln_precondition(exact(ima).has_data());
+ mln_trait_op_times(I,S) tmp;
+ initialize(tmp, ima);
+ arith::times_cst(ima, exact(s), tmp);
+ return tmp;
+ }
+
+ template <typename I, typename S>
+ I&
+ operator*=(Image<I>& ima, const value::Scalar<S>& s)
+ {
+ mln_precondition(exact(ima).has_data());
+ arith::times_cst(ima, exact(s), ima);
+ return exact(ima);
+ }
+
+
+
+ namespace arith
+ {
+
+ namespace impl
+ {
+
+ template <typename L, typename R, typename O>
+ void times_(trait::image::speed::any, const L& lhs,
+ trait::image::speed::any, const R& rhs,
+ trait::image::speed::any, O& output)
+ {
+ mln_piter(L) p(lhs.domain());
+ for_all(p)
+ output(p) = lhs(p) * rhs(p);
+ }
+
+ template <typename L, typename R, typename O>
+ void times_(trait::image::speed::fastest, const L& lhs,
+ trait::image::speed::fastest, const R& rhs,
+ trait::image::speed::fastest, O& output)
+ {
+ mln_pixter(const L) lp(lhs);
+ mln_pixter(const R) rp(rhs);
+ mln_pixter(O) op(output);
+ for_all_3(lp, rp, op)
+ op.val() = lp.val() * rp.val();
+ }
+
+ template <typename L, typename R>
+ void times_inplace_(trait::image::speed::any, L& lhs,
+ trait::image::speed::any, const R& rhs)
+ {
+ mln_piter(R) p(rhs.domain());
+ for_all(p)
+ lhs(p) *= rhs(p);
+ }
+
+ template <typename L, typename R>
+ void times_inplace_(trait::image::speed::fastest, L& lhs,
+ trait::image::speed::fastest, const R& rhs)
+ {
+ mln_pixter(L) lp(lhs);
+ mln_pixter(const R) rp(rhs);
+ for_all_2(rp, lp)
+ lp.val() *= rp.val();
+ }
+
+ } // end of namespace mln::arith::impl
+
+
+ // Facades.
+
+ template <typename L, typename R, typename O>
+ void times(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output)
+ {
+ mln_precondition(exact(rhs).domain() = exact(lhs).domain());
+ mln_precondition(exact(output).domain() = exact(lhs).domain());
+ impl::times_(mln_trait_image_speed(L)(), exact(lhs),
+ mln_trait_image_speed(R)(), exact(rhs),
+ mln_trait_image_speed(O)(), exact(output));
+ }
+
+ template <typename I, typename V, typename O>
+ void times_cst(const Image<I>& input, const V& val, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ times(input, pw::cst(val) | exact(input).domain(), output);
+ // Calls the previous version.
+ }
+
+ template <typename L, typename R>
+ void times_inplace(Image<L>& lhs, const Image<R>& rhs)
+ {
+ mln_precondition(exact(rhs).domain() <= exact(lhs).domain());
+ impl::times_inplace_(mln_trait_image_speed(L)(), exact(lhs),
+ mln_trait_image_speed(R)(), exact(rhs));
+ }
+
+ template <typename I, typename V>
+ void times_cst_inplace(Image<I>& input, const V& val)
+ {
+ mln_precondition(exact(input).has_data());
+ times_inplace(input, pw::cst(val) | exact(input).domain());
+ // Calls the previous version.
+ }
+
+ } // end of namespace mln::arith
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ARITH_TIMES_HH
Index: mln/arith/plus.hh
--- mln/arith/plus.hh (revision 1388)
+++ mln/arith/plus.hh (working copy)
@@ -32,31 +32,54 @@
*
* \brief Point-wise addition between images.
*
- * \todo Speedup versions with cst.
+ * \todo Speedup; some versions are not optimal.
*/
-# include <mln/core/concept/image.hh>
-
-# include <mln/pw/cst.hh>
-# include <mln/pw/image.hh>
-# include <mln/trait/op/plus.hh>
+# include <mln/arith/includes.hh>
namespace mln
{
-// namespace trait
-// {
+ namespace trait
+ {
+
+ template <typename L, typename R>
+ struct set_binary_< op::plus, Image, L, Image, R >
+ {
+ typedef mln_trait_op_plus(mln_value(L), mln_value(R)) value;
+ typedef mln_ch_value(L, value) ret;
+ };
+
+ template <typename I, typename S>
+ struct set_binary_< op::plus, Image, I, mln::value::Scalar, S >
+ {
+ typedef mln_trait_op_plus(mln_value(I), S) value;
+ typedef mln_ch_value(I, value) ret;
+ };
+
+ } // end of namespace mln::trait
+
+
+
+ template <typename L, typename R>
+ mln_trait_op_plus(L,R)
+ operator+(const Image<L>& lhs, const Image<R>& rhs);
+
+ template <typename L, typename R>
+ L&
+ operator+=(Image<L>& lhs, const Image<R>& rhs);
+
+
+ template <typename I, typename S>
+ mln_trait_op_plus(I,S)
+ operator+(const Image<I>& ima, const value::Scalar<S>& s);
-// template <typename L, typename R>
-// struct op_plus< Image,L, Image,R >
-// {
-// typedef mln_trait_op_plus(mln_value(L), mln_value(R)) value;
-// typedef mln_ch_value(L, value) ret;
-// };
+ template <typename I, typename S>
+ I&
+ operator+=(Image<I>& ima, const value::Scalar<S>& s);
-// } // end of namespace mln::trait
namespace arith
@@ -101,8 +124,60 @@
void plus_inplace(Image<L>& lhs, const Image<R>& rhs);
+ } // end of namespace mln::arith
+
+
+
+
# ifndef MLN_INCLUDE_ONLY
+
+ template <typename L, typename R>
+ mln_trait_op_plus(L,R)
+ operator+(const Image<L>& lhs, const Image<R>& rhs)
+ {
+ mln_precondition(exact(rhs).domain() = exact(lhs).domain());
+ mln_trait_op_plus(L,R) tmp;
+ initialize(tmp, lhs);
+ arith::plus(lhs, rhs, tmp);
+ return tmp;
+ }
+
+ template <typename L, typename R>
+ L&
+ operator+=(Image<L>& lhs, const Image<R>& rhs)
+ {
+ mln_precondition(exact(rhs).domain() = exact(lhs).domain());
+ arith::plus_inplace(lhs, rhs);
+ return exact(lhs);
+ }
+
+
+ template <typename I, typename S>
+ mln_trait_op_plus(I,S)
+ operator+(const Image<I>& ima, const value::Scalar<S>& s)
+ {
+ mln_precondition(exact(ima).has_data());
+ mln_trait_op_plus(I,S) tmp;
+ initialize(tmp, ima);
+ arith::plus_cst(ima, exact(s), tmp);
+ return tmp;
+ }
+
+ template <typename I, typename S>
+ I&
+ operator+=(Image<I>& ima, const value::Scalar<S>& s)
+ {
+ mln_precondition(exact(ima).has_data());
+ arith::plus_cst(ima, exact(s), ima);
+ return exact(ima);
+ }
+
+
+
+ namespace arith
+ {
+
namespace impl
{
@@ -152,7 +227,6 @@
// Facades.
-
template <typename L, typename R, typename O>
void plus(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output)
{
@@ -163,17 +237,6 @@
mln_trait_image_speed(O)(), exact(output));
}
-
-// template <typename L, typename R>
-// mln_trait_op_plus(L, R)
-// plus(const Image<L>& lhs, const Image<R>& rhs)
-// {
-// mln_precondition(exact(rhs).domain() = exact(lhs).domain());
-// mln_precondition(exact(output).domain() = exact(lhs).domain());
-// impl::plus_(exact(lhs), exact(rhs), exact(output));
-// }
-
-
template <typename I, typename V, typename O>
void plus_cst(const Image<I>& input, const V& val, Image<O>& output)
{
@@ -194,15 +257,14 @@
void plus_cst_inplace(Image<I>& input, const V& val)
{
mln_precondition(exact(input).has_data());
- plus_inplace(mln_trait_image_speed(I)(), exact(input),
- trait::image::speed::any(), pw::cst(val) | exact(input).domain());
+ plus_inplace(input, pw::cst(val) | exact(input).domain());
// Calls the previous version.
}
-# endif // ! MLN_INCLUDE_ONLY
-
} // end of namespace mln::arith
+# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace mln
Index: mln/arith/includes.hh
--- mln/arith/includes.hh (revision 0)
+++ mln/arith/includes.hh (revision 0)
@@ -0,0 +1,42 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_ARITH_INCLUDES_HH
+# define MLN_ARITH_INCLUDES_HH
+
+/*! \file mln/arith/includes.hh
+ *
+ * \brief File that includes what is required by arith files.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/value/ops.hh>
+# include <mln/pw/cst.hh>
+# include <mln/pw/image.hh>
+
+
+#endif // ! MLN_ARITH_INCLUDES_HH
Index: mln/arith/all.hh
--- mln/arith/all.hh (revision 1388)
+++ mln/arith/all.hh (working copy)
@@ -46,9 +46,13 @@
}
-# include <mln/arith/min.hh>
-# include <mln/arith/minus.hh>
+
# include <mln/arith/plus.hh>
+# include <mln/arith/minus.hh>
+# include <mln/arith/times.hh>
+
+# include <mln/arith/min.hh>
# include <mln/arith/revert.hh>
+
#endif // ! MLN_ARITH_ALL_HH
Index: mln/value/ops.hh
--- mln/value/ops.hh (revision 1388)
+++ mln/value/ops.hh (working copy)
@@ -89,6 +89,27 @@
};
+ template < template <class, class> class Name,
+ typename S, typename L >
+ struct set_binary_< Name,
+ mln::value::Scalar, S,
+ mln::Literal, L >
+ {
+ typedef mln_value_equiv(S) S_;
+ typedef mln_trait_binary(Name, S_, S_) ret;
+ };
+
+ template < template <class, class> class Name,
+ typename L, typename S >
+ struct set_binary_< Name,
+ mln::Literal, L,
+ mln::value::Scalar, S >
+ {
+ typedef mln_value_equiv(S) S_;
+ typedef mln_trait_binary(Name, S_, S_) ret;
+ };
+
+
// Some binary traits for "scalar(s) OP obj" when OP commutes => "obj OP scalar(s)".
template < typename S, typename O >
@@ -282,6 +303,53 @@
// ...
+
+ template <typename Sl, typename Sr>
+ mln_trait_op_eq(Sl, Sr)
+ operator = (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs)
+ {
+ return value::equiv(lhs) = value::equiv(rhs);
+ }
+
+
+ // FIXME: Uncomment when less and leq are handled.
+
+// template <typename Sl, typename Sr>
+// mln_trait_op_less(Sl, Sr)
+// operator < (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs)
+// {
+// return value::equiv(lhs) < value::equiv(rhs);
+// }
+
+// template <typename Sl, typename Sr>
+// mln_trait_op_leq(Sl, Sr)
+// operator <= (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs)
+// {
+// return value::equiv(lhs) <= value::equiv(rhs);
+// }
+
+ // ...
+
+
+
+
+ template <typename O, typename L>
+ mln_trait_op_eq(O, O)
+ operator=(const value::scalar_<O>& lhs, const Literal<L>& rhs)
+ {
+ // mlc_converts_to(L, O)::check();
+ return exact(lhs) = mln_value_equiv(O)(exact(rhs));
+ }
+
+ template <typename L, typename O>
+ mln_trait_op_eq(O, O)
+ operator=(const Literal<L>& lhs, const value::scalar_<O>& rhs)
+ {
+ // mlc_converts_to(L, O)::check();
+ return mln_value_equiv(O)(exact(lhs)) = exact(rhs);
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/value/scalar.hh
--- mln/value/scalar.hh (revision 1388)
+++ mln/value/scalar.hh (working copy)
@@ -62,9 +62,6 @@
/// Ctor.
explicit scalar_(const T& val);
- /// Conversion. FIXME: Is-it useful?
- operator T() const;
-
/// Access to the scalar value.
T to_equiv() const;
@@ -120,12 +117,6 @@
}
template <typename T>
- scalar_<T>::operator T() const
- {
- return val_;
- }
-
- template <typename T>
T
scalar_<T>::to_equiv() const
{
Index: mln/value/quat.hh
--- mln/value/quat.hh (revision 1388)
+++ mln/value/quat.hh (working copy)
@@ -452,7 +452,7 @@
quat operator*(const quat& lhs, const value::scalar_<S>& rhs)
{
mlc_converts_to(S, float)::check();
- quat tmp(lhs.to_vec() * float(rhs));
+ quat tmp(lhs.to_vec() * rhs.to_equiv());
return tmp;
}
@@ -460,7 +460,7 @@
quat operator/(const quat& lhs, const value::scalar_<S>& rhs_)
{
mlc_converts_to(S, float)::check();
- float rhs = float(rhs_);
+ float rhs = rhs_.to_equiv();
mln_precondition(rhs != 0.f);
quat tmp(lhs.to_vec() / rhs);
return tmp;
Index: mln/value/equiv.hh
--- mln/value/equiv.hh (revision 1388)
+++ mln/value/equiv.hh (working copy)
@@ -37,6 +37,7 @@
# define mln_value_equiv(V) typename mln::value::internal::equiv_<V>::ret
+# define mln_value_equiv_(V) mln::value::internal::equiv_<V>::ret
Index: mln/value/builtin/ops.hh
--- mln/value/builtin/ops.hh (revision 1388)
+++ mln/value/builtin/ops.hh (working copy)
@@ -112,6 +112,42 @@
+// Comparison.
+
+# define mln_internal_decl_op_cmp_(Symb, Name, Builtin) \
+ \
+ template <typename O> \
+ mln_trait_op_##Name (O, value::scalar_< Builtin >) \
+ operator Symb (const Object<O>& lhs, const Builtin & rhs); \
+ \
+ template <typename O> \
+ mln_trait_op_##Name (value::scalar_< Builtin >, O) \
+ operator Symb (const Builtin & lhs, const Object<O>& rhs); \
+ \
+ struct m_a_c_r_o__e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
+
+# define mln_internal_def_op_cmp_(Symb, Name, Builtin) \
+ \
+ template <typename O> \
+ mln_trait_op_##Name (O, value::scalar_< Builtin >) \
+ operator Symb (const Object<O>& lhs, const Builtin & rhs) \
+ { \
+ return exact(lhs) Symb value::scalar(rhs); \
+ } \
+ \
+ template <typename O> \
+ mln_trait_op_##Name (value::scalar_< Builtin >, O) \
+ operator Symb (const Builtin & lhs, const Object<O>& rhs) \
+ { \
+ return value::scalar(lhs) Symb exact(rhs); \
+ } \
+ \
+ struct m_a_c_r_o__e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
+
+
+
+
+
# define mln_internal_op_obj_builtins_(De, Symb, Name) \
\
@@ -206,7 +242,7 @@
template <typename O> \
mln_trait_op_##Name (value::scalar_< Builtin >, O) \
operator Symb (const Builtin & lhs, const Object<O>& rhs) \
- { std::cout << "hop" << std::endl; \
+ { \
return value::scalar(lhs) / exact(rhs); \
} \
\
@@ -229,6 +265,20 @@
struct m_a_c_r_o__e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
+# define mln_internal_op_builtins_cmp_(De, Symb, Name) \
+ \
+ mln_internal_##De##_op_cmp_(Symb, Name, signed char); \
+ mln_internal_##De##_op_cmp_(Symb, Name, unsigned char); \
+ mln_internal_##De##_op_cmp_(Symb, Name, signed short); \
+ mln_internal_##De##_op_cmp_(Symb, Name, unsigned short); \
+ mln_internal_##De##_op_cmp_(Symb, Name, signed int); \
+ mln_internal_##De##_op_cmp_(Symb, Name, unsigned int); \
+ mln_internal_##De##_op_cmp_(Symb, Name, signed long); \
+ mln_internal_##De##_op_cmp_(Symb, Name, unsigned long); \
+ mln_internal_##De##_op_cmp_(Symb, Name, float); \
+ mln_internal_##De##_op_cmp_(Symb, Name, double); \
+ \
+ struct m_a_c_r_o__e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
// FIXME: What about pointers, arrays, bool, etc.
@@ -268,7 +318,7 @@
namespace trait
{
- // A couple of builtins => promotion.
+ // A couple of builtins => promotion...
mln_internal_set_builtin_trait_is_promotion_(op::plus);
mln_internal_set_builtin_trait_is_promotion_(op::minus);
@@ -276,7 +326,14 @@
mln_internal_set_builtin_trait_is_promotion_(op::div);
mln_internal_set_builtin_trait_is_promotion_(op::mod);
- // FIXME: other (such as plus_eq)...
+ // ...or for comparisons => bool.
+
+ mln_internal_set_builtin_trait_is_bool_(op::eq);
+ mln_internal_set_builtin_trait_is_bool_(op::neq);
+ // FIXME: ...
+
+ // FIXME: What about +=, etc.
+
template< template <class> class Name,
@@ -386,6 +443,12 @@
mln_internal_builtins_dvmd_obj_(decl, %, mod);
+ // Ops "bi CMP obj" and "bi CMP obj"
+ mln_internal_op_builtins_cmp_(decl, =, eq);
+ mln_internal_op_builtins_cmp_(decl, !=, neq);
+ // FIXME: ...
+
+
# ifndef MLN_INCLUDE_ONLY
mln_internal_op_obj_builtins_(def, +, plus);
@@ -405,6 +468,12 @@
mln_internal_builtins_dvmd_obj_(def, /, div);
mln_internal_builtins_dvmd_obj_(def, %, mod);
+ // Ops "bi CMP obj" and "bi CMP obj"
+ mln_internal_op_builtins_cmp_(def, =, eq);
+ mln_internal_op_builtins_cmp_(def, !=, neq);
+
+ // FIXME: Add less, etc.
+
# endif // ! MLN_INCLUDE_ONLY
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-25 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add tree_fast_to_image.
* mln/util/tree_fast_to_image.hh: New function for tree_fast.
* tests/tree_fast_to_image.cc: New test for this function.
* mln/util/tree_fast.hh,
* tests/tree_fast.cc: Update.
---
mln/util/tree_fast.hh | 39 ++++++------
mln/util/tree_fast_to_image.hh | 85 +++++++++++++++++++++++++++
tests/tree_fast.cc | 26 ++++----
tests/tree_fast_to_image.cc | 127 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 245 insertions(+), 32 deletions(-)
Index: trunk/milena/tests/tree_fast.cc
===================================================================
--- trunk/milena/tests/tree_fast.cc (revision 1387)
+++ trunk/milena/tests/tree_fast.cc (revision 1388)
@@ -47,17 +47,17 @@
unsigned elt5 = 5;
unsigned elt6= 42;
- util::tree<unsigned> tree(elt1);
- mln_assertion(tree.has (elt1));
- tree.add_child(tree.search(elt1), elt2);
- mln_assertion(tree.has (elt2));
- tree.add_child(tree.search(elt1), elt3);
- mln_assertion(tree.has (elt3));
- tree.add_child(tree.search(elt2), elt4);
- mln_assertion(tree.has (elt4));
- tree.add_child(tree.search(elt2), elt5);
- mln_assertion(tree.has (elt5));
- tree.add_parent(elt6);
- mln_assertion(tree.has (elt6));
- mln_assertion(tree.search(elt6) == tree.root_);
+ util::tree_fast<unsigned> tree_fast(elt1);
+ mln_assertion(tree_fast.has (elt1));
+ tree_fast.add_child(tree_fast.search(elt1), elt2);
+ mln_assertion(tree_fast.has (elt2));
+ tree_fast.add_child(tree_fast.search(elt1), elt3);
+ mln_assertion(tree_fast.has (elt3));
+ tree_fast.add_child(tree_fast.search(elt2), elt4);
+ mln_assertion(tree_fast.has (elt4));
+ tree_fast.add_child(tree_fast.search(elt2), elt5);
+ mln_assertion(tree_fast.has (elt5));
+ tree_fast.add_parent(elt6);
+ mln_assertion(tree_fast.has (elt6));
+ mln_assertion(tree_fast.search(elt6) == tree_fast.root_);
}
Index: trunk/milena/tests/tree_fast_to_image.cc
===================================================================
--- trunk/milena/tests/tree_fast_to_image.cc (revision 0)
+++ trunk/milena/tests/tree_fast_to_image.cc (revision 1388)
@@ -0,0 +1,127 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*!
+ * \file tests/tree_to_image.cc
+ *
+ * \brief test of mln::util::tree_to_image
+ *
+ */
+
+#include <mln/core/contract.hh>
+#include <mln/core/image2d.hh>
+#include <mln/core/set_p.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/level/stretch.hh>
+#include <mln/io/pgm/save.hh>
+#include <vector>
+#include <mln/util/tree_fast_to_image.hh>
+#include <mln/util/tree_fast.hh>
+
+template <typename P, typename V>
+struct fllt_node
+{
+ V value;
+ mln::set_p<P> points;
+ mln::set_p<P> holes;
+};
+
+template <typename P, typename V>
+bool operator==(const struct fllt_node<P,V>& lhs, const struct fllt_node<P,V>& rhs)
+{
+ if (lhs.value != rhs.value)
+ return false;
+
+ /// FIXME
+
+// if (lhs.points != rhs.points)
+// return false;
+
+// if (lhs.holes != rhs.holes)
+// return false;
+
+ return true;
+}
+
+int main (void)
+{
+ using namespace mln;
+ using value::int_u8;
+
+ typedef set_p<point2d > I;
+ typedef fllt_node<point2d, int_u8> T;
+
+ T s1;
+ T s2;
+ T s3;
+ T s4;
+ T s5;
+ T s6;
+ T s7;
+
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ s1.points.insert(point2d(i, j));
+ s1.value = 60;
+ for (int i = 200; i < 300; ++i)
+ for (int j = 0; j < 100; ++j)
+ s2.points.insert(point2d(i, j));
+ s2.value = 100;
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ s3.points.insert(point2d(i, j));
+ s3.value = 110;
+ for (int i = 260; i < 290; ++i)
+ for (int j = 0; j < 50; ++j)
+ s4.points.insert(point2d(i, j));
+ s4.value = 170;
+ for (int i = 200; i < 210; ++i)
+ for (int j = 0; j < 50; ++j)
+ s5.points.insert(point2d(i, j));
+ s5.value = 180;
+ for (int i = 270; i < 280; ++i)
+ for (int j = 50; j < 60; ++j)
+ s6.points.insert(point2d(i, j));
+ s6.value = 210;
+ for (int i = 0; i < 300; ++i)
+ for (int j = 0; j < 200; ++j)
+ s7.points.insert(point2d(i, j));
+ s7.value = 10;
+
+ util::tree_fast<T> tree(s1);
+ tree.add_child(tree.search(s1), s2);
+ tree.add_child(tree.search(s1), s3);
+ tree.add_child(tree.search(s2), s4);
+ tree.add_child(tree.search(s2), s5);
+ tree.add_child(tree.search(s4), s6);
+ tree.add_parent(s7);
+ image2d<int_u8> out (300,300);
+ util::tree_fast_to_image(tree, out);
+ io::pgm::save(out, "out.pgm");
+ std::cout << "out.pgm generate"
+ << std::endl;
+}
Index: trunk/milena/mln/util/tree_fast.hh
===================================================================
--- trunk/milena/mln/util/tree_fast.hh (revision 1387)
+++ trunk/milena/mln/util/tree_fast.hh (revision 1388)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_UTIL_TREE_HH
-# define MLN_UTIL_TREE_HH
+#ifndef MLN_UTIL_TREE_FAST_HH
+# define MLN_UTIL_TREE_FAST_HH
# include <vector>
# include <mln/core/contract.hh>
@@ -34,7 +34,7 @@
/*!
* \file mln/util/tree_fast.hh
*
- * \brief Definition of a fast generic general tree.
+ * \brief Definition of a fast generic general fast tree.
*
*/
@@ -45,10 +45,10 @@
{
template <typename T>
- struct tree
+ struct tree_fast
{
- tree();
- tree(T& elt);
+// tree_fast();
+ tree_fast(T& elt);
const unsigned size() const;
bool has (T& elt) const;
@@ -65,13 +65,13 @@
# ifndef MLN_INCLUDE_ONLY
- template <typename T>
- tree<T>::tree()
- {
- }
+// template <typename T>
+// tree_fast<T>::tree_fast()
+// {
+// }
template <typename T>
- tree<T>::tree(T& elt)
+ tree_fast<T>::tree_fast(T& elt)
{
std::vector<unsigned> v;
data_.push_back(elt);
@@ -82,7 +82,7 @@
template <typename T>
const unsigned
- tree<T>::size() const
+ tree_fast<T>::size() const
{
return (data_.size ());
}
@@ -90,7 +90,7 @@
template <typename T>
bool
- tree<T>::has (T& elt) const
+ tree_fast<T>::has (T& elt) const
{
for (unsigned i = 0; i < data_.size (); ++i)
if (data_[i] == elt)
@@ -101,25 +101,26 @@
template <typename T>
unsigned
- tree<T>::search (T& elt) const
+ tree_fast<T>::search (T& elt) const
{
for (unsigned i = 0; i < data_.size (); ++i)
if (data_[i] == elt)
return i;
-
+ std::cerr << "BUGG !!!!"
+ << std::endl;
return (unsigned)(-1);
}
template <typename T>
bool
- tree<T>::is_root (unsigned i) const
+ tree_fast<T>::is_root (unsigned i) const
{
return (root_ == i);
}
template <typename T>
void
- tree<T>::add_child (unsigned i, T& elt)
+ tree_fast<T>::add_child (unsigned i, T& elt)
{
mln_assertion (i < data_.size ());
std::vector<unsigned> v;
@@ -131,7 +132,7 @@
template <typename T>
void
- tree<T>::add_parent (T& elt)
+ tree_fast<T>::add_parent (T& elt)
{
std::vector<unsigned> v;
data_.push_back(elt);
@@ -153,4 +154,4 @@
} // end of namespace mln
-#endif // !MLN_UTIL_TREE_HH
+#endif // !MLN_UTIL_TREE_FAST_HH
Index: trunk/milena/mln/util/tree_fast_to_image.hh
===================================================================
--- trunk/milena/mln/util/tree_fast_to_image.hh (revision 0)
+++ trunk/milena/mln/util/tree_fast_to_image.hh (revision 1388)
@@ -0,0 +1,85 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_UTIL_TREE_FAST_TO_IMAGE_HH
+# define MLN_UTIL_TREE_FAST_TO_IMAGE_HH
+
+/*!
+ * \file mln/util/tree_fast_to_image.hh
+ *
+ * \brief Definition of function which transform a tree_fast into an
+ * image.
+ *
+ */
+
+# include <mln/util/tree_fast.hh>
+# include <mln/core/set_p.hh>
+# include <list>
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ template <typename T, typename I>
+ void
+ tree_fast_to_image (tree_fast<T>& tree, Image<I>& output_);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename I>
+ void
+ tree_fast_to_image (tree_fast<T>& tree, Image<I>& output_)
+ {
+ I& output = exact(output_);
+ std::list<unsigned> q;
+
+ q.push_back (tree.root_);
+ while (!(q.empty ()))
+ {
+ unsigned current = q.front ();
+ for (unsigned i = 0; i < tree.child_[current].size (); ++i)
+ q.push_back (tree.child_[current][i]);
+
+ mln_piter(set_p<point2d>) p(tree.data_[current].points);
+
+ for_all(p)
+ {
+ output(p) = tree.data_[current].value;
+ }
+ q.pop_front ();
+ }
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::util
+
+} // end of namespace mln
+
+#endif // !MLN_UTIL_TREE_FAST_TO_IMAGE_HH
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-25 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add a structure of tree based on vector.
* mln/util/tree_fast.hh: New structure of tree.
* tests/tree_fast.cc: New test for fast_tree.
---
mln/util/tree_fast.hh | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++
tests/tree_fast.cc | 63 ++++++++++++++++++++
2 files changed, 219 insertions(+)
Index: trunk/milena/tests/tree_fast.cc
===================================================================
--- trunk/milena/tests/tree_fast.cc (revision 0)
+++ trunk/milena/tests/tree_fast.cc (revision 1387)
@@ -0,0 +1,63 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*!
+ * \file tests/tree_fast.cc
+ *
+ * \brief test of mln::util::tree_fast
+ *
+ */
+
+#include <mln/util/tree_fast.hh>
+#include <mln/core/contract.hh>
+#include <iostream>
+
+int main (void)
+{
+ using namespace mln;
+
+ unsigned elt1 = 1;
+ unsigned elt2 = 2;
+ unsigned elt3 = 3;
+ unsigned elt4 = 4;
+ unsigned elt5 = 5;
+ unsigned elt6= 42;
+
+ util::tree<unsigned> tree(elt1);
+ mln_assertion(tree.has (elt1));
+ tree.add_child(tree.search(elt1), elt2);
+ mln_assertion(tree.has (elt2));
+ tree.add_child(tree.search(elt1), elt3);
+ mln_assertion(tree.has (elt3));
+ tree.add_child(tree.search(elt2), elt4);
+ mln_assertion(tree.has (elt4));
+ tree.add_child(tree.search(elt2), elt5);
+ mln_assertion(tree.has (elt5));
+ tree.add_parent(elt6);
+ mln_assertion(tree.has (elt6));
+ mln_assertion(tree.search(elt6) == tree.root_);
+}
Index: trunk/milena/mln/util/tree_fast.hh
===================================================================
--- trunk/milena/mln/util/tree_fast.hh (revision 0)
+++ trunk/milena/mln/util/tree_fast.hh (revision 1387)
@@ -0,0 +1,156 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_UTIL_TREE_HH
+# define MLN_UTIL_TREE_HH
+
+# include <vector>
+# include <mln/core/contract.hh>
+
+/*!
+ * \file mln/util/tree_fast.hh
+ *
+ * \brief Definition of a fast generic general tree.
+ *
+ */
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ template <typename T>
+ struct tree
+ {
+ tree();
+ tree(T& elt);
+
+ const unsigned size() const;
+ bool has (T& elt) const;
+ unsigned search (T& elt) const;
+ bool is_root (unsigned i) const;
+ void add_child (unsigned i, T& elt);
+ void add_parent (T& elt);
+
+ std::vector<T> data_;
+ std::vector<unsigned> parent_;
+ std::vector<std::vector<unsigned> > child_;
+ unsigned root_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ tree<T>::tree()
+ {
+ }
+
+ template <typename T>
+ tree<T>::tree(T& elt)
+ {
+ std::vector<unsigned> v;
+ data_.push_back(elt);
+ parent_.push_back(0);
+ child_.push_back(v);
+ root_ = 0;
+ }
+
+ template <typename T>
+ const unsigned
+ tree<T>::size() const
+ {
+ return (data_.size ());
+ }
+
+
+ template <typename T>
+ bool
+ tree<T>::has (T& elt) const
+ {
+ for (unsigned i = 0; i < data_.size (); ++i)
+ if (data_[i] == elt)
+ return true;
+
+ return false;
+ }
+
+ template <typename T>
+ unsigned
+ tree<T>::search (T& elt) const
+ {
+ for (unsigned i = 0; i < data_.size (); ++i)
+ if (data_[i] == elt)
+ return i;
+
+ return (unsigned)(-1);
+ }
+
+ template <typename T>
+ bool
+ tree<T>::is_root (unsigned i) const
+ {
+ return (root_ == i);
+ }
+
+ template <typename T>
+ void
+ tree<T>::add_child (unsigned i, T& elt)
+ {
+ mln_assertion (i < data_.size ());
+ std::vector<unsigned> v;
+ data_.push_back(elt);
+ parent_.push_back(i);
+ child_.push_back(v);
+ child_[i].push_back(data_.size () - 1);
+ }
+
+ template <typename T>
+ void
+ tree<T>::add_parent (T& elt)
+ {
+ std::vector<unsigned> v;
+ data_.push_back(elt);
+ parent_.push_back(data_.size () - 1);
+ child_.push_back(v);
+ child_[data_.size () - 1].push_back(root_);
+ parent_[root_] = data_.size () - 1;
+ root_ = data_.size () - 1;
+ }
+
+
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::util
+
+
+} // end of namespace mln
+
+
+#endif // !MLN_UTIL_TREE_HH
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-24 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Update fllt and fix tree.
Fix mln::util::tree.
* mln/util/tree.hh,
* mln/util/tree_to_image.hh,
* tests/tree.cc,
* tests/tree_to_image.cc: Update.
Update fllt.
* sandbox/garrigues/fllt.hh,
* sandbox/garrigues/test_fllt.cc: Update.
Update.
* mln/display/save.hh: Update.
---
mln/display/save.hh | 30 +++++++
mln/util/tree.hh | 101 ++++++++++++++++++-----
mln/util/tree_to_image.hh | 29 ++++--
sandbox/garrigues/fllt.hh | 173 ++++++++++++++++++++++++-----------------
sandbox/garrigues/test_fllt.cc | 38 +++++----
tests/tree.cc | 28 ++++--
tests/tree_to_image.cc | 31 ++++---
7 files changed, 290 insertions(+), 140 deletions(-)
Index: trunk/milena/tests/tree.cc
===================================================================
--- trunk/milena/tests/tree.cc (revision 1385)
+++ trunk/milena/tests/tree.cc (revision 1386)
@@ -44,16 +44,22 @@
unsigned elt3 = 3;
unsigned elt4 = 4;
unsigned elt5 = 5;
+ unsigned elt6= 42;
- util::tree<unsigned> tree(elt1);
- tree.add_child(elt2);
- tree.add_child(elt3);
- util::tree<unsigned>* tree2 = tree.search(elt2);
- mln_assertion(tree2);
- tree2->add_child(elt4);
- tree2->add_child(elt5);
- util::tree<unsigned>* tree3 = tree.search(elt4);
- mln_assertion(tree3);
- tree3 = tree2->search(elt1);
- mln_assertion(!tree3);
+ util::node<unsigned> node(elt1);
+ node.add_child(elt2);
+ node.add_child(elt3);
+ util::node<unsigned>* node2 = node.search(elt2);
+ mln_assertion(node2);
+ node2->add_child(elt4);
+ node2->add_child(elt5);
+ util::node<unsigned>* node3 = node.search(elt4);
+ mln_assertion(node3);
+ node3 = node2->search(elt1);
+ mln_assertion(!node3);
+ util::tree<unsigned>* tre = new util::tree<unsigned>(&node);
+ mln_assertion(tre);
+ tre->add_tree_up(elt6);
+ util::tree<unsigned>* trees = tre->tree_get(elt5);
+ mln_assertion(trees);
}
Index: trunk/milena/tests/tree_to_image.cc
===================================================================
--- trunk/milena/tests/tree_to_image.cc (revision 1385)
+++ trunk/milena/tests/tree_to_image.cc (revision 1386)
@@ -57,6 +57,7 @@
I s4;
I s5;
I s6;
+ I s7;
for (int i = 0; i < 100; ++i)
for (int j = 0; j < 100; ++j)
@@ -82,17 +83,25 @@
for (int j = 50; j < 60; ++j)
s6.insert(point2d(i, j));
- util::tree<I> tree(s1);
- tree.add_child(s2);
- tree.add_child(s3);
-
- util::tree<I>* tree2 = tree.search(s2);
- mln_assertion(tree2);
- tree2->add_child(s4);
- tree2->add_child(s5);
- util::tree<I>* tree3 = tree.search(s4);
- mln_assertion(tree3);
- tree3->add_child(s6);
+ for (int i = 0; i < 300; ++i)
+ for (int j = 0; j < 200; ++j)
+ s7.insert(point2d(i, j));
+
+ util::node<I> node(s1);
+ node.add_child(s2);
+ node.add_child(s3);
+
+ util::node<I>* node2 = node.search(s2);
+ mln_assertion(node2);
+ node2->add_child(s4);
+ node2->add_child(s5);
+ util::node<I>* node3 = node.search(s4);
+ mln_assertion(node3);
+ node3->add_child(s6);
+
+ util::tree<I> tree (&node);
+
+ tree.add_tree_up(s7);
util::tree_to_image(tree, output);
Index: trunk/milena/mln/display/save.hh
===================================================================
--- trunk/milena/mln/display/save.hh (revision 1385)
+++ trunk/milena/mln/display/save.hh (revision 1386)
@@ -55,6 +55,10 @@
void
save(const Image<I>& input_);
+ template <typename I>
+ void
+ save_color(const Image<I>& input_);
+
# ifndef MLN_INCLUDE_ONLY
namespace impl
@@ -79,6 +83,25 @@
map_saved_image_tmp_[(void*)input.id_ ()] = path_tmp;
}
+ template <typename I>
+ void
+ save_color(const Image<I>& input_)
+ {
+ const I& input = exact (input_);
+
+ /// Use of mkstemp instead tempmap.
+ char *tmp = (char*)malloc (12 * sizeof (char));
+ strcpy(tmp, "/tmp/XXXXXX");
+ if (mkstemp(tmp) == -1)
+ return;
+ std::string path_tmp = tmp;
+
+ io::ppm::save(input, path_tmp);
+
+ std::cout << input.id_ () << " = " << path_tmp << std::endl;
+ map_saved_image_tmp_[(void*)input.id_ ()] = path_tmp;
+ }
+
} // end of namespace mln::display::impl
/// Facade.
@@ -89,6 +112,13 @@
return impl::save(input_);
}
+ template <typename I>
+ void
+ save_color(const Image<I>& input_)
+ {
+ return impl::save_color(input_);
+ }
+
# endif // !MLN_INCLUDE_ONLY
} // end of namespace mln::display
Index: trunk/milena/mln/util/tree_to_image.hh
===================================================================
--- trunk/milena/mln/util/tree_to_image.hh (revision 1385)
+++ trunk/milena/mln/util/tree_to_image.hh (revision 1386)
@@ -37,6 +37,7 @@
*/
#include <mln/util/tree.hh>
+# include <mln/core/set_p.hh>
namespace mln
{
@@ -46,7 +47,7 @@
template <typename T, typename I>
void
- tree_to_image_rec(tree<T>& tree, Image<I>& output_, const mln_value(I) lvl);
+ tree_to_image_rec(node<T>* node, Image<I>& output_);
template <typename T, typename I>
void
@@ -56,20 +57,28 @@
template <typename T, typename I>
void
- tree_to_image_rec(tree<T>& tree, Image<I>& output_, const mln_value(I) lvl)
+ tree_to_image_rec(node<T>* node, Image<I>& output_)
{
I& output = exact(output_);
- mln_piter(T) p(tree.elt_);
+
+ mln_piter(set_p<point2d>) p(node->elt_.points);
for_all(p)
- output(p) = lvl;
+ {
+ std::cout << p
+ << std::endl;
+ output(p) = node->elt_.value;
+ }
+ typename std::vector< util::node<T>* >::const_iterator it = node->child_.begin();
- typename std::vector< util::tree<T>* >::const_iterator it = tree.child_.begin();
- for (;
- it != tree.child_.end();
- ++it)
- tree_to_image_rec((**it), output, lvl + 1);
+ for (int i = 0;
+ it != node->child_.end();
+ ++it, ++i)
+ {
+ if (*it)
+ tree_to_image_rec((*it), output);
+ }
}
@@ -78,7 +87,7 @@
tree_to_image (tree<T>& tree, Image<I>& output_)
{
I& output = exact(output_);
- tree_to_image_rec(tree, output, 1);
+ tree_to_image_rec(tree.root_, output);
}
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/util/tree.hh
===================================================================
--- trunk/milena/mln/util/tree.hh (revision 1385)
+++ trunk/milena/mln/util/tree.hh (revision 1386)
@@ -44,37 +44,92 @@
{
template <typename T>
- struct tree
+ struct node
{
- tree();
- tree(T& elt);
+ node();
+ node(T& elt);
T& content();
const T& content() const;
void add_child(T& elt);
- void set_parent(tree<T>* parent);
- tree<T>* get_parent();
+ void set_parent(node<T>* parent);
+ node<T>* get_parent();
void print_rec(int n) const;
- void print(void) const;
- int search_rec(tree<T>** res, T& elt);
- tree<T>* search(T& elt);
+ void print() const;
+ int search_rec(node<T>** res, T& elt);
+ node<T>* search(T& elt);
T elt_;
- tree<T>* parent_;
- std::vector< tree<T>* > child_;
+ node<T>* parent_;
+ std::vector< node<T>* > child_;
};
+ template <typename T>
+ struct tree
+ {
+ typedef node<T> node_t;
+ tree();
+ tree(node<T>* root);
+
+ tree<T>* tree_get(T& elt);
+ void add_tree_up (T& elt);
+ void add_tree_down (T& elt);
+
+ node<T>* root_;
+ };
# ifndef MLN_INCLUDE_ONLY
template <typename T>
tree<T>::tree()
+ : root_ (0)
+ {
+ }
+
+ template <typename T>
+ tree<T>::tree(node<T>* root)
+ : root_ (root)
+ {
+ mln_assertion (root != 0);
+ }
+
+ template <typename T>
+ tree<T>*
+ tree<T>::tree_get(T& elt)
+ {
+ node<T>* n = root_->search(elt);
+ tree<T>* res = new tree (n);
+
+ return res;
+ }
+
+ template <typename T>
+ void
+ tree<T>::add_tree_up(T& elt)
+ {
+ node<T>* n = new node<T> (elt);
+ root_->parent_ = n;
+ n->child_.push_back (root_);
+ root_ = n;
+ }
+
+ template <typename T>
+ void
+ tree<T>::add_tree_down(T& elt)
+ {
+ node<T>* n = new node<T> (elt);
+ root_->child_.push_back (n);
+ }
+
+
+ template <typename T>
+ node<T>::node()
: parent_ (0)
{
}
template <typename T>
- tree<T>::tree(T& elt)
+ node<T>::node(T& elt)
: elt_ (elt),
parent_ (0)
{
@@ -82,23 +137,23 @@
template <typename T>
const T&
- tree<T>::content() const
+ node<T>::content() const
{
return elt_;
}
template <typename T>
T&
- tree<T>::content()
+ node<T>::content()
{
return elt_;
}
template <typename T>
void
- tree<T>::add_child(T& elt)
+ node<T>::add_child(T& elt)
{
- tree<T>* s = new tree<T>(elt);
+ node<T>* s = new node<T>(elt);
s->parent_ = this;
this->child_.push_back(s);
@@ -106,7 +161,7 @@
template <typename T>
void
- tree<T>::set_parent(tree<T>* parent)
+ node<T>::set_parent(node<T>* parent)
{
mln_assertion(parent != 0);
parent_ = parent;
@@ -115,15 +170,15 @@
template <typename T>
- tree<T>*
- tree<T>::get_parent()
+ node<T>*
+ node<T>::get_parent()
{
return parent_;
}
template <typename T>
int
- tree<T>::search_rec(tree<T>** res, T& elt)
+ node<T>::search_rec(node<T>** res, T& elt)
{
if (elt == this->elt_)
{
@@ -132,7 +187,7 @@
}
else
{
- for (typename std::vector<tree<T>* >::iterator it = this->child_.begin();
+ for (typename std::vector<node<T>* >::iterator it = this->child_.begin();
it != this->child_.end(); ++it)
{
if ((**it).search_rec(res, elt))
@@ -143,10 +198,10 @@
}
template <typename T>
- tree<T>*
- tree<T>::search(T& elt)
+ node<T>*
+ node<T>::search(T& elt)
{
- tree<T>* res = 0;
+ node<T>* res = 0;
if (search_rec(&res, elt))
return res;
Index: trunk/milena/sandbox/garrigues/fllt.hh
===================================================================
--- trunk/milena/sandbox/garrigues/fllt.hh (revision 1385)
+++ trunk/milena/sandbox/garrigues/fllt.hh (revision 1386)
@@ -72,19 +72,29 @@
# include <mln/pw/value.hh>
# include <mln/pw/cst.hh>
+# include <mln/util/tree_to_image.hh>
+# include <mln/value/int_u8.hh>
+# include <mln/level/stretch.hh>
+# include <mln/level/compare.hh>
+# include <mln/io/pgm/save.hh>
+
namespace mln
{
namespace fllt
{
- template <typename P>
+ template <typename P, typename V>
struct fllt_node
{
+ V value;
set_p<P> points;
set_p<P> holes;
};
- # define fllt_node(P) util::tree< fllt_node<P> >
+ # define fllt_tree(P, V) util::tree< fllt_node<P, V> >
+ # define fllt_node(P, V) util::node< fllt_node<P, V> >
+ // # define fllt_node(P, V) typename fllt_tree(P, V)::node_t
+
// LOWER LEVEL SET : region = c4, border = c8
@@ -132,14 +142,14 @@
V& g,
point2d& x0)
{
- std::cout << "entering step 1" << std::endl;
+ //std::cout << "entering step 1" << std::endl;
// x0 <- a not tagged local mininum of ima.
- std::cout << std::endl << "x0 = " << p << std::endl;
+ //std::cout << std::endl << "x0 = " << p << std::endl;
x0 = p;
// g <- u(x0)
g = ima(x0);
- std::cout << "g = " << g << std::endl;
- std::cout << "exiting step 1" << std::endl;
+ //std::cout << "g = " << g << std::endl;
+ //std::cout << "exiting step 1" << std::endl;
}
template <typename P>
@@ -148,7 +158,7 @@
set_p<P>& N,
point2d& x0)
{
- std::cout << "entering step 2" << std::endl;
+ //std::cout << "entering step 2" << std::endl;
// A <- {x0}
A.clear();
A.insert(x0);
@@ -156,7 +166,7 @@
R.clear();
// N <- {}
N.clear();
- std::cout << "exiting step 2" << std::endl;
+ //std::cout << "exiting step 2" << std::endl;
}
@@ -169,7 +179,7 @@
V& gn)
{
static bool finished = false;
- std::cout << "entering step 3" << std::endl;
+ //std::cout << "entering step 3" << std::endl;
// Stop the algorithm.
if (finished)
@@ -185,17 +195,17 @@
N.insert (n);
}
- debug::println(u);
+ // debug::println(u);
- std::cout << "A :" << std::endl;
- if (A.npoints())
- debug::println(u | A);
- std::cout << "N :" << std::endl;
- if (N.npoints())
- debug::println(u | N);
- std::cout << "R :" << std::endl;
- if (R.npoints())
- debug::println(u | R);
+// //std::cout << "A :" << std::endl;
+// if (A.npoints())
+// //debug::println(u | A);
+// //std::cout << "N :" << std::endl;
+// if (N.npoints())
+// //debug::println(u | N);
+// //std::cout << "R :" << std::endl;
+// if (R.npoints())
+// //debug::println(u | R);
// gn <- min u(x) x belongs to N.
if ((u | set::inter(N, u.domain())).npoints() > 0)
@@ -205,7 +215,7 @@
finished = true;
gn += F::inc;
}
- std::cout << std::endl << "gN = " << gn << std::endl;
+ //std::cout << std::endl << "gN = " << gn << std::endl;
// R <- R union A
// tag the pixels of A.
@@ -214,7 +224,7 @@
R.insert(qa);
tagged(qa) = true;
}
- std::cout << "exiting step 3" << std::endl;
+ //std::cout << "exiting step 3" << std::endl;
}
@@ -226,16 +236,17 @@
set_p<P>& N,
V& g,
V& gn,
- fllt_node(P)* current_region,
- image2d<fllt_node(P)*>& regions
+ fllt_node(P, V)*& current_region,
+ image2d<fllt_node(P, V)*>& regions
)
{
- std::cout << "entering step 4_1" << std::endl;
+ //std::cout << "entering step 4_1" << std::endl;
// Create a new conected component.
// FIXME : we can make it faster.
mln_piter(set_p<P>) p(R);
- current_region = new fllt_node(P)();
+ current_region = new fllt_node(P, V)();
+ current_region->content().value = g;
for_all(p)
{
if (regions(p) == 0)
@@ -260,9 +271,8 @@
labeling::level(border_ima, true, F::bdr_nbh(), tmp, n);
// debug::println(border_ima);
- std::cout << "nb composantes :" << n << std::endl;
- debug::println(tmp);
-
+ //std::cout << "nb composantes :" << n << std::endl;
+ // debug::println(tmp);
if (n > 1)
{
@@ -283,18 +293,18 @@
g = gn;
// A <- {x belongs to N / u(x) == g}
A.clear();
- A = set::uni(A, N | pw::value(u) == pw::cst(g));
+ A = set::uni(A, set::inter(N, u.domain()) | pw::value(u) == pw::cst(g));
// N <- N\{x belongs to N / u(x) == g}
- N = set::diff(N, N | pw::value(u) == pw::cst(g));
+ N = set::diff(N, set::inter(N, u.domain()) | pw::value(u) == pw::cst(g));
- std::cout << "A :" << std::endl;
- if (A.npoints())
- debug::println(u | A);
- std::cout << "N :" << std::endl;
- if (N.npoints())
- debug::println(u | N);
+// std::cout << "A :" << std::endl;
+// if (A.npoints())
+// debug::println(u | A);
+// std::cout << "N :" << std::endl;
+// if (N.npoints())
+// debug::println(u | N);
- std::cout << "exiting step 4_1" << std::endl;
+ //std::cout << "exiting step 4_1" << std::endl;
}
@@ -304,25 +314,25 @@
set_p<P>& A,
set_p<P>& N,
V& g,
- fllt_node(P)* current_region,
- image2d<fllt_node(P)*>& regions
+ fllt_node(P, V)* current_region,
+ image2d<fllt_node(P, V)*>& regions
)
{
- std::cout << "entering step 4_2" << std::endl;
+ //std::cout << "entering step 4_2" << std::endl;
// A <- {x belongs to N / u(x) == g}
- A = set::uni(A, N | pw::value(u) == pw::cst(g));
+ A = set::uni(A, set::inter(N, u.domain()) | pw::value(u) == pw::cst(g));
// N <- N\{x belongs to N / u(x) == g}
- N = set::diff(N, N | pw::value(u) == pw::cst(g));
+ N = set::diff(N, set::inter(N, u.domain()) | pw::value(u) == pw::cst(g));
- std::cout << "A :" << std::endl;
- if (A.npoints())
- debug::println(u | A);
- std::cout << "N :" << std::endl;
- if (N.npoints())
- debug::println(u | N);
+// std::cout << "A :" << std::endl;
+// if (A.npoints())
+// debug::println(u | A);
+// std::cout << "N :" << std::endl;
+// if (N.npoints())
+// debug::println(u | N);
- std::cout << "exiting step 4_2" << std::endl;
+ //std::cout << "exiting step 4_2" << std::endl;
}
/// IF g > gn.
@@ -332,7 +342,7 @@
const set_p<P>& R,
const V& g)
{
- std::cout << "entering step 4_3" << std::endl;
+ //std::cout << "entering step 4_3" << std::endl;
// set the gray-level of the pixels of R to g.
mln_piter(set_p<P>) p(R);
@@ -342,13 +352,13 @@
u (p) = g;
}
- std::cout << "exiting step 4_3" << std::endl;
+ //std::cout << "exiting step 4_3" << std::endl;
}
template <typename V, typename F>
- fllt_node(point2d)*
+ fllt_tree(point2d, V)*
compute_level_set(const image2d<V>& ima)
{
typedef point2d P;
@@ -358,10 +368,9 @@
typedef mln::image_if<
mln::image2d<V>,
mln::fun::greater_p2b_expr_<mln::pw::value_<mln::image2d<V> >,
- mln::pw::cst_<V> >
+ mln::pw::cst_<int> >
> I_IF;
-
// Declarations.
set_p<P> R, N, A;
V g, gn;
@@ -370,11 +379,11 @@
image2d<V> u = clone(ima);
border::fill(u, 0);
- std::cout << "image U:" << std::endl;
- debug::println_with_border(u);
+ //std::cout << "image U:" << std::endl;
+ // debug::println_with_border(u);
image2d<bool> tagged(ima.domain());
- fllt_node(P)* current_region;
- image2d<fllt_node(P)*> regions(ima.domain());
+ fllt_node(P, V)* current_region;
+ image2d<fllt_node(P, V)*> regions(ima.domain());
// INIT
R.clear();
@@ -392,12 +401,13 @@
unsigned nlabels;
F::regional_extremum(ima, F::reg_nbh(), min_locals, nlabels);
- debug::println(min_locals);
- debug::println(min_locals | (pw::value(min_locals) > pw::cst(0)));
+// debug::println(min_locals);
+// debug::println(min_locals | (pw::value(min_locals) > pw::cst(0)));
/// Algorithm.
{
// For all locals extremums
+ //void* x = min_locals | (pw::value(min_locals) > pw::cst(0));
I_IF min_locals_list(min_locals | (pw::value(min_locals) > pw::cst(0)));
mln_piter(I_IF) p(min_locals_list.domain());
for_all(p)
@@ -409,7 +419,7 @@
step2(A, R, N, x0);
while (1)
{
- std::cout << "g = " << g << std::endl;
+ //std::cout << "g = " << g << std::endl;
step3<V, P, F>(u, tagged, A, R, N, gn);
/// step4.
if (F::compare(g, gn))
@@ -435,14 +445,35 @@
break;
}
}
+ //std::cout << "current_region = " << current_region << std::endl;
}
} // end of Algorithm
std::cout << "END OF ALGORITHM" << std::endl;
- debug::println(regions);
- //debug::println(ima | regions(make::point2d(-4,-1))->content().points);
+ image2d<value::int_u8> output (ima.domain ());
+ fllt_tree(P, V)& tree = *new fllt_tree(P, V)(current_region);
+ util::tree_to_image (tree, output);
+
+
+ debug::println(output);
+ std::cout << std::endl;
+ debug::println(ima);
+
+ if (output != ima)
+ {
+ std::cerr << "BUG!!!" << std::endl;
+ abort();
+ }
+
+ io::pgm::save(output, "out.pgm");
+ std::cout << "out.pgm generate"
+ << std::endl;
- return (current_region);
+
+ // debug::println(regions);
+ //debug::println(ima | regions(make:defined reference to `mln::fllt::lower<mln::value::int_u<8u> >::inc':point2d(-4,-1))->content().points);
+
+ return (&tree);
} // end of compute_level_set
@@ -501,9 +532,9 @@
static const neighb2d& reg_nbh() { return c8(); }
};
- template <typename P>
- void find_shapes_of_holes(fllt_node(P)* lower,
- fllt_node(P)* upper)
+ template <typename P, typename V>
+ void find_shapes_of_holes(fllt_node(P, V)* lower,
+ fllt_node(P, V)* upper)
{
}
@@ -513,14 +544,14 @@
{
typedef point2d P;
- fllt_node(P)* upper_tree;
- fllt_node(P)* lower_tree;
+ fllt_tree(P, V)* upper_tree;
+ fllt_tree(P, V)* lower_tree;
lower_tree = compute_level_set<V, lower<V> >(ima);
- upper_tree = compute_level_set<V, upper<V> >(ima);
+ // upper_tree = compute_level_set<V, upper<V> >(ima);
- find_shapes_of_holes(lower_tree, upper_tree);
+ //find_shapes_of_holes(lower_tree, upper_tree);
}
} // end of namespace mln::fllt
Index: trunk/milena/sandbox/garrigues/test_fllt.cc
===================================================================
--- trunk/milena/sandbox/garrigues/test_fllt.cc (revision 1385)
+++ trunk/milena/sandbox/garrigues/test_fllt.cc (revision 1386)
@@ -1,30 +1,40 @@
-# include <mln/core/image2d.hh>
# include "fllt.hh"
+# include <mln/core/image2d.hh>
+# include <mln/core/clone.hh>
+# include <mln/value/int_u8.hh>
# include <mln/debug/println.hh>
# include <mln/convert/to_w_window.hh>
# include <mln/core/w_window2d_int.hh>
# include <mln/convert/to_image.hh>
+# include <mln/level/fill.hh>
+# include <mln/io/pgm/load.hh>
+# include <mln/io/pbm/load.hh>
int main()
{
using namespace mln;
- int ws[81] = {3,2,3,3,5,5,5,5,5,
- 2,1,3,4,4,4,4,5,5,
- 2,3,4,2,3,3,2,4,4,
- 1,4,2,1,1,2,1,2,2,
- 1,2,4,2,1,2,1,1,1,
- 1,3,3,4,2,3,2,1,1,
- 1,3,3,4,2,3,2,1,1,
- 1,3,3,4,2,3,2,1,1,
- 1,3,3,4,2,3,2,1,1};
+// int ws[81] = {3,2,3,3,5,5,5,5,5,
+// 2,1,3,4,4,4,4,5,5,
+// 2,3,4,2,3,3,2,4,4,
+// 1,4,2,1,1,2,1,2,2,
+// 1,2,4,2,1,2,1,1,1,
+// 1,3,3,3,4,3,2,5,1,
+// 1,3,4,3,4,3,2,5,1,
+// 1,3,3,3,4,3,2,5,1,
+// 1,3,3,4,2,3,2,1,1};
+
+// w_window2d_int w_win = make::w_window2d(ws);
+// image2d<int> ima = convert::to_image(w_win);
+//fllt::fllt(ima);
+
- w_window2d_int w_win = make::w_window2d(ws);
+ image2d<value::int_u8> ima = io::pgm::load("../../img/tiny.pgm");
- image2d<int> ima = convert::to_image(w_win);
+ image2d<int> ima_int(ima.domain());
+level::fill(ima_int, ima);
debug::println(ima);
- fllt::fllt(ima);
- //fllt::fllt(ima);
+ fllt::fllt(ima_int);
}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-24 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Update fllt.
* sandbox/garrigues/fllt.hh: (border_neighb and region_neighb) Rename
as...
(border_neighb and region_neighb) ...this.
---
fllt.hh | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
Index: trunk/milena/sandbox/garrigues/fllt.hh
===================================================================
--- trunk/milena/sandbox/garrigues/fllt.hh (revision 1384)
+++ trunk/milena/sandbox/garrigues/fllt.hh (revision 1385)
@@ -179,7 +179,7 @@
mln_piter(set_p<P>) qa(A);
for_all(qa)
{
- mln_niter(neighb2d) n(F::region_neighb(), qa);
+ mln_niter(neighb2d) n(F::reg_nbh(), qa);
for_all (n)
if (!R.has (n))
N.insert (n);
@@ -257,7 +257,7 @@
level::fill(border_ima, false);
level::fill(inplace(border_ima | N), true);
unsigned n;
- labeling::level(border_ima, true, F::border_neighb(), tmp, n);
+ labeling::level(border_ima, true, F::bdr_nbh(), tmp, n);
// debug::println(border_ima);
std::cout << "nb composantes :" << n << std::endl;
@@ -267,7 +267,7 @@
{
// IF number of conected components of the border > 1
- for (int i = 2; i < n; i++)
+ for (int i = 2; i <= n; i++)
{
// follow each border to find which is the exterior border
// and which are the holes. Keep one pixel of each holes.
@@ -390,7 +390,7 @@
// Get the locals extremums
unsigned nlabels;
- F::regional_extremum(ima, F::region_neighb(), min_locals, nlabels);
+ F::regional_extremum(ima, F::reg_nbh(), min_locals, nlabels);
debug::println(min_locals);
debug::println(min_locals | (pw::value(min_locals) > pw::cst(0)));
@@ -469,8 +469,8 @@
typedef accu::min accu_for_gn;
- static const neighb2d& border_neighb() { return c8(); }
- static const neighb2d& region_neighb() { return c4(); }
+ static const neighb2d& bdr_nbh() { return c8(); }
+ static const neighb2d& reg_nbh() { return c4(); }
};
@@ -497,8 +497,8 @@
static const int inc = -1;
typedef accu::max accu_for_gn;
- static const neighb2d& border_neighb() { return c4(); }
- static const neighb2d& region_neighb() { return c8(); }
+ static const neighb2d& bdr_nbh() { return c4(); }
+ static const neighb2d& reg_nbh() { return c8(); }
};
template <typename P>
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Make metal vec and mat work with traits and scalars.
* tests/metal_mat.cc: Inactivate "non" tests.
Augment.
* tests/metal_vec.cc: Augment.
* tests/value_int_u8.cc: Conform to style.
* mln/trait/op/eq.hh: Remove dead code.
* mln/core/category.hh: Add const version.
* mln/core/h_vec.hh: Add traits.
* mln/core/ops.hh: Handle const types in traits.
* mln/literal/ops.hh: Add traits.
* mln/metal/mat.hh: Fix.
* mln/metal/vec.hh (sprod): Replace by...
(operator*): ...this new operator.
* mln/arith/plus.hh (plus_cst): Simplify.
* mln/value/ops.hh: Add traits for scalar_.
* mln/value/quat.hh: Update.
* mln/value/int_u.hh (uminus): New trait.
* mln/value/int_u_sat.hh: Fix ctor.
* mln/value/builtin/ops.hh: Enhance FIXME txt.
* mln/morpho/includes.hh: Update.
mln/arith/plus.hh | 5
mln/core/category.hh | 5
mln/core/h_vec.hh | 43 ++++++
mln/core/ops.hh | 32 +++++
mln/literal/ops.hh | 39 +++++-
mln/metal/mat.hh | 292 ++++++++++++-----------------------------------
mln/metal/vec.hh | 64 +++++-----
mln/morpho/includes.hh | 2
mln/trait/op/eq.hh | 8 -
mln/value/builtin/ops.hh | 3
mln/value/int_u.hh | 6
mln/value/int_u_sat.hh | 12 +
mln/value/ops.hh | 125 +++++++++++++++++++-
mln/value/quat.hh | 4
tests/metal_mat.cc | 64 ++++++++--
tests/metal_vec.cc | 14 +-
tests/value_int_u8.cc | 1
17 files changed, 434 insertions(+), 285 deletions(-)
Index: tests/metal_mat.cc
--- tests/metal_mat.cc (revision 1383)
+++ tests/metal_mat.cc (working copy)
@@ -31,23 +31,63 @@
*/
#include <mln/metal/mat.hh>
+#include <mln/value/int_u8.hh>
+
int main()
{
using namespace mln;
- const int
- tab1[18] = {3, 6, 5, 2, 4, 8,
- 5, 7, 4, 6, 9, 2,
- 2, 7, 1, 1, 5, 3},
- tab2[6] = {2, 5, 1, 0, 7, 2},
- tab3[6] = {3, 1, 6, 2, 1, 0};
-
- metal::mat<3,6,int> mat36 = make::mat<3,6,18>(tab1);
- metal::mat<2,3,int> mat23_1 = make::mat<2,3,6>(tab2);
- metal::mat<2,3,int> mat23_2 = make::mat<2,3,6>(tab3);
+ // FIXME: A test should not print!
+
+ // const int
+ // tab1[18] = {3, 6, 5, 2, 4, 8,
+ // 5, 7, 4, 6, 9, 2,
+ // 2, 7, 1, 1, 5, 3},
+ // tab2[6] = {2, 5, 1, 0, 7, 2},
+ // tab3[6] = {3, 1, 6, 2, 1, 0};
+
+ // metal::mat<3,6,int> mat36 = make::mat<3,6,18>(tab1);
+ // metal::mat<2,3,int> mat23_1 = make::mat<2,3,6>(tab2);
+ // metal::mat<2,3,int> mat23_2 = make::mat<2,3,6>(tab3);
+
+ // metal::mat<2,3,float> mat23_3 = mat23_1 - mat23_2;
+
+ // std::cout << mat23_3 << std::endl << mat23_3 * mat36 << std::endl;
+
+ using metal::vec;
+ vec<2,int> v = make::vec(5,1);
+
+ using metal::mat;
+ mat<2,2, vec<2,int> > mv;
+ mv.set_all(v);
+ // std::cout << mv << std::endl;
- metal::mat<2,3,float> mat23_3 = mat23_1 - mat23_2;
+ {
+ mat<2,2,float> tmp = mv * mv;
+ // std::cout << tmp << std::endl;
+ tmp(0,0) = 0;
+ }
+ {
+ vec<2, vec<2,float> > tmp = mv * v;
+ // std::cout << (mv * v) << std::endl;
+ tmp[0] = v;
+ }
+ {
+ mat<2,2,float> tmp = value::scalar(v) * mv;
+ // std::cout << (value::scalar(v) * mv) << std::endl;
+ tmp(0,0) = 0;
+ }
+ {
+ vec<2, mat<2,2, vec<2,float> > > tmp = v * value::scalar(mv);
+ // std::cout << (v * value::scalar(mv)) << std::endl;
+ tmp[0](0,0) = v;
+ }
+ {
+ value::int_u8 i = 0;
+ mat<2,2, vec<2,int> > tmp = mv * i;
+ // std::cout << mv * i << std::endl;
+ tmp(0,0) = v;
+ }
- std::cout << mat23_3 << std::endl << mat23_3 * mat36 << std::endl;
}
Index: tests/metal_vec.cc
--- tests/metal_vec.cc (revision 1383)
+++ tests/metal_vec.cc (working copy)
@@ -34,6 +34,8 @@
#include <mln/value/int_u8.hh>
+struct nu {};
+
int main()
{
using namespace mln;
@@ -41,13 +43,11 @@
metal::vec<3,int> v_int = make::vec(3,6,7);
metal::vec<3,float> v_f = make::vec(2.6, 1.9, 5.2);
- std::cout << v_int + v_f << std::endl;
- std::cout << v_f / 3 << std::endl;
+ mln_assertion((v_int + v_f) = ((v_f + v_int)));
+ mln_assertion((v_f / 3) = ((3 * v_f) / 9));
- {
-// value::int_u8 i = 3;
-// std::cout << value::scalar(i) * v_f << std::endl;
- // FIXME: Read FIXME in metal::vec::operator* and set up a test!
- }
+ value::int_u8 i = 3;
+ mln_assertion((i * v_f) = (value::scalar(i) * v_f));
+ mln_assertion((literal::zero + v_f) = v_f);
}
Index: tests/value_int_u8.cc
--- tests/value_int_u8.cc (revision 1383)
+++ tests/value_int_u8.cc (working copy)
@@ -33,6 +33,7 @@
#include <mln/value/int_u8.hh>
#include <tests/value_macros.hh>
+
int main()
{
using namespace mln;
Index: mln/trait/op/eq.hh
--- mln/trait/op/eq.hh (revision 1383)
+++ mln/trait/op/eq.hh (working copy)
@@ -52,14 +52,6 @@
} // end of namespace mln::trait::op
-
-// /// Default definition of op::eq is 'bool'.
-// template <typename L, typename R>
-// struct set_binary_< op::eq, Object, L, Object, R >
-// {
-// typedef bool ret;
-// };
-
} // end of namespace mln::trait
} // end of namespace mln
Index: mln/core/category.hh
--- mln/core/category.hh (revision 1383)
+++ mln/core/category.hh (working copy)
@@ -64,6 +64,11 @@
typedef typename T::category ret; // FIXME: if found or Unknown<void> => write a meta-program...
};
+ template <typename T>
+ struct category< const T >
+ {
+ typedef typename category<T>::ret ret;
+ };
} // end of namespace mln
Index: mln/core/h_vec.hh
--- mln/core/h_vec.hh (revision 1383)
+++ mln/core/h_vec.hh (working copy)
@@ -39,6 +39,49 @@
namespace mln
{
+ // Fwd decl.
+ template <unsigned d, typename C> struct h_vec;
+
+
+
+ namespace trait
+ {
+
+ // For unary traits.
+
+ template < template <class> class Name,
+ unsigned d, typename C >
+ struct set_precise_unary_< Name, h_vec<d, C> >
+ {
+ typedef mln_trait_unary(Name, C) V;
+ typedef h_vec<d, V> ret;
+ };
+
+ // For binary traits.
+
+ template < template <class, class> class Name,
+ unsigned d, typename C,
+ typename Q >
+ struct set_precise_binary_< Name,
+ h_vec<d, C>, h_vec<d, Q> >
+ {
+ typedef mln_trait_binary(Name, C, Q) V;
+ typedef h_vec<d, V> ret;
+ };
+
+ template < template <class, class> class Name,
+ unsigned d, typename C,
+ typename S >
+ struct set_precise_binary_< Name,
+ h_vec<d, C>, mln::value::scalar_<S> >
+ {
+ typedef mln_trait_binary(Name, C, S) V;
+ typedef h_vec<d, V> ret;
+ };
+
+ } // end of namespace mln::trait
+
+
template <unsigned d, typename C>
struct h_vec : public metal::vec<d + 1, C>
Index: mln/core/ops.hh
--- mln/core/ops.hh (revision 1383)
+++ mln/core/ops.hh (working copy)
@@ -91,6 +91,38 @@
// FIXME: Same for the other definitions below...
+
+ // Case of "const" in types.
+
+ template< template <class> class Name,
+ typename O >
+ struct set_precise_unary_< Name, const O >
+ {
+ typedef mln_trait_unary(Name, O) ret;
+ };
+
+ template< template <class,class> class Name,
+ typename O1, typename O2 >
+ struct set_precise_binary_< Name, O1, const O2 >
+ {
+ typedef mln_trait_binary(Name, O1, O2) ret;
+ };
+
+ template< template <class,class> class Name,
+ typename O1, typename O2 >
+ struct set_precise_binary_< Name, const O1, O2 >
+ {
+ typedef mln_trait_binary(Name, O1, O2) ret;
+ };
+
+ template< template <class,class> class Name,
+ typename O1, typename O2 >
+ struct set_precise_binary_< Name, const O1, const O2 >
+ {
+ typedef mln_trait_binary(Name, O1, O2) ret;
+ };
+
+
} // end of mln::trait
Index: mln/literal/ops.hh
--- mln/literal/ops.hh (revision 1383)
+++ mln/literal/ops.hh (working copy)
@@ -29,7 +29,9 @@
# define MLN_LITERAL_OPS_HH
/*! \file mln/literal/ops.hh
- * \brief Definitions of some operators.
+ *
+ * \brief Definitions of some operators where at least one literal is
+ * involved.
*/
# include <mln/core/concept/literal.hh>
@@ -42,6 +44,39 @@
namespace mln
{
+
+ namespace trait
+ {
+
+ template < template <class, class> class Name,
+ typename L, typename O >
+ struct set_binary_< Name, mln::Literal, L, mln::Object, O >
+ {
+ typedef mln_trait_binary(Name, O, O) ret;
+ };
+
+ template < template <class, class> class Name,
+ typename O, typename L >
+ struct set_binary_< Name, mln::Object, O, mln::Literal, L >
+ {
+ typedef mln_trait_binary(Name, O, O) ret;
+ };
+
+ template < typename L1, typename L2 >
+ struct set_binary_< op::eq, mln::Literal, L1, mln::Literal, L2 >
+ {
+ typedef bool ret;
+ };
+
+ template < typename L1, typename L2 >
+ struct set_binary_< op::neq, mln::Literal, L1, mln::Literal, L2 >
+ {
+ typedef bool ret;
+ };
+
+ } // end of namespace mln::trait
+
+
// Arithmetical operators.
template <typename O, typename L>
@@ -214,7 +249,7 @@
operator=(const Literal<L>& lhs, const Object<O>& rhs)
{
// mlc_converts_to(L, O)::check();
- return rhs = lhs;
+ return O(exact(lhs)) = exact(rhs);
}
template <typename L1, typename L2>
Index: mln/metal/mat.hh
--- mln/metal/mat.hh (revision 1383)
+++ mln/metal/mat.hh (working copy)
@@ -100,41 +100,22 @@
namespace trait
{
- // promote
+ // Unarys.
- template <unsigned n, unsigned m, typename T, typename U>
- struct set_precise_binary_<promote, metal::mat<n,m, T>, metal::mat<n,m, U> >
+ template < template<class> class Name,
+ unsigned n, unsigned m, typename T >
+ struct set_precise_unary_< Name, metal::mat<n,m,T> >
{
- typedef metal::mat<n,m, mln_trait_promote(T, U)> ret;
+ typedef metal::mat<n, m, mln_trait_unary(Name, T)> ret;
};
+ // Default for binarys; works for (+), (-), comparisons, and promote.
- // mat + mat
-
- template <unsigned n, unsigned m, typename T,
- typename U>
- struct set_precise_binary_<op::plus, metal::mat<n, m, T>, metal::mat<n, m, U> >
+ template < template<class, class> class Name,
+ unsigned n, unsigned m, typename T, typename U>
+ struct set_precise_binary_< Name, metal::mat<n,m,T>, metal::mat<n,m,U> >
{
- typedef metal::mat<n, m, mln_trait_op_plus(T, U)> ret;
- };
-
- // FIXME: + mat
-
- // mat - mat
-
- template <unsigned n, unsigned m, typename T,
- typename U>
- struct set_precise_binary_<op::minus, metal::mat<n, m, T>, metal::mat<n, m, U> >
- {
- typedef metal::mat<n, m, mln_trait_op_minus(T, U)> ret;
- };
-
- // - mat
-
- template <unsigned n, unsigned m, typename T>
- struct set_precise_unary_<op::uminus, metal::mat<n, m, T> >
- {
- typedef metal::mat<n, m, mln_trait_op_uminus(T)> ret;
+ typedef metal::mat<n, m, mln_trait_binary(Name, T, U)> ret;
};
// mat * mat
@@ -143,7 +124,13 @@
unsigned m, typename U>
struct set_precise_binary_<op::times, metal::mat<n,o,T>, metal::mat<o,m,U> >
{
- typedef metal::mat< n, m, mln_trait_op_times(T,U) > ret;
+ typedef metal::mat<n, m, mln_sum_x(T, U)> ret;
+ };
+
+ template < unsigned n, typename T, typename U >
+ struct set_precise_binary_< op::times, metal::mat<n,n,T>, metal::mat<n,n,U> >
+ { // Disambiguate between both previous defs.
+ typedef metal::mat<n, n, mln_sum_x(T, U)> ret;
};
// mat * vec
@@ -152,17 +139,27 @@
typename U>
struct set_precise_binary_<op::times, metal::mat<n,m,T>, metal::vec<m,U> >
{
- typedef mln_trait_op_times(T,U) TxU;
- typedef metal::vec< m, mln_sum(TxU) > ret;
+ typedef metal::vec<n, mln_sum_x(T, U)> ret;
};
// mat * s
- template <unsigned n, unsigned m, typename T,
+ template < template<class, class> class Name,
+ unsigned n, unsigned m, typename T,
typename S>
- struct set_precise_binary_<op::times, metal::mat<n,m,T>, S >
+ struct set_precise_binary_< Name, metal::mat<n,m,T>, mln::value::scalar_<S> >
{
- typedef metal::mat< n, m, mln_trait_op_times(T,S) > ret;
+ typedef metal::mat<n, m, mln_trait_binary(Name, T, S)> ret;
+ };
+
+ template < template<class, class> class Name,
+ unsigned n, unsigned m, typename T,
+ typename S >
+ struct set_binary_< Name,
+ mln::Object, metal::mat<n,m,T>,
+ mln::value::Scalar, S >
+ {
+ typedef metal::mat<n, m, mln_trait_binary(Name, T, S)> ret;
};
} // end of namespace mln::trait
@@ -187,31 +184,19 @@
namespace metal
{
- // eq
+ // =
template <unsigned n, unsigned m, typename T, typename U>
bool
- operator=(const mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
+ operator=(mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
- // +-
- template <unsigned n, unsigned m, typename T, typename U>
- mat<n,m,T>&
- operator+=(mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
-
- // + (binary)
+ // +
template <unsigned n, unsigned m, typename T, typename U>
mat<n, m, mln_trait_op_plus(T,U)>
operator+(mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
- // --
- template <unsigned n, unsigned m, typename T, typename U>
- mat<n,m,T>&
- operator-=(mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
-
- // - (binary)
+ // -
template <unsigned n, unsigned m, typename T, typename U>
mat<n, m, mln_trait_op_minus(T,U)>
@@ -223,67 +208,32 @@
mat<n, m, mln_trait_op_uminus(T)>
operator-(const mat<n,m,T>& lhs);
- // Operator *.
+ // mat * mat
template <unsigned n, unsigned o, typename T,
unsigned m, typename U>
- mat<n, m, mln_trait_op_times(T,U)>
- operator*(const mat<n,o,T>& lhs, const mat<o,m,U>& rhs); // mat * mat
-
-
-// template <unsigned n, unsigned m, typename T,
-// typename S>
-// mat<n, m, mln_trait_op_times(T,S)>
-// operator*(const mat<n,m,T>& lhs, const S& s); // mat * s
-
-
- // FIXME: Simplification below of the general code above:
-
- template <unsigned n, unsigned m, typename T>
- mat<n, m, T>
- operator*(const mat<n,m,T>& lhs, const T& s); // mat * s
+ mat<n, m, mln_sum_x(T,U)>
+ operator*(const mat<n,o,T>& lhs, const mat<o,m,U>& rhs);
+ // mat * vec
template <unsigned n, unsigned m, typename T,
typename U>
- typename mln::trait::op::times< mat<n,m,T>, vec<m,U> >::ret
- operator*(const mat<n,m,T>& lhs, const vec<m,U>& rhs) // mat * vec
- // FIXME: Move below...
- {
- typedef mat<n,m,T> mat_t;
- typedef vec<m,U> vec_t;
- mln_trait_op_times(mat_t, vec_t) tmp;
- for (unsigned i = 0; i < n; ++i)
- {
- mln_trait_op_times(T,U) sum = 0; // FIXME: Use literal::zero.
- for (unsigned j = 0; j < m; ++j)
- sum += lhs(i, j) * rhs[j];
- tmp[i] = sum;
- }
- return tmp;
- }
+ vec<n, mln_sum_x(T,U)>
+ operator*(const mat<n,m,T>& lhs, const vec<m,U>& rhs);
- // *-
- template <unsigned n, typename T, typename U>
- mat<n,n,T>&
- operator*=(mat<n,n,T>& lhs, const mat<n,n,U>& rhs);
-
- template <unsigned n, unsigned m, typename T, typename U>
- mat<n,m,T>&
- operator*=(mat<n,m,T>& lhs, const U& rhs);
-
- // Operator /.
+ // mat * s
- template <unsigned n, unsigned m, typename T, typename S>
- mat<n, m, mln_trait_op_times(T,S)> // FIXME: times instead of div...
- operator/(const mat<n,m,T>& lhs, const S& s);
+ template <unsigned n, unsigned m, typename T,
+ typename S>
+ mat<n, m, mln_trait_op_times(T,S)>
+ operator*(const mat<n,m,T>& lhs, const value::scalar_<S>& s);
- // /+ // mat / s
template <unsigned n, unsigned m, typename T, typename S>
- mat<n,m,T>&
- operator/=(mat<n,m,T>& lhs, const S& s);
+ mat<n, m, mln_trait_op_div(T,S)>
+ operator/(const mat<n,m,T>& lhs, const value::scalar_<S>& s);
// <<
@@ -291,13 +241,6 @@
std::ostream&
operator<<(std::ostream& ostr, const mat<n,m,T>& v);
- template <unsigned n, unsigned m>
- std::ostream&
- operator<<(std::ostream& ostr, const mat<n,m,unsigned char>& v);
-
- template <unsigned n, unsigned m>
- std::ostream&
- operator<<(std::ostream& ostr, const mat<n,m,signed char>& v);
# ifndef MLN_INCLUDE_ONLY
@@ -382,7 +325,8 @@
}
- // eq
+ // Operators.
+
template <unsigned n, unsigned m, typename T, typename U>
bool
@@ -395,20 +339,6 @@
return true;
}
- // +-
- template <unsigned n, unsigned m, typename T, typename U>
- mat<n,m,T>&
- operator+=(mat<n,m,T>& lhs, const mat<n,m,U>& rhs)
- {
- for (unsigned i = 0; i < n; ++i)
- for (unsigned j = 0; j < m; ++j)
- lhs(i, j) += rhs(i, j);
- return lhs;
- }
-
- // Operator +.
-
template <unsigned n, unsigned m, typename T, typename U>
mat<n, m, mln_trait_op_plus(T,U)>
operator+(const mat<n,m,T>& lhs, const mat<n,m,U>& rhs)
@@ -420,20 +350,6 @@
return tmp;
}
- // --
- template <unsigned n, unsigned m, typename T, typename U>
- mat<n,m,T>&
- operator-=(mat<n,m,T>& lhs, const mat<n,m,U>& rhs)
- {
- for (unsigned i = 0; i < n; ++i)
- for (unsigned j = 0; j < m; ++j)
- lhs(i, j) -= rhs(i, j);
- return lhs;
- }
-
- // Operators -.
-
template <unsigned n, unsigned m, typename T, typename U>
mat<n,m, mln_trait_op_minus(T,U)>
operator-(const mat<n,m,T>& lhs, const mat<n,m,U>& rhs)
@@ -456,81 +372,55 @@
return tmp;
}
- // *-
- template <unsigned n, typename T, typename U>
- mat<n,n,T>&
- operator*=(mat<n,n,T>& lhs, const mat<n,n,U>& rhs)
- {
- // FIXME: Optimize!
- lhs = lhs * rhs;
- return lhs;
- }
-
- template <unsigned n, unsigned m, typename T, typename U>
- mat<n,m,T>&
- operator*=(mat<n,m,T>& lhs, const U& s)
- {
- for (unsigned i = 0; i < n; ++i)
- for (unsigned j = 0; j < m; ++j)
- lhs(i, j) *= s;
- return lhs;
- }
-
- // Operators *.
-
template <unsigned n, unsigned o, typename T,
unsigned m, typename U>
- mat<n,m, mln_trait_op_times(T,U)>
+ mat<n, m, mln_sum_x(T,U)>
operator*(const mat<n,o,T>& lhs, const mat<o,m,U>& rhs)
{
- mat<n,m, mln_trait_op_times(T,U)> tmp;
+ mat<n,m, mln_sum_x(T,U)> tmp;
for (unsigned i = 0; i < n; ++i)
for (unsigned j = 0; j < m; ++j)
{
- tmp(i, j) = 0;
+ tmp(i, j) = literal::zero;
for (unsigned k = 0; k < o; ++k)
tmp(i, j) += lhs(i, k) * rhs(k, j);
}
return tmp;
}
- template <unsigned n, unsigned m, typename T>
- mat<n, m, T>
- operator*(const mat<n,m,T>& lhs, const T& s) // mat * s
-
- // FIXME: Read above.
-
-// template <unsigned n, unsigned m, typename T,
-// typename S>
-// mat<n,m, mln_trait_op_times(T,S)>
-// operator*(const mat<n,m,T>& lhs, const S& s)
+ template <unsigned n, unsigned m, typename T,
+ typename U>
+ vec<n, mln_sum_x(T,U)>
+ operator*(const mat<n,m,T>& lhs, const vec<m,U>& rhs)
{
- mat<n,m, T> tmp;
+ vec<n, mln_sum_x(T,U)> tmp;
for (unsigned i = 0; i < n; ++i)
+ {
+ mln_sum_x(T,U) sum(literal::zero);
for (unsigned j = 0; j < m; ++j)
- tmp(i, j) = lhs(i, j) * s;
+ sum += lhs(i, j) * rhs[j];
+ tmp[i] = sum;
+ }
return tmp;
}
- // /
-
template <unsigned n, unsigned m, typename T, typename S>
- mat<n,m,T>&
- operator/=(mat<n,m,T>& lhs, const S& s)
+ mat<n, m, mln_trait_op_times(T,S)>
+ operator*(const mat<n,m,T>& lhs, const value::scalar_<S>& s_)
{
+ S s = s_.to_equiv();
+ mat<n, m, mln_trait_op_times(T,S)> tmp;
for (unsigned i = 0; i < n; ++i)
for (unsigned j = 0; j < m; ++j)
- lhs(i, j) /= s;
- return lhs;
+ tmp(i, j) = lhs(i, j) * s;
+ return tmp;
}
- // Operator /.
-
template <unsigned n, unsigned m, typename T, typename S>
- mat<n,m, mln_trait_op_times(T,S)> // FIXME: Use div, not times!
- operator/(const mat<n,m,T>& lhs, const S& s)
+ mat<n,m, mln_trait_op_div(T,S)>
+ operator/(const mat<n,m,T>& lhs, const value::scalar_<S>& s_)
{
+ S s = s_.to_equiv();
mat<n,m, mln_trait_op_times(T,S)> tmp;
for (unsigned i = 0; i < n; ++i)
for (unsigned j = 0; j < m; ++j)
@@ -546,44 +436,14 @@
{
for (unsigned i = 0; i < n; ++i)
{
- ostr << '(';
+ ostr << '[';
for (unsigned j = 0; j < m; ++j)
- ostr << v(i, j) << (j = m - 1 ? ")" : ", ");
+ ostr << debug::format(v(i, j)) << (j = m - 1 ? "]" : ", ");
ostr << std::endl;
}
return ostr;
}
- template <unsigned n, unsigned m>
- std::ostream&
- operator<<(std::ostream& ostr, const mat<n,m,unsigned char>& v)
- {
- for (unsigned i = 0; i < n; ++i)
- {
- ostr << '(';
- for (unsigned j = 0; j < m; ++j)
- ostr << (unsigned int)(v[i][j]) << (j = m - 1 ? ")" : ", ");
- ostr << std::endl;
- }
- return ostr;
- }
-
- template <unsigned n, unsigned m>
- std::ostream&
- operator<<(std::ostream& ostr, const mat<n,m,signed char>& v)
- {
- for (unsigned i = 0; i < n; ++i)
- {
- ostr << '(';
- for (unsigned j = 0; j < m; ++j)
- ostr << (signed int)(v[i][j]) << (j = m - 1 ? ")" : ", ");
- ostr << std::endl;
- }
- return ostr;
- }
-
-
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::metal
Index: mln/metal/vec.hh
--- mln/metal/vec.hh (revision 1383)
+++ mln/metal/vec.hh (working copy)
@@ -177,8 +177,6 @@
void set_all(const T& val);
- T sprod(const vec<n, T>& rhs) const; // FIXME: Return is not T.
-
unsigned size() const;
const vec<n, T>& normalize();
@@ -222,6 +220,14 @@
typedef metal::vec<n, V> ret;
};
+ template < unsigned n, typename T,
+ typename U >
+ struct set_precise_binary_< op::times,
+ metal::vec<n, T>, metal::vec<n, U> >
+ {
+ typedef mln_sum_x(T,U) ret;
+ };
+
template < template <class, class> class Name,
unsigned n, typename T,
typename S >
@@ -232,8 +238,16 @@
typedef metal::vec<n, V> ret;
};
- // FIXME: What about scalar * vec!!!
-
+ template < template<class, class> class Name,
+ unsigned n, typename T,
+ typename S >
+ struct set_binary_< Name,
+ mln::Object, metal::vec<n, T>,
+ mln::value::Scalar, S >
+ {
+ typedef mln_trait_binary(Name, T, S) V;
+ typedef metal::vec<n, V> ret;
+ };
} // end of namespace mln::trait
@@ -274,17 +288,19 @@
vec<n, mln_trait_op_minus(T,U)>
operator-(const vec<n,T>& lhs, const vec<n,U>& rhs);
-// template <unsigned n, typename T>
-// vec<n, mln_trait_op_uminus(T)>
-// operator-(const vec<n,T>& lhs);
+ // vec * vec
- // *
+ template <unsigned n, typename T, typename U>
+ mln_sum_x(T,U)
+ operator*(const vec<n,T>& lhs, const vec<n,U>& rhs);
+
+ // vec * s
template <unsigned n, typename T, typename S>
vec<n, mln_trait_op_times(T, S)>
operator*(const vec<n,T>& lhs, const mln::value::scalar_<S>& s);
- // /
+ // vec / s
template <unsigned n, typename T, typename S>
vec<n, mln_trait_op_div(T, S)>
@@ -372,16 +388,6 @@
}
template <unsigned n, typename T>
- T vec<n,T>::sprod(const vec<n, T>& rhs) const
- {
- T tmp = 0;
-
- for (unsigned i = 0; i < n; ++i)
- tmp += data_[i] * rhs.data_[i];
- return tmp;
- }
-
- template <unsigned n, typename T>
unsigned vec<n,T>::size() const
{
return n;
@@ -417,7 +423,8 @@
const vec<n, T> vec<n, T>::origin = all_to(0);
- // eq
+ // Operators.
+
template <unsigned n, typename T, typename U>
bool operator=(const vec<n,T>& lhs, const vec<n,U>& rhs)
@@ -428,7 +435,6 @@
return true;
}
- // +
template <unsigned n, typename T, typename U>
vec<n, mln_trait_op_plus(T,U)>
@@ -440,8 +446,6 @@
return tmp;
}
- // -
-
template <unsigned n, typename T, typename U>
vec<n, mln_trait_op_minus(T,U)>
operator-(const vec<n,T>& lhs, const vec<n,U>& rhs)
@@ -452,7 +456,16 @@
return tmp;
}
- // *
+ template <unsigned n, typename T, typename U>
+ mln_sum_x(T,U)
+ operator*(const vec<n,T>& lhs, const vec<n,U>& rhs)
+ {
+ mln_sum_x(T,U) tmp(literal::zero);
+ for (unsigned i = 0; i < n; ++i)
+ tmp += lhs[i] * rhs[i];
+ return tmp;
+ }
+
template <unsigned n, typename T, typename S>
vec<n, mln_trait_op_times(T, S)>
@@ -474,8 +487,6 @@
return tmp;
}
- // /
-
template <unsigned n, typename T, typename S>
vec<n, mln_trait_op_div(T, S)>
operator/(const vec<n,T>& lhs, const mln::value::scalar_<S>& s)
@@ -487,7 +498,6 @@
return tmp;
}
- // <<
template <unsigned n, typename T>
std::ostream&
Index: mln/arith/plus.hh
--- mln/arith/plus.hh (revision 1383)
+++ mln/arith/plus.hh (working copy)
@@ -178,9 +178,8 @@
void plus_cst(const Image<I>& input, const V& val, Image<O>& output)
{
mln_precondition(exact(output).domain() = exact(input).domain());
- impl::plus_(mln_trait_image_speed(I)(), exact(input),
- trait::image::speed::any(), pw::cst(val) | exact(input).domain(),
- mln_trait_image_speed(O)(), exact(output)); // Calls the previous version.
+ plus(input, pw::cst(val) | exact(input).domain(), output);
+ // Calls the previous version.
}
template <typename L, typename R>
Index: mln/value/ops.hh
--- mln/value/ops.hh (revision 1383)
+++ mln/value/ops.hh (working copy)
@@ -37,11 +37,16 @@
# include <mln/value/builtin/all.hh>
# include <mln/value/concept/all.hh>
# include <mln/value/equiv.hh>
+# include <mln/value/props.hh>
# include <mln/literal/zero.hh>
# include <mln/literal/one.hh>
+# include <mln/literal/ops.hh>
# include <mln/metal/ret.hh>
+# define mln_sum_x(T, U) typename mln::value::props< mln_trait_op_times(T,U) >::sum
+
+
// FIXME: In the definitions below, is that equiv or interop?
@@ -62,7 +67,8 @@
typedef mln_trait_unary(Name, mln_value_equiv(V)) ret;
};
- // Binary traits for any Scalar type.
+
+ // Binary traits for any Scalar type...
template < template <class, class> class Name,
typename Vl, typename Vr >
@@ -71,6 +77,36 @@
typedef mln_trait_binary(Name, mln_value_equiv(Vl), mln_value_equiv(Vr)) ret;
};
+ // ...and for the special case of a couple of value::scalar_.
+
+ template < template <class, class> class Name,
+ typename Sl, typename Sr >
+ struct set_binary_< Name,
+ mln::value::Scalar, mln::value::scalar_<Sl>,
+ mln::value::Scalar, mln::value::scalar_<Sr> >
+ {
+ typedef mln_trait_binary(Name, mln_value_equiv(Sl), mln_value_equiv(Sr)) ret;
+ };
+
+
+ // Some binary traits for "scalar(s) OP obj" when OP commutes => "obj OP scalar(s)".
+
+ template < typename S, typename O >
+ struct set_binary_< op::plus,
+ mln::value::Scalar, mln::value::scalar_<S>,
+ mln::Object, O >
+ {
+ typedef mln_trait_op_plus(O, mln::value::scalar_<S>) ret;
+ };
+
+ template < typename S, typename O >
+ struct set_binary_< op::times,
+ mln::value::Scalar, mln::value::scalar_<S>,
+ mln::Object, O >
+ {
+ typedef mln_trait_op_times(O, mln::value::scalar_<S>) ret;
+ };
+
} // end of namespace mln::trait
@@ -97,6 +133,16 @@
operator % (const value::Scalar<Vl>& lhs, const value::Scalar<Vr>& rhs);
+
+ template <typename S, typename O>
+ mln_trait_op_plus(O, value::scalar_<S>)
+ operator + (const value::scalar_<S>& lhs, const Object<O>& rhs);
+
+ template <typename S, typename O>
+ mln_trait_op_times(O, value::scalar_<S>)
+ operator * (const value::scalar_<S>& lhs, const Object<O>& rhs);
+
+
// Arithmetical unary operators.
template <typename S>
@@ -112,6 +158,29 @@
+ // Case of value::scalar_ OP value::scalar_.
+
+ template <typename Sl, typename Sr>
+ mln_trait_op_plus(Sl, Sr)
+ operator + (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs);
+
+ template <typename Sl, typename Sr>
+ mln_trait_op_minus(Sl, Sr)
+ operator - (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs);
+
+ template <typename Sl, typename Sr>
+ mln_trait_op_times(Sl, Sr)
+ operator * (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs);
+
+ template <typename Sl, typename Sr>
+ mln_trait_op_div(Sl, Sr)
+ operator / (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs);
+
+ template <typename Sl, typename Sr>
+ mln_trait_op_mod(Sl, Sr)
+ operator % (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs);
+
+
# ifndef MLN_INCLUDE_ONLY
@@ -157,6 +226,60 @@
return - rhs.to_equiv();
}
+ template <typename S, typename O>
+ mln_trait_op_plus(O, value::scalar_<S>)
+ operator + (const value::scalar_<S>& lhs, const Object<O>& rhs)
+ {
+ return exact(rhs) + lhs;
+ }
+
+ template <typename S, typename O>
+ mln_trait_op_times(O, value::scalar_<S>)
+ operator * (const value::scalar_<S>& lhs, const Object<O>& rhs)
+ {
+ return exact(rhs) * lhs;
+ }
+
+ // ...
+
+
+ // With scalar_ OP scalar_.
+
+ template <typename Sl, typename Sr>
+ mln_trait_op_plus(Sl, Sr)
+ operator + (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs)
+ {
+ return value::equiv(lhs) + value::equiv(rhs);
+ }
+
+ template <typename Sl, typename Sr>
+ mln_trait_op_minus(Sl, Sr)
+ operator - (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs)
+ {
+ return value::equiv(lhs) - value::equiv(rhs);
+ }
+
+ template <typename Sl, typename Sr>
+ mln_trait_op_times(Sl, Sr)
+ operator * (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs)
+ {
+ return value::equiv(lhs) * value::equiv(rhs);
+ }
+
+ template <typename Sl, typename Sr>
+ mln_trait_op_div(Sl, Sr)
+ operator / (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs)
+ {
+ return value::equiv(lhs) / value::equiv(rhs);
+ }
+
+ template <typename Sl, typename Sr>
+ mln_trait_op_mod(Sl, Sr)
+ operator % (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs)
+ {
+ return value::equiv(lhs) % value::equiv(rhs);
+ }
+
// ...
# endif // ! MLN_INCLUDE_ONLY
Index: mln/value/quat.hh
--- mln/value/quat.hh (revision 1383)
+++ mln/value/quat.hh (working copy)
@@ -335,7 +335,7 @@
float
quat::sprod(const quat& rhs) const
{
- return v_.sprod(rhs.to_vec());
+ return v_ * rhs.to_vec();
}
bool quat::is_unit() const
@@ -443,7 +443,7 @@
quat operator*(const quat& lhs, const quat& rhs)
{
- quat tmp(lhs.s() * rhs.s() - lhs.v().sprod(rhs.v()),
+ quat tmp(lhs.s() * rhs.s() - lhs.v() * rhs.v(),
metal::vprod(lhs.v(), rhs.v()) + lhs.s() * rhs.v() + rhs.s() * lhs.v());
return tmp;
}
Index: mln/value/int_u.hh
--- mln/value/int_u.hh (revision 1383)
+++ mln/value/int_u.hh (working copy)
@@ -59,6 +59,12 @@
{
template <unsigned n>
+ struct set_precise_unary_< op::uminus, mln::value::int_u<n> >
+ {
+ typedef int ret;
+ };
+
+ template <unsigned n>
struct value_< mln::value::int_u<n> > : mln::trait::value_integer_<n>
{
};
Index: mln/value/int_u_sat.hh
--- mln/value/int_u_sat.hh (revision 1383)
+++ mln/value/int_u_sat.hh (working copy)
@@ -60,7 +60,7 @@
public internal::value_like_< int_u<n>, // Equivalent.
mln_enc(int_u<n>), // Encoding.
- int, // Interoperation.
+ unsigned, // Interoperation.
int_u_sat<n> > // Exact.
{
/// Constructor without argument.
@@ -130,10 +130,11 @@
template <unsigned n>
int_u_sat<n>::int_u_sat(int i)
{
+ static const unsigned max_ = mln_max(int_u<n>);
if (i < 0)
this->v_ = 0;
- else if (i > mln_max(int_u_sat<n>))
- this->v_ = mln_max(int_u_sat<n>);
+ else if (i > max_)
+ this->v_ = max_;
else
this->v_ = i;
}
@@ -148,10 +149,11 @@
int_u_sat<n>&
int_u_sat<n>::operator=(int i)
{
+ static const unsigned max_ = mln_max(int_u<n>);
if (i < 0)
this->v_ = 0;
- else if (i > mln_max(int_u_sat<n>))
- this->v_ = mln_max(int_u_sat<n>);
+ else if (i > max_)
+ this->v_ = max_;
else
this->v_ = i;
return *this;
Index: mln/value/builtin/ops.hh
--- mln/value/builtin/ops.hh (revision 1383)
+++ mln/value/builtin/ops.hh (working copy)
@@ -284,7 +284,7 @@
struct set_unary_< Name,
mln::value::Built_In, B >
{
- typedef B ret; // FIXME: Wrong!
+ typedef B ret; // FIXME: Wrong because some types are unsigned!
};
@@ -364,7 +364,6 @@
typedef mln_trait_op_mod(mln::value::scalar_<B>, O) ret;
};
-
} // end of namespace mln::trait
Index: mln/morpho/includes.hh
--- mln/morpho/includes.hh (revision 1383)
+++ mln/morpho/includes.hh (working copy)
@@ -38,6 +38,8 @@
# include <mln/core/concept/window.hh>
# include <mln/core/concept/neighborhood.hh>
+# include <mln/value/ops.hh>
+
# include <mln/accu/min.hh>
# include <mln/accu/max.hh>
# include <mln/accu/min_h.hh>
1
0