From 870b9b2d43152edf7c8aafa8ed67c09b3ab940a1 Mon Sep 17 00:00:00 2001 From: Matthew Spellings Date: Tue, 18 Feb 2020 09:38:37 -0500 Subject: [PATCH 1/5] Improve jupyter display of many Scene objects. This change calls IPython.display.display(..., display_id=<>) for many of the types of scenes, which causes jupyter to update the scene if it has been displayed already. --- plato/draw/fresnel/Scene.py | 2 +- plato/draw/matplotlib/Scene.py | 17 +++++++++++++++-- plato/draw/povray/Scene.py | 3 ++- plato/draw/pythreejs/Scene.py | 5 +++-- plato/draw/vispy/Scene.py | 3 ++- plato/draw/zdog/Scene.py | 5 +++-- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/plato/draw/fresnel/Scene.py b/plato/draw/fresnel/Scene.py index b16f189..039c847 100644 --- a/plato/draw/fresnel/Scene.py +++ b/plato/draw/fresnel/Scene.py @@ -31,7 +31,7 @@ def show(self): import IPython if self._output is None: self.render() - IPython.display.display(self._output) + IPython.display.display(self._output, display_id=str(id(self))) def save(self, filename): """Render and save an image of this Scene. diff --git a/plato/draw/matplotlib/Scene.py b/plato/draw/matplotlib/Scene.py index 1705fe6..451c422 100644 --- a/plato/draw/matplotlib/Scene.py +++ b/plato/draw/matplotlib/Scene.py @@ -1,7 +1,17 @@ +import contextlib import matplotlib.pyplot as pp from matplotlib.collections import PatchCollection -from ... import draw import numpy as np +from ... import draw + +@contextlib.contextmanager +def manage_matplotlib_interactive(): + was_interactive = pp.isinteractive() + pp.ioff() + + yield None + if was_interactive: + pp.ion() class Scene(draw.Scene): __doc__ = (draw.Scene.__doc__ or '') + """ @@ -97,4 +107,7 @@ def save(self, filename): return figure.savefig(filename, dpi=figure.dpi) def _ipython_display_(self): - return self.show() + import IPython.display + with manage_matplotlib_interactive(): + (fig, _) = self.render() + return IPython.display.display(fig, display_id=str(id(self))) diff --git a/plato/draw/povray/Scene.py b/plato/draw/povray/Scene.py index 15dedf5..98194e4 100644 --- a/plato/draw/povray/Scene.py +++ b/plato/draw/povray/Scene.py @@ -128,7 +128,8 @@ def show(self): with tempfile.NamedTemporaryFile(suffix='.png') as temp: self.save(temp.name) - return IPython.display.Image(filename=temp.name) + img = IPython.display.Image(filename=temp.name) + return IPython.display.display(img, display_id=str(id(self))) def save(self, filename): """Save the scene, either as povray source or a rendered image. diff --git a/plato/draw/pythreejs/Scene.py b/plato/draw/pythreejs/Scene.py index 9de1cdc..9678b56 100644 --- a/plato/draw/pythreejs/Scene.py +++ b/plato/draw/pythreejs/Scene.py @@ -179,8 +179,9 @@ def enable(self, name, auto_value=None, **parameters): self._backend_objects['camera'].add(light) def show(self): - import IPython - IPython.display.display(self._backend_objects['renderer']) + import IPython.display + IPython.display.display( + self._backend_objects['renderer'], display_id=str(id(self))) def _ipython_display_(self): return self.show() diff --git a/plato/draw/vispy/Scene.py b/plato/draw/vispy/Scene.py index 1460f25..39958bc 100644 --- a/plato/draw/vispy/Scene.py +++ b/plato/draw/vispy/Scene.py @@ -167,7 +167,8 @@ def show(self): target = io.BytesIO() img = self._canvas.render() imageio.imwrite(target, img, 'png') - return IPython.display.Image(data=target.getvalue()) + to_display = IPython.display.Image(data=target.getvalue()) + return IPython.display.display(to_display, display_id=str(id(self))) msg = ('vispy has already loaded the {} backend, ignoring static' ' feature. Try manually selecting a desktop vispy backend ' diff --git a/plato/draw/zdog/Scene.py b/plato/draw/zdog/Scene.py index 4a3038a..d6b1359 100644 --- a/plato/draw/zdog/Scene.py +++ b/plato/draw/zdog/Scene.py @@ -136,10 +136,11 @@ def render(self): def show(self): """Render the scene to an image and display using ipython.""" import IPython.display - return IPython.display.HTML(self.render()) + disp = IPython.display.HTML(self.render()) + return IPython.display.display(disp, display_id=str(id(self))) def save(self, filename): - """Save the scene, either as povray source or a rendered image. + """Save the scene as an HTML file. :param filename: target filename to save the result into """ From b2bfcd3600ae20eaf207710692ce0b9777db6fea Mon Sep 17 00:00:00 2001 From: Matthew Spellings Date: Fri, 21 Feb 2020 17:26:31 -0500 Subject: [PATCH 2/5] Broadcast quantities in mesh.unfoldProperties with a size of 1 --- plato/mesh.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/plato/mesh.py b/plato/mesh.py index 7019f4d..eb0692d 100644 --- a/plato/mesh.py +++ b/plato/mesh.py @@ -50,7 +50,7 @@ def unfoldProperties(*args): resizedGroups = [] groupSizes = [] for (i, group) in enumerate(groups): - resizedGroups.append([]) + reshapedGroup = [] for chunk in group: if chunk.ndim > 2: chunk = chunk.reshape((-1, chunk.shape[-1])) @@ -59,8 +59,22 @@ def unfoldProperties(*args): newSize = list(sizeTemplate) newSize[i] = chunk.shape[0] newSize[-1] = chunk.shape[-1] - resizedGroups[-1].append(chunk.reshape(newSize)) - groupSizes.append(min(grp.size//grp.shape[-1] for grp in resizedGroups[-1])) + reshapedGroup.append(chunk.reshape(newSize)) + try: + groupSize = min(grp.size//grp.shape[-1] for grp in reshapedGroup + if grp.size//grp.shape[-1] > 1) + except ValueError: # empty sequence + groupSize = 1 + groupSizes.append(groupSize) + + resizedGroups.append([]) + for chunk in reshapedGroup: + # broadcast single values + if chunk.shape[i] == 1 and groupSize > 1: + tile = chunk.ndim*[1] + tile[i] = groupSize + chunk = np.tile(chunk, tile) + resizedGroups[-1].append(chunk) result = [] for (i, group) in enumerate(resizedGroups): From 467c6e5b0136d5c4cbebfeb11b8390ea16ac687f Mon Sep 17 00:00:00 2001 From: Matthew Spellings Date: Fri, 21 Feb 2020 17:34:09 -0500 Subject: [PATCH 3/5] Added ability to index Scenes to reference child primitives --- plato/draw/Scene.py | 10 ++++++++++ test/test_Scene.py | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/plato/draw/Scene.py b/plato/draw/Scene.py index da82f0a..0d26e15 100644 --- a/plato/draw/Scene.py +++ b/plato/draw/Scene.py @@ -28,6 +28,12 @@ class Scene: for prim in scene: # (do something with prim) + Primitives can also be accessed in the order they were added to + the scene using list-like syntax:: + + first_three_prims = scene[:3] + last_prim = scene[-1] + Optional rendering arguments are enabled as *features*, which are name-value pairs identifying a feature by name and any configuration of the feature in the value. @@ -83,6 +89,10 @@ def __init__(self, primitives=[], features={}, size=(40, 30), for name in kwargs: setattr(self, name, kwargs[name]) + def __getitem__(self, key): + """Returns the primitive(s) given an integer index or slice.""" + return self._primitives[key] + def __iter__(self): for prim in self._primitives: yield prim diff --git a/test/test_Scene.py b/test/test_Scene.py index cbff75f..9994d4b 100644 --- a/test/test_Scene.py +++ b/test/test_Scene.py @@ -83,5 +83,19 @@ def test_features(self): scene.get_feature_config('test3'), {'value': 'auto_value', 'another_value': None}) + def test_indexing(self): + prim0 = draw.Spheres() + prim1 = draw.ConvexPolyhedra() + + scene = draw.Scene([prim0, prim1]) + + self.assertIs(scene[0], prim0) + self.assertIs(scene[-1], prim1) + self.assertEqual(scene[:2], [prim0, prim1]) + self.assertEqual(scene[:3], [prim0, prim1]) + + with self.assertRaises(IndexError): + scene[5] + if __name__ == '__main__': unittest.main() From db9c4dfb1385814ce2fe8eec3fb1e134c5d981d9 Mon Sep 17 00:00:00 2001 From: Matthew Spellings Date: Sat, 22 Feb 2020 17:04:56 -0500 Subject: [PATCH 4/5] Make blender, povray, and zdog backends use mesh.unfoldPrimitives() This should make the broadcasting behavior of the various backends more consistent. --- plato/draw/blender/ConvexPolyhedra.py | 8 ++++---- plato/draw/blender/Spheres.py | 8 ++++---- plato/draw/povray/ConvexPolyhedra.py | 18 ++++++++++-------- plato/draw/povray/ConvexSpheropolyhedra.py | 10 ++++++---- plato/draw/povray/Ellipsoids.py | 10 ++++++---- plato/draw/povray/Mesh.py | 8 ++++---- plato/draw/povray/SphereUnions.py | 12 ++++++++---- plato/draw/povray/Spheres.py | 9 ++++++--- plato/draw/zdog/Lines.py | 7 ++++--- plato/draw/zdog/Spheres.py | 8 ++++---- plato/draw/zdog/internal.py | 6 +++--- 11 files changed, 59 insertions(+), 45 deletions(-) diff --git a/plato/draw/blender/ConvexPolyhedra.py b/plato/draw/blender/ConvexPolyhedra.py index 71bc4cb..9f18f95 100644 --- a/plato/draw/blender/ConvexPolyhedra.py +++ b/plato/draw/blender/ConvexPolyhedra.py @@ -1,7 +1,6 @@ import bpy import itertools -from ... import geometry, math -from ... import draw +from ... import draw, geometry, math, mesh import numpy as np class ConvexPolyhedra(draw.ConvexPolyhedra): @@ -22,8 +21,9 @@ def render(self, scene, suffix='', translation=(0, 0, 0), group = bpy.data.groups.new(prim_name) positions = math.quatrot(rotation[np.newaxis, :], self.positions) - for (i, position, orientation, color) in zip( - itertools.count(), positions, self.orientations, self.colors): + particles = zip(*mesh.unfoldProperties([ + positions, self.orientations, self.colors])) + for (i, (position, orientation, color)) in enumerate(particles): shape_name = prim_name + '_{}'.format(i) shape = bpy.data.objects.new(shape_name, object_data=mesh) shape.location = position diff --git a/plato/draw/blender/Spheres.py b/plato/draw/blender/Spheres.py index 3b94f20..91a1ddd 100644 --- a/plato/draw/blender/Spheres.py +++ b/plato/draw/blender/Spheres.py @@ -1,7 +1,6 @@ import bpy import itertools -from ... import math -from ... import draw +from ... import draw, math, mesh import numpy as np class Spheres(draw.Spheres): @@ -21,8 +20,9 @@ def render(self, scene, suffix='', translation=(0, 0, 0), group = bpy.data.groups.new(prim_name) positions = math.quatrot(rotation[np.newaxis, :], self.positions) - for (i, position, radius, color) in zip( - itertools.count(), positions, self.radii, self.colors): + particles = zip(*mesh.unfoldProperties([ + positions, self.radii, self.colors])) + for (i, (position, (radius,), color)) in enumerate(particles): shape_name = prim_name + '_{}'.format(i) shape = bpy.data.objects.new(shape_name, object_data=shape_params) shape.location = position diff --git a/plato/draw/povray/ConvexPolyhedra.py b/plato/draw/povray/ConvexPolyhedra.py index 4670cad..6b7c13b 100644 --- a/plato/draw/povray/ConvexPolyhedra.py +++ b/plato/draw/povray/ConvexPolyhedra.py @@ -18,7 +18,9 @@ class ConvexPolyhedra(draw.ConvexPolyhedra): def render(self, rotation=(1, 0, 0, 0), name_suffix='', **kwargs): rotation = np.asarray(rotation) - quat_magnitude = np.linalg.norm(self.orientations, axis=-1, keepdims=True) + (positions, orientations, colors) = pmesh.unfoldProperties([ + self.positions, self.orientations, self.colors]) + quat_magnitude = np.linalg.norm(orientations, axis=-1, keepdims=True) lines = [] @@ -39,7 +41,7 @@ def render(self, rotation=(1, 0, 0, 0), name_suffix='', **kwargs): lines.append(shapedef) qs = pmath.quatquat(rotation[np.newaxis, :], - self.orientations/quat_magnitude) + orientations/quat_magnitude) rotmat = np.array([[1 - 2*qs[:, 2]**2 - 2*qs[:, 3]**2, 2*(qs[:, 1]*qs[:, 2] - qs[:, 3]*qs[:, 0]), 2*(qs[:, 1]*qs[:, 3] + qs[:, 2]*qs[:, 0])], @@ -52,9 +54,9 @@ def render(self, rotation=(1, 0, 0, 0), name_suffix='', **kwargs): rotmat = rotmat.transpose([2, 1, 0]).reshape((-1, 9)) rotmat[:] *= quat_magnitude[:, 0, np.newaxis]**2 - positions = pmath.quatrot(rotation[np.newaxis, :], self.positions) + positions = pmath.quatrot(rotation[np.newaxis, :], positions) - for (p, m, a) in zip(positions, rotmat, 1 - self.colors[:, 3]): + for (p, m, a) in zip(positions, rotmat, 1 - colors[:, 3]): args = [shapeName] + m.tolist() + p.tolist() + [0, 0, 0, a] lines.append('object {{{} matrix <{},{},{},{},{},{},{},{},{},' '{},{},{}> pigment {{color <{},{},{}> transmit {} }}}}'.format( @@ -71,7 +73,7 @@ def render(self, rotation=(1, 0, 0, 0), name_suffix='', **kwargs): shapedef = '#declare {} = {}'.format(shapeName, meshStr) lines.append(shapedef) - qs = pmath.quatquat(rotation[np.newaxis, :], self.orientations/quat_magnitude) + qs = pmath.quatquat(rotation[np.newaxis, :], orientations/quat_magnitude) rotmat = np.array([[1 - 2*qs[:, 2]**2 - 2*qs[:, 3]**2, 2*(qs[:, 1]*qs[:, 2] - qs[:, 3]*qs[:, 0]), 2*(qs[:, 1]*qs[:, 3] + qs[:, 2]*qs[:, 0])], @@ -84,10 +86,10 @@ def render(self, rotation=(1, 0, 0, 0), name_suffix='', **kwargs): rotmat = rotmat.transpose([2, 1, 0]).reshape((-1, 9)) rotmat *= quat_magnitude[:, 0, np.newaxis]**2 - positions = pmath.quatrot(rotation[np.newaxis, :], self.positions) + positions = pmath.quatrot(rotation[np.newaxis, :], positions) - for (p, m, (r, g, b), a) in zip(positions, rotmat, self.colors[:, :3], - 1 - self.colors[:, 3]): + for (p, m, (r, g, b), a) in zip(positions, rotmat, colors[:, :3], + 1 - colors[:, 3]): args = [shapeName] + m.tolist() + p.tolist() + [r, g, b, a] lines.append('object {{{} matrix <{},{},{},{},{},{},{},{},{},' '{},{},{}> pigment {{color <{},{},{}> transmit ' diff --git a/plato/draw/povray/ConvexSpheropolyhedra.py b/plato/draw/povray/ConvexSpheropolyhedra.py index 9138fbd..111d90d 100644 --- a/plato/draw/povray/ConvexSpheropolyhedra.py +++ b/plato/draw/povray/ConvexSpheropolyhedra.py @@ -9,7 +9,9 @@ class ConvexSpheropolyhedra(draw.ConvexSpheropolyhedra): def render(self, rotation=(1, 0, 0, 0), name_suffix='', **kwargs): rotation = np.asarray(rotation) - quat_magnitude = np.linalg.norm(self.orientations, axis=-1, keepdims=True) + (positions, orientations, colors) = pmesh.unfoldProperties([ + self.positions, self.orientations, self.colors]) + quat_magnitude = np.linalg.norm(orientations, axis=-1, keepdims=True) lines = [] decomp = geometry.convexDecomposition(self.vertices) @@ -32,7 +34,7 @@ def render(self, rotation=(1, 0, 0, 0), name_suffix='', **kwargs): shapeName, '\n'.join(elt for elt in [meshStr] + edges + spheres)) lines.append(shapedef) - qs = pmath.quatquat(rotation[np.newaxis, :], self.orientations/quat_magnitude) + qs = pmath.quatquat(rotation[np.newaxis, :], orientations/quat_magnitude) rotmat = np.array([[1 - 2*qs[:, 2]**2 - 2*qs[:, 3]**2, 2*(qs[:, 1]*qs[:, 2] - qs[:, 3]*qs[:, 0]), 2*(qs[:, 1]*qs[:, 3] + qs[:, 2]*qs[:, 0])], @@ -45,9 +47,9 @@ def render(self, rotation=(1, 0, 0, 0), name_suffix='', **kwargs): rotmat = rotmat.transpose([2, 1, 0]).reshape((-1, 9)) rotmat[:] *= quat_magnitude[:, 0, np.newaxis]**2 - positions = pmath.quatrot(rotation[np.newaxis, :], self.positions) + positions = pmath.quatrot(rotation[np.newaxis, :], positions) - for (p, m, c) in zip(positions, rotmat, self.colors[:, :3]): + for (p, m, c) in zip(positions, rotmat, colors[:, :3]): args = [shapeName] + m.tolist() + p.tolist() + c.tolist() lines.append('object {{{} matrix <{},{},{},{},{},{},{},{},{},' '{},{},{}> pigment {{color <{},{},{}>}}}}'.format( diff --git a/plato/draw/povray/Ellipsoids.py b/plato/draw/povray/Ellipsoids.py index 8b30ad3..22f26cf 100644 --- a/plato/draw/povray/Ellipsoids.py +++ b/plato/draw/povray/Ellipsoids.py @@ -1,19 +1,21 @@ import numpy as np import rowan -from ... import draw +from ... import draw, mesh class Ellipsoids(draw.Ellipsoids): __doc__ = draw.Ellipsoids.__doc__ def render(self, rotation=(1, 0, 0, 0), **kwargs): - positions = rowan.rotate(rotation, self.positions) + (positions, orientations, colors) = mesh.unfoldProperties([ + self.positions, self.orientations, self.colors]) + positions = rowan.rotate(rotation, positions) orientations = rowan.multiply( - rotation, rowan.normalize(self.orientations)) + rotation, rowan.normalize(orientations)) rotations = np.degrees(rowan.to_euler(orientations)) lines = [] for (pos, rot, col, alpha) in zip( - positions, rotations, self.colors[:, :3], 1 - self.colors[:, 3]): + positions, rotations, colors[:, :3], 1 - colors[:, 3]): lines.append('sphere {{ ' '0, 1 scale<{a}, {b}, {c}> ' 'rotate <{rot[2]}, {rot[1]}, {rot[0]}> ' diff --git a/plato/draw/povray/Mesh.py b/plato/draw/povray/Mesh.py index 5ecf058..c8d9323 100644 --- a/plato/draw/povray/Mesh.py +++ b/plato/draw/povray/Mesh.py @@ -15,8 +15,8 @@ def render(self, rotation=(1, 0, 0, 0), name_suffix='', **kwargs): vertex_colors = np.tile( vertex_colors, (int(np.ceil(len(verts)/len(vertex_colors))), 1)) - positions = self.positions - shape_colors = self.shape_colors + (positions, orientations, shape_colors) = mesh.unfoldProperties([ + self.positions, self.orientations, self.shape_colors]) if len(shape_colors) < len(positions): shape_colors = np.tile( shape_colors, (int(np.ceil(len(positions)/len(shape_colors))), 1)) @@ -31,8 +31,8 @@ def render(self, rotation=(1, 0, 0, 0), name_suffix='', **kwargs): vertex_normals = mesh.computeNormals_(verts, self.indices) vertex_normal_text = ' '.join('<{},{},{}>'.format(*v) for v in vertex_normals) - quat_magnitude = np.linalg.norm(self.orientations, axis=-1, keepdims=True) - qs = pmath.quatquat(rotation[np.newaxis, :], self.orientations/quat_magnitude) + quat_magnitude = np.linalg.norm(orientations, axis=-1, keepdims=True) + qs = pmath.quatquat(rotation[np.newaxis, :], orientations/quat_magnitude) rotmats = np.array([[1 - 2*qs[:, 2]**2 - 2*qs[:, 3]**2, 2*(qs[:, 1]*qs[:, 2] - qs[:, 3]*qs[:, 0]), 2*(qs[:, 1]*qs[:, 3] + qs[:, 2]*qs[:, 0])], diff --git a/plato/draw/povray/SphereUnions.py b/plato/draw/povray/SphereUnions.py index 269dbdd..ae2c277 100644 --- a/plato/draw/povray/SphereUnions.py +++ b/plato/draw/povray/SphereUnions.py @@ -1,6 +1,7 @@ import numpy as np from ... import draw from ... import math +from ... import mesh class SphereUnions(draw.SphereUnions): __doc__ = draw.SphereUnions.__doc__ @@ -8,11 +9,14 @@ class SphereUnions(draw.SphereUnions): def render(self, rotation=(1, 0, 0, 0), **kwargs): rotation = np.asarray(rotation) - positions = np.tile(self.positions[:, np.newaxis, :], (1, len(self.points), 1)) - positions += math.quatrot(self.orientations[:, np.newaxis], self.points[np.newaxis]) + (positions, orientations) = mesh.unfoldProperties([ + self.positions, self.orientations]) - radii = np.repeat(self.radii[np.newaxis, :], len(self.positions),axis=0) - colors = np.repeat(self.colors[np.newaxis, :], len(self.positions), axis=0) + positions = np.tile(positions[:, np.newaxis, :], (1, len(self.points), 1)) + positions += math.quatrot(orientations[:, np.newaxis], self.points[np.newaxis]) + + radii = np.repeat(self.radii[np.newaxis, :], len(positions),axis=0) + colors = np.repeat(self.colors[np.newaxis, :], len(positions), axis=0) colors_reshaped = colors.reshape(-1,4) diff --git a/plato/draw/povray/Spheres.py b/plato/draw/povray/Spheres.py index 69e0af0..c662e61 100644 --- a/plato/draw/povray/Spheres.py +++ b/plato/draw/povray/Spheres.py @@ -1,6 +1,7 @@ import numpy as np from ... import draw from ... import math +from ... import mesh class Spheres(draw.Spheres): __doc__ = draw.Spheres.__doc__ @@ -8,11 +9,13 @@ class Spheres(draw.Spheres): def render(self, rotation=(1, 0, 0, 0), **kwargs): rotation = np.asarray(rotation) - positions = math.quatrot(rotation[np.newaxis, :], self.positions) + (positions, radii, colors) = mesh.unfoldProperties([ + self.positions, self.radii, self.colors]) + positions = math.quatrot(rotation[np.newaxis, :], positions) lines = [] - for (p, r, c, a) in zip(positions, self.radii, self.colors[:, :3], - 1 - self.colors[:, 3]): + for (p, r, c, a) in zip(positions, radii[:, 0], colors[:, :3], + 1 - colors[:, 3]): args = p.tolist() + [r] + c.tolist() + [a] lines.append('sphere {{<{},{},{}> {} pigment {{color ' '<{},{},{}> transmit {}}}}}'.format(*args)) diff --git a/plato/draw/zdog/Lines.py b/plato/draw/zdog/Lines.py index 5ea6d80..59f55e5 100644 --- a/plato/draw/zdog/Lines.py +++ b/plato/draw/zdog/Lines.py @@ -1,4 +1,5 @@ from ... import draw +from ... import mesh class Lines(draw.Lines): __doc__ = draw.Lines.__doc__ @@ -9,10 +10,10 @@ def render(self, rotation=(1, 0, 0, 0), name_suffix='', illo_id='illo', # and z is toward you lines = [] - particles = zip( + particles = zip(*mesh.unfoldProperties([ self.start_points*(1, -1, 1), self.end_points*(1, -1, 1), - self.widths, self.colors*255) - for i, (start, end, width, color) in enumerate(particles): + self.widths, self.colors*255])) + for i, (start, end, (width,), color) in enumerate(particles): path = ', '.join('{{x: {}, y: {}, z: {}}}'.format(*v) for v in [start, end]) (r, g, b) = map(int, color[:3]) diff --git a/plato/draw/zdog/Spheres.py b/plato/draw/zdog/Spheres.py index 273cd1f..14460f0 100644 --- a/plato/draw/zdog/Spheres.py +++ b/plato/draw/zdog/Spheres.py @@ -1,7 +1,7 @@ import collections import itertools import numpy as np -from ... import draw +from ... import draw, mesh from ...draw import internal LightInfo = collections.namedtuple( @@ -34,9 +34,9 @@ def render(self, rotation=(1, 0, 0, 0), name_suffix='', illo_id='illo', light_info.append(LightInfo(normal, mag)) - particles = zip( - self.positions*(1, -1, 1), self.diameters, self.colors*255) - for i, (position, diameter, color) in enumerate(particles): + particles = zip(*mesh.unfoldProperties([ + self.positions*(1, -1, 1), self.diameters, self.colors*255])) + for i, (position, (diameter,), color) in enumerate(particles): group_index = 'sphere_{}_{}'.format(name_suffix, i) lines.append(""" diff --git a/plato/draw/zdog/internal.py b/plato/draw/zdog/internal.py index 8520bd2..850dd6f 100644 --- a/plato/draw/zdog/internal.py +++ b/plato/draw/zdog/internal.py @@ -1,6 +1,6 @@ import numpy as np import rowan -from ... import geometry +from ... import geometry, mesh class PolyhedronRenderer: def render(self, rotation=(1, 0, 0, 0), name_suffix='', illo_id='illo', @@ -31,9 +31,9 @@ def render(self, rotation=(1, 0, 0, 0), name_suffix='', illo_id='illo', orientations_euler = rowan.to_euler( self.orientations, convention='xyz', axis_type='intrinsic') - particles = zip( + particles = zip(*mesh.unfoldProperties([ self.positions*(1, -1, 1), self.orientations, - -orientations_euler, self.colors*255) + -orientations_euler, self.colors*255])) for i, (position, orientation, eulers, color) in enumerate(particles): group_index = 'convexPoly_{}_{}'.format(name_suffix, i) From 50597ae007a6a30ca5269b2cfe5e194f39afc70d Mon Sep 17 00:00:00 2001 From: Matthew Spellings Date: Sun, 23 Feb 2020 07:49:11 -0500 Subject: [PATCH 5/5] Clean up import style --- plato/draw/Arrows2D.py | 3 ++- plato/draw/Box.py | 2 ++ plato/draw/ConvexPolyhedra.py | 2 ++ plato/draw/ConvexSpheropolyhedra.py | 2 ++ plato/draw/DiskUnions.py | 2 ++ plato/draw/Disks.py | 2 ++ plato/draw/Ellipsoids.py | 2 ++ plato/draw/Lines.py | 2 ++ plato/draw/Mesh.py | 2 ++ plato/draw/Polygons.py | 2 ++ plato/draw/Scene.py | 2 ++ plato/draw/SpherePoints.py | 2 ++ plato/draw/SphereUnions.py | 2 ++ plato/draw/Spheres.py | 2 ++ plato/draw/Spheropolygons.py | 2 ++ plato/draw/Voronoi.py | 2 ++ plato/draw/__init__.py | 1 - plato/draw/blender/ConvexPolyhedra.py | 6 ++++-- plato/draw/blender/Scene.py | 5 +++-- plato/draw/blender/Spheres.py | 6 ++++-- plato/draw/fresnel/ConvexPolyhedra.py | 4 +++- plato/draw/fresnel/Disks.py | 1 + plato/draw/fresnel/Ellipsoids.py | 4 +++- plato/draw/fresnel/Lines.py | 4 +++- plato/draw/fresnel/Polygons.py | 3 ++- plato/draw/fresnel/Scene.py | 2 +- plato/draw/fresnel/SphereUnions.py | 3 ++- plato/draw/fresnel/Spheres.py | 1 + plato/draw/fresnel/Spheropolygons.py | 3 ++- plato/draw/internal.py | 3 ++- plato/draw/matplotlib/ConvexPolyhedra.py | 5 +++-- plato/draw/matplotlib/DiskUnions.py | 5 +++-- plato/draw/matplotlib/Disks.py | 3 ++- plato/draw/matplotlib/Polygons.py | 7 ++++--- plato/draw/matplotlib/Scene.py | 2 ++ plato/draw/matplotlib/SpherePoints.py | 1 + plato/draw/matplotlib/Spheres.py | 4 +++- plato/draw/matplotlib/Spheropolygons.py | 7 ++++--- plato/draw/povray/ConvexPolyhedra.py | 2 ++ plato/draw/povray/ConvexSpheropolyhedra.py | 1 + plato/draw/povray/Ellipsoids.py | 1 + plato/draw/povray/Lines.py | 2 ++ plato/draw/povray/Mesh.py | 1 + plato/draw/povray/Scene.py | 3 ++- plato/draw/povray/SphereUnions.py | 1 + plato/draw/povray/Spheres.py | 1 + plato/draw/pythreejs/ConvexPolyhedra.py | 3 ++- plato/draw/pythreejs/ConvexSpheropolyhedra.py | 3 ++- plato/draw/pythreejs/Ellipsoids.py | 4 +++- plato/draw/pythreejs/Lines.py | 5 +++-- plato/draw/pythreejs/Mesh.py | 3 ++- plato/draw/pythreejs/Scene.py | 5 +++-- plato/draw/pythreejs/Spheres.py | 4 +++- plato/draw/pythreejs/internal.py | 3 ++- plato/draw/vispy/ConvexPolyhedra.py | 2 ++ plato/draw/vispy/ConvexSpheropolyhedra.py | 2 ++ plato/draw/vispy/DiskUnions.py | 2 ++ plato/draw/vispy/Disks.py | 2 ++ plato/draw/vispy/Ellipsoids.py | 2 ++ plato/draw/vispy/Lines.py | 2 ++ plato/draw/vispy/Mesh.py | 2 ++ plato/draw/vispy/Polygons.py | 2 ++ plato/draw/vispy/Scene.py | 4 +++- plato/draw/vispy/SpherePoints.py | 2 ++ plato/draw/vispy/SphereUnions.py | 2 ++ plato/draw/vispy/Spheres.py | 2 ++ plato/draw/vispy/Spheropolygons.py | 2 ++ plato/draw/vispy/Voronoi.py | 2 ++ plato/draw/vispy/internal.py | 2 ++ plato/draw/zdog/Scene.py | 3 ++- plato/draw/zdog/Spheres.py | 2 ++ plato/draw/zdog/internal.py | 1 + plato/imp.py | 3 ++- plato/mesh.py | 1 + 74 files changed, 155 insertions(+), 42 deletions(-) diff --git a/plato/draw/Arrows2D.py b/plato/draw/Arrows2D.py index 7c29e25..7055aad 100644 --- a/plato/draw/Arrows2D.py +++ b/plato/draw/Arrows2D.py @@ -1,6 +1,7 @@ import numpy as np -from .Polygons import Polygons + from .internal import ShapeDecorator +from .Polygons import Polygons @ShapeDecorator class Arrows2D(Polygons): diff --git a/plato/draw/Box.py b/plato/draw/Box.py index 1592e2d..7e15035 100644 --- a/plato/draw/Box.py +++ b/plato/draw/Box.py @@ -1,6 +1,8 @@ import functools import itertools + import numpy as np + from .. import math from .internal import ShapeDecorator, ShapeAttribute from .Lines import Lines diff --git a/plato/draw/ConvexPolyhedra.py b/plato/draw/ConvexPolyhedra.py index 1dc70fb..4104c07 100644 --- a/plato/draw/ConvexPolyhedra.py +++ b/plato/draw/ConvexPolyhedra.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from .internal import Shape, ShapeDecorator, ShapeAttribute @ShapeDecorator diff --git a/plato/draw/ConvexSpheropolyhedra.py b/plato/draw/ConvexSpheropolyhedra.py index 85bfe7e..66e179d 100644 --- a/plato/draw/ConvexSpheropolyhedra.py +++ b/plato/draw/ConvexSpheropolyhedra.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from .internal import Shape, ShapeDecorator, ShapeAttribute @ShapeDecorator diff --git a/plato/draw/DiskUnions.py b/plato/draw/DiskUnions.py index 095b769..ab54533 100644 --- a/plato/draw/DiskUnions.py +++ b/plato/draw/DiskUnions.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from .internal import Shape, ShapeDecorator, ShapeAttribute @ShapeDecorator diff --git a/plato/draw/Disks.py b/plato/draw/Disks.py index 328f8ed..4977bdd 100644 --- a/plato/draw/Disks.py +++ b/plato/draw/Disks.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from .internal import Shape, ShapeDecorator, ShapeAttribute @ShapeDecorator diff --git a/plato/draw/Ellipsoids.py b/plato/draw/Ellipsoids.py index 4ef7823..a2f32e9 100644 --- a/plato/draw/Ellipsoids.py +++ b/plato/draw/Ellipsoids.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from .internal import Shape, ShapeDecorator, ShapeAttribute @ShapeDecorator diff --git a/plato/draw/Lines.py b/plato/draw/Lines.py index abe4e47..3f9f7b5 100644 --- a/plato/draw/Lines.py +++ b/plato/draw/Lines.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from .internal import Shape, ShapeDecorator, ShapeAttribute @ShapeDecorator diff --git a/plato/draw/Mesh.py b/plato/draw/Mesh.py index d9ab021..c3b2bbb 100644 --- a/plato/draw/Mesh.py +++ b/plato/draw/Mesh.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from .internal import Shape, ShapeDecorator, ShapeAttribute from .. import mesh diff --git a/plato/draw/Polygons.py b/plato/draw/Polygons.py index b99c87b..ec65189 100644 --- a/plato/draw/Polygons.py +++ b/plato/draw/Polygons.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from .internal import Shape, ShapeDecorator, ShapeAttribute @ShapeDecorator diff --git a/plato/draw/Scene.py b/plato/draw/Scene.py index 0d26e15..7ee78ba 100644 --- a/plato/draw/Scene.py +++ b/plato/draw/Scene.py @@ -1,5 +1,7 @@ import logging + import numpy as np + from .internal import Shape DEFAULT_DIRECTIONAL_LIGHTS = ( diff --git a/plato/draw/SpherePoints.py b/plato/draw/SpherePoints.py index d1beb58..71478b4 100644 --- a/plato/draw/SpherePoints.py +++ b/plato/draw/SpherePoints.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from .internal import Shape, ShapeDecorator, ShapeAttribute @ShapeDecorator diff --git a/plato/draw/SphereUnions.py b/plato/draw/SphereUnions.py index 9247e2b..32e68ba 100644 --- a/plato/draw/SphereUnions.py +++ b/plato/draw/SphereUnions.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from .internal import Shape, ShapeDecorator, ShapeAttribute @ShapeDecorator diff --git a/plato/draw/Spheres.py b/plato/draw/Spheres.py index 17fd80f..a14e657 100644 --- a/plato/draw/Spheres.py +++ b/plato/draw/Spheres.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from .internal import Shape, ShapeDecorator, ShapeAttribute @ShapeDecorator diff --git a/plato/draw/Spheropolygons.py b/plato/draw/Spheropolygons.py index cbce399..e37ae76 100644 --- a/plato/draw/Spheropolygons.py +++ b/plato/draw/Spheropolygons.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from .internal import Shape, ShapeDecorator, ShapeAttribute @ShapeDecorator diff --git a/plato/draw/Voronoi.py b/plato/draw/Voronoi.py index 9dc293e..ef7df65 100644 --- a/plato/draw/Voronoi.py +++ b/plato/draw/Voronoi.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from .internal import Shape, ShapeDecorator, ShapeAttribute @ShapeDecorator diff --git a/plato/draw/__init__.py b/plato/draw/__init__.py index 161f868..05bdbe7 100644 --- a/plato/draw/__init__.py +++ b/plato/draw/__init__.py @@ -1,6 +1,5 @@ from .Scene import Scene - from .Arrows2D import Arrows2D from .Box import Box from .Disks import Disks diff --git a/plato/draw/blender/ConvexPolyhedra.py b/plato/draw/blender/ConvexPolyhedra.py index 9f18f95..d640167 100644 --- a/plato/draw/blender/ConvexPolyhedra.py +++ b/plato/draw/blender/ConvexPolyhedra.py @@ -1,8 +1,10 @@ -import bpy import itertools -from ... import draw, geometry, math, mesh + +import bpy import numpy as np +from ... import draw, geometry, math, mesh + class ConvexPolyhedra(draw.ConvexPolyhedra): def render(self, scene, suffix='', translation=(0, 0, 0), diff --git a/plato/draw/blender/Scene.py b/plato/draw/blender/Scene.py index 7923b4c..c774e7d 100644 --- a/plato/draw/blender/Scene.py +++ b/plato/draw/blender/Scene.py @@ -1,6 +1,7 @@ -from ... import draw -import numpy as np import bpy +import numpy as np + +from ... import draw class Scene(draw.Scene): __doc__ = draw.Scene.__doc__ diff --git a/plato/draw/blender/Spheres.py b/plato/draw/blender/Spheres.py index 91a1ddd..57817b6 100644 --- a/plato/draw/blender/Spheres.py +++ b/plato/draw/blender/Spheres.py @@ -1,8 +1,10 @@ -import bpy import itertools -from ... import draw, math, mesh + +import bpy import numpy as np +from ... import draw, math, mesh + class Spheres(draw.Spheres): def render(self, scene, suffix='', translation=(0, 0, 0), diff --git a/plato/draw/fresnel/ConvexPolyhedra.py b/plato/draw/fresnel/ConvexPolyhedra.py index 84a7e6b..91019c6 100644 --- a/plato/draw/fresnel/ConvexPolyhedra.py +++ b/plato/draw/fresnel/ConvexPolyhedra.py @@ -1,6 +1,8 @@ -import fresnel import itertools + +import fresnel import numpy as np + from ... import draw from ..internal import ShapeAttribute, ShapeDecorator from .FresnelPrimitive import FresnelPrimitive diff --git a/plato/draw/fresnel/Disks.py b/plato/draw/fresnel/Disks.py index b4a5831..df4168d 100644 --- a/plato/draw/fresnel/Disks.py +++ b/plato/draw/fresnel/Disks.py @@ -1,4 +1,5 @@ import fresnel + from ... import draw from .FresnelPrimitive import FresnelPrimitiveSolid diff --git a/plato/draw/fresnel/Ellipsoids.py b/plato/draw/fresnel/Ellipsoids.py index 12e65da..41a18a8 100644 --- a/plato/draw/fresnel/Ellipsoids.py +++ b/plato/draw/fresnel/Ellipsoids.py @@ -1,6 +1,8 @@ -import fresnel import itertools + +import fresnel import numpy as np + from ... import draw from ...geometry import fibonacciPositions from ..internal import ShapeAttribute, ShapeDecorator diff --git a/plato/draw/fresnel/Lines.py b/plato/draw/fresnel/Lines.py index 1fdb7e2..05ddd34 100644 --- a/plato/draw/fresnel/Lines.py +++ b/plato/draw/fresnel/Lines.py @@ -1,6 +1,8 @@ -import fresnel import itertools + +import fresnel import numpy as np + from ... import draw from ..internal import ShapeAttribute, ShapeDecorator from .FresnelPrimitive import FresnelPrimitiveSolid diff --git a/plato/draw/fresnel/Polygons.py b/plato/draw/fresnel/Polygons.py index 61691c8..95daaf9 100644 --- a/plato/draw/fresnel/Polygons.py +++ b/plato/draw/fresnel/Polygons.py @@ -1,7 +1,8 @@ import fresnel +import rowan + from ... import draw from .FresnelPrimitive import FresnelPrimitiveSolid -import rowan class Polygons(FresnelPrimitiveSolid, draw.Polygons): __doc__ = draw.Polygons.__doc__ diff --git a/plato/draw/fresnel/Scene.py b/plato/draw/fresnel/Scene.py index 039c847..f0ea3e7 100644 --- a/plato/draw/fresnel/Scene.py +++ b/plato/draw/fresnel/Scene.py @@ -1,8 +1,8 @@ import fresnel import numpy as np import rowan -from ... import draw +from ... import draw class Scene(draw.Scene): __doc__ = (draw.Scene.__doc__ or '') + """ diff --git a/plato/draw/fresnel/SphereUnions.py b/plato/draw/fresnel/SphereUnions.py index 68d286c..a0fe885 100644 --- a/plato/draw/fresnel/SphereUnions.py +++ b/plato/draw/fresnel/SphereUnions.py @@ -1,8 +1,9 @@ import fresnel +import numpy as np + from ... import draw from ... import math from .FresnelPrimitive import FresnelPrimitive -import numpy as np class SphereUnions(FresnelPrimitive, draw.SphereUnions): __doc__ = draw.SphereUnions.__doc__ diff --git a/plato/draw/fresnel/Spheres.py b/plato/draw/fresnel/Spheres.py index 8e25e9d..a551722 100644 --- a/plato/draw/fresnel/Spheres.py +++ b/plato/draw/fresnel/Spheres.py @@ -1,4 +1,5 @@ import fresnel + from ... import draw from .FresnelPrimitive import FresnelPrimitive diff --git a/plato/draw/fresnel/Spheropolygons.py b/plato/draw/fresnel/Spheropolygons.py index 70294c9..beb53e8 100644 --- a/plato/draw/fresnel/Spheropolygons.py +++ b/plato/draw/fresnel/Spheropolygons.py @@ -1,7 +1,8 @@ import fresnel +import rowan + from ... import draw from .FresnelPrimitive import FresnelPrimitiveSolid -import rowan class Spheropolygons(FresnelPrimitiveSolid, draw.Spheropolygons): __doc__ = draw.Spheropolygons.__doc__ diff --git a/plato/draw/internal.py b/plato/draw/internal.py index 396ea14..6689cb4 100644 --- a/plato/draw/internal.py +++ b/plato/draw/internal.py @@ -1,6 +1,7 @@ +from collections import namedtuple import functools import inspect -from collections import namedtuple + import numpy as np ATTRIBUTE_DOCSTRING_HEADER = '\n\nThis primitive has the following attributes:' diff --git a/plato/draw/matplotlib/ConvexPolyhedra.py b/plato/draw/matplotlib/ConvexPolyhedra.py index c0d3f13..fa11ff0 100644 --- a/plato/draw/matplotlib/ConvexPolyhedra.py +++ b/plato/draw/matplotlib/ConvexPolyhedra.py @@ -1,10 +1,11 @@ import numpy as np +from matplotlib.path import Path +from matplotlib.patches import PathPatch, Polygon + from ... import math from ... import geometry from ... import draw from .internal import PatchUser -from matplotlib.path import Path -from matplotlib.patches import PathPatch, Polygon class ConvexPolyhedra(draw.ConvexPolyhedra, PatchUser): __doc__ = draw.ConvexPolyhedra.__doc__ diff --git a/plato/draw/matplotlib/DiskUnions.py b/plato/draw/matplotlib/DiskUnions.py index 08f519e..27077f6 100644 --- a/plato/draw/matplotlib/DiskUnions.py +++ b/plato/draw/matplotlib/DiskUnions.py @@ -1,8 +1,9 @@ +from matplotlib.patches import Circle, Wedge +from matplotlib.transforms import Affine2D import numpy as np + from ... import draw from .internal import PatchUser -from matplotlib.patches import Circle, Wedge -from matplotlib.transforms import Affine2D class DiskUnions(draw.DiskUnions, PatchUser): __doc__ = draw.DiskUnions.__doc__ diff --git a/plato/draw/matplotlib/Disks.py b/plato/draw/matplotlib/Disks.py index 26a8de8..9b2f3d6 100644 --- a/plato/draw/matplotlib/Disks.py +++ b/plato/draw/matplotlib/Disks.py @@ -1,7 +1,8 @@ +from matplotlib.patches import Circle, Wedge import numpy as np + from ... import draw from .internal import PatchUser -from matplotlib.patches import Circle, Wedge class Disks(draw.Disks, PatchUser): __doc__ = draw.Disks.__doc__ diff --git a/plato/draw/matplotlib/Polygons.py b/plato/draw/matplotlib/Polygons.py index fd8d32d..28436b3 100644 --- a/plato/draw/matplotlib/Polygons.py +++ b/plato/draw/matplotlib/Polygons.py @@ -1,10 +1,11 @@ +from matplotlib.path import Path +from matplotlib.patches import PathPatch, Polygon +from matplotlib.transforms import Affine2D import numpy as np + from ... import geometry from ... import draw from .internal import PatchUser -from matplotlib.path import Path -from matplotlib.patches import PathPatch, Polygon -from matplotlib.transforms import Affine2D class Polygons(draw.Polygons, PatchUser): __doc__ = draw.Polygons.__doc__ diff --git a/plato/draw/matplotlib/Scene.py b/plato/draw/matplotlib/Scene.py index 451c422..27ba7b5 100644 --- a/plato/draw/matplotlib/Scene.py +++ b/plato/draw/matplotlib/Scene.py @@ -1,7 +1,9 @@ import contextlib + import matplotlib.pyplot as pp from matplotlib.collections import PatchCollection import numpy as np + from ... import draw @contextlib.contextmanager diff --git a/plato/draw/matplotlib/SpherePoints.py b/plato/draw/matplotlib/SpherePoints.py index 5bb1c0b..d09832d 100644 --- a/plato/draw/matplotlib/SpherePoints.py +++ b/plato/draw/matplotlib/SpherePoints.py @@ -1,4 +1,5 @@ import numpy as np + from ... import draw from ... import math diff --git a/plato/draw/matplotlib/Spheres.py b/plato/draw/matplotlib/Spheres.py index 68afa43..f0f6228 100644 --- a/plato/draw/matplotlib/Spheres.py +++ b/plato/draw/matplotlib/Spheres.py @@ -1,10 +1,12 @@ import itertools + +from matplotlib.patches import Circle import numpy as np + from ... import math from ... import draw from ...draw import internal from .internal import PatchUser -from matplotlib.patches import Circle @internal.ShapeDecorator class Spheres(draw.Spheres, PatchUser): diff --git a/plato/draw/matplotlib/Spheropolygons.py b/plato/draw/matplotlib/Spheropolygons.py index f6bc01d..2f63d93 100644 --- a/plato/draw/matplotlib/Spheropolygons.py +++ b/plato/draw/matplotlib/Spheropolygons.py @@ -1,9 +1,10 @@ -import numpy as np -from ... import draw -from .internal import PatchUser from matplotlib.path import Path from matplotlib.patches import PathPatch from matplotlib.transforms import Affine2D +import numpy as np + +from ... import draw +from .internal import PatchUser class Spheropolygons(draw.Spheropolygons, PatchUser): __doc__ = draw.Spheropolygons.__doc__ diff --git a/plato/draw/povray/ConvexPolyhedra.py b/plato/draw/povray/ConvexPolyhedra.py index 6b7c13b..14d52f8 100644 --- a/plato/draw/povray/ConvexPolyhedra.py +++ b/plato/draw/povray/ConvexPolyhedra.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from ... import draw from ... import mesh as pmesh from ... import geometry diff --git a/plato/draw/povray/ConvexSpheropolyhedra.py b/plato/draw/povray/ConvexSpheropolyhedra.py index 111d90d..3f34881 100644 --- a/plato/draw/povray/ConvexSpheropolyhedra.py +++ b/plato/draw/povray/ConvexSpheropolyhedra.py @@ -1,4 +1,5 @@ import numpy as np + from ... import draw from ... import mesh as pmesh from ... import geometry diff --git a/plato/draw/povray/Ellipsoids.py b/plato/draw/povray/Ellipsoids.py index 22f26cf..e5eca6f 100644 --- a/plato/draw/povray/Ellipsoids.py +++ b/plato/draw/povray/Ellipsoids.py @@ -1,5 +1,6 @@ import numpy as np import rowan + from ... import draw, mesh class Ellipsoids(draw.Ellipsoids): diff --git a/plato/draw/povray/Lines.py b/plato/draw/povray/Lines.py index 1b78ebc..d052e91 100644 --- a/plato/draw/povray/Lines.py +++ b/plato/draw/povray/Lines.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from ... import draw from ..internal import ShapeDecorator, ShapeAttribute from ... import math as pmath diff --git a/plato/draw/povray/Mesh.py b/plato/draw/povray/Mesh.py index c8d9323..061654a 100644 --- a/plato/draw/povray/Mesh.py +++ b/plato/draw/povray/Mesh.py @@ -1,4 +1,5 @@ import numpy as np + from ... import draw from ... import math as pmath from ... import mesh diff --git a/plato/draw/povray/Scene.py b/plato/draw/povray/Scene.py index 98194e4..9c16215 100644 --- a/plato/draw/povray/Scene.py +++ b/plato/draw/povray/Scene.py @@ -3,10 +3,11 @@ import subprocess import tempfile +import numpy as np + from ... import draw from ... import math from ... import __version__ -import numpy as np class Scene(draw.Scene): __doc__ = (draw.Scene.__doc__ or '') + """ diff --git a/plato/draw/povray/SphereUnions.py b/plato/draw/povray/SphereUnions.py index ae2c277..f763147 100644 --- a/plato/draw/povray/SphereUnions.py +++ b/plato/draw/povray/SphereUnions.py @@ -1,4 +1,5 @@ import numpy as np + from ... import draw from ... import math from ... import mesh diff --git a/plato/draw/povray/Spheres.py b/plato/draw/povray/Spheres.py index c662e61..c14ff8c 100644 --- a/plato/draw/povray/Spheres.py +++ b/plato/draw/povray/Spheres.py @@ -1,4 +1,5 @@ import numpy as np + from ... import draw from ... import math from ... import mesh diff --git a/plato/draw/pythreejs/ConvexPolyhedra.py b/plato/draw/pythreejs/ConvexPolyhedra.py index 8d33d59..c6415ff 100644 --- a/plato/draw/pythreejs/ConvexPolyhedra.py +++ b/plato/draw/pythreejs/ConvexPolyhedra.py @@ -1,7 +1,8 @@ +import numpy as np + from ... import draw from ... import mesh from .internal import ThreeJSPrimitive -import numpy as np class ConvexPolyhedra(draw.ConvexPolyhedra, ThreeJSPrimitive): __doc__ = draw.ConvexPolyhedra.__doc__ diff --git a/plato/draw/pythreejs/ConvexSpheropolyhedra.py b/plato/draw/pythreejs/ConvexSpheropolyhedra.py index b46c0f9..7e1aeb1 100644 --- a/plato/draw/pythreejs/ConvexSpheropolyhedra.py +++ b/plato/draw/pythreejs/ConvexSpheropolyhedra.py @@ -1,7 +1,8 @@ +import numpy as np + from ... import draw from ... import mesh from .internal import ThreeJSPrimitive -import numpy as np class ConvexSpheropolyhedra(draw.ConvexSpheropolyhedra, ThreeJSPrimitive): __doc__ = draw.ConvexSpheropolyhedra.__doc__ diff --git a/plato/draw/pythreejs/Ellipsoids.py b/plato/draw/pythreejs/Ellipsoids.py index 6ee296c..a7d7897 100644 --- a/plato/draw/pythreejs/Ellipsoids.py +++ b/plato/draw/pythreejs/Ellipsoids.py @@ -1,10 +1,12 @@ import itertools + +import numpy as np + from ... import draw from ...geometry import fibonacciPositions from ... import mesh from .internal import ThreeJSPrimitive from ..internal import ShapeAttribute, ShapeDecorator -import numpy as np @ShapeDecorator class Ellipsoids(draw.Ellipsoids, ThreeJSPrimitive): diff --git a/plato/draw/pythreejs/Lines.py b/plato/draw/pythreejs/Lines.py index 67cf69b..c93a213 100644 --- a/plato/draw/pythreejs/Lines.py +++ b/plato/draw/pythreejs/Lines.py @@ -1,8 +1,9 @@ +import numpy as np +import rowan + from ... import draw from ... import geometry from .internal import ThreeJSPrimitive -import numpy as np -import rowan class Lines(draw.Lines, ThreeJSPrimitive): __doc__ = draw.Lines.__doc__ diff --git a/plato/draw/pythreejs/Mesh.py b/plato/draw/pythreejs/Mesh.py index 9eef312..3738661 100644 --- a/plato/draw/pythreejs/Mesh.py +++ b/plato/draw/pythreejs/Mesh.py @@ -1,7 +1,8 @@ +import numpy as np + from ... import draw from ... import mesh from .internal import ThreeJSPrimitive -import numpy as np class Mesh(draw.Mesh, ThreeJSPrimitive): __doc__ = draw.Mesh.__doc__ diff --git a/plato/draw/pythreejs/Scene.py b/plato/draw/pythreejs/Scene.py index 9678b56..ae5ace9 100644 --- a/plato/draw/pythreejs/Scene.py +++ b/plato/draw/pythreejs/Scene.py @@ -1,9 +1,10 @@ -from ... import draw -from ..Scene import DEFAULT_DIRECTIONAL_LIGHTS import rowan import numpy as np import pythreejs +from ... import draw +from ..Scene import DEFAULT_DIRECTIONAL_LIGHTS + class Scene(draw.Scene): def __init__(self, *args, **kwargs): self._backend_objects = dict(scene=pythreejs.Scene()) diff --git a/plato/draw/pythreejs/Spheres.py b/plato/draw/pythreejs/Spheres.py index 9d5cf6f..5eda71b 100644 --- a/plato/draw/pythreejs/Spheres.py +++ b/plato/draw/pythreejs/Spheres.py @@ -1,10 +1,12 @@ import itertools + +import numpy as np + from ... import draw from ...geometry import fibonacciPositions from ... import mesh from .internal import ThreeJSPrimitive from ..internal import ShapeAttribute, ShapeDecorator -import numpy as np @ShapeDecorator class Spheres(draw.Spheres, ThreeJSPrimitive): diff --git a/plato/draw/pythreejs/internal.py b/plato/draw/pythreejs/internal.py index 56ef777..180e595 100644 --- a/plato/draw/pythreejs/internal.py +++ b/plato/draw/pythreejs/internal.py @@ -1,7 +1,8 @@ -from ... import math import numpy as np import pythreejs +from ... import math + class ThreeJSPrimitive: @property def threejs_primitive(self): diff --git a/plato/draw/vispy/ConvexPolyhedra.py b/plato/draw/vispy/ConvexPolyhedra.py index 85df61c..0248bb0 100644 --- a/plato/draw/vispy/ConvexPolyhedra.py +++ b/plato/draw/vispy/ConvexPolyhedra.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from ... import mesh from .internal import GLPrimitive, GLShapeDecorator from ... import draw diff --git a/plato/draw/vispy/ConvexSpheropolyhedra.py b/plato/draw/vispy/ConvexSpheropolyhedra.py index 693ff1e..a6538cb 100644 --- a/plato/draw/vispy/ConvexSpheropolyhedra.py +++ b/plato/draw/vispy/ConvexSpheropolyhedra.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from ... import mesh from .internal import GLPrimitive, GLShapeDecorator from ... import draw diff --git a/plato/draw/vispy/DiskUnions.py b/plato/draw/vispy/DiskUnions.py index b37e659..3f7484e 100644 --- a/plato/draw/vispy/DiskUnions.py +++ b/plato/draw/vispy/DiskUnions.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from ... import mesh from .internal import GLPrimitive, GLShapeDecorator from ... import draw diff --git a/plato/draw/vispy/Disks.py b/plato/draw/vispy/Disks.py index 3797b50..925e14f 100644 --- a/plato/draw/vispy/Disks.py +++ b/plato/draw/vispy/Disks.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from ... import mesh from .internal import GLPrimitive, GLShapeDecorator from ... import draw diff --git a/plato/draw/vispy/Ellipsoids.py b/plato/draw/vispy/Ellipsoids.py index 4352de8..3ddc985 100644 --- a/plato/draw/vispy/Ellipsoids.py +++ b/plato/draw/vispy/Ellipsoids.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from ... import mesh from .internal import GLPrimitive, GLShapeDecorator from .Spheres import Spheres diff --git a/plato/draw/vispy/Lines.py b/plato/draw/vispy/Lines.py index 21f7c7e..9f5d241 100644 --- a/plato/draw/vispy/Lines.py +++ b/plato/draw/vispy/Lines.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from ... import mesh from .internal import GLPrimitive, GLShapeDecorator from ... import draw diff --git a/plato/draw/vispy/Mesh.py b/plato/draw/vispy/Mesh.py index 8fe0b03..b9f9054 100644 --- a/plato/draw/vispy/Mesh.py +++ b/plato/draw/vispy/Mesh.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from ... import mesh from .internal import GLPrimitive, GLShapeDecorator from ... import draw diff --git a/plato/draw/vispy/Polygons.py b/plato/draw/vispy/Polygons.py index 973538d..fa2642b 100644 --- a/plato/draw/vispy/Polygons.py +++ b/plato/draw/vispy/Polygons.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from ... import geometry from ... import mesh from .internal import GLPrimitive, GLShapeDecorator diff --git a/plato/draw/vispy/Scene.py b/plato/draw/vispy/Scene.py index 39958bc..2bddb29 100644 --- a/plato/draw/vispy/Scene.py +++ b/plato/draw/vispy/Scene.py @@ -1,8 +1,10 @@ import logging + +import numpy as np import vispy.io + from .Canvas import Canvas from ... import draw -import numpy as np from ..Scene import DEFAULT_DIRECTIONAL_LIGHTS logger = logging.getLogger(__name__) diff --git a/plato/draw/vispy/SpherePoints.py b/plato/draw/vispy/SpherePoints.py index f8d57d1..2a624ea 100644 --- a/plato/draw/vispy/SpherePoints.py +++ b/plato/draw/vispy/SpherePoints.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from .internal import GLPrimitive, GLShapeDecorator from ... import draw from ..internal import ShapeAttribute diff --git a/plato/draw/vispy/SphereUnions.py b/plato/draw/vispy/SphereUnions.py index ce14b0a..3645c52 100644 --- a/plato/draw/vispy/SphereUnions.py +++ b/plato/draw/vispy/SphereUnions.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from ... import mesh from .internal import GLPrimitive, GLShapeDecorator from ... import draw diff --git a/plato/draw/vispy/Spheres.py b/plato/draw/vispy/Spheres.py index 9bb1103..bad62b4 100644 --- a/plato/draw/vispy/Spheres.py +++ b/plato/draw/vispy/Spheres.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from ... import mesh from .internal import GLPrimitive, GLShapeDecorator from ... import draw diff --git a/plato/draw/vispy/Spheropolygons.py b/plato/draw/vispy/Spheropolygons.py index c360d5a..3527b40 100644 --- a/plato/draw/vispy/Spheropolygons.py +++ b/plato/draw/vispy/Spheropolygons.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from ... import mesh from .internal import GLPrimitive, GLShapeDecorator from ... import draw diff --git a/plato/draw/vispy/Voronoi.py b/plato/draw/vispy/Voronoi.py index d3c97e5..300bc0f 100644 --- a/plato/draw/vispy/Voronoi.py +++ b/plato/draw/vispy/Voronoi.py @@ -1,5 +1,7 @@ import itertools + import numpy as np + from ... import mesh from .internal import GLPrimitive, GLShapeDecorator from ... import draw diff --git a/plato/draw/vispy/internal.py b/plato/draw/vispy/internal.py index 41d361a..1f55f35 100644 --- a/plato/draw/vispy/internal.py +++ b/plato/draw/vispy/internal.py @@ -1,8 +1,10 @@ import functools import itertools + import numpy as np import vispy, vispy.app from vispy import gloo + from ... import mesh from ..internal import array_size_checkers, ATTRIBUTE_DOCSTRING_TEMPLATE from ..Scene import DEFAULT_DIRECTIONAL_LIGHTS diff --git a/plato/draw/zdog/Scene.py b/plato/draw/zdog/Scene.py index d6b1359..b758f8a 100644 --- a/plato/draw/zdog/Scene.py +++ b/plato/draw/zdog/Scene.py @@ -1,7 +1,8 @@ -from ... import draw import numpy as np import rowan +from ... import draw + LOCAL_HELPER_SCRIPT = """ let is_in_view = function(elt) { let bounding_rect = elt.getBoundingClientRect(); diff --git a/plato/draw/zdog/Spheres.py b/plato/draw/zdog/Spheres.py index 14460f0..cc963cb 100644 --- a/plato/draw/zdog/Spheres.py +++ b/plato/draw/zdog/Spheres.py @@ -1,6 +1,8 @@ import collections import itertools + import numpy as np + from ... import draw, mesh from ...draw import internal diff --git a/plato/draw/zdog/internal.py b/plato/draw/zdog/internal.py index 850dd6f..62c7b8f 100644 --- a/plato/draw/zdog/internal.py +++ b/plato/draw/zdog/internal.py @@ -1,5 +1,6 @@ import numpy as np import rowan + from ... import geometry, mesh class PolyhedronRenderer: diff --git a/plato/imp.py b/plato/imp.py index 650bf45..f21ff79 100644 --- a/plato/imp.py +++ b/plato/imp.py @@ -24,9 +24,10 @@ """ import functools import importlib -import plato.draw as draw import sys +from . import draw + _pending_primitives = [] _last_scene = None _used_vispy_backend = None diff --git a/plato/mesh.py b/plato/mesh.py index eb0692d..7664791 100644 --- a/plato/mesh.py +++ b/plato/mesh.py @@ -1,6 +1,7 @@ from collections import defaultdict, namedtuple from itertools import repeat + import numpy as np from .geometry import convexHull, insetPolygon, massProperties, Polygon