27 const std::string& geo_name)
29 _geo_name(const_cast<std::string&>(geo_name)),
43 std::vector<GeoLib::Point*>
const* pnts(
64 std::vector<GeoLib::Point*>
const* pnts(
82 Eigen::Vector3d
const dir(0, 0, -1);
89 std::vector<MeshLib::Node> flat_nodes;
95 flat_nodes.emplace_back(*n_ptr);
96 flat_nodes.back()[2] = 0.0;
115 std::vector<GeoLib::Point*>
const* points(
117 if (points ==
nullptr)
122 std::for_each(points->begin(), points->end(),
138 for (
auto* pnt : points)
153 for (
auto* layer_pnt : layers)
155 (*layer_pnt)[2] = (*layer_pnt)[2] + offset;
161 std::vector<GeoLib::Point*>
const& points)
const
163 for (
auto* pnt : points)
171 std::vector<GeoLib::Point*>
const& pnts)
177 for (
auto* pnt : pnts)
182 if (p[0] < min[0] || max[0] < p[0])
186 if (p[1] < min[1] || max[1] < p[1])
197 double const elevation(
_raster->getValueAtPoint(pnt));
198 if (std::abs(elevation -
_raster->getHeader().no_data) <
199 std::numeric_limits<double>::epsilon())
203 return static_cast<float>(elevation);
207 double max_val)
const
213 std::unique_ptr<GeoLib::Point> intersection;
215 for (
auto const& element : elements)
217 if (intersection ==
nullptr &&
221 *element->getNode(0), *element->getNode(1),
226 if (intersection ==
nullptr &&
230 *element->getNode(0), *element->getNode(2),
237 return (*intersection)[2];
251 std::vector<MeshLib::Element const*>
const& elements,
254 for (
auto const elem : elements)
256 std::unique_ptr<MeshLib::Element> elem_2d(elem->clone());
258 for (std::size_t k(0); k < elem_2d->getNumberOfNodes(); ++k)
260 elem_2d->setNode(k,
new MeshLib::Node(*elem_2d->getNode(k)));
263 for (std::size_t k(0); k < elem_2d->getNumberOfNodes(); ++k)
270 for (std::size_t k(0); k < elem_2d->getNumberOfNodes(); ++k)
272 delete elem_2d->getNode(k);
277 for (std::size_t k(0); k < elem_2d->getNumberOfNodes(); ++k)
279 delete elem_2d->getNode(k);
288 std::vector<MathLib::Point3d> element_intersections;
292 std::unique_ptr<MeshLib::Element const>(elem.
getEdge(k));
301 std::vector<MathLib::Point3d>
const intersections(
303 element_intersections.insert(end(element_intersections),
304 begin(intersections), end(intersections));
306 return element_intersections;
310 std::vector<MathLib::Point3d>
const& intersections,
315 std::vector<GeoLib::LineSegment> sub_segments;
316 if (intersections.size() > 2)
318 std::stringstream out;
319 out <<
"element with id " << elem->
getID() <<
" and seg "
320 <<
" intersecting at more than two edges\n";
321 for (std::size_t k(0); k < intersections.size(); ++k)
323 out << k <<
" " << intersections[k] <<
"\n";
325 out <<
"Could not map segment on element. Aborting.\n";
329 if (intersections.size() == 1 && elem == beg_elem)
335 std::numeric_limits<double>::epsilon())
343 if (intersections.size() == 1 && elem == end_elem)
349 std::numeric_limits<double>::epsilon())
351 sub_segments.emplace_back(
new GeoLib::Point{intersections[0], 0},
356 if (intersections.size() == 1 && (elem != beg_elem && elem != end_elem))
364 if (intersections.size() == 2)
366 sub_segments.emplace_back(
new GeoLib::Point{intersections[0], 0},
374 std::vector<MeshLib::Element const*>
const& surface_elements,
378 std::vector<GeoLib::LineSegment> sub_segments;
382 for (
auto const elem : surface_elements)
385 std::vector<MathLib::Point3d> element_intersections(
387 if (element_intersections.empty())
394 std::vector<GeoLib::LineSegment> sub_seg_elem(
396 end_elem, beg_pnt, end_pnt, elem));
397 sub_segments.insert(sub_segments.end(), sub_seg_elem.begin(),
404 if (beg_elem ==
nullptr)
406 auto min_dist_segment = std::min_element(
407 sub_segments.begin(), sub_segments.end(),
413 std::min(MathLib::sqrDist(beg_pnt, seg0.getBeginPoint()),
414 MathLib::sqrDist(beg_pnt, seg0.getEndPoint())));
417 std::min(MathLib::sqrDist(beg_pnt, seg1.getBeginPoint()),
418 MathLib::sqrDist(beg_pnt, seg1.getEndPoint())));
426 sub_segments.emplace_back(
new GeoLib::Point{beg_pnt, 0}, pnt,
true);
431 sub_segments.erase(std::unique(sub_segments.begin(), sub_segments.end()),
449 double const d(n.dot(p));
450 q[2] = (d - n[0] * q[0] - n[1] * q[1]) / n[2];
454static std::vector<MeshLib::Element const*>
466 std::array<MathLib::Point3d, 2>
const pnts{
471 auto convert_to_Point3d = [](Eigen::Vector3d
const& v) {
475 auto const min = convert_to_Point3d(aabb.
getMinPoint());
476 auto const max = convert_to_Point3d(aabb.
getMaxPoint());
482 return candidate_elements;
491 double const sqr_eps(rel_eps * rel_eps * sqr_min);
494 auto const& node(*elem.
getNode(k));
496 if (sqr_dist_2d < sqr_eps)
498#ifdef DEBUG_GEOMAPPER
499 std::stringstream out;
500 out.precision(std::numeric_limits<double>::max_digits10);
501 out <<
"Segment point snapped from " << p;
504#ifdef DEBUG_GEOMAPPER
506 DBUG(
"{:s}", out.str());
517 std::vector<GeoLib::LineSegment>
const& sub_segments)
520 std::size_t new_pnts_cnt(0);
521 for (
auto const& segment : sub_segments)
525 if (ply.
insertPoint(j + new_pnts_cnt + 1, begin_id))
536 segment_it += new_pnts_cnt;
545 for (
auto segment_it(ply.
begin()); segment_it != ply.
end(); ++segment_it)
548 mesh_element_grid, *segment_it));
565 auto const* beg_elem(mapPoint((*segment_it).getBeginPoint()));
566 auto const* end_elem(mapPoint((*segment_it).getEndPoint()));
573 if (beg_elem == end_elem)
588 *segment_it, candidate_elements, beg_elem, end_elem));
590 if (sub_segments.empty())
597 if (sub_segments.size() > 1)
615 Eigen::Vector3d
const dir({0, 0, -1});
617 mesh, dir, 90 + 1e-6);
626 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
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
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.