Skip to content

Commit

Permalink
add arrow_data_to_origin option
Browse files Browse the repository at this point in the history
  • Loading branch information
j042 committed Sep 15, 2024
1 parent b017aa2 commit b805312
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
16 changes: 14 additions & 2 deletions examples/show_faces.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,17 @@
)

# show
tri.show()
quad.show()
gus.show(["triangles", tri], ["quads", quad])

# plot data - plots vector data as arrows
for mesh in [tri, quad]:
mesh.vertex_data["coords"] = np.random.default_rng().random(
tri.vertices.shape
)
mesh.show_options(arrow_data="coords")
gus.show(["triangles", tri], ["quads", quad])

# point data to origin
for mesh in [tri, quad]:
mesh.show_options(arrow_data_to_origin=True)
gus.show(["triangles", tri], ["quads", quad])
9 changes: 8 additions & 1 deletion gustaf/helpers/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __init__(self, key, default):
"dict with following items are accepted: "
"{title: str, pos: tuple, size: list, title_font: str, "
"title_xoffset: float, title_yoffset: float, title_size: float, "
"title_rotation: float, nlabels: int, label_font:str, "
"title_rotation: float, nlabels: int, label_font: str, "
"label_size: float, label_offset: float, label_rotation: int, "
"label_format: str, draw_box: bool, above_text: str, below_text: str, "
"nan_text: str, categories: list}",
Expand All @@ -180,6 +180,13 @@ def __init__(self, key, default):
"cmap, colors are based on the size of the arrows.",
(str, tuple, list, int),
),
Option(
"vedo",
"arrow_data_to_origin",
"Points arrow data to geometric origin."
"Equivalent to shifting arrows backwards with their own magitudes.",
(bool,),
),
Option(
"vedo",
"axes",
Expand Down
15 changes: 13 additions & 2 deletions gustaf/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,11 @@ def make_showable(obj, as_dict=False, **kwargs):

# we are here because this data is not a scalar
# is showable?
if arrow_data_value.shape[1] not in (2, 3):
a_data_dim = arrow_data_value.shape[1]
if a_data_dim not in (2, 3):
raise ValueError(
"Only 2D or 3D data can be shown.",
f"Requested data is {arrow_data_value.shape[1]}",
f"Requested data is {a_data_dim}D.",
)

as_edges = from_data(
Expand All @@ -379,6 +380,16 @@ def make_showable(obj, as_dict=False, **kwargs):
obj.show_options.get("arrow_data_scale", None),
data_norm=obj.vertex_data.as_scalar(arrow_data),
)

if obj.show_options.get("arrow_data_to_origin", False):
# point arrow to the origin instead
arrow_shift = np.diff(
as_edges.vertices.reshape(-1, 2, a_data_dim), axis=1
)
as_edges.vertices[:] = (
as_edges.vertices.reshape(-1, 2, a_data_dim) - arrow_shift
).reshape(-1, a_data_dim)

arrows = vedo.Arrows(
as_edges.vertices[as_edges.edges],
c=obj.show_options.get("arrow_data_color", "plasma"),
Expand Down

0 comments on commit b805312

Please sign in to comment.