Skip to content

Commit

Permalink
Update to new vedo version, fixes also some visualization bugs for k3d.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemens-fricke committed Jan 19, 2024
1 parent 56e350e commit 067656f
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"source": [
"import gustaf as gus\n",
"import vedo\n",
"\n",
"vedo.settings.default_backend = \"k3d\""
]
},
Expand All @@ -21,7 +22,7 @@
" bounds=[[0, 0], [2, 2]], resolutions=[2, 3]\n",
")\n",
"mesh_faces_box.show_options[\"c\"] = 6\n",
"a = mesh_faces_box.show()"
"a = mesh_faces_box.show(axes=1)"
]
},
{
Expand All @@ -38,8 +39,8 @@
"outputs": [],
"source": [
"mesh_volumes_box = gus.create.volumes.box(\n",
" bounds=[[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]], resolutions=[2, 3, 4]\n",
" )\n",
" bounds=[[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]], resolutions=[2, 3, 4]\n",
")\n",
"mesh_volumes_box.show()"
]
},
Expand All @@ -53,9 +54,9 @@
" bounds=[[0, 0], [2, 2]],\n",
" resolutions=[3, 3],\n",
" simplex=True,\n",
"\n",
")\n",
"mesh_faces_triangle.show()"
"mesh_faces_triangle.show()\n",
"print(mesh_faces_triangle.bounds())"
]
},
{
Expand Down Expand Up @@ -104,12 +105,26 @@
"source": [
"def CubeLinear(origin, length):\n",
" origin_length = origin + length\n",
" return splinepy.Bezier(degrees=[1] * 3, control_points=[[origin, origin, origin], [origin_length, origin, origin], [origin, origin_length, origin], [origin_length, origin_length, \\\n",
" origin], [origin, origin, origin_length], [origin_length, origin, origin_length], [origin, origin_length, origin_length], [origin_length, origin_length, \\\n",
" origin_length]])\n",
" return splinepy.Bezier(\n",
" degrees=[1] * 3,\n",
" control_points=[\n",
" [origin, origin, origin],\n",
" [origin_length, origin, origin],\n",
" [origin, origin_length, origin],\n",
" [origin_length, origin_length, origin],\n",
" [origin, origin, origin_length],\n",
" [origin_length, origin, origin_length],\n",
" [origin, origin_length, origin_length],\n",
" [origin_length, origin_length, origin_length],\n",
" ],\n",
" )\n",
"\n",
"\n",
"length_center, length_corner = 0.2, 0.1\n",
"cube_center, cube_corner = CubeLinear(origin=0.5, length=length_center), CubeLinear(origin=1.0, length=-length_corner)"
"cube_center, cube_corner = (\n",
" CubeLinear(origin=0.5, length=length_center),\n",
" CubeLinear(origin=1.0, length=-length_corner),\n",
")"
]
},
{
Expand All @@ -125,10 +140,14 @@
"metadata": {},
"outputs": [],
"source": [
"cube_center.show_options[\"knots\"] = True\n",
"cube_center.show_options[\"control_points\"] = False\n",
"cube_center.show_options[\"knot_lw\"] = 1\n",
"gus.show([\"cube-center\", cube_center], [\"cube-corner\", cube_corner])"
"cube_center.show_options[\"knots\"] = False\n",
"# cube_center.show_options[\"control_points\"] = True\n",
"# cube_center.show_options[\"control_point_ids\"] = False\n",
"# cube_center.show_options[\"control_mesh\"] = True\n",
"# cube_center.show_options[\"control_mesh_lw\"] = 1\n",
"# cube_center.show_options[\"knot_lw\"] = 1\n",
"# cube_center.show_options[\"control_point_r\"] = 1\n",
"gus.show([\"cube-center\", cube_center])"
]
},
{
Expand All @@ -147,10 +166,21 @@
"from splinepy import microstructure\n",
"from splinepy.io import iges\n",
"\n",
"turbine_blade_cross_section = iges.load(\"turbineBladeCrossSectionSurrogate.iges\")[0]\n",
"turbine_blade_tiled = microstructure.Microstructure(deformation_function=turbine_blade_cross_section, tiling=[1, 4],\n",
" microtile=microstructure.tiles.Cross2D())\n",
"turbine_blade_tiled.show(resolutions=10, control_points=False, knots=False, scalarbar=False, lightning=\"off\")"
"turbine_blade_cross_section = iges.load(\n",
" \"turbineBladeCrossSectionSurrogate.iges\"\n",
")[0]\n",
"turbine_blade_tiled = microstructure.Microstructure(\n",
" deformation_function=turbine_blade_cross_section,\n",
" tiling=[1, 4],\n",
" microtile=microstructure.tiles.Cross2D(),\n",
")\n",
"turbine_blade_tiled.show(\n",
" resolutions=10,\n",
" control_points=False,\n",
" knots=False,\n",
" scalarbar=False,\n",
" lightning=\"off\",\n",
")"
]
}
],
Expand Down
7 changes: 6 additions & 1 deletion gustaf/edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ class EdgesShowOption(helpers.options.ShowOption):

_valid_options = helpers.options.make_valid_options(
*helpers.options.vedo_common_options,
Option("vedo", "lw", "Width of edges (lines) in pixel units.", (int,)),
Option(
"vedo",
"lw",
"Width of edges (lines) in pixel units.",
(float, int),
),
Option("vedo", "as_arrows", "Show edges as arrows.", (bool,)),
Option(
"vedo",
Expand Down
40 changes: 18 additions & 22 deletions gustaf/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def show(
title = kwargs.get("title", "gustaf")
background = kwargs.get("background", "white")
return_show_list = kwargs.get("return_showable_list", False)
axes = kwargs.get("axes", None)

def clear_vedo_plotter(plotter, num_renderers, skip_cl=skip_clear):
"""enough said."""
Expand All @@ -96,9 +97,18 @@ def cam_tuple_to_list(dict_cam):

# get plotter
if plt is None:
if is_ipython():
if is_ipython() and vedo.settings.default_backend == "k3d":
vedo.settings.backend_autoclose = False
plt = K3DPlotterN(N, size, background)
else:
if is_ipython():
utils.log.warning(
"Gustaf plotting in notebooks is only supported with k3d"
"backend. To use this backend, set "
"vedo.settings.default_backend = 'k3d' in your notebook."
" Using the default backend might give unexpected results "
"and errors."
)
plt = vedo.Plotter(
N=N,
sharecam=False,
Expand All @@ -109,6 +119,11 @@ def cam_tuple_to_list(dict_cam):
)

else:
if is_ipython():
utils.log.warning(
"Please do not provide a plotter in IPython applications."
"This will produce an error shortly."
)
# check if plt has enough Ns
trueN = np.prod(plt.shape)
clear_vedo_plotter(plt, trueN) # always clear.
Expand Down Expand Up @@ -176,6 +191,7 @@ def cam_tuple_to_list(dict_cam):
at=i,
interactive=interact,
camera=cam_tuple_to_list(cam),
axes=axes,
# offscreen=offs,
)

Expand All @@ -185,6 +201,7 @@ def cam_tuple_to_list(dict_cam):
at=i,
interactive=False,
camera=cam_tuple_to_list(cam),
axes=axes,
# offscreen=offs,
)

Expand All @@ -205,27 +222,6 @@ def cam_tuple_to_list(dict_cam):
return plt


def show_notebook(
*args,
**kwargs,
):
elements_to_show = []
for element in args:
if hasattr(element, "showable"):
elements_to_show.append([element.showable(**kwargs)])
elif isinstance(element, list):
sub_list = []
for sub_element in element:
if hasattr(sub_element, "showable"):
sub_list.append(sub_element.showable(**kwargs))
else:
raise TypeError(
"Only gustaf objects can be shown in notebook"
)
else:
raise TypeError("For vedo_show, only list or dict is valid input")


def make_showable(obj, as_dict=False, **kwargs):
"""Generates a vedo obj based on `kind` attribute from given obj, as well
as show_options.
Expand Down
7 changes: 4 additions & 3 deletions gustaf/utils/notebook_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ def __init__(self, N, size, background=0xFFFFFF):
)

def _at_get_location(self, N):
if self.x * self.y < N:
if (self.x * self.y) < N:
return (self.x - 1, self.y - 1)
return (N // (self.y + 1), N % self.y)
return (N // (self.y), N % self.y)

def show(self, list_of_showables, at, interactive, camera):
def show(self, list_of_showables, at, interactive, camera, axes):
self[self._at_get_location(at)] = self.renderers[at].show(
list_of_showables,
interactive=interactive,
camera=camera,
axes=axes,
# offscreen=offscreen,
)

Expand Down
7 changes: 6 additions & 1 deletion gustaf/vertices.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ class VerticesShowOption(helpers.options.ShowOption):

_valid_options = helpers.options.make_valid_options(
*helpers.options.vedo_common_options,
Option("vedo", "r", "Radius of vertices in units of pixels.", (int,)),
Option(
"vedo",
"r",
"Radius of vertices in units of pixels.",
(float, int),
),
Option(
"vedo",
"labels",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ dev = [
"pytest",
"funi",
"napf",
"vedo>=2023.4.3,<2023.5.0",
"vedo==2023.5.0",
"scipy",
"meshio",
"requests",
Expand Down

0 comments on commit 067656f

Please sign in to comment.