Merge branch 'Combinatorial_map-reverse_orientation-kenohori-old' into Combinatorial_map-reverse_orientation-kenohori

This commit is contained in:
Guillaume Damiand 2013-06-23 21:02:11 +02:00
commit 37d7b8ef0f
5 changed files with 247 additions and 0 deletions

View File

@ -89,6 +89,12 @@ namespace CGAL {
template<typename CMap, unsigned int i, typename T>
friend struct internal::Decrease_attribute_functor_run;
template <typename CMap, typename Attrib>
friend struct internal::Reverse_orientation_of_map_functor;
template <typename CMap, typename Attrib>
friend struct internal::Reverse_orientation_of_connected_component_functor;
public:
typedef Tag_false Supports_cell_dart;
@ -195,6 +201,12 @@ namespace CGAL {
template<typename CMap, unsigned int i, typename T>
friend struct internal::Decrease_attribute_functor_run;
template <typename CMap, typename Attrib>
friend struct internal::Reverse_orientation_of_map_functor;
template <typename CMap, typename Attrib>
friend struct internal::Reverse_orientation_of_connected_component_functor;
public:
typedef Tag_true Supports_cell_dart;

View File

@ -2200,6 +2200,27 @@ namespace CGAL {
if ( update_attributes ) unsew<i>(adart);
else topo_unsew<i>(adart);
}
/** Reverse the orientation (swap beta 0 & 1 links) of the entire map.
* A valid map after this operation remains valid.
* @param none
* @return none
*/
void reverse_orientation()
{
internal::Reverse_orientation_of_map_functor<Self>::run(this);
}
/** Reverse the orientation (swap beta 0 & 1 links) of the connected
* component containing the given dart.
* A valid map after this operation remains valid.
* @param adart handle to a dart
* @return none
*/
void reverse_orientation_connected_component (Dart_handle adart)
{
internal::Reverse_orientation_of_connected_component_functor<Self>::run(this, adart);
}
/** Count the marked cells (at least one marked dart).
* @param amark the mark to consider.

View File

@ -72,6 +72,12 @@ namespace CGAL {
template <typename Map,unsigned int i>
friend struct internal::link_beta_functor;
template <typename CMap, typename Attrib>
friend struct internal::Reverse_orientation_of_map_functor;
template <typename CMap, typename Attrib>
friend struct internal::Reverse_orientation_of_connected_component_functor;
public:
typedef Dart<d,Refs> Self;
@ -272,6 +278,16 @@ namespace CGAL {
Helper::template Foreach_enabled_attributes<Init_attribute_functor>::
run(this);
}
/** Copy constructor:
* @param adart a dart.
*/
Dart(const std::bitset<NB_MARKS>& /*amarks*/, const Dart& adart) : mmarks(adart.mmarks),
mattribute_handles(adart.mattribute_handles)
{
for (unsigned int i = 0; i <= dimension; ++i)
mbeta[i] = adart.mbeta[i];
}
/** Return the mark value of a given mark number.
* @param amark the mark number.

View File

@ -630,6 +630,198 @@ struct Test_is_same_attribute_functor
template<typename Map1, typename Map2>
bool Test_is_same_attribute_functor<Map1, Map2>::value = true;
// ****************************************************************************
/// Functor to reverse the orientation of a combinatorial map
template <typename CMap, typename Attrib =
typename CMap::Helper::template Attribute_type<0>::type>
struct Reverse_orientation_of_map_functor
{
static void run(CMap *amap)
{
int mark = amap->get_new_mark();
CGAL_precondition(amap->is_whole_map_unmarked(mark));
CGAL_precondition(amap->is_valid());
for (typename CMap::Dart_range::iterator current_dart=amap->darts().begin(),
last_dart = amap->darts().end(); current_dart!=last_dart;
++current_dart)
{
if (amap->is_marked(current_dart, mark)) continue;
typename CMap::Dart_handle first_dart_in_cell= current_dart;
typename CMap::Dart_handle current_dart_in_cell=
first_dart_in_cell->beta(1);
typename CMap::Helper::template Attribute_handle<0>::type
attribute_for_first_dart=current_dart_in_cell->template attribute<0>();
attribute_for_first_dart->inc_nb_refs();
do {
amap->mark(current_dart_in_cell, mark);
typename CMap::Dart_handle previous_dart_in_cell=
current_dart_in_cell->beta(0);
typename CMap::Dart_handle next_dart_in_cell=
current_dart_in_cell->beta(1);
typename CMap::Helper::template Attribute_handle<0>::type
next_attribute=next_dart_in_cell->template attribute<0>();
// One line error???
CGAL::internal::Set_i_attribute_of_dart_functor<CMap, 0>::
run(amap, current_dart_in_cell, next_attribute);
current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1);
current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0);
current_dart_in_cell = current_dart_in_cell->beta(0);
}
while (current_dart_in_cell != first_dart_in_cell);
amap->mark(current_dart_in_cell, mark);
typename CMap::Dart_handle previous_dart_in_cell=
current_dart_in_cell->beta(0);
typename CMap::Dart_handle next_dart_in_cell=
current_dart_in_cell->beta(1);
CGAL::internal::Set_i_attribute_of_dart_functor<CMap, 0>::
run(amap, current_dart_in_cell, attribute_for_first_dart);
attribute_for_first_dart->dec_nb_refs();
current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1);
current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0);
}
amap->negate_mark(mark);
CGAL_postcondition(amap->is_whole_map_unmarked(mark));
CGAL_postcondition(amap->is_valid());
amap->free_mark(mark);
}
};
// ****************************************************************************
// Specialization for void 0-attributes
template <typename CMap>
struct Reverse_orientation_of_map_functor<CMap, CGAL::Void>
{
static void run(CMap *amap)
{
int mark = amap->get_new_mark();
CGAL_precondition(amap->is_whole_map_unmarked(mark));
CGAL_precondition(amap->is_valid());
for (typename CMap::Dart_range::iterator current_dart=amap->darts().begin(),
last_dart = amap->darts().end(); current_dart!=last_dart;
++current_dart)
{
if (amap->is_marked(current_dart, mark)) continue;
for (typename CMap::template Dart_of_cell_range<2>::iterator
current_dart_in_cell=amap->template darts_of_cell<2>(current_dart).
begin(), last_dart_in_cell=amap->template darts_of_cell<2>
(current_dart).end(); current_dart_in_cell!=last_dart_in_cell;
++current_dart_in_cell)
{
amap->mark(current_dart_in_cell, mark);
typename CMap::Dart_handle previous_dart_in_cell=
current_dart_in_cell->beta(0);
typename CMap::Dart_handle next_dart_in_cell=
current_dart_in_cell->beta(1);
current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1);
current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0);
}
}
amap->negate_mark(mark);
CGAL_postcondition(amap->is_whole_map_unmarked(mark));
CGAL_postcondition(amap->is_valid());
amap->free_mark(mark);
}
};
// ****************************************************************************
/// Functor to reverse the orientation of a connected component in a given map
template <typename CMap, typename Attrib=
typename CMap::Helper::template Attribute_type<0>::type>
struct Reverse_orientation_of_connected_component_functor
{
static void run(CMap *amap, typename CMap::Dart_handle adart)
{
int mark = amap->get_new_mark();
CGAL_precondition(amap->is_whole_map_unmarked(mark));
for (typename CMap::template Dart_of_cell_range<CMap::dimension+1>::iterator
current_dart=amap->template darts_of_cell<CMap::dimension+1>(adart).
begin(), last_dart=amap->template darts_of_cell<CMap::dimension+1>
(adart).end(); current_dart!=last_dart; ++current_dart)
{
if (amap->is_marked(current_dart, mark)) continue;
typename CMap::Dart_handle first_dart_in_cell=current_dart;
typename CMap::Dart_handle current_dart_in_cell=
first_dart_in_cell->beta(1);
typename CMap::Helper::template Attribute_handle<0>::type
attribute_for_first_dart=current_dart_in_cell->template attribute<0>();
attribute_for_first_dart->inc_nb_refs();
do {
amap->mark(current_dart_in_cell, mark);
typename CMap::Dart_handle previous_dart_in_cell=
current_dart_in_cell->beta(0);
typename CMap::Dart_handle next_dart_in_cell=
current_dart_in_cell->beta(1);
typename CMap::Helper::template Attribute_handle<0>::type
next_attribute=next_dart_in_cell->template attribute<0>();
CGAL::internal::Set_i_attribute_of_dart_functor<CMap, 0>::
run(amap, current_dart_in_cell, next_attribute);
current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1);
current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0);
current_dart_in_cell = current_dart_in_cell->beta(0);
}
while (current_dart_in_cell != first_dart_in_cell);
amap->mark(current_dart_in_cell, mark);
typename CMap::Dart_handle previous_dart_in_cell=
current_dart_in_cell->beta(0);
typename CMap::Dart_handle next_dart_in_cell=
current_dart_in_cell->beta(1);
CGAL::internal::Set_i_attribute_of_dart_functor<CMap, 0>::
run(amap, current_dart_in_cell, attribute_for_first_dart);
attribute_for_first_dart->dec_nb_refs();
current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1);
current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0);
}
for (typename CMap::template Dart_of_cell_range<CMap::dimension+1>::iterator
current_dart=amap->template darts_of_cell<CMap::dimension+1>(adart).
begin(), last_dart=amap->template darts_of_cell<CMap::dimension+1>
(adart).end(); current_dart!=last_dart; ++current_dart)
{
amap->unmark(current_dart, mark);
}
CGAL_postcondition(amap->is_whole_map_unmarked(mark));
amap->free_mark(mark);
}
};
// ****************************************************************************
// Specialization for void 0-attributes
template <typename CMap>
struct Reverse_orientation_of_connected_component_functor<CMap, CGAL::Void>
{
static void run(CMap *amap, typename CMap::Dart_handle adart)
{
int mark = amap->get_new_mark();
CGAL_precondition(amap->is_whole_map_unmarked(mark));
for (typename CMap::template Dart_of_cell_range<CMap::dimension+1>::iterator
current_dart=amap->template darts_of_cell<CMap::dimension+1>(adart).
begin(), last_dart=amap->template darts_of_cell<CMap::dimension+1>
(adart).end(); current_dart!=last_dart; ++current_dart)
{
if (amap->is_marked(current_dart, mark)) continue;
for (typename CMap::template Dart_of_cell_range<2>::iterator
current_dart_in_cell=amap->template darts_of_cell<2>(current_dart).
begin(), last_dart_in_cell=amap->template darts_of_cell<2>
(current_dart).end(); current_dart_in_cell!=last_dart_in_cell;
++current_dart_in_cell)
{
amap->mark(current_dart_in_cell, mark);
typename CMap::Dart_handle previous_dart_in_cell=
current_dart_in_cell->beta(0);
typename CMap::Dart_handle next_dart_in_cell=
current_dart_in_cell->beta(1);
current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1);
current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0);
}
}
for (typename CMap::template Dart_of_cell_range<CMap::dimension+1>::iterator
current_dart=amap->template darts_of_cell<CMap::dimension+1>(adart).
begin(), last_dart=amap->template darts_of_cell<CMap::dimension+1>
(adart).end(); current_dart!=last_dart; ++current_dart)
{
amap->unmark(current_dart, mark);
}
CGAL_postcondition(amap->is_whole_map_unmarked(mark));
amap->free_mark(mark);
}
};
// ****************************************************************************
// Beta functor, used to combine several beta.
#ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES
template<typename Dart_handle, typename ... Betas>

View File

@ -284,6 +284,12 @@ bool test_LCC_4()
return false;
}
lcc.reverse_orientation();
lcc.reverse_orientation();
lcc.reverse_orientation_connected_component(dh1);
lcc.reverse_orientation_connected_component(dh1);
/* import_from_polyhedron<LCC>(lcc,ap);
lcc.clear();