Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
92eaff23
Commit
92eaff23
authored
Mar 05, 2015
by
Tiago Peixoto
Browse files
Significant improvement of edge splines in graph_draw()
parent
66d10524
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
src/graph/draw/graph_cairo_draw.cc
View file @
92eaff23
This diff is collapsed.
Click to expand it.
src/graph/draw/graph_tree_cts.cc
View file @
92eaff23
...
...
@@ -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
)
continue
;
path
.
clear
();
tree_path
(
*
t
,
u
,
v
,
path
);
cp
.
clear
();
get_control_points
(
path
,
tpos
,
beta
,
cp
);
get_control_points
(
path
,
tpos
,
beta
[
e
]
,
cp
);
ncp
.
clear
();
to_bezier
(
cp
,
ncp
);
transform
(
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
o
beta
,
boost
::
any
octs
)
{
typedef
property_map_type
::
apply
<
vector
<
double
>
,
GraphInterface
::
edge_index_map_t
>::
type
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
);
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
,
...
...
src/graph_tool/draw/cairo_draw.py
View file @
92eaff23
...
...
@@ -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
)
else
:
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
...
...
Alex Henrie
@alex.henrie
mentioned in merge request
!54 (merged)
·
Feb 02, 2021
mentioned in merge request
!54 (merged)
mentioned in merge request !54
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment