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) ...@@ -40,6 +40,11 @@ point_t interpolate(const point_t& p1, const point_t& p2, double r = 0.5)
return ret; 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) void to_bezier(const vector<point_t> &x, vector<point_t>& ncp)
{ {
vector<point_t> cp(x.size() + 6); vector<point_t> cp(x.size() + 6);
...@@ -99,6 +104,9 @@ void transform(vector<point_t>& cp) ...@@ -99,6 +104,9 @@ void transform(vector<point_t>& cp)
for (size_t i = 0; i < cp.size(); ++i) for (size_t i = 0; i < cp.size(); ++i)
cp[i].first /= r; cp[i].first /= r;
d.first = d.second = 0;
cp.insert(cp.begin(), d);
} }
template <class PosProp> template <class PosProp>
...@@ -165,29 +173,28 @@ void pack(vector<point_t>& cp, vector<T>& ncp) ...@@ -165,29 +173,28 @@ void pack(vector<point_t>& cp, vector<T>& ncp)
struct do_get_cts struct do_get_cts
{ {
template <class Graph, class Tree, class PosProp, class CMap> template <class Graph, class Tree, class PosProp, class BProp, class CMap>
void operator()(Graph& g, Tree* t, PosProp tpos, double beta, CMap cts) const void operator()(Graph& g, Tree* t, PosProp tpos, BProp beta, CMap cts) const
{ {
vector<size_t> path; vector<size_t> path;
vector<point_t> cp; vector<point_t> cp;
vector<point_t> ncp; vector<point_t> ncp;
typename graph_traits<Graph>::edge_iterator e, e_end; for (auto e : edges_range(g))
for(tie(e, e_end) = edges(g); e != e_end; ++e)
{ {
typename graph_traits<Graph>::vertex_descriptor u, v; auto u = source(e, g);
u = source(*e, g); auto v = target(e, g);
v = target(*e, g);
if (u == v) if (u == v)
continue; continue;
path.clear(); path.clear();
tree_path(*t, u, v, path); tree_path(*t, u, v, path);
cp.clear(); cp.clear();
get_control_points(path, tpos, beta, cp); get_control_points(path, tpos, beta[e], cp);
ncp.clear(); ncp.clear();
to_bezier(cp, ncp); to_bezier(cp, ncp);
transform(ncp); transform(ncp);
pack(ncp, cts[*e]); pack(ncp, cts[e]);
} }
} }
}; };
...@@ -203,14 +210,17 @@ struct get_pointers ...@@ -203,14 +210,17 @@ struct get_pointers
}; };
void get_cts(GraphInterface& gi, GraphInterface& tgi, 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<vector<double>,
GraphInterface::edge_index_map_t>::type GraphInterface::edge_index_map_t>::type
eprop_t; eprop_t;
typedef property_map_type::apply<double,
GraphInterface::edge_index_map_t>::type
beprop_t;
eprop_t cts = boost::any_cast<eprop_t>(octs); 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_>() run_action<graph_tool::detail::always_directed, boost::mpl::true_>()
(gi, std::bind(do_get_cts(), placeholders::_1, placeholders::_2, (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): ...@@ -1192,9 +1192,11 @@ def get_hierarchy_control_points(g, t, tpos, beta=0.8, cts=None):
tpos : :class:`~graph_tool.PropertyMap` tpos : :class:`~graph_tool.PropertyMap`
Vector-valued vertex property map containing the x and y coordinates of Vector-valued vertex property map containing the x and y coordinates of
the vertices in graph ``t``. 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, 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``) cts : :class:`~graph_tool.PropertyMap` (optional, default: ``None``)
Edge property map of type ``vector<double>`` where the control points Edge property map of type ``vector<double>`` where the control points
will be stored. will be stored.
...@@ -1265,8 +1267,14 @@ def get_hierarchy_control_points(g, t, tpos, beta=0.8, cts=None): ...@@ -1265,8 +1267,14 @@ def get_hierarchy_control_points(g, t, tpos, beta=0.8, cts=None):
u = GraphView(g, directed=True) u = GraphView(g, directed=True)
tu = GraphView(t, directed=True) tu = GraphView(t, directed=True)
if not isinstance(beta, PropertyMap):
beta = u.new_edge_property("double", beta)
else:
beta = beta.copy("double")
libgraph_tool_draw.get_cts(u._Graph__graph, tu._Graph__graph, 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)) _prop("e", u, cts))
return cts return cts
......
Markdown is supported
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