28 const std::string& geo_name)
30 _geo_name(const_cast<std::string&>(geo_name)),
42 std::vector<GeoLib::Point*>
const* pnts(
63 std::vector<GeoLib::Point*>
const* pnts(
81 Eigen::Vector3d
const dir(0, 0, -1);
88 std::vector<MeshLib::Node> flat_nodes;
94 flat_nodes.emplace_back(*n_ptr);
95 flat_nodes.back()[2] = 0.0;
114 std::vector<GeoLib::Point*>
const* points(
116 if (points ==
nullptr)
121 std::for_each(points->begin(), points->end(),
137 for (
auto* pnt : points)
152 for (
auto* layer_pnt : layers)
154 (*layer_pnt)[2] = (*layer_pnt)[2] + offset;
160 std::vector<GeoLib::Point*>
const& points)
const
162 for (
auto* pnt : points)
170 std::vector<GeoLib::Point*>
const& pnts)
176 for (
auto* pnt : pnts)
181 if (p[0] < min[0] || max[0] < p[0])
185 if (p[1] < min[1] || max[1] < p[1])
196 double const elevation(
_raster->getValueAtPoint(pnt));
197 if (std::abs(elevation -
_raster->getHeader().no_data) <
198 std::numeric_limits<double>::epsilon())
202 return static_cast<float>(elevation);
206 double max_val)
const
212 std::unique_ptr<GeoLib::Point> intersection;
214 for (
auto const& element : elements)
216 if (intersection ==
nullptr &&
220 *element->getNode(0), *element->getNode(1),
225 if (intersection ==
nullptr &&
229 *element->getNode(0), *element->getNode(2),
236 return (*intersection)[2];
250 std::vector<MeshLib::Element const*>
const& elements,
253 for (
auto const elem : elements)
255 std::unique_ptr<MeshLib::Element> elem_2d(elem->clone());
257 for (std::size_t k(0); k < elem_2d->getNumberOfNodes(); ++k)
259 elem_2d->setNode(k,
new MeshLib::Node(*elem_2d->getNode(k)));
262 for (std::size_t k(0); k < elem_2d->getNumberOfNodes(); ++k)
269 for (std::size_t k(0); k < elem_2d->getNumberOfNodes(); ++k)
271 delete elem_2d->getNode(k);
276 for (std::size_t k(0); k < elem_2d->getNumberOfNodes(); ++k)
278 delete elem_2d->getNode(k);
287 std::vector<MathLib::Point3d> element_intersections;
291 std::unique_ptr<MeshLib::Element const>(elem.
getEdge(k));
300 std::vector<MathLib::Point3d>
const intersections(
302 element_intersections.insert(end(element_intersections),
303 begin(intersections), end(intersections));
305 return element_intersections;
309 std::vector<MathLib::Point3d>
const& intersections,
314 std::vector<GeoLib::LineSegment> sub_segments;
315 if (intersections.size() > 2)
317 std::stringstream out;
318 out <<
"element with id " << elem->
getID() <<
" and seg "
319 <<
" intersecting at more than two edges\n";
320 for (std::size_t k(0); k < intersections.size(); ++k)
322 out << k <<
" " << intersections[k] <<
"\n";
324 out <<
"Could not map segment on element. Aborting.\n";
328 if (intersections.size() == 1 && elem == beg_elem)
334 std::numeric_limits<double>::epsilon())
342 if (intersections.size() == 1 && elem == end_elem)
348 std::numeric_limits<double>::epsilon())
350 sub_segments.emplace_back(
new GeoLib::Point{intersections[0], 0},
355 if (intersections.size() == 1 && (elem != beg_elem && elem != end_elem))
363 if (intersections.size() == 2)
365 sub_segments.emplace_back(
new GeoLib::Point{intersections[0], 0},
373 std::vector<MeshLib::Element const*>
const& surface_elements,
377 std::vector<GeoLib::LineSegment> sub_segments;
381 for (
auto const elem : surface_elements)
384 std::vector<MathLib::Point3d> element_intersections(
386 if (element_intersections.empty())
393 std::vector<GeoLib::LineSegment> sub_seg_elem(
395 end_elem, beg_pnt, end_pnt, elem));
396 sub_segments.insert(sub_segments.end(), sub_seg_elem.begin(),
403 if (beg_elem ==
nullptr)
405 auto min_dist_segment = std::min_element(
406 sub_segments.begin(), sub_segments.end(),
412 std::min(MathLib::sqrDist(beg_pnt, seg0.getBeginPoint()),
413 MathLib::sqrDist(beg_pnt, seg0.getEndPoint())));
416 std::min(MathLib::sqrDist(beg_pnt, seg1.getBeginPoint()),
417 MathLib::sqrDist(beg_pnt, seg1.getEndPoint())));
425 sub_segments.emplace_back(
new GeoLib::Point{beg_pnt, 0}, pnt,
true);
430 sub_segments.erase(std::unique(sub_segments.begin(), sub_segments.end()),
448 double const d(n.dot(p));
449 q[2] = (d - n[0] * q[0] - n[1] * q[1]) / n[2];
453static std::vector<MeshLib::Element const*>
465 std::array<MathLib::Point3d, 2>
const pnts{
470 auto convert_to_Point3d = [](Eigen::Vector3d
const& v) {
474 auto const min = convert_to_Point3d(aabb.
getMinPoint());
475 auto const max = convert_to_Point3d(aabb.
getMaxPoint());
481 return candidate_elements;
490 double const sqr_eps(rel_eps * rel_eps * sqr_min);
493 auto const& node(*elem.
getNode(k));
495 if (sqr_dist_2d < sqr_eps)
497#ifdef DEBUG_GEOMAPPER
498 std::stringstream out;
499 out.precision(std::numeric_limits<double>::max_digits10);
500 out <<
"Segment point snapped from " << p;
503#ifdef DEBUG_GEOMAPPER
505 DBUG(
"{:s}", out.str());
516 std::vector<GeoLib::LineSegment>
const& sub_segments)
519 std::size_t new_pnts_cnt(0);
520 for (
auto const& segment : sub_segments)
524 if (ply.
insertPoint(j + new_pnts_cnt + 1, begin_id))
535 std::advance(segment_it, new_pnts_cnt);
544 for (
auto segment_it(ply.
begin()); segment_it != ply.
end(); ++segment_it)
547 mesh_element_grid, *segment_it));
564 auto const* beg_elem(mapPoint((*segment_it).getBeginPoint()));
565 auto const* end_elem(mapPoint((*segment_it).getEndPoint()));
572 if (beg_elem == end_elem)
587 *segment_it, candidate_elements, beg_elem, end_elem));
589 if (sub_segments.empty())
596 if (sub_segments.size() > 1)
614 Eigen::Vector3d
const dir({0, 0, -1});
616 mesh, dir, 90 + 1e-6);
625 for (
auto org_line : *org_lines)
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
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.
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
unsigned getDimension() 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.