Skip to content

Commit

Permalink
Impl: Implement changes from review. Some are outstanding.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemens-fricke committed Jan 24, 2024
1 parent 5dda22f commit 10a779c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
1 change: 0 additions & 1 deletion examples/ipynb/notebook_showcase_k3d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@
" microtile=splinepy.microstructure.tiles.Cross2D(),\n",
")\n",
"turbine_blade_tiled.show(\n",
" resolutions=10,\n",
" control_points=False,\n",
" knots=False,\n",
" scalarbar=False,\n",
Expand Down
25 changes: 19 additions & 6 deletions gustaf/helpers/notebook.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
"""gustaf/gustaf/helpers/notebook.py.
Enables the plotting in ipynb with k3d.
There are no import guards since they are in the place where this module is
imported. This should be enough since I do not think that this module
will/should be used outside this place.
"""
import importlib

import numpy as np
Expand Down Expand Up @@ -67,9 +75,9 @@ def __init__(self, N, size, background=0xFFFFFF):
self.x, self.y = get_shape(N, *(2160, 1440))
self.shape = (self.x, self.y)
super().__init__(self.x, self.y)
self.renderers = []
self.vedo_plotters = []
for _ in range(N):
self.renderers.append(
self.vedo_plotters.append(
vedo.Plotter(
size=size,
bg=background,
Expand Down Expand Up @@ -106,7 +114,7 @@ def show(self, list_of_showables, at, interactive, camera, axes):
axes: bool
Add axes to the plot. Will also cast int to bool.
"""
self[self._at_get_location(at)] = self.renderers[at].show(
self[self._at_get_location(at)] = self.vedo_plotters[at].show(
list_of_showables,
interactive=interactive,
camera=camera,
Expand All @@ -115,9 +123,14 @@ def show(self, list_of_showables, at, interactive, camera, axes):
)

def display(self):
"""Display the plotter."""
"""Display the plotter.
This is needed in case the plotter is the last thing in a cell. In that
case the IPython will try to call this function to display this.
"""
display(self)

def clear(*args, **kwargs):
def clear(self, *args, **kwargs):
"""Clear the plotters."""
pass
for renderer in self.vedo_plotters:
renderer.clear(*args, deep=True, **kwargs)
7 changes: 6 additions & 1 deletion gustaf/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ def __call__(self, *args, **kwargs):
sys.modules[__name__].__class__ = _CallableShowDotPy


def is_ipython() -> bool:
def is_ipython():
"""Returns True if the current environment is IPython.
Check if the code is run in a notebook.
Returns
-------
bool
True if the current environment is IPython.
"""
try:
from IPython import get_ipython
Expand Down

0 comments on commit 10a779c

Please sign in to comment.