Skip to content
Snippets Groups Projects
Commit 324bbf06 authored by Tom Fischer's avatar Tom Fischer
Browse files

Merge branch 'FixMemLeakInResetPropertiesInPolygonalRegion' into 'master'

[GL/MGTL] Pointer to vector of Point's wasn't cleaned up properly.

Closes #3212

See merge request ogs/ogs!3849
parents 2c8f2066 2cb70a7d
No related branches found
No related tags found
No related merge requests found
...@@ -442,35 +442,28 @@ void computeAndInsertAllIntersectionPoints(GeoLib::PointVec& pnt_vec, ...@@ -442,35 +442,28 @@ void computeAndInsertAllIntersectionPoints(GeoLib::PointVec& pnt_vec,
} }
} }
GeoLib::Polygon rotatePolygonToXY(GeoLib::Polygon const& polygon_in, std::tuple<std::vector<GeoLib::Point*>, Eigen::Vector3d>
Eigen::Vector3d& plane_normal) rotatePolygonPointsToXY(GeoLib::Polygon const& polygon_in)
{ {
// 1 copy all points // 1 copy all points
auto* polygon_pnts(new std::vector<GeoLib::Point*>); std::vector<GeoLib::Point*> polygon_points;
polygon_points.reserve(polygon_in.getNumberOfPoints());
for (std::size_t k(0); k < polygon_in.getNumberOfPoints(); k++) for (std::size_t k(0); k < polygon_in.getNumberOfPoints(); k++)
{ {
polygon_pnts->push_back(new GeoLib::Point(*(polygon_in.getPoint(k)))); polygon_points.push_back(new GeoLib::Point(*(polygon_in.getPoint(k))));
} }
// 2 rotate points // 2 rotate points
double d_polygon; auto [plane_normal, d_polygon] = GeoLib::getNewellPlane(polygon_points);
std::tie(plane_normal, d_polygon) = GeoLib::getNewellPlane(*polygon_pnts);
Eigen::Matrix3d const rot_mat = Eigen::Matrix3d const rot_mat =
GeoLib::computeRotationMatrixToXY(plane_normal); GeoLib::computeRotationMatrixToXY(plane_normal);
GeoLib::rotatePoints(rot_mat, *polygon_pnts); GeoLib::rotatePoints(rot_mat, polygon_points);
// 3 set z coord to zero // 3 set z coord to zero
std::for_each(polygon_pnts->begin(), polygon_pnts->end(), std::for_each(polygon_points.begin(), polygon_points.end(),
[](GeoLib::Point* p) { (*p)[2] = 0.0; }); [](GeoLib::Point* p) { (*p)[2] = 0.0; });
// 4 create new polygon return {polygon_points, plane_normal};
GeoLib::Polyline rot_polyline(*polygon_pnts);
for (std::size_t k(0); k < polygon_in.getNumberOfPoints(); k++)
{
rot_polyline.addPoint(k);
}
rot_polyline.addPoint(0);
return GeoLib::Polygon(rot_polyline);
} }
std::vector<MathLib::Point3d> lineSegmentIntersect2d( std::vector<MathLib::Point3d> lineSegmentIntersect2d(
......
...@@ -202,22 +202,21 @@ std::unique_ptr<Point> triangleLineIntersection( ...@@ -202,22 +202,21 @@ std::unique_ptr<Point> triangleLineIntersection(
* pnt_vec. For each intersection an id is returned. This id is used to split the two * pnt_vec. For each intersection an id is returned. This id is used to split the two
* intersecting straight line segments in four straight line segments. * intersecting straight line segments in four straight line segments.
*/ */
void computeAndInsertAllIntersectionPoints(PointVec &pnt_vec, void computeAndInsertAllIntersectionPoints(PointVec& pnt_vec,
std::vector<Polyline*> & plys); std::vector<Polyline*>& plys);
/** /**
* Function rotates a polygon to the xy plane. For this reason, (1) the points of * Function rotates a polygon to the xy plane. For this reason, (1) the points
* the given polygon are copied, (2) a so called Newell plane is computed * of the given polygon are copied, (2) a so called Newell plane is computed
* (getNewellPlane()) and the points are rotated, (3) for security the * (getNewellPlane()) and the points are rotated, (3) for accuracy reasons the
* \f$z\f$ coordinates of the rotated points are set to zero and finally, (4) a * \f$z\f$ coordinates of the rotated points are set to zero
* new polygon is constructed using the rotated points.
* \see getNewellPlane() * \see getNewellPlane()
* @param polygon_in a copy of the polygon_in polygon will be rotated * @param polygon_in a copy of the polygon_in polygon will be rotated
* @param plane_normal the normal of the original Newell plane * @return vector of rotated points and normal based on the original Newell
* @return a rotated polygon * plane
*/ */
Polygon rotatePolygonToXY(Polygon const& polygon_in, std::tuple<std::vector<GeoLib::Point*>, Eigen::Vector3d>
Eigen::Vector3d& plane_normal); rotatePolygonPointsToXY(GeoLib::Polygon const& polygon_in);
/// Sorts the vector of segments such that the \f$i\f$-th segment is connected /// Sorts the vector of segments such that the \f$i\f$-th segment is connected
/// with the \f$i+1\f$st segment, i.e. the end point of the \f$i\f$-th segment /// with the \f$i+1\f$st segment, i.e. the end point of the \f$i\f$-th segment
......
...@@ -23,9 +23,9 @@ namespace MeshGeoToolsLib ...@@ -23,9 +23,9 @@ namespace MeshGeoToolsLib
std::vector<bool> markNodesOutSideOfPolygon( std::vector<bool> markNodesOutSideOfPolygon(
std::vector<MeshLib::Node*> const& nodes, GeoLib::Polygon const& polygon) std::vector<MeshLib::Node*> const& nodes, GeoLib::Polygon const& polygon)
{ {
// *** rotate polygon to xy_plane // *** rotate polygon points to xy-plane
Eigen::Vector3d normal; auto [rotated_polygon_points, normal] =
GeoLib::Polygon rot_polygon(GeoLib::rotatePolygonToXY(polygon, normal)); GeoLib::rotatePolygonPointsToXY(polygon);
// *** rotate mesh nodes to xy-plane // *** rotate mesh nodes to xy-plane
// 1 copy all mesh nodes to GeoLib::Points // 1 copy all mesh nodes to GeoLib::Points
...@@ -41,13 +41,24 @@ std::vector<bool> markNodesOutSideOfPolygon( ...@@ -41,13 +41,24 @@ std::vector<bool> markNodesOutSideOfPolygon(
std::for_each(rotated_nodes.begin(), rotated_nodes.end(), std::for_each(rotated_nodes.begin(), rotated_nodes.end(),
[](GeoLib::Point* p) { (*p)[2] = 0.0; }); [](GeoLib::Point* p) { (*p)[2] = 0.0; });
// *** mark rotated nodes
std::vector<bool> outside(rotated_nodes.size(), true); std::vector<bool> outside(rotated_nodes.size(), true);
for (std::size_t k(0); k < rotated_nodes.size(); k++) // *** mark rotated nodes inside rotated polygon
{ {
if (rot_polygon.isPntInPolygon(*(rotated_nodes[k]))) // create new polygon using the rotated points
GeoLib::Polyline rotated_polyline(rotated_polygon_points);
for (std::size_t k(0); k < polygon.getNumberOfPoints(); k++)
{ {
outside[k] = false; rotated_polyline.addPoint(k);
}
rotated_polyline.addPoint(0);
GeoLib::Polygon const rotated_polygon(rotated_polyline);
for (std::size_t k(0); k < rotated_nodes.size(); k++)
{
if (rotated_polygon.isPntInPolygon(*(rotated_nodes[k])))
{
outside[k] = false;
}
} }
} }
...@@ -56,9 +67,7 @@ std::vector<bool> markNodesOutSideOfPolygon( ...@@ -56,9 +67,7 @@ std::vector<bool> markNodesOutSideOfPolygon(
delete rotated_node; delete rotated_node;
} }
std::vector<GeoLib::Point*>& rot_polygon_pnts( for (auto& rot_polygon_pnt : rotated_polygon_points)
const_cast<std::vector<GeoLib::Point*>&>(rot_polygon.getPointsVec()));
for (auto& rot_polygon_pnt : rot_polygon_pnts)
{ {
delete rot_polygon_pnt; delete rot_polygon_pnt;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment