Skip to content

Commit

Permalink
Merge pull request #403 from K3D-tools/devel
Browse files Browse the repository at this point in the history
docs + tests review
  • Loading branch information
artur-trzesiok authored Dec 18, 2022
2 parents 61d7652 + 6a584d1 commit fa53000
Show file tree
Hide file tree
Showing 55 changed files with 353 additions and 354 deletions.
8 changes: 1 addition & 7 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import shutil
import sys
import time
from source.k3d_directives.plot import K3D_Plot
import shutil
import json

sys.path.insert(0, os.path.abspath('../..'))

Expand All @@ -29,12 +28,8 @@
# The full version, including alpha/beta/rc tags
here = os.path.dirname(__file__)
repo = os.path.join(here, '..', '..')
_version_py = os.path.join(repo, 'package.json')
version_ns = {}

with open(_version_py) as f:
version = json.load(f)["version"]

# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
Expand Down Expand Up @@ -65,7 +60,6 @@
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import k3d
import numpy as np
from numpy import sin

import k3d
from k3d.headless import k3d_remote, get_headless_driver

sin = np.sin


def generate():
t = np.linspace(-5, 5, 100, dtype=np.float32)
x, y, z = np.meshgrid(t, t, t, indexing='ij')

scalars = sin(x*y + x*z + y*z) + sin(x*y) + sin(y*z) + sin(x*z) - 1
scalars = sin(x * y + x * z + y * z) + sin(x * y) + sin(y * z) + sin(x * z) - 1

