diff --git a/README.md b/README.md index 202ff55..b05ebe8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,63 @@ -# PhantomGaze -Simple GPU rendering of scientific data with Pytorch, Jax, CuPy, and Warp backends. +# PhantomGaze: A GPU-Accelerated Rendering Engine for Scientific Visualization + +## Introduction + +PhantomGaze is a Python package that provides a basic rendering engine optimized for scientific computing visualizations. Utilizing the power of Numba, it enables efficient operations directly on the GPU, enhancing the visualization of complex scientific data. This package is particularly useful for rendering volumetric data, geometric shapes, and contour visualizations with ease. + +## Features + +- GPU-accelerated rendering engine +- Volumetric rendering +- Geometric rendering +- Contour rendering +- Customizable color maps +- Integration with GPU libraries such as CuPy, JAX, PyTorch, and Warp. + +## Installation + +PhantomGaze can be installed using pip: + +```bash +pip install . +``` + +(TODO: Make package available on PyPI) + +## Usage + +There are several examples in the `examples` directory. A minimal example of a contour plot is shown below: + +```python +import cupy as cp +import matplotlib.pyplot as plt + +import phantomgaze as pg + +# Create SDF feild of a sphere using cupy +lin = cp.linspace(-1, 1, 256) +X, Y, Z = cp.meshgrid(lin, lin, lin, indexing="ij") +sphere = -(cp.sqrt(X**2 + Y**2 + Z**2) - 1.0) +sphere_volume = pg.objects.Volume( + sphere, spacing=(2 / 256, 2 / 256, 2 / 256), origin=(-1.0, -1.0, -1.0) +) +color_volume = pg.objects.Volume( + cp.sin(X * 2 * cp.pi) * cp.sin(Y * 2 * cp.pi) * cp.sin(Z * 2 * cp.pi), + spacing=(2 / 256, 2 / 256, 2 / 256), + origin=(-1.0, -1.0, -1.0), +) + +# Create camera object +camera = pg.Camera(position=(2.0, 1.0, -4.0), focal_point=(0.0, 0.0, 0.0), view_up=(0.0, 1.0, 0.0)) + +# Render the contour of the inner sphere +screen_buffer = pg.render.contour(sphere_volume, camera, threshold=0.0, color=color_volume) + +# Show the rendered image +plt.imshow(screen_buffer.image.get()) +plt.show() +``` + +This produces the following image: + +![Contour](https://github.com/loliverhennigh/PhantomGaze/assets/readme_example.png) + diff --git a/assets/axes.png b/assets/axes.png new file mode 100644 index 0000000..d417ebe Binary files /dev/null and b/assets/axes.png differ diff --git a/assets/geometry.png b/assets/geometry.png new file mode 100644 index 0000000..63ebb70 Binary files /dev/null and b/assets/geometry.png differ diff --git a/assets/readme_example.png b/assets/readme_example.png new file mode 100644 index 0000000..3414f0e Binary files /dev/null and b/assets/readme_example.png differ diff --git a/assets/sphere.png b/assets/sphere.png new file mode 100644 index 0000000..43dd09f Binary files /dev/null and b/assets/sphere.png differ diff --git a/assets/volume.png b/assets/volume.png new file mode 100644 index 0000000..2606a31 Binary files /dev/null and b/assets/volume.png differ diff --git a/examples/axes.py b/examples/axes.py index 32f2d1e..194ef1f 100644 --- a/examples/axes.py +++ b/examples/axes.py @@ -12,7 +12,7 @@ camera = pg.Camera(position=(0.0, 1.0, 6.69), focal_point=(0.0, 0.0, 0.0), view_up=(0.0, 1.0, 0.0)) # Render the axes - screen_buffer = pg.render.axes(size=1.0, center=(1.0, 0.0, 0.0), camera=camera) + screen_buffer = pg.render.axes(size=1.0, center=(0.0, 0.0, 0.0), camera=camera) # Plot the result plt.imshow(screen_buffer.image.get()) diff --git a/examples/volume.py b/examples/volume.py index e458bbd..8a82727 100644 --- a/examples/volume.py +++ b/examples/volume.py @@ -2,7 +2,6 @@ import cupy as cp import matplotlib.pyplot as plt -from tqdm import tqdm import phantomgaze as pg @@ -27,16 +26,6 @@ # Create screen buffer screen_buffer = pg.ScreenBuffer.from_camera(camera) - for _ in tqdm(range(100)): - # Render the axes - screen_buffer = pg.render.axes(size=0.1, center=(-1.5, -1.5, 1.0), camera=camera, screen_buffer=screen_buffer) - - # Render wireframe of the volume - screen_buffer = pg.render.wireframe(lower_bound=(-1.0, -1.0, -1.0), upper_bound=(1.0, 1.0, 1.0), thickness=2 / 256, camera=camera, screen_buffer=screen_buffer) - - # Render the volume plot - screen_buffer = pg.render.volume(sin_volume, camera, colormap=colormap, screen_buffer=screen_buffer) - # Render the axes screen_buffer = pg.render.axes(size=0.1, center=(-1.5, -1.5, 1.0), camera=camera)