Wildmeshing Toolkit
Loading...
Searching...
No Matches
Parameters.h
1#pragma once
2#include <jse/jse.h>
3#include <wmtk/components/topological_offset/Parameters.h>
4#include <nlohmann/json.hpp>
5#include <string>
6#include <topological_offset_spec.hpp>
7#include <wmtk/Types.hpp>
8#include <wmtk/components/simwild/expression_parser/Expression.hpp>
9
10
11using namespace wmtk::components;
12using ExpressionPtr = wmtk::components::simwild::expression_parser::ExpressionPtr;
13
14
15namespace wmtk::components::manifold_extraction {
16
17
19{
20 // parameters set by user
21 ExpressionPtr tag_selection;
22 std::set<std::string> fill_tags;
23 double radius_rel;
24 double radius;
25 std::string output_path;
26 bool debug_output;
27 bool save_vtu;
28 bool write_surface;
29
30 Parameters() = default;
31
32 Parameters(const nlohmann::json& json_params)
33 {
34 for (const std::string& tag : json_params["fill_tags"]) {
35 if (tag == "ambient") {
36 logger().warn(
37 "'ambient' tag cannot be given explicitly to fill_tags, ignoring. To "
38 "set offset to 'ambient', pass fill_tags=[].");
39 continue;
40 }
41 fill_tags.insert(tag);
42 }
43 radius_rel = json_params["radius_rel"];
44 radius = json_params["radius"];
45 output_path = json_params["output"];
46 debug_output = json_params["DEBUG_output"];
47 write_surface = json_params["write_surface"];
48 save_vtu = json_params["save_vtu"];
49 }
50
51 void init(const VectorXd& mins, const VectorXd& maxes)
52 {
53 const double diag = (maxes - mins).norm();
54 if (radius > 0) {
55 radius_rel = radius / diag;
56 } else {
57 radius = radius_rel * diag;
58 }
59 }
60
61 topological_offset::Parameters generate_offset_params()
62 {
63 nlohmann::json offset_params;
64 offset_params["application"] = "topological_offset";
65 offset_params["input"] = "this doesn't matter";
66 offset_params["offset_selection"] = "this should never be used.";
67
68 // inject defaults
69 const auto spec = jse::embed::wmtk_topological_offset_spec::topological_offset_spec::spec();
70 jse::JSE spec_engine;
71 bool r = spec_engine.verify_json(offset_params, spec);
72 if (!r) {
73 log_and_throw_error(spec_engine.log2str());
74 }
75 offset_params = spec_engine.inject_defaults(offset_params, spec);
76
77 auto ret_params = topological_offset::Parameters(offset_params);
78 ret_params.target_distance = radius;
79 ret_params.target_distance_rel = radius_rel;
80 ret_params.offset_output_tag = fill_tags;
81 ret_params.debug_output = debug_output;
82 ret_params.save_vtu = save_vtu;
83 return ret_params;
84 }
85};
86
87
88} // namespace wmtk::components::manifold_extraction
What the offset needs on top of the parameters every wmtk optimizer shares.
Definition Parameters.h:24