Skip to content

Commit

Permalink
cleanup backends
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Dec 2, 2024
1 parent 27b8c59 commit 6ffc1cd
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 65 deletions.
60 changes: 41 additions & 19 deletions examples/notebooks/interpolate_volume.ipynb

Large diffs are not rendered by default.

54 changes: 39 additions & 15 deletions examples/notebooks/pca.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1m\u001b[32minside points # 4889\u001b[0m\n",
"\u001b[1m\u001b[31moutside points # 111\u001b[0m\n",
"\u001b[1masphericity: 0.5458431953016063\u001b[0m\n"
"\u001b[1m\u001b[32minside points # 2500\u001b[0m\n",
"\u001b[1m\u001b[31moutside points # 2500\u001b[0m\n",
"\u001b[1masphericity: 0.5208038794048852\u001b[0m\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ac4bb1ce6313436ca69c2622dddd94d1",
"model_id": "ab661bcbf16948c288da403947912b54",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -59,30 +59,41 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"<vedo.plotter.Plotter at 0x7f683c497d40>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plt.close()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[7m\u001b[1mvedo version : 2023.5.0+dev2 (https://vedo.embl.es) \u001b[0m\n",
"\u001b[1mvtk version : 9.3.0\u001b[0m\n",
"\u001b[1mnumpy version : 1.26.0\u001b[0m\n",
"\u001b[1mpython version : 3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:08:06) [GCC 11.3.0]\u001b[0m\n",
"\u001b[1mpython interpreter: /home/musy/soft/miniconda3/bin/python3.10\u001b[0m\n",
"\u001b[7m\u001b[1mvedo version : 2024.5.2+dev17 (https://vedo.embl.es) \u001b[0m\n",
"\u001b[1mvtk version : 9.4.0\u001b[0m\n",
"\u001b[1mnumpy version : 1.26.4\u001b[0m\n",
"\u001b[1mpython version : 3.12.5 | packaged by conda-forge | (main, Aug 8 2024, 18:36:51) [GCC 12.4.0]\u001b[0m\n",
"\u001b[1mpython interpreter: /home/musy/soft/miniforge3/bin/python3.12\u001b[0m\n",
"\u001b[1minstallation point: /home/musy/Projects/vedo\u001b[0m\n",
"\u001b[1msystem : Linux 5.4.0-166-generic posix x86_64\u001b[0m\n",
"\u001b[2mk3d version : 2.16.0\u001b[0m\n",
"\u001b[1msystem : Linux 5.4.0-200-generic posix x86_64\u001b[0m\n",
"\u001b[2mk3d version : 2.16.1\u001b[0m\n",
"\u001b[1m\u001b[33m💡 No input files? Try:\n",
" vedo https://vedo.embl.es/examples/data/panther.stl.gz\u001b[0m\n"
]
Expand Down Expand Up @@ -116,7 +127,20 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.10"
"version": "3.12.5"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
Expand Down
15 changes: 14 additions & 1 deletion examples/notebooks/shrink.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,20 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.10"
"version": "3.12.5"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion vedo/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def __str__(self):

n = len(self.unpack())
out += "n. of objects".ljust(14) + ": " + str(n) + " "
names = [a.name for a in self.unpack() if a.name]
names = set([a.name for a in self.unpack() if a.name])
if names:
out += str(names).replace("'","")[:56]
out += "\n"
Expand Down
41 changes: 36 additions & 5 deletions vedo/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def get_notebook_backend(actors2show=()):
if settings.default_backend.startswith("ipyvtk"):
return start_ipyvtklink()

#########################################
if settings.default_backend.startswith("panel"):
return start_panel()

vedo.logger.error(f"Unknown jupyter backend: {settings.default_backend}")
return None

Expand Down Expand Up @@ -66,6 +70,33 @@ def start_2d():
plt.close()
return pil_img

#####################################################################################
def start_panel():
try:
import panel as pn
pn.extension('vtk', design='material', sizing_mode='stretch_width', template='material')
# pn.state.template.config.raw_css.append("""
# #main {
# padding: 0;
# }""")
except ImportError:
print("panel is not installed, try:\n> conda install panel")
return None

print("panel backend NOT YET FUNCTIONAL")
plt = vedo.plotter_instance

if hasattr(plt, "window") and plt.window:
plt.renderer.ResetCamera()
vtkpan = pn.pane.VTK(
plt.window,
margin=0, sizing_mode='stretch_both',
min_height=600,
orientation_widget=True,
enable_keybindings=True,
)
vedo.notebook_plotter = vtkpan
return vedo.notebook_plotter

####################################################################################
def start_k3d(actors2show):
Expand Down Expand Up @@ -200,7 +231,7 @@ def start_k3d(actors2show):
) * np.array([-1, 1] * 3)

