11#include <tclap/CmdLine.h>
15#include <range/v3/algorithm/for_each.hpp>
16#include <range/v3/range/conversion.hpp>
17#include <range/v3/view/filter.hpp>
18#include <range/v3/view/map.hpp>
19#include <range/v3/view/transform.hpp>
20#include <range/v3/view/zip.hpp>
36 auto getCountOrMax = [cnt = 0u](
bool used)
mutable
37 {
return used ? cnt++ : std::numeric_limits<std::size_t>::max(); };
39 return used_points | ranges::views::transform(getCountOrMax) |
40 ranges::to<std::vector>;
43int main(
int argc,
char* argv[])
46 "Remove points from geometry that are not used in any polyline nor "
47 "surface. Attention: Names of points are not handled correctly in "
49 "OpenGeoSys-6 software, version " +
52 "Copyright (c) 2012-2025, OpenGeoSys Community "
53 "(http://www.opengeosys.org)",
56 TCLAP::ValueArg<std::string> geo_output_arg(
57 "o",
"output",
"Output (.gml) geometry",
true,
"",
"OUTPUT_FILE");
58 cmd.add(geo_output_arg);
59 TCLAP::ValueArg<std::string> geo_input_arg(
60 "i",
"input",
"Input (.gml) geometry",
true,
"conceptual model",
62 cmd.add(geo_input_arg);
64 cmd.add(log_level_arg);
65 cmd.parse(argc, argv);
74 if (!xml.
readFile(geo_input_arg.getValue()))
76 ERR(
"Failed to read file `{:s}'.", geo_input_arg.getValue());
80 catch (std::runtime_error
const& err)
82 ERR(
"Failed to read file `{:s}'.", geo_input_arg.getValue());
83 ERR(
"{:s}", err.what());
88 auto* points =
const_cast<std::vector<GeoLib::Point*>*
>(
94 auto used_points = std::vector<bool>(points->size(),
false);
96 auto mark = [&](
auto const*
const object)
101 ranges::for_each(*polylines, mark);
105 ranges::for_each(*surfaces, mark);
108 auto const number_of_used_points =
static_cast<std::size_t
>(
109 std::count(used_points.begin(), used_points.end(),
true));
110 if (number_of_used_points == 0)
113 "Geometry consists of points only. A new geometry file won't "
118 "{} points in this geometry file are not used in any polyline or "
120 points->size() - number_of_used_points);
124 auto reset = [&mapping](
auto* object)
130 ranges::for_each(*polylines, reset);
135 ranges::for_each(*surfaces, reset);
138 std::stringstream unused_points_info;
139 unused_points_info << std::fixed;
143 ranges::views::zip(*points, used_points) |
144 ranges::views::filter([](
auto&& pair) {
return !pair.second; }) |
147 unused_points_info << point->getID() <<
" " << *point <<
'\n';
152 std::erase(*points,
nullptr);
153 if (!unused_points_info.str().empty())
155 INFO(
"Removed the following points:\n{}", unused_points_info.str());
158 WARN(
"Names of points are not handled correctly in every case.");
162 geo_output_arg.getValue());
Definition of the BoostXmlGmlInterface class.
Definition of the GEOObjects class.
Definition of the Point class.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the PolyLine class.
int main(int argc, char *argv[])
auto createMapping(std::vector< bool > const &used_points)
std::string writeToString()
Writes the object to a string.
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 std::vector< Surface * > * getSurfaceVec(const std::string &name) const
Returns the surface vector with the given name as a const.
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
bool readFile(const std::string &fname) override
Reads an xml-file containing OGS geometry.
int writeStringToFile(std::string_view content, std::filesystem::path const &file_path)
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
void markUsedPoints(Polyline const &polyline, std::vector< bool > &used_points)
Resets the point IDs of the polyline corresponding to the mapping.
void resetPointIDs(Polyline &polyline, std::vector< std::size_t > const &mapping)
Resets the point IDs of the polyline corresponding to the mapping.
GITINFOLIB_EXPORT const std::string ogs_version