Skip to content

Commit

Permalink
FIX : fix input crownsegmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
GaelleLeroux committed May 17, 2024
1 parent 70bb9a7 commit cf2db25
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 19 deletions.
20 changes: 19 additions & 1 deletion AREG/AREG.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,13 +814,18 @@ def TestFiles(self):
else:
name, url = self.ActualMeth.getTestFileList()

print("name : ",name)
print("url : ",url)

scan_folder = self.DownloadUnzip(
url=url,
directory=os.path.join(self.SlicerDownloadPath),
folder_name=os.path.join("Test_Files", name)
if not self.isDCMInput
else os.path.join("Test_Files", "DCM", name),
)

print("scan folder : ",scan_folder)
scan_folder_t1 = os.path.join(scan_folder, "T1")
scan_folder_t2 = os.path.join(scan_folder, "T2")

Expand Down Expand Up @@ -1092,7 +1097,7 @@ def onPredictButton(self):

if self.type == "IOS":
# Installation of pytorch is done before pytorch3d installation in the function because the order is important andfor version compatibility
list_libs_IOS =[('vtk',None,None),('pandas',None,None),('monai','==0.7.0',None),
list_libs_IOS =[("shapeaxi",None,None),('vtk',None,None),('pandas',None,None),('monai','==0.7.0',None),
('pytorch3d',"==0.7.0","https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/py39_cu113_pyt1120/download.html"),
('torchmetrics','==0.9.3',None),('pytorch-lightning','==1.7.7',None),('numpy','>=1.21.6,<1.28',None)]

Expand Down Expand Up @@ -1155,6 +1160,7 @@ def onPredictButton(self):
self.onProcessStarted()

# /!\ Launch of the first process /!\
print("module name : ",self.list_Processes_Parameters[0]["Module"])
self.process = slicer.cli.run(
self.list_Processes_Parameters[0]["Process"],
None,
Expand Down Expand Up @@ -1307,6 +1313,18 @@ def OnEndProcess(self):
)
s.exec_()

file_path = os.path.abspath(__file__)
folder_path = os.path.dirname(file_path)
csv_file = os.path.join(folder_path,"AREG_Method","liste_csv_file_T1.csv")
print("csv_file : ",csv_file)
if os.path.exists(csv_file):
os.remove(csv_file)

csv_file = os.path.join(folder_path,"AREG_Method","liste_csv_file_T2.csv")
print("csv_file : ",csv_file)
if os.path.exists(csv_file):
os.remove(csv_file)

def onCancel(self):
self.process.Cancel()

Expand Down
110 changes: 92 additions & 18 deletions AREG/AREG_Method/IOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import os
import vtk
import shutil
import platform
import csv


class Auto_IOS(Method):
Expand Down Expand Up @@ -63,6 +65,47 @@ def TestModel(self, model_folder: str, lineEditName) -> str:
out = "Please give folder with only one .ckpt file \n"

return out

def create_csv(self,input_dir,name_csv):
'''
create a csv with the complete path of the files in the folder (used for segmentation only)
'''
file_path = os.path.abspath(__file__)
folder_path = os.path.dirname(file_path)
csv_file = os.path.join(folder_path,f"{name_csv}.csv")
with open(csv_file, 'w', newline='') as fichier:
writer = csv.writer(fichier)
# Écrire l'en-tête du CSV
writer.writerow(["surf"])

# Parcourir le dossier et ses sous-dossiers
for root, dirs, files in os.walk(input_dir):
for file in files:
if file.endswith(".vtk") or file.endswith(".stl"):
# Écrire le chemin complet du fichier dans le CSV
if platform.system() != "Windows" :
writer.writerow([os.path.join(root, file)])
else :
file_path = os.path.join(root, file)
norm_file_path = os.path.normpath(file_path)
writer.writerow([self.windows_to_linux_path(norm_file_path)])


return csv_file

def windows_to_linux_path(self,windows_path):
'''
Convert a windows path to a wsl path
'''
windows_path = windows_path.strip()

path = windows_path.replace('\\', '/')

if ':' in path:
drive, path_without_drive = path.split(':', 1)
path = "/mnt/" + drive.lower() + path_without_drive

return path

def TestReference(self, ref_folder: str):

Expand Down Expand Up @@ -239,30 +282,61 @@ def Process(self, **kwargs):
number_scan_toseg_T2 = self.__BypassCrownseg__(
kwargs["input_t2_folder"], path_input_T2, path_seg_T2
)
slicer_path = slicer.app.applicationDirPath()
dentalmodelseg_path = os.path.join(slicer_path,"..","lib","Python","bin","dentalmodelseg")

surf_T1 = "None"
input_csv_T1 = "None"
vtk_folder_T1 = "None"
if os.path.isfile(path_input_T1):
extension = os.path.splitext(self.input)[1]
if extension == ".vtk" or extension == ".stl":
surf_T1 = path_input_T1

elif os.path.isdir(path_input_T1):
input_csv_T1 = self.create_csv(path_input_T1,"liste_csv_file_T1")
vtk_folder_T1 = path_input_T1

parameter_segteeth_T1 = {
"input": path_input_T1,
"output": path_seg_T1,
"subdivision_level": 2,
"resolution": 320,
"model": self.getModel(kwargs["model_folder_1"], extension="pth"),
"predictedId": "Universal_ID",
"sepOutputs": 0,
"chooseFDI": 0,
"logPath": kwargs["logPath"],
"surf": surf_T1,
"input_csv": input_csv_T1,
"out": path_seg_T1,
"overwrite": "0",
"model": "latest",
"crown_segmentation": "0",
"array_name": "Universal_ID",
"fdi": 0,
"suffix": "None",
"vtk_folder": vtk_folder_T1,
"dentalmodelseg_path":dentalmodelseg_path
}

surf_T2 = "None"
input_csv_T2 = "None"
vtk_folder_T2 = "None"
if os.path.isfile(path_input_T2):
extension = os.path.splitext(self.input)[1]
if extension == ".vtk" or extension == ".stl":
surf_T2 = path_input_T2

elif os.path.isdir(path_input_T1):
input_csv_T2 = self.create_csv(path_input_T1,"liste_csv_file_T2")
vtk_folder_T2 = path_input_T2

parameter_segteeth_T2 = {
"input": path_input_T2,
"output": path_seg_T2,
"subdivision_level": 2,
"resolution": 320,
"model": self.getModel(kwargs["model_folder_1"], extension="pth"),
"predictedId": "Universal_ID",
"sepOutputs": 0,
"chooseFDI": 0,
"logPath": kwargs["logPath"],
"surf": surf_T2,
"input_csv": input_csv_T2,
"out": path_seg_T2,
"overwrite": "0",
"model": "latest",
"crown_segmentation": "0",
"array_name": "Universal_ID",
"fdi": 0,
"suffix": "None",
"vtk_folder": vtk_folder_T2,
"dentalmodelseg_path":dentalmodelseg_path
}


parameter_pre_aso_T1 = {
"input": path_seg_T1,
Expand Down
Binary file modified ASO_IOS/ASO_IOS_utils/cache/source.npy
Binary file not shown.
Binary file modified ASO_IOS/ASO_IOS_utils/cache/target.npy
Binary file not shown.

0 comments on commit cf2db25

Please sign in to comment.