point_cloud_generator.py
Go to the documentation of this file.
1 # Code example for ICP generating different shapes using the built-in interface
2 import os.path
3 
4 import numpy as np
5 from pypointmatcher import pointmatcher as pm
6 
7 PM = pm.PointMatcher
8 DP = PM.DataPoints
9 Generator = pm.PointCloudGenerator
10 
11 # Path of output directory (default: tests/icp_simple/)
12 # The output directory must already exist
13 # Leave empty to save in the current directory
14 output_base_directory = "tests/generator/"
15 
16 # How many points will each generated shape contain
17 number_of_points = 10000
18 
19 # Toggle to switch between 2D and 3D clouds
20 # Only 3D is currently supported
21 is_3D = True
22 
23 if is_3D:
24  # Load 3D point clouds
25  ref = DP(DP.load('../data/car_cloud400.csv'))
26  data = DP(DP.load('../data/car_cloud401.csv'))
27  test_base = "3D"
28  translation = np.array([[0], [0], [0]])
29  rotation = np.array([1, 0, 0, 0], dtype=np.float32)
30 else:
31  raise Exception("The Point Cloud Generator only supports 3D shapes")
32 
33 box = Generator.generateUniformlySampledBox(1.0, 2.0, 3.0, number_of_points, translation, rotation)
34 circle = Generator.generateUniformlySampledCircle(1.0, number_of_points, translation, rotation)
35 cylinder = Generator.generateUniformlySampledCylinder(1.0, 2.0, number_of_points, translation, rotation)
36 plane = Generator.generateUniformlySampledPlane(np.array([1.0, 2.0, 3.0]), number_of_points, translation, rotation)
37 sphere = Generator.generateUniformlySampledSphere(1.0, number_of_points, translation, rotation)
38 
39 
40 # Save files to see the results
41 if not os.path.exists(output_base_directory):
42  os.makedirs(output_base_directory)
43 
44 box.save(f"{output_base_directory}box.vtk")
45 circle.save(f"{output_base_directory}circle.vtk")
46 cylinder.save(f"{output_base_directory}cylinder.vtk")
47 plane.save(f"{output_base_directory}plane.vtk")
48 sphere.save(f"{output_base_directory}sphere.vtk")
49 
50 print(f"Saved generated shapes into {output_base_directory}")
PointMatcher::DataPoints
A point cloud.
Definition: PointMatcher.h:207


libpointmatcher
Author(s):
autogenerated on Mon Jul 1 2024 02:22:43