1use crate::{
2 FILE_EXTENSION_E57_FORMAT, FILE_EXTENSION_EPOINT_FORMAT, FILE_EXTENSION_EPOINT_TAR_FORMAT,
3 FILE_EXTENSION_LAS_FORMAT, FILE_EXTENSION_LAZ_FORMAT, FILE_EXTENSION_XYZ_FORMAT,
4 FILE_EXTENSION_XYZ_ZST_FORMAT,
5};
6use std::path::Path;
7
8#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
9pub enum PointCloudFormat {
10 Epoint,
11 EpointTar,
12 E57,
13 Las,
14 Laz,
15 Xyz,
16 XyzZst,
17}
18
19impl PointCloudFormat {
20 pub fn from_path(path: impl AsRef<Path>) -> Option<PointCloudFormat> {
21 let path_str = path.as_ref().file_name()?.to_string_lossy().to_lowercase();
22
23 match path_str {
24 s if s.ends_with(FILE_EXTENSION_EPOINT_FORMAT) => Some(PointCloudFormat::Epoint),
25 s if s.ends_with(FILE_EXTENSION_EPOINT_TAR_FORMAT) => Some(PointCloudFormat::EpointTar),
26 s if s.ends_with(FILE_EXTENSION_E57_FORMAT) => Some(PointCloudFormat::E57),
27 s if s.ends_with(FILE_EXTENSION_LAS_FORMAT) => Some(PointCloudFormat::Las),
28 s if s.ends_with(FILE_EXTENSION_LAZ_FORMAT) => Some(PointCloudFormat::Laz),
29 s if s.ends_with(FILE_EXTENSION_XYZ_FORMAT) => Some(PointCloudFormat::Xyz),
30 s if s.ends_with(FILE_EXTENSION_XYZ_ZST_FORMAT) => Some(PointCloudFormat::XyzZst),
31 _ => None,
32 }
33 }
34
35 pub fn extension(&self) -> &'static str {
36 match self {
37 PointCloudFormat::Epoint => FILE_EXTENSION_EPOINT_FORMAT,
38 PointCloudFormat::EpointTar => FILE_EXTENSION_EPOINT_TAR_FORMAT,
39 PointCloudFormat::E57 => FILE_EXTENSION_E57_FORMAT,
40 PointCloudFormat::Las => FILE_EXTENSION_LAS_FORMAT,
41 PointCloudFormat::Laz => FILE_EXTENSION_LAZ_FORMAT,
42 PointCloudFormat::Xyz => FILE_EXTENSION_XYZ_FORMAT,
43 PointCloudFormat::XyzZst => FILE_EXTENSION_XYZ_ZST_FORMAT,
44 }
45 }
46
47 pub fn is_supported_point_cloud_format(path: impl AsRef<Path>) -> bool {
48 if !path.as_ref().is_file() {
49 return false;
50 }
51
52 PointCloudFormat::from_path(&path).is_some()
53 }
54}