Code Monkey home page Code Monkey logo

znvis's Introduction

PyTest code-style zincware

ZnVis

ZnVis is a visualisation engine for particle simulation data. Simply define the particles in the simulation with details including their positions, colour, direction, and shape, and the visualization engine will display the system using the Open3D engine. ZnVis works both from a Python script and in Jupyter!

ZnVis can currently perform the following tasks:

  • Visualize simulations and trajectories
  • Create spherical and cylindrical mesh's for visualization
  • Handle custom mesh objects
  • Export png stills from the visualizer
  • Export scences as .obj files.

Installation

ZnVis is a purely Python package hosted on PyPi. It can therefore be installed using pip with:

pip install znvis

If you prefer to access the source code, run the following from a terminal:

   git clone https://github.com/zincware/ZnVis.git
   cd ZnVis
   pip install .

Once complete, you will be able to start using the visualizer by importing it as:

import znvis

How does it work?

ZnVis is essentially a convenience wrapper of the Open3D project with a focus on mesh visualization. The idea came out of wanting a simple way of visualizing particle trajectories from numpy arrays directly from a simulation script.

Below we show an example script from a reinforcement learning experiment built using Shameless plug alert SwarmRL

import numpy as np
import h5py as hf

import znvis as vis

# Load data from the database
with hf.File("training/trajectory.hdf5", 'r') as db:
    positions = db["colloids"]["Unwrapped_Positions"][:]

# Split data for convenience
colloid_positions = positions[:, 0:10, :]
rod_positions = positions[:, 10:, :]

# Create free colloid mesh
colloid_mesh = vis.Sphere(radius=2.14, colour=np.array([30, 144, 255]) / 255, resolution=10)
colloid_particle = vis.Particle(name="Colloid", mesh=mesh, position=colloid_positions)

# Create rod colloid mesh
rod_mesh = vis.Sphere(radius=2.14, colour=np.array([255, 140, 0]) / 255, resolution=10)
rod_particle = vis.Particle(name="Rod", mesh=mesh, position=rod_positions)

# Run the visualizer
visualizer = vis.Visualizer(particles=[colloid_particle, rod_particle], frame_rate=80)
visualizer.run_visualization()

Just like that, a visualization window (shown below) will pop up from which you can play the trajectory and watch your RL agents rotate a rod.

Visualizer Example

znvis's People

Contributors

christophlohrmann avatar jpd-de avatar phohenberger avatar samtov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

znvis's Issues

New Scene handler

Re-write the scene handler with the Open3D primitives and allow support for web interfaces.

Export mesh objects

Just as one can export videos, allow users to export full mesh object scenes for rendering in a third party app such as Blender.

Particle Cache

It would be far more reasonable to have a cache of rendered mesh objects of N time steps rather than having all of them in memory at all times.

Linux App bug

On linux machines the app window opens during mesh loading leading to unresponsive app warnings.

Recorder trajectory

It would be nice to have automatic trajectories for the video recording. The following two options come to mind:

  1. Provide a degrees per second rotation speed and rotate about the z-axis at that speed. This requires multiplying the to_world or Open3D view_matrix by a rotation matrix each frame.
  2. Run the visualizer in a record_camera mode where while the trajectory is running at normal speed, the view_matrix at each frame is stored. After the trajectory completes, the rendering begins using the recorded matrices. This would allow for a very customized trajectory with a much greater speed.

In both cases, we need to add either a rendering class with additional options or implement a UI component just for rendering in the sidebar. Both possible, but I am happy for now with the API approach. It could look like this:

rendering = vis.Mitsuba(rotation_speed=0.1, from_trajectory=True, denoising=True, ...)

This would also allow for different engines to be selected such as https://plotoptix.rnd.team/ for example.

Support for PyVista meshes

It would be great to see support for PyVista mesh objects and maybe for more libraries in the future. It would provide greater flexibility for API generated Meshes.

Biggest challenge will be converting the data.

Move to the tensor data type of open3d

We should move away from simple TriangleMesh objects towards the tensor datatype. The issue is that some of the functionality will be reduced, such as smoothing. This also requires a re-write of the mesh creation as += is not supported. There may also be issues with memory due to constant duplication of objects.

Jupyter support

It seems that jupyter support here is possible. It looks like all of the apps would need to be written in two forms, one for Jupyter and one for the gui.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.