diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ef21e88..4d746cc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ fail_fast: true repos: - repo: https://github.com/psf/black - rev: 24.4.2 + rev: 24.8.0 hooks: - id: black @@ -14,7 +14,7 @@ repos: - id: isort - repo: https://github.com/PyCQA/flake8 - rev: 7.1.0 + rev: 7.1.1 hooks: - id: flake8 additional_dependencies: [flake8-isort] diff --git a/examples/all_shapes.py b/examples/all_shapes.py index a5dbf6d..ba65e70 100644 --- a/examples/all_shapes.py +++ b/examples/all_shapes.py @@ -39,11 +39,9 @@ material_2 = vis.Material(colour=np.array([255, 140, 0]) / 255, alpha=1.0) # Define the cylinder. trajectory_2 = np.random.uniform(-10, 10, (10, 1, 3)) - mesh_2 = vis.Cylinder(radius=1.0, - height=2.0, - split=1, - material=material_2, - resolution=30) + mesh_2 = vis.Cylinder( + radius=1.0, height=2.0, split=1, material=material_2, resolution=30 + ) particle_2 = vis.Particle(name="Cylinder", mesh=mesh_2, position=trajectory_2) material_3 = vis.Material(colour=np.array([100, 255, 130]) / 255, alpha=1.0) @@ -55,23 +53,28 @@ material_4 = vis.Material(colour=np.array([255, 200, 50]) / 255, alpha=1.0) # Define the torus. trajectory_4 = np.random.uniform(-10, 10, (10, 1, 3)) - mesh_4 = vis.Torus(torus_radius=1.0, - tube_radius=0.5, - tubular_resolution=30, - radial_resolution=30, - material=material_4) + mesh_4 = vis.Torus( + torus_radius=1.0, + tube_radius=0.5, + tubular_resolution=30, + radial_resolution=30, + material=material_4, + ) particle_4 = vis.Particle(name="Torus", mesh=mesh_4, position=trajectory_4) material_5 = vis.Material(colour=np.array([250, 50, 20]) / 255, alpha=1.0) # Define the mobius loop. trajectory_5 = np.random.uniform(-10, 10, (10, 1, 3)) - mesh_5 = vis.MobiusLoop(twists=3, - radius=2, - flatness=1, - width=2, scale=1, - length_split=200, - width_split=200, - material=material_5) + mesh_5 = vis.MobiusLoop( + twists=3, + radius=2, + flatness=1, + width=2, + scale=1, + length_split=200, + width_split=200, + material=material_5, + ) particle_5 = vis.Particle(name="MobiusLoop", mesh=mesh_5, position=trajectory_5) material_6 = vis.Material(colour=np.array([255, 90, 255]) / 255, alpha=1.0) @@ -91,10 +94,9 @@ trajectory_8 = np.random.uniform(-10, 10, (10, 1, 3)) direction_8 = np.random.uniform(-1, 1, (10, 1, 3)) mesh_8 = vis.Arrow(scale=2, material=material_8, resolution=30) - particle_8 = vis.Particle(name="Arrow", - mesh=mesh_8, - position=trajectory_8, - director=direction_8) + particle_8 = vis.Particle( + name="Arrow", mesh=mesh_8, position=trajectory_8, director=direction_8 + ) material_9 = vis.Material(colour=np.array([150, 255, 230]) / 255, alpha=1.0) # Define the box. @@ -108,8 +110,18 @@ mesh_10 = vis.Cone(radius=1.0, height=2.0, material=material_10, resolution=30) particle_10 = vis.Particle(name="Cone", mesh=mesh_10, position=trajectory_10) - particle_list = [particle, particle_2, particle_3, particle_4, particle_5, - particle_6, particle_7, particle_8, particle_9, particle_10] + particle_list = [ + particle, + particle_2, + particle_3, + particle_4, + particle_5, + particle_6, + particle_7, + particle_8, + particle_9, + particle_10, + ] # Create a bounding box bounding_box = vis.BoundingBox( @@ -120,4 +132,4 @@ visualizer = vis.Visualizer( particles=particle_list, frame_rate=20, bounding_box=bounding_box ) - visualizer.run_visualization() \ No newline at end of file + visualizer.run_visualization() diff --git a/examples/simple_vector_field.py b/examples/simple_vector_field.py index e473ac3..a120dad 100644 --- a/examples/simple_vector_field.py +++ b/examples/simple_vector_field.py @@ -45,12 +45,11 @@ directions = np.random.uniform(-1, 1, (100, 441, 3)) # confine the directions to be in the z = 0 plane - directions[:,:,2] = 0 + directions[:, :, 2] = 0 - vector_field = vis.VectorField(name="VectorField", - mesh=mesh, - position=grid, - direction=directions) + vector_field = vis.VectorField( + name="VectorField", mesh=mesh, position=grid, direction=directions + ) # Define particles material_2 = vis.Material(colour=np.array([255, 140, 0]) / 255, alpha=1.0) @@ -58,15 +57,14 @@ trajectory_2 = np.random.uniform(-10, 10, (100, 1, 3)) # confine the particles to be in the z = 0 plane - trajectory_2[:,:,2] = 0 + trajectory_2[:, :, 2] = 0 - particle = vis.Particle(name="Spheres", - mesh=mesh_2, - position=trajectory_2, - smoothing=False) + particle = vis.Particle( + name="Spheres", mesh=mesh_2, position=trajectory_2, smoothing=False + ) # Construct the visualizer and run - visualizer = vis.Visualizer(particles=[particle], - vector_field=[vector_field], - frame_rate=20) - visualizer.run_visualization() \ No newline at end of file + visualizer = vis.Visualizer( + particles=[particle], vector_field=[vector_field], frame_rate=20 + ) + visualizer.run_visualization() diff --git a/znvis/__init__.py b/znvis/__init__.py index 71277c7..463e7cd 100644 --- a/znvis/__init__.py +++ b/znvis/__init__.py @@ -26,17 +26,16 @@ from znvis.bounding_objects.bounding_box import BoundingBox from znvis.material.material import Material from znvis.mesh.arrow import Arrow +from znvis.mesh.box import Box +from znvis.mesh.cone import Cone from znvis.mesh.custom import CustomMesh from znvis.mesh.cylinder import Cylinder +from znvis.mesh.icosahedron import Icosahedron +from znvis.mesh.mobius_loop import MobiusLoop +from znvis.mesh.octahedron import Octahedron from znvis.mesh.sphere import Sphere -from znvis.mesh.arrow import Arrow -from znvis.mesh.box import Box -from znvis.mesh.cone import Cone from znvis.mesh.tetrahedron import Tetrahedron -from znvis.mesh.octahedron import Octahedron -from znvis.mesh.icosahedron import Icosahedron from znvis.mesh.torus import Torus -from znvis.mesh.mobius_loop import MobiusLoop from znvis.particle.particle import Particle from znvis.particle.vector_field import VectorField from znvis.visualizer.visualizer import Visualizer diff --git a/znvis/mesh/arrow.py b/znvis/mesh/arrow.py index 1da26ff..87b7f8c 100644 --- a/znvis/mesh/arrow.py +++ b/znvis/mesh/arrow.py @@ -76,9 +76,9 @@ def create_mesh(self, direction: np.ndarray) -> o3d.geometry.TriangleMesh: cone_height = 0.15 * direction_length * self.scale return o3d.geometry.TriangleMesh.create_arrow( - cylinder_radius=cylinder_radius, - cylinder_height=cylinder_height, - cone_radius=cone_radius, + cylinder_radius=cylinder_radius, + cylinder_height=cylinder_height, + cone_radius=cone_radius, cone_height=cone_height, resolution=self.resolution, ) diff --git a/znvis/mesh/box.py b/znvis/mesh/box.py index dc8a252..d68280a 100644 --- a/znvis/mesh/box.py +++ b/znvis/mesh/box.py @@ -26,11 +26,8 @@ from dataclasses import dataclass -import numpy as np import open3d as o3d -from znvis.transformations.rotation_matrices import rotation_matrix - from znvis.mesh import Mesh @@ -46,7 +43,7 @@ class Box(Mesh): height : float Height of the box. depth : float - Depth of the box. + Depth of the box. """ width: float = 1.0 @@ -56,8 +53,5 @@ class Box(Mesh): def create_mesh(self) -> o3d.geometry.TriangleMesh: return o3d.geometry.TriangleMesh.create_box( - width=self.width, - height=self.height, - depth=self.depth + width=self.width, height=self.height, depth=self.depth ) - diff --git a/znvis/mesh/cone.py b/znvis/mesh/cone.py index 241f810..2f295c2 100644 --- a/znvis/mesh/cone.py +++ b/znvis/mesh/cone.py @@ -26,11 +26,8 @@ from dataclasses import dataclass -import numpy as np import open3d as o3d -from znvis.transformations.rotation_matrices import rotation_matrix - from znvis.mesh import Mesh @@ -64,4 +61,3 @@ def create_mesh(self) -> o3d.geometry.TriangleMesh: resolution=self.resolution, split=self.split, ) - diff --git a/znvis/mesh/custom.py b/znvis/mesh/custom.py index 826c8af..7d847b3 100644 --- a/znvis/mesh/custom.py +++ b/znvis/mesh/custom.py @@ -29,9 +29,8 @@ import numpy as np import open3d as o3d -from znvis.transformations.rotation_matrices import rotation_matrix - from znvis.mesh import Mesh +from znvis.transformations.rotation_matrices import rotation_matrix @dataclass diff --git a/znvis/mesh/cylinder.py b/znvis/mesh/cylinder.py index 34b77ea..cfc5591 100644 --- a/znvis/mesh/cylinder.py +++ b/znvis/mesh/cylinder.py @@ -26,11 +26,8 @@ from dataclasses import dataclass -import numpy as np import open3d as o3d -from znvis.transformations.rotation_matrices import rotation_matrix - from znvis.mesh import Mesh @@ -57,11 +54,10 @@ class Cylinder(Mesh): resolution: int = 10 def create_mesh(self) -> o3d.geometry.TriangleMesh: - + return o3d.geometry.TriangleMesh.create_cylinder( radius=self.radius, height=self.height, split=self.split, resolution=self.resolution, ) - diff --git a/znvis/mesh/icosahedron.py b/znvis/mesh/icosahedron.py index 2c7f5d6..12ffa76 100644 --- a/znvis/mesh/icosahedron.py +++ b/znvis/mesh/icosahedron.py @@ -26,11 +26,8 @@ from dataclasses import dataclass -import numpy as np import open3d as o3d -from znvis.transformations.rotation_matrices import rotation_matrix - from znvis.mesh import Mesh @@ -49,7 +46,4 @@ class Icosahedron(Mesh): def create_mesh(self) -> o3d.geometry.TriangleMesh: - return o3d.geometry.TriangleMesh.create_icosahedron( - radius=self.radius - ) - + return o3d.geometry.TriangleMesh.create_icosahedron(radius=self.radius) diff --git a/znvis/mesh/mobius_loop.py b/znvis/mesh/mobius_loop.py index a4ea238..2cc6eea 100644 --- a/znvis/mesh/mobius_loop.py +++ b/znvis/mesh/mobius_loop.py @@ -26,11 +26,8 @@ from dataclasses import dataclass -import numpy as np import open3d as o3d -from znvis.transformations.rotation_matrices import rotation_matrix - from znvis.mesh import Mesh @@ -71,7 +68,7 @@ def create_mesh(self) -> o3d.geometry.TriangleMesh: length_split=self.length_split, width_split=self.width_split, twists=self.twists, - raidus=self.radius, # typo in open3d + raidus=self.radius, # typo in open3d flatness=self.flatness, width=self.width, scale=self.scale, diff --git a/znvis/mesh/octahedron.py b/znvis/mesh/octahedron.py index 6abc8ae..df1ea5a 100644 --- a/znvis/mesh/octahedron.py +++ b/znvis/mesh/octahedron.py @@ -26,11 +26,8 @@ from dataclasses import dataclass -import numpy as np import open3d as o3d -from znvis.transformations.rotation_matrices import rotation_matrix - from znvis.mesh import Mesh @@ -48,8 +45,5 @@ class Octahedron(Mesh): radius: float = 1.0 def create_mesh(self) -> o3d.geometry.TriangleMesh: - - return o3d.geometry.TriangleMesh.create_octahedron( - radius=self.radius - ) + return o3d.geometry.TriangleMesh.create_octahedron(radius=self.radius) diff --git a/znvis/mesh/sphere.py b/znvis/mesh/sphere.py index a1fda80..3a33f5a 100644 --- a/znvis/mesh/sphere.py +++ b/znvis/mesh/sphere.py @@ -23,11 +23,8 @@ from dataclasses import dataclass -import numpy as np import open3d as o3d -from znvis.transformations.rotation_matrices import rotation_matrix - from znvis.mesh import Mesh @@ -48,7 +45,7 @@ class Sphere(Mesh): resolution: int = 10 def create_mesh(self) -> o3d.geometry.TriangleMesh: - + return o3d.geometry.TriangleMesh.create_sphere( radius=self.radius, resolution=self.resolution ) diff --git a/znvis/mesh/tetrahedron.py b/znvis/mesh/tetrahedron.py index 4f9ff5b..56874e6 100644 --- a/znvis/mesh/tetrahedron.py +++ b/znvis/mesh/tetrahedron.py @@ -26,11 +26,8 @@ from dataclasses import dataclass -import numpy as np import open3d as o3d -from znvis.transformations.rotation_matrices import rotation_matrix - from .mesh import Mesh @@ -49,6 +46,4 @@ class Tetrahedron(Mesh): def create_mesh(self) -> o3d.geometry.TriangleMesh: - return o3d.geometry.TriangleMesh.create_tetrahedron( - radius=self.radius - ) + return o3d.geometry.TriangleMesh.create_tetrahedron(radius=self.radius) diff --git a/znvis/mesh/torus.py b/znvis/mesh/torus.py index 71ecb1b..a7a31a3 100644 --- a/znvis/mesh/torus.py +++ b/znvis/mesh/torus.py @@ -26,11 +26,8 @@ from dataclasses import dataclass -import numpy as np import open3d as o3d -from znvis.transformations.rotation_matrices import rotation_matrix - from znvis.mesh import Mesh @@ -46,7 +43,7 @@ class Torus(Mesh): tube_radius : float The radius of the torus tube. tubular_resolution : int - The number of segments along the tubular direction. + The number of segments along the tubular direction. radial_resolution : int The number of segments along the radial direction. """ @@ -64,4 +61,3 @@ def create_mesh(self) -> o3d.geometry.TriangleMesh: tubular_resolution=self.tubular_resolution, radial_resolution=self.radial_resolution, ) - diff --git a/znvis/particle/particle.py b/znvis/particle/particle.py index 719073d..2fa1e97 100644 --- a/znvis/particle/particle.py +++ b/znvis/particle/particle.py @@ -53,8 +53,8 @@ class Particle: A list of mesh objects, one for each time step. static : bool (default=False) If true, only render the mesh once at initialization. Be careful - as this changes the shape of the required position and director - to (n_particles, n_dims) + as this changes the shape of the required position and director + to (n_particles, n_dims) smoothing : bool (default=False) If true, apply smoothing to each mesh object as it is rendered. @@ -114,7 +114,7 @@ def construct_mesh_list(self): """ self.mesh_list = [] try: - if not self.static: + if not self.static: n_particles = int(self.position.shape[1]) n_time_steps = int(self.position.shape[0]) else: diff --git a/znvis/particle/vector_field.py b/znvis/particle/vector_field.py index c47dba0..a5f746f 100644 --- a/znvis/particle/vector_field.py +++ b/znvis/particle/vector_field.py @@ -49,8 +49,8 @@ class VectorField: A list of mesh objects, one for each time step. static : bool (default=False) If true, only render the mesh once at initialization. Be careful - as this changes the shape of the required position and direction - to (n_particles, n_dims) + as this changes the shape of the required position and direction + to (n_particles, n_dims) smoothing : bool (default=False) If true, apply smoothing to each mesh object as it is rendered. This will slow down the initial construction of the mesh objects @@ -108,7 +108,7 @@ def construct_mesh_list(self): """ self.mesh_list = [] try: - if not self.static: + if not self.static: n_particles = int(self.position.shape[1]) n_time_steps = int(self.position.shape[0]) else: diff --git a/znvis/visualizer/visualizer.py b/znvis/visualizer/visualizer.py index cf0785d..dcfdb2b 100644 --- a/znvis/visualizer/visualizer.py +++ b/znvis/visualizer/visualizer.py @@ -105,7 +105,7 @@ def __init__( for particle in particles: if not particle.static: len_list.append(len(particle.position)) - + if len_list == []: self.number_of_steps = 1 else: @@ -306,29 +306,29 @@ def _take_screenshot(self, vis): old_state = self.interrupt # get old state self.interrupt = 0 # stop live feed if running. mesh_dict = {} - + if self.vector_field is not None: for item in self.vector_field: if item.static: mesh_dict[item.name] = { - "mesh": item.mesh_list[0], - "bsdf": item.mesh.material.mitsuba_bsdf, - "material": item.mesh.o3d_material, - } + "mesh": item.mesh_list[0], + "bsdf": item.mesh.material.mitsuba_bsdf, + "material": item.mesh.o3d_material, + } else: mesh_dict[item.name] = { "mesh": item.mesh_list[self.counter], "bsdf": item.mesh.material.mitsuba_bsdf, "material": item.mesh.o3d_material, } - + for item in self.particles: if item.static: mesh_dict[item.name] = { "mesh": item.mesh_list[0], "bsdf": item.mesh.material.mitsuba_bsdf, "material": item.mesh.o3d_material, - } + } else: mesh_dict[item.name] = { "mesh": item.mesh_list[self.counter], @@ -343,7 +343,7 @@ def _take_screenshot(self, vis): view_matrix, save_name=f"frame_{self.counter}.png", resolution=self.renderer_resolution, - samples_per_pixel=self.renderer_spp + samples_per_pixel=self.renderer_spp, ) # Restart live feed if it was running before the export. @@ -477,24 +477,24 @@ def save_callable(): for item in self.vector_field: if item.static: mesh_dict[item.name] = { - "mesh": item.mesh_list[0], - "bsdf": item.mesh.material.mitsuba_bsdf, - "material": item.mesh.o3d_material, - } + "mesh": item.mesh_list[0], + "bsdf": item.mesh.material.mitsuba_bsdf, + "material": item.mesh.o3d_material, + } else: mesh_dict[item.name] = { "mesh": item.mesh_list[self.counter], "bsdf": item.mesh.material.mitsuba_bsdf, "material": item.mesh.o3d_material, } - + for item in self.particles: if item.static: mesh_dict[item.name] = { "mesh": item.mesh_list[0], "bsdf": item.mesh.material.mitsuba_bsdf, "material": item.mesh.o3d_material, - } + } else: mesh_dict[item.name] = { "mesh": item.mesh_list[self.counter], @@ -509,7 +509,7 @@ def save_callable(): save_dir=self.frame_folder, save_name=f"frame_{self.counter:0>6}.png", resolution=self.renderer_resolution, - samples_per_pixel=self.renderer_spp + samples_per_pixel=self.renderer_spp, ) self.save_thread_finished = True @@ -632,11 +632,11 @@ def _update_particles(self, visualizer=None, step: int = None): else: self.counter += 1 step = self.counter - if self.do_rewind == True: + if self.do_rewind is True: if self.counter <= 1: self.counter = self.number_of_steps - 2 else: - self.counter -= 2 + self.counter -= 2 self._draw_particles(visualizer=visualizer) # draw the particles. @@ -703,8 +703,8 @@ def _toggle_play_speed(self, visualizer=None): Toggle the play speed from 1 to 2 to 4 to 8 and back to 1. """ - if self.do_rewind == True: - self.do_rewind = False + if self.do_rewind is True: + self.do_rewind is False self.play_speed = 1 if self.play_speed == 1: @@ -720,7 +720,7 @@ def _toggle_play_speed_back(self, visualizer=None): """ Toggle the play speed from 1 to 2 to 4 to 8 and back to 1. """ - if self.do_rewind == False: + if self.do_rewind is False: self.play_speed = 1 self.do_rewind = True