Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Step Back and Restart feature #46

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
20 changes: 16 additions & 4 deletions znvis/particle/particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class Particle:
Director tensor of the shape (n_confs, n_particles, n_dims)
mesh_list : list
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)
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
Expand All @@ -64,7 +68,7 @@ class Particle:
force: np.ndarray = None
director: np.ndarray = None
mesh_list: typing.List[Mesh] = None

static: bool = False
smoothing: bool = False

def _create_mesh(self, position, director):
Expand Down Expand Up @@ -105,13 +109,21 @@ def construct_mesh_list(self):
"""
self.mesh_list = []
try:
# n_particles = int(self.position.shape[1])
n_time_steps = int(len(self.position))
if not self.static:
n_particles = int(self.position.shape[1])
n_time_steps = int(self.position.shape[0])
else:
n_particles = int(self.position.shape[0])
n_time_steps = 1
self.position = self.position[np.newaxis, :, :]
if self.director is not None:
self.director = self.director[np.newaxis, :, :]

except ValueError:
raise ValueError("There is no data for these particles.")

for i in track(range(n_time_steps), description=f"Building {self.name} Mesh"):
for j in range(np.shape(self.position[i])[0]):
for j in range(n_particles):
if j == 0:
if self.director is not None:
mesh = self._create_mesh(
Expand Down
31 changes: 24 additions & 7 deletions znvis/particle/vector_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class VectorField:
Direction tensor of the shape (n_steps, n_vectors, n_dims)
mesh_list : list
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)
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
Expand All @@ -58,7 +62,7 @@ class VectorField:
position: np.ndarray = None
direction: np.ndarray = None
mesh_list: typing.List[Arrow] = None

static: bool = False
smoothing: bool = False

def _create_mesh(self, position: np.ndarray, direction: np.ndarray):
Expand Down Expand Up @@ -97,15 +101,28 @@ def construct_mesh_list(self):
"""
self.mesh_list = []
try:
n_particles = int(self.position.shape[1])
n_time_steps = int(self.position.shape[0])
if not self.static:
n_particles = int(self.position.shape[1])
n_time_steps = int(self.position.shape[0])
else:
n_particles = int(self.position.shape[0])
n_time_steps = 1
self.position = self.position[np.newaxis, :, :]
self.direction = self.direction[np.newaxis, :, :]

except ValueError:
raise ValueError("There is no data for this vector field.")

new_mesh = True

for i in track(range(n_time_steps), description=f"Building {self.name} Mesh"):
for j in range(n_particles):
if j == 0:
mesh = self._create_mesh(self.position[i][j], self.direction[i][j])
else:
mesh += self._create_mesh(self.position[i][j], self.direction[i][j])
if np.max(self.direction[i][j]) > 0: # ignore vectors with length zero
if new_mesh is False:
mesh += self._create_mesh(self.position[i][j], self.direction[i][j])
else:
mesh = self._create_mesh(self.position[i][j], self.direction[i][j])
new_mesh = False
new_mesh = True

self.mesh_list.append(mesh)
Loading
Loading