@@ -82,17 +82,32 @@ def test_load_points(load_points):
8282def test_points (load_points ):
8383 _ , points_numpy , _ = load_points
8484
85- points = small_gicp .PointCloud (points_numpy )
85+ empty_normals = numpy .array ([])
86+ empty_covs = []
87+ points = small_gicp .PointCloud (points_numpy , empty_normals , empty_covs )
8688 assert points .size () == points_numpy .shape [0 ]
8789 assert numpy .all (numpy .abs (points .points () - points_numpy ) < 1e-6 )
8890
89- points = small_gicp .PointCloud (points_numpy [:, :3 ])
91+ points = small_gicp .PointCloud (points_numpy [:, :3 ], empty_normals , empty_covs )
9092 assert points .size () == points_numpy .shape [0 ]
9193 assert numpy .all (numpy .abs (points .points () - points_numpy ) < 1e-6 )
9294
9395 for i in range (10 ):
9496 assert numpy .all (numpy .abs (points .point (i ) - points_numpy [i ]) < 1e-6 )
95-
97+
98+ # Now test setting and getting pre-determined normals and covariances.
99+ N = 10
100+ points_numpy = numpy .cumsum (numpy .tile (numpy .array ([1.0 , 2.0 , 3.0 ]), (N , 1 )), axis = 0 )
101+ # Like the C++ API, setting non-unit norms and non-positive-definite
102+ # covariances is not enforced, and that's ok.
103+ nonsense_normals = numpy .cumsum (numpy .tile (numpy .array ([4.0 , 5.0 , 6.0 ]), (N , 1 )), axis = 0 )
104+ nonsense_covs = [numpy .array (list (range (9 ))).astype (numpy .float64 ).reshape (3 , 3 ) * i for i in range (N )]
105+ points_with_normals_and_covs = small_gicp .PointCloud (points_numpy , nonsense_normals , nonsense_covs )
106+
107+ assert points_with_normals_and_covs .size () == N
108+ for i in range (points_with_normals_and_covs .size ()):
109+ numpy .testing .assert_equal (points_with_normals_and_covs .cov (i )[:3 , :3 ], nonsense_covs [i ])
110+ numpy .testing .assert_equal (points_with_normals_and_covs .normal (i )[:3 ], nonsense_normals [i ])
96111
97112# Downsampling test
98113def test_downsampling (load_points ):
@@ -103,11 +118,13 @@ def test_downsampling(load_points):
103118
104119 downsampled2 = small_gicp .voxelgrid_sampling (points_numpy , 0.25 , num_threads = 2 )
105120 assert abs (1.0 - downsampled .size () / downsampled2 .size ()) < 0.05
106-
107- downsampled2 = small_gicp .voxelgrid_sampling (small_gicp .PointCloud (points_numpy ), 0.25 )
121+
122+ empty_normals = numpy .array ([])
123+ empty_covs = []
124+ downsampled2 = small_gicp .voxelgrid_sampling (small_gicp .PointCloud (points_numpy , empty_normals , empty_covs ), 0.25 )
108125 assert downsampled .size () == downsampled2 .size ()
109-
110- downsampled2 = small_gicp .voxelgrid_sampling (small_gicp .PointCloud (points_numpy ), 0.25 , num_threads = 2 )
126+
127+ downsampled2 = small_gicp .voxelgrid_sampling (small_gicp .PointCloud (points_numpy , empty_normals , empty_covs ), 0.25 , num_threads = 2 )
111128 assert abs (1.0 - downsampled .size () / downsampled2 .size ()) < 0.05
112129
113130# Preprocess test
@@ -117,13 +134,15 @@ def test_preprocess(load_points):
117134 downsampled , _ = small_gicp .preprocess_points (points_numpy , downsampling_resolution = 0.25 )
118135 assert downsampled .size () > 0
119136
137+ empty_normals = numpy .array ([])
138+ empty_covs = []
120139 downsampled2 , _ = small_gicp .preprocess_points (points_numpy , downsampling_resolution = 0.25 , num_threads = 2 )
121140 assert abs (1.0 - downsampled .size () / downsampled2 .size ()) < 0.05
122-
123- downsampled2 , _ = small_gicp .preprocess_points (small_gicp .PointCloud (points_numpy ), downsampling_resolution = 0.25 )
141+
142+ downsampled2 , _ = small_gicp .preprocess_points (small_gicp .PointCloud (points_numpy , empty_normals , empty_covs ), downsampling_resolution = 0.25 )
124143 assert downsampled .size () == downsampled2 .size ()
125-
126- downsampled2 , _ = small_gicp .preprocess_points (small_gicp .PointCloud (points_numpy ), downsampling_resolution = 0.25 , num_threads = 2 )
144+
145+ downsampled2 , _ = small_gicp .preprocess_points (small_gicp .PointCloud (points_numpy , empty_normals , empty_covs ), downsampling_resolution = 0.25 , num_threads = 2 )
127146 assert abs (1.0 - downsampled .size () / downsampled2 .size ()) < 0.05
128147
129148# Voxelmap test
0 commit comments