From 7f6cf79490d13fafe0ef6263797e127393193071 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 28 Jan 2013 22:13:56 +0100 Subject: [PATCH] Onsplit again... --- .../CGAL/Combinatorial_map_operations.h | 111 ++++++++---------- .../internal/Combinatorial_map_functors.h | 11 +- .../demo/Linear_cell_complex/CMakeLists.txt | 4 +- .../demo/Linear_cell_complex/MainWindow.cpp | 108 ++++++++--------- 4 files changed, 111 insertions(+), 123 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h index b4e60f7a412..084e53bbcae 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h @@ -233,7 +233,7 @@ namespace CGAL { for (int j=0; jbeta_inv(i); + d1 = (*it)->beta(iinv); while ( d1!=Map::null_dart_handle && amap.is_marked(d1, mark) ) { - d1 = d1->beta(i+1)->beta_inv(i); - if (d1 == (*it)->beta_inv(i)) d1 = Map::null_dart_handle; + d1 = d1->beta(i+1)->beta(iinv); + if (d1 == (*it)->beta(iinv)) d1 = Map::null_dart_handle; } d2 = (*it)->beta(i+1)->beta(i); @@ -273,6 +273,14 @@ namespace CGAL { if (d2 != Map::null_dart_handle) { if ( dg1==NULL ) { dg1 = d1; dg2=d2; } + Map::Helper::template Foreach_enabled_attributes + >:: + run(&amap, d1, mark, &mark_for_incident_cells[0], + &incident_cells[0]); + Map::Helper::template Foreach_enabled_attributes + >:: + run(&amap, d2, mark, &mark_for_incident_cells[0], + &incident_cells[0]); } else { @@ -280,7 +288,7 @@ namespace CGAL { { Map::Helper::template Foreach_enabled_attributes >:: - run(&amap, d1, mark, &mark_for_incident_cells[0], + run(&amap, d1->beta(i), mark, &mark_for_incident_cells[0], &incident_cells[0]); } } @@ -319,11 +327,11 @@ namespace CGAL { // For each dart of the i-cell, we modify i-links of neighbors. for ( it=to_erase.begin(); it != to_erase.end(); ++it) { - d1 = (*it)->beta_inv(i); + d1 = (*it)->beta(iinv); while ( d1!=Map::null_dart_handle && amap.is_marked(d1, mark) ) { - d1 = d1->beta(i+1)->beta_inv(i); - if (d1 == (*it)->beta_inv(i)) d1 = Map::null_dart_handle; + d1 = d1->beta(i+1)->beta(iinv); + if (d1 == (*it)->beta(iinv)) d1 = Map::null_dart_handle; } d2 = (*it)->beta(i+1)->beta(i); @@ -349,17 +357,17 @@ namespace CGAL { } else if (d2 != Map::null_dart_handle) { - if ( !d2->is_free(CGAL_BETAINV(i)) ) + if ( !d2->is_free(iinv) ) { - d2->unlink_beta(CGAL_BETAINV(i)); + d2->unlink_beta(iinv); } } if ((*it)->is_free(i+1) && !(*it)->is_free(i)) { d1 = (*it)->beta(i); - if ( !d1->is_free(CGAL_BETAINV(i)) ) + if ( !d1->is_free(iinv) ) { - d1->unlink_beta(CGAL_BETAINV(i)); + d1->unlink_beta(iinv); } } } @@ -386,7 +394,6 @@ namespace CGAL { amap.free_mark( mark_for_incident_cells[j] ); } - assert(amap.is_valid()); CGAL_expensive_postcondition( amap.is_valid() ); return res; @@ -409,11 +416,6 @@ namespace CGAL { int mark = amap.get_new_mark(); size_t res = 0; - // Stack of couple of dart for which we must call degroup_all_attributes - typedef std::pair - Dart_pair; - std::deque todegroup; - int mark_for_incident_cells[Map::Helper::nb_attribs]; std::deque > incident_cells[Map::Helper::nb_attribs]; @@ -421,19 +423,17 @@ namespace CGAL { // Marks used to mark all the incident cells. for (int j=0; j + it(amap,adart,mark); it.cont(); ++it) { - for (CMap_dart_iterator_basic_of_cell - it(amap,adart,mark); it.cont(); ++it) - { - to_erase.push_back(it); - amap.mark(it,mark); - ++res; - } + to_erase.push_back(it); + amap.mark(it,mark); + ++res; } typename std::deque::iterator @@ -462,20 +462,20 @@ namespace CGAL { } } - // 4) We remove all the darts of the d-cell. - for ( it = to_erase.begin(); it != to_erase.end(); ++it ) - { amap.erase_dart(*it); } - - CGAL_assertion( amap.is_whole_map_unmarked(mark) ); - amap.free_mark(mark); - - // 5) We test the split of all the incident cells for all the non + // 4) We test the split of all the incident cells for all the non // void attributes. Map::Helper::template Foreach_enabled_attributes >:: run(&amap, &mark_for_incident_cells[0], &incident_cells[0]); + // 5) We remove all the darts of the d-cell. + for ( it = to_erase.begin(); it != to_erase.end(); ++it ) + { amap.erase_dart(*it); } + + CGAL_assertion( amap.is_whole_map_unmarked(mark) ); + amap.free_mark(mark); + // We free the marks. for (int j=0; jis_free(0) ) { if ( !(*it)->is_free(1) && (*it)->beta(0)!=(*it) ) - amap.template basic_link_beta<1>((*it)->beta(0), (*it)->beta(1)); + { + if ( dg1==NULL ) { dg1=(*it)->beta(0); dg2=(*it)->beta(1); } + Map::Helper::template Foreach_enabled_attributes + >:: + run(&amap, *it, mark, &mark_for_incident_cells[0], + &incident_cells[0]); + } else { Map::Helper::template Foreach_enabled_attributes >:: run(&amap, *it, mark, &mark_for_incident_cells[0], &incident_cells[0]); - // todegroup.push(Dart_pair((*it)->beta(0), *it)); - // (*it)->beta(0)->unlink_beta(1); } - - /* for ( unsigned int j=2; j<=Map::dimension; ++j ) - { - if ( !(*it)->is_free(j) ) - amap.basic_link_beta((*it)->beta(0), (*it)->beta(j), j); - //((*it)->beta(0))->basic_link_beta((*it)->beta(j),j); - } */ } else { @@ -566,15 +562,7 @@ namespace CGAL { >:: run(&amap, (*it)->beta(1), mark, &mark_for_incident_cells[0], &incident_cells[0]); - //todegroup.push(Dart_pair((*it)->beta(1), *it)); - //(*it)->beta(1)->unlink_beta(0); } - - /* for ( unsigned int j=2; j<=Map::dimension; ++j ) - { - if ( !(*it)->is_free(j) ) - amap.unlink_beta(*it, j); - } */ } } @@ -618,13 +606,6 @@ namespace CGAL { } } - // We remove all the darts of the i-cell. - for ( it=to_erase.begin(); it!=to_erase.end(); ++it ) - { amap.erase_dart(*it); } - - CGAL_assertion( amap.is_whole_map_unmarked(mark) ); - amap.free_mark(mark); - // We test the split of all the incident cells for all the non // void attributes. Map::Helper::template Foreach_enabled_attributes @@ -632,6 +613,13 @@ namespace CGAL { run(&amap, &mark_for_incident_cells[0], &incident_cells[0]); + // We remove all the darts of the i-cell. + for ( it=to_erase.begin(); it!=to_erase.end(); ++it ) + { amap.erase_dart(*it); } + + CGAL_assertion( amap.is_whole_map_unmarked(mark) ); + amap.free_mark(mark); + // We free the marks. for (int j=0; j::iterator itj=it->begin(); itj!=it->end(); ++itj ) { - if ( !amap->is_marked( *itj, mark_for_jcells) ) + if ( !amap->is_marked(*itj, mark_for_jcells) ) { ++nbofjcell; if ( nbofjcell>1 ) { a2 = amap->template create_attribute(*a1); - std::cout<<"A2 "<<&*a2<<" "<<&**itj<<": "; + // std::cout<<"A2 "<<&*a2<<" "<<&**itj<<": "; // We call the on_split functor } else { a1=(*itj)->template attribute(); - // TODO a1->set_dart(*itj); - std::cout<<"A1 "<<&*a1<<" "<<&**itj<<": "; + // std::cout<<"A1 "<<&*a1<<" "<<&**itj<<": "; } for ( CMap_dart_iterator_basic_of_cell itj2(*amap, *itj, mark_for_jcells); itj2.cont(); ++itj2 ) { - std::cout<<&*itj2<<", "; + // std::cout<<&*itj2<<", "; if ( nbofjcell>1 ) amap->template set_attribute_of_dart(itj2, a2); amap->mark(itj2, mark_for_jcells); } - std::cout<1 ) Apply_cell_functor diff --git a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt index c2d47fc14a2..cf37a67d286 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt @@ -11,6 +11,8 @@ else() cmake_policy(VERSION 2.6) endif() +# add_definitions("-DCGAL_CHECK_EXPENSIVE") + find_package(CGAL COMPONENTS Qt4) include(${CGAL_USE_FILE}) @@ -23,7 +25,7 @@ find_package(Qt4) find_package(OpenGL) find_package(QGLViewer) -if ( NOT (CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND AND +if ( NOT (CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) ) MESSAGE(STATUS "NOTICE: This demo requires CGAL, QGLViewer, OpenGL " diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp index cafd1038604..050b835852d 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp @@ -40,7 +40,7 @@ MainWindow::MainWindow (QWidget * parent):CGAL::Qt::DemosMainWindow (parent), setupUi (this); scene.lcc = new LCC; - + volumeListDock = new QDockWidget(QString(tr("Volume List")),this); volumeListDock->setAllowedAreas(Qt::RightDockWidgetArea | Qt::LeftDockWidgetArea); @@ -68,7 +68,7 @@ MainWindow::MainWindow (QWidget * parent):CGAL::Qt::DemosMainWindow (parent), QObject::connect(&dialogmesh, SIGNAL(accepted()), this, SLOT(onCreateMeshOk())); - + this->viewer->setScene(&scene); connect_actions (); @@ -87,7 +87,7 @@ MainWindow::MainWindow (QWidget * parent):CGAL::Qt::DemosMainWindow (parent), } void MainWindow::connect_actions () -{ +{ QObject::connect (this->actionQuit, SIGNAL (triggered ()), qApp, SLOT (quit ())); @@ -134,7 +134,7 @@ void MainWindow::onSceneChanged () cells.push_back(2); cells.push_back(3); cells.push_back(4); - + std::vector res = scene.lcc->count_cells (cells); std::ostringstream os; @@ -225,14 +225,14 @@ void MainWindow::on_actionAddOFF_triggered() void MainWindow::load_off (const QString & fileName, bool clear) { QApplication::setOverrideCursor (Qt::WaitCursor); - + if (clear) this->clear_all(); #ifdef CGAL_PROFILE_LCC_DEMO CGAL::Timer timer; timer.start(); #endif - + std::ifstream ifs (qPrintable (fileName)); CGAL::import_from_polyhedron_3_flux < LCC > (*scene.lcc, ifs); @@ -284,7 +284,7 @@ void MainWindow::load_3DTDS (const QString & fileName, bool clear) <<" seconds (counting the time to compute denaulay triangulation)." <sew<3>(d1->beta(1)->beta(1)->beta(2), d2->beta (2)); scene.lcc->sew<3>(d1->beta(2)->beta(1)->beta(1)->beta (2), d3); @@ -378,7 +378,7 @@ void MainWindow::on_actionCreate_mesh_triggered () { dialogmesh.show(); } - + void MainWindow::onCreateMeshOk() { #ifdef CGAL_PROFILE_LCC_DEMO @@ -404,7 +404,7 @@ void MainWindow::onCreateMeshOk() #endif statusBar ()->showMessage (QString ("mesh created"),DELAY_STATUSMSG); - + emit (sceneChanged ()); } @@ -464,7 +464,7 @@ void MainWindow::on_actionCompute_Voronoi_3D_triggered () tr ("Data file (*)")); if (fileName.isEmpty ()) return; - + this->clear_all(); #ifdef CGAL_PROFILE_LCC_DEMO @@ -477,7 +477,7 @@ void MainWindow::on_actionCompute_Voronoi_3D_triggered () LCC delaunay_lcc; Dart_handle dh; - + std::ifstream ifs (qPrintable (fileName)); T.insert (std::istream_iterator < Point_3 >(ifs), std::istream_iterator < Point_3 >() ); @@ -494,14 +494,14 @@ void MainWindow::on_actionCompute_Voronoi_3D_triggered () { LCC::Dart_range::iterator it1=delaunay_lcc.darts().begin(); LCC::Dart_range::iterator it2=scene.lcc->darts().begin(); - + std::map dual; - + for ( ; it1!=delaunay_lcc.darts().end(); ++it1, ++it2 ) { dual[it1]=it2; } - + // We update the geometry of dual_lcc by using the std::map face_to_dart. for ( std::map ::iterator it=vol_to_dart.begin(), itend=vol_to_dart.end(); @@ -546,7 +546,7 @@ void MainWindow::on_actionCompute_Voronoi_3D_triggered () std::cout<<"Time to compute Voronoi 3D from "<showMessage (QString ("Voronoi 3D of points in ") + fileName, @@ -582,7 +582,7 @@ void MainWindow::on_actionDual_3_triggered () scene.lcc = duallcc; this->viewer->setScene(&scene); init_all_new_volumes(); - + statusBar ()->showMessage (QString ("Dual_3 computed"), DELAY_STATUSMSG); emit (sceneChanged ()); } @@ -734,7 +734,7 @@ void MainWindow::on_actionTriangulate_all_facets_triggered() std::cout<<"Time to triangulate all filled faces: " <showMessage (QString ("Facets of visible and filled volume(s) triangulated"), @@ -829,7 +829,7 @@ void MainWindow::update_volume_list_add(LCC::Attribute_handle<3>::type ah) } void MainWindow::update_volume_list_remove(int i) -{ +{ assert(irowCount()); volumeList->removeRow(i); } @@ -987,10 +987,10 @@ void MainWindow::on_actionExtend_filled_volumes_triggered() volumeList->disconnect(this); std::vector::type> tofill; - + int mark_volume = scene.lcc->get_new_mark(); bool already_tofill; - + for (LCC::Attribute_range<3>::type::iterator it=scene.lcc->attributes<3>().begin(), itend=scene.lcc->attributes<3>().end(); it!=itend; ++it) @@ -1020,7 +1020,7 @@ void MainWindow::on_actionExtend_filled_volumes_triggered() } CGAL_assertion( scene.lcc->is_whole_map_marked(mark_volume) ); - scene.lcc->free_mark(mark_volume); + scene.lcc->free_mark(mark_volume); if ( tofill.size()>0 ) { @@ -1029,7 +1029,7 @@ void MainWindow::on_actionExtend_filled_volumes_triggered() { (*it)->info().set_filled(true); } - + update_volume_list_all_ckeckstates(); emit(sceneChanged()); } @@ -1042,10 +1042,10 @@ void MainWindow::on_actionExtend_hidden_volumes_triggered() volumeList->disconnect(this); std::vector::type> tohide; - + int mark_volume = scene.lcc->get_new_mark(); bool already_tohide; - + for (LCC::Attribute_range<3>::type::iterator it=scene.lcc->attributes<3>().begin(), itend=scene.lcc->attributes<3>().end(); it!=itend; ++it) @@ -1075,7 +1075,7 @@ void MainWindow::on_actionExtend_hidden_volumes_triggered() } CGAL_assertion( scene.lcc->is_whole_map_marked(mark_volume) ); - scene.lcc->free_mark(mark_volume); + scene.lcc->free_mark(mark_volume); if ( tohide.size()>0 ) { @@ -1084,7 +1084,7 @@ void MainWindow::on_actionExtend_hidden_volumes_triggered() { (*it)->info().set_visible(false); } - + update_volume_list_all_ckeckstates(); emit(sceneChanged()); } @@ -1095,10 +1095,10 @@ void MainWindow::on_actionExtend_hidden_volumes_triggered() void MainWindow::on_actionCreate_Menger_Sponge_triggered () { dialogmenger.mengerLevel->disconnect(this); - + dialogmenger.mengerLevel->setValue(0); mengerLevel=0; - assert( mengerVolumes.empty() ); + assert( mengerVolumes.empty() ); mengerVolumes.push_back(on_actionCreate_cube_triggered()); update_operations_entries(false); @@ -1115,7 +1115,7 @@ void MainWindow::onMengerCancel() { CGAL::remove_cell(*scene.lcc, *it); } - + recreate_whole_volume_list(); mengerVolumes.clear(); emit(sceneChanged()); @@ -1228,14 +1228,14 @@ void MainWindow::split_edge_in_three(Dart_handle dh) { LCC::Point p1 = LCC::point(dh); LCC::Point p2 = LCC::point(dh->other_extremity()); - + LCC::Vector v1 = LCC::Traits::Construct_vector() (p1,p2); LCC::Vector v2 = LCC::Traits::Construct_scaled_vector() (v1,1.0/3); LCC::Vector v3 = LCC::Traits::Construct_scaled_vector() (v1,2.0/3); - + LCC::Point p3 = LCC::Traits::Construct_translated_point() (p1,v2); LCC::Point p4 = LCC::Traits::Construct_translated_point() (p1,v3); - + (scene.lcc)->insert_point_in_cell<1>(dh,p4); (scene.lcc)->insert_point_in_cell<1>(dh,p3); } @@ -1251,12 +1251,12 @@ void MainWindow::split_face_in_nine(Dart_handle dh) { Dart_handle d2 = dh->beta(1)->beta(1)->beta(1)->beta(1) ->beta(1)->beta(1)->beta(1); - + Dart_handle e2= CGAL::insert_cell_1_in_cell_2(*(scene.lcc), dh->beta(1)->beta(1),d2); Dart_handle e1= CGAL::insert_cell_1_in_cell_2(*(scene.lcc), dh->beta(1),d2->beta(1)); - + split_edge_in_three(e1); split_edge_in_three(e2); @@ -1289,10 +1289,10 @@ void MainWindow::split_vol_in_three(Dart_handle dh, bool removecenter) Dart_handle f1= insert_cell_2_in_cell_3(*(scene.lcc),edges1.begin(),edges1.end()); - + Dart_handle f2= insert_cell_2_in_cell_3(*(scene.lcc),edges2.begin(),edges2.end()); - + f1->attribute<3>()->info().color()= (CGAL::Color(myrandom.get_int(0,256), myrandom.get_int(0,256), @@ -1303,7 +1303,7 @@ void MainWindow::split_vol_in_three(Dart_handle dh, bool removecenter) myrandom.get_int(0,256))); update_volume_list_add(dh->attribute<3>()); - + if ( removecenter ) CGAL::remove_cell(*scene.lcc,f1); else @@ -1338,10 +1338,10 @@ void MainWindow::split_vol_in_nine(Dart_handle dh, bool removecenter) Dart_handle f1= insert_cell_2_in_cell_3(*(scene.lcc),edges1.begin(),edges1.end()); - + Dart_handle f2= insert_cell_2_in_cell_3(*(scene.lcc),edges2.begin(),edges2.end()); - + f1->attribute<3>()->info().color()= (CGAL::Color(myrandom.get_int(0,256), myrandom.get_int(0,256), @@ -1350,7 +1350,7 @@ void MainWindow::split_vol_in_nine(Dart_handle dh, bool removecenter) (CGAL::Color(myrandom.get_int(0,256), myrandom.get_int(0,256), myrandom.get_int(0,256))); - + update_volume_list_add(dh->attribute<3>()); if ( !removecenter) update_volume_list_add(f1->attribute<3>()); @@ -1359,7 +1359,7 @@ void MainWindow::split_vol_in_nine(Dart_handle dh, bool removecenter) split_face_in_three(f2); split_vol_in_three(dh,removecenter); - + mengerVolumes.push_back(f2->beta(2)->beta(1)); split_vol_in_three(f2->beta(2)->beta(1),removecenter); @@ -1392,7 +1392,7 @@ void MainWindow::split_vol_in_twentyseven(Dart_handle dh) curd=curd->beta(1)->beta(2)->beta(1); } assert( curd==dh->beta(1)->beta(1)->beta(2)->beta(1)->beta(1)->beta(2) ); - + Dart_handle f1= insert_cell_2_in_cell_3(*(scene.lcc),edges1.begin(),edges1.end()); @@ -1408,9 +1408,9 @@ void MainWindow::split_vol_in_twentyseven(Dart_handle dh) myrandom.get_int(0,256), myrandom.get_int(0,256))); - update_volume_list_add(dh->attribute<3>()); + update_volume_list_add(dh->attribute<3>()); update_volume_list_add(f1->attribute<3>()); - + mengerVolumes.push_back(f1->beta(2)); mengerVolumes.push_back(f2->beta(2)); @@ -1427,7 +1427,7 @@ void MainWindow::process_full_slice(Dart_handle init, int markVols) { Dart_handle d[12]; - d[0]=init->beta(1)->beta(2); + d[0]=init->beta(1)->beta(2); d[1]=d[0]->beta(3)->beta(1)->beta(2)->beta(1); d[2]=d[1]->beta(1)->beta(2)->beta(1); d[3]=d[2]->beta(3)->beta(1)->beta(2)->beta(1); @@ -1548,7 +1548,7 @@ void MainWindow::onMengerDec() { if ( (scene.lcc)->is_marked(*itvol, markVols) ) CGAL::unmark_cell(*(scene.lcc), *itvol, markVols); - + for (LCC::Dart_of_cell_range<3>::iterator it=scene.lcc->darts_of_cell<3>(*itvol).begin(), itend=scene.lcc->darts_of_cell<3>(*itvol).end(); @@ -1558,7 +1558,7 @@ void MainWindow::onMengerDec() edges.push_back(it); } } - + assert( (scene.lcc)->is_whole_map_unmarked(markVols) ); for(unsigned int i = 0; i < edges.size(); i++) @@ -1568,7 +1568,7 @@ void MainWindow::onMengerDec() CGAL::remove_cell(*scene.lcc, edges[i]); } edges.clear(); - + // Lastly we remove vertices. for ( std::vector::iterator itvol=mengerVolumes.begin(); itvol!=mengerVolumes.end(); ++itvol) @@ -1587,8 +1587,8 @@ void MainWindow::onMengerDec() } } } - - (scene.lcc)->negate_mark(markVols); + + (scene.lcc)->negate_mark(markVols); for ( std::vector::iterator itvol=mengerVolumes.begin(); itvol!=mengerVolumes.end(); ++itvol) { @@ -1602,8 +1602,8 @@ void MainWindow::onMengerDec() CGAL::unmark_cell(*scene.lcc, it, markVertices); } } - - (scene.lcc)->negate_mark(markVols); + + (scene.lcc)->negate_mark(markVols); assert( (scene.lcc)->is_whole_map_unmarked(markVols) ); assert( (scene.lcc)->is_whole_map_unmarked(markVertices) ); @@ -1612,7 +1612,7 @@ void MainWindow::onMengerDec() CGAL::remove_cell(*scene.lcc, vertices[i]); } vertices.clear(); - + (scene.lcc)->free_mark(markVols); (scene.lcc)->free_mark(markVertices);