From 95f0c7c009dcbfbfa3e4dc5238cce4232d3eead5 Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Tue, 21 Jan 2020 13:56:41 +0100 Subject: [PATCH] [MGTL] BoundaryElementsAlongPolyline: format. --- .../BoundaryElementsAlongPolyline.cpp | 68 ++++++++++--------- .../BoundaryElementsAlongPolyline.h | 47 +++++++++---- 2 files changed, 69 insertions(+), 46 deletions(-) diff --git a/MeshGeoToolsLib/BoundaryElementsAlongPolyline.cpp b/MeshGeoToolsLib/BoundaryElementsAlongPolyline.cpp index 6afa244b905..2ac93a42e3c 100644 --- a/MeshGeoToolsLib/BoundaryElementsAlongPolyline.cpp +++ b/MeshGeoToolsLib/BoundaryElementsAlongPolyline.cpp @@ -13,14 +13,12 @@ #include "BaseLib/quicksort.h" #include "GeoLib/Polyline.h" - -#include "MeshLib/Mesh.h" -#include "MeshLib/Node.h" +#include "MeshGeoToolsLib/MeshNodeSearcher.h" #include "MeshLib/Elements/Element.h" #include "MeshLib/Elements/Line.h" +#include "MeshLib/Mesh.h" #include "MeshLib/MeshSearch/ElementSearch.h" - -#include "MeshGeoToolsLib/MeshNodeSearcher.h" +#include "MeshLib/Node.h" namespace MeshGeoToolsLib { @@ -33,10 +31,11 @@ BoundaryElementsAlongPolyline::BoundaryElementsAlongPolyline( auto node_ids_on_poly = mshNodeSearcher.getMeshNodeIDsAlongPolyline(ply); MeshLib::ElementSearch es(_mesh); es.searchByNodeIDs(node_ids_on_poly); - auto &ele_ids_near_ply = es.getSearchedElementIDs(); + auto& ele_ids_near_ply = es.getSearchedElementIDs(); // check all edges of the elements near the polyline - for (auto ele_id : ele_ids_near_ply) { + for (auto ele_id : ele_ids_near_ply) + { auto* e = _mesh.getElement(ele_id); // skip line elements if (e->getDimension() == 1) @@ -49,9 +48,11 @@ BoundaryElementsAlongPolyline::BoundaryElementsAlongPolyline( continue; } // find edges on the polyline - for (unsigned i=0; i<e->getNumberOfEdges(); i++) { + for (unsigned i = 0; i < e->getNumberOfEdges(); i++) + { auto* edge = e->getEdge(i); - // check if all edge nodes are along the polyline (if yes, store a distance) + // check if all edge nodes are along the polyline (if yes, store a + // distance) std::vector<std::size_t> edge_node_distances_along_ply; if (includesAllEdgeNodeIDs(node_ids_on_poly, *edge, edge_node_distances_along_ply)) @@ -64,7 +65,9 @@ BoundaryElementsAlongPolyline::BoundaryElementsAlongPolyline( delete edge; } _boundary_elements.push_back(new_edge); - } else { + } + else + { delete edge; } } @@ -74,19 +77,18 @@ BoundaryElementsAlongPolyline::BoundaryElementsAlongPolyline( // needed anymore in OGS-6. // sort picked edges according to a distance of their first node along the // polyline - std::sort( - begin(_boundary_elements), end(_boundary_elements), - [&](MeshLib::Element* e1, MeshLib::Element* e2) { - std::size_t dist1 = std::distance( - node_ids_on_poly.begin(), - std::find(node_ids_on_poly.begin(), node_ids_on_poly.end(), - e1->getNodeIndex(0))); - std::size_t dist2 = std::distance( - node_ids_on_poly.begin(), - std::find(node_ids_on_poly.begin(), node_ids_on_poly.end(), - e2->getNodeIndex(0))); - return (dist1 < dist2); - }); + std::sort(begin(_boundary_elements), end(_boundary_elements), + [&](MeshLib::Element* e1, MeshLib::Element* e2) { + std::size_t dist1 = std::distance( + node_ids_on_poly.begin(), + std::find(node_ids_on_poly.begin(), + node_ids_on_poly.end(), e1->getNodeIndex(0))); + std::size_t dist2 = std::distance( + node_ids_on_poly.begin(), + std::find(node_ids_on_poly.begin(), + node_ids_on_poly.end(), e2->getNodeIndex(0))); + return (dist1 < dist2); + }); } BoundaryElementsAlongPolyline::~BoundaryElementsAlongPolyline() @@ -97,21 +99,26 @@ BoundaryElementsAlongPolyline::~BoundaryElementsAlongPolyline() } } -bool BoundaryElementsAlongPolyline::includesAllEdgeNodeIDs(const std::vector<std::size_t> &vec_node_ids, const MeshLib::Element &edge, std::vector<std::size_t> &edge_node_distances) const +bool BoundaryElementsAlongPolyline::includesAllEdgeNodeIDs( + const std::vector<std::size_t>& vec_node_ids, const MeshLib::Element& edge, + std::vector<std::size_t>& edge_node_distances) const { - unsigned j=0; - for (; j<edge.getNumberOfBaseNodes(); j++) { - auto itr = std::find(vec_node_ids.begin(), vec_node_ids.end(), edge.getNodeIndex(j)); + unsigned j = 0; + for (; j < edge.getNumberOfBaseNodes(); j++) + { + auto itr = std::find(vec_node_ids.begin(), vec_node_ids.end(), + edge.getNodeIndex(j)); if (itr != vec_node_ids.end()) { - edge_node_distances.push_back(std::distance(vec_node_ids.begin(), itr)); + edge_node_distances.push_back( + std::distance(vec_node_ids.begin(), itr)); } else { break; } } - return (j==edge.getNumberOfBaseNodes()); + return (j == edge.getNumberOfBaseNodes()); } MeshLib::Element* BoundaryElementsAlongPolyline::modifyEdgeNodeOrdering( @@ -150,5 +157,4 @@ MeshLib::Element* BoundaryElementsAlongPolyline::modifyEdgeNodeOrdering( // Return the original edge otherwise. return const_cast<MeshLib::Element*>(&edge); } -} // end namespace MeshGeoToolsLib - +} // end namespace MeshGeoToolsLib diff --git a/MeshGeoToolsLib/BoundaryElementsAlongPolyline.h b/MeshGeoToolsLib/BoundaryElementsAlongPolyline.h index 1a75e7e6311..b15869b4bdb 100644 --- a/MeshGeoToolsLib/BoundaryElementsAlongPolyline.h +++ b/MeshGeoToolsLib/BoundaryElementsAlongPolyline.h @@ -18,7 +18,7 @@ namespace MeshLib { class Mesh; class Element; -} +} // namespace MeshLib namespace MeshGeoToolsLib { @@ -34,7 +34,8 @@ public: /** * Constructor * @param mesh a mesh object - * @param mshNodeSearcher a MeshNodeSearcher object which is internally used to search mesh nodes + * @param mshNodeSearcher a MeshNodeSearcher object which is internally + * used to search mesh nodes * @param ply a polyline object where edges are searched */ BoundaryElementsAlongPolyline(MeshLib::Mesh const& mesh, @@ -45,44 +46,60 @@ public: virtual ~BoundaryElementsAlongPolyline(); /// return the mesh object - MeshLib::Mesh const& getMesh() const {return _mesh;} + MeshLib::Mesh const& getMesh() const { return _mesh; } /** * Deploying this method the user can get access to the underlying * GeoLib::Polyline. * @return the underlying GeoLib::Polyline */ - GeoLib::Polyline const& getPolyline () const {return _ply;} + GeoLib::Polyline const& getPolyline() const { return _ply; } /** - * Return the vector of boundary elements (i.e. edges). The elements are sorted - * according to their distance to the starting point of the given polyline. + * Return the vector of boundary elements (i.e. edges). The elements are + * sorted according to their distance to the starting point of the given + * polyline. */ - std::vector<MeshLib::Element*> const& getBoundaryElements() const {return _boundary_elements; } + std::vector<MeshLib::Element*> const& getBoundaryElements() const + { + return _boundary_elements; + } private: /** * Check if a vector of node IDs includes all nodes of a given element * @param vec_node_ids a vector of Node IDs * @param edge Edge object whose node IDs are checked - * @param edge_node_distances a vector of distances of the edge nodes from the beginning of the given node ID vector + * @param edge_node_distances a vector of distances of the edge nodes from + * the beginning of the given node ID vector * @return true if all element nodes are included in the vector */ - bool includesAllEdgeNodeIDs(const std::vector<std::size_t> &vec_node_ids, const MeshLib::Element &edge, std::vector<std::size_t> &edge_node_distances) const; + bool includesAllEdgeNodeIDs( + const std::vector<std::size_t>& vec_node_ids, + const MeshLib::Element& edge, + std::vector<std::size_t>& edge_node_distances) const; /** - * Modify node ordering of an edge so that its first node is closer to the beginning of a polyline than others + * Modify node ordering of an edge so that its first node is closer to the + * beginning of a polyline than others * @param edge Element object * @param ply Polyline object - * @param edge_node_distances_along_ply A vector of current edge node distances along poly - * @param node_ids_on_poly A vector of node IDs along the polyine - * @return A pointer to the new modified edge object. A pointer to the original edge is returned if the modification is unnecessary. + * @param edge_node_distances_along_ply A vector of current edge node + * distances along poly + * @param node_ids_on_poly A vector of node IDs along the + * polyine + * @return A pointer to the new modified edge object. A pointer to the + * original edge is returned if the modification is unnecessary. */ - MeshLib::Element* modifyEdgeNodeOrdering(const MeshLib::Element &edge, const GeoLib::Polyline &ply, const std::vector<std::size_t> &edge_node_distances_along_ply, const std::vector<std::size_t> &node_ids_on_poly) const; + MeshLib::Element* modifyEdgeNodeOrdering( + const MeshLib::Element& edge, + const GeoLib::Polyline& ply, + const std::vector<std::size_t>& edge_node_distances_along_ply, + const std::vector<std::size_t>& node_ids_on_poly) const; MeshLib::Mesh const& _mesh; GeoLib::Polyline const& _ply; std::vector<MeshLib::Element*> _boundary_elements; }; -} // end namespace MeshGeoToolsLib +} // end namespace MeshGeoToolsLib -- GitLab