def test_cwipc_new_encoder_bad_parameters(self): """Do we get exceptions when creating an encoder with unimplemented parameters?""" with self.assertRaises(cwipc.CwipcError): encoder = _cwipc_codec.cwipc_new_encoder(do_inter_frame=True) with self.assertRaises(cwipc.CwipcError): encoder = _cwipc_codec.cwipc_new_encoder(gop_size=0) with self.assertRaises(cwipc.CwipcError): encoder = _cwipc_codec.cwipc_new_encoder(gop_size=2)
def test_cwipc_encoder_octree_depth(self): """Test that octree_bits encoder param makes a significant difference""" pc = cwipc.cwipc_read(PLY_FILENAME, 1234) decoder = _cwipc_codec.cwipc_new_decoder() depth = 11 decoded_npoints_per_depth = {} cellsize_per_depth = {} while depth >= 0: encoder = _cwipc_codec.cwipc_new_encoder(octree_bits=depth) encoder.feed(pc) encoded_data = encoder.get_bytes() encoded_size = len(encoded_data) decoder.feed(encoded_data) assert decoder.available(True) decoded_pc = decoder.get() points = decoded_pc.get_points() decoded_npoints = len(points) decoded_npoints_per_depth[depth] = decoded_npoints cellsize_per_depth[depth] = decoded_pc.cellsize() encoder.free() decoded_pc.free() depth = depth - 1 # Some sanity checks for i in range(11): self.assertLessEqual(decoded_npoints_per_depth[i], decoded_npoints_per_depth[i + 1]) for i in range(11): self.assertGreater(cellsize_per_depth[i], cellsize_per_depth[i + 1]) if decoded_npoints_per_depth[11] < 80000: self.assertLessEqual(decoded_npoints_per_depth[0], 16) else: self.assertLessEqual(decoded_npoints_per_depth[0], decoded_npoints_per_depth[11] / 10000) pc.free()
def test_cwipc_encoder_close(self): """Can we close a encoder""" encoder = _cwipc_codec.cwipc_new_encoder() self.assertFalse(encoder.eof()) self.assertFalse(encoder.available(False)) encoder.close() self.assertTrue(encoder.eof()) self.assertFalse(encoder.available(True)) encoder.free()
def test_cwipc_encoder_plyfile_multiple_same(self): """Test that we can encode a ply file multiple times and the results are the same""" pc = cwipc.cwipc_read(PLY_FILENAME, 1234) encoder = _cwipc_codec.cwipc_new_encoder() encoder.feed(pc) data_one = encoder.get_bytes() encoder.feed(pc) data_two = encoder.get_bytes() self.assertEqual(data_one, data_two) encoder.free() pc.free()
def test_cwipc_encoder_plyfile(self): """Test that we can encode a PLY file and the available flags behaves correct""" pc = cwipc.cwipc_read(PLY_FILENAME, 1234) self._verify_pointcloud(pc) encoder = _cwipc_codec.cwipc_new_encoder() self.assertFalse(encoder.available(False)) encoder.feed(pc) self.assertTrue(encoder.available(False)) self.assertTrue(encoder.at_gop_boundary()) data = encoder.get_bytes() self.assertNotEqual(len(data), 0) self.assertFalse(encoder.available(False)) encoder.free() pc.free()
def test_cwipc_encoder_plyfile_multiple_different(self): """Test that we can encode a ply file multiple times and the results are the same, and different for different timestamps""" pc = cwipc.cwipc_read(PLY_FILENAME, 1234) encoder = _cwipc_codec.cwipc_new_encoder() encoder.feed(pc) data_one = encoder.get_bytes() pc3 = cwipc.cwipc_read(PLY_FILENAME, 4567) encoder.feed(pc3) data_three = encoder.get_bytes() self.assertNotEqual(data_one, data_three) encoder.free() pc.free() pc3.free()
def test_cwipc_encoder_jpeg_quality(self): """Test that jpeg_quality encoder param makes a difference""" pc = cwipc.cwipc_read(PLY_FILENAME, 1234) quality = 90 prev_size = None while quality >= 10: params = _cwipc_codec.cwipc_new_encoder_params( jpeg_quality=quality) encoder = _cwipc_codec.cwipc_new_encoder(params=params) encoder.feed(pc) encoded_data = encoder.get_bytes() encoded_size = len(encoded_data) if prev_size != None: self.assertLess(encoded_size, prev_size) prev_size = encoded_size encoder.free() quality = quality - 10 pc.free()
def test_cwipc_codec_roundtrip(self): """Check that we can roundtrip encoder-decoder and get at most as many points back""" timestamp = 0x1122334455667788 pc = cwipc.cwipc_read(PLY_FILENAME, timestamp) encoder = _cwipc_codec.cwipc_new_encoder() decoder = _cwipc_codec.cwipc_new_decoder() encoder.feed(pc) data = encoder.get_bytes() decoder.feed(data) pc2 = decoder.get() self._verify_pointcloud(pc2) points = pc.get_points() points2 = pc2.get_points() self.assertGreaterEqual(len(points), len(points2)) self.assertEqual(pc2.timestamp(), timestamp) encoder.free() decoder.free() pc.free() pc2.free()
def test_cwipc_codec_roundtrip_empty(self): """Check that we can roundtrip an empty pointcloud""" timestamp = 0x2233445566778899 pc = cwipc.cwipc_from_points([], timestamp) encoder = _cwipc_codec.cwipc_new_encoder() decoder = _cwipc_codec.cwipc_new_decoder() encoder.feed(pc) data = encoder.get_bytes() self.assertNotEqual(len(data), 0) decoder.feed(data) pc2 = decoder.get() points = pc.get_points() points2 = pc2.get_points() self.assertEqual(len(points), 0) self.assertEqual(len(points2), 0) self.assertEqual(pc2.timestamp(), timestamp) encoder.free() decoder.free() pc.free() pc2.free()
def test_cwipc_new_encoder(self): """Can we create and free a cwipc_encoder object""" encoder = _cwipc_codec.cwipc_new_encoder() self.assertFalse(encoder.eof()) self.assertFalse(encoder.available(False)) encoder.free()