From cf2db259e205460dafb5ac3830f6d4781cac257d Mon Sep 17 00:00:00 2001 From: GaelleLeroux Date: Fri, 17 May 2024 13:50:42 -0400 Subject: [PATCH] FIX : fix input crownsegmentation --- AREG/AREG.py | 20 ++++- AREG/AREG_Method/IOS.py | 110 +++++++++++++++++++++---- ASO_IOS/ASO_IOS_utils/cache/source.npy | Bin 601 -> 601 bytes ASO_IOS/ASO_IOS_utils/cache/target.npy | Bin 601 -> 601 bytes 4 files changed, 111 insertions(+), 19 deletions(-) diff --git a/AREG/AREG.py b/AREG/AREG.py index efd72c9..032c6da 100644 --- a/AREG/AREG.py +++ b/AREG/AREG.py @@ -814,6 +814,9 @@ 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), @@ -821,6 +824,8 @@ def TestFiles(self): 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") @@ -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)] @@ -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, @@ -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() diff --git a/AREG/AREG_Method/IOS.py b/AREG/AREG_Method/IOS.py index 745154d..f2050e3 100644 --- a/AREG/AREG_Method/IOS.py +++ b/AREG/AREG_Method/IOS.py @@ -6,6 +6,8 @@ import os import vtk import shutil +import platform +import csv class Auto_IOS(Method): @@ -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): @@ -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, diff --git a/ASO_IOS/ASO_IOS_utils/cache/source.npy b/ASO_IOS/ASO_IOS_utils/cache/source.npy index a36555c522c48babaf2c8b2184ce147937664770..c48c5c2a2fd8213a3f979f8c553ba01d4068c3ab 100644 GIT binary patch delta 110 zcmcb~a+764Hlq;3>`K!E3=9kpf}J=WfOJCKh9F^w%V*_5^aHQS2Z6#4 zHem)1AZ}T$5=fX~{bW`qW5ow1#tuNvfwd2KKy*U4$_M*G-I7ARq|(HaLj5E?00n~} A!vFvP delta 110 zcmcb~a+764Hlt9(>`K!E3=9ko2~M02Kw9DDBlwMqv-wBuw}CS%3>CdMGq1@j*8fanLal|R@Q>XsDhC6y+Y6zV7G0RUhM BB76V< diff --git a/ASO_IOS/ASO_IOS_utils/cache/target.npy b/ASO_IOS/ASO_IOS_utils/cache/target.npy index a36555c522c48babaf2c8b2184ce147937664770..c48c5c2a2fd8213a3f979f8c553ba01d4068c3ab 100644 GIT binary patch delta 110 zcmcb~a+764Hlq;3>`K!E3=9kpf}J=WfOJCKh9F^w%V*_5^aHQS2Z6#4 zHem)1AZ}T$5=fX~{bW`qW5ow1#tuNvfwd2KKy*U4$_M*G-I7ARq|(HaLj5E?00n~} A!vFvP delta 110 zcmcb~a+764Hlt9(>`K!E3=9ko2~M02Kw9DDBlwMqv-wBuw}CS%3>CdMGq1@j*8fanLal|R@Q>XsDhC6y+Y6zV7G0RUhM BB76V<