fix cell_selector use in flip()

This commit is contained in:
Jane Tournois 2022-10-28 12:50:23 +02:00
parent e1b319bf6a
commit 7a0cb92e43
2 changed files with 59 additions and 22 deletions

View File

@ -32,8 +32,9 @@ namespace Tetrahedral_remeshing
{ {
namespace internal namespace internal
{ {
template<typename C3t3> template<typename C3t3, typename CellSelector>
typename C3t3::Vertex_handle split_edge(const typename C3t3::Edge& e, typename C3t3::Vertex_handle split_edge(const typename C3t3::Edge& e,
CellSelector cell_selector,
C3t3& c3t3) C3t3& c3t3)
{ {
typedef typename C3t3::Triangulation Tr; typedef typename C3t3::Triangulation Tr;
@ -68,8 +69,16 @@ typename C3t3::Vertex_handle split_edge(const typename C3t3::Edge& e,
} }
CGAL_assertion(dimension > 0); CGAL_assertion(dimension > 0);
boost::unordered_map<Facet, Subdomain_index> cells_info; struct Cell_info {
boost::unordered_map<Facet, std::pair<Vertex_handle, Surface_patch_index> > facets_info; Subdomain_index subdomain_index_;
bool selected_;
};
struct Facet_info {
Vertex_handle opp_vertex_;
Surface_patch_index patch_index_;
};
boost::unordered_map<Facet, Cell_info> cells_info;
boost::unordered_map<Facet, Facet_info> facets_info;
// check orientation and collect incident cells to avoid circulating twice // check orientation and collect incident cells to avoid circulating twice
boost::container::small_vector<Cell_handle, 30> inc_cells; boost::container::small_vector<Cell_handle, 30> inc_cells;
@ -113,23 +122,21 @@ typename C3t3::Vertex_handle split_edge(const typename C3t3::Edge& e,
//keys are the opposite facets to the ones not containing e, //keys are the opposite facets to the ones not containing e,
//because they will not be modified //because they will not be modified
const Subdomain_index subdomain = c3t3.subdomain_index(c); const Subdomain_index subdomain = c3t3.subdomain_index(c);
const bool selected = get(cell_selector, c);
const Facet opp_facet1 = tr.mirror_facet(Facet(c, index_v1)); const Facet opp_facet1 = tr.mirror_facet(Facet(c, index_v1));
const Facet opp_facet2 = tr.mirror_facet(Facet(c, index_v2)); const Facet opp_facet2 = tr.mirror_facet(Facet(c, index_v2));
// volume data // volume data
cells_info.insert(std::make_pair(opp_facet1, subdomain)); cells_info.insert(std::make_pair(opp_facet1, Cell_info{subdomain, selected}));
cells_info.insert(std::make_pair(opp_facet2, subdomain)); cells_info.insert(std::make_pair(opp_facet2, Cell_info{subdomain, selected}));
if (c3t3.is_in_complex(c)) treat_before_delete(c, cell_selector, c3t3);
c3t3.remove_from_complex(c);
// surface data for facets of the cells to be split // surface data for facets of the cells to be split
const int findex = CGAL::Triangulation_utils_3::next_around_edge(index_v1, index_v2); const int findex = CGAL::Triangulation_utils_3::next_around_edge(index_v1, index_v2);
Surface_patch_index patch = c3t3.surface_patch_index(c, findex); Surface_patch_index patch = c3t3.surface_patch_index(c, findex);
Vertex_handle opp_vertex = c->vertex(findex); Vertex_handle opp_vertex = c->vertex(findex);
facets_info.insert(std::make_pair(opp_facet1, facets_info.insert(std::make_pair(opp_facet1, Facet_info{opp_vertex, patch}));
std::make_pair(opp_vertex, patch))); facets_info.insert(std::make_pair(opp_facet2, Facet_info{opp_vertex, patch}));
facets_info.insert(std::make_pair(opp_facet2,
std::make_pair(opp_vertex, patch)));
if(c3t3.is_in_complex(c, findex)) if(c3t3.is_in_complex(c, findex))
c3t3.remove_from_complex(c, findex); c3t3.remove_from_complex(c, findex);
@ -150,28 +157,26 @@ typename C3t3::Vertex_handle split_edge(const typename C3t3::Edge& e,
//get subdomain info back //get subdomain info back
CGAL_assertion(cells_info.find(mfi) != cells_info.end()); CGAL_assertion(cells_info.find(mfi) != cells_info.end());
Subdomain_index n_index = cells_info.at(mfi); Cell_info c_info = cells_info.at(mfi);
if (Subdomain_index() != n_index) treat_new_cell(new_cell, c_info.subdomain_index_,
c3t3.add_to_complex(new_cell, n_index); cell_selector, c_info.selected_, c3t3);
else
new_cell->set_subdomain_index(Subdomain_index());
// get surface info back // get surface info back
CGAL_assertion(facets_info.find(mfi) != facets_info.end()); CGAL_assertion(facets_info.find(mfi) != facets_info.end());
const std::pair<Vertex_handle, Surface_patch_index> v_and_opp_patch = facets_info.at(mfi); const Facet_info v_and_opp_patch = facets_info.at(mfi);
// facet opposite to new_v (status wrt c3t3 is unchanged) // facet opposite to new_v (status wrt c3t3 is unchanged)
new_cell->set_surface_patch_index(new_cell->index(new_v), new_cell->set_surface_patch_index(new_cell->index(new_v),
mfi.first->surface_patch_index(mfi.second)); mfi.first->surface_patch_index(mfi.second));
// new half-facet (added or not to c3t3 depending on the stored surface patch index) // new half-facet (added or not to c3t3 depending on the stored surface patch index)
if (Surface_patch_index() == v_and_opp_patch.second) if (Surface_patch_index() == v_and_opp_patch.patch_index_)
new_cell->set_surface_patch_index(new_cell->index(v_and_opp_patch.first), new_cell->set_surface_patch_index(new_cell->index(v_and_opp_patch.opp_vertex_),
Surface_patch_index()); Surface_patch_index());
else else
c3t3.add_to_complex(new_cell, c3t3.add_to_complex(new_cell,
new_cell->index(v_and_opp_patch.first), new_cell->index(v_and_opp_patch.opp_vertex_),
v_and_opp_patch.second); v_and_opp_patch.patch_index_);
// newly created internal facet // newly created internal facet
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
@ -301,7 +306,7 @@ void split_long_edges(C3T3& c3t3,
continue; continue;
visitor.before_split(tr, edge); visitor.before_split(tr, edge);
Vertex_handle vh = split_edge(edge, c3t3); Vertex_handle vh = split_edge(edge, cell_selector, c3t3);
if(vh != Vertex_handle()) if(vh != Vertex_handle())
visitor.after_split(tr, vh); visitor.after_split(tr, vh);

View File

@ -1134,6 +1134,38 @@ void get_edge_info(const typename C3t3::Edge& edge,
} }
} }
namespace internal
{
template<typename C3t3, typename CellSelector>
void treat_before_delete(typename C3t3::Cell_handle c,
CellSelector& cell_selector,
C3t3& c3t3)
{
if (c3t3.is_in_complex(c))
c3t3.remove_from_complex(c);
if (get(cell_selector, c))
put(cell_selector, c, false);
}
template<typename C3t3, typename CellSelector>
void treat_new_cell(typename C3t3::Cell_handle c,
const typename C3t3::Subdomain_index& subdomain,
CellSelector& cell_selector,
const bool selected,
C3t3& c3t3)
{
//update C3t3
using Subdomain_index = typename C3t3::Subdomain_index;
if (Subdomain_index() != subdomain)
c3t3.add_to_complex(c, subdomain);
else
c->set_subdomain_index(Subdomain_index());
//update cell_selector property map
put(cell_selector, c, selected);
}
}
namespace debug namespace debug
{ {