9 from pypointmatcher
import pointmatcher
as pm, pointmatchersupport
as pms
12 PMIO = pm.PointMatcherIO
14 params = pms.Parametrizable.Parameters()
18 total_point_count = 30000
23 output_base_directory =
"tests/build_map/"
26 output_file_name =
"test.vtk"
37 transformation = PM.get().TransformationRegistrar.create(
"RigidTransformation")
40 params[
"minDist"] =
"1.0"
41 remove_scanner = PM.get().DataPointsFilterRegistrar.create(
"MinDistDataPointsFilter", params)
45 params[
"prob"] =
"0.65"
46 rand_subsample = PM.get().DataPointsFilterRegistrar.create(
"RandomSamplingDataPointsFilter", params)
52 params[
"epsilon"] =
"5"
53 params[
"keepNormals"] =
"1"
54 params[
"keepDensities"] =
"0"
55 normal_filter = PM.get().DataPointsFilterRegistrar.create(
"SurfaceNormalDataPointsFilter", params)
59 params[
"epsilon"] =
"5"
60 params[
"keepDensities"] =
"1"
61 params[
"keepNormals"] =
"0"
62 density_filter = PM.get().DataPointsFilterRegistrar.create(
"SurfaceNormalDataPointsFilter", params)
65 observation_direction_filter = PM.get().DataPointsFilterRegistrar.create(
"ObservationDirectionDataPointsFilter")
67 params[
"towardCenter"] =
"1"
68 orien_normal_filter = PM.get().DataPointsFilterRegistrar.create(
"OrientNormalsDataPointsFilter", params)
71 params[
"maxDensity"] =
"30"
72 uniform_subsample = PM.get().DataPointsFilterRegistrar.create(
"MaxDensityDataPointsFilter", params)
75 shadow_filter = PM.get().DataPointsFilterRegistrar.create(
"ShadowDataPointsFilter")
77 for i
in range(len(file_info_list)):
78 print(
"\n-----------------------------")
79 print(f
"Loading {file_info_list[i].readingFileName} ", end=
"")
81 new_cloud = DP.load(file_info_list[i].readingFileName)
83 print(f
"found {new_cloud.getNbPoints()} points.")
85 if file_info_list[i].groundTruthTransformation.shape[0] != 0:
86 T = file_info_list[i].groundTruthTransformation
88 print(
"ERROR: the field gTXX (ground truth) is required")
92 new_cloud = remove_scanner.filter(new_cloud)
95 new_cloud = rand_subsample.filter(new_cloud)
98 new_cloud = normal_filter.filter(new_cloud)
99 new_cloud = observation_direction_filter.filter(new_cloud)
100 new_cloud = orien_normal_filter.filter(new_cloud)
101 new_cloud = shadow_filter.filter(new_cloud)
104 print(f
"Transformation matrix:\n{T}\n".replace(
"[",
" ").replace(
"]",
" "), end=
"")
105 new_cloud = transformation.compute(new_cloud, T)
108 map_cloud = new_cloud
110 map_cloud.concatenate(new_cloud)
113 prob_to_keep = total_point_count / map_cloud.features.shape[1]
116 map_cloud = density_filter.filter(map_cloud)
117 map_cloud = uniform_subsample.filter(map_cloud)
119 prob_to_keep = total_point_count / map_cloud.features.shape[1]
122 print(f
"Randomly keep {prob_to_keep * 100}% points")
124 rand_subsample = PM.get().DataPointsFilterRegistrar.create(
125 "RandomSamplingDataPointsFilter",
126 {
"prob": f
"{prob_to_keep}"})
128 map_cloud = rand_subsample.filter(map_cloud)
130 map_cloud.save(f
"{output_base_directory + output_file_name[:-4]}_{i}.vtk")
132 map_cloud = density_filter.filter(map_cloud)
133 map_cloud = uniform_subsample.filter(map_cloud)
134 map_cloud = density_filter.filter(map_cloud)
136 print(
"\n-----------------------------"*2)
137 print(f
"Final number of points in the map: {map_cloud.getNbPoints()}")
139 map_cloud.save(f
"{output_base_directory + output_file_name}")