marching = k3d.marching_cubes(scalars, level=0.0,
color=0x0e2763,
Expand Down
5 changes: 3 additions & 2 deletions docs/source/gallery/showcase/plots/lorenz_system_plot.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import k3d
import numpy as np

import k3d
from k3d.colormaps import paraview_color_maps


def generate():
def lorenz(x, y, z, s=10, r=28, b=8/3):
def lorenz(x, y, z, s=10, r=28, b=8 / 3):
x_dot = s * (y - x)
y_dot = r * x - y - x * z
z_dot = x * y - b * z
Expand Down
3 changes: 2 additions & 1 deletion docs/source/gallery/showcase/plots/menger_sponge_plot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import k3d
import numpy as np

import k3d


def generate():
def iterate(length, x, y, z):
Expand Down
165 changes: 83 additions & 82 deletions docs/source/gallery/showcase/plots/orbits_plot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import k3d
import numpy as np

import k3d
from k3d.colormaps import paraview_color_maps


Expand All @@ -9,90 +10,90 @@ def generate():

bodies_count = 40

bodies = np.array([[0.0000000e+00, 0.0000000e+00, 0.0000000e+00, 0.0000000e+00,
0.0000000e+00, 0.0000000e+00, 1.0000000e+06],
[-4.9679345e-01, 2.6570296e-01, 3.4227931e-01, -2.2651915e-02,
-2.5265724e-03, -9.3185175e-03, 6.3181415e+02],
[3.7021518e-02, -3.3532095e-01, -1.3006118e-01, 3.8169832e-03,
-1.7639263e-02, 1.7560443e-02, 1.2228839e+03],
[3.2473081e-01, -3.8958952e-01, 3.6065096e-01, -1.6591853e-02,
2.2979354e-02, 1.5027565e-02, 1.1379092e+03],
[1.9925886e-01, -4.3243438e-02, 2.3790616e-01, -2.4283929e-02,
2.2036737e-02, 1.5822455e-02, 7.3010986e+02],
[-4.4143024e-01, -7.1139961e-02, 1.7319494e-01, -1.1633939e-02,
5.0242455e-03, -5.0497951e-04, 6.7444598e+02],
[7.8688264e-02, -1.7087817e-01, -1.5081182e-01, -2.4320260e-03,
7.0646438e-03, -1.7999319e-02, 9.7800610e+02],
[-5.9594750e-02, -7.2615296e-02, 4.3256253e-01, -1.0310315e-02,
-1.0246425e-02, 1.0331392e-02, 5.5932916e+02],
[-2.2181371e-01, 1.2450159e-02, -3.5403877e-02, 2.4978900e-02,
-9.8985955e-03, -1.0434589e-02, 1.2175408e+03],
[2.1475327e-01, 4.1201133e-01, -3.1412601e-02, -1.1963538e-02,
1.0723472e-03, -3.5631433e-03, 1.1424460e+03],
[4.2195350e-01, 3.7973666e-01, -1.8134981e-02, -1.9921964e-02,
-7.1983635e-03, 7.6964349e-03, 1.4089318e+03],
[2.1617496e-01, -1.9794500e-01, -8.7558389e-02, -1.6835531e-02,
-1.5182316e-02, -1.3301859e-02, 5.5457037e+02],
[-4.1794181e-02, -1.9101912e-01, 1.8947464e-01, 1.4356637e-02,
-1.5364028e-02, 1.2453362e-02, 1.0287977e+03],
[2.2971267e-01, -2.8791130e-03, -2.1326435e-01, -7.8020454e-03,
2.5177689e-03, -9.7344117e-03, 1.0474579e+03],
[2.6785791e-02, 1.6838884e-01, 2.1399486e-01, 2.4175057e-02,
2.4402628e-02, -1.3445861e-02, 1.0599727e+03],
[3.1909162e-01, 3.1714398e-01, 2.0338118e-02, -2.4140883e-02,
1.5961260e-02, -2.0101408e-02, 9.4045221e+02],
[-3.3931443e-01, -2.2721624e-01, 9.7239554e-02, 3.6300363e-03,
-1.9278442e-02, 1.9151056e-02, 6.7030249e+02],
[6.6103995e-02, -4.8539740e-01, 1.7521322e-01, 1.8680961e-03,
9.0755373e-03, 1.3850155e-02, 9.4479297e+02],
[-1.6933033e-01, 5.7348192e-02, 2.0398575e-01, -1.0792896e-02,
-1.6141150e-02, 8.3085243e-03, 1.4722698e+03],
[3.5467851e-01, 2.5269783e-01, -4.7175428e-01, -2.1373475e-02,
4.0807934e-03, 2.4820814e-02, 8.4746240e+02],
[-2.7038407e-01, -4.8006400e-01, -3.2617545e-01, -2.1090398e-02,
1.7032122e-02, 1.7789362e-02, 6.2347046e+02],
[-4.8136929e-01, -3.3214843e-01, -1.8433192e-01, -8.0333194e-03,
-1.6524477e-02, 6.1281892e-03, 9.0508881e+02],
[5.4457009e-02, 1.7607331e-02, 6.7196190e-02, -1.7219210e-02,
1.9105632e-02, 2.4653585e-03, 5.7763861e+02],
[-1.3687915e-01, 8.4126353e-02, -1.3019252e-01, -1.8430030e-02,
2.0881360e-02, -2.4473562e-03, 5.5547150e+02],
[1.0026491e-01, 2.7884889e-01, -3.1183958e-03, 6.0113161e-03,
-1.4223135e-02, -1.8654644e-02, 5.5057245e+02],
[2.2953439e-01, -2.0373765e-01, 1.9156224e-01, -3.1318248e-03,
-2.5028258e-03, 8.5311802e-03, 6.9054175e+02],
[-4.9273950e-01, 2.5772792e-01, 4.5453101e-01, -1.1930334e-02,
-1.0238136e-02, 3.0950904e-03, 5.3005304e+02],
[3.5183370e-02, 4.1218692e-01, -3.8023493e-01, 1.6193924e-02,
8.6651091e-03, -5.8665574e-03, 8.8095959e+02],
[-3.0682594e-01, -1.1159393e-01, 3.8180280e-01, -1.8235832e-02,
2.0600855e-02, -5.5592731e-03, 1.2845226e+03],
[1.3181090e-01, -1.3926461e-01, 3.5556364e-01, 1.8209113e-02,
-7.5311526e-03, -2.0307558e-02, 9.4135608e+02],
[2.9862744e-01, 2.6593310e-01, 8.9805841e-02, 2.3497565e-02,
-2.3358732e-03, 6.1519952e-03, 6.3521173e+02],
[1.8002808e-02, -3.1908777e-01, -1.4509407e-01, 1.7548909e-02,
1.0903591e-02, -2.2118099e-02, 1.2389504e+03],
[-4.0650040e-02, -2.2764242e-01, -7.5831264e-02, -5.7892441e-03,
3.0585080e-03, -2.3829598e-02, 1.1236339e+03],
[-2.4570310e-01, 2.0286041e-01, 1.2090033e-01, -1.4608744e-02,
1.2567866e-02, -2.4784094e-02, 9.3537274e+02],
[3.9212245e-01, -1.8226206e-02, -3.4510234e-01, 2.7927459e-04,
-1.9444963e-02, 6.7013353e-03, 6.1505707e+02],
[-4.4596395e-01, -4.6554554e-01, -3.3184126e-01, 1.9790804e-02,
-2.9474200e-04, 1.0445378e-02, 6.7410992e+02],
[-4.7785598e-01, -4.4018179e-01, 3.1628680e-01, 3.2713532e-03,
1.2704453e-02, 1.4309299e-02, 7.2144165e+02],
[1.7605799e-01, 4.6154976e-01, 3.6913526e-01, -2.0895386e-02,
-2.3292074e-02, 4.9127610e-03, 6.6594043e+02],
[1.8955290e-02, -3.2265896e-01, 4.2756569e-01, -1.1221913e-02,
-2.0262299e-02, 1.1423305e-02, 9.2574188e+02],
[1.0150486e-01, -2.8043854e-01, -3.0282909e-01, 1.2297285e-02,
1.9709280e-02, 1.1570200e-02, 1.3365149e+03]]).astype(np.float32)
bodies = np.array([[0.0000000e+00, 0.0000000e+00, 0.0000000e+00, 0.0000000e+00,
0.0000000e+00, 0.0000000e+00, 1.0000000e+06],
[-4.9679345e-01, 2.6570296e-01, 3.4227931e-01, -2.2651915e-02,
-2.5265724e-03, -9.3185175e-03, 6.3181415e+02],
[3.7021518e-02, -3.3532095e-01, -1.3006118e-01, 3.8169832e-03,
-1.7639263e-02, 1.7560443e-02, 1.2228839e+03],
[3.2473081e-01, -3.8958952e-01, 3.6065096e-01, -1.6591853e-02,
2.2979354e-02, 1.5027565e-02, 1.1379092e+03],
[1.9925886e-01, -4.3243438e-02, 2.3790616e-01, -2.4283929e-02,
2.2036737e-02, 1.5822455e-02, 7.3010986e+02],
[-4.4143024e-01, -7.1139961e-02, 1.7319494e-01, -1.1633939e-02,
5.0242455e-03, -5.0497951e-04, 6.7444598e+02],
[7.8688264e-02, -1.7087817e-01, -1.5081182e-01, -2.4320260e-03,
7.0646438e-03, -1.7999319e-02, 9.7800610e+02],
[-5.9594750e-02, -7.2615296e-02, 4.3256253e-01, -1.0310315e-02,
-1.0246425e-02, 1.0331392e-02, 5.5932916e+02],
[-2.2181371e-01, 1.2450159e-02, -3.5403877e-02, 2.4978900e-02,
-9.8985955e-03, -1.0434589e-02, 1.2175408e+03],
[2.1475327e-01, 4.1201133e-01, -3.1412601e-02, -1.1963538e-02,
1.0723472e-03, -3.5631433e-03, 1.1424460e+03],
[4.2195350e-01, 3.7973666e-01, -1.8134981e-02, -1.9921964e-02,
-7.1983635e-03, 7.6964349e-03, 1.4089318e+03],
[2.1617496e-01, -1.9794500e-01, -8.7558389e-02, -1.6835531e-02,
-1.5182316e-02, -1.3301859e-02, 5.5457037e+02],
[-4.1794181e-02, -1.9101912e-01, 1.8947464e-01, 1.4356637e-02,
-1.5364028e-02, 1.2453362e-02, 1.0287977e+03],
[2.2971267e-01, -2.8791130e-03, -2.1326435e-01, -7.8020454e-03,
2.5177689e-03, -9.7344117e-03, 1.0474579e+03],
[2.6785791e-02, 1.6838884e-01, 2.1399486e-01, 2.4175057e-02,
2.4402628e-02, -1.3445861e-02, 1.0599727e+03],
[3.1909162e-01, 3.1714398e-01, 2.0338118e-02, -2.4140883e-02,
1.5961260e-02, -2.0101408e-02, 9.4045221e+02],
[-3.3931443e-01, -2.2721624e-01, 9.7239554e-02, 3.6300363e-03,
-1.9278442e-02, 1.9151056e-02, 6.7030249e+02],
[6.6103995e-02, -4.8539740e-01, 1.7521322e-01, 1.8680961e-03,
9.0755373e-03, 1.3850155e-02, 9.4479297e+02],
[-1.6933033e-01, 5.7348192e-02, 2.0398575e-01, -1.0792896e-02,
-1.6141150e-02, 8.3085243e-03, 1.4722698e+03],
[3.5467851e-01, 2.5269783e-01, -4.7175428e-01, -2.1373475e-02,
4.0807934e-03, 2.4820814e-02, 8.4746240e+02],
[-2.7038407e-01, -4.8006400e-01, -3.2617545e-01, -2.1090398e-02,
1.7032122e-02, 1.7789362e-02, 6.2347046e+02],
[-4.8136929e-01, -3.3214843e-01, -1.8433192e-01, -8.0333194e-03,
-1.6524477e-02, 6.1281892e-03, 9.0508881e+02],
[5.4457009e-02, 1.7607331e-02, 6.7196190e-02, -1.7219210e-02,
1.9105632e-02, 2.4653585e-03, 5.7763861e+02],
[-1.3687915e-01, 8.4126353e-02, -1.3019252e-01, -1.8430030e-02,
2.0881360e-02, -2.4473562e-03, 5.5547150e+02],
[1.0026491e-01, 2.7884889e-01, -3.1183958e-03, 6.0113161e-03,
-1.4223135e-02, -1.8654644e-02, 5.5057245e+02],
[2.2953439e-01, -2.0373765e-01, 1.9156224e-01, -3.1318248e-03,
-2.5028258e-03, 8.5311802e-03, 6.9054175e+02],
[-4.9273950e-01, 2.5772792e-01, 4.5453101e-01, -1.1930334e-02,
-1.0238136e-02, 3.0950904e-03, 5.3005304e+02],
[3.5183370e-02, 4.1218692e-01, -3.8023493e-01, 1.6193924e-02,
8.6651091e-03, -5.8665574e-03, 8.8095959e+02],
[-3.0682594e-01, -1.1159393e-01, 3.8180280e-01, -1.8235832e-02,
2.0600855e-02, -5.5592731e-03, 1.2845226e+03],
[1.3181090e-01, -1.3926461e-01, 3.5556364e-01, 1.8209113e-02,
-7.5311526e-03, -2.0307558e-02, 9.4135608e+02],
[2.9862744e-01, 2.6593310e-01, 8.9805841e-02, 2.3497565e-02,
-2.3358732e-03, 6.1519952e-03, 6.3521173e+02],
[1.8002808e-02, -3.1908777e-01, -1.4509407e-01, 1.7548909e-02,
1.0903591e-02, -2.2118099e-02, 1.2389504e+03],
[-4.0650040e-02, -2.2764242e-01, -7.5831264e-02, -5.7892441e-03,
3.0585080e-03, -2.3829598e-02, 1.1236339e+03],
[-2.4570310e-01, 2.0286041e-01, 1.2090033e-01, -1.4608744e-02,
1.2567866e-02, -2.4784094e-02, 9.3537274e+02],
[3.9212245e-01, -1.8226206e-02, -3.4510234e-01, 2.7927459e-04,
-1.9444963e-02, 6.7013353e-03, 6.1505707e+02],
[-4.4596395e-01, -4.6554554e-01, -3.3184126e-01, 1.9790804e-02,
-2.9474200e-04, 1.0445378e-02, 6.7410992e+02],
[-4.7785598e-01, -4.4018179e-01, 3.1628680e-01, 3.2713532e-03,
1.2704453e-02, 1.4309299e-02, 7.2144165e+02],
[1.7605799e-01, 4.6154976e-01, 3.6913526e-01, -2.0895386e-02,
-2.3292074e-02, 4.9127610e-03, 6.6594043e+02],
[1.8955290e-02, -3.2265896e-01, 4.2756569e-01, -1.1221913e-02,
-2.0262299e-02, 1.1423305e-02, 9.2574188e+02],
[1.0150486e-01, -2.8043854e-01, -3.0282909e-01, 1.2297285e-02,
1.9709280e-02, 1.1570200e-02, 1.3365149e+03]]).astype(np.float32)

for i in range(1, bodies_count):
bodies[i, 0:3] = (
bodies[i, 0:3] / np.linalg.norm(bodies[i, 0:3])) * 0.5
bodies[i, 0:3] / np.linalg.norm(bodies[i, 0:3])) * 0.5

