Utilities
Utilities header only library
FileTypes.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef UTILS_FILE_TYPES_H
7 #define UTILS_FILE_TYPES_H
8 
9 #include <string>
10 #include <vector>
11 #include <map>
12 
13 #include <Utils/ExtSTD.h>
14 
15 
17 namespace file_types
18 {
33  enum class Type : uint8_t
34  {
35  // 3d objects
36  praw,
37  cogs,
38  ply,
39  obj,
40  dae,
41  stl,
42  fbx,
43  bvh,
44  // images
45  jpg,
46  png,
47  gif,
48  bmp,
49  exr,
50  __count
51  };
52 
53 
54 
56  static const std::map<Type, std::string> file_extensions =
57  {
58  { Type::praw, "praw" },
59  { Type::cogs, "cogs" },
60  { Type::ply, "ply" },
61  { Type::obj, "obj" },
62  { Type::dae, "dae" },
63  { Type::stl, "stl" },
64  { Type::fbx, "fbx" },
65  { Type::bvh, "bvh" },
66  { Type::jpg, "jpg" },
67  { Type::png, "png" },
68  { Type::gif, "gif" },
69  { Type::bmp, "bmp" },
70  { Type::exr, "exr" },
71  };
72 
74  static const std::vector<Type> all_types = std_ext::Transformed(
75  file_extensions,
76  [](const std::pair<Type, std::string> &pair)->Type { return pair.first; });
77 
78 
79 
84  static const std::vector<Type> importable_scan_types
85  {
86  Type::praw,
87  Type::cogs,
88  Type::ply,
89  };
90 
94  static const std::vector<Type> exportable_scan_types
95  {
96  Type::cogs,
97  Type::ply,
98  Type::exr,
99  };
100 
101  static const std::vector<Type> exr_types
102  {
103  Type::exr,
104  };
105 
110  static const std::vector<Type> importable_point_cloud_types
111  {
112  Type::cogs,
113  Type::obj,
114  Type::fbx,
115  Type::ply,
116  };
117 
121  static const std::vector<Type> exportable_point_cloud_types
122  {
123  Type::cogs,
124  Type::obj,
125  Type::fbx,
126  Type::ply,
127  };
128 
133  static const std::vector<Type> importable_mesh_types
134  {
135  Type::cogs,
136  Type::dae,
137  Type::obj,
138  Type::fbx,
139  Type::ply,
140  Type::stl,
141  };
142 
146  static const std::vector<Type> exportable_mesh_types
147  {
148  Type::cogs,
149  Type::dae,
150  Type::obj,
151  Type::fbx,
152  Type::ply,
153  Type::stl,
154  };
155 
157  static const std::vector<Type> image_types
158  {
159  Type::jpg,
160  Type::png,
161  Type::gif,
162  Type::bmp,
163  Type::exr,
164  };
165 
169  static const std::vector<Type> assimp_importable_types
170  {
171  Type::bvh,
172  Type::dae,
173  Type::obj,
174  Type::fbx,
175  Type::ply,
176  Type::stl
177  };
178 
182  static const std::vector<Type> cogs_types
183  {
184  Type::cogs,
185  };
186 
187 
189  [[nodiscard]]
190  static inline std::string GetExt(const Type type)
191  {
192  if (std_ext::Contains(type, file_extensions))
193  {
194  return file_extensions.at(type);
195  }
196  return "";
197  }
198 
200  [[nodiscard]] static inline std::optional<file_types::Type> GetType(const std::string &filename)
201  {
202  static const std::unordered_map<std::string, Type> type_for_ext = []()
203  {
204  std::unordered_map<std::string, Type> type_map;
205  for (uint8_t i = 0; i < static_cast<uint8_t>(Type::__count); ++i)
206  {
207  const auto type = static_cast<Type>(i);
208  type_map[GetExt(type)] = type;
209  }
210  return type_map;
211  }
212  ();
213  const auto ext = std_ext::Lowercase(filename.substr(filename.find_last_of('.') + 1));
214  if (std_ext::Contains(ext, type_for_ext))
215  {
216  return type_for_ext.at(ext);
217  }
218  return std::nullopt;
219  }
220 
222  [[nodiscard]]
223  static inline bool IsType(const std::string &ext, file_types::Type type)
224  {
225  const auto etype = GetType(ext);
226  return etype.has_value() && etype == type;
227  }
228 
229 }
230 
231 #endif /* !UTILS_FILE_TYPES_H */
std::string Lowercase(const std::string &text)
Converts text into all lowercase.
Definition: ExtSTD.h:311
bool Contains(const std::string &substring, const std::string &text)
Checks if the text contains substring.
Definition: ExtSTD.h:327
Type
Enum class that specifies (geometry) file types that we recognize.
Definition: FileTypes.h:33
Definitions and functions for file types supported by codebase.
Definition: FileTypes.h:17
auto Transformed(const C &container, F Function)
Simplified wrapper for std::transform.
Definition: ExtSTD.h:831