diff --git a/examples/notebooks/interpolate_volume.ipynb b/examples/notebooks/interpolate_volume.ipynb index f4fae6c1..dd61dba4 100644 --- a/examples/notebooks/interpolate_volume.ipynb +++ b/examples/notebooks/interpolate_volume.ipynb @@ -4,18 +4,7 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "\"\"\"Generate a voxel dataset by interpolating a scalar\n", "which is only known on a scattered set of points or mesh.\n", @@ -40,7 +29,7 @@ "# this produces a hole in the histogram in the range [0.3, 0.4]'\n", "vol.threshold(above=0.3, below=0.4, replace=0.9) # replace voxel value in [vmin,vmax]\n", "\n", - "show(apts, vol, axes=1, elevation=-30)" + "plt = show(apts, vol, axes=1, elevation=-30)" ] }, { @@ -54,14 +43,14 @@ "\n", "\n", "\n", "
\n", - "\n", + "\n", "
\n", " Points:   vedo.pointcloud.Points\n", "\n", - "\n", - "\n", - "\n", + "\n", + "\n", + "\n", "\n", "\n", "\n", @@ -69,7 +58,7 @@ "
bounds
(x/y/z)
3.503e-4 ... 0.9995
4.542e-4 ... 0.9999
2.156e-4 ... 0.9989
center of mass (0.494, 0.533, 0.484)
average size 0.485
bounds
(x/y/z)
3.855e-4 ... 0.9994
1.426e-3 ... 0.9982
1.414e-4 ... 0.9987
center of mass (0.494, 0.504, 0.485)
average size 0.486
nr. points 500
point data array scals
" ], "text/plain": [ - "" + "" ] }, "execution_count": 2, @@ -81,6 +70,26 @@ "apts" ] }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plt.close()" + ] + }, { "cell_type": "code", "execution_count": null, @@ -105,7 +114,20 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.4" + "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, diff --git a/examples/notebooks/pca.ipynb b/examples/notebooks/pca.ipynb index e71db312..d942c4ab 100644 --- a/examples/notebooks/pca.ipynb +++ b/examples/notebooks/pca.ipynb @@ -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 }, @@ -59,30 +59,41 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "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" ] @@ -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, diff --git a/examples/notebooks/shrink.ipynb b/examples/notebooks/shrink.ipynb index eab579de..69b94610 100644 --- a/examples/notebooks/shrink.ipynb +++ b/examples/notebooks/shrink.ipynb @@ -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, diff --git a/vedo/assembly.py b/vedo/assembly.py index 64d05f37..31b1b527 100644 --- a/vedo/assembly.py +++ b/vedo/assembly.py @@ -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" diff --git a/vedo/backends.py b/vedo/backends.py index a904d1cd..9fcf3e40 100644 --- a/vedo/backends.py +++ b/vedo/backends.py @@ -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 @@ -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): @@ -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, @@ -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 @@ -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 diff --git a/vedo/plotter.py b/vedo/plotter.py index b49e8897..b003465a 100644 --- a/vedo/plotter.py +++ b/vedo/plotter.py @@ -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 @@ -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) @@ -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: @@ -796,6 +796,7 @@ def __init__( ##################################################################### ..init ends here. + def __str__(self): """Return Plotter info.""" axtype = { @@ -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) ######################################################################### @@ -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() ######################################################################### diff --git a/vedo/version.py b/vedo/version.py index 3a607b90..9ccddd88 100644 --- a/vedo/version.py +++ b/vedo/version.py @@ -1 +1 @@ -_version = '2024.5.2+dev17' +_version = '2024.5.2+dev18'