generate normals figure

This commit is contained in:
2023-07-03 22:57:54 +02:00
parent 37dab8cf4e
commit 9e93c6f477
+22 -25
View File
@@ -3,6 +3,9 @@ import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..') sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
import numpy as np import numpy as np
import cmapy as cm
from utils import remove_long_edges
from custom_utils.custom_utils import save_stl, write_obj from custom_utils.custom_utils import save_stl, write_obj
from data.cloth3d_io import readPC2Frame from data.cloth3d_io import readPC2Frame
@@ -12,24 +15,6 @@ import plotly.graph_objects as go
from plotly.subplots import make_subplots from plotly.subplots import make_subplots
def remove_long_edges(vertices, faces):
# Compute edge lengths
edges = np.vstack((faces[:,[0,1]], faces[:,[1,2]], faces[:,[2,0]]))
edge_lengths = np.linalg.norm(vertices[edges[:,0]] - vertices[edges[:,1]], axis=1)
# Find edges longer than 0.1
long_edges = edges[edge_lengths > 0.1]
# Find vertices that are part of long edges
vertices_to_remove = np.unique(long_edges)
# Remove vertices and update faces
mask = np.ones(vertices.shape[0], dtype=bool)
mask[vertices_to_remove] = False
new_vertices = vertices[mask]
return new_vertices, mask
def plot_unposing_example(): def plot_unposing_example():
@@ -87,7 +72,7 @@ def plot_normals_example():
# mesh_unposed = readPC2Frame(os.path.join(folder_test, 'mesh_unposed_no_shape', f'{frame.id}_{frame.garment}.pc16'), frame.frame_nr, True) # mesh_unposed = readPC2Frame(os.path.join(folder_test, 'mesh_unposed_no_shape', f'{frame.id}_{frame.garment}.pc16'), frame.frame_nr, True)
# mesh_unposed_shaped = readPC2Frame(os.path.join('temp', f'{frame.id}_{frame.garment}_unposed_shaped.pc16'), frame.frame_nr, True)[mesh_mask] # mesh_unposed_shaped = readPC2Frame(os.path.join('temp', f'{frame.id}_{frame.garment}_unposed_shaped.pc16'), frame.frame_nr, True)[mesh_mask]
mesh_normals = readPC2Frame(os.path.join(folder_test, 'mesh_normals', f'{frame.id}_{frame.garment}.pc16'), frame.frame_nr, True) mesh_normals = readPC2Frame(os.path.join(folder_test, 'mesh_normals', f'{frame.id}_{frame.garment}.pc16'), frame.frame_nr, True)
uv_normals = np.load(os.path.join(folder_test, 'uv_normals', f'{frame.id}_{frame.frame_nr}_{frame.garment}.npz')) # uv_normals = np.load(os.path.join(folder_test, 'uv_normals', f'{frame.id}_{frame.frame_nr}_{frame.garment}.npz'))
F = np.load('smpl/smpl_faces.npy') F = np.load('smpl/smpl_faces.npy')
_, faces = _maskFaces(np.zeros((14475, 3)), F, mesh_mask) _, faces = _maskFaces(np.zeros((14475, 3)), F, mesh_mask)
@@ -101,12 +86,13 @@ def plot_normals_example():
new_mask[mesh_mask] = v_mask new_mask[mesh_mask] = v_mask
_, faces = _maskFaces(np.zeros((14475, 3)), F, new_mask) _, faces = _maskFaces(np.zeros((14475, 3)), F, new_mask)
fig = make_subplots(rows=1, cols=4, specs=[[{'type': 'mesh3d'}, {'type': 'mesh3d'}, {'type': 'mesh3d'}, {'type': 'mesh3d'}]]) v_colors = (mesh_normals + 1.4) / 2.8
v_colors = v_colors[v_mask]
# v_colors = (v_colors - v_colors.min()) / (v_colors.max() - v_colors.min())
fig.add_trace(go.Mesh3d(x=mesh_static[:,0], y=mesh_static[:,2], z=mesh_static[:,1], i=faces[:,0], j=faces[:,1], k=faces[:,2], color='lightpink', opacity=1), row=1, col=1) fig = go.Figure()
fig.add_trace(go.Mesh3d(x=mesh_posed[:,0], y=mesh_posed[:,2], z=mesh_posed[:,1], i=faces[:,0], j=faces[:,1], k=faces[:,2], color='lightblue', opacity=1), row=1, col=2)
fig.add_trace(go.Mesh3d(x=mesh_unposed_shaped[:,0], y=mesh_unposed_shaped[:,2], z=mesh_unposed_shaped[:,1], i=faces[:,0], j=faces[:,1], k=faces[:,2], color='lightgreen', opacity=1), row=1, col=3) fig.add_trace(go.Mesh3d(x=mesh_posed[:,0], y=mesh_posed[:,2], z=mesh_posed[:,1], i=faces[:,0], j=faces[:,1], k=faces[:,2], vertexcolor=v_colors, opacity=1),)
fig.add_trace(go.Mesh3d(x=mesh_unposed[:,0], y=mesh_unposed[:,2], z=mesh_unposed[:,1], i=faces[:,0], j=faces[:,1], k=faces[:,2], color='lightyellow', opacity=1), row=1, col=4)
fig.update_layout(scene=dict( fig.update_layout(scene=dict(
xaxis=dict(range=[-1, 1]), xaxis=dict(range=[-1, 1]),
@@ -114,11 +100,22 @@ def plot_normals_example():
zaxis=dict(range=[-1, 1]), zaxis=dict(range=[-1, 1]),
), scene_aspectmode='cube') ), scene_aspectmode='cube')
helper = dict(xaxis = dict(range=[-1,1], showbackground=False, showticklabels=False, showaxeslabels=False, showspikes=False, visible=False),
yaxis = dict(range=[-1,1], showbackground=False, showticklabels=False, showaxeslabels=False, showspikes=False, visible=False),
zaxis = dict(range=[-1,1], showbackground=False, showticklabels=False, showaxeslabels=False, showspikes=False, visible=False),)
fig.update_layout(scene = helper)
fig.show()
pass
if __name__ == '__main__': if __name__ == '__main__':
folder_train = '/data-local/127/cloth3d_processed' folder_train = '/data-local/127/cloth3d_processed'
folder_test = '/data-local/127/cloth3d_processed_test' folder_test = '/data-local/127_2/cloth3d_processed_test'
# plot_unposing_example() # plot_unposing_example()
plot_normals_example() plot_normals_example()