From 35321988fd26c0a3be31c93699df55d54cc80cd2 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 9 Feb 2017 16:14:47 +0100 Subject: [PATCH 1/2] fix segfault after reload --- .../demo/Polyhedron/Scene_c3t3_item.cpp | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp index 3d0bde957d8..81a75f1322e 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp @@ -1644,25 +1644,28 @@ void Scene_c3t3_item::show_grid(bool b) } void Scene_c3t3_item::show_spheres(bool b) { - d->spheres_are_shown = b; - contextMenu()->findChild("actionShowSpheres")->setChecked(b); - if(b && !d->spheres) + if(is_valid()) { - d->spheres = new Scene_spheres_item(this, true); - d->spheres->setName("Protecting spheres"); - d->spheres->setRenderingMode(Gouraud); - connect(d->spheres, SIGNAL(destroyed()), this, SLOT(reset_spheres())); - scene->addItem(d->spheres); - scene->changeGroup(d->spheres, this); - lockChild(d->spheres); - d->computeSpheres(); + d->spheres_are_shown = b; + contextMenu()->findChild("actionShowSpheres")->setChecked(b); + if(b && !d->spheres) + { + d->spheres = new Scene_spheres_item(this, true); + d->spheres->setName("Protecting spheres"); + d->spheres->setRenderingMode(Gouraud); + connect(d->spheres, SIGNAL(destroyed()), this, SLOT(reset_spheres())); + scene->addItem(d->spheres); + scene->changeGroup(d->spheres, this); + lockChild(d->spheres); + d->computeSpheres(); + } + else if (!b && d->spheres!=NULL) + { + unlockChild(d->spheres); + scene->erase(scene->item_id(d->spheres)); + } + Q_EMIT redraw(); } - else if (!b && d->spheres!=NULL) - { - unlockChild(d->spheres); - scene->erase(scene->item_id(d->spheres)); - } - Q_EMIT redraw(); } void Scene_c3t3_item::show_intersection(bool b) @@ -1694,10 +1697,12 @@ void Scene_c3t3_item::show_intersection(bool b) } void Scene_c3t3_item::show_cnc(bool b) { - d->cnc_are_shown = b; - contextMenu()->findChild("actionShowCNC")->setChecked(b); - Q_EMIT redraw(); - + if(is_valid()) + { + d->cnc_are_shown = b; + contextMenu()->findChild("actionShowCNC")->setChecked(b); + Q_EMIT redraw(); + } } void Scene_c3t3_item::reset_intersection_item() From cc64739c669c99692897a58a4d6dcbc31c7b62d5 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 10 Feb 2017 10:10:00 +0100 Subject: [PATCH 2/2] Fixes : - set the dimension of vertices without connectivity to -1 (fixes the BBox's problem) - re-center the cut-plane after every type of load (fixes the cutplane problem) --- Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h | 10 +++++----- .../Plugins/Mesh_3/C3t3_io_plugin.cpp | 3 +++ Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp | 17 +++++------------ Polyhedron/demo/Polyhedron/Scene_c3t3_item.h | 2 ++ 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h b/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h index dcb828e3158..b327c749d87 100644 --- a/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h +++ b/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h @@ -115,6 +115,7 @@ void build_finite_cells(Tr& tr, { CGAL_precondition(static_cast(tet[j]) < tr.number_of_vertices() && tet[j] >= 0); + vertex_handle_vector[tet[j] + 1]->set_dimension(3); vs[j] = vertex_handle_vector[tet[j] + 1]; CGAL_postcondition(vs[j] != Vertex_handle()); } @@ -294,6 +295,10 @@ bool build_triangulation(Tr& tr, tr.tds().clear(); // not tr.clear() since it calls tr.init() which we don't want build_vertices(tr, points, vertex_handle_vector); + BOOST_FOREACH(Vertex_handle vh, vertex_handle_vector) + { + vh->set_dimension(-1); + } if(!finite_cells.empty()) { build_finite_cells(tr, finite_cells, vertex_handle_vector, incident_cells_map, border_facets); @@ -305,11 +310,6 @@ bool build_triangulation(Tr& tr, std::cout << tr.number_of_cells() << " cells" << std::endl; } std::cout << tr.number_of_vertices() << " vertices" << std::endl; - - BOOST_FOREACH(Vertex_handle vh, vertex_handle_vector) - { - vh->set_dimension(3); - } if(c3t3_loader_failed) { return true; diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp index 3c176400d4e..3eb3c27024f 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp @@ -81,6 +81,7 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) { if(try_load_other_binary_format(in, item->c3t3())) { item->c3t3_changed(); item->changed(); + item->resetCutPlane(); return item; } @@ -89,6 +90,7 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) { if(try_load_a_cdt_3(in, item->c3t3())) { item->c3t3_changed(); item->changed(); + item->resetCutPlane(); return item; } } @@ -143,6 +145,7 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) { } } item->c3t3_changed(); + item->resetCutPlane(); return item; } else if(item->c3t3().triangulation().number_of_finite_cells() == 0) diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp index 81a75f1322e..35b3bb4e9fe 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp @@ -492,18 +492,6 @@ struct Set_show_tetrahedra { } }; - -double complex_diag(const Scene_item* item) { - const Scene_item::Bbox& bbox = item->bbox(); - const double& xdelta = bbox.xmax()-bbox.xmin(); - const double& ydelta = bbox.ymax()-bbox.ymin(); - const double& zdelta = bbox.zmax()-bbox.zmin(); - const double diag = std::sqrt(xdelta*xdelta + - ydelta*ydelta + - zdelta*zdelta); - return diag * 0.7; -} - Scene_c3t3_item::Scene_c3t3_item() : Scene_group_item("unnamed", Scene_c3t3_item_priv::NumberOfBuffers, Scene_c3t3_item_priv::NumberOfVaos) , d(new Scene_c3t3_item_priv(this)) @@ -1519,6 +1507,7 @@ void Scene_c3t3_item_priv::computeElements() //The grid { + float x = (2 * (float)complex_diag()) / 10.0; float y = (2 * (float)complex_diag()) / 10.0; for (int u = 0; u < 11; u++) @@ -1997,4 +1986,8 @@ void Scene_c3t3_item::invalidateOpenGLBuffers() compute_bbox(); d->invalidate_stats(); } +void Scene_c3t3_item::resetCutPlane() +{ + d->reset_cut_plane(); +} #include "Scene_c3t3_item.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h index 54fb5d0d9a9..4af3ebe6af4 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h @@ -61,6 +61,8 @@ public: void c3t3_changed(); + void resetCutPlane(); + void set_valid(bool); const C3t3& c3t3() const;