Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quality-of-life improvements #50

Merged
merged 5 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plato/draw/Arrows2D.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
from .Polygons import Polygons

from .internal import ShapeDecorator
from .Polygons import Polygons

@ShapeDecorator
class Arrows2D(Polygons):
Expand Down
2 changes: 2 additions & 0 deletions plato/draw/Box.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import functools
import itertools

import numpy as np

from .. import math
from .internal import ShapeDecorator, ShapeAttribute
from .Lines import Lines
Expand Down
2 changes: 2 additions & 0 deletions plato/draw/ConvexPolyhedra.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import itertools

import numpy as np

from .internal import Shape, ShapeDecorator, ShapeAttribute

@ShapeDecorator
Expand Down
2 changes: 2 additions & 0 deletions plato/draw/ConvexSpheropolyhedra.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import itertools

import numpy as np

from .internal import Shape, ShapeDecorator, ShapeAttribute

@ShapeDecorator
Expand Down
2 changes: 2 additions & 0 deletions plato/draw/DiskUnions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import itertools

import numpy as np

from .internal import Shape, ShapeDecorator, ShapeAttribute

@ShapeDecorator
Expand Down
2 changes: 2 additions & 0 deletions plato/draw/Disks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import itertools

import numpy as np

from .internal import Shape, ShapeDecorator, ShapeAttribute

@ShapeDecorator
Expand Down
2 changes: 2 additions & 0 deletions plato/draw/Ellipsoids.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import itertools

import numpy as np

from .internal import Shape, ShapeDecorator, ShapeAttribute

@ShapeDecorator
Expand Down
2 changes: 2 additions & 0 deletions plato/draw/Lines.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import itertools

import numpy as np

from .internal import Shape, ShapeDecorator, ShapeAttribute

@ShapeDecorator
Expand Down
2 changes: 2 additions & 0 deletions plato/draw/Mesh.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import itertools

import numpy as np

from .internal import Shape, ShapeDecorator, ShapeAttribute
from .. import mesh

Expand Down
2 changes: 2 additions & 0 deletions plato/draw/Polygons.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import itertools

import numpy as np

from .internal import Shape, ShapeDecorator, ShapeAttribute

@ShapeDecorator
Expand Down
12 changes: 12 additions & 0 deletions plato/draw/Scene.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging

import numpy as np

from .internal import Shape

DEFAULT_DIRECTIONAL_LIGHTS = (
Expand Down Expand Up @@ -28,6 +30,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.
Expand Down Expand Up @@ -83,6 +91,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
Expand Down
2 changes: 2 additions & 0 deletions plato/draw/SpherePoints.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import itertools

import numpy as np

from .internal import Shape, ShapeDecorator, ShapeAttribute

@ShapeDecorator
Expand Down
2 changes: 2 additions & 0 deletions plato/draw/SphereUnions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import itertools

import numpy as np

from .internal import Shape, ShapeDecorator, ShapeAttribute

@ShapeDecorator
Expand Down
2 changes: 2 additions & 0 deletions plato/draw/Spheres.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import itertools

import numpy as np

from .internal import Shape, ShapeDecorator, ShapeAttribute

@ShapeDecorator
Expand Down
2 changes: 2 additions & 0 deletions plato/draw/Spheropolygons.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import itertools

import numpy as np

from .internal import Shape, ShapeDecorator, ShapeAttribute

@ShapeDecorator
Expand Down
2 changes: 2 additions & 0 deletions plato/draw/Voronoi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import itertools

import numpy as np

from .internal import Shape, ShapeDecorator, ShapeAttribute

@ShapeDecorator
Expand Down
1 change: 0 additions & 1 deletion plato/draw/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .Scene import Scene


from .Arrows2D import Arrows2D
from .Box import Box
from .Disks import Disks
Expand Down
12 changes: 7 additions & 5 deletions plato/draw/blender/ConvexPolyhedra.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import bpy
import itertools
from ... import geometry, math
from ... import draw

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),
Expand All @@ -22,8 +23,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
Expand Down
5 changes: 3 additions & 2 deletions plato/draw/blender/Scene.py
Original file line number Diff line number Diff line change
@@ -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__
Expand Down
12 changes: 7 additions & 5 deletions plato/draw/blender/Spheres.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import bpy
import itertools
from ... import math
from ... import draw

import bpy
import numpy as np

from ... import draw, math, mesh

class Spheres(draw.Spheres):

def render(self, scene, suffix='', translation=(0, 0, 0),
Expand All @@ -21,8 +22,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
Expand Down
4 changes: 3 additions & 1 deletion plato/draw/fresnel/ConvexPolyhedra.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions plato/draw/fresnel/Disks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fresnel

from ... import draw
from .FresnelPrimitive import FresnelPrimitiveSolid

Expand Down
4 changes: 3 additions & 1 deletion plato/draw/fresnel/Ellipsoids.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion plato/draw/fresnel/Lines.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion plato/draw/fresnel/Polygons.py
Original file line number Diff line number Diff line change
@@ -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__
Expand Down
4 changes: 2 additions & 2 deletions plato/draw/fresnel/Scene.py
Original file line number Diff line number Diff line change
@@ -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 '') + """
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion plato/draw/fresnel/SphereUnions.py
Original file line number Diff line number Diff line change
@@ -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__
Expand Down
1 change: 1 addition & 0 deletions plato/draw/fresnel/Spheres.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fresnel

from ... import draw
from .FresnelPrimitive import FresnelPrimitive

Expand Down
3 changes: 2 additions & 1 deletion plato/draw/fresnel/Spheropolygons.py
Original file line number Diff line number Diff line change
@@ -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__
Expand Down
3 changes: 2 additions & 1 deletion plato/draw/internal.py
Original file line number Diff line number Diff line change
@@ -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:'
Expand Down
5 changes: 3 additions & 2 deletions plato/draw/matplotlib/ConvexPolyhedra.py
Original file line number Diff line number Diff line change
@@ -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__
Expand Down
5 changes: 3 additions & 2 deletions plato/draw/matplotlib/DiskUnions.py
Original file line number Diff line number Diff line change
@@ -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__
Expand Down
3 changes: 2 additions & 1 deletion plato/draw/matplotlib/Disks.py
Original file line number Diff line number Diff line change
@@ -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__
Expand Down
7 changes: 4 additions & 3 deletions plato/draw/matplotlib/Polygons.py
Original file line number Diff line number Diff line change
@@ -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__
Expand Down
Loading