38 const std::string& geo_name)
39 : _geo_objects(geo_objects),
40 _geo_name(const_cast<std::string&>(geo_name)),
41 _surface_mesh(nullptr),
54 std::vector<GeoLib::Point*>
const* pnts(
75 std::vector<GeoLib::Point*>
const* pnts(
93 Eigen::Vector3d
const dir(0, 0, -1);
100 std::vector<MeshLib::Node> flat_nodes;
106 flat_nodes.emplace_back(*n_ptr);
107 flat_nodes.back()[2] = 0.0;
126 std::vector<GeoLib::Point*>
const* points(
128 if (points ==
nullptr)
133 std::for_each(points->begin(), points->end(),
149 for (
auto* pnt : points)
164 for (
auto* layer_pnt : layers)
166 (*layer_pnt)[2] = (*layer_pnt)[2] + offset;
172 std::vector<GeoLib::Point*>
const& points)
const
174 for (
auto* pnt : points)
182 std::vector<GeoLib::Point*>
const& pnts)
188 for (
auto* pnt : pnts)
193 if (p[0] < min[0] || max[0] < p[0])
197 if (p[1] < min[1] || max[1] < p[1])
208 double const elevation(
_raster->getValueAtPoint(pnt));
209 if (std::abs(elevation -
_raster->getHeader().no_data) <
210 std::numeric_limits<double>::epsilon())
214 return static_cast<float>(elevation);
218 double max_val)
const
224 std::unique_ptr<GeoLib::Point> intersection;
226 for (
auto const& element : elements)
228 if (intersection ==
nullptr &&
232 *element->getNode(0), *element->getNode(1),
237 if (intersection ==
nullptr &&
241 *element->getNode(0), *element->getNode(2),
248 return (*intersection)[2];
262 std::vector<MeshLib::Element const*>
const& elements,
265 for (
auto const elem : elements)
267 std::unique_ptr<MeshLib::Element> elem_2d(elem->clone());
269 for (std::size_t k(0); k < elem_2d->getNumberOfNodes(); ++k)
271 elem_2d->setNode(k,
new MeshLib::Node(*elem_2d->getNode(k)));
274 for (std::size_t k(0); k < elem_2d->getNumberOfNodes(); ++k)
281 for (std::size_t k(0); k < elem_2d->getNumberOfNodes(); ++k)
283 delete elem_2d->getNode(k);
288 for (std::size_t k(0); k < elem_2d->getNumberOfNodes(); ++k)
290 delete elem_2d->getNode(k);
299 std::vector<MathLib::Point3d> element_intersections;
303 std::unique_ptr<MeshLib::Element const>(elem.
getEdge(k));
312 std::vector<MathLib::Point3d>
const intersections(
314 element_intersections.insert(end(element_intersections),
315 begin(intersections), end(intersections));
317 return element_intersections;
321 std::vector<MathLib::Point3d>
const& intersections,
326 std::vector<GeoLib::LineSegment> sub_segments;
327 if (intersections.size() > 2)
329 std::stringstream out;
330 out <<
"element with id " << elem->
getID() <<
" and seg "
331 <<
" intersecting at more than two edges\n";
332 for (std::size_t k(0); k < intersections.size(); ++k)
334 out << k <<
" " << intersections[k] <<
"\n";
336 out <<
"Could not map segment on element. Aborting.\n";
340 if (intersections.size() == 1 && elem == beg_elem)
346 std::numeric_limits<double>::epsilon())
354 if (intersections.size() == 1 && elem == end_elem)
360 std::numeric_limits<double>::epsilon())
362 sub_segments.emplace_back(
new GeoLib::Point{intersections[0], 0},
367 if (intersections.size() == 1 && (elem != beg_elem && elem != end_elem))
375 if (intersections.size() == 2)
377 sub_segments.emplace_back(
new GeoLib::Point{intersections[0], 0},
385 std::vector<MeshLib::Element const*>
const& surface_elements,
389 std::vector<GeoLib::LineSegment> sub_segments;
393 for (
auto const elem : surface_elements)
396 std::vector<MathLib::Point3d> element_intersections(
398 if (element_intersections.empty())
405 std::vector<GeoLib::LineSegment> sub_seg_elem(
407 end_elem, beg_pnt, end_pnt, elem));
408 sub_segments.insert(sub_segments.end(), sub_seg_elem.begin(),
415 if (beg_elem ==
nullptr)
417 auto min_dist_segment = std::min_element(
418 sub_segments.begin(), sub_segments.end(),
424 std::min(MathLib::sqrDist(beg_pnt, seg0.getBeginPoint()),
425 MathLib::sqrDist(beg_pnt, seg0.getEndPoint())));
428 std::min(MathLib::sqrDist(beg_pnt, seg1.getBeginPoint()),
429 MathLib::sqrDist(beg_pnt, seg1.getEndPoint())));
437 sub_segments.emplace_back(
new GeoLib::Point{beg_pnt, 0}, pnt,
true);
442 sub_segments.erase(std::unique(sub_segments.begin(), sub_segments.end()),
460 double const d(n.dot(p));
461 q[2] = (d - n[0] * q[0] - n[1] * q[1]) / n[2];
465static std::vector<MeshLib::Element const*>
477 std::array<MathLib::Point3d, 2>
const pnts{
482 auto convert_to_Point3d = [](Eigen::Vector3d
const& v) {
486 auto const min = convert_to_Point3d(aabb.
getMinPoint());
487 auto const max = convert_to_Point3d(aabb.
getMaxPoint());
493 return candidate_elements;
502 double const sqr_eps(rel_eps * rel_eps * sqr_min);
505 auto const& node(*elem.
getNode(k));
507 if (sqr_dist_2d < sqr_eps)
509#ifdef DEBUG_GEOMAPPER
510 std::stringstream out;
511 out.precision(std::numeric_limits<double>::max_digits10);
512 out <<
"Segment point snapped from " << p;
515#ifdef DEBUG_GEOMAPPER
517 DBUG(
"{:s}", out.str());
528 std::vector<GeoLib::LineSegment>
const& sub_segments)
531 std::size_t new_pnts_cnt(0);
532 for (
auto const& segment : sub_segments)
536 if (ply.
insertPoint(j + new_pnts_cnt + 1, begin_id))
547 segment_it += new_pnts_cnt;
556 for (
auto segment_it(ply.
begin()); segment_it != ply.
end(); ++segment_it)
559 mesh_element_grid, *segment_it));
576 auto const* beg_elem(mapPoint((*segment_it).getBeginPoint()));
577 auto const* end_elem(mapPoint((*segment_it).getEndPoint()));
584 if (beg_elem == end_elem)
599 *segment_it, candidate_elements, beg_elem, end_elem));
601 if (sub_segments.empty())
608 if (sub_segments.size() > 1)
618 delete _surface_mesh;
626 Eigen::Vector3d
const dir({0, 0, -1});
628 mesh, dir, 90 + 1e-6);
635 auto org_lines(_geo_objects.getPolylineVec(_geo_name));
636 auto org_points(_geo_objects.getPointVecObj(_geo_name));
637 for (
auto org_line : *org_lines)
Definition of the AABB class.
Definition of analytical geometry functions.
Definition of the Element class.
Definition of the GEOObjects class.
Definition of the GeoMapper class.
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the Mesh class.
Definition of the Node class.
Definition of the GeoLib::Raster class.
Definition of the StationBorehole class.
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Eigen::Vector3d const & getMaxPoint() const
Eigen::Vector3d const & getMinPoint() const
MinMaxPoints getMinMaxPoints() const
Container class for geometric objects.
const std::vector< Point * > * getPointVec(const std::string &name) const
POINT * getNearestPoint(P const &pnt) const
GeoLib::Point const & getBeginPoint() const
GeoLib::Point const & getEndPoint() const
This class manages pointers to Points in a std::vector along with a name. It also handles the deletio...
std::size_t push_back(Point *pnt)
void resetInternalDataStructures()
std::size_t getSegmentNumber() const
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
virtual bool insertPoint(std::size_t pos, std::size_t pnt_id)
SegmentIterator begin() const
SegmentIterator end() const
A borehole as a geometric object.
std::size_t getID() const
Eigen::Vector3d const & asEigenVector3d() const
virtual const Element * getEdge(unsigned i) const =0
Returns the i-th edge of the element.
virtual unsigned getNumberOfNodes() const =0
virtual const Node * getNode(unsigned idx) const =0
virtual unsigned getNumberOfEdges() const =0
Get the number of edges for this element.
std::size_t getID() const
Returns the ID of the element.
static Eigen::Vector3d getSurfaceNormal(Element const &e)
Returns the surface normal of a 2D element.
Eigen::Vector3d const & getMinPoint() const
std::vector< MeshLib::Element const * > getElementsInVolume(POINT const &min, POINT const &max) const
Eigen::Vector3d const & getMaxPoint() const
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
const Node * getNode(std::size_t idx) const
Get the node with the given index.
std::size_t getNumberOfNodes() const
Get the number of nodes.
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
void makeVectorUnique(std::vector< T > &v)
bool isStation(GeoLib::Point const *pnt)
void sortSegments(MathLib::Point3d const &seg_beg_pnt, std::vector< GeoLib::LineSegment > &sub_segments)
bool isBorehole(GeoLib::Point const *pnt)
std::vector< MathLib::Point3d > lineSegmentIntersect2d(GeoLib::LineSegment const &ab, GeoLib::LineSegment const &cd)
std::unique_ptr< GeoLib::Point > triangleLineIntersection(MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c, MathLib::Point3d const &p, MathLib::Point3d const &q)
double sqrDist2d(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
double sqrDist(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
std::pair< double, double > computeSqrNodeDistanceRange(MeshLib::Element const &element, bool const check_allnodes)
Compute the minimum and maximum node distances for this element.