mirror of https://github.com/CGAL/cgal
Fix memory issues in PS/SS oracles after no longer taking oracles by const&
This commit is contained in:
parent
21fddd1c13
commit
fb682fe9eb
|
|
@ -28,6 +28,7 @@
|
|||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace CGAL {
|
||||
|
|
@ -41,6 +42,7 @@ struct PS_oracle_traits
|
|||
using Geom_traits = Alpha_wrap_AABB_geom_traits<GT_>; // Wrap the kernel to add Ball_3 + custom Do_intersect_3
|
||||
|
||||
using Points = std::vector<typename GT_::Point_3>;
|
||||
using Points_ptr = std::shared_ptr<Points>;
|
||||
using PR_iterator = typename Points::const_iterator;
|
||||
|
||||
using Primitive = AABB_primitive<PR_iterator,
|
||||
|
|
@ -69,26 +71,29 @@ public:
|
|||
|
||||
private:
|
||||
using Points = typename PSOT::Points;
|
||||
using Points_ptr = typename PSOT::Points_ptr;
|
||||
using AABB_tree = typename PSOT::AABB_tree;
|
||||
using Oracle_base = AABB_tree_oracle<Geom_traits, AABB_tree, CGAL::Default, BaseOracle>;
|
||||
|
||||
private:
|
||||
Points m_points;
|
||||
Points_ptr m_points_ptr;
|
||||
|
||||
public:
|
||||
// Constructors
|
||||
Point_set_oracle()
|
||||
: Oracle_base(BaseOracle(), Base_GT())
|
||||
{ }
|
||||
|
||||
Point_set_oracle(const BaseOracle& base_oracle,
|
||||
const Base_GT& gt = Base_GT())
|
||||
: Oracle_base(base_oracle, gt)
|
||||
{ }
|
||||
{
|
||||
m_points_ptr = std::make_shared<Points>();
|
||||
}
|
||||
|
||||
Point_set_oracle(const Base_GT& gt,
|
||||
const BaseOracle& base_oracle = BaseOracle())
|
||||
: Oracle_base(base_oracle, gt)
|
||||
: Point_set_oracle(gt, base_oracle)
|
||||
{ }
|
||||
|
||||
Point_set_oracle()
|
||||
: Point_set_oracle(BaseOracle(), Base_GT())
|
||||
{ }
|
||||
|
||||
public:
|
||||
|
|
@ -106,14 +111,14 @@ public:
|
|||
return;
|
||||
}
|
||||
|
||||
const std::size_t old_size = m_points.size();
|
||||
m_points.insert(std::cend(m_points), std::cbegin(points), std::cend(points));
|
||||
const std::size_t old_size = m_points_ptr->size();
|
||||
m_points_ptr->insert(std::cend(*m_points_ptr), std::cbegin(points), std::cend(points));
|
||||
|
||||
#ifdef CGAL_AW3_DEBUG
|
||||
std::cout << "Insert into AABB tree (points)..." << std::endl;
|
||||
#endif
|
||||
|
||||
this->tree().insert(std::next(std::cbegin(m_points), old_size), std::cend(m_points));
|
||||
this->tree().insert(std::next(std::cbegin(*m_points_ptr), old_size), std::cend(*m_points_ptr));
|
||||
|
||||
// Manually constructing it here purely for profiling reasons: if we keep the lazy approach,
|
||||
// it will be done at the first treatment of a facet that needs a Steiner point.
|
||||
|
|
@ -121,7 +126,7 @@ public:
|
|||
// to accelerate the tree.
|
||||
this->tree().accelerate_distance_queries();
|
||||
|
||||
CGAL_postcondition(this->tree().size() == m_points.size());
|
||||
CGAL_postcondition(this->tree().size() == m_points_ptr->size());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace CGAL {
|
||||
|
|
@ -42,6 +43,7 @@ struct SS_oracle_traits
|
|||
|
||||
using Segment = typename GT_::Segment_3;
|
||||
using Segments = std::vector<Segment>;
|
||||
using Segments_ptr = std::shared_ptr<Segments>;
|
||||
using SR_iterator = typename Segments::const_iterator;
|
||||
|
||||
using Primitive = AABB_primitive<SR_iterator,
|
||||
|
|
@ -71,26 +73,29 @@ public:
|
|||
private:
|
||||
using Segment = typename SSOT::Segment;
|
||||
using Segments = typename SSOT::Segments;
|
||||
using Segments_ptr = typename SSOT::Segments_ptr;
|
||||
using AABB_tree = typename SSOT::AABB_tree;
|
||||
using Oracle_base = AABB_tree_oracle<Geom_traits, AABB_tree, CGAL::Default, BaseOracle>;
|
||||
|
||||
private:
|
||||
Segments m_segments;
|
||||
Segments_ptr m_segments_ptr;
|
||||
|
||||
public:
|
||||
// Constructors
|
||||
Segment_soup_oracle()
|
||||
: Oracle_base(BaseOracle(), Base_GT())
|
||||
{ }
|
||||
|
||||
Segment_soup_oracle(const BaseOracle& base_oracle,
|
||||
const Base_GT& gt = Base_GT())
|
||||
: Oracle_base(base_oracle, gt)
|
||||
{ }
|
||||
{
|
||||
m_segments_ptr = std::make_shared<Segments>();
|
||||
}
|
||||
|
||||
Segment_soup_oracle(const Base_GT& gt,
|
||||
const BaseOracle& base_oracle = BaseOracle())
|
||||
: Oracle_base(base_oracle, gt)
|
||||
: Segment_soup_oracle(base_oracle, gt)
|
||||
{ }
|
||||
|
||||
Segment_soup_oracle()
|
||||
: Segment_soup_oracle(BaseOracle(), Base_GT())
|
||||
{ }
|
||||
|
||||
public:
|
||||
|
|
@ -109,7 +114,7 @@ public:
|
|||
|
||||
typename Geom_traits::Is_degenerate_3 is_degenerate = this->geom_traits().is_degenerate_3_object();
|
||||
|
||||
const std::size_t old_size = m_segments.size();
|
||||
const std::size_t old_size = m_segments_ptr->size();
|
||||
|
||||
for(const Segment& s : segments)
|
||||
{
|
||||
|
|
@ -121,13 +126,13 @@ public:
|
|||
continue;
|
||||
}
|
||||
|
||||
m_segments.push_back(s);
|
||||
m_segments_ptr->push_back(s);
|
||||
}
|
||||
|
||||
#ifdef CGAL_AW3_DEBUG
|
||||
std::cout << "Insert into AABB tree (segments)..." << std::endl;
|
||||
#endif
|
||||
this->tree().insert(std::next(std::cbegin(m_segments), old_size), std::cend(m_segments));
|
||||
this->tree().insert(std::next(std::cbegin(*m_segments_ptr), old_size), std::cend(*m_segments_ptr));
|
||||
|
||||
// Manually constructing it here purely for profiling reasons: if we keep the lazy approach,
|
||||
// it will be done at the first treatment of a facet that needs a Steiner point.
|
||||
|
|
@ -135,7 +140,7 @@ public:
|
|||
// to accelerate the tree.
|
||||
this->tree().accelerate_distance_queries();
|
||||
|
||||
CGAL_postcondition(this->tree().size() == m_segments.size());
|
||||
CGAL_postcondition(this->tree().size() == m_segments_ptr->size());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue