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
February 2008
- 12 participants
- 70 discussions
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Ovherhaul undirected graphs.
* mln/util/graph.hh (util::node, util::edge, util::graph): Move...
* mln/util/internal/graph_base.hh: ...here (new file).
(node_id, edge_id): New.
(util::graph): Rename as...
(util::internal::graph_base): ...this.
Factor the common implementations of undirected graphs.
(util::internal::consistency): Remove.
(util::internal::nb_node_, util::internal::nb_link_): Remove.
* mln/util/graph.hh: Include mln/util/internal/graph_base.hh.
(util::graph<N, E>): New class, inheriting from
util::internal::graph_base.
(util::graph<N, void>, util::graph<void, void>):
New specializations.
* tests/util/graph.cc: Adjust.
mln/util/graph.hh | 412 ++++++++++++++++++++--------------------
mln/util/internal/graph_base.hh | 399 ++++++++++++++++++++++++++++++++++++++
tests/util/graph.cc | 11 -
3 files changed, 610 insertions(+), 212 deletions(-)
Index: mln/util/internal/graph_base.hh
--- mln/util/internal/graph_base.hh (revision 0)
+++ mln/util/internal/graph_base.hh (revision 0)
@@ -0,0 +1,399 @@
+// 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
+// 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.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_UTIL_INTERNAL_GRAPH_BASE_HH
+# define MLN_UTIL_INTERNAL_GRAPH_BASE_HH
+
+/// \file mln/util/internal/graph.hh
+/// \brief Factored implementation of undirected graphs.
+
+# include <mln/core/concept/object.hh>
+# include <cstddef>
+# include <ostream>
+# include <vector>
+# include <list>
+# include <algorithm>
+# include <mln/util/ordpair.hh>
+
+namespace mln
+{
+
+ namespace util
+ {
+ /// \bref The type used to identify nodes.
+ ///
+ /// Used internally as a key to manipulate nodes.
+ typedef unsigned node_id;
+
+ /// \bref The type used to identify edges.
+ ///
+ /// Used internally as a key to manipulate edges.
+ typedef unsigned edge_id;
+
+
+ /*-------.
+ | Node. |
+ `-------*/
+
+ /// \brief Node of a graph, holding a value of type \p T.
+ template<typename T>
+ struct node
+ {
+ node(T data)
+ : data(data)
+ {}
+
+ T data;
+ std::vector<edge_id> edges;
+ };
+
+ /// \brief Specialization of mln::util::node for nodes with no
+ /// associated value.
+ template<>
+ struct node<void>
+ {
+ std::list<node_id> edges;
+ };
+
+
+ /*-------.
+ | Edge. |
+ `-------*/
+
+ /// \brief Edge of a graph, holding a value of type \p T.
+ template<typename T>
+ struct edge
+ {
+ edge(node_id n1, node_id n2)
+ : pair_node_ (n1, n2)
+ {}
+
+ /// Return the lowest node id adjacent to this edge.
+ node_id n1 () const { return pair_node_.first; }
+ /// Return the highest node id adjacent to this edge.
+ node_id n2 () const { return pair_node_.second; }
+
+ T data;
+ ordpair_<node_id> pair_node_;
+ };
+
+ /// \brief Specialization of mln::util::node for edges with no
+ /// associated value.
+ template<>
+ struct edge <void>
+ {
+ edge(node_id n1, node_id n2)
+ : pair_node_ (n1, n2)
+ {}
+
+ /// Return the lowest node id adjacent to this edge.
+ node_id n1 () const { return pair_node_.first; }
+ /// Return the highest node id adjacent to this edge.
+ node_id n2 () const { return pair_node_.second; }
+
+ ordpair_<node_id> pair_node_;
+ };
+
+ // FIXME: Document this. In particular, we should state that edges are
+ // only compared w.r.t. their adjacent nodes, not the data they
+ // possibly hold!
+ template <typename E>
+ bool
+ operator==(const edge<E>& lhs, const edge<E>& rhs);
+
+ template <typename E>
+ bool
+ operator< (const edge<E>& lhs, const edge<E>& rhs);
+
+
+ /*--------.
+ | Graph. |
+ `--------*/
+
+ namespace internal
+ {
+ /// \brief Base class for undirected graphs.
+ template<typename N, typename E>
+ class graph_base
+ {
+ public:
+ /* FIXME: Do we really want handle nodes and edges through
+ pointers? In my (Roland) opinion, this is just a drawback,
+ here. */
+ /// The type of the set of nodes.
+ typedef std::vector< node<N>* > nodes_t;
+ /// The type of the set of edges.
+ typedef std::vector< edge<E>* > edges_t;
+
+ /// Constructor.
+ graph_base();
+ /// Destructor.
+ ~graph_base();
+
+ /// Return the node whose id is \a n.
+ /// \{
+ util::node<N>& node(node_id n);
+ const util::node<N>& node(edge_id n) const;
+ /// \}
+
+ /// Return the edge whose id is \a e.
+ /// \{
+ util::edge<E>& edge(edge_id e);
+ const util::edge<E>& edge(edge_id e) const;
+ /// \}
+
+ /// Return the whole nodes of the graph.
+ /// \{
+ nodes_t& nodes ();
+ const nodes_t& nodes () const;
+ /// \}
+
+ /// Return the whole edges of the graph.
+ /// \{
+ edges_t& edges ();
+ const edges_t& edges () const;
+ /// \}
+
+ /// \brief Return the number of nodes in the graph.
+ size_t nnodes() const;
+ /// \brief Return the number of edges in the graph.
+ size_t nedges() const;
+
+ // FIXME: We might want to externalize this in routine of
+ // namespace mln::debug.
+ /** \brief Print on \p ostr the graph.
+
+ \param[in] ostr The output stream. */
+ void print_debug (std::ostream& ostr) const;
+
+ protected:
+ /// Shortcuts factoring the insertion of nodes and edges.
+ /// \{
+ void add_node_ (util::node<N>* node);
+ void add_edge_ (util::edge<E>* edge);
+ /// \}
+
+ protected:
+ /// The nodes.
+ nodes_t nodes_;
+ /// The edges.
+ edges_t edges_;
+ };
+
+ } // end of namespace mln::util::internal
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ bool
+ operator==(const edge<E>& lhs, const edge<E>& rhs)
+ {
+ return lhs.pair_node_ == rhs.pair_node_;
+ }
+
+ template <typename E>
+ bool
+ operator< (const edge<E>& lhs, const edge<E>& rhs)
+ {
+ return lhs.pair_node_ < rhs.pair_node_;
+ }
+
+ namespace internal
+ {
+
+ /*----------------.
+ | Ctor and dtor. |
+ `----------------*/
+
+ template<typename N, typename E>
+ inline
+ graph_base<N, E>::graph_base()
+ : nodes_(), edges_()
+ {
+ }
+
+ template<typename N, typename E>
+ inline
+ graph_base<N, E>::~graph_base()
+ {
+ // FIXME: Delete data dynamically allocated in nodes_ and
+ // edges_.
+ }
+
+ /*------------.
+ | Accessors. |
+ `------------*/
+
+ template<typename N, typename E>
+ inline
+ util::node<N>&
+ graph_base<N, E>::node(node_id n)
+ {
+ mln_assertion(n < this->nnodes());
+ return *nodes_[n];
+ }
+
+ template<typename N, typename E>
+ inline
+ const util::node<N>&
+ graph_base<N, E>::node(node_id n) const
+ {
+ mln_assertion(n < this->nnodes());
+ return *nodes_[n];
+ }
+
+ template<typename N, typename E>
+ inline
+ util::edge<E>&
+ graph_base<N, E>::edge(edge_id e)
+ {
+ mln_assertion(e < this->nedges());
+ return *edges_[e];
+ }
+
+ template<typename N, typename E>
+ inline
+ const util::edge<E>&
+ graph_base<N, E>::edge(edge_id e) const
+ {
+ mln_assertion(e < this->nedges());
+ return *edges_[e];
+ }
+
+ template<typename N, typename E>
+ inline
+ typename graph_base<N, E>::nodes_t&
+ graph_base<N, E>::nodes()
+ {
+ return nodes_;
+ }
+
+ template<typename N, typename E>
+ inline
+ const typename graph_base<N, E>::nodes_t&
+ graph_base<N, E>::nodes() const
+ {
+ return nodes_;
+ }
+
+ template<typename N, typename E>
+ inline
+ typename graph_base<N, E>::edges_t&
+ graph_base<N, E>::edges()
+ {
+ return edges_;
+ }
+
+ template<typename N, typename E>
+ inline
+ const typename graph_base<N, E>::edges_t&
+ graph_base<N, E>::edges() const
+ {
+ return edges_;
+ }
+
+ template<typename N, typename E>
+ inline
+ size_t
+ graph_base<N, E>::nnodes() const
+ {
+ return nodes_.size();
+ }
+
+ template<typename N, typename E>
+ inline
+ size_t
+ graph_base<N, E>::nedges() const
+ {
+ return edges_.size();
+ }
+
+ /*---------------.
+ | Manipulators. |
+ `---------------*/
+
+ template<typename N, typename E>
+ inline
+ void
+ graph_base<N, E>::add_node_(util::node<N>* node)
+ {
+ nodes_.push_back (node);
+ }
+
+ template<typename N, typename E>
+ inline
+ void
+ graph_base<N, E>::add_edge_(util::edge<E>* edge)
+ {
+ // Does this edge already exist in the graph?
+ if (std::find(edges_.begin(), edges_.end(), edge) != edges_.end ())
+ {
+ delete edge;
+ edge = 0;
+ }
+ else
+ {
+ edges_.push_back (edge);
+ nodes_[edge->n1()]->edges.push_back(edge->n2());
+ nodes_[edge->n2()]->edges.push_back(edge->n1());
+ }
+ }
+
+ /*--------.
+ | Debug. |
+ `--------*/
+
+ template<typename N, typename E>
+ inline
+ void
+ graph_base<N, E>::print_debug (std::ostream& ostr) const
+ {
+ ostr << "graph: " << std::endl;
+ int i = 0;
+ for (typename nodes_t::const_iterator n = nodes_.begin ();
+ n != nodes_.end (); ++n, ++i)
+ {
+ ostr << "node: " << i << std::endl << " -- adjacent nodes: ";
+ for (typename edges_t::const_iterator e = (*n)->edges.begin();
+ e != (*n)->edges.end(); ++e)
+ ostr << *e << " ";
+ ostr << std::endl;
+ }
+ ostr << std::endl;
+ }
+
+ } // end of namespace mln::util::internal
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::util
+
+} // end of namespace mln
+
+#endif // ! MLN_UTIL_INTERNAL_GRAPH_BASE_HH
Index: mln/util/graph.hh
--- mln/util/graph.hh (revision 1712)
+++ mln/util/graph.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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,274 +28,278 @@
#ifndef MLN_UTIL_GRAPH_HH
# define MLN_UTIL_GRAPH_HH
-# include <mln/core/concept/object.hh>
-# include <cstddef>
-# include <ostream>
-# include <vector>
-# include <list>
-# include <algorithm>
-# include <mln/util/ordpair.hh>
-
-/*! \file mln/util/graph.hh
- *
- * \brief Definition of a graph.
- */
-
-// FIXME: Rename `s_node' to `node'.
-// FIXME: Rename `s_edge' to `edge'.
-// FIXME: Rename `links' to `edges'.
+/// \file mln/util/graph.hh
+/// \brief Definitions of undirected graphs.
+
+# include <mln/util/internal/graph_base.hh>
+
+
+// FIXME: More doc!
+
namespace mln
{
+
namespace util
{
+ /*-----------.
+ | Fwd decl. |
+ `-----------*/
+
+ /// \brief Undirected graph.
+ template<typename N = void, typename E = void>
+ class graph;
+
+ /*--------------------.
+ | graph<void, void>. |
+ `--------------------*/
- /*! \brief Structure of generic node.
- *
- */
- template<typename T>
- struct s_node
- {
- T data;
- // FIXME: Rename to `out_edges'.
- std::vector<unsigned> links;
- };
-
-
- /*! \brief Structure of node with void parameter.
- *
- */
+ /// Specialization for undirected graphs with no data on nodes nor
+ /// on edges.
template<>
- struct s_node<void>
+ class graph<void, void> : public internal::graph_base<void, void>
{
- // FIXME: Rename to `out_edges'.
- std::list<unsigned> links;
- };
+ public:
+ /// The super class.
+ typedef internal::graph_base<void, void> super;
-
- /*! \brief Structure of generic edge.
- *
- */
- template<typename T>
- struct s_edge
- {
- s_edge()
- : pair_node_ (0, 0)
- {}
-
- T data;
- ordpair_<unsigned> pair_node_;
+ // FIXME: We should return the id of the newly created node.
+ /// \brief Add a node.
+ void add_node();
+ // FIXME: We should return the id of the newly created edge.
+ /// \brief Add an edge between nodes with ids \p n1 and \p n2.
+ void add_edge(node_id n1, node_id n2);
};
- /*! \brief Structure of edge with void parameter.
- *
- */
- template<>
- struct s_edge <void>
- {
- s_edge() : pair_node_ (0, 0) {}
- ordpair_<unsigned> pair_node_;
+ /*-----------------.
+ | graph<N, void>. |
+ `-----------------*/
+
+ /// Specialization for undirected graphs with data on nodes.
+ template <typename N>
+ class graph<N, void> : public internal::graph_base<N, void>
+ {
+ public:
+ /// The super class.
+ typedef internal::graph_base<N, void> super;
+
+ // FIXME: We should return the id of the newly created node.
+ /// \brief Add a node.
+ void add_node(const N& data);
+ // FIXME: We should return the id of the newly created edge.
+ /// \brief Add an edge between nodes with ids \p n1 and \p n2.
+ void add_edge(node_id n1, node_id n2);
+
+ /// Return the data associated to node with id \a n.
+ /// \{
+ N& node_data(node_id n);
+ const N& node_data(node_id n) const;
+ /// \}
};
- bool operator==(const struct s_edge <void>& lhs,
- const struct s_edge <void>& rhs);
-
- bool operator< (const struct s_edge <void>& lhs,
- const struct s_edge <void>& rhs);
+ /*--------------.
+ | graph<N, E>. |
+ `--------------*/
- /// \brief Generic graph structure using s_node and s_edge.
- /* FIXME: We don't mention anywhere whether this graph structure
- handles directed or undirected graphs! */
- template<typename N, typename E = void>
- struct graph
- {
- /* FIXME: Do we really want handle edges and nodes through
- pointers? In my (Roland) opinion, this is just a drawback,
- here. */
-
- /// The type of the set of nodes.
- typedef std::vector< s_node<N>* > nodes;
- /// The type of the set of edges.
- typedef std::vector< s_edge<E>* > edges;
+ /// Specialization for undirected graphs with data on nodes and
+ /// edges.
+ template <typename N, typename E>
+ class graph : public internal::graph_base<N, E>
+ {
+ public:
+ /// The super class.
+ typedef internal::graph_base<N, E> super;
+
+ // FIXME: We should return the id of the newly created node.
+ /// \brief Add a node.
+ void add_node(const N& data);
+ /// \brief Add an edge between nodes with ids \p n1 and \p n2.
+ // FIXME: We should return the id of the newly created edge.
+ void add_edge(node_id n1, node_id n2, const E& data);
+
+ /// Return the data associated to node with id \a n.
+ /// \{
+ N& node_data(node_id n);
+ const N& node_data(node_id n) const;
+ /// \}
+
+ /// Return the data associated to the edge with id \a e.
+ /// \{
+ E& edge_data(edge_id e);
+ const E& edge_data(edge_id e) const;
+ /// \}
+
+ /// Return the data associated to the edge between nodes with
+ /// ids \a n1 and \a n2.
+ /// \{
+ E& edge_data(node_id n1, node_id n2);
+ const E& edge_data(node_id n1, node_id n2) const;
+ /// \}
+ };
- /// Constructor.
- graph ();
- /// Destructor.
- ~graph();
- /*! \brief Add a void node. */
- void add_node ();
+# ifndef MLN_INCLUDE_ONLY
+ /*--------------------.
+ | graph<void, void>. |
+ `--------------------*/
- /*! \brief Add a void edge between \p n1 and \p n2.
- *
- * \param[in] n1 The first node to link.
- * \param[in] n2 The second node to link.
- *
- * \pre n1 < nb_node_.
- * \pre n2 < nb_node_.
- */
- void add_edge (unsigned n1, unsigned n2);
-
-
- /*! \brief Check the consistency of the graph.
- *
- * Check if all edge have their node in the graph.
- *
- * \pre nodes_.size () == nb_node_.
- * \pre links_.size () == nb_link_.
- */
- void consistency () const;
-
-
- /*! \brief Print on \p ostr the graph.
- *
- * \param[in] ostr The output stream.
- */
- void print_debug (std::ostream& ostr) const;
+ /* Note that ddefinition of members from fully specialized
+ template classes are not preceded by `template<>'. */
+ inline
+ void
+ graph<void, void>::add_node()
+ {
+ super::add_node_(new util::node<void>);
+ }
+ /* Note that ddefinition of members from fully specialized
+ template classes are not preceded by `template<>'. */
+ inline
+ void
+ graph<void, void>::add_edge(node_id n1, node_id n2)
+ {
+ super::add_edge_(new util::edge<void>(n1, n2));
+ }
+ /*-----------------.
+ | graph<N, void>. |
+ `-----------------*/
- /// The nuber of nodes.
- unsigned nb_node_;
+ template<typename N>
+ inline
+ void
+ graph<N, void>::add_node(const N& data)
+ {
+ super::add_node_(new util::node<N>(data));
+ }
- /// The nuber of links.
- unsigned nb_link_;
+ template<typename N>
+ inline
+ void
+ graph<N, void>::add_edge(node_id n1, node_id n2)
+ {
+ mln_assertion(n1 < this->nnodes());
+ mln_assertion(n2 < this->nnodes());
+ super::add_edge_(new util::edge<void>(n1, n2));
+ }
- /// The vector where is stocked the pointers of nodes.
- nodes nodes_;
+ template <class N>
+ inline
+ N&
+ graph<N, void>::node_data(node_id n)
+ {
+ mln_assertion(n < this->nnodes());
+ return this->nodes_[n]->data;
+ }
- /// The vector where is stocked the pointers of links.
- edges links_;
- };
+ template<typename N>
+ inline
+ const N&
+ graph<N, void>::node_data(node_id n) const
+ {
+ mln_assertion(n < this->nnodes());
+ return this->nodes_[n]->data;
+ }
-# ifndef MLN_INCLUDE_ONLY
+ /*--------------.
+ | graph<N, E>. |
+ `--------------*/
- bool
- operator==(const struct s_edge <void>& lhs, const struct s_edge <void>& rhs)
+ template<typename N, typename E>
+ inline
+ void
+ graph<N, E>::add_node(const N& data)
{
- return lhs.pair_node_ == rhs.pair_node_;
+ super::add_node_(new util::node<N>(data));
}
- bool
- operator< (const struct s_edge <void>& lhs, const struct s_edge <void>& rhs)
+ template<typename N, typename E>
+ inline
+ void
+ graph<N, E>::add_edge(node_id n1, node_id n2, const E& data)
{
- return lhs.pair_node_ < rhs.pair_node_;
+ mln_assertion(n1 < this->nnodes());
+ mln_assertion(n2 < this->nnodes());
+ super::add_edge_(new util::edge<E>(n1, n2, data));
}
template<typename N, typename E>
inline
- graph<N, E>::graph ()
- : nb_node_ (0),
- nb_link_ (0),
- nodes_ (0),
- links_ (0)
+ N&
+ graph<N, E>::node_data(node_id n)
{
+ mln_assertion(n < this->nnodes());
+ return this->nodes_[n]->data;
}
template<typename N, typename E>
inline
- graph<N, E>::~graph ()
+ const N&
+ graph<N, E>::node_data(node_id n) const
{
+ mln_assertion(n < this->nnodes());
+ return this->nodes_[n]->data;
}
template<typename N, typename E>
inline
- void
- graph<N, E>::add_node ()
+ E&
+ graph<N, E>::edge_data(edge_id e)
{
- struct s_node<N>* n = new struct s_node<N>;
-
- nodes_.push_back (n);
- ++nb_node_;
+ mln_assertion(e < this->nedges());
+ return this->edges_[e]->data;
}
template<typename N, typename E>
inline
- void
- graph<N, E>::add_edge (unsigned n1, unsigned n2)
+ const E&
+ graph<N, E>::edge_data(edge_id e) const
{
- mln_precondition(n1 < this->nb_node_);
- mln_precondition(n2 < this->nb_node_);
-
- struct s_edge<E>* edge;
-
- edge = new s_edge<E>;
- edge->pair_node_.first = n1;
- edge->pair_node_.second = n2;
- // Does this edge already exist in the graph?
- if (std::find(links_.begin(), links_.end(), edge) != links_.end ())
- {
- delete edge;
- edge = 0;
- }
- else
- {
- links_.push_back (edge);
- ++nb_link_;
- /* FIXME: In fact, we should store adjaceny information in
- *both* nodes. Change this globally later, and mention
- that the graph is undirected in the documentation. And
- don't forget to update clients! */
- nodes_[n1]->links.push_back (n2);
- }
+ mln_assertion(e < this->nedges());
+ return this->edges_[e]->data;
}
template<typename N, typename E>
inline
- void
- graph<N, E>::consistency () const
+ E&
+ graph<N, E>::edge_data(node_id n1, node_id n2)
{
- mln_precondition(nodes_.size () == this->nb_node_);
- mln_precondition(links_.size () == this->nb_link_);
- typename std::vector<struct s_node <N>*>::const_iterator it =
- nodes_.begin ();
- for (; it != nodes_.end (); ++it)
- {
- typename std::list<unsigned>::const_iterator it2 =
- (*it)->links.begin ();
- for (; it2 != (*it)->links.end (); ++it2)
- mln_precondition((*it2) < nb_node_);
- }
-
- typename std::vector<struct s_edge<E>*>::const_iterator it3 =
- links_.begin ();
- for (; it3 != links_.end (); ++it3)
- {
- mln_precondition((*it3)->pair_node_.first < nb_node_);
- mln_precondition((*it3)->pair_node_.second < nb_node_);
- }
+ mln_assertion(n1 < this->nnodes());
+ mln_assertion(n2 < this->nnodes());
+ ordpair_<node_id> node_pair (n1, n2);
+ std::vector<edge_id>& edges_ids = this->nodes_[n1]->edges;
+ for (std::vector<edge_id>::iterator e = edges_ids.begin();
+ e != edges_ids.end(); ++e)
+ if (this->edges_[*e] == node_pair)
+ return this->edges_[*e]->data;
+ // If no edge between N1 and N2 was found, abort.
+ abort();
}
template<typename N, typename E>
inline
- void
- graph<N, E>::print_debug (std::ostream& ostr) const
- {
- ostr << "nodes :" << std::endl;
-
- typename std::vector<struct s_node<N>*>::const_iterator it =
- nodes_.begin ();
- int i = 0;
- for (; it != nodes_.end (); ++it, ++i)
- {
- ostr << "node number = " << i << " nbh : ";
- typename std::list<unsigned>::const_iterator it2 = (*it)->links.begin ();
- for (; it2 != (*it)->links.end (); ++it2)
+ const E&
+ graph<N, E>::edge_data(node_id n1, node_id n2) const
{
- ostr << (*it2) << " ";
- }
- ostr << std::endl;
- }
- ostr << std::endl;
+ mln_assertion(n1 < this->nnodes());
+ mln_assertion(n2 < this->nnodes());
+ ordpair_<node_id> node_pair (n1, n2);
+ const std::vector<edge_id>& edges_ids = this->nodes_[n1]->edges;
+ for (std::vector<edge_id>::const_iterator e = edges_ids.begin();
+ e != edges_ids.end(); ++e)
+ if (this->edges_[*e] == node_pair)
+ return this->edges_[*e]->data;
+ // If no edge between N1 and N2 was found, abort.
+ abort();
}
# endif // ! MLN_INCLUDE_ONLY
- } // end of util
+ } // end of namespace mln::util
-} // end of mln
+} // end of namespace mln
-#endif // MLN_GRAPH_HH
+#endif // ! MLN_UTIL_GRAPH_HH
Index: tests/util/graph.cc
--- tests/util/graph.cc (revision 1712)
+++ tests/util/graph.cc (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
@@ -25,12 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*!
- * \file tests/util/graph.cc
- *
- * \brief test of mln::util::graph
- *
- */
+/// \file tests/util/graph.cc
+/// \brief test of mln::util::graph
#include <mln/util/graph.hh>
#include <iostream>
@@ -55,5 +51,4 @@
g.add_edge (1, 0);
g.add_edge (5, 3);
g.add_edge (2, 1);
- g.consistency ();
}
1
1
1712: Have priority queues of points catch up with the interface of Point_Set.
by Roland Levillain 07 Feb '08
by Roland Levillain 07 Feb '08
07 Feb '08
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Have priority queues of points catch up with the interface of
Point_Set.
* mln/core/p_priority_queue.hh (p_priority_queue::npoints)
* mln/core/p_priority_queue_fast.hh (p_priority_queue_fast::npoints):
Set the return type from `unsigned' to `size_t'.
p_priority_queue.hh | 4 ++--
p_priority_queue_fast.hh | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
Index: mln/core/p_priority_queue.hh
--- mln/core/p_priority_queue.hh (revision 1711)
+++ mln/core/p_priority_queue.hh (working copy)
@@ -83,7 +83,7 @@
bool is_empty() const;
/// Give the number of points.
- unsigned npoints() const;
+ size_t npoints() const;
/// Give the exact bounding box.
const box_<P>& bbox() const;
@@ -202,7 +202,7 @@
template <typename P, typename T>
inline
- unsigned
+ size_t
p_priority_queue<P, T>::npoints() const
{
unsigned res = 0;
Index: mln/core/p_priority_queue_fast.hh
--- mln/core/p_priority_queue_fast.hh (revision 1711)
+++ mln/core/p_priority_queue_fast.hh (working copy)
@@ -83,7 +83,7 @@
bool is_empty() const;
/// Give the number of points.
- unsigned npoints() const;
+ size_t npoints() const;
/// Give the exact bounding box.
const box_<P>& bbox() const;
@@ -202,7 +202,7 @@
template <typename P, typename T>
inline
- unsigned
+ size_t
p_priority_queue_fast<P, T>::npoints() const
{
unsigned res = 0;
1
0
Remember: changes altering only milena/ should be put into
milena/Changelog.
Index: milena/ChangeLog
===================================================================
--- milena/ChangeLog (révision 1710)
+++ milena/ChangeLog (révision 1711)
@@ -12,6 +12,11 @@
(pw_image_SOURCES, pw_value_SOURCES): Remove.
* mln/pw/all.hh: Update.
+2008-02-07 Maxime van Noppen <yabo(a)lrde.epita.fr>
+
+ Fix typo.
+ * mln/core/internal/force_exact.hh: Here.
+
2008-02-05 Roland Levillain <roland(a)lrde.epita.fr>
Add functors max and min.
Index: ChangeLog
===================================================================
--- ChangeLog (révision 1710)
+++ ChangeLog (révision 1711)
@@ -1,8 +1,3 @@
-2008-02-07 Maxime van Noppen <yabo(a)lrde.epita.fr>
-
- Fix typo.
- * milena/mln/core/internal/force_exact.hh: Here.
-
2008-01-25 Roland Levillain <roland(a)lrde.epita.fr>
* configure.ac: Configure milena/tests/neighb/Makefile.
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Update tests on pw material.
* tests/pw_image.cc: Rename as...
* tests/pw/image.cc: ...this.
* tests/pw_value.cc: Rename as...
* tests/pw/value.cc: ...this.
* tests/pw/Makefile.am (check_PROGRAMS): Update.
(image_SOURCES, value_SOURCES): New.
* tests/Makefile.am (SUBDIRS): Add pw.
(pw_image_SOURCES, pw_value_SOURCES): Remove.
* mln/pw/all.hh: Update.
mln/pw/all.hh | 6 ++++--
tests/Makefile.am | 5 +----
tests/pw/Makefile.am | 9 +++++++++
tests/pw/image.cc | 2 +-
tests/pw/value.cc | 22 ++++++++++++----------
5 files changed, 27 insertions(+), 17 deletions(-)
Index: tests/pw/value.cc
--- tests/pw/value.cc (revision 1608)
+++ tests/pw/value.cc (working copy)
@@ -25,15 +25,14 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/pw_value.cc
+/*! \file tests/pw/value.cc
*
* \brief Test on mln::pw::value_.
*/
#include <mln/core/image2d.hh>
-#include <mln/fun/ops.hh>
-#include <mln/pw/value.hh>
-#include <mln/pw/cst.hh>
+#include <mln/level/fill.hh>
+#include <mln/pw/all.hh>
int main()
@@ -41,13 +40,16 @@
using namespace mln;
image2d<int> ima(3, 3);
- point2d p = make::point2d(1, 1);
+ level::fill(ima, 0);
+
+ point2d p(1, 1);
ima(p) = 51;
mln_assertion( (pw::value(ima) = pw::cst(51))(p) = true );
- {
- image2d<float> imaf(3,3);
- imaf(p) = 51;
- mln_assertion(((pw::value(ima) + pw::value(imaf))(p) / 20) - 5.1 < 0.00001);
- }
+// {
+// image2d<float> imaf(3,3);
+// imaf(p) = 51;
+// mln_assertion(((pw::value(ima) + pw::value(imaf))(p) / 20) - 5.1 < 0.00001);
+// }
+
}
Index: tests/pw/image.cc
--- tests/pw/image.cc (revision 1608)
+++ tests/pw/image.cc (working copy)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/pw_image.cc
+/*! \file tests/pw/image.cc
*
* \brief Tests on mln::pw::image.
*/
Index: tests/pw/Makefile.am
--- tests/pw/Makefile.am (revision 1709)
+++ tests/pw/Makefile.am (working copy)
@@ -1,3 +1,12 @@
## Process this file through Automake to create Makefile.in -*- Makefile -*-
include $(top_srcdir)/milena/tests/tests.mk
+
+check_PROGRAMS = \
+ image \
+ value
+
+image_SOURCES = image.cc
+value_SOURCES = value.cc
+
+TESTS = $(check_PROGRAMS)
Index: tests/Makefile.am
--- tests/Makefile.am (revision 1709)
+++ tests/Makefile.am (working copy)
@@ -20,6 +20,7 @@
morpho \
neighb \
norm \
+ pw \
set \
util \
value \
@@ -92,8 +93,6 @@
point1d \
point2d \
point3d \
- pw_image \
- pw_value \
\
safe_image \
seed2tiling \
@@ -184,8 +183,6 @@
point1d_SOURCES = point1d.cc
point2d_SOURCES = point2d.cc
point3d_SOURCES = point3d.cc
-pw_image_SOURCES = pw_image.cc
-pw_value_SOURCES = pw_value.cc
safe_image_SOURCES = safe_image.cc
seed2tiling_SOURCES = seed2tiling.cc
Index: mln/pw/all.hh
--- mln/pw/all.hh (revision 1709)
+++ mln/pw/all.hh (working copy)
@@ -43,11 +43,13 @@
} // end of namespace mln
-# include <mln/pw/value.hh>
# include <mln/pw/cst.hh>
-# include <mln/pw/var.hh>
# include <mln/pw/image.hh>
+# include <mln/pw/value.hh>
+# include <mln/pw/var.hh>
+
+// Extra include so that we can use operators in point-wise expressions.
# include <mln/fun/ops.hh>
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk
ChangeLog:
2008-02-07 Maxime van Noppen <yabo(a)lrde.epita.fr>
Fix typo.
* milena/mln/core/internal/force_exact.hh: Here.
force_exact.hh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Index: trunk/milena/mln/core/internal/force_exact.hh
===================================================================
--- trunk/milena/mln/core/internal/force_exact.hh (revision 1708)
+++ trunk/milena/mln/core/internal/force_exact.hh (revision 1709)
@@ -44,7 +44,7 @@
/*! \internal Violent cast.
* This cast is an alternative to the mln::exact cast.
- * It is used for objects than do not derive from
+ * It is used for objects that do not derive from
* mln::Object.
* Warning Do not to use this cast!
* see mln::exact
--
\__/ \__/
(00) Maxime `yabo` van Noppen (00)
___) \ Epita 2009 / (___
(_____/ Président de Prologin \_____)
1
0
Re: [Olena-patches] [Olena] #7: Miscellaneous tasks related to the Olena 1.0ß release process
by Olena 07 Feb '08
by Olena 07 Feb '08
07 Feb '08
#7: Miscellaneous tasks related to the Olena 1.0ß release process
-----------------------+----------------------------------------------------
Reporter: levill_r | Owner: levill_r
Type: task | Status: new
Priority: trivial | Milestone: Olena 1.0ß
Component: other | Version: 1.0
Resolution: | Keywords: release NEWS dates copyright headers
-----------------------+----------------------------------------------------
Old description:
> To do before the release
> * update `NEWS` (see the similar task for Olena 0.10a/0.11: #8);
> * update `AUTHORS`;
> * ensure all copyright headers are sound (using Benoît Sigoure's
> `gplize.sh` script, or a variant of it).
>
> Split this ticket in several parts if the tasks are either too big or too
> numerous.
New description:
To do before the release
* update `NEWS` (see the similar task for Olena 0.10a/0.11: #8);
* update `AUTHORS`;
* ensure all copyright headers are sound (using Benoît Sigoure's
`gplize.sh` script, or a variant of it);
* use Vaucanson' `reheader` script to fix broken headers.
Split this ticket in several parts if the tasks are either too big or too
numerous.
Comment (by levill_r):
The use of `reheader` was suggested by Akim.
--
Ticket URL: <https://trac.lrde.org/olena/ticket/7#comment:6>
Olena <http://olena.lrde.epita.fr>
Olena, a generic and efficient C++ image processing library.
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add functors max and min.
* mln/core/concept/function.hh (mln::Function_vv2v): New.
* mln/fun/vv2v/max.hh, mln/fun/vv2v/min.hh: New.
* tests/fun/vv2v/max.cc, tests/fun/vv2v/min.cc: New tests.
* tests/fun/vv2v/Makefile.am: New.
* tests/fun/Makefile.am (SUBDIRS): Add i2v, p2b, p2v and vv2v.
* tests/norm/common.hh: Adjust coding style.
mln/core/concept/function.hh | 77 +++++++++++++++++++++++++++++++++++--------
mln/fun/vv2v/max.hh | 77 +++++++++++++++++++++++++++++++++++++++++++
mln/fun/vv2v/min.hh | 77 +++++++++++++++++++++++++++++++++++++++++++
tests/fun/Makefile.am | 2 -
tests/fun/vv2v/Makefile.am | 12 ++++++
tests/fun/vv2v/max.cc | 53 +++++++++++++++++++++++++++++
tests/fun/vv2v/min.cc | 53 +++++++++++++++++++++++++++++
tests/norm/common.hh | 0
8 files changed, 336 insertions(+), 15 deletions(-)
Index: mln/core/concept/function.hh
--- mln/core/concept/function.hh (revision 1707)
+++ mln/core/concept/function.hh (working copy)
@@ -39,9 +39,7 @@
namespace mln
{
- /// \{
- /// Fwd decls.
-
+ // Fwd decls.
template <typename E> struct Function;
template <typename E> struct Function_v2v;
template <typename E> struct Function_i2v;
@@ -50,11 +48,11 @@
template <typename E> struct Function_p2b;
template <typename E> struct Function_p2p;
template <typename E> struct Function_x2x;
- /// \}
+ template <typename E> struct Function_vv2v;
- // Function category flag type.
+ /// Function category flag type.
template <>
struct Function<void>
{
@@ -81,7 +79,9 @@
};
- // Value -> Value.
+ /*-----------------.
+ | Value -> Value. |
+ `-----------------*/
template <>
struct Function_v2v<void> { typedef Function<void> super; };
@@ -102,12 +102,13 @@
};
- // Index -> Value.
+ /*-----------------.
+ | Index -> Value. |
+ `-----------------*/
template <>
struct Function_i2v<void> { typedef Function_v2v<void> super; };
-
/*!
* \brief Base class for implementation of function-objects from
* index to value.
@@ -124,7 +125,9 @@
};
- // Point -> Value.
+ /*-----------------.
+ | Point -> Value. |
+ `-----------------*/
template <>
struct Function_p2v<void> { typedef Function_v2v<void> super; };
@@ -145,7 +148,9 @@
};
- // Value -> bool.
+ /*----------------.
+ | Value -> bool. |
+ `----------------*/
template <>
struct Function_v2b<void> { typedef Function_v2v<void> super; };
@@ -167,7 +172,9 @@
};
- // Point -> bool.
+ /*----------------.
+ | Point -> bool. |
+ `----------------*/
template <>
struct Function_p2b<void> { typedef Function_p2v<void> super; }; // FIXME
@@ -190,7 +197,9 @@
};
- // Point -> Point.
+ /*-----------------.
+ | Point -> Point. |
+ `-----------------*/
template <>
struct Function_p2p<void> { typedef Function_p2v<void> super; }; // FIXME
@@ -211,7 +220,9 @@
};
- // Vector -> Vector.
+ /*-------------------.
+ | Vector -> Vector. |
+ `-------------------*/
template <>
struct Function_x2x<void> { typedef Function_v2v<void> super; }; // FIXME
@@ -231,7 +242,10 @@
Function_x2x(const Function_x2x&);
};
- // Vector <-> Vector.
+
+ /*--------------------.
+ | Vector <-> Vector. |
+ `--------------------*/
/*!
* \brief Base class for implementation of bijective function-objects from
@@ -251,6 +265,28 @@
};
+ /*------------------------.
+ | Value, Value -> Value. |
+ `------------------------*/
+
+ template <>
+ struct Function_vv2v<void> { typedef Function<void> super; };
+
+ /*!
+ * \brief Base class for implementation of function-objects from
+ * a couple of values to a value.
+ *
+ * The parameter \a E is the exact type.
+ */
+ template <typename E>
+ struct Function_vv2v : public Function<E>
+ {
+ typedef Function_vv2v<void> category;
+ protected:
+ Function_vv2v();
+ Function_vv2v(const Function_vv2v&);
+ };
+
# ifndef MLN_INCLUDE_ONLY
@@ -370,6 +406,19 @@
m = 0;
}
+ template <typename E>
+ inline
+ Function_vv2v<E>::Function_vv2v()
+ {
+ }
+
+ template <typename E>
+ inline
+ Function_vv2v<E>::Function_vv2v(const Function_vv2v<E>& rhs)
+ : Function<E>(rhs)
+ {
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/fun/vv2v/min.hh
--- mln/fun/vv2v/min.hh (revision 0)
+++ mln/fun/vv2v/min.hh (revision 0)
@@ -0,0 +1,77 @@
+// 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 MLN_FUN_VV2V_MIN_HH
+# define MLN_FUN_VV2V_MIN_HH
+
+/// \file mln/fun/vv2v/min.hh
+/// \brief computing the minimum of two values using a functor.
+
+# include <mln/core/concept/function.hh>
+# include <mln/math/min.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace vv2v
+ {
+
+ // FIXME: Doc.
+
+ /// \brief A functor computing the minimum of two values.
+ template <typename V>
+ struct min : public Function_vv2v< min<V> >
+ {
+ typedef V result;
+ V operator()(const V& v1, const V& v2) const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ inline
+ V
+ min<V>::operator()(const V& v1, const V& v2) const
+ {
+ return mln::math::min(v1, v2);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::vv2v
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_VV2V_MIN_HH
Index: mln/fun/vv2v/max.hh
--- mln/fun/vv2v/max.hh (revision 0)
+++ mln/fun/vv2v/max.hh (revision 0)
@@ -0,0 +1,77 @@
+// 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 MLN_FUN_VV2V_MAX_HH
+# define MLN_FUN_VV2V_MAX_HH
+
+/// \file mln/fun/vv2v/max.hh
+/// \brief Computing the maximum of two values using a functor.
+
+# include <mln/core/concept/function.hh>
+# include <mln/math/max.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace vv2v
+ {
+
+ // FIXME: Doc.
+
+ /// \brief A functor computing the maximum of two values.
+ template <typename V>
+ struct max : public Function_vv2v< max<V> >
+ {
+ typedef V result;
+ V operator()(const V& v1, const V& v2) const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ inline
+ V
+ max<V>::operator()(const V& v1, const V& v2) const
+ {
+ return mln::math::max(v1, v2);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::vv2v
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_VV2V_MAX_HH
Index: tests/fun/vv2v/min.cc
--- tests/fun/vv2v/min.cc (revision 0)
+++ tests/fun/vv2v/min.cc (revision 0)
@@ -0,0 +1,53 @@
+// 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.
+
+/// \file tests/fun/vv2v/min.cc
+/// \brief Test the min functor.
+
+#include <cassert>
+
+#include <mln/metal/vec.hh>
+#include <mln/fun/vv2v/min.hh>
+
+int main()
+{
+ // Scalars.
+ mln::fun::vv2v::min<int> min_int;
+ assert (min_int(42, 51) == 42);
+
+ // FIXME: We don't have vectors-with-an-order (yet), so this won't
+ // work.
+#if 0
+ // Vectors.
+ typedef mln::metal::vec<3, int> vec_t;
+ mln::fun::vv2v::min<vec_t> min_vec_t;
+ vec_t t, u;
+ t.set (1, -2, 3);
+ u.set (5, 1, 0);
+ assert (min_vec_t(t, u) == t);
+#endif
+}
Index: tests/fun/vv2v/max.cc
--- tests/fun/vv2v/max.cc (revision 0)
+++ tests/fun/vv2v/max.cc (revision 0)
@@ -0,0 +1,53 @@
+// 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.
+
+/// \file tests/fun/vv2v/max.cc
+/// \brief Test the max functor.
+
+#include <cassert>
+
+#include <mln/metal/vec.hh>
+#include <mln/fun/vv2v/max.hh>
+
+int main()
+{
+ // Scalars.
+ mln::fun::vv2v::max<int> max_int;
+ assert (max_int(42, 51) == 51);
+
+ // FIXME: We don't have vectors-with-an-order (yet), so this won't
+ // work.
+#if 0
+ // Vectors.
+ typedef mln::metal::vec<3, int> vec_t;
+ mln::fun::vv2v::max<vec_t> max_vec_t;
+ vec_t t, u;
+ t.set (1, -2, 3);
+ u.set (5, 1, 0);
+ assert (max_vec_t(t, u) == u);
+#endif
+}
Index: tests/fun/vv2v/Makefile.am
--- tests/fun/vv2v/Makefile.am (revision 0)
+++ tests/fun/vv2v/Makefile.am (revision 0)
@@ -0,0 +1,12 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+include $(top_srcdir)/milena/tests/tests.mk
+
+check_PROGRAMS = \
+ max \
+ min
+
+max_SOURCES = max.cc
+min_SOURCES = min.cc
+
+TESTS = $(check_PROGRAMS)
Index: tests/fun/Makefile.am
--- tests/fun/Makefile.am (revision 1707)
+++ tests/fun/Makefile.am (working copy)
@@ -2,4 +2,4 @@
include $(top_srcdir)/milena/tests/tests.mk
-SUBDIRS = v2v x2x
+SUBDIRS = i2v p2b p2v v2v vv2v x2x
Index: tests/norm/common.hh
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Wow! I wanted to do this for *weeks*! Now it reads much better.
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Rename (and clean up a bit) graph-related classes.
* mln/util/graph.hh (add_edge): Fix the update of the list of
edges.
* mln/core/mesh_image.hh,
* mln/core/mesh_p.hh,
* mln/core/mesh_p_piter.hh,
* mln/core/mesh_psite.hh,
* mln/core/mesh_elt_window.hh,
* mln/core/mesh_window_piter.hh:
Rename as...
* mln/core/graph_image.hh,
* mln/core/p_graph.hh,
* mln/core/p_graph_piter.hh,
* mln/core/graph_psite.hh,
* mln/core/graph_elt_window.hh,
* mln/core/graph_window_piter.hh:
...these.
(mesh_image, mesh_p, mesh_p_piter_, mesh_psite)
(mesh_elt_window, mesh_window_fwd_piter):
Rename as...
(graph_image, p_graph, p_graph_piter_, graph_psite)
(graph_elt_window, graph_window_fwd_piter):
...these.
* mln/draw/mesh.hh:
Adjust.
Rename as...
* mln/draw/graph.hh: ...these.
(mesh(Image<I>&, const mesh_p<P>&, mln_value(I), mln_value(I)))
(mesh(Image<I>&, const mesh_image<P, V>&, mln_value(I))):
Rename as...
(graph(Image<I>&, const p_graph<P>&, mln_value(I), mln_value(I)))
(graph(Image<I>&, const graph_image<P, V>&, mln_value(I))):
...these.
* tests/core/mesh_elt_window.cc,
* tests/core/mesh_image.cc,
* tests/draw/mesh.cc:
Adjust.
Rename those tests as...
* tests/core/graph_elt_window.cc,
* tests/core/graph_image.cc,
* tests/draw/graph.cc:
...these.
* tests/core/Makefile.am, tests/draw/Makefile.am: Adjust names.
mln/core/graph_elt_window.hh | 94 ++++++++++++++++++++---------------------
mln/core/graph_image.hh | 90 +++++++++++++++++++--------------------
mln/core/graph_psite.hh | 50 ++++++++++-----------
mln/core/graph_window_piter.hh | 79 +++++++++++++++++-----------------
mln/core/p_graph.hh | 57 +++++++++++++-----------
mln/core/p_graph_piter.hh | 59 +++++++++++++------------
mln/draw/graph.hh | 86 ++++++++++++++++++-------------------
mln/util/graph.hh | 36 ++++++++++++---
tests/core/Makefile.am | 8 +--
tests/core/graph_elt_window.cc | 22 ++++-----
tests/core/graph_image.cc | 60 ++++++++++++--------------
tests/draw/Makefile.am | 4 -
tests/draw/graph.cc | 20 +++-----
13 files changed, 345 insertions(+), 320 deletions(-)
Index: mln/util/graph.hh
--- mln/util/graph.hh (revision 1703)
+++ mln/util/graph.hh (working copy)
@@ -79,7 +79,9 @@
template<typename T>
struct s_edge
{
- s_edge() : pair_node_ (0, 0) {}
+ s_edge()
+ : pair_node_ (0, 0)
+ {}
T data;
ordpair_<unsigned> pair_node_;
@@ -95,9 +97,11 @@
ordpair_<unsigned> pair_node_;
};
- bool operator==(const struct s_edge <void>& lhs, const struct s_edge <void>& rhs);
+ bool operator==(const struct s_edge <void>& lhs,
+ const struct s_edge <void>& rhs);
- bool operator< (const struct s_edge <void>& lhs, const struct s_edge <void>& rhs);
+ bool operator< (const struct s_edge <void>& lhs,
+ const struct s_edge <void>& rhs);
/// \brief Generic graph structure using s_node and s_edge.
/* FIXME: We don't mention anywhere whether this graph structure
@@ -105,6 +109,10 @@
template<typename N, typename E = void>
struct graph
{
+ /* FIXME: Do we really want handle edges and nodes through
+ pointers? In my (Roland) opinion, this is just a drawback,
+ here. */
+
/// The type of the set of nodes.
typedef std::vector< s_node<N>* > nodes;
/// The type of the set of edges.
@@ -217,12 +225,20 @@
edge = new s_edge<E>;
edge->pair_node_.first = n1;
edge->pair_node_.second = n2;
- if (links_.end () == std::find(links_.begin(), links_.end(), edge))
+ // Does this edge already exist in the graph?
+ if (std::find(links_.begin(), links_.end(), edge) != links_.end ())
+ {
delete edge;
+ edge = 0;
+ }
else
{
links_.push_back (edge);
++nb_link_;
+ /* FIXME: In fact, we should store adjaceny information in
+ *both* nodes. Change this globally later, and mention
+ that the graph is undirected in the documentation. And
+ don't forget to update clients! */
nodes_[n1]->links.push_back (n2);
}
}
@@ -234,15 +250,18 @@
{
mln_precondition(nodes_.size () == this->nb_node_);
mln_precondition(links_.size () == this->nb_link_);
- typename std::vector<struct s_node <N>*>::const_iterator it = nodes_.begin ();
+ typename std::vector<struct s_node <N>*>::const_iterator it =
+ nodes_.begin ();
for (; it != nodes_.end (); ++it)
{
- typename std::list<unsigned>::const_iterator it2 = (*it)->links.begin ();
+ typename std::list<unsigned>::const_iterator it2 =
+ (*it)->links.begin ();
for (; it2 != (*it)->links.end (); ++it2)
mln_precondition((*it2) < nb_node_);
}
- typename std::vector<struct s_edge<E>*>::const_iterator it3 = links_.begin ();
+ typename std::vector<struct s_edge<E>*>::const_iterator it3 =
+ links_.begin ();
for (; it3 != links_.end (); ++it3)
{
mln_precondition((*it3)->pair_node_.first < nb_node_);
@@ -257,7 +276,8 @@
{
ostr << "nodes :" << std::endl;
- typename std::vector<struct s_node<N>*>::const_iterator it = nodes_.begin ();
+ typename std::vector<struct s_node<N>*>::const_iterator it =
+ nodes_.begin ();
int i = 0;
for (; it != nodes_.end (); ++it, ++i)
{
Index: mln/core/graph_psite.hh
--- mln/core/graph_psite.hh (revision 1703)
+++ mln/core/graph_psite.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -25,35 +25,35 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_MESH_PSITE_HH
-# define MLN_CORE_MESH_PSITE_HH
+#ifndef MLN_CORE_GRAPH_PSITE_HH
+# define MLN_CORE_GRAPH_PSITE_HH
-/*! \file mln/core/mesh_psite.hh
+/*! \file mln/core/graph_psite.hh
*
* \brief Definition of a graph-based point site.
*
* \todo Clean-up!
*/
-# include <mln/core/mesh_p.hh>
+# include <mln/core/p_graph.hh>
namespace mln
{
// Fwd decl.
- template<typename P> class mesh_p;
+ template<typename P> class p_graph;
/*!
- * \brief Point site associate to mesh_image.
+ * \brief Point site associate to graph_image.
*
* \todo Fix access to member.
*/
template<typename P>
- class mesh_psite : public Point_Site< mesh_psite<P> >
+ class graph_psite : public Point_Site< graph_psite<P> >
{
- typedef mesh_psite<P> self_;
+ typedef graph_psite<P> self_;
public:
typedef mln_mesh(P) mesh;
@@ -64,8 +64,8 @@
/// Construction and assignment.
/// \{
- mesh_psite(const mesh_p<P>& mesh_, unsigned i);
- mesh_psite(const self_& rhs);
+ graph_psite(const p_graph<P>& pg_, unsigned i);
+ graph_psite(const self_& rhs);
self_& operator= (const self_& rhs);
/// \}
@@ -74,7 +74,7 @@
coord operator[](unsigned i) const;
// FIXME: These shouldn't be public.
- const mesh_p<P>& mesh_;
+ const p_graph<P>& pg_;
unsigned i_;
};
@@ -82,56 +82,56 @@
template<typename P>
inline
- mesh_psite<P>::mesh_psite(const mesh_p<P>& mesh, unsigned i)
- : mesh_(mesh),
+ graph_psite<P>::graph_psite(const p_graph<P>& g, unsigned i)
+ : pg_(g),
i_(i)
{
}
template<typename P>
inline
- mesh_psite<P>::mesh_psite(const mesh_psite<P>& rhs)
- : mesh_(rhs.mesh_),
+ graph_psite<P>::graph_psite(const graph_psite<P>& rhs)
+ : pg_(rhs.pg_),
i_(rhs.i_)
{
}
template<typename P>
inline
- mesh_psite<P>&
- mesh_psite<P>::operator= (const mesh_psite<P>& rhs)
+ graph_psite<P>&
+ graph_psite<P>::operator= (const graph_psite<P>& rhs)
{
if (&rhs == this)
return *this;
// FIXME: Could we get rid of this cast?
- const_cast< mesh_p<P>& >(mesh_) = rhs.mesh_;
+ const_cast< p_graph<P>& >(pg_) = rhs.pg_;
i_ = rhs.i_;
return *this;
}
template<typename P>
inline
- mesh_psite<P>::operator P() const
+ graph_psite<P>::operator P() const
{
// FIXME: This is quite unsafe: we should check that i_ is a valid
// index before dereferencing loc_ to ensure clear error messages.
- return mesh_.loc_[i_];
+ return pg_.loc_[i_];
}
template<typename P>
inline
const P&
- mesh_psite<P>::to_point() const
+ graph_psite<P>::to_point() const
{
// FIXME: This is quite unsafe: we should check that i_ is a valid
// index before dereferencing loc_ to ensure clear error messages.
- return mesh_.loc_[i_];
+ return pg_.loc_[i_];
}
template<typename P>
inline
mln_coord(P)
- mesh_psite<P>::operator[](unsigned i) const
+ graph_psite<P>::operator[](unsigned i) const
{
return to_point()[i];
}
@@ -141,4 +141,4 @@
} // end of mln
-#endif // MLN_CORE_MESH_PSITE_HH
+#endif // MLN_CORE_GRAPH_PSITE_HH
Index: mln/core/p_graph.hh
--- mln/core/p_graph.hh (revision 1703)
+++ mln/core/p_graph.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -25,48 +25,47 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_MESH_P_HH
-# define MLN_CORE_MESH_P_HH
+#ifndef MLN_CORE_GRAPH_P_HH
+# define MLN_CORE_GRAPH_P_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>
-# include <mln/core/mesh_psite.hh>
-# include <mln/core/mesh_p_piter.hh>
+# include <mln/core/graph_psite.hh>
+# include <mln/core/p_graph_piter.hh>
-// FIXME: Rename as mesh_p_set? We shall definitely write a coding
-// style somewhere.
-
-/*! \file mln/core/mesh_p.hh
- *
- * \brief Definition of an point set based on graph.
- */
+/// \file mln/core/p_graph.hh
+/// \brief Definition of a point set based on graph.
namespace mln
{
- template<typename P> class mesh_p_piter_;
+ template<typename P> class p_graph_piter_;
template<typename P>
- struct mesh_p : public internal::point_set_base_< mesh_psite<P>, mesh_p<P> >
+ struct p_graph : public internal::point_set_base_< graph_psite<P>, p_graph<P> >
{
typedef util::graph<void> graph;
- /// Construct a mesh psite set from a graph and an array of locations.
- mesh_p (graph& gr, std::vector<P>& loc);
+ /// Construct a graph psite set from a graph and an array of locations.
+ p_graph (graph& gr, std::vector<P>& loc);
/// Point_Site associated type.
- typedef mesh_psite<P> psite;
+ typedef graph_psite<P> psite;
/// Forward Point_Iterator associated type.
- typedef mesh_p_piter_<P> fwd_piter;
+ typedef p_graph_piter_<P> fwd_piter;
/// Backward Point_Iterator associated type.
- typedef mesh_p_piter_<P> bkd_piter; // FIXME
+ typedef p_graph_piter_<P> bkd_piter;
+ /// Return The number of points (i.e., nodes) in the graph.
std::size_t npoints() const;
+ /// Return The number of lines (i.e., edges) in the graph.
+ std::size_t nlines() const;
+
/// Give the exact bounding box.
const box_<P>& bbox() const;
@@ -75,7 +74,7 @@
graph gr_;
std::vector<P> loc_;
// FIXME: (Roland) Is it really useful/needed?
- /* 2007-12-19: It seems so, since mesh_image must implement a method
+ /* 2007-12-19: It seems so, since graph_image must implement a method
named bbox(). Now the question is: should each image type have a
bounding box? */
box_<P> bb_;
@@ -85,7 +84,7 @@
template<typename P>
inline
- mesh_p<P>::mesh_p (util::graph<void>& gr, std::vector<P>& loc)
+ p_graph<P>::p_graph (util::graph<void>& gr, std::vector<P>& loc)
: gr_ (gr),
loc_ (loc)
{
@@ -98,15 +97,23 @@
template<typename P>
inline
std::size_t
- mesh_p<P>::npoints() const
+ p_graph<P>::npoints() const
{
return this->gr_.nb_node_;
}
template<typename P>
inline
+ std::size_t
+ p_graph<P>::nlines() const
+ {
+ return this->gr_.nb_link_;
+ }
+
+ template<typename P>
+ inline
const box_<P>&
- mesh_p<P>::bbox() const
+ p_graph<P>::bbox() const
{
return bb_;
}
@@ -114,7 +121,7 @@
template<typename P>
inline
bool
- mesh_p<P>::has(const psite& p) const
+ p_graph<P>::has(const psite& p) const
{
for (unsigned i = 0; i < loc_.size(); ++i)
if (loc_[i] == p)
@@ -128,4 +135,4 @@
} // end of mln
-#endif // MLN_CORE_MESH_P_HH
+#endif // MLN_CORE_P_GRAPH_HH
Index: mln/core/graph_window_piter.hh
--- mln/core/graph_window_piter.hh (revision 1703)
+++ mln/core/graph_window_piter.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -25,40 +25,42 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_MESH_WINDOW_PITER_HH
-# define MLN_CORE_MESH_WINDOW_PITER_HH
+#ifndef MLN_CORE_GRAPH_WINDOW_PITER_HH
+# define MLN_CORE_GRAPH_WINDOW_PITER_HH
-/*!
- * \file mln/core/mesh_window_piter.hh
- *
- * \brief Definition of point iterator of mesh window.
- *
- */
+/// \file mln/core/graph_window_piter.hh
+/// \brief Definition of a point iterator on a graph window.
# include <mln/core/concept/point_iterator.hh>
-# include <mln/core/mesh_p.hh>
-# include <mln/core/mesh_psite.hh>
+# include <mln/core/p_graph.hh>
+# include <mln/core/graph_psite.hh>
+/* FIXME: Doc. */
+
+/* FIXME: Due to the poor interface of mln::p_graph and
+ mln::util::graph, we show to much implementation details here.
+ Enrich their interfaces to avoid that. */
namespace mln
{
// Fwd decls.
- template <typename P> class mesh_p;
- template <typename P> class mesh_psite;
+ template <typename P> class p_graph;
+ template <typename P> class graph_psite;
template <typename P>
- class mesh_window_fwd_piter :
- public Point_Iterator< mesh_window_fwd_piter<P> > // or Iterator<...>?
+ class graph_window_fwd_piter :
+ public Point_Iterator< graph_window_fwd_piter<P> > // or Iterator<...>?
{
- typedef mesh_window_fwd_piter<P> self_;
+ typedef graph_window_fwd_piter<P> self_;
typedef Point_Iterator< self_ > super_;
public:
- typedef mesh_psite<P> psite;
+ typedef graph_psite<P> psite;
enum { dim = P::dim };
- typedef mesh_p<P> mesh;
+ // FIXME: Dummy value.
+ typedef void mesh;
typedef P point;
// FIXME: Dummy typedef.
@@ -67,8 +69,7 @@
public:
template <typename W, typename Pref>
- mesh_window_fwd_piter(const W& win,
- const Point_Site<Pref>& p_ref);
+ graph_window_fwd_piter(const W& win, const Point_Site<Pref>& p_ref);
bool is_valid() const;
void invalidate();
@@ -78,7 +79,7 @@
bool adjacent_or_equal_to_p_ref_() const;
// FIXME: In fact, this method should be named `to_psite', since
- // it return as mln::mesh_psite<P> object, not a P object.
+ // it returns a mln::graph_psite<P> object, not a P object.
const point& to_point() const;
operator psite () const;
coord operator[](unsigned i) const;
@@ -91,7 +92,7 @@
unsigned i_;
};
- // FIXME: mesh_window_bkd_piter.
+ // FIXME: Implement graph_window_bkd_piter.
# ifndef MLN_INCLUDE_ONLY
@@ -99,7 +100,7 @@
// FIXME: Currently, argument win is ignored.
template <typename P>
template <typename W, typename Pref>
- mesh_window_fwd_piter<P>::mesh_window_fwd_piter(const W& /* win */,
+ graph_window_fwd_piter<P>::graph_window_fwd_piter(const W& /* win */,
const Point_Site<Pref>& p_ref)
: p_ref_(exact(p_ref).to_psite())
{
@@ -109,24 +110,24 @@
template <typename P>
bool
- mesh_window_fwd_piter<P>::is_valid() const
+ graph_window_fwd_piter<P>::is_valid() const
{
// FIXME: We depend too much on the implementation of util::graph
// here. The util::graph should provide the service to abstract
// these manipulations.
- return i_ >= 0 && i_ < p_ref_.mesh_.gr_.nb_node_;
+ return i_ >= 0 && i_ < p_ref_.pg_.gr_.nb_node_;
}
template <typename P>
void
- mesh_window_fwd_piter<P>::invalidate()
+ graph_window_fwd_piter<P>::invalidate()
{
- i_ = p_ref_.mesh_.gr_.nb_node_;
+ i_ = p_ref_.pg_.gr_.nb_node_;
}
template <typename P>
void
- mesh_window_fwd_piter<P>::start()
+ graph_window_fwd_piter<P>::start()
{
i_ = 0;
if (!adjacent_or_equal_to_p_ref_())
@@ -135,7 +136,7 @@
template <typename P>
void
- mesh_window_fwd_piter<P>::next_()
+ graph_window_fwd_piter<P>::next_()
{
// FIXME: This is inefficient. The graph structure should be able
// to produce the set of adjacent nodes fast. Boost Graphs
@@ -148,7 +149,7 @@
template <typename P>
bool
- mesh_window_fwd_piter<P>::adjacent_or_equal_to_p_ref_() const
+ graph_window_fwd_piter<P>::adjacent_or_equal_to_p_ref_() const
{
// FIXME: Likewise, this is inefficient.
@@ -162,9 +163,9 @@
{
// Paranoid assertion.
assert (p_ref_.i_ >= 0 &&
- p_ref_.i_ < p_ref_.mesh_.gr_.nodes_.size ());
+ p_ref_.i_ < p_ref_.pg_.gr_.nodes_.size ());
const adjacency_type& p_ref_neighbs =
- p_ref_.mesh_.gr_.nodes_[p_ref_.i_]->links;
+ p_ref_.pg_.gr_.nodes_[p_ref_.i_]->links;
adjacency_type::const_iterator j =
std::find (p_ref_neighbs.begin(), p_ref_neighbs.end(), i_);
if (j != p_ref_neighbs.end())
@@ -174,7 +175,7 @@
// Check whether P_REF_ is among the neighbors of the iterator.
{
assert (is_valid ());
- const adjacency_type& i_neighbs = p_ref_.mesh_.gr_.nodes_[i_]->links;
+ const adjacency_type& i_neighbs = p_ref_.pg_.gr_.nodes_[i_]->links;
adjacency_type::const_iterator k =
std::find (i_neighbs.begin(), i_neighbs.end(), p_ref_.i_);
if (k != i_neighbs.end())
@@ -187,21 +188,21 @@
template <typename P>
const P&
- mesh_window_fwd_piter<P>::to_point() const
+ graph_window_fwd_piter<P>::to_point() const
{
- return p_ref_.mesh_.loc_[i_];
+ return p_ref_.pg_.loc_[i_];
}
template <typename P>
- mesh_window_fwd_piter<P>::operator mesh_psite<P> () const
+ graph_window_fwd_piter<P>::operator graph_psite<P> () const
{
- return mesh_psite<P>(p_ref_.mesh_, i_);
+ return graph_psite<P>(p_ref_.pg_, i_);
}
template <typename P>
inline
mln_coord(P)
- mesh_window_fwd_piter<P>::operator[](unsigned i) const
+ graph_window_fwd_piter<P>::operator[](unsigned i) const
{
assert(i < dim);
return to_point()[i];
@@ -211,4 +212,4 @@
} // end of namespace mln
-#endif // ! MLN_CORE_MESH_WINDOW_PITER_HH
+#endif // ! MLN_CORE_GRAPH_WINDOW_PITER_HH
Index: mln/core/graph_image.hh
--- mln/core/graph_image.hh (revision 1703)
+++ mln/core/graph_image.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -25,10 +25,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_MESH_IMAGE_HH
-# define MLN_CORE_MESH_IMAGE_HH
+#ifndef MLN_CORE_GRAPH_IMAGE_HH
+# define MLN_CORE_GRAPH_IMAGE_HH
-/*! \file mln/core/mesh_image.hh
+/*! \file mln/core/graph_image.hh
*
* \brief Definition of a graph-based image.
*/
@@ -37,8 +37,8 @@
# include <mln/core/internal/image_primary.hh>
# include <mln/metal/vec.hh>
-# include <mln/core/mesh_p.hh>
-# include <mln/core/mesh_psite.hh>
+# include <mln/core/p_graph.hh>
+# include <mln/core/graph_psite.hh>
# include <mln/value/set.hh>
# include <vector>
@@ -46,19 +46,19 @@
{
// Fwd decl.
- template <typename P, typename V> struct mesh_image;
+ template <typename P, typename V> struct graph_image;
namespace internal
{
- /// \internal Data structure for \c mln::mesh_image<P,V>.
+ /// \internal Data structure for \c mln::graph_image<P,V>.
template <typename P, typename V>
- struct data_< mesh_image<P, V> >
+ struct data_< graph_image<P, V> >
{
- data_(mesh_p<P>& mesh, std::vector<V>& val);
+ data_(p_graph<P>& g, std::vector<V>& val);
std::vector<V> val_;
- mesh_p<P>& mesh_;
+ p_graph<P>& pg_;
};
} // end of namespace mln::internal
@@ -68,7 +68,7 @@
{
template <typename P, typename V>
- struct image_< mesh_image<P, V> > : default_image_< V, mesh_image<P, V> >
+ struct image_< graph_image<P, V> > : default_image_< V, graph_image<P, V> >
{
typedef trait::image::category::primary category;
@@ -91,11 +91,11 @@
*
*/
template <typename P, typename V>
- struct mesh_image :
- public internal::image_primary_< mesh_p<P>, mesh_image<P, V> >
+ struct graph_image :
+ public internal::image_primary_< p_graph<P>, graph_image<P, V> >
{
- typedef mln::internal::image_base_< mesh_p<P>, mesh_image<P, V> > super_;
+ typedef mln::internal::image_base_< p_graph<P>, graph_image<P, V> > super_;
/// Value associated type.
typedef V value;
@@ -111,20 +111,20 @@
/// Skeleton.
- typedef mesh_image< tag::psite_<P>, tag::value_<V> > skeleton;
+ typedef graph_image< tag::psite_<P>, tag::value_<V> > skeleton;
/// Constructors.
- mesh_image(mesh_p<P>& mesh, std::vector<V>& val);
- mesh_image();
+ graph_image(p_graph<P>& g, std::vector<V>& val);
+ graph_image();
/// Initialize an empty image.
- void init_(mesh_p<P>& mesh, std::vector<V>& val);
+ void init_(p_graph<P>& g, std::vector<V>& val);
/// Read-only access of pixel value at point site \p p.
- const V& operator()(const mesh_psite<P>& p) const;
+ const V& operator()(const graph_psite<P>& p) const;
/// Read-write access of pixel value at point site \p p.
- V& operator()(const mesh_psite<P>& p);
+ V& operator()(const graph_psite<P>& p);
/// Give the set of values of the image.
const vset& values() const;
@@ -132,7 +132,7 @@
// FIXME: Keep this name?
const std::vector<V>& data_values () const;
- const mesh_p<P>& domain() const;
+ const p_graph<P>& domain() const;
/// Return the first node of the link at i from loc
const P& access_location_link_node1 (const unsigned& i) const;
@@ -144,7 +144,7 @@
// Fwd decl.
template <typename P, typename V>
void init_(tag::image_t,
- mesh_image<P, V>& target, const mesh_image<P, V>& model);
+ graph_image<P, V>& target, const graph_image<P, V>& model);
# ifndef MLN_INCLUDE_ONLY
@@ -156,7 +156,7 @@
template <typename P, typename V>
inline
void init_(tag::image_t,
- mesh_image<P, V>& target, const mesh_image<P, V>& model)
+ graph_image<P, V>& target, const graph_image<P, V>& model)
{
/* FIXME: Unfortunately, we cannot simply use
@@ -164,9 +164,9 @@
here, since domain() and data_values() return const data, and
init_ expects non mutable data. These constness problems exist
- also in mesh_psite (see uses of const_cast<>). Hence the
+ also in graph_psite (see uses of const_cast<>). Hence the
inelegant use of const_cast<>'s. */
- target.init_(const_cast<mesh_p<P>&> (model.domain()),
+ target.init_(const_cast<p_graph<P>&> (model.domain()),
const_cast<std::vector<V>&> (model.data_values ()));
}
@@ -178,9 +178,9 @@
{
template <typename P, typename V>
inline
- data_< mesh_image<P, V> >::data_(mesh_p<P>& mesh, std::vector<V>& val)
+ data_< graph_image<P, V> >::data_(p_graph<P>& g, std::vector<V>& val)
: val_ (val),
- mesh_ (mesh)
+ pg_ (g)
{
}
@@ -192,28 +192,28 @@
template <typename P, typename V>
inline
- mesh_image<P, V>::mesh_image(mesh_p<P>& mesh, std::vector<V>& val)
+ graph_image<P, V>::graph_image(p_graph<P>& g, std::vector<V>& val)
{
- init_(mesh, val);
+ init_(g, val);
}
template <typename P, typename V>
inline
- mesh_image<P, V>::mesh_image()
+ graph_image<P, V>::graph_image()
{
}
template <typename P, typename V>
inline
void
- mesh_image<P, V>::init_(mesh_p<P>& mesh, std::vector<V>& val)
+ graph_image<P, V>::init_(p_graph<P>& g, std::vector<V>& val)
{
/* FIXME: We leak memory here: calling init_ twice loses the
previous content pointed by data_.
We should definitely write down formal guidelines on
initialization and memory management in general! */
- this->data_ = new internal::data_< mesh_image<P, V> > (mesh, val);
+ this->data_ = new internal::data_< graph_image<P, V> > (g, val);
}
/*---------------.
@@ -223,9 +223,9 @@
template <typename P, typename V>
inline
const V&
- mesh_image<P, V>::operator()(const mesh_psite<P>& p) const
+ graph_image<P, V>::operator()(const graph_psite<P>& p) const
{
- mln_precondition(&p.mesh_ == &this->data_->mesh_);
+ mln_precondition(&p.pg_ == &this->data_->pg_);
mln_precondition(p.i_ < this->data_->val_.size());
return this->data_->val_[p.i_];
}
@@ -233,9 +233,9 @@
template <typename P, typename V>
inline
V&
- mesh_image<P, V>::operator()(const mesh_psite<P>& p)
+ graph_image<P, V>::operator()(const graph_psite<P>& p)
{
- mln_precondition(&p.mesh_ == &this->data_->mesh_);
+ mln_precondition(&p.pg_ == &this->data_->pg_);
mln_precondition(p.i_ < this->data_->val_.size());
return this->data_->val_[p.i_];
}
@@ -243,7 +243,7 @@
template <typename P, typename V>
inline
const mln::value::set<V> &
- mesh_image<P, V>::values() const
+ graph_image<P, V>::values() const
{
return vset::the();
}
@@ -251,24 +251,24 @@
template <typename P, typename V>
inline
const std::vector<V>&
- mesh_image<P, V>::data_values () const
+ graph_image<P, V>::data_values () const
{
return this->data_->val_;
}
template <typename P, typename V>
inline
- const mesh_p<P>&
- mesh_image<P, V>::domain() const
+ const p_graph<P>&
+ graph_image<P, V>::domain() const
{
mln_precondition(this->has_data());
- return this->data_->mesh_;
+ return this->data_->pg_;
}
template <typename P, typename V>
inline
const P&
- mesh_image<P, V>::access_location_link_node1 (const unsigned& i) const
+ graph_image<P, V>::access_location_link_node1 (const unsigned& i) const
{
// FIXME: This is ugly! Too much implementation details are shown here.
return this->domain().loc_[this->domain().gr_.links_[i]->pair_node_.first];
@@ -277,7 +277,7 @@
template <typename P, typename V>
inline
const P&
- mesh_image<P, V>::access_location_link_node2 (const unsigned& i) const
+ graph_image<P, V>::access_location_link_node2 (const unsigned& i) const
{
// FIXME: This is ugly! Too much implementation details are shown here.
return this->domain().loc_[this->domain().gr_.links_[i]->pair_node_.second];
@@ -288,4 +288,4 @@
} // end of namespace mln
-#endif // ! MLN_CORE_MESH_IMAGE_HH
+#endif // ! MLN_CORE_GRAPH_IMAGE_HH
Index: mln/core/p_graph_piter.hh
--- mln/core/p_graph_piter.hh (revision 1703)
+++ mln/core/p_graph_piter.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -25,14 +25,14 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_MESH_P_PITER_HH
-# define MLN_CORE_MESH_P_PITER_HH
+#ifndef MLN_CORE_P_GRAPH_PITER_HH
+# define MLN_CORE_P_GRAPH_PITER_HH
# include <mln/core/internal/point_iterator_base.hh>
-# include <mln/core/mesh_p.hh>
-# include <mln/core/mesh_psite.hh>
+# include <mln/core/p_graph.hh>
+# include <mln/core/graph_psite.hh>
-/*! \file mln/core/mesh_p_piter.hh
+/*! \file mln/core/p_graph_piter.hh
*
* \brief Definition of point iterator on graph-based point set.
*/
@@ -40,26 +40,27 @@
namespace mln
{
// Fwd decls.
- template<typename P> class mesh_p;
- template<typename P> class mesh_psite;
+ template<typename P> class p_graph;
+ template<typename P> class graph_psite;
- // FIXME: Why `mesh_p_piter_' and not `mesh_p_piter' (without `_')?
+ // FIXME: Why `p_graph_piter_' and not `p_graph_piter' (without `_')?
template<typename P>
- class mesh_p_piter_ : public internal::point_iterator_base_< P, mesh_p_piter_<P> >
+ class p_graph_piter_
+ : public internal::point_iterator_base_< P, p_graph_piter_<P> >
{
- typedef mesh_p_piter_<P> self_;
+ typedef p_graph_piter_<P> self_;
typedef internal::point_iterator_base_< P, self_ > super_;
public:
// Make definitions from super class available.
enum { dim = super_::dim };
- typedef mesh_psite<P> psite;
+ typedef graph_psite<P> psite;
typedef P point;
- mesh_p_piter_(const mesh_p<P>& psite_set);
+ p_graph_piter_(const p_graph<P>& psite_set);
/// Read-only access to the \p i-th coordinate.
mln_coord(P) operator[](unsigned i) const;
@@ -88,11 +89,11 @@
/// Convert the iterator into a point.
operator point() const;
- /// Convert the iterator into a mesh psite.
+ /// Convert the iterator into a graph psite.
operator psite() const;
protected:
- const mesh_p<P>& psite_set_;
+ const p_graph<P>& psite_set_;
unsigned i_;
P p_;
psite psite_;
@@ -104,7 +105,7 @@
template<typename P>
inline
- mesh_p_piter_<P>::mesh_p_piter_(const mesh_p<P>& psite_set)
+ p_graph_piter_<P>::p_graph_piter_(const p_graph<P>& psite_set)
: psite_set_(psite_set),
p_(),
// Initialize psite_ to a dummy value.
@@ -117,7 +118,7 @@
template<typename P>
inline
mln_coord(P)
- mesh_p_piter_<P>::operator[](unsigned i) const
+ p_graph_piter_<P>::operator[](unsigned i) const
{
return p_[i];
}
@@ -125,7 +126,7 @@
template<typename P>
inline
bool
- mesh_p_piter_<P>::is_valid() const
+ p_graph_piter_<P>::is_valid() const
{
return i_ != psite_set_.loc_.size();
}
@@ -133,7 +134,7 @@
template<typename P>
inline
void
- mesh_p_piter_<P>::invalidate()
+ p_graph_piter_<P>::invalidate()
{
i_ = psite_set_.loc_.size();
}
@@ -141,7 +142,7 @@
template<typename P>
inline
void
- mesh_p_piter_<P>::start()
+ p_graph_piter_<P>::start()
{
i_ = 0;
if (is_valid())
@@ -151,7 +152,7 @@
template<typename P>
inline
void
- mesh_p_piter_<P>::next_()
+ p_graph_piter_<P>::next_()
{
++i_;
if (is_valid())
@@ -161,18 +162,18 @@
template<typename P>
inline
void
- mesh_p_piter_<P>::update_()
+ p_graph_piter_<P>::update_()
{
// Update p_.
p_ = psite_set_.loc_[i_];
// Update psite_.
- psite_ = mesh_psite<P>(psite_set_, i_);
+ psite_ = graph_psite<P>(psite_set_, i_);
}
template<typename P>
inline
const P&
- mesh_p_piter_<P>::to_point() const
+ p_graph_piter_<P>::to_point() const
{
/* We don't check whether the iterator is valid before returning
the value using
@@ -190,8 +191,8 @@
template<typename P>
inline
- const mesh_psite<P>&
- mesh_p_piter_<P>::to_psite() const
+ const graph_psite<P>&
+ p_graph_piter_<P>::to_psite() const
{
/* We don't check whether the iterator is valid before returning
the value using
@@ -209,7 +210,7 @@
template<typename P>
inline
- mesh_p_piter_<P>::operator P() const
+ p_graph_piter_<P>::operator P() const
{
mln_precondition(is_valid());
return p_;
@@ -217,7 +218,7 @@
template<typename P>
inline
- mesh_p_piter_<P>::operator mesh_psite<P>() const
+ p_graph_piter_<P>::operator graph_psite<P>() const
{
mln_precondition(is_valid());
return psite_;
@@ -228,4 +229,4 @@
} // end of mln
-#endif // MLN_MESH_P_PITER_HH
+#endif // MLN_P_GRAPH_PITER_HH
Index: mln/core/graph_elt_window.hh
--- mln/core/graph_elt_window.hh (revision 1703)
+++ mln/core/graph_elt_window.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -25,39 +25,37 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_WIN_MESH_ELT_WINDOW_HH
-# define MLN_WIN_MESH_ELT_WINDOW_HH
+#ifndef MLN_WIN_GRAPH_ELT_WINDOW_HH
+# define MLN_WIN_GRAPH_ELT_WINDOW_HH
-/*! \file mln/core/mesh_elt_window.hh
+/*! \file mln/core/graph_elt_window.hh
*
- * \brief Definition of the elementary neighborhood (wrongly
- * -- but purposefully -- named "window" here, for consistency
- * reasons) on a mesh (a graph, in fact).
+ * \brief Definition of the elementary ``window'' on a graph.
*
* \todo Make naming coherent: we have window (without '_') but
* point_, neighb_, etc.
*/
# include <mln/core/concept/window.hh>
-# include <mln/core/mesh_psite.hh>
-# include <mln/core/mesh_window_piter.hh>
+# include <mln/core/graph_psite.hh>
+# include <mln/core/graph_window_piter.hh>
namespace mln
{
// Fwd decls.
- template <typename P> class mesh_window_fwd_piter;
- template <typename P> class mesh_window_bkd_piter;
+ template <typename P> class graph_window_fwd_piter;
+ template <typename P> class graph_window_bkd_piter;
- /*! \brief Elementary window on mesh class.
+ /*! \brief Elementary window on graph class.
*
* FIXME: Doc.
*/
template <typename P>
- class mesh_elt_window : public Window< mesh_elt_window<P> >
+ class graph_elt_window : public Window< graph_elt_window<P> >
{
- typedef mesh_elt_window<P> self_;
+ typedef graph_elt_window<P> self_;
public:
/// Associated types.
@@ -67,97 +65,101 @@
// psites, not points?
typedef P point;
- // FIXME: This is a dummy value. This is yet another evidence
- // that mesh_elt_window shall not be a Window, and therefore be
- // renamed as mesh_elt_neighb, or better: elt_graph_neighb.
+ // FIXME: This is a dummy value.
typedef void dpoint;
/*! \brief Point_Iterator type to browse the points of a generic window
* w.r.t. the ordering of delta-points.
*/
- typedef mesh_window_fwd_piter<P> fwd_qiter;
+ typedef graph_window_fwd_piter<P> fwd_qiter;
/*! \brief Point_Iterator type to browse the points of a generic window
* w.r.t. the reverse ordering of delta-points.
*/
- typedef mesh_window_bkd_piter<P> bkd_qiter;
+ typedef graph_window_bkd_piter<P> bkd_qiter;
/// The default qiter type.
typedef fwd_qiter qiter;
/// \}
- /// Construct an elementary mesh window centered on \a psite.
- mesh_elt_window(/*const mesh_psite<P>& psite*/);
+ /// Construct an elementary graph window.
+ graph_elt_window();
- // FIXME: The following methods make no sense for a
- // general-purpose neighborhood. Anyway, we provide
- // implementations for them for this first draft of graph
- // neighborhood.
+ /// Is the window is empty?
bool is_empty() const;
+
+ /// Is the window centered?
bool is_centered() const;
+
+ /// Is the window symmetric?
+ // FIXME: We should defin this more precisely.
bool is_symmetric() const;
- unsigned delta() const;
- self_& sym();
- // protected:
- // const mesh_psite<P>& psite_;
- };
+ /// Return the maximum coordinate gap between the window center
+ /// and a window point.
+ /* FIXME: This method returns a dummy value (0), since the delta
+ of a window on a graph
+ 1. is not constant (graph nodes are not necessarily aligned on
+ a regular grid);
- // FIXME: Add an operator<< on ostreams ?
+ 2. depends on the underlying graph, too.
+
+ It raises another question: should delta() be part of the
+ concept ``Window''? */
+ unsigned delta() const;
+
+ /// Apply a central symmetry to the target window.
+ self_& sym();
+ };
# ifndef MLN_INCLUDE_ONLY
template <typename P>
inline
- mesh_elt_window<P>::mesh_elt_window(/*const mesh_psite<P>& psite*/)
- // : psite_(psite)
+ graph_elt_window<P>::graph_elt_window()
{
}
template <typename P>
inline
bool
- mesh_elt_window<P>::is_empty() const
+ graph_elt_window<P>::is_empty() const
{
- // FIXME: Dummy value.
return false;
}
template <typename P>
inline
bool
- mesh_elt_window<P>::is_centered() const
+ graph_elt_window<P>::is_centered() const
{
- // FIXME: Dummy value.
return false;
}
template <typename P>
inline
bool
- mesh_elt_window<P>::is_symmetric() const
+ graph_elt_window<P>::is_symmetric() const
{
- // FIXME: Dummy value.
- return false;
+ return true;
}
template <typename P>
inline
unsigned
- mesh_elt_window<P>::delta() const
+ graph_elt_window<P>::delta() const
{
- // FIXME: Dummy value.
+ // Dummy value (see the interface of the method above).
return 0;
}
template <typename P>
inline
- mesh_elt_window<P>&
- mesh_elt_window<P>::sym()
+ graph_elt_window<P>&
+ graph_elt_window<P>::sym()
{
- // FIXME: Dummy value.
return *this;
}
@@ -166,4 +168,4 @@
} // end of namespace mln
-#endif // ! MLN_WIN_MESH_ELT_WINDOW_HH
+#endif // ! MLN_WIN_GRAPH_ELT_WINDOW_HH
Index: mln/draw/graph.hh
--- mln/draw/graph.hh (revision 1703)
+++ mln/draw/graph.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -25,103 +25,101 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_DRAW_MESH_HH
-# define MLN_DRAW_MESH_HH
+#ifndef MLN_DRAW_GRAPH_HH
+# define MLN_DRAW_GRAPH_HH
-/*! \file mln/draw/mesh.hh
- *
- * \brief Draw an image from type mesh_image.
- *
- */
+/// \file mln/draw/graph.hh
+/// \brief Draw an (classical) image from a mln::graph_image.
# include <mln/pw/image.hh>
# include <mln/level/fill.hh>
# include <mln/draw/line.hh>
-# include <mln/core/mesh_p.hh>
-# include <mln/core/mesh_image.hh>
+# include <mln/core/p_graph.hh>
+# include <mln/core/graph_image.hh>
namespace mln
{
namespace draw
{
- /* FIXME: `draw::mesh' is not a good name. These functions do not
- actually draw the mesh/mesh_image; it *converts* it to a
+ /* FIXME: `draw::graph' is not a good name. These functions do not
+ actually _draw_ the graph/graph_image; it *converts* it to a
printable image. These functions should be put elsewhere
(e.g., in debug::). */
- /*! Draw an image \p ima from a mesh_p \p m, with value \p node_v
- * for nodes, value \p link_v for links and 0 for the background.
+ /*! \brief Draw an image \p ima from a mln::p_graph \p pg, with
+ * value \p node_v for nodes, value \p link_v for links and 0 for
+ * the background.
*
* \param[in,out] ima The image to be drawn.
- * \param[in] m The mesh_p which contains nodes and links positions.
- * \param[in] node_v The value to assign to pixels which contains nodes.
- * \param[in] link_v The value to assign to pixels which contains links.
- *
+ * \param[in] pg The p_graph which contains nodes and links
+ * positions.
+ * \param[in] node_v The value to assign to pixels which contains
+ * nodes.
+ * \param[in] link_v The value to assign to pixels which contains
+ * links.
*/
template <typename I, typename P>
void
- mesh(Image<I>& ima, const mesh_p<P>& m,
- mln_value(I) node_v,
- mln_value(I) link_v);
+ graph(Image<I>& ima, const p_graph<P>& pg,
+ mln_value(I) node_v, mln_value(I) link_v);
- /*! Draw an image \p ima from a mesh_image \p mesh.
- * The background is filled to value 0.
+ /*! \brief Draw an image \p ima from a mln::graph_image \p gi.
+ *
+ * The background is filled with value 0.
*
* \param[in,out] ima The image to be drawn.
- * \param[in] mesh The mesh_image which contains nodes, links
+ * \param[in] gi The graph_image which contains the nodes, links
* positions and the values of it.
- * \param[in] link_v The value to assign to pixels which contains links,
- * defaulting to 1.
- *
+ * \param[in] link_v The value to assign to pixels which contains
+ * links, defaulting to 1.
*/
// FIXME: The type of the last argument cannot always been
// constructed from `int'! We should remove this last argument.
template <typename I, typename P, typename V>
void
- mesh(Image<I>& ima, const mesh_image<P, V>& mesh,
+ graph(Image<I>& ima, const graph_image<P, V>& gi,
mln_value(I) link_v = 1);
# ifndef MLN_INCLUDE_ONLY
// FIXME: Add assertions on the size of the image: it must be large
- // enough to hold the reprensentation of the graph.
+ // enough to hold the representation of the graph/graph_image.
template <typename I, typename P>
inline
void
- mesh(Image<I>& ima, const mesh_p<P>& m,
- mln_value(I) node_v,
- mln_value(I) link_v)
+ graph(Image<I>& ima, const p_graph<P>& pg,
+ mln_value(I) node_v, mln_value(I) link_v)
{
level::fill(ima, 0);
- for (unsigned i = 0; i < m.gr_.nb_link_; ++i)
+ for (unsigned i = 0; i < pg.nlines(); ++i)
line (exact(ima),
- m.loc_[m.gr_.links_[i]->pair_node_.first],
- m.loc_[m.gr_.links_[i]->pair_node_.second],
+ pg.loc_[pg.gr_.links_[i]->pair_node_.first],
+ pg.loc_[pg.gr_.links_[i]->pair_node_.second],
link_v);
- for (unsigned i = 0; i < m.gr_.nb_node_; ++i)
- exact(ima)(m.loc_[i]) = node_v;
+ for (unsigned i = 0; i < pg.npoints(); ++i)
+ exact(ima)(pg.loc_[i]) = node_v;
}
template <typename I, typename P, typename V>
inline
void
- mesh(Image<I>& ima, const mesh_image<P, V>& mesh,
+ graph(Image<I>& ima, const graph_image<P, V>& gi,
mln_value(I) link_v)
{
level::fill(ima, 0);
- for (unsigned i = 0; i < mesh.domain().gr_.nb_link_; ++i)
+ for (unsigned i = 0; i < gi.domain().nlines(); ++i)
line (exact(ima),
- mesh.access_location_link_node1 (i),
- mesh.access_location_link_node2 (i),
+ gi.access_location_link_node1 (i),
+ gi.access_location_link_node2 (i),
link_v);
- for (unsigned i = 0; i < mesh.domain().gr_.nb_node_; ++i)
- exact(ima)(mesh.domain().loc_[i]) = mesh.data_values ()[i];
+ for (unsigned i = 0; i < gi.domain().npoints(); ++i)
+ exact(ima)(gi.domain().loc_[i]) = gi.data_values ()[i];
}
# endif // ! MLN_INCLUDE_ONLY
@@ -130,4 +128,4 @@
} // end of namespace mln
-#endif // MLN_MESH_PSITE_HH
+#endif // MLN_GRAPH_PSITE_HH
Index: tests/core/graph_elt_window.cc
--- tests/core/graph_elt_window.cc (revision 1703)
+++ tests/core/graph_elt_window.cc (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -25,15 +25,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/core/mesh_elt_window.cc
+/*! \file tests/core/graph_elt_window.cc
*
- * \brief Tests on mln::win::mesh_elt_window.
+ * \brief Tests on mln::win::graph_elt_window.
*/
#include <vector>
#include <mln/core/point2d.hh>
-#include <mln/core/mesh_elt_window.hh>
+#include <mln/core/graph_elt_window.hh>
#include <mln/debug/iota.hh>
#include <mln/debug/println.hh>
@@ -70,13 +70,13 @@
g.add_edge(4, 2);
/*------------------.
- | Mesh and window. |
+ | Graph and window. |
`------------------*/
- // Mesh psite set.
- mesh_p<p_t> mesh(g, points);
- // Mesh point site.
- mesh_psite<p_t> psite(mesh, 0);
- // ``Sliding'' window (in fact, neighborhood) of a psite of MESH.
- mesh_elt_window<p_t> win;
+ // Graph psite set.
+ p_graph<p_t> pg(g, points);
+ // Graph point site.
+ graph_psite<p_t> psite(pg, 0);
+ // ``Sliding'' window (in fact, neighborhood) of a psite of PG.
+ graph_elt_window<p_t> win;
}
Index: tests/core/graph_image.cc
--- tests/core/graph_image.cc (revision 1703)
+++ tests/core/graph_image.cc (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -25,19 +25,19 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file tests/core/mesh_image.cc
-/// \brief Tests on mln::mesh_image.
+/// \file tests/core/graph_image.cc
+/// \brief Tests on mln::graph_image.
#include <vector>
#include <mln/core/point2d.hh>
-#include <mln/core/mesh_image.hh>
-#include <mln/core/mesh_elt_window.hh>
-#include <mln/core/mesh_window_piter.hh>
+#include <mln/core/graph_image.hh>
+#include <mln/core/graph_elt_window.hh>
+#include <mln/core/graph_window_piter.hh>
#include <mln/morpho/dilation.hh>
-#include <mln/draw/mesh.hh>
+#include <mln/draw/graph.hh>
#include <mln/debug/iota.hh>
#include <mln/debug/println.hh>
@@ -71,45 +71,45 @@
g.add_edge(4, 2);
/*-------.
- | Mesh. |
+ | Graph. |
`-------*/
- mesh_p<point2d> mesh(g, points);
+ p_graph<point2d> pg(g, points);
/*-------------.
- | Mesh image. |
+ | Graph image. |
`-------------*/
// Values ("empty" vector).
std::vector<int> values(5);
- // Mesh image.
- typedef mesh_image<point2d, int> ima_t;
- ima_t ima(mesh, values);
+ // Graph image.
+ typedef graph_image<point2d, int> ima_t;
+ ima_t ima(pg, values);
// Initialize values.
debug::iota(ima);
// Print the image.
- /* FIXME: Unfortunately, displaying mesh images is not easy right
- now (2007-12-19). We could use
+ /* FIXME: Unfortunately, displaying graph images is not easy right
+ now (2008-02-05). We could use
debug::println(ima);
- but there's not specialization working for mesh_image; the one
+ but there's not specialization working for graph_image; the one
selected by the compiler is based on a 2-D bbox, and expects the
- interface of mesh_image to work with points (not psites).
- Moreover, this iplementation only shows *values*, not the graph
+ interface of graph_image to work with points (not psites).
+ Moreover, this implementation only shows *values*, not the graph
itslef.
- An alternative is to use draw::mesh (which, again, is misnamed),
+ An alternative is to use draw::graph (which, again, is misnamed),
but it doesn't show the values, only the nodes and edges of the
graph.
- The current solution is a mix between draw::mesh and hand-made
+ The current solution is a mix between draw::graph and hand-made
iterations. */
image2d<int> ima_rep(ima.bbox());
- // We use the value 9 in draw::mesh instead of the default (which is
+ // We use the value 9 in draw::graph instead of the default (which is
// 1) to represent edges to distinguish it from nodes holding a
// value of 1.
- draw::mesh (ima_rep, ima, 9);
+ draw::graph (ima_rep, ima, 9);
debug::println (ima_rep);
@@ -123,10 +123,7 @@
std::cout << "ima (" << p << ") = " << ima(p) << std::endl;
// Manual iterations over the neighborhoods of each point site of IMA.
- /* FIXME: In fact, this class should be named
- `mesh_elt_neighborhood' (there's no such thing as an elementary
- window on a mesh/graph!). */
- typedef mesh_elt_window<point2d> win_t;
+ typedef graph_elt_window<point2d> win_t;
win_t win;
mln_qiter_(win_t) q(win, p);
for_all (p)
@@ -136,16 +133,17 @@
for_all (q)
std::cout << " " << q << " (level = " << ima(q) << ")" << std::endl;
}
+ std::cout << std::endl;
/*-------------------------.
- | Processing mesh images. |
+ | Processing graph images. |
`-------------------------*/
- mesh_image<point2d, int> ima_dil = morpho::dilation(ima, win);
- draw::mesh(ima_rep, ima_dil, 9);
+ graph_image<point2d, int> ima_dil = morpho::dilation(ima, win);
+ draw::graph(ima_rep, ima_dil, 9);
debug::println(ima_rep);
- mesh_image<point2d, int> ima_ero = morpho::erosion(ima, win);
- draw::mesh(ima_rep, ima_ero, 9);
+ graph_image<point2d, int> ima_ero = morpho::erosion(ima, win);
+ draw::graph(ima_rep, ima_ero, 9);
debug::println(ima_rep);
}
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 1703)
+++ tests/core/Makefile.am (working copy)
@@ -8,8 +8,8 @@
exact \
h_vec \
initialize \
- mesh_elt_window \
- mesh_image \
+ graph_elt_window \
+ graph_image \
mono_obased_rle_image \
mono_rle_image \
obased_rle_image \
@@ -29,8 +29,8 @@
exact_SOURCES = exact.cc
h_vec_SOURCES = h_vec.cc
initialize_SOURCES = initialize.cc
-mesh_elt_window_SOURCES = mesh_elt_window.cc
-mesh_image_SOURCES = mesh_image.cc
+graph_elt_window_SOURCES = graph_elt_window.cc
+graph_image_SOURCES = graph_image.cc
mono_obased_rle_image_SOURCES = mono_obased_rle_image.cc
mono_rle_image_SOURCES = mono_rle_image.cc
obased_rle_image_SOURCES = obased_rle_image.cc
Index: tests/draw/graph.cc
--- tests/draw/graph.cc (revision 1703)
+++ tests/draw/graph.cc (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -25,9 +25,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/draw/mesh.cc
+/*! \file tests/draw/graph.cc
*
- * \brief Tests on mln::draw::mesh.
+ * \brief Tests on mln::draw::graph.
*
* Build a graph, convert it to an image, and compare it with a
* reference images.
@@ -40,10 +40,10 @@
#include <mln/core/point2d.hh>
#include <mln/debug/println.hh>
#include <mln/util/graph.hh>
-#include <mln/core/mesh_p.hh>
-#include <mln/core/mesh_psite.hh>
-#include <mln/draw/mesh.hh>
-#include <mln/core/mesh_image.hh>
+#include <mln/core/p_graph.hh>
+#include <mln/core/graph_psite.hh>
+#include <mln/draw/graph.hh>
+#include <mln/core/graph_image.hh>
#include <mln/level/compare.hh>
@@ -71,12 +71,10 @@
// Check its consistency.
g.consistency ();
- mln::mesh_p<point2d> m(g, points);
+ mln::p_graph<point2d> pg(g, points);
image2d<int> ima(nrows, ncols);
- // FIXME: `draw::mesh' is not a good name. This function doesn't
- // actually draw the mesh; it *converts* it to a printable image.
- draw::mesh (ima, m, 2, 1);
+ draw::graph (ima, pg, 2, 1);
mln_assertion (ima == ref);
}
Index: tests/draw/Makefile.am
--- tests/draw/Makefile.am (revision 1703)
+++ tests/draw/Makefile.am (working copy)
@@ -5,10 +5,10 @@
check_PROGRAMS = \
all_headers \
line \
- mesh
+ graph
all_headers_SOURCES = all_headers.cc
line_SOURCES = line.cc
-mesh_SOURCES = mesh.cc
+graph_SOURCES = graph.cc
TESTS = $(check_PROGRAMS)
1
1
1703: Fix mesh_image w.r.t. the recently updated interface of graphs.
by Roland Levillain 05 Feb '08
by Roland Levillain 05 Feb '08
05 Feb '08
https://svn.lrde.epita.fr/svn/oln/trunk/milena
When altering something as central as a graph class, please pay attention
to all client code using it! Thanks in advance.
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Fix mesh_image w.r.t. the recently updated interface of graphs.
* mln/core/mesh_image.hh:
(mesh_image<P, V>::access_location_link_node1 (const unsigned&))
(mesh_image<P, V>::access_location_link_node2 (const unsigned&)):
Catch up with the new interface of mln::util::s_edge.
mesh_image.hh | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
Index: mln/core/mesh_image.hh
--- mln/core/mesh_image.hh (revision 1702)
+++ mln/core/mesh_image.hh (working copy)
@@ -212,7 +212,7 @@
previous content pointed by data_.
We should definitely write down formal guidelines on
- initializaion and memory management in general! */
+ initialization and memory management in general! */
this->data_ = new internal::data_< mesh_image<P, V> > (mesh, val);
}
@@ -270,7 +270,8 @@
const P&
mesh_image<P, V>::access_location_link_node1 (const unsigned& i) const
{
- return this->domain().loc_[this->domain().gr_.links_[i]->node1];
+ // FIXME: This is ugly! Too much implementation details are shown here.
+ return this->domain().loc_[this->domain().gr_.links_[i]->pair_node_.first];
}
template <typename P, typename V>
@@ -278,7 +279,8 @@
const P&
mesh_image<P, V>::access_location_link_node2 (const unsigned& i) const
{
- return this->domain().loc_[this->domain().gr_.links_[i]->node2];
+ // FIXME: This is ugly! Too much implementation details are shown here.
+ return this->domain().loc_[this->domain().gr_.links_[i]->pair_node_.second];
}
# endif // ! MLN_INCLUDE_ONLY
1
0
05 Feb '08
https://svn.lrde.epita.fr/svn/oln/trunk/milena
This is just a fix. There's still some work to do there (see
https://trac.lrde.org/olena/ticket/134)
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Have the documentation compile again with parallel builds.
* doc/Makefile.am (html-local, html_user): Fix paths.
(Doxyfile): Likewise.
Use information from Milena's ChangeLog, not from the top-most
ChangeLog.
Makefile.am | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
Index: doc/Makefile.am
--- doc/Makefile.am (revision 1701)
+++ doc/Makefile.am (working copy)
@@ -1,3 +1,5 @@
+# FIXME: To be overhauled! (See ticket #134).
+
DOXYGEN = doxygen
.PHONY: doc user-doc internal-doc html html_user
@@ -10,10 +12,10 @@
html-local: Doxyfile
- $(DOXYGEN) $(srcdir)/Doxyfile_internal
+ $(DOXYGEN) Doxyfile_internal
-html_user:: Doxyfile
- $(DOXYGEN) $(srcdir)/Doxyfile_user
+html_user: Doxyfile
+ $(DOXYGEN) Doxyfile_user
edit = sed -e "s|@ID@|$$Id|" \
@@ -22,6 +24,10 @@
-e 's,@top_builddir\@,$(top_builddir),g' \
-e 's,@top_srcdir\@,$(top_srcdir),g'
+# FIXME: This is not good. We should set these parameters for both
+# documentation (internal and user) using @VARIABLES@. Don't generate
+# Doxyfile_user from Doxyfile_internal! Both should be a product
+# derived from a single source, Doxyfile.in.
edit_user = sed -e 's,OUTPUT_DIRECTORY = ./internal/,OUTPUT_DIRECTORY = ./user/,g' \
-e 's,EXTRACT_ALL = YES,EXTRACT_ALL = NO,g' \
-e 's,EXTRACT_PRIVATE = YES,EXTRACT_PRIVATE = NO,g' \
@@ -44,10 +50,10 @@
# configure, because the former is way faster than the latter.
# Moreover, this file is updated whenever ChangeLog is touched: using
# sed instead of configure saves us a lot of time.
-Doxyfile: $(top_srcdir)/ChangeLog $(srcdir)/Doxyfile.in
- Id=`grep '^\$$Id' $(top_srcdir)/ChangeLog`; \
- $(edit) $(srcdir)/Doxyfile.in >Doxyfile_internal; \
- $(edit_user) $(srcdir)/Doxyfile_internal >Doxyfile_user
+Doxyfile: $(top_srcdir)/milena/ChangeLog $(srcdir)/Doxyfile.in
+ Id=`grep '^\$$Id' $(top_srcdir)/milena/ChangeLog`; \
+ $(edit) $(srcdir)/Doxyfile.in >Doxyfile_internal && \
+ $(edit_user) Doxyfile_internal >Doxyfile_user
clean-local:
rm -rf internal user
1
0