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

Increasing output PLY file #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion demo/demo_3d_letters2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
with_gui = True
write_to_disk = True

w2ply = True

# Try to run on GPU
ti.init(arch=ti.cuda,
kernel_profiler=True,
Expand All @@ -22,7 +24,7 @@
if with_gui:
gui = ti.GUI("MLS-MPM", res=512, background_color=0x112F41)

if write_to_disk:
if write_to_disk or w2ply:
output_dir = create_output_folder('./sim')


Expand Down Expand Up @@ -117,5 +119,9 @@ def visualize(particles):

if write_to_disk:
mpm.write_particles(f'{output_dir}/{frame:05d}.npz')

if w2ply:
mpm.write_ply(output_dir,frame + 1)

print(f'Frame total time {time.time() - t:.3f}')
print(f'Total running time {time.time() - start_t:.3f}')
64 changes: 64 additions & 0 deletions engine/mpm_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,70 @@ def write_particles(self, fn):
p.start()

self.writers.append(p)

def write_ply(self,fn,frame):
p_info = self.particle_info()

p_pos = p_info['position']
p_mat = p_info['material']
p_null = np.array([[np.nan]])

arr_water = np.where(p_mat == 0)
arr_elast = np.where(p_mat == 1)
arr_snow = np.where(p_mat == 2)
arr_sand = np.where(p_mat == 3)

series_prefix_0 = fn + "/water.ply"
series_prefix_1 = fn + "/elast.ply"
series_prefix_2 = fn + "/snow.ply"
series_prefix_3 = fn + "/sand.ply"

print("num_particles:{0},elast:{1},water:{2},snow:{3},sand:{4},out_particles:{5}".format(self.n_particles,len(arr_elast[0]) ,len(arr_water[0]) ,len(arr_snow[0]) ,len(arr_sand[0]) ,len(arr_water[0]) + len(arr_elast[0]) + len(arr_snow[0]) + len(arr_sand[0])),end='\n')

if len(arr_water[0]) > 0:
min_water = np.min(arr_water)
max_water = np.max(arr_water)
writer_0 = ti.PLYWriter(num_vertices=max_water - min_water + 1)
writer_0.add_vertex_pos(p_pos[min_water: max_water + 1, 0],p_pos[min_water: max_water + 1, 1],p_pos[min_water: max_water + 1, 2])
writer_0.export_frame_ascii(frame,series_prefix_0)
else:
writer_0 = ti.PLYWriter(num_vertices=1)
writer_0.add_vertex_pos(p_null[ : , 0],p_null[ : , 0],p_null[ : , 0])
writer_0.export_frame_ascii(frame,series_prefix_0)

if len(arr_elast[0]) > 0:
min_elast = np.min(arr_elast)
max_elast = np.max(arr_elast)
writer_1 = ti.PLYWriter(num_vertices=max_elast - min_elast + 1)
writer_1.add_vertex_pos(p_pos[min_elast: max_elast + 1, 0],p_pos[min_elast: max_elast + 1, 1],p_pos[min_elast: max_elast + 1, 2])
writer_1.export_frame_ascii(frame,series_prefix_1)
else:
writer_1 = ti.PLYWriter(num_vertices=1)
writer_1.add_vertex_pos(p_null[ : , 0],p_null[ : , 0],p_null[ : , 0])
writer_1.export_frame_ascii(frame,series_prefix_1)

if len(arr_snow[0]) > 0:
min_snow = np.min(arr_snow)
max_snow = np.max(arr_snow)
writer_2 = ti.PLYWriter(num_vertices=max_snow - min_snow + 1)
writer_2.add_vertex_pos(p_pos[min_snow: max_snow + 1, 0],p_pos[min_snow: max_snow + 1, 1],p_pos[min_snow: max_snow + 1, 2])
writer_2.export_frame_ascii(frame,series_prefix_2)
else:
writer_2 = ti.PLYWriter(num_vertices=1)
writer_2.add_vertex_pos(p_null[ : , 0],p_null[ : , 0],p_null[ : , 0])
writer_2.export_frame_ascii(frame,series_prefix_2)

if len(arr_sand[0]) > 0:
min_sand = np.min(arr_sand)
max_sand = np.max(arr_sand)
writer_3 = ti.PLYWriter(num_vertices=max_sand - min_sand + 1)
writer_3.add_vertex_pos(p_pos[min_sand: max_sand + 1, 0],p_pos[min_sand: max_sand + 1, 1],p_pos[min_sand: max_sand + 1, 2])
writer_3.export_frame_ascii(frame,series_prefix_3)
else:
writer_3 = ti.PLYWriter(num_vertices=1)
writer_3.add_vertex_pos(p_null[ : , 0],p_null[ : , 0],p_null[ : , 0])
writer_3.export_frame_ascii(frame,series_prefix_3)


def flush(self):
for p in self.writers:
Expand Down