milena r1165: Add graph in sandbox

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-09-24 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr> Add graph in sandbox. * graph.hh: New. * graph.hxx: New. * main.cc: Update for graph. * test_debug_iota_3d.cc: Update. --- graph.hh | 78 +++++++++++++++++++++++++++++++++++++++++ graph.hxx | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ main.cc | 57 ++++++------------------------ test_debug_iota_3d.cc | 2 - 4 files changed, 185 insertions(+), 46 deletions(-) Index: trunk/milena/sandbox/duhamel/graph.hh =================================================================== --- trunk/milena/sandbox/duhamel/graph.hh (revision 0) +++ trunk/milena/sandbox/duhamel/graph.hh (revision 1165) @@ -0,0 +1,78 @@ +// 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. +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_GRAPH_HH +# define MLN_GRAPH_HH + +# include <cstddef> +# include <iostream> +# include <vector> +# include <map> +# include <mln/core/concept/object.hh> + +namespace mln +{ + namespace util + { + + template<typename N, typename E = void> + class Graph + { + public: + typedef struct s_node + { + std::vector<unsigned> links; + } s_node; + + typedef struct s_edge + { + unsigned node1; + unsigned node2; + } s_edge; + + Graph () {} + Graph (unsigned nb_node, unsigned nb_link) : + nb_node_ (nb_node), nb_link_ (nb_link) {} + ~Graph () {} + void add_node (); + void add_edge (unsigned n1, unsigned n2); + void coherce (); + void print (); +// void coherence () const; + private: + unsigned nb_node_; + unsigned nb_link_; + std::vector<s_node*> nodes_; + std::vector<s_edge*> links_; + }; + + } // end of util +} // end of mln + +#include "graph.hxx" + +#endif // MLN_GRAPH_HH Index: trunk/milena/sandbox/duhamel/graph.hxx =================================================================== --- trunk/milena/sandbox/duhamel/graph.hxx (revision 0) +++ trunk/milena/sandbox/duhamel/graph.hxx (revision 1165) @@ -0,0 +1,94 @@ +#ifndef MLN_GRAPH_HXX +# define MLN_GRAPH_HXX + +# include "graph.hh" + +namespace mln +{ + + namespace util + { + + template<typename N, typename E> + inline + void + Graph<N, E>::add_node () + { + nodes_.push_back (new s_node); + ++nb_node_; + } + + template<typename N, typename E> + inline + void + Graph<N, E>::add_edge (unsigned n1, unsigned n2) + { + mln_precondition(n1 < this->nb_node_); + mln_precondition(n2 < this->nb_node_); + + s_edge* edge; + + edge = new s_edge; + edge->node1 = n1; + edge->node2 = n2; + links_.push_back (edge); + ++nb_link_; + nodes_[n1]->links.push_back (n2); + } + + template<typename N, typename E> + inline + void + Graph<N, E>::coherce () + { + mln_precondition(nodes_.size () == this->nb_node_); + mln_precondition(links_.size () == this->nb_link_); + typename std::vector<s_node*>::const_iterator it = nodes_.begin (); + for (; it != nodes_.end (); ++it) + { + typename std::vector<unsigned>::const_iterator it2 = (*it)->links.begin (); + for (; it2 != (*it)->links.end (); ++it2) + mln_precondition((*it2) < nb_node_); + } + + typename std::vector<s_edge*>::const_iterator it3 = links_.begin (); + for (; it3 != links_.end (); ++it3) + { + mln_precondition((*it3)->node1 < nb_node_); + mln_precondition((*it3)->node2 < nb_node_); + } + } + + template<typename N, typename E> + inline + void + Graph<N, E>::print () + { + std::cout << "nodes :" + << std::endl; + + typename std::vector<s_node*>::const_iterator it = nodes_.begin (); + int i = 0; + for (; it != nodes_.end (); ++it, ++i) + { + std::cout << "node number = " + << i + << " nbh : "; + typename std::vector<unsigned>::const_iterator it2 = (*it)->links.begin (); + for (; it2 != (*it)->links.end (); ++it2, ++i) + { + std::cout << (*it2) + << " "; + } + std::cout << std::endl; + } + std::cout << std::endl; + } + + + + } // end of util + +} // end of mln + +#endif // MLN_GRAPH_HXX Index: trunk/milena/sandbox/duhamel/main.cc =================================================================== --- trunk/milena/sandbox/duhamel/main.cc (revision 1164) +++ trunk/milena/sandbox/duhamel/main.cc (revision 1165) @@ -1,54 +1,21 @@ -#include <mln/core/image2d_b.hh> -#include <mln/value/int_u8.hh> -#include <mln/debug/println.hh> - - -#include <mln/geom/nrows.hh> -#include <mln/geom/ncols.hh> - -#include <mln/level/fill.hh> - -#include <mln/debug/println_with_border.hh> - -#include "paste.hh" -#include "fill.hh" - -//#include "level.hh" -//#include "labeling.hh" - -#include <mln/core/image2d_b.hh> -#include <mln/core/neighb2d.hh> -#include <mln/value/int_u8.hh> -#include <mln/pw/all.hh> - -#include <mln/io/pgm/load.hh> -#include <mln/io/pgm/save.hh> -#include <mln/labeling/foreground.hh> -#include <mln/debug/println_with_border.hh> - +#include "graph.hh" using namespace mln; -int main (void) +int +main (void) { - image2d_b<value::int_u8> i1(3, 3); -// Neighborhood<value::int_u8> nbh; - -// labeling::level (i1, 3, nbh,2); -// image2d_b<int> i2(3, 3); -// mln::sparse_image<mln::point2d, int> sparse; -// mln::sparse_image<mln::point2d, int> sparse2; -// mln::rle_image<mln::point2d, int> rle1; -// mln::rle_image<mln::point2d, int> rle2; - + mln::util::Graph<void> g (0,0); -// level::fill_opt2(i1, 8); + g.add_node (); + g.add_node (); + g.add_node (); + g.add_edge (0,1); + g.coherce (); + g.print (); -// debug::println_with_border(i1); +// image2d_b<int> out (5, 5, 1); -// level::paste(rle1, rle2); -// level::fill(sparse, 42); -// debug::println_with_border(i2); + // debug::println_with_border (out); - return (0); } Index: trunk/milena/sandbox/duhamel/test_debug_iota_3d.cc =================================================================== --- trunk/milena/sandbox/duhamel/test_debug_iota_3d.cc (revision 1164) +++ trunk/milena/sandbox/duhamel/test_debug_iota_3d.cc (revision 1165) @@ -43,7 +43,7 @@ main (void) { - image3d_b<bool> ima(2,3,3,1); + image3d_b<bool> ima(5,4,3,1); debug::iota (ima); debug::println_with_border(ima);
participants (1)
-
Guillaume Duhamel