#pragma once #include "config/types.h" #include "ray.h" #include "triangle.h" #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 GeoDataMesh : public OpenMesh::TriMesh_ArrayKernelT { public: struct PointFace { // NOLINTNEXTLINE(hicpp-explicit-conversions) PointFace(GlobalPosition2D coord) : point {coord} { } PointFace(GlobalPosition2D coord, FaceHandle face) : point {coord}, faceCache {face} { } PointFace(GlobalPosition2D coord, const GeoDataMesh *); PointFace(GlobalPosition2D coord, GeoDataMesh const *, FaceHandle start); const GlobalPosition2D point; [[nodiscard]] FaceHandle face(const GeoDataMesh *) const; [[nodiscard]] FaceHandle face(const GeoDataMesh *, FaceHandle start) const; [[nodiscard]] bool isLocated() const { return faceCache.is_valid(); } private: mutable FaceHandle faceCache; }; template using Triangle = ::Triangle; [[nodiscard]] FaceHandle findPoint(GlobalPosition2D) const; [[nodiscard]] FaceHandle findPoint(GlobalPosition2D, FaceHandle) const; [[nodiscard]] GlobalPosition3D positionAt(const PointFace &) const; protected: void sanityCheck(const std::source_location & = std::source_location::current()) const; [[nodiscard]] bool faceContainsPoint(GlobalPosition2D, FaceHandle) const; [[nodiscard]] HalfedgeHandle findBoundaryStart() const; [[nodiscard]] RelativePosition3D difference(HalfedgeHandle) const; using HalfEdgeVertices = std::pair; [[nodiscard]] HalfEdgeVertices toVertexHandles(HalfedgeHandle) const; using HalfEdgePoints = std::pair; [[nodiscard]] HalfEdgePoints points(HalfEdgeVertices) const; template [[nodiscard]] RelativeDistance length(HalfedgeHandle heh) const { return ::distance( point(to_vertex_handle(heh)), point(from_vertex_handle(heh))); } [[nodiscard]] GlobalPosition3D centre(HalfedgeHandle) const; template [[nodiscard]] Triangle triangle(FaceHandle face) const { Triangle triangle; std::ranges::transform(fv_range(face), triangle.begin(), [this](auto vertex) { return point(vertex); }); return triangle; } };