MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / main

Function main

examples/python-examples/GlobalRegistration.dox.py:20–65  ·  view source on GitHub ↗
(argv)

Source from the content-addressed store, hash-verified

18
19
20def main(argv):
21 if len(argv) < 4:
22 print(f"Usage for script: {argv[0]} INPUT1 INPUT2 [INPUTS...] OUTPUT")
23 return
24 file_args = argv[1:]
25
26 # the global registration can be applied to meshes and point clouds
27 # to simplify the sample app, we will work with point clouds only
28 input_clouds_num = len(file_args) - 1
29 inputs = []
30 # as ICP and MultiwayICP classes accept both meshes and point clouds,
31 # the input data must be converted to special wrapper objects
32 # NB: the wrapper objects hold *references* to the source data, NOT their copies
33 max_bbox = None
34 for i in range(input_clouds_num):
35 points = mrmeshpy.loadPoints(file_args[i])
36 # you may also set an affine transformation for each input as a second argument
37 inputs.append(mrmeshpy.MeshOrPointsXf(points, mrmeshpy.AffineXf3f()))
38
39 bbox = points.getBoundingBox()
40 if not max_bbox or bbox.volume() > max_bbox.volume():
41 max_bbox = bbox
42
43 # you can set various parameters for the global registration; see the documentation for more info
44 sampling_params = mrmeshpy.MultiwayICPSamplingParameters()
45 # set sampling voxel size
46 sampling_params.samplingVoxelSize = max_bbox.diagonal() * 0.03
47
48 icp = mrmeshpy.MultiwayICP(mrmeshpy.Vector_MeshOrPointsXf_ObjId(inputs), sampling_params)
49 icp.setParams(mrmeshpy.ICPProperties())
50
51 # gather statistics
52 icp.updateAllPointPairs()
53 print_stats(icp)
54
55 print("Calculating transformations...")
56 xfs = icp.calculateTransformations()
57 print_stats(icp)
58
59 output = mrmeshpy.PointCloud()
60 for i in range(input_clouds_num):
61 xf = xfs.vec_[i]
62 for point in inputs[i].obj.points():
63 output.addPoint(xf(point))
64
65 mrmeshpy.PointsSave.toAnySupportedFormat(output, file_args[-1])
66
67
68main(sys.argv)

Callers 1

Calls 9

updateAllPointPairsMethod · 0.95
addPointMethod · 0.95
print_statsFunction · 0.85
MultiwayICPMethod · 0.80
getBoundingBoxMethod · 0.45
volumeMethod · 0.45
diagonalMethod · 0.45
setParamsMethod · 0.45

Tested by

no test coverage detected