8 from pypointmatcher
import pointmatcher
as pm, pointmatchersupport
as pms
11 PMIO = pm.PointMatcherIO
13 params = pms.Parametrizable.Parameters()
18 output_base_directory =
"tests/align_sequence/"
21 output_file_name =
"align_sequence"
24 rigid_trans = PM.get().TransformationRegistrar.create(
"RigidTransformation")
28 params[
"epsilon"] =
"5"
29 params[
"keepNormals"] =
"0"
30 params[
"keepDensities"] =
"1"
31 density_filter = PM.get().DataPointsFilterRegistrar.create(
"SurfaceNormalDataPointsFilter", params)
34 params[
"maxDensity"] =
"30"
35 max_density_subsample = PM.get().DataPointsFilterRegistrar.create(
"MaxDensityDataPointsFilter",
43 config_file =
"../data/default.yaml"
45 icp.loadFromYaml(config_file)
52 map_point_cloud =
DP()
55 T_to_map_from_new = np.identity(4)
57 for i
in range(len(file_info_list)):
58 print(f
"---------------------\nLoading: {file_info_list[i].readingFileName}")
61 new_cloud = DP.load(file_info_list[i].readingFileName)
63 if map_point_cloud.getNbPoints() == 0:
64 map_point_cloud = new_cloud
72 prior = T_to_map_from_new
74 T_to_map_from_new =
icp(new_cloud, map_point_cloud, prior)
76 except PM.ConvergenceError
as CE:
77 print(f
"ERROR PM.ICP failed to converge: \n\t{CE}\n\n")
82 T_to_map_from_new = rigid_trans.correctParameters(T_to_map_from_new)
85 new_cloud = rigid_trans.compute(new_cloud, T_to_map_from_new)
88 map_point_cloud.concatenate(new_cloud)
91 map_point_cloud = density_filter.filter(map_point_cloud)
92 map_point_cloud = max_density_subsample.filter(map_point_cloud)
95 output_file_name_iter = f
"{output_file_name}_{i}.vtk"
96 print(f
"outputFileName: {output_file_name_iter}")
97 map_point_cloud.save(f
"{output_base_directory}{output_file_name_iter}")