def ds_from_filelist(filelist): meshes = [] mesheslist = [] for file in filelist: meshes.append(MeshFactory.mesh_from_file(file)) mesheslist.append(meshes) return (DatasetCollection(datasets=mesheslist))
def ds_from_dir(dir_path, center_scale=False): c = [join(dir_path, x) for x in listdir(dir_path)] files = [ f for f in c if isfile(f) and splitext(f)[1] in DatasetFactory.__ftypes ] if not files: msg = 'No appropriate files were found in ' + dir_path raise OSError(msg) meshes = [] mesheslist = [] for file in files: meshes.append(MeshFactory.mesh_from_file(file, center_scale)) mesheslist.append(meshes) return (DatasetCollection(datasets=mesheslist))
#Test script for the mesh factory from auto3dgm_nazar.mesh.meshfactory import MeshFactory #Test case 0: Giving out a non-sense file #Conditions: filestring refers to a non existing file #Expect: When I try to create a mesh, I get an error filestring = '/home/safari/Desktop/tutkimus/Slicer/HackathonJAN/testdata/20_Test_Teeth_PLY/Non-existing file.ply' MeshFactory.mesh_from_file(filestring) ''' In [27]: filestring='/home/safari/Desktop/tutkimus/Slicer/HackathonJAN/testdata/20_Test_Teeth_PLY/Non-existing file.ply' In [28]: MeshFactory.mesh_from_file(filestring) --------------------------------------------------------------------------- OSError Traceback (most recent call last) <ipython-input-28-dce76620cc80> in <module>() ----> 1 MeshFactory.mesh_from_file(filestring) /home/safari/Desktop/tutkimus/Slicer/HackathonJAN/gitstuff/auto3dgm/auto3dgm/mesh/meshfactory.py in mesh_from_file(file_path) 52 msg = 'File {} not present or not allowed filetype: {}'.format( 53 file_path, ', '.join(allowed_filetypes)) ---> 54 raise OSError(msg) 55 56 @staticmethod OSError: File /home/safari/Desktop/tutkimus/Slicer/HackathonJAN/testdata/20_Test_Teeth_PLY/Non-existing file.ply not present or not allowed filetype: .ply, .obj, .stl ''' # Result: Success! #Test case 1: Giving out an invalid #Conditions: filestring refers to a file type not supported #Expect: When I try to create a mesh, I get an error