/// @file /// @brief TriangleMesh: class definition and member function declarations #pragma once // hpp #include // std::array #include // std::tuple #include // std::vector #include // std::unordered_set #include // std::filesystem namespace ex5 { ///@brief Two-dimensional triangle mesh class TriangleMesh { public: ///@brief Vertex coordinate using Vec2d = std::array; ///@brief Index triplet using Vec3i = std::array; ///@brief Axis-aligned bounding box described using the bottom left and upper right coordinate using BBox = std::tuple; private: std::vector vertices; ///< sequence of vertices std::vector triangles; ///< sequence of index triplets each indexing the three corner vertices of a triangle public: /// @brief Generates a regular triangular mesh pattern inside an axis-aligned bounding box /// @param box Axis-aligned bounding box of the generated mesh /// @param h Lower bound for the edge length of the generate triangles TriangleMesh(BBox box, double h); /// @brief Calculates the current axis-aligned bounding box /// @return Bounding box of all triangles/vertices in the mesh BBox bbox() const; /// @brief Read-only access to the vertices of the mesh /// @return Reference to the underlying sequence of vertices const std::vector& getVertices() const; /// @brief Read-only access to triangles of the mesh /// @return Reference to the underlying sequence of triangles const std::vector& getTriangles() const; /// @brief Prints the sequences of vertices and triangles to the console void print() const; /// @brief Generate SVG image /// @param filepath Filename for the generated output BBox save(std::filesystem::path filepath) const; /// @brief Evaluates the invariants of the class /// @return false, if any of the invariants is violated, true otherwise /// Invariants: /// - each triangle references valid indices /// - each triangle references three distinct corners /// - edges are not occupied more than twice (no hidden edges) /// - no unreferenced vertices are present bool check_invariants() const; /// @brief Removes a set of vertices from the mesh: /// - all triangles connected to the removed vertices are removed /// - all unused vertices potentially originating from the triangle removal are removed /// @param indices Vertex indices to be removed /// @return Total number of removed vertices and total number of removed triangles std::tuple remove_vertices(std::unordered_set indices); }; } // namespace mesh