Skip to content
Snippets Groups Projects
Commit 2d89680b authored by Tom Fischer's avatar Tom Fischer Committed by Dmitri Naumov
Browse files

[GL/MGTL] Cleanup Pointer to vector of Point's.

Pointer to vector of Point's wasn't cleaned up properly.

In rotatePolygonToXY a pointer to the vector of
polygon points was created. The rotated polygon is
on this vector. When the polygon is returned from
the function it isn't possible to cleanup the vector
properly. So the creation of the polygon is move to
the function markNodesOutSideOfPolygon.
parent 2c8f2066
No related branches found
No related tags found
No related merge requests found
...@@ -442,11 +442,12 @@ void computeAndInsertAllIntersectionPoints(GeoLib::PointVec& pnt_vec, ...@@ -442,11 +442,12 @@ void computeAndInsertAllIntersectionPoints(GeoLib::PointVec& pnt_vec,
} }
} }
GeoLib::Polygon rotatePolygonToXY(GeoLib::Polygon const& polygon_in, std::unique_ptr<std::vector<GeoLib::Point*>> rotatePolygonPointsToXY(
Eigen::Vector3d& plane_normal) GeoLib::Polygon const& polygon_in, Eigen::Vector3d& plane_normal)
{ {
// 1 copy all points // 1 copy all points
auto* polygon_pnts(new std::vector<GeoLib::Point*>); auto polygon_pnts = std::make_unique<std::vector<GeoLib::Point*>>();
polygon_pnts->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_pnts->push_back(new GeoLib::Point(*(polygon_in.getPoint(k))));
...@@ -463,14 +464,7 @@ GeoLib::Polygon rotatePolygonToXY(GeoLib::Polygon const& polygon_in, ...@@ -463,14 +464,7 @@ GeoLib::Polygon rotatePolygonToXY(GeoLib::Polygon const& polygon_in,
std::for_each(polygon_pnts->begin(), polygon_pnts->end(), std::for_each(polygon_pnts->begin(), polygon_pnts->end(),
[](GeoLib::Point* p) { (*p)[2] = 0.0; }); [](GeoLib::Point* p) { (*p)[2] = 0.0; });
// 4 create new polygon return polygon_pnts;
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(
......
...@@ -214,10 +214,10 @@ void computeAndInsertAllIntersectionPoints(PointVec &pnt_vec, ...@@ -214,10 +214,10 @@ void computeAndInsertAllIntersectionPoints(PointVec &pnt_vec,
* \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 * @param plane_normal the normal of the original Newell plane
* @return a rotated polygon * @return a vector of rotated points
*/ */
Polygon rotatePolygonToXY(Polygon const& polygon_in, std::unique_ptr<std::vector<GeoLib::Point*>> rotatePolygonPointsToXY(
Eigen::Vector3d& plane_normal); GeoLib::Polygon const& polygon_in, Eigen::Vector3d& plane_normal);
/// 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,10 @@ namespace MeshGeoToolsLib ...@@ -23,9 +23,10 @@ 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; Eigen::Vector3d normal;
GeoLib::Polygon rot_polygon(GeoLib::rotatePolygonToXY(polygon, normal)); auto rotated_polygon_points =
GeoLib::rotatePolygonPointsToXY(polygon, normal);
// *** 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 +42,24 @@ std::vector<bool> markNodesOutSideOfPolygon( ...@@ -41,13 +42,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 +68,7 @@ std::vector<bool> markNodesOutSideOfPolygon( ...@@ -56,9 +68,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