points = k3d.points(bodies[:, 0:3],
point_size=0.03,
Expand Down
2 changes: 1 addition & 1 deletion docs/source/gallery/showcase/plots/point_cloud_plot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import os

import k3d
import numpy as np


def generate():
Expand Down
2 changes: 1 addition & 1 deletion docs/source/gallery/showcase/plots/segmentation_plot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import os

import k3d
import numpy as np


def generate():
Expand Down
5 changes: 2 additions & 3 deletions docs/source/gallery/showcase/plots/streamlines_plot.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import numpy as np
import os

import k3d
import numpy as np
from k3d import matplotlib_color_maps


def generate():
Expand All @@ -19,7 +18,7 @@ def generate():
plt_streamlines = k3d.line(lines,
width=0.00007,
attribute=v,
color_map=matplotlib_color_maps.Inferno,
color_map=k3d.matplotlib_color_maps.Inferno,
color_range=[0, 0.5],
shader='mesh')

Expand Down
11 changes: 4 additions & 7 deletions docs/source/gallery/showcase/plots/turbine_cfd_plot.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import numpy as np
import os
import pyvista as pv

import k3d
import numpy as np
import pyvista as pv
from k3d.colormaps import paraview_color_maps
from k3d.helpers import map_colors
from numpy.linalg import norm


def generate():
Expand All @@ -30,8 +27,8 @@ def generate():
plot += plt_vectors

plot.camera = [3.0792, 14.6017, -8.8171,
-0.9959, 0.5287, -0.2337,
1, 0, 0]
-0.9959, 0.5287, -0.2337,
1, 0, 0]

