wip split...

This commit is contained in:
Guillaume Damiand 2013-01-29 16:30:43 +01:00
parent bde3be7571
commit 29039d2fde
4 changed files with 186 additions and 61 deletions

View File

@ -175,6 +175,8 @@ namespace CGAL {
internal::Call_split_functor<Map, 2>::run(c.d1, c.d2); internal::Call_split_functor<Map, 2>::run(c.d1, c.d2);
} }
CGAL_expensive_postcondition( amap.is_valid() );
return n1; return n1;
} }
@ -221,11 +223,13 @@ namespace CGAL {
typename Map::Dart_handle d1, d2; typename Map::Dart_handle d1, d2;
int mark = amap.get_new_mark(); int mark = amap.get_new_mark();
int mark_modified_darts = amap.get_new_mark();
std::deque<typename Map::Dart_handle> to_erase; std::deque<typename Map::Dart_handle> to_erase;
typename Map::Dart_handle dg1=NULL, dg2=NULL;
const int iinv = CGAL_BETAINV(i); const int iinv = CGAL_BETAINV(i);
/* int mark_for_incident_cells[Map::Helper::nb_attribs]; /*int mark_for_incident_cells[Map::Helper::nb_attribs];
std::deque<std::deque<typename Map::Dart_handle> > std::deque<std::deque<typename Map::Dart_handle> >
incident_cells[Map::Helper::nb_attribs]; incident_cells[Map::Helper::nb_attribs];
@ -242,17 +246,17 @@ namespace CGAL {
it.cont(); ++it ) it.cont(); ++it )
{ {
to_erase.push_back(it); to_erase.push_back(it);
if ( !it->is_free(i+1) && dg1==NULL )
{ dg1=it; dg2=it->beta(i+1); }
amap.mark(it, mark); amap.mark(it, mark);
++res; ++res;
} }
typename Map::Dart_handle dg1=NULL, dg2=NULL;
// Second we store all the incident cells that can be split by // Second we store all the incident cells that can be split by
// the operation. // the operation.
typename std::deque<typename Map::Dart_handle>::iterator it = typename std::deque<typename Map::Dart_handle>::iterator it =
to_erase.begin(); to_erase.begin();
/* for (; it != to_erase.end(); ++it) /*for (; it != to_erase.end(); ++it)
{ {
d1 = (*it)->beta(iinv); d1 = (*it)->beta(iinv);
while ( d1!=Map::null_dart_handle && amap.is_marked(d1, mark) ) while ( d1!=Map::null_dart_handle && amap.is_marked(d1, mark) )
@ -320,10 +324,14 @@ namespace CGAL {
amap.update_dart_of_all_attributes(*it, mark); amap.update_dart_of_all_attributes(*it, mark);
}*/ }*/
//for (; it != to_erase.end(); ++it)
// amap.update_dart_of_all_attributes(*it, mark);
// We group the two (i+1)-cells incident if they exist. // We group the two (i+1)-cells incident if they exist.
// TODO GROUP BEFORE TO MODIFY if ( dg1!=NULL )
/* if ( dg1!=NULL ) amap.template group_attribute<i+1>(dg1, dg2);
amap.template group_attribute<i+1>(dg1, dg2);*/
//amap.update_dart_of_all_attributes(adart, mark);
std::deque<typename Map::Dart_handle> modified_darts; std::deque<typename Map::Dart_handle> modified_darts;
@ -337,47 +345,66 @@ namespace CGAL {
if (d1 == (*it)->beta(iinv)) d1 = Map::null_dart_handle; if (d1 == (*it)->beta(iinv)) d1 = Map::null_dart_handle;
} }
d2 = (*it)->beta(i+1)->beta(i); if ( !amap.is_marked(d1, mark_modified_darts) )
while ( d2!=Map::null_dart_handle && amap.is_marked(d2, mark) )
{ {
d2 = d2->beta(i+1)->beta(i); d2 = (*it)->beta(i+1)->beta(i);
if ( d2==(*it)->beta(i+1)->beta(i) ) d2=Map::null_dart_handle; while ( d2!=Map::null_dart_handle && amap.is_marked(d2, mark) )
} {
d2 = d2->beta(i+1)->beta(i);
if ( d2==(*it)->beta(i+1)->beta(i) ) d2=Map::null_dart_handle;
}
// TODO ? We can optimize by using map.basic_link_beta but we if ( !amap.is_marked(d2, mark_modified_darts) )
// need to mark the second dart to not process another time...
if (d1 != Map::null_dart_handle)
{
if (d2 != Map::null_dart_handle)
{ {
d1->basic_link_beta(d2, i); if (d1 != Map::null_dart_handle)
if ( i==1 ) d2->basic_link_beta(d1, 0);
modified_darts.push_back(d1);
}
else
{
if ( !d1->is_free(i) )
{ {
d1->unlink_beta(i); if (d2 != Map::null_dart_handle)
modified_darts.push_back(d1); {
//d1->basic_link_beta(d2, i);
amap.template basic_link_beta<i>(d1, d2);
amap.mark(d1, mark_modified_darts);
amap.mark(d2, mark_modified_darts);
modified_darts.push_back(d1);
modified_darts.push_back(d2);
/*if ( i==1 )
{
d2->basic_link_beta(d1, 0);
// modified_darts2.push_back(d2);
}*/
// modified_darts2.push_back(d1);
}
else
{
if ( !d1->is_free(i) )
{
d1->unlink_beta(i);
CGAL_assertion( !amap.is_marked(d1, mark_modified_darts) );
amap.mark(d1, mark_modified_darts);
modified_darts.push_back(d1);
}
}
}
else if (d2 != Map::null_dart_handle)
{
if ( !d2->is_free(iinv) )
{
d2->unlink_beta(iinv);
CGAL_assertion( !amap.is_marked(d2, mark_modified_darts) );
amap.mark(d2, mark_modified_darts);
modified_darts.push_back(d2);
}
}
if ((*it)->is_free(i+1) && !(*it)->is_free(i))
{
d1 = (*it)->beta(i);
if ( !d1->is_free(iinv) )
{
d1->unlink_beta(iinv);
CGAL_assertion( !amap.is_marked(d1, mark_modified_darts) );
amap.mark(d1, mark_modified_darts);
modified_darts.push_back(d1);
}
} }
}
}
else if (d2 != Map::null_dart_handle)
{
if ( !d2->is_free(iinv) )
{
d2->unlink_beta(iinv);
modified_darts.push_back(d2);
}
}
if ((*it)->is_free(i+1) && !(*it)->is_free(i))
{
d1 = (*it)->beta(i);
if ( !d1->is_free(iinv) )
{
d1->unlink_beta(iinv);
modified_darts.push_back(d1);
} }
} }
} }
@ -385,10 +412,10 @@ namespace CGAL {
// We test the split of all the incident cells for all the non // We test the split of all the incident cells for all the non
// void attributes. // void attributes.
Map::Helper::template Foreach_enabled_attributes Map::Helper::template Foreach_enabled_attributes
<internal::Test2_split_with_deque<Map,i> >:: <internal::Test2_split_with_deque<Map,i, i> >::
run(&amap, &modified_darts); // <internal::Test_split_with_deque<Map,i> >::
//&mark_for_incident_cells[0], run(&amap, &modified_darts, mark_modified_darts);
//&incident_cells[0]); //&mark_for_incident_cells[0], &incident_cells[0]);
// We remove all the darts of the i-cell. // We remove all the darts of the i-cell.
for ( it=to_erase.begin(); it!=to_erase.end(); ++it ) for ( it=to_erase.begin(); it!=to_erase.end(); ++it )
@ -397,15 +424,27 @@ namespace CGAL {
CGAL_assertion( amap.is_whole_map_unmarked(mark) ); CGAL_assertion( amap.is_whole_map_unmarked(mark) );
amap.free_mark(mark); amap.free_mark(mark);
if ( !amap.is_whole_map_unmarked(mark_modified_darts) )
{
for ( typename std::deque<typename Map::Dart_handle>::
iterator it=modified_darts.begin();
it!=modified_darts.end(); ++it )
amap.unmark(*it, mark_modified_darts);
}
CGAL_assertion ( amap.is_whole_map_unmarked(mark_modified_darts) );
amap.free_mark(mark_modified_darts);
// We free the marks. // We free the marks.
/* for (int j=0; j<Map::Helper::nb_attribs; ++j) /*for (int j=0; j<Map::Helper::nb_attribs; ++j)
{ {
CGAL_assertion( amap.is_whole_map_marked CGAL_assertion( amap.is_whole_map_marked
(mark_for_incident_cells[j]) ); (mark_for_incident_cells[j]) );
amap.free_mark( mark_for_incident_cells[j] ); amap.free_mark( mark_for_incident_cells[j] );
} }*/
*/
CGAL_expensive_postcondition( amap.is_valid() ); CGAL_expensive_postcondition( amap.is_valid() );
assert( amap.is_valid() );
return res; return res;
} }
@ -806,7 +845,7 @@ namespace CGAL {
CGAL_assertion( amap.is_whole_map_unmarked(mark) ); CGAL_assertion( amap.is_whole_map_unmarked(mark) );
amap.free_mark(mark); amap.free_mark(mark);
// CGAL_postcondition( amap.is_valid() ); CGAL_expensive_postcondition( amap.is_valid() );
return res; return res;
} }
@ -922,6 +961,8 @@ namespace CGAL {
amap.template degroup_attribute<1>(adart, adart->beta(1)); amap.template degroup_attribute<1>(adart, adart->beta(1));
// CGAL_expensive_postcondition( amap.is_valid() );
return adart->beta(1); return adart->beta(1);
} }
@ -1014,7 +1055,8 @@ namespace CGAL {
CGAL_assertion( amap.is_whole_map_unmarked(mark1) ); CGAL_assertion( amap.is_whole_map_unmarked(mark1) );
amap.free_mark(mark1); amap.free_mark(mark1);
// CGAL_postcondition(amap.is_valid()); // CGAL_expensive_postcondition( amap.is_valid() );
return adart1->beta(0); return adart1->beta(0);
} }
@ -1135,7 +1177,8 @@ namespace CGAL {
CGAL_assertion( amap.is_whole_map_unmarked(mark1) ); CGAL_assertion( amap.is_whole_map_unmarked(mark1) );
amap.free_mark(mark1); amap.free_mark(mark1);
// CGAL_postcondition(amap.is_valid()); // CGAL_expensive_postcondition( amap.is_valid() );
return adart1->beta(0); return adart1->beta(0);
} }
@ -1249,7 +1292,8 @@ namespace CGAL {
if ( withBeta3 ) if ( withBeta3 )
amap.template degroup_attribute<3>( first, first->beta(3) ); amap.template degroup_attribute<3>( first, first->beta(3) );
// CGAL_postcondition(amap.is_valid()); // CGAL_expensive_postcondition( amap.is_valid() );
return first; return first;
} }
} // namespace CGAL } // namespace CGAL

View File

@ -575,6 +575,7 @@ namespace CGAL {
typename Map::Helper::template Attribute_handle<j>::type typename Map::Helper::template Attribute_handle<j>::type
a2=NULL; a2=NULL;
int nb=0;
for ( typename std::deque<std::deque<typename Map::Dart_handle> >:: for ( typename std::deque<std::deque<typename Map::Dart_handle> >::
iterator it=jcells.begin(); it!=jcells.end(); ++it ) iterator it=jcells.begin(); it!=jcells.end(); ++it )
{ {
@ -605,7 +606,7 @@ namespace CGAL {
// std::cout<<&*itj2<<", "; // std::cout<<&*itj2<<", ";
if ( nbofjcell>1 ) if ( nbofjcell>1 )
amap->template set_attribute_of_dart<j>(itj2, a2); amap->template set_attribute_of_dart<j>(itj2, a2);
++nb;
amap->mark(itj2, mark_for_jcells); amap->mark(itj2, mark_for_jcells);
} }
// std::cout<<std::endl; // std::cout<<std::endl;
@ -618,22 +619,25 @@ namespace CGAL {
} }
} }
} }
//std::cout<<"number of marked darts for <"<<j<<"> : "<<amap->number_of_marked_darts(mark_for_jcells)<<std::endl;
//std::cout<<"number of iterated darts : "<<nb<<std::endl;
} }
}; };
template<typename Map, unsigned int i> template<typename Map, unsigned int i, unsigned int k>
struct Test2_split_with_deque struct Test2_split_with_deque
{ {
template <unsigned int j> template <unsigned int j>
static void run( Map* amap, static void run( Map* amap,
std::deque<typename Map::Dart_handle> std::deque<typename Map::Dart_handle>
*modified_darts ) *modified_darts,
int mark_modified_darts )
{ {
if ( i==j ) return; if ( i==j || j==k ) return;
CGAL_assertion( amap!=NULL ); CGAL_assertion( amap!=NULL );
int nbofjcell = 0;
typename Map::Helper::template Attribute_handle<j>::type typename Map::Helper::template Attribute_handle<j>::type
a1 = NULL; a1 = NULL;
typename Map::Helper::template Attribute_handle<j>::type typename Map::Helper::template Attribute_handle<j>::type
@ -643,7 +647,7 @@ namespace CGAL {
Attribute_handle<j>::type> found_attributes; Attribute_handle<j>::type> found_attributes;
int mark = amap->get_new_mark(); int mark = amap->get_new_mark();
int nb=0;
for ( typename std::deque<typename Map::Dart_handle>:: for ( typename std::deque<typename Map::Dart_handle>::
iterator it=modified_darts->begin(); iterator it=modified_darts->begin();
it!=modified_darts->end(); ++it ) it!=modified_darts->end(); ++it )
@ -662,6 +666,7 @@ namespace CGAL {
itj(*amap, *it, mark); itj(*amap, *it, mark);
itj.cont(); ++itj ) itj.cont(); ++itj )
{ {
++nb;
// std::cout<<&*itj<<", "; // std::cout<<&*itj<<", ";
amap->template set_attribute_of_dart<j>(itj, a2); amap->template set_attribute_of_dart<j>(itj, a2);
amap->mark(itj, mark); amap->mark(itj, mark);
@ -681,6 +686,7 @@ namespace CGAL {
itj(*amap, *it, mark); itj(*amap, *it, mark);
itj.cont(); ++itj ) itj.cont(); ++itj )
{ {
++nb;
// std::cout<<&*itj<<", "; // std::cout<<&*itj<<", ";
CGAL_assertion( itj->template attribute<j>()==a1 ); CGAL_assertion( itj->template attribute<j>()==a1 );
amap->mark(itj, mark); amap->mark(itj, mark);
@ -688,8 +694,64 @@ namespace CGAL {
} }
// std::cout<<std::endl; // std::cout<<std::endl;
} }
if ( i!=1 && j==0 )
{
typename Map::Dart_handle od = (*it)->other_extremity();
if ( od!=NULL && od->template attribute<j>()!=NULL &&
!amap->is_marked(od, mark) )
{
a1 = od->template attribute<j>();
if ( found_attributes.insert(a1).second )
{ // Here the attribute was not in the set as we are able
// to insert it.
a2 = amap->template create_attribute<j>(*a1);
// std::cout<<"A2 "<<&*a2<<" "<<&**itj<<": ";
for ( CMap_dart_iterator_basic_of_cell<Map,j>
itj(*amap, od, mark);
itj.cont(); ++itj )
{
++nb;
// std::cout<<&*itj<<", ";
amap->template set_attribute_of_dart<j>(itj, a2);
amap->mark(itj, mark);
}
Apply_cell_functor
<typename Map::Helper::template Attribute_type<j>::type,
typename Map::Helper::template Attribute_type<j>::type::
On_split>::run(*a1, *a2);
}
else
{ // Here the attribute was already present in the set
a1->set_dart(od);
// std::cout<<"A1 "<<&*a1<<" "<<&**itj<<": ";
for ( CMap_dart_iterator_basic_of_cell<Map,j>
itj(*amap, od, mark);
itj.cont(); ++itj )
{
++nb;
// std::cout<<&*itj<<", ";
CGAL_assertion( itj->template attribute<j>()==a1 );
amap->mark(itj, mark);
}
}
// std::cout<<std::endl;
}
}
} }
/* std::cout<<"Size of set for dim "<<j<<": "<<found_attributes.size()<<std::endl;
std::cout<<"Size of deque for dim "<<j<<": "<<modified_darts->size()<<std::endl;
std::cout<<"number of marked darts : "<<amap->number_of_marked_darts(mark)<<std::endl;
std::cout<<"number of iterated darts : "<<nb<<std::endl;
*/
// Now we unmark all the marked darts. // Now we unmark all the marked darts.
amap->negate_mark(mark); amap->negate_mark(mark);
@ -697,6 +759,8 @@ namespace CGAL {
iterator it=modified_darts->begin(); iterator it=modified_darts->begin();
it!=modified_darts->end(); ++it ) it!=modified_darts->end(); ++it )
{ {
amap->unmark(*it, mark_modified_darts);
if ( !amap->is_marked(*it, mark) ) if ( !amap->is_marked(*it, mark) )
for ( CMap_dart_iterator_basic_of_cell<Map,j> for ( CMap_dart_iterator_basic_of_cell<Map,j>
itj(*amap, *it, mark); itj(*amap, *it, mark);
@ -704,6 +768,18 @@ namespace CGAL {
{ {
amap->mark(itj, mark); amap->mark(itj, mark);
} }
if ( i!=1 && j==0 )
{
typename Map::Dart_handle od = (*it)->other_extremity();
if ( od!=NULL && !amap->is_marked(od, mark) )
for ( CMap_dart_iterator_basic_of_cell<Map,j>
itj(*amap, od, mark);
itj.cont(); ++itj )
{
amap->mark(itj, mark);
}
}
} }
CGAL_assertion( amap->is_whole_map_marked(mark) ); CGAL_assertion( amap->is_whole_map_marked(mark) );

View File

@ -13,6 +13,11 @@ endif()
# add_definitions("-DCGAL_CHECK_EXPENSIVE") # add_definitions("-DCGAL_CHECK_EXPENSIVE")
# For profilling with gprof
add_definitions("-pg")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
##################
find_package(CGAL COMPONENTS Qt4) find_package(CGAL COMPONENTS Qt4)
include(${CGAL_USE_FILE}) include(${CGAL_USE_FILE})

View File

@ -281,9 +281,9 @@ subdivide_lcc_pqq (LCC & m)
{ {
CGAL_assertion( (CGAL::is_removable<LCC, 1>(m,*dit)) ); CGAL_assertion( (CGAL::is_removable<LCC, 1>(m,*dit)) );
CGAL::remove_cell<LCC, 1>(m, *dit); CGAL::remove_cell<LCC, 1>(m, *dit);
CGAL_assertion( m.is_valid() );
} }
remove.resize(0); remove.resize(0);
CGAL_assertion( m.is_valid() );
} }
} }