-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #423 from K3D-tools/devel
Docs update
- Loading branch information
Showing
6 changed files
with
169 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import numpy as np | ||
import os | ||
|
||
import k3d | ||
|
||
|
||
def generate(): | ||
filepath = os.path.join(os.path.abspath(os.path.dirname(__file__)), | ||
'../assets/tractogram.npz') | ||
|
||
data = np.load(filepath)['data'] | ||
|
||
v = data.copy() | ||
v[1:] = (v[1:] - v[:-1]) | ||
v = np.absolute((v / np.linalg.norm(v, axis=1)[..., np.newaxis])) | ||
v = (v * 255).astype(np.int32) | ||
colors = np.sum((v * np.array([1, 256, 256 * 256])), axis=1).astype(np.uint32) | ||
|
||
streamlines = k3d.line(data, shader='simple', colors=colors) | ||
|
||
plot = k3d.plot(grid_visible=False, | ||
camera_auto_fit=False, | ||
background_color=0, | ||
screenshot_scale=1.0) | ||
plot += streamlines | ||
|
||
plot.camera = [-50.0, 125.0, 40.0, | ||
-1.0, 0.5, -5.0, | ||
0.0, -0.25, 1.0] | ||
|
||
plot.snapshot_type = 'inline' | ||
return plot.get_snapshot() |
41 changes: 41 additions & 0 deletions
41
docs/source/gallery/showcase/thumbnails/tractogram_thumbnail.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import numpy as np | ||
import os | ||
|
||
import k3d | ||
from k3d.headless import k3d_remote, get_headless_driver | ||
|
||
|
||
def generate(): | ||
filepath = os.path.join(os.path.abspath(os.path.dirname(__file__)), | ||
'../assets/tractogram.npz') | ||
|
||
data = np.load(filepath)['data'] | ||
|
||
v = data.copy() | ||
v[1:] = (v[1:] - v[:-1]) | ||
v = np.absolute((v / np.linalg.norm(v, axis=1)[..., np.newaxis])) | ||
v = (v * 255).astype(np.int32) | ||
colors = np.sum((v * np.array([1, 256, 256 * 256])), axis=1).astype(np.uint32) | ||
|
||
streamlines = k3d.line(data, shader='thick', colors=colors, width=0.005) | ||
|
||
plot = k3d.plot(grid_visible=False, | ||
camera_auto_fit=False, | ||
background_color=0, | ||
screenshot_scale=1.0, | ||
axes_helper=0) | ||
|
||
plot += streamlines | ||
|
||
plot.camera = [-60.0, 135.0, 45.0, | ||
-1.0, 0.5, -5.0, | ||
0.0, -0.25, 1.0] | ||
|
||
headless = k3d_remote(plot, get_headless_driver(), width=800, height=800) | ||
|
||
headless.sync(hold_until_refreshed=True) | ||
|
||
screenshot = headless.get_screenshot() | ||
headless.close() | ||
|
||
return screenshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Tractogram | ||
========== | ||
|
||
.. admonition:: References | ||
|
||
- :ref:`plot` | ||
- :ref:`lines` | ||
|
||
:download:`tractogram.npz <./assets/tractogram.npz>` | ||
|
||
.. code-block:: python3 | ||
filepath = os.path.join('tractogram.npz') | ||
data = np.load(filepath)['data'] | ||
v = data.copy() | ||
v[1:] = (v[1:] - v[:-1]) | ||
v = np.absolute((v / np.linalg.norm(v, axis=1)[..., np.newaxis])) | ||
v = (v * 255).astype(np.int32) | ||
colors = np.sum((v * np.array([1, 256, 256 * 256])), axis=1).astype(np.uint32) | ||
streamlines = k3d.line(data, shader='simple', colors=colors) | ||
plot = k3d.plot(grid_visible=False, | ||
camera_auto_fit=False, | ||
background_color=0, | ||
screenshot_scale=1.0) | ||
plot += streamlines | ||
plot.camera = [-50.0, 125.0, 40.0, | ||
-1.0, 0.5, -5.0, | ||
0.0, -0.25, 1.0] | ||
plot.display() | ||
.. k3d_plot :: | ||
:filename: plots/tractogram_plot.py |