* mln/core/internal/graph_psite_base.hh: Add conversion to graph
element id (unsigned).
* mln/pw/image.hh: Allow construction of pw::image from Function_v2v
instead of Function_p2v.
* tests/core/image/graph_image.cc,
* tests/core/image/line_graph_image.cc: cleanup code.
---
milena/ChangeLog | 13 +++++++++
milena/mln/core/internal/graph_psite_base.hh | 11 +++++++
milena/mln/pw/image.hh | 37 ++++++++++++--------------
milena/tests/core/image/graph_image.cc | 31 +++-------------------
milena/tests/core/image/line_graph_image.cc | 31 +++-------------------
5 files changed, 49 insertions(+), 74 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 4edc4c2..1efcb92 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,18 @@
2008-12-08 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Allow construction of pw images using Function_v2v.
+
+ * mln/core/internal/graph_psite_base.hh: Add conversion to graph
+ element id (unsigned).
+
+ * mln/pw/image.hh: Allow construction of pw::image from Function_v2v
+ instead of Function_p2v.
+
+ * tests/core/image/graph_image.cc,
+ * tests/core/image/line_graph_image.cc: cleanup code.
+
+2008-12-08 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Fix build system.
* Makefile.am: Split and move data related to headers distribution...
diff --git a/milena/mln/core/internal/graph_psite_base.hh
b/milena/mln/core/internal/graph_psite_base.hh
index 2309862..c1fe14d 100644
--- a/milena/mln/core/internal/graph_psite_base.hh
+++ b/milena/mln/core/internal/graph_psite_base.hh
@@ -90,6 +90,9 @@ namespace mln
/// Invalidate this psite.
void invalidate();
+ /// Convertion towards the graph element Id.
+ operator unsigned() const;
+
/// Conversion towards the graph element (vertex or edge).
operator const typename S::graph_element&() const;
@@ -254,6 +257,14 @@ namespace mln
template <typename S, typename E>
inline
+ graph_psite_base<S,E>::operator unsigned() const
+ {
+ mln_precondition(is_valid());
+ return elt_.id();
+ }
+
+ template <typename S, typename E>
+ inline
graph_psite_base<S,E>::operator const typename S::graph_element&() const
{
mln_precondition(is_valid());
diff --git a/milena/mln/pw/image.hh b/milena/mln/pw/image.hh
index b6ba3a8..5a35153 100644
--- a/milena/mln/pw/image.hh
+++ b/milena/mln/pw/image.hh
@@ -1,4 +1,5 @@
// Copyright (C) 2007, 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
@@ -28,12 +29,10 @@
#ifndef MLN_PW_IMAGE_HH
# define MLN_PW_IMAGE_HH
-/*! \file mln/pw/image.hh
- *
- * \brief FIXME.
- *
- * \todo Relax Function_p2v into Function_v2v.
- */
+/// \file mln/pw/image.hh
+///
+/// FIXME.
+
# include <mln/core/internal/image_primary.hh>
# include <mln/core/concept/function.hh>
@@ -49,12 +48,11 @@ namespace mln
- /*! \brief FIXME
- *
- */
+ /// Construct an image from a function and a site set.
+ /// image = function | site_set.
template <typename F, typename S>
pw::image<F,S>
- operator | (const Function_p2v<F>& f, const Site_Set<S>& ps);
+ operator | (const Function_v2v<F>& f, const Site_Set<S>& ps);
@@ -114,9 +112,8 @@ namespace mln
namespace pw
{
- /*! \brief FIXME
- *
- */
+ /// FIXME
+ ///
template <typename F, typename S>
struct image :
public internal::image_primary<mln_result(F), S, image<F,S> >
@@ -138,10 +135,10 @@ namespace mln
image();
/// Constructor.
- image(const Function_p2v<F>& f, const Site_Set<S>& ps);
+ image(const Function_v2v<F>& f, const Site_Set<S>& ps);
/// Initialize an empty image.
- void init_(const Function_p2v<F>& f, const Site_Set<S>& ps);
+ void init_(const Function_v2v<F>& f, const Site_Set<S>& ps);
/// Give the definition domain.
const S& domain() const;
@@ -159,7 +156,7 @@ namespace mln
} // end of namespace mln::pw
template <typename F, typename S>
- void init_(tag::function_t, Function_p2v<F>& target,
+ void init_(tag::function_t, Function_v2v<F>& target,
const mln::pw::image<F,S>& model);
template <typename F, typename S, typename J>
@@ -171,7 +168,7 @@ namespace mln
// init_
template <typename F, typename S>
- void init_(tag::function_t, Function_p2v<F>& target,
+ void init_(tag::function_t, Function_v2v<F>& target,
const mln::pw::image<F,S>& model)
{
target = model.function();
@@ -192,7 +189,7 @@ namespace mln
template <typename F, typename S>
inline
pw::image<F,S>
- operator | (const Function_p2v<F>& f, const Site_Set<S>& ps)
+ operator | (const Function_v2v<F>& f, const Site_Set<S>& ps)
{
pw::image<F,S> tmp(f, ps);
return tmp;
@@ -226,7 +223,7 @@ namespace mln
template <typename F, typename S>
inline
- image<F,S>::image(const Function_p2v<F>& f, const
Site_Set<S>& ps)
+ image<F,S>::image(const Function_v2v<F>& f, const
Site_Set<S>& ps)
{
this->data_ = new internal::data< pw::image<F,S> >(exact(f),
exact(ps));
}
@@ -234,7 +231,7 @@ namespace mln
template <typename F, typename S>
inline
void
- image<F,S>::init_(const Function_p2v<F>& f, const
Site_Set<S>& ps)
+ image<F,S>::init_(const Function_v2v<F>& f, const
Site_Set<S>& ps)
{
this->data_ = new internal::data< image<F,S> >(exact(f),
exact(ps));
}
diff --git a/milena/tests/core/image/graph_image.cc
b/milena/tests/core/image/graph_image.cc
index bd47c8a..2094a24 100644
--- a/milena/tests/core/image/graph_image.cc
+++ b/milena/tests/core/image/graph_image.cc
@@ -62,32 +62,6 @@ static unsigned bkd[5][3] = { { 1, -1, -1 },
{ 2, 3, -1 } };
-
-template <typename S>
-struct viota_t : public mln::Function_p2v< viota_t<S> >
-{
- typedef unsigned result;
-
- viota_t(unsigned size)
- {
- v_.resize(size);
- for (unsigned i = 0; i < size; ++i)
- v_[i] = 10 + i;
- }
-
- unsigned
- operator()(const mln_psite(S)& p) const
- {
- return v_[p.v().id()];
- }
-
- protected:
- std::vector<result> v_;
-};
-
-
-
-
int main()
{
using namespace mln;
@@ -144,7 +118,10 @@ int main()
`-------------*/
// Graph values.
- viota_t<S> iota(5);
+ typedef fun::i2v::array<unsigned> viota_t;
+ viota_t iota(pv.nsites());
+ for (unsigned i = 0; i < iota.size(); ++i)
+ iota(i) = 10 + i;
// Create graph image.
mln_const_VAR(ima, (iota | pv));
diff --git a/milena/tests/core/image/line_graph_image.cc
b/milena/tests/core/image/line_graph_image.cc
index 14a43db..36a836f 100644
--- a/milena/tests/core/image/line_graph_image.cc
+++ b/milena/tests/core/image/line_graph_image.cc
@@ -59,32 +59,6 @@ static unsigned bkd[5][3] = { { 2, 1, -1 },
{ 3, 1, -1 } };
-
-template <typename S>
-struct viota_t : public mln::Function_p2v< viota_t<S> >
-{
- typedef unsigned result;
-
- viota_t(unsigned size)
- {
- v_.resize(size);
- for (unsigned i = 0; i < size; ++i)
- v_[i] = 10 + i;
- }
-
- unsigned
- operator()(const mln_psite(S)& p) const
- {
- return v_[p.e().id()];
- }
-
- protected:
- std::vector<result> v_;
-};
-
-
-
-
int main()
{
using namespace mln;
@@ -138,7 +112,10 @@ int main()
`-------------------*/
// Graph values.
- viota_t<S> iota(5);
+ typedef fun::i2v::array<unsigned> viota_t;
+ viota_t iota(pe.nsites());
+ for (unsigned i = 0; i < iota.size(); ++i)
+ iota(i) = 10 + i;
// Create line graph image.
mln_const_VAR(ima, (iota | pe));
--
1.5.6.5