OGS
MoveMesh.cpp File Reference

Detailed Description

Date
Jan 17, 2014

Definition in file MoveMesh.cpp.

#include <tclap/CmdLine.h>
#include "BaseLib/FileTools.h"
#include "BaseLib/StringTools.h"
#include "GeoLib/AABB.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/Elements/Element.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/MeshEditing/moveMeshNodes.h"
#include "MeshLib/Node.h"
Include dependency graph for MoveMesh.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 26 of file MoveMesh.cpp.

27 {
28  TCLAP::CmdLine cmd(
29  "Moves the mesh nodes using the given displacement vector or if no "
30  "displacement vector is given, moves the mesh nodes such that the "
31  "centroid of the given mesh is in the origin.\n\n"
32  "OpenGeoSys-6 software, version " +
34  ".\n"
35  "Copyright (c) 2012-2021, OpenGeoSys Community "
36  "(http://www.opengeosys.org)",
38  // Define a value argument and add it to the command line.
39  // A value arg defines a flag and a type of value that it expects,
40  // such as "-m meshfile".
41  TCLAP::ValueArg<std::string> mesh_arg("m", "mesh", "input mesh file", true,
42  "", "string");
43 
44  // Add the argument mesh_arg to the CmdLine object. The CmdLine object
45  // uses this Arg to parse the command line.
46  cmd.add(mesh_arg);
47 
48  TCLAP::ValueArg<double> x_arg("x", "x", "displacement in x direction",
49  false, 0.0, "floating point number");
50  cmd.add(x_arg);
51  TCLAP::ValueArg<double> y_arg("y", "y", "displacement in y direction",
52  false, 0.0, "floating point number");
53  cmd.add(y_arg);
54  TCLAP::ValueArg<double> z_arg("z", "z", "displacement in z direction",
55  false, 0.0, "floating point number");
56  cmd.add(z_arg);
57 
58  TCLAP::ValueArg<std::string> mesh_out_arg(
59  "o", "output-mesh", "output mesh file", false, "", "string");
60  cmd.add(mesh_out_arg);
61 
62  cmd.parse(argc, argv);
63 
64  std::string fname(mesh_arg.getValue());
65 
66  std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::IO::readMeshFromFile(fname));
67 
68  if (!mesh)
69  {
70  ERR("Could not read mesh from file '{:s}'.", fname);
71  return EXIT_FAILURE;
72  }
73 
74  MeshLib::Node displacement(0.0, 0.0, 0.0);
75  if (fabs(x_arg.getValue()) < std::numeric_limits<double>::epsilon() &&
76  fabs(y_arg.getValue()) < std::numeric_limits<double>::epsilon() &&
77  fabs(z_arg.getValue()) < std::numeric_limits<double>::epsilon())
78  {
79  GeoLib::AABB aabb(mesh->getNodes().begin(), mesh->getNodes().end());
80  displacement[0] =
81  -(aabb.getMaxPoint()[0] + aabb.getMinPoint()[0]) / 2.0;
82  displacement[1] =
83  -(aabb.getMaxPoint()[1] + aabb.getMinPoint()[1]) / 2.0;
84  displacement[2] =
85  -(aabb.getMaxPoint()[2] + aabb.getMinPoint()[2]) / 2.0;
86  }
87  else
88  {
89  displacement[0] = x_arg.getValue();
90  displacement[1] = y_arg.getValue();
91  displacement[2] = z_arg.getValue();
92  }
93 
94  INFO("translate model ({:f}, {:f}, {:f}).",
95  displacement[0],
96  displacement[1],
97  displacement[2]);
98  MeshLib::moveMeshNodes(mesh->getNodes().begin(), mesh->getNodes().end(),
99  displacement);
100 
101  std::string out_fname(mesh_out_arg.getValue());
102  if (out_fname.empty())
103  {
104  out_fname = BaseLib::dropFileExtension(mesh_out_arg.getValue());
105  out_fname += "_displaced.vtu";
106  }
107 
108  MeshLib::IO::writeMeshToFile(*mesh, out_fname);
109 
110  return EXIT_SUCCESS;
111 }
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition: AABB.h:49
std::string dropFileExtension(std::string const &filename)
Definition: FileTools.cpp:169
GITINFOLIB_EXPORT const std::string ogs_version
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)
void moveMeshNodes(Iterator begin, Iterator end, MeshLib::Node const &displacement)
Definition: moveMeshNodes.h:32

References BaseLib::dropFileExtension(), ERR(), GeoLib::AABB::getMaxPoint(), GeoLib::AABB::getMinPoint(), INFO(), MeshLib::moveMeshNodes(), GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), and MeshLib::IO::writeMeshToFile().