Skip to content

Commit

Permalink
Merge pull request #50 from zincware/samtov_formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTov authored Sep 18, 2024
2 parents ba6aaff + aa0e55d commit 1f2157a
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 128 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]
60 changes: 36 additions & 24 deletions examples/all_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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.
Expand All @@ -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(
Expand All @@ -120,4 +132,4 @@
visualizer = vis.Visualizer(
particles=particle_list, frame_rate=20, bounding_box=bounding_box
)
visualizer.run_visualization()
visualizer.run_visualization()
26 changes: 12 additions & 14 deletions examples/simple_vector_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,26 @@

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)
mesh_2 = vis.Sphere(radius=1.0, resolution=20, material=material_2)

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()
visualizer = vis.Visualizer(
particles=[particle], vector_field=[vector_field], frame_rate=20
)
visualizer.run_visualization()
11 changes: 5 additions & 6 deletions znvis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions znvis/mesh/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
10 changes: 2 additions & 8 deletions znvis/mesh/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand All @@ -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
)

4 changes: 0 additions & 4 deletions znvis/mesh/cone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -64,4 +61,3 @@ def create_mesh(self) -> o3d.geometry.TriangleMesh:
resolution=self.resolution,
split=self.split,
)

3 changes: 1 addition & 2 deletions znvis/mesh/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions znvis/mesh/cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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,
)

8 changes: 1 addition & 7 deletions znvis/mesh/icosahedron.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
5 changes: 1 addition & 4 deletions znvis/mesh/mobius_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand Down
8 changes: 1 addition & 7 deletions znvis/mesh/octahedron.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
5 changes: 1 addition & 4 deletions znvis/mesh/sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
)
7 changes: 1 addition & 6 deletions znvis/mesh/tetrahedron.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
Loading

0 comments on commit 1f2157a

Please sign in to comment.