Skip to content

Commit

Permalink
support repeat of volumetric data (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed May 28, 2023
1 parent ca2ecbc commit 1c8af1c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions batoms/batoms.py
Expand Up @@ -943,8 +943,8 @@ def __imul__(self, m):
# self.set_frames(frames_new)
self.cell.repeat(m)
self.update_gn_cell()
# if self.volumetric_data is not None:
# self.volumetric_data = np.tile(self.volumetric_data, m)
if self.volumetric_data is not None:
self._volumetric_data *= m
self.species.update_geometry_node()
if self._boundary is not None:
self.boundary.update()
Expand Down
11 changes: 10 additions & 1 deletion batoms/volumetric_data.py
Expand Up @@ -90,6 +90,8 @@ def build_object(self, setting, volume):
name = "{}_volume_{}".format(self.label, setting.name)
if name in bpy.data.objects:
bpy.data.objects.remove(bpy.data.objects[name], do_unlink=True)
if name in bpy.data.meshes:
bpy.data.meshes.remove(bpy.data.meshes[name], do_unlink=True)
shape = volume.shape
volume = volume.reshape(-1, 1)
npoint = len(volume)
Expand All @@ -98,11 +100,12 @@ def build_object(self, setting, volume):
dn = 3 - npoint % 3
verts = np.append(volume, np.zeros((dn, 1)), axis=0)
verts = verts.reshape(-1, 3)
mesh = bpy.data.meshes.new("%s_volume" % self.label)
mesh = bpy.data.meshes.new(name)
mesh.from_pydata(verts, [], [])
mesh.update()
obj = bpy.data.objects.new(name, mesh)
obj.data = mesh
obj.parent = self.parent.obj
obj.batoms.type = 'VOLUME'
obj.batoms.volume.shape = shape
self.coll.objects.link(obj)
Expand Down Expand Up @@ -134,6 +137,12 @@ def get_volume(self, name):
# print('Read volume: {0:1.2f}'.format(time() - tstart))
return volume

def __imul__(self, m):
import numpy as np
for volume in self.bpy_setting:
data = self[volume.name]
self[volume.name] = np.tile(data, m)
return self

def __repr__(self) -> str:
s = "-"*60 + "\n"
Expand Down
10 changes: 10 additions & 0 deletions tests/test_volumetric_data.py
Expand Up @@ -82,3 +82,13 @@ def test_ops_create():
operator='Minus')
assert h2o.coll.batoms.ui_list_index_volumetric_data == 2
assert np.isclose(h2o.volumetric_data['diff'], 0).all()

def test_repeat():
from batoms.bio.bio import read
bpy.ops.batoms.delete()
h2o = read("../tests/datas/h2o-homo.cube")
shape = h2o.volumetric_data["h2o_homo"].shape
M = [2, 2, 1]
h2o._volumetric_data *= M
new_shape = h2o.volumetric_data["h2o_homo"].shape
assert list(new_shape) == [shape[i]*M[i] for i in range(3)]

0 comments on commit 1c8af1c

Please sign in to comment.