#pragma once #include "collections.h" // IWYU pragma: keep IterableCollection #include "config/types.h" #include "ray.h" #include #include #include #include #include struct GeoDataTraits : public OpenMesh::DefaultTraits { FaceAttributes(OpenMesh::Attributes::Status); EdgeAttributes(OpenMesh::Attributes::Status); VertexAttributes(OpenMesh::Attributes::Normal | OpenMesh::Attributes::Status); HalfedgeAttributes(OpenMesh::Attributes::Status); using Point = GlobalPosition3D; using Normal = Normal3D; }; class GeoData : public OpenMesh::TriMesh_ArrayKernelT { private: GeoData() = default; public: static GeoData loadFromAsciiGrid(const std::filesystem::path &); static GeoData createFlat(GlobalPosition2D lower, GlobalPosition2D upper, GlobalDistance h); struct PointFace { // NOLINTNEXTLINE(hicpp-explicit-conversions) PointFace(const GlobalPosition2D p) : point {p} { } PointFace(const GlobalPosition2D p, FaceHandle face) : point {p}, _face {face} { } PointFace(const GlobalPosition2D p, const GeoData *); PointFace(const GlobalPosition2D p, const GeoData *, FaceHandle start); const GlobalPosition2D point; [[nodiscard]] FaceHandle face(const GeoData *) const; [[nodiscard]] FaceHandle face(const GeoData *, FaceHandle start) const; [[nodiscard]] bool isLocated() const { return _face.is_valid(); } private: mutable FaceHandle _face {}; }; template struct Triangle : public glm::vec<3, glm::vec> { using base = glm::vec<3, glm::vec>; using base::base; template Triangle(const GeoData * m, Range range) { assert(std::distance(range.begin(), range.end()) == 3); std::transform(range.begin(), range.end(), &base::operator[](0), [m](auto vh) { return m->point(vh); }); } glm::vec operator*(BaryPosition bari) const { const auto & t {*this}; return t[0] + (RelativePosition(t[1] - t[0]) * bari.x) + (RelativePosition(t[2] - t[1]) * bari.y); } }; [[nodiscard]] FaceHandle findPoint(GlobalPosition2D) const; [[nodiscard]] FaceHandle findPoint(GlobalPosition2D, FaceHandle start) const; [[nodiscard]] GlobalPosition3D positionAt(const PointFace &) const; [[nodiscard]] std::optional intersectRay(const Ray &) const; [[nodiscard]] std::optional intersectRay(const Ray &, FaceHandle start) const; void walk(const PointFace & from, const GlobalPosition2D to, const std::function & op) const; void walkUntil(const PointFace & from, const GlobalPosition2D to, const std::function & op) const; void boundaryWalk(const std::function &) const; void boundaryWalk(const std::function &, HalfedgeHandle start) const; void boundaryWalkUntil(const std::function &) const; void boundaryWalkUntil(const std::function &, HalfedgeHandle start) const; [[nodiscard]] HalfedgeHandle findEntry(const GlobalPosition2D from, const GlobalPosition2D to) const; [[nodiscard]] auto getExtents() const { return std::tie(lowerExtent, upperExtent); } protected: template [[nodiscard]] Triangle triangle(FaceHandle f) const { return {this, fv_range(f)}; } [[nodiscard]] static bool triangleContainsPoint(const GlobalPosition2D, const Triangle<2> &); [[nodiscard]] bool triangleContainsPoint(const GlobalPosition2D, FaceHandle) const; [[nodiscard]] HalfedgeHandle findBoundaryStart() const; void update_vertex_normals_only(); private: GlobalPosition3D lowerExtent {}, upperExtent {}; };