| | |
| | | from pathlib import Path |
| | | |
| | | import laspy |
| | | import numpy as np |
| | | |
| | | sys.path.insert(0, str(Path(__file__).resolve().parents[1])) |
| | | from apply_pointcloud_semantic_model import load_cloud # noqa: E402 |
| | | from apply_pointcloud_semantic_model import load_cloud, write_prediction_preview # noqa: E402 |
| | | |
| | | |
| | | class ApplyPointCloudSemanticModelTests(unittest.TestCase): |
| | |
| | | with self.assertRaisesRegex(ValueError, "没有可读取的点"): |
| | | load_cloud(source) |
| | | |
| | | def test_prediction_preview_retains_stable_classification_property(self) -> None: |
| | | with tempfile.TemporaryDirectory() as directory: |
| | | output = Path(directory) / "prediction.ply" |
| | | write_prediction_preview( |
| | | output, |
| | | np.asarray([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], dtype=np.float32), |
| | | np.asarray([5, 15], dtype=np.uint8), |
| | | {5: {"color": [59, 163, 87]}, 15: {"color": [149, 89, 210]}}, |
| | | ) |
| | | |
| | | header, records = output.read_bytes().split(b"end_header\n", maxsplit=1) |
| | | self.assertIn(b"property uchar classification", header) |
| | | self.assertEqual(len(records), 2 * 16) |
| | | self.assertEqual(records[15], 5) |
| | | self.assertEqual(records[31], 15) |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | unittest.main() |