Visualize_obj / app.py
huathedev's picture
Upload app.py
4976b70
raw
history blame
934 Bytes
import pyvista as pv
import json
from stpyvista import stpyvista
# Load the .obj file
mesh = pv.read('file.obj')
# Load the JSON file
with open('dental-labels4.json', 'r') as file:
labels_data = json.load(file)
# Assuming labels_data['labels'] is a list of labels
labels = labels_data['labels']
# Make sure the number of labels matches the number of vertices or faces
assert len(labels) == mesh.n_points or len(labels) == mesh.n_cells
# If labels correspond to vertices
if len(labels) == mesh.n_points:
mesh.point_data['Labels'] = labels
# If labels correspond to faces
elif len(labels) == mesh.n_cells:
mesh.cell_data['Labels'] = labels
# Create a pyvista plotter
plotter = pv.Plotter()
# Add the mesh to the plotter with labels as a scalar field
plotter.add_mesh(mesh, scalars='Labels', show_scalar_bar=True, cmap='jet')
# Show the plot
#plotter.show()
## Send to streamlit
stpyvista(plotter)