OGS
generateGeometry.cpp File Reference
#include <tclap/CmdLine.h>
#include <numeric>
#include "BaseLib/Logging.h"
#include "BaseLib/MPI.h"
#include "BaseLib/TCLAPArguments.h"
#include "GeoLib/GEOObjects.h"
#include "GeoLib/IO/XmlIO/Boost/BoostXmlGmlInterface.h"
#include "GeoLib/Point.h"
#include "GeoLib/Polyline.h"
#include "GeoLib/Utils.h"
#include "InfoLib/GitInfo.h"
Include dependency graph for generateGeometry.cpp:

Go to the source code of this file.

Functions

std::tuple< std::vector< GeoLib::Polyline * >, GeoLib::PolylineVec::NameIdMapappendNamedPolyline (std::unique_ptr< GeoLib::Polyline > polyline, std::string &&polyline_name)
void generateSinglePointGeometry (GeoLib::Point const &point, std::string &&point_name, std::string &&geometry_name, GeoLib::GEOObjects &geometry)
void generatePolylineGeometry (GeoLib::Point const &point0, GeoLib::Point const &point1, int const number_of_subdivisions, std::string &&polyline_name, std::string &&geometry_name, GeoLib::GEOObjects &geometry)
std::vector< GeoLib::Point * > generateQuadPoints (std::array< GeoLib::Point, 4 > const &points, std::array< int, 4 > const &number_of_subdivisions_per_edge)
int generateQuadGeometry (GeoLib::Point const &point0, GeoLib::Point const &point1, int const number_of_subdivisions_first_x, int const number_of_subdivisions_second_x, int const number_of_subdivisions_first_y, int const number_of_subdivisions_second_y, int const number_of_subdivisions_first_z, int const number_of_subdivisions_second_z, std::string &&quad_name, std::string &&geometry_name, GeoLib::GEOObjects &geometry)
int main (int argc, char *argv[])

Function Documentation

◆ appendNamedPolyline()

std::tuple< std::vector< GeoLib::Polyline * >, GeoLib::PolylineVec::NameIdMap > appendNamedPolyline ( std::unique_ptr< GeoLib::Polyline > polyline,
std::string && polyline_name )

Definition at line 19 of file generateGeometry.cpp.

21{
22 std::vector<GeoLib::Polyline*> lines;
24
25 lines.push_back(polyline.release());
26 name_map[std::move(polyline_name)] = lines.size() - 1;
27
28 return {lines, name_map};
29}
std::map< std::string, std::size_t > NameIdMap
Definition TemplateVec.h:30

Referenced by generatePolylineGeometry(), and generateQuadGeometry().

◆ generatePolylineGeometry()

void generatePolylineGeometry ( GeoLib::Point const & point0,
GeoLib::Point const & point1,
int const number_of_subdivisions,
std::string && polyline_name,
std::string && geometry_name,
GeoLib::GEOObjects & geometry )

Definition at line 44 of file generateGeometry.cpp.

