build() always trigger the reconstruction of the tree

It can be useful for a mesh with update vertex coordinates
This commit is contained in:
Sébastien Loriot 2020-04-22 15:56:26 +02:00
parent cbd7dfc793
commit c8eddc4efc
1 changed files with 19 additions and 26 deletions

View File

@ -704,35 +704,28 @@ public:
template<typename Tr> template<typename Tr>
void AABB_tree<Tr>::build() void AABB_tree<Tr>::build()
{ {
#ifdef CGAL_HAS_THREADS clear_nodes();
if (m_atomic_need_build.load()) if(m_primitives.size() > 1) {
#else
if (m_need_build)
#endif
{
clear_nodes();
if(m_primitives.size() > 1) {
// allocates tree nodes // allocates tree nodes
m_p_root_node = new Node[m_primitives.size()-1](); m_p_root_node = new Node[m_primitives.size()-1]();
if(m_p_root_node == nullptr) if(m_p_root_node == nullptr)
{ {
std::cerr << "Unable to allocate memory for AABB tree" << std::endl; std::cerr << "Unable to allocate memory for AABB tree" << std::endl;
CGAL_assertion(m_p_root_node != nullptr); CGAL_assertion(m_p_root_node != nullptr);
m_primitives.clear(); m_primitives.clear();
clear(); clear();
}
// constructs the tree
m_p_root_node->expand(m_primitives.begin(), m_primitives.end(),
m_primitives.size(), m_traits);
} }
#ifdef CGAL_HAS_THREADS
m_atomic_need_build.store(false, std::memory_order_release); // in case build() is triggered by a call to root_node() // constructs the tree
#else m_p_root_node->expand(m_primitives.begin(), m_primitives.end(),
m_need_build = false; m_primitives.size(), m_traits);
#endif
} }
#ifdef CGAL_HAS_THREADS
m_atomic_need_build.store(false, std::memory_order_release); // in case build() is triggered by a call to root_node()
#else
m_need_build = false;
#endif
} }
// constructs the search KD tree from given points // constructs the search KD tree from given points
// to accelerate the distance queries // to accelerate the distance queries