From 57d1b3c9a5c14588daf4096ffa3e9ef93dd7ceed Mon Sep 17 00:00:00 2001 From: rahv <karsten.rink@ufz.de> Date: Thu, 29 Jan 2015 15:36:16 +0100 Subject: [PATCH] added boundary extraction method that will return lines for 2d meshes --- MeshLib/MeshSurfaceExtraction.cpp | 47 +++++++++++++++++++++++++++---- MeshLib/MeshSurfaceExtraction.h | 6 ++-- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/MeshLib/MeshSurfaceExtraction.cpp b/MeshLib/MeshSurfaceExtraction.cpp index 82f4a7863b3..ede09883d0d 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 fd58ff99a67..2c0c3f9fee7 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); -- GitLab