Skip to content

Commit

Permalink
convert tuple to struct for Facets_erase_counters
Browse files Browse the repository at this point in the history
  • Loading branch information
janetournois committed Jun 10, 2024
1 parent accfc2a commit 8d6d934
Showing 1 changed file with 39 additions and 34 deletions.
73 changes: 39 additions & 34 deletions Mesh_3/include/CGAL/Mesh_3/Refine_facets_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,48 @@
#include <optional>
#include <boost/optional/optional_io.hpp>
#include <boost/mpl/has_xxx.hpp>
#include <CGAL/tuple.h>

#include <sstream>
#include <atomic>

namespace CGAL {

namespace Mesh_3 {

template<typename Facet>
struct Facets_erase_counters
{
const Facet& f1_;
const unsigned int f1_erase_counter_;
const Facet& f2_;
const unsigned int f2_erase_counter_;
};

// Predicate to know if a facet in a refinement queue is a zombie
// A facet is a pair <cell, index of the opposite vertex>.
// A facet is a "zombie" if at least one of its two adjacent cells
// has been erased. We test it thanks to the "erase counter" which
// is inside each cell (incremented by the compact container).
// In the refinement queue, we store a tuple
// In the refinement queue, we store a struct
// <facet1, facet1_erase counter, facet2, facet2_erase_counter>
// where facet2 = mirror_facet(facet1) and facetx_erase_counter is
// the erase_counter of facetx's cell when added to the queue>
template<typename Facet>
class Facet_to_refine_is_not_zombie
{
typedef Facets_erase_counters<Facet> Facets_ec;

public:
Facet_to_refine_is_not_zombie() {}

bool operator()(const std::tuple<
Facet, unsigned int, Facet, unsigned int> &f) const
bool operator()(const Facets_ec& f) const
{
#ifdef _DEBUG
/*
int f1_current_erase_counter = std::get<0>(f).first->erase_counter();
int f1_saved_erase_counter = std::get<1>(f);
int f2_current_erase_counter = std::get<2>(f).first->erase_counter();
int f2_saved_erase_counter = std::get<3>(f);
int f1_current_erase_counter = f.f1_.first->erase_counter();
int f1_saved_erase_counter = f.f1_erase_counter_;
int f2_current_erase_counter = f.f2_.first->erase_counter();
int f2_saved_erase_counter = f.f2_erase_counter_;
*/
//f1_current_erase_counter - f1_saved_erase_counter + f2_current_erase_counter - f2_saved_erase_counter == 1

Expand All @@ -89,15 +99,15 @@ namespace Mesh_3 {
#endif
std::stringstream sstr;
Facet facet = std::get<0>(f);
Facet facet = f.f1_;
sstr << "Facet 1 { " << std::endl
<< " - " << *facet.first->vertex((facet.second+1)%4) << std::endl
<< " - " << *facet.first->vertex((facet.second+2)%4) << std::endl
<< " - " << *facet.first->vertex((facet.second+3)%4) << std::endl
<< " - 4th vertex in cell: " << *facet.first->vertex(facet.second) << std::endl
<< "}" << std::endl;
facet = std::get<2>(f);
facet = f.f2_;
sstr << "Facet 2 { " << std::endl
<< " - " << *facet.first->vertex((facet.second+1)%4) << std::endl
<< " - " << *facet.first->vertex((facet.second+2)%4) << std::endl
Expand All @@ -109,8 +119,8 @@ namespace Mesh_3 {
std::cerr << s << std::endl;
}*/
#endif
return (std::get<0>(f).first->erase_counter() == std::get<1>(f)
&& std::get<2>(f).first->erase_counter() == std::get<3>(f) );
return (f.f1_.first->erase_counter() == f.f1_erase_counter_
&& f.f2_.first->erase_counter() == f.f2_erase_counter_ );
}
};

Expand All @@ -123,6 +133,8 @@ namespace Mesh_3 {
template <typename Index, typename Facet, typename Concurrency_tag>
class Refine_facets_3_handle_queue_base
{
typedef Facets_erase_counters<Facet> Facets_counters;

protected:
Refine_facets_3_handle_queue_base() : m_last_vertex_index() {}

Expand All @@ -139,21 +151,20 @@ class Refine_facets_3_handle_queue_base
#if defined(CGAL_MESH_3_USE_LAZY_SORTED_REFINEMENT_QUEUE) \
|| defined(CGAL_MESH_3_USE_LAZY_UNSORTED_REFINEMENT_QUEUE)

std::tuple<Facet, unsigned int, Facet, unsigned int>
Facets_counters
from_facet_to_refinement_queue_element(const Facet &facet,
const Facet &mirror) const
{
return std::make_tuple(
facet, facet.first->erase_counter(),
mirror, mirror.first->erase_counter());
return Facets_counters{facet, facet.first->erase_counter(),
mirror, mirror.first->erase_counter()};
}

public:
template<typename Container_element>
Facet extract_element_from_container_value(const Container_element &e) const
{
// We get the first Facet inside the tuple
return std::get<0>(e);
// We get the first Facet inside the struct
return e.f1_;
}

#else
Expand Down Expand Up @@ -198,21 +209,20 @@ class Refine_facets_3_handle_queue_base<Index, Facet, Parallel_tag>
m_last_vertex_index.local() = i;
}

std::tuple<Facet, unsigned int, Facet, unsigned int>
Facets_erase_counters<Facet>
from_facet_to_refinement_queue_element(const Facet &facet,
const Facet &mirror) const
{
return std::make_tuple(
facet, facet.first->erase_counter(),
mirror, mirror.first->erase_counter());
return Facets_erase_counters<Facet>{facet, facet.first->erase_counter(),
mirror, mirror.first->erase_counter()};
}

public:
template<typename Container_element>
Facet extract_element_from_container_value(const Container_element &e) const
{
// We get the first Facet inside the tuple
return std::get<0>(e);
// We get the first Facet inside the struct
return e.f1_;
}

protected:
Expand Down Expand Up @@ -667,8 +677,7 @@ template<class Tr,
Meshes::Filtered_multimap_container
# endif
<
std::tuple<typename Tr::Facet, unsigned int,
typename Tr::Facet, unsigned int>,
Facets_erase_counters<typename Tr::Facet>,
typename Criteria::Facet_quality,
Facet_to_refine_is_not_zombie<typename Tr::Facet>,
Concurrency_tag
Expand All @@ -677,17 +686,15 @@ template<class Tr,
# ifdef CGAL_MESH_3_USE_LAZY_UNSORTED_REFINEMENT_QUEUE
Meshes::Filtered_deque_container
<
std::tuple<typename Tr::Facet, unsigned int,
typename Tr::Facet, unsigned int>,
Facets_erase_counters<typename Tr::Facet>,
typename Criteria::Facet_quality,
Facet_to_refine_is_not_zombie<typename Tr::Facet>,
Concurrency_tag
>
# elif defined(CGAL_MESH_3_USE_LAZY_SORTED_REFINEMENT_QUEUE)
Meshes::Filtered_multimap_container
<
std::tuple<typename Tr::Facet, unsigned int,
typename Tr::Facet, unsigned int>,
Facets_erase_counters<typename Tr::Facet>,
typename Criteria::Facet_quality,
Facet_to_refine_is_not_zombie<typename Tr::Facet>,
Concurrency_tag
Expand All @@ -705,17 +712,15 @@ template<class Tr,
# ifdef CGAL_MESH_3_USE_LAZY_UNSORTED_REFINEMENT_QUEUE
Meshes::Filtered_deque_container
<
std::tuple<typename Tr::Facet, unsigned int,
typename Tr::Facet, unsigned int>,
Facets_erase_counters<typename Tr::Facet>,
typename Criteria::Facet_quality,
Facet_to_refine_is_not_zombie<typename Tr::Facet>,
Concurrency_tag
>
# elif defined(CGAL_MESH_3_USE_LAZY_SORTED_REFINEMENT_QUEUE)
Meshes::Filtered_multimap_container
<
std::tuple<typename Tr::Facet, unsigned int,
typename Tr::Facet, unsigned int>,
Facets_erase_counters<typename Tr::Facet>,
typename Criteria::Facet_quality,
Facet_to_refine_is_not_zombie<typename Tr::Facet>,
Concurrency_tag
Expand Down

0 comments on commit 8d6d934

Please sign in to comment.