|
23 | 23 | import os |
24 | 24 | import numpy as np |
25 | 25 |
|
26 | | -import ctypes, platform |
27 | | -from ctypes import util |
28 | | -# check for the extension |
29 | | -if platform.system() == 'Linux': |
30 | | - dll = 'libctomophantom.so' |
31 | | -elif platform.system() == 'Windows': |
32 | | - dll_file = 'ctomophantom.dll' |
33 | | - dll = util.find_library(dll_file) |
34 | | -elif platform.system() == 'Darwin': |
35 | | - dll = 'libctomophantom.dylib' |
36 | | -else: |
37 | | - raise ValueError('Not supported platform, ', platform.system()) |
38 | | - |
39 | | -libtomophantom = ctypes.cdll.LoadLibrary(dll) |
40 | | - |
41 | | - |
| 26 | +import ctypes |
| 27 | +import tomophantom.ctypes.external as external |
42 | 28 |
|
43 | 29 | path = os.path.dirname(tomophantom.__file__) |
44 | | -path_library2D = os.path.join(path, "Phantom2DLibrary.dat") |
45 | | -path_library3D = os.path.join(path, "Phantom3DLibrary.dat") |
| 30 | +path_library2D = os.path.join(path, "phantomlib", "Phantom2DLibrary.dat") |
| 31 | +path_library3D = os.path.join(path, "phantomlib", "Phantom3DLibrary.dat") |
46 | 32 |
|
47 | 33 | def is_model_temporal(num_model, num_dims=2): |
48 | 34 | '''Returns whether a model in the TomoPhantom library is temporal |
@@ -89,24 +75,20 @@ def check_model_params(num_model, num_dims=2): |
89 | 75 | :type num_dims: int, default 2 |
90 | 76 | ''' |
91 | 77 | if num_dims == 2: |
92 | | - libtomophantom.checkParams2D.argtypes = [ctypes.POINTER(ctypes.c_int), # pointer to the params array |
| 78 | + external.c_checkParams2D.argtypes = [ctypes.POINTER(ctypes.c_int), # pointer to the params array |
93 | 79 | ctypes.c_int, # model number selector (int) |
94 | 80 | ctypes.c_char_p] # string to the library file |
95 | 81 | params = np.zeros([10], dtype=np.int32) |
96 | | - params_p = params.ctypes.data_as(ctypes.POINTER(ctypes.c_int)) |
97 | | - lib2d_p = str(path_library2D).encode('utf-8') |
98 | | - libtomophantom.checkParams2D(params_p, num_model, lib2d_p) |
| 82 | + external.c_checkParams2D(params, num_model, str(path_library2D)) |
99 | 83 |
|
100 | 84 | return params |
101 | 85 |
|
102 | 86 | elif num_dims == 3: |
103 | | - libtomophantom.checkParams3D.argtypes = [ctypes.POINTER(ctypes.c_int), # pointer to the params array |
| 87 | + external.c_checkParams3D.argtypes = [ctypes.POINTER(ctypes.c_int), # pointer to the params array |
104 | 88 | ctypes.c_int, # model number selector (int) |
105 | 89 | ctypes.c_char_p] # string to the library file |
106 | 90 | params = np.zeros([11], dtype=np.int32) |
107 | | - params_p = params.ctypes.data_as(ctypes.POINTER(ctypes.c_int)) |
108 | | - lib2d_p = str(path_library3D).encode('utf-8') |
109 | | - libtomophantom.checkParams3D(params_p, num_model, lib2d_p) |
| 91 | + external.c_checkParams3D(params, num_model, str(path_library3D)) |
110 | 92 |
|
111 | 93 | return params |
112 | 94 |
|
|
0 commit comments