graph_components.cc 2.15 KB
Newer Older
Tiago Peixoto's avatar
Tiago Peixoto committed
1
// Copyright (C) 2008  Tiago de Paula Peixoto <tiago@skewed.de>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program 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 program. If not, see <http://www.gnu.org/licenses/>.

#include "graph.hh"
#include "graph_filtering.hh"
#include "graph_properties.hh"
19
#include "graph_selectors.hh"
20
21
22

#include "graph_components.hh"

23
24
#include "numpy_bind.hh"

25
26
27
28
29
30
#include <boost/python.hpp>

using namespace std;
using namespace boost;
using namespace graph_tool;

31
python::object do_label_components(GraphInterface& gi, boost::any prop)
32
{
33
34
    vector<size_t> hist;
    run_action<>()(gi, bind<void>(label_components(), _1, _2, ref(hist)),
35
                   writable_vertex_scalar_properties())(prop);
36
    return wrap_vector_owned(hist);
37
38
}

39
40
41
python::object
do_label_biconnected_components(GraphInterface& gi, boost::any comp,
                                boost::any art)
42
{
43
    vector<size_t> hist;
44
45
    run_action<graph_tool::detail::never_directed>()
        (gi, bind<void>(label_biconnected_components(), _1, _2, _3,
46
                        ref(hist)),
47
48
49
         writable_edge_scalar_properties(),
         writable_vertex_scalar_properties())
        (comp, art);
50
    return wrap_vector_owned(hist);
51
52
}

53
54
55
56
57
58
void do_label_out_component(GraphInterface& gi, size_t root, boost::any prop)
{
    run_action<>()(gi, bind<void>(label_out_component(), _1, _2, root),
                   writable_vertex_scalar_properties())(prop);
}

59
60
61
void export_components()
{
    python::def("label_components", &do_label_components);
62
63
    python::def("label_biconnected_components",
                &do_label_biconnected_components);
64
    python::def("label_out_component", &do_label_out_component);
65
};