PointCloudCrafter
Loading...
Searching...
No Matches
formats.hpp
1/*
2 * Copyright 2024 Markus Pielmeier, Florian Sauerbeck,
3 * Dominik Kulmer, Maximilian Leitenstern
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
20#include <string>
21
22namespace pointcloudcrafter::tools::formats
23{
27enum class FileFormat
28{
29 PCD,
30 PLY,
31 TXT,
32 KITTI,
33 NUSCENES,
34 OBJ
35};
41inline std::string format_to_extension(FileFormat format)
42{
43 switch (format) {
44 case FileFormat::PCD: return ".pcd";
45 case FileFormat::PLY: return ".ply";
46 case FileFormat::TXT: return ".txt";
47 case FileFormat::KITTI: return ".bin";
48 case FileFormat::NUSCENES: return ".pcd.bin";
49 case FileFormat::OBJ: return ".obj";
50 default: return ".pcd";
51 }
52}
64inline bool matches_format(const std::filesystem::path & path, FileFormat format)
65{
66 std::string ext = path.extension().string();
67
68 if (format == FileFormat::NUSCENES) {
69 // Check for .pcd.bin
70 if (ext == ".bin") {
71 std::string stem = path.stem().string();
72 return stem.size() > 4 && stem.substr(stem.size() - 4) == ".pcd";
73 }
74 return false;
75 }
76
77 if (format == FileFormat::KITTI) {
78 // .bin but NOT .pcd.bin
79 if (ext == ".bin") {
80 std::string stem = path.stem().string();
81 return stem.size() <= 4 || stem.substr(stem.size() - 4) != ".pcd";
82 }
83 return false;
84 }
85
86 return ext == format_to_extension(format);
87}
93inline std::string get_stem(const std::filesystem::path & path)
94{
95 std::string ext = path.extension().string();
96 std::string stem = path.stem().string();
97
98 // Handle .pcd.bin case (nuscenes)
99 if (ext == ".bin" && stem.size() > 4 && stem.substr(stem.size() - 4) == ".pcd") {
100 return stem.substr(0, stem.size() - 4);
101 }
102
103 return stem;
104}
105} // namespace pointcloudcrafter::tools::formats