From 84687db1e38cdeb65073e339e3a61cf013466940 Mon Sep 17 00:00:00 2001 From: marcomusy Date: Sun, 29 Aug 2021 21:37:36 +0200 Subject: [PATCH] reset plotter.load --- examples/advanced/quadratic_morphing.py | 8 +++---- examples/basic/closewindow.py | 5 +--- vedo/plotter.py | 31 ++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/examples/advanced/quadratic_morphing.py b/examples/advanced/quadratic_morphing.py index d853c483..b200e999 100644 --- a/examples/advanced/quadratic_morphing.py +++ b/examples/advanced/quadratic_morphing.py @@ -5,13 +5,12 @@ The fitting minimizes the distance to the target surface using algorithms available in the scipy.optimize package. """ -from __future__ import division, print_function - -print(__doc__) - from vedo import * import scipy.optimize as opt +print(__doc__) + +settings.useDepthPeeling = True plt = Plotter(shape=[1, 3], interactive=0, axes=1) @@ -51,7 +50,6 @@ def _func(self, pars): #calculate chi2 d2sum, n = 0.0, self.source.N() srcpts = self.source.points() - mpts = self.msource.points() rng = range(0, n, int(n / self.subsample)) for i in rng: p1 = srcpts[i] diff --git a/examples/basic/closewindow.py b/examples/basic/closewindow.py index e8744c78..2f9abacb 100644 --- a/examples/basic/closewindow.py +++ b/examples/basic/closewindow.py @@ -38,9 +38,6 @@ vp2.closeWindow() printc('vp2.closeWindow() called') -vp3.show(Hyperboloid()) - -from vedo import closeWindow -closeWindow() # automatically find and close the current window +vp3.show(Hyperboloid()).close() printc('done.') diff --git a/vedo/plotter.py b/vedo/plotter.py index ae00a5a9..3e962a09 100644 --- a/vedo/plotter.py +++ b/vedo/plotter.py @@ -786,7 +786,36 @@ def __iadd__(self, actors): def __isub__(self, actors): self.remove(actors, render=False) return self - + + def load(self, filename, unpack=True, force=False): + """ + Load objects from file. + The output will depend on the file extension. See examples below. + :param bool unpack: only for multiblock data, + if True returns a flat list of objects. + :param bool force: when downloading a file ignore any previous + cached downloads and force a new one. + :Example: + .. code-block:: python + from vedo import * + # Return a list of 2 Mesh + g = load([dataurl+'250.vtk', dataurl+'290.vtk']) + show(g) + # Return a list of meshes by reading all files in a directory + # (if directory contains DICOM files then a Volume is returned) + g = load('mydicomdir/') + show(g) + # Return a Volume. Color/Opacity transfer function can be specified too. + g = load(dataurl+'embryo.slc') + g.c(['y','lb','w']).alpha((0.0, 0.4, 0.9, 1)).show() + """ + acts = vedo.io.load(filename, unpack, force) + if utils.isSequence(acts): + self.actors += acts + else: + self.actors.append(acts) + return acts + def add(self, actors, at=None, render=True, resetcam=False): """Append input object to the internal list of actors to be shown.