Commit 92eaff23 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Significant improvement of edge splines in graph_draw()

parent 66d10524
This diff is collapsed.
......@@ -40,6 +40,11 @@ point_t interpolate(const point_t& p1, const point_t& p2, double r = 0.5)
return ret;
double dist(point_t& p1, point_t& p2)
return sqrt(pow(p1.first - p2.first, 2) + pow(p1.second - p2.second, 2));
void to_bezier(const vector<point_t> &x, vector<point_t>& ncp)
vector<point_t> cp(x.size() + 6);
......@@ -99,6 +104,9 @@ void transform(vector<point_t>& cp)
for (size_t i = 0; i < cp.size(); ++i)
cp[i].first /= r;
d.first = d.second = 0;
cp.insert(cp.begin(), d);
template <class PosProp>
......@@ -165,29 +173,28 @@ void pack(vector<point_t>& cp, vector<T>& ncp)
struct do_get_cts
template <class Graph, class Tree, class PosProp, class CMap>
void operator()(Graph& g, Tree* t, PosProp tpos, double beta, CMap cts) const
template <class Graph, class Tree, class PosProp, class BProp, class CMap>
void operator()(Graph& g, Tree* t, PosProp tpos, BProp beta, CMap cts) const
vector<size_t> path;
vector<point_t> cp;
vector<point_t> ncp;
typename graph_traits<Graph>::edge_iterator e, e_end;
for(tie(e, e_end) = edges(g); e != e_end; ++e)
for (auto e : edges_range(g))
typename graph_traits<Graph>::vertex_descriptor u, v;
u = source(*e, g);
v = target(*e, g);
auto u = source(e, g);
auto v = target(e, g);
if (u == v)
tree_path(*t, u, v, path);
get_control_points(path, tpos, beta, cp);
get_control_points(path, tpos, beta[e], cp);
to_bezier(cp, ncp);
pack(ncp, cts[*e]);
pack(ncp, cts[e]);
......@@ -203,14 +210,17 @@ struct get_pointers
void get_cts(GraphInterface& gi, GraphInterface& tgi,
boost::any otpos, double beta, boost::any octs)
boost::any otpos, boost::any obeta, boost::any octs)
typedef property_map_type::apply<vector<double>,
typedef property_map_type::apply<double,
eprop_t cts = boost::any_cast<eprop_t>(octs);
beprop_t beta = boost::any_cast<beprop_t>(obeta);
run_action<graph_tool::detail::always_directed, boost::mpl::true_>()
(gi, std::bind(do_get_cts(), placeholders::_1, placeholders::_2,
......@@ -1192,9 +1192,11 @@ def get_hierarchy_control_points(g, t, tpos, beta=0.8, cts=None):
tpos : :class:`~graph_tool.PropertyMap`
Vector-valued vertex property map containing the x and y coordinates of
the vertices in graph ``t``.
beta : ``float`` (optional, default: ``0.8``)
beta : ``float`` (optional, default: ``0.8`` or :class:`~graph_tool.PropertyMap`)
Edge bundling strength. For ``beta == 0`` the edges are straight lines,
and for ``beta == 1`` they strictly follow the hierarchy.
and for ``beta == 1`` they strictly follow the hierarchy. This can be
optionally an edge property map, which specified a different bundling
strength for each edge.
cts : :class:`~graph_tool.PropertyMap` (optional, default: ``None``)
Edge property map of type ``vector<double>`` where the control points
will be stored.
......@@ -1265,8 +1267,14 @@ def get_hierarchy_control_points(g, t, tpos, beta=0.8, cts=None):
u = GraphView(g, directed=True)
tu = GraphView(t, directed=True)
if not isinstance(beta, PropertyMap):
beta = u.new_edge_property("double", beta)
beta = beta.copy("double")
libgraph_tool_draw.get_cts(u._Graph__graph, tu._Graph__graph,
_prop("v", tu, tpos), beta,
_prop("v", tu, tpos),
_prop("e", u, beta),
_prop("e", u, cts))
return cts
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