Continue on group/ungroup: nyf

This commit is contained in:
Guillaume Damiand 2013-02-11 22:03:18 +01:00
parent 6678832c7a
commit fbe2a506d7
3 changed files with 732 additions and 668 deletions

View File

@ -86,13 +86,7 @@ namespace CGAL {
insert_cell_0_in_cell_2(Map& amap, typename Map::Dart_handle adart); insert_cell_0_in_cell_2(Map& amap, typename Map::Dart_handle adart);
/*template<typename CMap, unsigned int i, typename Type_attr, typename Range> /*template<typename CMap, unsigned int i, typename Type_attr, typename Range>
friend struct internal::Degroup_one_attribute_of_dart_functor;*/ friend struct internal::Degroup_one_attribute_of_dart_functor;
template <typename CMap, unsigned int i, typename Type_attr>
friend struct internal::Degroup_one_attribute_functor;
template<typename Map>
friend struct internal::Test_is_valid_attribute_functor;
template<typename CMap, unsigned int i, typename T> template<typename CMap, unsigned int i, typename T>
friend struct internal::Group_attribute_functor_of_dart_run; friend struct internal::Group_attribute_functor_of_dart_run;
@ -100,11 +94,16 @@ namespace CGAL {
template<typename Map,unsigned int i> template<typename Map,unsigned int i>
friend struct internal::Group_attribute_functor_run; friend struct internal::Group_attribute_functor_run;
template <typename CMap, unsigned int i, typename Type_attr>
friend struct internal::Group_one_attribute_functor;
template<typename Map,unsigned int i> template<typename Map,unsigned int i>
friend struct internal::Degroup_attribute_functor_run; friend struct internal::Degroup_attribute_functor_run;
*/
template <typename CMap, unsigned int i, typename Type_attr>
friend struct internal::Degroup_one_attribute_functor;
template<typename Map>
friend struct internal::Test_is_valid_attribute_functor;
template<typename Map> template<typename Map>
friend struct internal::Update_dart_of_attribute_functor; friend struct internal::Update_dart_of_attribute_functor;
@ -1420,7 +1419,7 @@ namespace CGAL {
CGAL_assertion( (is_sewable_1(adart1,adart2)) ); CGAL_assertion( (is_sewable_1(adart1,adart2)) );
int m = get_new_mark(); int m = get_new_mark();
std::vector<Dart_handle> dartv; std::deque<Dart_handle> dartv;
for (CMap_dart_iterator_basic_of_cell<Self,0> it(*this,adart1,m); for (CMap_dart_iterator_basic_of_cell<Self,0> it(*this,adart1,m);
it.cont(); ++it) it.cont(); ++it)
{ {
@ -1432,14 +1431,12 @@ namespace CGAL {
CMap_dart_iterator_of_involution_inv<Self,1> I2(*this, adart2); CMap_dart_iterator_of_involution_inv<Self,1> I2(*this, adart2);
while ( I1.cont() ) while ( I1.cont() )
{ {
if ( is_marked(I1,m) ) if ( is_marked(I1,m) ) basic_link_beta_1(I1, I2);
basic_link_beta_1(I1, I2); else basic_link_beta_0(I1, I2);
else
basic_link_beta_0(I1, I2);
++I1; ++I2; ++I1; ++I2;
} }
for (typename std::vector<Dart_handle>::iterator for (typename std::deque<Dart_handle>::iterator
it=dartv.begin(); it!=dartv.end(); ++it) it=dartv.begin(); it!=dartv.end(); ++it)
{ unmark(*it,m); } { unmark(*it,m); }
CGAL_assertion( is_whole_map_unmarked(m) ); CGAL_assertion( is_whole_map_unmarked(m) );
@ -1521,8 +1518,8 @@ namespace CGAL {
{ {
Dart_handle od1=I1->other_extremity(); Dart_handle od1=I1->other_extremity();
Dart_handle od2=I2->other_extremity(); Dart_handle od2=I2->other_extremity();
if (od1!=NULL && od2!=NULL) /*if (od1!=NULL && od2!=NULL) TODO
group_all_attributes_except(od1, od2, 1); group_all_attributes_except(od1, od2, 1);*/
++I1; ++I2; ++I1; ++I2;
} }
@ -1567,7 +1564,7 @@ namespace CGAL {
CMap_dart_iterator_of_involution_inv<Self,1> I2(*this, adart2); CMap_dart_iterator_of_involution_inv<Self,1> I2(*this, adart2);
while ( I1.cont() ) while ( I1.cont() )
{ {
group_all_attributes_except(I1,I2,1); // TODO group_all_attributes_except(I1,I2,1);
++I1; ++I2; ++I1; ++I2;
} }
@ -1613,7 +1610,7 @@ namespace CGAL {
while ( I1.cont() ) while ( I1.cont() )
{ {
group_all_attributes_except(I1,I2,i); // TODO group_all_attributes_except(I1,I2,i);
++I1; ++I2; ++I1; ++I2;
} }
@ -1783,8 +1780,8 @@ namespace CGAL {
// TODO do the degroup after the loop (cf unsew_for_involution) // TODO do the degroup after the loop (cf unsew_for_involution)
Dart_handle od1=it->other_extremity(); Dart_handle od1=it->other_extremity();
Dart_handle od2=d2->other_extremity(); Dart_handle od2=d2->other_extremity();
if ( od1!=NULL && od2!=NULL ) /* TODO if ( od1!=NULL && od2!=NULL )
degroup_all_attributes_except(od1,od2,1); degroup_all_attributes_except(od1,od2,1); */
++it; ++it;
} }
@ -1828,7 +1825,7 @@ namespace CGAL {
else else
{ d2 = it->beta(0); unlink_beta_0(it); } { d2 = it->beta(0); unlink_beta_0(it); }
// TODO do the degroup after the loop (cf unsew_for_involution) // TODO do the degroup after the loop (cf unsew_for_involution)
degroup_all_attributes_except(it,d2,1); // TODO degroup_all_attributes_except(it,d2,1);
++it; ++it;
} }
} }
@ -1869,7 +1866,7 @@ namespace CGAL {
{ {
internal::Couple_dart_and_dim<Dart_handle> c=todegroup.top(); internal::Couple_dart_and_dim<Dart_handle> c=todegroup.top();
todegroup.pop(); todegroup.pop();
degroup_all_attributes_except(c.d1,c.d2,c.dim); // TODO degroup_all_attributes_except(c.d1,c.d2,c.dim);
} }
} }
@ -2057,6 +2054,7 @@ namespace CGAL {
} }
} }
public:
/** Update the dart of the given i-cell attribute onto a non marked dart. /** Update the dart of the given i-cell attribute onto a non marked dart.
* @param ah the attribute to update. * @param ah the attribute to update.
* @param amark the mark. * @param amark the mark.
@ -2097,91 +2095,6 @@ namespace CGAL {
<internal::Update_dart_of_attribute_functor<Self> >::run(this,ah,amark); <internal::Update_dart_of_attribute_functor<Self> >::run(this,ah,amark);
} }
/** Group the i-cell-attributes of the two given darts, if required.
* If the two i-cell-attributes of \em adart1 and \em adart2 are different,
* we set the i-cell-attribute of adart2 onto the attribute of adart1.
* @param adart1 the first dart.
* @param adart2 the second dart.
* @return true iff the two attributes are merged.
*/
template<unsigned int i>
bool group_enabled_attribute_of_dart( Dart_handle dh1, Dart_handle dh2)
{
}
/** Degroup the i-cell attribute of the two given darts, if required.
* We create a new attribute and link dart2 onto this new attribute.
* The new attribute is initialized by copying the old one.
* @param adart1 the first dart.
* @param adart2 the second dart.
* @return true iff the attribute is split.
*/
template<unsigned int i>
bool degroup_enabled_attribute_of_dart( Dart_handle dh1, Dart_handle dh2)
{
CGAL_static_assertion(i<=dimension);
CGAL_static_assertion_msg(Helper::template Dimension_index<i>::value>=0,
"group_enabled_attribute_of_dart<i> but "
"i-attributes are disabled");
CGAL_assertion( dh1!=NULL && dh2!=NULL );
CGAL_assertion( dh1!=null_dart_handle && dh2!=null_dart_handle );
typename Attribute_handle<i>::type a1=dh1->template attribute<i>();
typename Attribute_handle<i>::type a2=dh2->template attribute<i>();
// If the two attributes are different, nothing to do.
if ( a1==NULL || a1 != a2 ) return false;
a2 = create_attribute<i>(*a1);
// We set the attribute of dh2 to a2.
set_attribute_of_dart<i>(dh2, a2);
return true;
}
/** Group the i cell-attributes of two darts.
* If the two i cell-attribute of \em adart1 and \em adart2 are different,
* we set the i cell-attribute of each dart belonging to the i-cell orbit
* of \em adart2 onto the i-cell of \em adart1.
* We use the functor On_merge and possibly remove the second
* cell-attribute if there is no more darts linked to it.
* @param adart1 the first dart.
* @param adart2 the second dart.
*/
template<unsigned int i, class Type_attr>
void group_enabled_attribute( Dart_handle adart1, Dart_handle adart2)
{
CGAL_static_assertion(i<=dimension);
CGAL_static_assertion_msg(Helper::template Dimension_index<i>::value>=0,
"group_enabled_attribute<i> but "
"i-attributes are disabled");
CGAL_assertion(adart1 != NULL && adart2 != NULL);
CGAL_assertion(adart1 != null_dart_handle && adart2 != null_dart_handle);
typename Attribute_handle<i>::type a1=adart1->template attribute<i>();
typename Attribute_handle<i>::type a2=adart2->template attribute<i>();
// If the two attributes are equal, nothing to do.
if ( a1 == a2 ) return;
Dart_handle toSet = NULL;
// If the attribute associated to adart1 is NULL, set it with
// the attribute associated to adart2 (necessarily != NULL)
if (a1 == NULL)
{ toSet = adart1; a1 = a2; }
else
{
toSet = adart2;
if (a2 != NULL)
{
internal::Apply_cell_functor<Type_attr,
typename Type_attr::On_merge>::run(*a1,*a2);
}
}
set_attribute<i>(toSet, a1);
}
/** Degroup the i-cell attribute of the two given darts, if required. /** Degroup the i-cell attribute of the two given darts, if required.
* If the two darts are incident to the same attribute and do not belong to * If the two darts are incident to the same attribute and do not belong to
* the same i-cell, we create a new attibute and link each dart * the same i-cell, we create a new attibute and link each dart
@ -2230,86 +2143,6 @@ namespace CGAL {
return true; return true;
} }
/** Group all the attributes of adart1 and adart2. If both dart have a
* i-attribute, the attribute associated to adart1 is kept.
* @param adart1 the first dart.
* @param adart1 the second dart.
*/
template<unsigned int i>
void group_attribute(Dart_handle adart1, Dart_handle adart2)
{
internal::Group_one_attribute_functor<Self,i,
typename Attribute_type<i>::type>::run(this,adart1,adart2);
}
/** Group all the dart attributes of adart1 and adart2, except the
* adim-cell attribute.
* @param adart1 the first dart.
* @param adart1 the second dart.
* @param adim the dimension to not group (-1 to group all dimensions).
* note that 0-attr are always grouped if adart1-> other_extremity()!=NULL.
*/
void group_all_dart_attributes_except(Dart_handle adart1,
Dart_handle adart2, int adim)
{
CGAL_assertion( adim==-1 || (1<=adim && (unsigned int)adim<=dimension) );
Helper::template Foreach_enabled_attributes
<internal::Group_attribute_functor_of_dart<Self> >::
run(this,adart1,adart2,adim);
}
/** Group all the cells attributes of adart1 and adart2, except the
* adim-cell attribute.
* @param adart1 the first dart.
* @param adart1 the second dart.
* @param adim the dimension to not group (-1 to group all dimensions).
* note that 0-attr are always grouped if adart1-> other_extremity()!=NULL.
*/
void group_all_attributes_except(Dart_handle adart1, Dart_handle adart2,
int adim)
{
CGAL_assertion( adim==-1 || (1<=adim && (unsigned int)adim<=dimension) );
Helper::template Foreach_enabled_attributes
<internal::Group_attribute_functor<Self> >::
run(this,adart1,adart2,adim);
}
template<unsigned int i>
bool degroup_attribute(Dart_handle adart1, Dart_handle adart2)
{
return internal::Degroup_one_attribute_functor<Self,i,
typename Attribute_type<i>::type>::run(this,adart1,adart2);
}
/** Degroup all the cells attributes of adart1 and adart2, except the
* adim-cell attribute.
* @param adart1 the first dart.
* @param adart1 the second dart.
* @param adim the dimension to not degroup (-1 to degroup all).
*/
void degroup_all_attributes_except(Dart_handle adart1, Dart_handle adart2,
int adim)
{
CGAL_assertion( adim==-1 || (1<=adim && (unsigned int)adim<=dimension) );
Helper::template Foreach_enabled_attributes
<internal::Degroup_attribute_functor<Self> >::
run(this,adart1,adart2,adim);
}
/** Degroup all the cells attributes of adart1 and adart2.
* @param adart1 the first dart.
* @param adart1 the second dart.
*/
void degroup_all_attributes(Dart_handle adart1, Dart_handle adart2)
{ degroup_all_attributes_except(adart1, adart2, -1); }
/* template<unsigned int i>
bool degroup_attribute_of_dart(Dart_handle adart1, Dart_handle adart2)
{
return internal::Degroup_one_attribute_of_dart_functor<Self,i>::
run(this,adart1,adart2);
}*/
/** Test the validity of a i-cell-attribute. /** Test the validity of a i-cell-attribute.
* ie all the darts belonging to a i-cell are linked to the same attribute. * ie all the darts belonging to a i-cell are linked to the same attribute.
* @param adart a dart. * @param adart a dart.
@ -2393,52 +2226,6 @@ namespace CGAL {
return res; return res;
} }
public:
/** Set the i th attribute of the given dart.
* @param adart a dart.
* @param ah the attribute to set.
*/
template<unsigned int i>
void set_attribute_of_dart(Dart_handle adart,
typename Attribute_handle<i>::type ah)
{
CGAL_static_assertion(i<=dimension);
CGAL_static_assertion_msg(Helper::template Dimension_index<i>::value>=0,
"set_attribute_of_dart<i> but "
"i-attributes are disabled");
CGAL_assertion( adart!=NULL && adart!=null_dart_handle && ah!=NULL );
CGAL_assertion( adart->template attribute<i>()!=ah );
decrease_attribute_ref_counting<i>(adart);
adart->template set_attribute<i>(ah);
// TODO remove the set_dart ?
ah->set_dart(adart);
}
/** Set the i th attribute of all the darts of a given i-cell.
* @param adart a dart of the i-cell.
* @param ah the vertex to set.
*/
template<unsigned int i>
void set_attribute(Dart_handle adart,
typename Attribute_handle<i>::type ah)
{
CGAL_static_assertion(i<=dimension);
CGAL_static_assertion_msg(Helper::template Dimension_index<i>::value>=0,
"set_attribute<i> but i-attributes are disabled");
CGAL_assertion( adart!=NULL && adart!=null_dart_handle && ah!=NULL );
for (CMap_dart_iterator_of_cell<Self,i> it(*this, adart);
it.cont(); ++it)
{
if ( it->template attribute<i>()!=ah )
{
decrease_attribute_ref_counting<i>(it);
it->template set_attribute<i>(ah);
}
}
ah->set_dart(adart);
}
#ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES #ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES
//************************************************************************** //**************************************************************************
// Dart_of_orbit_basic_range // Dart_of_orbit_basic_range
@ -3266,6 +3053,71 @@ namespace CGAL {
{ return one_dart_per_cell<i,Self::dimension>(); } { return one_dart_per_cell<i,Self::dimension>(); }
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** Set the i th attribute of the given dart.
* @param adart a dart.
* @param ah the attribute to set.
*/
template<unsigned int i>
void set_attribute_of_dart(Dart_handle adart,
typename Attribute_handle<i>::type ah)
{
CGAL_static_assertion(i<=dimension);
CGAL_static_assertion_msg(Helper::template Dimension_index<i>::value>=0,
"set_attribute_of_dart<i> but "
"i-attributes are disabled");
CGAL_assertion( adart!=NULL && adart!=null_dart_handle && ah!=NULL );
CGAL_assertion( adart->template attribute<i>()!=ah );
decrease_attribute_ref_counting<i>(adart);
adart->template set_attribute<i>(ah);
// TODO remove the set_dart ?
// ah->set_dart(adart);
}
public:
/** Set the i-attribute of all the darts of a given range.
* @param adart a starting dart.
* @param ah an handle to the i-attribute to set.
*/
template<unsigned int i>
void set_attribute(Dart_handle adart,
typename Attribute_handle<i>::type ah)
{
CGAL_static_assertion(i<=dimension);
CGAL_static_assertion_msg(Helper::template Dimension_index<i>::value>=0,
"set_attribute<i> but i-attributes are disabled");
CGAL_assertion( adart!=NULL && adart!=null_dart_handle && ah!=NULL );
for (typename Dart_of_cell_range<i>::iterator it(*this, adart);
it.cont(); ++it)
{
if ( it->template attribute<i>()!=ah )
{
decrease_attribute_ref_counting<i>(it);
it->template set_attribute<i>(ah);
}
}
ah->set_dart(adart);
}
template<unsigned int i, typename Range>
void set_attribute(Dart_handle adart,
typename Attribute_handle<i>::type ah)
{
CGAL_static_assertion(i<=dimension);
CGAL_static_assertion_msg(Helper::template Dimension_index<i>::value>=0,
"set_attribute<i> but i-attributes are disabled");
CGAL_assertion( adart!=NULL && adart!=null_dart_handle && ah!=NULL );
for (typename Range::iterator it(*this, adart); it.cont(); ++it)
{
if ( it->template attribute<i>()!=ah )
{
decrease_attribute_ref_counting<i>(it);
it->template set_attribute<i>(ah);
}
}
ah->set_dart(adart);
}
/** Compute the dual of a Combinatorial_map. /** Compute the dual of a Combinatorial_map.
* @param amap the cmap in which we build the dual of this map. * @param amap the cmap in which we build the dual of this map.
* @param adart a dart of the initial map, NULL by default. * @param adart a dart of the initial map, NULL by default.
@ -3331,7 +3183,6 @@ namespace CGAL {
return res; return res;
} }
public:
/// Void dart. A dart d is i-free if beta_i(d)=null_dart_handle. /// Void dart. A dart d is i-free if beta_i(d)=null_dart_handle.
static Dart_handle null_dart_handle; static Dart_handle null_dart_handle;

File diff suppressed because it is too large Load Diff

View File

@ -31,34 +31,139 @@
* compiling time. * compiling time.
* *
* Group_attribute_functor_of_dart<CMap> to group the <i>-attributes of two * Group_attribute_functor_of_dart<CMap> to group the <i>-attributes of two
* given darts (except for adim). * given darts (except for j-dim). Only the attributes of the two given
* darts are possibly modified.
* Group_attribute_functor_of_dart_run<CMap,i> same than * Group_attribute_functor_of_dart_run<CMap,i> same than
* Group_attribute_functor_of_dart<CMap>::run<i>, with i template argument * Group_attribute_functor_of_dart<CMap>::run<i>, with i template argument
* given in the struct to enable specialization. * given in the struct to enable specialization.
* *
* Group_attribute_functor<CMap> to group the <i>-attributes of two
* given i-cells (except forj-adim). If one i-attribute is NULL, we set the
* darts of its i-cell to the second attribute. If both i-attributes are
* non NULL, we overide all the i-attribute of the second i-cell to the
* first i-attribute.
* *
* Call_split_functor<CMap,i> to call the OnSplit functor on two given
* i-attributes.
* *
** Call_merge_functor<CMap,i> to call the OnMerge functor on two given
* i-attributes.
*/ */
namespace CGAL { namespace CGAL
namespace internal { {
namespace internal
{
/** @file Combinatorial_map_functors.h /** @file Combinatorial_map_functors.h
* Definition of functors used for dD Combinatorial map. * Definition of functors used for dD Combinatorial map.
*/ */
// **************************************************************************
// Functor which call Functor::operator() on the two given cell_attributes
template<typename Cell_attribute, typename Functor>
struct Apply_cell_functor
{
static void run(Cell_attribute& acell1, Cell_attribute& acell2)
{
Functor() (acell1,acell2);
}
};
//...except for Null_functor.
template<typename Cell_attribute>
struct Apply_cell_functor<Cell_attribute,Null_functor>
{
static void run(Cell_attribute&, Cell_attribute&)
{}
};
// Functor used to call the On_split functor between the two given darts.
template<typename Map,unsigned int i,
typename Enabled=typename Map::Helper::
#ifndef CGAL_CFG_TEMPLATE_IN_DEFAULT_PARAMETER_BUG
template
#endif
Attribute_type<i>::type>
struct Call_split_functor
{
static void run(typename Map::Dart_handle adart1,
typename Map::Dart_handle adart2)
{
Apply_cell_functor
<typename Map::Helper::template Attribute_type<i>::type,
typename Map::Helper::template Attribute_type<i>::type::On_split>::
run(*(adart1->template attribute<i>()),
*(adart2->template attribute<i>()));
}
static void
run(typename Map::Helper::template Attribute_handle<i>::type a1,
typename Map::Helper::template Attribute_handle<i>::type a2)
{
Apply_cell_functor
<typename Map::Helper::template Attribute_type<i>::type,
typename Map::Helper::template Attribute_type<i>::type::On_split>::
run(*a1, *a2);
}
};
// Specialization for disabled attributes.
template<typename Map,unsigned int i>
struct Call_split_functor<Map,i,CGAL::Void>
{
static void run(typename Map::Dart_handle,
typename Map::Dart_handle)
{}
};
// Functor used to call the On_merge functor between the two given darts.
template<typename Map,unsigned int i,
typename Enabled=typename Map::Helper::
#ifndef CGAL_CFG_TEMPLATE_IN_DEFAULT_PARAMETER_BUG
template
#endif
Attribute_type<i>::type>
struct Call_merge_functor
{
static void run(typename Map::Dart_handle adart1,
typename Map::Dart_handle adart2)
{
Apply_cell_functor
<typename Map::Helper::template Attribute_type<i>::type,
typename Map::Helper::template Attribute_type<i>::type::On_merge>::
run(*(adart1->template attribute<i>()),
*(adart2->template attribute<i>()));
}
static void
run(typename Map::Helper::template Attribute_handle<i>::type a1,
typename Map::Helper::template Attribute_handle<i>::type a2)
{
Apply_cell_functor
<typename Map::Helper::template Attribute_type<i>::type,
typename Map::Helper::template Attribute_type<i>::type::On_merge>::
run(*a1, *a2);
}
};
// Specialization for disabled attributes.
template<typename Map,unsigned int i>
struct Call_merge_functor<Map,i,CGAL::Void>
{
static void run(typename Map::Dart_handle,
typename Map::Dart_handle)
{}
};
// ************************************************************************** // **************************************************************************
/// Functor used for link_beta to update the i-attributes of /// Functor used for link_beta to update the i-attributes of
/// adart2 on the attributes of this dart, except if i=j. /// adart2 on the attributes of this dart, except if i=j.
/// Only attributes of dh1 or dh2 can be modified. /// Only attributes of dh1 or dh2 can be modified.
template<typename CMap, unsigned int i, unsigned int j=CMap::dimension+1, template<typename CMap, unsigned int i, unsigned int j=CMap::dimension+1,
typename T= typename T=
typename CMap::Helper::template Attribute_handle<i>::type> typename CMap::Helper::template Attribute_type<i>::type>
struct Group_attribute_functor_of_dart_run struct Group_attribute_functor_of_dart_run
{ {
/// Group the i-attribute of dh1 and dh2. /// Group the i-attribute of dh1 and dh2.
/// @return true if the two attributes are grouped, false otherwise. static void run(CMap* amap,
static bool run(CMap* amap,
typename CMap::Dart_handle dh1, typename CMap::Dart_handle dh1,
typename CMap::Dart_handle dh2) typename CMap::Dart_handle dh2)
{ {
@ -69,29 +174,38 @@ namespace CGAL {
"Group_attribute_functor_of_dart_run<i> but " "Group_attribute_functor_of_dart_run<i> but "
"i-attributes are disabled"); "i-attributes are disabled");
CGAL_assertion( dh1!=NULL && dh2!=NULL ); CGAL_assertion( dh1!=NULL && dh2!=NULL );
CGAL_assertion( dh1!=CMap::null_dart_handle &&
dh1!=CMap::null_dart_handle );
T a1=dh1->template attribute<i>(); typename CMap::Helper::template Attribute_handle<i>::type
T a2=dh2->template attribute<i>(); a1=dh1->template attribute<i>();
typename CMap::Helper::template Attribute_handle<i>::type
a2=dh2->template attribute<i>();
// If the two attributes are equal, nothing to do. // If the two attributes are equal, nothing to do.
if ( a1==a2 ) return false; if ( a1==a2 ) return;
if ( a1==NULL ) amap->template set_attribute_of_dart<i>(dh1, a2); if ( a1==NULL ) amap->template set_attribute_of_dart<i>(dh1, a2);
else amap->template set_attribute_of_dart<i>(dh2, a1); else amap->template set_attribute_of_dart<i>(dh2, a1);
return true;
} }
}; };
template<typename CMap, unsigned int j, typename T> template<typename CMap, unsigned int j, typename T>
struct Group_attribute_functor_of_dart_run<CMap, 0, j, T> struct Group_attribute_functor_of_dart_run<CMap, 0, j, T>
{ {
static bool run(CMap* amap, static void run(CMap* amap,
typename CMap::Dart_handle dh1, typename CMap::Dart_handle dh1,
typename CMap::Dart_handle dh2) typename CMap::Dart_handle dh2)
{ {
CGAL_static_assertion(j!=0 && j!=1); CGAL_static_assertion(j!=0 && j!=1);
bool res = false; CGAL_assertion( dh1!=NULL && dh2!=NULL );
T a1=NULL, a2=NULL; CGAL_assertion( dh1!=CMap::null_dart_handle &&
dh1!=CMap::null_dart_handle );
CGAL_static_assertion_msg(CMap::Helper::template
Dimension_index<0>::value>=0,
"Group_attribute_functor_of_dart_run<0> but "
"0-attributes are disabled");
typename CMap::Helper::template Attribute_handle<0>::type
a1=NULL, a2=NULL;
// First extremity // First extremity
typename CMap::Dart_handle od = dh2->other_extremity(); typename CMap::Dart_handle od = dh2->other_extremity();
@ -103,7 +217,6 @@ namespace CGAL {
if ( a1==NULL && a2!=NULL ) if ( a1==NULL && a2!=NULL )
{ {
amap->template set_attribute_of_dart<0>(dh1, a2); amap->template set_attribute_of_dart<0>(dh1, a2);
res = true;
} }
} }
@ -117,60 +230,70 @@ namespace CGAL {
if ( a1!=NULL ) if ( a1!=NULL )
{ {
amap->template set_attribute_of_dart<0>(dh2, a1); amap->template set_attribute_of_dart<0>(dh2, a1);
res = true;
} }
} }
return res;
} }
}; };
template<typename CMap, typename T> template<typename CMap, typename T>
struct Group_attribute_functor_of_dart_run<CMap, 0, 0, T> struct Group_attribute_functor_of_dart_run<CMap, 0, 0, T>
{ {
static bool run(CMap* amap, static void run(CMap* amap,
typename CMap::Dart_handle dh1, typename CMap::Dart_handle dh1,
typename CMap::Dart_handle dh2) typename CMap::Dart_handle dh2)
{ {
CGAL_assertion( dh1!=NULL && dh2!=NULL );
CGAL_assertion( dh1!=CMap::null_dart_handle &&
dh1!=CMap::null_dart_handle );
CGAL_static_assertion_msg(CMap::Helper::template
Dimension_index<0>::value>=0,
"Group_attribute_functor_of_dart_run<0> but "
"0-attributes are disabled");
typename CMap::Dart_handle od = dh2->other_extremity(); typename CMap::Dart_handle od = dh2->other_extremity();
if ( od!=NULL ) if ( od!=NULL )
{ {
T a1=dh1->template attribute<0>(); typename CMap::Helper::template Attribute_handle<0>::type
T a2=od->template attribute<0>(); a1=dh1->template attribute<0>();
typename CMap::Helper::template Attribute_handle<0>::type
a2=od->template attribute<0>();
if ( a1==NULL && a2!=NULL ) if ( a1==NULL && a2!=NULL )
{ {
amap->template set_attribute_of_dart<0>(dh1, a2); amap->template set_attribute_of_dart<0>(dh1, a2);
return true;
} }
} }
return false;
} }
}; };
template<typename CMap, typename T> template<typename CMap, typename T>
struct Group_attribute_functor_of_dart_run<CMap, 0, 1, T> struct Group_attribute_functor_of_dart_run<CMap, 0, 1, T>
{ {
static bool run(CMap* amap, static void run(CMap* amap,
typename CMap::Dart_handle dh1, typename CMap::Dart_handle dh1,
typename CMap::Dart_handle dh2) typename CMap::Dart_handle dh2)
{ {
CGAL_assertion( dh1!=NULL && dh2!=NULL );
CGAL_assertion( dh1!=CMap::null_dart_handle &&
dh1!=CMap::null_dart_handle );
CGAL_static_assertion_msg(CMap::Helper::template
Dimension_index<0>::value>=0,
"Group_attribute_functor_of_dart_run<0> but "
"0-attributes are disabled");
typename CMap::Dart_handle od = dh1->other_extremity(); typename CMap::Dart_handle od = dh1->other_extremity();
if ( od!=NULL ) if ( od!=NULL )
{ {
T a1=od->template attribute<0>(); typename CMap::Helper::template Attribute_handle<0>::type
T a2=dh2->template attribute<0>(); a1=od->template attribute<0>();
typename CMap::Helper::template Attribute_handle<0>::type
a2=dh2->template attribute<0>();
if ( a1!=NULL ) if ( a1!=NULL )
{ {
amap->template set_attribute_of_dart<0>(dh2, a1); amap->template set_attribute_of_dart<0>(dh2, a1);
return true;
} }
} }
return false;
} }
}; };
template<typename CMap, unsigned int i, unsigned int j> template<typename CMap, unsigned int i, unsigned int j>
struct Group_attribute_functor_of_dart_run<CMap,i,j,Void> struct Group_attribute_functor_of_dart_run<CMap,i,j,CGAL::Void>
{ {
static void run(CMap*, static void run(CMap*,
typename CMap::Dart_handle, typename CMap::Dart_handle,
@ -196,16 +319,287 @@ namespace CGAL {
struct Group_attribute_functor_of_dart struct Group_attribute_functor_of_dart
{ {
template <unsigned int i> template <unsigned int i>
static bool run(CMap* amap, static void run(CMap* amap,
typename CMap::Dart_handle adart1, typename CMap::Dart_handle adart1,
typename CMap::Dart_handle adart2) typename CMap::Dart_handle adart2)
{ {
return Group_attribute_functor_of_dart_run<CMap,i,j>:: Group_attribute_functor_of_dart_run<CMap,i,j>::run(amap,adart1,adart2);
run(amap,adart1,adart2);
} }
}; };
// ************************************************************************** // **************************************************************************
// Functor used to group the two i-attributes of the two i-cells, except the
// attribute of j
template<typename CMap, unsigned int i, unsigned int j=CMap::dimension+1,
typename T=
typename CMap::Helper::template Attribute_type<i>::type>
struct Group_attribute_functor_run
{
static void run(CMap* amap,
typename CMap::Dart_handle adart1,
typename CMap::Dart_handle adart2)
{
CGAL_static_assertion( i<=CMap::dimension );
CGAL_static_assertion( i!=j );
CGAL_static_assertion_msg
( CMap::Helper::template Dimension_index<i>::value>=0,
"Group_attribute_functor_run<i> but i-attributes are disabled" );
CGAL_assertion( adart1!=NULL && adart2!=NULL );
CGAL_assertion( adart1!=CMap::null_dart_handle &&
adart2!=CMap::null_dart_handle );
typename CMap::Helper::template Attribute_handle<i>::type
a1=adart1->template attribute<i>();
typename CMap::Helper::template Attribute_handle<i>::type
a2=adart2->template attribute<i>();
// If the two attributes are equal, nothing to do.
if ( a1 == a2 ) return;
typename CMap::Dart_handle toSet = NULL;
// If the attribute associated to adart1 is NULL, set it with
// the attribute associated to adart2 (necessarily != NULL)
if (a1 == NULL)
{ toSet = adart1; a1 = a2; }
else
{
toSet = adart2;
if (a2 != NULL)
{
Call_merge_functor<CMap, i>::run(a1, a2);
}
}
amap->template set_attribute<i>(toSet, a1);
}
};
template<typename CMap, unsigned int j, typename T>
struct Group_attribute_functor_run<CMap, 0, j, T>
{
static void run( CMap* amap,
typename CMap::Dart_handle dh1,
typename CMap::Dart_handle dh2 )
{
CGAL_static_assertion_msg
( CMap::Helper::template Dimension_index<0>::value>=0,
"Group_attribute_functor_run<0> but 0-attributes are disabled" );
CGAL_assertion( dh1!=NULL && dh2!=NULL );
CGAL_assertion( dh1!=CMap::null_dart_handle &&
dh2!=CMap::null_dart_handle );
CGAL_static_assertion(j!=0 && j!=1);
typename CMap::Helper::template Attribute_handle<0>::type
a1=NULL, a2=NULL;
typename CMap::Dart_handle toSet=NULL;
// First extremity
typename CMap::Dart_handle od=dh2->other_extremity();
if ( od!=NULL )
{
a1=dh1->template attribute<0>();
a2=od->template attribute<0>();
if ( a1!=a2 )
{
if ( a1==NULL )
{ toSet=dh1; a1=a2; }
else
{
toSet=od;
if ( a2!=NULL )
{ // TODO REMOVE ?
Call_merge_functor<CMap, 0>::run(a1, a2);
}
}
// TODO set_attribute templated by a range
amap->template set_attribute<0>(toSet, a1);
}
}
// Second extremity
od = dh1->other_extremity();
if ( od!=NULL )
{
a1=od->template attribute<0>();
a2=dh2->template attribute<0>();
if ( a1!=a2 )
{
if ( a1==NULL )
{ toSet=od; a1=a2; }
else
{
toSet=dh2;
if ( a2!=NULL )
{ // TODO REMOVE ?
Call_merge_functor<CMap, 0>::run(a1, a2);
}
}
// TODO set_attribute templated by a range
amap->template set_attribute<0>(toSet, a1);
}
}
}
};
template<typename CMap, typename T>
struct Group_attribute_functor_run<CMap, 0, 0, T>
{
static void run( CMap* amap,
typename CMap::Dart_handle dh1,
typename CMap::Dart_handle dh2 )
{
CGAL_static_assertion_msg
( CMap::Helper::template Dimension_index<0>::value>=0,
"Group_attribute_functor_run<0> but 0-attributes are disabled" );
CGAL_assertion( dh1!=NULL && dh2!=NULL );
CGAL_assertion( dh1!=CMap::null_dart_handle &&
dh2!=CMap::null_dart_handle );
typename CMap::Dart_handle od=dh2->other_extremity();
if ( od!=NULL )
{
typename CMap::Dart_handle toSet=NULL;
typename CMap::Helper::template Attribute_handle<0>::type
a1=dh1->template attribute<0>();
typename CMap::Helper::template Attribute_handle<0>::type
a2=od->template attribute<0>();
if ( a1!=a2 )
{
if ( a1==NULL )
{ toSet=dh1; a1=a2; }
else
{
toSet=od;
if ( a2!=NULL )
{ // TODO REMOVE ?
Call_merge_functor<CMap, 0>::run(a1, a2);
}
}
// TODO set_attribute templated by a range
amap->template set_attribute<0>(toSet, a1);
}
}
}
};
template<typename CMap, typename T>
struct Group_attribute_functor_run<CMap, 0, 1, T>
{
static void run( CMap* amap,
typename CMap::Dart_handle dh1,
typename CMap::Dart_handle dh2 )
{
CGAL_static_assertion_msg
( CMap::Helper::template Dimension_index<0>::value>=0,
"Group_attribute_functor_run<0> but 0-attributes are disabled" );
CGAL_assertion( dh1!=NULL && dh2!=NULL );
CGAL_assertion( dh1!=CMap::null_dart_handle &&
dh2!=CMap::null_dart_handle );
typename CMap::Dart_handle od = dh1->other_extremity();
if ( od!=NULL )
{
typename CMap::Dart_handle toSet=NULL;
typename CMap::Helper::template Attribute_handle<0>::type
a1=od->template attribute<0>();
typename CMap::Helper::template Attribute_handle<0>::type
a2=dh2->template attribute<0>();
if ( a1!=a2 )
{
if ( a1==NULL )
{ toSet=od; a1=a2; }
else
{
toSet=dh2;
if ( a2!=NULL )
{ // TODO REMOVE ?
Call_merge_functor<CMap, 0>::run(a1, a2);
}
}
// TODO set_attribute templated by a range
amap->template set_attribute<0>(toSet, a1);
}
}
}
};
template<typename CMap, unsigned int i, unsigned int j>
struct Group_attribute_functor_run<CMap, i, j, CGAL::Void>
{
static void run( CMap*,
typename CMap::Dart_handle,
typename CMap::Dart_handle )
{}
};
/// Functor used for sew to update the attributes of
/// adart2 on the attributes of this dart, except for j-attributes.
/// We define run<i> to allows to use this functor with
/// Foreach_enabled_attributes.
/// If you know i at compiling time, use directly
/// Group_attribute_functor_run.
template<typename CMap, unsigned int j=CMap::dimension+1>
struct Group_attribute_functor
{
template <unsigned int i>
static void run(CMap* amap,
typename CMap::Dart_handle adart1,
typename CMap::Dart_handle adart2)
{
Group_attribute_functor_run<CMap,i,j>::run(amap,adart1,adart2);
}
};
// Functor used to degroup the two n-attributes of the two darts, except the
// attribute of adim
template<typename CMap,unsigned int i>
struct Degroup_attribute_functor_run
{
static void run(CMap* amap,
typename CMap::Dart_handle adart1,
typename CMap::Dart_handle adart2, int adim)
{
CGAL_assertion( adim==-1 ||
(1<=adim && (unsigned int)adim<=CMap::dimension) );
if (i!=adim )
{
amap->template degroup_enabled_attribute
<i, typename CMap::Helper::template Attribute_type<i>::type>
(adart1, adart2);
}
}
};
template<typename CMap>
struct Degroup_attribute_functor_run<CMap, 0>
{
static void run(CMap* amap,
typename CMap::Dart_handle adart1,
typename CMap::Dart_handle adart2, int adim)
{
CGAL_assertion( adim==-1 ||
(1<=adim && (unsigned int)adim<=CMap::dimension) );
typename CMap::Dart_handle od = adart1->other_extremity();
if ( od!=NULL )
amap->template degroup_enabled_attribute
<0, typename CMap::Helper::template Attribute_type<0>::type >
(od, adart2);
if ( adim!=1 )
{
od = adart2->other_extremity();
if ( od!=NULL )
{
amap->template degroup_enabled_attribute
<0, typename CMap::Helper::template Attribute_type<0>::type>
(adart1, od);
}
}
}
};
template<typename Map>
struct Degroup_attribute_functor
{
template <unsigned int i>
static void run(Map* amap,typename Map::Dart_handle adart1,
typename Map::Dart_handle adart2, int adim)
{
Degroup_attribute_functor_run<Map,i>::run(amap,adart1,adart2,adim);
}
};
//////////////////////////////////// ////////////////////////////////////
@ -219,30 +613,6 @@ namespace CGAL {
int dim; int dim;
}; };
// Functor used to group one attribute of two given darts
template <typename CMap, unsigned int i, typename Type_attr>
struct Group_one_attribute_functor
{
static void run(CMap* amap,
typename CMap::Dart_handle adart1,
typename CMap::Dart_handle adart2)
{
CGAL_assertion(amap!=NULL);
amap->template group_enabled_attribute<i, Type_attr>(adart1,adart2);
}
};
// Specialization for i-attributes disabled.
template <typename CMap, unsigned int i>
struct Group_one_attribute_functor<CMap,i,CGAL::Void>
{
static void run(CMap*,
typename CMap::Dart_handle,
typename CMap::Dart_handle)
{}
};
// Functor used to degroup one attribute of two given darts // Functor used to degroup one attribute of two given darts
template <typename CMap, unsigned int i, typename Type_attr> template <typename CMap, unsigned int i, typename Type_attr>
struct Degroup_one_attribute_functor struct Degroup_one_attribute_functor
@ -375,167 +745,6 @@ namespace CGAL {
} }
}; };
// Functor used to group the two n-attributes of the two darts, except the
// attribute of adim (adim==-1 || 1<=adim<=dimension)
template<typename Map,unsigned int i>
struct Group_attribute_functor_run
{
static void run(Map* amap,
typename Map::Dart_handle adart1,
typename Map::Dart_handle adart2, int adim)
{
if ( i!=adim )
{
amap->template group_enabled_attribute
<i, typename Map::Helper::template Attribute_type<i>::type>
(adart1, adart2);
}
}
};
template<typename CMap>
struct Group_attribute_functor_run<CMap,0>
{
static void run(CMap* amap,
typename CMap::Dart_handle adart1,
typename CMap::Dart_handle adart2, int adim)
{
typename CMap::Dart_handle od = adart1->other_extremity();
if ( od!=NULL )
{
amap->template group_enabled_attribute
<0, typename CMap::Helper::template Attribute_type<0>::type>
(od, adart2);
}
if ( adim!=1 )
{
od = adart2->other_extremity();
if ( od!=NULL )
amap->template group_enabled_attribute
<0, typename CMap::Helper::template Attribute_type<0>::type>
(adart1, od);
}
}
};
template<typename Map>
struct Group_attribute_functor
{
template <unsigned int i>
static void run(Map* amap,
typename Map::Dart_handle adart1,
typename Map::Dart_handle adart2, int adim)
{
CGAL_assertion( adim==-1 ||
(1<=adim && (unsigned int)adim<=Map::dimension) );
Group_attribute_functor_run<Map,i>::run(amap,adart1,adart2,adim);
}
};
// Functor used to degroup the two n-attributes of the two darts, except the
// attribute of adim
template<typename CMap,unsigned int i>
struct Degroup_attribute_functor_run
{
static void run(CMap* amap,
typename CMap::Dart_handle adart1,
typename CMap::Dart_handle adart2, int adim)
{
CGAL_assertion( adim==-1 ||
(1<=adim && (unsigned int)adim<=CMap::dimension) );
if (i!=adim )
{
amap->template degroup_enabled_attribute
<i, typename CMap::Helper::template Attribute_type<i>::type>
(adart1, adart2);
}
}
};
template<typename CMap>
struct Degroup_attribute_functor_run<CMap, 0>
{
static void run(CMap* amap,
typename CMap::Dart_handle adart1,
typename CMap::Dart_handle adart2, int adim)
{
CGAL_assertion( adim==-1 ||
(1<=adim && (unsigned int)adim<=CMap::dimension) );
typename CMap::Dart_handle od = adart1->other_extremity();
if ( od!=NULL )
amap->template degroup_enabled_attribute
<0, typename CMap::Helper::template Attribute_type<0>::type >
(od, adart2);
if ( adim!=1 )
{
od = adart2->other_extremity();
if ( od!=NULL )
{
amap->template degroup_enabled_attribute
<0, typename CMap::Helper::template Attribute_type<0>::type>
(adart1, od);
}
}
}
};
template<typename Map>
struct Degroup_attribute_functor
{
template <unsigned int i>
static void run(Map* amap,typename Map::Dart_handle adart1,
typename Map::Dart_handle adart2, int adim)
{
Degroup_attribute_functor_run<Map,i>::run(amap,adart1,adart2,adim);
}
};
// Functor which call operator() on the cell_attribute...
template<typename Cell_attribute, typename Functor>
struct Apply_cell_functor
{
static void run(Cell_attribute& acell1, Cell_attribute& acell2)
{
Functor() (acell1,acell2);
}
};
//...except for Null_functor.
template<typename Cell_attribute>
struct Apply_cell_functor<Cell_attribute,Null_functor>
{
static void run(Cell_attribute&, Cell_attribute&)
{}
};
// Functor used to call the On_split functor between the two given darts.
template<typename Map,unsigned int i,
typename Enabled=
typename Map::Helper::
#ifndef CGAL_CFG_TEMPLATE_IN_DEFAULT_PARAMETER_BUG
template
#endif
Attribute_type<i>::type>
struct Call_split_functor
{
static void run(typename Map::Dart_handle adart1,
typename Map::Dart_handle adart2)
{
Apply_cell_functor
<typename Map::Helper::template Attribute_type<i>::type,
typename Map::Helper::template Attribute_type<i>::type::On_split>::
run(*(adart1->template attribute<i>()),
*(adart2->template attribute<i>()));
}
};
// Specialization for disabled attributes.
template<typename Map,unsigned int i>
struct Call_split_functor<Map,i,CGAL::Void>
{
static void run(typename Map::Dart_handle,
typename Map::Dart_handle)
{}
};
/// Functor for counting the memory occupation of attributes /// Functor for counting the memory occupation of attributes
/// Be careful not reentrant !!! TODO a Foreach_enabled_attributes /// Be careful not reentrant !!! TODO a Foreach_enabled_attributes