50{
51 auto intermediate_points = GeoLib::generateEquidistantPoints(
52 point0, point1, number_of_subdivisions);
53 std::vector<GeoLib::Point*> points(intermediate_points.begin(),
54 intermediate_points.end());
55 geometry.addPointVec(std::move(points), geometry_name,
57 auto const& point_vec = *geometry.getPointVecObj(geometry_name);
58
59 std::vector<std::size_t> polyline_point_ids(point_vec.getVector().size());
60 std::iota(begin(polyline_point_ids), end(polyline_point_ids), 0);
61
62 auto [lines, name_map] = appendNamedPolyline(
63 GeoLib::createPolyline(point_vec, std::move(polyline_point_ids)),
64 std::move(polyline_name));
65
66 geometry.addPolylineVec(std::move(lines), geometry_name,
67 std::move(name_map));
68}
void addPolylineVec(std::vector< Polyline * > &&lines, std::string const &name, PolylineVec::NameIdMap &&ply_names)
void addPointVec(std::vector< Point * > &&points, std::string &name, PointVec::NameIdMap &&pnt_id_name_map, double const eps=std::sqrt(std::numeric_limits< double >::epsilon()))
const PointVec * getPointVecObj(const std::string &name) const
std::tuple< std::vector< GeoLib::Polyline * >, GeoLib::PolylineVec::NameIdMap > appendNamedPolyline(std::unique_ptr< GeoLib::Polyline > polyline, std::string &&polyline_name)
std::unique_ptr< Polyline > createPolyline(GeoLib::PointVec const &points_vec, std::vector< std::size_t > &&point_ids)
Create a polyline from given point ids.
Definition Polyline.cpp:553
std::vector< GeoLib::Point * > generateEquidistantPoints(MathLib::Point3d const &begin, MathLib::Point3d const &end, int const number_of_subdivisions)

References GeoLib::GEOObjects::addPointVec(), GeoLib::GEOObjects::addPolylineVec(), appendNamedPolyline(), GeoLib::createPolyline(), GeoLib::generateEquidistantPoints(), and GeoLib::GEOObjects::getPointVecObj().

Referenced by main().

◆ generateQuadGeometry()

int generateQuadGeometry ( GeoLib::Point const & point0,
GeoLib::Point const & point1,
int const number_of_subdivisions_first_x,
int const number_of_subdivisions_second_x,
int const number_of_subdivisions_first_y,
int const number_of_subdivisions_second_y,
int const number_of_subdivisions_first_z,
int const number_of_subdivisions_second_z,
std::string && quad_name,
std::string && geometry_name,
GeoLib::GEOObjects & geometry )

Definition at line 95 of file generateGeometry.cpp.

105{
106 std::array<GeoLib::Point, 4> edge_points;
107 edge_points[0] = point0;
108 edge_points[2] = point1;
109 std::array<int, 4> number_of_subdivisions;
110 if (point0[0] != point1[0] && point0[1] != point1[1] &&
111 point0[2] == point1[2])
112 {
113 // quad in xy plane
114 edge_points[1] =
115 GeoLib::Point{point1[0], point0[1], point0[2]}; // right front
116 edge_points[3] =
117 GeoLib::Point{point0[0], point1[1], point0[2]}; // left back
118 number_of_subdivisions = {
119 number_of_subdivisions_first_x, number_of_subdivisions_first_y,
120 number_of_subdivisions_second_x, number_of_subdivisions_second_y};
121 }
122 else if (point0[0] != point1[0] && point0[1] == point1[1] &&
123 point0[2] != point1[2])
124 {
125 // quad in xz plane
126 edge_points[1] =
127 GeoLib::Point{point1[0], point1[1], point0[2]}; // lower right
128 edge_points[3] =
129 GeoLib::Point{point0[0], point0[1], point1[2]}; // upper left
130 number_of_subdivisions = {
131 number_of_subdivisions_first_x, number_of_subdivisions_first_z,
132 number_of_subdivisions_second_x, number_of_subdivisions_second_z};
133 }
134 else if (point0[0] == point1[0] && point0[1] != point1[1] &&
135 point0[2] != point1[2])
136 {
137 // quad in yz plane
138 edge_points[1] =
139 GeoLib::Point{point1[0], point1[1], point0[2]}; // lower back
140 edge_points[3] =
141 GeoLib::Point{point0[0], point0[1], point1[2]}; // upper front
142 number_of_subdivisions = {
143 number_of_subdivisions_first_y, number_of_subdivisions_first_z,
144 number_of_subdivisions_second_y, number_of_subdivisions_second_z};
145 }
146 else
147 {
148 ERR("Input coordinates don't describe an axis aligned polyline or "
149 "quad.");
150 return EXIT_FAILURE;
151 }
152
153 geometry.addPointVec(
154 generateQuadPoints(edge_points, number_of_subdivisions), geometry_name,
156 auto const& point_vec = *geometry.getPointVecObj(geometry_name);
157
158 std::vector<std::size_t> polyline_point_ids(point_vec.getVector().size() +
159 1);
160 std::iota(begin(polyline_point_ids), end(polyline_point_ids), 0);
161 polyline_point_ids.back() = polyline_point_ids.front();
162
163 auto [lines, name_map] = appendNamedPolyline(
164 GeoLib::createPolyline(point_vec, std::move(polyline_point_ids)),
165 std::move(quad_name));
166
167 geometry.addPolylineVec(std::move(lines), geometry_name,
168 std::move(name_map));
169 return EXIT_SUCCESS;
170}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
std::vector< GeoLib::Point * > generateQuadPoints(std::array< GeoLib::Point, 4 > const &points, std::array< int, 4 > const &number_of_subdivisions_per_edge)

References GeoLib::GEOObjects::addPointVec(), GeoLib::GEOObjects::addPolylineVec(), appendNamedPolyline(), GeoLib::createPolyline(), ERR(), generateQuadPoints(), and GeoLib::GEOObjects::getPointVecObj().

Referenced by main().

◆ generateQuadPoints()

std::vector< GeoLib::Point * > generateQuadPoints ( std::array< GeoLib::Point, 4 > const & points,
std::array< int, 4 > const & number_of_subdivisions_per_edge )

Definition at line 70 of file generateGeometry.cpp.

73{
74 std::vector<GeoLib::Point*> quad_points;
75
76 auto addPointsOnLine = [&quad_points](auto const& begin, auto const& end,
77 auto const number_of_subdivisions)
78 {
79 auto intermediate_points = GeoLib::generateEquidistantPoints(
80 begin, end, number_of_subdivisions);
81 quad_points.insert(quad_points.end(), intermediate_points.begin(),
82 --intermediate_points.end());
83 delete intermediate_points.back(); // Release last point, other points
84 // are managed by GEOObjects.
85 };
86
87 addPointsOnLine(points[0], points[1], number_of_subdivisions_per_edge[0]);
88 addPointsOnLine(points[1], points[2], number_of_subdivisions_per_edge[1]);
89 addPointsOnLine(points[2], points[3], number_of_subdivisions_per_edge[2]);
90 addPointsOnLine(points[3], points[0], number_of_subdivisions_per_edge[3]);
91
92 return quad_points;
93}

References GeoLib::generateEquidistantPoints().

Referenced by generateQuadGeometry().

◆ generateSinglePointGeometry()

void generateSinglePointGeometry ( GeoLib::Point const & point,
std::string && point_name,
std::string && geometry_name,
GeoLib::GEOObjects & geometry )

Definition at line 31 of file generateGeometry.cpp.

35{
36 std::vector<GeoLib::Point*> points;
37 points.push_back(new GeoLib::Point{point});
38
39 GeoLib::PointVec::NameIdMap name_map{{std::move(point_name), 0}};
40
41 geometry.addPointVec(std::move(points), geometry_name, std::move(name_map));
42}

References GeoLib::GEOObjects::addPointVec().

Referenced by main().

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 172 of file generateGeometry.cpp.

173{
174 TCLAP::CmdLine cmd(
175 "Generate point, axis parallel polyline or axis parallel quad "
176 "geometry. \n\n"
177 "OpenGeoSys-6 software, version " +
179 ".\n"
180 "Copyright (c) 2012-2026, OpenGeoSys Community "
181 "(http://www.opengeosys.org)",
183 TCLAP::ValueArg<double> z0("", "z0", "z coordinate of the first point",
184 true, 0.0, "Z0");
185 cmd.add(z0);
186 TCLAP::ValueArg<double> y0("", "y0", "y coordinate of the first point",
187 true, 0.0, "Y0");
188 cmd.add(y0);
189 TCLAP::ValueArg<double> x0("", "x0", "x coordinate of the first point",
190 true, 0.0, "X0");
191 cmd.add(x0);
192 TCLAP::ValueArg<double> z1("", "z1", "z coordinate of the first point",
193 true, 1.0, "Z1");
194 cmd.add(z1);
195 TCLAP::ValueArg<double> y1("", "y1", "y coordinate of the first point",
196 true, 1.0, "Y1");
197 cmd.add(y1);
198 TCLAP::ValueArg<double> x1("", "x1", "x coordinate of the first point",
199 true, 1.0, "X1");
200 cmd.add(x1);
201 TCLAP::ValueArg<int> nx("", "nx", "number of subdivisions in x direction",
202 false, 0, "NX");
203 cmd.add(nx);
204 TCLAP::ValueArg<int> nx1("", "nx1", "number of subdivisions in x direction",
205 false, -1, "NX1");
206 cmd.add(nx1);
207 TCLAP::ValueArg<int> ny("", "ny", "number of subdivisions in y direction",
208 false, 0, "NY");
209 cmd.add(ny);
210 TCLAP::ValueArg<int> ny1("", "ny1", "number of subdivisions in y direction",
211 false, -1, "NY1");
212 cmd.add(ny1);
213 TCLAP::ValueArg<int> nz("", "nz", "number of subdivisions in z direction",
214 false, 0, "number of subdivisions in z direction");
215 cmd.add(nz);
216 TCLAP::ValueArg<int> nz1("", "nz1", "number of subdivisions in z direction",
217 false, -1, "NZ1");
218 cmd.add(nz1);
219 TCLAP::ValueArg<std::string> geometry_name(
220 "", "geometry_name", "name of the generated geometry", false,
221 "conceptual model", "GEOMETRY_NAME");
222 cmd.add(geometry_name);
223 TCLAP::ValueArg<std::string> polyline_name(
224 "", "polyline_name", "name of the generated polyline", false,
225 "polyline", "POLYLINE_NAME");
226 cmd.add(polyline_name);
227 TCLAP::ValueArg<std::string> geo_output_arg(
228 "o", "output", "Output (.gml) geometry file", true, "", "OUTPUT_FILE");
229 cmd.add(geo_output_arg);
230 auto log_level_arg = BaseLib::makeLogLevelArg();
231 cmd.add(log_level_arg);
232 cmd.parse(argc, argv);
233
234 BaseLib::MPI::Setup mpi_setup(argc, argv);
235 BaseLib::initOGSLogger(log_level_arg.getValue());
236
237 auto const p0 = GeoLib::Point{x0.getValue(), y0.getValue(), z0.getValue()};
238 auto const p1 = GeoLib::Point{x1.getValue(), y1.getValue(), z1.getValue()};
239
240 GeoLib::GEOObjects geometry;
241 auto constexpr eps = std::numeric_limits<double>::epsilon();
242 if (p1[0] - p0[0] < eps && p1[1] - p0[1] < eps && p1[2] - p0[2] < eps)
243 {
244 generateSinglePointGeometry(p0, std::string(polyline_name.getValue()),
245 std::string(geometry_name.getValue()),
246 geometry);
247 }
248 else if ((p1[0] - p0[0] >= eps && p1[1] - p0[1] < eps &&
249 p1[2] - p0[2] < eps) ||
250 (p1[0] - p0[0] < eps && p1[1] - p0[1] >= eps &&
251 p1[2] - p0[2] < eps) ||
252 (p1[0] - p0[0] < eps && p1[1] - p0[1] < eps &&
253 p1[2] - p0[2] >= eps))
254 {
256 p0, p1, nx.getValue(), std::string(polyline_name.getValue()),
257 std::string(geometry_name.getValue()), geometry);
258 }
259 else
260 {
261 auto eval = [](int v, int v1)
262 {
263 if (v1 == -1)
264 {
265 return v;
266 }
267 else
268 {
269 return v1;
270 }
271 };
273 p0, p1, nx.getValue(), eval(nx.getValue(), nx1.getValue()),
274 ny.getValue(), eval(ny.getValue(), ny1.getValue()),
275 nz.getValue(), eval(nz.getValue(), nz1.getValue()),
276 std::string(polyline_name.getValue()),
277 std::string(geometry_name.getValue()),
278 geometry) == EXIT_FAILURE)
279 {
280 return EXIT_FAILURE;
281 }
282 }
283
285 xml.export_name = geometry.getGeometryNames()[0];
287 geo_output_arg.getValue());
288
289 return EXIT_SUCCESS;
290}
std::string writeToString()
Writes the object to a string.
Definition Writer.cpp:20
Container class for geometric objects.
Definition GEOObjects.h:46
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
void generateSinglePointGeometry(GeoLib::Point const &point, std::string &&point_name, std::string &&geometry_name, GeoLib::GEOObjects &geometry)
void generatePolylineGeometry(GeoLib::Point const &point0, GeoLib::Point const &point1, int const number_of_subdivisions, std::string &&polyline_name, std::string &&geometry_name, GeoLib::GEOObjects &geometry)
int generateQuadGeometry(GeoLib::Point const &point0, GeoLib::Point const &point1, int const number_of_subdivisions_first_x, int const number_of_subdivisions_second_x, int const number_of_subdivisions_first_y, int const number_of_subdivisions_second_y, int const number_of_subdivisions_first_z, int const number_of_subdivisions_second_z, std::string &&quad_name, std::string &&geometry_name, GeoLib::GEOObjects &geometry)
int writeStringToFile(std::string_view content, std::filesystem::path const &file_path)
Definition Writer.cpp:34
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:56
GITINFOLIB_EXPORT const std::string ogs_version
auto eval(Function &f, Tuples &... ts) -> typename detail::GetFunctionReturnType< decltype(&Function::eval)>::type
Definition Apply.h:268

References BaseLib::IO::XMLInterface::export_name, generatePolylineGeometry(), generateQuadGeometry(), generateSinglePointGeometry(), GeoLib::GEOObjects::getGeometryNames(), BaseLib::initOGSLogger(), BaseLib::makeLogLevelArg(), GitInfoLib::GitInfo::ogs_version, BaseLib::IO::writeStringToFile(), and BaseLib::IO::Writer::writeToString().