Dear team,
How to convert below mentioned code to Julia only without using Pycall module or any Python modules. Please help
import os
import vtk
import numpy as np
def process_jaw_stl(input_file, output_file, jaw_type, plane_normal, translation_vector, middle_z_offset=5, ver=10, hor=10, xas=10, top_margin=0.1, bottom_margin=0.1):
reader = vtk.vtkSTLReader()
reader.SetFileName(input_file)
reader.Update()
mesh = reader.GetOutput()
transform = vtk.vtkTransform()
transform.RotateX(90)
transform.Translate(xas, ver, hor)
transform_filter = vtk.vtkTransformPolyDataFilter()
transform_filter.SetTransform(transform)
transform_filter.SetInputData(mesh)
transform_filter.Update()
transformed_mesh = transform_filter.GetOutput()
if jaw_type == 'upper':
slice_plane = vtk.vtkPlane()
slice_plane.SetOrigin(transformed_mesh.GetCenter())
slice_plane.SetNormal(plane_normal)
slicer = vtk.vtkClipPolyData()
slicer.SetInputData(transformed_mesh)
slicer.SetClipFunction(slice_plane)
slicer.InsideOutOn()
slicer.Update()
sliced_mesh = slicer.GetOutput()
middle_clipper = vtk.vtkClipPolyData()
middle_plane = vtk.vtkPlane()
middle_plane.SetOrigin(sliced_mesh.GetCenter()[0], sliced_mesh.GetCenter()[1], sliced_mesh.GetCenter()[2] + middle_z_offset)
middle_plane.SetNormal(0, 0, -1)
middle_clipper.SetInputData(sliced_mesh)
middle_clipper.SetClipFunction(middle_plane)
middle_clipper.Update()
middle_removed_mesh = middle_clipper.GetOutput()
hole_filler = vtk.vtkFillHolesFilter()
hole_filler.SetInputData(middle_removed_mesh)
hole_filler.SetHoleSize(50000)
hole_filler.Update()
filled_mesh = hole_filler.GetOutput()
elif jaw_type == 'lower':
bounds = transformed_mesh.GetBounds()
centroid = [(bounds[0] + bounds[1]) / 2, (bounds[2] + bounds[3]) / 2, (bounds[4] + bounds[5]) / 2]
clipper_bottom = vtk.vtkClipPolyData()
clipper_bottom.SetInputData(transformed_mesh)
plane_bottom = vtk.vtkPlane()
plane_bottom.SetOrigin(0, 0, bounds[4] + bottom_margin)
plane_bottom.SetNormal(0, 0, 1)
clipper_bottom.SetClipFunction(plane_bottom)
clipper_bottom.Update()
clipped_mesh_bottom = clipper_bottom.GetOutput()
clipper_top = vtk.vtkClipPolyData()
clipper_top.SetInputData(clipped_mesh_bottom)
plane_top = vtk.vtkPlane()
plane_top.SetOrigin(0, 0, bounds[5] - top_margin)
plane_top.SetNormal(0, 0, -1)
clipper_top.SetClipFunction(plane_top)
clipper_top.Update()
final_clipped_mesh = clipper_top.GetOutput()
middle_clipper = vtk.vtkClipPolyData()
middle_plane = vtk.vtkPlane()
middle_plane.SetOrigin(centroid[0], centroid[1], centroid[2] + middle_z_offset / 2)
middle_plane.SetNormal(0, 0, 1)
middle_clipper.SetInputData(final_clipped_mesh)
middle_clipper.SetClipFunction(middle_plane)
middle_clipper.InsideOutOff()
middle_clipper.Update()
middle_removed_mesh = middle_clipper.GetOutput()
hole_filler = vtk.vtkFillHolesFilter()
hole_filler.SetInputData(middle_removed_mesh)
hole_filler.SetHoleSize(1000.0)
hole_filler.Update()
filled_mesh = hole_filler.GetOutput()
normals = vtk.vtkPolyDataNormals()
normals.SetInputData(filled_mesh)
normals.SetFeatureAngle(30.0)
normals.SplittingOff()
normals.Update()
final_mesh = normals.GetOutput()
writer = vtk.vtkSTLWriter()
writer.SetFileName(output_file)
writer.SetInputData(final_mesh)
writer.Write()
print(f"Final STL saved to {output_file}")
def automate_jaw_processing(directory):
stl_files = [f for f in os.listdir(directory) if f.endswith('.stl')]
if len(stl_files) == 2:
for stl_file in stl_files:
input_path = os.path.join(directory, stl_file)
if 'UpperJaw' in stl_file:
output_path = os.path.join(directory, 'UpperJaw_Cleaned_Filled.stl')
process_jaw_stl(
input_file=input_path,
output_file=output_path,
jaw_type='upper',
plane_normal=[0, 0, 1],
translation_vector=[0, 0, 10],
middle_z_offset=5,
ver=10,
hor=6,
xas=10
)
elif 'LowerJaw' in stl_file:
output_path = os.path.join(directory, 'LowerJaw_Cleaned_Filled.stl')
process_jaw_stl(
input_file=input_path,
output_file=output_path,
jaw_type='lower',
plane_normal=[0, 0, 1],
translation_vector=[0, 0, 25],
top_margin=0.13,
bottom_margin=0.13
)
else:
print("Please ensure there are exactly two STL files in the directory, named appropriately with 'UpperJaw' and 'LowerJaw'.")
directory_path = r'C:\Users\OMG\Desktop\Dental STL-TEST'
automate_jaw_processing(directory_path)
Attached is the sample screenshot after importing Original files to Blender software
Thanks and regards