33 GeoLib::Point const& pnt, std::vector<MeshLib::Node*>
const& nodes,
35 std::pair<int, int>
const& mat_limits,
36 std::pair<double, double>
const& elevation_limits,
39 std::vector<std::size_t> pnt_nodes;
40 for (
auto node : nodes)
42 double const eps = std::numeric_limits<double>::epsilon();
43 if (std::abs((*node)[0] - pnt[0]) < eps &&
44 std::abs((*node)[1] - pnt[1]) < eps)
49 if (mat_ids[e->getID()] >= mat_limits.first &&
50 mat_ids[e->getID()] <= mat_limits.second &&
51 (*node)[2] >= elevation_limits.first &&
52 (*node)[2] <= elevation_limits.second)
54 pnt_nodes.push_back(node->getID());
60 if (pnt_nodes.size() < 2)
62 WARN(
"No nodes found for point {:d}...", pnt.
getID());
67 std::sort(pnt_nodes.begin(), pnt_nodes.end(),
68 [nodes](std::size_t a, std::size_t b)
69 { return (*nodes[a])[2] > (*nodes[b])[2]; });
74int main(
int argc,
char* argv[])
77 "Integrates line elements representing boreholes into a pre-existing "
78 "3D mesh. Corresponding nodes matching the (x,y)-coordinates given in "
79 "the gml-file are found in the mesh and connected from top to bottom "
80 "via line elements. Each borehole (i.e. all points at a given "
81 "(x,y)-location but at different depths) is assigned a unique material "
82 "ID. Vertical limits of boreholes can be specified via Material IDs "
83 "and/or elevation. Point not matching any mesh nodes or located outside"
84 " the mesh are ignored.\n\n"
85 "OpenGeoSys-6 software, version " +
88 "Copyright (c) 2012-2025, OpenGeoSys Community "
89 "(http://www.opengeosys.org)",
92 double const dmax = std::numeric_limits<double>::max();
93 TCLAP::ValueArg<double> max_elevation_arg(
95 "Maximum elevation for an integrated borehole, "
97 false, 0,
"MAX_ELEVATION");
98 cmd.add(max_elevation_arg);
99 TCLAP::ValueArg<double> min_elevation_arg(
101 "Minimum elevation for an integrated borehole, "
103 false, 0,
"MIN_ELEVATION");
104 cmd.add(min_elevation_arg);
105 TCLAP::ValueArg<int> max_id_arg(
106 "",
"max-id",
"Maximum MaterialID for an integrated borehole",
false,
109 TCLAP::ValueArg<int> min_id_arg(
110 "",
"min-id",
"Minimum MaterialID for an integrated borehole",
false,
113 TCLAP::ValueArg<std::string> geo_arg(
114 "g",
"geo",
"Input (.gml). Name of the geometry file",
true,
"",
117 TCLAP::ValueArg<std::string> output_arg(
118 "o",
"output",
"Output (.vtu). Name of the mesh file",
true,
"",
121 TCLAP::ValueArg<std::string> input_arg(
122 "i",
"input",
"Input (.vtu). Name of the mesh file",
true,
"",
126 cmd.add(log_level_arg);
127 cmd.parse(argc, argv);
132 std::pair<int, int> mat_limits(0, std::numeric_limits<int>::max());
133 std::pair<double, double> elevation_limits(
134 std::numeric_limits<double>::lowest(), dmax);
136 if (min_id_arg.isSet() != max_id_arg.isSet())
138 ERR(
"If minimum MaterialID is set, maximum ID must be set, too (and "
142 if (min_id_arg.isSet() && max_id_arg.isSet())
145 std::make_pair(min_id_arg.getValue(), max_id_arg.getValue());
147 if (mat_limits.first > mat_limits.second)
149 std::swap(mat_limits.first, mat_limits.second);
151 if (min_id_arg.isSet() && (mat_limits.first < 0 || mat_limits.second < 0))
153 ERR(
"Specified MaterialIDs must have non-negative values.");
156 if (min_elevation_arg.isSet() != max_elevation_arg.isSet())
158 ERR(
"If minimum elevation is set, maximum elevation must be set, too "
159 "(and vice versa).");
162 if (min_elevation_arg.isSet() && max_elevation_arg.isSet())
164 elevation_limits = std::make_pair(min_elevation_arg.getValue(),
165 max_elevation_arg.getValue());
167 if (elevation_limits.first > elevation_limits.second)
169 std::swap(elevation_limits.first, elevation_limits.second);
172 std::string
const& mesh_name = input_arg.getValue();
173 std::string
const& output_name = output_arg.getValue();
174 std::string
const& geo_name = geo_arg.getValue();
180 ERR(
"Failed to read geometry file `{:s}'.", geo_name);
183 std::vector<GeoLib::Point*>
const& points =
186 std::unique_ptr<MeshLib::Mesh>
const mesh(
190 ERR(
"Failed to read input mesh file `{:s}'.", mesh_name);
193 if (mesh->getDimension() != 3)
195 ERR(
"Method can only be applied to 3D meshes.");
199 auto const& nodes = mesh->getNodes();
201 if (mat_ids ==
nullptr)
203 ERR(
"Mesh is required to have MaterialIDs");
207 auto const& elems = mesh->getElements();
211 std::copy(mat_ids->cbegin(), mat_ids->cend(),
212 std::back_inserter(*new_mat_ids));
213 int const max_id = *std::max_element(mat_ids->begin(), mat_ids->end());
215 std::size_t
const n_points = points.size();
216 std::vector<MeshLib::Element*> new_elems =
219 for (std::size_t i = 0; i < n_points; ++i)
221 std::vector<std::size_t>
const& line_nodes =
getNodes(
222 *points[i], nodes, *mat_ids, mat_limits, elevation_limits, *mesh);
223 std::size_t
const n_line_nodes = line_nodes.size();
224 if (n_line_nodes < 2)
228 for (std::size_t j = 0; j < n_line_nodes - 1; ++j)
231 {new_nodes[line_nodes[j]], new_nodes[line_nodes[j + 1]]},
233 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)