Towards the Automatization of Cranial Implant Design in Cranioplasty II
MICCAI 2021 Challenge
The official proceedings can be found on SpringerLink.
(Thinning & Border Adjustment)
import nrrd
import pyvista as pv
import numpy as np
import vtk
import trimesh
# Load original mesh
mesh = pv.PolyData('original.stl')
# Extract the interior surface of an implant
mesh.compute_normals(cell_normals=True, point_normals=False, inplace=True)
ids = np.arange(mesh.n_cells)[mesh['Normals'][:,2] < 0.0 ]
top = mesh.extract_cells(ids)
ind = []
newList1 = []
newList2 = []
# Convert PyVista datatype to list for fast processing of points
for i in range(len(top.points)):
newList1.append([top.points[i][0], top.points[i][1], top.points[i][2]])
for i in range(len(mesh.points)):
newList2.append([mesh.points[i][0], mesh.points[i][1], mesh.points[i][2]])
for i in range(len(top.points)):
idx = newList2.index(newList1[i])
ind.append(idx)
# Rescale x, y, z
for i in range(len(ind)):
mesh.points[ind[i]][2] = mesh.points[ind[i]][2] * 1.05
mesh.points[ind[i]][1] = mesh.points[ind[i]][1] * 0.95
mesh.points[ind[i]][0] = mesh.points[ind[i]][0] * 1.00
mesh.plot()
mesh = mesh.extract_surface().triangulate()
mesh.save('result.stl')
# Note: After generating the processed mesh, intersection can be done using MeshLab:
# MeshLab -> Loading result.stl and original.stl -> Filters -> Remeshing, Simplification, Reconstruction
# -> Mesh Boolean: Intersection