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
June 2008
- 9 participants
- 135 discussions
17 Jun '08
#20: Generate reference documentation (Doxygen)
------------------------+---------------------------------------------------
Reporter: levill_r | Owner: levill_r
Type: task | Status: closed
Priority: major | Milestone: Olena 2.0
Component: Olena | Version: 2.0
Resolution: duplicate | Keywords: doxygen doxy
------------------------+---------------------------------------------------
Changes (by levill_r):
* status: new => closed
* resolution: => duplicate
Comment:
Merge with #80, then close.
--
Ticket URL: <https://trac.lrde.org/olena/ticket/20#comment:3>
Olena <http://olena.lrde.epita.fr>
Olena, a generic and efficient C++ image processing library.
1
0
17 Jun '08
#17: Add basic mathematical morphology filters
-----------------------+----------------------------------------------------
Reporter: levill_r | Owner: levill_r
Type: task | Status: closed
Priority: major | Milestone: Olena 2.0
Component: Olena | Version: 2.0
Resolution: fixed | Keywords: morpho erosion dilation opening closing
-----------------------+----------------------------------------------------
Changes (by levill_r):
* status: new => closed
* resolution: => fixed
Old description:
> Start with
> * erosion / dilation,
> * opening / closing.
>
> Write
> * simple versions using neighborhoods,
> * variants (binary, etc.) using using neighborhoods,
> * simple versions using dpoint sets (windows),
> * variants (binary, etc.) using using dpoint sets (windows).
New description:
Start with
* erosion / dilation,
* opening / closing.
Write
* ~~simple versions using neighborhoods~~ (postponed to a later version),
* ~~variants (binary, etc.) using using neighborhoods~~ (postponed to a
later version),
* simple versions using dpoint sets (windows),
* variants (binary, etc.) using using dpoint sets (windows).
Comment:
Those filters have been implemented for a while. They need some
refactoring though (see #74).
--
Ticket URL: <https://trac.lrde.org/olena/ticket/17#comment:4>
Olena <http://olena.lrde.epita.fr>
Olena, a generic and efficient C++ image processing library.
1
0
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Cleanup site proxy materials.
* TODO: Remove; obsolete.
* mln/trait/solve_binary.hh: Use exact.
* mln/trait/solve_unary.hh: Likewise.
* mln/core/exact.hh (mln_exact): Disambiguate.
(exact): Use macro as return.
* mln/core/concept/site_proxy.hh: Remove redundant code,
use exact and cleanup.
core/concept/site_proxy.hh | 95 ++++++++++++++++-----------------------------
core/exact.hh | 14 ++----
trait/solve_binary.hh | 12 +++--
trait/solve_unary.hh | 8 ++-
4 files changed, 54 insertions(+), 75 deletions(-)
Index: mln/trait/solve_binary.hh
--- mln/trait/solve_binary.hh (revision 2028)
+++ mln/trait/solve_binary.hh (working copy)
@@ -37,6 +37,7 @@
*/
# include <mln/core/category.hh>
+# include <mln/core/exact.hh>
# include <mln/metal/equal.hh>
# include <mln/metal/if.hh>
# include <mln/metal/ret.hh>
@@ -294,13 +295,16 @@
template < template <class, class> class Name,
typename L,
typename R >
- struct solve_binary : internal::helper_solve_binary_< Name,
- typename mln::category<L>::ret, L,
- typename mln::category<R>::ret, R >
+ struct solve_binary
{
+ typedef mln_exact(L) L_;
+ typedef mln_exact(R) R_;
+ typedef typename mln::category<L_>::ret CatL;
+ typedef typename mln::category<R_>::ret CatR;
+ typedef internal::helper_solve_binary_< Name, CatL, L, CatR, R > meta_code;
+ typedef typename meta_code::ret ret;
};
-
} // end of namespace mln::trait
} // end of namespace mln
Index: mln/trait/solve_unary.hh
--- mln/trait/solve_unary.hh (revision 2028)
+++ mln/trait/solve_unary.hh (working copy)
@@ -37,6 +37,7 @@
*/
# include <mln/core/category.hh>
+# include <mln/core/exact.hh>
# include <mln/metal/equal.hh>
# include <mln/metal/if.hh>
# include <mln/metal/ret.hh>
@@ -166,9 +167,12 @@
// FIXME: Postfix solve_unary with a '-'(?)
template < template <class> class Name,
typename T >
- struct solve_unary : internal::helper_solve_unary_< Name,
- typename mln::category<T>::ret, T > // FIXME: typedef!
+ struct solve_unary
{
+ typedef mln_exact(T) E;
+ typedef typename mln::category<E>::ret Cat;
+ typedef internal::helper_solve_unary_< Name, Cat, E > meta_code;
+ typedef typename meta_code::ret ret;
};
} // end of namespace mln::trait
Index: mln/core/exact.hh
--- mln/core/exact.hh (revision 2028)
+++ mln/core/exact.hh (working copy)
@@ -36,7 +36,7 @@
/// FIXME: Doc!
-#define mln_exact(T) typename internal::exact_<T>::ret
+#define mln_exact(T) typename mln::internal::exact_<T>::ret
@@ -57,12 +57,10 @@
/// \{
template <typename T>
- typename internal::exact_<T>::ret*
- exact(T* ptr);
+ mln_exact(T)* exact(T* ptr);
template <typename T>
- typename internal::exact_<T>::ret&
- exact(T& ref);
+ mln_exact(T)& exact(T& ref);
/// \}
@@ -73,16 +71,14 @@
template <typename T>
inline
- typename internal::exact_<T>::ret*
- exact(T* ptr)
+ mln_exact(T)* exact(T* ptr)
{
return internal::exact_<T>::run(ptr);
}
template <typename T>
inline
- typename internal::exact_<T>::ret&
- exact(T& ref)
+ mln_exact(T)& exact(T& ref)
{
return *exact(&ref);
}
Index: mln/core/concept/site_proxy.hh
--- mln/core/concept/site_proxy.hh (revision 2028)
+++ mln/core/concept/site_proxy.hh (working copy)
@@ -49,6 +49,7 @@
namespace internal
{
+
// Every "Site_Proxy" class should derive from site_impl. The
// couple of classes below are provided to be specialized so that
// an effective implementation (with the interface of the
@@ -81,34 +82,52 @@
- // Meta-routine to get the site type from either a site or a site
- // proxy.
-
+ // Fwd decl.
template <typename P> struct site_from;
- template <typename P, bool is_proxy = true>
+ namespace deep
+ {
+
+ template <typename P, bool is_site_proxy = true>
struct helper_site_from
{
- typedef typename P::subject P_;
- typedef typename site_from<P_>::ret ret;
+ typedef typename P::subject S;
+ // Recursion.
+ typedef typename mln::internal::site_from<S>::ret ret;
+ // Routine.
+ static const ret& on(const P& p)
+ {
+ return p.to_site();
+ }
};
- template <typename P>
- struct helper_site_from<P, false>
+ template <typename O>
+ struct helper_site_from<O, /* is_site_proxy = */ false>
+ {
+ // Stop Recursion.
+ typedef O ret;
+ // Routine.
+ static const ret& on(const O& obj)
{
- typedef P ret;
+ return obj;
+ }
};
+ } // end of namespace internal::deep
+
+
+ /// Meta-routine to get the site type from a type \p P that can be
+ /// either a site proxy or a site.
template <typename P>
struct site_from
{
- enum { is_proxy = mlc_is_a(P, Site_Proxy)::value };
- typedef typename helper_site_from< P, is_proxy >::ret ret;
+ typedef mln_exact(P) E;
+ enum { is_site_proxy = mlc_is_a(E, Site_Proxy)::value };
+ typedef typename deep::helper_site_from< E, is_site_proxy >::ret ret;
};
- // Access to site reference.
-
+ /// Access to site reference.
template <typename O>
const typename site_from<O>::ret&
to_site(const O& obj);
@@ -171,57 +190,13 @@
// Access to site reference.
- namespace deep
- {
-
- template <bool b> struct to_site_;
-
- template <>
- struct to_site_< /* is proxy = */ true >
- {
- template <typename P>
- const typename site_from<P>::ret&
- doit(const Site_Proxy<P>& p) const
- {
- return exact(p).to_site();
- }
- };
-
- template <>
- struct to_site_< /* is proxy = */ false >
- {
- template <typename O>
- const O&
- doit(const O& obj) const
- {
- return obj;
- }
- };
-
- // FIXME: was:
-
-// template <typename P>
-// const typename site_from<P>::ret&
-// to_site(const Site_Proxy<P>& p)
-// {
-// return exact(p).to_site();
-// }
-
-// template <typename P>
-// const typename site_from<P>::ret&
-// to_site(const Object<P>& p)
-// {
-// return exact(p);
-// }
-
- } // end of namespace internal::deep
-
template <typename O>
const typename site_from<O>::ret&
to_site(const O& obj)
{
- enum { is_proxy = mlc_is_a(O, Site_Proxy)::value };
- return deep::to_site_< is_proxy >().doit(obj);
+ typedef mln_exact(O) E;
+ enum { is_site_proxy = mlc_is_a(E, Site_Proxy)::value };
+ return deep::helper_site_from<E, is_site_proxy>::on(exact(obj));
}
} // end of namespace mln::internal
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Sample code for Roland.
* geraud/dmap.cc: New.
dmap.cc | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 129 insertions(+)
Index: geraud/dmap.cc
--- geraud/dmap.cc (revision 0)
+++ geraud/dmap.cc (revision 0)
@@ -0,0 +1,129 @@
+#include <vector>
+
+#include <mln/core/image2d.hh>
+#include <mln/core/w_window2d_int.hh>
+#include <mln/debug/println.hh>
+#include <mln/level/fill.hh>
+#include <mln/level/stretch.hh>
+#include <mln/accu/max.hh>
+#include <mln/io/pbm/load.hh>
+#include <mln/io/pgm/save.hh>
+
+
+namespace mln
+{
+
+ template<typename I, typename W>
+ mln_ch_value(I, unsigned) dmap(const Image<I>& input_,
+ const Weighted_Window<W>& win_)
+ {
+ const I& input = exact(input_);
+ const W& win = exact(win_);
+ mln_precondition(input.has_data());
+
+ typedef std::vector<mln_point(I)> bucket_t;
+
+ // Initialization of distance.
+ mln_ch_value(I, unsigned) distance;
+ initialize(distance, input);
+
+ // Mod determination.
+ mln_accu_with_(accu::max, unsigned) max;
+ for (unsigned i = 0; i < win.ndpoints(); ++i)
+ max.take(win.w(i));
+ unsigned mod = unsigned(max) + 1;
+
+ // Aux data.
+ std::vector<bucket_t> bucket(mod);
+ unsigned bucket_size = 0;
+
+ // Initialization.
+ {
+ mln_piter(I) p(input.domain());
+ mln_qiter(W) q(win, p);
+ for_all(p)
+ if (input(p))
+ {
+ distance(p) = literal::zero;
+ for_all(q)
+ if (input.has(q) && ! input(q))
+ {
+ bucket[0].push_back(p);
+ ++bucket_size;
+ break;
+ }
+ }
+ else
+ distance(p) = mln_max(unsigned);
+ }
+
+ // Propagation.
+ {
+ mln_point(I) p;
+ mln_qiter(W) q(win, p);
+
+ for (unsigned d = 0; bucket_size != 0; ++d)
+ {
+ bucket_t& bucket_d = bucket[d % mod];
+ for (unsigned i = 0; i < bucket_d.size(); ++i)
+ {
+ p = bucket_d[i];
+
+ if (distance(p) < d)
+ // p has already been processed, having a distance less than d.
+ continue;
+
+ for_all(q)
+ if (distance.has(q) && distance(q) > d)
+ {
+ unsigned d_ = d + q.w();
+
+ if (d_ < distance(q))
+ {
+ distance(q) = d_;
+ bucket[d_ % mod].push_back(q);
+ ++bucket_size;
+ }
+ }
+ }
+ bucket_size -= bucket_d.size();
+ bucket_d.clear();
+ }
+
+ } // end of propagation.
+
+ return distance;
+ }
+
+} // end of namespace mln
+
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ const unsigned n = 256;
+ image2d<bool> ima(n, n);
+ level::fill(ima, false);
+ ima.at(n / 2, n / 2) = true;
+
+ int ws[] = { 3, 2, 3,
+ 2, 0, 2,
+ 3, 2, 3 };
+
+// int ws[] = { 0, 9, 0, 9, 0,
+// 9, 6, 4, 6, 9,
+// 0, 4, 0, 4, 0,
+// 9, 6, 4, 6, 9,
+// 0, 9, 0, 9, 0 }; // coef = 4.1203
+
+ w_window2d_int win = make::w_window2d(ws);
+
+ image2d<unsigned> d = dmap(ima, win);
+
+ image2d<int_u8> out(d.domain());
+ level::stretch(d, out);
+ io::pgm::save(out, "out.pgm");
+}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk
Index: milena/sandbox/ChangeLog
===================================================================
--- milena/sandbox/ChangeLog (revision 2026)
+++ milena/sandbox/ChangeLog (revision 2027)
@@ -105,6 +105,12 @@
* levillain/morpho/shortest_path_watershed.hh:
New (imported from Olena proto-1.0).
+2008-05-29 Thierry Géraud <thierry.geraud(a)lrde.epita.fr>
+
+ Test (sorry).
+
+ * geraud/toto: New.
+
2008-05-28 Ugo Jardonnet <jardonnet(a)lrde.epita.fr>
Sandbox: ICP: Materials for report.
Index: ChangeLog
===================================================================
--- ChangeLog (revision 2026)
+++ ChangeLog (revision 2027)
@@ -1,9 +1,3 @@
-2008-05-29 Thierry Géraud <thierry.geraud(a)lrde.epita.fr>
-
- Test (sorry).
-
- * milena/sandbox/geraud/toto: New.
-
2008-05-15 Roland Levillain <roland(a)lrde.epita.fr>
Pass option nostdinc to Automake.
1
0
16 Jun '08
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Preparing cleanup and update of trait::solve_unary.
* mln/trait/solve.hh: Split this file contents into...
* mln/trait/solve_binary.hh,
* mln/trait/solve_unary.hh: ... these new files.
* doc/tutorial/examples/p_array.2.cc,
* mln/trait/image/props.hh,
* mln/core/concept/site_set.hh: Fix warning.
doc/tutorial/examples/p_array.2.cc | 3
mln/core/concept/site_set.hh | 2
mln/trait/image/props.hh | 20 -
mln/trait/solve.hh | 370 -----------------------------------
mln/trait/solve_binary.hh | 255 ------------------------
mln/trait/solve_unary.hh | 385 -------------------------------------
6 files changed, 28 insertions(+), 1007 deletions(-)
Index: doc/tutorial/examples/p_array.2.cc
--- doc/tutorial/examples/p_array.2.cc (revision 2025)
+++ doc/tutorial/examples/p_array.2.cc (working copy)
@@ -62,7 +62,8 @@
util::index i;
mln_qiter_(W) j(win, i);
- for (i = 0; i < arr.nsites(); i = i + 1)
+ int n = arr.nsites();
+ for (i = 0; i < n; i = i + 1)
{
std::cout << "i=" << i << ": ";
for_all(j)
Index: mln/trait/image/props.hh
--- mln/trait/image/props.hh (revision 2025)
+++ mln/trait/image/props.hh (working copy)
@@ -94,11 +94,11 @@
// |
// + -- site_wise_only
// |
-// + ------- cell_wise
-// | \
-// + -- value_wise \
-// \ \
-// ---- + -- cell_and_value_wise
+// + -------- cell_wise
+// | |
+// + -- value_wise |
+// \ |
+// -- + -- cell_and_value_wise
// value_io: /any/
// |
@@ -321,11 +321,11 @@
// |
// + -- site_wise_only
// |
-// + ------- cell_wise
-// | \
-// + -- value_wise \
-// \ \
-// ---- + -- cell_and_value_wise
+// + -------- cell_wise
+// | |
+// + -- value_wise |
+// \ |
+// -- + -- cell_and_value_wise
struct value_browsing
{
Index: mln/trait/solve.hh
--- mln/trait/solve.hh (revision 2025)
+++ mln/trait/solve.hh (working copy)
@@ -136,123 +136,6 @@
- namespace internal
- {
-
- // Fwd decls.
- template < template <class> class Name,
- template <class> class Category_T, typename T >
- struct get_unary_;
-
-
- template < typename user_ret, /* != not_found and != undefined */
- template <class> class Name,
- template <class> class Category_T, typename T >
- struct helper_get_unary_
- {
- typedef user_ret ret; // The user has defined 'ret' so we return it.
- };
-
-
- template < template <class> class Name,
- template <class> class Category_T, typename T >
- struct helper_get_unary_< /* user_ret == */ not_found,
- Name, Category_T, T >
- {
- typedef not_found ret; // End of search due to a blocker; 'ret' is not found.
- };
-
-
- template < template <class> class Name, typename Super_Category, typename T >
- struct helper_get_unary_rec_;
-
- template < template <class> class Name, template <class> class Super_Category_T, typename T >
- struct helper_get_unary_rec_< Name, Super_Category_T<void>, T > {
- typedef typename get_unary_<Name, Super_Category_T, T>::ret ret;
- };
-
- template < template <class> class Name,
- template <class> class Category_T, typename T >
- struct helper_get_unary_< /* user_ret == */ undefined,
- Name, Category_T, T >
- {
- typedef typename internal::super_category_< Category_T, T >::ret super;
- typedef typename helper_get_unary_rec_<Name, super, T>::ret ret; // No user ret definition => Recursion.
- };
-
-
- template < template <class> class Name,
- template <class> class Category_T, typename T >
- struct get_unary_
- {
- typedef typename mln::trait::set_unary_<Name, Category_T, T>::ret user_ret; // First get 'user_ret'
- typedef helper_get_unary_<user_ret, Name, Category_T, T> helper; // Set the helper to make a decision.
- typedef mlc_ret(helper) ret; // Return.
- };
-
-
- template < typename precise_ret,
- template <class> class Name,
- template <class> class Category_T, typename T >
- struct helper_choose_unary_wrt_ /* precise_ret != undefined */
- {
- typedef precise_ret ret; // -> A precise ret has been defined so it is it.
- };
-
- template < template <class> class Name,
- template <class> class Category_T, typename T >
- struct helper_choose_unary_wrt_< /* precise_ret == */ undefined,
- Name, Category_T, T >
- {
- typedef typename get_unary_<Name, Category_T, T>::ret ret; // -> Go up into the category inheritance
- // to fetch a ret from 'set_unary_'s.
- };
-
- template < template <class> class Name,
- template <class> class Category_T, typename T >
- struct helper_choose_unary_
- {
- typedef typename set_precise_unary_<Name, T>::ret precise_ret;
- typedef helper_choose_unary_wrt_< precise_ret, /* undefined or not (?) */
- Name, Category_T, T> helper;
- typedef mlc_ret(helper) ret;
- };
-
-
- template < template <class> class Name,
- typename Category_T_void, typename T >
- struct helper_solve_unary_; // This helper changes the category plain type into the category meta type.
-
- template < template <class> class Name,
- template <class> class Category_T, typename void_T, typename T >
- struct helper_solve_unary_< Name, Category_T<void_T>, T >
- :
- helper_choose_unary_< Name, Category_T, T > // FIXME: typedef!
- {
- // FIXME: Check that void_T is 'void' or 'void*'.
- };
-
- // FIXME: Remove below.
-
-// template < template <class> class Name,
-// template <class> class Category_T, typename T >
-// struct helper_solve_unary_< Name, Category_T<void*>, T >
-// :
-// helper_choose_unary_< Name, Category_T, T > // FIXME: typedef!
-// {};
-
- } // end of namespace mln::trait::internal
-
-
- // FIXME: Postfix solve_unary with a '-'(?)
- template < template <class> class Name,
- typename T >
- struct solve_unary : internal::helper_solve_unary_< Name,
- typename mln::category<T>::ret, T > // FIXME: typedef!
- {
- };
-
-
// Binary case.
@@ -265,6 +148,7 @@
typedef undefined ret;
};
+
template < template <class, class> class Name,
template <class> class Category_L, typename L,
template <class> class Category_R, typename R >
@@ -273,7 +157,6 @@
typedef undefined ret;
};
-
template < template <class, class> class Name,
typename L,
template <class> class Category_R, typename R >
@@ -299,256 +182,13 @@
};
-
- namespace internal
- {
-
- // triplet_ret_
-
- template < unsigned i_L_, unsigned i_R_, typename ret_ >
- struct triplet_
- {
- typedef ret_ ret;
- };
-
-
- // merge_triplets_
-
- template < typename L_trp, typename R_trp >
- struct merge_triplets_;
-
- template < unsigned L_i_L, unsigned L_i_R, typename L_ret,
- unsigned R_i_L, unsigned R_i_R, typename R_ret >
- struct merge_triplets_< triplet_<L_i_L, L_i_R, L_ret>,
- triplet_<R_i_L, R_i_R, R_ret> >
- {
- typedef metal::bool_<(L_i_L <= R_i_L && L_i_R <= R_i_R)> take_L;
- typedef metal::bool_<(R_i_L <= L_i_L && R_i_R <= L_i_R)> take_R;
- typedef metal::or_<take_L, take_R> ok;
- typedef typename metal::if_< metal::and_<ok, take_L>,
- triplet_<L_i_L, L_i_R, L_ret>,
- typename metal::if_< metal::and_<ok, take_R>,
- triplet_<R_i_L, R_i_R, R_ret>,
- triplet_<0,0, not_found> >::ret >::ret ret;
- };
-
- template < unsigned i_L, unsigned i_R, typename LR_ret >
- struct merge_triplets_< triplet_<i_L, i_R, LR_ret>,
- triplet_<i_L, i_R, LR_ret> >
- {
- typedef triplet_<i_L, i_R, LR_ret> ret;
- };
-
-
- template < unsigned L_i_L, unsigned L_i_R, unsigned L_i_max,
- unsigned R_i_L, unsigned R_i_R, unsigned R_i_max >
- // L_i_max and R_i_max differ
- struct helper_merge_triplets_same_ret_
- {
- // The winning couple between L_* and R_* is the one which
- // maximum index is the smallest; for instance, with:
- // left branch giving L_i_L = 5 and L_i_R = 1 so L_i_max = 5
- // right branch giving L_i_L = 3 and L_i_R = 4 so R_i_max = 4
- // the right branch wins.
- enum { i_L = (L_i_max < R_i_max ? L_i_L : R_i_L),
- i_R = (L_i_max < R_i_max ? L_i_R : R_i_R) };
- };
-
- template < unsigned L_i_L, unsigned L_i_R, unsigned i_max,
- unsigned R_i_L, unsigned R_i_R >
- // L_i_max is equal to R_i_max
- struct helper_merge_triplets_same_ret_< L_i_L, L_i_R, i_max,
- R_i_L, R_i_R, i_max >
- {
- // The winning couple is the one with the minimum index.
- enum { L_i_min = (L_i_L < L_i_R ? L_i_L : L_i_R),
- R_i_min = (R_i_L < R_i_R ? R_i_L : R_i_R),
- i_L = (L_i_min < R_i_min ? L_i_L : R_i_L),
- i_R = (L_i_min < R_i_min ? L_i_R : R_i_R) };
- };
-
-
- template < unsigned L_i_L, unsigned L_i_R, typename LR_ret,
- unsigned R_i_L, unsigned R_i_R >
- struct merge_triplets_< triplet_<L_i_L, L_i_R, LR_ret>,
- triplet_<R_i_L, R_i_R, LR_ret> >
- {
- typedef helper_merge_triplets_same_ret_< L_i_L, L_i_R, (L_i_L > L_i_R ? L_i_L : L_i_R),
- R_i_L, R_i_R, (R_i_L > R_i_R ? R_i_L : R_i_R) > helper;
- typedef triplet_<helper::i_L, helper::i_R, LR_ret> ret;
- };
-
- template < unsigned L_i_L, unsigned L_i_R, typename L_ret >
- struct merge_triplets_< triplet_<L_i_L, L_i_R, L_ret>,
- triplet_< 0, 0, not_found> >
- {
- typedef triplet_<L_i_L, L_i_R, L_ret> ret;
- };
-
- template < unsigned R_i_L, unsigned R_i_R, typename R_ret >
- struct merge_triplets_< triplet_< 0, 0, not_found>,
- triplet_<R_i_L, R_i_R, R_ret> >
- {
- typedef triplet_<R_i_L, R_i_R, R_ret> ret;
- };
-
- template <> // To disambiguate.
- struct merge_triplets_< triplet_<0, 0, not_found>,
- triplet_<0, 0, not_found> >
- {
- typedef triplet_<0u,0u, not_found> ret;
- };
-
-
-
- // Fwd decl.
- template < template <class, class> class Name,
- unsigned i_L, template <class> class Category_L, typename L,
- unsigned i_R, template <class> class Category_R, typename R >
- struct get_binary_;
-
-
- template < typename user_ret, /* != not_found and != undefined */
- template <class, class> class Name,
- unsigned i_L, template <class> class Category_L, typename L,
- unsigned i_R, template <class> class Category_R, typename R >
- struct helper_get_binary_
- {
- typedef triplet_< i_L, i_R, user_ret > ret; // The user has defined 'ret' so we return it.
- };
-
- template < template <class, class> class Name,
- unsigned i_L, template <class> class Category_L, typename L,
- unsigned i_R, template <class> class Category_R, typename R >
- struct helper_get_binary_< /* user_ret == */ not_found,
- Name, i_L, Category_L, L, i_R, Category_R, R >
- {
- typedef triplet_< 0, 0, not_found > ret; // End of search due to a blocker; 'ret' is not found.
- };
-
-
- template < template <class, class> class Name, // Nota bene: Seq means "super or equal".
- unsigned i_L, typename Seq_Category_L, typename L,
- unsigned i_R, typename Seq_Category_R, typename R >
- struct helper_get_binary_rec_;
-
- template < template <class, class> class Name,
- unsigned i_L, template <class> class Seq_Category_L, typename L,
- unsigned i_R, template <class> class Seq_Category_R, typename R >
- struct helper_get_binary_rec_< Name, i_L, Seq_Category_L<void>, L, i_R, Seq_Category_R<void>, R >
- {
- typedef typename get_binary_<Name, i_L, Seq_Category_L, L, i_R, Seq_Category_R, R>::ret ret;
- };
-
-
- template < template <class, class> class Name,
- unsigned i_L, template <class> class Category_L, typename L,
- unsigned i_R, template <class> class Category_R, typename R >
- struct helper_get_binary_< /* user_ret == */ undefined,
- Name, i_L,Category_L, L, i_R,Category_R, R >
- {
- // No user definition for 'ret' so treillis construction in a static recursive way.
-
- // FIXME: We *do* need to handle this search with a priority!
- // FIXME: for a result can be found in both branches...
-
- typedef typename super_category_< Category_L, L >::ret Super_Category_L;
- typedef typename super_category_< Category_R, R >::ret Super_Category_R;
-
- typedef helper_get_binary_rec_< Name,
- i_L + 1, Super_Category_L, L,
- i_R, Category_R<void>, R > L_branch;
- typedef mlc_ret(L_branch) L_trp;
-
- typedef helper_get_binary_rec_< Name,
- i_L, Category_L<void>, L,
- i_R + 1, Super_Category_R, R > R_branch;
- typedef mlc_ret(R_branch) R_trp;
-
- typedef typename merge_triplets_< L_trp, R_trp >::ret ret;
- };
-
-
- template < template <class, class> class Name,
- unsigned i_L, template <class> class Category_L, typename L,
- unsigned i_R, template <class> class Category_R, typename R >
- struct get_binary_
- {
- typedef typename mln::trait::set_binary_<Name, Category_L,L,
- Category_R,R>::ret user_ret; // First get 'user_ret'
- typedef helper_get_binary_<user_ret, Name, i_L,Category_L,L,
- i_R,Category_R,R> helper; // Set the helper to make a decision.
- typedef mlc_ret(helper) ret; // Return a triplet.
- };
-
-
- template < typename precise_ret,
- template <class, class> class Name,
- template <class> class Category_L, typename L,
- template <class> class Category_R, typename R >
- struct helper_choose_binary_wrt_ /* precise_ret != undefined */
- {
- typedef precise_ret ret; // -> A precise ret has been defined so it is it.
- };
-
- template < template <class, class> class Name,
- template <class> class Category_L, typename L,
- template <class> class Category_R, typename R >
- struct helper_choose_binary_wrt_< /* precise_ret == */ undefined,
- Name, Category_L, L, Category_R, R >
- {
- typedef typename get_binary_< Name,
- 0, Category_L, L,
- 0, Category_R, R >::ret triplet; // Browse upwards the category inheritance
- typedef mlc_ret(triplet) ret; // to fetch ret from 'get_binary_'s.
- };
-
-
- template < template <class, class> class Name,
- template <class> class Category_L, typename L,
- template <class> class Category_R, typename R >
- struct helper_choose_binary_
- {
- typedef typename set_precise_binary_<Name, L, R>::ret precise_ret; /* undefined or not (?) */
- typedef helper_choose_binary_wrt_<precise_ret, Name, Category_L,L, Category_R,R> helper;
- typedef mlc_ret(helper) ret;
- };
-
-
- template < template <class, class> class Name,
- typename Category_L_void, typename L,
- typename Category_R_void, typename R >
- struct helper_solve_binary_;
-
- template < template <class, class> class Name,
- template <class> class Category_L, typename void_L, typename L,
- template <class> class Category_R, typename void_R, typename R >
- struct helper_solve_binary_< Name,
- Category_L<void_L>, L,
- Category_R<void_R>, R > : helper_choose_binary_< Name,
- Category_L, L,
- Category_R, R >
- {
- // FIXME: Check that void_L and void_R are 'void' or 'void*'.
- };
-
- } // end of namespace mln::trait::internal
-
-
- // FIXME: Postfix solve_binary with a '-'(?)
- template < template <class, class> class Name,
- typename L,
- typename R >
- struct solve_binary : internal::helper_solve_binary_< Name,
- typename mln::category<L>::ret, L,
- typename mln::category<R>::ret, R >
- {
- };
-
-
} // end of namespace mln::trait
} // end of namespace mln
+# include <mln/trait/solve_unary.hh>
+# include <mln/trait/solve_binary.hh>
+
+
#endif // ! MLN_TRAIT_SOLVE_HH
Index: mln/trait/solve_binary.hh
--- mln/trait/solve_binary.hh (revision 2025)
+++ mln/trait/solve_binary.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006 EPITA Research and Development Laboratory
+// Copyright (C) 2006, 2008 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,11 +25,11 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_TRAIT_SOLVE_HH
-# define MLN_TRAIT_SOLVE_HH
+#ifndef MLN_TRAIT_SOLVE_BINARY_HH
+# define MLN_TRAIT_SOLVE_BINARY_HH
/*!
- * \file mln/trait/solve.hh
+ * \file mln/trait/solve_binary.hh
*
* \brief FIXME
*
@@ -48,13 +48,6 @@
# endif // ! MLN_DEBUG_TRAITS
-# 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
-
-
namespace mln
{
@@ -62,244 +55,6 @@
namespace trait
{
- /// Flag type for a not found trait.
- struct not_found {};
-
- /// Flag type for an undefined trait.
- struct undefined {};
-
- /// Flag type for a trait that is multiply undefined.
- struct multiply_defined {};
-
-
-
- // Utility meta-function: from a category (meta) and a type, get the super category.
-
- namespace internal
- {
-
- template < template <class> class Category, typename T,
- typename Super_Category >
- struct helper_super_category_;
-
- template < template <class> class Category, typename T,
- template <class> class Super_Category >
- struct helper_super_category_< Category, T,
- Super_Category<void> >
- {
- typedef Super_Category<void> ret; // One super category: keep it.
- };
-
- template < template <class> class Category, typename T >
- struct helper_super_category_< Category, T,
- void* > // Meaning: several super categories exist, depending on T.
- {
- typedef typename mln::category< T >::super ret; // Specific call depending on T.
- };
-
-
- template < template <class> class Category, typename T >
- struct super_category_ // Entry.
- {
- typedef typename helper_super_category_< Category, T,
- typename Category<void>::super >::ret ret;
- };
-
- } // end of namespace mln::trait::internal
-
-
-
- // Unary case.
-
-
- template < template <class> class Name,
- typename T >
- struct set_precise_unary_
- {
- typedef undefined ret;
- };
-
-
- template < template <class> class Name,
- template <class> class Category_T, typename T >
- struct set_unary_
- {
- typedef undefined ret;
- };
-
- template < template <class> class Name,
- typename T >
- struct set_unary_< Name, Unknown, T > // Blocker; top of inheritance.
- {
- typedef not_found ret;
- };
-
-
-
- namespace internal
- {
-
- // Fwd decls.
- template < template <class> class Name,
- template <class> class Category_T, typename T >
- struct get_unary_;
-
-
- template < typename user_ret, /* != not_found and != undefined */
- template <class> class Name,
- template <class> class Category_T, typename T >
- struct helper_get_unary_
- {
- typedef user_ret ret; // The user has defined 'ret' so we return it.
- };
-
-
- template < template <class> class Name,
- template <class> class Category_T, typename T >
- struct helper_get_unary_< /* user_ret == */ not_found,
- Name, Category_T, T >
- {
- typedef not_found ret; // End of search due to a blocker; 'ret' is not found.
- };
-
-
- template < template <class> class Name, typename Super_Category, typename T >
- struct helper_get_unary_rec_;
-
- template < template <class> class Name, template <class> class Super_Category_T, typename T >
- struct helper_get_unary_rec_< Name, Super_Category_T<void>, T > {
- typedef typename get_unary_<Name, Super_Category_T, T>::ret ret;
- };
-
- template < template <class> class Name,
- template <class> class Category_T, typename T >
- struct helper_get_unary_< /* user_ret == */ undefined,
- Name, Category_T, T >
- {
- typedef typename internal::super_category_< Category_T, T >::ret super;
- typedef typename helper_get_unary_rec_<Name, super, T>::ret ret; // No user ret definition => Recursion.
- };
-
-
- template < template <class> class Name,
- template <class> class Category_T, typename T >
- struct get_unary_
- {
- typedef typename mln::trait::set_unary_<Name, Category_T, T>::ret user_ret; // First get 'user_ret'
- typedef helper_get_unary_<user_ret, Name, Category_T, T> helper; // Set the helper to make a decision.
- typedef mlc_ret(helper) ret; // Return.
- };
-
-
- template < typename precise_ret,
- template <class> class Name,
- template <class> class Category_T, typename T >
- struct helper_choose_unary_wrt_ /* precise_ret != undefined */
- {
- typedef precise_ret ret; // -> A precise ret has been defined so it is it.
- };
-
- template < template <class> class Name,
- template <class> class Category_T, typename T >
- struct helper_choose_unary_wrt_< /* precise_ret == */ undefined,
- Name, Category_T, T >
- {
- typedef typename get_unary_<Name, Category_T, T>::ret ret; // -> Go up into the category inheritance
- // to fetch a ret from 'set_unary_'s.
- };
-
- template < template <class> class Name,
- template <class> class Category_T, typename T >
- struct helper_choose_unary_
- {
- typedef typename set_precise_unary_<Name, T>::ret precise_ret;
- typedef helper_choose_unary_wrt_< precise_ret, /* undefined or not (?) */
- Name, Category_T, T> helper;
- typedef mlc_ret(helper) ret;
- };
-
-
- template < template <class> class Name,
- typename Category_T_void, typename T >
- struct helper_solve_unary_; // This helper changes the category plain type into the category meta type.
-
- template < template <class> class Name,
- template <class> class Category_T, typename void_T, typename T >
- struct helper_solve_unary_< Name, Category_T<void_T>, T >
- :
- helper_choose_unary_< Name, Category_T, T > // FIXME: typedef!
- {
- // FIXME: Check that void_T is 'void' or 'void*'.
- };
-
- // FIXME: Remove below.
-
-// template < template <class> class Name,
-// template <class> class Category_T, typename T >
-// struct helper_solve_unary_< Name, Category_T<void*>, T >
-// :
-// helper_choose_unary_< Name, Category_T, T > // FIXME: typedef!
-// {};
-
- } // end of namespace mln::trait::internal
-
-
- // FIXME: Postfix solve_unary with a '-'(?)
- template < template <class> class Name,
- typename T >
- struct solve_unary : internal::helper_solve_unary_< Name,
- typename mln::category<T>::ret, T > // FIXME: typedef!
- {
- };
-
-
-
- // Binary case.
-
-
- template < template <class, class> class Name,
- typename L,
- typename R >
- struct set_precise_binary_
- {
- typedef undefined ret;
- };
-
- template < template <class, class> class Name,
- template <class> class Category_L, typename L,
- template <class> class Category_R, typename R >
- struct set_binary_
- {
- typedef undefined ret;
- };
-
-
- template < template <class, class> class Name,
- typename L,
- template <class> class Category_R, typename R >
- struct set_binary_< Name, Unknown, L, Category_R, R > // Left blocker.
- {
- typedef not_found ret;
- };
-
- template < template <class, class> class Name,
- template <class> class Category_L, typename L,
- typename R >
- struct set_binary_< Name, Category_L, L, Unknown, R > // Right blocker.
- {
- typedef not_found ret;
- };
-
- template < template <class, class> class Name,
- typename L,
- typename R >
- struct set_binary_< Name, Unknown, L, Unknown, R > // Blocker.
- {
- typedef not_found ret;
- };
-
-
-
namespace internal
{
@@ -551,4 +306,4 @@
} // end of namespace mln
-#endif // ! MLN_TRAIT_SOLVE_HH
+#endif // ! MLN_TRAIT_SOLVE_BINARY_HH
Index: mln/trait/solve_unary.hh
--- mln/trait/solve_unary.hh (revision 2025)
+++ mln/trait/solve_unary.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006 EPITA Research and Development Laboratory
+// Copyright (C) 2006, 2008 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,11 +25,11 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_TRAIT_SOLVE_HH
-# define MLN_TRAIT_SOLVE_HH
+#ifndef MLN_TRAIT_SOLVE_UNARY_HH
+# define MLN_TRAIT_SOLVE_UNARY_HH
/*!
- * \file mln/trait/solve.hh
+ * \file mln/trait/solve_unary.hh
*
* \brief FIXME
*
@@ -48,13 +48,6 @@
# endif // ! MLN_DEBUG_TRAITS
-# 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
-
-
namespace mln
{
@@ -62,80 +55,6 @@
namespace trait
{
- /// Flag type for a not found trait.
- struct not_found {};
-
- /// Flag type for an undefined trait.
- struct undefined {};
-
- /// Flag type for a trait that is multiply undefined.
- struct multiply_defined {};
-
-
-
- // Utility meta-function: from a category (meta) and a type, get the super category.
-
- namespace internal
- {
-
- template < template <class> class Category, typename T,
- typename Super_Category >
- struct helper_super_category_;
-
- template < template <class> class Category, typename T,
- template <class> class Super_Category >
- struct helper_super_category_< Category, T,
- Super_Category<void> >
- {
- typedef Super_Category<void> ret; // One super category: keep it.
- };
-
- template < template <class> class Category, typename T >
- struct helper_super_category_< Category, T,
- void* > // Meaning: several super categories exist, depending on T.
- {
- typedef typename mln::category< T >::super ret; // Specific call depending on T.
- };
-
-
- template < template <class> class Category, typename T >
- struct super_category_ // Entry.
- {
- typedef typename helper_super_category_< Category, T,
- typename Category<void>::super >::ret ret;
- };
-
- } // end of namespace mln::trait::internal
-
-
-
- // Unary case.
-
-
- template < template <class> class Name,
- typename T >
- struct set_precise_unary_
- {
- typedef undefined ret;
- };
-
-
- template < template <class> class Name,
- template <class> class Category_T, typename T >
- struct set_unary_
- {
- typedef undefined ret;
- };
-
- template < template <class> class Name,
- typename T >
- struct set_unary_< Name, Unknown, T > // Blocker; top of inheritance.
- {
- typedef not_found ret;
- };
-
-
-
namespace internal
{
@@ -252,303 +171,9 @@
{
};
-
-
- // Binary case.
-
-
- template < template <class, class> class Name,
- typename L,
- typename R >
- struct set_precise_binary_
- {
- typedef undefined ret;
- };
-
- template < template <class, class> class Name,
- template <class> class Category_L, typename L,
- template <class> class Category_R, typename R >
- struct set_binary_
- {
- typedef undefined ret;
- };
-
-
- template < template <class, class> class Name,
- typename L,
- template <class> class Category_R, typename R >
- struct set_binary_< Name, Unknown, L, Category_R, R > // Left blocker.
- {
- typedef not_found ret;
- };
-
- template < template <class, class> class Name,
- template <class> class Category_L, typename L,
- typename R >
- struct set_binary_< Name, Category_L, L, Unknown, R > // Right blocker.
- {
- typedef not_found ret;
- };
-
- template < template <class, class> class Name,
- typename L,
- typename R >
- struct set_binary_< Name, Unknown, L, Unknown, R > // Blocker.
- {
- typedef not_found ret;
- };
-
-
-
- namespace internal
- {
-
- // triplet_ret_
-
- template < unsigned i_L_, unsigned i_R_, typename ret_ >
- struct triplet_
- {
- typedef ret_ ret;
- };
-
-
- // merge_triplets_
-
- template < typename L_trp, typename R_trp >
- struct merge_triplets_;
-
- template < unsigned L_i_L, unsigned L_i_R, typename L_ret,
- unsigned R_i_L, unsigned R_i_R, typename R_ret >
- struct merge_triplets_< triplet_<L_i_L, L_i_R, L_ret>,
- triplet_<R_i_L, R_i_R, R_ret> >
- {
- typedef metal::bool_<(L_i_L <= R_i_L && L_i_R <= R_i_R)> take_L;
- typedef metal::bool_<(R_i_L <= L_i_L && R_i_R <= L_i_R)> take_R;
- typedef metal::or_<take_L, take_R> ok;
- typedef typename metal::if_< metal::and_<ok, take_L>,
- triplet_<L_i_L, L_i_R, L_ret>,
- typename metal::if_< metal::and_<ok, take_R>,
- triplet_<R_i_L, R_i_R, R_ret>,
- triplet_<0,0, not_found> >::ret >::ret ret;
- };
-
- template < unsigned i_L, unsigned i_R, typename LR_ret >
- struct merge_triplets_< triplet_<i_L, i_R, LR_ret>,
- triplet_<i_L, i_R, LR_ret> >
- {
- typedef triplet_<i_L, i_R, LR_ret> ret;
- };
-
-
- template < unsigned L_i_L, unsigned L_i_R, unsigned L_i_max,
- unsigned R_i_L, unsigned R_i_R, unsigned R_i_max >
- // L_i_max and R_i_max differ
- struct helper_merge_triplets_same_ret_
- {
- // The winning couple between L_* and R_* is the one which
- // maximum index is the smallest; for instance, with:
- // left branch giving L_i_L = 5 and L_i_R = 1 so L_i_max = 5
- // right branch giving L_i_L = 3 and L_i_R = 4 so R_i_max = 4
- // the right branch wins.
- enum { i_L = (L_i_max < R_i_max ? L_i_L : R_i_L),
- i_R = (L_i_max < R_i_max ? L_i_R : R_i_R) };
- };
-
- template < unsigned L_i_L, unsigned L_i_R, unsigned i_max,
- unsigned R_i_L, unsigned R_i_R >
- // L_i_max is equal to R_i_max
- struct helper_merge_triplets_same_ret_< L_i_L, L_i_R, i_max,
- R_i_L, R_i_R, i_max >
- {
- // The winning couple is the one with the minimum index.
- enum { L_i_min = (L_i_L < L_i_R ? L_i_L : L_i_R),
- R_i_min = (R_i_L < R_i_R ? R_i_L : R_i_R),
- i_L = (L_i_min < R_i_min ? L_i_L : R_i_L),
- i_R = (L_i_min < R_i_min ? L_i_R : R_i_R) };
- };
-
-
- template < unsigned L_i_L, unsigned L_i_R, typename LR_ret,
- unsigned R_i_L, unsigned R_i_R >
- struct merge_triplets_< triplet_<L_i_L, L_i_R, LR_ret>,
- triplet_<R_i_L, R_i_R, LR_ret> >
- {
- typedef helper_merge_triplets_same_ret_< L_i_L, L_i_R, (L_i_L > L_i_R ? L_i_L : L_i_R),
- R_i_L, R_i_R, (R_i_L > R_i_R ? R_i_L : R_i_R) > helper;
- typedef triplet_<helper::i_L, helper::i_R, LR_ret> ret;
- };
-
- template < unsigned L_i_L, unsigned L_i_R, typename L_ret >
- struct merge_triplets_< triplet_<L_i_L, L_i_R, L_ret>,
- triplet_< 0, 0, not_found> >
- {
- typedef triplet_<L_i_L, L_i_R, L_ret> ret;
- };
-
- template < unsigned R_i_L, unsigned R_i_R, typename R_ret >
- struct merge_triplets_< triplet_< 0, 0, not_found>,
- triplet_<R_i_L, R_i_R, R_ret> >
- {
- typedef triplet_<R_i_L, R_i_R, R_ret> ret;
- };
-
- template <> // To disambiguate.
- struct merge_triplets_< triplet_<0, 0, not_found>,
- triplet_<0, 0, not_found> >
- {
- typedef triplet_<0u,0u, not_found> ret;
- };
-
-
-
- // Fwd decl.
- template < template <class, class> class Name,
- unsigned i_L, template <class> class Category_L, typename L,
- unsigned i_R, template <class> class Category_R, typename R >
- struct get_binary_;
-
-
- template < typename user_ret, /* != not_found and != undefined */
- template <class, class> class Name,
- unsigned i_L, template <class> class Category_L, typename L,
- unsigned i_R, template <class> class Category_R, typename R >
- struct helper_get_binary_
- {
- typedef triplet_< i_L, i_R, user_ret > ret; // The user has defined 'ret' so we return it.
- };
-
- template < template <class, class> class Name,
- unsigned i_L, template <class> class Category_L, typename L,
- unsigned i_R, template <class> class Category_R, typename R >
- struct helper_get_binary_< /* user_ret == */ not_found,
- Name, i_L, Category_L, L, i_R, Category_R, R >
- {
- typedef triplet_< 0, 0, not_found > ret; // End of search due to a blocker; 'ret' is not found.
- };
-
-
- template < template <class, class> class Name, // Nota bene: Seq means "super or equal".
- unsigned i_L, typename Seq_Category_L, typename L,
- unsigned i_R, typename Seq_Category_R, typename R >
- struct helper_get_binary_rec_;
-
- template < template <class, class> class Name,
- unsigned i_L, template <class> class Seq_Category_L, typename L,
- unsigned i_R, template <class> class Seq_Category_R, typename R >
- struct helper_get_binary_rec_< Name, i_L, Seq_Category_L<void>, L, i_R, Seq_Category_R<void>, R >
- {
- typedef typename get_binary_<Name, i_L, Seq_Category_L, L, i_R, Seq_Category_R, R>::ret ret;
- };
-
-
- template < template <class, class> class Name,
- unsigned i_L, template <class> class Category_L, typename L,
- unsigned i_R, template <class> class Category_R, typename R >
- struct helper_get_binary_< /* user_ret == */ undefined,
- Name, i_L,Category_L, L, i_R,Category_R, R >
- {
- // No user definition for 'ret' so treillis construction in a static recursive way.
-
- // FIXME: We *do* need to handle this search with a priority!
- // FIXME: for a result can be found in both branches...
-
- typedef typename super_category_< Category_L, L >::ret Super_Category_L;
- typedef typename super_category_< Category_R, R >::ret Super_Category_R;
-
- typedef helper_get_binary_rec_< Name,
- i_L + 1, Super_Category_L, L,
- i_R, Category_R<void>, R > L_branch;
- typedef mlc_ret(L_branch) L_trp;
-
- typedef helper_get_binary_rec_< Name,
- i_L, Category_L<void>, L,
- i_R + 1, Super_Category_R, R > R_branch;
- typedef mlc_ret(R_branch) R_trp;
-
- typedef typename merge_triplets_< L_trp, R_trp >::ret ret;
- };
-
-
- template < template <class, class> class Name,
- unsigned i_L, template <class> class Category_L, typename L,
- unsigned i_R, template <class> class Category_R, typename R >
- struct get_binary_
- {
- typedef typename mln::trait::set_binary_<Name, Category_L,L,
- Category_R,R>::ret user_ret; // First get 'user_ret'
- typedef helper_get_binary_<user_ret, Name, i_L,Category_L,L,
- i_R,Category_R,R> helper; // Set the helper to make a decision.
- typedef mlc_ret(helper) ret; // Return a triplet.
- };
-
-
- template < typename precise_ret,
- template <class, class> class Name,
- template <class> class Category_L, typename L,
- template <class> class Category_R, typename R >
- struct helper_choose_binary_wrt_ /* precise_ret != undefined */
- {
- typedef precise_ret ret; // -> A precise ret has been defined so it is it.
- };
-
- template < template <class, class> class Name,
- template <class> class Category_L, typename L,
- template <class> class Category_R, typename R >
- struct helper_choose_binary_wrt_< /* precise_ret == */ undefined,
- Name, Category_L, L, Category_R, R >
- {
- typedef typename get_binary_< Name,
- 0, Category_L, L,
- 0, Category_R, R >::ret triplet; // Browse upwards the category inheritance
- typedef mlc_ret(triplet) ret; // to fetch ret from 'get_binary_'s.
- };
-
-
- template < template <class, class> class Name,
- template <class> class Category_L, typename L,
- template <class> class Category_R, typename R >
- struct helper_choose_binary_
- {
- typedef typename set_precise_binary_<Name, L, R>::ret precise_ret; /* undefined or not (?) */
- typedef helper_choose_binary_wrt_<precise_ret, Name, Category_L,L, Category_R,R> helper;
- typedef mlc_ret(helper) ret;
- };
-
-
- template < template <class, class> class Name,
- typename Category_L_void, typename L,
- typename Category_R_void, typename R >
- struct helper_solve_binary_;
-
- template < template <class, class> class Name,
- template <class> class Category_L, typename void_L, typename L,
- template <class> class Category_R, typename void_R, typename R >
- struct helper_solve_binary_< Name,
- Category_L<void_L>, L,
- Category_R<void_R>, R > : helper_choose_binary_< Name,
- Category_L, L,
- Category_R, R >
- {
- // FIXME: Check that void_L and void_R are 'void' or 'void*'.
- };
-
- } // end of namespace mln::trait::internal
-
-
- // FIXME: Postfix solve_binary with a '-'(?)
- template < template <class, class> class Name,
- typename L,
- typename R >
- struct solve_binary : internal::helper_solve_binary_< Name,
- typename mln::category<L>::ret, L,
- typename mln::category<R>::ret, R >
- {
- };
-
-
} // end of namespace mln::trait
} // end of namespace mln
-#endif // ! MLN_TRAIT_SOLVE_HH
+#endif // ! MLN_TRAIT_SOLVE_UNARY_HH
Index: mln/core/concept/site_set.hh
--- mln/core/concept/site_set.hh (revision 2025)
+++ mln/core/concept/site_set.hh (working copy)
@@ -229,7 +229,7 @@
template <typename Sl, typename Sr>
inline
- util::yes operator<(const Site_Set<Sl>& lhs_, const Site_Set<Sr>& rhs_)
+ util::yes operator<(const Site_Set<Sl>&, const Site_Set<Sr>&)
{
// // FIXME: Same grid!
// const Sl& lhs = exact(lhs_);
1
0
cleanup-2008 2025: Add a default ordering (util::less); update (d)points and vec.
by Thierry Geraud 16 Jun '08
by Thierry Geraud 16 Jun '08
16 Jun '08
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add a default ordering (util::less); update (d)points and vec.
* mln/core/point.hh (todo): New in doc.
(to_vec): New; was missing.
(less_than): New specialization.
* mln/core/dpoint.hh (to_vec): Avoid copy at return.
(less_than): New specialization.
* mln/core/box.hh: Rely on util::less.
(is_valid): New.
(contract): Add pre- and post-conditions.
* mln/core/concept/point_site.hh (operator<): Remove.
* mln/algebra/vec.hh (less_than): New.
* mln/util/set.hh: Rely on util::less.
* mln/util/less.hh: New.
* mln/util/less_than.hh: New.
algebra/vec.hh | 48 +++++++++++++++++++++++++-
core/box.hh | 30 +++++++++++++++-
core/concept/point_site.hh | 42 -----------------------
core/dpoint.hh | 51 ++++++++++++++++++++++++++--
core/point.hh | 66 ++++++++++++++++++++++++++++++++++++
util/less.hh | 80 ++++++++++++++++++++++++++++++++++++++++++++
util/less_than.hh | 81 +++++++++++++++++++++++++++++++++++++++++++++
util/set.hh | 8 +++-
8 files changed, 356 insertions(+), 50 deletions(-)
Index: mln/core/point.hh
--- mln/core/point.hh (revision 2024)
+++ mln/core/point.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -31,6 +31,8 @@
/*! \file mln/core/point.hh
*
* \brief Definition of the generic point class mln::point_.
+ *
+ * \todo Try to generalize less_than with Ml and Mr.
*/
# include <mln/core/concept/point.hh>
@@ -47,6 +49,7 @@
{
/// \{ Fwd decls.
+ template <typename M, typename C> struct point_;
template <typename M, typename C> struct dpoint_;
namespace literal {
struct zero_t;
@@ -154,6 +157,9 @@
operator typename internal::point_to_<M, C>::metal_vec () const;
operator algebra::vec<M::dim, float> () const;
+ /// Explicit conversion towards mln::algebra::vec.
+ const algebra::vec<M::dim, C>& to_vec() const;
+
/// Transform to point in homogene coordinate system.
h_vec<M::dim, C> to_h_vec() const;
@@ -162,6 +168,38 @@
};
+ namespace util
+ {
+
+ /*! \brief Ordering "less than" comparison between a couple of
+ * points.
+ *
+ * The ordering is based on a lexicographical ordering over
+ * coordinates.
+ *
+ * Both points have to be defined on the same topology.
+ *
+ * \warning In the general case this ordering relationship is \em
+ * not bound to the way of browsing a domain with a forward point
+ * iterator.
+ */
+ template <typename M, typename Cl, typename Cr>
+ struct less_than< point_<M,Cl>,
+ point_<M,Cr> >
+ {
+ /*! \brief Comparison between a couple of points \a lhs and \a
+ * rhs.
+ *
+ * \return True if \p lhs is before \p rhs in the sense of the
+ * coordinates lexicographic comparison, otherwise false.
+ */
+ bool operator()(const point_<M,Cl>& lhs,
+ const point_<M,Cr>& rhs) const;
+ };
+
+ } // end of namespace mln::util
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename M, typename C>
@@ -327,6 +365,14 @@
template <typename M, typename C>
inline
+ const algebra::vec<M::dim, C>&
+ point_<M,C>::to_vec() const
+ {
+ return coord_;
+ }
+
+ template <typename M, typename C>
+ inline
h_vec<M::dim, C> point_<M,C>::to_h_vec() const
{
h_vec<M::dim, C> tmp;
@@ -336,6 +382,24 @@
return tmp;
}
+
+ namespace util
+ {
+
+ template <typename M, typename Cl, typename Cr>
+ bool
+ less_than< point_<M,Cl>,
+ point_<M,Cr> >::operator()(const point_<M,Cl>& lhs,
+ const point_<M,Cr>& rhs) const
+ {
+ enum { n = M::dim };
+ typedef less_than< algebra::vec<n,Cl>, algebra::vec<n,Cr> > less_t;
+ static const less_t op = less_t();
+ return op(lhs.to_vec(), rhs.to_vec());
+ }
+
+ } // end of namespace mln::util
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/dpoint.hh
--- mln/core/dpoint.hh (revision 2024)
+++ mln/core/dpoint.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -123,13 +123,41 @@
operator algebra::vec<M::dim, Q>() const;
/// Explicit conversion.
- algebra::vec<M::dim, C> to_vec() const;
+ const algebra::vec<M::dim, C>& to_vec() const;
protected:
algebra::vec<M::dim, C> coord_;
};
+ namespace util
+ {
+
+ /*! \brief Ordering "less than" comparison between a couple of
+ * delta-points.
+ *
+ * The ordering is based on a lexicographical ordering over
+ * coordinates.
+ *
+ * Both delta-points have to be defined on the same topology.
+ */
+ template <typename M, typename Cl, typename Cr>
+ struct less_than< dpoint_<M,Cl>,
+ dpoint_<M,Cr> >
+ {
+ /*! \brief Comparison between a couple of delta-points \a lhs
+ * and \a rhs.
+ *
+ * \return True if \p lhs is before \p rhs in the sense of the
+ * coordinates lexicographic comparison, otherwise false.
+ */
+ bool operator()(const dpoint_<M,Cl>& lhs,
+ const dpoint_<M,Cr>& rhs) const;
+ };
+
+ } // end of namespace mln::util
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename M, typename C>
@@ -244,12 +272,29 @@
template <typename M, typename C>
inline
- algebra::vec<M::dim, C>
+ const algebra::vec<M::dim, C>&
dpoint_<M,C>::to_vec() const
{
return coord_;
}
+ namespace util
+ {
+
+ template <typename M, typename Cl, typename Cr>
+ bool
+ less_than< dpoint_<M,Cl>,
+ dpoint_<M,Cr> >::operator()(const dpoint_<M,Cl>& lhs,
+ const dpoint_<M,Cr>& rhs) const
+ {
+ enum { n = M::dim };
+ typedef less_than< algebra::vec<n,Cl>, algebra::vec<n,Cr> > less_t;
+ static const less_t op = less_t();
+ return op(lhs.to_vec(), rhs.to_vec());
+ }
+
+ } // end of namespace mln::util
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/box.hh
--- mln/core/box.hh (revision 2024)
+++ mln/core/box.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -37,6 +37,7 @@
# include <mln/core/internal/box_impl.hh>
# include <mln/core/point.hh>
# include <mln/literal/origin.hh>
+# include <mln/util/less.hh>
namespace mln
@@ -124,7 +125,12 @@
/// Give a larger box.
box_<P> to_larger(unsigned b) const;
+ /// Test that the box owns valid data, i.e., pmin is 'less-than'
+ /// pmax.
+ bool is_valid() const;
+
protected:
+
P pmin_, pmax_;
};
@@ -146,9 +152,20 @@
template <typename P>
inline
+ bool
+ box_<P>::is_valid() const
+ {
+ typedef util::less<P> less_t;
+ static const less_t op = less_t();
+ return op(pmin_, pmax_);
+ }
+
+ template <typename P>
+ inline
P
box_<P>::pmin() const
{
+ mln_precondition(is_valid());
return pmin_;
}
@@ -165,6 +182,7 @@
P
box_<P>::pmax() const
{
+ mln_precondition(is_valid());
return pmax_;
}
@@ -188,7 +206,7 @@
: pmin_(pmin),
pmax_(pmax)
{
-
+ mln_precondition(is_valid());
}
template <typename P>
@@ -207,6 +225,7 @@
metal::bool_<(dim == 2)>::check();
pmin_ = literal::origin;
pmax_ = P(nrows - 1, ncols - 1);
+ mln_postcondition(is_valid());
}
template <typename P>
@@ -216,6 +235,7 @@
metal::bool_<(dim == 3)>::check();
pmin_ = literal::origin;
pmax_ = P(nslis - 1, nrows - 1, ncols - 1);
+ mln_postcondition(is_valid());
}
template <typename P>
@@ -223,6 +243,7 @@
bool
box_<P>::has(const P& p) const
{
+ mln_precondition(is_valid());
for (unsigned i = 0; i < P::dim; ++i)
if (p[i] < pmin_[i] || p[i] > pmax_[i])
return false;
@@ -234,11 +255,13 @@
void
box_<P>::enlarge(unsigned b)
{
+ mln_precondition(is_valid());
for (unsigned i = 0; i < P::dim; ++i)
{
pmin_[i] -= b;
pmax_[i] += b;
}
+ mln_postcondition(is_valid());
}
@@ -247,6 +270,7 @@
box_<P>
box_<P>::to_larger(unsigned b) const
{
+ mln_precondition(is_valid());
box_<P> tmp(*this);
for (unsigned i = 0; i < P::dim; ++i)
@@ -254,6 +278,7 @@
tmp.pmin_[i] -= b;
tmp.pmax_[i] += b;
}
+ mln_postcondition(tmp.is_valid());
return tmp;
}
@@ -261,6 +286,7 @@
inline
std::ostream& operator<<(std::ostream& ostr, const box_<P>& b)
{
+ mln_precondition(b.is_valid());
return ostr << "[" << b.pmin() << ".." << b.pmax() << ']';
}
Index: mln/core/concept/point_site.hh
--- mln/core/concept/point_site.hh (revision 2024)
+++ mln/core/concept/point_site.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -145,30 +145,6 @@
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.
*
@@ -281,22 +257,6 @@
template <typename L, typename R>
inline
- 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>
- inline
mln_dpoint(L) // FIXME: promote!
operator-(const Point_Site<L>& lhs_, const Point_Site<R>& rhs_)
{
Index: mln/algebra/vec.hh
--- mln/algebra/vec.hh (revision 2024)
+++ mln/algebra/vec.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006 EPITA Research and Development Laboratory
+// Copyright (C) 2006, 2008 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -42,6 +42,7 @@
# include <mln/trait/all.hh>
# include <mln/trait/value_.hh>
# include <mln/fun/i2v/all_to.hh>
+# include <mln/util/less_than.hh>
# include <mln/debug/format.hh>
# include <mln/value/ops.hh>
@@ -63,6 +64,19 @@
template <unsigned d, typename C> struct h_vec;
+ namespace util
+ {
+
+ template <unsigned n, typename Tl, typename Tr>
+ struct less_than< algebra::vec<n,Tl>,
+ algebra::vec<n,Tr> >
+ {
+ bool operator()(const algebra::vec<n,Tl>& lhs,
+ const algebra::vec<n,Tr>& rhs) const;
+ };
+
+ } // end of namespace mln::util
+
namespace trait
{
@@ -326,9 +340,16 @@
vec<3, mln_trait_op_times(T,U)> // FIXME: Sum of product...
vprod(const vec<3, T>& lhs, const vec<3, U>& rhs);
+ } // end of namespace mln::algebra
+
+
+
# ifndef MLN_INCLUDE_ONLY
+ namespace algebra
+ {
+
template <unsigned n, typename T>
inline
vec<n,T>::vec()
@@ -561,10 +582,33 @@
return tmp;
}
-# endif // MLN_INCLUDE_ONLY
} // end of namespace mln::algebra
+
+ namespace util
+ {
+
+ template <unsigned n, typename Tl, typename Tr>
+ bool
+ less_than< algebra::vec<n,Tl>,
+ algebra::vec<n,Tr> >::operator()(const algebra::vec<n,Tl>& lhs,
+ const algebra::vec<n,Tr>& rhs) const
+ {
+ for (unsigned i = 0; i < n; ++i)
+ {
+ if (lhs[i] == rhs[i])
+ continue;
+ return lhs[i] < rhs[i];
+ }
+ return false;
+ }
+
+ } // end of namespace mln::util
+
+
+# endif // MLN_INCLUDE_ONLY
+
} // end of namespace mln
Index: mln/util/set.hh
--- mln/util/set.hh (revision 2024)
+++ mln/util/set.hh (working copy)
@@ -42,6 +42,7 @@
# include <iostream>
# include <mln/core/contract.hh>
+# include <mln/util/less.hh>
namespace mln
@@ -66,7 +67,12 @@
* The parameter \c T is the element type, which shall not be
* const-qualified.
*
+ * The unicity of set elements is handled by the mln::util::less
+ * function-object.
+ *
* \todo Add a remove method.
+ *
+ * \see mln::util::less
*/
template <typename T>
class set
@@ -174,7 +180,7 @@
*
* This structure is always up-to-date w.r.t. the set contents.
*/
- mutable std::set<T> s_;
+ mutable std::set< T, mln::util::less<T> > s_;
/*! \brief Freeze the contents of the set (update \a v_ from \a
Index: mln/util/less.hh
--- mln/util/less.hh (revision 0)
+++ mln/util/less.hh (revision 0)
@@ -0,0 +1,80 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_UTIL_LESS_HH
+# define MLN_UTIL_LESS_HH
+
+/*! \file mln/util/less.hh
+ *
+ * \brief Definition of a "less" function-object with one type (T).
+ *
+ * \todo Use mln_trait_op_less as return type (?)
+ */
+
+# include <mln/util/less_than.hh>
+
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ /*! \brief Function-object to define a less-than comparison
+ * between a couple of objects with the same type \p T.
+ *
+ * This implementation relies on mln::util::less_than so prefer to
+ * overload mln::util::less_than (because it is more general).
+ *
+ * \see mln::util::less_than
+ */
+ template <typename T>
+ struct less
+ {
+ bool operator()(const T& lhs, const T& rhs) const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ inline
+ bool
+ less<T>::operator()(const T& lhs, const T& rhs) const
+ {
+ static const less_than<T,T> lt_ = less_than<T,T>();
+ return lt_(lhs, rhs);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::util
+
+} // end of namespace mln
+
+
+#endif // ! MLN_UTIL_LESS_HH
Index: mln/util/less_than.hh
--- mln/util/less_than.hh (revision 0)
+++ mln/util/less_than.hh (revision 0)
@@ -0,0 +1,81 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_UTIL_LESS_THAN_HH
+# define MLN_UTIL_LESS_THAN_HH
+
+/*! \file mln/util/less_than.hh
+ *
+ * \brief Definition of a "less-than" function-object with a couple of
+ * types (L and R).
+ *
+ * \todo Use mln_trait_op_less as return type (?)
+ */
+
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ /*! \brief Function-object to define a less-than comparison
+ * between a couple of objects respectively with types \p L and
+ * \p R.
+ *
+ * This is a default implementation that relies on 'operator<'.
+ * It shall be overloaded for types that do not have such an
+ * operator when those types are involved with an ordered
+ * container.
+ *
+ * \see mln::util::less_than
+ */
+ template <typename L, typename R>
+ struct less_than
+ {
+ bool operator()(const L& lhs, const R& rhs) const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename L, typename R>
+ inline
+ bool
+ less_than<L,R>::operator()(const L& lhs, const R& rhs) const
+ {
+ return lhs < rhs;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::util
+
+} // end of namespace mln
+
+
+#endif // ! MLN_UTIL_LESS_THAN_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Remove (empty) rapports/.
* rapports/duhamel/, rapports/garrigues/, rapports/nivault/:
Remove these empty directories.
* rapports/: Likewise.
0 files changed
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
===================================================================
--- ChangeLog (revision 2022)
+++ ChangeLog (revision 2023)
@@ -7,7 +7,7 @@
Typos and aesthetic changes.
(color2uchar, write_verts_asc, write_faces_asc_colored)
(write_off_colored): Move these I/O
- routines...
+ routines...
* levillain/statues/io.hh: ...here.
* levillain/statues/test: New test.
* levillain/statues/Makefile (mesh-segm.o): Depend on io.hh
@@ -40,11 +40,11 @@
* jardonnet/test/img/c10.pbm,
* jardonnet/test/img/c11.pbm: New test images.
-<2008>-<06>-<09> aroune aroumougame <aroune.aroumougame(a)gmail.com>
+2008-06-09 Aroune Aroumougame <aroune.aroumougame(a)gmail.com>
Thinning test files.
* skeleton/test.cc: New.
- * skeleton/test.pbm: New.
+ * skeleton/test.pbm: New.
* skeleton/test.pgm: New.
* skeleton/test1.pbm: New.
* skeleton/test1.pgm: New.
@@ -87,7 +87,7 @@
* beguin/fusion_graph.hh, beguin/irm.cc: Do it.
-<2008>-<05>-<30> Aroune Aroumougame <aroune.aroumougame(a)gmail.com>
+2008-05-30 Aroune Aroumougame <aroune.aroumougame(a)gmail.com>
Test files.
* makefile1: Remove. old file
@@ -396,7 +396,7 @@
Update final_qk.
- Final_qk didn't use correct points.
+ Final_qk didn't use correct points.
* jardonnet/test/icp.cc: .
* jardonnet/registration/final_qk.hh: .
@@ -666,7 +666,7 @@
New red getter.
* conv/getred.hh: New red getter for all color spaces.
* conv/tored.hh: New function that takes a color as argument
- and return red part in rgb.
+ and return red part in rgb.
2008-05-07 Nicolas Ballas <ballas(a)lrde.epita.fr>
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Start to clean up levillain/statues/.
* levillain/statues/mesh-segm.cc (main): Process command line
arguments.
Typos and aesthetic changes.
(color2uchar, write_verts_asc, write_faces_asc_colored)
(write_off_colored): Move these I/O
routines...
* levillain/statues/io.hh: ...here.
* levillain/statues/test: New test.
* levillain/statues/Makefile (mesh-segm.o): Depend on io.hh
(check): Depend on test.
Run `test' instead of `mesh-segm'.
Makefile | 5 +-
io.hh | 115 ++++++++++++++++++++++++++++++++++++++++++++++++
mesh-segm.cc | 139 +++++++++++++----------------------------------------------
test | 9 +++
4 files changed, 159 insertions(+), 109 deletions(-)
Index: levillain/statues/test
--- levillain/statues/test (revision 0)
+++ levillain/statues/test (revision 0)
@@ -0,0 +1,9 @@
+#! /bin/sh
+
+set -ex
+
+mesh_dir=../../../mesh
+
+time ./mesh-segm $mesh_dir/socket.off 25 socket-segm.off
+time ./mesh-segm $mesh_dir/teapot.off 50 teapot-segm.off
+time ./mesh-segm $mesh_dir/bunny-holefilled.off 500 bunny-holefilled-segm.off
Property changes on: levillain/statues/test
___________________________________________________________________
Name: svn:executable
+ *
Index: levillain/statues/io.hh
--- levillain/statues/io.hh (revision 0)
+++ levillain/statues/io.hh (revision 0)
@@ -0,0 +1,115 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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 SANDBOX_LEVILLAIN_IO_HH
+# define SANDBOX_LEVILLAIN_IO_HH
+
+/// \brief I/O routines adapted from TriMesh's ones.
+
+/// Taken from TriMesh_io.cc
+/// \{
+// Convert colors float -> uchar
+inline unsigned char color2uchar(float p)
+{
+ return min(max(int(255.0f * p + 0.5f), 0), 255);
+}
+
+// Write a bunch of vertices to an ASCII file
+inline void write_verts_asc(TriMesh *mesh, FILE *f,
+ const char *before_vert,
+ const char *before_norm,
+ const char *before_color,
+ bool float_color,
+ const char *before_conf,
+ const char *after_line)
+{
+ for (int i = 0; i < mesh->vertices.size(); i++) {
+ fprintf(f, "%s%.7g %.7g %.7g", before_vert,
+ mesh->vertices[i][0],
+ mesh->vertices[i][1],
+ mesh->vertices[i][2]);
+ if (!mesh->normals.empty() && before_norm)
+ fprintf(f, "%s%.7g %.7g %.7g", before_norm,
+ mesh->normals[i][0],
+ mesh->normals[i][1],
+ mesh->normals[i][2]);
+ if (!mesh->colors.empty() && before_color && float_color)
+ fprintf(f, "%s%.7g %.7g %.7g", before_color,
+ mesh->colors[i][0],
+ mesh->colors[i][1],
+ mesh->colors[i][2]);
+ if (!mesh->colors.empty() && before_color && !float_color)
+ fprintf(f, "%s%d %d %d", before_color,
+ color2uchar(mesh->colors[i][0]),
+ color2uchar(mesh->colors[i][1]),
+ color2uchar(mesh->colors[i][2]));
+ if (!mesh->confidences.empty() && before_conf)
+ fprintf(f, "%s%.7g", before_conf, mesh->confidences[i]);
+ fprintf(f, "%s\n", after_line);
+ }
+}
+/// \}
+
+
+/// Taken and adapted from TriMesh_io.cc
+/// \{
+/// Write a bunch of faces to an ASCII file with colors.
+inline void write_faces_asc_colored(TriMesh *mesh,
+ const std::vector<mln::value::rgb8>& colors,
+ FILE *f,
+ const char *before_face,
+ const char *after_line)
+{
+ mesh->need_faces();
+ for (int i = 0; i < mesh->faces.size(); i++)
+ {
+ fprintf(f, "%s%d %d %d %d %d %d%s\n",
+ before_face,
+ mesh->faces[i][0], mesh->faces[i][1], mesh->faces[i][2],
+ int(colors[i].red()),
+ int(colors[i].green()),
+ int(colors[i].blue()),
+ after_line);
+ }
+}
+
+/// Write an off file with colors.
+inline void write_off_colored(TriMesh *mesh,
+ const std::vector<mln::value::rgb8>& colors,
+ FILE *f)
+{
+ fprintf(f, "OFF\n");
+ mesh->need_faces();
+ fprintf(f, "%lu %lu 0\n", (unsigned long) mesh->vertices.size(),
+ (unsigned long) mesh->faces.size());
+ write_verts_asc(mesh, f, "", 0, 0, false, 0, "");
+ write_faces_asc_colored(mesh, colors, f, "3 ", "");
+}
+/// \}
+
+
+#endif // ! SANDBOX_LEVILLAIN_IO_HH
Index: levillain/statues/mesh-segm.cc
--- levillain/statues/mesh-segm.cc (revision 2021)
+++ levillain/statues/mesh-segm.cc (working copy)
@@ -25,6 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
+#include <cstdlib>
#include <cmath>
#include <utility>
@@ -44,117 +45,45 @@
#include <mln/morpho/closing_area.hh>
#include <mln/morpho/meyer_wst.hh>
+#include "io.hh"
+
// Doesn't C++ have a better way to express Pi ?
const float pi = 4 * atanf(1);
-// -------------------------------------------------------------------
-// Taken from TriMesh_io.cc
-// -------------------------------------------------------------------
-// Convert colors float -> uchar
-static unsigned char color2uchar(float p)
-{
- return min(max(int(255.0f * p + 0.5f), 0), 255);
-}
-
-// Write a bunch of vertices to an ASCII file
-static void write_verts_asc(TriMesh *mesh, FILE *f,
- const char *before_vert,
- const char *before_norm,
- const char *before_color,
- bool float_color,
- const char *before_conf,
- const char *after_line)
-{
- for (int i = 0; i < mesh->vertices.size(); i++) {
- fprintf(f, "%s%.7g %.7g %.7g", before_vert,
- mesh->vertices[i][0],
- mesh->vertices[i][1],
- mesh->vertices[i][2]);
- if (!mesh->normals.empty() && before_norm)
- fprintf(f, "%s%.7g %.7g %.7g", before_norm,
- mesh->normals[i][0],
- mesh->normals[i][1],
- mesh->normals[i][2]);
- if (!mesh->colors.empty() && before_color && float_color)
- fprintf(f, "%s%.7g %.7g %.7g", before_color,
- mesh->colors[i][0],
- mesh->colors[i][1],
- mesh->colors[i][2]);
- if (!mesh->colors.empty() && before_color && !float_color)
- fprintf(f, "%s%d %d %d", before_color,
- color2uchar(mesh->colors[i][0]),
- color2uchar(mesh->colors[i][1]),
- color2uchar(mesh->colors[i][2]));
- if (!mesh->confidences.empty() && before_conf)
- fprintf(f, "%s%.7g", before_conf, mesh->confidences[i]);
- fprintf(f, "%s\n", after_line);
- }
-}
-// -------------------------------------------------------------------
-
-
-// -------------------------------------------------------------------
-// Taken and adapted from TriMesh_io.cc
-// -------------------------------------------------------------------
-// Write a bunch of faces to an ASCII file with colors.
-static void write_faces_asc_colored(TriMesh *mesh,
- const std::vector<mln::value::rgb8>& colors,
- FILE *f,
- const char *before_face,
- const char *after_line)
+int main(int argc, char* argv[])
{
- mesh->need_faces();
- for (int i = 0; i < mesh->faces.size(); i++)
+ if (argc != 4)
{
- fprintf(f, "%s%d %d %d %d %d %d%s\n",
- before_face,
- mesh->faces[i][0], mesh->faces[i][1], mesh->faces[i][2],
- int(colors[i].red()),
- int(colors[i].green()),
- int(colors[i].blue()),
- after_line);
- }
+ std::cerr << "usage: " << argv[1] << " input.off lambda output.off";
+ exit(1);
}
-/// Write an off file with colors.
-static void write_off_colored(TriMesh *mesh,
- const std::vector<mln::value::rgb8>& colors,
- FILE *f)
-{
- fprintf(f, "OFF\n");
- mesh->need_faces();
- fprintf(f, "%lu %lu 0\n", (unsigned long) mesh->vertices.size(),
- (unsigned long) mesh->faces.size());
- write_verts_asc(mesh, f, "", 0, 0, false, 0, "");
- write_faces_asc_colored(mesh, colors, f, "3 ", "");
-}
-// -------------------------------------------------------------------
+ std::string input_filename = argv[1];
+ unsigned lambda = atoi(argv[2]);
+ std::string output_filename = argv[3];
-int main(int argc, char* argv[])
-{
/*-------.
| Mesh. |
`-------*/
-// std::string filename = "../../aroumougame/test/test.off";
- std::string filename = "bunny-holefilled.off";
-
- // TriMesh is a pain: it systematically allocate on the heap.
- TriMesh* mesh_ptr = TriMesh::read(filename.c_str());
+ // TriMesh is a pain: it systematically allocates on the heap.
+ // Introduce another name to manipulate the mesh as a (non-pointer)
+ // object.
+ TriMesh* mesh_ptr = TriMesh::read(input_filename.c_str());
if (!mesh_ptr)
- exit(1);
+ exit(2);
TriMesh& mesh = *mesh_ptr;
// Computes faces (triangles).
mesh.need_faces();
-
// Computation of the mean curvature on each vertex of the mesh.
mesh.need_curvatures();
- // FIXME: Our implementation of the WST doesn't work well with floats.
- // Convert to a proportional integer value for the moment.
+ /* FIXME: Our implementation of the WST doesn't work well with
+ floats. Convert floating point values to a proportional integer
+ value for the moment. */
typedef int curv_t;
std::vector<float> vertex_h_inv(mesh.vertices.size(), 0.f);
for (unsigned v = 0; v < mesh.vertices.size(); ++v)
@@ -162,8 +91,9 @@
float h = (mesh.curv1[v] + mesh.curv2[v]) / 2;
float h_inv = 1 / pi * atan(-h) + pi / 2;
/* FIXME: This coefficient is used to distinguish small
- curvature values. We sould get rid of it as soon as
- meyer_wst works correctly on image of float values. */
+ curvature values. We should get rid of it as soon as
+ morpho::meyer_wst works correctly on images of float
+ values. */
vertex_h_inv[v] = 1000 * h_inv;
}
@@ -202,7 +132,7 @@
// Find the edge (i.e., the two vertices) common to faces
// F and F_ADJ.
/* FIXME: We lack a proper interface from the TriMesh
- strucure to do this elegantly. */
+ structure to do this elegantly. */
std::vector<int> adj_vertices;
adj_vertices.reserve(2);
for (unsigned i = 0; i < 3; ++i)
@@ -239,22 +169,21 @@
nbh_t nbh;
ima_t closed_lg_ima (lg_ima.domain());
- mln::morpho::closing_area(lg_ima, nbh, 500, closed_lg_ima);
+ mln::morpho::closing_area(lg_ima, nbh, lambda, closed_lg_ima);
/*------.
| WST. |
`------*/
- // Perform a Watershed Transform.
typedef unsigned wst_val_t;
wst_val_t nbasins;
typedef mln::line_graph_image<mln::point3d, wst_val_t> wst_ima_t;
wst_ima_t wshed = mln::morpho::meyer_wst(closed_lg_ima, nbh, nbasins);
std::cout << "nbasins = " << nbasins << std::endl;
- /*------------------------------------.
- | Label graph vertices (mesh faces). |
- `------------------------------------*/
+ /*------------------------------------------.
+ | Label graph vertices (i.e., mesh faces). |
+ `------------------------------------------*/
/* FIXME: We should be using wshed.vertex_values_ if
mln::line_graph_image were fully functional... */
@@ -272,30 +201,26 @@
| Output. |
`---------*/
- // Get random colors for each basin.
+ // Choose random colors for each basin number.
std::vector<mln::value::rgb8> basin_color (nbasins + 1);
for (unsigned i = 0; i <= nbasins; ++i)
basin_color[i] = mln::value::rgb8(random() % 256,
random() % 256,
random() % 256);
-
- // Assign colors to faces.
+ // Assign colors to graph vertices (mesh faces).
std::vector<mln::value::rgb8> face_color (vertex_label.size());
for (unsigned i = 0; i < vertex_label.size() ; ++i)
face_color[i] = basin_color[vertex_label[i]];
- // FIXME: This is ugly; convert to C++ code ASAP.
// Taken and adapted from TriMesh_io.cc
- const char* out_filename = "out.off";
- FILE* f_out = fopen(out_filename, "wb");
+ FILE* f_out = fopen(output_filename.c_str(), "wb");
if (!f_out)
{
- perror("fopen");
- fprintf(stderr, "Error opening %s for writing.\n", out_filename);
- exit(1);
+ std::cerr << "Error opening " << output_filename.c_str()
+ << " for writing." << std::endl;
+ exit(2);
}
-
write_off_colored(mesh_ptr, face_color, f_out);
fclose(f_out);
Property changes on: levillain/statues/mesh-segm.cc
___________________________________________________________________
Name: svn:executable
- *
Index: levillain/statues/Makefile
--- levillain/statues/Makefile (revision 2021)
+++ levillain/statues/Makefile (working copy)
@@ -19,11 +19,12 @@
all: mesh-segm
+mesh-segm.o: mesh-segm.cc io.hh
mesh-segm: mesh-segm.o
$(CXX) -o $@ $(LDFLAGS) $<
-check: mesh-segm
- ./mesh-segm
+check: mesh-segm test
+ ./test
CLEANFILES = mesh-segm.o mesh-segm
clean:
1
0