
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2008-01-17 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr> Update graph. * mln/util/graph.hh: Fix : ordpair replace unsigned for edge. * mln/draw/mesh.hh: Apply this modification. * sandbox/nivault/extract_character.cc: Update. * mln/make/voronoi.hh: Fix comment. --- mln/draw/mesh.hh | 4 +- mln/make/voronoi.hh | 10 +++++++ mln/util/graph.hh | 49 +++++++++++++++++++++++++++++------ sandbox/nivault/extract_character.cc | 11 ++++--- 4 files changed, 59 insertions(+), 15 deletions(-) Index: trunk/milena/mln/draw/mesh.hh =================================================================== --- trunk/milena/mln/draw/mesh.hh (revision 1669) +++ trunk/milena/mln/draw/mesh.hh (revision 1670) @@ -98,8 +98,8 @@ for (unsigned i = 0; i < m.gr_.nb_link_; ++i) line (exact(ima), - m.loc_[m.gr_.links_[i]->node1], - m.loc_[m.gr_.links_[i]->node2], + m.loc_[m.gr_.links_[i]->pair_node_.first], + m.loc_[m.gr_.links_[i]->pair_node_.second], link_v); for (unsigned i = 0; i < m.gr_.nb_node_; ++i) Index: trunk/milena/mln/make/voronoi.hh =================================================================== --- trunk/milena/mln/make/voronoi.hh (revision 1669) +++ trunk/milena/mln/make/voronoi.hh (revision 1670) @@ -47,6 +47,16 @@ namespace make { + /*! + * \brief Apply Voronoi algorithm on \p ima_ with the original + * image \p orig_ for node computing with neighborhood \p nbh. + * + * \param[in] ima_ The labeling image. + * \param[in] orig_ The original image. + * \param[in] nbh The neighborhood for computing algorithm. + * + * \return The computed graph. + */ template <typename I, typename N> mesh_p<mln_psite(I)> voronoi (Image<I>& ima_, Index: trunk/milena/mln/util/graph.hh =================================================================== --- trunk/milena/mln/util/graph.hh (revision 1669) +++ trunk/milena/mln/util/graph.hh (revision 1670) @@ -34,6 +34,7 @@ # include <vector> # include <list> # include <algorithm> +# include <mln/util/ordpair.hh> /*! \file mln/util/graph.hh * @@ -78,9 +79,10 @@ template<typename T> struct s_edge { + s_edge() : pair_node_ (0, 0) {} + T data; - unsigned node1; - unsigned node2; + ordpair_<unsigned> pair_node_; }; /*! \brief Structure of edge with void parameter. @@ -89,10 +91,14 @@ template<> struct s_edge <void> { - unsigned node1; - unsigned node2; + s_edge() : pair_node_ (0, 0) {} + ordpair_<unsigned> pair_node_; }; + bool operator==(const struct s_edge <void>& lhs, const struct s_edge <void>& rhs); + + bool operator< (const struct s_edge <void>& lhs, const struct s_edge <void>& rhs); + /// \brief Generic graph structure using s_node and s_edge. /* FIXME: We don't mention anywhere whether this graph structure handles directed or undirected graphs! */ @@ -104,8 +110,12 @@ /// The type of the set of edges. typedef std::vector< s_edge<E>* > edges; + /// Constructor. graph (); + /// Destructor. + ~graph(); + /*! \brief Add a void node. */ void add_node (); @@ -155,6 +165,18 @@ # ifndef MLN_INCLUDE_ONLY + bool + operator==(const struct s_edge <void>& lhs, const struct s_edge <void>& rhs) + { + return lhs.pair_node_ == rhs.pair_node_; + } + + bool + operator< (const struct s_edge <void>& lhs, const struct s_edge <void>& rhs) + { + return lhs.pair_node_ < rhs.pair_node_; + } + template<typename N, typename E> inline graph<N, E>::graph () @@ -167,6 +189,12 @@ template<typename N, typename E> inline + graph<N, E>::~graph () + { + } + + template<typename N, typename E> + inline void graph<N, E>::add_node () { @@ -187,12 +215,17 @@ struct s_edge<E>* edge; edge = new s_edge<E>; - edge->node1 = n1; - edge->node2 = n2; + edge->pair_node_.first = n1; + edge->pair_node_.second = n2; + if (links_.end () == std::find(links_.begin(), links_.end(), edge)) + delete edge; + else + { links_.push_back (edge); ++nb_link_; nodes_[n1]->links.push_back (n2); } + } template<typename N, typename E> inline @@ -212,8 +245,8 @@ typename std::vector<struct s_edge<E>*>::const_iterator it3 = links_.begin (); for (; it3 != links_.end (); ++it3) { - mln_precondition((*it3)->node1 < nb_node_); - mln_precondition((*it3)->node2 < nb_node_); + mln_precondition((*it3)->pair_node_.first < nb_node_); + mln_precondition((*it3)->pair_node_.second < nb_node_); } } Index: trunk/milena/sandbox/nivault/extract_character.cc =================================================================== --- trunk/milena/sandbox/nivault/extract_character.cc (revision 1669) +++ trunk/milena/sandbox/nivault/extract_character.cc (revision 1670) @@ -154,6 +154,7 @@ unsigned value = image(point2d(r, i)); if (value != 0) { + /// to_result ? draw::box (output, v_bbox[value].to_result(), literal::blue); typedef sub_image<I_LABEL, box2d> I_SUB; @@ -331,7 +332,7 @@ // for (unsigned i = 0; i <= nb_dilated_node_labels; ++i) // draw::box(output, vec_bbox2[i].to_result(), literal::red); -// image2d<int_u8> out (label_image.domain ()); + image2d<int_u8> out (label_image.domain ()); // // Save the influence area of the node of the graphe (seed2tiling result). // level::stretch (zi_image, out); @@ -343,10 +344,10 @@ // io::pgm::save(out, path_output + ".text_graph.pgm"); // std::cout << path_output + ".text_graph.pgm" << " generated" << std::endl; -// // Save the graph of the text. -// level::stretch (text_image, out); -// io::pgm::save(out, path_output + ".text.pgm"); -// std::cout << path_output + ".text.pgm" << " generated" << std::endl; + // Save the the text image. + level::stretch (text_image, out); + io::pgm::save(out, path_output + ".text.pgm"); + std::cout << path_output + ".text.pgm" << " generated" << std::endl; // Save the output image (input image + bounding box text in red). io::ppm::save(output, path_output + ".ppm");