plot.snapshot_type = 'inline'
return plot.get_snapshot()
19 changes: 5 additions & 14 deletions docs/source/gallery/showcase/plots/vtk_cutter_plot.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import numpy as np
import os
import vtk

import k3d
import numpy as np
import vtk
from ipywidgets import FloatSlider, interact
from k3d.colormaps import paraview_color_maps
from vtk.util import numpy_support

numpy_support = vtk.util.numpy_support


def generate():
Expand Down Expand Up @@ -59,10 +58,8 @@ def get_mesh_data(poly_data, color_attribute=('Umag', 0.0, 0.1)):
if color_attribute is not None:
attribute = numpy_support.vtk_to_numpy(
poly_data.GetPointData().GetArray(color_attribute[0]))
color_range = color_attribute[1:3]
else:
attribute = []
color_range = []

vertices = numpy_support.vtk_to_numpy(poly_data.GetPoints().GetData())
indices = numpy_support.vtk_to_numpy(
Expand All @@ -72,12 +69,6 @@ def get_mesh_data(poly_data, color_attribute=('Umag', 0.0, 0.1)):
np.array(indices, np.uint32),
np.array(attribute, np.float32))

def clipping_plane_to_vtkPlane(clipping_plane):
vtk_n = -np.array(clipping_plane[:3])
vtk_o = clipping_plane[3] * vtk_n

