27 GeoLib::Point const& pnt, std::vector<MeshLib::Node*>
const& nodes,
29 std::pair<int, int>
const& mat_limits,
30 std::pair<double, double>
const& elevation_limits,
33 std::vector<std::size_t> pnt_nodes;
34 for (
auto node : nodes)
36 double const eps = std::numeric_limits<double>::epsilon();
37 if (std::abs((*node)[0] - pnt[0]) < eps &&
38 std::abs((*node)[1] - pnt[1]) < eps)
43 if (mat_ids[e->getID()] >= mat_limits.first &&
44 mat_ids[e->getID()] <= mat_limits.second &&
45 (*node)[2] >= elevation_limits.first &&
46 (*node)[2] <= elevation_limits.second)
48 pnt_nodes.push_back(node->getID());
54 if (pnt_nodes.size() < 2)
56 WARN(
"No nodes found for point {:d}...", pnt.
getID());
61 std::sort(pnt_nodes.begin(), pnt_nodes.end(),
62 [nodes](std::size_t a, std::size_t b)
63 { return (*nodes[a])[2] > (*nodes[b])[2]; });
68int main(
int argc,
char* argv[])
71 "Integrates line elements representing boreholes into a pre-existing "
72 "3D mesh. Corresponding nodes matching the (x,y)-coordinates given in "
73 "the gml-file are found in the mesh and connected from top to bottom "
74 "via line elements. Each borehole (i.e. all points at a given "
75 "(x,y)-location but at different depths) is assigned a unique material "
76 "ID. Vertical limits of boreholes can be specified via Material IDs "
77 "and/or elevation. Point not matching any mesh nodes or located outside"
78 " the mesh are ignored.\n\n"
79 "OpenGeoSys-6 software, version " +
82 "Copyright (c) 2012-2026, OpenGeoSys Community "
83 "(http://www.opengeosys.org)",
86 double const dmax = std::numeric_limits<double>::max();
87 TCLAP::ValueArg<double> max_elevation_arg(
89 "Maximum elevation for an integrated borehole, "
91 false, 0,
"MAX_ELEVATION");
92 cmd.add(max_elevation_arg);
93 TCLAP::ValueArg<double> min_elevation_arg(
95 "Minimum elevation for an integrated borehole, "
97 false, 0,
"MIN_ELEVATION");
98 cmd.add(min_elevation_arg);
99 TCLAP::ValueArg<int> max_id_arg(
100 "",
"max-id",
"Maximum MaterialID for an integrated borehole",
false,
103 TCLAP::ValueArg<int> min_id_arg(
104 "",
"min-id",
"Minimum MaterialID for an integrated borehole",
false,
107 TCLAP::ValueArg<std::string> geo_arg(
108 "g",
"geo",
"Input (.gml). Name of the geometry file",
true,
"",
111 TCLAP::ValueArg<std::string> output_arg(
112 "o",
"output",
"Output (.vtu). Name of the mesh file",
true,
"",
115 TCLAP::ValueArg<std::string> input_arg(
116 "i",
"input",
"Input (.vtu). Name of the mesh file",
true,
"",
120 cmd.add(log_level_arg);
121 cmd.parse(argc, argv);
126 std::pair<int, int> mat_limits(0, std::numeric_limits<int>::max());
127 std::pair<double, double> elevation_limits(
128 std::numeric_limits<double>::lowest(), dmax);
130 if (min_id_arg.isSet() != max_id_arg.isSet())
132 ERR(
"If minimum MaterialID is set, maximum ID must be set, too (and "
136 if (min_id_arg.isSet() && max_id_arg.isSet())
139 std::make_pair(min_id_arg.getValue(), max_id_arg.getValue());
141 if (mat_limits.first > mat_limits.second)
143 std::swap(mat_limits.first, mat_limits.second);
145 if (min_id_arg.isSet() && (mat_limits.first < 0 || mat_limits.second < 0))
147 ERR(
"Specified MaterialIDs must have non-negative values.");
150 if (min_elevation_arg.isSet() != max_elevation_arg.isSet())
152 ERR(
"If minimum elevation is set, maximum elevation must be set, too "
153 "(and vice versa).");
156 if (min_elevation_arg.isSet() && max_elevation_arg.isSet())
158 elevation_limits = std::make_pair(min_elevation_arg.getValue(),
159 max_elevation_arg.getValue());
161 if (elevation_limits.first > elevation_limits.second)
163 std::swap(elevation_limits.first, elevation_limits.second);
166 std::string
const& mesh_name = input_arg.getValue();
167 std::string
const& output_name = output_arg.getValue();
168 std::string
const& geo_name = geo_arg.getValue();
174 ERR(
"Failed to read geometry file `{:s}'.", geo_name);
177 std::vector<GeoLib::Point*>
const& points =
180 std::unique_ptr<MeshLib::Mesh>
const mesh(
184 ERR(
"Failed to read input mesh file `{:s}'.", mesh_name);
187 if (mesh->getDimension() != 3)
189 ERR(
"Method can only be applied to 3D meshes.");
193 auto const& nodes = mesh->getNodes();
195 if (mat_ids ==
nullptr)
197 ERR(
"Mesh is required to have MaterialIDs");
201 auto const& elems = mesh->getElements();
205 std::copy(mat_ids->cbegin(), mat_ids->cend(),
206 std::back_inserter(*new_mat_ids));
207 int const max_id = *std::max_element(mat_ids->begin(), mat_ids->end());
209 std::size_t
const n_points = points.size();
210 std::vector<MeshLib::Element*> new_elems =
213 for (std::size_t i = 0; i < n_points; ++i)
215 std::vector<std::size_t>
const& line_nodes =
getNodes(
216 *points[i], nodes, *mat_ids, mat_limits, elevation_limits, *mesh);
217 std::size_t
const n_line_nodes = line_nodes.size();
218 if (n_line_nodes < 2)
222 for (std::size_t j = 0; j < n_line_nodes - 1; ++j)
225 {new_nodes[line_nodes[j]], new_nodes[line_nodes[j + 1]]},
227 new_mat_ids->push_back(max_id + i + 1);
std::vector< std::size_t > getNodes(GeoLib::Point const &pnt, std::vector< MeshLib::Node * > const &nodes, MeshLib::PropertyVector< int > const &mat_ids, std::pair< int, int > const &mat_limits, std::pair< double, double > const &elevation_limits, MeshLib::Mesh const &mesh)