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
1725: Add neighborhoods and corresponding piters for graph-based images.
by Roland Levillain 14 Feb '08
by Roland Levillain 14 Feb '08
14 Feb '08
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add neighborhoods and corresponding piters for graph-based images.
* mln/core/graph_elt_neighborhood.hh,
* mln/core/graph_neighborhood_piter.hh,
* mln/core/line_graph_elt_neighborhood.hh,
* mln/core/line_graph_neighborhood_piter.hh:
New.
* mln/core/graph_elt_window.hh,
* mln/core/graph_window_piter.hh,
* mln/core/line_graph_elt_window.hh,
* mln/core/line_graph_window_piter.hh:
More FIXME.
* mln/convert/to_window.hh (convert::nbh_to_win_trait):
New trait.
(convert::to_window(const Neighborhood<N>&)): Turn this into a
facade dispatching to...
(convert::impl::to_window(const N&))
(convert::impl::to_window(const line_graph_elt_neighborhood<P>&)):
...these (new) implementations.
* mln/convert/to_p_array.hh: Wrap long lines.
convert/to_p_array.hh | 10 +-
convert/to_window.hh | 81 +++++++++++++++++----
core/graph_elt_neighborhood.hh | 131 +++++++---------------------------
core/graph_elt_window.hh | 6 +
core/graph_neighborhood_piter.hh | 76 ++++++++++++-------
core/graph_window_piter.hh | 22 +++++
core/line_graph_elt_neighborhood.hh | 128 ++++++---------------------------
core/line_graph_elt_window.hh | 6 +
core/line_graph_neighborhood_piter.hh | 89 +++++++++++++----------
core/line_graph_window_piter.hh | 14 +++
10 files changed, 277 insertions(+), 286 deletions(-)
Index: mln/core/graph_elt_neighborhood.hh
--- mln/core/graph_elt_neighborhood.hh (revision 1723)
+++ mln/core/graph_elt_neighborhood.hh (working copy)
@@ -25,147 +25,72 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_GRAPH_ELT_WINDOW_HH
-# define MLN_CORE_GRAPH_ELT_WINDOW_HH
+#ifndef MLN_CORE_GRAPH_ELT_NEIGHBORHOOD_HH
+# define MLN_CORE_GRAPH_ELT_NEIGHBORHOOD_HH
-/*! \file mln/core/graph_elt_window.hh
+/*! \file mln/core/graph_elt_neighborhood.hh
*
- * \brief Definition of the elementary ``window'' on a graph.
+ * \brief Definition of the elementary ``neighborhood'' on a graph.
*
- * \todo Make naming coherent: we have window (without '_') but
+ * \todo Make naming coherent: we have neighborhood (without '_') but
* point_, neighb_, etc.
*/
-# include <mln/core/concept/window.hh>
+/* FIXME: Factor those classes:
+ - mln::graph_elt_window
+ - mln::graph_elt_neighborhood
+ - mln::line_graph_elt_window
+ - mln::line_graph_elt_neighborhood. */
+
+# include <mln/core/concept/neighborhood.hh>
# include <mln/core/graph_psite.hh>
-# include <mln/core/graph_window_piter.hh>
+# include <mln/core/graph_neighborhood_piter.hh>
namespace mln
{
// Fwd decls.
- template <typename P> class graph_window_fwd_piter;
- template <typename P> class graph_window_bkd_piter;
+ template <typename P> class graph_neighborhood_fwd_piter;
+ template <typename P> class graph_neighborhood_bkd_piter;
- /*! \brief Elementary window on graph class.
+ /*! \brief Elementary neighborhood on graph class.
*
* FIXME: Doc.
*/
template <typename P>
- class graph_elt_window : public Window< graph_elt_window<P> >
+ class graph_elt_neighborhood
+ : public Neighborhood< graph_elt_neighborhood<P> >
{
- typedef graph_elt_window<P> self_;
+ typedef graph_elt_neighborhood<P> self_;
public:
/// Associated types.
/// \{
- /// The type of point stored into the window.
- // FIXME: Is this right, if we consider that this window stores
+ /// The type of point stored into the neighborhood.
+ // FIXME: Is this right, if we consider that this neighborhood stores
// psites, not points?
typedef P point;
// 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.
+ /*! \brief Point_Iterator type to browse the points of a generic
+ * neighborhood w.r.t. the ordering of delta-points.
*/
- typedef graph_window_fwd_piter<P> fwd_qiter;
+ typedef graph_neighborhood_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.
+ /*! \brief Point_Iterator type to browse the points of a generic
+ * neighborhood w.r.t. the reverse ordering of delta-points.
*/
- typedef graph_window_bkd_piter<P> bkd_qiter;
+ typedef graph_neighborhood_bkd_piter<P> bkd_qiter;
/// The default qiter type.
typedef fwd_qiter qiter;
/// \}
-
- /// Construct an elementary graph window.
- graph_elt_window();
-
- /// 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;
-
- /// 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);
-
- 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
- graph_elt_window<P>::graph_elt_window()
- {
- }
-
- template <typename P>
- inline
- bool
- graph_elt_window<P>::is_empty() const
- {
- return false;
- }
-
- template <typename P>
- inline
- bool
- graph_elt_window<P>::is_centered() const
- {
- return false;
- }
-
- template <typename P>
- inline
- bool
- graph_elt_window<P>::is_symmetric() const
- {
- return true;
- }
-
- template <typename P>
- inline
- unsigned
- graph_elt_window<P>::delta() const
- {
- // Dummy value (see the interface of the method above).
- return 0;
- }
-
- template <typename P>
- inline
- graph_elt_window<P>&
- graph_elt_window<P>::sym()
- {
- return *this;
- }
-
-# endif // ! MLN_INCLUDE_ONLY
-
} // end of namespace mln
-#endif // ! MLN_CORE_GRAPH_ELT_WINDOW_HH
+#endif // ! MLN_CORE_GRAPH_ELT_NEIGHBORHOOD_HH
Index: mln/core/graph_neighborhood_piter.hh
--- mln/core/graph_neighborhood_piter.hh (revision 1723)
+++ mln/core/graph_neighborhood_piter.hh (working copy)
@@ -25,11 +25,25 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_GRAPH_WINDOW_PITER_HH
-# define MLN_CORE_GRAPH_WINDOW_PITER_HH
+#ifndef MLN_CORE_GRAPH_NEIGHBORHOOD_PITER_HH
+# define MLN_CORE_GRAPH_NEIGHBORHOOD_PITER_HH
-/// \file mln/core/graph_window_piter.hh
-/// \brief Definition of a point iterator on a graph window.
+/// \file mln/core/graph_neighborhood_piter.hh
+/// \brief Definition of a point iterator on a graph neighborhood.
+
+/* FIXME: Factor those classes:
+
+ - mln::graph_window_fwd_piter
+ - mln::graph_neighborhood_fwd_piter
+ - mln::line_graph_window_fwd_piter
+ - mln::line_graph_neighborhood_fwd_piter.
+
+ and later (when they get implemented):
+
+ - mln::graph_window_bkd_piter
+ - mln::graph_neighborhood_bkd_piter
+ - mln::line_graph_window_bkd_piter
+ - mln::line_graph_neighborhood_bkd_piter. */
# include <mln/core/concept/point_iterator.hh>
# include <mln/core/p_graph.hh>
@@ -48,11 +62,15 @@
template <typename P> class graph_psite;
+ /*----------------------------------.
+ | graph_neighborhood_fwd_piter<P>. |
+ `----------------------------------*/
+
template <typename P>
- class graph_window_fwd_piter :
- public Point_Iterator< graph_window_fwd_piter<P> > // or Iterator<...>?
+ class graph_neighborhood_fwd_piter :
+ public Point_Iterator< graph_neighborhood_fwd_piter<P> > // or Iterator<...>?
{
- typedef graph_window_fwd_piter<P> self_;
+ typedef graph_neighborhood_fwd_piter<P> self_;
typedef Point_Iterator< self_ > super_;
public:
@@ -68,8 +86,8 @@
typedef mln_coord(P) coord;
public:
- template <typename W, typename Pref>
- graph_window_fwd_piter(const W& win, const Point_Site<Pref>& p_ref);
+ template <typename N, typename Pref>
+ graph_neighborhood_fwd_piter(const N& nbh, const Point_Site<Pref>& p_ref);
bool is_valid() const;
void invalidate();
@@ -92,7 +110,7 @@
coord operator[](unsigned i) const;
private:
- /// The ``central'' psite of the window.
+ /// The ``central'' psite of the neighborhood.
const psite& p_ref_;
/// An internal iterator on the set of nodes of the underlying graph.
util::node_id id_;
@@ -102,16 +120,18 @@
point p_;
};
- // FIXME: Implement graph_window_bkd_piter.
+ /*----------------------------------.
+ | graph_neighborhood_bkd_piter<P>. |
+ `----------------------------------*/
# ifndef MLN_INCLUDE_ONLY
- // FIXME: Currently, argument win is ignored.
+ // FIXME: Currently, argument nbh is ignored.
template <typename P>
- template <typename W, typename Pref>
+ template <typename N, typename Pref>
inline
- graph_window_fwd_piter<P>::graph_window_fwd_piter(const W& /* win */,
+ graph_neighborhood_fwd_piter<P>::graph_neighborhood_fwd_piter(const N& /* nbh */,
const Point_Site<Pref>& p_ref)
: p_ref_(exact(p_ref).to_psite()),
// Initialize psite_ to a dummy value.
@@ -125,7 +145,7 @@
template <typename P>
inline
bool
- graph_window_fwd_piter<P>::is_valid() const
+ graph_neighborhood_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
@@ -136,7 +156,7 @@
template <typename P>
inline
void
- graph_window_fwd_piter<P>::invalidate()
+ graph_neighborhood_fwd_piter<P>::invalidate()
{
id_ = p_ref_.pg().gr_.nnodes();
}
@@ -144,7 +164,7 @@
template <typename P>
inline
void
- graph_window_fwd_piter<P>::start()
+ graph_neighborhood_fwd_piter<P>::start()
{
id_ = 0;
if (!adjacent_or_equal_to_p_ref_())
@@ -159,15 +179,15 @@
template <typename P>
inline
void
- graph_window_fwd_piter<P>::next_()
+ graph_neighborhood_fwd_piter<P>::next_()
{
/* FIXME: This is inefficient. The graph structure should be able
to produce the set of adjacent nodes fast. Boost Graphs
probably provides adequates structures to fetch these
neighbors in constant time. */
/* FIXME: Moreover, the behavior of next shall depend on the
- window, which is not the case now! (Currently, next_() behaves
- as win was always an elementary window.) */
+ neighborhood, which is not the case now! (Currently, next_() behaves
+ as nbh was always an elementary neighborhood.) */
do
++id_;
while (is_valid() && !adjacent_or_equal_to_p_ref_());
@@ -178,7 +198,7 @@
template <typename P>
inline
bool
- graph_window_fwd_piter<P>::adjacent_or_equal_to_p_ref_() const
+ graph_neighborhood_fwd_piter<P>::adjacent_or_equal_to_p_ref_() const
{
// FIXME: Likewise, this is inefficient.
@@ -208,7 +228,7 @@
template <typename P>
inline
void
- graph_window_fwd_piter<P>::update_()
+ graph_neighborhood_fwd_piter<P>::update_()
{
// Update psite_.
psite_ = graph_psite<P>(p_ref_.pg(), id_);
@@ -219,7 +239,7 @@
template <typename P>
inline
const P&
- graph_window_fwd_piter<P>::to_point() const
+ graph_neighborhood_fwd_piter<P>::to_point() const
{
return p_;
}
@@ -227,14 +247,14 @@
template <typename P>
inline
const graph_psite<P>&
- graph_window_fwd_piter<P>::to_psite() const
+ graph_neighborhood_fwd_piter<P>::to_psite() const
{
return psite_;
}
template <typename P>
inline
- graph_window_fwd_piter<P>::operator P() const
+ graph_neighborhood_fwd_piter<P>::operator P() const
{
mln_precondition(is_valid());
return p_;
@@ -242,7 +262,7 @@
template <typename P>
inline
- graph_window_fwd_piter<P>::operator graph_psite<P>() const
+ graph_neighborhood_fwd_piter<P>::operator graph_psite<P>() const
{
mln_precondition(is_valid());
return psite_;
@@ -251,7 +271,7 @@
template <typename P>
inline
mln_coord(P)
- graph_window_fwd_piter<P>::operator[](unsigned i) const
+ graph_neighborhood_fwd_piter<P>::operator[](unsigned i) const
{
assert(i < dim);
return p_[i];
@@ -261,4 +281,4 @@
} // end of namespace mln
-#endif // ! MLN_CORE_GRAPH_WINDOW_PITER_HH
+#endif // ! MLN_CORE_GRAPH_NEIGHBORHOOD_PITER_HH
Index: mln/core/line_graph_elt_neighborhood.hh
--- mln/core/line_graph_elt_neighborhood.hh (revision 1719)
+++ mln/core/line_graph_elt_neighborhood.hh (working copy)
@@ -25,10 +25,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_LINE_GRAPH_ELT_WINDOW_HH
-# define MLN_CORE_LINE_GRAPH_ELT_WINDOW_HH
+#ifndef MLN_CORE_LINE_GRAPH_ELT_NEIGHBORHOOD_HH
+# define MLN_CORE_LINE_GRAPH_ELT_NEIGHBORHOOD_HH
-/*! \file mln/core/line_graph_elt_window.hh
+/*! \file mln/core/line_graph_elt_neighborhood.hh
*
* \brief Definition of the elementary ``window'' on a line graph.
*
@@ -36,136 +36,60 @@
* point_, neighb_, etc.
*/
-# include <mln/core/concept/window.hh>
+# include <mln/core/concept/neighborhood.hh>
# include <mln/core/line_graph_psite.hh>
-# include <mln/core/line_graph_window_piter.hh>
+# include <mln/core/line_graph_neighborhood_piter.hh>
+/* FIXME: Factor those classes:
+ - mln::graph_elt_window
+ - mln::graph_elt_neighborhood
+ - mln::line_graph_elt_window
+ - mln::line_graph_elt_neighborhood. */
namespace mln
{
// Fwd decls.
- template <typename P> class line_graph_window_fwd_piter;
- template <typename P> class line_graph_window_bkd_piter;
+ template <typename P> class line_graph_neighborhood_fwd_piter;
+ template <typename P> class line_graph_neighborhood_bkd_piter;
- /*! \brief Elementary window on line graph class.
+ /*! \brief Elementary neighborhood on line graph class.
*
* FIXME: Doc.
*/
template <typename P>
- class line_graph_elt_window : public Window< line_graph_elt_window<P> >
+ class line_graph_elt_neighborhood
+ : public Neighborhood< line_graph_elt_neighborhood<P> >
{
- typedef line_graph_elt_window<P> self_;
+ typedef line_graph_elt_neighborhood<P> self_;
public:
/// Associated types.
/// \{
- /// The type of point stored into the window.
- // FIXME: Is this right, if we consider that this window stores
+ /// The type of point stored into the neighborhood.
+ // FIXME: Is this right, if we consider that this neighborhood stores
// psites, not points?
typedef P point;
// 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.
+ /*! \brief Point_Iterator type to browse the points of a generic
+ * neighborhood w.r.t. the ordering of delta-points.
*/
- typedef line_graph_window_fwd_piter<P> fwd_qiter;
+ typedef line_graph_neighborhood_fwd_piter<P> fwd_niter;
- /*! \brief Point_Iterator type to browse the points of a generic window
- * w.r.t. the reverse ordering of delta-points.
+ /*! \brief Point_Iterator type to browse the points of a generic
+ * neighborhood w.r.t. the reverse ordering of delta-points.
*/
- typedef line_graph_window_bkd_piter<P> bkd_qiter;
+ typedef line_graph_neighborhood_bkd_piter<P> bkd_niter;
/// The default qiter type.
- typedef fwd_qiter qiter;
+ typedef fwd_niter niter;
/// \}
-
- /// Construct an elementary line_graph window.
- line_graph_elt_window();
-
- /// 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;
-
- /// 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 line_graph
-
- 1. is not constant (line graph edges are not necessarily
- aligned on a regular grid);
-
- 2. depends on the underlying line_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
- line_graph_elt_window<P>::line_graph_elt_window()
- {
- }
-
- template <typename P>
- inline
- bool
- line_graph_elt_window<P>::is_empty() const
- {
- return false;
- }
-
- template <typename P>
- inline
- bool
- line_graph_elt_window<P>::is_centered() const
- {
- return false;
- }
-
- template <typename P>
- inline
- bool
- line_graph_elt_window<P>::is_symmetric() const
- {
- return true;
- }
-
- template <typename P>
- inline
- unsigned
- line_graph_elt_window<P>::delta() const
- {
- // Dummy value (see the interface of the method above).
- return 0;
- }
-
- template <typename P>
- inline
- line_graph_elt_window<P>&
- line_graph_elt_window<P>::sym()
- {
- return *this;
- }
-
-# endif // ! MLN_INCLUDE_ONLY
-
} // end of namespace mln
-#endif // ! MLN_CORE_LINE_GRAPH_ELT_WINDOW_HH
+#endif // ! MLN_CORE_LINE_GRAPH_ELT_NEIGHBORHOOD_HH
Index: mln/core/line_graph_neighborhood_piter.hh
--- mln/core/line_graph_neighborhood_piter.hh (revision 1719)
+++ mln/core/line_graph_neighborhood_piter.hh (working copy)
@@ -25,11 +25,25 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_LINE_GRAPH_WINDOW_PITER_HH
-# define MLN_CORE_LINE_GRAPH_WINDOW_PITER_HH
+#ifndef MLN_CORE_LINE_GRAPH_NEIGHBORHOOD_PITER_HH
+# define MLN_CORE_LINE_GRAPH_NEIGHBORHOOD_PITER_HH
-/// \file mln/core/line_graph_window_piter.hh
-/// \brief Definition of a point iterator on a line_graph window.
+/// \file mln/core/line_graph_neighborhood_piter.hh
+/// \brief Definition of a point iterator on a line_graph neighborhood.
+
+/* FIXME: Factor those classes:
+
+ - mln::graph_window_fwd_piter
+ - mln::graph_neighborhood_fwd_piter
+ - mln::line_graph_window_fwd_piter
+ - mln::line_graph_neighborhood_fwd_piter.
+
+ and later (when they get implemented):
+
+ - mln::graph_window_bkd_piter
+ - mln::graph_neighborhood_bkd_piter
+ - mln::line_graph_window_bkd_piter
+ - mln::line_graph_neighborhood_bkd_piter. */
# include <mln/core/concept/point_iterator.hh>
# include <mln/core/p_line_graph.hh>
@@ -49,15 +63,15 @@
template <typename P> class line_graph_psite;
- /*---------------------------------.
- | line_graph_window_fwd_piter<P>. |
- `---------------------------------*/
+ /*---------------------------------------.
+ | line_graph_neighborhood_fwd_piter<P>. |
+ `---------------------------------------*/
template <typename P>
- class line_graph_window_fwd_piter :
- public Point_Iterator< line_graph_window_fwd_piter<P> > // or Iterator<...>?
+ class line_graph_neighborhood_fwd_piter :
+ public Point_Iterator< line_graph_neighborhood_fwd_piter<P> > // or Iterator<...>?
{
- typedef line_graph_window_fwd_piter<P> self_;
+ typedef line_graph_neighborhood_fwd_piter<P> self_;
typedef Point_Iterator< self_ > super_;
public:
@@ -73,8 +87,9 @@
typedef mln_coord(point) coord;
public:
- template <typename W, typename Pref>
- line_graph_window_fwd_piter(const W& win, const Point_Site<Pref>& p_ref);
+ template <typename N, typename Pref>
+ line_graph_neighborhood_fwd_piter(const N& nbh,
+ const Point_Site<Pref>& p_ref);
bool is_valid() const;
void invalidate();
@@ -95,7 +110,7 @@
coord operator[](unsigned i) const;
private:
- /// The ``central'' psite of the window.
+ /// The ``central'' psite of the neighborhood.
const psite& p_ref_;
/// An internal iterator on the set of edges of the underlying graph.
util::edge_id id_;
@@ -112,23 +127,24 @@
template <typename P>
inline
std::ostream&
- operator<<(std::ostream& ostr, const line_graph_window_fwd_piter<P>& p);
+ operator<<(std::ostream& ostr,
+ const line_graph_neighborhood_fwd_piter<P>& p);
- /*---------------------------------.
- | line_graph_window_bkd_piter<P>. |
- `---------------------------------*/
+ /*---------------------------------------.
+ | line_graph_neighborhood_bkd_piter<P>. |
+ `---------------------------------------*/
- // FIXME: Implement line_graph_window_bkd_piter.
+ // FIXME: Implement line_graph_neighborhood_bkd_piter.
# ifndef MLN_INCLUDE_ONLY
- // FIXME: Currently, argument win is ignored.
+ // FIXME: Currently, argument nbh is ignored.
template <typename P>
- template <typename W, typename Pref>
+ template <typename N, typename Pref>
inline
- line_graph_window_fwd_piter<P>::line_graph_window_fwd_piter(const W& /* win */,
+ line_graph_neighborhood_fwd_piter<P>::line_graph_neighborhood_fwd_piter(const N& /* nbh */,
const Point_Site<Pref>& p_ref)
: p_ref_(exact(p_ref).to_psite()),
// Initialize psite_ to a dummy value.
@@ -142,7 +158,7 @@
template <typename P>
inline
bool
- line_graph_window_fwd_piter<P>::is_valid() const
+ line_graph_neighborhood_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
@@ -153,7 +169,7 @@
template <typename P>
inline
void
- line_graph_window_fwd_piter<P>::invalidate()
+ line_graph_neighborhood_fwd_piter<P>::invalidate()
{
id_ = p_ref_.plg().gr_.nedges();
}
@@ -161,7 +177,7 @@
template <typename P>
inline
void
- line_graph_window_fwd_piter<P>::start()
+ line_graph_neighborhood_fwd_piter<P>::start()
{
id_ = 0;
if (!adjacent_or_equal_to_p_ref_())
@@ -176,15 +192,15 @@
template <typename P>
inline
void
- line_graph_window_fwd_piter<P>::next_()
+ line_graph_neighborhood_fwd_piter<P>::next_()
{
/* FIXME: This is inefficient. The graph structure should be able
to produce the set of adjacent edges fast. Boost Graphs
probably provides adequates structures to fetch these
neighbors in constant time. */
/* FIXME: Moreover, the behavior of next shall depend on the
- window, which is not the case now! (Currently, next_() behaves
- as win was always an elementary window.) */
+ neighborhood, which is not the case now! (Currently, next_()
+ behaves as nbh was always an elementary neighborhood.) */
do
++id_;
while (is_valid() && !adjacent_or_equal_to_p_ref_());
@@ -195,7 +211,7 @@
template <typename P>
inline
bool
- line_graph_window_fwd_piter<P>::adjacent_or_equal_to_p_ref_() const
+ line_graph_neighborhood_fwd_piter<P>::adjacent_or_equal_to_p_ref_() const
{
// Check wether the iterator points to P_REF_.
if (id_ == p_ref_.id())
@@ -227,7 +243,7 @@
template <typename P>
inline
void
- line_graph_window_fwd_piter<P>::update_()
+ line_graph_neighborhood_fwd_piter<P>::update_()
{
// Update psite_.
psite_ = line_graph_psite<P>(p_ref_.plg(), id_);
@@ -241,7 +257,7 @@
template <typename P>
inline
const point_pair<P>&
- line_graph_window_fwd_piter<P>::to_point() const
+ line_graph_neighborhood_fwd_piter<P>::to_point() const
{
return p_;
}
@@ -249,14 +265,14 @@
template <typename P>
inline
const line_graph_psite<P>&
- line_graph_window_fwd_piter<P>::to_psite() const
+ line_graph_neighborhood_fwd_piter<P>::to_psite() const
{
return psite_;
}
template <typename P>
inline
- line_graph_window_fwd_piter<P>::operator point_pair<P>() const
+ line_graph_neighborhood_fwd_piter<P>::operator point_pair<P>() const
{
mln_precondition(is_valid());
return p_;
@@ -264,7 +280,7 @@
template <typename P>
inline
- line_graph_window_fwd_piter<P>::operator line_graph_psite<P> () const
+ line_graph_neighborhood_fwd_piter<P>::operator line_graph_psite<P> () const
{
mln_precondition(is_valid());
return psite_;
@@ -273,7 +289,7 @@
template <typename P>
inline
mln_coord(point_pair<P>)
- line_graph_window_fwd_piter<P>::operator[](unsigned i) const
+ line_graph_neighborhood_fwd_piter<P>::operator[](unsigned i) const
{
assert(i < dim);
return p_[i];
@@ -282,7 +298,8 @@
template <typename P>
inline
std::ostream&
- operator<<(std::ostream& ostr, const line_graph_window_fwd_piter<P>& p)
+ operator<<(std::ostream& ostr,
+ const line_graph_neighborhood_fwd_piter<P>& p)
{
return ostr << p.to_point();
}
@@ -291,4 +308,4 @@
} // end of namespace mln
-#endif // ! MLN_CORE_LINE_GRAPH_WINDOW_PITER_HH
+#endif // ! MLN_CORE_LINE_GRAPH_NEIGHBORHOOD_PITER_HH
Index: mln/core/graph_elt_window.hh
--- mln/core/graph_elt_window.hh (revision 1724)
+++ mln/core/graph_elt_window.hh (working copy)
@@ -36,6 +36,12 @@
* point_, neighb_, etc.
*/
+/* FIXME: Factor those classes:
+ - mln::graph_elt_window
+ - mln::graph_elt_neighborhood
+ - mln::line_graph_elt_window
+ - mln::line_graph_elt_neighborhood. */
+
# include <mln/core/concept/window.hh>
# include <mln/core/graph_psite.hh>
# include <mln/core/graph_window_piter.hh>
Index: mln/core/graph_window_piter.hh
--- mln/core/graph_window_piter.hh (revision 1724)
+++ mln/core/graph_window_piter.hh (working copy)
@@ -31,6 +31,20 @@
/// \file mln/core/graph_window_piter.hh
/// \brief Definition of a point iterator on a graph window.
+/* FIXME: Factor those classes:
+
+ - mln::graph_window_fwd_piter
+ - mln::graph_neighborhood_fwd_piter
+ - mln::line_graph_window_fwd_piter
+ - mln::line_graph_neighborhood_fwd_piter.
+
+ and later (when they get implemented):
+
+ - mln::graph_window_bkd_piter
+ - mln::graph_neighborhood_bkd_piter
+ - mln::line_graph_window_bkd_piter
+ - mln::line_graph_neighborhood_bkd_piter. */
+
# include <mln/core/concept/point_iterator.hh>
# include <mln/core/p_graph.hh>
# include <mln/core/graph_psite.hh>
@@ -48,6 +62,10 @@
template <typename P> class graph_psite;
+ /*----------------------------.
+ | graph_window_fwd_piter<P>. |
+ `----------------------------*/
+
template <typename P>
class graph_window_fwd_piter :
public Point_Iterator< graph_window_fwd_piter<P> > // or Iterator<...>?
@@ -102,7 +120,9 @@
point p_;
};
- // FIXME: Implement graph_window_bkd_piter.
+ /*----------------------------.
+ | graph_window_bkd_piter<P>. |
+ `----------------------------*/
# ifndef MLN_INCLUDE_ONLY
Index: mln/core/line_graph_elt_window.hh
--- mln/core/line_graph_elt_window.hh (revision 1724)
+++ mln/core/line_graph_elt_window.hh (working copy)
@@ -36,6 +36,12 @@
* point_, neighb_, etc.
*/
+/* FIXME: Factor those classes:
+ - mln::graph_elt_window
+ - mln::graph_elt_neighborhood
+ - mln::line_graph_elt_window
+ - mln::line_graph_elt_neighborhood. */
+
# include <mln/core/concept/window.hh>
# include <mln/core/line_graph_psite.hh>
# include <mln/core/line_graph_window_piter.hh>
Index: mln/core/line_graph_window_piter.hh
--- mln/core/line_graph_window_piter.hh (revision 1724)
+++ mln/core/line_graph_window_piter.hh (working copy)
@@ -31,6 +31,20 @@
/// \file mln/core/line_graph_window_piter.hh
/// \brief Definition of a point iterator on a line_graph window.
+/* FIXME: Factor those classes:
+
+ - mln::graph_window_fwd_piter
+ - mln::graph_neighborhood_fwd_piter
+ - mln::line_graph_window_fwd_piter
+ - mln::line_graph_neighborhood_fwd_piter.
+
+ and later (when they get implemented):
+
+ - mln::graph_window_bkd_piter
+ - mln::graph_neighborhood_bkd_piter
+ - mln::line_graph_window_bkd_piter
+ - mln::line_graph_neighborhood_bkd_piter. */
+
# include <mln/core/concept/point_iterator.hh>
# include <mln/core/p_line_graph.hh>
# include <mln/core/line_graph_psite.hh>
Index: mln/convert/to_window.hh
--- mln/convert/to_window.hh (revision 1724)
+++ mln/convert/to_window.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory (LRDE)
+// 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
@@ -42,16 +42,34 @@
# include <mln/pw/cst.hh>
# include <mln/metal/is_a.hh>
+# include <mln/core/line_graph_elt_neighborhood.hh>
+# include <mln/core/line_graph_elt_window.hh>
+
namespace mln
{
namespace convert
{
+ // Return type trait of neighborhood-to-window conversions.
+
+ /* FIXME: This trait should probably be moved elsewhere. And/or
+ it could encapsulate the conversion function, too. */
+
+ // Default case.
+ template <typename N>
+ struct nbh_to_win_trait
+ { typedef window<mln_dpoint(N)> ret; };
+
+ // Case of line_graph_elt_neighborhood<P>.
+ template <typename P>
+ struct nbh_to_win_trait< line_graph_elt_neighborhood<P> >
+ { typedef line_graph_elt_window<P> ret; };
+
/// Convert a neighborhood \p nbh into a window.
template <typename N>
- window<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh);
+ typename nbh_to_win_trait<N>::ret to_window(const Neighborhood<N>& nbh);
/// Convert a binary image \p ima into a window.
template <typename I>
@@ -68,18 +86,16 @@
# ifndef MLN_INCLUDE_ONLY
- /* FIXME: According to milena/core/concepts/README, windows are
- not necessarily based on a set of dpoints. So the current
- algorithm won't work on non dpoint-set-based windows. In the
- general case (of windows not being a set of dpoints), the
- window resulting from this conversion (as well as the iterators
- based on such windows!) should depend on the initial
- neighborhood (i.e., delegate the actual iteration to the
- aggregated neighborhood). When this is fixed, document this in
- depth in milena/core/concepts/README. */
+ /*-------------------------------------.
+ | Neighborhood-to-window conversions. |
+ `-------------------------------------*/
+
+ namespace impl
+ {
+
template <typename N>
inline
- window<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh_)
+ window<mln_dpoint(N)> to_window(const N& nbh_)
{
const N& nbh = exact(nbh_);
typedef mln_dpoint(N) D;
@@ -91,7 +107,38 @@
return win;
}
- // FIXME: Same remark as for to_window(const Neighborhood<N>&)
+ template <typename P>
+ inline
+ line_graph_elt_window<P>
+ to_window(const line_graph_elt_neighborhood<P>& /* nbh_ */ )
+ {
+ return line_graph_elt_window<P>();
+ }
+
+ } // end of namepace mln::convert::impl
+
+
+ // Facade.
+ template <typename N>
+ inline
+ typename nbh_to_win_trait<N>::ret to_window(const Neighborhood<N>& nbh)
+ {
+ return impl::to_window(exact(nbh));
+ }
+
+ /*------------------------------.
+ | Image-to-window conversions. |
+ `------------------------------*/
+
+ /* FIXME: According to milena/core/concepts/README, windows are
+ not necessarily based on a set of dpoints. So the current
+ algorithm won't work on non dpoint-set-based windows. In the
+ general case (of windows not being a set of dpoints), the
+ window resulting from this conversion (as well as the iterators
+ based on such windows!) should depend on the initial
+ neighborhood (i.e., delegate the actual iteration to the
+ aggregated neighborhood). When this is fixed, document this in
+ depth in milena/core/concepts/README. */
template <typename I>
inline
window<mln_dpoint(I)> to_window(const Image<I>& ima_)
@@ -109,6 +156,10 @@
return win;
}
+ /*----------------------------------.
+ | Point set-to-window conversions. |
+ `----------------------------------*/
+
template <typename S>
inline
window<mln_dpoint(S)> to_window(const Point_Set<S>& pset)
@@ -116,6 +167,10 @@
return to_window(pw::cst(true) | pset);
}
+ /*---------------------------------.
+ | std::set-to-window conversions. |
+ `---------------------------------*/
+
template <typename D>
inline
window<D> to_window(const std::set<D>& s)
Index: mln/convert/to_p_array.hh
--- mln/convert/to_p_array.hh (revision 1724)
+++ mln/convert/to_p_array.hh (working copy)
@@ -48,9 +48,12 @@
p_array<mln_point(S)> to_p_array(const Point_Set<S>& pset);
- /// Convert a window \p win centered at point \p p into a p_array (point set vector).
+ /// Convert a window \p win centered at point \p p into a p_array
+ /// (point set vector).
template <typename W>
- p_array<mln_point(W)> to_p_array(const Window<W>& win, const mln_point(W)& p);
+ p_array<mln_point(W)> to_p_array(const Window<W>& win,
+ const mln_point(W)& p);
+
# ifndef MLN_INCLUDE_ONLY
@@ -70,7 +73,8 @@
template <typename W>
inline
- p_array<mln_point(W)> to_p_array(const Window<W>& win, const mln_point(W)& p)
+ p_array<mln_point(W)> to_p_array(const Window<W>& win,
+ const mln_point(W)& p)
{
p_array<mln_point(W)> v;
v.reserve(exact(win).ndpoints());
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-02-14 Etienne FOLIO <folio(a)lrde.epita.fr>
First work on naive dt.
* sandbox/folio/dt_naive.cc: Test file, in progress
* sandbox/folio/dt_naive.hh: Algorithm
---
dt_naive.cc | 49 +++++++++++++++++++++++++
dt_naive.hh | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 166 insertions(+)
Index: trunk/milena/sandbox/folio/dt_naive.hh
===================================================================
--- trunk/milena/sandbox/folio/dt_naive.hh (revision 0)
+++ trunk/milena/sandbox/folio/dt_naive.hh (revision 1724)
@@ -0,0 +1,117 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef DISTANCE_NAIVE_HH_
+# define DISTANCE_NAIVE_HH_
+
+/*! \file TODO
+ *
+ * \brief Defines a function that creates a distance map corresponding to a
+ * given image.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/math/sqr.hh>
+# include <mln/core/math/sqrt.hh>
+# include <mln/core/level/fill.hh>
+
+namespace mln
+{
+ namespace dist
+ {
+ /*! Calculates the distance map corresponding to a given image
+ *
+ * \param[in] img The binary reference image.
+ * \param[in] objColor The object's color.
+ * \param[in] bgColor The background color.
+ * \return New distance map image.
+ *
+ * \pre \p img has to be initialized.
+ *
+ * \todo
+ */
+ template <typename I, typename J>
+ Image<J>&
+ dt_naive(const Image<I>& img,
+ const mln_value(I)& objColor,
+ const mln_value(I)& bgColor);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+ template <typename J>
+ inline void
+ dt_naive_calc(mln_value(J)& res,
+ const mln_point(I)& ref,
+ const mln_point(I)& test)
+ {
+ mln_value(J) sum = 0;
+
+ for (unsigned i = 0; i < I::pset::dim; ++i)
+ sum += math::sqr(ref[i] - test[i]);
+
+ res = math::sqrt(sum);
+ }
+ }
+
+ // Facade.
+ template <typename I, typename J>
+ inline Image<J>&
+ dt_naive(const Image<I>& img,
+ const mln_value(I)& objColor,
+ const mln_value(I)& bgColor)
+ {
+ Image<J> res(img.domain());
+ mln_piter(I) p(img.domain());
+ mln_piter(I) q(img.domain());
+
+ level::fill(res, literal::zero);
+
+ for_all(p)
+ {
+ if (img(p) == bgColor)
+ continue;
+
+ for_all(q)
+ {
+ if (img(q) == objColor)
+ continue;
+
+ dt_naive_calc(res(q), p, q));
+ }
+ }
+
+ return res;
+ }
+
+# endif // !MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::dist
+} // end of namespace mln
+
+#endif /* !DISTANCE_NAIVE_HH_ */
Index: trunk/milena/sandbox/folio/dt_naive.cc
===================================================================
--- trunk/milena/sandbox/folio/dt_naive.cc (revision 0)
+++ trunk/milena/sandbox/folio/dt_naive.cc (revision 1724)
@@ -0,0 +1,49 @@
+// 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. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/linear_gaussian.cc
+ *
+ * \brief Test on mln::linear::gaussian.
+ */
+
+#include "dt_naive.hh"
+
+int main()
+{
+ using namespace mln;
+
+ image2d< value::int_u8 > lena;
+ io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
+
+// image2d<float> tmp(lena.domain());
+// linear::gaussian(lena, 5.1f, tmp);
+
+// image2d< value::int_u_sat<8> > out(lena.domain());
+// level::transform(tmp, math::round<int>(), out);
+// io::pgm::save(out, "out.pgm");
+ }
+}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-02-14 Caroline Vigouroux <vigour_c(a)epita.fr>
Corrections on color structures.
* color/my_cmy.hh: corrections.
* color/my_hsi.hh: corrections.
* color/rgb_to_cmy.hh: corrections.
* color/rgb_to_yuv.hh: corrections.
* color/tests.cc: corrections.
---
my_cmy.hh | 12 ++++++------
my_hsi.hh | 35 ++++++++++++++++++++++++++++++-----
rgb_to_cmy.hh | 16 ++++++++++------
rgb_to_yuv.hh | 13 +++++++++----
tests.cc | 2 +-
5 files changed, 56 insertions(+), 22 deletions(-)
Index: trunk/milena/sandbox/vigouroux/color/rgb_to_cmy.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/rgb_to_cmy.hh (revision 1722)
+++ trunk/milena/sandbox/vigouroux/color/rgb_to_cmy.hh (revision 1723)
@@ -5,6 +5,7 @@
#include <mln/io/ppm/save.hh>
#include <mln/display/save_and_show.hh>
#include <mln/level/fill.hh>
+#include <mln/value/int_u.hh>
#include "my_cmy.hh"
@@ -12,7 +13,7 @@
namespace convert {
struct f_rgb_to_cmy
{
- struct value::cmy
+ struct value::cmy<8>
doit(const struct value::rgb<8> rgb) const
{
struct value::cmy cmy;
@@ -30,11 +31,14 @@
struct value::rgb<8>
doit(const struct value::cmy cmy) const
{
- struct value::rgb<8> rgb;
-
- rgb.red() = 1 - cmy.c();
- rgb.green() = 1 - cmy.m();
- rgb.blue() = 1 - cmy.y();
+ int red;
+ int green;
+ int blue;
+
+ red = int(1 - cmy.c());
+ green = int(1 - cmy.m());
+ blue = int(1 - cmy.y());
+ struct value::rgb<8> rgb(red, green, blue);
return (rgb);
}
Index: trunk/milena/sandbox/vigouroux/color/tests.cc
===================================================================
--- trunk/milena/sandbox/vigouroux/color/tests.cc (revision 1722)
+++ trunk/milena/sandbox/vigouroux/color/tests.cc (revision 1723)
@@ -13,7 +13,7 @@
{
using namespace mln;
- struct value::yuv yuv(4, 4, 4);
+ struct value::yuv<8> yuv(4, 4, 4);
std::cout << yuv.y() << std::endl;
std::cout << yuv.u() << std::endl;
std::cout << yuv.v() << std::endl;
Index: trunk/milena/sandbox/vigouroux/color/my_hsi.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/my_hsi.hh (revision 1722)
+++ trunk/milena/sandbox/vigouroux/color/my_hsi.hh (revision 1723)
@@ -4,6 +4,9 @@
#include <mln/value/int_u.hh>
#include <mln/metal/vec.hh>
+#ifndef MLN_VALUE_HSI_HH
+# define MLN_VALUE_HSI_HH
+
namespace mln
{
namespace value
@@ -18,22 +21,42 @@
/// Constructor from component values.
hsi<n>(int h, int s, int i);
+ /// Access to component values.
+ double h() const { return this->h_; }
+ double s() const { return this->s_; }
+ double i() const { return this->i_; }
+
+ /// Set component values.
+ void h(double h)
+ {
+ this->h_ = h;
+ }
+ void s(double s)
+ {
+ this->s_ = s;
+ }
+ void i(double i)
+ {
+ mln_precondition(i >= 0);
+ this->i_ = i;
+ }
+
private:
- int h_;
- int s_;
- int i_;
+ double h_;
+ double s_;
+ double i_;
};
template <unsigned n>
inline
- hsi::hsi<n>()
+ hsi<n>::hsi()
:h_(0), s_(0), i_(0)
{
}
template <unsigned n>
inline
- hsi::hsi<n>(int h, int s, int i)
+ hsi<n>::hsi(int h, int s, int i)
{
mln_precondition(h >= 0);
mln_precondition(s >= 0);
@@ -44,3 +67,5 @@
}
}
}
+
+#endif // ! MLN_VALUE_HSI_HH
Index: trunk/milena/sandbox/vigouroux/color/my_cmy.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/my_cmy.hh (revision 1722)
+++ trunk/milena/sandbox/vigouroux/color/my_cmy.hh (revision 1723)
@@ -1,11 +1,11 @@
-#ifndef MLN_VALUE_YUV_HH
-# define MLN_VALUE_YUV_HH
+#ifndef MLN_VALUE_CMY_HH
+# define MLN_VALUE_CMY_HH
namespace mln
{
namespace value
{
-// template <unsigned n>
+ template <unsigned n>
struct cmy
{
public:
@@ -43,14 +43,14 @@
double y_;
};
-// template <unsigned n>
+ template <unsigned n>
inline
yuv::cmy()
:c_(0), m_(0), y_(0)
{
}
-// template <unsigned n>
+ template <unsigned n>
inline
cmy::cmy(double c, double m, double y)
{
@@ -64,4 +64,4 @@
}
}
-#endif // ! MLN_VALUE_YUV_HH
+#endif // ! MLN_VALUE_CMY_HH
Index: trunk/milena/sandbox/vigouroux/color/rgb_to_yuv.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/rgb_to_yuv.hh (revision 1722)
+++ trunk/milena/sandbox/vigouroux/color/rgb_to_yuv.hh (revision 1723)
@@ -5,6 +5,7 @@
#include <mln/io/ppm/save.hh>
#include <mln/display/save_and_show.hh>
#include <mln/level/fill.hh>
+#include <mln/value/int_u.hh>
#include "my_yuv.hh"
@@ -30,11 +31,15 @@
struct value::rgb<8>
doit(const struct value::yuv<8> yuv) const
{
- struct value::rgb<8> rgb;
+ int r;
+ int g;
+ int b;
+
+ r = int(yuv.y() + 1.13983 * yuv.v());
+ g = int(yuv.y() - 0.39465 * yuv.u() - 0.58060 * yuv.v());
+ b = int(yuv.y() + 2.03211 * yuv.u());
- rgb.red(yuv.y() + 1.13983 * yuv.v());
- rgb.green(yuv.y() - 0.39465 * yuv.u() - 0.58060 * yuv.v());
- rgb.blue(yuv.y() + 2.03211 * yuv.u());
+ struct value::rgb<8> rgb(r, g, b);
return (rgb);
}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-02-13 Caroline Vigouroux <vigour_c(a)epita.fr>
color structures.
* my_cmy.hh: CMY struct.
* my_hsi.hh: HSI struct.
* my_yuv.hh: YUV struct.
* rgb_to_cmy.hh: transform equations.
* rgb_to_hsi.hh: transform equations.
* rgb_to_yuv.hh: transform equations.
* tests.cc: New test.
---
my_cmy.hh | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
my_hsi.hh | 46 ++++++++++++++++++++++++++++++++++++++
my_yuv.hh | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rgb_to_cmy.hh | 43 ++++++++++++++++++++++++++++++++++++
rgb_to_hsi.hh | 43 ++++++++++++++++++++++++++++++++++++
rgb_to_yuv.hh | 43 ++++++++++++++++++++++++++++++++++++
tests.cc | 22 ++++++++++++++++++
7 files changed, 333 insertions(+)
Index: trunk/milena/sandbox/vigouroux/color/rgb_to_cmy.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/rgb_to_cmy.hh (revision 0)
+++ trunk/milena/sandbox/vigouroux/color/rgb_to_cmy.hh (revision 1722)
@@ -0,0 +1,43 @@
+#include <mln/core/image_if_value.hh>
+#include <mln/core/inplace.hh>
+#include <mln/core/w_window2d_int.hh>
+#include <mln/display/show.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/display/save_and_show.hh>
+#include <mln/level/fill.hh>
+
+#include "my_cmy.hh"
+
+namespace mln {
+ namespace convert {
+ struct f_rgb_to_cmy
+ {
+ struct value::cmy
+ doit(const struct value::rgb<8> rgb) const
+ {
+ struct value::cmy cmy;
+
+ cmy.c(1 - rgb.red());
+ cmy.m(1 - rgb.green());
+ cmy.y(1 - rgb.blue());
+
+ return (cmy);
+ }
+ };
+
+ struct f_cmy_to_rgb
+ {
+ struct value::rgb<8>
+ doit(const struct value::cmy cmy) const
+ {
+ struct value::rgb<8> rgb;
+
+ rgb.red() = 1 - cmy.c();
+ rgb.green() = 1 - cmy.m();
+ rgb.blue() = 1 - cmy.y();
+
+ return (rgb);
+ }
+ };
+ }
+}
Index: trunk/milena/sandbox/vigouroux/color/tests.cc
===================================================================
--- trunk/milena/sandbox/vigouroux/color/tests.cc (revision 0)
+++ trunk/milena/sandbox/vigouroux/color/tests.cc (revision 1722)
@@ -0,0 +1,22 @@
+#include <mln/core/image_if_value.hh>
+#include <mln/core/inplace.hh>
+#include <mln/core/w_window2d_int.hh>
+#include <mln/display/show.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/display/save_and_show.hh>
+#include <mln/level/fill.hh>
+
+#include "rgb_to_yuv.hh"
+#include "my_yuv.hh"
+
+int main()
+{
+ using namespace mln;
+
+ struct value::yuv yuv(4, 4, 4);
+ std::cout << yuv.y() << std::endl;
+ std::cout << yuv.u() << std::endl;
+ std::cout << yuv.v() << std::endl;
+
+ return (0);
+}
Index: trunk/milena/sandbox/vigouroux/color/my_hsi.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/my_hsi.hh (revision 0)
+++ trunk/milena/sandbox/vigouroux/color/my_hsi.hh (revision 1722)
@@ -0,0 +1,46 @@
+#include <mln/value/ops.hh>
+
+#include <mln/value/concept/vectorial.hh>
+#include <mln/value/int_u.hh>
+#include <mln/metal/vec.hh>
+
+namespace mln
+{
+ namespace value
+ {
+ template <unsigned n>
+ struct hsi
+ {
+ public:
+ /// Constructor without argument.
+ hsi<n>();
+
+ /// Constructor from component values.
+ hsi<n>(int h, int s, int i);
+
+ private:
+ int h_;
+ int s_;
+ int i_;
+ };
+
+ template <unsigned n>
+ inline
+ hsi::hsi<n>()
+ :h_(0), s_(0), i_(0)
+ {
+ }
+
+ template <unsigned n>
+ inline
+ hsi::hsi<n>(int h, int s, int i)
+ {
+ mln_precondition(h >= 0);
+ mln_precondition(s >= 0);
+ mln_precondition(i >= 0);
+ this->h_ = h;
+ this->s_ = s;
+ this->i_ = i;
+ }
+ }
+}
Index: trunk/milena/sandbox/vigouroux/color/my_yuv.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/my_yuv.hh (revision 0)
+++ trunk/milena/sandbox/vigouroux/color/my_yuv.hh (revision 1722)
@@ -0,0 +1,69 @@
+// #include <mln/value/ops.hh>
+
+// #include <mln/value/concept/vectorial.hh>
+// #include <mln/value/int_u.hh>
+// #include <mln/metal/vec.hh>
+
+#ifndef MLN_VALUE_YUV_HH
+# define MLN_VALUE_YUV_HH
+
+namespace mln
+{
+ namespace value
+ {
+ template <unsigned n>
+ struct yuv
+ {
+ public:
+ /// Constructor without argument.
+ yuv<n>();
+
+ /// Constructor from component values.
+ yuv<n>(double y, double u, double v);
+
+ /// Access to component values.
+ double y() const { return this->y_; }
+ double u() const { return this->u_; }
+ double v() const { return this->v_; }
+
+ /// Set component values.
+ void y(double y)
+ {
+ this->y_ = y;
+ }
+ void u(double u)
+ {
+ this->u_ = u;
+ }
+ void v(double v)
+ {
+ mln_precondition(v >= 0);
+ this->v_ = v;
+ }
+
+ private:
+ double y_;
+ double u_;
+ double v_;
+ };
+
+ template <unsigned n>
+ inline
+ yuv<n>::yuv()
+ :y_(0), u_(0), v_(0)
+ {
+ }
+
+ template <unsigned n>
+ inline
+ yuv<n>::yuv(double y, double u, double v)
+ {
+ mln_precondition(v >= 0);
+ this->y_ = y;
+ this->u_ = u;
+ this->v_ = v;
+ }
+ }
+}
+
+#endif // ! MLN_VALUE_YUV_HH
Index: trunk/milena/sandbox/vigouroux/color/my_cmy.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/my_cmy.hh (revision 0)
+++ trunk/milena/sandbox/vigouroux/color/my_cmy.hh (revision 1722)
@@ -0,0 +1,67 @@
+#ifndef MLN_VALUE_YUV_HH
+# define MLN_VALUE_YUV_HH
+
+namespace mln
+{
+ namespace value
+ {
+// template <unsigned n>
+ struct cmy
+ {
+ public:
+ /// Constructor without argument.
+ cmy();
+
+ /// Constructor from component values.
+ cmy(double c, double m, double y);
+
+ /// Access to component values.
+ double c() const { return this->c_; }
+ double m() const { return this->m_; }
+ double y() const { return this->y_; }
+
+ /// Set component values.
+ void c(double c)
+ {
+ mln_precondition(c >= 0);
+ this->c_ = c;
+ }
+ void m(double m)
+ {
+ mln_precondition(m >= 0);
+ this->m_ = m;
+ }
+ void y(double y)
+ {
+ mln_precondition(y >= 0);
+ this->y_ = y;
+ }
+
+ private:
+ double c_;
+ double m_;
+ double y_;
+ };
+
+// template <unsigned n>
+ inline
+ yuv::cmy()
+ :c_(0), m_(0), y_(0)
+ {
+ }
+
+// template <unsigned n>
+ inline
+ cmy::cmy(double c, double m, double y)
+ {
+ mln_precondition(c >= 0);
+ mln_precondition(m >= 0);
+ mln_precondition(y >= 0);
+ this->c_ = c;
+ this->m_ = m;
+ this->y_ = y;
+ }
+ }
+}
+
+#endif // ! MLN_VALUE_YUV_HH
Index: trunk/milena/sandbox/vigouroux/color/rgb_to_yuv.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/rgb_to_yuv.hh (revision 0)
+++ trunk/milena/sandbox/vigouroux/color/rgb_to_yuv.hh (revision 1722)
@@ -0,0 +1,43 @@
+#include <mln/core/image_if_value.hh>
+#include <mln/core/inplace.hh>
+#include <mln/core/w_window2d_int.hh>
+#include <mln/display/show.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/display/save_and_show.hh>
+#include <mln/level/fill.hh>
+
+#include "my_yuv.hh"
+
+namespace mln {
+ namespace convert {
+ struct f_rgb_to_yuv
+ {
+ struct mln::value::yuv<8>
+ doit(const struct value::rgb<8> rgb) const
+ {
+ struct value::yuv<8> yuv;
+
+ yuv.y(0.299 * rgb.red() + 0.587 * rgb.green() + 0.114 * rgb.blue());
+ yuv.u(0.436 * (rgb.blue() - yuv.y()) / (1 - 0.114));
+ yuv.v(0.615 * (rgb.red() - yuv.y()) / (1 - 0.299));
+
+ return (yuv);
+ }
+ };
+
+ struct f_yuv_to_rgb
+ {
+ struct value::rgb<8>
+ doit(const struct value::yuv<8> yuv) const
+ {
+ struct value::rgb<8> rgb;
+
+ rgb.red(yuv.y() + 1.13983 * yuv.v());
+ rgb.green(yuv.y() - 0.39465 * yuv.u() - 0.58060 * yuv.v());
+ rgb.blue(yuv.y() + 2.03211 * yuv.u());
+
+ return (rgb);
+ }
+ };
+ }
+}
Index: trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 0)
+++ trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 1722)
@@ -0,0 +1,43 @@
+#include <mln/core/image_if_value.hh>
+#include <mln/core/inplace.hh>
+#include <mln/core/w_window2d_int.hh>
+#include <mln/display/show.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/display/save_and_show.hh>
+#include <mln/level/fill.hh>
+
+#include "my_hsi.hh"
+
+namespace mln {
+ namespace convert {
+ struct f_rgb_to_hsi
+ {
+ struct value::hsi
+ doit(const struct value::rgb<8> rgb) const
+ {
+ struct value::hsi hsi;
+
+ hsi.h(0.299 * rgb.red() + 0.587 * rgb.green() + 0.114 * rgb.blue());
+ hsi.s(0.436 * (rgb.blue() - yuv.y()) / (1 - 0.114));
+ hsi.i(0.615 * (rgb.red() - yuv.y()) / (1 - 0.299));
+
+ return (hsi);
+ }
+ };
+
+ struct f_hsi_to_rgb
+ {
+ struct value::rgb<8>
+ doit(const struct value::hsi hsi) const
+ {
+ struct value::rgb<8> rgb;
+
+ rgb.red() = yuv.y() + 1.13983 * yuv.v();
+ rgb.green() = yuv.y() - 0.39465 * yuv.u() - 0.58060 * yuv.v();
+ rgb.blue() = yuv.y() + 2.03211 * yuv.u();
+
+ return (rgb);
+ }
+ };
+ }
+}
1
0
1719: Typos and aesthetic changes in documentation of graph-related entities.
by Roland Levillain 11 Feb '08
by Roland Levillain 11 Feb '08
11 Feb '08
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Typos and aesthetic changes in documentation of graph-related
entities.
* mln/core/p_graph_piter.hh,
* mln/core/graph_window_piter.hh,
* tests/core/graph_elt_window.cc:
Fix Doxygen comments.
* mln/core/graph_psite.hh: Likewise.
(graph_psite<P>::operator[]): s/util::node_id/unsigned/.
s/id/i/.
mln/core/graph_psite.hh | 8 ++++----
mln/core/graph_window_piter.hh | 4 ++--
mln/core/p_graph_piter.hh | 8 ++++----
tests/core/graph_elt_window.cc | 4 ++--
4 files changed, 12 insertions(+), 12 deletions(-)
Index: mln/core/graph_psite.hh
--- mln/core/graph_psite.hh (revision 1718)
+++ mln/core/graph_psite.hh (working copy)
@@ -74,9 +74,9 @@
util::node_id id() const;
private:
- // The p_graph this point site belongs to.
+ /// The p_graph this point site belongs to.
const p_graph<P>& pg_;
- // The id of the node this psite is pointing towards.
+ /// The id of the node this psite is pointing towards.
util::node_id id_;
};
@@ -131,9 +131,9 @@
template<typename P>
inline
mln_coord(P)
- graph_psite<P>::operator[](util::node_id id) const
+ graph_psite<P>::operator[](unsigned i) const
{
- return to_point()[id];
+ return to_point()[i];
}
template<typename P>
Index: mln/core/graph_window_piter.hh
--- mln/core/graph_window_piter.hh (revision 1718)
+++ mln/core/graph_window_piter.hh (working copy)
@@ -96,9 +96,9 @@
const psite& p_ref_;
/// An internal iterator on the set of nodes of the underlying graph.
util::node_id id_;
- // The psite corresponding to this iterator.
+ /// The psite corresponding to this iterator.
psite psite_;
- // The point corresponding to this iterator.
+ /// The point corresponding to this iterator.
point p_;
};
Index: mln/core/p_graph_piter.hh
--- mln/core/p_graph_piter.hh (revision 1718)
+++ mln/core/p_graph_piter.hh (working copy)
@@ -93,13 +93,13 @@
operator psite() const;
protected:
- // The p_graph this point site belongs to.
+ /// The p_graph this point site belongs to.
const p_graph<P>& pg_;
- // The id of the node this psite is pointing towards.
+ /// The id of the node this psite is pointing towards.
unsigned id_;
- // The psite corresponding to this iterator.
+ /// The psite corresponding to this iterator.
psite psite_;
- // The point corresponding to this iterator.
+ /// The point corresponding to this iterator.
point p_;
};
Index: tests/core/graph_elt_window.cc
--- tests/core/graph_elt_window.cc (revision 1718)
+++ tests/core/graph_elt_window.cc (working copy)
@@ -27,7 +27,7 @@
/*! \file tests/core/graph_elt_window.cc
*
- * \brief Tests on mln::win::graph_elt_window.
+ * \brief Tests on mln::graph_elt_window.
*/
#include <vector>
@@ -77,6 +77,6 @@
p_graph<p_t> pg(g);
// Graph point site.
graph_psite<p_t> psite(pg, 0);
- // ``Sliding'' window (in fact, neighborhood) of a psite of PG.
+ // ``Sliding'' window of a psite of PG.
graph_elt_window<p_t> win;
}
1
0
11 Feb '08
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Of course, there's a lot of duplication with the entities of graph-based
images, and we'll have to refactor, in particular when we'll implement
simplicial complexes.
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add the required entities to express line graph-based images.
* mln/core/point_pair.hh: New.
Used to represent the ``points'' of line graph-based images.
* mln/core/line_graph_elt_window.hh,
* mln/core/line_graph_image.hh,
* mln/core/line_graph_psite.hh,
* mln/core/line_graph_window_piter.hh,
* mln/core/p_line_graph.hh,
* mln/core/p_line_graph_piter.hh:
New.
Entities involved in line graph-based images.
* tests/core/line_graph_elt_window.cc,
* tests/core/line_graph_image.cc:
New tests.
* tests/core/Makefile.am: Reorder the lists of tests.
(check_PROGRAMS): Add line_graph_elt_window and line_graph_image.
(line_graph_elt_window_SOURCES, line_graph_image_SOURCES): New.
mln/core/line_graph_elt_window.hh | 54 ++++----
mln/core/line_graph_image.hh | 138 +++++++++++++---------
mln/core/line_graph_psite.hh | 148 +++++++++++++++++-------
mln/core/line_graph_window_piter.hh | 194 +++++++++++++++++++++++---------
mln/core/p_line_graph.hh | 97 +++++++++-------
mln/core/p_line_graph_piter.hh | 114 +++++++++++-------
mln/core/point_pair.hh | 217 ++++++++++++++++++++++++++++++++++++
tests/core/Makefile.am | 26 ++--
tests/core/line_graph_elt_window.cc | 18 +-
tests/core/line_graph_image.cc | 99 +++++++---------
10 files changed, 773 insertions(+), 332 deletions(-)
Index: mln/core/point_pair.hh
--- mln/core/point_pair.hh (revision 0)
+++ mln/core/point_pair.hh (revision 0)
@@ -0,0 +1,217 @@
+// 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_CORE_POINT_PAIR_HH
+# define MLN_CORE_POINT_PAIR_HH
+
+/// \file mln/core/point_pair.hh
+/// \brief Definition of the generic point_pair class mln::point_pair.
+
+// FIXME: Might be renamed to something else, like ``segment''.
+
+# include <utility>
+# include <ostream>
+
+# include <mln/core/concept/point.hh>
+
+
+namespace mln
+{
+
+ /** \brief Generic point pair class.
+
+ The sole parameter P is the type of the points of the pair.
+
+ Pair points are mainly used to make a reference to a given edge
+ in an line graph-based image. */
+ template <typename P>
+ struct point_pair : public Point< point_pair<P> >
+ {
+ /// \var dim
+ /// \brief Dimension of the space.
+ /// \invariant dim > 0
+ enum { dim = P::dim };
+
+ /// Mesh associated type.
+ // FIXME: Dummy value.
+ typedef mln_mesh(P) mesh;
+
+ /// Dpoint associated type.
+ // FIXME: Dummy value.
+ typedef void dpoint;
+
+ /// Coordinate associated type.
+ typedef std::pair<typename P::coord, typename P::coord> coord;
+
+ /// Constructors.
+ /// \{
+ /// Constructor without argument.
+ point_pair();
+ /// Constructor using two points.
+ point_pair(const P& first, const P& second);
+ /// Constructor using a pair of points.
+ point_pair(const std::pair<P, P>& points);
+ /// \}
+
+ /// Accessors.
+ /// \{
+
+ /// \brief Read-only access to the \p i-th coordinate value.
+ /// \param[in] i The coordinate index.
+ /// \pre \p i < \c dim
+ coord operator[](unsigned i) const;
+
+ /* FIXME: Providing this accessor requires the point pair to be
+ actually stored in this object, which both takes space and time
+ (updates). */
+
+// /// \brief Read-write access to the \p i-th coordinate value.
+// /// \param[in] i The coordinate index.
+// /// \pre \p i < \c dim
+// coord& operator[](unsigned i);
+
+ /// Read-only access to the first point.
+ P first() const;
+ /// Read-write access to the first point.
+ P& first();
+
+ /// Read-only access to the second point.
+ P second() const;
+ /// Read-write access to the second point.
+ P& second();
+ /// \}
+
+ protected:
+ /// The pair of points.
+ // FIXME: Should we use an ordpair_ instead of as std::pair?
+ std::pair<P, P> points_;
+ };
+
+ template <typename P>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const point_pair<P>& p);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ /*------------.
+ | Accessors. |
+ `------------*/
+
+ template <typename P>
+ inline
+ typename point_pair<P>::coord
+ point_pair<P>::operator[](unsigned i) const
+ {
+ assert(i < dim);
+ return std::make_pair(points_.first[i], points_.second[i]);
+ }
+
+// template <typename P>
+// inline
+// typename point_pair<P>::coord&
+// point_pair<P>::operator[](unsigned i)
+// {
+// assert(i < dim);
+// return std::make_pair(points_.first[i], points_.second[i]);
+// }
+
+ template <typename P>
+ inline
+ P
+ point_pair<P>::first() const
+ {
+ return points_.first;
+ }
+
+ template <typename P>
+ inline
+ P&
+ point_pair<P>::first()
+ {
+ return points_.first;
+ }
+
+ template <typename P>
+ inline
+ P
+ point_pair<P>::second() const
+ {
+ return points_.second;
+ }
+
+ template <typename P>
+ inline
+ P&
+ point_pair<P>::second()
+ {
+ return points_.second;
+ }
+
+ /*---------------.
+ | Constructors. |
+ `---------------*/
+
+ template <typename P>
+ inline
+ point_pair<P>::point_pair()
+ {
+ }
+
+ template <typename P>
+ inline
+ point_pair<P>::point_pair(const P& first, const P& second)
+ : points_(first, second)
+ {
+ }
+
+ template <typename P>
+ inline
+ point_pair<P>::point_pair(const std::pair<P, P>& points)
+ : points_(points)
+ {
+ }
+
+ /*----------.
+ | Display. |
+ `----------*/
+
+ template <typename P>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const point_pair<P>& p)
+ {
+ return ostr << '(' << p.first() << " -- " << p.second() << ")";
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_POINT_PAIR_HH
Index: mln/core/line_graph_elt_window.hh
--- mln/core/line_graph_elt_window.hh (revision 1714)
+++ mln/core/line_graph_elt_window.hh (working copy)
@@ -25,37 +25,37 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_WIN_GRAPH_ELT_WINDOW_HH
-# define MLN_WIN_GRAPH_ELT_WINDOW_HH
+#ifndef MLN_CORE_LINE_GRAPH_ELT_WINDOW_HH
+# define MLN_CORE_LINE_GRAPH_ELT_WINDOW_HH
-/*! \file mln/core/graph_elt_window.hh
+/*! \file mln/core/line_graph_elt_window.hh
*
- * \brief Definition of the elementary ``window'' on a graph.
+ * \brief Definition of the elementary ``window'' on a line graph.
*
* \todo Make naming coherent: we have window (without '_') but
* point_, neighb_, etc.
*/
# include <mln/core/concept/window.hh>
-# include <mln/core/graph_psite.hh>
-# include <mln/core/graph_window_piter.hh>
+# include <mln/core/line_graph_psite.hh>
+# include <mln/core/line_graph_window_piter.hh>
namespace mln
{
// Fwd decls.
- template <typename P> class graph_window_fwd_piter;
- template <typename P> class graph_window_bkd_piter;
+ template <typename P> class line_graph_window_fwd_piter;
+ template <typename P> class line_graph_window_bkd_piter;
- /*! \brief Elementary window on graph class.
+ /*! \brief Elementary window on line graph class.
*
* FIXME: Doc.
*/
template <typename P>
- class graph_elt_window : public Window< graph_elt_window<P> >
+ class line_graph_elt_window : public Window< line_graph_elt_window<P> >
{
- typedef graph_elt_window<P> self_;
+ typedef line_graph_elt_window<P> self_;
public:
/// Associated types.
@@ -71,19 +71,19 @@
/*! \brief Point_Iterator type to browse the points of a generic window
* w.r.t. the ordering of delta-points.
*/
- typedef graph_window_fwd_piter<P> fwd_qiter;
+ typedef line_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 graph_window_bkd_piter<P> bkd_qiter;
+ typedef line_graph_window_bkd_piter<P> bkd_qiter;
/// The default qiter type.
typedef fwd_qiter qiter;
/// \}
- /// Construct an elementary graph window.
- graph_elt_window();
+ /// Construct an elementary line_graph window.
+ line_graph_elt_window();
/// Is the window is empty?
bool is_empty() const;
@@ -98,12 +98,12 @@
/// 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
+ of a window on a line_graph
- 1. is not constant (graph nodes are not necessarily aligned on
- a regular grid);
+ 1. is not constant (line graph edges are not necessarily
+ aligned on a regular grid);
- 2. depends on the underlying graph, too.
+ 2. depends on the underlying line_graph, too.
It raises another question: should delta() be part of the
concept ``Window''? */
@@ -118,14 +118,14 @@
template <typename P>
inline
- graph_elt_window<P>::graph_elt_window()
+ line_graph_elt_window<P>::line_graph_elt_window()
{
}
template <typename P>
inline
bool
- graph_elt_window<P>::is_empty() const
+ line_graph_elt_window<P>::is_empty() const
{
return false;
}
@@ -133,7 +133,7 @@
template <typename P>
inline
bool
- graph_elt_window<P>::is_centered() const
+ line_graph_elt_window<P>::is_centered() const
{
return false;
}
@@ -141,7 +141,7 @@
template <typename P>
inline
bool
- graph_elt_window<P>::is_symmetric() const
+ line_graph_elt_window<P>::is_symmetric() const
{
return true;
}
@@ -149,7 +149,7 @@
template <typename P>
inline
unsigned
- graph_elt_window<P>::delta() const
+ line_graph_elt_window<P>::delta() const
{
// Dummy value (see the interface of the method above).
return 0;
@@ -157,8 +157,8 @@
template <typename P>
inline
- graph_elt_window<P>&
- graph_elt_window<P>::sym()
+ line_graph_elt_window<P>&
+ line_graph_elt_window<P>::sym()
{
return *this;
}
@@ -168,4 +168,4 @@
} // end of namespace mln
-#endif // ! MLN_WIN_GRAPH_ELT_WINDOW_HH
+#endif // ! MLN_CORE_LINE_GRAPH_ELT_WINDOW_HH
Index: mln/core/line_graph_image.hh
--- mln/core/line_graph_image.hh (revision 1714)
+++ mln/core/line_graph_image.hh (working copy)
@@ -25,40 +25,54 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_GRAPH_IMAGE_HH
-# define MLN_CORE_GRAPH_IMAGE_HH
+#ifndef MLN_CORE_LINE_GRAPH_IMAGE_HH
+# define MLN_CORE_LINE_GRAPH_IMAGE_HH
-/*! \file mln/core/graph_image.hh
- *
- * \brief Definition of a graph-based image.
- */
+/// \file mln/core/line_graph_image.hh
+/// \brief Definition of a line graph-based image.
# include <mln/trait/images.hh>
# include <mln/core/internal/image_primary.hh>
# include <mln/metal/vec.hh>
-# include <mln/core/p_graph.hh>
-# include <mln/core/graph_psite.hh>
+# include <mln/core/p_line_graph.hh>
+# include <mln/core/line_graph_psite.hh>
# include <mln/value/set.hh>
# include <vector>
+/* FIXME: This class shares a lot with graph_image. Factor as much as
+ possible. */
+
+/* FIXME: This is only a very naive prototype. For instance, this
+ image associates values to both the nodes and the edges of the
+ graph, but only values on edges are accessible. We probably want
+ to fork this class to have a pure image of line graph (with no data
+ on nodes) and one having data on both nodes and edges.
+
+ Moreover, in the current implementation, the type of values on
+ nodes and edges is necessarily the same (V). We should allow
+ different data types for nodes and edges. */
+
+
namespace mln
{
// Fwd decl.
- template <typename P, typename V> struct graph_image;
+ template <typename P, typename V> struct line_graph_image;
namespace internal
{
- /// \internal Data structure for \c mln::graph_image<P,V>.
+ /// \internal Data structure for \c mln::line_graph_image<P,V>.
template <typename P, typename V>
- struct data_< graph_image<P, V> >
+ struct data_< line_graph_image<P, V> >
{
- data_(p_graph<P>& g, std::vector<V>& val);
+ data_(p_line_graph<P>& g,
+ std::vector<V>& node_val, std::vector<V>& edge_val);
- std::vector<V> val_;
- p_graph<P>& pg_;
+ std::vector<V> node_val_;
+ std::vector<V> edge_val_;
+ p_line_graph<P>& plg_;
};
} // end of namespace mln::internal
@@ -68,7 +82,8 @@
{
template <typename P, typename V>
- struct image_< graph_image<P, V> > : default_image_< V, graph_image<P, V> >
+ struct image_< line_graph_image<P, V> >
+ : default_image_< V, line_graph_image<P, V> >
{
typedef trait::image::category::primary category;
@@ -91,11 +106,12 @@
*
*/
template <typename P, typename V>
- struct graph_image :
- public internal::image_primary_< p_graph<P>, graph_image<P, V> >
+ struct line_graph_image :
+ public internal::image_primary_< p_line_graph<P>, line_graph_image<P, V> >
{
- typedef mln::internal::image_base_< p_graph<P>, graph_image<P, V> > super_;
+ typedef mln::internal::image_base_< p_line_graph<P>,
+ line_graph_image<P, V> > super_;
/// Value associated type.
typedef V value;
@@ -111,20 +127,22 @@
/// Skeleton.
- typedef graph_image< tag::psite_<P>, tag::value_<V> > skeleton;
+ typedef line_graph_image< tag::psite_<P>, tag::value_<V> > skeleton;
/// Constructors.
- graph_image(p_graph<P>& g, std::vector<V>& val);
- graph_image();
+ line_graph_image(p_line_graph<P>& g,
+ std::vector<V>& node_val, std::vector<V>& edge_val);
+ line_graph_image();
/// Initialize an empty image.
- void init_(p_graph<P>& g, std::vector<V>& val);
+ void init_(p_line_graph<P>& g,
+ std::vector<V>& node_val, std::vector<V>& edge_val);
/// Read-only access of pixel value at point site \p p.
- const V& operator()(const graph_psite<P>& p) const;
+ const V& operator()(const line_graph_psite<P>& p) const;
/// Read-write access of pixel value at point site \p p.
- V& operator()(const graph_psite<P>& p);
+ V& operator()(const line_graph_psite<P>& p);
/// Give the set of values of the image.
const vset& values() const;
@@ -132,7 +150,9 @@
// FIXME: Keep this name?
const std::vector<V>& data_values () const;
- const p_graph<P>& domain() const;
+ const p_line_graph<P>& domain() const;
+
+ // FIXME: Do we want to provide these two methods?
/// Return the point of the first node adjacent to the edge with
/// id \a e.
@@ -145,7 +165,8 @@
// Fwd decl.
template <typename P, typename V>
void init_(tag::image_t,
- graph_image<P, V>& target, const graph_image<P, V>& model);
+ line_graph_image<P, V>& target,
+ const line_graph_image<P, V>& model);
# ifndef MLN_INCLUDE_ONLY
@@ -157,7 +178,8 @@
template <typename P, typename V>
inline
void init_(tag::image_t,
- graph_image<P, V>& target, const graph_image<P, V>& model)
+ line_graph_image<P, V>& target,
+ const line_graph_image<P, V>& model)
{
/* FIXME: Unfortunately, we cannot simply use
@@ -165,9 +187,9 @@
here, since domain() and data_values() return const data, and
init_ expects non mutable data. These constness problems exist
- also in graph_psite (see uses of const_cast<>). Hence the
+ also in line_graph_psite (see uses of const_cast<>). Hence the
inelegant use of const_cast<>'s. */
- target.init_(const_cast<p_graph<P>&> (model.domain()),
+ target.init_(const_cast<p_line_graph<P>&>(model.domain()),
const_cast<std::vector<V>&> (model.data_values ()));
}
@@ -179,9 +201,12 @@
{
template <typename P, typename V>
inline
- data_< graph_image<P, V> >::data_(p_graph<P>& g, std::vector<V>& val)
- : val_ (val),
- pg_ (g)
+ data_< line_graph_image<P, V> >::data_(p_line_graph<P>& g,
+ std::vector<V>& node_val,
+ std::vector<V>& edge_val)
+ : node_val_(node_val),
+ edge_val_(edge_val),
+ plg_(g)
{
}
@@ -193,28 +218,33 @@
template <typename P, typename V>
inline
- graph_image<P, V>::graph_image(p_graph<P>& g, std::vector<V>& val)
+ line_graph_image<P, V>::line_graph_image(p_line_graph<P>& g,
+ std::vector<V>& node_val,
+ std::vector<V>& edge_val)
{
- init_(g, val);
+ init_(g, node_val, edge_val);
}
template <typename P, typename V>
inline
- graph_image<P, V>::graph_image()
+ line_graph_image<P, V>::line_graph_image()
{
}
template <typename P, typename V>
inline
void
- graph_image<P, V>::init_(p_graph<P>& g, std::vector<V>& val)
+ line_graph_image<P, V>::init_(p_line_graph<P>& g,
+ std::vector<V>& node_val,
+ std::vector<V>& edge_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_< graph_image<P, V> > (g, val);
+ this->data_ =
+ new internal::data_< line_graph_image<P, V> >(g, node_val, edge_val);
}
/*---------------.
@@ -224,27 +254,27 @@
template <typename P, typename V>
inline
const V&
- graph_image<P, V>::operator()(const graph_psite<P>& p) const
+ line_graph_image<P, V>::operator()(const line_graph_psite<P>& p) const
{
- mln_precondition(&p.pg() == &this->data_->pg_);
- mln_precondition(p.id() < this->data_->val_.size());
- return this->data_->val_[p.id()];
+ mln_precondition(&p.plg() == &this->data_->plg_);
+ mln_precondition(p.id() < this->data_->edge_val_.size());
+ return this->data_->edge_val_[p.id()];
}
template <typename P, typename V>
inline
V&
- graph_image<P, V>::operator()(const graph_psite<P>& p)
+ line_graph_image<P, V>::operator()(const line_graph_psite<P>& p)
{
- mln_precondition(&p.pg() == &this->data_->pg_);
- mln_precondition(p.id() < this->data_->val_.size());
- return this->data_->val_[p.id()];
+ mln_precondition(&p.plg() == &this->data_->plg_);
+ mln_precondition(p.id() < this->data_->edge_val_.size());
+ return this->data_->edge_val_[p.id()];
}
template <typename P, typename V>
inline
const mln::value::set<V> &
- graph_image<P, V>::values() const
+ line_graph_image<P, V>::values() const
{
return vset::the();
}
@@ -252,24 +282,24 @@
template <typename P, typename V>
inline
const std::vector<V>&
- graph_image<P, V>::data_values () const
+ line_graph_image<P, V>::data_values() const
{
- return this->data_->val_;
+ return this->data_->edge_val_;
}
template <typename P, typename V>
inline
- const p_graph<P>&
- graph_image<P, V>::domain() const
+ const p_line_graph<P>&
+ line_graph_image<P, V>::domain() const
{
mln_precondition(this->has_data());
- return this->data_->pg_;
+ return this->data_->plg_;
}
template <typename P, typename V>
inline
const P&
- graph_image<P, V>::node1(const util::edge_id& e) const
+ line_graph_image<P, V>::node1(const util::edge_id& e) const
{
// FIXME: Improve the interface of graph to avoid these low-level
// manipulations.
@@ -280,7 +310,7 @@
template <typename P, typename V>
inline
const P&
- graph_image<P, V>::node2(const util::edge_id& e) const
+ line_graph_image<P, V>::node2(const util::edge_id& e) const
{
// FIXME: Improve the interface of graph to avoid these low-level
// manipulations.
@@ -293,4 +323,4 @@
} // end of namespace mln
-#endif // ! MLN_CORE_GRAPH_IMAGE_HH
+#endif // ! MLN_CORE_LINE_GRAPH_IMAGE_HH
Index: mln/core/line_graph_psite.hh
--- mln/core/line_graph_psite.hh (revision 1714)
+++ mln/core/line_graph_psite.hh (working copy)
@@ -25,134 +25,200 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_GRAPH_PSITE_HH
-# define MLN_CORE_GRAPH_PSITE_HH
+#ifndef MLN_CORE_LINE_GRAPH_PSITE_HH
+# define MLN_CORE_LINE_GRAPH_PSITE_HH
-/// \file mln/core/graph_psite.hh
-/// \brief Definition of a graph-based point site.
+/// \file mln/core/line_graph_psite.hh
+/// \brief Definition of a line graph-based point site.
-# include <mln/core/p_graph.hh>
+# include <mln/core/p_line_graph.hh>
+# include <mln/core/point_pair.hh>
+
+/* FIXME: This class shares a lot with graph_psite. Factor as much as
+ possible. */
namespace mln
{
// Fwd decl.
- template<typename P> class p_graph;
+ template<typename P> class p_line_graph;
/// \brief Point site associated to a mln::graph_image.
template<typename P>
- class graph_psite : public Point_Site< graph_psite<P> >
+ class line_graph_psite : public Point_Site< line_graph_psite<P> >
{
- typedef graph_psite<P> self_;
+ typedef line_graph_psite<P> self_;
public:
- typedef mln_mesh(P) mesh;
- enum { dim = P::dim };
- typedef P point;
- typedef mln_dpoint(P) dpoint;
- typedef mln_coord(P) coord;
+ typedef point_pair<P> point;
+ typedef mln_mesh(point) mesh;
+ enum { dim = point::dim };
+ typedef mln_dpoint(point) dpoint;
+ typedef mln_coord(point) coord;
/// Construction and assignment.
/// \{
- graph_psite(const p_graph<P>& pg_, unsigned id);
- graph_psite(const self_& rhs);
+ line_graph_psite(const p_line_graph<P>& plg_, unsigned id);
+ line_graph_psite(const self_& rhs);
self_& operator= (const self_& rhs);
/// \}
/// Access to point/psite.
/// \{
- operator P() const;
+ operator point() const;
const point& to_point() const;
coord operator[](unsigned id) const;
/// \}
- /// Return the mln::p_graph this point site belongs to.
- const p_graph<P>& pg() const;
+ /// Return the mln::p_line_graph this point site belongs to.
+ const p_line_graph<P>& plg() const;
/// Return the node id of this point site.
util::node_id id() const;
private:
- const p_graph<P>& pg_;
- util::node_id id_;
+ /// Update \a p_.
+ void update_();
+ /// Is this psite valid?
+ bool is_valid_() const;
+
+ private:
+ /// The p_line_graph this point site belongs to.
+ const p_line_graph<P>& plg_;
+ /// The id of the edge this psite is pointing towards.
+ util::edge_id id_;
+ /** \brief The point associated to this psite.
+
+ Contrary to mln::graph_psite, this information is actually
+ stored in the mln::line_graph_psite. In mln::graph_psite, the
+ point is retrieved from the data associated with the
+ corresponding node in the graph. We cannot do this here,
+ since points associated to edges are computed on the fly
+ (storing them in the graph could be possible, but too costly
+ in space). */
+ point p_;
};
+ /* FIXME: This hand-made delegation is painful. We should rely on
+ the general mechanism provided by Point_Site. But then again, we
+ need to refine/adjust the interface of Point_Site w.r.t. the
+ mandatory conversions to points. */
+ template <typename P>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const line_graph_psite<P>& p);
# ifndef MLN_INCLUDE_ONLY
+ /* Careful, the current interface of line_graph_psite allows the
+ construction of ill-formed psites (i.e., whose edge is is beyond
+ bounds). Actually, p_line_graph_piters *do* create ill-formed
+ psites at their initialization. */
+
template<typename P>
inline
- graph_psite<P>::graph_psite(const p_graph<P>& g, util::node_id id)
- : pg_(g),
- id_(id)
+ line_graph_psite<P>::line_graph_psite(const p_line_graph<P>& g,
+ util::edge_id id)
+ : plg_(g),
+ id_(id),
+ p_()
{
}
template<typename P>
inline
- graph_psite<P>::graph_psite(const graph_psite<P>& rhs)
- : pg_(rhs.pg_),
+ line_graph_psite<P>::line_graph_psite(const line_graph_psite<P>& rhs)
+ : plg_(rhs.plg_),
id_(rhs.id_)
{
}
template<typename P>
inline
- graph_psite<P>&
- graph_psite<P>::operator= (const graph_psite<P>& rhs)
+ line_graph_psite<P>&
+ line_graph_psite<P>::operator= (const line_graph_psite<P>& rhs)
{
if (&rhs == this)
return *this;
// FIXME: Could we get rid of this cast?
- const_cast< p_graph<P>& >(pg_) = rhs.pg_;
+ const_cast< p_line_graph<P>& >(plg_) = rhs.plg_;
id_ = rhs.id_;
+ update_();
return *this;
}
template<typename P>
inline
- graph_psite<P>::operator P() const
+ line_graph_psite<P>::operator point_pair<P>() const
+ {
+ mln_assertion (is_valid_());
+ return p_;
+ }
+
+ template<typename P>
+ inline
+ bool
+ line_graph_psite<P>::is_valid_() const
{
- return pg_.gr_.node_data(id_);
+ return id_ < plg_.gr_.nedges();
}
template<typename P>
inline
- const P&
- graph_psite<P>::to_point() const
+ const point_pair<P>&
+ line_graph_psite<P>::to_point() const
{
- return pg_.gr_.node_data(id_);
+ return p_;
}
template<typename P>
inline
- mln_coord(P)
- graph_psite<P>::operator[](util::node_id id) const
+ mln_coord(point_pair<P>)
+ line_graph_psite<P>::operator[](unsigned i) const
{
- return to_point()[id];
+ mln_assertion (is_valid_());
+ return to_point()[i];
}
template<typename P>
inline
- const p_graph<P>&
- graph_psite<P>::pg() const
+ void
+ line_graph_psite<P>::update_()
{
- return pg_;
+ p_ = point(plg_.gr_.node_data(plg_.gr_.edge(id_).n1()),
+ plg_.gr_.node_data(plg_.gr_.edge(id_).n2()));
+ }
+
+ template<typename P>
+ inline
+ const p_line_graph<P>&
+ line_graph_psite<P>::plg() const
+ {
+ return plg_;
}
template<typename P>
inline
util::node_id
- graph_psite<P>::id() const
+ line_graph_psite<P>::id() const
{
return id_;
}
+
+ template <typename P>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const line_graph_psite<P>& p)
+ {
+ return ostr << p.to_point();
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of mln
-#endif // MLN_CORE_GRAPH_PSITE_HH
+#endif // MLN_CORE_LINE_GRAPH_PSITE_HH
Index: mln/core/line_graph_window_piter.hh
--- mln/core/line_graph_window_piter.hh (revision 1714)
+++ mln/core/line_graph_window_piter.hh (working copy)
@@ -25,51 +25,56 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_GRAPH_WINDOW_PITER_HH
-# define MLN_CORE_GRAPH_WINDOW_PITER_HH
+#ifndef MLN_CORE_LINE_GRAPH_WINDOW_PITER_HH
+# define MLN_CORE_LINE_GRAPH_WINDOW_PITER_HH
-/// \file mln/core/graph_window_piter.hh
-/// \brief Definition of a point iterator on a graph window.
+/// \file mln/core/line_graph_window_piter.hh
+/// \brief Definition of a point iterator on a line_graph window.
# include <mln/core/concept/point_iterator.hh>
-# include <mln/core/p_graph.hh>
-# include <mln/core/graph_psite.hh>
+# include <mln/core/p_line_graph.hh>
+# include <mln/core/line_graph_psite.hh>
+# include <mln/core/point_pair.hh>
/* FIXME: Doc. */
-/* FIXME: Due to the poor interface of mln::p_graph and
+/* FIXME: Due to the poor interface of mln::p_line_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 p_graph;
- template <typename P> class graph_psite;
+ template <typename P> class p_line_graph;
+ template <typename P> class line_graph_psite;
+ /*---------------------------------.
+ | line_graph_window_fwd_piter<P>. |
+ `---------------------------------*/
+
template <typename P>
- class graph_window_fwd_piter :
- public Point_Iterator< graph_window_fwd_piter<P> > // or Iterator<...>?
+ class line_graph_window_fwd_piter :
+ public Point_Iterator< line_graph_window_fwd_piter<P> > // or Iterator<...>?
{
- typedef graph_window_fwd_piter<P> self_;
+ typedef line_graph_window_fwd_piter<P> self_;
typedef Point_Iterator< self_ > super_;
public:
- typedef graph_psite<P> psite;
+ typedef line_graph_psite<P> psite;
enum { dim = P::dim };
// FIXME: Dummy value.
typedef void mesh;
- typedef P point;
+ typedef point_pair<P> point;
// FIXME: Dummy typedef.
typedef void dpoint;
- typedef mln_coord(P) coord;
+ typedef mln_coord(point) coord;
public:
template <typename W, typename Pref>
- graph_window_fwd_piter(const W& win, const Point_Site<Pref>& p_ref);
+ line_graph_window_fwd_piter(const W& win, const Point_Site<Pref>& p_ref);
bool is_valid() const;
void invalidate();
@@ -77,23 +82,44 @@
void next_();
bool adjacent_or_equal_to_p_ref_() const;
+ /// Update the internal data of the iterator.
+ void update_();
- // FIXME: In fact, this method should be named `to_psite', since
- // it returns a mln::graph_psite<P> object, not a P object.
const point& to_point() const;
+ const psite& to_psite() const;
+
+ operator point() const;
operator psite () const;
+
/// Return the \a i th coordinate of the (iterated) point.
coord operator[](unsigned i) const;
private:
- /// The ``central'' point of the window.
+ /// The ``central'' psite of the window.
const psite& p_ref_;
-
- /// An internal iterator on the set of nodes of the underlying graph.
- util::node_id id_;
+ /// An internal iterator on the set of edges of the underlying graph.
+ util::edge_id id_;
+ /// The psite corresponding to this iterator.
+ psite psite_;
+ /// The point corresponding to this iterator.
+ point p_;
};
- // FIXME: Implement graph_window_bkd_piter.
+ /* FIXME: This hand-made delegation is painful. We should rely on
+ the general mechanism provided by Point_Site. But then again, we
+ need to refine/adjust the interface of Point_Site w.r.t. the
+ mandatory conversions to points. */
+ template <typename P>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const line_graph_window_fwd_piter<P>& p);
+
+
+ /*---------------------------------.
+ | line_graph_window_bkd_piter<P>. |
+ `---------------------------------*/
+
+ // FIXME: Implement line_graph_window_bkd_piter.
# ifndef MLN_INCLUDE_ONLY
@@ -101,61 +127,76 @@
// FIXME: Currently, argument win is ignored.
template <typename P>
template <typename W, typename Pref>
- graph_window_fwd_piter<P>::graph_window_fwd_piter(const W& /* win */,
+ inline
+ line_graph_window_fwd_piter<P>::line_graph_window_fwd_piter(const W& /* win */,
const Point_Site<Pref>& p_ref)
- : p_ref_(exact(p_ref).to_psite())
+ : p_ref_(exact(p_ref).to_psite()),
+ // Initialize psite_ to a dummy value.
+ psite_(p_ref_.plg(), p_ref_.plg().nlines()),
+ p_()
{
// Invalidate id_.
invalidate();
}
template <typename P>
+ inline
bool
- graph_window_fwd_piter<P>::is_valid() const
+ line_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 id_ < p_ref_.pg().gr_.nnodes();
+ return id_ < p_ref_.plg().gr_.nedges();
}
template <typename P>
+ inline
void
- graph_window_fwd_piter<P>::invalidate()
+ line_graph_window_fwd_piter<P>::invalidate()
{
- id_ = p_ref_.pg().gr_.nnodes();
+ id_ = p_ref_.plg().gr_.nedges();
}
template <typename P>
+ inline
void
- graph_window_fwd_piter<P>::start()
+ line_graph_window_fwd_piter<P>::start()
{
id_ = 0;
if (!adjacent_or_equal_to_p_ref_())
next_();
+ /* FIXME: This is redundant with the end of next_(), but we might
+ change the implementation of start_() when we'll fix it later,
+ and no longer use next_(). */
+ if (is_valid())
+ update_();
}
template <typename P>
+ inline
void
- graph_window_fwd_piter<P>::next_()
+ line_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
+ to produce the set of adjacent edges fast. Boost Graphs
probably provides adequates structures to fetch these
neighbors in constant time. */
/* FIXME: Moreover, the behavior of next shall depend on the
- window, which is not the case now! */
+ window, which is not the case now! (Currently, next_() behaves
+ as win was always an elementary window.) */
do
++id_;
while (is_valid() && !adjacent_or_equal_to_p_ref_());
+ if (is_valid())
+ update_();
}
template <typename P>
+ inline
bool
- graph_window_fwd_piter<P>::adjacent_or_equal_to_p_ref_() const
+ line_graph_window_fwd_piter<P>::adjacent_or_equal_to_p_ref_() const
{
- // FIXME: Likewise, this is inefficient.
-
// Check wether the iterator points to P_REF_.
if (id_ == p_ref_.id())
return true;
@@ -163,15 +204,19 @@
// Check whether the iterator is among the neighbors of P_REF_.
{
// Paranoid assertion.
- assert (p_ref_.id() < p_ref_.pg().gr_.nnodes());
- // FIXME: This is too low-level. Yet another service the graph
- // should provide.
- typedef std::vector<util::node_id> adjacency_type;
- const adjacency_type& p_ref_neighbs =
- p_ref_.pg().gr_.nodes()[p_ref_.id()]->edges;
- adjacency_type::const_iterator j =
- std::find (p_ref_neighbs.begin(), p_ref_neighbs.end(), id_);
- if (j != p_ref_neighbs.end())
+ assert (p_ref_.id() < p_ref_.plg().gr_.nedges());
+ /* FIXME: We should have a convenient shortcut for these
+ repetitive accesses to p_ref_.plg().gr_ (e.g., a method gr()
+ or g() in this class. */
+ const typename p_line_graph<P>::graph& gr = p_ref_.plg().gr_;
+ // Check whether the edge this iterator points to is adjacent to
+ // the one p_ref points to, by comparing their ajacent nodes.
+ /* FIXME: This is too low-level. Yet another service the graph
+ // should provide. */
+ if (gr.edge(id_).n1() == gr.edge(p_ref_.id()).n1() ||
+ gr.edge(id_).n1() == gr.edge(p_ref_.id()).n2() ||
+ gr.edge(id_).n2() == gr.edge(p_ref_.id()).n1() ||
+ gr.edge(id_).n2() == gr.edge(p_ref_.id()).n2())
return true;
}
@@ -180,29 +225,70 @@
}
template <typename P>
- const P&
- graph_window_fwd_piter<P>::to_point() const
+ inline
+ void
+ line_graph_window_fwd_piter<P>::update_()
{
- return p_ref_.pg().gr_.node_data(id_);
+ // Update psite_.
+ psite_ = line_graph_psite<P>(p_ref_.plg(), id_);
+ // Update p_.
+ // FIXME: These repeated assignments might be very costly.
+ /* FIXME: Likewise, it's hard to read. Simplify accesses to the graph. */
+ p_ = point(p_ref_.plg().gr_.node_data(p_ref_.plg().gr_.edge(id_).n1()),
+ p_ref_.plg().gr_.node_data(p_ref_.plg().gr_.edge(id_).n2()));
}
template <typename P>
- graph_window_fwd_piter<P>::operator graph_psite<P> () const
+ inline
+ const point_pair<P>&
+ line_graph_window_fwd_piter<P>::to_point() const
{
- return graph_psite<P>(p_ref_.pg(), id_);
+ return p_;
}
template <typename P>
inline
- mln_coord(P)
- graph_window_fwd_piter<P>::operator[](unsigned i) const
+ const line_graph_psite<P>&
+ line_graph_window_fwd_piter<P>::to_psite() const
+ {
+ return psite_;
+ }
+
+ template <typename P>
+ inline
+ line_graph_window_fwd_piter<P>::operator point_pair<P>() const
+ {
+ mln_precondition(is_valid());
+ return p_;
+ }
+
+ template <typename P>
+ inline
+ line_graph_window_fwd_piter<P>::operator line_graph_psite<P> () const
+ {
+ mln_precondition(is_valid());
+ return psite_;
+ }
+
+ template <typename P>
+ inline
+ mln_coord(point_pair<P>)
+ line_graph_window_fwd_piter<P>::operator[](unsigned i) const
{
assert(i < dim);
- return to_point()[i];
+ return p_[i];
+ }
+
+ template <typename P>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const line_graph_window_fwd_piter<P>& p)
+ {
+ return ostr << p.to_point();
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
-#endif // ! MLN_CORE_GRAPH_WINDOW_PITER_HH
+#endif // ! MLN_CORE_LINE_GRAPH_WINDOW_PITER_HH
Index: mln/core/p_line_graph.hh
--- mln/core/p_line_graph.hh (revision 1714)
+++ mln/core/p_line_graph.hh (working copy)
@@ -25,41 +25,58 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_GRAPH_P_HH
-# define MLN_CORE_GRAPH_P_HH
+#ifndef MLN_CORE_LINE_GRAPH_P_HH
+# define MLN_CORE_LINE_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/graph_psite.hh>
-# include <mln/core/p_graph_piter.hh>
+# include <mln/core/line_graph_psite.hh>
+# include <mln/core/p_line_graph_piter.hh>
+# include <mln/core/point_pair.hh>
-/// \file mln/core/p_graph.hh
-/// \brief Definition of a point set based on graph.
+/* FIXME: This class shares a lot with p_graph. Factor as much as
+ possible. */
+
+
+/// \file mln/core/p_line_graph.hh
+/// \brief Definition of a point set based on line graph.
namespace mln
{
- template<typename P> class p_graph_piter_;
+ // FIXME: Dummy specialization, only to have this first version of
+ // our code compile.
+ template <typename P>
+ struct box_< point_pair<P> > : public Box< box_<P> >
+ {
+ // Nothing.
+ };
+
+
+ template<typename P> class p_line_graph_piter_;
template<typename P>
- struct p_graph
- : public internal::point_set_base_< graph_psite<P>, p_graph<P> >
+ struct p_line_graph
+ : public internal::point_set_base_< line_graph_psite<P>, p_line_graph<P> >
{
typedef util::graph<P> graph;
- /// Construct a graph psite set from a graph of points.
- p_graph (graph& gr);
+ /// Construct a line graph psite set from a graph of points.
+ p_line_graph (graph& gr);
/// Point_Site associated type.
- typedef graph_psite<P> psite;
+ typedef line_graph_psite<P> psite;
+
+ /// Point associated type.
+ typedef point_pair<P> point;
/// Forward Point_Iterator associated type.
- typedef p_graph_piter_<P> fwd_piter;
+ typedef p_line_graph_piter_<P> fwd_piter;
/// Backward Point_Iterator associated type.
- typedef p_graph_piter_<P> bkd_piter;
+ typedef p_line_graph_piter_<P> bkd_piter;
/// Return The number of points (i.e., nodes) in the graph.
std::size_t npoints() const;
@@ -68,32 +85,37 @@
std::size_t nlines() const;
/// Give the exact bounding box.
- const box_<P>& bbox() const;
+ // FIXME: Dummy.
+ const box_<point>& bbox() const;
bool has(const psite& p) const;
// FIXME: Should be private.
graph gr_;
// FIXME: (Roland) Is it really useful/needed?
- /* 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_;
+ /* 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? In particular, an image whose sites
+ are actually /pairs of points/! */
+ // FIXME: Dummy.
+ box_<point> bb_;
};
# ifndef MLN_INCLUDE_ONLY
template<typename P>
inline
- p_graph<P>::p_graph (util::graph<P>& gr)
+ p_line_graph<P>::p_line_graph (util::graph<P>& gr)
: gr_ (gr)
{
- // FIXME: Warning: if the underlying graph is updated later, this
- // won't be taken into account by this p_graph!
- accu::bbox<P> a;
- for (unsigned i = 0; i < npoints(); ++i)
- a.take(gr_.node_data(i));
- bb_ = a.to_result();
+ // FIXME: Dummy initialization of bb_.
+// // FIXME: Warning: if the underlying graph is updated later, this
+// // won't be taken into account by this p_line_graph!
+// accu::bbox<point> a;
+// for (util::edge_id e = 0; e < nlines(); ++e)
+// a.take(point(gr_.node_data(gr_.edge(e).n1()),
+// gr_.node_data(gr_.edge(e).n2())));
+// bb_ = a.to_result();
}
// FIXME: Rename to npsites? In fact, this depends on the
@@ -101,7 +123,7 @@
template<typename P>
inline
std::size_t
- p_graph<P>::npoints() const
+ p_line_graph<P>::npoints() const
{
return this->gr_.nnodes();
}
@@ -109,15 +131,15 @@
template<typename P>
inline
std::size_t
- p_graph<P>::nlines() const
+ p_line_graph<P>::nlines() const
{
return this->gr_.nedges();
}
template<typename P>
inline
- const box_<P>&
- p_graph<P>::bbox() const
+ const box_< point_pair<P> >&
+ p_line_graph<P>::bbox() const
{
return bb_;
}
@@ -125,16 +147,13 @@
template<typename P>
inline
bool
- p_graph<P>::has(const psite& p) const
+ p_line_graph<P>::has(const psite& p) const
{
- // FIXME: util::graph (or util::internal::graph_base) should
- // provide the iteration facility (iterators, find, etc.)
- const typename graph::nodes_t& nodes = gr_.nodes();
- for (typename graph::nodes_t::const_iterator n = nodes.begin();
- n != nodes.end(); ++n)
- if ((*n)->data == p)
- return true;
- return false;
+ return
+ // Check whether P is compatible with this psite set.
+ (&p.plg() == this) &&
+ // Check that the edge id of P belongs to the range of valid edge ids.
+ (p.id() < gr_.nedges());
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/p_line_graph_piter.hh
--- mln/core/p_line_graph_piter.hh (revision 1714)
+++ mln/core/p_line_graph_piter.hh (working copy)
@@ -25,14 +25,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_P_GRAPH_PITER_HH
-# define MLN_CORE_P_GRAPH_PITER_HH
+#ifndef MLN_CORE_P_LINE_GRAPH_PITER_HH
+# define MLN_CORE_P_LINE_GRAPH_PITER_HH
# include <mln/core/internal/point_iterator_base.hh>
-# include <mln/core/p_graph.hh>
-# include <mln/core/graph_psite.hh>
+# include <mln/core/p_line_graph.hh>
+# include <mln/core/line_graph_psite.hh>
+# include <mln/core/point_pair.hh>
-/*! \file mln/core/p_graph_piter.hh
+/*! \file mln/core/p_line_graph_piter.hh
*
* \brief Definition of point iterator on graph-based point set.
*/
@@ -40,30 +41,32 @@
namespace mln
{
// Fwd decls.
- template<typename P> class p_graph;
- template<typename P> class graph_psite;
+ template<typename P> class p_line_graph;
+ template<typename P> class line_graph_psite;
- // FIXME: Why `p_graph_piter_' and not `p_graph_piter' (without `_')?
+ // FIXME: Why `p_line_graph_piter_' and not `p_line_graph_piter'
+ // (without `_')?
template<typename P>
- class p_graph_piter_
- : public internal::point_iterator_base_< P, p_graph_piter_<P> >
+ class p_line_graph_piter_
+ : public internal::point_iterator_base_< P, p_line_graph_piter_<P> >
{
- typedef p_graph_piter_<P> self_;
+ typedef p_line_graph_piter_<P> self_;
typedef internal::point_iterator_base_< P, self_ > super_;
public:
// Make definitions from super class available.
enum { dim = super_::dim };
- typedef graph_psite<P> psite;
- typedef P point;
+ typedef line_graph_psite<P> psite;
+ typedef point_pair<P> point;
+ typedef mln_coord(point_pair<P>) coord;
- p_graph_piter_(const p_graph<P>& pg);
+ p_line_graph_piter_(const p_line_graph<P>& plg);
/// Read-only access to the \p i-th coordinate.
- mln_coord(P) operator[](unsigned i) const;
+ mln_coord(point) operator[](unsigned i) const;
/// Test if the iterator is valid.
bool is_valid() const;
@@ -93,32 +96,44 @@
operator psite() const;
protected:
- const p_graph<P>& pg_;
- unsigned i_;
- P p_;
+ /// The p_line_graph this point site belongs to.
+ const p_line_graph<P>& plg_;
+ /// The id of the edge this psite is pointing towards.
+ util::edge_id id_;
+ /// The psite corresponding to this iterator.
psite psite_;
+ /// The psite corresponding to this iterator.
+ point p_;
};
+ /* FIXME: This hand-made delegation is painful. We should rely on
+ the general mechanism provided by Point_Site. But then again, we
+ need to refine/adjust the interface of Point_Site w.r.t. the
+ mandatory conversions to points. */
+ template <typename P>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const p_line_graph_piter_<P>& p);
# ifndef MLN_INCLUDE_ONLY
template<typename P>
inline
- p_graph_piter_<P>::p_graph_piter_(const p_graph<P>& pg)
- : pg_(pg),
- p_(),
+ p_line_graph_piter_<P>::p_line_graph_piter_(const p_line_graph<P>& plg)
+ : plg_(plg),
// Initialize psite_ to a dummy value.
- psite_(pg, pg_.npoints())
+ psite_(plg, plg_.nlines()),
+ p_()
{
- // Invalidate i_.
+ // Invalidate id_.
invalidate();
}
template<typename P>
inline
- mln_coord(P)
- p_graph_piter_<P>::operator[](unsigned i) const
+ mln_coord(point_pair<P>)
+ p_line_graph_piter_<P>::operator[](unsigned i) const
{
return p_[i];
}
@@ -126,25 +141,25 @@
template<typename P>
inline
bool
- p_graph_piter_<P>::is_valid() const
+ p_line_graph_piter_<P>::is_valid() const
{
- return i_ < pg_.npoints();
+ return id_ < plg_.nlines();
}
template<typename P>
inline
void
- p_graph_piter_<P>::invalidate()
+ p_line_graph_piter_<P>::invalidate()
{
- i_ = pg_.npoints();
+ id_ = plg_.nlines();
}
template<typename P>
inline
void
- p_graph_piter_<P>::start()
+ p_line_graph_piter_<P>::start()
{
- i_ = 0;
+ id_ = 0;
if (is_valid())
update_();
}
@@ -152,9 +167,9 @@
template<typename P>
inline
void
- p_graph_piter_<P>::next_()
+ p_line_graph_piter_<P>::next_()
{
- ++i_;
+ ++id_;
if (is_valid())
update_();
}
@@ -162,18 +177,20 @@
template<typename P>
inline
void
- p_graph_piter_<P>::update_()
+ p_line_graph_piter_<P>::update_()
{
- // Update p_.
- p_ = pg_.gr_.node_data(i_);
// Update psite_.
- psite_ = graph_psite<P>(pg_, i_);
+ psite_ = line_graph_psite<P>(plg_, id_);
+ // Update p_.
+ // FIXME: These repeated assignments might be very costly.
+ p_ = point(plg_.gr_.node_data(plg_.gr_.edge(id_).n1()),
+ plg_.gr_.node_data(plg_.gr_.edge(id_).n2()));
}
template<typename P>
inline
- const P&
- p_graph_piter_<P>::to_point() const
+ const point_pair<P>&
+ p_line_graph_piter_<P>::to_point() const
{
/* We don't check whether the iterator is valid before returning
the value using
@@ -191,8 +208,8 @@
template<typename P>
inline
- const graph_psite<P>&
- p_graph_piter_<P>::to_psite() const
+ const line_graph_psite<P>&
+ p_line_graph_piter_<P>::to_psite() const
{
/* We don't check whether the iterator is valid before returning
the value using
@@ -210,7 +227,7 @@
template<typename P>
inline
- p_graph_piter_<P>::operator P() const
+ p_line_graph_piter_<P>::operator point_pair<P>() const
{
mln_precondition(is_valid());
return p_;
@@ -218,15 +235,24 @@
template<typename P>
inline
- p_graph_piter_<P>::operator graph_psite<P>() const
+ p_line_graph_piter_<P>::operator line_graph_psite<P>() const
{
mln_precondition(is_valid());
return psite_;
}
+
+ template <typename P>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const p_line_graph_piter_<P>& p)
+ {
+ return ostr << p.to_point();
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of mln
-#endif // MLN_P_GRAPH_PITER_HH
+#endif // MLN_P_LINE_GRAPH_PITER_HH
Index: tests/core/line_graph_elt_window.cc
--- tests/core/line_graph_elt_window.cc (revision 1715)
+++ tests/core/line_graph_elt_window.cc (working copy)
@@ -25,15 +25,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/core/graph_elt_window.cc
+/*! \file tests/core/line_graph_elt_window.cc
*
- * \brief Tests on mln::win::graph_elt_window.
+ * \brief Tests on mln::line_graph_elt_window.
*/
#include <vector>
#include <mln/core/point2d.hh>
-#include <mln/core/graph_elt_window.hh>
+#include <mln/core/line_graph_elt_window.hh>
#include <mln/debug/iota.hh>
#include <mln/debug/println.hh>
@@ -73,10 +73,10 @@
| Graph and window. |
`------------------*/
- // Graph psite set.
- p_graph<p_t> pg(g);
- // 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;
+ // Line graph psite set.
+ p_line_graph<p_t> plg(g);
+ // Line graph point site.
+ line_graph_psite<p_t> psite(plg, 0);
+ // ``Sliding'' window of a psite of PLG.
+ line_graph_elt_window<p_t> win;
}
Index: tests/core/line_graph_image.cc
--- tests/core/line_graph_image.cc (revision 1714)
+++ tests/core/line_graph_image.cc (working copy)
@@ -31,9 +31,9 @@
#include <vector>
#include <mln/core/point2d.hh>
-#include <mln/core/graph_image.hh>
-#include <mln/core/graph_elt_window.hh>
-#include <mln/core/graph_window_piter.hh>
+#include <mln/core/line_graph_image.hh>
+#include <mln/core/line_graph_elt_window.hh>
+#include <mln/core/line_graph_window_piter.hh>
#include <mln/morpho/dilation.hh>
@@ -74,44 +74,26 @@
| Graph. |
`-------*/
- p_graph<point2d> pg(g);
-
- /*-------------.
- | Graph image. |
- `-------------*/
-
- // Values ("empty" vector).
- std::vector<int> values(5);
- // 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 graph images is not easy right
- now (2008-02-05). We could use
-
- debug::println(ima);
-
- 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 graph_image to work with points (not psites).
- Moreover, this implementation only shows *values*, not the graph
- itslef.
-
- 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::graph and hand-made
- iterations. */
- image2d<int> ima_rep(ima.bbox());
- // 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::graph (ima_rep, ima, 9);
- debug::println (ima_rep);
+ p_line_graph<point2d> plg(g);
+ /*-------------------.
+ | Line graph image. |
+ `-------------------*/
+
+ // Values ("empty" vectors).
+ std::vector<int> node_values(5);
+ std::vector<int> edge_values(5);
+ // FIXME: hand-made iota's.
+ for (unsigned i = 0; i < node_values.size(); ++i)
+ node_values[i] = i;
+ for (unsigned i = 0; i < edge_values.size(); ++i)
+ edge_values[i] = i;
+
+ // Line graph image.
+ /* FIXME: We probably don't want to build line_graph_images by hand;
+ provide helpers and/or conversion functions. */
+ typedef line_graph_image<point2d, int> ima_t;
+ ima_t ima(plg, node_values, edge_values);
/*------------.
| Iterators. |
@@ -123,7 +105,7 @@
std::cout << "ima (" << p << ") = " << ima(p) << std::endl;
// Manual iterations over the neighborhoods of each point site of IMA.
- typedef graph_elt_window<point2d> win_t;
+ typedef line_graph_elt_window<point2d> win_t;
win_t win;
mln_qiter_(win_t) q(win, p);
for_all (p)
@@ -131,19 +113,30 @@
std::cout << "neighbors of " << p << " (" << ima(p) << "), "
<< "including the site itself:" << std::endl;
for_all (q)
- std::cout << " " << q << " (level = " << ima(q) << ")" << std::endl;
+ std::cout << " " << q << " (level = " << ima(q) << ")"
+ << std::endl;
}
std::cout << std::endl;
- /*-------------------------.
- | Processing graph images. |
- `-------------------------*/
-
- graph_image<point2d, int> ima_dil = morpho::dilation(ima, win);
- draw::graph(ima_rep, ima_dil, 9);
- debug::println(ima_rep);
-
- graph_image<point2d, int> ima_ero = morpho::erosion(ima, win);
- draw::graph(ima_rep, ima_ero, 9);
- debug::println(ima_rep);
+
+// /* FIXME: When implementing convert::to_line_graph_image, don't
+// forget to give a second argument defaulting to something like
+// fun::vv2v::max(). This second argument is a functor used to
+// compute the values of the edges of the line graph image. */
+// image2d ima; // = ...
+// lg_ima_t lg_ima = convert::to_line_graph_image (ima);
+
+// // Image2d representation.
+// image2d<value_t> out = convert::to_image2d (lg_ima);
+// io::pgm::save(out, "out.pgm");
+
+// /* FIXME: Then, add some real processing on the line graph image
+// before converting to an image2d:
+// - erosion/dilation,
+// - Beucher's gradient,
+// - Meyer's WST (on the gradient of LG_IMA?),
+// - attribute filters (see my notes on Laurent's remarks about
+// attributes),
+// - etc.
+// Creating seperate tests for all these would be wise. */
}
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 1717)
+++ tests/core/Makefile.am (working copy)
@@ -10,19 +10,21 @@
initialize \
graph_elt_window \
graph_image \
+ line_graph_elt_window \
+ line_graph_image \
mono_obased_rle_image \
mono_rle_image \
obased_rle_image \
- p_runs \
- rle_image \
- sparse_image \
- t_image \
- tr_image \
p_priority_queue \
p_priority_queue_fast \
p_priority_queue_fast_with_array \
p_queue \
- p_queue_fast
+ p_queue_fast \
+ p_runs \
+ rle_image \
+ sparse_image \
+ t_image \
+ tr_image
category_SOURCES = category.cc
clone_SOURCES = clone.cc
@@ -31,18 +33,20 @@
initialize_SOURCES = initialize.cc
graph_elt_window_SOURCES = graph_elt_window.cc
graph_image_SOURCES = graph_image.cc
+line_graph_elt_window_SOURCES = line_graph_elt_window.cc
+line_graph_image_SOURCES = line_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
-p_runs_SOURCES = p_runs.cc
-rle_image_SOURCES = rle_image.cc
-sparse_image_SOURCES = sparse_image.cc
-t_image_SOURCES = t_image.cc
-tr_image_SOURCES = tr_image.cc
p_priority_queue_SOURCES = p_priority_queue.cc
p_priority_queue_fast_SOURCES = p_priority_queue_fast.cc
p_priority_queue_fast_with_array_SOURCES = p_priority_queue_fast.cc
p_queue_SOURCES = p_priority_queue_fast.cc
p_queue_fast_SOURCES = p_priority_queue_fast.cc
+p_runs_SOURCES = p_runs.cc
+rle_image_SOURCES = rle_image.cc
+sparse_image_SOURCES = sparse_image.cc
+t_image_SOURCES = t_image.cc
+tr_image_SOURCES = tr_image.cc
TESTS = $(check_PROGRAMS)
1
0
1717: Initialize the last component of h_vec's to 1 in default ctor. .
by Roland Levillain 11 Feb '08
by Roland Levillain 11 Feb '08
11 Feb '08
https://svn.lrde.epita.fr/svn/oln/trunk/milena
This error was triggered by the corresponding test (tests/core/h_vec).
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Initialize the last component of h_vec's to 1 in default ctor. .
* mln/core/h_vec.hh (h_vec<d,C>::h_vec): Initialize the last
component to the unit (1) to prevent unitialized vectors from
triggering division-by-zero errors.
h_vec.hh | 5 +++++
1 file changed, 5 insertions(+)
Index: mln/core/h_vec.hh
--- mln/core/h_vec.hh (revision 1716)
+++ mln/core/h_vec.hh (working copy)
@@ -110,6 +110,11 @@
inline
h_vec<d,C>::h_vec()
{
+ /* Safety measure: set the last component to the unit (1). This
+ way, converting an unitialized h_vec to a vector won't trigger
+ division-by-zero errors if this last component were randomly
+ initialized to 0. */
+ this->data_[d] = literal::one;
}
template <unsigned d, typename C>
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Fix documentation.
* mln/util/graph.hh, mln/util/internal/graph_base.hh: fix documentation
graph_base.hh | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Index: mln/util/graph.hh
Index: mln/util/internal/graph_base.hh
--- mln/util/internal/graph_base.hh (revision 1715)
+++ mln/util/internal/graph_base.hh (working copy)
@@ -50,12 +50,12 @@
Conversion to and from unsigned would still be useful, but it
might be safer to turn them into explicit ones. */
- /// \bref The type used to identify nodes.
+ /// \brief 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.
+ /// \brief The type used to identify edges.
///
/// Used internally as a key to manipulate edges.
typedef unsigned edge_id;
@@ -82,7 +82,7 @@
template<>
struct node<void>
{
- std::list<node_id> edges;
+ std::list<edge_id> edges;
};
2
1
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Revamp iterators on windows on graphs.
* mln/core/graph_window_piter.hh: Add missing inline `keywords' on
methods.
(graph_window_fwd_piter<P>::psite_)
(graph_window_fwd_piter<P>::p_):
New attributes.
(graph_window_fwd_piter<P>::graph_window_fwd_piter): Adjust ctor.
(graph_window_fwd_piter<P>::update_): New method.
Use it...
(graph_window_fwd_piter<P>::start)
(graph_window_fwd_piter<P>::next_)
...here
(graph_window_fwd_piter<P>::to_psite)
(graph_window_fwd_piter<P>::operator point):
New methods.
(graph_window_fwd_piter<P>::to_psite)
(graph_window_fwd_piter<P>::operator psite)
(graph_window_fwd_piter<P>::operator[]):
Adjust.
* mln/core/p_graph.hh (p_graph<P>::has): Rewrite this method using
a much simpler and faster approach.
* mln/core/p_graph_piter.hh
(p_graph_piter_<P>::i_): Rename as...
(p_graph_piter_<P>::id_): ...this.
(p_graph_piter_<P>::p_graph_piter_): Adjust ctor.
(p_graph_piter_<P>::is_valid)
(p_graph_piter_<P>::invalidate)
(p_graph_piter_<P>::start)
(p_graph_piter_<P>::next_)
(p_graph_piter_<P>::update_):
Adjust.
* mln/core/graph_psite.hh: More doc.
* mln/core/graph_elt_window.hh: Fix header guards.
* mln/core/graph_image.hh: Aesthetic changes.
* mln/util/internal/graph_base.hh: More FIXME.
core/graph_elt_window.hh | 6 +--
core/graph_image.hh | 6 +--
core/graph_psite.hh | 4 +-
core/graph_window_piter.hh | 74 ++++++++++++++++++++++++++++++++++++++------
core/p_graph.hh | 13 ++-----
core/p_graph_piter.hh | 28 +++++++++-------
util/internal/graph_base.hh | 6 +++
7 files changed, 100 insertions(+), 37 deletions(-)
Index: mln/core/graph_elt_window.hh
--- mln/core/graph_elt_window.hh (revision 1714)
+++ mln/core/graph_elt_window.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_WIN_GRAPH_ELT_WINDOW_HH
-# define MLN_WIN_GRAPH_ELT_WINDOW_HH
+#ifndef MLN_CORE_GRAPH_ELT_WINDOW_HH
+# define MLN_CORE_GRAPH_ELT_WINDOW_HH
/*! \file mln/core/graph_elt_window.hh
*
@@ -168,4 +168,4 @@
} // end of namespace mln
-#endif // ! MLN_WIN_GRAPH_ELT_WINDOW_HH
+#endif // ! MLN_CORE_GRAPH_ELT_WINDOW_HH
Index: mln/core/graph_image.hh
--- mln/core/graph_image.hh (revision 1714)
+++ mln/core/graph_image.hh (working copy)
@@ -28,10 +28,8 @@
#ifndef MLN_CORE_GRAPH_IMAGE_HH
# define MLN_CORE_GRAPH_IMAGE_HH
-/*! \file mln/core/graph_image.hh
- *
- * \brief Definition of a graph-based image.
- */
+/// \file mln/core/graph_image.hh
+/// \brief Definition of a graph-based image.
# include <mln/trait/images.hh>
Index: mln/core/graph_psite.hh
--- mln/core/graph_psite.hh (revision 1714)
+++ mln/core/graph_psite.hh (working copy)
@@ -68,13 +68,15 @@
coord operator[](unsigned id) const;
/// \}
- /// Return the mln::p_graph this point site belongs to.
+ /// Return the p_graph this point site belongs to.
const p_graph<P>& pg() const;
/// Return the node id of this point site.
util::node_id id() const;
private:
+ // The p_graph this point site belongs to.
const p_graph<P>& pg_;
+ // The id of the node this psite is pointing towards.
util::node_id id_;
};
Index: mln/core/graph_window_piter.hh
--- mln/core/graph_window_piter.hh (revision 1714)
+++ mln/core/graph_window_piter.hh (working copy)
@@ -77,20 +77,29 @@
void next_();
bool adjacent_or_equal_to_p_ref_() const;
+ /// Update the internal data of the iterator.
+ void update_();
- // FIXME: In fact, this method should be named `to_psite', since
- // it returns a mln::graph_psite<P> object, not a P object.
const point& to_point() const;
+
+ const psite& to_psite() const;
+
+ operator point() const;
+
operator psite () const;
+
/// Return the \a i th coordinate of the (iterated) point.
coord operator[](unsigned i) const;
private:
- /// The ``central'' point of the window.
+ /// The ``central'' psite of the window.
const psite& p_ref_;
-
/// An internal iterator on the set of nodes of the underlying graph.
util::node_id id_;
+ // The psite corresponding to this iterator.
+ psite psite_;
+ // The point corresponding to this iterator.
+ point p_;
};
// FIXME: Implement graph_window_bkd_piter.
@@ -101,15 +110,20 @@
// FIXME: Currently, argument win is ignored.
template <typename P>
template <typename W, typename Pref>
+ inline
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())
+ : p_ref_(exact(p_ref).to_psite()),
+ // Initialize psite_ to a dummy value.
+ psite_(p_ref_.pg(), p_ref_.pg().npoints()),
+ p_()
{
// Invalidate id_.
invalidate();
}
template <typename P>
+ inline
bool
graph_window_fwd_piter<P>::is_valid() const
{
@@ -120,6 +134,7 @@
}
template <typename P>
+ inline
void
graph_window_fwd_piter<P>::invalidate()
{
@@ -127,15 +142,22 @@
}
template <typename P>
+ inline
void
graph_window_fwd_piter<P>::start()
{
id_ = 0;
if (!adjacent_or_equal_to_p_ref_())
next_();
+ /* FIXME: This is redundant with the end of next_(), but we might
+ change the implementation of start_() when we'll fix it later,
+ and no longer use next_(). */
+ if (is_valid())
+ update_();
}
template <typename P>
+ inline
void
graph_window_fwd_piter<P>::next_()
{
@@ -144,13 +166,17 @@
probably provides adequates structures to fetch these
neighbors in constant time. */
/* FIXME: Moreover, the behavior of next shall depend on the
- window, which is not the case now! */
+ window, which is not the case now! (Currently, next_() behaves
+ as win was always an elementary window.) */
do
++id_;
while (is_valid() && !adjacent_or_equal_to_p_ref_());
+ if (is_valid())
+ update_();
}
template <typename P>
+ inline
bool
graph_window_fwd_piter<P>::adjacent_or_equal_to_p_ref_() const
{
@@ -180,16 +206,46 @@
}
template <typename P>
+ inline
+ void
+ graph_window_fwd_piter<P>::update_()
+ {
+ // Update psite_.
+ psite_ = graph_psite<P>(p_ref_.pg(), id_);
+ // Update p_.
+ p_ = p_ref_.pg().gr_.node_data(id_);
+ }
+
+ template <typename P>
+ inline
const P&
graph_window_fwd_piter<P>::to_point() const
{
- return p_ref_.pg().gr_.node_data(id_);
+ return p_;
+ }
+
+ template <typename P>
+ inline
+ const graph_psite<P>&
+ graph_window_fwd_piter<P>::to_psite() const
+ {
+ return psite_;
}
template <typename P>
+ inline
+ graph_window_fwd_piter<P>::operator P() const
+ {
+ mln_precondition(is_valid());
+ return p_;
+ }
+
+ template <typename P>
+ inline
graph_window_fwd_piter<P>::operator graph_psite<P> () const
{
- return graph_psite<P>(p_ref_.pg(), id_);
+ mln_precondition(is_valid());
+ return psite_;
}
template <typename P>
@@ -198,7 +254,7 @@
graph_window_fwd_piter<P>::operator[](unsigned i) const
{
assert(i < dim);
- return to_point()[i];
+ return p_[i];
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/p_graph.hh
--- mln/core/p_graph.hh (revision 1714)
+++ mln/core/p_graph.hh (working copy)
@@ -127,14 +127,11 @@
bool
p_graph<P>::has(const psite& p) const
{
- // FIXME: util::graph (or util::internal::graph_base) should
- // provide the iteration facility (iterators, find, etc.)
- const typename graph::nodes_t& nodes = gr_.nodes();
- for (typename graph::nodes_t::const_iterator n = nodes.begin();
- n != nodes.end(); ++n)
- if ((*n)->data == p)
- return true;
- return false;
+ return
+ // Check whether P is compatible with this psite set.
+ (&p.pg() == this) &&
+ // Check that the node id of P belongs to the range of valid node ids.
+ (p.id() < gr_.nnodes());
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/p_graph_piter.hh
--- mln/core/p_graph_piter.hh (revision 1714)
+++ mln/core/p_graph_piter.hh (working copy)
@@ -93,10 +93,14 @@
operator psite() const;
protected:
+ // The p_graph this point site belongs to.
const p_graph<P>& pg_;
- unsigned i_;
- P p_;
+ // The id of the node this psite is pointing towards.
+ unsigned id_;
+ // The psite corresponding to this iterator.
psite psite_;
+ // The point corresponding to this iterator.
+ point p_;
};
@@ -107,11 +111,11 @@
inline
p_graph_piter_<P>::p_graph_piter_(const p_graph<P>& pg)
: pg_(pg),
- p_(),
// Initialize psite_ to a dummy value.
- psite_(pg, pg_.npoints())
+ psite_(pg, pg_.npoints()),
+ p_()
{
- // Invalidate i_.
+ // Invalidate id_.
invalidate();
}
@@ -128,7 +132,7 @@
bool
p_graph_piter_<P>::is_valid() const
{
- return i_ < pg_.npoints();
+ return id_ < pg_.npoints();
}
template<typename P>
@@ -136,7 +140,7 @@
void
p_graph_piter_<P>::invalidate()
{
- i_ = pg_.npoints();
+ id_ = pg_.npoints();
}
template<typename P>
@@ -144,7 +148,7 @@
void
p_graph_piter_<P>::start()
{
- i_ = 0;
+ id_ = 0;
if (is_valid())
update_();
}
@@ -154,7 +158,7 @@
void
p_graph_piter_<P>::next_()
{
- ++i_;
+ ++id_;
if (is_valid())
update_();
}
@@ -164,10 +168,10 @@
void
p_graph_piter_<P>::update_()
{
- // Update p_.
- p_ = pg_.gr_.node_data(i_);
// Update psite_.
- psite_ = graph_psite<P>(pg_, i_);
+ psite_ = graph_psite<P>(pg_, id_);
+ // Update p_.
+ p_ = pg_.gr_.node_data(id_);
}
template<typename P>
Index: mln/util/internal/graph_base.hh
--- mln/util/internal/graph_base.hh (revision 1714)
+++ mln/util/internal/graph_base.hh (working copy)
@@ -44,6 +44,12 @@
namespace util
{
+ /* FIXME: We should create actual types for node_id and edge_id,
+ (not just typedefs), at least to prevent the user from using a
+ node_id where an edge_id is expected (and vice versa).
+ Conversion to and from unsigned would still be useful, but it
+ might be safer to turn them into explicit ones. */
+
/// \bref The type used to identify nodes.
///
/// Used internally as a key to manipulate nodes.
1
0
1714: Update to new mln::util::graph and improve graph-based entities.
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>
Catch up with the new interface of mln::util::graph and improve
graph-based entities.
* mln/core/p_graph.hh: Store points associated to nodes in the
graph itself, not in an separate array.
(p_graph<P>::graph): Set this typedef from `util::graph<void>' to
`util::graph<P>'.
(p_graph<P>::loc_): Remove.
(p_graph<P>::graph): Adjust ctor.
(p_graph<P>::npoints, p_graph<P>::nlines, p_graph<P>::has):
Use the new interface of mln::util::graph.
* mln/core/graph_psite.hh (graph_psite<P>::i_): Rename as
(graph_psite<P>::id_): ...this.
Make it a private argument.
(graph_psite<P>::pg_): Likewise.
(graph_psite<P>::id, graph_psite<P>::pg): New accessors.
Adjust users.
* mln/core/graph_image.hh
(graph_image<P, V>::access_location_link_node1)
(graph_image<P, V>::access_location_link_node2):
Rename as...
(graph_image<P, V>::node1)
(graph_image<P, V>::node2):
...these.
Use the new interface of mln::util::graph.
(graph_image<P, V>::operator())
Use the new interface of mln::graph_psite.
* mln/core/graph_window_piter.hh (graph_window_fwd_piter<P>::i_):
Rename as...
(graph_window_fwd_piter<P>::id_): ...this.
Set its to type from `unsigned' to `util::node_id'.
Adjust users.
(graph_window_fwd_piter<P>::is_valid)
(graph_window_fwd_piter<P>::invalidate)
(graph_window_fwd_piter<P>::adjacent_or_equal_to_p_ref_)
(graph_window_fwd_piter<P>::to_point)
(graph_window_fwd_piter<P>::operator graph_psite<P>):
Use the new interface of mln::util::graph.
* mln/core/p_graph_piter.hh (p_graph_piter_<P>::psite_set_):
Rename as...
(p_graph_piter_<P>::pg_): ...this.
Use the new interface of mln::p_graph.
(p_graph_piter_<P>::is_valid)
(p_graph_piter_<P>::invalidate)
(p_graph_piter_<P>::update_):
Likewise.
* mln/draw/graph.hh (draw::graph): Update to the new
interfaces of mln::util::graph and mln::p_graph.
* mln/draw/all.hh: Adjust and complete the list of included
headers.
* tests/core/graph_elt_window.cc,
* tests/core/graph_image.cc,
* tests/draw/graph.cc:
Update tests.
mln/core/graph_image.hh | 39 +++++++++++++----------
mln/core/graph_psite.hh | 68 ++++++++++++++++++++++++-----------------
mln/core/graph_window_piter.hh | 51 +++++++++++++-----------------
mln/core/p_graph.hh | 37 +++++++++++++---------
mln/core/p_graph_piter.hh | 18 +++++-----
mln/draw/all.hh | 4 +-
mln/draw/graph.hh | 33 ++++++++++---------
tests/core/graph_elt_window.cc | 6 +--
tests/core/graph_image.cc | 6 +--
tests/draw/graph.cc | 8 +---
10 files changed, 145 insertions(+), 125 deletions(-)
Index: mln/core/graph_psite.hh
--- mln/core/graph_psite.hh (revision 1713)
+++ mln/core/graph_psite.hh (working copy)
@@ -28,12 +28,8 @@
#ifndef MLN_CORE_GRAPH_PSITE_HH
# define MLN_CORE_GRAPH_PSITE_HH
-/*! \file mln/core/graph_psite.hh
- *
- * \brief Definition of a graph-based point site.
- *
- * \todo Clean-up!
- */
+/// \file mln/core/graph_psite.hh
+/// \brief Definition of a graph-based point site.
# include <mln/core/p_graph.hh>
@@ -45,11 +41,7 @@
template<typename P> class p_graph;
- /*!
- * \brief Point site associate to graph_image.
- *
- * \todo Fix access to member.
- */
+ /// \brief Point site associated to a mln::graph_image.
template<typename P>
class graph_psite : public Point_Site< graph_psite<P> >
{
@@ -64,27 +56,37 @@
/// Construction and assignment.
/// \{
- graph_psite(const p_graph<P>& pg_, unsigned i);
+ graph_psite(const p_graph<P>& pg_, unsigned id);
graph_psite(const self_& rhs);
self_& operator= (const self_& rhs);
/// \}
+ /// Access to point/psite.
+ /// \{
operator P() const;
const point& to_point() const;
- coord operator[](unsigned i) const;
+ coord operator[](unsigned id) const;
+ /// \}
- // FIXME: These shouldn't be public.
+ /// Return the mln::p_graph this point site belongs to.
+ const p_graph<P>& pg() const;
+ /// Return the node id of this point site.
+ util::node_id id() const;
+
+ private:
const p_graph<P>& pg_;
- unsigned i_;
+ util::node_id id_;
};
+
+
# ifndef MLN_INCLUDE_ONLY
template<typename P>
inline
- graph_psite<P>::graph_psite(const p_graph<P>& g, unsigned i)
+ graph_psite<P>::graph_psite(const p_graph<P>& g, util::node_id id)
: pg_(g),
- i_(i)
+ id_(id)
{
}
@@ -92,7 +94,7 @@
inline
graph_psite<P>::graph_psite(const graph_psite<P>& rhs)
: pg_(rhs.pg_),
- i_(rhs.i_)
+ id_(rhs.id_)
{
}
@@ -105,7 +107,7 @@
return *this;
// FIXME: Could we get rid of this cast?
const_cast< p_graph<P>& >(pg_) = rhs.pg_;
- i_ = rhs.i_;
+ id_ = rhs.id_;
return *this;
}
@@ -113,9 +115,7 @@
inline
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 pg_.loc_[i_];
+ return pg_.gr_.node_data(id_);
}
template<typename P>
@@ -123,17 +123,31 @@
const P&
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 pg_.loc_[i_];
+ return pg_.gr_.node_data(id_);
}
template<typename P>
inline
mln_coord(P)
- graph_psite<P>::operator[](unsigned i) const
+ graph_psite<P>::operator[](util::node_id id) const
+ {
+ return to_point()[id];
+ }
+
+ template<typename P>
+ inline
+ const p_graph<P>&
+ graph_psite<P>::pg() const
+ {
+ return pg_;
+ }
+
+ template<typename P>
+ inline
+ util::node_id
+ graph_psite<P>::id() const
{
- return to_point()[i];
+ return id_;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/p_graph.hh
--- mln/core/p_graph.hh (revision 1713)
+++ mln/core/p_graph.hh (working copy)
@@ -44,12 +44,13 @@
template<typename P> class p_graph_piter_;
template<typename P>
- struct p_graph : public internal::point_set_base_< graph_psite<P>, p_graph<P> >
+ struct p_graph
+ : public internal::point_set_base_< graph_psite<P>, p_graph<P> >
{
- typedef util::graph<void> graph;
+ typedef util::graph<P> graph;
- /// Construct a graph psite set from a graph and an array of locations.
- p_graph (graph& gr, std::vector<P>& loc);
+ /// Construct a graph psite set from a graph of points.
+ p_graph (graph& gr);
/// Point_Site associated type.
typedef graph_psite<P> psite;
@@ -71,8 +72,8 @@
bool has(const psite& p) const;
+ // FIXME: Should be private.
graph gr_;
- std::vector<P> loc_;
// FIXME: (Roland) Is it really useful/needed?
/* 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
@@ -84,22 +85,25 @@
template<typename P>
inline
- p_graph<P>::p_graph (util::graph<void>& gr, std::vector<P>& loc)
- : gr_ (gr),
- loc_ (loc)
+ p_graph<P>::p_graph (util::graph<P>& gr)
+ : gr_ (gr)
{
+ // FIXME: Warning: if the underlying graph is updated later, this
+ // won't be taken into account by this p_graph!
accu::bbox<P> a;
- for (unsigned i = 0; i < loc.size(); ++i)
- a.take(loc[i]);
+ for (unsigned i = 0; i < npoints(); ++i)
+ a.take(gr_.node_data(i));
bb_ = a.to_result();
}
+ // FIXME: Rename to npsites? In fact, this depends on the
+ // interface expected from models of Point_Sets.
template<typename P>
inline
std::size_t
p_graph<P>::npoints() const
{
- return this->gr_.nb_node_;
+ return this->gr_.nnodes();
}
template<typename P>
@@ -107,7 +111,7 @@
std::size_t
p_graph<P>::nlines() const
{
- return this->gr_.nb_link_;
+ return this->gr_.nedges();
}
template<typename P>
@@ -123,13 +127,16 @@
bool
p_graph<P>::has(const psite& p) const
{
- for (unsigned i = 0; i < loc_.size(); ++i)
- if (loc_[i] == p)
+ // FIXME: util::graph (or util::internal::graph_base) should
+ // provide the iteration facility (iterators, find, etc.)
+ const typename graph::nodes_t& nodes = gr_.nodes();
+ for (typename graph::nodes_t::const_iterator n = nodes.begin();
+ n != nodes.end(); ++n)
+ if ((*n)->data == p)
return true;
return false;
}
-
# endif // ! MLN_INCLUDE_ONLY
} // end of mln
Index: mln/core/graph_window_piter.hh
--- mln/core/graph_window_piter.hh (revision 1713)
+++ mln/core/graph_window_piter.hh (working copy)
@@ -82,6 +82,7 @@
// it returns a mln::graph_psite<P> object, not a P object.
const point& to_point() const;
operator psite () const;
+ /// Return the \a i th coordinate of the (iterated) point.
coord operator[](unsigned i) const;
private:
@@ -89,7 +90,7 @@
const psite& p_ref_;
/// An internal iterator on the set of nodes of the underlying graph.
- unsigned i_;
+ util::node_id id_;
};
// FIXME: Implement graph_window_bkd_piter.
@@ -104,7 +105,7 @@
const Point_Site<Pref>& p_ref)
: p_ref_(exact(p_ref).to_psite())
{
- // Invalidate i_.
+ // Invalidate id_.
invalidate();
}
@@ -115,21 +116,21 @@
// 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_.pg_.gr_.nb_node_;
+ return id_ < p_ref_.pg().gr_.nnodes();
}
template <typename P>
void
graph_window_fwd_piter<P>::invalidate()
{
- i_ = p_ref_.pg_.gr_.nb_node_;
+ id_ = p_ref_.pg().gr_.nnodes();
}
template <typename P>
void
graph_window_fwd_piter<P>::start()
{
- i_ = 0;
+ id_ = 0;
if (!adjacent_or_equal_to_p_ref_())
next_();
}
@@ -138,12 +139,14 @@
void
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
- // probably provides adequates structures to fetch these
- // neighbors in constant time.
+ /* FIXME: This is inefficient. The graph structure should be able
+ to produce the set of adjacent nodes fast. Boost Graphs
+ probably provides adequates structures to fetch these
+ neighbors in constant time. */
+ /* FIXME: Moreover, the behavior of next shall depend on the
+ window, which is not the case now! */
do
- ++i_;
+ ++id_;
while (is_valid() && !adjacent_or_equal_to_p_ref_());
}
@@ -154,34 +157,24 @@
// FIXME: Likewise, this is inefficient.
// Check wether the iterator points to P_REF_.
- if (i_ == p_ref_.i_)
+ if (id_ == p_ref_.id())
return true;
- typedef std::list<unsigned> adjacency_type;
-
// Check whether the iterator is among the neighbors of P_REF_.
{
// Paranoid assertion.
- assert (p_ref_.i_ >= 0 &&
- p_ref_.i_ < p_ref_.pg_.gr_.nodes_.size ());
+ assert (p_ref_.id() < p_ref_.pg().gr_.nnodes());
+ // FIXME: This is too low-level. Yet another service the graph
+ // should provide.
+ typedef std::vector<util::node_id> adjacency_type;
const adjacency_type& p_ref_neighbs =
- p_ref_.pg_.gr_.nodes_[p_ref_.i_]->links;
+ p_ref_.pg().gr_.nodes()[p_ref_.id()]->edges;
adjacency_type::const_iterator j =
- std::find (p_ref_neighbs.begin(), p_ref_neighbs.end(), i_);
+ std::find (p_ref_neighbs.begin(), p_ref_neighbs.end(), id_);
if (j != p_ref_neighbs.end())
return true;
}
- // Check whether P_REF_ is among the neighbors of the iterator.
- {
- assert (is_valid ());
- 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())
- return true;
- }
-
// Otherwise, the iterator is not adjacent to P_REF_.
return false;
}
@@ -190,13 +183,13 @@
const P&
graph_window_fwd_piter<P>::to_point() const
{
- return p_ref_.pg_.loc_[i_];
+ return p_ref_.pg().gr_.node_data(id_);
}
template <typename P>
graph_window_fwd_piter<P>::operator graph_psite<P> () const
{
- return graph_psite<P>(p_ref_.pg_, i_);
+ return graph_psite<P>(p_ref_.pg(), id_);
}
template <typename P>
Index: mln/core/graph_image.hh
--- mln/core/graph_image.hh (revision 1713)
+++ mln/core/graph_image.hh (working copy)
@@ -134,11 +134,12 @@
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;
-
- /// Return the second node of the link at i from loc
- const P& access_location_link_node2 (const unsigned& i) const;
+ /// Return the point of the first node adjacent to the edge with
+ /// id \a e.
+ const P& node1(const util::edge_id& e) const;
+ /// Return the point of the second node adjacent to the edge with
+ /// id \a e.
+ const P& node2(const util::edge_id& e) const;
};
// Fwd decl.
@@ -225,9 +226,9 @@
const V&
graph_image<P, V>::operator()(const graph_psite<P>& p) const
{
- mln_precondition(&p.pg_ == &this->data_->pg_);
- mln_precondition(p.i_ < this->data_->val_.size());
- return this->data_->val_[p.i_];
+ mln_precondition(&p.pg() == &this->data_->pg_);
+ mln_precondition(p.id() < this->data_->val_.size());
+ return this->data_->val_[p.id()];
}
template <typename P, typename V>
@@ -235,9 +236,9 @@
V&
graph_image<P, V>::operator()(const graph_psite<P>& p)
{
- mln_precondition(&p.pg_ == &this->data_->pg_);
- mln_precondition(p.i_ < this->data_->val_.size());
- return this->data_->val_[p.i_];
+ mln_precondition(&p.pg() == &this->data_->pg_);
+ mln_precondition(p.id() < this->data_->val_.size());
+ return this->data_->val_[p.id()];
}
template <typename P, typename V>
@@ -268,19 +269,23 @@
template <typename P, typename V>
inline
const P&
- graph_image<P, V>::access_location_link_node1 (const unsigned& i) const
+ graph_image<P, V>::node1(const util::edge_id& e) const
{
- // FIXME: This is ugly! Too much implementation details are shown here.
- return this->domain().loc_[this->domain().gr_.links_[i]->pair_node_.first];
+ // FIXME: Improve the interface of graph to avoid these low-level
+ // manipulations.
+ util::node_id n1 = this->domain().gr_.edge(e).n1();
+ return this->domain().gr_.node_data(n1);
}
template <typename P, typename V>
inline
const P&
- graph_image<P, V>::access_location_link_node2 (const unsigned& i) const
+ graph_image<P, V>::node2(const util::edge_id& e) const
{
- // FIXME: This is ugly! Too much implementation details are shown here.
- return this->domain().loc_[this->domain().gr_.links_[i]->pair_node_.second];
+ // FIXME: Improve the interface of graph to avoid these low-level
+ // manipulations.
+ util::node_id n2 = this->domain().gr_.edge(e).n2();
+ return this->domain().gr_.node_data(n2);
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/p_graph_piter.hh
--- mln/core/p_graph_piter.hh (revision 1713)
+++ mln/core/p_graph_piter.hh (working copy)
@@ -60,7 +60,7 @@
typedef graph_psite<P> psite;
typedef P point;
- p_graph_piter_(const p_graph<P>& psite_set);
+ p_graph_piter_(const p_graph<P>& pg);
/// Read-only access to the \p i-th coordinate.
mln_coord(P) operator[](unsigned i) const;
@@ -93,7 +93,7 @@
operator psite() const;
protected:
- const p_graph<P>& psite_set_;
+ const p_graph<P>& pg_;
unsigned i_;
P p_;
psite psite_;
@@ -105,11 +105,11 @@
template<typename P>
inline
- p_graph_piter_<P>::p_graph_piter_(const p_graph<P>& psite_set)
- : psite_set_(psite_set),
+ p_graph_piter_<P>::p_graph_piter_(const p_graph<P>& pg)
+ : pg_(pg),
p_(),
// Initialize psite_ to a dummy value.
- psite_(psite_set, psite_set_.loc_.size())
+ psite_(pg, pg_.npoints())
{
// Invalidate i_.
invalidate();
@@ -128,7 +128,7 @@
bool
p_graph_piter_<P>::is_valid() const
{
- return i_ != psite_set_.loc_.size();
+ return i_ < pg_.npoints();
}
template<typename P>
@@ -136,7 +136,7 @@
void
p_graph_piter_<P>::invalidate()
{
- i_ = psite_set_.loc_.size();
+ i_ = pg_.npoints();
}
template<typename P>
@@ -165,9 +165,9 @@
p_graph_piter_<P>::update_()
{
// Update p_.
- p_ = psite_set_.loc_[i_];
+ p_ = pg_.gr_.node_data(i_);
// Update psite_.
- psite_ = graph_psite<P>(psite_set_, i_);
+ psite_ = graph_psite<P>(pg_, i_);
}
template<typename P>
Index: mln/draw/graph.hh
--- mln/draw/graph.hh (revision 1713)
+++ mln/draw/graph.hh (working copy)
@@ -92,16 +92,19 @@
graph(Image<I>& ima, const p_graph<P>& pg,
mln_value(I) node_v, mln_value(I) link_v)
{
+ // Draw the background.
level::fill(ima, 0);
-
- for (unsigned i = 0; i < pg.nlines(); ++i)
+ // Draw the lines (edges).
+ for (size_t l = 0; l < pg.nlines(); ++l)
line (exact(ima),
- pg.loc_[pg.gr_.links_[i]->pair_node_.first],
- pg.loc_[pg.gr_.links_[i]->pair_node_.second],
+ // FIXME: Too low-level. See similar remarks
+ // in mln/core/graph_image.hh
+ pg.gr_.node_data(pg.gr_.edge(l).n1()),
+ pg.gr_.node_data(pg.gr_.edge(l).n2()),
link_v);
-
- for (unsigned i = 0; i < pg.npoints(); ++i)
- exact(ima)(pg.loc_[i]) = node_v;
+ // Draw the points (nodes).
+ for (size_t p = 0; p < pg.npoints(); ++p)
+ exact(ima)(pg.gr_.node_data(p)) = node_v;
}
template <typename I, typename P, typename V>
@@ -110,16 +113,14 @@
graph(Image<I>& ima, const graph_image<P, V>& gi,
mln_value(I) link_v)
{
+ // Draw the background.
level::fill(ima, 0);
-
- for (unsigned i = 0; i < gi.domain().nlines(); ++i)
- line (exact(ima),
- gi.access_location_link_node1 (i),
- gi.access_location_link_node2 (i),
- link_v);
-
- for (unsigned i = 0; i < gi.domain().npoints(); ++i)
- exact(ima)(gi.domain().loc_[i]) = gi.data_values ()[i];
+ // Draw the lines (edges).
+ for (size_t l = 0; l < gi.domain().nlines(); ++l)
+ line (exact(ima), gi.node1(l), gi.node2(l), link_v);
+ // Draw the points (nodes).
+ for (size_t p = 0; p < gi.domain().npoints(); ++p)
+ exact(ima)(gi.domain().gr_.node_data(p)) = gi.data_values()[p];
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/draw/all.hh
--- mln/draw/all.hh (revision 1713)
+++ mln/draw/all.hh (working copy)
@@ -42,7 +42,9 @@
}
+# include <mln/draw/box.hh>
+# include <mln/draw/graph.hh>
+# include <mln/draw/label.hh>
# include <mln/draw/line.hh>
-# include <mln/draw/mesh.hh>
#endif // ! MLN_DRAW_ALL_HH
Index: tests/core/graph_elt_window.cc
--- tests/core/graph_elt_window.cc (revision 1713)
+++ tests/core/graph_elt_window.cc (working copy)
@@ -58,10 +58,10 @@
points.push_back(make::point2d(4,4)); // Point associated to node 4.
// Edges.
- mln::util::graph<void> g;
+ mln::util::graph<p_t> g;
// Populate the graph with nodes.
for (unsigned i = 0; i < points.size(); ++i)
- g.add_node ();
+ g.add_node (points[i]);
// Populate the graph with edges.
g.add_edge(0, 1);
g.add_edge(1, 2);
@@ -74,7 +74,7 @@
`------------------*/
// Graph psite set.
- p_graph<p_t> pg(g, points);
+ p_graph<p_t> pg(g);
// Graph point site.
graph_psite<p_t> psite(pg, 0);
// ``Sliding'' window (in fact, neighborhood) of a psite of PG.
Index: tests/core/graph_image.cc
--- tests/core/graph_image.cc (revision 1713)
+++ tests/core/graph_image.cc (working copy)
@@ -59,10 +59,10 @@
points.push_back(make::point2d(4,4)); // Point associated to node 4.
// Edges.
- util::graph<void> g;
+ util::graph<point2d> g;
// Populate the graph with nodes.
for (unsigned i = 0; i < points.size(); ++i)
- g.add_node ();
+ g.add_node (points[i]);
// Populate the graph with edges.
g.add_edge(0, 1);
g.add_edge(1, 2);
@@ -74,7 +74,7 @@
| Graph. |
`-------*/
- p_graph<point2d> pg(g, points);
+ p_graph<point2d> pg(g);
/*-------------.
| Graph image. |
Index: tests/draw/graph.cc
--- tests/draw/graph.cc (revision 1713)
+++ tests/draw/graph.cc (working copy)
@@ -61,17 +61,15 @@
unsigned nrows, unsigned ncols, const mln::image2d<int>& ref)
{
// Graph.
- util::graph<void> g;
+ util::graph<mln::point2d> g;
// Populate the graph with nodes.
for (unsigned i = 0; i < points.size(); ++i)
- g.add_node ();
+ g.add_node (points[i]);
// Populate the graph with edges.
for (edges_type::const_iterator i = edges.begin(); i != edges.end(); ++i)
g.add_edge (i->first, i->second);
- // Check its consistency.
- g.consistency ();
- mln::p_graph<point2d> pg(g, points);
+ mln::p_graph<point2d> pg(g);
image2d<int> ima(nrows, ncols);
draw::graph (ima, pg, 2, 1);
1
0