OGS
MoveGeometry.cpp
Go to the documentation of this file.
1 
14 // ThirdParty
15 #include <tclap/CmdLine.h>
16 
17 #include "GeoLib/GEOObjects.h"
19 #include "InfoLib/GitInfo.h"
20 
21 int main(int argc, char* argv[])
22 {
23  TCLAP::CmdLine cmd(
24  "Moves the points of a geometry by a given displacement vector\n\n"
25  "OpenGeoSys-6 software, version " +
27  ".\n"
28  "Copyright (c) 2012-2021, OpenGeoSys Community "
29  "(http://www.opengeosys.org)",
31  TCLAP::ValueArg<double> z_arg("z", "z", "displacement in z direction",
32  false, 0.0, "z-displacement");
33  cmd.add(z_arg);
34  TCLAP::ValueArg<double> y_arg("y", "y", "displacement in y direction",
35  false, 0.0, "y-displacement");
36  cmd.add(y_arg);
37  TCLAP::ValueArg<double> x_arg("x", "x", "displacement in x direction",
38  false, 0.0, "x-displacement");
39  cmd.add(x_arg);
40  TCLAP::ValueArg<std::string> geo_output_arg(
41  "o", "output", "output geometry file (*.gml)", true, "", "output file");
42  cmd.add(geo_output_arg);
43  TCLAP::ValueArg<std::string> geo_input_arg(
44  "i", "input", "input geometry file (*.gml)", true, "", "input file");
45  cmd.add(geo_input_arg);
46  cmd.parse(argc, argv);
47 
48  GeoLib::GEOObjects geo_objects;
49  GeoLib::IO::BoostXmlGmlInterface xml(geo_objects);
50  try
51  {
52  if (!xml.readFile(geo_input_arg.getValue()))
53  {
54  return EXIT_FAILURE;
55  }
56  }
57  catch (std::runtime_error const& err)
58  {
59  ERR("Failed to read file `{:s}'.", geo_input_arg.getValue());
60  ERR("{:s}", err.what());
61  return EXIT_FAILURE;
62  }
63 
64  Eigen::Vector3d displacement = Eigen::Vector3d::Zero();
65  if (x_arg.isSet())
66  {
67  displacement[0] = x_arg.getValue();
68  }
69  if (y_arg.isSet())
70  {
71  displacement[1] = y_arg.getValue();
72  }
73  if (z_arg.isSet())
74  {
75  displacement[2] = z_arg.getValue();
76  }
77 
78  auto const geo_name = geo_objects.getGeometryNames()[0];
79 
80  std::vector<GeoLib::Point*> const* point_vec =
81  geo_objects.getPointVec(geo_name);
82  std::size_t const n_points = point_vec->size();
83  for (std::size_t i = 0; i < n_points; ++i)
84  {
85  for (std::size_t c = 0; c < 3; ++c)
86  {
87  (*(*point_vec)[i])[c] += displacement[c];
88  }
89  }
90 
91  xml.export_name = geo_name;
93  geo_output_arg.getValue());
94 
95  return EXIT_SUCCESS;
96 }
Definition of the BoostXmlGmlInterface class.
Definition of the GEOObjects class.
Git information.
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
int main(int argc, char *argv[])
std::string writeToString()
Writes the object to a string.
Definition: Writer.cpp:31
Container class for geometric objects.
Definition: GEOObjects.h:61
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
Definition: GEOObjects.cpp:401
const std::vector< Point * > * getPointVec(const std::string &name) const
Definition: GEOObjects.cpp:71
bool readFile(const std::string &fname) override
Reads an xml-file containing OGS geometry.
int writeStringToFile(std::string content, std::filesystem::path const &file_path)
Definition: Writer.cpp:45
GITINFOLIB_EXPORT const std::string ogs_version