return (vtk_o, vtk_n)

vtk_n = np.array([0., .3, 0.])
vtk_o = np.array([0.04984861, 20.03934663, 0.04888905])

Expand All @@ -89,7 +80,7 @@ def clipping_plane_to_vtkPlane(clipping_plane):
vtk_o, vtk_n
),
color_attribute=('Umag', 0.0, 0.32),
color_map=paraview_color_maps.Cool_to_Warm,
color_map=k3d.paraview_color_maps.Cool_to_Warm,
side='double')

plt_vtk.flat_shading = True
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import k3d
import numpy as np

import k3d
from k3d.colormaps import paraview_color_maps
from k3d.headless import k3d_remote, get_headless_driver


def generate():
def lorenz(x, y, z, s=10, r=28, b=8/3):
def lorenz(x, y, z, s=10, r=28, b=8 / 3):
x_dot = s * (y - x)
y_dot = r * x - y - x * z
z_dot = x * y - b * z
Expand Down Expand Up @@ -36,7 +37,7 @@ def lorenz(x, y, z, s=10, r=28, b=8/3):
label_color=0xf0f0f0,
grid_visible=False,
menu_visibility=False,
axes_helper = 0)
axes_helper=0)
plot += plt_line

plot.camera = [10.1646, -36.8108, -0.4144,
Expand Down
Loading

0 comments on commit fa53000

Please sign in to comment.