Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
import pyvista as pv
|
| 2 |
import json
|
| 3 |
from stpyvista import stpyvista
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Load the .obj file
|
| 6 |
mesh = pv.read('file.obj')
|
|
@@ -12,6 +14,7 @@ with open('dental-labels4.json', 'r') as file:
|
|
| 12 |
# Assuming labels_data['labels'] is a list of labels
|
| 13 |
labels = labels_data['labels']
|
| 14 |
|
|
|
|
| 15 |
# Make sure the number of labels matches the number of vertices or faces
|
| 16 |
assert len(labels) == mesh.n_points or len(labels) == mesh.n_cells
|
| 17 |
|
|
@@ -25,8 +28,16 @@ elif len(labels) == mesh.n_cells:
|
|
| 25 |
# Create a pyvista plotter
|
| 26 |
plotter = pv.Plotter()
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
# Add the mesh to the plotter with labels as a scalar field
|
| 29 |
-
plotter.add_mesh(mesh, scalars='Labels', show_scalar_bar=True, cmap='jet')
|
|
|
|
| 30 |
|
| 31 |
# Show the plot
|
| 32 |
#plotter.show()
|
|
|
|
| 1 |
import pyvista as pv
|
| 2 |
import json
|
| 3 |
from stpyvista import stpyvista
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
import matplotlib.colors as mcolors
|
| 6 |
|
| 7 |
# Load the .obj file
|
| 8 |
mesh = pv.read('file.obj')
|
|
|
|
| 14 |
# Assuming labels_data['labels'] is a list of labels
|
| 15 |
labels = labels_data['labels']
|
| 16 |
|
| 17 |
+
|
| 18 |
# Make sure the number of labels matches the number of vertices or faces
|
| 19 |
assert len(labels) == mesh.n_points or len(labels) == mesh.n_cells
|
| 20 |
|
|
|
|
| 28 |
# Create a pyvista plotter
|
| 29 |
plotter = pv.Plotter()
|
| 30 |
|
| 31 |
+
cmap = plt.cm.get_cmap('tab20', n_clusters) # Using a colormap with sufficient distinct colors
|
| 32 |
+
|
| 33 |
+
colors = cmap(np.linspace(0, 1, n_clusters)) # Generate colors
|
| 34 |
+
|
| 35 |
+
# Convert colors to a format acceptable by PyVista
|
| 36 |
+
colormap = mcolors.ListedColormap(colors)
|
| 37 |
+
|
| 38 |
# Add the mesh to the plotter with labels as a scalar field
|
| 39 |
+
#plotter.add_mesh(mesh, scalars='Labels', show_scalar_bar=True, cmap='jet')
|
| 40 |
+
plotter.add_mesh(mesh, scalars='Labels', show_scalar_bar=True, cmap=colormap, clim=[0, n_clusters - 1])
|
| 41 |
|
| 42 |
# Show the plot
|
| 43 |
#plotter.show()
|