Commit 01c98c67 authored by Roland Levillain's avatar Roland Levillain
Browse files

Add adjaceny tests for mln::p_line_graph.

	* mln/core/p_line_graph.hh
	(mln::p_line_graph<P>::adjacent)
	(mln::p_line_graph<P>::adjacent_or_equal):
	New methods.
	(mln::p_line_graph<P>::p_line_graph): Remove outdated FIXME.
	* mln/core/p_graph.hh: Improve documentation.
	(mln::p_graph<P>::p_graph): Remove outdated FIXME.
	* tests/core/graph_image.cc, tests/core/line_graph_image.cc:
	Exercise adjacency tests.
	* tests/core/line_graph_elt_neighborhood.cc,
	* tests/core/line_graph_elt_window.cc:
	Typos in documentation.
	* tests/core/graph_elt_neighborhood.cc,
	* tests/core/graph_elt_window.cc:
	Aesthetic changes.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1912 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent eaab599c
2008-05-01 Roland Levillain <roland@lrde.epita.fr>
Add adjaceny tests for mln::p_line_graph.
* mln/core/p_line_graph.hh
(mln::p_line_graph<P>::adjacent)
(mln::p_line_graph<P>::adjacent_or_equal):
New methods.
(mln::p_line_graph<P>::p_line_graph): Remove outdated FIXME.
* mln/core/p_graph.hh: Improve documentation.
(mln::p_graph<P>::p_graph): Remove outdated FIXME.
* tests/core/graph_image.cc, tests/core/line_graph_image.cc:
Exercise adjacency tests.
* tests/core/line_graph_elt_neighborhood.cc,
* tests/core/line_graph_elt_window.cc:
Typos in documentation.
* tests/core/graph_elt_neighborhood.cc,
* tests/core/graph_elt_window.cc:
Aesthetic changes.
2008-05-01 Roland Levillain <roland@lrde.epita.fr>
Overhaul 1-D, 2-D and 3-D pixters.
......
......@@ -96,14 +96,16 @@ namespace mln
/// Adjacency tests.
/// \{
/// Return true if the psites lhs and rhs are adjacent.
/// Return true if the psites \a lhs and \a rhs are adjacent.
/// (If \a lhs and \a rhs are equal, return false).
bool adjacent(const psite& lhs, const psite& rhs) const;
/// Return true if the nodes lhs and rhs are adjacent.
/// Return true if the nodes \a lhs and \a rhs are adjacent.
/// (If \a lhs and \a rhs are equal, return false).
bool adjacent(const util::node_id& lhs, const util::node_id& rhs) const;
/// Return true if the psites lhs and rhs are adjacent, or equal.
/// Return true if the psites \a lhs and \a rhs are adjacent, or equal.
bool adjacent_or_equal(const psite& lhs, const psite& rhs) const;
/// Return true if the nodes lhs and rhs are adjacent, or equal
/// Return true if the nodes \a lhs and \a rhs are adjacent, or equal
bool adjacent_or_equal(const util::node_id& lhs,
const util::node_id& rhs) const;
/// \}
......@@ -151,10 +153,9 @@ namespace mln
template<typename P>
inline
p_graph<P>::p_graph (const util::graph<P>& gr)
// Create a deep, managed copy of GR.
: gr_ (new util::graph<P>(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));
......@@ -258,7 +259,8 @@ namespace mln
// Ensure LHS and RHS are *not* equal.
if (rhs == lhs)
return false;
// Check whether RHS and LHS are adjacent (i.e., whether RHS is
// Check whether LHS and RHS are adjacent (i.e., whether RHS is
// among the neighbors of LHS).
typedef std::vector<util::edge_id> edges_t;
const edges_t& lhs_neighbs = gr_->nodes()[lhs]->edges;
......@@ -290,10 +292,10 @@ namespace mln
mln_assertion(rhs < this->npoints());
// Check whether LHS and RHS are equal.
if (rhs == lhs)
if (lhs == rhs)
return true;
// Check whether RHS and LHS are adjacent.
return adjacent(rhs, lhs);
// Check whether LHS and RHS are adjacent.
return adjacent(lhs, rhs);
}
template <typename P>
......
......@@ -89,6 +89,22 @@ namespace mln
bool has(const psite& p) const;
/// Adjacency tests.
/// \{
/// Return true if the psites \a lhs and \a rhs are adjacent.
/// (If \a lhs and \a rhs are equal, return false).
bool adjacent(const psite& lhs, const psite& rhs) const;
/// Return true if the edges \a lhs and \a rhs are adjacent.
/// (If \a lhs and \a rhs are equal, return false).
bool adjacent(const util::edge_id& lhs, const util::edge_id& rhs) const;
/// Return true if the psites \a lhs and \a rhs are adjacent, or equal.
bool adjacent_or_equal(const psite& lhs, const psite& rhs) const;
/// Return true if the edges \a lhs and \a rhs are adjacent, or equal
bool adjacent_or_equal(const util::edge_id& lhs,
const util::edge_id& rhs) const;
/// \}
// FIXME: Should be private.
util::tracked_ptr<graph> gr_;
// FIXME: (Roland) Is it really useful/needed?
......@@ -125,10 +141,9 @@ namespace mln
template<typename P>
inline
p_line_graph<P>::p_line_graph (const util::graph<P>& gr)
// Create a deep, managed copy of GR.
: gr_ (new util::graph<P>(gr))
{
// FIXME: Warning: if the underlying graph is updated later, this
// won't be taken into account by this p_line_graph!
accu::bbox<P> a;
for (unsigned i = 0; i < nnodes(); ++i)
a.take(gr_->node_data(i));
......@@ -179,6 +194,68 @@ namespace mln
(p.id() < gr_->nedges());
}
template <typename P>
inline
bool
p_line_graph<P>::adjacent(const psite& lhs, const psite& rhs) const
{
mln_assertion(&lhs.plg() == this && rhs.plg() == this);
return adjacent(lhs.id(), rhs.id());
}
/* FIXME: This could be more efficient, if the graph structure had a
richer interface. */
template <typename P>
inline
bool
p_line_graph<P>::adjacent(const util::edge_id& lhs,
const util::edge_id& rhs) const
{
mln_assertion(lhs < this->npoints());
mln_assertion(rhs < this->npoints());
// Ensure LHS and RHS are *not* equal.
if (lhs == rhs)
return false;
// Check whether LHS and RHS are adjacent (i.e., whether LHS and
// RHS share a common vertex.
/* FIXME: This is too low-level. Yet another service the graph
should provide. */
if (gr_->edge(lhs).n1() == gr_->edge(rhs).n1() ||
gr_->edge(lhs).n1() == gr_->edge(rhs).n2() ||
gr_->edge(lhs).n2() == gr_->edge(rhs).n1() ||
gr_->edge(lhs).n2() == gr_->edge(rhs).n2())
return true;
return false;
}
template <typename P>
inline
bool
p_line_graph<P>::adjacent_or_equal(const psite& lhs, const psite& rhs) const
{
mln_assertion(&lhs.pg() == this && rhs.pg() == this);
return adjacent_or_equal(lhs.id(), rhs.id());
}
template <typename P>
inline
bool
p_line_graph<P>::adjacent_or_equal(const util::edge_id& lhs,
const util::edge_id& rhs) const
{
mln_assertion(lhs < this->npoints());
mln_assertion(rhs < this->npoints());
// Check whether LHS and RHS are equal.
if (lhs == rhs)
return true;
// Check whether RHS and LHS are adjacent.
return adjacent(lhs, rhs);
}
template <typename P>
bool
......
......@@ -25,10 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
/*! \file tests/core/graph_elt_neighborhood.cc
*
* \brief Tests on mln::graph_elt_neighborhood.
*/
/// \file tests/core/graph_elt_neighborhood.cc
/// \brief Tests on mln::graph_elt_neighborhood.
#include <iostream>
......
......@@ -25,10 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
/*! \file tests/core/graph_elt_window.cc
*
* \brief Tests on mln::graph_elt_window.
*/
/// \file tests/core/graph_elt_window.cc
/// \brief Tests on mln::graph_elt_window.
#include <iostream>
......
......@@ -50,6 +50,19 @@ int main()
| Graph. |
`--------*/
/* The graph is as follows:
0 1 2 3 4
.-----------
|
0 | 0 2
1 | \ / |
2 | 1 |
3 | \ |
4 | 3-4
*/
// Points associated to nodes.
std::vector<point2d> points;
points.push_back(make::point2d(0,0)); // Point associated to node 0.
......@@ -70,12 +83,20 @@ int main()
g.add_edge(3, 4);
g.add_edge(4, 2);
/*-------.
| Graph. |
`-------*/
g.print_debug(std::cout);
/*----------------------.
| Graph image support. |
`----------------------*/
p_graph<point2d> pg(g);
g.print_debug(std::cout);
// Check adjacencies of vertex 1.
mln_assertion( pg.adjacent(1, 0));
mln_assertion(!pg.adjacent(1, 1));
mln_assertion( pg.adjacent(1, 2));
mln_assertion( pg.adjacent(1, 3));
mln_assertion(!pg.adjacent(1, 4));
/*-------------.
| Graph image. |
......
......@@ -25,10 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
/*! \file tests/core/line_graph_elt_neighborhood.cc
*
* \brief Tests on mln::line_graph_elt_neighborhood.
*/
/// \file tests/core/line_graph_elt_neighborhood.cc
/// \brief Tests on mln::line_graph_elt_neighborhood.
#include <vector>
......@@ -49,8 +47,7 @@ int main()
| Graph. |
`--------*/
/* The graph is as follows and its corresponding line graph are as
follows:
/* The graph and its corresponding line graph are as follows:
0 1 2 3 4 0 1 2 3 4
.----------- .-----------
......
......@@ -25,10 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
/*! \file tests/core/line_graph_elt_window.cc
*
* \brief Tests on mln::line_graph_elt_window.
*/
/// \file tests/core/line_graph_elt_window.cc
/// \brief Tests on mln::line_graph_elt_window.
#include <vector>
......@@ -49,8 +47,7 @@ int main()
| Graph. |
`--------*/
/* The graph is as follows and its corresponding line graph are as
follows:
/* The graph and its corresponding line graph are as follows:
0 1 2 3 4 0 1 2 3 4
.----------- .-----------
......
......@@ -50,6 +50,19 @@ int main()
| Graph. |
`--------*/
/* The graph and its corresponding line graph are as follows:
0 1 2 3 4 0 1 2 3 4
.----------- .-----------
| |
0 | 0 2 0 | * *
1 | \ / | 1 | 0 1 |
2 | 1 | 2 | * 4
3 | \ | 3 | 2 |
4 | 3-4 4 | *3*
*/
// Points associated to nodes.
std::vector<point2d> points;
points.push_back(make::point2d(0,0)); // Point associated to node 0.
......@@ -70,12 +83,19 @@ int main()
g.add_edge(3, 4);
g.add_edge(4, 2);
/*-------.
| Graph. |
`-------*/
/*---------------------------.
| Line graph image support. |
`---------------------------*/
p_line_graph<point2d> plg(g);
// Check adjacencies of edge 1.
mln_assertion( plg.adjacent(1, 0));
mln_assertion(!plg.adjacent(1, 1));
mln_assertion( plg.adjacent(1, 2));
mln_assertion(!plg.adjacent(1, 3));
mln_assertion( plg.adjacent(1, 4));
/*-------------------.
| Line graph image. |
`-------------------*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment