* Re-add set_attribute method in CMap class (was removed by error).

* Make functors Is_removable_functor and Is_contractible_functor to avoid a warning.
This commit is contained in:
Guillaume Damiand 2013-02-14 17:21:36 +01:00
parent 450a07786b
commit 481908df1f
4 changed files with 119 additions and 66 deletions

View File

@ -48,35 +48,35 @@ int main()
// 1) Create all 2-attributes and associated them to darts.
for (CMap_3::Dart_range::iterator
it=cm.darts().begin(), itend=cm.darts().end();
it!=itend; ++it)
{
if ( it->attribute<2>()==NULL )
cm.set_attribute<2>(it, cm.create_attribute<2>());
}
it=cm.darts().begin(), itend=cm.darts().end();
it!=itend; ++it)
{
if ( it->attribute<2>()==NULL )
cm.set_attribute<2>(it, cm.create_attribute<2>());
}
// 2) Set the color of all facets of the first hexahedron to 7.
for (CMap_3::One_dart_per_incident_cell_range<2, 3>::iterator
it=cm.one_dart_per_incident_cell<2,3>(dh1).begin(),
itend=cm.one_dart_per_incident_cell<2,3>(dh1).end(); it!=itend; ++it)
{ it->attribute<2>()->info()=7; }
it=cm.one_dart_per_incident_cell<2,3>(dh1).begin(),
itend=cm.one_dart_per_incident_cell<2,3>(dh1).end(); it!=itend; ++it)
{ it->attribute<2>()->info()=7; }
// 3) Set the color of all facets of the second hexahedron to 13.
for (CMap_3::One_dart_per_incident_cell_range<2, 3>::iterator it=
cm.one_dart_per_incident_cell<2,3>(dh2).begin(),
itend=cm.one_dart_per_incident_cell<2,3>(dh2).end(); it!=itend; ++it)
{ it->attribute<2>()->info()=13; }
cm.one_dart_per_incident_cell<2,3>(dh2).begin(),
itend=cm.one_dart_per_incident_cell<2,3>(dh2).end(); it!=itend; ++it)
{ it->attribute<2>()->info()=13; }
// 4) 3-Sew the two hexahedra along one facet.
cm.sew<3>(dh1, dh2);
// 5) Display all the values of 2-attributes.
for (CMap_3::Attribute_range<2>::type::iterator
it=cm.attributes<2>().begin(), itend=cm.attributes<2>().end();
it=cm.attributes<2>().begin(), itend=cm.attributes<2>().end();
it!=itend; ++it)
{
std::cout<<it->info()<<"; ";
}
{
std::cout<<it->info()<<"; ";
}
std::cout<<std::endl;
// 6) Insert a vertex in the facet between the two hexahedra.
@ -84,11 +84,11 @@ int main()
// 7) Display all the values of 2-attributes.
for (CMap_3::Attribute_range<2>::type::iterator
it=cm.attributes<2>().begin(), itend=cm.attributes<2>().end();
it=cm.attributes<2>().begin(), itend=cm.attributes<2>().end();
it!=itend; ++it)
{
std::cout<<it->info()<<"; ";
}
{
std::cout<<it->info()<<"; ";
}
std::cout<<std::endl;
cm.display_characteristics(std::cout);
std::cout<<", valid="<<cm.is_valid()<<std::endl;

View File

@ -985,6 +985,20 @@ namespace CGAL {
(mattribute_containers).size();
}
/** 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");
Set_i_attribute_functor<Self,i>::run(this, adart, ah);
}
/// @return a Attributes_range<i> (range through all the
/// attributes<i> of the map).
template<unsigned int i>

View File

@ -126,10 +126,6 @@ insert_cell_0_in_cell_2( CMap& amap, typename CMap::Dart_handle adart,
while ( !first->template is_free<0>() && first->template beta<0>()!=adart )
first = first->template beta<0>();
// Stack of couple of dart and dimension for which
// we must call on_split functor
std::deque<typename CMap::Dart_handle> modified_darts;
// Mark used to mark darts already treated.
int treated = amap.get_new_mark();
@ -203,7 +199,6 @@ insert_cell_0_in_cell_2( CMap& amap, typename CMap::Dart_handle adart,
(nn1, prev->beta(dim));
amap.mark(cur->beta(dim), treated);
tounmark.push_back(cur->beta(dim));
}
else
{
@ -240,7 +235,11 @@ insert_cell_0_in_cell_2( CMap& amap, typename CMap::Dart_handle adart,
itd=tounmark.begin(); itd!=tounmark.end(); ++itd )
{
amap.unmark(*itd, treated);
for (unsigned int dim=3; dim<=CMap::dimension; ++dim)
{
if ( !(*itd)->is_free(dim) )
amap.unmark((*itd)->beta(dim), treated);
}
if ( *itd!=adart )
CGAL::internal::Degroup_attribute_functor_run<CMap, 2>::
run(&amap, adart, *itd);
@ -300,9 +299,9 @@ insert_dangling_cell_1_in_cell_2( CMap& amap,
if ( !it1->is_free(s1) )
{
if ( s1==0 )
amap.template link_beta_1(it1->template beta<0>(), d2);
amap.link_beta_1(it1->template beta<0>(), d2);
else
amap.template link_beta_0(it1->template beta<1>(), d2);
amap.link_beta_0(it1->template beta<1>(), d2);
}
if (s1==0)

View File

@ -31,6 +31,43 @@ namespace CGAL
* Some operations to modify a combinatorial map.
*/
/** Test if an i-cell can be removed.
* An i-cell can be removed if i==CMap::dimension or i==CMap::dimension-1,
* or if there are at most two (i+1)-cell incident to it.
* @param adart a dart of the i-cell.
* @return true iff the i-cell can be removed.
*/
template <class CMap, unsigned int i, unsigned int nmi=CMap::dimension-i>
struct Is_removable_functor
{
static bool run(const CMap& amap, typename CMap::Dart_const_handle adart)
{
// TODO? Optimisation for dim-2, and to not test all the darts of the cell?
bool res = true;
for ( CGAL::CMap_dart_const_iterator_of_cell<CMap,i> it(amap, adart);
res && it.cont(); ++it )
{
if (it->template beta<i+2>()->template beta<i+1>()!=
it->template beta_inv<i+1>()->template beta<i+2>() )
res = false;
}
return res;
}
};
// Specialization for i=CMap::dimension
template <class CMap, unsigned int i>
struct Is_removable_functor<CMap, i, 0>
{
static bool run(const CMap&, typename CMap::Dart_const_handle)
{ return true; }
};
// Specialization for i=CMap::dimension-1
template <class CMap, unsigned int i>
struct Is_removable_functor<CMap, i, 1>
{
static bool run(const CMap&, typename CMap::Dart_const_handle)
{ return true; }
};
/** Test if an i-cell can be removed.
* An i-cell can be removed if i==CMap::dimension or i==CMap::dimension-1,
* or if there are at most two (i+1)-cell incident to it.
@ -39,24 +76,7 @@ namespace CGAL
*/
template < class CMap, unsigned int i >
bool is_removable(const CMap& amap, typename CMap::Dart_const_handle adart)
{
CGAL_assertion( adart!=NULL );
CGAL_static_assertion( 0<=i && i<=CMap::dimension );
if ( i==CMap::dimension ) return true;
if ( i==CMap::dimension-1 ) return true;
// TODO? Optimisation for dim-2, and to not test all the darts of the cell?
bool res = true;
for ( CGAL::CMap_dart_const_iterator_of_cell<CMap,i> it(amap, adart);
res && it.cont(); ++it )
{
if (it->template beta<i+2>()->template beta<i+1>()!=
it->template beta_inv<i+1>()->template beta<i+2>() )
res = false;
}
return res;
}
{ return CGAL::Is_removable_functor<CMap, i>::run(amap,adart); }
/** Remove an i-cell, 0<i<dimension, and merge eventually both incident
* (i+1)-cells.
@ -425,6 +445,43 @@ namespace CGAL
CGAL::Remove_cell_functor<CMap,i,CMap::dimension-i>::run(amap,adart);
}
/** Test if an i-cell can be contracted.
* An i-cell can be contracted if i==1
* or if there are at most two (i-1)-cell incident to it.
* @param adart a dart of the i-cell.
* @return true iff the i-cell can be contracted.
*/
template <class CMap, unsigned int i>
struct Is_contractible_functor
{
static bool run(const CMap& amap, typename CMap::Dart_const_handle adart)
{
// TODO ? Optimisation possible to not test all the darts of the cell ?
bool res = true;
for ( CGAL::CMap_dart_const_iterator_of_cell<CMap,i> it(amap, adart);
res && it.cont(); ++it )
{
if ( it->template beta<i-2>()->template beta<i-1>()!=
it->template beta<i-1>()->template beta_inv<i-2>() )
res = false;
}
return res;
}
};
// Specialization for i=0
template <class CMap>
struct Is_contractible_functor<CMap, 0>
{
static bool run(const CMap&, typename CMap::Dart_const_handle)
{ return false; }
};
// Specialization for i=1
template <class CMap>
struct Is_contractible_functor<CMap, 1>
{
static bool run(const CMap&, typename CMap::Dart_const_handle)
{ return true; }
};
/** Test if an i-cell can be contracted.
* An i-cell can be contracted if i==1
* or if there are at most two (i-1)-cell incident to it.
@ -433,24 +490,7 @@ namespace CGAL
*/
template < class CMap, unsigned int i >
bool is_contractible(const CMap& amap, typename CMap::Dart_const_handle adart)
{
CGAL_assertion(adart != NULL);
CGAL_static_assertion(0<=i && i<=CMap::dimension);
if ( i==0 ) return false;
if ( i==1 ) return true;
// TODO ? Optimisation possible to not test all the darts of the cell ?
bool res = true;
for ( CGAL::CMap_dart_const_iterator_of_cell<CMap,i> it(amap, adart);
res && it.cont(); ++it )
{
if ( it->template beta<i-2>()->template beta<i-1>()!=
it->template beta<i-1>()->template beta_inv<i-2>() )
res = false;
}
return res;
}
{ return CGAL::Is_contractible_functor<CMap, i>::run(amap,adart); }
/** Contract an i-cell, 1<i<=dimension, and merge eventually both incident
* (i-1)-cells.