27 std::vector<MeshLib::Node*>
const& nodes,
28 double const& max_dist)
30 double sqr_shortest_dist(max_dist);
31 double elevation(
p[2]);
34 double sqr_dist = (
p[0] - (*node)[0]) * (
p[0] - (*node)[0]) +
35 (
p[1] - (*node)[1]) * (
p[1] - (*node)[1]);
36 if (sqr_dist < sqr_shortest_dist)
38 sqr_shortest_dist = sqr_dist;
39 elevation = (*node)[2];
45 int main(
int argc,
char* argv[])
47 std::vector<std::string> keywords;
48 keywords.emplace_back(
"-ALL");
49 keywords.emplace_back(
"-MESH");
50 keywords.emplace_back(
"-LOWPASS");
55 "Moves mesh nodes and connected elements either by a given value "
56 "or based on a list.\n");
57 INFO(
"Usage: {:s} <msh-file.msh> <keyword> [<value1>] [<value2>]",
59 INFO(
"Available keywords:");
61 "\t-ALL <value1> <value2> : changes the elevation of all mesh "
62 "nodes by <value2> in direction <value1> [x,y,z].");
64 "\t-MESH <value1> <value2> : changes the elevation of mesh nodes "
65 "based on a second mesh <value1> with a search range of <value2>.");
67 "\t-LOWPASS : applies a lowpass filter over node elevation using "
68 "directly connected nodes.");
72 const std::string msh_name(argv[1]);
73 const std::string current_key(argv[2]);
75 if (!(ext ==
".msh" || ext ==
".vtu"))
77 ERR(
"Error: Parameter 1 must be a mesh-file (*.msh / *.vtu).");
78 INFO(
"Usage: {:s} <msh-file.gml> <keyword> <value>", argv[0]);
82 bool const is_keyword = std::any_of(keywords.begin(), keywords.end(),
83 [current_key](
auto const& keyword)
84 { return current_key == keyword; });
88 ERR(
"Keyword not recognised. Available keywords:");
89 for (
auto const& keyword : keywords)
90 INFO(
"\t{:s}", keyword);
94 std::unique_ptr<MeshLib::Mesh> mesh(
98 ERR(
"Error reading mesh file.");
105 if (current_key ==
"-ALL")
109 ERR(
"Missing parameter...");
112 const std::string dir(argv[3]);
113 unsigned idx = (dir ==
"x") ? 0 : (dir ==
"y") ? 1 : 2;
114 const double value(strtod(argv[4], 0));
115 INFO(
"Moving all mesh nodes by {:g} in direction {:d} ({:s})...", value,
118 const std::size_t nNodes(mesh->getNumberOfNodes());
119 std::vector<MeshLib::Node*> nodes(mesh->getNodes());
120 for (std::size_t i = 0; i < nNodes; i++)
122 (*nodes[i])[idx] += value;
128 if (current_key ==
"-MESH")
132 ERR(
"Missing parameter...");
135 const std::string value(argv[3]);
136 double max_dist(pow(strtod(argv[4], 0), 2));
137 std::unique_ptr<MeshLib::Mesh> ground_truth(
139 if (ground_truth ==
nullptr)
141 ERR(
"Error reading mesh file.");
145 std::vector<MeshLib::Node*>
const& nodes = mesh->getNodes();
147 double const max_edge(mesh->getMaxEdgeLength());
152 (*node)[1] - max_edge,
153 -std::numeric_limits<double>::max()}};
155 (*node)[1] + max_edge,
156 std::numeric_limits<double>::max()}};
157 std::vector<const MeshLib::Element*>
const& elems =
159 auto const* element =
172 if (current_key ==
"-LOWPASS")
174 const std::size_t nNodes(mesh->getNumberOfNodes());
175 std::vector<MeshLib::Node*> nodes(mesh->getNodes());
177 std::vector<double> elevation(nNodes);
178 for (std::size_t i = 0; i < nNodes; i++)
180 elevation[i] = (*nodes[i])[2];
183 auto const& connections =
185 for (std::size_t i = 0; i < nNodes; i++)
187 auto const& conn_nodes(connections[nodes[i]->getID()]);
188 const unsigned nConnNodes(conn_nodes.size());
189 elevation[i] = (2 * (*nodes[i])[2]);
190 for (std::size_t j = 0; j < nConnNodes; ++j)
192 elevation[i] += (*conn_nodes[j])[2];
194 elevation[i] /= (nConnNodes + 2);
197 for (std::size_t i = 0; i < nNodes; i++)
199 (*nodes[i])[2] = elevation[i];
204 std::string
const new_mesh_name(msh_name.substr(0, msh_name.length() - 4) +
211 INFO(
"Result successfully written.");
Definition of the AABB class.
void INFO(char const *fmt, Args const &... args)
void ERR(char const *fmt, Args const &... args)
Definition of the Mesh class.
Definition of the Node class.
std::vector< MeshLib::Element const * > getElementsInVolume(POINT const &min, POINT const &max) const
int main(int argc, char *argv[])
double getClosestPointElevation(MeshLib::Node const &p, std::vector< MeshLib::Node * > const &nodes, double const &max_dist)
std::string getFileExtension(const std::string &path)
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, [[maybe_unused]] std::set< std::string > variable_output_names)
double getElevation(Element const &element, Node const &node)
Element const * getProjectedElement(std::vector< const Element * > const &elements, Node const &node)
std::vector< std::vector< Node * > > calculateNodesConnectedByElements(Mesh const &mesh)
Definition of readMeshFromFile function.