diff --git a/MeshLib/MeshSurfaceExtraction.cpp b/MeshLib/MeshSurfaceExtraction.cpp index 82f4a7863b373407973b4b1262cce871dff30181..ede09883d0df0112d134cd8065b146fb8cc2a3d3 100644 --- a/MeshLib/MeshSurfaceExtraction.cpp +++ b/MeshLib/MeshSurfaceExtraction.cpp @@ -20,11 +20,14 @@ #include "GeoLib/PointWithID.h" -#include "Mesh.h" -#include "Elements/Face.h" -#include "Elements/Cell.h" -#include "Elements/Tri.h" -#include "Elements/Quad.h" +#include "MeshLib/Mesh.h" +#include "MeshLib/Elements/Line.h" +#include "MeshLib/Elements/Face.h" +#include "MeshLib/Elements/Cell.h" +#include "MeshLib/Elements/Tri.h" +#include "MeshLib/Elements/Quad.h" +#include "MeshLib/MeshEditing/DuplicateMeshComponents.h" +#include "MeshLib/MeshQuality/MeshValidation.h" namespace MeshLib { @@ -118,6 +121,40 @@ MeshLib::Mesh* MeshSurfaceExtraction::getMeshSurface(const MeshLib::Mesh &mesh, return result; } +MeshLib::Mesh* MeshSurfaceExtraction::getMeshBoundary(const MeshLib::Mesh &mesh) +{ + if (mesh.getDimension()==1) + return nullptr; + + // For 3D meshes return the 2D surface + if (mesh.getDimension()==3) + { + MathLib::Vector3 dir(0,0,0); + return getMeshSurface(mesh, dir, 90); + } + + // For 2D meshes return the boundary lines + std::vector<MeshLib::Node*> nodes = MeshLib::copyNodeVector(mesh.getNodes()); + std::vector<MeshLib::Element*> boundary_elements; + + std::vector<MeshLib::Element*> const& org_elems (mesh.getElements()); + for (auto it=org_elems.begin(); it!=org_elems.end(); ++it) + { + MeshLib::Element* elem (*it); + std::size_t const n_edges (elem->getNEdges()); + for (std::size_t i=0; i<n_edges; ++i) + if (elem->getNeighbor(i) == nullptr) + { + MeshLib::Element const*const edge (elem->getEdge(i)); + boundary_elements.push_back(MeshLib::copyElement(edge, nodes)); + delete edge; + } + } + MeshLib::Mesh* result = new MeshLib::Mesh("Boundary Mesh", nodes, boundary_elements); + MeshLib::MeshValidation::removeUnusedMeshNodes(*result); + return result; +} + void MeshSurfaceExtraction::get2DSurfaceElements(const std::vector<MeshLib::Element*> &all_elements, std::vector<MeshLib::Element*> &sfc_elements, const MathLib::Vector3 &dir, double angle, unsigned mesh_dimension) { if (mesh_dimension<2 || mesh_dimension>3) diff --git a/MeshLib/MeshSurfaceExtraction.h b/MeshLib/MeshSurfaceExtraction.h index fd58ff99a6738951d658f7212afb5ea9a24eecd6..2c0c3f9fee73e60a7eb2621e1260e3b4b38ea791 100644 --- a/MeshLib/MeshSurfaceExtraction.h +++ b/MeshLib/MeshSurfaceExtraction.h @@ -39,11 +39,11 @@ public: /// Returns a vector of the areas assigned to each node on a surface mesh. static std::vector<double> getSurfaceAreaForNodes(const MeshLib::Mesh &mesh); - /// Returns the surface nodes of a layered mesh. + /// Returns the surface nodes of a mesh. static std::vector<GeoLib::PointWithID*> getSurfaceNodes(const MeshLib::Mesh &mesh, const MathLib::Vector3 &dir, double angle); /** - * Returns the 2d-element mesh representing the surface of the given layered mesh. + * Returns the 2d-element mesh representing the surface of the given mesh. * \param mesh The original mesh * \param dir The direction in which face normals have to point to be considered surface elements * \param angle The angle of the allowed deviation from the given direction (0 <= angle <= 90 degrees) @@ -52,6 +52,8 @@ public: */ static MeshLib::Mesh* getMeshSurface(const MeshLib::Mesh &mesh, const MathLib::Vector3 &dir, double angle, bool keepOriginalNodeIds = false); + static MeshLib::Mesh* getMeshBoundary(const MeshLib::Mesh &mesh); + private: /// Functionality needed for getSurfaceNodes() and getMeshSurface() static void get2DSurfaceElements(const std::vector<MeshLib::Element*> &all_elements, std::vector<MeshLib::Element*> &sfc_elements, const MathLib::Vector3 &dir, double angle, unsigned mesh_dimension);