40int main(
int argc,
char* argv[])
43 "Remove points from geometry that are not used in any polyline nor "
44 "surface. Attention: Names of points are not handled correctly in "
46 "OpenGeoSys-6 software, version " +
49 "Copyright (c) 2012-2024, OpenGeoSys Community "
50 "(http://www.opengeosys.org)",
53 TCLAP::ValueArg<std::string> geo_output_arg(
54 "o",
"output",
"output geometry",
true,
"",
"gml file");
55 cmd.add(geo_output_arg);
56 TCLAP::ValueArg<std::string> geo_input_arg(
57 "i",
"input",
"input geometry",
true,
"conceptual model",
"gml file");
58 cmd.add(geo_input_arg);
59 cmd.parse(argc, argv);
65 if (!xml.readFile(geo_input_arg.getValue()))
67 ERR(
"Failed to read file `{:s}'.", geo_input_arg.getValue());
71 catch (std::runtime_error
const& err)
73 ERR(
"Failed to read file `{:s}'.", geo_input_arg.getValue());
74 ERR(
"{:s}", err.what());
79 auto* points =
const_cast<std::vector<GeoLib::Point*>*
>(
85 auto used_points = std::vector<bool>(points->size(),
false);
87 auto mark = [&](
auto const*
const object)
92 ranges::for_each(*polylines, mark);
96 ranges::for_each(*surfaces, mark);
99 auto const number_of_used_points =
static_cast<std::size_t
>(
100 std::count(used_points.begin(), used_points.end(),
true));
101 if (number_of_used_points == 0)
104 "Geometry consists of points only. A new geometry file won't "
109 "{} points in this geometry file are not used in any polyline or "
111 points->size() - number_of_used_points);
115 auto reset = [&mapping](
auto* object)
121 ranges::for_each(*polylines, reset);
126 ranges::for_each(*surfaces, reset);
129 std::stringstream unused_points_info;
130 unused_points_info << std::fixed;
134 ranges::views::zip(*points, used_points) |
135 ranges::views::filter([](
auto&& pair) {
return !pair.second; }) |
138 unused_points_info << point->getID() <<
" " << *point <<
'\n';
143 std::erase(*points,
nullptr);
144 if (!unused_points_info.str().empty())
146 INFO(
"Removed the following points:\n{}", unused_points_info.str());
149 WARN(
"Names of points are not handled correctly in every case.");
153 geo_output_arg.getValue());