Wildmeshing Toolkit
Loading...
Searching...
No Matches
input.cpp
Go to the documentation of this file.
1#include "input.hpp"
2
3#include <fstream>
8#include "InputOptions.hpp"
9
11
12std::shared_ptr<Mesh> input(
13 const std::filesystem::path& file,
14 const bool ignore_z_if_zero,
15 const std::vector<std::string>& tetrahedron_attributes)
16{
17 InputOptions options;
18 options.old_mode = true;
19 options.file = file;
20 options.ignore_z_if_zero = ignore_z_if_zero;
21 if (!tetrahedron_attributes.empty()) {
22 options.imported_attributes = {{}, {}, {}, tetrahedron_attributes};
23 }
24 return input(options).root().shared_from_this();
25}
26
27
29{
30 return input(options, {});
31}
33 const InputOptions& options,
34 const components::utils::PathResolver& resolver)
35{
36 const auto [file_path, found] = resolver.resolve(options.file);
37 if (!found) {
38 const auto& paths = resolver.get_paths();
39 std::vector<std::string> path_strs;
40 std::transform(
41 paths.begin(),
42 paths.end(),
43 std::back_inserter(path_strs),
44 [](const std::filesystem::path& p) { return p.string(); });
45
47 "file [{}] not found (input path was [{}], paths searched were [{}]",
48 file_path.string(),
49 options.file.string(),
50 fmt::join(path_strs, ","));
51 }
52
53 std::shared_ptr<Mesh> mesh;
54
55 if (options.old_mode) {
56 if (options.imported_attributes.has_value()) {
58 file_path,
59 options.ignore_z_if_zero,
60 options.imported_attributes->at(3));
61 } else {
62 mesh = wmtk::io::read_mesh(file_path, options.ignore_z_if_zero);
63 }
64 } else {
65 if (options.imported_attributes.has_value()) {
66 mesh = wmtk::io::read_mesh(file_path, options.imported_attributes.value());
67 } else {
68 mesh = wmtk::io::read_mesh(file_path);
69 }
70 }
71 assert(mesh->is_connectivity_valid());
72
73
75 mm.set_mesh(*mesh);
76 if (!options.name_spec.is_null()) {
77 mm.set_names(options.name_spec);
78 } else if (options.name_spec_file.has_value()) {
79 std::ifstream ifs(options.name_spec_file.value());
80 nlohmann::json js;
81 ifs >> js;
82 mm.set_names(js);
83 }
84
85 return mm;
86}
87} // namespace wmtk::components::input
std::optional< std::vector< std::vector< std::string > > > imported_attributes
std::optional< std::filesystem::path > name_spec_file
void set_mesh(Mesh &m)
Navigates to the root of the multimesh.
void set_names(const nlohmann::json &js)
std::vector< std::filesystem::path > get_paths() const
std::pair< std::filesystem::path, bool > resolve(const std::filesystem::path &path) const
std::shared_ptr< Mesh > input(const std::filesystem::path &file, const bool ignore_z_if_zero, const std::vector< std::string > &tetrahedron_attributes)
Definition input.cpp:12
std::shared_ptr< Mesh > read_mesh(const std::filesystem::path &filename, FileType file_type)
Definition read_mesh.cpp:35
void log_and_throw_error(const std::string &msg)
Definition Logger.cpp:101