13 #include <tclap/CmdLine.h>
32 std::string
const& id_area_fname, std::string
const& csv_fname,
33 std::vector<std::pair<std::size_t, double>>
const& ids_and_areas,
34 std::vector<MeshLib::Node*>
const& mesh_nodes)
36 std::ofstream ids_and_area_out(id_area_fname);
37 if (!ids_and_area_out)
39 OGS_FATAL(
"Unable to open the file '{:s}' - aborting.", id_area_fname);
41 std::ofstream csv_out(csv_fname);
44 OGS_FATAL(
"Unable to open the file '{:s}' - aborting.", csv_fname);
47 ids_and_area_out << std::setprecision(20);
48 csv_out << std::setprecision(20);
50 ids_and_area_out << ids_and_areas[0].first <<
" "
51 << ids_and_areas[0].second;
52 csv_out <<
"ID x y z area node_id\n";
53 csv_out << 0 <<
" " << *mesh_nodes[ids_and_areas[0].first]
54 << ids_and_areas[0].second <<
" " << ids_and_areas[0].first;
55 for (std::size_t k(1); k < ids_and_areas.size(); k++)
57 ids_and_area_out <<
"\n"
58 << ids_and_areas[k].first <<
" "
59 << ids_and_areas[k].second;
61 << k <<
" " << *mesh_nodes[ids_and_areas[k].first]
62 << ids_and_areas[k].second <<
" " << ids_and_areas[k].first;
64 ids_and_area_out <<
"\n";
68 int main(
int argc,
char* argv[])
71 "Computes ids of mesh nodes that are in polygonal regions and resides "
72 "on the top surface. The polygonal regions have to be given in a gml- "
73 "or gli-file. The found mesh nodes and the associated area are written "
74 "as txt and csv data. The documentation is available at "
75 "https://docs.opengeosys.org/docs/tools/model-preparation/"
76 "computesurfacenodeidsinpolygonalregion.\n\n"
77 "OpenGeoSys-6 software, version " +
80 "Copyright (c) 2012-2021, OpenGeoSys Community "
81 "(http://www.opengeosys.org)",
83 TCLAP::ValueArg<std::string> mesh_in(
84 "m",
"mesh-input-file",
85 "the name of the file containing the input mesh",
true,
"",
86 "file name of input mesh");
88 TCLAP::ValueArg<std::string> geo_in(
89 "g",
"geo-file",
"the name of the gml file containing the polygons",
90 true,
"",
"file name of input geometry");
93 TCLAP::ValueArg<std::string> gmsh_path_arg(
"g",
"gmsh-path",
94 "the path to the gmsh binary",
95 false,
"",
"path as string");
96 cmd.add(gmsh_path_arg);
97 cmd.parse(argc, argv);
99 std::unique_ptr<MeshLib::Mesh const> mesh(
101 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
102 mesh->getNumberOfElements());
106 gmsh_path_arg.getValue());
108 INFO(
"Geometry '{:s}' read: {:d} points, {:d} polylines.",
113 Eigen::Vector3d
const dir({0.0, 0.0, -1.0});
116 auto computeElementTopSurfaceAreas =
117 [](
MeshLib::Mesh const& mesh, Eigen::Vector3d
const& d,
double angle)
119 std::unique_ptr<MeshLib::Mesh> surface_mesh(
125 std::vector<double> areas(computeElementTopSurfaceAreas(*mesh, dir, angle));
126 std::vector<MeshLib::Node*> all_sfc_nodes(
129 std::for_each(all_sfc_nodes.begin(), all_sfc_nodes.end(),
132 std::vector<MeshLib::Node*>
const& mesh_nodes(mesh->getNodes());
134 std::vector<GeoLib::Polyline*>
const& plys(*(ply_vec->
getVector()));
136 for (std::size_t j(0); j < plys.size(); j++)
138 if (!plys[j]->isClosed())
142 std::string polygon_name;
144 if (polygon_name.empty())
146 polygon_name =
"Polygon-" + std::to_string(j);
151 std::vector<std::pair<std::size_t, double>> ids_and_areas;
152 for (std::size_t k(0); k < all_sfc_nodes.size(); k++)
155 if (polygon.isPntInPolygon(surface_node))
157 ids_and_areas.emplace_back(surface_node.
getID(), areas[k]);
160 if (ids_and_areas.empty())
162 ERR(
"Polygonal part of surface '{:s}' doesn't contains nodes. No "
163 "output will be generated.",
169 std::string id_and_area_fname(out_path + polygon_name);
170 std::string csv_fname(out_path + polygon_name);
171 id_and_area_fname += std::to_string(j) +
".txt";
172 csv_fname += std::to_string(j) +
".csv";
174 "Polygonal part of surface '{:s}' contains %{ul} nodes. Writing to "
175 "files '{:s}' and '{:s}'.",
177 ids_and_areas.size(),
180 writeToFile(id_and_area_fname, csv_fname, ids_and_areas, mesh_nodes);
183 std::for_each(all_sfc_nodes.begin(), all_sfc_nodes.end(),
184 std::default_delete<MeshLib::Node>());
Definition of the GEOObjects 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.
Definition of the Polygon class.
Container class for geometric objects.
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
const std::vector< Point * > * getPointVec(const std::string &name) const
const PolylineVec * getPolylineVecObj(const std::string &name) const
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
The class TemplateVec takes a unique name and manages a std::vector of pointers to data elements of t...
const std::vector< T * > * getVector() const
bool getNameOfElement(const T *data, std::string &name) const
std::size_t getID() const
int main(int argc, char *argv[])
void writeToFile(std::string const &id_area_fname, std::string const &csv_fname, std::vector< std::pair< std::size_t, double >> const &ids_and_areas, std::vector< MeshLib::Node * > const &mesh_nodes)
std::string extractPath(std::string const &pathname)
void readGeometryFromFile(std::string const &fname, GeoLib::GEOObjects &geo_objs, std::string const &gmsh_path)
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
Definition of readMeshFromFile function.