From 5fa276c08da625d0259333846052f9c05b5de78c Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Tue, 23 Feb 2016 10:12:48 +0100 Subject: [PATCH] [GL] Surface: Use unique_ptr for ptr. attributes. --- GeoLib/Surface.cpp | 10 ++++------ GeoLib/Surface.h | 5 +++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/GeoLib/Surface.cpp b/GeoLib/Surface.cpp index 3805ab63a3e..3e7cac6b932 100644 --- a/GeoLib/Surface.cpp +++ b/GeoLib/Surface.cpp @@ -40,8 +40,6 @@ Surface::~Surface () { for (std::size_t k(0); k < _sfc_triangles.size(); k++) delete _sfc_triangles[k]; - delete _bounding_volume; - delete _surface_grid; } void Surface::addTriangle(std::size_t pnt_a, std::size_t pnt_b, std::size_t pnt_c) @@ -53,15 +51,15 @@ void Surface::addTriangle(std::size_t pnt_a, std::size_t pnt_b, std::size_t pnt_ return; // Adding a new triangle invalides the surface grid. - if (_surface_grid) - delete _surface_grid; + _surface_grid.reset(); + _sfc_triangles.push_back(new Triangle(_sfc_pnts, pnt_a, pnt_b, pnt_c)); if (!_bounding_volume) { std::vector<std::size_t> ids(3); ids[0] = pnt_a; ids[1] = pnt_b; ids[2] = pnt_c; - _bounding_volume = new AABB(_sfc_pnts, ids); + _bounding_volume.reset(new AABB(_sfc_pnts, ids)); } else { _bounding_volume->update(*_sfc_pnts[pnt_a]); _bounding_volume->update(*_sfc_pnts[pnt_b]); @@ -132,7 +130,7 @@ bool Surface::isPntInSfc(MathLib::Point3d const& pnt) const { // Mutable _surface_grid is constructed if method is called the first time. if (_surface_grid == nullptr) { - _surface_grid = new SurfaceGrid(this); + _surface_grid.reset(new SurfaceGrid(this)); } return _surface_grid->isPointInSurface( pnt, std::numeric_limits<double>::epsilon()); diff --git a/GeoLib/Surface.h b/GeoLib/Surface.h index 63185aed82b..67908462a60 100644 --- a/GeoLib/Surface.h +++ b/GeoLib/Surface.h @@ -16,6 +16,7 @@ #define SURFACE_H_ #include <vector> +#include <memory> #include "GeoObject.h" #include "Point.h" @@ -95,12 +96,12 @@ protected: /** position of pointers to the geometric points */ std::vector<Triangle*> _sfc_triangles; /** bounding volume is an axis aligned bounding box */ - AABB *_bounding_volume; + std::unique_ptr<AABB> _bounding_volume; /// The surface grid is a helper data structure to accelerate the point /// search. The method addTriangle() invalidates/resets the surface grid. /// A valid surface grid is created in case the const method isPntInSfc() is /// called and a valid surface grid is not existing. - mutable SurfaceGrid* _surface_grid; + mutable std::unique_ptr<SurfaceGrid> _surface_grid; }; } -- GitLab