Skip to content

Commit

Permalink
Release v0.6.0
Browse files Browse the repository at this point in the history
- use current k3d for latest features
- refactoring
- python3 related improvements
  • Loading branch information
skremiec committed Nov 25, 2015
1 parent 8735768 commit efd182f
Show file tree
Hide file tree
Showing 15 changed files with 326 additions and 184 deletions.
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "k3d-jupyter",
"version": "0.5.0",
"version": "0.6.0",
"authors": [
"Artur Trzęsiok <[email protected]>",
"Sebastian Kremiec <[email protected]>"
],
"description": "Juyter notebook extension for K3D visualization library.",
"license": "GPLv2",
"dependencies": {
"k3d": "~0.8.2",
"k3d": "~0.9.2",
"pako": "~0.2.8"
}
}
4 changes: 3 additions & 1 deletion examples/line.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
" 10.0, -15.0, 0.0\n",
")\n",
"\n",
"lines = K3D.line(positions, view_matrix=view_matrix, color=0xff0000, width=2.5) + K3D.line((0, 0, 0, 5, 10, 15))\n",
"\n",
"plot = K3D(antialias=True)\n",
"plot += K3D.line(positions, view_matrix=view_matrix, color=0xff0000, width=2.5)\n",
"plot += lines\n",
"plot.display()"
]
}
Expand Down
2 changes: 1 addition & 1 deletion examples/marching_cubes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"X, Y, Z = numpy.mgrid[:30, :30, :30]\n",
"scalars_field = ((X-15.0)/15.0)**2 + ((Y-15.0)/15.0)**2 + ((Z-15.0)/15.0)**2\n",
"\n",
"plot = K3D(background_color=0x000000)\n",
"plot = K3D()\n",
"plot += K3D.marching_cubes(scalars_field, level=0.8)\n",
"plot.display()"
]
Expand Down
2 changes: 1 addition & 1 deletion examples/points.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"colors = numpy.random.randint(0, 0xFFFFFF, points_number)\n",
"\n",
"plot = K3D()\n",
"plot += K3D.points(positions, colors, xmin=-2, xmax=2, zmin=-2, zmax=2, point_size=3.0)\n",
"plot += K3D.points(positions, colors, point_size=3.0)\n",
"plot.display()"
]
}
Expand Down
4 changes: 2 additions & 2 deletions examples/surface.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"\n",
"view_matrix = (\n",
" 10.0, 2.0, -20.0, 0.0,\n",
" 0.0, 10.0, 0.0, 5.0,\n",
" 0.0, 10.0, 0.0, 9.0,\n",
" 0.0, 0.0, 10.0, 0.0,\n",
" 0.0, 0.0, 0.0, 1.0\n",
")\n",
Expand All @@ -26,7 +26,7 @@
"scalars_field = [[f(x, y) for y in range(height)] for x in range(width)]\n",
"\n",
"plot = K3D()\n",
"plot += K3D.surface(scalars_field, view_matrix=view_matrix, color=0xFF0000)\n",
"plot += K3D.surface(scalars_field, xmin=-2, xmax=2, zmin=-2, zmax=2, view_matrix=view_matrix, color=0xFF0000)\n",
"plot.display()"
]
}
Expand Down
41 changes: 0 additions & 41 deletions examples/torus_knot.ipynb

This file was deleted.

8 changes: 4 additions & 4 deletions examples/vector2d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
"def f(x, y):\n",
" return sin(float(x) / width * pi * 2.0), cos(float(y) / height * pi * 2.0)\n",
"\n",
"colors = [0xFF0000, 0xFFFFFF] * width * height\n",
"vectors = [[f(x, y) for x in range(width)] for y in range(height)]\n",
"colors = (0xFF0000, 0x00FF00) * width * height\n",
"vectors = [[f(x, y) for y in range(height)] for x in range(width)]\n",
"\n",
"plot = K3D(background_color=0)\n",
"plot += K3D.vectors_fields(vectors, colors, view_matrix=view_matrix, use_head=False)\n",
"plot = K3D()\n",
"plot += K3D.vectors_fields(vectors, colors, view_matrix=view_matrix)\n",
"plot.display()"
]
}
Expand Down
8 changes: 4 additions & 4 deletions examples/vector3d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
"def f(x, y, z):\n",
" return sin(float(x) / width * pi * 2.0), cos(float(y) / height * pi * 2.0), sin(float(z) / length * pi * 2.0)\n",
"\n",
"colors = (0xFF0000, 0xFFFFFF) * width * height * length\n",
"vectors = [[[f(x, y, z) for x in range(width)] for y in range(height)] for z in range(length)]\n",
"colors = (0xFF0000, 0x00FF00) * width * height * length\n",
"vectors = [[[f(x, y, z) for z in range(length)] for y in range(height)] for x in range(width)]\n",
"\n",
"plot = K3D(background_color=0x000000)\n",
"plot += K3D.vectors_fields(vectors, colors, view_matrix=view_matrix)\n",
"plot = K3D()\n",
"plot += K3D.vectors_fields(vectors, colors, view_matrix=view_matrix, use_head=False)\n",
"plot.display()"
]
}
Expand Down
2 changes: 1 addition & 1 deletion examples/voxels.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
" return 0 if r(x, y, z) > width / 2 else 1 if y + sin(x / 20) * 10 > height / 2 else 2\n",
"\n",
"color_map = (0xffff00, 0xff0000)\n",
"voxels = [[[f(x, y, z) for x in range(width)] for y in range(height)] for z in range(length)]\n",
"voxels = [[[f(x, y, z) for z in range(length)] for y in range(height)] for x in range(width)]\n",
"\n",
"plot = K3D()\n",
"plot += K3D.voxels(voxels, color_map)\n",
Expand Down
18 changes: 12 additions & 6 deletions k3d/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from ipywidgets import DOMWidget
from IPython.display import display
from traitlets import Unicode, Bytes, Dict
from .objects import Objects
from .factory import Factory
from .objects import Drawable
from .queue import Queue
import base64
import json
import zlib
Expand All @@ -22,9 +23,9 @@ class K3D(DOMWidget, Factory):
def __init__(self, antialias=False, background_color=0xFFFFFF, height=512):
super(K3D, self).__init__()

self.__objects = Objects(self.__show)
self.__queue = Queue(self.__show)
self.__display_strategy = self.__display
self.on_displayed(lambda x: self.__objects.flush())
self.on_displayed(lambda x: self.__queue.flush())

self.parameters = {
'antialias': antialias,
Expand All @@ -33,7 +34,11 @@ def __init__(self, antialias=False, background_color=0xFFFFFF, height=512):
}

def __add__(self, obj):
self.__objects.add(obj)
assert isinstance(obj, Drawable)

if obj.set_plot(self):
self.__queue.add(obj)

return self

def display(self):
Expand All @@ -43,8 +48,9 @@ def __display(self):
display(self)
self.__display_strategy = self.__pass

def __show(self, obj):
self.data = base64.b64encode(zlib.compress(json.dumps(obj, separators=(',', ':')), self.COMPRESSION_LEVEL))
def __show(self, objs):
for obj in objs:
self.data = base64.b64encode(zlib.compress(json.dumps(obj.__dict__, separators=(',', ':')), self.COMPRESSION_LEVEL))

def __pass(self):
pass
Loading

0 comments on commit efd182f

Please sign in to comment.