Skip to content

Commit daa61cd

Browse files
committed
feat: adding network viz
feat: adding network core and parsers with test feat: network visualization working fix: fixing speed of forcelayout calculation cleaning comment cleaning example, creating utility, setting dyanmicbb default to true
1 parent e182267 commit daa61cd

15 files changed

Lines changed: 2227 additions & 1 deletion

File tree

docs/examples/_valid_examples.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ files = [
3737
"viz_line_projections.py",
3838
"viz_streamlines_roi.py",
3939
"viz_contour.py",
40-
40+
"viz_network.py",
4141
]
4242

4343
[ui]

docs/examples/viz_network.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
====================================
3+
Force-Directed Network Visualization
4+
====================================
5+
6+
This example demonstrates how to use the `Network` actor to visualize
7+
graphs using a GPU-accelerated Fruchterman-Reingold force-directed layout.
8+
9+
It supports two modes:
10+
1. Dummy: Generates a random synthetic graph.
11+
2. File: Loads a graph from .gexf, .gml, or .xnet files.
12+
"""
13+
14+
import numpy as np
15+
from fury import window, ui, actor
16+
17+
N_NODES = 500
18+
N_EDGES = 1000
19+
K_DISTANCE = 20.0
20+
SIM_SPEED = 0.01
21+
22+
# To load from file, uncomment the lines below:
23+
# from fury.io import load_network
24+
# network_data = load_network("path/to/graph.gexf")
25+
# network_actor = actor.network(network_data, k=K_DISTANCE, speed=SIM_SPEED)
26+
27+
nodes = (np.random.rand(N_NODES, 3) - 0.5) * 100
28+
edges = np.random.randint(0, N_NODES, size=(N_EDGES, 2))
29+
edges = edges[edges[:, 0] != edges[:, 1]]
30+
colors = np.random.rand(N_NODES, 4).astype(np.float32)
31+
32+
network_actor = actor.create_network(
33+
nodes=nodes, edges=edges, colors=colors, k=K_DISTANCE, speed=SIM_SPEED
34+
)
35+
36+
scene = window.Scene()
37+
scene.background = (0.1, 0.1, 0.1)
38+
scene.add(network_actor)
39+
40+
info_text = f"Nodes: {N_NODES}\nEdges: {N_EDGES}\nMode: GPU Simulation"
41+
ui_label = ui.TextBlock2D(
42+
text=info_text, position=(10, 10), font_size=16, dynamic_bbox=True
43+
)
44+
scene.add(ui_label)
45+
46+
if __name__ == "__main__":
47+
show_manager = window.ShowManager(scene=scene, title="FURY Network")
48+
show_manager.start()

fury/actor/__init__.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ __all__ = [
4747
"create_point",
4848
"create_text",
4949
"create_image",
50+
"create_network",
5051
"Mesh",
5152
"Line",
5253
"Points",
@@ -67,6 +68,7 @@ __all__ = [
6768
"contour_from_label",
6869
"read_buffer",
6970
"create_axes_helper",
71+
"extract_graph_data_from_network",
7072
]
7173

7274
from ._billboard import Billboard, billboard, billboard_sphere
@@ -92,6 +94,7 @@ from .core import (
9294
line,
9395
)
9496
from .curved import cone, cylinder, ellipsoid, sphere, streamlines, streamtube
97+
from .network import create_network
9598
from .planar import (
9699
disk,
97100
image,
@@ -127,6 +130,7 @@ from .topology import contour_from_volume, surface
127130
from .utils import (
128131
apply_affine_to_actor,
129132
apply_affine_to_group,
133+
extract_graph_data_from_network,
130134
get_slices,
131135
read_buffer,
132136
set_group_opacity,

0 commit comments

Comments
 (0)