diff --git a/README.md b/README.md index 6c3ef700..e56623a4 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ Jupyter notebook extension for K3D visualization library. * [bower](http://bower.io/#install-bower) (to fetch K3D dependency) * [pip](https://pypi.python.org/pypi/pip) (to install Python module) +* [jupyter-pip](https://pypi.python.org/pypi/jupyter-pip) (to install Jupyter nbextension) +* [numpy](https://pypi.python.org/pypi/numpy) (for efficient data manipulation) ## Installation diff --git a/bower.json b/bower.json index 6e81db08..b07f59a0 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "k3d-jupyter", - "version": "0.9.0", + "version": "1.0.0", "authors": [ "Artur Trzesiok ", "Sebastian Kremiec " @@ -8,7 +8,7 @@ "description": "Juyter notebook extension for K3D visualization library.", "license": "GPLv2", "dependencies": { - "k3d": "~0.12.0", + "k3d": "~1.0.0", "pako": "~0.2.8" } } diff --git a/examples/voxels_edit.ipynb b/examples/voxels_edit.ipynb index ac6dd015..7c96e6ea 100644 --- a/examples/voxels_edit.ipynb +++ b/examples/voxels_edit.ipynb @@ -9,15 +9,21 @@ "outputs": [], "source": [ "from k3d import K3D\n", + "from ipywidgets import interact, IntSlider\n", "\n", "width = height = length = 3\n", "\n", - "color_map = (0xFF0000,) * width * height * length\n", + "color_map = (0xFF0000, 0x00FF00)\n", "voxels = (1,) * width * height * length\n", "obj = K3D.voxels(voxels, color_map, width=width, height=height, length=length)\n", "\n", - "plot = K3D()\n", + "plot = K3D(voxel_paint_color=2)\n", "plot += obj\n", + "\n", + "@interact(color=IntSlider(value=plot.voxel_paint_color, min=0, max=len(color_map)))\n", + "def color(color):\n", + " plot.voxel_paint_color = color\n", + "\n", "plot.display()" ] }, diff --git a/k3d/__init__.py b/k3d/__init__.py index 8a8778c6..5b4fb891 100644 --- a/k3d/__init__.py +++ b/k3d/__init__.py @@ -1,6 +1,6 @@ from ipywidgets import DOMWidget from IPython.display import display -from traitlets import Unicode, Bytes, Dict, Bool +from traitlets import Unicode, Bytes, Dict, Bool, Int from functools import partial from .factory import Factory from .objects import Drawable @@ -23,8 +23,9 @@ class K3D(DOMWidget, Factory): camera_auto_fit = Bool(sync=True) data = Bytes(sync=True) parameters = Dict(sync=True) + voxel_paint_color = Int(sync=True) - def __init__(self, antialias=False, background_color=0xFFFFFF, camera_auto_fit=True, height=512): + def __init__(self, antialias=False, background_color=0xFFFFFF, camera_auto_fit=True, height=512, voxel_paint_color=0): super(K3D, self).__init__() self.on_msg(self.__on_msg) @@ -39,6 +40,7 @@ def __init__(self, antialias=False, background_color=0xFFFFFF, camera_auto_fit=T 'backgroundColor': background_color, 'height': height, } + self.voxel_paint_color = voxel_paint_color def __add__(self, obj): assert isinstance(obj, Drawable) diff --git a/k3d_widget/view.js b/k3d_widget/view.js index a231eec9..12ddc355 100644 --- a/k3d_widget/view.js +++ b/k3d_widget/view.js @@ -27,26 +27,36 @@ define(['nbextensions/widgets/widgets/js/widget', 'k3d/providers/k3d.threejs.min this.model.on('change:camera_auto_fit', this._setCameraAutoFit, this); this.model.on('change:object', this._onObjectChange, this); + this.model.on('change:voxel_paint_color', this._setVoxelPaintColor, this); this.model.on('fetchData', this._fetchData, this); }, _init: function () { var renderer = new THREE.WebGLRenderer({ - antialias: this.parameters.antialias, - }); + antialias: this.parameters.antialias, + }), + self = this; this.K3D = K3D.Core(K3D.Providers.ThreeJS, this.container, { renderer: renderer + }, function (newInstance) { + self.K3D = newInstance; }); renderer.setClearColor(this.parameters.backgroundColor); this._setCameraAutoFit(); + this._setVoxelPaintColor(); }, _setCameraAutoFit: function () { this.K3D.setCameraAutoFit(this.model.get('camera_auto_fit')); }, + _setVoxelPaintColor: function () { + this.K3D.parameters.voxelPaintColor = this.model.get('voxel_paint_color'); + console.log(this.K3D.parameters.voxelPaintColor); + }, + _onObjectChange: function (model, object) { if (object.type) { return this._add(object); diff --git a/setup.py b/setup.py index c4a6e413..55395791 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ def run(self): version=version, packages=['k3d'], include_package_data=True, - install_requires=['jupyter-pip'], + install_requires=['ipywidgets', 'jupyter-pip', 'numpy'], cmdclass={ 'install': InstallK3D },