kobj = k3d.volume(
kimage.astype(float),
kimage.astype(np.float32),
color_map=kcmap,
# color_range=ia.dataset.GetScalarRange(),
alpha_coef=10,
Expand Down Expand Up @@ -243,11 +274,11 @@ def start_k3d(actors2show):
aves = ia.diagonal_size() * iap.GetLineWidth() / 100

kobj = k3d.line(
pts.astype(float),
pts.astype(np.float32),
color=_rgb2int(iap.GetColor()),
opacity=iap.GetOpacity(),
shader=settings.k3d_line_shader,
width=aves,
width=aves.astype(float),
name=name,
)
vedo.notebook_plotter += kobj
Expand Down Expand Up @@ -316,12 +347,12 @@ def start_k3d(actors2show):
aves = ia.average_size() * iap.GetPointSize() / 200

kobj = k3d.points(
ia.vertices.astype(float),
ia.vertices.astype(np.float32),
color=_rgb2int(iap.GetColor()),
colors=kcols,
opacity=iap.GetOpacity(),
shader=settings.k3d_point_shader,
point_size=aves,
point_size=aves.astype(float),
name=name,
)
vedo.notebook_plotter += kobj
Expand Down
47 changes: 24 additions & 23 deletions vedo/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,29 +510,28 @@ def __init__(
####################################

#############################################################
if vedo.settings.default_backend in ["vtk", "2d", "trame"]:
if screensize == "auto":
screensize = (2160, 1440) # TODO: get actual screen size

if screensize == "auto":
screensize = (2160, 1440) # TODO: get actual screen size
# build the rendering window:
self.window = vtki.vtkRenderWindow()

# build the rendering window:
self.window = vtki.vtkRenderWindow()
self.window.GlobalWarningDisplayOff()

self.window.GlobalWarningDisplayOff()
if self.title == "vedo": # check if dev version
if "dev" in vedo.__version__:
self.title = f"vedo ({vedo.__version__})"
self.window.SetWindowName(self.title)

if self.title == "vedo": # check if dev version
if "dev" in vedo.__version__:
self.title = f"vedo ({vedo.__version__})"
self.window.SetWindowName(self.title)
# more vedo.settings
if vedo.settings.use_depth_peeling:
self.window.SetAlphaBitPlanes(vedo.settings.alpha_bit_planes)
self.window.SetMultiSamples(vedo.settings.multi_samples)

# more vedo.settings
if vedo.settings.use_depth_peeling:
self.window.SetAlphaBitPlanes(vedo.settings.alpha_bit_planes)
self.window.SetMultiSamples(vedo.settings.multi_samples)
self.window.SetPolygonSmoothing(vedo.settings.polygon_smoothing)
self.window.SetLineSmoothing(vedo.settings.line_smoothing)
self.window.SetPointSmoothing(vedo.settings.point_smoothing)

self.window.SetPolygonSmoothing(vedo.settings.polygon_smoothing)
self.window.SetLineSmoothing(vedo.settings.line_smoothing)
self.window.SetPointSmoothing(vedo.settings.point_smoothing)

#############################################################
if N: # N = number of renderers. Find out the best
Expand Down Expand Up @@ -697,7 +696,6 @@ def __init__(
arenderer.SetTwoSidedLighting(vedo.settings.two_sided_lighting)

arenderer.SetUseDepthPeeling(vedo.settings.use_depth_peeling)
# arenderer.SetUseDepthPeelingForVolumes(vedo.settings.use_depth_peeling)
if vedo.settings.use_depth_peeling:
arenderer.SetMaximumNumberOfPeels(vedo.settings.max_number_of_peels)
arenderer.SetOcclusionRatio(vedo.settings.occlusion_ratio)
Expand Down Expand Up @@ -750,12 +748,14 @@ def __init__(
except AttributeError:
pass

# Backend ####################################################
if vedo.settings.default_backend in ["panel", "trame", "k3d"]:
return ################
########################

#########################################################
if self.qt_widget or self.wx_widget:
# self.window.SetSize(int(self.size[0]), int(self.size[1]))
self.interactor.SetRenderWindow(self.window)
# vsty = vtki.new("InteractorStyleTrackballCamera")
# self.interactor.SetInteractorStyle(vsty)
if vedo.settings.enable_default_keyboard_callbacks:
self.interactor.AddObserver("KeyPressEvent", self._default_keypress)
if vedo.settings.enable_default_mouse_callbacks:
Expand Down Expand Up @@ -796,6 +796,7 @@ def __init__(

##################################################################### ..init ends here.


def __str__(self):
"""Return Plotter info."""
axtype = {
Expand Down Expand Up @@ -3327,7 +3328,7 @@ def show(
self.add(objects)

# Backend ###############################################################
if vedo.settings.default_backend in ["k3d"]:
if vedo.settings.default_backend in ["k3d", "panel"]:
return backends.get_notebook_backend(self.objects)
#########################################################################

Expand Down Expand Up @@ -3469,7 +3470,7 @@ def show(
self.clock = time.time() - self._clockt0

# 2d ####################################################################
if vedo.settings.default_backend == "2d":
if vedo.settings.default_backend in ["2d"]:
return backends.get_notebook_backend()
#########################################################################

Expand Down
2 changes: 1 addition & 1 deletion vedo/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
_version = '2024.5.2+dev17'
_version = '2024.5.2+dev18'

0 comments on commit 6ffc1cd

Please sign in to comment.