OGS
ResetPropertiesInPolygonalRegion.cpp File Reference
#include <tclap/CmdLine.h>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include "Applications/FileIO/readGeometryFromFile.h"
#include "GeoLib/GEOObjects.h"
#include "GeoLib/Polygon.h"
#include "InfoLib/GitInfo.h"
#include "MeshGeoToolsLib/MeshEditing/ResetMeshElementProperty.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/MeshInformation.h"
Include dependency graph for ResetPropertiesInPolygonalRegion.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 28 of file ResetPropertiesInPolygonalRegion.cpp.

29 {
30  TCLAP::CmdLine cmd(
31  "Sets the property value of a mesh element to a given new value iff at "
32  "least one node of the element is within a polygonal region that is "
33  "given by a polygon. The documentation is available at "
34  "https://docs.opengeosys.org/docs/tools/model-preparation/"
35  "set-properties-in-polygonal-region.\n\n"
36  "OpenGeoSys-6 software, version " +
38  ".\n"
39  "Copyright (c) 2012-2021, OpenGeoSys Community "
40  "(http://www.opengeosys.org)",
42  TCLAP::ValueArg<std::string> mesh_out(
43  "o", "mesh-output-file",
44  "the name of the file the mesh will be written to, format depends on "
45  "the given file name extension",
46  true, "", "file name");
47  cmd.add(mesh_out);
48  TCLAP::ValueArg<std::string> polygon_name_arg(
49  "p", "polygon-name", "name of polygon in the geometry", true, "",
50  "string");
51  cmd.add(polygon_name_arg);
52  TCLAP::ValueArg<std::string> geometry_fname(
53  "g", "geometry",
54  "the name of the file containing the input geometry (gli or gml "
55  "format)",
56  true, "", "file name");
57  cmd.add(geometry_fname);
58  TCLAP::SwitchArg any_of_arg(
59  "", "any_of",
60  "all nodes of an element has to be inside the polygon (default "
61  "behaviour without switch) or any node of an element has to be inside "
62  "(switch is given)",
63  false);
64  cmd.add(any_of_arg);
65  TCLAP::ValueArg<char> char_property_arg(
66  "c", "char-property-value", "new property value (data type char)",
67  false, 'A', "character");
68  cmd.add(char_property_arg);
69  TCLAP::ValueArg<int> int_property_arg("i", "int-property-value",
70  "new property value (data type int)",
71  false, 0, "number");
72  cmd.add(int_property_arg);
73  TCLAP::ValueArg<bool> bool_property_arg(
74  "b", "bool-property-value", "new property value (data type bool)",
75  false, false, "boolean value");
76  cmd.add(bool_property_arg);
77  TCLAP::ValueArg<std::string> property_name_arg(
78  "n", "property-name", "name of property in the mesh", false,
79  "MaterialIDs", "string");
80  cmd.add(property_name_arg);
81  TCLAP::ValueArg<int> restrict_arg(
82  "r", "restrict-to-MaterialID",
83  "Restrict resetting the property to the material id", false, -1,
84  "MaterialID");
85  cmd.add(restrict_arg);
86  TCLAP::ValueArg<std::string> mesh_in(
87  "m", "mesh-input-file",
88  "the name of the file containing the input mesh", true, "",
89  "file name");
90  cmd.add(mesh_in);
91  TCLAP::ValueArg<std::string> gmsh_path_arg("", "gmsh-path",
92  "the path to the gmsh binary",
93  false, "", "path as string");
94  cmd.add(gmsh_path_arg);
95  cmd.parse(argc, argv);
96 
97  // *** read geometry
98  GeoLib::GEOObjects geometries;
99  FileIO::readGeometryFromFile(geometry_fname.getValue(), geometries,
100  gmsh_path_arg.getValue());
101 
102  auto const geo_name = geometries.getGeometryNames()[0];
103 
104  // *** check if the data is usable
105  // *** get vector of polylines
106  GeoLib::PolylineVec const* plys(geometries.getPolylineVecObj(geo_name));
107  if (!plys)
108  {
109  ERR("Could not get vector of polylines out of geometry '{:s}'.",
110  geo_name);
111  return EXIT_FAILURE;
112  }
113 
114  // *** get polygon
115  GeoLib::Polyline const* ply(
116  plys->getElementByName(polygon_name_arg.getValue()));
117  if (!ply)
118  {
119  ERR("Polyline '{:s}' not found.", polygon_name_arg.getValue());
120  return EXIT_FAILURE;
121  }
122 
123  // *** check if the polyline is closed (i.e. is a polygon)
124  if (!ply->isClosed())
125  {
126  ERR("Polyline '{:s}' is not closed, i.e. does not describe a region.",
127  polygon_name_arg.getValue());
128  return EXIT_FAILURE;
129  }
130 
131  GeoLib::Polygon const polygon(*(ply));
132 
133  // *** read mesh
134  auto mesh = std::unique_ptr<MeshLib::Mesh>(
135  MeshLib::IO::readMeshFromFile(mesh_in.getValue()));
136  if (!mesh)
137  {
138  // error message written already by readMeshFromFile
139  return EXIT_FAILURE;
140  }
141  std::string const& property_name(property_name_arg.getValue());
142 
143  if (char_property_arg.isSet())
144  {
146  *mesh, polygon, property_name, char_property_arg.getValue(),
147  restrict_arg.getValue(), any_of_arg.getValue());
148  }
149 
150  if (int_property_arg.isSet())
151  {
153  *mesh, polygon, property_name, int_property_arg.getValue(),
154  restrict_arg.getValue(), any_of_arg.getValue());
155  }
156 
157  if (bool_property_arg.isSet())
158  {
160  *mesh, polygon, property_name, bool_property_arg.getValue(),
161  restrict_arg.getValue(), any_of_arg.getValue());
162  }
163 
165 
166  MeshLib::IO::writeMeshToFile(*mesh, mesh_out.getValue());
167 
168  return EXIT_SUCCESS;
169 }
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
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 PolylineVec * getPolylineVecObj(const std::string &name) const
Definition: GEOObjects.cpp:227
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition: Polyline.h:51
The class TemplateVec takes a unique name and manages a std::vector of pointers to data elements of t...
Definition: TemplateVec.h:40
static void writePropertyVectorInformation(const MeshLib::Mesh &mesh)
writes out property vector information
void readGeometryFromFile(std::string const &fname, GeoLib::GEOObjects &geo_objs, std::string const &gmsh_path)
GITINFOLIB_EXPORT const std::string ogs_version
void resetMeshElementProperty(MeshLib::Mesh &mesh, GeoLib::Polygon const &polygon, std::string const &property_name, PT new_property_value, int restrict_to_material_id, bool const any_of)
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)

References ERR(), GeoLib::TemplateVec< T >::getElementByName(), GeoLib::GEOObjects::getGeometryNames(), GeoLib::GEOObjects::getPolylineVecObj(), GeoLib::Polyline::isClosed(), GitInfoLib::GitInfo::ogs_version, FileIO::readGeometryFromFile(), MeshLib::IO::readMeshFromFile(), MeshGeoToolsLib::resetMeshElementProperty(), MeshLib::IO::writeMeshToFile(), and MeshLib::MeshInformation::writePropertyVectorInformation().