Skip to content

Commit f69e0c5

Browse files
authored
Merge pull request #45 from rnd-team-dev/r0.16.0
R0.16.0
2 parents d00768f + 91463fe commit f69e0c5

26 files changed

+782
-106
lines changed

CHANGELOG.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
Release history
22
===============
33

4+
`v0.16.0` - 2023-05-17
5+
----------------------
6+
7+
Added
8+
~~~~~
9+
10+
- set texture data from pytorch tensors
11+
- texture filter modes enabled, default is *trilinear*, optionally can be changed to *nearest*
12+
13+
- set geometry data directly from numpy array or pytorch tensor (no host copy is mada)
14+
- synchronization method to update host copy with data from gpu: NpOptiX.sync_raw_data()
15+
16+
- convenience method to get a copy of geometry data (more simple than PinnedBuffer, though returns a copy): NpOptiX.get_data()
17+
418
`v0.15.1` - 2023-03-16
519
----------------------
620

@@ -568,6 +582,7 @@ Added
568582
- this changelog, markdown description content type tag for PyPI
569583
- use [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
570584

585+
.. _`v0.16.0`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.16.0
571586
.. _`v0.15.1`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.15.1
572587
.. _`v0.15.0`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.15.0
573588
.. _`v0.14.4`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.14.4

README.rst

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ PlotOptiX
1515

1616
`Docs <https://plotoptix.rnd.team>`__
1717

18-
- Check what we are doing with PlotOptiX on `Behance <https://www.behance.net/RnDTeam>`__, `Facebook <https://www.facebook.com/rndteam>`__, and `Instagram <https://www.instagram.com/rnd.team.studio/>`__.
18+
- Have a look what is possible with PlotOptiX: `Behance <https://www.behance.net/RnDTeam>`__, `Instagram <https://www.instagram.com/rnd.team.studio/>`__, and `Facebook <https://www.facebook.com/rndteam>`__.
1919
- Join us on `Patreon <https://www.patreon.com/rndteam?fan_landing=true>`__ for news, release plans and hi-res content.
2020

2121
PlotOptiX is a 3D `ray tracing <https://en.wikipedia.org/wiki/Ray_tracing_(graphics)>`__ package for Python, aimed at easy and aesthetic visualization
2222
of large datasets (and small as well). Data features can be represented in images as a position, size/thickness and color of primitives
2323
of several basic shapes, or projected onto surfaces of objects in form of a color textures and displacement maps. Triangular meshes,
24-
generated in the code or loaded from a file, are supported as well. All is finished with a photorealistic lighting, depth of field, and many other physically based effects simulated with a high quality.
24+
generated in the code or loaded from a file, are supported as well. All is finished with a photorealistic lighting, depth of field, and many other
25+
physically based effects simulated with a high quality.
2526

2627
No need to write shaders, intersection algorithms, handle 3D scene technicalities. Basic usage is even more simple than with
2728
`matplotlib <https://matplotlib.org/gallery/mplot3d/scatter3d.html>`__:
@@ -65,8 +66,9 @@ Features
6566
- *light sources*: spherical and parallelogram, light emission in volumes, uniform environmental light or environment map
6667
- *post-processing*: tonal correction curves, levels adjustment, apply mask/overlay, AI denoiser and upsampler
6768
- *callbacks*: at the scene initialization, start and end of each frame raytracing, end of progressive accumulation
68-
- 8/16/32bps(hdr) image output to `numpy <http://www.numpy.org>`__ array, or save to popular image file formats
69+
- 8/16/32bps(hdr) image output to `numpy <https://numpy.org>`__ array, or save to popular image file formats
6970
- zero-copy access to GPU buffers wrapped in ndarrays: 8/32bpc image, hit and object info, albedo, normals
71+
- direct access to `PyTorch <https://pytorch.org>`__ tensors data stored on GPU (and CPU as well) for texture and geometry updates
7072
- GPU acceleration using RT Cores and everything else what comes with `OptiX <https://developer.nvidia.com/optix>`__
7173
- hardware accelerated video output to MP4 file format using `NVENC 9.0 <https://developer.nvidia.com/nvidia-video-codec-sdk>`__
7274
- Tkinter based simple GUI window or a headless raytracer
@@ -95,7 +97,7 @@ What's Included
9597
Installation
9698
============
9799

98-
**Note**, at this point, PlotOptiX binaries are tested in: Windows 10/11 (any Python 3), and Linux (Python 3.8 recommended): Ubuntu 18.04, CentOS 7.
100+
**Note**, at this point, PlotOptiX binaries are tested in: Windows 10/11 (any Python 3), and Linux (Python 3.8-3.10 recommended): Ubuntu 18.04, CentOS 7.
99101

100102
PlotOptiX was also successfully tested on the `Google Cloud Platform <https://cloud.google.com/>`__, using Compute Engine instance with 2x V100 GPU's and Ubuntu 18.04 image.
101103
Here are the `installation steps <https://github.com/rnd-team-dev/plotoptix/blob/master/gcp_install_gpu.txt>`__ so you can save some precious seconds (FFmpeg not included).
@@ -107,15 +109,7 @@ Windows prerequisites
107109

108110
*.NET Framework:*
109111

110-
Most likely you already got the right version with your Windows installation. Just in case of doubts, here is the command verifying this::
111-
112-
C:\>reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\full" /v version
113-
114-
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\full
115-
version REG_SZ 4.8.04084
116-
117-
If the number in your output is < 4.8, visit `download page <https://dotnet.microsoft.com/download/dotnet-framework>`__ and
118-
install the most recent release.
112+
You have it built in your Windows. Go ahead and install PlotOptiX.
119113

120114
Linux prerequisites
121115
-------------------
@@ -191,21 +185,14 @@ Then, try running code from the top of this readme, or one of the examples. You
191185
Development path
192186
================
193187

194-
This is still an early version. There are some important features not available yet, eg. ticks and labels on plot axes.
188+
This is still an experimental version in many aspects.
195189

196190
PlotOptiX is basically an interface to RnD.SharpOptiX library which we are developing and using in our Studio. RnD.SharpOptiX offers
197-
much more functionality than it is now available through PlotOptiX. We'll progressively add more to PlotOptiX if there is interest in
198-
this project (download, star, and `become our Patron <https://www.patreon.com/rndteam>`__
199-
if you like it!).
200-
201-
The idea for development is:
202-
203-
1. Binaries for Linux (done in v0.3.0).
204-
2. Migrate to OptiX 7.0 (done in v0.7.0).
205-
3. Complete the plot layout / cover more raytracing features.
206-
4. Convenience functions for various plot styles. Other GUI's.
191+
much more functionality than it is now available through PlotOptiX. We progressively add more to PlotOptiX based mostly on the interest
192+
of our patrons and applications that this project supports.
207193

208-
*Here, the community input is possible and warmly welcome!*
194+
Download, star, and `become our Patron <https://www.patreon.com/rndteam>`__ if you like the project. Get in touch, share your use case,
195+
we are always happy to help and take part in exciting ideas of our users.
209196

210197
Examples
211198
========

docs/npoptix.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ basic rules are:
2525
.. image:: images/flow_1.png
2626
:alt: PlotOptiX compute flow
2727

28-
Fig. 1. PlotOptiX computations flow. Details of the OptiX tast are ommited for clarity (i.e. scene compilation and multi-gpu management).
28+
Fig. 1. PlotOptiX computations flow. Details of the OptiX task are ommited for clarity (i.e. scene compilation and multi-gpu management).
2929

3030
.. image:: images/flow_2.png
3131
:alt: PlotOptiX compute flow

docs/npoptix_geometry.rst

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
Plot geometry
2-
=============
1+
Geometry
2+
========
33

44
Create, load, update, and remove a plot
55
---------------------------------------
66

77
.. automethod:: plotoptix.NpOptiX.get_geometry_names
8+
.. automethod:: plotoptix.NpOptiX.get_data
89
.. automethod:: plotoptix.NpOptiX.set_data
910
.. automethod:: plotoptix.NpOptiX.update_data
1011
.. automethod:: plotoptix.NpOptiX.set_data_2d
@@ -19,10 +20,17 @@ Create, load, update, and remove a plot
1920
.. automethod:: plotoptix.NpOptiX.load_displacement
2021
.. automethod:: plotoptix.NpOptiX.delete_geometry
2122

22-
Direct modifications of data
23-
----------------------------
23+
Direct access and modifications of data
24+
---------------------------------------
25+
26+
**Fast updates:**
27+
28+
.. automethod:: plotoptix.NpOptiX.update_raw_data
29+
.. automethod:: plotoptix.NpOptiX.sync_raw_data
30+
31+
**Geometry modifications:**
2432

25-
These methods allow making changes to properties of data points
33+
Following methods allow making changes to properties of data points
2634
stored internally in the raytracer, without re-sending whole data
2735
arrays from the Python code.
2836

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""
2+
Pytorch texture source - game of life.
3+
"""
4+
5+
import torch
6+
import torch.nn.functional as F
7+
8+
from plotoptix import TkOptiX
9+
from plotoptix.materials import m_flat
10+
11+
12+
class params():
13+
if torch.cuda.is_available:
14+
device = torch.device('cuda')
15+
dtype = torch.float16
16+
else:
17+
device = torch.device('cpu')
18+
dtype = torch.float32
19+
w = torch.tensor(
20+
[[[[1.0,1.0,1.0], [1.0,0.0,1.0], [1.0,1.0,1.0]]]],
21+
dtype=dtype, device=device, requires_grad=False
22+
)
23+
cells = torch.rand((1,1,128,128), dtype=dtype, device=device, requires_grad=False)
24+
cells[cells > 0.995] = 1.0
25+
cells[cells < 1.0] = 0.0
26+
tex2D = torch.unsqueeze(cells[0, 0].type(torch.float32), -1).expand(-1, -1, 4).contiguous()
27+
28+
29+
# Update texture data with a simple "game of life" rules.
30+
def compute(rt, delta):
31+
params.cells = F.conv2d(params.cells, weight=params.w, stride=1, padding=1)
32+
params.cells[params.cells < 2.0] = 0.0
33+
params.cells[params.cells > 3.0] = 0.0
34+
params.cells[params.cells != 0.0] = 1.0
35+
36+
# Conversion to float32 and to contiguous memoty layout is ensured by plotoptix,
37+
# though you may wamt to make it explicit like here, eg for performance reasons.
38+
params.tex2D = torch.unsqueeze(params.cells[0, 0].type(torch.float32), -1).expand(-1, -1, 4).contiguous()
39+
40+
41+
# Copy texture data to plotoptix scene.
42+
def update_data(rt):
43+
rt.set_torch_texture_2d("tex2d", params.tex2D, refresh=True)
44+
45+
46+
def main():
47+
rt = TkOptiX(
48+
on_scene_compute=compute,
49+
on_rt_completed=update_data
50+
)
51+
rt.set_param(min_accumulation_step=1)
52+
rt.set_background(0)
53+
rt.set_ambient(0)
54+
55+
# NOTE: pytorch features are not enabled by default. You need
56+
# to call this method before using anything related to pytorch.
57+
rt.enable_torch()
58+
59+
rt.set_torch_texture_2d("tex2d", params.tex2D, addr_mode="Clamp", filter_mode="Nearest")
60+
m_flat["ColorTextures"] = [ "tex2d" ]
61+
rt.setup_material("flat", m_flat)
62+
63+
rt.setup_camera("cam1", eye=[0, 0, 3], target=[0, 0, 0], fov=35, glock=True)
64+
65+
rt.set_data("plane", geom="Parallelograms", mat="flat",
66+
pos=[-1, -1, 0], u=[2, 0, 0], v=[0, 2, 0], c=0.9
67+
)
68+
69+
rt.start()
70+
71+
if __name__ == '__main__':
72+
main()
73+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
Direct update of geometry data on device.
3+
4+
This example uses numpy arrays, but pytorch tensors are supported as well,
5+
just note that rt.enable_torch() call is required before using pytorch.
6+
"""
7+
8+
import numpy as np
9+
10+
from plotoptix import TkOptiX
11+
from plotoptix.utils import simplex
12+
13+
14+
class params():
15+
n = 100
16+
rx = (-20, 20)
17+
r = 0.85 * 0.5 * (rx[1] - rx[0]) / (n - 1)
18+
19+
x = np.linspace(rx[0], rx[1], n)
20+
z = np.linspace(rx[0], rx[1], n)
21+
X, Z = np.meshgrid(x, z)
22+
23+
data = np.stack([X.flatten(), np.zeros(n*n), Z.flatten()], axis=1)
24+
t = 0
25+
26+
# Compute updated geometry data.
27+
def compute(rt, delta):
28+
row = np.ones((params.data.shape[0], 1))
29+
xn = simplex(np.concatenate([params.data, params.t * row], axis=1))
30+
yn = simplex(np.concatenate([params.data, (params.t + 20) * row], axis=1))
31+
zn = simplex(np.concatenate([params.data, (params.t - 20) * row], axis=1))
32+
dv = np.stack([xn, yn, zn], axis=1)
33+
params.data += 0.02 * dv
34+
params.t += 0.05
35+
36+
# Fast copy to geometry buffer on device, without making a host copy.
37+
def update_data(rt):
38+
rt.update_raw_data("balls", pos=params.data)
39+
40+
41+
def main():
42+
rt = TkOptiX(
43+
on_scene_compute=compute,
44+
on_rt_completed=update_data
45+
)
46+
rt.set_param(min_accumulation_step=10, max_accumulation_frames=16)
47+
rt.set_background(0)
48+
rt.set_ambient(0)
49+
50+
rt.setup_camera("cam1", cam_type="ThinLens", eye=[3.5, 1.27, 3.5], target=[0, 0, 0], fov=30, glock=True)
51+
rt.setup_light("light1", pos=[4, 5, 5], color=18, radius=1.0)
52+
53+
exposure = 1.0; gamma = 2.2
54+
rt.set_float("tonemap_exposure", exposure)
55+
rt.set_float("tonemap_gamma", gamma)
56+
rt.add_postproc("Gamma")
57+
58+
rt.set_data("balls", pos=params.data, c=0.82, r=params.r)
59+
60+
rt.start()
61+
62+
if __name__ == '__main__':
63+
main()
64+

plotoptix/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
__author__ = "Robert Sulej, R&D Team <dev@rnd.team>"
1414
__status__ = "beta"
15-
__version__ = "0.15.1"
16-
__date__ = "16 March 2023"
15+
__version__ = "0.16.0"
16+
__date__ = "17 May 2023"
1717

1818
import logging
1919

0 commit comments

Comments
 (0)