Wildmeshing Toolkit
Loading...
Searching...
No Matches
input.cpp
Go to the documentation of this file.
1#include <catch2/catch_test_macros.hpp>
2#include <nlohmann/json.hpp>
6#include <wmtk/io/Cache.hpp>
8
9using json = nlohmann::json;
10
11namespace {
12const std::filesystem::path data_dir = WMTK_DATA_DIR;
13}
14
15TEST_CASE("component_input", "[components][input]")
16{
17 SECTION("should pass")
18 {
19 const std::filesystem::path input_file = data_dir / "small.msh";
20
21
22 CHECK_NOTHROW(wmtk::components::input::input(input_file, false, {}));
23 auto a = wmtk::components::input::input(input_file, false, {});
24
25 json component_json = {
26 {"file", input_file.string()},
27 {"old_mode", true},
28 {"ignore_z", false},
29 {"tetrahedron_attributes", json::array()}};
30 auto opts = component_json.get<wmtk::components::input::InputOptions>();
31 CHECK(opts.file == input_file);
32 CHECK(opts.ignore_z_if_zero == false);
33 CHECK(opts.old_mode == true);
34 CHECK(opts.old_mode == true);
35 REQUIRE(opts.imported_attributes.has_value());
36 CHECK(opts.imported_attributes.value().size() == 4);
37 json js2 = opts;
38 for (const auto& v : opts.imported_attributes.value()) {
39 CHECK(v.size() == 0);
40 }
41
42 CHECK(js2 == component_json);
43
44 auto b = wmtk::components::input::input(opts);
45
46 CHECK(*a == b.root());
47 }
48
49 {
50 nlohmann::json js = "path";
51 REQUIRE(js.is_string());
52 auto opts = js.get<wmtk::components::input::InputOptions>();
53 CHECK(opts.file.string() == "path");
54 }
55
56 SECTION("should throw")
57 {
58 // json component_json = {
59 // {"type", "input"},
60 // {"name", "input_mesh"},
61 // {"file", "In case you ever name your file like that: What is wrong with
62 // you?"},
63 // {"ignore_z", false},
64 // {"tetrahedron_attributes", json::array()}};
65
66 CHECK_THROWS(wmtk::components::input::input("no file exists at this path", false));
67 }
68}
69
70TEST_CASE("component_input_point", "[components][input][.]")
71{
72 const std::filesystem::path input_path = data_dir / "point_clouds" / "bunny_pts.msh";
73 CHECK_NOTHROW(wmtk::components::input::input(input_path));
74}
75
76TEST_CASE("mesh_with_tag_from_image", "[components][input]")
77{
78 using namespace wmtk;
79 io::Cache cache("wmtk_cache", std::filesystem::current_path());
80
81 std::filesystem::path img_path = data_dir / "images/half_white_half_black.png";
82
83 const std::string tag_name = "img_tag";
84
85 std::shared_ptr<TriMesh> m;
86
87 REQUIRE_NOTHROW(m = components::input::mesh_with_tag_from_image(img_path, tag_name));
88
89 ParaviewWriter writer(
90 cache.get_cache_path() / "mesh_with_tag_from_image",
91 "vertices",
92 *m,
93 true,
94 true,
95 true,
96 false);
97 m->serialize(writer);
98}
std::filesystem::path get_cache_path() const
Get the path of the cache folder.
Definition Cache.cpp:146
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
const std::filesystem::path data_dir
TEST_CASE("component_input", "[components][input]")
Definition input.cpp:15
nlohmann::json json
Definition input.cpp:9