def setUp(self): self.useLocal = False if self.useLocal: self.tempdir = tempdir = '.' else: self.tempdir = tempdir = mkdtemp(prefix='patty-analytics') self.drivemapLas = os.path.join(tempdir, 'testDriveMap.las') self.sourcelas = os.path.join(tempdir, 'testSource.las') self.footprint_csv = os.path.join(tempdir, 'testFootprint.csv') self.foutlas = os.path.join(tempdir, 'testOutput.las') self.min = -10 self.max = 10 self.num_rows = 1000 # Create plane with a pyramid dm_pct = 0.5 dm_rows = np.round(self.num_rows * dm_pct) dm_min = self.min * dm_pct dm_max = self.max * dm_pct delta = dm_max / dm_rows shape_side = dm_max - dm_min dm_offset = [0, 0, 0] self.dense_obj_offset = [3, 2, -(1 + shape_side / 2)] # make drivemap plane_row = np.linspace(start=self.min, stop=self.max, num=self.num_rows) plane_points = cartesian((plane_row, plane_row, [0])) shape_points, footprint = make_tri_pyramid_with_base( shape_side, delta, dm_offset) np.savetxt(self.footprint_csv, footprint, fmt='%.3f', delimiter=',') dm_points = np.vstack([plane_points, shape_points]) plane_grid = np.zeros((dm_points.shape[0], 6), dtype=np.float32) plane_grid[:, 0:3] = dm_points self.drivemap_pc = pcl.PointCloudXYZRGB(plane_grid) self.drivemap_pc = downsample_voxel(self.drivemap_pc, voxel_size=delta * 20) # utils.set_registration(self.drivemap_pc) utils.save(self.drivemap_pc, self.drivemapLas) # Create a simple pyramid dense_grid = np.zeros((shape_points.shape[0], 6), dtype=np.float32) dense_grid[:, 0:3] = shape_points + self.dense_obj_offset self.source_pc = pcl.PointCloudXYZRGB(dense_grid) self.source_pc = downsample_voxel(self.source_pc, voxel_size=delta * 5) utils.save(self.source_pc, self.sourcelas)
def test_filter(): ''' Test Voxel Grid Filter functionality ''' side = 10 delta = 0.05 offset = [-5, -5, 0] points, footprint = make_tri_pyramid_with_base(side, delta, offset) pc = pcl.PointCloudXYZRGB(points.astype(np.float32)) # Build Voxel Grid Filter vgf = pc.make_voxel_grid_filter() # Filter with Voxel size 1 vgf.set_leaf_size(1, 1, 1) pc2 = vgf.filter() # Filter with Voxel size 0.1 vgf.set_leaf_size(0.1, 0.1, 0.1) pc3 = vgf.filter() # Filter with Voxel size 10 vgf.set_leaf_size(10, 10, 10) pc4 = vgf.filter() assert_greater(len(pc), len(pc2)) assert_greater(len(pc3), len(pc2)) assert_greater(len(pc), len(pc4))
def test_centered_line_on_x_axis(): '''Test get_red_mask function from patty.segmentation.segRedStick''' # Arrange ar = np.asarray( [[0, 0, 0, 210, 25, 30], [0, 0, 0, 0, 0, 150], [0, 0, 0, 0, 150, 70]], dtype=np.float32) pc = pcl.PointCloudXYZRGB(ar) expected = 1 # Act reds = get_red_mask(pc) # Assert assert_almost_equal(sum(reds), expected)
def _load_las(lasfile): """Read a LAS file Returns: registered pointcloudxyzrgb The pointcloud has color and XYZ coordinates, and the offset and precision set. """ _check_readable(lasfile) las = None try: las = liblas.file.File(lasfile) lsrs = las.header.get_srs() lsrs = lsrs.get_wkt() n_points = las.header.get_count() precise_points = np.zeros((n_points, 6), dtype=np.float64) for i, point in enumerate(las): precise_points[i] = (point.x, point.y, point.z, point.color.red / 256, point.color.green / 256, point.color.blue / 256) # reduce the offset to decrease floating point errors bbox = BoundingBox(points=precise_points[:, 0:3]) center = bbox.center precise_points[:, 0:3] -= center pointcloud = pcl.PointCloudXYZRGB(precise_points.astype(np.float32)) force_srs(pointcloud, srs=lsrs, offset=center) finally: if las is not None: las.close() return pointcloud
def setUp(self): self.pc = pcl.PointCloudXYZRGB( [[0.0, 0.0, 0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]])
def make_pointcloud(sticks, noise): data = np.array(np.concatenate(sticks, axis=0), dtype=np.float32) _add_noise(data, noise, np.random.RandomState(0)) pc = pcl.PointCloudXYZRGB(data) return extract_mask(pc, get_red_mask(pc))
def test_stickscale_nocluster(noise): '''Cloud without clusters should return zero confidence.''' pc = pcl.PointCloudXYZRGB([[0, 0, 0], [10000, 10000, 10000]]) meter, confidence = get_stick_scale(pc) np.testing.assert_almost_equal(confidence, 0.0)
def test_stickscale_emptycloud(noise): '''Cloud with zero point should return zero confidence.''' pc = pcl.PointCloudXYZRGB() meter, confidence = get_stick_scale(pc) np.testing.assert_almost_equal(confidence, 0.0)