|
a |
|
b/testing/statistics/ProcrustesRegistration_test.py |
|
|
1 |
import glob |
|
|
2 |
import os |
|
|
3 |
import time |
|
|
4 |
|
|
|
5 |
import pytest |
|
|
6 |
|
|
|
7 |
from pymskt.statistics import ProcrustesRegistration |
|
|
8 |
|
|
|
9 |
file_path = os.path.abspath(__file__) |
|
|
10 |
# Construct the path to the package directory |
|
|
11 |
package_dir = os.path.dirname(os.path.dirname(os.path.dirname(file_path))) |
|
|
12 |
|
|
|
13 |
LIST_MESH_PATHS = [ |
|
|
14 |
os.path.join( |
|
|
15 |
package_dir, "data", "femur_meshes_registration", f"{idx}_RIGHT_femur_Nov_02_2021.vtk" |
|
|
16 |
) |
|
|
17 |
for idx in range(1, 6) |
|
|
18 |
] |
|
|
19 |
REF_MESH_PATH = LIST_MESH_PATHS.pop(0) |
|
|
20 |
|
|
|
21 |
for path in LIST_MESH_PATHS: |
|
|
22 |
print(os.path.exists(path)) |
|
|
23 |
|
|
|
24 |
|
|
|
25 |
@pytest.mark.skip(reason="Takes too long - and probably still fails?") |
|
|
26 |
def test_ProcrustesRegistration_runs(): |
|
|
27 |
folder_save = os.path.join( |
|
|
28 |
package_dir, "data", "femur_meshes_registration", "registered_meshes" |
|
|
29 |
) |
|
|
30 |
|
|
|
31 |
procrustes_reg = ProcrustesRegistration( |
|
|
32 |
path_ref_mesh=REF_MESH_PATH, # using the idx of the best mesh from the previous step |
|
|
33 |
list_mesh_paths=LIST_MESH_PATHS, # This will automatically remove the ref_mesh path if it is in the list. |
|
|
34 |
max_n_registration_steps=1, |
|
|
35 |
n_coords_spectral_ordering=10000, |
|
|
36 |
n_coords_spectral_registration=1000, |
|
|
37 |
n_extra_spectral=6, |
|
|
38 |
include_points_as_features=True, |
|
|
39 |
vertex_features=["thickness (mm)"], |
|
|
40 |
multiprocessing=True, |
|
|
41 |
verbose=False, |
|
|
42 |
save_meshes_during_registration=True, |
|
|
43 |
folder_save=folder_save, |
|
|
44 |
) |
|
|
45 |
|
|
|
46 |
tic = time.time() |
|
|
47 |
procrustes_reg.execute() |
|
|
48 |
toc = time.time() |
|
|
49 |
|
|
|
50 |
print(f"Time taken for ProcrustesRegistration: {toc - tic} seconds") |
|
|
51 |
|
|
|
52 |
# procrustes_reg.save_meshes(folder=folder_save) |
|
|
53 |
|
|
|
54 |
list_meshes = glob.glob(os.path.join(folder_save, "*.vtk")) |
|
|
55 |
assert len(list_meshes) == len(LIST_MESH_PATHS) |
|
|
56 |
|
|
|
57 |
# delete the folder of registered meshes |
|
|
58 |
os.system(f"rm -r {folder_save}") |
|
|
59 |
|
|
|
60 |
print(procrustes_reg.registered_pt_coords.shape) |
|
|
61 |
print(procrustes_reg.registered_vertex_features.shape) |
|
|
62 |
|
|
|
63 |
|
|
|
64 |
if __name__ == "__main__": |
|
|
65 |
# pytest.main([__file__]) |
|
|
66 |
test_ProcrustesRegistration_runs() |